Index: mitk/CoreUI/Qmitk/QmitkDataStorageTreeModel.h =================================================================== --- mitk/CoreUI/Qmitk/QmitkDataStorageTreeModel.h (revision 29742) +++ mitk/CoreUI/Qmitk/QmitkDataStorageTreeModel.h (working copy) @@ -125,6 +125,10 @@ /// If a predicate is set (not null) the node will be checked against it.The node has to have a data object (no one wants to see empty nodes). /// virtual void AddNode(const mitk::DataNode* node); + + virtual void Modified( const mitk::DataNode* node ); + + /// /// Removes a node from this model. Also removes any event listener from the node. /// Index: mitk/CoreUI/Qmitk/QmitkDataStorageTreeModel.cpp =================================================================== --- mitk/CoreUI/Qmitk/QmitkDataStorageTreeModel.cpp (revision 29742) +++ mitk/CoreUI/Qmitk/QmitkDataStorageTreeModel.cpp (working copy) @@ -1,18 +1,18 @@ /*========================================================================= - + Program: MITK Language: C++ Date: $Date: 2008-08-13 16:56:36 +0200 (Mi, 13 Aug 2008) $ Version: $Revision: 14972 $ - + Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. - + This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. - + =========================================================================*/ #include #include @@ -33,9 +33,9 @@ #include QmitkDataStorageTreeModel::QmitkDataStorageTreeModel( mitk::DataStorage* _DataStorage - , bool _PlaceNewNodesOnTop - , bool _ShowHelperObjects - , QObject* parent ) + , bool _PlaceNewNodesOnTop + , bool _ShowHelperObjects + , QObject* parent ) : QAbstractItemModel(parent) , m_DataStorage(0) , m_PlaceNewNodesOnTop(_PlaceNewNodesOnTop) @@ -65,19 +65,19 @@ QModelIndex QmitkDataStorageTreeModel::index( int row, int column, const QModelIndex & parent ) const { TreeItem* parentItem; - + if (!parent.isValid()) parentItem = m_Root; else parentItem = static_cast(parent.internalPointer()); - + TreeItem *childItem = parentItem->GetChild(row); if (childItem) return createIndex(row, column, childItem); else return QModelIndex(); - - + + } int QmitkDataStorageTreeModel::rowCount(const QModelIndex &parent) const @@ -91,7 +91,7 @@ { if (index.isValid()) return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable - | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; + | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; else return Qt::ItemIsDropEnabled; } @@ -105,13 +105,13 @@ { if (!index.isValid()) return QModelIndex(); - + TreeItem *childItem = this->TreeItemFromIndex(index); TreeItem *parentItem = childItem->GetParent(); - + if (parentItem == m_Root) return QModelIndex(); - + return this->createIndex(parentItem->GetIndex(), 0, parentItem); } @@ -133,11 +133,11 @@ } bool QmitkDataStorageTreeModel::dropMimeData(const QMimeData *data, - Qt::DropAction action, int /*row*/, int /*column*/, const QModelIndex &parent) + Qt::DropAction action, int /*row*/, int /*column*/, const QModelIndex &parent) { if (action == Qt::IgnoreAction) return true; - + if(data->hasFormat("application/x-qabstractitemmodeldatalist")) { QString arg = QString(data->data("application/x-qabstractitemmodeldatalist").data()); @@ -147,69 +147,69 @@ TreeItem* parentItem = dropItem->GetParent(); if(dropItem == m_Root) // item was dropped onto empty space parentItem = m_Root; - + if(draggedItem != dropItem && draggedItem->GetParent() == parentItem) // dragging is only allowed within the same parent { QModelIndex parentModelIndex = this->IndexFromTreeItem(parentItem); - + // remove dragged item this->beginRemoveRows(parentModelIndex, draggedItem->GetIndex(), draggedItem->GetIndex()); - + parentItem->RemoveChild(draggedItem); - + endRemoveRows(); - + // now insert it again at the drop item position int index = parentItem->IndexOfChild(dropItem); if(dropItem == m_Root) index = parentItem->GetChildCount(); - + beginInsertRows(parentModelIndex, index, index); - + // add node parentItem->InsertChild( draggedItem, index ); - + // emit endInsertRows event endInsertRows(); - + this->AdjustLayerProperty(); } } else if(data->hasFormat("application/x-mitk-datanode")) { - QString arg = QString(data->data("application/x-mitk-datanode").data()); - long val = arg.toLong(); - mitk::DataNode* node = static_cast((void*)val); - - if(node && m_DataStorage.IsNotNull() && !m_DataStorage->Exists(node)) + QString arg = QString(data->data("application/x-mitk-datanode").data()); + long val = arg.toLong(); + mitk::DataNode* node = static_cast((void*)val); + + if(node && m_DataStorage.IsNotNull() && !m_DataStorage->Exists(node)) + { + m_DataStorage->Add( node ); + mitk::BaseData::Pointer basedata = node->GetData(); + if (basedata.IsNotNull()) { - m_DataStorage->Add( node ); - mitk::BaseData::Pointer basedata = node->GetData(); - if (basedata.IsNotNull()) - { - mitk::RenderingManager::GetInstance()->InitializeViews( - basedata->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - } + mitk::RenderingManager::GetInstance()->InitializeViews( + basedata->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } + } } return false; } QStringList QmitkDataStorageTreeModel::mimeTypes() const { - QStringList types = QAbstractItemModel::mimeTypes(); - types << "application/x-mitk-datanode"; - return types; + QStringList types = QAbstractItemModel::mimeTypes(); + types << "application/x-mitk-datanode"; + return types; } QMimeData * QmitkDataStorageTreeModel::mimeData(const QModelIndexList & indexes) const{ QMimeData * ret = new QMimeData; - + TreeItem* treeItem = static_cast(indexes.at(0).internalPointer()); long a = reinterpret_cast(treeItem); long b = reinterpret_cast(treeItem->GetDataNode().GetPointer()); - + QString result; QString result2; QTextStream(&result) << a; @@ -222,12 +222,12 @@ QVariant QmitkDataStorageTreeModel::data( const QModelIndex & index, int role ) const { mitk::DataNode* dataNode = this->TreeItemFromIndex(index)->GetDataNode(); - + // get name of treeItem (may also be edited) QString nodeName = QString::fromStdString(dataNode->GetName()); if(nodeName.isEmpty()) nodeName = "unnamed"; - + if (role == Qt::DisplayRole) return nodeName; else if(role == Qt::ToolTipRole) @@ -235,7 +235,7 @@ else if(role == Qt::DecorationRole) { QmitkNodeDescriptor* nodeDescriptor - = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor(dataNode); + = QmitkNodeDescriptorManager::GetInstance()->GetDescriptor(dataNode); return nodeDescriptor->GetIcon(); } else if(role == Qt::CheckStateRole) @@ -246,18 +246,18 @@ { return QVariant::fromValue(mitk::DataNode::Pointer(dataNode)); } - + return QVariant(); } QVariant QmitkDataStorageTreeModel::headerData(int /*section*/, - Qt::Orientation orientation, - int role) const + Qt::Orientation orientation, + int role) const { - if (orientation == Qt::Horizontal && role == Qt::DisplayRole && m_Root) - return QString::fromStdString(m_Root->GetDataNode()->GetName()); - - return QVariant(); + if (orientation == Qt::Horizontal && role == Qt::DisplayRole && m_Root) + return QString::fromStdString(m_Root->GetDataNode()->GetName()); + + return QVariant(); } void QmitkDataStorageTreeModel::SetDataStorage( mitk::DataStorage* _DataStorage ) @@ -268,23 +268,26 @@ { // remove Listener for the data storage itself m_DataStorage.ObjectDelete.RemoveListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::SetDataStorageDeleted ) ); - + , const itk::Object*>( this, &QmitkDataStorageTreeModel::SetDataStorageDeleted ) ); + // remove listeners for the nodes m_DataStorage->AddNodeEvent.RemoveListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::AddNode ) ); - + , const mitk::DataNode*>( this, &QmitkDataStorageTreeModel::AddNode ) ); + m_DataStorage->ChangedNodeEvent.RemoveListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::SetNodeModified ) ); - + , const mitk::DataNode*>( this, &QmitkDataStorageTreeModel::SetNodeModified ) ); + + //m_DataStorage->ChangedNodeEvent.RemoveListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::Modified ) ); + m_DataStorage->RemoveNodeEvent.RemoveListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::RemoveNode ) ); - + , const mitk::DataNode*>( this, &QmitkDataStorageTreeModel::RemoveNode ) ); + } - + // take over the new data storage m_DataStorage = _DataStorage; - + // delete the old root (if necessary, create new) if(m_Root) m_Root->Delete(); @@ -292,25 +295,28 @@ rootDataNode->SetName("Data Manager"); m_Root = new TreeItem(rootDataNode, 0); this->reset(); - + if(m_DataStorage.IsNotNull()) { // add Listener for the data storage itself m_DataStorage.ObjectDelete.AddListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::SetDataStorageDeleted ) ); - + , const itk::Object*>( this, &QmitkDataStorageTreeModel::SetDataStorageDeleted ) ); + // add listeners for the nodes m_DataStorage->AddNodeEvent.AddListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::AddNode ) ); - + , const mitk::DataNode*>( this, &QmitkDataStorageTreeModel::AddNode ) ); + m_DataStorage->ChangedNodeEvent.AddListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::SetNodeModified ) ); - + , const mitk::DataNode*>( this, &QmitkDataStorageTreeModel::SetNodeModified ) ); + + //m_DataStorage->ChangedNodeEvent.AddListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::Modified ) ); + m_DataStorage->RemoveNodeEvent.AddListener( mitk::MessageDelegate1( this, &QmitkDataStorageTreeModel::RemoveNode ) ); - + , const mitk::DataNode*>( this, &QmitkDataStorageTreeModel::RemoveNode ) ); + mitk::DataStorage::SetOfObjects::ConstPointer _NodeSet = m_DataStorage->GetSubset(m_Predicate); - + // finally add all nodes to the model this->Update(); } @@ -322,20 +328,114 @@ this->SetDataStorage(0); } +void QmitkDataStorageTreeModel::Modified( const mitk::DataNode* node )//, const mitk::DataNode* parent) +{ + + + + + if(node == 0) + { MITK_INFO << "node is 0" ; return;} + if( m_DataStorage.IsNull()) + { MITK_INFO << "DS is null" ; return;} + + if( !m_DataStorage->Exists(node)) + { MITK_INFO << "node does not exist in DS" ; return;} + + if ( !m_Predicate->CheckNode(node) ) + { MITK_INFO << "checkNode..." ; return;} + + + + + MITK_INFO << "here we go, modified.." << node->GetName(); + /* + if(parent == 0 + || m_DataStorage.IsNull() + || !m_DataStorage->Exists(parent) + || !m_Predicate->CheckNode(parent) + || m_Root->Find(parent) != 0) + return; + */ + mitk::DataNode* parentDataNode = this->GetParentNode(node); + + // get node's tree item + TreeItem* treeItem = m_Root->Find(node); + if(!treeItem) + return; // return because there is no treeitem containing this node + + MITK_INFO << "1" ; + // get parent index + TreeItem* parentTreeItem = treeItem->GetParent(); + QModelIndex parentIndex = this->IndexFromTreeItem(parentTreeItem); + + MITK_INFO << parentTreeItem->GetDataNode().GetPointer() << " vs. " << parentDataNode; + // compare actual parent with tree item parent + // nein p = 0 und tp == root + // nein p = index1 und tp == index1 + // ja p = index1 und tp == index2 + // ja p = 0 und tp == index + if( ( parentDataNode != 0 && parentTreeItem->GetDataNode().GetPointer() != parentDataNode ) + || (parentDataNode == 0 && parentTreeItem->GetDataNode().GetPointer() != m_Root->GetDataNode().GetPointer() ) ) + { + MITK_INFO << "2 we go, modified.." ; + // remove treeitem + this->beginRemoveRows(parentIndex, treeItem->GetIndex(), treeItem->GetIndex()); + endRemoveRows(); + + + // find parent index + TreeItem* parentTreeItem = m_Root; + QModelIndex index; + parentTreeItem = m_Root->Find(parentDataNode); // find the corresponding tree item + if(parentTreeItem) + { + //MITK_INFO << "3." ; + //this->AddNode(parentDataNode); + //parentTreeItem = m_Root->Find(parentDataNode); + //if (!parentTreeItem) return; + //} + // index of parent with the help of the grand parent + index = this->createIndex(parentTreeItem->GetIndex(), 0, parentDataNode); + //index = this->IndexFromTreeItem(parent); + MITK_INFO << "index OK" ; + + + + + // insert node with new tree item at index + beginInsertRows(index, 0, 0); + parentTreeItem->InsertChild(treeItem, 0); + endInsertRows(); + } + + delete treeItem; + + //this->AdjustLayerProperty(); + + } + + // find current parent tree item of node + // remove node tree item from parent-treeitem-children + // find new parent tree item + // add new child tree item with node attached + +} + void QmitkDataStorageTreeModel::AddNode( const mitk::DataNode* node ) { if(node == 0 - || m_DataStorage.IsNull() - || !m_DataStorage->Exists(node) - || !m_Predicate->CheckNode(node) - || m_Root->Find(node) != 0) + || m_DataStorage.IsNull() + || !m_DataStorage->Exists(node) + || !m_Predicate->CheckNode(node) + || m_Root->Find(node) != 0) return; - + // find out if we have a root node TreeItem* parentTreeItem = m_Root; QModelIndex index; mitk::DataNode* parentDataNode = this->GetParentNode(node); - + if(parentDataNode) // no top level data node { parentTreeItem = m_Root->Find(parentDataNode); // find the corresponding tree item @@ -346,18 +446,18 @@ if(!parentTreeItem) return; } - + // get the index of this parent with the help of the grand parent index = this->createIndex(parentTreeItem->GetIndex(), 0, parentTreeItem); } - + // add node if(m_PlaceNewNodesOnTop) { // emit beginInsertRows event beginInsertRows(index, 0, 0); parentTreeItem->InsertChild(new TreeItem( - const_cast(node)), 0); + const_cast(node)), 0); } else { @@ -365,10 +465,10 @@ , parentTreeItem->GetChildCount()); new TreeItem(const_cast(node), parentTreeItem); } - + // emit endInsertRows event endInsertRows(); - + this->AdjustLayerProperty(); } @@ -381,66 +481,72 @@ void QmitkDataStorageTreeModel::RemoveNode( const mitk::DataNode* node ) { if(!m_Root) return; - + TreeItem* treeItem = m_Root->Find(node); if(!treeItem) return; // return because there is no treeitem containing this node - + TreeItem* parentTreeItem = treeItem->GetParent(); QModelIndex parentIndex = this->IndexFromTreeItem(parentTreeItem); - + // emit beginRemoveRows event (QModelIndex is empty because we dont have a tree model) this->beginRemoveRows(parentIndex, treeItem->GetIndex(), treeItem->GetIndex()); - + // remove node std::vector children = treeItem->GetChildren(); delete treeItem; - + // emit endRemoveRows event endRemoveRows(); - + // move all children of deleted node into its parent for ( std::vector::iterator it = children.begin() - ; it != children.end(); it++) + ; it != children.end(); it++) { // emit beginInsertRows event beginInsertRows(parentIndex, parentTreeItem->GetChildCount(), parentTreeItem->GetChildCount()); - + // add nodes again parentTreeItem->AddChild(*it); - + // emit endInsertRows event endInsertRows(); } - + this->AdjustLayerProperty(); } void QmitkDataStorageTreeModel::SetNodeModified( const mitk::DataNode* node ) { + + MITK_INFO << "set node modified()"; TreeItem* treeItem = m_Root->Find(node); if(!treeItem) return; - + TreeItem* parentTreeItem = treeItem->GetParent(); // as the root node should not be removed one should always have a parent item if(!parentTreeItem) return; QModelIndex index = this->createIndex(treeItem->GetIndex(), 0, treeItem); - + + this->Modified(node); + // now emit the dataChanged signal emit dataChanged(index, index); + + } mitk::DataNode* QmitkDataStorageTreeModel::GetParentNode( const mitk::DataNode* node ) const { mitk::DataNode* dataNode = 0; - + mitk::DataStorage::SetOfObjects::ConstPointer _Sources = m_DataStorage->GetSources(node); - + if(_Sources->Size() > 0) dataNode = _Sources->front(); - + return dataNode; } @@ -449,7 +555,7 @@ mitk::DataNode* dataNode = this->TreeItemFromIndex(index)->GetDataNode(); if(!dataNode) return false; - + if(role == Qt::EditRole && !value.toString().isEmpty()) { dataNode->SetStringProperty("name", value.toString().toStdString().c_str()); @@ -457,12 +563,12 @@ else if(role == Qt::CheckStateRole) { // Please note: value.toInt() returns 2, independentely from the actual checkstate of the index element. - // Therefore the checkstate is being estimated again here. - - QVariant qcheckstate = index.data(Qt::CheckStateRole); - int checkstate = qcheckstate.toInt(); + // Therefore the checkstate is being estimated again here. + + QVariant qcheckstate = index.data(Qt::CheckStateRole); + int checkstate = qcheckstate.toInt(); bool isVisible = bool(checkstate); - dataNode->SetVisibility(!isVisible); + dataNode->SetVisibility(!isVisible); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } // inform listeners about changes @@ -480,7 +586,7 @@ /// transform the tree into an array and set the layer property descending std::vector vec; this->TreeToVector(m_Root, vec); - + int i = vec.size()-1; for(std::vector::const_iterator it = vec.begin(); it != vec.end(); ++it) { @@ -514,7 +620,7 @@ std::vector vec; if(m_Root) this->TreeToNodeSet(m_Root, vec); - + return vec; } @@ -558,7 +664,7 @@ { while(m_Children.size() > 0) delete m_Children.back(); - + delete this; } @@ -617,7 +723,7 @@ { if (m_Parent) return m_Parent->IndexOfChild(this); - + return 0; } @@ -644,7 +750,7 @@ } else m_Children.push_back(item); - + // add parent if necessary if(item->GetParent() != this) item->SetParent(this); @@ -666,12 +772,12 @@ void QmitkDataStorageTreeModel::SetShowHelperObjects(bool _ShowHelperObjects) { m_ShowHelperObjects = _ShowHelperObjects; - + mitk::NodePredicateData::Pointer dataIsNull = mitk::NodePredicateData::New(0); mitk::NodePredicateNot::Pointer dataIsNotNull = mitk::NodePredicateNot::New(dataIsNull);// Show only nodes that really contain dat mitk::NodePredicateProperty::Pointer isHelperObject = mitk::NodePredicateProperty::New("helper object", mitk::BoolProperty::New(true)); mitk::NodePredicateNot::Pointer isNotHelperObject = mitk::NodePredicateNot::New(isHelperObject);// Show only nodes that really contain dat - + if (! m_ShowHelperObjects) { //hide helper objects @@ -682,7 +788,7 @@ //show helper objects m_Predicate = dataIsNotNull; } - + this->Update(); } @@ -691,23 +797,23 @@ if (m_DataStorage.IsNotNull()) { this->reset(); - + mitk::DataStorage::SetOfObjects::ConstPointer _NodeSet = m_DataStorage->GetSubset(m_Predicate); - + for(mitk::DataStorage::SetOfObjects::const_iterator it=_NodeSet->begin(); it!=_NodeSet->end(); it++) { // save node this->AddNode(*it); } - + mitk::DataStorage::SetOfObjects::ConstPointer _NotNodeSet = m_DataStorage->GetSubset(mitk::NodePredicateNot::New(m_Predicate)); - + for(mitk::DataStorage::SetOfObjects::const_iterator it=_NotNodeSet->begin(); it!=_NotNodeSet->end(); it++) { // remove node this->RemoveNode(*it); } - + } } Index: mitk/Core/Code/DataManagement/mitkDataStorage.cpp =================================================================== --- mitk/Core/Code/DataManagement/mitkDataStorage.cpp (revision 29742) +++ mitk/Core/Code/DataManagement/mitkDataStorage.cpp (working copy) @@ -43,6 +43,13 @@ //m_NodeDeleteObserverTags.clear(); } +void mitk::DataStorage::AddSource(mitk::DataNode* node, mitk::DataNode* parent) +{ + mitk::DataStorage::SetOfObjects::Pointer parents = mitk::DataStorage::SetOfObjects::New(); + parents->InsertElement(0, parent); + this->AddSource(node, parents); + +} void mitk::DataStorage::Add(mitk::DataNode* node, mitk::DataNode* parent) { Index: mitk/Core/Code/DataManagement/mitkStandaloneDataStorage.h =================================================================== --- mitk/Core/Code/DataManagement/mitkStandaloneDataStorage.h (revision 29742) +++ mitk/Core/Code/DataManagement/mitkStandaloneDataStorage.h (working copy) @@ -84,6 +84,12 @@ //## method by providing a predicate as the condition parameter. SetOfObjects::ConstPointer GetDerivations(const mitk::DataNode* node, const NodePredicateBase* condition = NULL, bool onlyDirectDerivations = true) const; + + + + void AddSource(mitk::DataNode* , const mitk::DataStorage::SetOfObjects* ); + + //##Documentation //## @brief returns a set of all data objects that are stored in the data storage //## Index: mitk/Core/Code/DataManagement/mitkDataStorage.h =================================================================== --- mitk/Core/Code/DataManagement/mitkDataStorage.h (revision 29742) +++ mitk/Core/Code/DataManagement/mitkDataStorage.h (working copy) @@ -67,6 +67,9 @@ //## an exception will be thrown. virtual void Add(mitk::DataNode* node, const mitk::DataStorage::SetOfObjects* parents = NULL) = 0; + virtual void AddSource(mitk::DataNode* node, const mitk::DataStorage::SetOfObjects* parents = NULL) = 0; + void AddSource(mitk::DataNode* node, mitk::DataNode* parent); + //##Documentation //## @brief Convenience method to add a node that has one parent //## Index: mitk/Core/Code/DataManagement/mitkStandaloneDataStorage.cpp =================================================================== --- mitk/Core/Code/DataManagement/mitkStandaloneDataStorage.cpp (revision 29742) +++ mitk/Core/Code/DataManagement/mitkStandaloneDataStorage.cpp (working copy) @@ -1,20 +1,20 @@ /*========================================================================= + + Program: Medical Imaging & Interaction Toolkit + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) German Cancer Research Center, Division of Medical and + Biological Informatics. All rights reserved. + See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ -Program: Medical Imaging & Interaction Toolkit -Language: C++ -Date: $Date$ -Version: $Revision$ - -Copyright (c) German Cancer Research Center, Division of Medical and -Biological Informatics. All rights reserved. -See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ - #include "mitkStandaloneDataStorage.h" #include "mitkDataNode.h" @@ -35,7 +35,7 @@ mitk::StandaloneDataStorage::~StandaloneDataStorage() { for(AdjacencyList::iterator it = m_SourceNodes.begin(); - it != m_SourceNodes.end(); it++) + it != m_SourceNodes.end(); it++) { this->RemoveListeners(it->first); } @@ -49,7 +49,61 @@ return true; } +void mitk::StandaloneDataStorage::AddSource(mitk::DataNode* node, const mitk::DataStorage::SetOfObjects* parents) +{ + { + itk::MutexLockHolder locked(m_Mutex); + if (!IsInitialized()) + throw std::logic_error("DataStorage not initialized"); + /* check if node is in its own list of sources */ + if ((parents != NULL) && (std::find(parents->begin(), parents->end(), node) != parents->end())) + throw std::invalid_argument("Node is it's own parent"); + /* check if node already exists in StandaloneDataStorage */ + if (m_SourceNodes.find(node) == m_SourceNodes.end()) + throw std::invalid_argument("Node not found in DataStorage"); + if (parents == NULL) + throw std::invalid_argument("Parent has to be provided"); + + + mitk::DataStorage::SetOfObjects* currentParents = const_cast(m_SourceNodes[node].GetPointer()); + if (currentParents == NULL) + throw std::invalid_argument("ParentList not found"); + + + for (SetOfObjects::ConstIterator it = parents->Begin(); it != parents->End(); it++) + { + mitk::DataNode::Pointer parent = it.Value().GetPointer(); + + if (parent.IsNull()) + throw std::invalid_argument("extracted Parent not found in DataStorage"); + + if (m_SourceNodes.find(parent.GetPointer()) == m_SourceNodes.end()) + throw std::invalid_argument("Parent not found in DataStorage"); + + + mitk::DataNode::ConstPointer constparent = it.Value().GetPointer(); + currentParents->InsertElement(currentParents->Size(), parent); // node is derived from parent. Insert it into the parents list of derived objects + + mitk::DataStorage::SetOfObjects::ConstPointer derivedObjects = m_DerivedNodes[constparent]; // get or create pointer to list of derived objects for that parent node + if (derivedObjects.IsNull()) + m_DerivedNodes[constparent] = mitk::DataStorage::SetOfObjects::New(); // Create a set of Objects, if it does not already exist + mitk::DataStorage::SetOfObjects* deob = const_cast(m_DerivedNodes[constparent].GetPointer()); // temporarily get rid of const pointer to insert new element + deob->InsertElement(deob->Size(), node); // node is derived from parent. Insert it into the parents list of derived objects + + } + + } + + itk::ModifiedEvent itkEvent; + + /* Notify observers */ + OnNodeModifiedOrDeleted(node, itkEvent); + /* Notify observers */ + EmitAddNodeEvent(node); +} + + void mitk::StandaloneDataStorage::Add(mitk::DataNode* node, const mitk::DataStorage::SetOfObjects* parents) { { @@ -62,7 +116,7 @@ /* check if node already exists in StandaloneDataStorage */ if (m_SourceNodes.find(node) != m_SourceNodes.end()) throw std::invalid_argument("Node is already in DataStorage"); - + /* create parent list if it does not exist */ mitk::DataStorage::SetOfObjects::ConstPointer sp; if (parents != NULL) @@ -71,11 +125,11 @@ sp = mitk::DataStorage::SetOfObjects::New(); /* Store node and parent list in sources adjacency list */ m_SourceNodes.insert(std::make_pair(node, sp)); - + /* Store node and an empty children list in derivations adjacency list */ mitk::DataStorage::SetOfObjects::Pointer children = mitk::DataStorage::SetOfObjects::New(); m_DerivedNodes.insert(std::make_pair(node, children)); - + /* create entry in derivations adjacency list for each parent of the new node */ for (SetOfObjects::ConstIterator it = sp->Begin(); it != sp->End(); it++) { @@ -86,14 +140,14 @@ mitk::DataStorage::SetOfObjects* deob = const_cast(m_DerivedNodes[parent].GetPointer()); // temporarily get rid of const pointer to insert new element deob->InsertElement(deob->Size(), node); // node is derived from parent. Insert it into the parents list of derived objects } - + // register for ITK changed events this->AddListeners(node); } - + /* Notify observers */ EmitAddNodeEvent(node); - + } @@ -103,10 +157,10 @@ throw std::logic_error("DataStorage not initialized"); if (node == NULL) return; - + // remove ITK modified event listener this->RemoveListeners(node); - + // muellerm, 22.9.10: add additional reference count to ensure // that the node is not deleted when removed from the relation map // while m_Mutex is locked. This would cause the an itk::DeleteEvent @@ -114,7 +168,7 @@ // access the DataStorage again in their event processing function // mitk::DataNode::ConstPointer nodeGuard(node); - + /* Notify observers of imminent node removal */ EmitRemoveNodeEvent(node); { @@ -154,7 +208,7 @@ itk::MutexLockHolder locked(m_Mutex); if (!IsInitialized()) throw std::logic_error("DataStorage not initialized"); - + mitk::DataStorage::SetOfObjects::Pointer resultset = mitk::DataStorage::SetOfObjects::New(); /* Fill resultset with all objects that are managed by the StandaloneDataStorage object */ unsigned int index = 0; @@ -163,7 +217,7 @@ continue; else resultset->InsertElement(index++, const_cast(it->first.GetPointer())); - + return SetOfObjects::ConstPointer(resultset); } @@ -172,7 +226,7 @@ { if (node == NULL) throw std::invalid_argument("invalid node"); - + /* Either read direct relations directly from adjacency list */ if (onlyDirectlyRelated) { @@ -182,15 +236,15 @@ else return this->FilterSetOfObjects(it->second, condition); } - + /* Or traverse adjacency list to collect all related nodes */ std::vector resultset; std::vector openlist; - + /* Initialize openlist with node. this will add node to resultset, - but that is necessary to detect circular relations that would lead to endless recursion */ + but that is necessary to detect circular relations that would lead to endless recursion */ openlist.push_back(node); - + while (openlist.size() > 0) { mitk::DataNode::ConstPointer current = openlist.back(); // get element that needs to be processed @@ -210,7 +264,7 @@ openlist.push_back(p); // then add it to openlist, so that it can be processed } } - + /* now finally copy the results to a proper SetOfObjects variable exluding the initial node and checking the condition if any is given */ mitk::DataStorage::SetOfObjects::Pointer realResultset = mitk::DataStorage::SetOfObjects::New(); if (condition != NULL) Index: mbi/Modules/DiffusionImaging/DataStructures/PlanarFigureComposite/mitkPlanarFigureComposite.cpp =================================================================== --- mbi/Modules/DiffusionImaging/DataStructures/PlanarFigureComposite/mitkPlanarFigureComposite.cpp (revision 29742) +++ mbi/Modules/DiffusionImaging/DataStructures/PlanarFigureComposite/mitkPlanarFigureComposite.cpp (working copy) @@ -14,6 +14,7 @@ { m_PFVector = CompositionContainer::New(); + m_DNVector = DataNodeContainer::New(); } @@ -22,18 +23,34 @@ } +void mitk::PlanarFigureComposite::addDataNode(mitk::DataNode::Pointer dnode) +{ + + m_DNVector->InsertElement(m_DNVector->Size(), dnode); + +} + + void mitk::PlanarFigureComposite::addPlanarFigure(PlanarFigure::Pointer pf) { - MITK_INFO << "PFVector Size: " << m_PFVector->Size(); + MITK_INFO << "addPlanarFigure: size before: " << this->getNumberOfChildren(); m_PFVector->InsertElement(m_PFVector->Size(), pf); - MITK_INFO << "inserted PF Type to PFCompositeVector."; - MITK_INFO << "PFVector new Size: " << m_PFVector->Size(); + MITK_INFO << "addPlanarFigure: size after: " << this->getNumberOfChildren(); + + + } +void mitk::PlanarFigureComposite::replaceDataNodeAt(int idx, mitk::DataNode::Pointer dn) +{ + MITK_INFO << "replace: size before: " << this->getNumberOfChildren(); + m_DNVector->SetElement( idx, dn ); + MITK_INFO << "replace: size after: " << this->getNumberOfChildren(); + +} - void mitk::PlanarFigureComposite::setOperationType(PFCompositionOperation pfcOp) { this->m_compOperation = pfcOp; @@ -49,13 +66,45 @@ } +void mitk::PlanarFigureComposite::setDisplayName(std::string displName) +{ + + m_name = displName; + +} +std::string mitk::PlanarFigureComposite::getDisplayName() +{ + return m_name; +} +int mitk::PlanarFigureComposite::getNumberOfChildren() +{ + return m_PFVector->Size(); + +} +mitk::PlanarFigure::Pointer mitk::PlanarFigureComposite::getChildAt(int idx) +{ + + return m_PFVector->ElementAt(idx); +} +mitk::DataNode::Pointer mitk::PlanarFigureComposite::getDataNodeAt(int idx) +{ + + return m_DNVector->ElementAt(idx); + +} + + + + + + //musthave implementations from superclass.... not sure if return true makes sense bool mitk::PlanarFigureComposite::SetControlPoint( unsigned int index, const Point2D &point, bool createIfDoesNotExist ) { @@ -64,7 +113,7 @@ void mitk::PlanarFigureComposite::GeneratePolyLine() { - + } void mitk::PlanarFigureComposite::GenerateHelperPolyLine(double /*mmPerDisplayUnit*/, unsigned int /*displayHeight*/) Index: mbi/Modules/DiffusionImaging/DataStructures/PlanarFigureComposite/mitkPlanarFigureComposite.h =================================================================== --- mbi/Modules/DiffusionImaging/DataStructures/PlanarFigureComposite/mitkPlanarFigureComposite.h (revision 29742) +++ mbi/Modules/DiffusionImaging/DataStructures/PlanarFigureComposite/mitkPlanarFigureComposite.h (working copy) @@ -15,6 +15,7 @@ #include "MitkDiffusionImagingMBIExports.h" #include "mitkPlanarFigure.h" #include "itkVectorContainer.h" +#include "mitkDataNode.h"; namespace mitk { @@ -25,18 +26,20 @@ PFCOMPOSITION_NOT_OPERATION, }; - - + + class MitkDiffusionImagingMBI_EXPORT PlanarFigureComposite : public PlanarFigure { typedef itk::VectorContainer CompositionContainer; - + typedef itk::VectorContainer DataNodeContainer; + + public: mitkClassMacro(PlanarFigureComposite, PlanarFigure); itkNewMacro( Self ); - + // ///MUST HAVE IMPLEMENTATION////// bool SetControlPoint( unsigned int index, const Point2D &point, bool createIfDoesNotExist ); unsigned int GetMinimumNumberOfControlPoints() const @@ -49,14 +52,25 @@ return 0; } // ///////////////////////// - + + + int getNumberOfChildren(); + mitk::PlanarFigure::Pointer getChildAt(int); void addPlanarFigure(PlanarFigure::Pointer); - + + mitk::DataNode::Pointer getDataNodeAt(int); + void addDataNode(mitk::DataNode::Pointer); + void replaceDataNodeAt(int, mitk::DataNode::Pointer); + + // set if this compsition is AND, OR, NOT void setOperationType(PFCompositionOperation); PFCompositionOperation getOperationType(); + void setDisplayName(std::string); + std::string getDisplayName(); + protected: PlanarFigureComposite(); virtual ~PlanarFigureComposite(); @@ -75,17 +89,22 @@ virtual void PrintSelf( std::ostream &os, itk::Indent indent ) const; // //////////////////// - - + + private: //this vector takes planarfigures and planarfigureComosite types CompositionContainer::Pointer m_PFVector; PFCompositionOperation m_compOperation; + DataNodeContainer::Pointer m_DNVector; + std::string m_name; + + + }; - + } #endif \ No newline at end of file Index: mbi-sb/BundlesQt/org.mitk.gui.qt.diffusionimaginginternal/src/internal/QmitkFiberBundleOperationsView.cpp =================================================================== --- mbi-sb/BundlesQt/org.mitk.gui.qt.diffusionimaginginternal/src/internal/QmitkFiberBundleOperationsView.cpp (revision 29742) +++ mbi-sb/BundlesQt/org.mitk.gui.qt.diffusionimaginginternal/src/internal/QmitkFiberBundleOperationsView.cpp (working copy) @@ -1,21 +1,21 @@ /*========================================================================= + + Program: Medical Imaging & Interaction Toolkit + Language: C++ + Date: $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $ + Version: $Revision: 21975 $ + + Copyright (c) German Cancer Research Center, Division of Medical and + Biological Informatics. All rights reserved. + See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ -Program: Medical Imaging & Interaction Toolkit -Language: C++ -Date: $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $ -Version: $Revision: 21975 $ -Copyright (c) German Cancer Research Center, Division of Medical and -Biological Informatics. All rights reserved. -See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ - - // Blueberry #include #include @@ -62,7 +62,7 @@ //, m_SelectedFBNodes( NULL ) //, m_SelectedPFNodes(0) { - + } // Destructor @@ -84,7 +84,7 @@ m_Controls->PFCompoANDButton->setDisabled(true); m_Controls->PFCompoORButton->setDisabled(true); m_Controls->PFCompoNOTButton->setDisabled(true); - m_Controls->PFCompoDELButton->setDisabled(true); + m_Controls->PFCompoDELButton->setDisabled(true); connect( m_Controls->doExtractFibersButton, SIGNAL(clicked()), this, SLOT(DoFiberExtraction()) ); //connect( m_Controls->comboBox_fiberAlgo, SIGNAL(selected()), this, SLOT(handleAlgoSelection() ); @@ -92,10 +92,10 @@ connect(m_Controls->PFCompoANDButton, SIGNAL(clicked()), this, SLOT(generatePFCompo_AND()) ); connect(m_Controls->PFCompoORButton, SIGNAL(clicked()), this, SLOT(generatePFCompo_OR()) ); connect(m_Controls->PFCompoNOTButton, SIGNAL(clicked()), this, SLOT(generatePFCompo_NOT()) ); - connect(m_Controls->PFCompoDELButton, SIGNAL(clicked()), this, SLOT(deletePFCompo()) ); - - + connect(m_Controls->PFCompoDELButton, SIGNAL(clicked()), this, SLOT(deletePFCompo()) ); + + } } @@ -118,7 +118,7 @@ void QmitkFiberBundleOperationsView::OnSelectionChanged( std::vector nodes ) { - + if ( !this->IsVisible() ) { // do nothing if nobody wants to see me :-( @@ -136,33 +136,33 @@ // 2) BOOLEAN OPERATORS HANDLING ... selection of multiple PF, and or multiple Spaghetti - //scenario 1 + //scenario 1 - for( std::vector::iterator it = nodes.begin(); - it != nodes.end(); ++it ) + for( std::vector::iterator it = nodes.begin(); + it != nodes.end(); ++it ) + { + + mitk::DataNode::Pointer node = *it; + if ( dynamic_cast(node->GetData()) ) { - - mitk::DataNode::Pointer node = *it; - if ( dynamic_cast(node->GetData()) ) - { // MITK_INFO << "onselectionchg(): " << node->GetData()->GetNameOfClass(); - m_SelectedFB.push_back(node); - - } else if (dynamic_cast(node->GetData())){ + m_SelectedFB.push_back(node); + } else if (dynamic_cast(node->GetData())){ + // MITK_INFO << "onselectionchg(): " << node->GetData()->GetNameOfClass(); - m_SelectedPF.push_back(node); - - } - + m_SelectedPF.push_back(node); + } + + } - + //quick and dirty control structure for extraction ATM if (m_SelectedPF.size() == 1) { - + //############################################# //### PLANAR FIGURE COMPOSIT SelectionLOGIC ### //############################################# @@ -170,15 +170,15 @@ m_Controls->PFCompoANDButton->setDisabled(true); m_Controls->PFCompoORButton->setDisabled(true); m_Controls->PFCompoNOTButton->setEnabled(true); - m_Controls->PFCompoDELButton->setDisabled(true); - - //if planarFigureComposite selected, activate DEL button - if ( dynamic_cast(m_SelectedPF.at(0)->GetData()) ) - { - m_Controls->PFCompoDELButton->setEnabled(true); - } - + m_Controls->PFCompoDELButton->setDisabled(true); + //if planarFigureComposite selected, activate DEL button + if ( dynamic_cast(m_SelectedPF.at(0)->GetData()) ) + { + m_Controls->PFCompoDELButton->setEnabled(true); + } + + } else if (m_SelectedPF.size() > 1) { //############################################# @@ -190,7 +190,7 @@ m_Controls->PFCompoANDButton->setEnabled(true); m_Controls->PFCompoORButton->setEnabled(true); m_Controls->PFCompoNOTButton->setDisabled(true); - m_Controls->PFCompoDELButton->setDisabled(true); + m_Controls->PFCompoDELButton->setDisabled(true); } @@ -202,35 +202,35 @@ //##### EXTRACT FIBERBUNDLE SelectionLOGIC #### //############################################# - m_Controls->doExtractFibersButton->setEnabled(true); + m_Controls->doExtractFibersButton->setEnabled(true); - + } else if (nodes.size() > 1 ) { - //scenario 2 - - + //scenario 2 + + } else if (nodes.empty()) { - + //############################################# //##### EXTRACT FIBERBUNDLE SelectionLOGIC #### //############################################# m_Controls->doExtractFibersButton->setDisabled(true); - + //############################################# //### PLANAR FIGURE COMPOSIT SelectionLOGIC ### //############################################# - + m_Controls->PFCompoANDButton->setDisabled(true); m_Controls->PFCompoORButton->setDisabled(true); m_Controls->PFCompoNOTButton->setDisabled(true); } - + } @@ -280,36 +280,36 @@ MITK_INFO << "FB OPerations ACTIVATED()"; /* - - mitk::DataStorage::SetOfObjects::ConstPointer _NodeSet = this->GetDefaultDataStorage()->GetAll(); - mitk::DataNode* node = 0; - mitk::PlanarFigureInteractor::Pointer figureInteractor = 0; - mitk::PlanarFigure* figure = 0; - - for(mitk::DataStorage::SetOfObjects::ConstIterator it=_NodeSet->Begin(); it!=_NodeSet->End() - ; it++) - { - node = const_cast(it->Value().GetPointer()); - figure = dynamic_cast(node->GetData()); - - if(figure) - { - figureInteractor = dynamic_cast(node->GetInteractor()); - - if(figureInteractor.IsNull()) - figureInteractor = mitk::PlanarFigureInteractor::New("PlanarFigureInteractor", node); - - mitk::GlobalInteraction::GetInstance()->AddInteractor(figureInteractor); - } - } + + mitk::DataStorage::SetOfObjects::ConstPointer _NodeSet = this->GetDefaultDataStorage()->GetAll(); + mitk::DataNode* node = 0; + mitk::PlanarFigureInteractor::Pointer figureInteractor = 0; + mitk::PlanarFigure* figure = 0; + + for(mitk::DataStorage::SetOfObjects::ConstIterator it=_NodeSet->Begin(); it!=_NodeSet->End() + ; it++) + { + node = const_cast(it->Value().GetPointer()); + figure = dynamic_cast(node->GetData()); + + if(figure) + { + figureInteractor = dynamic_cast(node->GetInteractor()); + + if(figureInteractor.IsNull()) + figureInteractor = mitk::PlanarFigureInteractor::New("PlanarFigureInteractor", node); + + mitk::GlobalInteraction::GetInstance()->AddInteractor(figureInteractor); + } + } + + */ - */ - } void QmitkFiberBundleOperationsView::AddFigureToDataStorage(mitk::PlanarFigure* figure, const QString& name, - const char *propertyKey, mitk::BaseProperty *property ) + const char *propertyKey, mitk::BaseProperty *property ) { //set desired data to DataNode where Planarfigure is stored mitk::DataNode::Pointer newNode = mitk::DataNode::New(); @@ -328,7 +328,7 @@ - // mitk::FiberBundle::Pointer selectedFBNode = m_SelectedFBNodes.at(0); + // mitk::FiberBundle::Pointer selectedFBNode = m_SelectedFBNodes.at(0); // figure drawn on the topmost layer / image this->GetDataStorage()->Add(newNode ); @@ -340,9 +340,9 @@ } //selectedNodes = m_SelectedPlanarFigureNodes->GetNodes(); /*for(unsigned int i = 0; i < selectedNodes.size(); i++) - { - selectedNodes[i]->SetSelected(false); - } + { + selectedNodes[i]->SetSelected(false); + } */ newNode->SetSelected(true); @@ -353,11 +353,11 @@ { mitk::FiberBundle::Pointer selFB = dynamic_cast(m_SelectedFB.at(0)->GetData()); mitk::PlanarFigure::Pointer selPF = dynamic_cast (m_SelectedPF.at(0)->GetData()); - - + + mitk::FiberBundle::Pointer extFB = selFB->extractFibersPF(selPF); MITK_INFO << " Number Of Tracts: " << selFB->GetNumTracts(); - + mitk::DataNode::Pointer fbNode; fbNode = mitk::DataNode::New(); fbNode->SetData(extFB); @@ -373,136 +373,298 @@ { mitk::PlanarFigureComposite::Pointer PFCAnd = mitk::PlanarFigureComposite::New(); PFCAnd->setOperationType(mitk::PFCOMPOSITION_AND_OPERATION); - - //create OR Node - mitk::DataNode::Pointer fbNode; - fbNode = mitk::DataNode::New(); - fbNode->SetData(PFCAnd); - fbNode->SetName("AND_PFCombo"); - + + for( std::vector::iterator it = m_SelectedPF.begin(); it != m_SelectedPF.end(); ++it ) { - mitk::DataNode::Pointer nodePF = *it; - mitk::PlanarFigure::Pointer tmpPF = dynamic_cast( nodePF->GetData() ); + mitk::DataNode::Pointer nodePF = *it; + mitk::PlanarFigure::Pointer tmpPF = dynamic_cast( nodePF->GetData() ); PFCAnd->addPlanarFigure( tmpPF ); - //set to NOT Node its child - fbNode->SetVisibility(true); - GetDataStorage()->Remove(nodePF); - GetDataStorage()->Add(nodePF, fbNode); + // PFCAnd->addDataNode( nodePF ); + PFCAnd->setDisplayName("AND_COMPO"); + // MITK_INFO << "PFCAND(): added to AND PF" << nodePF->GetName(); + } -// this->addPFCompositionToDataStorage(PFCAnd, NULL /*parent*/); + // debugPFComposition(PFCAnd, 0); + + this->addPFCompositionToDataStorage(PFCAnd, NULL /*parent*/); + } -void QmitkFiberBundleOperationsView::generatePFCompo_OR() + +void QmitkFiberBundleOperationsView::debugPFComposition(mitk::PlanarFigureComposite::Pointer pfc, int itLevelStatus) { - mitk::PlanarFigureComposite::Pointer PFCOr = mitk::PlanarFigureComposite::New(); - PFCOr->setOperationType(mitk::PFCOMPOSITION_OR_OPERATION); + int myLevel = itLevelStatus; + if (myLevel == 0) + { + MITK_INFO << "############################################## " ; + MITK_INFO << "######### DEBUG START ############## " ; + MITK_INFO << "############################################## " ; + } + MITK_INFO << "############################################## " ; + MITK_INFO << "Name: " << pfc->getDisplayName(); + MITK_INFO << "iterationLevel: " << myLevel; + MITK_INFO << "CompositionType: " << pfc->getOperationType(); + MITK_INFO << "Number of children: " << pfc->getNumberOfChildren(); - //create OR Node - mitk::DataNode::Pointer fbNode; - fbNode = mitk::DataNode::New(); - fbNode->SetData(PFCOr); - fbNode->SetName("OR_PFCombo"); + //iterate through pfcs children + for(int i=0; igetNumberOfChildren(); ++i) + { + + mitk::PlanarFigure::Pointer tmpPFchild = pfc->getChildAt(i); + mitk::DataNode::Pointer savedPFchildNode = pfc->getDataNodeAt(i); + + if (tmpPFchild == savedPFchildNode->GetData()) + { + MITK_INFO << "[OK] Pointers point to same Data..."; + + }else{ + MITK_INFO << "Pointers differ in equation"; + } + + MITK_INFO << "Level: " << myLevel << " ChildNr.: " << i ; + + mitk::PlanarFigureComposite::Pointer pfcompcastNode= dynamic_cast(savedPFchildNode->GetData()); + mitk::PlanarFigureComposite::Pointer pfcompcast= dynamic_cast(tmpPFchild.GetPointer()); + if( !pfcompcast.IsNull() ) + { // we have a composite as child + + if ( pfcompcastNode.IsNull() ) + { + MITK_INFO << "************** NODE DIFFER FROM PFC...ERROR! ***************"; + } else { + MITK_INFO << "[OK]...node contains right type "; + } + + + + itLevelStatus++; + MITK_INFO << "child is PFC...debug this PFC"; + debugPFComposition(pfcompcast, itLevelStatus); + + } else { + + + // we have a planarFigure as child + // figure out which type + mitk::PlanarCircle::Pointer circleName = mitk::PlanarCircle::New(); + mitk::PlanarRectangle::Pointer rectName = mitk::PlanarRectangle::New(); + mitk::PlanarPolygon::Pointer polyName = mitk::PlanarPolygon::New(); + + + if (tmpPFchild->GetNameOfClass() == circleName->GetNameOfClass() ) + { + MITK_INFO << "a circle child of " << pfc->getDisplayName() ; + + } else if (tmpPFchild->GetNameOfClass() == rectName->GetNameOfClass() ){ + + MITK_INFO << "a rectangle child of " << pfc->getDisplayName() ; + + } else if (tmpPFchild->GetNameOfClass() == polyName->GetNameOfClass() ) { + + MITK_INFO << "a polygon child of " << pfc->getDisplayName() ; + } + + MITK_INFO << "....................................................... " ; + + + + + } + + } //end for + if (myLevel == 0) + { + MITK_INFO << "############################################## " ; + MITK_INFO << "######### DEBUG END ############## " ; + MITK_INFO << "############################################## " ; + } - for( std::vector::iterator it = m_SelectedPF.begin(); - it != m_SelectedPF.end(); ++it ) - { - mitk::DataNode::Pointer nodePF = *it; - mitk::PlanarFigure::Pointer tmpPF = dynamic_cast( nodePF->GetData() ); - PFCOr->addPlanarFigure( tmpPF ); +} - //set to OR Node its child - fbNode->SetVisibility(true); - GetDataStorage()->Add(fbNode,nodePF); - - } - +void QmitkFiberBundleOperationsView::generatePFCompo_OR() +{ //this->addPFCompositionToDataStorage(PFCOr, NULL /*parent*/); } void QmitkFiberBundleOperationsView::generatePFCompo_NOT() { - mitk::PlanarFigureComposite::Pointer PFCNot = mitk::PlanarFigureComposite::New(); - PFCNot->setOperationType(mitk::PFCOMPOSITION_NOT_OPERATION); - - //create NOT Node - mitk::DataNode::Pointer fbNode; - fbNode = mitk::DataNode::New(); - fbNode->SetData(PFCNot); - - - for( std::vector::iterator it = m_SelectedPF.begin(); - it != m_SelectedPF.end(); ++it ) - { - mitk::DataNode::Pointer nodePF = *it; - mitk::PlanarFigure::Pointer tmpPF = dynamic_cast( nodePF->GetData() ); - PFCNot->addPlanarFigure( tmpPF ); - //set to NOT Node its child - - fbNode->SetVisibility(true); - GetDataStorage()->Add(fbNode,nodePF); - - } - //this->addPFCompositionToDataStorage(PFCNot, NULL /*parent*/); } void QmitkFiberBundleOperationsView::deletePFCompo() { - + } void QmitkFiberBundleOperationsView::addPFCompositionToDataStorage(mitk::PlanarFigureComposite::Pointer pfcomp, mitk::DataNode::Pointer parentDataNode ) { - mitk::DataNode::Pointer fbNode; - fbNode = mitk::DataNode::New(); - fbNode->SetData(pfcomp); + //a new planarFigureComposition arrived + //convert it into a dataNode + mitk::DataNode::Pointer newPFCNode; + newPFCNode = mitk::DataNode::New(); + newPFCNode->SetName( pfcomp->getDisplayName() ); + newPFCNode->SetData(pfcomp); + newPFCNode->SetVisibility(true); + GetDataStorage()->Add(newPFCNode); - // selectedPlanarFigureNode1->setSource(fbNode); - // selectedPlanarFigureNode2->setSource(fbNode); + + mitk::DataNode::Pointer becomingChildNode; + for(std::vector::iterator it = m_SelectedPF.begin(); + it != m_SelectedPF.end(); + ++it) + { + becomingChildNode = *it; + GetDataStorage()->AddSource(becomingChildNode, newPFCNode); + + + } + + GetDataStorage()->Modified(); + /* + switch (pfcomp->getOperationType()) { case 0: - fbNode->SetName("AND_PFCombo"); - //TODO childcheck + // AND PLANARFIGURECOMPOSITE + // newPFCNode->SetName("AND_PFCombo"); + if (!parentDataNode.IsNull()) { + MITK_INFO << "adding " << newPFCNode->GetName() << " to " << parentDataNode->GetName() ; + GetDataStorage()->Add(newPFCNode, parentDataNode); + + } else { + MITK_INFO << "adding " << newPFCNode->GetName(); + GetDataStorage()->Add(newPFCNode); + + } + + //iterate through its childs + for(int i=0; igetNumberOfChildren(); ++i) + { + mitk::PlanarFigure::Pointer tmpPFchild = pfcomp->getChildAt(i); + mitk::DataNode::Pointer savedPFchildNode = pfcomp->getDataNodeAt(i); + + mitk::PlanarFigureComposite::Pointer pfcompcast= dynamic_cast(tmpPFchild.GetPointer()); + if ( !pfcompcast.IsNull() ) + { // child is of type planar Figure composite + // make new node of the child, cuz later the child has to be removed of its old position in datamanager + // feed new dataNode with information of the savedDataNode, which is gonna be removed soon + mitk::DataNode::Pointer newChildPFCNode; + newChildPFCNode = mitk::DataNode::New(); + newChildPFCNode->SetData(tmpPFchild); + newChildPFCNode->SetName( savedPFchildNode->GetName() ); + pfcompcast->setDisplayName( savedPFchildNode->GetName() ); //name might be changed in DataManager by user + + //update inside vector the dataNodePointer + pfcomp->replaceDataNodeAt(i, newChildPFCNode); + + addPFCompositionToDataStorage(pfcompcast, newPFCNode); //the current PFCNode becomes the childs parent + + + // remove savedNode here, cuz otherwise its children will change their position in the dataNodeManager + // without having its parent anymore + //GetDataStorage()->Remove(savedPFchildNode); + + if ( GetDataStorage()->Exists(savedPFchildNode)) { + MITK_INFO << savedPFchildNode->GetName() << " exists in DS...trying to remove it"; + + }else{ + MITK_INFO << "[ERROR] does NOT exist, but can I read its Name? " << savedPFchildNode->GetName(); + + } + // remove old child position in dataStorage + GetDataStorage()->Remove(savedPFchildNode); + + + if ( GetDataStorage()->Exists(savedPFchildNode)) { + MITK_INFO << savedPFchildNode->GetName() << " still exists"; + } + + + } else { + + // child is not of type PlanarFigureComposite, so its one of the planarFigures + // create new dataNode containing the data of the old dataNode, but position in dataManager will be + // modified cuz we re setting a (new) parent. + mitk::DataNode::Pointer newPFchildNode = mitk::DataNode::New(); + newPFchildNode->SetName(savedPFchildNode->GetName() ); + newPFchildNode->SetData(tmpPFchild); + newPFchildNode->SetVisibility(true); + + // replace the dataNode in PFComp DataNodeVector + pfcomp->replaceDataNodeAt(i, newPFchildNode); + + + if ( GetDataStorage()->Exists(savedPFchildNode)) { + MITK_INFO << savedPFchildNode->GetName() << " exists in DS...trying to remove it"; + + }else{ + MITK_INFO << "[ERROR] does NOT exist, but can I read its Name? " << savedPFchildNode->GetName(); + + } + // remove old child position in dataStorage + GetDataStorage()->Remove(savedPFchildNode); + + + if ( GetDataStorage()->Exists(savedPFchildNode)) { + MITK_INFO << savedPFchildNode->GetName() << " still exists"; + } + + MITK_INFO << "adding " << newPFchildNode->GetName() << " to " << newPFCNode->GetName(); + //add new child to datamanager with its new position as child of newPFCNode parent + GetDataStorage()->Add(newPFchildNode, newPFCNode); + + } + + + + + } + GetDataStorage()->Modified(); + + + + break; case 1: - fbNode->SetName("OR_PFCombo"); + newPFCNode->SetName("OR_PFCombo"); //TODO childcheck break; - + case 2: - fbNode->SetName("NOT_PFCombo"); + newPFCNode->SetName("NOT_PFCombo"); //TODO childcheck break; - + default: MITK_INFO << "we have an UNDEFINED composition... ERROR" ; break; } - - fbNode->SetVisibility(true); - GetDataStorage()->Add(fbNode); + */ + + } + + Index: mbi-sb/BundlesQt/org.mitk.gui.qt.diffusionimaginginternal/src/internal/QmitkFiberBundleOperationsView.h =================================================================== --- mbi-sb/BundlesQt/org.mitk.gui.qt.diffusionimaginginternal/src/internal/QmitkFiberBundleOperationsView.h (revision 29742) +++ mbi-sb/BundlesQt/org.mitk.gui.qt.diffusionimaginginternal/src/internal/QmitkFiberBundleOperationsView.h (working copy) @@ -1,20 +1,20 @@ /*========================================================================= + + Program: Medical Imaging & Interaction Toolkit + Language: C++ + Date: $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $ + Version: $Revision: 21975 $ + + Copyright (c) German Cancer Research Center, Division of Medical and + Biological Informatics. All rights reserved. + See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ -Program: Medical Imaging & Interaction Toolkit -Language: C++ -Date: $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $ -Version: $Revision: 21975 $ - -Copyright (c) German Cancer Research Center, Division of Medical and -Biological Informatics. All rights reserved. -See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. - -This software is distributed WITHOUT ANY WARRANTY; without even -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ - #ifndef QmitkFiberBundleOperationsView_h #define QmitkFiberBundleOperationsView_h @@ -34,37 +34,37 @@ /*! -\brief QmitkFiberBundleView - -\warning This application module is not yet documented. Use "svn blame/praise/annotate" and ask the author to provide basic documentation. - -\sa QmitkFunctionality -\ingroup Functionalities -*/ + \brief QmitkFiberBundleView + + \warning This application module is not yet documented. Use "svn blame/praise/annotate" and ask the author to provide basic documentation. + + \sa QmitkFunctionality + \ingroup Functionalities + */ class QmitkFiberBundleOperationsView : public QObject, public QmitkFunctionality { - - + + // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT - + public: - + static const std::string VIEW_ID; - + QmitkFiberBundleOperationsView(); virtual ~QmitkFiberBundleOperationsView(); - + virtual void CreateQtPartControl(QWidget *parent); - + virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget); virtual void StdMultiWidgetNotAvailable(); virtual void Activated(); protected slots: - - /// \brief Called when the user clicks the GUI button + + /// \brief Called when the user clicks the GUI button void ActionDrawEllipseTriggered(); void DoFiberExtraction(); void generatePFCompo_AND(); @@ -74,21 +74,21 @@ virtual void AddFigureToDataStorage(mitk::PlanarFigure* figure, const QString& name, const char *propertyKey = NULL, mitk::BaseProperty *property = NULL ); - - + + protected: - + /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged( std::vector nodes ); - + Ui::QmitkFiberBundleOperationsViewControls* m_Controls; - + QmitkStdMultiWidget* m_MultiWidget; //void Select( mitk::DataNode::Pointer node, bool clearMaskOnFirstArgNULL=false, bool clearImageOnFirstArgNULL=false ); - + private: - + int m_EllipseCounter; //contains the selected FiberBundles std::vector m_SelectedFB; @@ -97,7 +97,8 @@ std::vector m_SelectedPF; void addPFCompositionToDataStorage(mitk::PlanarFigureComposite::Pointer, mitk::DataNode::Pointer); - + void debugPFComposition(mitk::PlanarFigureComposite::Pointer , int ); + };