32 #include <itkMersenneTwisterRandomVariateGenerator.h>
38 #include <vtkImageData.h>
49 bool matrixIsEqual =
true;
50 std::stringstream sstream;
57 ImageType::RegionType myRegion;
58 ImageType::SizeType mySize;
59 ImageType::IndexType myIndex;
60 ImageType::SpacingType mySpacing;
67 myRegion.SetSize(mySize);
68 myRegion.SetIndex(myIndex);
69 itkImage->SetSpacing(mySpacing);
70 itkImage->SetRegions(myRegion);
72 itkImage->FillBuffer(50);
87 mitkImage2D->GetGeometry()->ExecuteOperation(&op);
91 Original_col0.SetVnlVector(
92 mitkImage2D->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0));
93 Original_col1.SetVnlVector(
94 mitkImage2D->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1));
95 Original_col2.SetVnlVector(
96 mitkImage2D->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2));
97 MITK_INFO <<
"Rotated Matrix: " << Original_col0 <<
" " << Original_col1 <<
" " << Original_col2;
99 mitk::Point3D Original_Origin = mitkImage2D->GetGeometry()->GetOrigin();
100 mitk::Vector3D Original_Spacing = mitkImage2D->GetGeometry()->GetSpacing();
109 <<
"/rotatedImage2D.nrrd";
120 mitk::Vector3D Loaded2D_Spacing = imageLoaded2D->GetGeometry()->GetSpacing();
122 error = std::fabs(Loaded2D_Spacing[0] - Original_Spacing[0]) + std::fabs(Loaded2D_Spacing[1] - Original_Spacing[1]) +
123 std::fabs(Loaded2D_Spacing[2] - 1);
128 mitk::Point3D Loaded2D_Origin = imageLoaded2D->GetGeometry()->GetOrigin();
130 error = std::fabs(Loaded2D_Origin[0] - Original_Origin[0]) + std::fabs(Loaded2D_Origin[1] - Original_Origin[1]) +
131 std::fabs(Loaded2D_Origin[2] - 0);
137 Loaded2D_col0.SetVnlVector(
138 imageLoaded2D->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0));
139 Loaded2D_col1.SetVnlVector(
140 imageLoaded2D->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1));
141 Loaded2D_col2.SetVnlVector(
142 imageLoaded2D->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2));
144 if ((std::fabs(1 - Loaded2D_col0[0]) > eps) || (std::fabs(0 - Loaded2D_col0[1]) >
eps) ||
145 (std::fabs(0 - Loaded2D_col0[2]) >
eps) || (std::fabs(0 - Loaded2D_col1[0]) >
eps) ||
146 (std::fabs(1 - Loaded2D_col1[1]) >
eps) || (std::fabs(0 - Loaded2D_col1[2]) >
eps) ||
147 (std::fabs(0 - Loaded2D_col2[0]) >
eps) || (std::fabs(0 - Loaded2D_col2[1]) >
eps) ||
148 (std::fabs(1 - Loaded2D_col2[2]) >
eps))
150 matrixIsEqual =
false;
153 matrixIsEqual =
true;
160 convertFilter->SetInput(mitkImage2D);
161 convertFilter->Update();
167 mitk::Vector3D Converted_Spacing = mitkImage3D->GetGeometry()->GetSpacing();
169 error = std::fabs(Converted_Spacing[0] - Original_Spacing[0]) +
170 std::fabs(Converted_Spacing[1] - Original_Spacing[1]) + std::fabs(Converted_Spacing[2] - Original_Spacing[2]);
174 mitk::Point3D Converted_Origin = mitkImage3D->GetGeometry()->GetOrigin();
176 error = std::fabs(Converted_Origin[0] - Original_Origin[0]) + std::fabs(Converted_Origin[1] - Original_Origin[1]) +
177 std::fabs(Converted_Origin[2] - Original_Origin[2]);
179 MITK_INFO << Converted_Origin <<
" and " << Original_Origin;
183 Converted_col0.SetVnlVector(
184 mitkImage3D->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0));
185 Converted_col1.SetVnlVector(
186 mitkImage3D->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1));
187 Converted_col2.SetVnlVector(
188 mitkImage3D->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2));
190 if ((std::fabs(Original_col0[0] - Converted_col0[0]) > eps) ||
191 (std::fabs(Original_col0[1] - Converted_col0[1]) >
eps) ||
192 (std::fabs(Original_col0[2] - Converted_col0[2]) >
eps) ||
193 (std::fabs(Original_col1[0] - Converted_col1[0]) >
eps) ||
194 (std::fabs(Original_col1[1] - Converted_col1[1]) >
eps) ||
195 (std::fabs(Original_col1[2] - Converted_col1[2]) >
eps) ||
196 (std::fabs(Original_col2[0] - Converted_col2[0]) >
eps) ||
197 (std::fabs(Original_col2[1] - Converted_col2[1]) >
eps) ||
198 (std::fabs(Original_col2[2] - Converted_col2[2]) >
eps))
200 MITK_INFO <<
"Oh No! Original Image Matrix and Converted Image Matrix are different!";
201 MITK_INFO <<
"original Image:" << Original_col0 <<
" " << Original_col1 <<
" " << Original_col2;
202 MITK_INFO <<
"converted Image:" << Converted_col0 <<
" " << Converted_col1 <<
" " << Converted_col2;
203 matrixIsEqual =
false;
206 matrixIsEqual =
true;
213 std::stringstream sstream2;
214 sstream2 << MITK_TEST_OUTPUT_DIR <<
""
215 <<
"/rotatedImage.nrrd";
226 mitk::Vector3D Loaded_Spacing = imageLoaded->GetGeometry()->GetSpacing();
227 error = std::fabs(Loaded_Spacing[0] - Original_Spacing[0]) + std::fabs(Loaded_Spacing[1] - Original_Spacing[1]) +
228 std::fabs(Loaded_Spacing[2] - Original_Spacing[2]);
232 mitk::Point3D Loaded_Origin = imageLoaded->GetGeometry()->GetOrigin();
233 error = std::fabs(Loaded_Origin[0] - Original_Origin[0]) + std::fabs(Loaded_Origin[1] - Original_Origin[1]) +
234 std::fabs(Loaded_Origin[2] - Original_Origin[2]);
238 Loaded_col0.SetVnlVector(
239 imageLoaded->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0));
240 Loaded_col1.SetVnlVector(
241 imageLoaded->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1));
242 Loaded_col2.SetVnlVector(
243 imageLoaded->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2));
245 if ((std::fabs(Original_col0[0] - Loaded_col0[0]) > eps) || (std::fabs(Original_col0[1] - Loaded_col0[1]) >
eps) ||
246 (std::fabs(Original_col0[2] - Loaded_col0[2]) >
eps) || (std::fabs(Original_col1[0] - Loaded_col1[0]) >
eps) ||
247 (std::fabs(Original_col1[1] - Loaded_col1[1]) >
eps) || (std::fabs(Original_col1[2] - Loaded_col1[2]) >
eps) ||
248 (std::fabs(Original_col2[0] - Loaded_col2[0]) >
eps) || (std::fabs(Original_col2[1] - Loaded_col2[1]) >
eps) ||
249 (std::fabs(Original_col2[2] - Loaded_col2[2]) >
eps))
251 MITK_INFO <<
"Oh No! Original Image Matrix and Converted Image Matrix are different!";
252 MITK_INFO <<
"original Image:" << Original_col0 <<
" " << Original_col1 <<
" " << Original_col2;
253 MITK_INFO <<
"converted Image:" << Loaded_col0 <<
" " << Loaded_col1 <<
" " << Loaded_col2;
254 matrixIsEqual =
false;
257 matrixIsEqual =
true;
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
itk::SmartPointer< Self > Pointer
itk::Image< unsigned char, 3 > ImageType
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
Constants for most interaction classes, due to the generic StateMachines.
#define MITK_TEST_OUTPUT_DIR
int mitkImageDimensionConverterTest(int, char *[])
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
MITKCORE_EXPORT const ScalarType eps
Operation, that holds everything necessary for an rotation operation on mitk::BaseData.
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.