Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkImageSliceSelectorTest.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 <mitkIOUtil.h>
14 #include <mitkImage.h>
15 #include <mitkImageSliceSelector.h>
16 
17 #include <fstream>
18 int mitkImageSliceSelectorTest(int argc, char *argv[])
19 {
20  int slice_nr = 1;
21  std::cout << "Loading file: ";
22  if (argc == 0)
23  {
24  std::cout << "no file specified [FAILED]" << std::endl;
25  return EXIT_FAILURE;
26  }
27 
29  try
30  {
31  image = mitk::IOUtil::Load<mitk::Image>(argv[1]);
32  }
33  catch (const mitk::Exception &)
34  {
35  std::cout << "file not an image - test will not be applied [PASSED]" << std::endl;
36  std::cout << "[TEST DONE]" << std::endl;
37  return EXIT_SUCCESS;
38  }
39  catch ( const itk::ExceptionObject &ex )
40  {
41  std::cout << "Exception: " << ex.GetDescription() << "[FAILED]" << std::endl;
42  return EXIT_FAILURE;
43  }
44 
45  if (image->GetDimension(2) < 2)
46  slice_nr = 0;
47 
48  // Take a slice
50  slice->SetInput(image);
51  slice->SetSliceNr(slice_nr);
52  slice->Update();
53 
54  std::cout << "Testing IsInitialized(): ";
55  if (slice->GetOutput()->IsInitialized() == false)
56  {
57  std::cout << "[FAILED]" << std::endl;
58  return EXIT_FAILURE;
59  }
60  std::cout << "[PASSED]" << std::endl;
61 
62  std::cout << "Testing IsSliceSet(): ";
63  if (slice->GetOutput()->IsSliceSet(0) == false)
64  {
65  std::cout << "[FAILED]" << std::endl;
66  return EXIT_FAILURE;
67  }
68  std::cout << "[PASSED]" << std::endl;
69 
70  /* deactivated because IpPic is not available any more (see bug 16662)
71  if(itksys::SystemTools::LowerCase(itksys::SystemTools::GetFilenameExtension(argv[1])).find(".pic")!=std::string::npos)
72  {
73  std::cout << "Testing whether the slice is identical with a slice loaded by mitkIpPicGetSlice:";
74  mitkIpPicDescriptor *picslice = mitkIpPicGetSlice(argv[1], nullptr, (image->GetDimension(2)-1-slice_nr)+1);
75  int i, size = _mitkIpPicSize(picslice);
76  char * p1 = (char*)slice->GetPic()->data;
77  char * p2 = (char*)picslice->data;
78  //picslice->info->write_protect=mitkIpFalse;
79  //mitkIpPicPut("C:\\1aaaaIPPIC.pic", picslice);
80  //mitkIpPicPut("C:\\1aaaaSEL.pic", slice->GetPic());
81  for(i=0; i<size; ++i, ++p1, ++p2)
82  {
83  if((*p1) != (*p2))
84  {
85  std::cout<<"[FAILED]"<<std::endl;
86  return EXIT_FAILURE;
87  }
88  }
89  std::cout<<"[PASSED]"<<std::endl;
90  mitkIpPicFree(picslice);
91  }
92  */
93 
94  /* Deactivated because CylindricToCartesianFilter is not available any more (see bug 16662)
95  try
96  {
97  std::cout << "Testing another, smaller (!!) input with the same slice-selector(): ";
98  //Use CylindricToCartesianFilter
99  mitk::CylindricToCartesianFilter::Pointer cyl2cart = mitk::CylindricToCartesianFilter::New();
100  cyl2cart->SetInput(image);
101  //the output size of this filter is smaller than the of the input!!
102  cyl2cart->SetTargetXSize( 64 );
103 
104  //Use the same slice-selector again, this time to take a slice of the filtered image
105  //which is smaller than the one of the old input!!
106  slice->SetInput(cyl2cart->GetOutput());
107  slice->SetSliceNr(1);
108 
109  //The requested region is still the old one,
110  //therefore the following results in most ITK versions
111  //in an exception!
112  slice->Update();
113 
114  //If no exception occured, check that the requested region is now
115  //the one of the smaller image
116  if(cyl2cart->GetOutput()->GetLargestPossibleRegion().GetSize()[0]!=64)
117  {
118  std::cout<<"Part 1 [FAILED]"<<std::endl;
119  return EXIT_FAILURE;
120  }
121  std::cout<<"Part 1 (without exception) [PASSED] ";
122 
123  //Check that the size of the output is now the one of the smaller image
124  if((cyl2cart->GetOutput()->GetDimensions()[0]!=64) || (cyl2cart->GetOutput()->GetDimensions()[1]!=64))
125  {
126  std::cout<<"Part 1b [FAILED]"<<std::endl;
127  return EXIT_FAILURE;
128  }
129  std::cout<<"Part 1b [PASSED] ";
130  }
131  catch (const itk::ExceptionObject &err)
132  {
133  std::cout<<"Part 1(with expected exception) ... seems to be not ITK 2.0.0 [PASSED]"<<std::endl;
134  std::cout<<err<<std::endl;
135  //after such an exception, we need to call ResetPipeline.
136  slice->ResetPipeline();
137  }
138  */
139  try
140  {
141  slice->UpdateLargestPossibleRegion();
142  }
143  catch (const itk::ExceptionObject &)
144  {
145  std::cout << "Part 2 [FAILED]" << std::endl;
146  return EXIT_FAILURE;
147  }
148  std::cout << "Part 2 [PASSED]" << std::endl;
149 
150  std::cout << "Testing IsInitialized(): ";
151  if (slice->GetOutput()->IsInitialized() == false)
152  {
153  std::cout << "[FAILED]" << std::endl;
154  return EXIT_FAILURE;
155  }
156  std::cout << "[PASSED]" << std::endl;
157 
158  std::cout << "Testing IsSliceSet(): ";
159  if (slice->GetOutput()->IsSliceSet(0) == false)
160  {
161  std::cout << "[FAILED]" << std::endl;
162  return EXIT_FAILURE;
163  }
164  std::cout << "[PASSED]" << std::endl;
165 
166  if (image->GetDimension(3) > 1)
167  {
168  int time = image->GetDimension(3) - 1;
169 
170  std::cout << "Testing 3D+t: Setting time to " << time << ": ";
171  slice->SetTimeNr(time);
172  if (slice->GetTimeNr() != time)
173  {
174  std::cout << "[FAILED]" << std::endl;
175  return EXIT_FAILURE;
176  }
177  std::cout << "[PASSED]" << std::endl;
178 
179  std::cout << "Testing 3D+t: Updating slice: ";
180  slice->Update();
181  if (slice->GetOutput()->IsInitialized() == false)
182  {
183  std::cout << "[FAILED]" << std::endl;
184  return EXIT_FAILURE;
185  }
186  std::cout << "[PASSED]" << std::endl;
187 
188  std::cout << "Testing 3D+t: IsSliceSet(): ";
189  if (slice->GetOutput()->IsSliceSet(0) == false)
190  {
191  std::cout << "[FAILED]" << std::endl;
192  return EXIT_FAILURE;
193  }
194  std::cout << "[PASSED]" << std::endl;
195 
196  std::cout << "Testing 3D+t: First slice in reader available: ";
197  if (image->IsSliceSet(0, time) == false)
198  {
199  std::cout << "[FAILED]" << std::endl;
200  return EXIT_FAILURE;
201  }
202  std::cout << "[PASSED]" << std::endl;
203  }
204 
205  std::cout << "[TEST DONE]" << std::endl;
206  return EXIT_SUCCESS;
207 }
int mitkImageSliceSelectorTest(int argc, char *argv[])
static Pointer New()
An object of this class represents an exception of MITK. Please don&#39;t instantiate exceptions manually...
Definition: mitkException.h:45
mitk::Image::Pointer image