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 "mitkContourInteractor.h"
00019
00020 #include <mitkContour.h>
00021
00022
00023
00024 #include <mitkProperties.h>
00025 #include <mitkStringProperty.h>
00026 #include <mitkPointOperation.h>
00027 #include <mitkAction.h>
00028 #include <mitkPositionEvent.h>
00029 #include <mitkInteractionConst.h>
00030 #include <mitkPositionEvent.h>
00031 #include <mitkStateEvent.h>
00032 #include <mitkVtkPropRenderer.h>
00033
00034 #include <vtkRenderer.h>
00035
00036 mitk::ContourInteractor::ContourInteractor(const char * type, mitk::DataNode* dataNode)
00037 : mitk::Interactor(type, dataNode), m_Started(false)
00038 {
00039 assert(m_DataNode != NULL);
00040
00041 m_DataNode->SetProperty("layer", mitk::IntProperty::New(100) );
00042 m_DataNode->SetProperty("name", mitk::StringProperty::New("InteractiveFeedbackData") );
00043 m_DataNode->SetOpacity(1);
00044 m_DataNode->SetColor(0.4,0.9,0.0);
00045 m_DataNode->SetProperty( "Width", mitk::FloatProperty::New(2.0) );
00046 m_Started = false;
00047 }
00048
00049 mitk::ContourInteractor::~ContourInteractor()
00050 {
00051
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 bool mitk::ContourInteractor::ExecuteAction(mitk::Action* action, mitk::StateEvent const* stateEvent)
00083 {
00084 mitk::Point3D eventPoint;
00085
00086 const mitk::PositionEvent* posEvent = dynamic_cast<const mitk::PositionEvent*>(stateEvent->GetEvent());
00087
00088 if(posEvent==NULL)
00089 {
00090 const mitk::DisplayPositionEvent* displayPosEvent = dynamic_cast<const mitk::DisplayPositionEvent*>(stateEvent->GetEvent());
00091 mitk::VtkPropRenderer* sender = (mitk::VtkPropRenderer*) stateEvent->GetEvent()->GetSender();
00092
00093 if((displayPosEvent == NULL) || (sender == NULL))
00094 return false;
00095
00096 eventPoint[0] = displayPosEvent->GetDisplayPosition()[0];
00097 eventPoint[1] = displayPosEvent->GetDisplayPosition()[1];
00098 eventPoint[2] = 0;
00099
00100 #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) ))
00101 typedef itk::Point<double,3> DoublePoint3D;
00102 DoublePoint3D p;
00103 p.CastFrom(eventPoint);
00104 sender->GetVtkRenderer()->SetDisplayPoint(p.GetDataPointer());
00105 #else
00106 sender->GetVtkRenderer()->SetDisplayPoint(eventPoint.GetDataPointer());
00107 #endif
00108
00109 sender->GetVtkRenderer()->DisplayToWorld();
00110 vtkFloatingPointType *vtkwp = sender->GetVtkRenderer()->GetWorldPoint();
00111 vtk2itk(vtkwp, eventPoint);
00112 }
00113 else
00114 {
00115 eventPoint = posEvent->GetWorldPosition();
00116 }
00117
00118
00119 bool ok = false;
00120 switch (action->GetActionId())
00121 {
00122 case mitk::AcNEWPOINT:
00123 {
00124 Press(eventPoint);
00125 ok = true;
00126 m_Started = true;
00127 break;
00128 }
00129 case mitk::AcINITMOVEMENT:
00130 {
00131 if (m_Started)
00132 {
00133 Move(eventPoint);
00134 ok = true;
00135 break;
00136 }
00137 }
00138 case mitk::AcMOVEPOINT:
00139 {
00140 if (m_Started)
00141 {
00142 Move(eventPoint);
00143 ok = true;
00144 break;
00145 }
00146 }
00147 case mitk::AcFINISHMOVEMENT:
00148 {
00149 if (m_Started)
00150 {
00151 Release(eventPoint);
00152 ok = true;
00153 m_Started = false;
00154 }
00155 break;
00156 }
00157 default:
00158 ok = false;
00159 break;
00160 }
00161 return ok;
00162 }
00163
00164 void mitk::ContourInteractor::Press(mitk::Point3D& point)
00165 {
00166 mitk::Contour* contour = dynamic_cast<mitk::Contour*>(m_DataNode->GetData());
00167 assert(contour!=NULL);
00168
00169 if (!m_Positive)
00170 m_DataNode->SetColor(1.0,0.0,0.0);
00171
00172 contour->Initialize();
00173 contour->AddVertex( point );
00174 }
00175
00176 void mitk::ContourInteractor::Move(mitk::Point3D& point)
00177 {
00178 mitk::Contour* contour = dynamic_cast<mitk::Contour*>(m_DataNode->GetData());
00179 assert(contour!=NULL);
00180
00181 contour->AddVertex( point );
00182
00183 }
00184
00185 void mitk::ContourInteractor::Release(mitk::Point3D& )
00186 {
00187
00188 }