Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkLevelWindowTest.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 "mitkImageWriteAccessor.h"
18 #include "mitkLevelWindow.h"
19 #include <mitkImage.h>
20 
21 /*
22 * Reseting the Levelwindow to default values:
23 * i.e. Range = -1000..1000, Level = 0 and Window = 500
24 */
26 {
27  // Default window bounds
28  lw.SetRangeMinMax(-10000, 10000);
29  lw.SetLevelWindow(0, 500, false);
30  if (lw.GetRangeMin() != -10000 || lw.GetRangeMax() != 10000 || lw.GetLevel() != 0 || lw.GetWindow() != 500)
31  {
32  std::cout << "[Failed] To reset Levelwindow" << std::endl;
33  }
34 }
35 
36 int mitkLevelWindowTest(int, char *[])
37 {
38  std::cout << "Testing mitk::LevelWindow " << std::endl;
39 
40  std::cout << "Testing mitk::LevelWindow constructor with Level and Window ";
41  auto levWin = new mitk::LevelWindow(256, 500);
42  std::cout << "[PASSED]" << std::endl;
43 
44  std::cout << "Testing mitk::LevelWindow GetDefaultWindow ";
45  mitk::ScalarType defaultWindow = levWin->GetDefaultWindow();
46  if (!(defaultWindow == 500))
47  {
48  std::cout << defaultWindow << " [FAILED]" << std::endl;
49  return EXIT_FAILURE;
50  }
51  std::cout << "[PASSED]" << std::endl;
52 
53  std::cout << "Testing mitk::LevelWindow GetDefaultLevel ";
54  mitk::ScalarType defaultLevel = levWin->GetDefaultLevel();
55  if (!(defaultLevel == 256))
56  {
57  std::cout << "[FAILED]" << std::endl;
58  return EXIT_FAILURE;
59  }
60  std::cout << "[PASSED]" << std::endl;
61 
62  std::cout << "Testing mitk::LevelWindow GetWindow ";
63  mitk::ScalarType window = levWin->GetWindow();
64  if (!(window == 500))
65  {
66  std::cout << "[FAILED]" << std::endl;
67  return EXIT_FAILURE;
68  }
69  std::cout << "[PASSED]" << std::endl;
70 
71  std::cout << "Testing mitk::LevelWindow GetMin ";
72  if (!(levWin->GetLowerWindowBound() == 6))
73  {
74  std::cout << "[FAILED]" << std::endl;
75  return EXIT_FAILURE;
76  }
77  std::cout << "[PASSED]" << std::endl;
78 
79  std::cout << "Testing mitk::LevelWindow GetMax ";
80  if (!(levWin->GetUpperWindowBound() == 506))
81  {
82  std::cout << "[FAILED]" << std::endl;
83  return EXIT_FAILURE;
84  }
85  std::cout << "[PASSED]" << std::endl;
86 
87  std::cout << "Testing mitk::LevelWindow GetLevel ";
88  mitk::ScalarType level = levWin->GetLevel();
89  if (!(level == 256))
90  {
91  std::cout << "[FAILED]" << std::endl;
92  return EXIT_FAILURE;
93  }
94  std::cout << "[PASSED]" << std::endl;
95 
96  std::cout << "Testing mitk::LevelWindow GetWindow : GetDefaultWindow ";
97  if (!(defaultWindow == window))
98  {
99  std::cout << "[FAILED]" << std::endl;
100  return EXIT_FAILURE;
101  }
102  std::cout << "[PASSED]" << std::endl;
103 
104  std::cout << "Testing mitk::LevelWindow GetLevel : GetDefaultLevel ";
105  if (!(defaultLevel == level))
106  {
107  std::cout << "[FAILED]" << std::endl;
108  return EXIT_FAILURE;
109  }
110  std::cout << "[PASSED]" << std::endl;
111 
112  std::cout << "Testing mitk::LevelWindow SetLevelWindow ";
113  levWin->SetLevelWindow(20, 100);
114  if (!(levWin->GetLevel() == 20))
115  {
116  std::cout << "[FAILED]" << std::endl;
117  return EXIT_FAILURE;
118  }
119  if (!(levWin->GetWindow() == 100))
120  {
121  std::cout << "[FAILED]" << std::endl;
122  return EXIT_FAILURE;
123  }
124  std::cout << "[PASSED]" << std::endl;
125 
126  std::cout << "Testing mitk::LevelWindow SetLevelWindow ";
127  levWin->SetLevelWindow(levWin->GetDefaultLevel(), levWin->GetDefaultWindow());
128  if (!(levWin->GetLevel() == 256) && !(levWin->GetWindow() == 500))
129  {
130  std::cout << "[FAILED]" << std::endl;
131  return EXIT_FAILURE;
132  }
133  std::cout << "[PASSED]" << std::endl;
134 
135  std::cout << "Testing mitk::LevelWindow SetDefaultLevelWindow ";
136  levWin->SetDefaultLevelWindow(20, 200);
137  if (!(levWin->GetDefaultLevel() == 20) && !(levWin->GetDefaultWindow() == 200))
138  {
139  std::cout << "[FAILED]" << std::endl;
140  return EXIT_FAILURE;
141  }
142  std::cout << "[PASSED]" << std::endl;
143 
144  std::cout << "Testing mitk::LevelWindow ResetDefaultLevelWindow ";
145  levWin->SetLevelWindow(100, 50);
146  levWin->ResetDefaultLevelWindow();
147  // double a = levWin->GetLevel();
148  // double d = levWin->GetWindow();
149 
150  if (!((levWin->GetLevel() == 20) && (levWin->GetWindow() == 200)))
151  {
152  std::cout << "[FAILED]" << std::endl;
153  return EXIT_FAILURE;
154  }
155  std::cout << "[PASSED]" << std::endl;
156 
157  std::cout << "Testing mitk::LevelWindow SetWindowBounds ";
158  levWin->SetWindowBounds(0, 2);
159  if (!((levWin->GetLowerWindowBound() == 0) && (levWin->GetUpperWindowBound() == 2) && (levWin->GetLevel() == 1) &&
160  (levWin->GetWindow() == 2)))
161  {
162  std::cout << "[FAILED]" << std::endl;
163  return EXIT_FAILURE;
164  }
165  levWin->ResetDefaultLevelWindow();
166  std::cout << "[PASSED]" << std::endl;
167 
168  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with rangemin = rangemax";
169  levWin->SetRangeMinMax(2000, 2000);
170  if (!(levWin->GetRangeMin() == 1999 && levWin->GetRangeMax() == 2000))
171  {
172  std::cout << "[FAILED]" << std::endl;
173  return EXIT_FAILURE;
174  }
175  std::cout << "[PASSED]" << std::endl;
176 
177  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with rangemin > rangemax";
178  levWin->SetRangeMinMax(2100, 2000);
179  if (!(levWin->GetRangeMin() == 2000 && levWin->GetRangeMax() == 2100))
180  {
181  std::cout << "[FAILED]" << std::endl;
182  return EXIT_FAILURE;
183  }
184  std::cout << "[PASSED]" << std::endl;
185 
186  std::cout << "Testing mitk::LevelWindow SetRangeMinMax ";
187  levWin->SetRangeMinMax(-1000, 2000);
188  std::cout << "[PASSED]" << std::endl;
189 
190  std::cout << "Testing mitk::LevelWindow GetRangeMin ";
191  if (!(levWin->GetRangeMin() == -1000))
192  {
193  std::cout << "[FAILED]" << std::endl;
194  return EXIT_FAILURE;
195  }
196  std::cout << "[PASSED]" << std::endl;
197 
198  std::cout << "Testing mitk::LevelWindow GetRangeMax ";
199  if (!(levWin->GetRangeMax() == 2000))
200  {
201  std::cout << "[FAILED]" << std::endl;
202  return EXIT_FAILURE;
203  }
204  std::cout << "[PASSED]" << std::endl;
205 
206  std::cout << "Testing mitk::LevelWindow GetRange ";
207  if (!((levWin->GetRangeMax() - levWin->GetRangeMin()) == levWin->GetRange()))
208  {
209  std::cout << "[FAILED]" << std::endl;
210  return EXIT_FAILURE;
211  }
212  std::cout << "[PASSED]" << std::endl;
213 
214  std::cout << "Testing mitk::LevelWindow SetDefaultBoundaries with rangemin = rangemax";
215  levWin->SetDefaultBoundaries(2000, 2000);
216  if (!(levWin->GetDefaultLowerBound() == 1999 && levWin->GetDefaultUpperBound() == 2000))
217  {
218  std::cout << "[FAILED]" << std::endl;
219  return EXIT_FAILURE;
220  }
221  std::cout << "[PASSED]" << std::endl;
222 
223  std::cout << "Testing mitk::LevelWindow SetDefaultBoundaries with rangemin > rangemax";
224  levWin->SetDefaultBoundaries(2100, 2000);
225  if (!(levWin->GetDefaultLowerBound() == 2000 && levWin->GetDefaultUpperBound() == 2100))
226  {
227  std::cout << "[FAILED]" << std::endl;
228  return EXIT_FAILURE;
229  }
230  std::cout << "[PASSED]" << std::endl;
231 
232  std::cout << "Testing mitk::LevelWindow SetDefaultBoundaries ";
233  levWin->SetDefaultBoundaries(-2000, 8000);
234  std::cout << "[PASSED]" << std::endl;
235 
236  std::cout << "Testing mitk::LevelWindow GetDefaultLowerBound ";
237  if (!(levWin->GetDefaultLowerBound() == -2000))
238  {
239  std::cout << "[FAILED]" << std::endl;
240  return EXIT_FAILURE;
241  }
242  std::cout << "[PASSED]" << std::endl;
243 
244  std::cout << "Testing mitk::LevelWindow GetDefaultUpperBound ";
245  if (!(levWin->GetDefaultUpperBound() == 8000))
246  {
247  std::cout << "[FAILED]" << std::endl;
248  return EXIT_FAILURE;
249  }
250  std::cout << "[PASSED]" << std::endl;
251 
252  std::cout << "Testing mitk::LevelWindow ResetDefaultRangeMinMax ";
253  levWin->ResetDefaultRangeMinMax();
254  if (!((levWin->GetRangeMin() == levWin->GetDefaultLowerBound()) &&
255  (levWin->GetRangeMax() == levWin->GetDefaultUpperBound())))
256  {
257  std::cout << "[FAILED]" << std::endl;
258  return EXIT_FAILURE;
259  }
260  std::cout << "[PASSED]" << std::endl;
261 
262  std::cout << "Testing mitk::LevelWindow minRange > maxRange ";
263  levWin->SetRangeMinMax(2000, 1000);
264  if (!((levWin->GetRangeMin() == 1000) && (levWin->GetRangeMax() == 2000)))
265  {
266  std::cout << "[FAILED]" << std::endl;
267  return EXIT_FAILURE;
268  }
269  levWin->SetRangeMinMax(2000, -1000);
270  if (!((levWin->GetRangeMin() == -1000) && (levWin->GetRangeMax() == 2000)))
271  {
272  std::cout << "[FAILED]" << std::endl;
273  return EXIT_FAILURE;
274  }
275  levWin->SetRangeMinMax(-2000, -3000);
276  if (!((levWin->GetRangeMin() == -3000) && (levWin->GetRangeMax() == -2000)))
277  {
278  std::cout << "[FAILED]" << std::endl;
279  return EXIT_FAILURE;
280  }
281  levWin->SetRangeMinMax(0, -1000);
282  if (!((levWin->GetRangeMin() == -1000) && (levWin->GetRangeMax() == 0)))
283  {
284  std::cout << "[FAILED]" << std::endl;
285  return EXIT_FAILURE;
286  }
287  levWin->SetRangeMinMax(2000, 0);
288  if (!((levWin->GetRangeMin() == 0) && (levWin->GetRangeMax() == 2000)))
289  {
290  std::cout << "[FAILED]" << std::endl;
291  return EXIT_FAILURE;
292  }
293  levWin->SetRangeMinMax(-10000, 10000);
294  std::cout << "[PASSED]" << std::endl;
295 
296  std::cout << "Testing mitk::LevelWindow defaultMinRange > defaultMaxRange ";
297  levWin->SetDefaultBoundaries(2000, 1000);
298  if (!((levWin->GetDefaultLowerBound() == 1000) && (levWin->GetDefaultUpperBound() == 2000)))
299  {
300  std::cout << "[FAILED]" << std::endl;
301  return EXIT_FAILURE;
302  }
303  levWin->SetDefaultBoundaries(2000, -1000);
304  if (!((levWin->GetDefaultLowerBound() == -1000) && (levWin->GetDefaultUpperBound() == 2000)))
305  {
306  std::cout << "[FAILED]" << std::endl;
307  return EXIT_FAILURE;
308  }
309  levWin->SetDefaultBoundaries(-2000, -3000);
310  if (!((levWin->GetDefaultLowerBound() == -3000) && (levWin->GetDefaultUpperBound() == -2000)))
311  {
312  std::cout << "[FAILED]" << std::endl;
313  return EXIT_FAILURE;
314  }
315  levWin->SetDefaultBoundaries(0, -1000);
316  if (!((levWin->GetDefaultLowerBound() == -1000) && (levWin->GetDefaultUpperBound() == 0)))
317  {
318  std::cout << "[FAILED]" << std::endl;
319  return EXIT_FAILURE;
320  }
321  levWin->SetDefaultBoundaries(2000, 0);
322  if (!((levWin->GetDefaultLowerBound() == 0) && (levWin->GetDefaultUpperBound() == 2000)))
323  {
324  std::cout << "[FAILED]" << std::endl;
325  return EXIT_FAILURE;
326  }
327  levWin->SetDefaultBoundaries(-10000, 10000);
328  std::cout << "[PASSED]" << std::endl;
329 
330  std::cout << "Testing mitk::LevelWindow min > max ";
331  levWin->SetWindowBounds(2000, 1000);
332  if (!((levWin->GetLowerWindowBound() == 1000) && (levWin->GetUpperWindowBound() == 2000)))
333  {
334  std::cout << "[FAILED]" << std::endl;
335  return EXIT_FAILURE;
336  }
337  levWin->SetWindowBounds(2000, -1000);
338  if (!((levWin->GetLowerWindowBound() == -1000) && (levWin->GetUpperWindowBound() == 2000)))
339  {
340  std::cout << "[FAILED]" << std::endl;
341  return EXIT_FAILURE;
342  }
343  levWin->SetWindowBounds(-2000, -3000);
344  if (!((levWin->GetLowerWindowBound() == -3000) && (levWin->GetUpperWindowBound() == -2000)))
345  {
346  std::cout << "[FAILED]" << std::endl;
347  return EXIT_FAILURE;
348  }
349  levWin->SetWindowBounds(0, -1000);
350  if (!((levWin->GetLowerWindowBound() == -1000) && (levWin->GetUpperWindowBound() == 0)))
351  {
352  std::cout << "[FAILED]" << std::endl;
353  return EXIT_FAILURE;
354  }
355  levWin->SetWindowBounds(2000, 0);
356  if (!((levWin->GetLowerWindowBound() == 0) && (levWin->GetUpperWindowBound() == 2000)))
357  {
358  std::cout << "[FAILED]" << std::endl;
359  return EXIT_FAILURE;
360  }
361  levWin->ResetDefaultLevelWindow();
362  std::cout << "[PASSED]" << std::endl;
363 
364  // minmax > maxrange, minmax < minrange, min<maxrange & max >maxrange, min < minrange & max > minrange
365  // max < minrange & min > minrange, min > maxrange & max < maxrange, min < minrange & max > maxrange
366  // min > maxrange & max < minrange
367  std::cout << "Testing mitk::LevelWindow max > min > maxrange autoexpand = FALSE";
368  levWin->SetWindowBounds(11000, 12000, false);
369  if (!((levWin->GetLowerWindowBound() == 9999) && (levWin->GetUpperWindowBound() == 10000)))
370  {
371  std::cout << "[FAILED]" << levWin->GetLowerWindowBound() << "," << levWin->GetUpperWindowBound() << std::endl;
372  return EXIT_FAILURE;
373  }
374  levWin->ResetDefaultLevelWindow();
375  std::cout << "[PASSED]" << std::endl;
376 
377  std::cout << "Testing mitk::LevelWindow max > min > maxrange autoexpand = TRUE";
378  levWin->SetWindowBounds(11000, 12000);
379  if (!((levWin->GetLowerWindowBound() == 11000) && (levWin->GetUpperWindowBound() == 12000)))
380  {
381  std::cout << "[FAILED]" << levWin->GetLowerWindowBound() << "," << levWin->GetUpperWindowBound() << std::endl;
382  return EXIT_FAILURE;
383  }
384  levWin->ResetDefaultLevelWindow();
385  std::cout << "[PASSED]" << std::endl;
386 
387  // Reset default window
388  resetLevelWindow(*levWin);
389 
390  std::cout << "Testing mitk::LevelWindow min > max > maxrange autoexpand = FALSE";
391  levWin->SetWindowBounds(12000, 11000, false);
392  if (!((levWin->GetLowerWindowBound() == 9999) && (levWin->GetUpperWindowBound() == 10000)))
393  {
394  std::cout << "[FAILED]" << std::endl;
395  return EXIT_FAILURE;
396  }
397  levWin->ResetDefaultLevelWindow();
398  std::cout << "[PASSED]" << std::endl;
399 
400  std::cout << "Testing mitk::LevelWindow min > max > maxrange autoexpand = TRUE";
401  levWin->SetWindowBounds(12000, 11000);
402  if (!((levWin->GetLowerWindowBound() == 11000) && (levWin->GetUpperWindowBound() == 12000)))
403  {
404  std::cout << "[FAILED]" << std::endl;
405  return EXIT_FAILURE;
406  }
407  levWin->ResetDefaultLevelWindow();
408  std::cout << "[PASSED]" << std::endl;
409 
410  resetLevelWindow(*levWin);
411 
412  std::cout << "Testing mitk::LevelWindow min < max < minrange autoexpand = FALSE";
413  levWin->SetWindowBounds(-12000, -11000, false);
414  if (!((levWin->GetLowerWindowBound() == -10000) && (levWin->GetUpperWindowBound() == -9999)))
415  {
416  std::cout << "[FAILED]" << std::endl;
417  return EXIT_FAILURE;
418  }
419  levWin->ResetDefaultLevelWindow();
420  std::cout << "[PASSED]" << std::endl;
421 
422  std::cout << "Testing mitk::LevelWindow min < max < minrange autoexpand = TRUE";
423  levWin->SetWindowBounds(-12000, -11000);
424  if (!((levWin->GetLowerWindowBound() == -12000) && (levWin->GetUpperWindowBound() == -11000)))
425  {
426  std::cout << "[FAILED]" << std::endl;
427  return EXIT_FAILURE;
428  }
429  levWin->ResetDefaultLevelWindow();
430  std::cout << "[PASSED]" << std::endl;
431 
432  resetLevelWindow(*levWin);
433 
434  std::cout << "Testing mitk::LevelWindow max < min < minrange autoexpand = FALSE";
435  levWin->SetWindowBounds(-11000, -12000, false);
436  if (!((levWin->GetLowerWindowBound() == -10000) && (levWin->GetUpperWindowBound() == -9999)))
437  {
438  std::cout << "[FAILED]: Expected (-10000, -9999): " << levWin->GetLowerWindowBound() << " - "
439  << levWin->GetUpperWindowBound() << std::endl;
440  return EXIT_FAILURE;
441  }
442  levWin->ResetDefaultLevelWindow();
443  std::cout << "[PASSED]" << std::endl;
444 
445  std::cout << "Testing mitk::LevelWindow max < min < minrange autoexpand = TRUE";
446  levWin->SetWindowBounds(-11000, -12000);
447  if (!((levWin->GetLowerWindowBound() == -12000) && (levWin->GetUpperWindowBound() == -11000)))
448  {
449  std::cout << "[FAILED]" << std::endl;
450  return EXIT_FAILURE;
451  }
452  levWin->ResetDefaultLevelWindow();
453  std::cout << "[PASSED]" << std::endl;
454 
455  resetLevelWindow(*levWin);
456 
457  std::cout << "Testing mitk::LevelWindow min < maxrang & max > maxrange autoexpand = FALSE";
458  levWin->SetWindowBounds(9999, 12000, false);
459  if (!((levWin->GetLowerWindowBound() == 9999) && (levWin->GetUpperWindowBound() == 10000)))
460  {
461  std::cout << "[FAILED]" << std::endl;
462  return EXIT_FAILURE;
463  }
464  levWin->ResetDefaultLevelWindow();
465  std::cout << "[PASSED]" << std::endl;
466 
467  std::cout << "Testing mitk::LevelWindow min < maxrang & max > maxrange autoexpand = TRUE";
468  levWin->SetWindowBounds(9999, 12000);
469  if (!((levWin->GetLowerWindowBound() == 9999) && (levWin->GetUpperWindowBound() == 12000)))
470  {
471  std::cout << "[FAILED]" << std::endl;
472  return EXIT_FAILURE;
473  }
474  levWin->ResetDefaultLevelWindow();
475  std::cout << "[PASSED]" << std::endl;
476 
477  resetLevelWindow(*levWin);
478 
479  std::cout << "Testing mitk::LevelWindow min < minrange & max > minrange autoexpand = FALSE";
480  levWin->SetWindowBounds(-11000, -9999, false);
481  if (!((levWin->GetLowerWindowBound() == -10000) && (levWin->GetUpperWindowBound() == -9999)))
482  {
483  std::cout << "[FAILED]" << std::endl;
484  return EXIT_FAILURE;
485  }
486  levWin->ResetDefaultLevelWindow();
487  std::cout << "[PASSED]" << std::endl;
488 
489  std::cout << "Testing mitk::LevelWindow min < minrange & max > minrange autoexpand = TRUE";
490  levWin->SetWindowBounds(-11000, -9999);
491  if (!((levWin->GetLowerWindowBound() == -11000) && (levWin->GetUpperWindowBound() == -9999)))
492  {
493  std::cout << "[FAILED]" << std::endl;
494  return EXIT_FAILURE;
495  }
496  levWin->ResetDefaultLevelWindow();
497  std::cout << "[PASSED]" << std::endl;
498 
499  resetLevelWindow(*levWin);
500 
501  std::cout << "Testing mitk::LevelWindow min < minrange & max > maxrange autoexpand = FALSE";
502  levWin->SetWindowBounds(-11000, 11000, false);
503  if (!((levWin->GetLowerWindowBound() == -10000) && (levWin->GetUpperWindowBound() == 10000)))
504  {
505  std::cout << "[FAILED]" << std::endl;
506  return EXIT_FAILURE;
507  }
508  levWin->ResetDefaultLevelWindow();
509  std::cout << "[PASSED]" << std::endl;
510 
511  std::cout << "Testing mitk::LevelWindow min < minrange & max > maxrange autoexpand = TRUE";
512  levWin->SetWindowBounds(-11000, 11000);
513  if (!((levWin->GetLowerWindowBound() == -11000) && (levWin->GetUpperWindowBound() == 11000)))
514  {
515  std::cout << "[FAILED]" << std::endl;
516  return EXIT_FAILURE;
517  }
518  levWin->ResetDefaultLevelWindow();
519  std::cout << "[PASSED]" << std::endl;
520 
521  resetLevelWindow(*levWin);
522 
523  std::cout << "Testing mitk::LevelWindow maxrange > min = max > minrange autoexpand = FALSE";
524  levWin->SetWindowBounds(5000, 5000, false);
525  if (!((levWin->GetLowerWindowBound() == 4999.5) && (levWin->GetUpperWindowBound() == 5000.5)))
526  {
527  std::cout << "[FAILED]: Expected (4999.5, 5000.5): " << levWin->GetLowerWindowBound() << " - "
528  << levWin->GetUpperWindowBound() << std::endl;
529  return EXIT_FAILURE;
530  }
531  levWin->ResetDefaultLevelWindow();
532  std::cout << "[PASSED]" << std::endl;
533 
534  std::cout << "Testing mitk::LevelWindow maxrange > min = max > minrange autoexpand = TRUE";
535  levWin->SetWindowBounds(5000, 5000);
536  if (!((levWin->GetLowerWindowBound() == 4999.5) && (levWin->GetUpperWindowBound() == 5000.5)))
537  {
538  std::cout << "[FAILED]" << std::endl;
539  return EXIT_FAILURE;
540  }
541  levWin->ResetDefaultLevelWindow();
542  std::cout << "[PASSED]" << std::endl;
543 
544  resetLevelWindow(*levWin);
545 
546  std::cout << "Testing mitk::LevelWindow min = max = minrange autoexpand = FALSE";
547  levWin->SetWindowBounds(-10000, -10000, false);
548  if (!((levWin->GetLowerWindowBound() == -10000) && (levWin->GetUpperWindowBound() == -9999)))
549  {
550  std::cout << "[FAILED]: Expected (-10000, -9999): " << levWin->GetLowerWindowBound() << " - "
551  << levWin->GetUpperWindowBound() << " . " << levWin->GetRangeMin() << std::endl;
552  return EXIT_FAILURE;
553  }
554  levWin->ResetDefaultLevelWindow();
555  std::cout << "[PASSED]" << std::endl;
556 
557  std::cout << "Testing mitk::LevelWindow min = max = minrange autoexpand = TRUE";
558  levWin->SetWindowBounds(-10000, -10000);
559  if (!((levWin->GetLowerWindowBound() == -10000) && (levWin->GetUpperWindowBound() == -9999)))
560  {
561  std::cout << "[FAILED]" << std::endl;
562  return EXIT_FAILURE;
563  }
564  levWin->ResetDefaultLevelWindow();
565  std::cout << "[PASSED]" << std::endl;
566 
567  resetLevelWindow(*levWin);
568 
569  std::cout << "Testing mitk::LevelWindow min = max = maxrange autoexpand = FALSE";
570  levWin->SetWindowBounds(10000, 10000, false);
571  if (!((levWin->GetLowerWindowBound() == 9999) && (levWin->GetUpperWindowBound() == 10000)))
572  {
573  std::cout << "[FAILED]" << std::endl;
574  return EXIT_FAILURE;
575  }
576  levWin->ResetDefaultLevelWindow();
577  std::cout << "[PASSED]" << std::endl;
578 
579  std::cout << "Testing mitk::LevelWindow min = max = maxrange autoexpand = TRUE";
580  levWin->SetWindowBounds(10000, 10000);
581  if (!((levWin->GetLowerWindowBound() == 9999) && (levWin->GetUpperWindowBound() == 10000)))
582  {
583  std::cout << "[FAILED]" << std::endl;
584  return EXIT_FAILURE;
585  }
586  levWin->ResetDefaultLevelWindow();
587  std::cout << "[PASSED]" << std::endl;
588 
589  resetLevelWindow(*levWin);
590 
591  std::cout << "Testing mitk::LevelWindow min = max > maxrange autoexpand = FALSE";
592  levWin->SetWindowBounds(11000, 11000, false);
593  if (!((levWin->GetLowerWindowBound() == 9999) && (levWin->GetUpperWindowBound() == 10000)))
594  {
595  std::cout << "[FAILED]" << std::endl;
596  return EXIT_FAILURE;
597  }
598  levWin->ResetDefaultLevelWindow();
599  std::cout << "[PASSED]" << std::endl;
600 
601  std::cout << "Testing mitk::LevelWindow min = max > maxrange autoexpand = TRUE";
602  levWin->SetWindowBounds(11000, 11000);
603  if (!((levWin->GetLowerWindowBound() == 10999) && (levWin->GetUpperWindowBound() == 11000)))
604  {
605  std::cout << "[FAILED]" << std::endl;
606  return EXIT_FAILURE;
607  }
608  levWin->ResetDefaultLevelWindow();
609  std::cout << "[PASSED]" << std::endl;
610 
611  resetLevelWindow(*levWin);
612 
613  std::cout << "Testing mitk::LevelWindow min = max < minrange autoexpand = FALSE";
614  levWin->SetWindowBounds(-11000, -11000, false);
615  if (!((levWin->GetLowerWindowBound() == -10000) && (levWin->GetUpperWindowBound() == -9999)))
616  {
617  std::cout << "[FAILED]" << std::endl;
618  return EXIT_FAILURE;
619  }
620  levWin->ResetDefaultLevelWindow();
621  std::cout << "[PASSED]" << std::endl;
622 
623  std::cout << "Testing mitk::LevelWindow min = max < minrange autoexpand = TRUE";
624  levWin->SetWindowBounds(-11000, -11000);
625  if (!((levWin->GetLowerWindowBound() == -11000) && (levWin->GetUpperWindowBound() == -10999)))
626  {
627  std::cout << "[FAILED]" << std::endl;
628  return EXIT_FAILURE;
629  }
630  levWin->ResetDefaultLevelWindow();
631  std::cout << "[PASSED]" << std::endl;
632 
633  resetLevelWindow(*levWin);
634 
635  std::cout << "Testing mitk::LevelWindow maxrange > min > minrange > max autoexpand = FALSE";
636  levWin->SetWindowBounds(-9000, -11000, false);
637  if (!((levWin->GetLowerWindowBound() == -10000) && (levWin->GetUpperWindowBound() == -9000)))
638  {
639  std::cout << "[FAILED]" << std::endl;
640  return EXIT_FAILURE;
641  }
642  levWin->ResetDefaultLevelWindow();
643  std::cout << "[PASSED]" << std::endl;
644 
645  std::cout << "Testing mitk::LevelWindow maxrange > min > minrange > max autoexpand = TRUE";
646  levWin->SetWindowBounds(-9000, -11000, true);
647  if (!((levWin->GetLowerWindowBound() == -11000) && (levWin->GetUpperWindowBound() == -9000)))
648  {
649  std::cout << "[FAILED]" << std::endl;
650  return EXIT_FAILURE;
651  }
652  levWin->ResetDefaultLevelWindow();
653  std::cout << "[PASSED]" << std::endl;
654 
655  resetLevelWindow(*levWin);
656 
657  std::cout << "Testing mitk::LevelWindow min > maxrange > minrange > max autoexpand = FALSE";
658  levWin->SetWindowBounds(11000, -11000, false);
659  if (!((levWin->GetLowerWindowBound() == -10000) && (levWin->GetUpperWindowBound() == 10000)))
660  {
661  std::cout << "[FAILED]" << std::endl;
662  return EXIT_FAILURE;
663  }
664  levWin->ResetDefaultLevelWindow();
665  std::cout << "[PASSED]" << std::endl;
666 
667  std::cout << "Testing mitk::LevelWindow min > maxrange > minrange > max autoexpand = TRUE";
668  levWin->SetWindowBounds(11000, -11000);
669  if (!((levWin->GetLowerWindowBound() == -11000) && (levWin->GetUpperWindowBound() == 11000)))
670  {
671  std::cout << "[FAILED]" << std::endl;
672  return EXIT_FAILURE;
673  }
674  levWin->ResetDefaultLevelWindow();
675  std::cout << "[PASSED]" << std::endl;
676 
677  resetLevelWindow(*levWin);
678 
679  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with maxrange < min < max autoexpand = FALSE";
680  levWin->SetRangeMinMax(-20000, -15000);
681  if (!((levWin->GetLowerWindowBound() == -15001) && (levWin->GetUpperWindowBound() == -15000)))
682  {
683  std::cout << "[FAILED]" << std::endl;
684  return EXIT_FAILURE;
685  }
686  levWin->ResetDefaultRangeMinMax();
687  levWin->ResetDefaultLevelWindow();
688  std::cout << "[PASSED]" << std::endl;
689 
690  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with minrange > maxrange & maxrange < min < max ";
691  levWin->ResetDefaultLevelWindow();
692  levWin->SetRangeMinMax(-15000, -20000);
693  if (!((levWin->GetLowerWindowBound() == -15001) && (levWin->GetUpperWindowBound() == -15000)))
694  {
695  std::cout << "[FAILED]" << std::endl;
696  return EXIT_FAILURE;
697  }
698  levWin->ResetDefaultRangeMinMax();
699  levWin->ResetDefaultLevelWindow();
700  std::cout << "[PASSED]" << std::endl;
701 
702  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with minrange < min < maxrange < max autoexpand = FALSE";
703  levWin->SetRangeMinMax(-80, 1000);
704  levWin->SetWindowBounds(-1000, 110, false);
705  if (!((levWin->GetLowerWindowBound() == -80) && (levWin->GetUpperWindowBound() == 110)))
706  {
707  std::cout << "[FAILED]" << std::endl;
708  return EXIT_FAILURE;
709  }
710  levWin->ResetDefaultRangeMinMax();
711  levWin->ResetDefaultLevelWindow();
712  std::cout << "[PASSED]" << std::endl;
713 
714  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with minrange < min < maxrange < max autoexpand = TRUE";
715  levWin->SetRangeMinMax(-80, 1000);
716  levWin->SetWindowBounds(-1000, 110);
717  if (!((levWin->GetLowerWindowBound() == -1000) && (levWin->GetUpperWindowBound() == 110)))
718  {
719  std::cout << "[FAILED]" << std::endl;
720  return EXIT_FAILURE;
721  }
722  levWin->ResetDefaultRangeMinMax();
723  levWin->ResetDefaultLevelWindow();
724  std::cout << "[PASSED]" << std::endl;
725 
726  resetLevelWindow(*levWin);
727 
728  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with maxrange < minrange & minrange < min < maxrange < max "
729  "autoexpand = FALSE";
730  levWin->SetRangeMinMax(1000, -80);
731  levWin->SetWindowBounds(-1000, 110, false);
732  if (!((levWin->GetLowerWindowBound() == -80) && (levWin->GetUpperWindowBound() == 110)))
733  {
734  std::cout << "[FAILED]" << std::endl;
735  return EXIT_FAILURE;
736  }
737  levWin->ResetDefaultRangeMinMax();
738  levWin->ResetDefaultLevelWindow();
739  std::cout << "[PASSED]" << std::endl;
740 
741  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with maxrange < minrange & minrange < min < maxrange < max "
742  "autoexpand = TRUE";
743  levWin->SetRangeMinMax(1000, -80);
744  levWin->SetWindowBounds(-1000, 110);
745  if (!((levWin->GetLowerWindowBound() == -1000) && (levWin->GetUpperWindowBound() == 110)))
746  {
747  std::cout << "[FAILED]" << std::endl;
748  return EXIT_FAILURE;
749  }
750  levWin->ResetDefaultRangeMinMax();
751  levWin->ResetDefaultLevelWindow();
752  std::cout << "[PASSED]" << std::endl;
753 
754  resetLevelWindow(*levWin);
755 
756  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with min < minrange < maxrange <max ";
757  levWin->SetRangeMinMax(20, 110);
758  if (!((levWin->GetLowerWindowBound() == 20) && (levWin->GetUpperWindowBound() == 110)))
759  {
760  std::cout << "[FAILED]" << std::endl;
761  return EXIT_FAILURE;
762  }
763  levWin->ResetDefaultRangeMinMax();
764  levWin->ResetDefaultLevelWindow();
765  std::cout << "[PASSED]" << std::endl;
766 
767  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with minRange > maxRange & min < maxrange < max ";
768  levWin->SetWindowBounds(-90, 1000);
769  levWin->SetRangeMinMax(100, -80);
770 
771  if (!((levWin->GetLowerWindowBound() == -80) && (levWin->GetUpperWindowBound() == 100)))
772  {
773  std::cout << "[FAILED]" << std::endl;
774  return EXIT_FAILURE;
775  }
776  levWin->ResetDefaultRangeMinMax();
777  levWin->ResetDefaultLevelWindow();
778  std::cout << "[PASSED]" << std::endl;
779 
780  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with minRange > maxRange & min < minrange < maxrange <max ";
781  levWin->SetRangeMinMax(20, 100);
782  if (!((levWin->GetLowerWindowBound() == 20) && (levWin->GetUpperWindowBound() == 100)))
783  {
784  std::cout << "[FAILED]" << std::endl;
785  return EXIT_FAILURE;
786  }
787  levWin->ResetDefaultRangeMinMax();
788  levWin->ResetDefaultLevelWindow();
789  std::cout << "[PASSED]" << std::endl;
790 
791  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with min < max < minrange ";
792  levWin->SetRangeMinMax(20000, 15000);
793  if (!((levWin->GetLowerWindowBound() == 15000) && (levWin->GetUpperWindowBound() == 15001)))
794  {
795  std::cout << "[FAILED]" << std::endl;
796  return EXIT_FAILURE;
797  }
798  levWin->ResetDefaultRangeMinMax();
799  levWin->ResetDefaultLevelWindow();
800  std::cout << "[PASSED]" << std::endl;
801 
802  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with minrange > maxrange & min < max < minrange ";
803  levWin->SetRangeMinMax(20000, 15000);
804  if (!((levWin->GetLowerWindowBound() == 15000) && (levWin->GetUpperWindowBound() == 15001)))
805  {
806  std::cout << "[FAILED]" << std::endl;
807  return EXIT_FAILURE;
808  }
809  levWin->ResetDefaultRangeMinMax();
810  levWin->ResetDefaultLevelWindow();
811  std::cout << "[PASSED]" << std::endl;
812 
813  std::cout << "Testing mitk::LevelWindow SetRangeMinMax with min < minrange <max ";
814  levWin->SetRangeMinMax(-20000, -15000);
815  if (!((levWin->GetLowerWindowBound() == -15001) && (levWin->GetUpperWindowBound() == -15000)))
816  {
817  std::cout << "[FAILED]" << std::endl;
818  return EXIT_FAILURE;
819  }
820  levWin->ResetDefaultRangeMinMax();
821  levWin->ResetDefaultLevelWindow();
822  std::cout << "[PASSED]" << std::endl;
823 
824  // auch für default levelwindow und default range
825 
826  // Create Image out of nowhere
827  mitk::Image::Pointer image;
828  // mitk::PixelType pt(typeid(int));
829  unsigned int dim[] = {100, 100, 20};
830 
831  std::cout << "Creating image: ";
832  image = mitk::Image::New();
833  // image->DebugOn();
834 
835  image->Initialize(mitk::MakePixelType<int, int, 1>(), 3, dim);
836  mitk::ImageWriteAccessor imAccess(image);
837  int *p = (int *)imAccess.GetData();
838 
839  int size = dim[0] * dim[1] * dim[2];
840  int i;
841  for (i = 0; i < size; ++i, ++p)
842  *p = i;
843  std::cout << "[PASSED]" << std::endl;
844 
845  std::cout << "Testing mitk::LevelWindow SetAuto ";
846  mitk::LevelWindow levelwindow;
847  levelwindow.SetAuto(image);
848  std::cout << "[PASSED]" << std::endl;
849 
850  std::cout << "Testing mitk::LevelWindow constructor with mitkLevelWindow ";
851  const mitk::LevelWindow *lw = new mitk::LevelWindow(levelwindow);
852  if (!(lw->GetRange() == levelwindow.GetRange()))
853  {
854  std::cout << "[FAILED]" << std::endl;
855  delete lw;
856  return EXIT_FAILURE;
857  }
858  std::cout << "[PASSED]" << std::endl;
859 
860  std::cout << "Testing mitk::LevelWindow destructor ";
861  delete levWin;
862  delete lw;
863 
864  std::cout << "[PASSED]" << std::endl;
865 
866  mitk::LevelWindow levelWindow(50, 100);
867  levelWindow.SetRangeMinMax(0, 100);
868  // test range restriction/adaption for SetLevelWindow and SetWindowBounds
869  std::cout << "Testing range restriction of mitk::LevelWindow::SetWindowBounds() autoexpand = FALSE";
870  mitk::ScalarType initialUpperBound = levelWindow.GetUpperWindowBound();
871  mitk::ScalarType initialLowerBound = levelWindow.GetLowerWindowBound();
872  levelWindow.SetWindowBounds(-10, 110, false);
873  if (levelWindow.GetUpperWindowBound() != initialUpperBound || levelWindow.GetLowerWindowBound() != initialLowerBound)
874  {
875  std::cout << "[FAILED]" << std::endl;
876  return EXIT_FAILURE;
877  }
878  std::cout << "[PASSED]" << std::endl;
879 
880  std::cout << "Testing range restriction of mitk::LevelWindow::SetWindowBounds() autoexpand = TRUE";
881  levelWindow.SetWindowBounds(-10, 110);
882  if (levelWindow.GetUpperWindowBound() != 110 || levelWindow.GetLowerWindowBound() != -10)
883  {
884  std::cout << "[FAILED]" << std::endl;
885  return EXIT_FAILURE;
886  }
887  std::cout << "[PASSED]" << std::endl;
888 
889  levelWindow.SetRangeMinMax(0, 100);
890  levelWindow.SetLevelWindow(50, 100);
891 
892  std::cout << "Testing range restriction of mitk::LevelWindow::SetLevelWindow() autoexpand = FALSE";
893  levelWindow.SetLevelWindow(60, 100, false);
894  if (levelWindow.GetUpperWindowBound() != initialUpperBound)
895  {
896  std::cout << "[FAILED]" << std::endl;
897  return EXIT_FAILURE;
898  }
899  std::cout << "[PASSED]" << std::endl;
900 
901  std::cout << "Testing range restriction of mitk::LevelWindow::SetLevelWindow() autoexpand = TRUE";
902  levelWindow.SetLevelWindow(60, 100);
903  if (levelWindow.GetUpperWindowBound() != initialUpperBound + 10)
904  {
905  std::cout << "[FAILED]" << std::endl;
906  return EXIT_FAILURE;
907  }
908  std::cout << "[PASSED]" << std::endl;
909 
910  levelWindow.SetRangeMinMax(0, 100);
911  levelWindow.SetLevelWindow(50, 100);
912 
913  std::cout << "Testing range restriction of mitk::LevelWindow::SetLevelWindow() autoexpand = FALSE";
914  levelWindow.SetLevelWindow(40, 100, false);
915  if (levelWindow.GetLowerWindowBound() != initialLowerBound)
916  {
917  std::cout << "[FAILED]" << std::endl;
918  return EXIT_FAILURE;
919  }
920  std::cout << "[PASSED]" << std::endl;
921 
922  std::cout << "Testing range restriction of mitk::LevelWindow::SetLevelWindow() autoexpand = TRUE";
923  levelWindow.SetLevelWindow(40, 100);
924  if (levelWindow.GetLowerWindowBound() != initialLowerBound - 10)
925  {
926  std::cout << "[FAILED]" << std::endl;
927  return EXIT_FAILURE;
928  }
929  std::cout << "[PASSED]" << std::endl;
930 
931  std::cout << "Testing range adaption of mitk::LevelWindow::SetWindowBounds()";
932  levelWindow.SetWindowBounds(-10, 90, true); // ture == force
933  if (levelWindow.GetUpperWindowBound() != 90.0 || levelWindow.GetLowerWindowBound() != -10.0)
934  {
935  std::cout << "[FAILED]" << std::endl;
936  return EXIT_FAILURE;
937  }
938  std::cout << "[PASSED]" << std::endl;
939 
940  std::cout << "Testing range adaption of mitk::LevelWindow::SetWindowBounds()";
941  levelWindow.SetWindowBounds(-20, 110, true); // ture == force
942  if (levelWindow.GetUpperWindowBound() != 110.0 || levelWindow.GetLowerWindowBound() != -20.0)
943  {
944  std::cout << "[FAILED]" << std::endl;
945  return EXIT_FAILURE;
946  }
947  std::cout << "[PASSED]" << std::endl;
948 
949  std::cout << "Testing range adaption of mitk::LevelWindow::SetLevelWindow()";
950  levelWindow.SetLevelWindow(50, 140, true); // ture == force
951  if (levelWindow.GetUpperWindowBound() != 120.0 || levelWindow.GetLowerWindowBound() != -20.0)
952  {
953  std::cout << "[FAILED]" << std::endl;
954  return EXIT_FAILURE;
955  }
956  std::cout << "[PASSED]" << std::endl;
957 
958  std::cout << "Testing c'tor with x-ray values (formerly did not expand range enough)";
959  mitk::LevelWindow crLevelWindow(16352, 16444);
960  if (crLevelWindow.GetLevel() != 16352.0 || crLevelWindow.GetWindow() != 16444.0)
961  {
962  std::cout << "[FAILED]" << std::endl;
963  return EXIT_FAILURE;
964  }
965  std::cout << "[PASSED]" << std::endl;
966 
967  std::cout << "[PASSED]" << std::endl;
968  std::cout << "[TEST DONE]" << std::endl;
969  return EXIT_SUCCESS;
970 }
void SetWindowBounds(ScalarType lowerBound, ScalarType upperBound, bool expandRangesIfNecessary=true)
ScalarType GetLowerWindowBound() const
double ScalarType
void * GetData()
Gives full data access.
void SetRangeMinMax(ScalarType min, ScalarType max)
The LevelWindow class Class to store level/window values.
void resetLevelWindow(mitk::LevelWindow &lw)
void SetAuto(const Image *image, bool tryPicTags=true, bool guessByCentralSlice=true, unsigned selectedComponent=0)
sets level/window to optimize the contrast of the given Image
static Pointer New()
int mitkLevelWindowTest(int, char *[])
ScalarType GetRangeMax() const
ScalarType GetRangeMin() const
ImageWriteAccessor class to get locked write-access for a particular image part.
ScalarType GetUpperWindowBound() const
void SetLevelWindow(ScalarType level, ScalarType window, bool expandRangesIfNecessary=true)
ScalarType GetWindow() const
returns the current window size, i.e the range size of the current grey value interval ...
ScalarType GetRange() const
returns the size of the grey value range
ScalarType GetLevel() const
method that returns the level value, i.e. the center of the current grey value interval ...