1 #include "vtkBiDimensionalRepresentation2D.h"
2 
3 #include <cstdlib>
4 #include <iostream>
5 
6 #include "vtkImageData.h"
7 #include "vtkProperty2D.h"
8 #include "vtkTextProperty.h"
9 
10 #include "WidgetTestingMacros.h"
11 
vtkBiDimensionalRepresentation2DTest1(int,char * [])12 int vtkBiDimensionalRepresentation2DTest1(int, char*[])
13 {
14   vtkSmartPointer<vtkBiDimensionalRepresentation2D> node1 =
15     vtkSmartPointer<vtkBiDimensionalRepresentation2D>::New();
16 
17   EXERCISE_BASIC_REPRESENTATION_METHODS(vtkBiDimensionalRepresentation2D, node1);
18 
19   double pos[3] = { 55.0, 66.6, 77.9 };
20   double p[3];
21 
22   // world position
23   node1->SetPoint1WorldPosition(pos);
24   node1->GetPoint1WorldPosition(p);
25   if (p[0] != pos[0] || p[1] != pos[1] || p[2] != pos[2])
26   {
27     std::cerr << "Failure in Get/Set Point1WorldPosition, expected " << pos[0] << ", " << pos[1]
28               << ", " << pos[2] << ", instead got " << p[0] << ", " << p[1] << ", " << p[2]
29               << std::endl;
30     return EXIT_FAILURE;
31   }
32 
33   pos[2] = 99.9;
34   node1->SetPoint2WorldPosition(pos);
35   node1->GetPoint2WorldPosition(p);
36   if (p[0] != pos[0] || p[1] != pos[1] || p[2] != pos[2])
37   {
38     std::cerr << "Failure in Get/Set Point2WorldPosition, expected " << pos[0] << ", " << pos[1]
39               << ", " << pos[2] << ", instead got " << p[0] << ", " << p[1] << ", " << p[2]
40               << std::endl;
41     return EXIT_FAILURE;
42   }
43 
44   pos[2] = -88.9;
45   node1->SetPoint3WorldPosition(pos);
46   node1->GetPoint3WorldPosition(p);
47   if (p[0] != pos[0] || p[1] != pos[1] || p[2] != pos[2])
48   {
49     std::cerr << "Failure in Get/Set Point3WorldPosition, expected " << pos[0] << ", " << pos[1]
50               << ", " << pos[2] << ", instead got " << p[0] << ", " << p[1] << ", " << p[2]
51               << std::endl;
52     return EXIT_FAILURE;
53   }
54 
55   pos[0] = -44.9;
56   node1->SetPoint4WorldPosition(pos);
57   node1->GetPoint4WorldPosition(p);
58   if (p[0] != pos[0] || p[1] != pos[1] || p[2] != pos[2])
59   {
60     std::cerr << "Failure in Get/Set Point4WorldPosition, expected " << pos[0] << ", " << pos[1]
61               << ", " << pos[2] << ", instead got " << p[0] << ", " << p[1] << ", " << p[2]
62               << std::endl;
63     return EXIT_FAILURE;
64   }
65 
66   // display position
67   node1->SetPoint1DisplayPosition(pos);
68   node1->GetPoint1DisplayPosition(p);
69   // only compare first two points in vector, last is always zero
70   if (p[0] != pos[0] || p[1] != pos[1] || p[2] != 0.0)
71   {
72     std::cerr << "Failure in Get/Set Point1DisplayPosition, expected " << pos[0] << ", " << pos[1]
73               << ", " << pos[2] << ", instead got " << p[0] << ", " << p[1] << ", " << p[2]
74               << std::endl;
75     return EXIT_FAILURE;
76   }
77 
78   pos[1] = 99.9;
79   node1->SetPoint2DisplayPosition(pos);
80   node1->GetPoint2DisplayPosition(p);
81   if (p[0] != pos[0] || p[1] != pos[1] || p[2] != 0.0)
82   {
83     std::cerr << "Failure in Get/Set Point2DisplayPosition, expected " << pos[0] << ", " << pos[1]
84               << ", " << pos[2] << ", instead got " << p[0] << ", " << p[1] << ", " << p[2]
85               << std::endl;
86     return EXIT_FAILURE;
87   }
88 
89   pos[1] = -88.9;
90   node1->SetPoint3DisplayPosition(pos);
91   node1->GetPoint3DisplayPosition(p);
92   if (p[0] != pos[0] || p[1] != pos[1] || p[2] != 0.0)
93   {
94     std::cerr << "Failure in Get/Set Point3DisplayPosition, expected " << pos[0] << ", " << pos[1]
95               << ", " << pos[2] << ", instead got " << p[0] << ", " << p[1] << ", " << p[2]
96               << std::endl;
97     return EXIT_FAILURE;
98   }
99 
100   pos[0] = -44.9;
101   node1->SetPoint4DisplayPosition(pos);
102   node1->GetPoint4DisplayPosition(p);
103   if (p[0] != pos[0] || p[1] != pos[1] || p[2] != 0.0)
104   {
105     std::cerr << "Failure in Get/Set Point4DisplayPosition, expected " << pos[0] << ", " << pos[1]
106               << ", " << pos[2] << ", instead got " << p[0] << ", " << p[1] << ", " << p[2]
107               << std::endl;
108     return EXIT_FAILURE;
109   }
110 
111   TEST_SET_GET_BOOLEAN(node1, Line1Visibility);
112   TEST_SET_GET_BOOLEAN(node1, Line2Visibility);
113 
114   vtkSmartPointer<vtkHandleRepresentation> hRep;
115   hRep = node1->GetPoint1Representation();
116   hRep = node1->GetPoint2Representation();
117   hRep = node1->GetPoint4Representation();
118   hRep = node1->GetPoint4Representation();
119 
120   vtkSmartPointer<vtkProperty2D> prop2d;
121   prop2d = node1->GetLineProperty();
122   prop2d = node1->GetSelectedLineProperty();
123 
124   vtkSmartPointer<vtkTextProperty> textProp;
125   textProp = node1->GetTextProperty();
126 
127   TEST_SET_GET_INT_RANGE(node1, Tolerance, 2, 99);
128 
129   std::cout << "Length 1 = " << node1->GetLength1() << std::endl;
130   std::cout << "Length 2 = " << node1->GetLength2() << std::endl;
131 
132   TEST_SET_GET_STRING(node1, LabelFormat);
133 
134   double e[2] = { 10.0, 8.0 };
135   node1->Point2WidgetInteraction(e);
136   e[1] = 7.0;
137   // node1->Point3WidgetInteraction(e);
138 
139   TEST_SET_GET_BOOLEAN(node1, ShowLabelAboveWidget);
140 
141   TEST_SET_GET_INT_RANGE(node1, ID, 1, 10000);
142 
143   std::cout << "LabelText = "
144             << (node1->GetLabelText() == nullptr ? "nullptr" : node1->GetLabelText()) << std::endl;
145   double* labelPos = node1->GetLabelPosition();
146   if (labelPos)
147   {
148     std::cout << "LabelPosition: " << labelPos[0] << ", " << labelPos[1] << ", " << labelPos[2]
149               << std::endl;
150   }
151   else
152   {
153     std::cout << "LabelPosition is null" << std::endl;
154   }
155   double labelPosition[3];
156   node1->GetLabelPosition(labelPosition);
157   std::cout << "LabelPosition [3]: " << labelPosition[0] << ", " << labelPosition[1] << ", "
158             << labelPosition[2] << std::endl;
159   //  node1->GetWorldLabelPosition(labelPosition);
160   //  std::cout << "WorldLabelPosition: " << labelPosition[0] << ", " << labelPosition[1] << ", " <<
161   //  labelPosition[2] << std::endl;
162   return EXIT_SUCCESS;
163 }
164