1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: task4.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "TaskParallelismWithPorts.h"
16
17 #include "vtkImageData.h"
18 #include "vtkOutputPort.h"
19 #include "vtkPolyData.h"
20
21 // Task 4 for TaskParallelism.
22 // See TaskParallelismWithPorts.cxx for more information.
task4(double data)23 void task4(double data)
24 {
25 double extent = data;
26 int iextent = static_cast<int>(data);
27 // The pipeline
28
29 // Synthetic image source.
30 vtkRTAnalyticSource* source1 = vtkRTAnalyticSource::New();
31 source1->SetWholeExtent (-1*iextent, iextent, -1*iextent, iextent,
32 -1*iextent, iextent );
33 source1->SetCenter(0, 0, 0);
34 source1->SetStandardDeviation( 0.5 );
35 source1->SetMaximum( 255.0 );
36 source1->SetXFreq( 60 );
37 source1->SetXMag( 10 );
38 source1->SetYFreq( 30 );
39 source1->SetYMag( 18 );
40 source1->SetZFreq( 40 );
41 source1->SetZMag( 5 );
42 source1->GetOutput()->SetSpacing(2.0/extent,2.0/extent,2.0/extent);
43
44 // Gradient vector.
45 vtkImageGradient* grad = vtkImageGradient::New();
46 grad->SetDimensionality( 3 );
47 grad->SetInputConnection(source1->GetOutputPort());
48
49 vtkImageShrink3D* mask = vtkImageShrink3D::New();
50 mask->SetInputConnection(grad->GetOutputPort());
51 mask->SetShrinkFactors(5, 5, 5);
52
53
54 // Label the scalar field as the active vectors.
55 vtkAssignAttribute* aa = vtkAssignAttribute::New();
56 aa->SetInputConnection(mask->GetOutputPort());
57 aa->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS,
58 vtkAssignAttribute::POINT_DATA);
59
60 vtkGlyphSource2D* arrow = vtkGlyphSource2D::New();
61 arrow->SetGlyphTypeToArrow();
62 arrow->SetScale(0.2);
63 arrow->FilledOff();
64
65 // Glyph the gradient vector (with arrows)
66 vtkGlyph3D* glyph = vtkGlyph3D::New();
67 glyph->SetInputConnection(aa->GetOutputPort());
68 glyph->SetSource(arrow->GetOutput());
69 glyph->ScalingOff();
70 glyph->OrientOn();
71 glyph->SetVectorModeToUseVector();
72 glyph->SetColorModeToColorByVector();
73
74 // Output port
75 vtkOutputPort* op = vtkOutputPort::New();
76 op->SetInputConnection(glyph->GetOutputPort());
77 op->SetTag(11);
78
79 // Process requests
80 op->WaitForUpdate();
81
82 // Cleanup
83 op->Delete();
84 source1->Delete();
85 grad->Delete();
86 aa->Delete();
87 mask->Delete();
88 glyph->Delete();
89 arrow->Delete();
90
91 }
92
93
94
95
96
97
98