Page MenuHomePhabricator

6047_patchNodeDependentPointSetInteractor.patch

Authored By
wegner
Nov 12 2010, 3:31 PM
Size
17 KB
Referenced Files
None
Subscribers
None

6047_patchNodeDependentPointSetInteractor.patch

Index: mitk/Applications/Tutorial/Step5.cpp
===================================================================
--- mitk/Applications/Tutorial/Step5.cpp (revision 27420)
+++ mitk/Applications/Tutorial/Step5.cpp (working copy)
@@ -26,12 +26,14 @@
#include "mitkGlobalInteraction.h"
#include "mitkPointSet.h"
-#include "mitkPointSetInteractor.h"
+#include "mitkNodeDepententPointSetInteractor.h"
#include <itksys/SystemTools.hxx>
#include <QApplication>
#include <QHBoxLayout>
+#include "mitkNodePredicateDataType.h"
+
//##Documentation
//## @brief Interactively add points
//##
@@ -79,6 +81,7 @@
// Create a DataNodeFactory to read a data format supported
// by the DataNodeFactory (many image formats, surface formats, etc.)
mitk::DataNodeFactory::Pointer nodeReader=mitk::DataNodeFactory::New();
+
const char * filename = argv[i];
try
{
@@ -90,8 +93,8 @@
// Since the DataNodeFactory directly creates a node,
// use the iterator to add the read node to the tree
- mitk::DataNode::Pointer node = nodeReader->GetOutput();
- ds->Add(node);
+ mitk::DataNode::Pointer imageNode = nodeReader->GetOutput();
+ ds->Add(imageNode);
}
catch(...)
{
@@ -100,6 +103,15 @@
}
}
+
+ mitk::NodePredicateDataType::Pointer predicate(mitk::NodePredicateDataType::New("Image"));
+ mitk::DataStorage::SetOfObjects::ConstPointer allImagesInDS = ds->GetSubset(predicate);
+ if (allImagesInDS->Size()<2)
+ {
+ fprintf( stderr, "please specify two images in command line \n");
+ exit(2);
+ }
+
// *******************************************************
// ****************** START OF NEW PART ******************
// *******************************************************
@@ -109,19 +121,25 @@
//*************************************************************************
// Create PointSet and a node for it
- mitk::PointSet::Pointer pointSet = mitk::PointSet::New();
- mitk::DataNode::Pointer pointSetNode = mitk::DataNode::New();
- pointSetNode->SetData(pointSet);
+ mitk::PointSet::Pointer pointSet1 = mitk::PointSet::New();
+ mitk::DataNode::Pointer pointSetNode1 = mitk::DataNode::New();
+ pointSetNode1->AddProperty( "unselectedcolor", mitk::ColorProperty::New(0.0f, 1.0f, 0.0f));
+ pointSetNode1->SetData(pointSet1);
+ mitk::NodeDepententPointSetInteractor::Pointer interactor1 = mitk::NodeDepententPointSetInteractor::New("pointsetinteractor", pointSetNode1, allImagesInDS->GetElement(0));
+ // Add the node to the tree
+ ds->Add(pointSetNode1);
+ mitk::GlobalInteraction::GetInstance()->AddInteractor(interactor1);
+
+ mitk::PointSet::Pointer pointSet2 = mitk::PointSet::New();
+ mitk::DataNode::Pointer pointSetNode2 = mitk::DataNode::New();
+ pointSetNode2->AddProperty( "unselectedcolor", mitk::ColorProperty::New(0.0f, 0.0f, 1.0f));
+ pointSetNode2->SetData(pointSet2);
+ mitk::NodeDepententPointSetInteractor::Pointer interactor2 = mitk::NodeDepententPointSetInteractor::New("pointsetinteractor", pointSetNode2, allImagesInDS->GetElement(1));
// Add the node to the tree
- ds->Add(pointSetNode);
+ ds->Add(pointSetNode2);
+ mitk::GlobalInteraction::GetInstance()->AddInteractor(interactor2);
- // Create PointSetInteractor, associate to pointSetNode and add as
- // interactor to GlobalInteraction
- mitk::GlobalInteraction::GetInstance()->AddInteractor(
- mitk::PointSetInteractor::New("pointsetinteractor", pointSetNode)
- );
-
// *******************************************************
// ******************* END OF NEW PART *******************
// *******************************************************
@@ -151,6 +169,9 @@
// Use it as a 3D view
renderWindow.GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard3D);
+ allImagesInDS->GetElement(0)->SetBoolProperty("visible", true, renderWindow.GetRenderer());
+ allImagesInDS->GetElement(1)->SetBoolProperty("visible", true, renderWindow.GetRenderer());
+
//*************************************************************************
// Part Vb: 2D view for slicing transversally
//*************************************************************************
@@ -169,6 +190,9 @@
// slice itself in 3D: add it to the tree!
ds->Add(view2.GetRenderer()->GetCurrentWorldGeometry2DNode());
+ allImagesInDS->GetElement(0)->SetBoolProperty("visible", true, view2.GetRenderer());
+ allImagesInDS->GetElement(1)->SetBoolProperty("visible", false, view2.GetRenderer());
+
//*************************************************************************
// Part Vc: 2D view for slicing sagitally
//*************************************************************************
@@ -187,6 +211,11 @@
// slice itself in 3D: add it to the tree!
ds->Add(view3.GetRenderer()->GetCurrentWorldGeometry2DNode());
+ //set property visibility
+ allImagesInDS->GetElement(0)->SetBoolProperty("visible", false, view3.GetRenderer());
+ allImagesInDS->GetElement(1)->SetBoolProperty("visible", true, view3.GetRenderer());
+
+
//*************************************************************************
//Part VII: Qt-specific initialization
//*************************************************************************
Index: mitk/Core/Code/files.cmake
===================================================================
--- mitk/Core/Code/files.cmake (revision 27420)
+++ mitk/Core/Code/files.cmake (working copy)
@@ -139,6 +139,7 @@
Interactions/mitkInteractor.cpp
Interactions/mitkMouseMovePointSetInteractor.cpp
Interactions/mitkMoveSurfaceInteractor.cpp
+ Interactions/mitkNodeDepententPointSetInteractor.cpp
Interactions/mitkPointSetInteractor.cpp
Interactions/mitkPositionEvent.cpp
Interactions/mitkPositionTracker.cpp
Index: mitk/Core/Code/Interactions/mitkNodeDepententPointSetInteractor.cpp
===================================================================
--- mitk/Core/Code/Interactions/mitkNodeDepententPointSetInteractor.cpp (revision 0)
+++ mitk/Core/Code/Interactions/mitkNodeDepententPointSetInteractor.cpp (revision 0)
@@ -0,0 +1,54 @@
+/*=========================================================================
+
+Program: Medical Imaging & Interaction Toolkit
+Language: C++
+Date: $Date: 2010-09-14 09:48:51 +0200 (Di, 14 Sep 2010) $
+Version: $Revision: 26074 $
+
+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 "mitkNodeDepententPointSetInteractor.h"
+#include "mitkStateEvent.h"
+#include "mitkEvent.h"
+
+mitk::NodeDepententPointSetInteractor
+::NodeDepententPointSetInteractor(const char * type, DataNode* dataNode, DataNode* dependentDataNode, int n)
+:PointSetInteractor(type, dataNode, n), m_DependentDataNode(dependentDataNode)
+{
+}
+
+mitk::NodeDepententPointSetInteractor::~NodeDepententPointSetInteractor()
+{
+}
+
+float mitk::NodeDepententPointSetInteractor::CanHandleEvent(StateEvent const* stateEvent) const
+{
+ if (m_DependentDataNode.IsNull())
+ return 0;
+
+ // use sender to check if the specified dependentDataNode is visible there
+ mitk::BaseRenderer* sender = stateEvent->GetEvent()->GetSender();
+ if (sender == NULL)
+ return 0;
+
+ bool value = false;
+
+ if ( m_DependentDataNode->GetPropertyList(sender)->GetBoolProperty("visible", value) == false)//property doesn't exist
+ return 0;
+ if (value == false) //the dependent node is invisible
+ return 0;
+
+ //ok, it is visible, so check the standard way.
+ return Superclass::CanHandleEvent(stateEvent);
+}
+
+
Property changes on: mitk\Core\Code\Interactions\mitkNodeDepententPointSetInteractor.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Index: mitk/Core/Code/Interactions/mitkNodeDepententPointSetInteractor.h
===================================================================
--- mitk/Core/Code/Interactions/mitkNodeDepententPointSetInteractor.h (revision 0)
+++ mitk/Core/Code/Interactions/mitkNodeDepententPointSetInteractor.h (revision 0)
@@ -0,0 +1,74 @@
+/*=========================================================================
+
+Program: Medical Imaging & Interaction Toolkit
+Language: C++
+Date: $Date: 2010-10-04 14:49:09 +0200 (Mo, 04 Okt 2010) $
+Version: $Revision: 26576 $
+
+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 MITKNodeDepententPointSetInteractor_H_HEADER_INCLUDED
+#define MITKNodeDepententPointSetInteractor_H_HEADER_INCLUDED
+
+#include "mitkCommon.h"
+#include "mitkVector.h"
+#include <mitkInteractor.h>
+#include <mitkDataNode.h>
+#include <mitkPointSetInteractor.h>
+
+
+namespace mitk
+{
+
+ /**
+ * \brief PointSetInteraction that is dependent on a node.
+ *
+ * Dependent on a node means, that the interactor checks if the
+ * specified node (e.g. image) for instance is visible in the renderwindow the event comes from.
+ * Thus a image specific pointsetinteraction for registration can be built up.
+ * \ingroup Interaction
+ */
+ class MITK_CORE_EXPORT NodeDepententPointSetInteractor : public PointSetInteractor
+ {
+ public:
+ mitkClassMacro(NodeDepententPointSetInteractor, PointSetInteractor);
+ mitkNewMacro4Param(Self, const char*, DataNode*, DataNode*, int);
+ mitkNewMacro3Param(Self, const char*, DataNode*, DataNode*);
+
+ /**
+ * \brief Checks visibility of the specified node (e.g. image),
+ * returns 0 if node is not visible in sending render window
+ * If Sender within stateEvent is NULL a value of 0 is returned.
+ */
+ virtual float CanHandleEvent(StateEvent const* stateEvent) const;
+
+ protected:
+ /**
+ * \brief Constructor with Param n for limited Set of Points
+ *
+ * If no n is set, then the number of points is unlimited
+ * n=0 is not supported. In this case, n is set to 1.
+ */
+ NodeDepententPointSetInteractor(const char * type, DataNode* dataNode, DataNode* dependentDataNode, int n = -1);
+
+ /**
+ * \brief Default Destructor
+ **/
+ virtual ~NodeDepententPointSetInteractor();
+
+ public:
+
+ mitk::DataNode::Pointer m_DependentDataNode;
+
+ };
+}
+#endif /* MITKNodeDepententPointSetInteractor_H_HEADER_INCLUDED */
Property changes on: mitk\Core\Code\Interactions\mitkNodeDepententPointSetInteractor.h
___________________________________________________________________
Added: svn:eol-style
+ native
Index: mitk/Core/Code/Interactions/StateMachine.xml
===================================================================
--- mitk/Core/Code/Interactions/StateMachine.xml (revision 27420)
+++ mitk/Core/Code/Interactions/StateMachine.xml (working copy)
@@ -2055,9 +2055,8 @@
<transition NAME="0SmallerPointsLoadedSmallerN" NEXT_STATE_ID="2" EVENT_ID="1014" /> <!-- If points have been loaded, goto right state; checked in constructor -->
<transition NAME="PointsLoadedGreaterEqualsN" NEXT_STATE_ID="4" EVENT_ID="1015" /> <!-- If points have been loaded, goto right state; checked in constructor -->
<transition NAME="addPoint but check n" NEXT_STATE_ID="3" EVENT_ID="3">
- <action ID="1101">
+ <action ID="1101" />
<!--AcMODE_SELECT-->
- </action>
<action ID="32" />
</transition>
<transition NAME="checkn Delete" NEXT_STATE_ID="30" EVENT_ID="12">
@@ -2065,14 +2064,12 @@
<!--AcCHECKNUMBEROFPOINTS-->
</transition>
<transition NAME="SetThisStatemachineOnSelected" NEXT_STATE_ID="1" EVENT_ID="1030">
- <action ID="1101">
+ <action ID="1101" />
<!--AcMODE_SELECT-->
- </action>
</transition>
<transition NAME="SetThisStatemachineOnDeselected" NEXT_STATE_ID="1" EVENT_ID="1031">
- <action ID="1100">
+ <action ID="1100" />
<!--AcMODE_DESELECT-->
- </action>
</transition>
</state>
<state NAME="space left" ID="2" X_POS="659" Y_POS="257" WIDTH="100" HEIGHT="50">
@@ -2088,12 +2085,10 @@
</transition>
<transition NAME="DeselectAll" NEXT_STATE_ID="2" EVENT_ID="14">
<!--Event = ESC-->
- <action ID="72">
+ <action ID="72" />
<!--AcDESELECTALL-->
- </action>
- <action ID="1100">
+ <action ID="1100" />
<!--AcMODE_DESELECT-->
- </action>
</transition>
</state>
<state NAME="checkedN" ID="3" X_POS="745" Y_POS="744" WIDTH="100" HEIGHT="50">
@@ -2106,41 +2101,33 @@
</state>
<state NAME="set full" ID="4" X_POS="267" Y_POS="633" WIDTH="100" HEIGHT="50">
<transition NAME="Select or move point FULL" NEXT_STATE_ID="20" EVENT_ID="1">
- <action ID="30">
+ <action ID="30" />
<!--AcCHECKELEMENT-->
- </action>
</transition>
<transition NAME="checkn Delete selected Point" NEXT_STATE_ID="30" EVENT_ID="12">
- <action ID="330">
+ <action ID="330" />
<!--AcCHECKNUMBEROFPOINTS-->
- </action>
</transition>
<transition NAME="DeselectAll" NEXT_STATE_ID="2" EVENT_ID="14">
<!--Event = ESC-->
- <action ID="72">
+ <action ID="72" />
<!--AcDESELECTALL-->
- </action>
- <action ID="1100">
+ <action ID="1100" />
<!--AcMODEDESELECT-->
- </action>
</transition>
</state>
<state NAME="picked NotFull" ID="10" X_POS="903" Y_POS="38" WIDTH="100" HEIGHT="50">
<transition NAME="StNo" NEXT_STATE_ID="2" EVENT_ID="1003">
- <action ID="72">
+ <action ID="72" />
<!--AcDESELECTALL-->
- </action>
- <action ID="1100">
+ <action ID="1100" />
<!--AcMODEDESELECT-->
- </action>
</transition>
<transition NAME="StYes" NEXT_STATE_ID="11" EVENT_ID="1004">
- <action ID="34">
+ <action ID="34" />
<!--AcCHECKSELECTED-->
- </action>
- <action ID="1101">
+ <action ID="1101" />
<!--AcMODESELECT-->
- </action>
</transition>
</state>
<state NAME="already selected Space" ID="11" X_POS="391" Y_POS="11" WIDTH="100" HEIGHT="50">
@@ -2164,32 +2151,26 @@
</state>
<state NAME="picked Full" ID="20" X_POS="122" Y_POS="766" WIDTH="100" HEIGHT="50">
<transition NAME="StNO" NEXT_STATE_ID="4" EVENT_ID="1003">
- <action ID="72">
+ <action ID="72" />
<!--AcDESELECTALL-->
- </action>
- <action ID="1100">
+ <action ID="1100" />
<!--AcMODEDESELECT-->
- </action>
</transition>
<transition NAME="StYES" NEXT_STATE_ID="21" EVENT_ID="1004">
- <action ID="34">
+ <action ID="34" />
<!--AcCHECKSELECTED-->
- </action>
- <action ID="1101">
+ <action ID="1101" />
<!--AcMODESELECT-->
- </action>
</transition>
</state>
<state NAME="selected Full" ID="21" X_POS="23" Y_POS="485" WIDTH="100" HEIGHT="50">
<transition NAME="StNo" NEXT_STATE_ID="4" EVENT_ID="1003">
- <action ID="60">
+ <action ID="60" />
<!--AcSELECTPICKEDOBJECT-->
- </action>
</transition>
<transition NAME="StYes" NEXT_STATE_ID="22" EVENT_ID="1004">
- <action ID="8">
+ <action ID="8" />
<!--AcINITMOVEMENT-->
- </action>
</transition>
</state>
<state NAME="move Point Full" ID="22" X_POS="67" Y_POS="255" WIDTH="100" HEIGHT="50">
@@ -2207,16 +2188,17 @@
<state NAME="checkn Delete" ID="30" X_POS="1124" Y_POS="708" WIDTH="100" HEIGHT="50">
<transition NAME="StillFull" NEXT_STATE_ID="4" EVENT_ID="1015">
<action ID="100" />
+ <!--AcREMOVEPOINT-->
</transition>
<transition NAME="NotEmptyNotFull" NEXT_STATE_ID="2" EVENT_ID="1014">
<action ID="100" />
+ <!--AcREMOVEPOINT-->
</transition>
<transition NAME="WillBeEmpty" NEXT_STATE_ID="1" EVENT_ID="1017">
<action ID="100" />
<!--AcREMOVEPOINT-->
- <action ID="1100">
+ <action ID="1100" />
<!--AcMODEDESELECT-->
- </action>
</transition>
</state>
<state NAME="selected space left" ID="31" X_POS="22" Y_POS="480" WIDTH="90" HEIGHT="50">
@@ -2229,18 +2211,25 @@
<state NAME="checkedPositionEventSmallerN" ID="40" X_POS="267" Y_POS="301" WIDTH="173" HEIGHT="50">
<transition NAME="PositionEvent" NEXT_STATE_ID="2" EVENT_ID="1004">
<action ID="10" />
- <!--AcADDPOINT-->
+ <!--AcADDPOINT-->
+ <action ID="1100" />
+ <!--AcMODE_DESELECT-->
</transition>
<transition NAME="others" NEXT_STATE_ID="2" EVENT_ID="1003">
- <action ID="0" />
+ <action ID="1100" />
+ <!--AcMODE_DESELECT-->
</transition>
</state>
<state NAME="checkedPositionEventGreaterN" ID="41" X_POS="562" Y_POS="424" WIDTH="168" HEIGHT="50">
<transition NAME="PositionEvent" NEXT_STATE_ID="4" EVENT_ID="1004">
<action ID="10" />
+ <!--AcADDPOINT-->
+ <action ID="1100" />
+ <!--AcMODE_DESELECT-->
</transition>
<transition NAME="others" NEXT_STATE_ID="2" EVENT_ID="1003">
- <action ID="0" />
+ <action ID="1100" />
+ <!--AcMODE_DESELECT-->
</transition>
</state>
</stateMachine>

File Metadata

Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
609
Default Alt Text
6047_patchNodeDependentPointSetInteractor.patch (17 KB)

Event Timeline

Changes to show data node dependent point set interaction