43 class TestStandaloneDataStorage :
public StandaloneDataStorage
47 itkFactorylessNewMacro(Self)
48 itkCloneMacro(Self) std::map<const mitk::DataNode *, unsigned long> GetModifiedObserverTags()
const 54 TestStandaloneDataStorage() {}
64 DSEventReceiver() : m_NodeAdded(nullptr), m_NodeRemoved(nullptr) {}
66 void OnRemove(
const mitk::DataNode *node) { m_NodeRemoved = node; }
76 struct ItkDeleteEventListener
85 itk::MemberCommand<ItkDeleteEventListener>::Pointer onObjectDelete =
86 itk::MemberCommand<ItkDeleteEventListener>::New();
88 onObjectDelete->SetCallbackFunction(
this, &ItkDeleteEventListener::OnObjectDelete);
89 m_DeleteObserverTag =
m_Node->AddObserver(itk::DeleteEvent(), onObjectDelete);
92 void OnObjectDelete(
const itk::Object * ,
const itk::EventObject &)
104 unsigned int m_DeleteObserverTag;
120 "Testing if modified" 121 " observer was added.");
124 " observer was added.");
127 "Testing if modified" 128 " observer was removed.");
131 " observer was removed.");
175 mitk::DataStorage::SetOfObjects::Pointer parents1 = mitk::DataStorage::SetOfObjects::New();
179 n2->SetData(surface);
182 color.Set(1.0f, 1.0f, 0.0f);
185 mitk::DataStorage::SetOfObjects::Pointer parents2 = mitk::DataStorage::SetOfObjects::New();
186 parents2->InsertElement(0, n1);
192 mitk::DataStorage::SetOfObjects::Pointer parents3 = mitk::DataStorage::SetOfObjects::New();
193 parents3->InsertElement(0, n2);
198 mitk::DataStorage::SetOfObjects::Pointer parents4 = mitk::DataStorage::SetOfObjects::New();
199 parents4->InsertElement(0, n2);
200 parents4->InsertElement(1, n3);
208 ds->
Add(n1, parents1);
210 "Testing Adding a new object");
218 ds->
Add(n2, parents2);
222 ds->
Add(n3, parents3);
223 ds->
Add(n4, parents4);
236 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetAll();
237 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
241 (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()) &&
242 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
243 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end()) &&
244 (std::find(stlAll.begin(), stlAll.end(), n4) != stlAll.end()) &&
245 (std::find(stlAll.begin(), stlAll.end(), n5) != stlAll.end()),
252 mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSubset(predicate);
253 MITK_TEST_CONDITION((all->Size() == 1) && (all->GetElement(0) == n2),
"Requesting a named object");
259 mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSubset(predicate);
260 MITK_TEST_CONDITION((all->Size() == 1) && (all->GetElement(0) == n1),
"Requesting objects of specific data type")
265 mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSubset(predicate);
266 MITK_TEST_CONDITION((all->Size() == 1) && (all->GetElement(0) == n1),
"Requesting objects of specific dimension")
271 mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSubset(predicate);
273 "Requesting objects with specific data object")
278 mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSubset(predicate);
279 MITK_TEST_CONDITION((all->Size() == 3) && (std::find(all->begin(), all->end(), n3) != all->end()) &&
280 (std::find(all->begin(), all->end(), n4) != all->end()) &&
281 (std::find(all->begin(), all->end(), n5) != all->end()),
282 "Requesting objects with nullptr data");
290 predicate->AddPredicate(p1);
291 predicate->AddPredicate(p2);
292 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSubset(predicate);
294 "Requesting objects that meet a conjunction criteria");
302 predicate->AddPredicate(p1);
303 predicate->AddPredicate(p2);
304 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSubset(predicate);
305 MITK_TEST_CONDITION((all->Size() == 3) && (std::find(all->begin(), all->end(), n1) != all->end()) &&
306 (std::find(all->begin(), all->end(), n2) != all->end()) &&
307 (std::find(all->begin(), all->end(), n4) != all->end()),
308 "Requesting objects that meet a disjunction criteria");
316 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSubset(predicate);
317 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
320 (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()) &&
321 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end()) &&
322 (std::find(stlAll.begin(), stlAll.end(), n5) != stlAll.end()),
323 "Requesting objects that do not meet a criteria");
328 const mitk::DataStorage::SetOfObjects::ConstPointer all =
330 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
331 MITK_TEST_CONDITION((all->Size() == 1) && (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()),
332 "Requesting *direct* source objects");
337 const mitk::DataStorage::SetOfObjects::ConstPointer all =
339 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
340 MITK_TEST_CONDITION((all->Size() == 2) && (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()) &&
341 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()),
342 "Requesting *all* source objects");
347 const mitk::DataStorage::SetOfObjects::ConstPointer all =
349 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
351 (all->Size() == 3) && (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()) &&
352 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
353 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end())
355 "Requesting *all* sources of object with multiple parents");
360 const mitk::DataStorage::SetOfObjects::ConstPointer all =
362 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
366 "Requesting *direct* derived objects");
372 const mitk::DataStorage::SetOfObjects::ConstPointer all =
374 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
376 (all->Size() == 2) &&
377 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end())
379 (std::find(stlAll.begin(), stlAll.end(), n4) != stlAll.end())
381 "Requesting *direct* derived objects with multiple parents/derivations");
386 const mitk::DataStorage::SetOfObjects::ConstPointer all =
388 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
389 MITK_TEST_CONDITION((all->Size() == 3) && (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
390 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end()) &&
391 (std::find(stlAll.begin(), stlAll.end(), n4) != stlAll.end()),
392 "Requesting *all* derived objects");
397 parents1->InsertElement(0, n4);
398 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSources(
402 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
404 (all->Size() == 3) && (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()) &&
405 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
406 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end())
408 "Checking for circular source relationships");
420 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSubset(pred);
421 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
424 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
425 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end()),
426 "Checking GroupTagProperty");
433 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSubset(pred);
434 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
437 (std::find(stlAll.begin(), stlAll.end(), n3) != stlAll.end()) &&
438 (std::find(stlAll.begin(), stlAll.end(), n4) != stlAll.end()),
439 "Checking GroupTagProperty 2");
445 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSources(n4, pred,
true);
446 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
449 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()),
450 "checking direct sources with condition");
456 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSources(n4, pred,
false);
457 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
460 (std::find(stlAll.begin(), stlAll.end(), n1) != stlAll.end()),
461 "Checking all sources with condition");
467 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetSources(n4, pred,
false);
469 "Checking all sources with condition with empty resultset");
475 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetDerivations(n1, pred,
true);
476 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
479 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()),
480 "Checking direct derivations with condition");
487 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetDerivations(n1, pred,
false);
488 std::vector<mitk::DataNode::Pointer> stlAll = all->CastToSTLConstContainer();
491 (std::find(stlAll.begin(), stlAll.end(), n2) != stlAll.end()) &&
492 (std::find(stlAll.begin(), stlAll.end(), n4) != stlAll.end()),
493 "Checking direct derivations with condition");
499 "Checking named node(std::string) method");
503 "Checking named node method with wrong name");
507 "Checking named object method");
509 "Checking named object(std::string) method");
513 "Checking named object method with wrong DataType");
517 "Checking named object method with wrong name");
521 "Checking GetNamedDerivedNode with valid name & direct derivation only");
525 "Checking GetNamedDerivedNode with invalid name & direct derivation only");
529 "Checking GetNamedDerivedNode with invalid name & direct derivation only");
533 "Checking GetNamedDerivedNode with valid Name but direct derivation only");
558 int refCountbeforeDS = watcher->GetReferenceCount();
563 "Checking removal of a node without relations");
573 int refCountbeforeDS = watcher->GetReferenceCount();
579 "Adding extra node");
583 "Checking removal of a node with a parent");
593 int refCountbeforeDS = watcher->GetReferenceCount();
594 mitk::DataStorage::SetOfObjects::Pointer p = mitk::DataStorage::SetOfObjects::New();
607 (ds->
GetNamedNode(
"extra") ==
nullptr) && (refCountbeforeDS == watcher->GetReferenceCount()) &&
612 "Checking removal of a node with two parents");
621 int refCountbeforeDS = watcher->GetReferenceCount();
642 (ds->
GetNamedNode(
"d2") == d2) && (refCountbeforeDS == watcher->GetReferenceCount()) &&
647 "Checking removal of a node with two derived nodes");
657 int refCountbeforeDS = watcher->GetReferenceCount();
659 mitk::DataStorage::SetOfObjects::Pointer p = mitk::DataStorage::SetOfObjects::New();
688 (refCountbeforeDS == watcher->GetReferenceCount()) &&
697 "Checking removal of a node with two parents and two derived nodes");
711 mitk::DataStorage::SetOfObjects::Pointer p = mitk::DataStorage::SetOfObjects::New();
723 mitk::DataStorage::SetOfObjects::Pointer p = mitk::DataStorage::SetOfObjects::New();
729 MITK_TEST_CONDITION(watcher->GetReferenceCount() == 0,
"Checking reference count of node after add and remove");
741 int refCountbeforeDS = watcherD1y->GetReferenceCount();
763 (refCountbeforeDS == watcherD1y->GetReferenceCount()),
764 "Checking removal of subset of two derived nodes from one parent node");
773 const std::set<std::string> groupTags = ds->
GetGroupTags();
775 (std::find(groupTags.begin(), groupTags.end(),
"Resection Proposal 1") != groupTags.end()) &&
776 (std::find(groupTags.begin(), groupTags.end(),
"Resection Proposal 2") != groupTags.end()),
777 "Checking GetGrouptags()");
781 DSEventReceiver listener;
803 listener.m_NodeAdded =
nullptr;
804 listener.m_NodeRemoved =
nullptr;
807 MITK_TEST_CONDITION((listener.m_NodeRemoved ==
nullptr) && (listener.m_NodeAdded ==
nullptr),
"Checking RemoveListener");
809 std::cout <<
"Pointer handling after event handling: " << std::flush;
811 MITK_TEST_CONDITION(watcher->GetReferenceCount() == 0,
"Pointer handling after event handling");
824 const mitk::DataStorage::SetOfObjects::ConstPointer all = ds->
GetAll();
826 MITK_TEST_CONDITION(geometry->CountTimeSteps() == 4,
"Test for number or time steps with ComputeBoundingGeometry()");
829 "Test for timebounds with ComputeBoundingGeometry()");
830 for (
unsigned int i = 0; i < geometry->CountTimeSteps(); i++)
835 "Test for timebounds of geometry at different time steps with ComputeBoundingGeometry()");
839 "Test for number or time steps with ComputeBoundingGeometry(allNodes)");
840 timebounds = geometry->GetTimeBounds();
842 "Test for timebounds with ComputeBoundingGeometry(allNodes)");
843 for (
unsigned int i = 0; i < geometry->CountTimeSteps(); i++)
848 "Test for timebounds of geometry at different time steps with ComputeBoundingGeometry()");
855 ItkDeleteEventListener listener(standaloneDataStorage);
859 listener.SetNode(emptyNode);
860 standaloneDataStorage->Add(emptyNode);
863 standaloneDataStorage->Remove(pEmptyNode);
Class for storing surfaces (vtkPolyData).
Data management class that handles 'was created by' relations.
DataNode * GetNode(const NodePredicateBase *condition=nullptr) const
Convenience method to get the first node that matches the predicate condition.
#define MITK_TEST_FOR_EXCEPTION_END(EXCEPTIONCLASS)
virtual SetOfObjects::ConstPointer GetDerivations(const DataNode *node, const NodePredicateBase *condition=nullptr, bool onlyDirectDerivations=true) const =0
returns a set of derived objects for a given node.
int mitkDataStorageTest(int argc, char *argv[])
itk::FixedArray< ScalarType, 2 > TimeBounds
Standard typedef for time-bounds.
DataType * GetNamedObject(const char *name) const
Convenience method to get the first data object of a given data type with a given name...
std::map< const DataNode *, unsigned long > m_NodeDeleteObserverTags
Saves Delete-Observer Tags for each node in order to remove the event listeners again.
TimeGeometry::ConstPointer ComputeBoundingGeometry3D(const SetOfObjects *input, const char *boolPropertyKey=nullptr, const BaseRenderer *renderer=nullptr, const char *boolPropertyKey2=nullptr) const
Compute the axis-parallel bounding geometry of the input objects.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
DataCollection - Class to facilitate loading/accessing structured data.
virtual SetOfObjects::ConstPointer GetSources(const 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).
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
static Pointer New(unsigned int _arg)
DataNode * GetNamedDerivedNode(const char *name, const DataNode *sourceNode, bool onlyDirectDerivations=true) const
Convenience method to get the first node with a given name that is derived from sourceNode.
virtual void Add(DataNode *node, const DataStorage::SetOfObjects *parents=nullptr)=0
Adds a DataNode containing a data object to its internal storage.
#define MITK_TEST_FOR_EXCEPTION(EXCEPTIONCLASS, STATEMENT)
Simplified version of MITK_TEST_FOR_EXCEPTION_BEGIN / END for a single statement. ...
#define MITK_TEST_OUTPUT(x)
Output some text.
mitk::DataNode::Pointer m_Node
virtual SetOfObjects::ConstPointer GetAll() const =0
returns a set of all data objects that are stored in the data storage
mitk::DataStorage::Pointer m_DataStorage
Keeps track of the reference count of an object even if it is destroyed.
static Pointer New(mitk::BaseData *_arg)
#define MITK_TEST_CONDITION(COND, MSG)
#define mitkClassMacro(className, SuperClassName)
SetOfObjects::ConstPointer GetSubset(const NodePredicateBase *condition) const
returns a set of data objects that meet the given condition(s)
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.
std::map< const DataNode *, unsigned long > m_NodeModifiedObserverTags
Saves Modified-Observer Tags for each node in order to remove the event listeners again...
mitk::Image::Pointer image
static Pointer New(const char *_arg)
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
static Pointer New(const char *_arg)
virtual void Remove(const DataNode *node)=0
Removes node from the DataStorage.
DataStorageEvent RemoveNodeEvent
RemoveEvent is emitted directly before a node is removed from the DataStorage.
const DataNode::GroupTagList GetGroupTags() const
Returns a list of used grouptags.
DataNode * GetNamedNode(const char *name) const
Convenience method to get the first node with a given name.
Class for nodes of the DataTree.