Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkExtrudedContourInteractor.h"
00019
00020 #include <mitkContour.h>
00021 #include <mitkExtrudedContour.h>
00022
00023 #include <mitkStateEvent.h>
00024 #include <mitkUndoController.h>
00025 #include <mitkProperties.h>
00026 #include <mitkStringProperty.h>
00027 #include <mitkPointOperation.h>
00028 #include <mitkAction.h>
00029 #include <mitkPositionEvent.h>
00030 #include <mitkInteractionConst.h>
00031 #include <mitkPositionEvent.h>
00032 #include <mitkVtkPropRenderer.h>
00033 #include <mitkDataNodeFactory.h>
00034 #include <mitkVtkRepresentationProperty.h>
00035
00036 #include <vtkRenderer.h>
00037 #include <vtkCamera.h>
00038
00039 mitk::ExtrudedContourInteractor::ExtrudedContourInteractor(const char * type, mitk::DataNode* dataNode)
00040 : mitk::Interactor(type, dataNode), m_Started(false)
00041 {
00042 assert(m_DataNode != NULL);
00043
00044 m_DataNode->SetProperty( "material.representation", mitk::VtkRepresentationProperty::New("surface") );
00045
00046 m_Contour = mitk::Contour::New();
00047
00048 m_ContourNode = mitk::DataNode::New();
00049 m_ContourNode->SetData(m_Contour);
00050
00051 m_ContourNode->SetProperty("layer", mitk::IntProperty::New(100) );
00052 m_ContourNode->SetProperty("name", mitk::StringProperty::New("InteractiveFeedbackData") );
00053 m_ContourNode->SetOpacity(1);
00054 m_ContourNode->SetColor(0.4,0.9,0.0);
00055 m_ContourNode->SetProperty( "Width", mitk::FloatProperty::New(2.0) );
00056 m_Started = false;
00057 }
00058
00059 mitk::ExtrudedContourInteractor::~ExtrudedContourInteractor()
00060 {
00061
00062 }
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 bool mitk::ExtrudedContourInteractor::ExecuteAction(mitk::Action* action, mitk::StateEvent const* stateEvent)
00093 {
00094 mitk::Point3D eventPoint;
00095 mitk::Vector3D eventPlaneNormal;
00096
00097 const mitk::PositionEvent* posEvent = dynamic_cast<const mitk::PositionEvent*>(stateEvent->GetEvent());
00098
00099 if(posEvent==NULL)
00100 {
00101 const mitk::DisplayPositionEvent* displayPosEvent = dynamic_cast<const mitk::DisplayPositionEvent*>(stateEvent->GetEvent());
00102 mitk::VtkPropRenderer* sender = (mitk::VtkPropRenderer*) stateEvent->GetEvent()->GetSender();
00103
00104 if((displayPosEvent == NULL) || (sender == NULL))
00105 return false;
00106
00107 eventPoint[0] = displayPosEvent->GetDisplayPosition()[0];
00108 eventPoint[1] = displayPosEvent->GetDisplayPosition()[1];
00109 eventPoint[2] = 0;
00110
00111 #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) ))
00112 typedef itk::Point<double,3> DoublePoint3D;
00113 DoublePoint3D p;
00114 p.CastFrom(eventPoint);
00115 sender->GetVtkRenderer()->SetDisplayPoint(p.GetDataPointer());
00116 #else
00117 sender->GetVtkRenderer()->SetDisplayPoint(eventPoint.GetDataPointer());
00118 #endif
00119 sender->GetVtkRenderer()->DisplayToWorld();
00120
00121
00122 #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) ))
00123 double *vtkwp = sender->GetVtkRenderer()->GetWorldPoint();
00124 #else
00125 float *vtkwp = sender->GetVtkRenderer()->GetWorldPoint();
00126 #endif
00127 vtk2itk(vtkwp, eventPoint);
00128
00129 double *vtkvpn = sender->GetVtkRenderer()->GetActiveCamera()->GetViewPlaneNormal();
00130 vtk2itk(vtkvpn, eventPlaneNormal); eventPlaneNormal = -eventPlaneNormal;
00131 }
00132 else
00133 {
00134 eventPoint = posEvent->GetWorldPosition();
00135 mitk::BaseRenderer* sender = (mitk::BaseRenderer*) stateEvent->GetEvent()->GetSender();
00136 eventPlaneNormal = sender->GetCurrentWorldGeometry2D()->GetAxisVector(2);
00137 }
00138
00139
00140 bool ok = false;
00141 switch (action->GetActionId())
00142 {
00143 case mitk::AcNEWPOINT:
00144 {
00145 Press(eventPoint);
00146 ok = true;
00147 m_Started = true;
00148 break;
00149 }
00150 case mitk::AcINITMOVEMENT:
00151 {
00152 if (m_Started)
00153 {
00154 Move(eventPoint);
00155 ok = true;
00156 break;
00157 }
00158 }
00159 case mitk::AcMOVEPOINT:
00160 {
00161 if (m_Started)
00162 {
00163 Move(eventPoint);
00164 ok = true;
00165 break;
00166 }
00167 }
00168 case mitk::AcFINISHMOVEMENT:
00169 {
00170 if (m_Started)
00171 {
00172 mitk::ExtrudedContour* extrudedcontour = dynamic_cast<mitk::ExtrudedContour*>(m_DataNode->GetData());
00173 extrudedcontour->SetContour(m_Contour);
00174 extrudedcontour->SetVector(eventPlaneNormal);
00175 Release(eventPoint);
00176 ok = true;
00177 m_Started = false;
00178 InvokeEvent(itk::EndEvent());
00179 }
00180 break;
00181 }
00182 default:
00183 ok = false;
00184 break;
00185 }
00186 return ok;
00187 }
00188
00189 void mitk::ExtrudedContourInteractor::Press(mitk::Point3D& point)
00190 {
00191 if (!m_Positive)
00192 m_ContourNode->SetColor(1.0,0.0,0.0);
00193
00194 m_Contour->Initialize();
00195 m_Contour->AddVertex( point );
00196 }
00197
00198 void mitk::ExtrudedContourInteractor::Move(mitk::Point3D& point)
00199 {
00200 assert(m_Contour.IsNotNull());
00201
00202 m_Contour->AddVertex( point );
00203
00204 }
00205
00206 void mitk::ExtrudedContourInteractor::Release(mitk::Point3D& )
00207 {
00208
00209 }