Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkBaseProperty.h"
18 #include "mitkBaseRenderer.h"
19 #include "mitkDataNode.h"
20 #include "mitkMaterial.h"
21 #include "mitkTestingMacros.h"
22 #include <mitkColorProperty.h>
23 #include <mitkVtkPropRenderer.h>
24 
25 #include <iostream>
26 
36 class MaterialTest
37 {
38 public:
40 
41  MaterialTest() { myMP = NULL; }
42  void testConstructor()
43  {
44  myMP = mitk::Material::New();
45  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
46  }
47 
48  void testConstructorWithColorOpacity()
49  {
50  mitk::Color color;
51  color.Set(0, 0, 0);
52  double opacity = 1.0f;
53  myMP = mitk::Material::New(color, opacity);
54  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
55  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a Color object was set correctly")
56  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity object was set correctly")
57  }
58 
59  void testConstructorWithRedGreenBlueOpacity()
60  {
62  color.Set(0, 0, 0);
63  double opacity = 1.0f;
64  double rgb = 0;
65 
66  myMP = mitk::Material::New(rgb, rgb, rgb, opacity);
67  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
68  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a Color object was set correctly")
69  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity object was set correctly")
70  }
71 
72  void testConstructorRedGreenBlueColorCoefficientSpecularCoefficientSpecularPowerOpacity()
73  {
75  color.Set(0, 0, 0);
76  double opacity = 1.0f;
77  double rgb = 0;
78  double colorCoefficient = 0;
79  double specularCoefficient = 0;
80  double specularPower = 0;
81 
82  myMP = mitk::Material::New(rgb, rgb, rgb, colorCoefficient, specularCoefficient, specularPower, opacity);
83  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
84  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a Color object was set correctly")
85  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity object was set correctly")
86  MITK_TEST_CONDITION(specularCoefficient == myMP->GetSpecularCoefficient(),
87  "Testing if a Coefficient object was set correctly")
88  MITK_TEST_CONDITION(specularPower == myMP->GetSpecularPower(),
89  "Testing if a SpecularPower object was set correctly")
90  MITK_TEST_CONDITION(colorCoefficient == myMP->GetColorCoefficient(),
91  "Testing if a colorCoefficient object was set correctly")
92  }
93 
94  void testConstructorColorColorCoefficientSpecularCoefficientSpecularPowerOpacity()
95  {
97  color.Set(0, 0, 0);
98  double opacity = 1.0f;
99  double rgb = 0;
100  double colorCoefficient = 0;
101  double specularCoefficient = 0;
102  double specularPower = 0;
103 
104  myMP = mitk::Material::New(rgb, rgb, rgb, colorCoefficient, specularCoefficient, specularPower, opacity);
105  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
106  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a Color object was set correctly")
107  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity object was set correctly")
108  MITK_TEST_CONDITION(specularCoefficient == myMP->GetSpecularCoefficient(),
109  "Testing if a Coefficient object was set correctly")
110  MITK_TEST_CONDITION(specularPower == myMP->GetSpecularPower(),
111  "Testing if a SpecularPower object was set correctly")
112  }
113 
114  void testConstructorPropertyRedGreenBlueOpacityAndName()
115  {
116  mitk::Material::Pointer reference = myMP;
117  double opacity = 1.0f;
118  double rgb = 0;
119  std::string name = "Hans Wurst";
120 
121  myMP = mitk::Material::New(*reference, rgb, rgb, rgb, opacity, name);
122  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
123  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity object was set correctly")
124  // MITK_TEST_CONDITION( name.compare(myMP->GetName(),0,9), "Testing if a Name object was set correctly" )
125  }
126  void testSetColor()
127  {
128  mitk::Material::Color color;
129  color.Set(0, 0, 0);
130  myMP = mitk::Material::New();
131  myMP->SetColor(color);
132  MITK_TEST_CONDITION_REQUIRED(myMP.IsNotNull(), "Testing instantiation")
133  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a color was set correctly")
134  color.Set(0, 0, 0);
135  myMP->SetColor(color);
136  MITK_TEST_CONDITION(color == myMP->GetColor(), "Testing if a color was set correctly")
137  }
138 
139  void testSetColorCoefficient()
140  {
141  double colorCoefficient = 0;
142  myMP = mitk::Material::New();
143  myMP->SetColorCoefficient(colorCoefficient);
144  MITK_TEST_CONDITION(colorCoefficient == myMP->GetColorCoefficient(),
145  "Testing if a colorcoefficent was set correctly")
146  }
147  void testSetSpecularColor()
148  {
149  mitk::Material::Color color;
150  color.Set(0, 0, 0);
151  myMP = mitk::Material::New();
152  myMP->SetSpecularColor(color);
153  MITK_TEST_CONDITION(color == myMP->GetSpecularColor(), "Testing if a SpecularColor was set correctly")
154  }
155 
156  void testSetSpecularCoefficient()
157  {
158  myMP = mitk::Material::New();
159  double specularCoefficient = 1;
160  myMP->SetSpecularCoefficient(specularCoefficient);
161  MITK_TEST_CONDITION(specularCoefficient == myMP->GetSpecularCoefficient(),
162  "Testing if a SpecularCoefficient was set correctly")
163  }
164  void testSetSpecularPower()
165  {
166  myMP = mitk::Material::New();
167  double specularPower = 1;
168  myMP->SetSpecularPower(specularPower);
169  MITK_TEST_CONDITION(specularPower == myMP->GetSpecularPower(), "Testing if a SpecularPower was set correctly")
170  }
171  void testSetOpacity()
172  {
173  myMP = mitk::Material::New();
174  double opacity = 1;
175  myMP->SetOpacity(opacity);
176  MITK_TEST_CONDITION(opacity == myMP->GetOpacity(), "Testing if a Opacity was set correctly")
177  }
178 
179  void testSetInterpolation()
180  {
181  myMP = mitk::Material::New();
183  myMP->SetInterpolation(interpolation);
184  MITK_TEST_CONDITION(interpolation == myMP->GetInterpolation(), "Testing if a Interpolation was set correctly")
185  }
186  void testSetRepresentation()
187  {
188  myMP = mitk::Material::New();
190  myMP->SetRepresentation(representation);
191  MITK_TEST_CONDITION(representation == myMP->GetRepresentation(), "Testing if a Representation was set correctly")
192  }
193 
194  void testSetLineWidth()
195  {
196  myMP = mitk::Material::New();
197  double lineWidth = 1;
198  myMP->SetLineWidth(lineWidth);
199  MITK_TEST_CONDITION(lineWidth == myMP->GetLineWidth(), "Testing if a LineWidth was set correctly")
200  }
201 
202  void testInitialize()
203  {
204  mitk::Material::Color color;
205  color.Set(0, 0, 0);
206  double opacity = 1.0f;
207  double rgb = 0;
208  double colorCoefficient = 0;
209  double specularCoefficient = 0;
210  double specularPower = 0;
211 
212  myMP = mitk::Material::New(rgb, rgb, rgb, colorCoefficient, specularCoefficient, specularPower, opacity);
213  double lineWidth = 1;
214  myMP->SetLineWidth(lineWidth);
216  myMP->SetRepresentation(representation);
218  myMP->SetInterpolation(interpolation);
219  myMP->SetSpecularColor(color);
220  std::string name = "Hans Wurst";
221  myMP->SetName(name);
223  myMP2->Initialize(*myMP);
224  MITK_TEST_CONDITION(*myMP == *myMP2, "testing equality after .Intitialize")
225  }
226  void testOperatorequality()
227  {
228  {
229  mitk::Material::Color color;
230  color.Set(0, 0, 0);
231  double opacity = 1.0f;
232  double rgb = 0;
233  double colorCoefficient = 0;
234  double specularCoefficient = 0;
235  double specularPower = 0;
236 
237  myMP = mitk::Material::New(rgb, rgb, rgb, colorCoefficient, specularCoefficient, specularPower, opacity);
238  double lineWidth = 1;
239  myMP->SetLineWidth(lineWidth);
241  myMP->SetRepresentation(representation);
243  myMP->SetInterpolation(interpolation);
244  myMP->SetSpecularColor(color);
245  std::string name = "Hans Wurst";
246  myMP->SetName(name);
247 
248  mitk::Material::Color color2;
249  color2.Set(0, 0, 0);
250  double opacity2 = 1.0f;
251  double rgb2 = 0;
252  double colorCoefficient2 = 0;
253  double specularCoefficient2 = 0;
254  double specularPower2 = 0;
255 
257  mitk::Material::New(rgb2, rgb2, rgb2, colorCoefficient2, specularCoefficient2, specularPower2, opacity2);
258  double lineWidth2 = 1;
259  myMP2->SetLineWidth(lineWidth2);
261  myMP2->SetRepresentation(representation2);
263  myMP2->SetInterpolation(interpolation2);
264  myMP2->SetSpecularColor(color2);
265  std::string name2 = "Hans Wurst";
266  myMP2->SetName(name2);
267  MITK_TEST_CONDITION(*myMP == *myMP2, "testing equality Operator")
268  }
269  {
270  mitk::Material::Color color;
271  color.Set(0, 0, 0);
272  double opacity = 1.0f;
273  double rgb = 0;
274  double colorCoefficient = 0;
275  double specularCoefficient = 0;
276  double specularPower = 0;
277 
278  myMP = mitk::Material::New(rgb, rgb, rgb, colorCoefficient, specularCoefficient, specularPower, opacity);
279  double lineWidth = 1;
280  myMP->SetLineWidth(lineWidth);
282  myMP->SetRepresentation(representation);
284  myMP->SetInterpolation(interpolation);
285  myMP->SetSpecularColor(color);
286  std::string name = "Hans Wurst";
287  myMP->SetName(name);
288 
289  mitk::Material::Color color2;
290  color2.Set(0, 0, 0);
291  double opacity2 = 1.0f;
292  double rgb2 = 1;
293  double colorCoefficient2 = 0;
294  double specularCoefficient2 = 0;
295  double specularPower2 = 0;
296 
298  mitk::Material::New(rgb2, rgb2, rgb2, colorCoefficient2, specularCoefficient2, specularPower2, opacity2);
299  double lineWidth2 = 1;
300  myMP2->SetLineWidth(lineWidth2);
302  myMP2->SetRepresentation(representation2);
304  myMP2->SetInterpolation(interpolation2);
305  myMP2->SetSpecularColor(color2);
306  std::string name2 = "Hans Wurst";
307  myMP2->SetName(name2);
308  MITK_TEST_CONDITION(!(*myMP == *myMP2), "testing equality Operator")
309  }
310  }
311 
312  void testAssignable()
313  {
315  MITK_TEST_CONDITION(myMP->Assignable(*materialProp), "testing Assignable with Material")
316  }
317 
318  void testOperatorAssign()
319  {
321  *myMP2 = *myMP;
322  MITK_TEST_CONDITION(*myMP == *myMP2, "Testing Assignment Operator")
323  }
324 };
325 
326 int mitkMaterialTest(int /* argc */, char * /*argv*/ [])
327 {
328  // always start with this!
329  MITK_TEST_BEGIN("Material")
330 
331  MaterialTest materialTest;
332 
333  materialTest.testConstructor();
334  materialTest.testConstructorWithColorOpacity();
335  materialTest.testConstructorWithRedGreenBlueOpacity();
336  materialTest.testConstructorRedGreenBlueColorCoefficientSpecularCoefficientSpecularPowerOpacity();
337  materialTest.testConstructorColorColorCoefficientSpecularCoefficientSpecularPowerOpacity();
338  materialTest.testConstructorPropertyRedGreenBlueOpacityAndName();
339  materialTest.testAssignable();
340  materialTest.testOperatorAssign();
341  materialTest.testSetColor();
342  materialTest.testSetColorCoefficient();
343  materialTest.testSetSpecularColor();
344  materialTest.testSetSpecularCoefficient();
345  materialTest.testSetSpecularPower();
346  materialTest.testSetOpacity();
347  materialTest.testSetInterpolation();
348  materialTest.testSetRepresentation();
349  materialTest.testSetLineWidth();
350  materialTest.testInitialize();
351  materialTest.testOperatorequality();
352 
353  // first test: did this work?
354  // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
355  // it makes no sense to continue without an object.
356 
357  // write your own tests here and use the macros from mitkTestingMacros.h !!!
358  // do not write to std::cout and do not return from this function yourself!
359 
360  // always end with this!
361  MITK_TEST_END()
362 }
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
static Pointer New()
Definition: mitkMaterial.h:68
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:41
and MITK_TEST_END()