1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestDensifyPolyData.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 "vtkDensifyPolyData.h"
16 #include "vtkXMLPolyDataWriter.h"
17 #include "vtkRenderer.h"
18 #include "vtkRenderWindow.h"
19 #include "vtkRenderWindowInteractor.h"
20 #include "vtkActor.h"
21 #include "vtkCamera.h"
22 #include "vtkTextActor.h"
23 #include "vtkTextProperty.h"
24 #include "vtkTestUtilities.h"
25 #include "vtkPointData.h"
26 #include "vtkCellData.h"
27 #include "vtkCellArray.h"
28 #include "vtkSmartPointer.h"
29 #include "vtkProperty.h"
30 #include "vtkPolyDataMapper.h"
31 #include "vtkPoints.h"
32 #include "vtkSphereSource.h"
33
34 #define VTK_CREATE(type, var) \
35 vtkSmartPointer<type> var = vtkSmartPointer<type>::New()
36
TestDensifyPolyData(int,char * [])37 int TestDensifyPolyData(int, char *[])
38 {
39
40 VTK_CREATE(vtkPoints, boxPoints);
41 boxPoints->InsertNextPoint(-0.5,-0.5,-0.5);
42 boxPoints->InsertNextPoint(-0.5,-0.5,0.5);
43 boxPoints->InsertNextPoint(-0.5,0.5,0.5);
44 boxPoints->InsertNextPoint(-0.5,0.5,-0.5);
45 boxPoints->InsertNextPoint(0.5,-0.5,-0.5);
46 boxPoints->InsertNextPoint(0.5,0.5,-0.5);
47 boxPoints->InsertNextPoint(0.5,-0.5,0.5);
48 boxPoints->InsertNextPoint(0.5,0.5,0.023809850216);
49 boxPoints->InsertNextPoint(0.5,0.072707727551,0.5);
50 boxPoints->InsertNextPoint(-0.014212930575,0.5,0.5);
51
52 VTK_CREATE(vtkPolyData, boxPolydata);;
53 VTK_CREATE(vtkCellArray, polys);
54 boxPolydata->SetPolys(polys);
55 boxPolydata->SetPoints(boxPoints);
56 { vtkIdType ids[] = {0,1,2,3};
57 boxPolydata->InsertNextCell(VTK_POLYGON, 4, ids ); }
58 { vtkIdType ids[] = {4,5,7,8,6};
59 boxPolydata->InsertNextCell(VTK_POLYGON, 5, ids ); }
60 { vtkIdType ids[] = {0,4,6,1};
61 boxPolydata->InsertNextCell(VTK_POLYGON, 4, ids ); }
62 { vtkIdType ids[] = {3,2,9,7,5};
63 boxPolydata->InsertNextCell(VTK_POLYGON, 5, ids ); }
64 { vtkIdType ids[] = {0,3,5,4};
65 boxPolydata->InsertNextCell(VTK_POLYGON, 4, ids ); }
66 { vtkIdType ids[] = {1,6,8,9,2};
67 boxPolydata->InsertNextCell(VTK_POLYGON, 5, ids ); }
68 { vtkIdType ids[] = {7,9,8};
69 boxPolydata->InsertNextCell(VTK_POLYGON, 3, ids ); }
70
71 VTK_CREATE( vtkDensifyPolyData, densifyFilter );
72 densifyFilter->SetInputData(boxPolydata);
73 densifyFilter->SetNumberOfSubdivisions(2);
74
75 VTK_CREATE( vtkXMLPolyDataWriter, writer);
76 writer->SetInputConnection(densifyFilter->GetOutputPort());
77 writer->SetFileName("tessellatedBox.vtp");
78 writer->SetDataModeToAscii();
79 writer->Update();
80
81 VTK_CREATE( vtkSphereSource, sphere );
82 VTK_CREATE( vtkDensifyPolyData, densifyFilter2 );
83 densifyFilter2->SetInputConnection(sphere->GetOutputPort());
84 densifyFilter2->SetNumberOfSubdivisions(1);
85
86
87 // Throw the stuff on the screen.
88 VTK_CREATE(vtkRenderWindow, renwin);
89 renwin->SetMultiSamples(0);
90 renwin->SetSize(800, 640);
91
92 VTK_CREATE(vtkRenderWindowInteractor, iren);
93 iren->SetRenderWindow(renwin);
94
95 VTK_CREATE(vtkPolyDataMapper, mapper1);
96 mapper1->SetInputData(boxPolydata);
97
98 VTK_CREATE(vtkActor, actor1);
99 actor1->SetMapper(mapper1);
100 actor1->GetProperty()->SetPointSize(3.0f);
101
102 VTK_CREATE(vtkRenderer, renderer1);
103 renderer1->AddActor(actor1);
104 renderer1->SetBackground(0.0, 0.5, 0.5);
105 renderer1->SetViewport(0, 0, 0.5, 0.5);
106 renwin->AddRenderer(renderer1);
107 actor1->GetProperty()->SetRepresentationToWireframe();
108
109 VTK_CREATE(vtkPolyDataMapper, mapper2);
110 mapper2->SetInputConnection(densifyFilter->GetOutputPort());
111
112 VTK_CREATE(vtkActor, actor2);
113 actor2->SetMapper(mapper2);
114 actor2->GetProperty()->SetPointSize(3.0f);
115
116 VTK_CREATE(vtkRenderer, renderer2);
117 renderer2->AddActor(actor2);
118 renderer2->SetBackground(0.0, 0.5, 0.5);
119 renderer2->SetViewport(0.5, 0.0, 1, 0.5);
120 renwin->AddRenderer(renderer2);
121 actor2->GetProperty()->SetRepresentationToWireframe();
122
123 VTK_CREATE(vtkPolyDataMapper, mapper3);
124 mapper3->SetInputConnection(sphere->GetOutputPort());
125
126 VTK_CREATE(vtkActor, actor3);
127 actor3->SetMapper(mapper3);
128 actor3->GetProperty()->SetPointSize(3.0f);
129
130 VTK_CREATE(vtkRenderer, renderer3);
131 renderer3->AddActor(actor3);
132 renderer3->SetBackground(0.0, 0.5, 0.5);
133 renderer3->SetViewport(0, 0.5, 0.5, 1);
134 renwin->AddRenderer(renderer3);
135 actor3->GetProperty()->SetRepresentationToWireframe();
136
137 VTK_CREATE(vtkPolyDataMapper, mapper4);
138 mapper4->SetInputConnection(densifyFilter2->GetOutputPort());
139
140 VTK_CREATE(vtkActor, actor4);
141 actor4->SetMapper(mapper4);
142 actor4->GetProperty()->SetPointSize(3.0f);
143
144 VTK_CREATE(vtkRenderer, renderer4);
145 renderer4->AddActor(actor4);
146 renderer4->SetBackground(0.0, 0.5, 0.5);
147 renderer4->SetViewport(0.5, 0.5, 1, 1);
148 renwin->AddRenderer(renderer4);
149 actor4->GetProperty()->SetRepresentationToWireframe();
150
151 renwin->Render();
152 iren->Start();
153
154 return EXIT_SUCCESS;
155 }
156
157