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
00019 #include "mitkMoveSurfaceInteractor.h"
00020 #include "mitkSurface.h"
00021 #include "mitkInteractionConst.h"
00022 #include <mitkDataNode.h>
00023 #include "mitkDisplayPositionEvent.h"
00024 #include "mitkStateEvent.h"
00025 #include "mitkProperties.h"
00026
00027
00028 #include "mitkRenderingManager.h"
00029
00030
00031 mitk::MoveSurfaceInteractor
00032 ::MoveSurfaceInteractor(const char * type, DataNode* dataNode)
00033 :Interactor(type, dataNode)
00034 {
00035 }
00036
00037 mitk::MoveSurfaceInteractor::~MoveSurfaceInteractor()
00038 {
00039 }
00040
00041
00042 bool mitk::MoveSurfaceInteractor::ExecuteAction( Action* action, mitk::StateEvent const* stateEvent )
00043 {
00044 bool ok = false;
00045
00046
00047 switch (action->GetActionId())
00048 {
00049 case AcDONOTHING:
00050 ok = true;
00051 break;
00052 case AcCHECKELEMENT:
00053
00054
00055
00056
00057 {
00058 mitk::DisplayPositionEvent const *posEvent = dynamic_cast <const mitk::DisplayPositionEvent *> (stateEvent->GetEvent());
00059 if (posEvent == NULL)
00060 {
00061 MITK_WARN<<"Wrong usage of mitkMoveSurfaceInteractor! Aborting interaction!\n";
00062 return false;
00063 }
00064
00065 mitk::Point3D worldPoint = posEvent->GetWorldPosition();
00066
00067
00068 mitk::StateEvent* newStateEvent = NULL;
00069 const Geometry3D* geometry = GetData()->GetUpdatedTimeSlicedGeometry()->GetGeometry3D( m_TimeStep );
00070 if (geometry->IsInside(worldPoint))
00071 newStateEvent = new mitk::StateEvent(EIDYES, stateEvent->GetEvent());
00072 else
00073 newStateEvent = new mitk::StateEvent(EIDNO, stateEvent->GetEvent());
00074
00075
00076 this->HandleEvent( newStateEvent );
00077
00078 ok = true;
00079 break;
00080 }
00081 case AcSELECT:
00082
00083 {
00084 mitk::BoolProperty::Pointer selected = dynamic_cast<mitk::BoolProperty*>(m_DataNode->GetProperty("selected"));
00085 if ( selected.IsNull() )
00086 {
00087 selected = mitk::BoolProperty::New();
00088 m_DataNode->GetPropertyList()->SetProperty("selected", selected);
00089 }
00090
00091 mitk::ColorProperty::Pointer color = dynamic_cast<mitk::ColorProperty*>(m_DataNode->GetProperty("color"));
00092 if ( color.IsNull() )
00093 {
00094 color = mitk::ColorProperty::New();
00095 m_DataNode->GetPropertyList()->SetProperty("color", color);
00096 }
00097
00098 selected->SetValue(true);
00099 color->SetColor(1.0, 1.0, 0.0);
00100
00101
00102 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
00103
00104 ok = true;
00105 break;
00106 }
00107 case AcDESELECT:
00108
00109 {
00110 mitk::BoolProperty::Pointer selected = dynamic_cast<mitk::BoolProperty*>(m_DataNode->GetProperty("selected"));
00111 if ( selected.IsNull() )
00112 {
00113 selected = mitk::BoolProperty::New();
00114 m_DataNode->GetPropertyList()->SetProperty("selected", selected);
00115 }
00116
00117 mitk::ColorProperty::Pointer color = dynamic_cast<mitk::ColorProperty*>(m_DataNode->GetProperty("color"));
00118 if ( color.IsNull() )
00119 {
00120 color = mitk::ColorProperty::New();
00121 m_DataNode->GetPropertyList()->SetProperty("color", color);
00122 }
00123
00124 selected = mitk::BoolProperty::New(false);
00125 color->SetColor(0.0, 0.0, 1.0);
00126
00127
00128 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
00129
00130 ok = true;
00131 break;
00132 }
00133 case AcMOVE:
00134 {
00135
00136 mitk::IntProperty* xP = dynamic_cast<mitk::IntProperty*>(action->GetProperty("DIRECTION_X"));
00137 mitk::IntProperty* yP = dynamic_cast<mitk::IntProperty*>(action->GetProperty("DIRECTION_Y"));
00138 mitk::IntProperty* zP = dynamic_cast<mitk::IntProperty*>(action->GetProperty("DIRECTION_Z"));
00139 if (xP == NULL || yP == NULL || zP == NULL)
00140 {
00141 MITK_WARN<<"No properties returned\n!";
00142 return false;
00143 }
00144 mitk::Vector3D movementVector;
00145 movementVector.SetElement(0, (float) xP->GetValue());
00146 movementVector.SetElement(1, (float) yP->GetValue());
00147 movementVector.SetElement(2, (float) zP->GetValue());
00148
00149
00150 mitk::Surface* surface = dynamic_cast<mitk::Surface*>(m_DataNode->GetData());
00151 if ( surface == NULL )
00152 {
00153 MITK_WARN<<"MoveSurfaceInteractor got wrong type of data! Aborting interaction!\n";
00154 return false;
00155 }
00156 Geometry3D* geometry = surface->GetUpdatedTimeSlicedGeometry()->GetGeometry3D( m_TimeStep );
00157 geometry->Translate(movementVector);
00158
00159
00160 m_DataNode->Modified();
00161
00162
00163 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
00164
00165 ok = true;
00166 break;
00167 }
00168
00169 default:
00170 return Superclass::ExecuteAction( action, stateEvent );
00171 }
00172
00173 return ok;
00174 }
00175