Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkMaterialTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkBaseProperty.h"
14 #include "mitkBaseRenderer.h"
15 #include "mitkDataNode.h"
16 #include "mitkMaterial.h"
17 #include "mitkTestingMacros.h"
18 #include <mitkColorProperty.h>
19 #include <mitkVtkPropRenderer.h>
20 
21 #include <iostream>
22 
32 class MaterialTest
33 {
34 public:
36 
37  MaterialTest() { myMP = nullptr; }
38  void testConstructor()
39  {
40  myMP = mitk::Material::New();
41  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
42  }
43 
44  void testConstructorWithColorOpacity()
45  {
46  mitk::Color color;
47  color.Set(0, 0, 0);
48  double opacity = 1.0f;
49  myMP = mitk::Material::New(color, opacity);
50  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
51  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a Color object was set correctly")
52  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity object was set correctly")
53  }
54 
55  void testConstructorWithRedGreenBlueOpacity()
56  {
58  color.Set(0, 0, 0);
59  double opacity = 1.0f;
60  double rgb = 0;
61 
62  myMP = mitk::Material::New(rgb, rgb, rgb, opacity);
63  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
64  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a Color object was set correctly")
65  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity object was set correctly")
66  }
67 
68  void testConstructorRedGreenBlueColorCoefficientSpecularCoefficientSpecularPowerOpacity()
69  {
71  color.Set(0, 0, 0);
72  double opacity = 1.0f;
73  double rgb = 0;
74  double colorCoefficient = 0;
75  double specularCoefficient = 0;
76  double specularPower = 0;
77 
78  myMP = mitk::Material::New(rgb, rgb, rgb, colorCoefficient, specularCoefficient, specularPower, opacity);
79  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
80  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a Color object was set correctly")
81  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity object was set correctly")
82  MITK_TEST_CONDITION(specularCoefficient == myMP->GetSpecularCoefficient(),
83  "Testing if a Coefficient object was set correctly")
84  MITK_TEST_CONDITION(specularPower == myMP->GetSpecularPower(),
85  "Testing if a SpecularPower object was set correctly")
86  MITK_TEST_CONDITION(colorCoefficient == myMP->GetColorCoefficient(),
87  "Testing if a colorCoefficient object was set correctly")
88  }
89 
90  void testConstructorColorColorCoefficientSpecularCoefficientSpecularPowerOpacity()
91  {
93  color.Set(0, 0, 0);
94  double opacity = 1.0f;
95  double rgb = 0;
96  double colorCoefficient = 0;
97  double specularCoefficient = 0;
98  double specularPower = 0;
99 
100  myMP = mitk::Material::New(rgb, rgb, rgb, colorCoefficient, specularCoefficient, specularPower, opacity);
101  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
102  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a Color object was set correctly")
103  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity object was set correctly")
104  MITK_TEST_CONDITION(specularCoefficient == myMP->GetSpecularCoefficient(),
105  "Testing if a Coefficient object was set correctly")
106  MITK_TEST_CONDITION(specularPower == myMP->GetSpecularPower(),
107  "Testing if a SpecularPower object was set correctly")
108  }
109 
110  void testConstructorPropertyRedGreenBlueOpacityAndName()
111  {
112  mitk::Material::Pointer reference = myMP;
113  double opacity = 1.0f;
114  double rgb = 0;
115  std::string name = "Hans Wurst";
116 
117  myMP = mitk::Material::New(*reference, rgb, rgb, rgb, opacity, name);
118  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
119  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity object was set correctly")
120  // MITK_TEST_CONDITION( name.compare(myMP->GetName(),0,9), "Testing if a Name object was set correctly" )
121  }
122  void testSetColor()
123  {
124  mitk::Material::Color color;
125  color.Set(0, 0, 0);
126  myMP = mitk::Material::New();
127  myMP->SetColor(color);
128  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
129  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a color was set correctly")
130  color.Set(0, 0, 0);
131  myMP->SetColor(color);
132  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a color was set correctly")
133  }
134 
135  void testSetColorCoefficient()
136  {
137  double colorCoefficient = 0;
138  myMP = mitk::Material::New();
139  myMP->SetColorCoefficient(colorCoefficient);
140  MITK_TEST_CONDITION(colorCoefficient == myMP->GetColorCoefficient(),
141  "Testing if a colorcoefficent was set correctly")
142  }
143  void testSetSpecularColor()
144  {
145  mitk::Material::Color color;
146  color.Set(0, 0, 0);
147  myMP = mitk::Material::New();
148  myMP->SetSpecularColor(color);
149  MITK_TEST_CONDITION(color == myMP->GetSpecularColor(), "Testing if a SpecularColor was set correctly")
150  }
151 
152  void testSetSpecularCoefficient()
153  {
154  myMP = mitk::Material::New();
155  double specularCoefficient = 1;
156  myMP->SetSpecularCoefficient(specularCoefficient);
157  MITK_TEST_CONDITION(specularCoefficient == myMP->GetSpecularCoefficient(),
158  "Testing if a SpecularCoefficient was set correctly")
159  }
160  void testSetSpecularPower()
161  {
162  myMP = mitk::Material::New();
163  double specularPower = 1;
164  myMP->SetSpecularPower(specularPower);
165  MITK_TEST_CONDITION(specularPower == myMP->GetSpecularPower(), "Testing if a SpecularPower was set correctly")
166  }
167  void testSetOpacity()
168  {
169  myMP = mitk::Material::New();
170  double opacity = 1;
171  myMP->SetOpacity(opacity);
172  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity was set correctly")
173  }
174 
175  void testSetInterpolation()
176  {
177  myMP = mitk::Material::New();
179  myMP->SetInterpolation(interpolation);
180  MITK_TEST_CONDITION(interpolation == myMP->GetInterpolation(), "Testing if a Interpolation was set correctly")
181  }
182  void testSetRepresentation()
183  {
184  myMP = mitk::Material::New();
186  myMP->SetRepresentation(representation);
187  MITK_TEST_CONDITION(representation == myMP->GetRepresentation(), "Testing if a Representation was set correctly")
188  }
189 
190  void testSetLineWidth()
191  {
192  myMP = mitk::Material::New();
193  double lineWidth = 1;
194  myMP->SetLineWidth(lineWidth);
195  MITK_TEST_CONDITION(lineWidth == myMP->GetLineWidth(), "Testing if a LineWidth was set correctly")
196  }
197 
198  void testInitialize()
199  {
200  mitk::Material::Color color;
201  color.Set(0, 0, 0);
202  double opacity = 1.0f;
203  double rgb = 0;
204  double colorCoefficient = 0;
205  double specularCoefficient = 0;
206  double specularPower = 0;
207 
208  myMP = mitk::Material::New(rgb, rgb, rgb, colorCoefficient, specularCoefficient, specularPower, opacity);
209  double lineWidth = 1;
210  myMP->SetLineWidth(lineWidth);
212  myMP->SetRepresentation(representation);
214  myMP->SetInterpolation(interpolation);
215  myMP->SetSpecularColor(color);
216  std::string name = "Hans Wurst";
217  myMP->SetName(name);
219  myMP2->Initialize(*myMP);
220  MITK_TEST_CONDITION(*myMP == *myMP2, "testing equality after .Intitialize")
221  }
222  void testOperatorequality()
223  {
224  {
225  mitk::Material::Color color;
226  color.Set(0, 0, 0);
227  double opacity = 1.0f;
228  double rgb = 0;
229  double colorCoefficient = 0;
230  double specularCoefficient = 0;
231  double specularPower = 0;
232 
233  myMP = mitk::Material::New(rgb, rgb, rgb, colorCoefficient, specularCoefficient, specularPower, opacity);
234  double lineWidth = 1;
235  myMP->SetLineWidth(lineWidth);
237  myMP->SetRepresentation(representation);
239  myMP->SetInterpolation(interpolation);
240  myMP->SetSpecularColor(color);
241  std::string name = "Hans Wurst";
242  myMP->SetName(name);
243 
244  mitk::Material::Color color2;
245  color2.Set(0, 0, 0);
246  double opacity2 = 1.0f;
247  double rgb2 = 0;
248  double colorCoefficient2 = 0;
249  double specularCoefficient2 = 0;
250  double specularPower2 = 0;
251 
253  mitk::Material::New(rgb2, rgb2, rgb2, colorCoefficient2, specularCoefficient2, specularPower2, opacity2);
254  double lineWidth2 = 1;
255  myMP2->SetLineWidth(lineWidth2);
257  myMP2->SetRepresentation(representation2);
259  myMP2->SetInterpolation(interpolation2);
260  myMP2->SetSpecularColor(color2);
261  std::string name2 = "Hans Wurst";
262  myMP2->SetName(name2);
263  MITK_TEST_CONDITION(*myMP == *myMP2, "testing equality Operator")
264  }
265  {
266  mitk::Material::Color color;
267  color.Set(0, 0, 0);
268  double opacity = 1.0f;
269  double rgb = 0;
270  double colorCoefficient = 0;
271  double specularCoefficient = 0;
272  double specularPower = 0;
273 
274  myMP = mitk::Material::New(rgb, rgb, rgb, colorCoefficient, specularCoefficient, specularPower, opacity);
275  double lineWidth = 1;
276  myMP->SetLineWidth(lineWidth);
278  myMP->SetRepresentation(representation);
280  myMP->SetInterpolation(interpolation);
281  myMP->SetSpecularColor(color);
282  std::string name = "Hans Wurst";
283  myMP->SetName(name);
284 
285  mitk::Material::Color color2;
286  color2.Set(0, 0, 0);
287  double opacity2 = 1.0f;
288  double rgb2 = 1;
289  double colorCoefficient2 = 0;
290  double specularCoefficient2 = 0;
291  double specularPower2 = 0;
292 
294  mitk::Material::New(rgb2, rgb2, rgb2, colorCoefficient2, specularCoefficient2, specularPower2, opacity2);
295  double lineWidth2 = 1;
296  myMP2->SetLineWidth(lineWidth2);
298  myMP2->SetRepresentation(representation2);
300  myMP2->SetInterpolation(interpolation2);
301  myMP2->SetSpecularColor(color2);
302  std::string name2 = "Hans Wurst";
303  myMP2->SetName(name2);
304  MITK_TEST_CONDITION(!(*myMP == *myMP2), "testing equality Operator")
305  }
306  }
307 
308  void testAssignable()
309  {
311  MITK_TEST_CONDITION(myMP->Assignable(*materialProp), "testing Assignable with Material")
312  }
313 
314  void testOperatorAssign()
315  {
317  *myMP2 = *myMP;
318  MITK_TEST_CONDITION(*myMP == *myMP2, "Testing Assignment Operator")
319  }
320 };
321 
322 int mitkMaterialTest(int /* argc */, char * /*argv*/ [])
323 {
324  // always start with this!
325  MITK_TEST_BEGIN("Material")
326 
327  MaterialTest materialTest;
328 
329  materialTest.testConstructor();
330  materialTest.testConstructorWithColorOpacity();
331  materialTest.testConstructorWithRedGreenBlueOpacity();
332  materialTest.testConstructorRedGreenBlueColorCoefficientSpecularCoefficientSpecularPowerOpacity();
333  materialTest.testConstructorColorColorCoefficientSpecularCoefficientSpecularPowerOpacity();
334  materialTest.testConstructorPropertyRedGreenBlueOpacityAndName();
335  materialTest.testAssignable();
336  materialTest.testOperatorAssign();
337  materialTest.testSetColor();
338  materialTest.testSetColorCoefficient();
339  materialTest.testSetSpecularColor();
340  materialTest.testSetSpecularCoefficient();
341  materialTest.testSetSpecularPower();
342  materialTest.testSetOpacity();
343  materialTest.testSetInterpolation();
344  materialTest.testSetRepresentation();
345  materialTest.testSetLineWidth();
346  materialTest.testInitialize();
347  materialTest.testOperatorequality();
348 
349  // first test: did this work?
350  // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
351  // it makes no sense to continue without an object.
352 
353  // write your own tests here and use the macros from mitkTestingMacros.h !!!
354  // do not write to std::cout and do not return from this function yourself!
355 
356  // always end with this!
357  MITK_TEST_END()
358 }
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
static Pointer New()
Definition: mitkMaterial.h:64
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
#define MITK_TEST_CONDITION(COND, MSG)
int mitkMaterialTest(int, char *[])
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
itk::RGBPixel< double > Color
Definition: mitkMaterial.h:37
and MITK_TEST_END()