9 #include "visuVTKAdaptor/SPointList.hpp" 11 #include <fwCom/Slot.hpp> 12 #include <fwCom/Slot.hxx> 13 #include <fwCom/Slots.hpp> 14 #include <fwCom/Slots.hxx> 16 #include <fwData/Material.hpp> 17 #include <fwData/PointList.hpp> 18 #include <fwData/Reconstruction.hpp> 20 #include <fwServices/macros.hpp> 21 #include <fwServices/op/Add.hpp> 23 #include <boost/function.hpp> 26 #include <vtkCubeSource.h> 27 #include <vtkPolyDataMapper.h> 38 static const ::fwCom::Slots::SlotKeyType s_ADD_POINT_SLOT =
"addPoint";
39 static const ::fwCom::Slots::SlotKeyType s_UPDATE_SPLINE_SLOT =
"updateSpline";
41 const ::fwServices::IService::KeyType SPointList::s_POINTLIST_INPUT =
"pointList";
45 SPointList::SPointList() noexcept :
49 newSlot(s_ADD_POINT_SLOT, &SPointList::addPoint,
this);
50 newSlot(s_UPDATE_SPLINE_SLOT, &SPointList::updateSpline,
this);
52 m_ptColor = ::fwData::Color::New();
57 SPointList::~SPointList() noexcept
66 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
68 const std::string hexaColor = config.get<std::string>(
"color",
"");
69 m_ptColor = ::fwData::Color::New();
70 if (!hexaColor.empty())
72 m_ptColor->setRGBA(hexaColor);
75 const std::string radius = config.get<std::string>(
"radius",
"");
78 m_radius = std::stod(radius);
81 const std::string interaction = config.get<std::string>(
"interaction",
"");
83 if (!interaction.empty())
85 SLM_FATAL_IF(
"value for 'interaction' must be 'on' or 'off', actual: " + interaction,
86 interaction !=
"on" && interaction !=
"off");
88 m_interaction = (interaction ==
"on");
98 m_oldWeakPointList.clear();
100 m_weakPointList = this->getWeakPointList();
109 WeakPointListType points = this->getNewPoints();
110 this->createServices( points );
116 void SPointList::addPoint(::fwData::Point::sptr )
118 m_oldWeakPointList = m_weakPointList;
119 m_weakPointList = this->getWeakPointList();
126 void SPointList::updateSpline()
137 m_oldWeakPointList.clear();
138 m_weakPointList.clear();
144 void SPointList::createServices(WeakPointListType& wPtList)
146 for( ::fwData::Point::wptr wpt : wPtList )
150 ::fwData::Point::sptr pt = wpt.lock();
153 auto pointAdaptor = this->registerService< ::visuVTKAdaptor::SPoint >(
"::visuVTKAdaptor::SPoint");
154 pointAdaptor->registerInOut(pt, SPoint::s_POINT_INOUT,
true);
156 SLM_ASSERT(
"Bad cast of IAdaptor to Point", pointAdaptor);
161 pointAdaptor->start();
163 pointAdaptor->setColor(m_ptColor->red(), m_ptColor->green(), m_ptColor->blue(), m_ptColor->alpha());
164 pointAdaptor->setRadius(m_radius);
165 pointAdaptor->setInteraction(m_interaction);
171 SPointList::WeakPointListType SPointList::getWeakPointList()
173 ::fwData::PointList::csptr ptList = this->getInput< ::fwData::PointList >(s_POINTLIST_INPUT);
174 SLM_ASSERT(
"'pointList' is not defined.", ptList);
176 WeakPointListType weakList;
178 std::copy(ptList->getPoints().begin(), ptList->getPoints().end(), std::back_inserter(weakList));
185 SPointList::WeakPointListType SPointList::getNewPoints()
187 WeakPointListType newPoints;
190 for(::fwData::Point::wptr
point : m_weakPointList)
193 for(::fwData::Point::wptr oldPoint : m_oldWeakPointList)
195 isFound = (
point.lock() == oldPoint.lock());
203 newPoints.push_back(
point);
222 void SPointList::setRadius(
const double radius)
229 void SPointList::setColor(
const fwData::Color::sptr ptColor)
236 void SPointList::setInteraction(
const bool interaction)
238 m_interaction = interaction;
Adaptor to display a point list.
This class is a helper to define the connections of a service and its data.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
FWRENDERVTK_API void requestRender()
notify a render request iff vtkPipeline is modified
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 void setVtkPipelineModified()
End-user have to call this method when a vtk structure has been modified, thus a render request will ...
FWRENDERVTK_API SRender::sptr getRenderService() const
Returd the associated render service.
FWRENDERVTK_API SRender::PickerIdType getPickerId() const
Gets the identifier of the picker used by this adaptor.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_ADDED_SIG
Signal emitted when a Point is added.
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
FWSERVICES_API void unregisterServices(const std::string &_implType="")
Unregister all services linked to this service, optionally matches only a given type of services...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
#define SLM_FATAL_IF(message, cond)
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
FWRENDERVTK_API SRender::RendererIdType getRendererId() const
Returns the renderer identifier.
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
Base class for VTK adaptors.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.