Commit a5aaabeb authored by alexy's avatar alexy

BUG 2764. Made vtkMRMLSceneViewNode handle node ids cache: NodeIDs....

BUG 2764. Made vtkMRMLSceneViewNode handle node ids cache: NodeIDs. Restructured handling of  NodeIDs in the vtkMRMLScene

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21563 3bd1e089-480b-0410-8dfb-8563597acbee
parent 98ac3bf5
......@@ -1242,7 +1242,7 @@ vtkMRMLNode* vtkMRMLScene::AddNodeNoNotify(vtkMRMLNode *n)
if (nodeID != this->NodeIDs.end() &&
nodeID->second == sn)
{
this->NodeIDs.erase(nodeID);
this->RemoveNodeID((char*)nodeID->first.c_str());
}
// If NodeIDs[newId] already contains a value, that node can't be found
// anymore in the NodeIDs cache.
......@@ -1284,8 +1284,7 @@ vtkMRMLNode* vtkMRMLScene::AddNodeNoNotify(vtkMRMLNode *n)
this->Nodes->vtkCollection::AddItem((vtkObject *)n);
// cache the node so the whole scene cache stays up-todate
this->NodeIDs[std::string(n->GetID())] = n;
this->NodeIDsMTime = this->Nodes->GetMTime();
this->AddNodeID(n);
n->EndModify(wasModifying);
return n;
......@@ -1415,8 +1414,7 @@ void vtkMRMLScene::RemoveNode(vtkMRMLNode *n)
}
this->Nodes->vtkCollection::RemoveItem((vtkObject *)n);
this->NodeIDs.erase(n->GetID());
this->NodeIDsMTime = this->Nodes->GetMTime();
this->RemoveNodeID(n->GetID());
this->InvokeEvent(vtkMRMLScene::NodeRemovedEvent, n);
n->UnRegister(this);
......@@ -2027,8 +2025,7 @@ vtkMRMLNode* vtkMRMLScene::InsertAfterNode(vtkMRMLNode *item, vtkMRMLNode *n)
this->Nodes->vtkCollection::InsertItem(index, (vtkObject *)n);
}
// cache the node so the whole scene cache stays up-todate
this->NodeIDs[std::string(n->GetID())] = n;
this->NodeIDsMTime = this->Nodes->GetMTime();
this->AddNodeID(n);
n->SetDisableModifiedEvent(modifyStatus);
......@@ -2109,8 +2106,7 @@ vtkMRMLNode* vtkMRMLScene::InsertBeforeNode(vtkMRMLNode *item, vtkMRMLNode *n)
this->Nodes->vtkCollection::InsertItem(index, (vtkObject *)n);
}
// cache the node so the whole scene cache stays up-todate
this->NodeIDs[std::string(n->GetID())] = n;
this->NodeIDsMTime = this->Nodes->GetMTime();
this->AddNodeID(n);
n->SetDisableModifiedEvent(modifyStatus);
......@@ -3072,7 +3068,7 @@ void vtkMRMLScene::UpdateNodeIDs()
{
if (this->Nodes->GetNumberOfItems() == 0)
{
this->NodeIDs.clear();
this->ClearNodeIDs();
}
else if (this->Nodes->GetMTime() > this->NodeIDsMTime)
{
......@@ -3084,7 +3080,7 @@ void vtkMRMLScene::UpdateNodeIDs()
" were called prior, the NodeIDsMTime would be in sync"
" without having the map in sync.");
}
this->NodeIDs.clear();
this->ClearNodeIDs();
#ifdef MRMLSCENE_VERBOSE
std::cerr << "Recompute node id cache..." << std::endl;
#endif
......@@ -3095,11 +3091,38 @@ void vtkMRMLScene::UpdateNodeIDs()
{
if (node->GetID())
{
this->NodeIDs[std::string(node->GetID())] = node;
this->AddNodeID(node);
}
}
}
this->NodeIDsMTime = this->Nodes->GetMTime();
}
void vtkMRMLScene::AddNodeID(vtkMRMLNode *node)
{
if (this->Nodes && node && node->GetID())
{
this->NodeIDs[std::string(node->GetID())] = node;
this->NodeIDsMTime = this->Nodes->GetMTime();
}
}
void vtkMRMLScene::RemoveNodeID(char *nodeID)
{
if (this->Nodes && nodeID)
{
this->NodeIDs.erase(std::string(nodeID));
this->NodeIDsMTime = this->Nodes->GetMTime();
}
}
void vtkMRMLScene::ClearNodeIDs()
{
if (this->Nodes)
{
this->NodeIDs.clear();
this->NodeIDsMTime = this->Nodes->GetMTime();
}
}
//------------------------------------------------------------------------------
......
......@@ -48,6 +48,12 @@ class vtkMRMLSceneViewNode;
/// \sa vtkCollection
class VTK_MRML_EXPORT vtkMRMLScene : public vtkObject
{
///
/// make the vtkMRMLSceneViewNode a friend since it has internal vtkMRMLScene
/// so that it can call protected methods, for example UpdateNodeIDs()
/// but that's the only class that is allowed to do so
friend class vtkMRMLSceneViewNode;
public:
static vtkMRMLScene *New();
vtkTypeMacro(vtkMRMLScene, vtkObject);
......@@ -629,6 +635,19 @@ protected:
/// Combine a basename and an index to produce a full name.
std::string BuildName(const std::string& baseName, int nameIndex)const;
/// Syncronize NodeIDs map used to speedup GetByID() method with the Nodes collection
void UpdateNodeIDs();
/// Add node to NodeIDs map used to speedup GetByID() method
void AddNodeID(vtkMRMLNode *node);
/// Remove node from NodeIDs map used to speedup GetByID() method
void RemoveNodeID(char *nodeID);
/// Clear NodeIDs map used to speedup GetByID() method
void ClearNodeIDs();
vtkCollection* Nodes;
unsigned long SceneModifiedTime;
......@@ -673,8 +692,6 @@ protected:
int ReadDataOnLoad;
void UpdateNodeIDs();
unsigned long NodeIDsMTime;
void RemoveAllNodesExceptSingletons();
......
......@@ -203,6 +203,9 @@ void vtkMRMLSceneViewNode::ProcessChildNode(vtkMRMLNode *node)
int disabledModify = this->GetDisableModifiedEvent();
this->DisableModifiedEventOn();
int disabledModifyNode = node->GetDisableModifiedEvent();
node->DisableModifiedEventOn();
Superclass::ProcessChildNode(node);
node->SetAddToSceneNoModify(0);
......@@ -210,10 +213,14 @@ void vtkMRMLSceneViewNode::ProcessChildNode(vtkMRMLNode *node)
{
this->Nodes = vtkMRMLScene::New();
}
node->SetScene(this->Nodes);
this->Nodes->GetNodes()->vtkCollection::AddItem((vtkObject *)node);
node->SetDisableModifiedEvent(disabledModify);
this->Nodes->AddNodeID(node);
node->SetScene(this->Nodes);
node->SetDisableModifiedEvent(disabledModifyNode);
this->SetDisableModifiedEvent(disabledModify);
}
......@@ -236,6 +243,7 @@ void vtkMRMLSceneViewNode::Copy(vtkMRMLNode *anode)
else
{
this->Nodes->GetNodes()->RemoveAllItems();
this->Nodes->ClearNodeIDs();
}
vtkMRMLNode *node = NULL;
if ( snode->Nodes != NULL )
......@@ -247,8 +255,8 @@ void vtkMRMLSceneViewNode::Copy(vtkMRMLNode *anode)
if (node)
{
node->SetScene(this->Nodes);
this->Nodes->GetNodes()->vtkCollection::AddItem((vtkObject *)node);
}
this->Nodes->AddNodeID(node);
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment