1#ifndef vtkWidgetTestingMacros_h
2#define vtkWidgetTestingMacros_h
27#define EXERCISE_BASIC_OBJECT_METHODS(object) \
29 if (object == nullptr) \
31 std::cerr << "EXERCISE_BASIC_OBJECT_METHODS( with nullptr object )" << std::endl; \
32 return EXIT_FAILURE; \
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; \
40#define TEST_SET_GET_BOOLEAN(object, variable) \
41 object->Set##variable(false); \
42 object->Set##variable(true); \
43 if (object->Get##variable() != 1) \
45 std::cerr << "Error in Set/Get" #variable << ", Get" #variable << " is " \
46 << object->Get##variable() << " instead of 1" << std::endl; \
47 return EXIT_FAILURE; \
49 object->Set##variable(false); \
50 if (object->Get##variable() != 0) \
52 std::cerr << "Error in Set/Get" #variable << ", Get" #variable << " is " \
53 << object->Get##variable() << " instead of 0" << std::endl; \
54 return EXIT_FAILURE; \
56 object->variable##On(); \
57 if (object->Get##variable() != 1) \
59 std::cerr << "Error in On/Get" #variable << ", Get" #variable << " is " \
60 << object->Get##variable() << " instead of 1" << std::endl; \
61 return EXIT_FAILURE; \
63 object->variable##Off(); \
64 if (object->Get##variable() != 0) \
66 std::cerr << "Error in Off/Get" #variable << ", Get" #variable << " is " \
67 << object->Get##variable() << " instead of 0" << std::endl; \
68 return EXIT_FAILURE; \
73#define TEST_SET_GET_INT(object, variable, value) \
75 object->Set##variable(value); \
76 if (object->Get##variable() != value) \
78 std::cerr << "Error in Set/Get" #variable << " using value " << value << std::endl; \
79 return EXIT_FAILURE; \
87#define TEST_SET_GET_INT_RANGE(object, variable, min, max) \
90 int val = min - epsilon; \
91 TEST_SET_GET_INT(object, variable, val); \
93 TEST_SET_GET_INT(object, variable, val); \
94 val = min + epsilon; \
95 TEST_SET_GET_INT(object, variable, val); \
96 val = (min + max) / 2; \
97 TEST_SET_GET_INT(object, variable, val); \
98 val = max - epsilon; \
99 TEST_SET_GET_INT(object, variable, val); \
101 TEST_SET_GET_INT(object, variable, val); \
102 val = max + epsilon; \
103 TEST_SET_GET_INT(object, variable, val); \
108#define TEST_SET_GET_DOUBLE(object, variable, value) \
110 object->Set##variable(value); \
111 if (object->Get##variable() != value) \
113 std::cerr << "Error in Set/Get" #variable << " using value '" << value << "', got '" \
114 << object->Get##variable() << "'" << std::endl; \
115 return EXIT_FAILURE; \
123#define TEST_SET_GET_DOUBLE_RANGE(object, variable, min, max) \
125 double epsilon = 1.0; \
126 double val = min - epsilon; \
127 TEST_SET_GET_DOUBLE(object, variable, val); \
129 TEST_SET_GET_DOUBLE(object, variable, val); \
130 val = min + epsilon; \
131 TEST_SET_GET_DOUBLE(object, variable, val); \
132 val = (min + max) / 2.0; \
133 TEST_SET_GET_DOUBLE(object, variable, val); \
134 val = max - epsilon; \
135 TEST_SET_GET_DOUBLE(object, variable, val); \
137 TEST_SET_GET_DOUBLE(object, variable, val); \
138 val = max + epsilon; \
139 TEST_SET_GET_DOUBLE(object, variable, val); \
144#define TEST_SET_GET_VECTOR3_DOUBLE(object, variable, x, y, z) \
146 object->Set##variable(x, y, z); \
147 double* val = object->Get##variable(); \
148 if (val == nullptr || val[0] != x || val[1] != y || val[2] != z) \
150 std::cerr << "Error in Set/Get" #variable << std::endl; \
151 return EXIT_FAILURE; \
157#define TEST_SET_GET_VECTOR2(object, variable, x, y) \
159 object->Set##variable(x, y); \
160 int* val = object->Get##variable(); \
161 if (val == nullptr || val[0] != x || val[1] != y) \
163 std::cerr << "Error in Set/Get" #variable << std::endl; \
164 return EXIT_FAILURE; \
173#define TEST_SET_GET_VECTOR2_INT_RANGE(object, variable, min, max) \
176 TEST_SET_GET_VECTOR2(object, variable, min - epsilon, min - epsilon); \
177 TEST_SET_GET_VECTOR2(object, variable, min, min); \
178 TEST_SET_GET_VECTOR2(object, variable, min + epsilon, min + epsilon); \
179 int half = (min + max / 2); \
180 TEST_SET_GET_VECTOR2(object, variable, half, half); \
181 TEST_SET_GET_VECTOR2(object, variable, max - epsilon, max - epsilon); \
182 TEST_SET_GET_VECTOR2(object, variable, max, max); \
183 TEST_SET_GET_VECTOR2(object, variable, max + epsilon, max + epsilon); \
191#define TEST_SET_GET_VECTOR2_DOUBLE_RANGE(object, variable, min, max) \
193 double epsilon = 1.0; \
194 TEST_SET_GET_VECTOR2(object, variable, min - epsilon, min - epsilon); \
195 TEST_SET_GET_VECTOR2(object, variable, min, min); \
196 TEST_SET_GET_VECTOR2(object, variable, min + epsilon, min + epsilon); \
197 double half = (min + max / 2.0); \
198 TEST_SET_GET_VECTOR2(object, variable, half, half); \
199 TEST_SET_GET_VECTOR2(object, variable, max - epsilon, max - epsilon); \
200 TEST_SET_GET_VECTOR2(object, variable, max, max); \
201 TEST_SET_GET_VECTOR2(object, variable, max + epsilon, max + epsilon); \
209#define TEST_SET_GET_VECTOR3_DOUBLE_RANGE(object, variable, min, max) \
211 double epsilon = 1.0; \
212 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min - epsilon, min - epsilon, min - epsilon); \
213 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min, min, min); \
214 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min + epsilon, min + epsilon, min + epsilon); \
215 double half = (min + max / 2.0); \
216 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, half, half, half); \
217 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max - epsilon, max - epsilon, max - epsilon); \
218 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max, max, max); \
219 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max + epsilon, max + epsilon, max + epsilon); \
223#define TEST_SET_GET_STRING(object, variable) \
225 const char* originalStringPointer = object->Get##variable(); \
226 std::string originalString; \
227 if (originalStringPointer != nullptr) \
229 originalString = originalStringPointer; \
231 object->Set##variable("testing with a const char"); \
232 if (strcmp(object->Get##variable(), "testing with a const char") != 0) \
234 std::cerr << "Error in Set/Get" #variable << " with a string literal" << std::endl; \
235 return EXIT_FAILURE; \
237 std::string string1 = "testingIsGood"; \
238 object->Set##variable(string1.c_str()); \
239 if (object->Get##variable() != string1) \
241 std::cerr << "Error in Set/Get" #variable << std::endl; \
242 return EXIT_FAILURE; \
244 std::string string2 = "moreTestingIsBetter"; \
245 object->Set##variable(string2.c_str()); \
246 if (object->Get##variable() != string2) \
248 std::cerr << "Error in Set/Get" #variable << std::endl; \
249 return EXIT_FAILURE; \
251 if (originalStringPointer != nullptr) \
253 object->Set##variable(originalString.c_str()); \
257 object->Set##variable(nullptr); \
262#define TEST_SET_GET_CHAR(object, variable) \
264 const char originalChar = object->Get##variable(); \
265 object->Set##variable('t'); \
266 if (object->Get##variable() != 't') \
268 std::cerr << "Error in Set/Get" #variable << " with a literal 't'" << std::endl; \
269 return EXIT_FAILURE; \
271 object->Set##variable('3'); \
272 if (object->Get##variable() != '3') \
274 std::cerr << "Error in Set/Get" #variable << " with a literal '3'" << std::endl; \
275 return EXIT_FAILURE; \
277 object->Set##variable(originalChar); \
281#define EXERCISE_BASIC_INTERACTOR_OBSERVER_METHODS(object) \
283 EXERCISE_BASIC_OBJECT_METHODS(object); \
284 vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New(); \
285 vtkSmartPointer<vtkCamera> cam1 = vtkSmartPointer<vtkCamera>::New(); \
286 ren1->SetActiveCamera(cam1); \
287 vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New(); \
288 renWin->SetMultiSamples(0); \
289 renWin->AddRenderer(ren1); \
290 if (object->GetInteractor() != nullptr) \
292 std::cout << "Object has an interactor already defined." << std::endl; \
294 vtkSmartPointer<vtkRenderWindowInteractor> iren = \
295 vtkSmartPointer<vtkRenderWindowInteractor>::New(); \
296 iren->SetRenderWindow(renWin); \
297 object->SetInteractor(iren); \
298 if (object->GetInteractor() != iren) \
300 std::cerr << "Error in Set/GetInteractor" << std::endl; \
301 return EXIT_FAILURE; \
303 if (object->GetDefaultRenderer() != nullptr) \
305 std::cout << "Object has default renderer already defined." << std::endl; \
308 vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New(); \
309 renWin->AddRenderer(ren); \
310 object->SetDefaultRenderer(ren); \
311 if (object->GetDefaultRenderer() != ren) \
313 std::cerr << "Error in Set/GetDefaultRenderer, default renderer is " \
314 << (object->GetDefaultRenderer() == nullptr ? "nullptr" : "not null") \
316 return EXIT_FAILURE; \
318 object->SetCurrentRenderer(ren); \
319 if (object->GetCurrentRenderer() != ren) \
321 std::cerr << "Get current renderer failed." << std::endl; \
324 iren->Initialize(); \
328 object->CreateDefaultRepresentation(); \
329 TEST_SET_GET_BOOLEAN(object, Enabled); \
331 if (!object->GetEnabled()) \
333 std::cerr << "Error in On" << std::endl; \
334 return EXIT_FAILURE; \
337 if (object->GetEnabled()) \
339 std::cerr << "Error in Off" << std::endl; \
340 return EXIT_FAILURE; \
343 TEST_SET_GET_DOUBLE(object, Priority, 0.0); \
344 float min = object->GetPriorityMinValue(); \
345 float max = object->GetPriorityMaxValue(); \
346 std::cout << "Priority min = " << min << ", max = " << max << std::endl; \
347 TEST_SET_GET_DOUBLE(object, Priority, 0.1f); \
348 TEST_SET_GET_DOUBLE(object, Priority, 0.5f); \
349 TEST_SET_GET_DOUBLE(object, Priority, 0.9f); \
350 TEST_SET_GET_DOUBLE(object, Priority, 1.0f); \
352 TEST_SET_GET_BOOLEAN(object, KeyPressActivation); \
353 TEST_SET_GET_CHAR(object, KeyPressActivationValue); \
359 double x = 1.0, y = 1.0, z = 1.0; \
360 object->ComputeDisplayToWorld(ren, x, y, z, worldPt); \
361 std::cout << "Display " << x << "," << y << "," << z << " to world = " << worldPt[0] << "," \
362 << worldPt[1] << "," << worldPt[2] << "," << worldPt[3] << std::endl; \
363 double displayPt[3]; \
364 object->ComputeWorldToDisplay(ren, x, y, z, displayPt); \
365 std::cout << "World " << x << "," << y << "," << z << " to display = " << displayPt[0] \
366 << "," << displayPt[1] << "," << displayPt[2] << std::endl; \
369 object->GrabFocus(nullptr, nullptr); \
370 object->ReleaseFocus(); \
374#define EXERCISE_BASIC_ABSTRACT_METHODS(object) \
376 EXERCISE_BASIC_INTERACTOR_OBSERVER_METHODS(object); \
377 TEST_SET_GET_BOOLEAN(object, ProcessEvents); \
378 if (object->GetEventTranslator() == nullptr) \
380 std::cerr << "Error getting event translator, is null." << std::endl; \
381 return EXIT_FAILURE; \
383 object->CreateDefaultRepresentation(); \
385 if (object->GetParent() != nullptr) \
387 std::cerr << "Error, parent is not null." << std::endl; \
388 return EXIT_FAILURE; \
393#define EXERCISE_BASIC_BORDER_METHODS(object) \
395 EXERCISE_BASIC_ABSTRACT_METHODS(object); \
396 TEST_SET_GET_BOOLEAN(object, Selectable); \
397 TEST_SET_GET_BOOLEAN(object, Resizable); \
401#define EXERCISE_BASIC_HOVER_METHODS(object) \
403 EXERCISE_BASIC_ABSTRACT_METHODS(object); \
404 TEST_SET_GET_INT(object, TimerDuration, 1); \
405 TEST_SET_GET_INT(object, TimerDuration, 2); \
406 TEST_SET_GET_INT(object, TimerDuration, 50000); \
407 TEST_SET_GET_INT(object, TimerDuration, 99999); \
408 TEST_SET_GET_INT(object, TimerDuration, 100000); \
412#define EXERCISE_BASIC_PROP_METHODS(className, object) \
414 EXERCISE_BASIC_OBJECT_METHODS(object); \
415 vtkSmartPointer<vtkPropCollection> propCollection = vtkSmartPointer<vtkPropCollection>::New(); \
416 object->GetActors(propCollection); \
417 object->GetActors2D(propCollection); \
418 object->GetVolumes(propCollection); \
420 TEST_SET_GET_BOOLEAN(object, Visibility); \
421 TEST_SET_GET_BOOLEAN(object, Pickable); \
422 TEST_SET_GET_BOOLEAN(object, Dragable); \
423 TEST_SET_GET_BOOLEAN(object, UseBounds); \
424 object->UseBoundsOff(); \
428 vtkMTimeType redrawMTime = object->GetRedrawMTime(); \
429 std::cout << "Redraw Modified Time = " << redrawMTime << std::endl; \
431 vtkSmartPointer<className> copyProp = vtkSmartPointer<className>::New(); \
432 object->ShallowCopy(copyProp); \
434 object->InitPathTraversal(); \
436 vtkSmartPointer<vtkAssemblyPath> assemblyPath = vtkSmartPointer<vtkAssemblyPath>::New(); \
437 assemblyPath = object->GetNextPath(); \
438 std::cout << "Number of paths = " << object->GetNumberOfPaths() << std::endl; \
440 vtkSmartPointer<vtkMatrix4x4> mat = vtkSmartPointer<vtkMatrix4x4>::New(); \
441 object->PokeMatrix(mat); \
442 mat = object->GetMatrix(); \
443 if (mat == nullptr) \
445 std::cout << "No matrix." << std::endl; \
448 vtkSmartPointer<vtkInformation> info = vtkSmartPointer<vtkInformation>::New(); \
449 info = object->GetPropertyKeys(); \
450 if (info != nullptr) \
452 info->Print(std::cout); \
456 std::cout << "No property keys" << std::endl; \
458 object->SetPropertyKeys(info); \
459 std::cout << "Has null required keys? " << object->HasKeys(nullptr) << std::endl; \
461 std::cout << "Skipping the internal render calls, requires vtkViewPort. Testing get macros." \
463 std::cout << "HasTranslucentPolygonalGeometry = " << object->HasTranslucentPolygonalGeometry() \
465 std::cout << "AllocatedRenderTime = " << object->GetAllocatedRenderTime() << std::endl; \
466 std::cout << "RenderTimeMultiplier = " << object->GetRenderTimeMultiplier() << std::endl; \
467 std::cout << "SupportsSelection = " << object->GetSupportsSelection() << std::endl; \
468 std::cout << "NumberOfConsumers = " << object->GetNumberOfConsumers() << std::endl; \
471#define NOT_DEFINED_CONSUMERS_FAIL() \
473 vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); \
474 object->AddConsumer(actor); \
475 if (object->IsConsumer(actor) != 1) \
477 std::cerr << "Failed IsConsumer check for a valid consumer." << std::endl; \
478 return EXIT_FAILURE; \
480 if (object->IsConsumer(nullptr) != 0) \
482 std::cerr << "Failed IsConsumer check for a null consumer." << std::endl; \
483 return EXIT_FAILURE; \
485 vtkSmartPointer<vtkActor> actor2 = object->GetConsumer(0); \
486 if (actor2 != actor) \
488 std::cerr << "Failed get consumer check for a valid consumer." << std::endl; \
489 return EXIT_FAILURE; \
491 object->RemoveConsumer(actor); \
492 actor2 = object->GetConsumer(0); \
493 if (actor2 != nullptr) \
495 std::cerr << "Failed get consumer check for an invalid consumer number 0." << std::endl; \
496 return EXIT_FAILURE; \
501#define EXERCISE_BASIC_REPRESENTATION_METHODS(className, object) \
502 std::cout << "Creating a renderer and a default widget..." << std::endl; \
503 vtkSmartPointer<vtkCamera> cam1 = vtkSmartPointer<vtkCamera>::New(); \
504 vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New(); \
505 ren1->SetActiveCamera(cam1); \
506 vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New(); \
507 renWin->SetMultiSamples(0); \
508 renWin->AddRenderer(ren1); \
509 vtkSmartPointer<vtkRenderWindowInteractor> iren = \
510 vtkSmartPointer<vtkRenderWindowInteractor>::New(); \
511 iren->SetRenderWindow(renWin); \
513 object->SetRenderer(ren1); \
514 vtkSmartPointer<vtkRenderer> ren2 = object->GetRenderer(); \
517 std::cerr << "Failure in GetRenderer." << std::endl; \
518 return EXIT_FAILURE; \
521 object->BuildRepresentation(); \
523 double bounds[6] = { -1.0, 0.0, -10.0, 10.0, -5.0, 2.0 }; \
524 object->PlaceWidget(bounds); \
525 const double* bounds2 = object->GetBounds(); \
526 if (bounds2 == nullptr) \
528 std::cout << "GetBounds is null." << std::endl; \
532 std::cout << "Bounds = " << bounds[0] << "," << bounds[1] << "," << bounds[2] << "," \
533 << bounds[3] << "," << bounds[4] << "," << bounds[5] << std::endl; \
536 double eventPos[2] = { 10.0, 10.0 }; \
537 object->StartWidgetInteraction(eventPos); \
538 object->WidgetInteraction(eventPos); \
539 object->EndWidgetInteraction(eventPos); \
540 std::cout << "InteractionState computed to be = " << object->ComputeInteractionState(10, 10, 0) \
542 std::cout << "GetInteractionState = " << object->GetInteractionState() << std::endl; \
543 object->Highlight(0); \
544 object->Highlight(1); \
546 TEST_SET_GET_DOUBLE_RANGE(object, PlaceFactor, 1.01, 1000.0); \
547 TEST_SET_GET_DOUBLE_RANGE(object, HandleSize, 1.002, 999.0); \
548 TEST_SET_GET_BOOLEAN(object, NeedToRender); \
550 std::cout << "Trying to get back to init state for further testing." << std::endl; \
551 object->SetPlaceFactor(0.5); \
552 object->SetHandleSize(0.05); \
553 std::cout << "Done basic rep methods" << std::endl; \
554 EXERCISE_BASIC_PROP_METHODS(className, object);
557#define EXERCISE_BASIC_ANGLE_REPRESENTATION_METHODS(className, object) \
559 vtkSmartPointer<vtkPointHandleRepresentation2D> phandle0 = \
560 vtkSmartPointer<vtkPointHandleRepresentation2D>::New(); \
561 object->SetHandleRepresentation(phandle0); \
562 object->InstantiateHandleRepresentation(); \
564 std::cout << "GetAngle = " << object->GetAngle() << std::endl; \
567 object->GetPoint1WorldPosition(pos); \
568 std::cout << "GetPoint1WorldPosition = " << pos[0] << ", " << pos[1] << ", " << pos[2] \
570 object->GetCenterWorldPosition(pos); \
571 std::cout << "GetCenterWorldPosition = " << pos[0] << ", " << pos[1] << ", " << pos[2] \
573 object->GetPoint2WorldPosition(pos); \
574 std::cout << "GetPoint2WorldPosition = " << pos[0] << ", " << pos[1] << ", " << pos[2] \
581 object->SetCenterDisplayPosition(pos2); \
582 object->GetCenterDisplayPosition(pos); \
583 if (pos[0] != pos2[0] || pos[0] != pos2[0] || pos[0] != pos2[0]) \
585 std::cerr << "Failed to SetCenterDisplayPosition to " << pos2[0] << ", " << pos2[1] << ", " \
586 << pos2[2] << ", instead got " << pos[0] << ", " << pos[1] << ", " << pos[2] \
588 return EXIT_FAILURE; \
592 object->SetPoint1DisplayPosition(pos2); \
593 object->GetPoint1DisplayPosition(pos); \
594 if (pos[0] != pos2[0] || pos[0] != pos2[0] || pos[0] != pos2[0]) \
596 std::cerr << "Failed to SetPoint1DisplayPosition to " << pos2[0] << ", " << pos2[1] << ", " \
597 << pos2[2] << ", instead got " << pos[0] << ", " << pos[1] << ", " << pos[2] \
599 return EXIT_FAILURE; \
603 object->SetPoint2DisplayPosition(pos2); \
604 object->GetPoint2DisplayPosition(pos); \
605 if (pos[0] != pos2[0] || pos[0] != pos2[0] || pos[0] != pos2[0]) \
607 std::cerr << "Failed to SetPoint2DisplayPosition to " << pos2[0] << ", " << pos2[1] << ", " \
608 << pos2[2] << ", instead got " << pos[0] << ", " << pos[1] << ", " << pos[2] \
610 return EXIT_FAILURE; \
613 vtkSmartPointer<vtkPointHandleRepresentation2D> phandle = \
614 vtkSmartPointer<vtkPointHandleRepresentation2D>::New(); \
615 object->SetHandleRepresentation(phandle); \
616 object->InstantiateHandleRepresentation(); \
618 vtkSmartPointer<vtkHandleRepresentation> handleRep = nullptr; \
619 handleRep = object->GetPoint1Representation(); \
620 handleRep = object->GetPoint2Representation(); \
621 handleRep = object->GetCenterRepresentation(); \
623 TEST_SET_GET_INT_RANGE(object, Tolerance, 2, 99); \
624 TEST_SET_GET_STRING(object, LabelFormat); \
625 TEST_SET_GET_BOOLEAN(object, Ray1Visibility); \
626 TEST_SET_GET_BOOLEAN(object, Ray2Visibility); \
627 TEST_SET_GET_BOOLEAN(object, ArcVisibility); \
629 double e[2] = { 5.0, 1.0 }; \
630 object->CenterWidgetInteraction(e); \
631 EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
635#define EXERCISE_BASIC_BORDER_REPRESENTATION_METHODS(className, object) \
637 EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
639 double pos[2] = { 10.0, 11.0 }; \
640 double* pos2 = nullptr; \
641 object->SetPosition(pos); \
642 pos2 = object->GetPosition(); \
643 if (pos2 == nullptr) \
645 std::cerr << "Failure in Get/Set Position pos, got null position back." << std::endl; \
646 return EXIT_FAILURE; \
648 else if (pos2[0] != pos[0] || pos2[1] != pos[1]) \
650 std::cerr << "Failure in Get/Set Position pos, expected " << pos[0] << ", " << pos[1] \
651 << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
652 return EXIT_FAILURE; \
656 std::cout << "Set Position to " << pos2[0] << ", " << pos2[1] << std::endl; \
660 object->SetPosition(pos[0], pos[1]); \
661 pos2 = object->GetPosition(); \
662 if (pos2 == nullptr || pos2[0] != pos[0] || pos2[1] != pos[1]) \
664 std::cerr << "Failure in Get/Set Position x,y, expected " << pos[0] << ", " << pos[1] \
665 << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
666 return EXIT_FAILURE; \
668 vtkSmartPointer<vtkCoordinate> coord = object->GetPositionCoordinate(); \
669 pos2 = coord->GetValue(); \
670 if (pos2 == nullptr || pos2[0] != pos[0] || pos2[1] != pos[1]) \
672 std::cerr << "Failure in Get/ Coordinate, expected " << pos[0] << ", " << pos[1] \
673 << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
674 return EXIT_FAILURE; \
678 object->SetPosition2(pos); \
679 pos2 = object->GetPosition2(); \
680 if (pos2 == nullptr || pos2[0] != pos[0] || pos2[1] != pos[1]) \
682 std::cerr << "Failure in Get/Set Position2 pos, expected " << pos[0] << ", " << pos[1] \
683 << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
684 return EXIT_FAILURE; \
687 object->SetPosition2(pos[0], pos[1]); \
688 pos2 = object->GetPosition2(); \
689 if (pos2 == nullptr || pos2[0] != pos[0] || pos2[1] != pos[1]) \
691 std::cerr << "Failure in Get/Set Position2 x,y, expected " << pos[0] << ", " << pos[1] \
692 << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
693 return EXIT_FAILURE; \
695 coord = object->GetPosition2Coordinate(); \
696 pos2 = coord->GetValue(); \
697 if (pos2 == nullptr || pos2[0] != pos[0] || pos2[1] != pos[1]) \
699 std::cerr << "Failure in Get/ Coordinate 2, expected " << pos[0] << ", " << pos[1] \
700 << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl; \
701 return EXIT_FAILURE; \
704 TEST_SET_GET_INT(object, ShowBorder, 0); \
705 TEST_SET_GET_INT(object, ShowBorder, 1); \
706 TEST_SET_GET_INT(object, ShowBorder, 2); \
707 object->SetShowBorderToOff(); \
708 object->SetShowBorderToOn(); \
709 object->SetShowBorderToActive(); \
711 vtkSmartPointer<vtkProperty2D> borderProperty = object->GetBorderProperty(); \
713 TEST_SET_GET_BOOLEAN(object, ProportionalResize); \
715 TEST_SET_GET_VECTOR2_INT_RANGE(object, MinimumSize, 0, 100); \
716 TEST_SET_GET_VECTOR2_INT_RANGE(object, MaximumSize, 0, 100); \
717 TEST_SET_GET_INT_RANGE(object, Tolerance, 2, 9); \
719 double* selPoint = object->GetSelectionPoint(); \
722 std::cout << "Selection Point = " << selPoint[0] << ", " << selPoint[1] << std::endl; \
725 TEST_SET_GET_BOOLEAN(object, Moving); \
728 object->GetSize(size); \
729 std::cout << "Size = " << size[0] << ", " << size[1] << std::endl; \
731 int interactionState = object->ComputeInteractionState(10, 10); \
732 std::cout << "Interaction state = " << interactionState << std::endl; \
736#define EXERCISE_BASIC_IMPLICIT_PLANE_REPRESENTATION_METHODS(className, object) \
738 EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
740 TEST_SET_GET_VECTOR3_DOUBLE_RANGE(node1, Origin, -100, 100); \
741 TEST_SET_GET_VECTOR3_DOUBLE_RANGE(node1, Normal, -1, 1); \
742 TEST_SET_GET_BOOLEAN(node1, NormalToXAxis); \
743 TEST_SET_GET_BOOLEAN(node1, NormalToYAxis); \
744 TEST_SET_GET_BOOLEAN(node1, NormalToZAxis); \
745 TEST_SET_GET_BOOLEAN(node1, Tubing); \
746 TEST_SET_GET_BOOLEAN(node1, DrawPlane); \
747 TEST_SET_GET_BOOLEAN(node1, OutlineTranslation); \
748 TEST_SET_GET_BOOLEAN(node1, OutsideBounds); \
749 TEST_SET_GET_BOOLEAN(node1, ScaleEnabled); \
753#define TEST_SET_GET_PROPERTY(object, variable) \
755 vtkSmartPointer<vtkProperty> prop1 = vtkSmartPointer<vtkProperty>::New(); \
756 double colour[3] = { 0.2, 0.3, 0.4 }; \
757 prop1->SetColor(colour); \
758 node1->Set##variable(prop1); \
759 vtkSmartPointer<vtkProperty> prop = node1->Get##variable(); \
762 std::cerr << "Got null variable property back after setting it!" << std::endl; \
763 return EXIT_FAILURE; \
765 double* col = prop->GetColor(); \
768 std::cerr << "Got null colour back!" << std::endl; \
769 return EXIT_FAILURE; \
771 if (col[0] != colour[0] || col[1] != colour[1] || col[2] != colour[2]) \
773 std::cerr << "Got wrong colour back after setting it! Expected " << colour[0] << ", " \
774 << colour[1] << ", " << colour[2] << ", but got " << col[0] << ", " << col[1] \
775 << ", " << col[2] << std::endl; \
776 return EXIT_FAILURE; \
783#define EXERCISE_BASIC_HANDLE_REPRESENTATION_METHODS(className, object) \
785 EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
787 double dpos[3], wpos[3]; \
797 std::cout << "Testing SetWorldPosition" << std::endl; \
799 object->SetWorldPosition(wpos); \
800 std::cout << "Testing GetWorldPosition" << std::endl; \
801 object->GetWorldPosition(pos2); \
802 if (pos2[0] != wpos[0] || pos2[1] != wpos[1] || pos2[2] != wpos[2]) \
804 std::cerr << "Failure in Get WorldPosition pos2, expected " << wpos[0] << ", " << wpos[1] \
805 << ", " << wpos[2] << ", instead got " << pos2[0] << ", " << pos2[1] << ", " \
806 << pos2[2] << std::endl; \
807 return EXIT_FAILURE; \
809 pos3 = object->GetWorldPosition(); \
812 std::cerr << "Failure in double * GetWorldPosition , expected " << wpos[0] << ", " \
813 << wpos[1] << ", " << wpos[2] << ", instead got a null pointer." << std::endl; \
814 return EXIT_FAILURE; \
816 if (pos3[0] != wpos[0] || pos3[1] != wpos[1] || pos3[2] != wpos[2]) \
818 std::cerr << "Failure in double * GetWorldyPosition , expected " << wpos[0] << ", " \
819 << wpos[1] << ", " << wpos[2] << ", instead got " << pos3[0] << ", " << pos3[1] \
820 << ", " << pos3[2] << std::endl; \
821 return EXIT_FAILURE; \
823 std::cout << "Done testing world position." << std::endl; \
825 std::cout << "Testing Set/Get Display Position" << std::endl; \
827 object->GetDisplayPosition(pos2); \
828 std::cout << "After GetDisplayPosition." << std::endl; \
829 object->SetDisplayPosition(dpos); \
830 std::cout << "After SetDisplayPosition" << std::endl; \
831 object->GetDisplayPosition(pos2); \
832 std::cout << "After GetDisplayPosition second time." << std::endl; \
833 if (pos2[0] != 0 || pos2[1] != 0) \
835 std::cerr << "Failure in GetDisplayPosition pos2, expected (0,0) instead got " << pos2[0] \
836 << ", " << pos2[1] << std::endl; \
837 return EXIT_FAILURE; \
839 pos3 = object->GetDisplayPosition(); \
843 << "Failure in double * GetDisplayPosition, expected (0,0) instead got a null pointer." \
845 return EXIT_FAILURE; \
847 if (pos3[0] != 0 || pos3[1] != 0) \
849 std::cerr << "Failure in double * GetDisplayPosition , expected (0,0) instead got " \
850 << pos3[0] << ", " << pos3[1] << std::endl; \
851 return EXIT_FAILURE; \
853 TEST_SET_GET_INT_RANGE(object, Tolerance, 2, 99); \
854 TEST_SET_GET_BOOLEAN(object, ActiveRepresentation); \
855 TEST_SET_GET_BOOLEAN(object, Constrained); \
857 vtkSmartPointer<vtkRenderer> ren3 = object->GetRenderer(); \
858 double posToCheck[3] = { 0.0, 0.0, 0.0 }; \
859 int flag = object->CheckConstraint(ren3, posToCheck); \
860 std::cout << "Check Constraint = " << flag << std::endl; \
862 std::cout << "MTime = " << object->GetMTime() << std::endl; \
864 vtkSmartPointer<vtkPointPlacer> pplacer = vtkSmartPointer<vtkPointPlacer>::New(); \
865 object->SetPointPlacer(pplacer); \
866 vtkSmartPointer<vtkPointPlacer> pplacer2 = object->GetPointPlacer(); \
867 if (pplacer2 != pplacer) \
869 std::cerr << "Error in Set/Get point placer." << std::endl; \
870 return EXIT_FAILURE; \
872 flag = object->CheckConstraint(ren3, posToCheck); \
873 std::cout << "Check Constraint after setting point placer = " << flag << std::endl; \
877#define EXERCISE_BASIC_ABSTRACT_POLYGONAL_HANDLE_REPRESENTATION3D_METHODS(className, object) \
879 EXERCISE_BASIC_HANDLE_REPRESENTATION_METHODS(className, object); \
881 vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New(); \
882 object->SetHandle(pd); \
883 vtkSmartPointer<vtkPolyData> pd2 = object->GetHandle(); \
884 if (pd2 == nullptr) \
886 std::cerr << "Error getting handle, null pointer." << std::endl; \
887 return EXIT_FAILURE; \
891 std::cerr << "Error getting handle, not the same as set." << std::endl; \
892 return EXIT_FAILURE; \
894 TEST_SET_GET_PROPERTY(object, Property); \
895 TEST_SET_GET_PROPERTY(object, SelectedProperty); \
897 vtkSmartPointer<vtkAbstractTransform> at = object->GetTransform(); \
899 TEST_SET_GET_BOOLEAN(object, LabelVisibility); \
900 TEST_SET_GET_STRING(object, LabelText); \
901 TEST_SET_GET_VECTOR3_DOUBLE_RANGE(object, LabelTextScale, 0.0, 10.0); \
903 vtkSmartPointer<vtkFollower> follower = object->GetLabelTextActor(); \
904 if (follower == nullptr) \
906 std::cout << "Follower is null." << std::endl; \
909 object->SetUniformScale(-1.0); \
910 object->SetUniformScale(0.0); \
911 object->SetUniformScale(1.0); \
912 object->SetUniformScale(35.44); \
914 TEST_SET_GET_BOOLEAN(object, HandleVisibility); \