Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkLevelWindowManagerTest.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 "itkMersenneTwisterRandomVariateGenerator.h"
14 #include "mitkLevelWindowManager.h"
17 #include <itkComposeImageFilter.h>
18 #include <itkEventObject.h>
19 #include <itkImageDuplicator.h>
20 #include <itkImageIterator.h>
21 #include <itkMersenneTwisterRandomVariateGenerator.h>
22 #include <mitkIOUtil.h>
23 #include <mitkImageCast.h>
24 #include <mitkTestingMacros.h>
25 
26 class mitkLevelWindowManagerTestClass
27 {
28 public:
29  static void TestInstantiation()
30  {
33  MITK_TEST_CONDITION_REQUIRED(manager.IsNotNull(), "Testing mitk::LevelWindowManager::New()");
34  }
35 
36  static void TestSetGetDataStorage()
37  {
40  MITK_TEST_OUTPUT(<< "Creating DataStorage: ");
42 
43  bool success = true;
44  try
45  {
46  manager->SetDataStorage(ds);
47  }
48  catch (std::exception &e)
49  {
50  success = false;
51  MITK_ERROR << "Exception: " << e.what();
52  }
53  MITK_TEST_CONDITION_REQUIRED(success, "Testing mitk::LevelWindowManager SetDataStorage() ");
54  MITK_TEST_CONDITION_REQUIRED(ds == manager->GetDataStorage(), "Testing mitk::LevelWindowManager GetDataStorage ");
55  }
56 
57  static void TestMethodsWithInvalidParameters()
58  {
62  manager->SetDataStorage(ds);
63 
64  bool success = false;
66  try
67  {
68  manager->SetLevelWindowProperty(levelWindowProperty);
69  }
70  catch (const mitk::Exception &)
71  {
72  success = true;
73  }
74  MITK_TEST_CONDITION(success, "Testing mitk::LevelWindowManager SetLevelWindowProperty with invalid parameter");
75  }
76 
77  static void TestOtherMethods()
78  {
82  manager->SetDataStorage(ds);
83 
84  MITK_TEST_CONDITION(manager->IsAutoTopMost(), "Testing mitk::LevelWindowManager isAutoTopMost");
85 
86  // It is not clear what the following code is supposed to test. The expression in
87  // the catch(...) block does have no effect, so success is always true.
88  // Related bugs are 13894 and 13889
89  /*
90  bool success = true;
91  try
92  {
93  mitk::LevelWindow levelWindow = manager->GetLevelWindow();
94  manager->SetLevelWindow(levelWindow);
95  }
96  catch (...)
97  {
98  success == false;
99  }
100  MITK_TEST_CONDITION(success,"Testing mitk::LevelWindowManager GetLevelWindow() and SetLevelWindow()");
101  */
102 
103  manager->SetAutoTopMostImage(true);
104  MITK_TEST_CONDITION(manager->IsAutoTopMost(), "Testing mitk::LevelWindowManager isAutoTopMost()");
105  }
106 
107  static void TestRemoveObserver(std::string testImageFile)
108  {
110  manager = mitk::LevelWindowManager::New();
112  manager->SetDataStorage(ds);
113 
114  // add multiple objects to the data storage => multiple observers should be created
115  mitk::Image::Pointer image1 = mitk::IOUtil::Load<mitk::Image>(testImageFile);
117  node1->SetData(image1);
118  mitk::Image::Pointer image2 = mitk::IOUtil::Load<mitk::Image>(testImageFile);
120  node2->SetData(image2);
121  ds->Add(node1);
122  ds->Add(node2);
123 
124  MITK_TEST_CONDITION_REQUIRED(manager->GetRelevantNodes()->size() == 2, "Test if nodes have been added");
126  static_cast<int>(manager->GetRelevantNodes()->size()) == manager->GetNumberOfObservers(),
127  "Test if number of nodes is similar to number of observers");
128 
129  mitk::Image::Pointer image3 = mitk::IOUtil::Load<mitk::Image>(testImageFile);
131  node3->SetData(image3);
132  ds->Add(node3);
133  MITK_TEST_CONDITION_REQUIRED(manager->GetRelevantNodes()->size() == 3, "Test if another node have been added");
135  static_cast<int>(manager->GetRelevantNodes()->size()) == manager->GetNumberOfObservers(),
136  "Test if number of nodes is similar to number of observers");
137 
138  ds->Remove(node1);
139  MITK_TEST_CONDITION_REQUIRED(manager->GetRelevantNodes()->size() == 2, "Deleted node 1 (test GetRelevantNodes())");
140  MITK_TEST_CONDITION_REQUIRED(manager->GetNumberOfObservers() == 2, "Deleted node 1 (test GetNumberOfObservers())");
141 
142  ds->Remove(node2);
143  MITK_TEST_CONDITION_REQUIRED(manager->GetRelevantNodes()->size() == 1, "Deleted node 2 (test GetRelevantNodes())");
144  MITK_TEST_CONDITION_REQUIRED(manager->GetNumberOfObservers() == 1, "Deleted node 2 (test GetNumberOfObservers())");
145 
146  ds->Remove(node3);
147  MITK_TEST_CONDITION_REQUIRED(manager->GetRelevantNodes()->size() == 0, "Deleted node 3 (test GetRelevantNodes())");
148  MITK_TEST_CONDITION_REQUIRED(manager->GetNumberOfObservers() == 0, "Deleted node 3 (test GetNumberOfObservers())");
149  }
150 
151  static bool VerifyRenderingModes()
152  {
157 
158  return ok;
159  }
160 
161  static void TestLevelWindowSliderVisibility(std::string testImageFile)
162  {
163  bool renderingModesValid = mitkLevelWindowManagerTestClass::VerifyRenderingModes();
164  if (!renderingModesValid)
165  {
166  MITK_ERROR << "Exception: Image Rendering.Mode property value types inconsistent.";
167  }
168 
170  manager = mitk::LevelWindowManager::New();
172  manager->SetDataStorage(ds);
173 
174  // add multiple objects to the data storage => multiple observers should be created
175  mitk::Image::Pointer image1 = mitk::IOUtil::Load<mitk::Image>(testImageFile);
177  node1->SetData(image1);
178  ds->Add(node1);
179 
180  mitk::DataNode::Pointer node2 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
181  mitk::DataNode::Pointer node3 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
182  std::vector<mitk::DataNode::Pointer> nodeVec;
183  // nodeVec.resize( 3 );
184  nodeVec.push_back(node1);
185  nodeVec.push_back(node2);
186  nodeVec.push_back(node3);
187 
188  typedef itk::Statistics::MersenneTwisterRandomVariateGenerator RandomGeneratorType;
189  RandomGeneratorType::Pointer rnd = RandomGeneratorType::New();
190  rnd->Initialize();
191 
192  for (unsigned int i = 0; i < 8; ++i)
193  {
194  unsigned int parity = i;
195 
196  for (unsigned int img = 0; img < 3; ++img)
197  {
198  if (parity & 1)
199  {
200  int mode = rnd->GetIntegerVariate() % 3;
201  nodeVec[img]->SetProperty("Image Rendering.Mode", mitk::RenderingModeProperty::New(mode));
202  }
203  else
204  {
205  int mode = rnd->GetIntegerVariate() % 2;
206  nodeVec[img]->SetProperty("Image Rendering.Mode", mitk::RenderingModeProperty::New(3 + mode));
207  }
208  parity >>= 1;
209  }
210 
212  renderingModesValid && ((!manager->GetLevelWindowProperty() && !i) || (manager->GetLevelWindowProperty() && i)),
213  "Testing level window property member according to rendering mode");
214  }
215  }
216 
217  static void TestSetLevelWindowProperty(std::string testImageFile)
218  {
221  manager->SetDataStorage(ds);
222 
223  // add multiple objects to the data storage => multiple observers should be created
224  mitk::DataNode::Pointer node3 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
225  mitk::DataNode::Pointer node2 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
226  mitk::DataNode::Pointer node1 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
227 
228  node3->SetIntProperty("layer", 1);
229  node2->SetIntProperty("layer", 2);
230  node1->SetIntProperty("layer", 3);
231 
232  manager->SetAutoTopMostImage(true);
233 
234  bool isImageForLevelWindow1, isImageForLevelWindow2, isImageForLevelWindow3;
235  node1->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow1);
236  node2->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow2);
237  node3->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow3);
238 
239  MITK_TEST_CONDITION(isImageForLevelWindow1 && !isImageForLevelWindow2 && !isImageForLevelWindow3,
240  "Testing exclusive imageForLevelWindow property for node 1.");
241 
242  manager->SetAutoTopMostImage(false);
243 
245  dynamic_cast<mitk::LevelWindowProperty *>(node2->GetProperty("levelwindow"));
246  manager->SetLevelWindowProperty(prop);
247  node1->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow1);
248  node2->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow2);
249  node3->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow3);
250 
251  MITK_TEST_CONDITION(!isImageForLevelWindow1 && isImageForLevelWindow2 && !isImageForLevelWindow3,
252  "Testing exclusive imageForLevelWindow property for node 2.");
253 
254  prop = dynamic_cast<mitk::LevelWindowProperty *>(node3->GetProperty("levelwindow"));
255  manager->SetLevelWindowProperty(prop);
256  node1->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow1);
257  node2->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow2);
258  node3->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow3);
259 
260  MITK_TEST_CONDITION(!isImageForLevelWindow1 && !isImageForLevelWindow2 && isImageForLevelWindow3,
261  "Testing exclusive imageForLevelWindow property for node 3.");
262 
263  prop = dynamic_cast<mitk::LevelWindowProperty *>(node1->GetProperty("levelwindow"));
264  manager->SetLevelWindowProperty(prop);
265  node1->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow1);
266  node2->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow2);
267  node3->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow3);
268 
269  MITK_TEST_CONDITION(isImageForLevelWindow1 && !isImageForLevelWindow2 && !isImageForLevelWindow3,
270  "Testing exclusive imageForLevelWindow property for node 3.");
271  }
272 
273  static void TestImageForLevelWindowOnVisibilityChange(std::string testImageFile)
274  {
277  manager->SetDataStorage(ds);
278 
279  // add multiple objects to the data storage => multiple observers should be created
280  mitk::DataNode::Pointer node3 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
281  mitk::DataNode::Pointer node2 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
282  mitk::DataNode::Pointer node1 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
283 
284  node3->SetIntProperty("layer", 1);
285  node2->SetIntProperty("layer", 2);
286  node1->SetIntProperty("layer", 3);
287 
288  manager->SetAutoTopMostImage(false);
289 
290  bool isImageForLevelWindow1, isImageForLevelWindow2, isImageForLevelWindow3;
291  node1->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow1);
292  node2->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow2);
293  node3->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow3);
294 
295  MITK_TEST_CONDITION(isImageForLevelWindow1 && !isImageForLevelWindow2 && !isImageForLevelWindow3,
296  "Testing initial imageForLevelWindow setting.");
297 
298  node1->SetVisibility(false);
299  node1->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow1);
300  node2->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow2);
301  node3->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow3);
302 
303  MITK_TEST_CONDITION(!isImageForLevelWindow1 && isImageForLevelWindow2 && !isImageForLevelWindow3,
304  "Testing exclusive imageForLevelWindow property for node 2.");
305 
306  node2->SetVisibility(false);
307  node1->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow1);
308  node2->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow2);
309  node3->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow3);
310 
311  MITK_TEST_CONDITION(!isImageForLevelWindow1 && !isImageForLevelWindow2 && isImageForLevelWindow3,
312  "Testing exclusive imageForLevelWindow property for node 3.");
313 
314  node3->SetVisibility(false);
315  node1->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow1);
316  node2->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow2);
317  node3->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow3);
318 
319  MITK_TEST_CONDITION(!isImageForLevelWindow1 && !isImageForLevelWindow2 && isImageForLevelWindow3,
320  "Testing exclusive imageForLevelWindow property for node 3.");
321 
322  node1->SetVisibility(true);
323  node1->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow1);
324  node2->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow2);
325  node3->GetBoolProperty("imageForLevelWindow", isImageForLevelWindow3);
326 
327  MITK_TEST_CONDITION(isImageForLevelWindow1 && !isImageForLevelWindow2 && !isImageForLevelWindow3,
328  "Testing exclusive imageForLevelWindow property for node 3.");
329  }
330 
331  static void TestImageForLevelWindowOnRandomPropertyChange(std::string testImageFile)
332  {
333  typedef std::vector<bool> BoolVecType;
334  typedef itk::Statistics::MersenneTwisterRandomVariateGenerator RandomGeneratorType;
335 
336  // initialize the data storage
339  manager->SetDataStorage(ds);
340 
341  mitk::DataNode::Pointer node3 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
342  mitk::DataNode::Pointer node2 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
343  mitk::DataNode::Pointer node1 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
344 
345  node3->SetIntProperty("layer", 1);
346  node2->SetIntProperty("layer", 2);
347  node1->SetIntProperty("layer", 3);
348 
349  // node visibilities
350  std::vector<bool> nodesVisible;
351  nodesVisible.resize(3);
352  std::fill(nodesVisible.begin(), nodesVisible.end(), true);
353 
354  // which node has the level window
355  std::vector<bool> nodesForLevelWindow;
356  nodesForLevelWindow.resize(3);
357  std::fill(nodesForLevelWindow.begin(), nodesForLevelWindow.end(), false);
358 
359  // the nodes themselves
360  std::vector<mitk::DataNode::Pointer> nodes;
361  nodes.push_back(node1);
362  nodes.push_back(node2);
363  nodes.push_back(node3);
364 
365  // status quo
366  manager->SetAutoTopMostImage(false);
367 
368  bool lvlWin1, lvlWin2, lvlWin3;
369  node1->GetBoolProperty("imageForLevelWindow", lvlWin1);
370  node2->GetBoolProperty("imageForLevelWindow", lvlWin2);
371  node3->GetBoolProperty("imageForLevelWindow", lvlWin3);
372 
373  MITK_TEST_CONDITION(lvlWin1 && !lvlWin2 && !lvlWin3, "Testing initial imageForLevelWindow setting.");
374 
375  nodesForLevelWindow[0] = lvlWin1;
376  nodesForLevelWindow[1] = lvlWin2;
377  nodesForLevelWindow[2] = lvlWin3;
378 
379  // prepare randomized visibility changes
380  RandomGeneratorType::Pointer ranGen = RandomGeneratorType::New();
381  ranGen->Initialize();
382 
383  int ranCount = 100;
384  int validCount = 0;
385  int invalidCount = 0;
386  int mustHaveLvlWindow = 4;
387  for (int run = 0; run < ranCount; ++run)
388  {
389  // toggle node visibility
390  int ran = ranGen->GetIntegerVariate(2);
391  nodes[ran]->SetBoolProperty("imageForLevelWindow", !nodesForLevelWindow[ran]);
392 
393  // one node must have the level window
394  std::vector<bool>::const_iterator found = std::find(nodesForLevelWindow.begin(), nodesForLevelWindow.end(), true);
395  if (found == nodesForLevelWindow.end())
396  {
397  break;
398  }
399 
400  // all invisible?
401  found = std::find(nodesVisible.begin(), nodesVisible.end(), true);
402 
403  if (!nodesForLevelWindow[ran])
404  {
405  mustHaveLvlWindow = pow(2, 2 - ran);
406  }
407  else
408  {
409  mustHaveLvlWindow = 4;
410  }
411 
412  // get the current status
413  node1->GetBoolProperty("imageForLevelWindow", lvlWin1);
414  node2->GetBoolProperty("imageForLevelWindow", lvlWin2);
415  node3->GetBoolProperty("imageForLevelWindow", lvlWin3);
416  nodesForLevelWindow[0] = lvlWin1;
417  nodesForLevelWindow[1] = lvlWin2;
418  nodesForLevelWindow[2] = lvlWin3;
419 
420  int hasLevelWindow = 0;
421  for (int i = 0; i < 3; ++i)
422  {
423  if (nodesForLevelWindow[i])
424  {
425  hasLevelWindow += pow(2, 2 - i);
426  }
427  }
428 
429  validCount += hasLevelWindow == mustHaveLvlWindow ? 1 : 0;
430 
431  // test sensitivity
432  int falseran = 0;
433  while (falseran == 0)
434  {
435  falseran = ranGen->GetIntegerVariate(7);
436  }
437  BoolVecType falseNodes;
438  falseNodes.push_back((falseran & 1) == 1 ? !lvlWin1 : lvlWin1);
439  falseran >>= 1;
440  falseNodes.push_back((falseran & 1) == 1 ? !lvlWin2 : lvlWin2);
441  falseran >>= 1;
442  falseNodes.push_back((falseran & 1) == 1 ? !lvlWin3 : lvlWin3);
443  int falseLevelWindow = 0;
444  for (int i = 0; i < 3; ++i)
445  {
446  if (falseNodes[i])
447  {
448  falseLevelWindow += pow(2, 2 - i);
449  }
450  }
451 
452  invalidCount += falseLevelWindow == mustHaveLvlWindow ? 0 : 1;
453 
454  // in case of errors proceed anyway
455  mustHaveLvlWindow = hasLevelWindow;
456  }
457 
458  MITK_TEST_CONDITION(validCount == ranCount, "Testing proper node for level window property.");
459  MITK_TEST_CONDITION(invalidCount == ranCount, "Sensitivity test.");
460  }
461 
462  static void TestImageForLevelWindowOnRandomVisibilityChange(std::string testImageFile)
463  {
464  typedef std::vector<bool> BoolVecType;
465  typedef itk::Statistics::MersenneTwisterRandomVariateGenerator RandomGeneratorType;
466 
467  // initialize the data storage
470  manager->SetDataStorage(ds);
471 
472  mitk::DataNode::Pointer node3 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
473  mitk::DataNode::Pointer node2 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
474  mitk::DataNode::Pointer node1 = mitk::IOUtil::Load(testImageFile, *ds)->GetElement(0);
475 
476  node3->SetIntProperty("layer", 1);
477  node2->SetIntProperty("layer", 2);
478  node1->SetIntProperty("layer", 3);
479 
480  // node visibilities
481  std::vector<bool> nodesVisible;
482  nodesVisible.resize(3);
483  std::fill(nodesVisible.begin(), nodesVisible.end(), true);
484 
485  // which node has the level window
486  std::vector<bool> nodesForLevelWindow;
487  nodesForLevelWindow.resize(3);
488  std::fill(nodesForLevelWindow.begin(), nodesForLevelWindow.end(), false);
489 
490  // the nodes themselves
491  std::vector<mitk::DataNode::Pointer> nodes;
492  nodes.push_back(node1);
493  nodes.push_back(node2);
494  nodes.push_back(node3);
495 
496  // status quo
497  manager->SetAutoTopMostImage(false);
498 
499  bool lvlWin1, lvlWin2, lvlWin3;
500  node1->GetBoolProperty("imageForLevelWindow", lvlWin1);
501  node2->GetBoolProperty("imageForLevelWindow", lvlWin2);
502  node3->GetBoolProperty("imageForLevelWindow", lvlWin3);
503 
504  MITK_TEST_CONDITION(lvlWin1 && !lvlWin2 && !lvlWin3, "Testing initial imageForLevelWindow setting.");
505 
506  nodesForLevelWindow[0] = lvlWin1;
507  nodesForLevelWindow[1] = lvlWin2;
508  nodesForLevelWindow[2] = lvlWin3;
509 
510  // prepare randomized visibility changes
511  RandomGeneratorType::Pointer ranGen = RandomGeneratorType::New();
512  ranGen->Initialize();
513 
514  int ranCount = 100;
515  int validCount = 0;
516  int invalidCount = 0;
517  int mustHaveLvlWindow = 4;
518  for (int run = 0; run < ranCount; ++run)
519  {
520  // toggle node visibility
521  int ran = ranGen->GetIntegerVariate(2);
522  nodesVisible[ran] = !nodesVisible[ran];
523  nodes[ran]->SetVisibility(nodesVisible[ran]);
524 
525  // one node must have the level window
526  std::vector<bool>::const_iterator found = std::find(nodesForLevelWindow.begin(), nodesForLevelWindow.end(), true);
527  if (found == nodesForLevelWindow.end())
528  {
529  break;
530  }
531  int ind = found - nodesForLevelWindow.begin();
532 
533  // all invisible?
534  found = std::find(nodesVisible.begin(), nodesVisible.end(), true);
535  bool allInvisible = (found == nodesVisible.end());
536 
537  // which node shall get the level window now
538  if (!allInvisible && !nodesVisible[ind])
539  {
540  int count = 0;
541  for (std::vector<bool>::const_iterator it = nodesVisible.begin(); it != nodesVisible.end(); ++it, ++count)
542  {
543  if (*it)
544  {
545  mustHaveLvlWindow = pow(2, 2 - count);
546  break;
547  }
548  }
549  }
550 
551  // get the current status
552  node1->GetBoolProperty("imageForLevelWindow", lvlWin1);
553  node2->GetBoolProperty("imageForLevelWindow", lvlWin2);
554  node3->GetBoolProperty("imageForLevelWindow", lvlWin3);
555  nodesForLevelWindow[0] = lvlWin1;
556  nodesForLevelWindow[1] = lvlWin2;
557  nodesForLevelWindow[2] = lvlWin3;
558 
559  int hasLevelWindow = 0;
560  for (int i = 0; i < 3; ++i)
561  {
562  if (nodesForLevelWindow[i])
563  {
564  hasLevelWindow += pow(2, 2 - i);
565  }
566  }
567 
568  validCount += hasLevelWindow == mustHaveLvlWindow ? 1 : 0;
569 
570  // test sensitivity
571  int falseran = 0;
572  while (falseran == 0)
573  {
574  falseran = ranGen->GetIntegerVariate(7);
575  }
576  BoolVecType falseNodes;
577  falseNodes.push_back((falseran & 1) == 1 ? !lvlWin1 : lvlWin1);
578  falseran >>= 1;
579  falseNodes.push_back((falseran & 1) == 1 ? !lvlWin2 : lvlWin2);
580  falseran >>= 1;
581  falseNodes.push_back((falseran & 1) == 1 ? !lvlWin3 : lvlWin3);
582  int falseLevelWindow = 0;
583  for (int i = 0; i < 3; ++i)
584  {
585  if (falseNodes[i])
586  {
587  falseLevelWindow += pow(2, 2 - i);
588  }
589  }
590 
591  invalidCount += falseLevelWindow == mustHaveLvlWindow ? 0 : 1;
592 
593  // in case of errors proceed anyway
594  mustHaveLvlWindow = hasLevelWindow;
595  }
596 
597  MITK_TEST_CONDITION(validCount == ranCount, "Testing proper node for level window property.");
598  MITK_TEST_CONDITION(invalidCount == ranCount, "Sensitivity test.");
599  }
600 };
601 
602 int mitkLevelWindowManagerTest(int argc, char *args[])
603 {
604  MITK_TEST_BEGIN("mitkLevelWindowManager");
605 
606  MITK_TEST_CONDITION_REQUIRED(argc >= 2, "Testing if test file is given.");
607  std::string testImage = args[1];
608 
609  mitkLevelWindowManagerTestClass::TestInstantiation();
610  mitkLevelWindowManagerTestClass::TestSetGetDataStorage();
611  mitkLevelWindowManagerTestClass::TestMethodsWithInvalidParameters();
612  mitkLevelWindowManagerTestClass::TestOtherMethods();
613  mitkLevelWindowManagerTestClass::TestRemoveObserver(testImage);
614  mitkLevelWindowManagerTestClass::TestLevelWindowSliderVisibility(testImage);
615  mitkLevelWindowManagerTestClass::TestSetLevelWindowProperty(testImage);
616  mitkLevelWindowManagerTestClass::TestImageForLevelWindowOnVisibilityChange(testImage);
617  mitkLevelWindowManagerTestClass::TestImageForLevelWindowOnRandomVisibilityChange(testImage);
618  mitkLevelWindowManagerTestClass::TestImageForLevelWindowOnRandomPropertyChange(testImage);
619 
620  MITK_TEST_END();
621 }
The LevelWindowProperty class Property for the mitk::LevelWindow.
static Pointer New()
#define MITK_ERROR
Definition: mitkLogMacros.h:20
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
#define MITK_TEST_OUTPUT(x)
Output some text.
static Pointer New()
An object of this class represents an exception of MITK. Please don&#39;t instantiate exceptions manually...
Definition: mitkException.h:45
#define MITK_TEST_CONDITION(COND, MSG)
int mitkLevelWindowManagerTest(int argc, char *args[])
and MITK_TEST_END()
static Pointer New()
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:489