22 #include "Poco/File.h"
23 #include "Poco/TemporaryFile.h"
39 class SceneIOTestClass
86 mitk::AffineTransform3D::MatrixType matrix;
90 mitk::AffineTransform3D::OffsetType
offset;
92 bool isImageGeometry(
false);
93 unsigned int frameOfReferenceID(47);
102 newTransform->SetMatrix(matrix);
103 newTransform->SetOffset(offset);
106 newGeometry->SetFrameOfReferenceID(frameOfReferenceID);
107 newGeometry->SetImageGeometry(isImageGeometry);
109 newGeometry->SetIndexToWorldTransform(newTransform);
111 newGeometry->SetBounds(bounds);
112 newGeometry->SetOrigin(origin);
113 newGeometry->SetSpacing(spacing);
116 gdata->SetGeometry(newGeometry);
121 static void FillStorage(
mitk::DataStorage *storage, std::string imageName, std::string surfaceName)
131 imagenode->SetData(image);
132 imagenode->SetName(
"Pic3D");
133 storage->
Add(imagenode);
136 imagechildnode->SetData(image);
137 imagechildnode->SetName(
"Pic3D again");
138 storage->
Add(imagechildnode, imagenode);
147 surfacenode->SetData(surface);
148 surfacenode->SetName(
"binary");
149 storage->
Add(surfacenode);
153 psenode->SetData(ps);
154 psenode->SetName(
"points");
155 storage->
Add(psenode);
159 geomNode->SetData(gdo);
160 geomNode->SetName(
"geometry3d");
161 storage->
Add(geomNode);
173 std::string testString(
"");
174 float testFloatValue = 0.0f;
177 imagePropList->GetStringProperty(
"image type", testString);
178 MITK_TEST_CONDITION(testString ==
"test image",
"Get StringProperty from previously stored image");
180 imagePropList->GetStringProperty(
"greetings", testString);
181 MITK_TEST_CONDITION(testString ==
"to mom",
"Get another StringProperty from previously stored image");
183 imagePropList->GetFloatProperty(
"test_float_property", testFloatValue);
184 MITK_TEST_CONDITION(testFloatValue == -2.57f,
"Get FloatProperty from previously stored image.")
187 mitk::DataNode::
Pointer imagechildnode = storage->GetNamedNode("Pic3D again");
188 mitk::DataStorage::SetOfObjects::
ConstPointer objects = storage->GetSources(imagechildnode);
197 mitk::DataNode::
Pointer surfacenode = storage->GetNamedNode("binary");
200 mitk::Surface::
Pointer surface = dynamic_cast<
mitk::Surface *>(surfacenode->GetData());
204 mitk::PropertyList::
Pointer surfacePropList = surface->GetPropertyList();
205 surfacePropList->GetStringProperty("surface type", testString);
207 "Get StringProperty from previously stored surface node");
209 surfacePropList->GetStringProperty("greetings", testString);
211 "Get another StringProperty from previously stored surface node");
214 mitk::DataNode::
Pointer pointsnode = storage->GetNamedNode("points");
217 mitk::PointSet::
Pointer pointset = dynamic_cast<
mitk::PointSet *>(pointsnode->GetData());
223 p = pointset->GetPoint(1);
225 "Test Pointset entry 1 after loading");
227 p = pointset->GetPoint(2);
231 mitk::DataNode::
Pointer geomnode = storage->GetNamedNode("geometry3d");
234 mitk::GeometryData::
Pointer gdata = dynamic_cast<
mitk::GeometryData *>(geomnode->GetData());
237 mitk::Geometry3D::
Pointer geom3D = dynamic_cast<
mitk::Geometry3D *>(gdata->GetGeometry());
239 MITK_TEST_CONDITION(geom3D->GetImageGeometry() == false, "Reconstructed Geometry3D 'is image geometry'");
240 MITK_TEST_CONDITION(geom3D->GetFrameOfReferenceID() == 47, "Reconstructa Geometry3D has frame of reference '47'");
249 std::string sceneFileName;
251 for (
unsigned int i = 0; i < 1; ++i)
258 long int value = ulimit(UL_SETFSIZE, 1);
272 std::cout <<
"ImageName: " << argv[1] << std::endl;
273 std::cout <<
"SurfaceName: " << argv[2] << std::endl;
275 SceneIOTestClass::FillStorage(storage, argv[1], argv[2]);
278 Poco::Path newname(Poco::TemporaryFile::tempName());
279 sceneFileName = std::string(
MITK_TEST_OUTPUT_DIR) + Poco::Path::separator() + newname.getFileName() +
".zip";
281 "Saving scene file '" << sceneFileName <<
"'");
285 if (failedNodes.IsNotNull() && !failedNodes->empty())
288 for (mitk::SceneIO::FailedBaseDataListType::const_iterator iter = failedNodes->begin();
289 iter != failedNodes->end();
308 if (failedProperties.IsNotNull() && !failedProperties->IsEmpty())
312 for (mitk::PropertyList::PropertyMap::const_iterator iter = propmap->begin(); iter != propmap->end(); ++iter)
314 MITK_TEST_OUTPUT(<<
" - " << iter->second->GetNameOfClass() <<
" associated to key '" << iter->first <<
"'");
319 "Checking if all properties have been saved.")
321 "Checking if all nodes have been saved.")
328 storage = sceneIO->LoadScene(sceneFileName, storage,
true);
331 failedNodes = sceneIO->GetFailedNodes();
332 if (failedNodes.IsNotNull() && !failedNodes->empty())
335 for (mitk::SceneIO::FailedBaseDataListType::const_iterator iter = failedNodes->begin();
336 iter != failedNodes->end();
354 failedProperties = sceneIO->GetFailedProperties();
355 if (failedProperties.IsNotNull() && !failedProperties->IsEmpty())
359 for (mitk::PropertyList::PropertyMap::const_iterator iter = propmap->begin(); iter != propmap->end(); ++iter)
361 MITK_TEST_OUTPUT(<<
" - " << iter->second->GetNameOfClass() <<
" associated to key '" << iter->first <<
"'");
367 SceneIOTestClass::VerifyStorage(storage);
374 pocoSceneFile.remove();
virtual void Add(mitk::DataNode *node, const mitk::DataStorage::SetOfObjects *parents=nullptr)=0
Adds a DataNode containing a data object to its internal storage.
static mitk::Surface::Pointer LoadSurface(const std::string &path)
LoadSurface Convenience method to load an arbitrary mitkSurface.
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
BoundingBoxType::BoundsArrayType BoundsArrayType
Base of all data objects.
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
DataCollection - Class to facilitate loading/accessing structured data.
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
itk::SmartPointer< const Self > ConstPointer
#define MITK_TEST_OUTPUT(x)
Output some text.
T::Pointer GetData(const std::string &name)
int mitkSceneIOTest(int, char *argv[])
static TestManager * GetInstance()
#define MITK_TEST_OUTPUT_NO_ENDL(x)
Output some text without generating a terminating newline. Include.
virtual SetOfObjects::ConstPointer GetAll() const =0
returns a set of all data objects that are stored in the data storage
#define MITK_TEST_OUTPUT_DIR
std::map< std::string, BaseProperty::Pointer > PropertyMap
#define MITK_TEST_CONDITION(COND, MSG)
bool compare(std::pair< double, int > i, std::pair< double, int > j)
static const std::string filename
#define MITK_TEST_FAILED_MSG(MSG)
Fail and finish test with message MSG.
Image class for storing images.
mitk::DataNode * GetNamedNode(const char *name) const
Convenience method to get the first node with a given name.
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.