9 #include "visuVTKAdaptor/SPlaneInteractor.hpp" 11 #include <fwCom/Signal.hpp> 12 #include <fwCom/Signal.hxx> 13 #include <fwCom/Signals.hpp> 15 #include <fwData/Plane.hpp> 17 #include <fwMath/PlaneFunctions.hpp> 19 #include <fwServices/macros.hpp> 21 #include <vtkCommand.h> 22 #include <vtkRenderWindowInteractor.h> 29 static const ::fwServices::IService::KeyType s_PLANE_INOUT =
"plane";
51 virtual void Execute( vtkObject* caller,
unsigned long eventId,
void*)
53 if ( eventId == vtkCommand::KeyPressEvent)
55 vtkRenderWindowInteractor* rwi = vtkRenderWindowInteractor::SafeDownCast(caller);
56 SLM_ASSERT(
"invalid vtkRenderWindowInteractor", rwi);
59 char* keySym = rwi->GetKeySym();
61 if (std::string(keySym) ==
"space")
63 m_adaptor->switchPlaneNormal();
65 else if (std::string(keySym) ==
"Escape" || std::string(keySym) ==
"Tab")
67 m_adaptor->deselectPlane();
70 else if (eventId == vtkCommand::MouseWheelForwardEvent)
73 m_adaptor->pushPlane(1);
75 else if (eventId == vtkCommand::MouseWheelBackwardEvent)
78 m_adaptor->pushPlane(-1);
84 void setAdaptor( SPlaneInteractor::sptr adaptor)
90 SPlaneInteractor::sptr m_adaptor;
96 SPlaneInteractor::SPlaneInteractor() noexcept :
97 m_vtkObserver(
nullptr),
104 SPlaneInteractor::~SPlaneInteractor() noexcept
112 this->configureParams();
121 if (this->getInOut< ::fwData::Plane >(s_PLANE_INOUT))
124 observer->setAdaptor( SPlaneInteractor::dynamicCast(this->getSptr()) );
126 m_vtkObserver = observer;
128 this->getInteractor()->AddObserver(vtkCommand::KeyPressEvent, m_vtkObserver, m_priority);
129 this->getInteractor()->AddObserver(vtkCommand::KeyReleaseEvent, m_vtkObserver, m_priority);
130 this->getInteractor()->AddObserver(vtkCommand::MouseWheelForwardEvent, m_vtkObserver, m_priority);
131 this->getInteractor()->AddObserver(vtkCommand::MouseWheelBackwardEvent, m_vtkObserver, m_priority);
147 this->getInteractor()->RemoveObservers(vtkCommand::KeyPressEvent, m_vtkObserver);
148 this->getInteractor()->RemoveObservers(vtkCommand::KeyReleaseEvent, m_vtkObserver);
149 this->getInteractor()->RemoveObservers(vtkCommand::MouseWheelForwardEvent, m_vtkObserver);
150 this->getInteractor()->RemoveObservers(vtkCommand::MouseWheelBackwardEvent, m_vtkObserver);
151 m_vtkObserver->Delete();
152 m_vtkObserver =
nullptr;
160 ::fwData::Plane::sptr plane = this->getInOut< ::fwData::Plane >(s_PLANE_INOUT);
164 ::fwData::Point::sptr pt0 = plane->getPoints()[0];
165 ::fwData::Point::sptr pt1 = plane->getPoints()[1];
166 ::fwData::Point::sptr pt2 = plane->getPoints()[2];
167 if ( pt0 && pt1 && pt2 )
169 plane->setValue(pt0, pt2, pt1);
174 this->setVtkPipelineModified();
182 ::fwData::Plane::sptr plane = this->getInOut< ::fwData::Plane >(s_PLANE_INOUT);
185 ::fwData::Point::sptr pt0 = plane->getPoints()[0];
186 ::fwData::Point::sptr pt1 = plane->getPoints()[1];
187 ::fwData::Point::sptr pt2 = plane->getPoints()[2];
190 ::fwMath::setValues(planeDesc, pt0->getCoord(), pt1->getCoord(), pt2->getCoord());
192 fwVec3d normal = ::fwMath::getNormal(planeDesc);
193 if ( pt0 && pt1 && pt2 )
195 fwVec3d vec0 = pt0->getCoord();
196 fwVec3d vec1 = pt1->getCoord();
197 fwVec3d vec2 = pt2->getCoord();
199 vec0 = vec0 + normal*factor;
200 vec1 = vec1 + normal*factor;
201 vec2 = vec2 + normal*factor;
207 plane->setValue(pt0, pt1, pt2);
208 ::fwMath::setValues(planeDesc, pt0->getCoord(), pt1->getCoord(), pt2->getCoord());
209 normal = ::fwMath::getNormal(planeDesc);
211 ::fwData::Object::ModifiedSignalType::sptr sig;
221 this->setVtkPipelineModified();
230 ::fwData::Plane::csptr plane = this->getInOut< ::fwData::Plane >(s_PLANE_INOUT);
234 sig->asyncEmit(
false);
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
VISUVTKADAPTOR_API void switchPlaneNormal()
Switch plane normal.
This service allows to interact with the plane (switch normal, deselect, move along the normal) ...
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
Base class for each data object.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
VISUVTKADAPTOR_API void deselectPlane()
Deselect the plane.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_SELECTED_SIG
Signal emitted when plane is selected/deselected.
VISUVTKADAPTOR_API void pushPlane(double factor)
Move the plane along the normal.
Base class for VTK adaptors.