9 #include "visuVTKAdaptor/SPoint.hpp" 11 #include "fwRenderVTK/vtk/Helpers.hpp" 12 #include "fwRenderVTK/vtk/MarkedSphereHandleRepresentation.hpp" 14 #include <fwCom/Signal.hpp> 15 #include <fwCom/Signal.hxx> 17 #include <fwData/Material.hpp> 18 #include <fwData/Point.hpp> 20 #include <fwServices/macros.hpp> 23 #include <vtkCommand.h> 24 #include <vtkHandleWidget.h> 25 #include <vtkPicker.h> 26 #include <vtkPolyDataMapper.h> 27 #include <vtkPropCollection.h> 28 #include <vtkProperty.h> 29 #include <vtkRenderer.h> 30 #include <vtkRenderWindowInteractor.h> 31 #include <vtkSphereHandleRepresentation.h> 32 #include <vtkSphereSource.h> 33 #include <vtkWidgetEventTranslator.h> 42 const ::fwServices::IService::KeyType SPoint::s_POINT_INOUT =
"point";
65 virtual void Execute( vtkObject* caller,
unsigned long eventId,
void*)
67 vtkHandleWidget* handler = vtkHandleWidget::SafeDownCast(caller);
73 if ( eventId == vtkCommand::StartInteractionEvent)
75 handler->AddObserver(
"EndInteractionEvent",
this );
76 handler->AddObserver(
"InteractionEvent",
this );
79 else if ( eventId == vtkCommand::EndInteractionEvent )
81 handler->RemoveObservers(
"EndInteractionEvent",
this );
82 handler->RemoveObservers(
"InteractionEvent",
this );
86 SLM_ASSERT(
"inout 'point' is not defined", point);
88 vtkHandleRepresentation* representation = vtkHandleRepresentation::SafeDownCast(handler->GetRepresentation());
90 double* world = representation->GetWorldPosition();
92 if ( (eventId == vtkCommand::InteractionEvent)
93 || eventId == vtkCommand::EndInteractionEvent )
97 handler->GetInteractor()->GetLastEventPosition(x, y);
104 ::fwRenderVTK::vtk::getNearestPickedPosition(m_service->
getPicker(), m_service->
getRenderer(), world);
107 std::copy( world, world+3, point->getCoord().begin() );
112 else if (eventId == vtkCommand::StartInteractionEvent)
128 SPoint::SPoint() noexcept :
129 m_handle( vtkHandleWidget::New() ),
130 m_representation( ::fwRenderVTK::vtk::MarkedSphereHandleRepresentation::New() ),
131 m_pointUpdateCommand(
nullptr),
135 m_ptColor = ::fwData::Color::New();
136 m_ptSelectedColor = ::fwData::Color::New();
138 m_ptSelectedColor->setRGBA(
"#00FF00");
140 m_handle->SetRepresentation(m_representation);
141 m_handle->SetPriority(0.8f);
143 vtkWidgetEventTranslator* translator = m_handle->GetEventTranslator();
145 translator->RemoveTranslation(vtkCommand::MiddleButtonPressEvent);
146 translator->RemoveTranslation(vtkCommand::MiddleButtonReleaseEvent);
147 translator->RemoveTranslation(vtkCommand::RightButtonPressEvent);
148 translator->RemoveTranslation(vtkCommand::RightButtonReleaseEvent);
151 ::fwRenderVTK::vtk::MarkedSphereHandleRepresentation::SafeDownCast(m_representation);
153 rep->GetSelectedProperty()->SetOpacity(.3);
154 rep->GetMarkerProperty()->SetOpacity(.3);
155 rep->SetHandleSize(m_radius);
157 newSignal<InteractionStartedSignalType>(s_INTERACTION_STARTED_SIG);
162 SPoint::~SPoint() noexcept
164 m_handle->SetRepresentation(0);
168 m_representation->Delete();
169 m_representation =
nullptr;
176 this->configureParams();
178 const ConfigType config = this->getConfigTree().get_child(
"config.<xmlattr>");
180 const std::string hexaSelectedColor = config.get<std::string>(
"selectedColor",
"");
181 m_ptSelectedColor = ::fwData::Color::New();
182 if (!hexaSelectedColor.empty())
184 m_ptSelectedColor->setRGBA(hexaSelectedColor);
187 const std::string hexaColor = config.get<std::string>(
"color",
"");
188 m_ptColor = ::fwData::Color::New();
189 if (!hexaColor.empty())
191 m_ptColor->setRGBA(hexaColor);
194 const std::string radius = config.get<std::string>(
"radius",
"");
197 m_radius = std::stod(radius);
200 const std::string interaction = config.get<std::string>(
"interaction",
"");
201 if(!interaction.empty())
203 SLM_FATAL_IF(
"value for 'interaction' must be 'on' or 'off', actual: " + interaction,
204 interaction !=
"on" && interaction !=
"off");
205 m_interaction = (interaction ==
"on");
215 m_handle->SetInteractor( this->getInteractor() );
216 m_handle->KeyPressActivationOff();
218 m_pointUpdateCommand = vtkPointUpdateCallBack::New(
this);
220 m_handle->AddObserver(
"StartInteractionEvent", m_pointUpdateCommand );
226 this->registerProp(m_representation);
235 ::fwData::Point::sptr
point = this->getInOut< ::fwData::Point >(s_POINT_INOUT);
240 std::copy(point->getCoord().begin(), point->getCoord().end(), ps );
241 m_representation->SetWorldPosition( ps );
243 getRenderer()->ResetCameraClippingRange();
246 ::fwRenderVTK::vtk::MarkedSphereHandleRepresentation::SafeDownCast(m_representation);
248 SLM_ASSERT(
"MarkedSphereHandleRepresentation cast failed", rep);
250 rep->SetHandleSize(m_radius);
252 rep->GetProperty()->SetColor(m_ptColor->red(), m_ptColor->green(), m_ptColor->blue());
253 rep->GetProperty()->SetOpacity(m_ptColor->alpha());
255 rep->GetSelectedProperty()->SetColor(m_ptSelectedColor->red(), m_ptSelectedColor->green(),
256 m_ptSelectedColor->blue());
257 rep->GetSelectedProperty()->SetOpacity(m_ptSelectedColor->alpha());
259 m_handle->SetProcessEvents(m_interaction);
260 m_handle->SetManagesCursor(m_interaction);
262 this->setVtkPipelineModified();
263 this->requestRender();
271 m_handle->RemoveObserver(m_pointUpdateCommand);
273 m_pointUpdateCommand->Delete();
274 m_pointUpdateCommand = 0;
276 m_handle->SetInteractor(0);
278 this->unregisterProps();
279 this->setVtkPipelineModified();
280 this->requestRender();
285 void SPoint::setRadius(
const double radius)
293 void SPoint::setColor(
const float red,
const float green,
const float blue,
const float alpha)
295 m_ptColor->setRGBA(red, green, blue, alpha);
301 void SPoint::setSelectedColor(
const float red,
const float green,
const float blue,
const float alpha)
303 m_ptSelectedColor->setRGBA(red, green, blue, alpha);
309 void SPoint::setInteraction(
const bool interaction)
311 m_interaction = interaction;
This class is a helper to define the connections of a service and its data.
Adaptor to display a point.
FWRENDERVTK_API vtkRenderer * getRenderer()
Returns the renderer.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
This class define a 3D point.
static VISUVTKADAPTOR_APIconst::fwCom::Signals::SignalKeyType s_INTERACTION_STARTED_SIG
Type of signal when point interaction is started.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
FWRENDERVTK_API vtkAbstractPropPicker * getPicker(std::string pickerId="")
Get the picker.
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
#define SLM_FATAL_IF(message, cond)
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
std::shared_ptr< DATATYPE > getInOut(const KeyType &key) const
Return the inout object at the given key. Asserts if the data is not of the right type...
Base class for VTK adaptors.