47 class TestStandaloneDataStorage :
public StandaloneDataStorage
51 itkFactorylessNewMacro(Self)
52 itkCloneMacro(Self)
std::
map<const
mitk::DataNode *,
unsigned long> GetModifiedObserverTags()
const
58 TestStandaloneDataStorage() {}
68 DSEventReceiver() : m_NodeAdded(NULL), m_NodeRemoved(NULL) {}
70 void OnRemove(
const mitk::DataNode *node) { m_NodeRemoved = node; }
80 struct ItkDeleteEventListener
92 onObjectDelete->SetCallbackFunction(
this, &ItkDeleteEventListener::OnObjectDelete);
93 m_DeleteObserverTag =
m_Node->AddObserver(itk::DeleteEvent(), onObjectDelete);
96 void OnObjectDelete(
const itk::Object * ,
const itk::EventObject &)
108 unsigned int m_DeleteObserverTag;
124 "Testing if modified"
125 " observer was added.");
128 " observer was added.");
131 "Testing if modified"
132 " observer was removed.");
135 " observer was removed.");
183 n2->SetData(surface);
186 color.Set(1.0f, 1.0f, 0.0f);
190 parents2->InsertElement(0, n1);
197 parents3->InsertElement(0, n2);
203 parents4->InsertElement(0, n2);
204 parents4->InsertElement(1, n3);
212 ds->
Add(n1, parents1);
214 "Testing Adding a new object");
222 ds->
Add(n2, parents2);
226 ds->
Add(n3, parents3);
227 ds->
Add(n4, parents4);
241 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
245 (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()) &&
246 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
247 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end()) &&
248 (std::find(stlAll.begin(), stlAll.end(), n4) != stlAll.end()) &&
249 (std::find(stlAll.begin(), stlAll.end(), n5) != stlAll.end()),
257 MITK_TEST_CONDITION((all->Size() == 1) && (all->GetElement(0) == n2),
"Requesting a named object");
264 MITK_TEST_CONDITION((all->Size() == 1) && (all->GetElement(0) == n1),
"Requesting objects of specific data type")
270 MITK_TEST_CONDITION((all->Size() == 1) && (all->GetElement(0) == n1),
"Requesting objects of specific dimension")
277 "Requesting objects with specific data object")
283 MITK_TEST_CONDITION((all->Size() == 3) && (std::find(all->begin(), all->end(), n3) != all->end()) &&
284 (std::find(all->begin(), all->end(), n4) != all->end()) &&
285 (std::find(all->begin(), all->end(), n5) != all->end()),
286 "Requesting objects with NULL data");
294 predicate->AddPredicate(p1);
295 predicate->AddPredicate(p2);
298 "Requesting objects that meet a conjunction criteria");
306 predicate->AddPredicate(p1);
307 predicate->AddPredicate(p2);
309 MITK_TEST_CONDITION((all->Size() == 3) && (std::find(all->begin(), all->end(), n1) != all->end()) &&
310 (std::find(all->begin(), all->end(), n2) != all->end()) &&
311 (std::find(all->begin(), all->end(), n4) != all->end()),
312 "Requesting objects that meet a disjunction criteria");
321 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
324 (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()) &&
325 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end()) &&
326 (std::find(stlAll.begin(), stlAll.end(), n5) != stlAll.end()),
327 "Requesting objects that do not meet a criteria");
334 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
335 MITK_TEST_CONDITION((all->Size() == 1) && (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()),
336 "Requesting *direct* source objects");
343 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
344 MITK_TEST_CONDITION((all->Size() == 2) && (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()) &&
345 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()),
346 "Requesting *all* source objects");
353 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
355 (all->Size() == 3) && (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()) &&
356 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
357 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end())
359 "Requesting *all* sources of object with multiple parents");
366 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
370 "Requesting *direct* derived objects");
378 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
380 (all->Size() == 2) &&
381 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end())
383 (std::find(stlAll.begin(), stlAll.end(), n4) != stlAll.end())
385 "Requesting *direct* derived objects with multiple parents/derivations");
392 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
393 MITK_TEST_CONDITION((all->Size() == 3) && (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
394 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end()) &&
395 (std::find(stlAll.begin(), stlAll.end(), n4) != stlAll.end()),
396 "Requesting *all* derived objects");
401 parents1->InsertElement(0, n4);
406 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
408 (all->Size() == 3) && (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()) &&
409 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
410 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end())
412 "Checking for circular source relationships");
425 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
428 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
429 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end()),
430 "Checking GroupTagProperty");
438 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
441 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end()) &&
442 (std::find(stlAll.begin(), stlAll.end(), n4) != stlAll.end()),
443 "Checking GroupTagProperty 2");
450 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
453 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()),
454 "checking direct sources with condition");
461 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
464 (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()),
465 "Checking all sources with condition");
473 "Checking all sources with condition with empty resultset");
480 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
483 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()),
484 "Checking direct derivations with condition");
492 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
495 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
496 (std::find(stlAll.begin(), stlAll.end(), n4) != stlAll.end()),
497 "Checking direct derivations with condition");
503 "Checking named node(std::string) method");
507 "Checking named node method with wrong name");
511 "Checking named object method");
513 "Checking named object(std::string) method");
517 "Checking named object method with wrong DataType");
521 "Checking named object method with wrong name");
525 "Checking GetNamedDerivedNode with valid name & direct derivation only");
529 "Checking GetNamedDerivedNode with invalid name & direct derivation only");
533 "Checking GetNamedDerivedNode with invalid name & direct derivation only");
537 "Checking GetNamedDerivedNode with valid Name but direct derivation only");
562 int refCountbeforeDS = watcher->GetReferenceCount();
567 "Checking removal of a node without relations");
577 int refCountbeforeDS = watcher->GetReferenceCount();
583 "Adding extra node");
587 "Checking removal of a node with a parent");
597 int refCountbeforeDS = watcher->GetReferenceCount();
611 (ds->
GetNamedNode(
"extra") == NULL) && (refCountbeforeDS == watcher->GetReferenceCount()) &&
616 "Checking removal of a node with two parents");
625 int refCountbeforeDS = watcher->GetReferenceCount();
646 (ds->
GetNamedNode(
"d2") == d2) && (refCountbeforeDS == watcher->GetReferenceCount()) &&
651 "Checking removal of a node with two derived nodes");
661 int refCountbeforeDS = watcher->GetReferenceCount();
692 (refCountbeforeDS == watcher->GetReferenceCount()) &&
701 "Checking removal of a node with two parents and two derived nodes");
733 MITK_TEST_CONDITION(watcher->GetReferenceCount() == 0,
"Checking reference count of node after add and remove");
745 int refCountbeforeDS = watcherD1y->GetReferenceCount();
767 (refCountbeforeDS == watcherD1y->GetReferenceCount()),
768 "Checking removal of subset of two derived nodes from one parent node");
777 const std::set<std::string> groupTags = ds->
GetGroupTags();
779 (std::find(groupTags.begin(), groupTags.end(),
"Resection Proposal 1") != groupTags.end()) &&
780 (std::find(groupTags.begin(), groupTags.end(),
"Resection Proposal 2") != groupTags.end()),
781 "Checking GetGrouptags()");
785 DSEventReceiver listener;
807 listener.m_NodeAdded = NULL;
808 listener.m_NodeRemoved = NULL;
811 MITK_TEST_CONDITION((listener.m_NodeRemoved == NULL) && (listener.m_NodeAdded == NULL),
"Checking RemoveListener");
813 std::cout <<
"Pointer handling after event handling: " << std::flush;
815 MITK_TEST_CONDITION(watcher->GetReferenceCount() == 0,
"Pointer handling after event handling");
830 MITK_TEST_CONDITION(geometry->CountTimeSteps() == 4,
"Test for number or time steps with ComputeBoundingGeometry()");
833 "Test for timebounds with ComputeBoundingGeometry()");
834 for (
unsigned int i = 0; i < geometry->CountTimeSteps(); i++)
839 "Test for timebounds of geometry at different time steps with ComputeBoundingGeometry()");
843 "Test for number or time steps with ComputeBoundingGeometry(allNodes)");
844 timebounds = geometry->GetTimeBounds();
846 "Test for timebounds with ComputeBoundingGeometry(allNodes)");
847 for (
unsigned int i = 0; i < geometry->CountTimeSteps(); i++)
852 "Test for timebounds of geometry at different time steps with ComputeBoundingGeometry()");
859 ItkDeleteEventListener listener(standaloneDataStorage);
863 listener.SetNode(emptyNode);
864 standaloneDataStorage->Add(emptyNode);
867 standaloneDataStorage->Remove(pEmptyNode);
mitk::DataNode * GetNode(const NodePredicateBase *condition=nullptr) const
Convenience method to get the first node that matches the predicate condition.
virtual void Add(mitk::DataNode *node, const mitk::DataStorage::SetOfObjects *parents=nullptr)=0
Adds a DataNode containing a data object to its internal storage.
Class for storing surfaces (vtkPolyData).
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
#define MITK_TEST_FOR_EXCEPTION_END(EXCEPTIONCLASS)
int mitkDataStorageTest(int argc, char *argv[])
itk::FixedArray< ScalarType, 2 > TimeBounds
Standard typedef for time-bounds.
std::map< const mitk::DataNode *, unsigned long > m_NodeModifiedObserverTags
Saves Modified-Observer Tags for each node in order to remove the event listeners again...
virtual SetOfObjects::ConstPointer GetDerivations(const mitk::DataNode *node, const NodePredicateBase *condition=nullptr, bool onlyDirectDerivations=true) const =0
returns a set of derived objects for a given node.
#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()
static Pointer New(unsigned int _arg)
#define MITK_TEST_FOR_EXCEPTION(EXCEPTIONCLASS, STATEMENT)
Simplified version of MITK_TEST_FOR_EXCEPTION_BEGIN / END for a single statement. ...
itk::SmartPointer< const Self > ConstPointer
virtual SetOfObjects::ConstPointer GetSources(const mitk::DataNode *node, const NodePredicateBase *condition=nullptr, bool onlyDirectSources=true) const =0
returns a set of source objects for a given node that meet the given condition(s).
#define MITK_TEST_OUTPUT(x)
Output some text.
mitk::DataNode::Pointer m_Node
const DataNode::GroupTagList GetGroupTags() const
Returns a list of used grouptags.
virtual SetOfObjects::ConstPointer GetAll() const =0
returns a set of all data objects that are stored in the data storage
DataType * GetNamedObject(const char *name) const
Convenience method to get the first data object of a given data type with a given name...
mitk::DataStorage::Pointer m_DataStorage
Keeps track of the reference count of an object even if it is destroyed.
SetOfObjects::ConstPointer GetSubset(const NodePredicateBase *condition) const
returns a set of data objects that meet the given condition(s)
static Pointer New(mitk::BaseData *_arg)
#define MITK_TEST_CONDITION(COND, MSG)
static const std::string filename
#define mitkClassMacro(className, SuperClassName)
std::map< const mitk::DataNode *, unsigned long > m_NodeDeleteObserverTags
Saves Delete-Observer Tags for each node in order to remove the event listeners again.
void TestDataStorage(mitk::DataStorage *ds, std::string filename)
Test for the DataStorage class and its associated classes (e.g. the predicate classes) This method wi...
static Pointer New(const mitk::NodePredicateBase *_arg)
#define MITK_TEST_FAILED_MSG(MSG)
Fail and finish test with message MSG.
Image class for storing images.
#define MITK_TEST_FOR_EXCEPTION_BEGIN(EXCEPTIONCLASS)
Begin block which should be checked for exceptions.
DataStorageEvent AddNodeEvent
AddEvent is emitted whenever a new node has been added to the DataStorage.
mitk::DataNode * GetNamedDerivedNode(const char *name, const mitk::DataNode *sourceNode, bool onlyDirectDerivations=true) const
Convenience method to get the first node with a given name that is derived from sourceNode.
static Pointer New(const char *_arg)
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
mitk::TimeGeometry::Pointer ComputeBoundingGeometry3D(const SetOfObjects *input, const char *boolPropertyKey=nullptr, const mitk::BaseRenderer *renderer=nullptr, const char *boolPropertyKey2=nullptr) const
Compute the axis-parallel bounding geometry of the input objects.
static Pointer New(const char *_arg)
DataStorageEvent RemoveNodeEvent
RemoveEvent is emitted directly before a node is removed from the DataStorage.
virtual void Remove(const mitk::DataNode *node)=0
Removes node from the DataStorage.
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.
Class for nodes of the DataTree.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.