1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestLODActor.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 // The test creates a Kline, replaces the default strategy from vtkMaskPoints
16 // to vtkQuadricClustering ; so instead of seeing a point cloud during
17 // interaction, (when run with -I) you will see a low res kline.
18 
19 #include "vtkTestUtilities.h"
20 #include "vtkRegressionTestImage.h"
21 #include "vtkRenderer.h"
22 #include "vtkRenderWindow.h"
23 #include "vtkRenderWindowInteractor.h"
24 #include "vtkPolyDataMapper.h"
25 #include "vtkCamera.h"
26 #include "vtkPoints.h"
27 #include "vtkCellArray.h"
28 #include "vtkPolyData.h"
29 #include "vtkLODActor.h"
30 #include "vtkLoopSubdivisionFilter.h"
31 #include "vtkDataSetMapper.h"
32 #include "vtkProperty.h"
33 #include "vtkQuadricClustering.h"
34 #include "vtkMaskPoints.h"
35 
TestLODActor(int argc,char * argv[])36 int TestLODActor( int argc, char* argv[])
37 {
38   // Create a Kline.
39 
40   vtkPoints *points = vtkPoints::New();
41   points->InsertNextPoint(0,-16,0);
42   points->InsertNextPoint(0,0,-14);
43   points->InsertNextPoint(0,0,14);
44   points->InsertNextPoint(14,0,0);
45   points->InsertNextPoint(10,20,-10);
46   points->InsertNextPoint(10,20,10);
47   points->InsertNextPoint(10,-20,-10);
48   points->InsertNextPoint(10,-20,10);
49   points->InsertNextPoint(-10,-20,-10);
50   points->InsertNextPoint(-10,-20,10);
51   points->InsertNextPoint(-10,20,-10);
52   points->InsertNextPoint(-10,20,10);
53   points->InsertNextPoint(-2,27,0);
54   points->InsertNextPoint(0,27,2);
55   points->InsertNextPoint(0,27,-2);
56   points->InsertNextPoint(2,27,0);
57   points->InsertNextPoint(-14,4,-1);
58   points->InsertNextPoint(-14,3,0);
59   points->InsertNextPoint(-14,5,0);
60   points->InsertNextPoint(-14,4,1);
61   points->InsertNextPoint(-1,38,-2);
62   points->InsertNextPoint(-1,38,2);
63   points->InsertNextPoint(2,35,-2);
64   points->InsertNextPoint(2,35,2);
65   points->InsertNextPoint(17,42,0);
66   points->InsertNextPoint(15,40,2);
67   points->InsertNextPoint(15,39,-2);
68   points->InsertNextPoint(13,37,0);
69   points->InsertNextPoint(19,-2,-2);
70   points->InsertNextPoint(19,-2,2);
71   points->InsertNextPoint(15,2,-2);
72   points->InsertNextPoint(15,2,2);
73 
74   vtkCellArray *faces = vtkCellArray::New();
75   faces->InsertNextCell(3);
76   faces->InsertCellPoint(3);
77   faces->InsertCellPoint(4);
78   faces->InsertCellPoint(5);
79   faces->InsertNextCell(3);
80   faces->InsertCellPoint(3);
81   faces->InsertCellPoint(5);
82   faces->InsertCellPoint(7);
83   faces->InsertNextCell(3);
84   faces->InsertCellPoint(3);
85   faces->InsertCellPoint(7);
86   faces->InsertCellPoint(6);
87   faces->InsertNextCell(3);
88   faces->InsertCellPoint(3);
89   faces->InsertCellPoint(6);
90   faces->InsertCellPoint(4);
91   faces->InsertNextCell(3);
92   faces->InsertCellPoint(0);
93   faces->InsertCellPoint(6);
94   faces->InsertCellPoint(7);
95   faces->InsertNextCell(3);
96   faces->InsertCellPoint(0);
97   faces->InsertCellPoint(7);
98   faces->InsertCellPoint(9);
99   faces->InsertNextCell(3);
100   faces->InsertCellPoint(0);
101   faces->InsertCellPoint(9);
102   faces->InsertCellPoint(8);
103   faces->InsertNextCell(3);
104   faces->InsertCellPoint(0);
105   faces->InsertCellPoint(8);
106   faces->InsertCellPoint(6);
107   faces->InsertNextCell(3);
108   faces->InsertCellPoint(1);
109   faces->InsertCellPoint(4);
110   faces->InsertCellPoint(6);
111   faces->InsertNextCell(3);
112   faces->InsertCellPoint(1);
113   faces->InsertCellPoint(6);
114   faces->InsertCellPoint(8);
115   faces->InsertNextCell(3);
116   faces->InsertCellPoint(1);
117   faces->InsertCellPoint(8);
118   faces->InsertCellPoint(10);
119   faces->InsertNextCell(3);
120   faces->InsertCellPoint(1);
121   faces->InsertCellPoint(10);
122   faces->InsertCellPoint(4);
123   faces->InsertNextCell(3);
124   faces->InsertCellPoint(2);
125   faces->InsertCellPoint(11);
126   faces->InsertCellPoint(9);
127   faces->InsertNextCell(3);
128   faces->InsertCellPoint(2);
129   faces->InsertCellPoint(9);
130   faces->InsertCellPoint(7);
131   faces->InsertNextCell(3);
132   faces->InsertCellPoint(2);
133   faces->InsertCellPoint(7);
134   faces->InsertCellPoint(5);
135   faces->InsertNextCell(3);
136   faces->InsertCellPoint(2);
137   faces->InsertCellPoint(5);
138   faces->InsertCellPoint(11);
139   faces->InsertNextCell(3);
140   faces->InsertCellPoint(4);
141   faces->InsertCellPoint(15);
142   faces->InsertCellPoint(5);
143   faces->InsertNextCell(3);
144   faces->InsertCellPoint(4);
145   faces->InsertCellPoint(14);
146   faces->InsertCellPoint(15);
147   faces->InsertNextCell(3);
148   faces->InsertCellPoint(5);
149   faces->InsertCellPoint(13);
150   faces->InsertCellPoint(11);
151   faces->InsertNextCell(3);
152   faces->InsertCellPoint(5);
153   faces->InsertCellPoint(15);
154   faces->InsertCellPoint(13);
155   faces->InsertNextCell(3);
156   faces->InsertCellPoint(11);
157   faces->InsertCellPoint(12);
158   faces->InsertCellPoint(10);
159   faces->InsertNextCell(3);
160   faces->InsertCellPoint(11);
161   faces->InsertCellPoint(13);
162   faces->InsertCellPoint(12);
163   faces->InsertNextCell(3);
164   faces->InsertCellPoint(10);
165   faces->InsertCellPoint(14);
166   faces->InsertCellPoint(4);
167   faces->InsertNextCell(3);
168   faces->InsertCellPoint(10);
169   faces->InsertCellPoint(12);
170   faces->InsertCellPoint(14);
171   faces->InsertNextCell(3);
172   faces->InsertCellPoint(8);
173   faces->InsertCellPoint(17);
174   faces->InsertCellPoint(16);
175   faces->InsertNextCell(3);
176   faces->InsertCellPoint(8);
177   faces->InsertCellPoint(9);
178   faces->InsertCellPoint(17);
179   faces->InsertNextCell(3);
180   faces->InsertCellPoint(9);
181   faces->InsertCellPoint(19);
182   faces->InsertCellPoint(17);
183   faces->InsertNextCell(3);
184   faces->InsertCellPoint(9);
185   faces->InsertCellPoint(11);
186   faces->InsertCellPoint(19);
187   faces->InsertNextCell(3);
188   faces->InsertCellPoint(11);
189   faces->InsertCellPoint(18);
190   faces->InsertCellPoint(19);
191   faces->InsertNextCell(3);
192   faces->InsertCellPoint(11);
193   faces->InsertCellPoint(10);
194   faces->InsertCellPoint(18);
195   faces->InsertNextCell(3);
196   faces->InsertCellPoint(10);
197   faces->InsertCellPoint(16);
198   faces->InsertCellPoint(18);
199   faces->InsertNextCell(3);
200   faces->InsertCellPoint(10);
201   faces->InsertCellPoint(8);
202   faces->InsertCellPoint(16);
203   faces->InsertNextCell(3);
204   faces->InsertCellPoint(13);
205   faces->InsertCellPoint(21);
206   faces->InsertCellPoint(12);
207   faces->InsertNextCell(3);
208   faces->InsertCellPoint(12);
209   faces->InsertCellPoint(21);
210   faces->InsertCellPoint(20);
211   faces->InsertNextCell(3);
212   faces->InsertCellPoint(12);
213   faces->InsertCellPoint(20);
214   faces->InsertCellPoint(14);
215   faces->InsertNextCell(3);
216   faces->InsertCellPoint(14);
217   faces->InsertCellPoint(20);
218   faces->InsertCellPoint(22);
219   faces->InsertNextCell(3);
220   faces->InsertCellPoint(14);
221   faces->InsertCellPoint(22);
222   faces->InsertCellPoint(15);
223   faces->InsertNextCell(3);
224   faces->InsertCellPoint(15);
225   faces->InsertCellPoint(22);
226   faces->InsertCellPoint(23);
227   faces->InsertNextCell(3);
228   faces->InsertCellPoint(15);
229   faces->InsertCellPoint(23);
230   faces->InsertCellPoint(13);
231   faces->InsertNextCell(3);
232   faces->InsertCellPoint(13);
233   faces->InsertCellPoint(23);
234   faces->InsertCellPoint(21);
235   faces->InsertNextCell(3);
236   faces->InsertCellPoint(21);
237   faces->InsertCellPoint(25);
238   faces->InsertCellPoint(24);
239   faces->InsertNextCell(3);
240   faces->InsertCellPoint(21);
241   faces->InsertCellPoint(24);
242   faces->InsertCellPoint(20);
243   faces->InsertNextCell(3);
244   faces->InsertCellPoint(20);
245   faces->InsertCellPoint(24);
246   faces->InsertCellPoint(26);
247   faces->InsertNextCell(3);
248   faces->InsertCellPoint(20);
249   faces->InsertCellPoint(26);
250   faces->InsertCellPoint(22);
251   faces->InsertNextCell(3);
252   faces->InsertCellPoint(22);
253   faces->InsertCellPoint(26);
254   faces->InsertCellPoint(27);
255   faces->InsertNextCell(3);
256   faces->InsertCellPoint(22);
257   faces->InsertCellPoint(27);
258   faces->InsertCellPoint(23);
259   faces->InsertNextCell(3);
260   faces->InsertCellPoint(23);
261   faces->InsertCellPoint(27);
262   faces->InsertCellPoint(25);
263   faces->InsertNextCell(3);
264   faces->InsertCellPoint(23);
265   faces->InsertCellPoint(25);
266   faces->InsertCellPoint(21);
267   faces->InsertNextCell(3);
268   faces->InsertCellPoint(25);
269   faces->InsertCellPoint(29);
270   faces->InsertCellPoint(24);
271   faces->InsertNextCell(3);
272   faces->InsertCellPoint(24);
273   faces->InsertCellPoint(29);
274   faces->InsertCellPoint(28);
275   faces->InsertNextCell(3);
276   faces->InsertCellPoint(24);
277   faces->InsertCellPoint(28);
278   faces->InsertCellPoint(26);
279   faces->InsertNextCell(3);
280   faces->InsertCellPoint(26);
281   faces->InsertCellPoint(28);
282   faces->InsertCellPoint(30);
283   faces->InsertNextCell(3);
284   faces->InsertCellPoint(26);
285   faces->InsertCellPoint(30);
286   faces->InsertCellPoint(27);
287   faces->InsertNextCell(3);
288   faces->InsertCellPoint(27);
289   faces->InsertCellPoint(30);
290   faces->InsertCellPoint(31);
291   faces->InsertNextCell(3);
292   faces->InsertCellPoint(27);
293   faces->InsertCellPoint(31);
294   faces->InsertCellPoint(25);
295   faces->InsertNextCell(3);
296   faces->InsertCellPoint(25);
297   faces->InsertCellPoint(31);
298   faces->InsertCellPoint(29);
299   faces->InsertNextCell(3);
300   faces->InsertCellPoint(29);
301   faces->InsertCellPoint(19);
302   faces->InsertCellPoint(17);
303   faces->InsertNextCell(3);
304   faces->InsertCellPoint(29);
305   faces->InsertCellPoint(17);
306   faces->InsertCellPoint(28);
307   faces->InsertNextCell(3);
308   faces->InsertCellPoint(28);
309   faces->InsertCellPoint(17);
310   faces->InsertCellPoint(16);
311   faces->InsertNextCell(3);
312   faces->InsertCellPoint(28);
313   faces->InsertCellPoint(16);
314   faces->InsertCellPoint(30);
315   faces->InsertNextCell(3);
316   faces->InsertCellPoint(30);
317   faces->InsertCellPoint(16);
318   faces->InsertCellPoint(18);
319   faces->InsertNextCell(3);
320   faces->InsertCellPoint(30);
321   faces->InsertCellPoint(18);
322   faces->InsertCellPoint(31);
323   faces->InsertNextCell(3);
324   faces->InsertCellPoint(31);
325   faces->InsertCellPoint(18);
326   faces->InsertCellPoint(19);
327   faces->InsertNextCell(3);
328   faces->InsertCellPoint(31);
329   faces->InsertCellPoint(19);
330   faces->InsertCellPoint(29);
331 
332 
333   vtkPolyData * model = vtkPolyData::New();
334   model->SetPolys(faces);
335   model->SetPoints(points);
336 
337   // Create the RenderWindow, Renderer and both Actors
338 
339   vtkRenderer *ren1 = vtkRenderer::New();
340   vtkRenderWindow *renWin = vtkRenderWindow::New();
341   renWin->AddRenderer(ren1);
342   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
343   iren->SetRenderWindow(renWin);
344 
345   vtkLoopSubdivisionFilter *subdivide = vtkLoopSubdivisionFilter::New();
346     subdivide->SetInputData (model);
347     subdivide->SetNumberOfSubdivisions(6);
348 
349   vtkDataSetMapper *mapper = vtkDataSetMapper::New();
350      mapper->SetInputConnection (subdivide->GetOutputPort());
351 
352   vtkLODActor *rose = vtkLODActor::New();
353       rose->SetMapper (mapper);
354 
355   // Now replace the default strategy of the LOD Actor from to show a low
356   // resolution kline. We will use vtkQuadricClustering for this purpose.
357 
358   vtkQuadricClustering * q = vtkQuadricClustering::New();
359   q->SetNumberOfXDivisions(8);
360   q->SetNumberOfYDivisions(8);
361   q->SetNumberOfZDivisions(8);
362   q->UseInputPointsOn();
363   rose->SetLowResFilter(q);
364   q->Delete();
365 
366   q = vtkQuadricClustering::New();
367   q->SetNumberOfXDivisions(5);
368   q->SetNumberOfYDivisions(5);
369   q->SetNumberOfZDivisions(5);
370   q->UseInputPointsOn();
371   rose->SetMediumResFilter(q);
372   q->Delete();
373 
374   // Add the actors to the renderer, set the background and size
375 
376   ren1->AddActor(rose);
377 
378   vtkProperty *backP = vtkProperty::New();
379   backP->SetDiffuseColor (1, 1, .3);
380   rose->SetBackfaceProperty (backP);
381 
382   rose->GetProperty()->SetDiffuseColor( 1, .4, .3);
383   rose->GetProperty()->SetSpecular(.4);
384   rose->GetProperty()->SetDiffuse(.8);
385   rose->GetProperty()->SetSpecularPower(40);
386 
387   ren1->SetBackground(0.1, 0.2, 0.4);
388   renWin->SetSize(300, 300);
389 
390   // render the image
391 
392   ren1->ResetCamera();
393   vtkCamera * cam1 = ren1->GetActiveCamera();
394   cam1->Azimuth(-90);
395   ren1->ResetCameraClippingRange();
396   iren->Initialize();
397   iren->SetDesiredUpdateRate(5000);
398 
399   int retVal = vtkRegressionTestImage( renWin );
400   if ( retVal == vtkRegressionTester::DO_INTERACTOR)
401     {
402     iren->Start();
403     }
404 
405   model->Delete();
406   backP->Delete();
407   mapper->Delete();
408   subdivide->Delete();
409   ren1->Delete();
410   renWin->Delete();
411   rose->Delete();
412   faces->Delete();
413   points->Delete();
414   iren->Delete();
415 
416   return EXIT_SUCCESS;
417 }
418