Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkSceneIOTestScenarioProvider.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 
18 
19 #include "mitkGeometryData.h"
20 #include "mitkImage.h"
21 #include "mitkImageGenerator.h"
22 #include "mitkPointSet.h"
23 #include "mitkProperties.h"
24 #include "mitkSurface.h"
25 
26 #include <vtkCellArray.h>
27 #include <vtkPolyData.h>
28 #include <vtkPolygon.h>
29 
30 namespace
31 {
32  std::string VeryLongText =
33  "Lorem ipsum dolor sit amet, consectetur adipiscing elit.Donec a diam lectus.Sed sit amet ipsum mauris.Maecenas "
34  "congue ligula ac quam viverra nec consectetur ante hendrerit.Donec et mollis dolor.Praesent et diam eget libero "
35  "egestas mattis sit amet vitae augue.Nam tincidunt congue enim, ut porta lorem lacinia consectetur.Donec ut libero "
36  "sed arcu vehicula ultricies a non tortor.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Aenean ut "
37  "gravida lorem.Ut turpis felis, pulvinar a semper sed, adipiscing id dolor.Pellentesque auctor nisi id magna "
38  "consequat sagittis.Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet.Ut convallis "
39  "libero in urna ultrices accumsan.Donec sed odio eros.Donec viverra mi quis quam pulvinar at malesuada arcu "
40  "rhoncus.Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.In rutrum accumsan "
41  "ultricies.Mauris vitae nisi at sem facilisis semper ac in est.\n"
42  "Vivamus fermentum semper porta.Nunc diam velit, adipiscing ut tristique vitae, sagittis vel odio.Maecenas "
43  "convallis ullamcorper ultricies.Curabitur ornare, ligula semper consectetur sagittis, nisi diam iaculis velit, id "
44  "fringilla sem nunc vel mi.Nam dictum, odio nec pretium volutpat, arcu ante placerat erat, non tristique elit urna "
45  "et turpis.Quisque mi metus, ornare sit amet fermentum et, tincidunt et orci.Fusce eget orci a orci congue "
46  "vestibulum.Ut dolor diam, elementum et vestibulum eu, porttitor vel elit.Curabitur venenatis pulvinar tellus "
47  "gravida ornare.Sed et erat faucibus nunc euismod ultricies ut id justo.Nullam cursus suscipit nisi, et ultrices "
48  "justo sodales nec.Fusce venenatis facilisis lectus ac semper.Aliquam at massa ipsum.Quisque bibendum purus "
49  "convallis nulla ultrices ultricies.Nullam aliquam, mi eu aliquam tincidunt, purus velit laoreet tortor, viverra "
50  "pretium nisi quam vitae mi.Fusce vel volutpat elit.Nam sagittis nisi dui.\r\n"
51  "Suspendisse lectus leo, consectetur in tempor sit amet, placerat quis neque.Etiam luctus porttitor lorem, sed "
52  "suscipit est rutrum non.Curabitur lobortis nisl a enim congue semper.Aenean commodo ultrices imperdiet.Vestibulum "
53  "ut justo vel sapien venenatis tincidunt.Phasellus eget dolor sit amet ipsum dapibus condimentum vitae quis "
54  "lectus.Aliquam ut massa in turpis dapibus convallis.Praesent elit lacus, vestibulum at malesuada et, ornare et "
55  "est.Ut augue nunc, sodales ut euismod non, adipiscing vitae orci.Mauris ut placerat justo.Mauris in ultricies "
56  "enim.Quisque nec est eleifend nulla ultrices egestas quis ut quam.Donec sollicitudin lectus a mauris pulvinar id "
57  "aliquam urna cursus.Cras quis ligula sem, vel elementum mi.Phasellus non ullamcorper urna.\t\n"
58  "Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.In euismod ultrices "
59  "facilisis.Vestibulum porta sapien adipiscing augue congue id pretium lectus molestie.Proin quis dictum nisl.Morbi "
60  "id quam sapien, sed vestibulum sem.Duis elementum rutrum mauris sed convallis.Proin vestibulum magna mi.Aenean "
61  "tristique hendrerit magna, ac facilisis nulla hendrerit ut.Sed non tortor sodales quam auctor elementum.Donec "
62  "hendrerit nunc eget elit pharetra pulvinar.Suspendisse id tempus tortor.Aenean luctus, elit commodo laoreet "
63  "commodo, justo nisi consequat massa, sed vulputate quam urna quis eros.Donec vel.";
64 }
65 
66 // --------------- SceneIOTestScenarioProvider::Scenario ---------------
67 
69 {
70  return (*m_ScenarioProvider.*m_ProviderMethod)(); // calls function
71 }
72 
74  const SceneIOTestScenarioProvider *_scenarioProvider,
76  bool _isSerializable,
77  const std::string &_referenceArchiveFilename,
78  bool _isReferenceLoadable,
79  double _comparisonPrecision)
80  : key(_key),
81  serializable(_isSerializable),
82  referenceArchiveFilename(_referenceArchiveFilename),
83  referenceArchiveLoadable(_isReferenceLoadable),
84  comparisonPrecision(_comparisonPrecision),
85  m_ScenarioProvider(_scenarioProvider),
86  m_ProviderMethod(_providerMethod)
87 {
88 }
89 
90 // --------------- SceneIOTestScenarioProvider ---------------
91 
93 {
94  return m_Scenarios;
95 }
96 
97 void mitk::SceneIOTestScenarioProvider::AddScenario(const std::string &key,
98  BuilderMethodPointer creator,
99  bool isSerializable,
100  const std::string &referenceArchiveFilename,
101  bool isReferenceLoadable,
102  double comparisonPrecision)
103 {
104  Scenario newScenario(
105  key, this, creator, isSerializable, referenceArchiveFilename, isReferenceLoadable, comparisonPrecision);
106  m_Scenarios.push_back(newScenario);
107 }
108 
109 mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::EmptyStorage() const
110 {
112  return storage;
113 }
114 
115 mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::OneEmptyNode() const
116 {
118 
120  storage->Add(node);
121 
122  return storage;
123 }
124 
125 mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::OneEmptyNamedNode() const
126 {
128 
130  node->SetName("Urmel");
131  storage->Add(node);
132 
133  return storage;
134 }
135 
136 mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::ManyTopLevelNodes() const
137 {
139 
140  for (auto i = 0; i < m_HowMuchIsMany; ++i)
141  {
143  std::stringstream s;
144  s << "Node #" << i;
145  node->SetName(s.str());
146  storage->Add(node);
147  }
148 
149  return storage;
150 }
151 
152 mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::LineOfManyOnlyChildren() const
153 {
155 
157  for (auto i = 0; i < m_HowMuchIsMany; ++i)
158  {
160  std::stringstream s;
161  s << "Node #" << i;
162  node->SetName(s.str());
163  storage->Add(node, parent);
164  parent = node;
165  }
166 
167  return storage;
168 }
169 
170 #define AddNode(name) storage->Add(name);
171 
172 #define DefineNode(name) \
173  mitk::DataNode::Pointer name = mitk::DataNode::New(); \
174  name->SetName(#name);
175 
176 #define DefNode0(name) DefineNode(name) AddNode(name)
177 
178 #define DefNode1(source, name) DefineNode(name) storage->Add(name, source);
179 
180 #define DefNode2(source1, source2, name) \
181  DefineNode(name) \
182  { \
183  mitk::DataStorage::SetOfObjects::Pointer sources = mitk::DataStorage::SetOfObjects::New(); \
184  sources->push_back(source1); \
185  sources->push_back(source2); \
186  storage->Add(name, sources); \
187  }
188 
189 #define DefNode3(source1, source2, source3, name) \
190  DefineNode(name) \
191  { \
192  mitk::DataStorage::SetOfObjects::Pointer sources = mitk::DataStorage::SetOfObjects::New(); \
193  sources->push_back(source1); \
194  sources->push_back(source2); \
195  sources->push_back(source3); \
196  storage->Add(name, sources); \
197  }
198 
199 mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::ComplicatedFamilySituation() const
200 {
202 
203  // constructing a hierarchy with multiple levels
204  // and a couple of multiple parent relations.
205 
206  // Anybody, feel free to make this something
207  // meaningful and/or visualize it :-)
208 
209  DefNode0(Color) DefNode0(White)
210 
211  DefNode1(Color, Green) DefNode1(Color, Election) DefNode1(Color, Red)
212 
213  DefNode1(Green, Yellow)
214 
215  DefNode1(Election, Looser) DefNode1(Election, FreeBeer) DefNode1(Election, Winner)
216 
217  DefNode1(Looser, Tears) DefNode1(Looser, Anger)
218 
219  DefNode1(FreeBeer, OpenSource);
220 
221  DefNode1(White, Sweet)
222 
223  DefNode2(White, Sweet, Sugar) DefNode2(Red, Sweet, Tomatoe) DefNode2(Tomatoe, Sugar, Ketchup)
224 
225  DefNode1(Ketchup, BBQSauce) DefNode1(Tomatoe, ATLAS)
226 
227  DefNode0(Fish) DefNode0(OperatingSystem) DefNode1(Fish, Bird) DefNode1(Bird, Penguin)
228 
229  DefNode3(Penguin, OperatingSystem, OpenSource, Linux)
230 
231  return storage;
232 }
233 
234 mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::Image() const
235 {
237 
238  { // Image of ints
239  mitk::Image::Pointer image3Dints = mitk::ImageGenerator::GenerateRandomImage<int>(10,
240  5,
241  7, // dim
242  1,
243  0.5,
244  0.5, // spacing
245  1, // time steps
246  3000,
247  -1000); // random max / min
249  node->SetName("Image-Int");
250  node->SetData(image3Dints);
251  storage->Add(node);
252  }
253 
254  { // Image of doubles
255  mitk::Image::Pointer image3Ddouble = mitk::ImageGenerator::GenerateRandomImage<double>(5,
256  10,
257  8, // dim
258  1,
259  0.5,
260  0.5, // spacing
261  2, // time steps
262  3000,
263  -1000); // random max / min
265  node->SetName("Image-Double");
266  node->SetData(image3Ddouble);
267  storage->Add(node);
268  }
269 
270  return storage;
271 }
272 
273 mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::Surface() const
274 {
276 
277  { // Surface
278  vtkSmartPointer<vtkPoints> points1 = vtkSmartPointer<vtkPoints>::New();
279  points1->InsertNextPoint(0.0, 0.0, 0.0);
280  points1->InsertNextPoint(1.0, 0.0, 0.0);
281  points1->InsertNextPoint(0.0, 1.0, 0.0);
282  points1->InsertNextPoint(1.0, 1.0, 0.0);
283 
284  vtkSmartPointer<vtkPolygon> polygon1 = vtkSmartPointer<vtkPolygon>::New();
285  polygon1->GetPointIds()->SetNumberOfIds(4);
286  polygon1->GetPointIds()->SetId(0, 0);
287  polygon1->GetPointIds()->SetId(1, 1);
288  polygon1->GetPointIds()->SetId(2, 2);
289  polygon1->GetPointIds()->SetId(3, 3);
290 
291  vtkSmartPointer<vtkPolygon> polygon2 = vtkSmartPointer<vtkPolygon>::New();
292  polygon2->GetPointIds()->SetNumberOfIds(4);
293  polygon2->GetPointIds()->SetId(0, 3);
294  polygon2->GetPointIds()->SetId(1, 2);
295  polygon2->GetPointIds()->SetId(2, 0);
296  polygon2->GetPointIds()->SetId(3, 1);
297 
298  // generate polydatas
299  vtkSmartPointer<vtkCellArray> polygonArray1 = vtkSmartPointer<vtkCellArray>::New();
300  polygonArray1->InsertNextCell(polygon1);
301 
302  vtkSmartPointer<vtkPolyData> polydata1 = vtkSmartPointer<vtkPolyData>::New();
303  polydata1->SetPoints(points1);
304  polydata1->SetPolys(polygonArray1);
305 
306  vtkSmartPointer<vtkCellArray> polygonArray2 = vtkSmartPointer<vtkCellArray>::New();
307  polygonArray2->InsertNextCell(polygon2);
308 
309  vtkSmartPointer<vtkPolyData> polyDataTwo = vtkSmartPointer<vtkPolyData>::New();
310  polyDataTwo->SetPoints(points1);
311  polyDataTwo->SetPolys(polygonArray2);
312 
313  // generate surfaces
315  surface->SetVtkPolyData(polydata1);
316 
318  node->SetName("Surface");
319  node->SetData(surface);
320  storage->Add(node);
321  }
322 
323  return storage;
324 }
325 
326 mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::PointSet() const
327 {
329 
330  { // PointSet
333  mitk::FillVector3D(p, 1.0, -2.0, 33.0);
334  ps->SetPoint(0, p);
335  mitk::FillVector3D(p, 100.0, -200.0, 3300.0);
336  ps->SetPoint(1, p);
337  mitk::FillVector3D(p, 2.0, -3.0, 22.0);
338  ps->SetPoint(2, p, mitk::PTCORNER); // add point spec
339 
341  node->SetName("PointSet");
342  node->SetData(ps);
343  storage->Add(node);
344  }
345 
346  return storage;
347 }
348 
349 mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::GeometryData() const
350 {
352 
353  { // GeometryData
355 
356  // define Geometry3D parameters
357  mitk::AffineTransform3D::MatrixType matrix;
358  matrix[0][0] = 1.1;
359  matrix[1][1] = 2.2;
360  matrix[2][2] = 3.3;
361  mitk::AffineTransform3D::OffsetType offset;
362  mitk::FillVector3D(offset, 0.1, 0.2, 0.3);
363  bool isImageGeometry(false);
364  unsigned int frameOfReferenceID(47);
365 
368  bounds[1] = -52.723;
369  bounds[2] = -0.002;
370  bounds[3] = 918273645.18293746;
371  bounds[4] = -0.002;
372  bounds[5] = +52.723;
373 
374  mitk::Point3D origin;
375  mitk::FillVector3D(origin, 5.1, 5.2, 5.3);
376  mitk::Vector3D spacing;
377  mitk::FillVector3D(spacing, 2.1, 2.2, 2.3);
378 
379  // build GeometryData from matrix/offset/etc.
381  newTransform->SetMatrix(matrix);
382  newTransform->SetOffset(offset);
383 
385  newGeometry->SetFrameOfReferenceID(frameOfReferenceID);
386  newGeometry->SetImageGeometry(isImageGeometry);
387 
388  newGeometry->SetIndexToWorldTransform(newTransform);
389 
390  newGeometry->SetBounds(bounds);
391  newGeometry->SetOrigin(origin);
392  newGeometry->SetSpacing(spacing);
393 
395  geometryData->SetGeometry(newGeometry);
396 
398  node->SetName("GeometryData");
399  node->SetData(geometryData);
400  storage->Add(node);
401  }
402 
403  return storage;
404 }
405 
406 mitk::DataStorage::Pointer mitk::SceneIOTestScenarioProvider::SpecialProperties() const
407 {
409 
411  node->SetName("Camion");
412 
413  node->SetProperty("", StringProperty::New("Colis")); // no name!
414  node->SetProperty("Livre", StringProperty::New(VeryLongText)); // defined at the top of this file
415  node->SetProperty(VeryLongText.c_str(), StringProperty::New("Shorty"));
416 
417  node->GetPropertyList("Chapitre1")->SetProperty("Page 1", StringProperty::New(VeryLongText));
418  node->GetPropertyList("Chapitre1")->SetProperty("Page 2", StringProperty::New(VeryLongText));
419  node->GetPropertyList("Chapitre 2")->SetProperty("Page", StringProperty::New(VeryLongText));
420  node->GetPropertyList("Chapitre 3")->SetProperty("Page", StringProperty::New(VeryLongText));
421  node->GetPropertyList(VeryLongText)->SetProperty("Page", StringProperty::New(VeryLongText));
422 
423  // not working (NaN etc.)
424  // node->SetProperty("NotAFloat", FloatProperty::New( sqrt(-1.0) ) );
425  node->SetProperty("sqrt(2)", FloatProperty::New(-sqrt(2.0)));
426  node->SetProperty("sqrt(3)", FloatProperty::New(sqrt(3.0)));
427 
428  // most values work fine, just min/max double produces serialization precision errors
429  node->SetProperty("sqrt(4)", DoubleProperty::New(-sqrt(4.0)));
430  node->SetProperty("sqrt(5)", DoubleProperty::New(sqrt(5.0)));
431  // node->SetProperty("maxd", DoubleProperty::New( std::numeric_limits<double>::max() ) );
432  node->SetProperty("zero", DoubleProperty::New(0.0));
433  node->SetProperty("minzero", DoubleProperty::New(-0.0));
434  // node->SetProperty("mind", DoubleProperty::New( std::numeric_limits<double>::min() ) );
435 
436  storage->Add(node);
437 
438  return storage;
439 }
static Pointer New()
itk::SmartPointer< Self > Pointer
BoundingBoxType::BoundsArrayType BoundsArrayType
#define DefNode2(source1, source2, name)
static Pointer New()
static Pointer New()
void FillVector3D(Tout &out, mitk::ScalarType x, mitk::ScalarType y, mitk::ScalarType z)
Definition: mitkArray.h:110
DataStorage::Pointer BuildDataStorage() const
Construct the DataStorage for this scenario.
static Vector3D offset
static Pointer New()
DataStorage::Pointer(SceneIOTestScenarioProvider::* BuilderMethodPointer)() const
Typedef for type BuilderMethodPointer which is function pointer to member of SceneIOTestScenarioProvi...
#define DefNode3(source1, source2, source3, name)
static Pointer New()
#define DefNode1(source, name)
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
static Pointer New()
Scenario(const std::string &_key, const SceneIOTestScenarioProvider *_scenarioProvider, SceneIOTestScenarioProvider::BuilderMethodPointer _providerMethod, bool _isSerializable, const std::string &_referenceArchiveFilename, bool _isReferenceLoadable, double _comparisonPrecision)
static T min(T x, T y)
Definition: svm.cpp:67
Provides DataStorages that serve as test scenarios.
std::vector< Scenario > ScenarioList
List of Scenarios.
#define DefNode0(name)
static Pointer New()
static Pointer New()
ScenarioList GetAllScenarios() const
Returns all registered scenarios.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.