1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestUncertaintyTubeFilter.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 // This test creates some polylines with uncertainty values.
16
17 #include "vtkUncertaintyTubeFilter.h"
18
19 #include "vtkSmartPointer.h"
20 #include "vtkPolyData.h"
21 #include "vtkDelaunay2D.h"
22 #include "vtkCellArray.h"
23 #include "vtkShrinkPolyData.h"
24 #include "vtkPolyDataMapper.h"
25 #include "vtkActor.h"
26 #include "vtkRenderer.h"
27 #include "vtkRenderWindow.h"
28 #include "vtkDoubleArray.h"
29 #include "vtkMath.h"
30 #include "vtkCamera.h"
31 #include "vtkPointData.h"
32 #include "vtkRenderWindowInteractor.h"
33 #include "vtkTriangleFilter.h"
34
TestUncertaintyTubeFilter(int,char * [])35 int TestUncertaintyTubeFilter( int, char*[] )
36 {
37 vtkSmartPointer<vtkPoints> newPts =
38 vtkSmartPointer<vtkPoints>::New();
39 newPts->SetNumberOfPoints(10);
40 newPts->SetPoint( 0, 10,10,0);
41 newPts->SetPoint( 1, 10,10,2);
42 newPts->SetPoint( 2, 10,10,4);
43 newPts->SetPoint( 3, 10,10,8);
44 newPts->SetPoint( 4, 10,10,12);
45 newPts->SetPoint( 5, 1,1,2);
46 newPts->SetPoint( 6, 1,2,3);
47 newPts->SetPoint( 7, 1,4,3);
48 newPts->SetPoint( 8, 1,8,4);
49 newPts->SetPoint( 9, 1,16,5);
50
51 vtkMath::RandomSeed(1177);
52 vtkSmartPointer<vtkDoubleArray> s =
53 vtkSmartPointer<vtkDoubleArray>::New();
54 s->SetNumberOfComponents(1);
55 s->SetNumberOfTuples(10);
56 vtkSmartPointer<vtkDoubleArray> v =
57 vtkSmartPointer<vtkDoubleArray>::New();
58 v->SetNumberOfComponents(3);
59 v->SetNumberOfTuples(10);
60 for (int i=0; i<10; i++)
61 {
62 s->SetTuple1(i, vtkMath::Random(0,1));
63 double x=vtkMath::Random(0.0,2);
64 double y=vtkMath::Random(0.0,2);
65 double z=vtkMath::Random(0.0,2);
66 v->SetTuple3(i,x,y,z);
67 }
68
69 vtkSmartPointer<vtkCellArray> lines =
70 vtkSmartPointer<vtkCellArray>::New();
71 lines->EstimateSize(2,5);
72 lines->InsertNextCell(5);
73 lines->InsertCellPoint(0);
74 lines->InsertCellPoint(1);
75 lines->InsertCellPoint(2);
76 lines->InsertCellPoint(3);
77 lines->InsertCellPoint(4);
78 lines->InsertNextCell(5);
79 lines->InsertCellPoint(5);
80 lines->InsertCellPoint(6);
81 lines->InsertCellPoint(7);
82 lines->InsertCellPoint(8);
83 lines->InsertCellPoint(9);
84
85 vtkSmartPointer<vtkPolyData> pd =
86 vtkSmartPointer<vtkPolyData>::New();
87 pd->SetPoints(newPts);
88 pd->SetLines(lines);
89 pd->GetPointData()->SetScalars(s);
90 pd->GetPointData()->SetVectors(v);
91
92 vtkSmartPointer<vtkUncertaintyTubeFilter> utf =
93 vtkSmartPointer<vtkUncertaintyTubeFilter>::New();
94 utf->SetInputData(pd);
95 utf->SetNumberOfSides(8);
96
97 vtkSmartPointer<vtkTriangleFilter> tf =
98 vtkSmartPointer<vtkTriangleFilter>::New();
99 tf->SetInputConnection(utf->GetOutputPort());
100
101 vtkSmartPointer<vtkPolyDataMapper> mapper =
102 vtkSmartPointer<vtkPolyDataMapper>::New();
103 //mapper->SetInputConnection( utf->GetOutputPort() );
104 mapper->SetInputConnection( tf->GetOutputPort() );
105
106 vtkSmartPointer<vtkActor> actor =
107 vtkSmartPointer<vtkActor>::New();
108 actor->SetMapper(mapper);
109
110 vtkSmartPointer<vtkRenderer> ren =
111 vtkSmartPointer<vtkRenderer>::New();
112 ren->AddActor(actor);
113
114 vtkSmartPointer<vtkRenderWindow> renWin =
115 vtkSmartPointer<vtkRenderWindow>::New();
116 renWin->AddRenderer(ren);
117
118 vtkSmartPointer<vtkRenderWindowInteractor> iren =
119 vtkSmartPointer<vtkRenderWindowInteractor>::New();
120 iren->SetRenderWindow(renWin);
121
122 ren->GetActiveCamera()->SetPosition(1,1,1);
123 ren->GetActiveCamera()->SetFocalPoint(0,0,0);
124 ren->ResetCamera();
125
126 iren->Initialize();
127
128 renWin->Render();
129
130 iren->Start();
131
132 return EXIT_SUCCESS;
133 }
134