7 #include "visuVTKAdaptor/SMeshNormals.hpp" 9 #include <fwCom/Slot.hpp> 10 #include <fwCom/Slot.hxx> 11 #include <fwCom/Slots.hpp> 12 #include <fwCom/Slots.hxx> 14 #include <fwData/Mesh.hpp> 16 #include <fwServices/macros.hpp> 18 #include <fwVtkIO/helper/Mesh.hpp> 20 #include <boost/assign/list_of.hpp> 23 #include <vtkArrowSource.h> 24 #include <vtkCellCenters.h> 25 #include <vtkGlyph3D.h> 26 #include <vtkGlyphSource2D.h> 27 #include <vtkMaskPoints.h> 28 #include <vtkPolyDataMapper.h> 29 #include <vtkProperty.h> 36 const ::fwServices::IService::KeyType SMeshNormals::s_MESH_INPUT =
"mesh";
40 std::map< std::string, SMeshNormals::NormalRepresentation >
41 SMeshNormals::m_normalRepresentationConversion
42 = ::boost::assign::map_list_of(std::string(
"POINT"), POINT_NORMAL)
43 (std::string(
"CELL"), CELL_NORMAL)
44 (std::string(
"NONE"), NONE);
58 SMeshNormals::SMeshNormals() noexcept :
59 m_normalRepresentation(CELL_NORMAL)
61 m_actor = vtkActor::New();
74 SMeshNormals::~SMeshNormals() noexcept
86 const ConfigType config = this->
getConfigTree().get_child(
"config.<xmlattr>");
88 if(config.count(
"normal") )
90 const std::string normal = config.get<std::string>(
"normal");
91 SLM_ASSERT(
"Wrong normal representation '" + normal +
"' (required POINT, CELL or NONE)",
92 m_normalRepresentationConversion.find(normal) != m_normalRepresentationConversion.end());
94 m_normalRepresentation = m_normalRepresentationConversion[normal];
112 this->updateMeshNormals();
118 vtkActor* SMeshNormals::getActor()
const 125 void SMeshNormals::setPolyData(vtkSmartPointer< vtkPolyData > polydata)
129 m_polyData = polydata;
135 void SMeshNormals::updateMeshNormals()
137 ::fwData::Mesh::csptr mesh = this->getInput< ::fwData::Mesh >(s_MESH_INPUT);
140 if(m_normalRepresentation == NONE)
142 m_actor->SetVisibility(
false );
146 m_polyData = vtkSmartPointer< vtkPolyData >::New();
149 vtkSmartPointer<vtkPolyDataAlgorithm> algo;
150 if(m_normalRepresentation == CELL_NORMAL)
152 algo = vtkSmartPointer<vtkCellCenters>::New();
154 else if(m_normalRepresentation == POINT_NORMAL)
156 vtkSmartPointer<vtkMaskPoints> ptMask = vtkSmartPointer<vtkMaskPoints>::New();
157 ptMask->SetOnRatio(1);
158 ptMask->RandomModeOn();
159 ptMask->SetMaximumNumberOfPoints(static_cast<vtkIdType>(mesh->getNumberOfPoints()));
163 algo->SetInputData(m_polyData);
165 vtkSmartPointer<vtkGlyphSource2D> arrow = vtkSmartPointer<vtkGlyphSource2D>::New();
166 arrow->SetGlyphTypeToArrow();
169 vtkSmartPointer<vtkGlyph3D> glyph = vtkSmartPointer<vtkGlyph3D>::New();
170 glyph->SetInputConnection(algo->GetOutputPort());
171 glyph->SetSourceConnection(arrow->GetOutputPort());
172 glyph->SetVectorModeToUseNormal();
173 glyph->SetScaleModeToScaleByVector();
174 glyph->SetScaleFactor(10.0);
176 vtkSmartPointer<vtkPolyDataMapper> glyphMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
177 glyphMapper->SetInputConnection(glyph->GetOutputPort());
179 m_actor->SetVisibility(
true );
180 this->getActor()->SetMapper(glyphMapper);
181 this->getActor()->GetProperty()->SetColor(1., 1., 1.);
212 ::fwData::Mesh::csptr mesh = this->getInput< ::fwData::Mesh >(s_MESH_INPUT);
225 ::fwData::Mesh::csptr mesh = this->getInput< ::fwData::Mesh >(s_MESH_INPUT);
236 ::fwData::Mesh::csptr mesh = this->getInput< ::fwData::Mesh >(s_MESH_INPUT);
247 m_normalRepresentation = POINT_NORMAL;
248 this->updateMeshNormals();
255 m_normalRepresentation = CELL_NORMAL;
256 this->updateMeshNormals();
263 m_normalRepresentation = NONE;
264 this->updateMeshNormals();
290 OSLM_ERROR(
"mode " << mode <<
" is not allowed");
This class is a helper to define the connections of a service and its data.
This adaptor displays mesh normals.
FWRENDERVTK_API void addToRenderer(vtkProp *prop)
Adds the vtkProp to the renderer.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_NORMALS_MODIFIED_SIG
Key in m_signals map of signal m_sigPointNormalsModified.
void updateNormalMode(std::uint8_t mode)
Slot: used to update normal mode (0: none, 1: point, 2: cell)
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
static FWVTKIO_API void toVTKMesh(const ::fwData::Mesh::csptr &_mesh, vtkSmartPointer< vtkPolyData > _polyData)
Convert a ::fwData::Mesh::csptr to a vtkPolyData.
void updatePointNormals()
Slot: used to update point normals.
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
static FWVTKIO_API void updatePolyDataPoints(vtkSmartPointer< vtkPolyData > polyDataDst, const ::fwData::Mesh::csptr &meshSrc)
Update a vtkPolyData with ::fwData::Mesh::sptr points.
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 void removeAllPropFromRenderer()
Removes all the vtkProp from the renderer.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CELL_NORMALS_MODIFIED_SIG
Key in m_signals map of signal m_sigCellNormalsModified.
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_CELL_NORMALS_SLOT
normal mode (0: none, 1: point, 2: cell)
void updateCellNormals()
Slot: used to update cell normals.
void showPointNormals()
Slot: used to show point normals.
#define OSLM_ERROR(message)
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_NORMAL_MODE_SLOT
normal mode (0: none, 1: point, 2: cell)
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_HIDE_NORMALS_SLOT
normal mode (0: none, 1: point, 2: cell)
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
static FWVTKIO_API void updatePolyDataCellNormals(vtkSmartPointer< vtkPolyData > polyDataDst, const ::fwData::Mesh::csptr &meshSrc)
Update a vtkPolyData with cell normals of fwData::Mesh.
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_SHOW_CELL_NORMALS_SLOT
normal mode (0: none, 1: point, 2: cell)
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_VERTEX_SLOT
normal mode (0: none, 1: point, 2: cell)
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
void showCellNormals()
Slot: used to show cell normals.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_VERTEX_MODIFIED_SIG
Key in m_signals map of signal m_sigVertexModified.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
void updateVertex()
Slot: used to update mesh vertex.
static FWVTKIO_API void updatePolyDataPointNormals(vtkSmartPointer< vtkPolyData > polyDataDst, const ::fwData::Mesh::csptr &meshSrc)
Update a vtkPolyData with point normals of fwData::Mesh.
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_POINT_NORMALS_SLOT
normal mode (0: none, 1: point, 2: cell)
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
void hideNormals()
Slot: used to hide normals.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
static VISUVTKADAPTOR_APIconst::fwCom::Slots::SlotKeyType s_SHOW_POINT_NORMALS_SLOT
normal mode (0: none, 1: point, 2: cell)
Base class for VTK adaptors.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.