Hi,

recently I needed to change PolyData inside a mitk::Surface and felt that it would be nice to have that mechanism also available for the undo/redo component of mitk. So I've created a new Operation that stores the PolyData to be replaced and implemented an ExecuteOperation method for mitk::Surface to catch the operation and replace the PolyData.

Attached you can find a patch against revision 15966. Maybe you find it also useful.

All the best,
Marius
Index: Core/DataStructures/files.cmake
===================================================================
--- Core/DataStructures/files.cmake     (revision 15965)
+++ Core/DataStructures/files.cmake     (working copy)
@@ -122,4 +122,5 @@
   mitkVtkScalarModeProperty.cpp
   mitkWeakPointerProperty.cpp
   mitkXMLIO.cpp
+  mitkSurfaceOperation.cpp
 )
Index: Core/DataStructures/mitkSurface.cpp
===================================================================
--- Core/DataStructures/mitkSurface.cpp (revision 15965)
+++ Core/DataStructures/mitkSurface.cpp (working copy)
@@ -27,6 +27,8 @@
 #include "mitkSurfaceVtkWriter.h"
 #include "mitkDataTreeNodeFactory.h"
 #include <itkSmartPointerForwardReference.txx>
+#include "mitkInteractionConst.h"
+#include "mitkSurfaceOperation.h"
 
 mitk::Surface::Surface() : m_CalculateBoundingBox( false )
 {
@@ -314,3 +316,27 @@
 
   return true;
 }
+
+void mitk::Surface::ExecuteOperation(Operation *operation)
+{
+       switch ( operation->GetOperationType() )
+       {
+       case OpSURFACECHANGED:
+       
+               mitk::SurfaceOperation* surfOp = 
dynamic_cast<mitk::SurfaceOperation*>(operation);
+               if( ! surfOp ) break;
+
+               unsigned int time = surfOp->GetTimeStep();
+
+               if(m_PolyDataSeries[ time ] != NULL)
+               {
+                       vtkPolyData* updatePoly = surfOp->GetVtkPolyData();
+                       if( updatePoly ){
+                               this->SetVtkPolyData( updatePoly, time );
+                               this->CalculateBoundingBox();
+                       }
+               }
+               break;
+       }
+       this->Modified();
+}
\ No newline at end of file
Index: Core/DataStructures/mitkSurface.h
===================================================================
--- Core/DataStructures/mitkSurface.h   (revision 15965)
+++ Core/DataStructures/mitkSurface.h   (working copy)
@@ -92,6 +92,8 @@
 
     void CalculateBoundingBox();
 
+       virtual void ExecuteOperation(Operation *operation);
+
   protected:
 
     typedef std::vector< vtkPolyData* > VTKPolyDataSeries;
Index: Core/DataStructures/mitkSurfaceOperation.cpp
===================================================================
--- Core/DataStructures/mitkSurfaceOperation.cpp        (revision 0)
+++ Core/DataStructures/mitkSurfaceOperation.cpp        (revision 0)
@@ -0,0 +1,21 @@
+#include "mitkSurfaceOperation.h"
+
+mitk::SurfaceOperation::SurfaceOperation(mitk::OperationType operationType, 
vtkPolyData* polyData, unsigned int t)
+: mitk::Operation(operationType), m_polyData(polyData), m_timeStep(t)
+{
+}
+
+
+mitk::SurfaceOperation::~SurfaceOperation()
+{
+}
+
+vtkPolyData* mitk::SurfaceOperation::GetVtkPolyData()
+{
+       return m_polyData;
+}
+
+unsigned int mitk::SurfaceOperation::GetTimeStep()
+{
+       return m_timeStep;
+}
\ No newline at end of file
Index: Core/DataStructures/mitkSurfaceOperation.h
===================================================================
--- Core/DataStructures/mitkSurfaceOperation.h  (revision 0)
+++ Core/DataStructures/mitkSurfaceOperation.h  (revision 0)
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "mitkCommon.h"
+#include "mitkOperation.h"
+
+#include <vtkPolyData.h>
+
+namespace mitk {
+
+       /*
+        * @brief Operation that stores polydata for changing surfaces
+        */
+       class MITK_CORE_EXPORT SurfaceOperation : public Operation
+       {
+       public:
+
+          /*
+           * Constructor
+           * @param operationType type of the operation (OpSURFACECHANGED)
+               * @param polyData the polydata object to replace in the surface
+               * @param t the time step
+           */
+               SurfaceOperation(mitk::OperationType operationType,     
vtkPolyData* polyData, unsigned int t);
+
+               virtual ~SurfaceOperation();
+
+               vtkPolyData* GetVtkPolyData();
+
+               unsigned int GetTimeStep();
+
+       private:
+
+               vtkPolyData* m_polyData;
+               unsigned int m_timeStep;
+       };
+}; // end namespace mitk
+
Index: Core/Interactions/mitkInteractionConst.h
===================================================================
--- Core/Interactions/mitkInteractionConst.h    (revision 15965)
+++ Core/Interactions/mitkInteractionConst.h    (working copy)
@@ -193,6 +193,7 @@
   OpSHORTESTPATHSEARCH = 2003,       //used in VesselGraphInteractor
   OpATTRIBUTATION = 2004,       //used in VesselGraphInteractor
   OpDEFAULT = 2006,                  //used in VesselGraphInteractor
+  OpSURFACECHANGED = 3000,     // used for changing polydata in surfaces
 };
 
 //##Constants for EventMapping...
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to