7 #include "visuVTKAdaptor/SReconstruction.hpp" 9 #include "visuVTKAdaptor/SMesh.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/Mesh.hpp> 18 #include <fwData/Reconstruction.hpp> 20 #include <fwServices/macros.hpp> 21 #include <fwServices/op/Add.hpp> 23 #include <fwTools/fwID.hpp> 26 #include <vtkCamera.h> 28 #include <vtkMatrix4x4.h> 29 #include <vtkPicker.h> 30 #include <vtkPlaneCollection.h> 31 #include <vtkPolyDataMapper.h> 32 #include <vtkPolyDataNormals.h> 33 #include <vtkProperty.h> 34 #include <vtkRenderer.h> 35 #include <vtkRenderWindowInteractor.h> 36 #include <vtkTransform.h> 46 const ::fwServices::IService::KeyType SReconstruction::s_RECONSTRUCTION_INPUT =
"reconstruction";
49 SReconstruction::SReconstruction() noexcept :
50 m_autoResetCamera(true)
58 SReconstruction::~SReconstruction() noexcept
68 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
70 const std::string autoresetcamera = config.get<std::string>(
"autoresetcamera",
"yes");
71 SLM_ASSERT(
"'autoresetcamera' value must be 'yes' or 'no', actual: " + autoresetcamera,
72 autoresetcamera ==
"yes" || autoresetcamera ==
"no");
73 m_autoResetCamera = (autoresetcamera ==
"yes");
81 this->createMeshService();
87 void SReconstruction::createMeshService()
89 auto reconstruction = this->getInput < ::fwData::Reconstruction >(s_RECONSTRUCTION_INPUT);
90 SLM_ASSERT(
"Missing Reconstruction", reconstruction);
92 ::fwData::Mesh::sptr mesh = reconstruction->getMesh();
98 auto meshAdaptor = this->registerService< ::visuVTKAdaptor::SMesh >(
"::visuVTKAdaptor::SMesh");
99 meshAdaptor->registerInput(mesh, SMesh::s_MESH_INPUT,
true);
106 meshAdaptor->setClippingPlanesId( m_clippingPlanesId);
107 meshAdaptor->setShowClippedPart(
true );
108 meshAdaptor->setMaterial( reconstruction->getMaterial() );
109 meshAdaptor->setAutoResetCamera( m_autoResetCamera );
110 meshAdaptor->start();
111 meshAdaptor->updateVisibility( reconstruction->getIsVisible() );
112 meshAdaptor->update();
114 m_meshService = meshAdaptor;
115 OSLM_TRACE(
"Mesh is visible : "<< reconstruction->getIsVisible());
116 OSLM_TRACE(
"Mesh nb points : "<< mesh->getNumberOfPoints());
124 ::fwRenderVTK::IAdaptor::sptr meshService = m_meshService.lock();
127 auto reconstruction = this->getInput < ::fwData::Reconstruction >(s_RECONSTRUCTION_INPUT);
128 SLM_ASSERT(
"Missing Reconstruction", reconstruction);
129 ::visuVTKAdaptor::SMesh::sptr meshAdaptor = SMesh::dynamicCast(meshService);
131 ::fwData::Mesh::csptr newMesh = reconstruction->getMesh();
132 ::fwData::Mesh::csptr oldMesh = meshAdaptor->getInput<
::fwData::Mesh >(SMesh::s_MESH_INPUT);
133 ::fwData::Material::csptr newMat = reconstruction->getMaterial();
134 ::fwData::Material::csptr oldMat = meshAdaptor->getMaterial();
137 if (newMesh != oldMesh || newMat != oldMat)
140 this->createMeshService();
144 meshAdaptor->updateVisibility( reconstruction->getIsVisible());
145 meshAdaptor->updateOptionsMode();
150 this->createMeshService();
167 void SReconstruction::setForceHide(
bool hide)
169 ::fwData::Reconstruction::csptr reconstruction =
170 this->getInput < ::fwData::Reconstruction >(s_RECONSTRUCTION_INPUT);
171 SLM_ASSERT(
"Missing Reconstruction", reconstruction);
172 this->updateVisibility((hide ?
false : reconstruction->getIsVisible()));
177 void SReconstruction::updateVisibility(
bool visible)
179 if (!m_meshService.expired())
181 ::fwRenderVTK::IAdaptor::sptr meshService = m_meshService.lock();
182 ::visuVTKAdaptor::SMesh::sptr meshAdaptor
183 = SMesh::dynamicCast(meshService);
187 meshAdaptor->updateVisibility( visible );
196 m_autoResetCamera = autoResetCamera;
203 if (!m_meshService.expired())
205 ::visuVTKAdaptor::SMesh::sptr meshAdaptor = ::visuVTKAdaptor::SMesh::dynamicCast(m_meshService.lock());
208 meshAdaptor->updateNormalMode(mode);
This class is a helper to define the connections of a service and its data.
#define SLM_TRACE_IF(message, cond)
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
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.
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
FWSERVICES_API void unregisterService(const ::fwTools::fwID::IDType &_id)
Unregister a specific service.
FWRENDERVTK_API void requestRender()
notify a render request iff vtkPipeline is modified
#define OSLM_TRACE(message)
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.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MESH_CHANGED_SIG
Key in m_signals map of signal m_sigMeshModified.
Displays a Reconstruction.
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) ...
FWRENDERVTK_API SRender::VtkObjectIdType getTransformId() const
Returns the identifier of the transform used by this adaptor.
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_VISIBILITY_SLOT
slot used to update visibility
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_VISIBILITY_MODIFIED_SIG
Key in m_signals map of signal m_sigVisibilityModified.
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_NORMAL_MODE_SLOT
slot used to update normal mode (0: none, 1: point, 2: cell)
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).
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
Data holding a geometric structure composed of points, lines, triangles, quads or polygons...
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
VISUVTKADAPTOR_API void setAutoResetCamera(bool autoResetCamera)
Active/Inactive automatic reset on camera for triangular mesh adaptor. By default =true...
Base class for VTK adaptors.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
void updateNormalMode(std::uint8_t mode)
Slot: used to update normal display(0: none, 1: point, 2: cell)