VTK  9.1.0
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"
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 { \
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 " \
46 << object->Get##variable() << " instead of 1" << std::endl; \
47 return EXIT_FAILURE; \
48 } \
49 object->Set##variable(false); \
50 if (object->Get##variable() != 0) \
51 { \
52 std::cerr << "Error in Set/Get" #variable << ", Get" #variable << " is " \
53 << object->Get##variable() << " instead of 0" << std::endl; \
54 return EXIT_FAILURE; \
55 } \
56 object->variable##On(); \
57 if (object->Get##variable() != 1) \
58 { \
59 std::cerr << "Error in On/Get" #variable << ", Get" #variable << " is " \
60 << object->Get##variable() << " instead of 1" << std::endl; \
61 return EXIT_FAILURE; \
62 } \
63 object->variable##Off(); \
64 if (object->Get##variable() != 0) \
65 { \
66 std::cerr << "Error in Off/Get" #variable << ", Get" #variable << " is " \
67 << object->Get##variable() << " instead of 0" << std::endl; \
68 return EXIT_FAILURE; \
69 }
70
73#define TEST_SET_GET_INT(object, variable, value) \
74 { \
75 object->Set##variable(value); \
76 if (object->Get##variable() != value) \
77 { \
78 std::cerr << "Error in Set/Get" #variable << " using value " << value << std::endl; \
79 return EXIT_FAILURE; \
80 } \
81 }
82
87#define TEST_SET_GET_INT_RANGE(object, variable, min, max) \
88 { \
89 int epsilon = 1; \
90 int val = min - epsilon; \
91 TEST_SET_GET_INT(object, variable, val); \
92 val = min; \
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); \
100 val = max; \
101 TEST_SET_GET_INT(object, variable, val); \
102 val = max + epsilon; \
103 TEST_SET_GET_INT(object, variable, val); \
104 }
105
108#define TEST_SET_GET_DOUBLE(object, variable, value) \
109 { \
110 object->Set##variable(value); \
111 if (object->Get##variable() != value) \
112 { \
113 std::cerr << "Error in Set/Get" #variable << " using value '" << value << "', got '" \
114 << object->Get##variable() << "'" << std::endl; \
115 return EXIT_FAILURE; \
116 } \
117 }
118
123#define TEST_SET_GET_DOUBLE_RANGE(object, variable, min, max) \
124 { \
125 double epsilon = 1.0; \
126 double val = min - epsilon; \
127 TEST_SET_GET_DOUBLE(object, variable, val); \
128 val = min; \
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); \
136 val = max; \
137 TEST_SET_GET_DOUBLE(object, variable, val); \
138 val = max + epsilon; \
139 TEST_SET_GET_DOUBLE(object, variable, val); \
140 }
141
144#define TEST_SET_GET_VECTOR3_DOUBLE(object, variable, x, y, z) \
145 { \
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) \
149 { \
150 std::cerr << "Error in Set/Get" #variable << std::endl; \
151 return EXIT_FAILURE; \
152 } \
153 }
154
157#define TEST_SET_GET_VECTOR2(object, variable, x, y) \
158 { \
159 object->Set##variable(x, y); \
160 int* val = object->Get##variable(); \
161 if (val == nullptr || val[0] != x || val[1] != y) \
162 { \
163 std::cerr << "Error in Set/Get" #variable << std::endl; \
164 return EXIT_FAILURE; \
165 } \
166 }
167
173#define TEST_SET_GET_VECTOR2_INT_RANGE(object, variable, min, max) \
174 { \
175 int epsilon = 1; \
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); \
184 }
185
191#define TEST_SET_GET_VECTOR2_DOUBLE_RANGE(object, variable, min, max) \
192 { \
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); \
202 }
203
209#define TEST_SET_GET_VECTOR3_DOUBLE_RANGE(object, variable, min, max) \
210 { \
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); \
220 }
221
223#define TEST_SET_GET_STRING(object, variable) \
224 { \
225 const char* originalStringPointer = object->Get##variable(); \
226 std::string originalString; \
227 if (originalStringPointer != nullptr) \
228 { \
229 originalString = originalStringPointer; \
230 } \
231 object->Set##variable("testing with a const char"); \
232 if (strcmp(object->Get##variable(), "testing with a const char") != 0) \
233 { \
234 std::cerr << "Error in Set/Get" #variable << " with a string literal" << std::endl; \
235 return EXIT_FAILURE; \
236 } \
237 std::string string1 = "testingIsGood"; \
238 object->Set##variable(string1.c_str()); \
239 if (object->Get##variable() != string1) \
240 { \
241 std::cerr << "Error in Set/Get" #variable << std::endl; \
242 return EXIT_FAILURE; \
243 } \
244 std::string string2 = "moreTestingIsBetter"; \
245 object->Set##variable(string2.c_str()); \
246 if (object->Get##variable() != string2) \
247 { \
248 std::cerr << "Error in Set/Get" #variable << std::endl; \
249 return EXIT_FAILURE; \
250 } \
251 if (originalStringPointer != nullptr) \
252 { \
253 object->Set##variable(originalString.c_str()); \
254 } \
255 else \
256 { \
257 object->Set##variable(nullptr); \
258 } \
259 }
260
262#define TEST_SET_GET_CHAR(object, variable) \
263 { \
264 const char originalChar = object->Get##variable(); \
265 object->Set##variable('t'); \
266 if (object->Get##variable() != 't') \
267 { \
268 std::cerr << "Error in Set/Get" #variable << " with a literal 't'" << std::endl; \
269 return EXIT_FAILURE; \
270 } \
271 object->Set##variable('3'); \
272 if (object->Get##variable() != '3') \
273 { \
274 std::cerr << "Error in Set/Get" #variable << " with a literal '3'" << std::endl; \
275 return EXIT_FAILURE; \
276 } \
277 object->Set##variable(originalChar); \
278 }
279
281#define EXERCISE_BASIC_INTERACTOR_OBSERVER_METHODS(object) \
282 { \
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) \
291 { \
292 std::cout << "Object has an interactor already defined." << std::endl; \
293 } \
294 vtkSmartPointer<vtkRenderWindowInteractor> iren = \
295 vtkSmartPointer<vtkRenderWindowInteractor>::New(); \
296 iren->SetRenderWindow(renWin); \
297 object->SetInteractor(iren); \
298 if (object->GetInteractor() != iren) \
299 { \
300 std::cerr << "Error in Set/GetInteractor" << std::endl; \
301 return EXIT_FAILURE; \
302 } \
303 if (object->GetDefaultRenderer() != nullptr) \
304 { \
305 std::cout << "Object has default renderer already defined." << std::endl; \
306 } \
307 \
308 vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New(); \
309 renWin->AddRenderer(ren); \
310 object->SetDefaultRenderer(ren); \
311 if (object->GetDefaultRenderer() != ren) \
312 { \
313 std::cerr << "Error in Set/GetDefaultRenderer, default renderer is " \
314 << (object->GetDefaultRenderer() == nullptr ? "nullptr" : "not null") \
315 << std::endl; \
316 return EXIT_FAILURE; \
317 } \
318 object->SetCurrentRenderer(ren); \
319 if (object->GetCurrentRenderer() != ren) \
320 { \
321 std::cerr << "Get current renderer failed." << std::endl; \
322 } \
323 \
324 iren->Initialize(); \
325 renWin->Render(); \
326 if (0) \
327 { \
328 object->CreateDefaultRepresentation(); \
329 TEST_SET_GET_BOOLEAN(object, Enabled); \
330 object->On(); \
331 if (!object->GetEnabled()) \
332 { \
333 std::cerr << "Error in On" << std::endl; \
334 return EXIT_FAILURE; \
335 } \
336 object->Off(); \
337 if (object->GetEnabled()) \
338 { \
339 std::cerr << "Error in Off" << std::endl; \
340 return EXIT_FAILURE; \
341 } \
342 } \
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); \
351 \
352 TEST_SET_GET_BOOLEAN(object, KeyPressActivation); \
353 TEST_SET_GET_CHAR(object, KeyPressActivationValue); \
354 \
355 object->OnChar(); \
356 if (0) \
357 { \
358 double worldPt[4]; \
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; \
367 } \
368 \
369 object->GrabFocus(nullptr, nullptr); \
370 object->ReleaseFocus(); \
371 }
372
374#define EXERCISE_BASIC_ABSTRACT_METHODS(object) \
375 { \
376 EXERCISE_BASIC_INTERACTOR_OBSERVER_METHODS(object); \
377 TEST_SET_GET_BOOLEAN(object, ProcessEvents); \
378 if (object->GetEventTranslator() == nullptr) \
379 { \
380 std::cerr << "Error getting event translator, is null." << std::endl; \
381 return EXIT_FAILURE; \
382 } \
383 object->CreateDefaultRepresentation(); \
384 object->Render(); \
385 if (object->GetParent() != nullptr) \
386 { \
387 std::cerr << "Error, parent is not null." << std::endl; \
388 return EXIT_FAILURE; \
389 } \
390 }
391
393#define EXERCISE_BASIC_BORDER_METHODS(object) \
394 { \
395 EXERCISE_BASIC_ABSTRACT_METHODS(object); \
396 TEST_SET_GET_BOOLEAN(object, Selectable); \
397 TEST_SET_GET_BOOLEAN(object, Resizable); \
398 }
399
401#define EXERCISE_BASIC_HOVER_METHODS(object) \
402 { \
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); \
409 }
410
412#define EXERCISE_BASIC_PROP_METHODS(className, object) \
413 { \
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); \
419 \
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(); \
425 \
426 object->Pick(); \
427 \
428 vtkMTimeType redrawMTime = object->GetRedrawMTime(); \
429 std::cout << "Redraw Modified Time = " << redrawMTime << std::endl; \
430 \
431 vtkSmartPointer<className> copyProp = vtkSmartPointer<className>::New(); \
432 object->ShallowCopy(copyProp); \
433 \
434 object->InitPathTraversal(); \
435 \
436 vtkSmartPointer<vtkAssemblyPath> assemblyPath = vtkSmartPointer<vtkAssemblyPath>::New(); \
437 assemblyPath = object->GetNextPath(); \
438 std::cout << "Number of paths = " << object->GetNumberOfPaths() << std::endl; \
439 \
440 vtkSmartPointer<vtkMatrix4x4> mat = vtkSmartPointer<vtkMatrix4x4>::New(); \
441 object->PokeMatrix(mat); \
442 mat = object->GetMatrix(); \
443 if (mat == nullptr) \
444 { \
445 std::cout << "No matrix." << std::endl; \
446 } \
447 \
448 vtkSmartPointer<vtkInformation> info = vtkSmartPointer<vtkInformation>::New(); \
449 info = object->GetPropertyKeys(); \
450 if (info != nullptr) \
451 { \
452 info->Print(std::cout); \
453 } \
454 else \
455 { \
456 std::cout << "No property keys" << std::endl; \
457 } \
458 object->SetPropertyKeys(info); \
459 std::cout << "Has null required keys? " << object->HasKeys(nullptr) << std::endl; \
460 \
461 std::cout << "Skipping the internal render calls, requires vtkViewPort. Testing get macros." \
462 << std::endl; \
463 std::cout << "HasTranslucentPolygonalGeometry = " << object->HasTranslucentPolygonalGeometry() \
464 << std::endl; \
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; \
469 }
470
471#define NOT_DEFINED_CONSUMERS_FAIL() \
472 { \
473 vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); \
474 object->AddConsumer(actor); \
475 if (object->IsConsumer(actor) != 1) \
476 { \
477 std::cerr << "Failed IsConsumer check for a valid consumer." << std::endl; \
478 return EXIT_FAILURE; \
479 } \
480 if (object->IsConsumer(nullptr) != 0) \
481 { \
482 std::cerr << "Failed IsConsumer check for a null consumer." << std::endl; \
483 return EXIT_FAILURE; \
484 } \
485 vtkSmartPointer<vtkActor> actor2 = object->GetConsumer(0); \
486 if (actor2 != actor) \
487 { \
488 std::cerr << "Failed get consumer check for a valid consumer." << std::endl; \
489 return EXIT_FAILURE; \
490 } \
491 object->RemoveConsumer(actor); \
492 actor2 = object->GetConsumer(0); \
493 if (actor2 != nullptr) \
494 { \
495 std::cerr << "Failed get consumer check for an invalid consumer number 0." << std::endl; \
496 return EXIT_FAILURE; \
497 } \
498 }
499
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); \
512 \
513 object->SetRenderer(ren1); \
514 vtkSmartPointer<vtkRenderer> ren2 = object->GetRenderer(); \
515 if (ren2 != ren1) \
516 { \
517 std::cerr << "Failure in GetRenderer." << std::endl; \
518 return EXIT_FAILURE; \
519 } \
520 \
521 object->BuildRepresentation(); \
522 \
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) \
527 { \
528 std::cout << "GetBounds is null." << std::endl; \
529 } \
530 else \
531 { \
532 std::cout << "Bounds = " << bounds[0] << "," << bounds[1] << "," << bounds[2] << "," \
533 << bounds[3] << "," << bounds[4] << "," << bounds[5] << std::endl; \
534 } \
535 \
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) \
541 << std::endl; \
542 std::cout << "GetInteractionState = " << object->GetInteractionState() << std::endl; \
543 object->Highlight(0); \
544 object->Highlight(1); \
545 \
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); \
549 \
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);
555
557#define EXERCISE_BASIC_ANGLE_REPRESENTATION_METHODS(className, object) \
558 { \
559 vtkSmartPointer<vtkPointHandleRepresentation2D> phandle0 = \
560 vtkSmartPointer<vtkPointHandleRepresentation2D>::New(); \
561 object->SetHandleRepresentation(phandle0); \
562 object->InstantiateHandleRepresentation(); \
563 \
564 std::cout << "GetAngle = " << object->GetAngle() << std::endl; \
565 \
566 double pos[3]; \
567 object->GetPoint1WorldPosition(pos); \
568 std::cout << "GetPoint1WorldPosition = " << pos[0] << ", " << pos[1] << ", " << pos[2] \
569 << std::endl; \
570 object->GetCenterWorldPosition(pos); \
571 std::cout << "GetCenterWorldPosition = " << pos[0] << ", " << pos[1] << ", " << pos[2] \
572 << std::endl; \
573 object->GetPoint2WorldPosition(pos); \
574 std::cout << "GetPoint2WorldPosition = " << pos[0] << ", " << pos[1] << ", " << pos[2] \
575 << std::endl; \
576 \
577 double pos2[3]; \
578 pos2[0] = -99.0; \
579 pos2[1] = 99.0; \
580 pos2[2] = 55.0; \
581 object->SetCenterDisplayPosition(pos2); \
582 object->GetCenterDisplayPosition(pos); \
583 if (pos[0] != pos2[0] || pos[0] != pos2[0] || pos[0] != pos2[0]) \
584 { \
585 std::cerr << "Failed to SetCenterDisplayPosition to " << pos2[0] << ", " << pos2[1] << ", " \
586 << pos2[2] << ", instead got " << pos[0] << ", " << pos[1] << ", " << pos[2] \
587 << std::endl; \
588 return EXIT_FAILURE; \
589 } \
590 \
591 pos[0] = -100.0; \
592 object->SetPoint1DisplayPosition(pos2); \
593 object->GetPoint1DisplayPosition(pos); \
594 if (pos[0] != pos2[0] || pos[0] != pos2[0] || pos[0] != pos2[0]) \
595 { \
596 std::cerr << "Failed to SetPoint1DisplayPosition to " << pos2[0] << ", " << pos2[1] << ", " \
597 << pos2[2] << ", instead got " << pos[0] << ", " << pos[1] << ", " << pos[2] \
598 << std::endl; \
599 return EXIT_FAILURE; \
600 } \
601 \
602 pos[0] = 101.0; \
603 object->SetPoint2DisplayPosition(pos2); \
604 object->GetPoint2DisplayPosition(pos); \
605 if (pos[0] != pos2[0] || pos[0] != pos2[0] || pos[0] != pos2[0]) \
606 { \
607 std::cerr << "Failed to SetPoint2DisplayPosition to " << pos2[0] << ", " << pos2[1] << ", " \
608 << pos2[2] << ", instead got " << pos[0] << ", " << pos[1] << ", " << pos[2] \
609 << std::endl; \
610 return EXIT_FAILURE; \
611 } \
612 \
613 vtkSmartPointer<vtkPointHandleRepresentation2D> phandle = \
614 vtkSmartPointer<vtkPointHandleRepresentation2D>::New(); \
615 object->SetHandleRepresentation(phandle); \
616 object->InstantiateHandleRepresentation(); \
617 \
618 vtkSmartPointer<vtkHandleRepresentation> handleRep = nullptr; \
619 handleRep = object->GetPoint1Representation(); \
620 handleRep = object->GetPoint2Representation(); \
621 handleRep = object->GetCenterRepresentation(); \
622 \
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); \
628 \
629 double e[2] = { 5.0, 1.0 }; \
630 object->CenterWidgetInteraction(e); \
631 EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
632 }
633
635#define EXERCISE_BASIC_BORDER_REPRESENTATION_METHODS(className, object) \
636 { \
637 EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
638 \
639 double pos[2] = { 10.0, 11.0 }; \
640 double* pos2 = nullptr; \
641 object->SetPosition(pos); \
642 pos2 = object->GetPosition(); \
643 if (pos2 == nullptr) \
644 { \
645 std::cerr << "Failure in Get/Set Position pos, got null position back." << std::endl; \
646 return EXIT_FAILURE; \
647 } \
648 else if (pos2[0] != pos[0] || pos2[1] != pos[1]) \
649 { \
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; \
653 } \
654 else \
655 { \
656 std::cout << "Set Position to " << pos2[0] << ", " << pos2[1] << std::endl; \
657 } \
658 \
659 pos[0] = 12.0; \
660 object->SetPosition(pos[0], pos[1]); \
661 pos2 = object->GetPosition(); \
662 if (pos2 == nullptr || pos2[0] != pos[0] || pos2[1] != pos[1]) \
663 { \
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; \
667 } \
668 vtkSmartPointer<vtkCoordinate> coord = object->GetPositionCoordinate(); \
669 pos2 = coord->GetValue(); \
670 if (pos2 == nullptr || pos2[0] != pos[0] || pos2[1] != pos[1]) \
671 { \
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; \
675 } \
676 \
677 pos[0] = 44.0; \
678 object->SetPosition2(pos); \
679 pos2 = object->GetPosition2(); \
680 if (pos2 == nullptr || pos2[0] != pos[0] || pos2[1] != pos[1]) \
681 { \
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; \
685 } \
686 pos[0] = 12.0; \
687 object->SetPosition2(pos[0], pos[1]); \
688 pos2 = object->GetPosition2(); \
689 if (pos2 == nullptr || pos2[0] != pos[0] || pos2[1] != pos[1]) \
690 { \
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; \
694 } \
695 coord = object->GetPosition2Coordinate(); \
696 pos2 = coord->GetValue(); \
697 if (pos2 == nullptr || pos2[0] != pos[0] || pos2[1] != pos[1]) \
698 { \
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; \
702 } \
703 \
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(); \
710 \
711 vtkSmartPointer<vtkProperty2D> borderProperty = object->GetBorderProperty(); \
712 \
713 TEST_SET_GET_BOOLEAN(object, ProportionalResize); \
714 \
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); \
718 \
719 double* selPoint = object->GetSelectionPoint(); \
720 if (selPoint) \
721 { \
722 std::cout << "Selection Point = " << selPoint[0] << ", " << selPoint[1] << std::endl; \
723 } \
724 \
725 TEST_SET_GET_BOOLEAN(object, Moving); \
726 \
727 double size[2]; \
728 object->GetSize(size); \
729 std::cout << "Size = " << size[0] << ", " << size[1] << std::endl; \
730 \
731 int interactionState = object->ComputeInteractionState(10, 10); \
732 std::cout << "Interaction state = " << interactionState << std::endl; \
733 }
734
736#define EXERCISE_BASIC_IMPLICIT_PLANE_REPRESENTATION_METHODS(className, object) \
737 { \
738 EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
739 \
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); \
750 }
751
753#define TEST_SET_GET_PROPERTY(object, variable) \
754 { \
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(); \
760 if (!prop) \
761 { \
762 std::cerr << "Got null variable property back after setting it!" << std::endl; \
763 return EXIT_FAILURE; \
764 } \
765 double* col = prop->GetColor(); \
766 if (!col) \
767 { \
768 std::cerr << "Got null colour back!" << std::endl; \
769 return EXIT_FAILURE; \
770 } \
771 if (col[0] != colour[0] || col[1] != colour[1] || col[2] != colour[2]) \
772 { \
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; \
777 } \
778 }
779
783#define EXERCISE_BASIC_HANDLE_REPRESENTATION_METHODS(className, object) \
784 { \
785 EXERCISE_BASIC_REPRESENTATION_METHODS(className, object); \
786 \
787 double dpos[3], wpos[3]; \
788 wpos[0] = 0.1; \
789 wpos[1] = -1.0; \
790 wpos[2] = 3.6; \
791 dpos[0] = 25; \
792 dpos[1] = 50; \
793 dpos[2] = 0.0; \
794 double pos2[3]; \
795 double* pos3; \
796 \
797 std::cout << "Testing SetWorldPosition" << std::endl; \
798 \
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]) \
803 { \
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; \
808 } \
809 pos3 = object->GetWorldPosition(); \
810 if (!pos3) \
811 { \
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; \
815 } \
816 if (pos3[0] != wpos[0] || pos3[1] != wpos[1] || pos3[2] != wpos[2]) \
817 { \
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; \
822 } \
823 std::cout << "Done testing world position." << std::endl; \
824 \
825 std::cout << "Testing Set/Get Display Position" << std::endl; \
826 \
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) \
834 { \
835 std::cerr << "Failure in GetDisplayPosition pos2, expected (0,0) instead got " << pos2[0] \
836 << ", " << pos2[1] << std::endl; \
837 return EXIT_FAILURE; \
838 } \
839 pos3 = object->GetDisplayPosition(); \
840 if (!pos3) \
841 { \
842 std::cerr \
843 << "Failure in double * GetDisplayPosition, expected (0,0) instead got a null pointer." \
844 << std::endl; \
845 return EXIT_FAILURE; \
846 } \
847 if (pos3[0] != 0 || pos3[1] != 0) \
848 { \
849 std::cerr << "Failure in double * GetDisplayPosition , expected (0,0) instead got " \
850 << pos3[0] << ", " << pos3[1] << std::endl; \
851 return EXIT_FAILURE; \
852 } \
853 TEST_SET_GET_INT_RANGE(object, Tolerance, 2, 99); \
854 TEST_SET_GET_BOOLEAN(object, ActiveRepresentation); \
855 TEST_SET_GET_BOOLEAN(object, Constrained); \
856 \
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; \
861 \
862 std::cout << "MTime = " << object->GetMTime() << std::endl; \
863 \
864 vtkSmartPointer<vtkPointPlacer> pplacer = vtkSmartPointer<vtkPointPlacer>::New(); \
865 object->SetPointPlacer(pplacer); \
866 vtkSmartPointer<vtkPointPlacer> pplacer2 = object->GetPointPlacer(); \
867 if (pplacer2 != pplacer) \
868 { \
869 std::cerr << "Error in Set/Get point placer." << std::endl; \
870 return EXIT_FAILURE; \
871 } \
872 flag = object->CheckConstraint(ren3, posToCheck); \
873 std::cout << "Check Constraint after setting point placer = " << flag << std::endl; \
874 }
875
877#define EXERCISE_BASIC_ABSTRACT_POLYGONAL_HANDLE_REPRESENTATION3D_METHODS(className, object) \
878 { \
879 EXERCISE_BASIC_HANDLE_REPRESENTATION_METHODS(className, object); \
880 \
881 vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New(); \
882 object->SetHandle(pd); \
883 vtkSmartPointer<vtkPolyData> pd2 = object->GetHandle(); \
884 if (pd2 == nullptr) \
885 { \
886 std::cerr << "Error getting handle, null pointer." << std::endl; \
887 return EXIT_FAILURE; \
888 } \
889 if (pd2 != pd) \
890 { \
891 std::cerr << "Error getting handle, not the same as set." << std::endl; \
892 return EXIT_FAILURE; \
893 } \
894 TEST_SET_GET_PROPERTY(object, Property); \
895 TEST_SET_GET_PROPERTY(object, SelectedProperty); \
896 \
897 vtkSmartPointer<vtkAbstractTransform> at = object->GetTransform(); \
898 \
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); \
902 \
903 vtkSmartPointer<vtkFollower> follower = object->GetLabelTextActor(); \
904 if (follower == nullptr) \
905 { \
906 std::cout << "Follower is null." << std::endl; \
907 } \
908 \
909 object->SetUniformScale(-1.0); \
910 object->SetUniformScale(0.0); \
911 object->SetUniformScale(1.0); \
912 object->SetUniformScale(35.44); \
913 \
914 TEST_SET_GET_BOOLEAN(object, HandleVisibility); \
915 }
916#endif