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