29 #include <itksys/SystemTools.hxx> 33 return original->Clone();
37 class PlanarFigureIOTestClass
40 typedef std::list<mitk::PlanarFigure::Pointer> PlanarFigureList;
41 typedef std::vector<mitk::PlanarFigureWriter::Pointer> PlanarFigureToMemoryWriterList;
43 static PlanarFigureList CreatePlanarFigures()
45 PlanarFigureList planarFigures;
49 planeGeometry->InitializeStandardPlane(100.0, 100.0);
67 planarAngle->SetPlaneGeometry(planeGeometry);
68 planarAngle->PlaceFigure(p0);
69 planarAngle->SetCurrentControlPoint(p1);
70 planarAngle->AddControlPoint(p2);
71 planarAngle->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
72 planarFigures.push_back(planarAngle.GetPointer());
76 planarCircle->SetPlaneGeometry(planeGeometry);
77 planarCircle->PlaceFigure(p0);
78 planarCircle->SetCurrentControlPoint(p1);
79 planarCircle->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
80 planarFigures.push_back(planarCircle.GetPointer());
84 planarCross->SetSingleLineMode(
false);
85 planarCross->SetPlaneGeometry(planeGeometry);
86 planarCross->PlaceFigure(p0);
87 planarCross->SetCurrentControlPoint(p1);
88 planarCross->AddControlPoint(p2);
89 planarCross->AddControlPoint(p3);
90 planarCross->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
91 planarFigures.push_back(planarCross.GetPointer());
95 planarFourPointAngle->SetPlaneGeometry(planeGeometry);
96 planarFourPointAngle->PlaceFigure(p0);
97 planarFourPointAngle->SetCurrentControlPoint(p1);
98 planarFourPointAngle->AddControlPoint(p2);
99 planarFourPointAngle->AddControlPoint(p3);
100 planarFourPointAngle->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
101 planarFigures.push_back(planarFourPointAngle.GetPointer());
105 planarLine->SetPlaneGeometry(planeGeometry);
106 planarLine->PlaceFigure(p0);
107 planarLine->SetCurrentControlPoint(p1);
108 planarLine->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
109 planarFigures.push_back(planarLine.GetPointer());
113 planarPolygon->SetClosed(
false);
114 planarPolygon->SetPlaneGeometry(planeGeometry);
115 planarPolygon->PlaceFigure(p0);
116 planarPolygon->SetCurrentControlPoint(p1);
117 planarPolygon->AddControlPoint(p2);
118 planarPolygon->AddControlPoint(p3);
119 planarPolygon->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
120 planarFigures.push_back(planarPolygon.GetPointer());
124 planarSubdivisionPolygon->SetClosed(
false);
125 planarSubdivisionPolygon->SetPlaneGeometry(planeGeometry);
126 planarSubdivisionPolygon->PlaceFigure(p0);
127 planarSubdivisionPolygon->SetCurrentControlPoint(p1);
128 planarSubdivisionPolygon->AddControlPoint(p2);
129 planarSubdivisionPolygon->AddControlPoint(p3);
130 planarSubdivisionPolygon->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
131 planarFigures.push_back(planarSubdivisionPolygon.GetPointer());
135 planarRectangle->SetPlaneGeometry(planeGeometry);
136 planarRectangle->PlaceFigure(p0);
137 planarRectangle->SetCurrentControlPoint(p1);
138 planarRectangle->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
139 planarFigures.push_back(planarRectangle.GetPointer());
154 spacing[0] = 0.0123456;
155 spacing[1] = 0.0123456;
156 spacing[2] = 1.123456;
157 preciseGeometry->InitializeStandardPlane(right, down, &spacing);
161 p0precise[0] = p0[0] * spacing[0];
162 p0precise[1] = p0[1] * spacing[1];
164 p1precise[0] = p1[0] * spacing[0];
165 p1precise[1] = p1[1] * spacing[1];
167 p2precise[0] = p2[0] * spacing[0];
168 p2precise[1] = p2[1] * spacing[1];
170 p3precise[0] = p3[0] * spacing[0];
171 p3precise[1] = p3[1] * spacing[1];
176 nochncross->SetSingleLineMode(
false);
177 nochncross->SetPlaneGeometry(preciseGeometry);
178 nochncross->PlaceFigure(p0precise);
179 nochncross->SetCurrentControlPoint(p1precise);
180 nochncross->AddControlPoint(p2precise);
181 nochncross->AddControlPoint(p3precise);
182 nochncross->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
183 planarFigures.push_back(nochncross.GetPointer());
187 planarAnglePrecise->SetPlaneGeometry(preciseGeometry);
188 planarAnglePrecise->PlaceFigure(p0precise);
189 planarAnglePrecise->SetCurrentControlPoint(p1precise);
190 planarAnglePrecise->AddControlPoint(p2precise);
191 planarAnglePrecise->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
192 planarFigures.push_back(planarAnglePrecise.GetPointer());
196 planarCirclePrecise->SetPlaneGeometry(preciseGeometry);
197 planarCirclePrecise->PlaceFigure(p0precise);
198 planarCirclePrecise->SetCurrentControlPoint(p1precise);
199 planarCirclePrecise->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
200 planarFigures.push_back(planarCirclePrecise.GetPointer());
204 planarFourPointAnglePrecise->SetPlaneGeometry(preciseGeometry);
205 planarFourPointAnglePrecise->PlaceFigure(p0precise);
206 planarFourPointAnglePrecise->SetCurrentControlPoint(p1precise);
207 planarFourPointAnglePrecise->AddControlPoint(p2precise);
208 planarFourPointAnglePrecise->AddControlPoint(p3precise);
209 planarFourPointAnglePrecise->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
210 planarFigures.push_back(planarFourPointAnglePrecise.GetPointer());
214 planarLinePrecise->SetPlaneGeometry(preciseGeometry);
215 planarLinePrecise->PlaceFigure(p0precise);
216 planarLinePrecise->SetCurrentControlPoint(p1precise);
217 planarLinePrecise->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
218 planarFigures.push_back(planarLinePrecise.GetPointer());
222 planarPolygonPrecise->SetClosed(
false);
223 planarPolygonPrecise->SetPlaneGeometry(preciseGeometry);
224 planarPolygonPrecise->PlaceFigure(p0precise);
225 planarPolygonPrecise->SetCurrentControlPoint(p1precise);
226 planarPolygonPrecise->AddControlPoint(p2precise);
227 planarPolygonPrecise->AddControlPoint(p3precise);
228 planarPolygonPrecise->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
229 planarFigures.push_back(planarPolygonPrecise.GetPointer());
233 planarSubdivisionPolygonPrecise->SetClosed(
false);
234 planarSubdivisionPolygonPrecise->SetPlaneGeometry(preciseGeometry);
235 planarSubdivisionPolygonPrecise->PlaceFigure(p0precise);
236 planarSubdivisionPolygonPrecise->SetCurrentControlPoint(p1precise);
237 planarSubdivisionPolygonPrecise->AddControlPoint(p2precise);
238 planarSubdivisionPolygonPrecise->AddControlPoint(p3precise);
239 planarSubdivisionPolygonPrecise->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
240 planarFigures.push_back(planarSubdivisionPolygonPrecise.GetPointer());
244 planarRectanglePrecise->SetPlaneGeometry(preciseGeometry);
245 planarRectanglePrecise->PlaceFigure(p0precise);
246 planarRectanglePrecise->SetCurrentControlPoint(p1precise);
247 planarRectanglePrecise->GetPropertyList()->SetBoolProperty(
"initiallyplaced",
true);
248 planarFigures.push_back(planarRectanglePrecise.GetPointer());
250 return planarFigures;
253 static PlanarFigureList CreateDeepCopiedPlanarFigures(PlanarFigureList original)
255 PlanarFigureList copiedPlanarFigures;
257 PlanarFigureList::iterator it1;
259 for (it1 = original.begin(); it1 != original.end(); ++it1)
263 copiedPlanarFigures.push_back(copiedFigure);
265 return copiedPlanarFigures;
268 static PlanarFigureList CreateClonedPlanarFigures(PlanarFigureList original)
270 PlanarFigureList clonedPlanarFigures;
271 clonedPlanarFigures.resize(original.size());
272 std::transform(original.begin(), original.end(), clonedPlanarFigures.begin(),
Clone);
273 return clonedPlanarFigures;
276 static void VerifyPlanarFigures(PlanarFigureList &planarFigures1, PlanarFigureList &planarFigures2)
278 PlanarFigureList::iterator it1, it2;
281 for (it1 = planarFigures1.begin(); it1 != planarFigures1.end(); ++it1)
283 bool planarFigureFound =
false;
285 for (it2 = planarFigures2.begin(); it2 != planarFigures2.end(); ++it2)
288 if (ComparePlanarFigures(*it1, *it2))
290 planarFigureFound =
true;
297 "Testing if " << (*it1)->GetNameOfClass() <<
" has a counterpart " << i);
305 if (strcmp(figure1->GetNameOfClass(), figure2->GetNameOfClass()) != 0)
310 if (strcmp(figure1->GetNameOfClass(),
"PlanarCross") == 0)
312 std::cout <<
"Planar Cross Found" << std::endl;
327 if (point1.EuclideanDistanceTo(point2) >=
mitk::eps)
338 if (properties1->size() != properties2->size())
344 for (
auto i1 = properties1->begin(); i1 != properties1->end(); ++i1)
346 std::cout << i1->first << std::endl;
350 for (
auto i2 = properties2->begin(); i2 != properties2->end(); ++i2)
352 std::cout << i2->first << std::endl;
358 if (!std::equal(properties1->begin(), properties1->end(), properties2->begin(), PropertyMapEntryCompare()))
370 const TransformType::ParametersType ¶meters1 = affineGeometry1->GetParameters();
371 const TransformType::ParametersType ¶meters2 = planeGeometry2->GetIndexToWorldTransform()->GetParameters();
372 for (
unsigned int i = 0; i < affineGeometry1->GetNumberOfParameters(); ++i)
374 if (fabs(parameters1.GetElement(i) - parameters2.GetElement(i)) >=
mitk::eps)
382 const BoundsArrayType &bounds1 = planeGeometry1->GetBounds();
383 const BoundsArrayType &bounds2 = planeGeometry2->GetBounds();
384 for (
unsigned int i = 0; i < 6; ++i)
386 if (fabs(bounds1.GetElement(i) - bounds2.GetElement(i)) >=
mitk::eps)
395 if ((spacing1 - spacing2).GetNorm() >=
mitk::eps)
403 if (origin1.EuclideanDistanceTo(origin2) >=
mitk::eps)
410 static void SerializePlanarFigures(PlanarFigureList &planarFigures, std::string &fileName)
413 std::cout <<
"File name: " << fileName << std::endl;
416 writer->SetFileName(fileName.c_str());
419 PlanarFigureList::iterator it;
420 for (it = planarFigures.begin(), i = 0; it != planarFigures.end(); ++it, ++i)
422 writer->SetInput(i, *it);
430 static PlanarFigureList DeserializePlanarFigures(std::string &fileName)
434 reader->SetFileName(fileName.c_str());
440 PlanarFigureList planarFigures;
441 for (
unsigned int i = 0; i < reader->GetNumberOfOutputs(); ++i)
444 planarFigures.push_back(figure);
447 return planarFigures;
450 static PlanarFigureToMemoryWriterList SerializePlanarFiguresToMemoryBuffers(PlanarFigureList &planarFigures)
452 PlanarFigureToMemoryWriterList pfMemoryWriters;
454 PlanarFigureList::iterator it;
457 for (it = planarFigures.begin(), i = 0; it != planarFigures.end(); ++it, ++i)
460 writer->SetWriteToMemory(
true);
461 writer->SetInput(*it);
464 pfMemoryWriters.push_back(writer);
466 if (!writer->GetSuccess())
472 return pfMemoryWriters;
475 static PlanarFigureList DeserializePlanarFiguresFromMemoryBuffers(PlanarFigureToMemoryWriterList pfMemoryWriters)
478 PlanarFigureList planarFigures;
480 for (
unsigned int i = 0; i < pfMemoryWriters.size(); ++i)
484 reader->SetReadFromMemory(
true);
485 reader->SetMemoryBuffer(pfMemoryWriters[i]->GetMemoryPointer(), pfMemoryWriters[i]->GetMemorySize());
488 planarFigures.push_back(figure);
490 if (!reader->GetSuccess())
496 return planarFigures;
500 class PropertyMapEntryCompare
503 bool operator()(
const mitk::PropertyList::PropertyMap::value_type &entry1,
504 const mitk::PropertyList::PropertyMap::value_type &entry2)
506 MITK_INFO <<
"Comparing " << entry1.first <<
"(" << entry1.second->GetValueAsString() <<
") and " << entry2.first
507 <<
"(" << entry2.second->GetValueAsString() <<
")";
509 return *(entry1.second) == *(entry2.second);
529 PlanarFigureIOTestClass::PlanarFigureList originalPlanarFigures = PlanarFigureIOTestClass::CreatePlanarFigures();
532 PlanarFigureIOTestClass::PlanarFigureList copiedPlanarFigures =
533 PlanarFigureIOTestClass::CreateDeepCopiedPlanarFigures(originalPlanarFigures);
535 PlanarFigureIOTestClass::VerifyPlanarFigures(originalPlanarFigures, copiedPlanarFigures);
538 PlanarFigureIOTestClass::PlanarFigureList clonedPlanarFigures =
539 PlanarFigureIOTestClass::CreateClonedPlanarFigures(originalPlanarFigures);
541 PlanarFigureIOTestClass::VerifyPlanarFigures(originalPlanarFigures, clonedPlanarFigures);
545 static unsigned long count = 0;
546 unsigned long n = count++;
547 std::ostringstream name;
548 for (
int i = 0; i < 6; ++i)
550 name << char(
'a' + (n % 26));
554 myname.append(name.str());
556 std::string fileName = itksys::SystemTools::GetCurrentWorkingDirectory() + myname +
".pf";
558 PlanarFigureIOTestClass::SerializePlanarFigures(originalPlanarFigures, fileName);
561 PlanarFigureIOTestClass::PlanarFigureToMemoryWriterList writersWithMemoryBuffers =
562 PlanarFigureIOTestClass::SerializePlanarFiguresToMemoryBuffers(originalPlanarFigures);
565 PlanarFigureIOTestClass::PlanarFigureList retrievedPlanarFigures =
566 PlanarFigureIOTestClass::DeserializePlanarFigures(fileName);
569 PlanarFigureIOTestClass::PlanarFigureList retrievedPlanarFiguresFromMemory =
570 PlanarFigureIOTestClass::DeserializePlanarFiguresFromMemoryBuffers(writersWithMemoryBuffers);
572 auto it = writersWithMemoryBuffers.begin();
573 while (it != writersWithMemoryBuffers.end())
575 (*it)->ReleaseMemory();
580 PlanarFigureIOTestClass::VerifyPlanarFigures(originalPlanarFigures, retrievedPlanarFigures);
583 PlanarFigureIOTestClass::VerifyPlanarFigures(originalPlanarFigures, retrievedPlanarFiguresFromMemory);
586 originalPlanarFigures.clear();
589 PlanarFigureIOTestClass::VerifyPlanarFigures(copiedPlanarFigures, retrievedPlanarFigures);
BoundingBoxType::BoundsArrayType BoundsArrayType
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
GeometryTransformHolder::TransformType TransformType
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
std::map< std::string, BaseProperty::Pointer > PropertyMap
mitk::PropertyList::Pointer GetPropertyList() const
Get the data's property list.
MITKCORE_EXPORT const ScalarType eps
Describes a two-dimensional, rectangular plane.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
BoundingBoxType::BoundsArrayType BoundsArrayType