7 #include "visuVTKAdaptor/SLabeledPointList.hpp" 9 #include "visuVTKAdaptor/SPointLabel.hpp" 10 #include "visuVTKAdaptor/SPointList.hpp" 12 #include <fwCom/Signal.hxx> 14 #include <fwData/Point.hpp> 15 #include <fwData/PointList.hpp> 17 #include <fwDataTools/fieldHelper/Image.hpp> 19 #include <fwServices/macros.hpp> 20 #include <fwServices/op/Add.hpp> 23 #include <vtkAssemblyNode.h> 24 #include <vtkAssemblyPath.h> 25 #include <vtkCellPicker.h> 26 #include <vtkCommand.h> 27 #include <vtkCubeSource.h> 28 #include <vtkPolyDataMapper.h> 29 #include <vtkRenderer.h> 30 #include <vtkRenderWindowInteractor.h> 39 static const ::fwServices::IService::KeyType s_POINTLIST_INOUT =
"pointList";
56 m_picker( vtkCellPicker::New() ),
57 m_propCollection( vtkPropCollection::New() )
61 m_picker->PickFromListOn();
62 m_picker->SetTolerance(0.001);
72 m_propCollection->Delete();
73 m_propCollection = NULL;
80 m_picker->InitializePickList();
81 m_propCollection->RemoveAllItems();
83 m_propCollection->InitTraversal();
87 while ( (prop = m_propCollection->GetNextProp()) )
89 m_picker->AddPickList(prop);
95 virtual void Execute( vtkObject* caller,
unsigned long eventId,
void*)
101 if ( eventId == vtkCommand::RightButtonPressEvent )
103 std::copy(pos, pos+1, m_lastPos);
104 m_display[0] = pos[0];
105 m_display[1] = pos[1];
107 this->fillPickList();
108 if (m_picker->Pick( m_display, m_service->
getRenderer() ) )
110 if(this->getSelectedPoint())
112 this->SetAbortFlag(1);
116 m_pickedPoint.reset();
117 m_pickedPointList.reset();
121 else if ( (eventId == vtkCommand::RightButtonReleaseEvent ) && !m_pickedPoint.expired() &&
122 !m_pickedPointList.expired() && std::equal(pos, pos+1, m_lastPos) )
124 ::fwData::PointList::PointListContainer& points = m_pickedPointList.lock()->getPoints();
125 ::fwData::PointList::PointListContainer::iterator itr =
126 std::find( points.begin(), points.end(), m_pickedPoint.lock() );
127 if(itr != points.end())
129 ::fwData::Point::sptr
point = *itr;
133 sig->asyncEmit(point);
139 bool getSelectedPoint()
142 vtkPropCollection* propc = m_picker->GetActors();
145 propc->InitTraversal();
146 while ( (prop = propc->GetNextProp()) )
153 m_pickedPoint = pointSrv->getInOut<
::fwData::Point >(SPoint::s_POINT_INOUT);
156 if (!m_pickedPoint.expired() && !m_pickedPointList.expired())
158 ::fwData::PointList::PointListContainer& points = m_pickedPointList.lock()->getPoints();
159 ::fwData::PointList::PointListContainer::iterator itr =
160 std::find(points.begin(), points.end(), m_pickedPoint.lock());
161 if(itr != points.end() )
175 vtkPropCollection* m_propCollection;
178 ::fwData::Point::wptr m_pickedPoint;
179 ::fwData::PointList::wptr m_pickedPointList;
185 SLabeledPointList::SLabeledPointList() noexcept :
186 m_rightButtonCommand(
nullptr),
194 SLabeledPointList::~SLabeledPointList() noexcept
202 this->configureParams();
204 const ConfigType config = this->getConfigTree().get_child(
"config.<xmlattr>");
206 const std::string hexaColor = config.get< std::string >(
"color",
"");
207 m_ptColor = ::fwData::Color::New();
208 if (!hexaColor.empty())
210 m_ptColor->setRGBA(hexaColor);
213 const std::string radius = config.get< std::string >(
"radius",
"");
216 m_radius = std::stod(radius);
219 const std::string interaction = config.get< std::string >(
"interaction",
"");
220 if(!interaction.empty())
222 SLM_FATAL_IF(
"value for 'interaction' must be 'on' or 'off', actual: " + interaction,
223 interaction !=
"on" && interaction !=
"off");
224 m_interaction = (interaction ==
"on");
236 m_rightButtonCommand = vtkLabeledPointDeleteCallBack::New(
this);
237 this->getInteractor()->AddObserver(
"RightButtonPressEvent", m_rightButtonCommand, 1 );
238 this->getInteractor()->AddObserver(
"RightButtonReleaseEvent", m_rightButtonCommand, 1 );
249 ::fwData::PointList::sptr landmarks = this->getInOut< ::fwData::PointList >(s_POINTLIST_INOUT);
251 this->unregisterServices();
253 if ( !landmarks->getPoints().empty() )
256 auto pointListAdaptor = this->registerService< ::visuVTKAdaptor::SPointList>(
"::visuVTKAdaptor::SPointList");
258 pointListAdaptor->registerInput(landmarks, SPointList::s_POINTLIST_INPUT,
true);
260 pointListAdaptor->setColor(m_ptColor);
261 pointListAdaptor->setRadius(m_radius);
262 pointListAdaptor->setInteraction(m_interaction);
264 pointListAdaptor->setPickerId( this->getPickerId() );
265 pointListAdaptor->setRenderService( this->getRenderService() );
266 pointListAdaptor->start();
268 for( ::fwData::Point::sptr
point : landmarks->getPoints() )
270 auto serviceLabel = this->registerService< ::fwRenderVTK::IAdaptor>(
"::visuVTKAdaptor::SPointLabel");
272 serviceLabel->registerInput(
point, SPointLabel::s_POINT_INPUT,
true);
274 serviceLabel->setRenderService( this->getRenderService() );
275 serviceLabel->start();
279 this->setVtkPipelineModified();
280 this->requestRender();
287 if ( m_rightButtonCommand )
289 this->getInteractor()->RemoveObserver(m_rightButtonCommand);
290 m_rightButtonCommand->Delete();
291 m_rightButtonCommand = 0;
294 this->unregisterServices();
295 this->requestRender();
FWRENDERVTK_API vtkRenderWindowInteractor * getInteractor()
Returns the render interactor.
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
This class is a helper to define the connections of a service and its data.
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.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
FWRENDERVTK_API IAdaptor::sptr getAssociatedAdaptor(vtkProp *prop, int depth)
Returns the adaptor associated to the vtkProp.
#define OSLM_TRACE(message)
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_ADDED_SIG
Signal emitted when a Point is added.
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
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...
Adaptor to display a labeled point list.
FWRENDERVTK_API void getAllSubProps(vtkPropCollection *propc, int depth=-1)
Gets all the vtkProp associated to this adaptor.
#define SLM_FATAL_IF(message, cond)
This class defines a list of points.
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.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_REMOVED_SIG
Signal emitted when a Point is added.