VTK
WidgetTestingMacros.h
Go to the documentation of this file.
1 #ifndef vtkWidgetTestingMacros_h
2 #define vtkWidgetTestingMacros_h
3 
4 #include <vtkAbstractTransform.h>
5 #include <vtkActor.h>
6 #include <vtkAssemblyPath.h>
7 #include "vtkCamera.h"
8 #include "vtkDebugLeaks.h"
9 #include <vtkFollower.h>
10 #include <vtkInformation.h>
11 #include <vtkLineWidget2.h>
12 #include "vtkMath.h"
13 #include <vtkMatrix4x4.h>
15 #include <vtkPointPlacer.h>
16 #include <vtkPolyData.h>
17 #include <vtkPropCollection.h>
18 #include <vtkProperty2D.h>
19 #include <vtkProperty.h>
20 #include <vtkProp.h>
21 #include "vtkRenderWindow.h"
23 #include "vtkRenderer.h"
24 #include "vtkSmartPointer.h"
25 
27 #define EXERCISE_BASIC_OBJECT_METHODS( object ) \
28  { \
29  if ( object == nullptr ) \
30  { \
31  std::cerr << "EXERCISE_BASIC_OBJECT_METHODS( with nullptr object )" << std::endl; \
32  return EXIT_FAILURE; \
33  } \
34  object->Print( std::cout ); \
35  std::cout << "Name of Class = " << object->GetClassName() << std::endl; \
36  std::cout << "Name of Superclass = " << object->Superclass::GetClassName() << std::endl; \
37 }
38 
40 #define TEST_SET_GET_BOOLEAN( object, variable ) \
41  object->Set##variable( false ); \
42  object->Set##variable( true ); \
43  if( object->Get##variable() != 1 ) \
44  { \
45  std::cerr << "Error in Set/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 1" << std::endl; \
46  return EXIT_FAILURE; \
47  } \
48  object->Set##variable( false ); \
49  if( object->Get##variable() != 0 ) \
50  { \
51  std::cerr << "Error in Set/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 0" << std::endl; \
52  return EXIT_FAILURE; \
53  } \
54  object->variable##On(); \
55  if( object->Get##variable() != 1 ) \
56  { \
57  std::cerr << "Error in On/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 1" << std::endl; \
58  return EXIT_FAILURE; \
59  } \
60  object->variable##Off(); \
61  if( object->Get##variable() != 0 ) \
62  { \
63  std::cerr << "Error in Off/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 0" << std::endl; \
64  return EXIT_FAILURE; \
65  }
66 
69 #define TEST_SET_GET_INT( object, variable, value ) \
70  { \
71  object->Set##variable( value ); \
72  if( object->Get##variable() != value ) \
73  { \
74  std::cerr << "Error in Set/Get"#variable << " using value " << value << std::endl; \
75  return EXIT_FAILURE; \
76  } \
77  }
78 
83 #define TEST_SET_GET_INT_RANGE( object, variable, min, max ) \
84  { \
85  int epsilon = 1; \
86  int val = min - epsilon; \
87  TEST_SET_GET_INT( object, variable, val); \
88  val = min; \
89  TEST_SET_GET_INT( object, variable, val); \
90  val = min + epsilon; \
91  TEST_SET_GET_INT( object, variable, val); \
92  val = (min + max) / 2; \
93  TEST_SET_GET_INT( object, variable, val); \
94  val = max - epsilon; \
95  TEST_SET_GET_INT( object, variable, val); \
96  val = max; \
97  TEST_SET_GET_INT( object, variable, val); \
98  val = max + epsilon; \
99  TEST_SET_GET_INT( object, variable, val); \
100  }
101 
104 #define TEST_SET_GET_DOUBLE( object, variable, value ) \
105  { \
106  object->Set##variable( value ); \
107  if( object->Get##variable() != value ) \
108  { \
109  std::cerr << "Error in Set/Get"#variable << " using value '" << value << "', got '" << object->Get##variable() << "'" << std::endl; \
110  return EXIT_FAILURE; \
111  } \
112  }
113 
118 #define TEST_SET_GET_DOUBLE_RANGE( object, variable, min, max ) \
119  { \
120  double epsilon = 1.0; \
121  double val = min - epsilon; \
122  TEST_SET_GET_DOUBLE( object, variable, val); \
123  val = min; \
124  TEST_SET_GET_DOUBLE( object, variable, val); \
125  val = min + epsilon; \
126  TEST_SET_GET_DOUBLE( object, variable, val); \
127  val = (min + max) / 2.0; \
128  TEST_SET_GET_DOUBLE( object, variable, val); \
129  val = max - epsilon; \
130  TEST_SET_GET_DOUBLE( object, variable, val); \
131  val = max; \
132  TEST_SET_GET_DOUBLE( object, variable, val); \
133  val = max + epsilon; \
134  TEST_SET_GET_DOUBLE( object, variable, val); \
135  }
136 
139 #define TEST_SET_GET_VECTOR3_DOUBLE( object, variable, x, y, z ) \
140  { \
141  object->Set##variable( x, y, z ); \
142  double *val = object->Get##variable(); \
143  if( val == nullptr || val[0] != x || val[1] != y || val[2] != z ) \
144  { \
145  std::cerr << "Error in Set/Get"#variable << std::endl; \
146  return EXIT_FAILURE; \
147  } \
148  }
149 
150 
153 #define TEST_SET_GET_VECTOR2( object, variable, x, y ) \
154  { \
155  object->Set##variable( x, y ); \
156  int *val = object->Get##variable(); \
157  if( val == nullptr || val[0] != x || val[1] != y ) \
158  { \
159  std::cerr << "Error in Set/Get"#variable << std::endl; \
160  return EXIT_FAILURE; \
161  } \
162  }
163 
169 #define TEST_SET_GET_VECTOR2_INT_RANGE( object, variable, min, max ) \
170  { \
171  int epsilon = 1; \
172  TEST_SET_GET_VECTOR2(object, variable, min - epsilon, min - epsilon); \
173  TEST_SET_GET_VECTOR2(object, variable, min, min); \
174  TEST_SET_GET_VECTOR2(object, variable, min + epsilon, min + epsilon); \
175  int half = (min+max/2); \
176  TEST_SET_GET_VECTOR2(object, variable, half, half); \
177  TEST_SET_GET_VECTOR2(object, variable, max - epsilon, max - epsilon); \
178  TEST_SET_GET_VECTOR2(object, variable, max, max); \
179  TEST_SET_GET_VECTOR2(object, variable, max + epsilon, max + epsilon); \
180  }
181 
187 #define TEST_SET_GET_VECTOR2_DOUBLE_RANGE( object, variable, min, max ) \
188  { \
189  double epsilon = 1.0; \
190  TEST_SET_GET_VECTOR2(object, variable, min - epsilon, min - epsilon); \
191  TEST_SET_GET_VECTOR2(object, variable, min, min); \
192  TEST_SET_GET_VECTOR2(object, variable, min + epsilon, min + epsilon); \
193  double half = (min+max/2.0); \
194  TEST_SET_GET_VECTOR2(object, variable, half, half); \
195  TEST_SET_GET_VECTOR2(object, variable, max - epsilon, max - epsilon); \
196  TEST_SET_GET_VECTOR2(object, variable, max, max); \
197  TEST_SET_GET_VECTOR2(object, variable, max + epsilon, max + epsilon); \
198  }
199 
205 #define TEST_SET_GET_VECTOR3_DOUBLE_RANGE( object, variable, min, max ) \
206  { \
207  double epsilon = 1.0; \
208  TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min - epsilon, min - epsilon, min - epsilon); \
209  TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min, min, min); \
210  TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min + epsilon, min + epsilon, min + epsilon); \
211  double half = (min+max/2.0); \
212  TEST_SET_GET_VECTOR3_DOUBLE(object, variable, half, half, half); \
213  TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max - epsilon, max - epsilon, max - epsilon); \
214  TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max, max, max); \
215  TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max + epsilon, max + epsilon, max + epsilon); \
216  }
217 
219 #define TEST_SET_GET_STRING( object, variable ) \
220  { \
221  const char * originalStringPointer = object->Get##variable(); \
222  std::string originalString; \
223  if( originalStringPointer != nullptr ) \
224  { \
225  originalString = originalStringPointer; \
226  } \
227  object->Set##variable( "testing with a const char"); \
228  if( strcmp(object->Get##variable(), "testing with a const char") != 0) \
229  { \
230  std::cerr << "Error in Set/Get"#variable << " with a string literal" << std::endl; \
231  return EXIT_FAILURE; \
232  } \
233  std::string string1 = "testingIsGood"; \
234  object->Set##variable( string1.c_str() ); \
235  if( object->Get##variable() != string1 ) \
236  { \
237  std::cerr << "Error in Set/Get"#variable << std::endl; \
238  return EXIT_FAILURE; \
239  } \
240  std::string string2 = "moreTestingIsBetter"; \
241  object->Set##variable( string2.c_str() ); \
242  if( object->Get##variable() != string2 ) \
243  { \
244  std::cerr << "Error in Set/Get"#variable << std::endl; \
245  return EXIT_FAILURE; \
246  } \
247  if( originalStringPointer != nullptr ) \
248  { \
249  object->Set##variable( originalString.c_str() ); \
250  } \
251  else \
252  { \
253  object->Set##variable( nullptr ); \
254  } \
255  }
256 
258 #define TEST_SET_GET_CHAR( object, variable ) \
259  { \
260  const char originalChar = object->Get##variable(); \
261  object->Set##variable( 't'); \
262  if( object->Get##variable() != 't') \
263  { \
264  std::cerr << "Error in Set/Get"#variable << " with a literal 't'" << std::endl; \
265  return EXIT_FAILURE; \
266  } \
267  object->Set##variable( '3'); \
268  if( object->Get##variable() != '3') \
269  { \
270  std::cerr << "Error in Set/Get"#variable << " with a literal '3'" << std::endl; \
271  return EXIT_FAILURE; \
272  } \
273  object->Set##variable( originalChar ); \
274  }
275 
277 #define EXERCISE_BASIC_INTERACTOR_OBSERVER_METHODS(object) \
278  { \
279  EXERCISE_BASIC_OBJECT_METHODS(object); \
280  vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer< vtkRenderer >::New(); \
281  vtkSmartPointer< vtkCamera > cam1 = vtkSmartPointer< vtkCamera >::New(); \
282  ren1->SetActiveCamera(cam1); \
283  vtkSmartPointer< vtkRenderWindow > renWin = vtkSmartPointer< vtkRenderWindow >::New(); \
284  renWin->SetMultiSamples(0); \
285  renWin->AddRenderer(ren1); \
286  if (object->GetInteractor() != nullptr) \
287  { \
288  std::cout << "Object has an interactor already defined." << std::endl; \
289  } \
290  vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New(); \
291  iren->SetRenderWindow(renWin); \
292  object->SetInteractor(iren); \
293  if (object->GetInteractor() != iren) \
294  { \
295  std::cerr << "Error in Set/GetInteractor" << std::endl; \
296  return EXIT_FAILURE; \
297  } \
298  if (object->GetDefaultRenderer() != nullptr) \
299  { \
300  std::cout << "Object has default renderer already defined." << std::endl; \
301  } \
302  \
303  vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New(); \
304  renWin->AddRenderer(ren); \
305  object->SetDefaultRenderer(ren); \
306  if (object->GetDefaultRenderer() != ren) \
307  { \
308  std::cerr << "Error in Set/GetDefaultRenderer, default renderer is " << (object->GetDefaultRenderer() == nullptr ? "nullptr" : "not null") << std::endl; \
309  return EXIT_FAILURE; \
310  } \
311  object->SetCurrentRenderer(ren); \
312  if (object->GetCurrentRenderer() != ren) \
313  { \
314  std::cerr << "Get current renderer failed." << std::endl; \
315  } \
316  \
317  iren->Initialize(); \
318  renWin->Render(); \
319  if (0) \
320  { \
321  object->CreateDefaultRepresentation(); \
322  TEST_SET_GET_BOOLEAN( object, Enabled); \
323  object->On(); \
324  if (!object->GetEnabled()) \
325  { \
326  std::cerr << "Error in On" << std::endl; \
327  return EXIT_FAILURE; \
328  } \
329  object->Off(); \
330  if (object->GetEnabled()) \
331  { \
332  std::cerr << "Error in Off" << std::endl; \
333  return EXIT_FAILURE; \
334  } \
335  } \
336  TEST_SET_GET_DOUBLE( object, Priority, 0.0); \
337  float min = object->GetPriorityMinValue(); \
338  float max = object->GetPriorityMaxValue(); \
339  std::cout << "Priority min = " << min << ", max = " << max << std::endl; \
340  TEST_SET_GET_DOUBLE( object, Priority, 0.1f); \
341  TEST_SET_GET_DOUBLE( object, Priority, 0.5f); \
342  TEST_SET_GET_DOUBLE( object, Priority, 0.9f); \
343  TEST_SET_GET_DOUBLE( object, Priority, 1.0f); \
344  \
345  TEST_SET_GET_BOOLEAN( object, KeyPressActivation); \
346  TEST_SET_GET_CHAR( object, KeyPressActivationValue); \
347  \
348  object->OnChar(); \
349  if (0) \
350  { \
351  double worldPt[4]; \
352  double x = 1.0, y = 1.0, z = 1.0; \
353  object->ComputeDisplayToWorld(ren, x, y, z, worldPt); \
354  std::cout << "Display " << x << "," << y << "," << z << " to world = " << worldPt[0] << "," << worldPt[1] << "," << worldPt[2] << "," << worldPt[3] << std::endl; \
355  double displayPt[3]; \
356  object->ComputeWorldToDisplay(ren, x, y, z, displayPt); \
357  std::cout << "World " << x << "," << y << "," << z << " to display = " << displayPt[0] << "," << displayPt[1] << "," << displayPt[2] << std::endl; \
358  } \
359  \
360  object->GrabFocus(nullptr, nullptr); \
361  object->ReleaseFocus(); \
362  }
363 
365 #define EXERCISE_BASIC_ABSTRACT_METHODS(object) \
366  { \
367  EXERCISE_BASIC_INTERACTOR_OBSERVER_METHODS(object); \
368  TEST_SET_GET_BOOLEAN( object, ProcessEvents); \
369  if (object->GetEventTranslator() == nullptr) \
370  { \
371  std::cerr << "Error getting event translator, is null." << std::endl; \
372  return EXIT_FAILURE; \
373  } \
374  object->CreateDefaultRepresentation(); \
375  object->Render(); \
376  if (object->GetParent() != nullptr) \
377  { \
378  std::cerr << "Error, parent is not null." << std::endl; \
379  return EXIT_FAILURE; \
380  } \
381  }
382 
384 #define EXERCISE_BASIC_BORDER_METHODS(object) \
385  { \
386  EXERCISE_BASIC_ABSTRACT_METHODS(object); \
387  TEST_SET_GET_BOOLEAN( object, Selectable); \
388  TEST_SET_GET_BOOLEAN( object, Resizable); \
389  }
390 
392 #define EXERCISE_BASIC_HOVER_METHODS(object) \
393  { \
394  EXERCISE_BASIC_ABSTRACT_METHODS (object); \
395  TEST_SET_GET_INT( object, TimerDuration, 1); \
396  TEST_SET_GET_INT( object, TimerDuration, 2); \
397  TEST_SET_GET_INT( object, TimerDuration, 50000); \
398  TEST_SET_GET_INT( object, TimerDuration, 99999); \
399  TEST_SET_GET_INT( object, TimerDuration, 100000); \
400  }
401 
403 #define EXERCISE_BASIC_PROP_METHODS(className, object) \
404  { \
405  EXERCISE_BASIC_OBJECT_METHODS(object); \
406  vtkSmartPointer<vtkPropCollection> propCollection = vtkSmartPointer<vtkPropCollection>::New(); \
407  object->GetActors(propCollection); \
408  object->GetActors2D(propCollection); \
409  object->GetVolumes(propCollection); \
410  \
411  TEST_SET_GET_BOOLEAN( object, Visibility); \
412  TEST_SET_GET_BOOLEAN( object, Pickable); \
413  TEST_SET_GET_BOOLEAN( object, Dragable); \
414  TEST_SET_GET_BOOLEAN( object, UseBounds); \
415  object->UseBoundsOff(); \
416  \
417  object->Pick(); \
418  \
419  vtkMTimeType redrawMTime = object->GetRedrawMTime(); \
420  std::cout << "Redraw Modified Time = " << redrawMTime << std::endl; \
421  \
422  vtkSmartPointer< className > copyProp = vtkSmartPointer< className >::New(); \
423  object->ShallowCopy(copyProp); \
424  \
425  object->InitPathTraversal(); \
426  \
427  vtkSmartPointer<vtkAssemblyPath> assemblyPath = vtkSmartPointer<vtkAssemblyPath>::New(); \
428  assemblyPath = object->GetNextPath(); \
429  std::cout << "Number of paths = " << object->GetNumberOfPaths() << std::endl; \
430  \
431  vtkSmartPointer<vtkMatrix4x4> mat = vtkSmartPointer<vtkMatrix4x4>::New(); \
432  object->PokeMatrix(mat); \
433  mat = object->GetMatrix(); \
434  if (mat == nullptr) \
435  { \
436  std::cout << "No matrix." << std::endl; \
437  } \
438  \
439  vtkSmartPointer<vtkInformation> info = vtkSmartPointer<vtkInformation>::New(); \
440  info = object->GetPropertyKeys(); \
441  if (info != nullptr) \
442  { \
443  info->Print(std::cout); \
444  } \
445  else \
446  { \
447  std::cout << "No property keys" << std::endl; \
448  } \
449  object->SetPropertyKeys(info); \
450  std::cout << "Has null required keys? " << object->HasKeys(nullptr) << std::endl; \
451  \
452  std::cout << "Skipping the internal render calls, requires vtkViewPort. Testing get macros." << std::endl; \
453  std::cout << "HasTranslucentPolygonalGeometry = " << object->HasTranslucentPolygonalGeometry() << std::endl; \
454  std::cout << "AllocatedRenderTime = " << object->GetAllocatedRenderTime() << std::endl; \
455  std::cout << "RenderTimeMultiplier = " << object->GetRenderTimeMultiplier() << std::endl; \
456  std::cout << "SupportsSelection = " << object->GetSupportsSelection() << std::endl; \
457  std::cout << "NumberOfConsumers = " << object->GetNumberOfConsumers() << std::endl; \
458  \
459  }
460 
461 #define NOT_DEFINED_CONSUMERS_FAIL() \
462  { \
463  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); \
464  object->AddConsumer(actor); \
465  if (object->IsConsumer(actor) != 1) \
466  { \
467  std::cerr << "Failed IsConsumer check for a valid consumer." << std::endl;\
468  return EXIT_FAILURE; \
469  } \
470  if (object->IsConsumer(nullptr) != 0) \
471  { \
472  std::cerr << "Failed IsConsumer check for a null consumer." << std::endl; \
473  return EXIT_FAILURE; \
474  } \
475  vtkSmartPointer<vtkActor> actor2 = object->GetConsumer(0); \
476  if (actor2 != actor) \
477  { \
478  std::cerr << "Failed get consumer check for a valid consumer." << std::endl; \
479  return EXIT_FAILURE; \
480  } \
481  object->RemoveConsumer(actor); \
482  actor2 = object->GetConsumer(0); \
483  if (actor2 != nullptr) \
484  { \
485  std::cerr << "Failed get consumer check for an invalid consumer number 0." << std::endl; \
486  return EXIT_FAILURE; \
487  } \
488  }
489 
491 #define EXERCISE_BASIC_REPRESENTATION_METHODS(className, object) \
492  std::cout << "Creating a renderer and a default widget..." << std::endl; \
493  vtkSmartPointer< vtkCamera > cam1 = vtkSmartPointer< vtkCamera >::New(); \
494  vtkSmartPointer< vtkRenderer > ren1 = vtkSmartPointer< vtkRenderer >::New(); \
495  ren1->SetActiveCamera(cam1); \
496  vtkSmartPointer< vtkRenderWindow > renWin = vtkSmartPointer< vtkRenderWindow >::New(); \
497  renWin->SetMultiSamples(0); \
498  renWin->AddRenderer(ren1); \
499  vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New(); \
500  iren->SetRenderWindow(renWin); \
501  \
502  \
503  object->SetRenderer(ren1); \
504  vtkSmartPointer<vtkRenderer> ren2 = object->GetRenderer(); \
505  if (ren2 != ren1) \
506  { \
507  std::cerr << "Failure in GetRenderer." << std::endl; \
508  return EXIT_FAILURE; \
509  } \
510  \
511  object->BuildRepresentation(); \
512  \
513  double bounds[6] = {-1.0, 0.0, -10.0, 10.0, -5.0, 2.0}; \
514  object->PlaceWidget(bounds); \
515  const double *bounds2 = object->GetBounds(); \
516  if (bounds2 == nullptr) \
517  { \
518  std::cout << "GetBounds is null." << std::endl; \
519  } \
520  else \
521  { \
522  std::cout << "Bounds = " << bounds[0] << "," << bounds[1] << "," << bounds[2] << "," << bounds[3] << "," << bounds[4] << "," << bounds[5] << std::endl; \
523  } \
524  \
525  double eventPos[2] = {10.0, 10.0}; \
526  object->StartWidgetInteraction(eventPos); \
527  object->WidgetInteraction(eventPos); \
528  object->EndWidgetInteraction(eventPos); \
529  std::cout << "InteractionState computed to be = " << object->ComputeInteractionState(10, 10, 0) << std::endl; \
530  std::cout << "GetInteractionState = " << object->GetInteractionState() << std::endl; \
531  object->Highlight(0); \
532  object->Highlight(1); \
533  \
534  TEST_SET_GET_DOUBLE_RANGE(object, PlaceFactor, 1.01, 1000.0); \
535  TEST_SET_GET_DOUBLE_RANGE(object, HandleSize, 1.002, 999.0); \
536  TEST_SET_GET_BOOLEAN(object, NeedToRender); \
537  \
538  std::cout << "Trying to get back to init state for further testing." << std::endl; \
539  object->SetPlaceFactor(0.5); \
540  object->SetHandleSize(0.05); \
541  std::cout << "Done basic rep methods" << std::endl; \
542  EXERCISE_BASIC_PROP_METHODS(className, object);
543 
545 #define EXERCISE_BASIC_ANGLE_REPRESENTATION_METHODS(className, object) \
546  { \
547  vtkSmartPointer<vtkPointHandleRepresentation2D> phandle0 = vtkSmartPointer<vtkPointHandleRepresentation2D>::New(); \
548  object->SetHandleRepresentation(phandle0); \
549  object->InstantiateHandleRepresentation(); \
550  \
551  std::cout << "GetAngle = " << object->GetAngle() << std::endl; \
552  \
553  double pos[3]; \
554  object->GetPoint1WorldPosition(pos); \
555  std::cout << "GetPoint1WorldPosition = " << pos[0] << ", " << pos[1] << ", " << pos[2] << std::endl; \
556  object->GetCenterWorldPosition(pos); \
557  std::cout << "GetCenterWorldPosition = " << pos[0] << ", " << pos[1] << ", " << pos[2] << std::endl; \
558  object->GetPoint2WorldPosition(pos); \
559  std::cout << "GetPoint2WorldPosition = " << pos[0] << ", " << pos[1] << ", " << pos[2] << std::endl; \
560  \
561  double pos2[3]; \
562  pos2[0] = -99.0; \
563  pos2[1] = 99.0; \
564  pos2[2] = 55.0; \
565  object->SetCenterDisplayPosition(pos2); \
566  object->GetCenterDisplayPosition(pos); \
567  if (pos[0] != pos2[0] || \
568  pos[0] != pos2[0] || \
569  pos[0] != pos2[0]) \
570  { \
571  std::cerr << "Failed to SetCenterDisplayPosition to " << pos2[0] << ", " << pos2[1] << ", " << pos2[2] << ", instead got " << pos[0] << ", " << pos[1] << ", " << pos[2] << std::endl; \
572  return EXIT_FAILURE; \
573  } \
574  \
575  pos[0] = -100.0; \
576  object->SetPoint1DisplayPosition(pos2); \
577  object->GetPoint1DisplayPosition(pos); \
578  if (pos[0] != pos2[0] || \
579  pos[0] != pos2[0] || \
580  pos[0] != pos2[0]) \
581  { \
582  std::cerr << "Failed to SetPoint1DisplayPosition to " << pos2[0] << ", " << pos2[1] << ", " << pos2[2] << ", instead got " << pos[0] << ", " << pos[1] << ", " << pos[2] << std::endl; \
583  return EXIT_FAILURE; \
584  } \
585  \
586  pos[0] = 101.0; \
587  object->SetPoint2DisplayPosition(pos2); \
588  object->GetPoint2DisplayPosition(pos); \
589  if (pos[0] != pos2[0] || \
590  pos[0] != pos2[0] || \
591  pos[0] != pos2[0]) \
592  { \
593  std::cerr << "Failed to SetPoint2DisplayPosition to " << pos2[0] << ", " << pos2[1] << ", " << pos2[2] << ", instead got " << pos[0] << ", " << pos[1] << ", " << pos[2] << std::endl; \
594  return EXIT_FAILURE; \
595  } \
596  \
597  vtkSmartPointer<vtkPointHandleRepresentation2D> phandle = vtkSmartPointer<vtkPointHandleRepresentation2D>::New(); \
598  object->SetHandleRepresentation(phandle); \
599  object->InstantiateHandleRepresentation(); \
600  \
601  vtkSmartPointer<vtkHandleRepresentation> handleRep = nullptr; \
602  handleRep = object->GetPoint1Representation(); \
603  handleRep = object->GetPoint2Representation(); \
604  handleRep = object->GetCenterRepresentation(); \
605  \
606  TEST_SET_GET_INT_RANGE(object, Tolerance, 2, 99); \
607  TEST_SET_GET_STRING( object, LabelFormat); \
608  TEST_SET_GET_BOOLEAN( object, Ray1Visibility); \
609  TEST_SET_GET_BOOLEAN( object, Ray2Visibility); \
610  TEST_SET_GET_BOOLEAN( object, ArcVisibility); \
611  \
612  double e[2] = {5.0, 1.0}; \
613  object->CenterWidgetInteraction(e); \
614  EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
615  }
616 
618 #define EXERCISE_BASIC_BORDER_REPRESENTATION_METHODS(className, object) \
619  { \
620  EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
621  \
622  double pos[2] = {10.0, 11.0}; \
623  double *pos2 = nullptr; \
624  object->SetPosition(pos); \
625  pos2 = object->GetPosition(); \
626  if (pos2 == nullptr) \
627  { \
628  std::cerr << "Failure in Get/Set Position pos, got null position back." << std::endl; \
629  return EXIT_FAILURE; \
630  } \
631  else if (pos2[0] != pos[0] || \
632  pos2[1] != pos[1]) \
633  { \
634  std::cerr << "Failure in Get/Set Position pos, expected " << pos[0] << ", " << pos[1] << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
635  return EXIT_FAILURE; \
636  } \
637  else \
638  { \
639  std::cout << "Set Position to " << pos2[0] << ", " << pos2[1] << std::endl; \
640  }\
641  \
642  pos[0] = 12.0; \
643  object->SetPosition(pos[0], pos[1]); \
644  pos2 = object->GetPosition(); \
645  if (pos2 == nullptr || \
646  pos2[0] != pos[0] || \
647  pos2[1] != pos[1]) \
648  { \
649  std::cerr << "Failure in Get/Set Position x,y, expected " << pos[0] << ", " << pos[1] << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
650  return EXIT_FAILURE; \
651  } \
652  vtkSmartPointer<vtkCoordinate> coord = object->GetPositionCoordinate(); \
653  pos2 = coord->GetValue(); \
654  if (pos2 == nullptr || \
655  pos2[0] != pos[0] || \
656  pos2[1] != pos[1]) \
657  { \
658  std::cerr << "Failure in Get/ Coordinate, expected " << pos[0] << ", " << pos[1] << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
659  return EXIT_FAILURE; \
660  } \
661  \
662  pos[0] = 44.0; \
663  object->SetPosition2(pos); \
664  pos2 = object->GetPosition2(); \
665  if (pos2 == nullptr || \
666  pos2[0] != pos[0] || \
667  pos2[1] != pos[1]) \
668  { \
669  std::cerr << "Failure in Get/Set Position2 pos, expected " << pos[0] << ", " << pos[1] << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
670  return EXIT_FAILURE; \
671  } \
672  pos[0] = 12.0; \
673  object->SetPosition2(pos[0], pos[1]); \
674  pos2 = object->GetPosition2(); \
675  if (pos2 == nullptr || \
676  pos2[0] != pos[0] || \
677  pos2[1] != pos[1]) \
678  { \
679  std::cerr << "Failure in Get/Set Position2 x,y, expected " << pos[0] << ", " << pos[1] << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
680  return EXIT_FAILURE; \
681  } \
682  coord = object->GetPosition2Coordinate(); \
683  pos2 = coord->GetValue(); \
684  if (pos2 == nullptr || \
685  pos2[0] != pos[0] || \
686  pos2[1] != pos[1]) \
687  { \
688  std::cerr << "Failure in Get/ Coordinate 2, expected " << pos[0] << ", " << pos[1] << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
689  return EXIT_FAILURE; \
690  } \
691  \
692  TEST_SET_GET_INT(object, ShowBorder, 0); \
693  TEST_SET_GET_INT(object, ShowBorder, 1); \
694  TEST_SET_GET_INT(object, ShowBorder, 2); \
695  object->SetShowBorderToOff(); \
696  object->SetShowBorderToOn(); \
697  object->SetShowBorderToActive(); \
698  \
699  vtkSmartPointer<vtkProperty2D> borderProperty = object->GetBorderProperty(); \
700  \
701  TEST_SET_GET_BOOLEAN( object, ProportionalResize); \
702  \
703  TEST_SET_GET_VECTOR2_INT_RANGE(object, MinimumSize, 0, 100); \
704  TEST_SET_GET_VECTOR2_INT_RANGE(object, MaximumSize, 0, 100); \
705  TEST_SET_GET_INT_RANGE(object, Tolerance, 2, 9); \
706  \
707  double *selPoint = object->GetSelectionPoint(); \
708  if (selPoint) \
709  { \
710  std::cout << "Selection Point = " << selPoint[0] << ", " << selPoint[1] << std::endl; \
711  } \
712  \
713  TEST_SET_GET_BOOLEAN( object,Moving); \
714  \
715  double size[2]; \
716  object->GetSize(size); \
717  std::cout << "Size = " << size[0] << ", " << size[1] << std::endl; \
718  \
719  int interactionState = object->ComputeInteractionState(10, 10); \
720  std::cout << "Interaction state = " << interactionState << std::endl; \
721  }
722 
724 #define EXERCISE_BASIC_IMPLICIT_PLANE_REPRESENTATION_METHODS(className, object) \
725  { \
726  EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
727  \
728  TEST_SET_GET_VECTOR3_DOUBLE_RANGE(node1, Origin, -100, 100); \
729  TEST_SET_GET_VECTOR3_DOUBLE_RANGE(node1, Normal, -1, 1); \
730  TEST_SET_GET_BOOLEAN( node1, NormalToXAxis); \
731  TEST_SET_GET_BOOLEAN( node1, NormalToYAxis); \
732  TEST_SET_GET_BOOLEAN( node1, NormalToZAxis); \
733  TEST_SET_GET_BOOLEAN( node1, Tubing); \
734  TEST_SET_GET_BOOLEAN( node1, DrawPlane); \
735  TEST_SET_GET_BOOLEAN( node1, OutlineTranslation); \
736  TEST_SET_GET_BOOLEAN( node1, OutsideBounds); \
737  TEST_SET_GET_BOOLEAN( node1, ScaleEnabled); \
738  }
739 
740 
742 #define TEST_SET_GET_PROPERTY(object, variable)\
743  { \
744  vtkSmartPointer<vtkProperty> prop1 = vtkSmartPointer<vtkProperty>::New(); \
745  double colour[3] = {0.2, 0.3, 0.4}; \
746  prop1->SetColor(colour); \
747  node1->Set##variable(prop1); \
748  vtkSmartPointer<vtkProperty> prop = node1->Get##variable(); \
749  if (!prop) \
750  { \
751  std::cerr << "Got null variable property back after setting it!" << std::endl; \
752  return EXIT_FAILURE; \
753  } \
754  double *col = prop->GetColor(); \
755  if (!col) \
756  { \
757  std::cerr << "Got null colour back!" << std::endl; \
758  return EXIT_FAILURE; \
759  } \
760  if (col[0] != colour[0] || \
761  col[1] != colour[1] || \
762  col[2] != colour[2]) \
763  { \
764  std::cerr << "Got wrong colour back after setting it! Expected " << colour[0] << ", " << colour[1] << ", " << colour[2] << ", but got " << col[0] << ", " << col[1] << ", " << col[2] << std::endl; \
765  return EXIT_FAILURE; \
766  } \
767  \
768  \
769  } \
770 
771 #define EXERCISE_BASIC_HANDLE_REPRESENTATION_METHODS(className, object) \
775  { \
776  EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
777  \
778  double dpos[3], wpos[3]; \
779  wpos[0] = 0.1; \
780  wpos[1] = -1.0; \
781  wpos[2] = 3.6; \
782  dpos[0] = 25; \
783  dpos[1] = 50; \
784  dpos[2] = 0.0; \
785  double pos2[3]; \
786  double *pos3; \
787  \
788  std::cout << "Testing SetWorldPosition" << std::endl; \
789  \
790  object->SetWorldPosition(wpos); \
791  std::cout << "Testing GetWorldPosition" << std::endl; \
792  object->GetWorldPosition(pos2); \
793  if (pos2[0] != wpos[0] || \
794  pos2[1] != wpos[1] || \
795  pos2[2] != wpos[2]) \
796  { \
797  std::cerr << "Failure in Get WorldPosition pos2, expected " << wpos[0] << ", " << wpos[1] << ", " << wpos[2] << ", instead got " << pos2[0] << ", " << pos2[1] << ", " << pos2[2] << std::endl; \
798  return EXIT_FAILURE; \
799  } \
800  pos3 = object->GetWorldPosition(); \
801  if (!pos3) \
802  { \
803  std::cerr << "Failure in double * GetWorldPosition , expected " << wpos[0] << ", " << wpos[1] << ", " << wpos[2] << ", instead got a null pointer." << std::endl; \
804  return EXIT_FAILURE; \
805  } \
806  if (pos3[0] != wpos[0] || \
807  pos3[1] != wpos[1] || \
808  pos3[2] != wpos[2]) \
809  { \
810  std::cerr << "Failure in double * GetWorldyPosition , expected " << wpos[0] << ", " << wpos[1] << ", " << wpos[2] << ", instead got " << pos3[0] << ", " << pos3[1] << ", " << pos3[2] << std::endl; \
811  return EXIT_FAILURE; \
812  } \
813  std::cout << "Done testing world position." << std::endl; \
814  \
815  std::cout << "Testing Set/Get Display Position" << std::endl; \
816  \
817  \
818  object->GetDisplayPosition(pos2); \
819  std::cout << "After GetDisplayPosition." << std::endl; \
820  object->SetDisplayPosition(dpos); \
821  std::cout << "After SetDisplayPosition" << std::endl; \
822  object->GetDisplayPosition(pos2); \
823  std::cout << "After GetDisplayPosition second time." << std::endl; \
824  if (pos2[0] != 0 || \
825  pos2[1] != 0 ) \
826  { \
827  std::cerr << "Failure in GetDisplayPosition pos2, expected (0,0) instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
828  return EXIT_FAILURE; \
829  } \
830  pos3 = object->GetDisplayPosition(); \
831  if (!pos3) \
832  { \
833  std::cerr << "Failure in double * GetDisplayPosition, expected (0,0) instead got a null pointer." << std::endl; \
834  return EXIT_FAILURE; \
835  } \
836  if (pos3[0] != 0 || \
837  pos3[1] != 0) \
838  { \
839  std::cerr << "Failure in double * GetDisplayPosition , expected (0,0) instead got " << pos3[0] << ", " << pos3[1] << std::endl; \
840  return EXIT_FAILURE; \
841  } \
842  TEST_SET_GET_INT_RANGE(object, Tolerance, 2, 99); \
843  TEST_SET_GET_BOOLEAN( object, ActiveRepresentation); \
844  TEST_SET_GET_BOOLEAN( object, Constrained); \
845  \
846  vtkSmartPointer<vtkRenderer> ren3 = object->GetRenderer(); \
847  double posToCheck[3] = {0.0, 0.0, 0.0}; \
848  int flag = object->CheckConstraint(ren3, posToCheck); \
849  std::cout << "Check Constraint = " << flag << std::endl; \
850  \
851  std::cout << "MTime = " << object->GetMTime() << std::endl; \
852  \
853  vtkSmartPointer<vtkPointPlacer> pplacer = vtkSmartPointer<vtkPointPlacer>::New(); \
854  object->SetPointPlacer(pplacer); \
855  vtkSmartPointer<vtkPointPlacer> pplacer2 = object->GetPointPlacer(); \
856  if (pplacer2 != pplacer) \
857  { \
858  std::cerr << "Error in Set/Get point placer." << std::endl; \
859  return EXIT_FAILURE; \
860  } \
861  flag = object->CheckConstraint(ren3, posToCheck); \
862  std::cout << "Check Constraint after setting point placer = " << flag << std::endl; \
863  }
864 
866 #define EXERCISE_BASIC_ABSTRACT_POLYGONAL_HANDLE_REPRESENTATION3D_METHODS(className, object) \
867  { \
868  EXERCISE_BASIC_HANDLE_REPRESENTATION_METHODS(className, object); \
869  \
870  vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New(); \
871  object->SetHandle(pd); \
872  vtkSmartPointer<vtkPolyData> pd2 = object->GetHandle(); \
873  if (pd2 == nullptr) \
874  { \
875  std::cerr << "Error getting handle, null pointer." << std::endl; \
876  return EXIT_FAILURE; \
877  } \
878  if (pd2 != pd) \
879  { \
880  std::cerr << "Error getting handle, not the same as set." << std::endl; \
881  return EXIT_FAILURE; \
882  } \
883  TEST_SET_GET_PROPERTY(object, Property); \
884  TEST_SET_GET_PROPERTY(object, SelectedProperty); \
885  \
886  vtkSmartPointer<vtkAbstractTransform> at = object->GetTransform(); \
887  \
888  TEST_SET_GET_BOOLEAN(object, LabelVisibility); \
889  TEST_SET_GET_STRING(object, LabelText); \
890  TEST_SET_GET_VECTOR3_DOUBLE_RANGE(object, LabelTextScale, 0.0, 10.0); \
891  \
892  vtkSmartPointer<vtkFollower> follower = object->GetLabelTextActor(); \
893  if (follower == nullptr) \
894  { \
895  std::cout << "Follower is null." << std::endl; \
896  } \
897  \
898  object->SetUniformScale(-1.0); \
899  object->SetUniformScale(0.0); \
900  object->SetUniformScale(1.0); \
901  object->SetUniformScale(35.44); \
902  \
903  TEST_SET_GET_BOOLEAN(object, HandleVisibility); \
904  }
905 #endif