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