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