9 #include "visuVTKAdaptor/SPlane.hpp" 11 #include "visuVTKAdaptor/SPoint.hpp" 13 #include <fwCom/Signal.hpp> 14 #include <fwCom/Signal.hxx> 15 #include <fwCom/Slot.hpp> 16 #include <fwCom/Slot.hxx> 17 #include <fwCom/Slots.hpp> 18 #include <fwCom/Slots.hxx> 20 #include <fwData/Color.hpp> 21 #include <fwData/Plane.hpp> 23 #include <fwMath/IntrasecTypes.hpp> 24 #include <fwMath/PlaneFunctions.hpp> 26 #include <fwRenderVTK/vtk/Helpers.hpp> 27 #include <fwRenderVTK/vtk/MarkedSphereHandleRepresentation.hpp> 29 #include <fwServices/macros.hpp> 30 #include <fwServices/op/Add.hpp> 33 #include <vtkPlaneCollection.h> 34 #include <vtkPolyDataMapper.h> 35 #include <vtkPropCollection.h> 36 #include <vtkProperty.h> 37 #include <vtkRenderer.h> 38 #include <vtkRenderWindowInteractor.h> 45 static const ::fwCom::Slots::SlotKeyType s_UPDATE_POINTS_SLOT =
"updatePoints";
46 static const ::fwCom::Slots::SlotKeyType s_START_INTERACTION_SLOT =
"startInteraction";
47 static const ::fwCom::Slots::SlotKeyType s_SELECT_PLANE_SLOT =
"selectPlane";
51 const ::fwServices::IService::KeyType SPlane::s_PLANE_INOUT =
"plane";
55 SPlane::SPlane() noexcept :
58 m_vtkImplicitPlane(
nullptr),
59 m_vtkPlaneCollection(
nullptr)
70 SPlane::~SPlane() noexcept
80 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
82 m_planeCollectionId = config.get(
"planecollection",
"");
91 ::fwData::Plane::csptr plane = this->getInOut< ::fwData::Plane >(s_PLANE_INOUT);
94 for( const ::fwData::Point::sptr&
point : plane->getPoints() )
97 auto servicePoint = this->registerService< ::fwRenderVTK::IAdaptor >(
"::visuVTKAdaptor::SPoint");
98 servicePoint->registerInOut(
point, SPoint::s_POINT_INOUT,
true);
103 servicePoint->start();
107 this->getSptr(), s_START_INTERACTION_SLOT);
110 if (!m_planeCollectionId.empty())
112 m_vtkPlaneCollection = vtkPlaneCollection::SafeDownCast(this->
getVtkObject(m_planeCollectionId));
115 if (m_vtkPlaneCollection)
117 m_vtkImplicitPlane = vtkPlane::New();
118 m_vtkPlaneCollection->AddItem(m_vtkImplicitPlane);
129 ::fwData::Plane::csptr plane = this->getInOut< ::fwData::Plane >(s_PLANE_INOUT);
132 ::fwData::Point::csptr pt0 = plane->getPoints()[0];
133 ::fwData::Point::csptr pt1 = plane->getPoints()[1];
134 ::fwData::Point::csptr pt2 = plane->getPoints()[2];
137 ::fwMath::setValues(planeDesc, pt0->getCoord(), pt1->getCoord(), pt2->getCoord());
139 if(m_vtkImplicitPlane)
141 fwVec3d normal = ::fwMath::getNormal(planeDesc);
143 m_vtkImplicitPlane->SetOrigin(pt0->getCoord()[0], pt0->getCoord()[1], pt0->getCoord()[2]);
144 m_vtkImplicitPlane->SetNormal(normal[0], normal[1], normal[2]);
145 m_vtkImplicitPlane->Modified();
157 ::fwData::Plane::csptr plane = this->getInOut< ::fwData::Plane >(s_PLANE_INOUT);
171 ::fwData::Plane::sptr plane = this->getInOut< ::fwData::Plane >(s_PLANE_INOUT);
177 sig->asyncEmit(plane);
184 if (m_vtkPlaneCollection && m_vtkImplicitPlane)
186 m_vtkPlaneCollection->RemoveItem(m_vtkImplicitPlane);
187 m_vtkImplicitPlane->Delete();
188 m_vtkImplicitPlane = 0;
200 void SPlane::setVtkPlaneCollection( vtkObject* col )
202 if (m_vtkPlaneCollection != col)
204 if (m_vtkPlaneCollection)
206 if (m_vtkImplicitPlane)
208 m_vtkPlaneCollection->RemoveItem(m_vtkImplicitPlane);
210 m_vtkPlaneCollection = 0;
215 m_vtkPlaneCollection = vtkPlaneCollection::SafeDownCast(col);
216 if (m_vtkImplicitPlane)
218 m_vtkPlaneCollection->AddItem(m_vtkImplicitPlane);
231 for (const ::fwServices::IService::wptr& adaptor: subServices)
233 auto servicePoint = ::visuVTKAdaptor::SPoint::dynamicCast(adaptor.lock());
238 servicePoint->setColor(1., 0., 0.);
242 servicePoint->setColor(1., 1., 1.);
This class is a helper to define the connections of a service and its data.
FWRENDERVTK_API vtkObject * getVtkObject(const SRender::VtkObjectIdType &objectId) const
Returns the vtk object defined by 'objectId' in the vtk scene.
FWCOM_API void disconnect()
Disconnect all registered connections and clear m_connections.
This class defines a plane defined by tree points.
Class allowing to block a Connection.
void startInteraction()
Re-notify "startInteraction" for this service.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
void updatePoints()
Update the plane from the points and notify planes is modified.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
static VISUVTKADAPTOR_APIconst::fwCom::Signals::SignalKeyType s_INTERACTION_STARTED_SIG
Type of signal when point interaction is started.
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
static VISUVTKADAPTOR_APIconst::fwCom::Signals::SignalKeyType s_INTERACTION_STARTED_SIG
Type of signal when plane interaction is started (store current plane)
const ServiceVector & getRegisteredServices() const
Get all subservices linked to this service.
FWRENDERVTK_API void requestRender()
notify a render request iff vtkPipeline is modified
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.
FWRENDERVTK_API void removeAllPropFromRenderer()
Removes all the vtkProp from the renderer.
void selectPlane(bool select)
Changes points color (red is selected, else white)
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
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) ...
Represents a Plane that can be interacted with 3 points.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
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).
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_SELECTED_SIG
Signal emitted when plane is selected/deselected.
FWCOM_API void connect(const ::fwCom::HasSignals::csptr &hasSignals,::fwCom::Signals::SignalKeyType signalKey, const ::fwCom::HasSlots::csptr &hasSlots,::fwCom::Slots::SlotKeyType slotKey)
Connect signal to slot, and register this new connection in m_connections.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Base class for VTK adaptors.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.