1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkSeedRepresentationTest1.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkSeedRepresentation.h"
16
17 #include <cstdlib>
18 #include <iostream>
19
20 #include "vtkImageData.h"
21 #include "vtkProperty2D.h"
22 #include "vtkTextProperty.h"
23
24 #include "WidgetTestingMacros.h"
25 #include "vtkTestErrorObserver.h"
26
27 #include "vtkPointHandleRepresentation3D.h"
28 #include "vtkTextActor.h"
29
vtkSeedRepresentationTest1(int,char * [])30 int vtkSeedRepresentationTest1(int, char*[])
31 {
32 vtkSmartPointer<vtkSeedRepresentation> node1 = vtkSmartPointer<vtkSeedRepresentation>::New();
33
34 EXERCISE_BASIC_REPRESENTATION_METHODS(vtkSeedRepresentation, node1);
35
36 std::cout << "Number of Seeds = " << node1->GetNumberOfSeeds() << std::endl;
37
38 double pos[3] = { 1.0, 2.0, -3.0 };
39 double pos2[3];
40 int s = 0;
41
42 // set/get display and world should fail without seeds
43 vtkSmartPointer<vtkTest::ErrorObserver> errorObserver =
44 vtkSmartPointer<vtkTest::ErrorObserver>::New();
45 node1->AddObserver(vtkCommand::ErrorEvent, errorObserver);
46 node1->SetSeedDisplayPosition(s, pos);
47
48 int status = errorObserver->CheckErrorMessage("Trying to access non-existent handle");
49 node1->GetSeedWorldPosition(s, pos2);
50 status += errorObserver->CheckErrorMessage("Trying to access non-existent handle");
51 node1->GetSeedDisplayPosition(s, pos);
52 status += errorObserver->CheckErrorMessage("Trying to access non-existent handle");
53
54 // set/get display and world position will fail without seeds having been
55 // created, so add some and then do the testing of return values.
56
57 // have to set rep first
58 vtkSmartPointer<vtkPointHandleRepresentation3D> handleRep =
59 vtkSmartPointer<vtkPointHandleRepresentation3D>::New();
60 node1->SetHandleRepresentation(handleRep);
61
62 double e[2] = { 10.0, 10.0 };
63 int numSeeds = 10;
64 for (int n = 0; n < numSeeds; n++)
65 {
66 int handleNum = node1->CreateHandle(e);
67 std::cout << "Created handle number " << handleNum << std::endl;
68 e[0] -= 1.0;
69 e[1] += 1.0;
70 }
71 std::cout << "Number of Seeds = " << node1->GetNumberOfSeeds() << std::endl;
72
73 node1->SetSeedDisplayPosition(s, pos);
74 node1->GetSeedDisplayPosition(s, pos2);
75 if (pos2[0] != pos[0] || pos2[1] != pos[1])
76 {
77 std::cerr << "Error in Set/Get Seed display position " << s << ", expected " << pos[0] << ", "
78 << pos[1] << ", instead got " << pos2[0] << ", " << pos2[1] << std::endl;
79 return EXIT_FAILURE;
80 }
81
82 node1->GetSeedWorldPosition(s, pos2);
83 std::cout << "Get Seed world position " << s << " = " << pos2[0] << ", " << pos2[1] << ", "
84 << pos2[2] << std::endl;
85
86 vtkSmartPointer<vtkPointHandleRepresentation3D> handleRep2;
87 handleRep2 = vtkPointHandleRepresentation3D::SafeDownCast(node1->GetHandleRepresentation());
88 if (handleRep2 == nullptr || handleRep2 != handleRep)
89 {
90 std::cerr << "Error in Set/Get handle rep at top level." << std::endl;
91 return EXIT_FAILURE;
92 }
93 handleRep2 = vtkPointHandleRepresentation3D::SafeDownCast(node1->GetHandleRepresentation(0));
94 if (handleRep2 == nullptr)
95 {
96 std::cerr << "Error in Set/Get handle rep 0." << std::endl;
97 return EXIT_FAILURE;
98 }
99
100 // clamped 1,100
101 TEST_SET_GET_INT_RANGE(node1, Tolerance, 2, 99);
102
103 int activeHandle = node1->GetActiveHandle();
104 std::cout << "Active Handle = " << activeHandle << std::endl;
105
106 node1->RemoveLastHandle();
107 node1->RemoveActiveHandle();
108
109 node1->RemoveHandle(0);
110
111 return EXIT_SUCCESS;
112 }
113