fw4spl
SMesh.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __VISUVTKADAPTOR_SMESH_HPP__
8 #define __VISUVTKADAPTOR_SMESH_HPP__
9 
10 #include "visuVTKAdaptor/config.hpp"
11 
12 #include <fwCom/Slot.hpp>
13 #include <fwCom/Slots.hpp>
14 
15 #include <fwRenderVTK/IAdaptor.hpp>
16 
17 class vtkCommand;
18 class vtkDepthSortPolyData;
19 class vtkAlgorithm;
20 class vtkAlgorithmOutput;
21 class vtkPolyDataNormals;
22 class vtkPlaneCollection;
23 class vtkActorCollection;
24 class vtkActor;
25 class vtkPolyData;
26 class vtkPolyDataMapper;
27 class vtkTransform;
28 
29 namespace fwData
30 {
31 class Mesh;
32 class Material;
33 }
34 
35 namespace visuVTKAdaptor
36 {
37 
38 class STransform;
39 
40 class VISUVTKADAPTOR_CLASS_API MeshVtkCommand;
41 
88 class VISUVTKADAPTOR_CLASS_API SMesh : public ::fwRenderVTK::IAdaptor
89 {
90 
91 public:
93 
94  VISUVTKADAPTOR_API SMesh() noexcept;
95  VISUVTKADAPTOR_API virtual ~SMesh() noexcept;
96 
97  static const ::fwServices::IService::KeyType s_MESH_INPUT;
98 
103  typedef ::fwCom::Signal< void ( SPTR(::fwData::Material) ) > TextureAppliedSignalType;
104  VISUVTKADAPTOR_API static const ::fwCom::Signals::SignalKeyType s_TEXTURE_APPLIED_SIG;
111  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_UPDATE_VISIBILITY_SLOT;
112  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_UPDATE_POINT_COLORS_SLOT;
113  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_UPDATE_CELL_COLORS_SLOT;
114  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_UPDATE_VERTEX_SLOT;
115  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_UPDATE_POINT_NORMALS_SLOT;
116  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_UPDATE_CELL_NORMALS_SLOT;
117  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_UPDATE_POINT_TEX_COORDS_SLOT;
118  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_UPDATE_CELL_TEX_COORDS_SLOT;
119  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_SHOW_POINT_COLORS_SLOT;
120  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_SHOW_CELL_COLORS_SLOT;
121  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_HIDE_COLORS_SLOT;
122  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_UPDATE_COLOR_MODE_SLOT;
123  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_UPDATE_NORMAL_MODE_SLOT;
124  VISUVTKADAPTOR_API static const ::fwCom::Slots::SlotKeyType s_UPDATE_MATRIX_FIELD_SLOT;
125 
127  VISUVTKADAPTOR_API void updateVisibility ( bool isVisible );
130  VISUVTKADAPTOR_API SPTR(::fwData::Material) getMaterial() const;
131  VISUVTKADAPTOR_API void setMaterial(SPTR(::fwData::Material) material);
132 
133  VISUVTKADAPTOR_API SPTR(::fwData::Material) getUnclippedMaterial() const;
134  VISUVTKADAPTOR_API void setUnclippedPartMaterial(SPTR(::fwData::Material) material);
135 
136  VISUVTKADAPTOR_API void setShowClippedPart ( bool show );
137  VISUVTKADAPTOR_API void setClippingPlanesId( ::fwRenderVTK::SRender::VtkObjectIdType id );
138 
139  VISUVTKADAPTOR_API void setVtkClippingPlanes ( vtkPlaneCollection* planes );
140  VISUVTKADAPTOR_API void setActorPropertyToUnclippedMaterial( bool opt );
141 
143  VISUVTKADAPTOR_API void setAutoResetCamera(bool autoResetCamera);
144 
145  VISUVTKADAPTOR_API bool getVisibility() const;
146 
148  VISUVTKADAPTOR_API void updateOptionsMode();
149 
151  VISUVTKADAPTOR_API void updateNormalMode(std::uint8_t mode);
152 
166  VISUVTKADAPTOR_API virtual KeyConnectionsMap getAutoConnections() const override;
167 
168 protected:
169 
170  VISUVTKADAPTOR_API void configuring() override;
171  VISUVTKADAPTOR_API void starting() override;
172  VISUVTKADAPTOR_API void updating() override;
173  VISUVTKADAPTOR_API void stopping() override;
174 
180  void updatePointColors();
182 
184  void updateCellColors();
185 
187  void updateVertex();
188 
190  void updatePointNormals();
191 
193  void updateCellNormals();
194 
196  void updatePointTexCoords();
197 
199  void updateCellTexCoords();
200 
202  void showPointColors();
203 
205  void showCellColors();
206 
208  void hideColors();
209 
211  void updateColorMode(std::uint8_t mode);
212 
214  void updateMatrixField(::fwData::Object::FieldsContainerType fields);
219  vtkActor* newActor();
220  void buildPipeline();
221 
222  void updateMesh( CSPTR(::fwData::Mesh) mesh );
223 
224  void setServiceOnMaterial(::fwRenderVTK::IAdaptor::sptr &srv,
225  SPTR(::fwData::Material) material);
226 
227  void removeServicesStarterCommand();
228  void createServicesStarterCommand();
229 
230  void createTransformService();
231  void createNormalsService();
232  void removeNormalsService();
233 
234  bool m_showClippedPart;
235  bool m_autoResetCamera;
236 
237  vtkPolyData* m_polyData;
238  vtkPolyDataMapper* m_mapper;
239  vtkActor* m_actor;
240 
241  vtkPlaneCollection* m_clippingPlanes;
242  ::fwRenderVTK::SRender::VtkObjectIdType m_clippingPlanesId;
243 
244  MeshVtkCommand* m_servicesStarterCallback;
245 
246  SPTR(::fwData::Material) m_material;
247  SPTR(::fwData::Material) m_unclippedPartMaterial;
248 
249  ::fwRenderVTK::IAdaptor::wptr m_materialService;
250  ::fwRenderVTK::IAdaptor::wptr m_unclippedPartMaterialService;
251  ::fwRenderVTK::IAdaptor::wptr m_normalsService;
252 
253  vtkTransform* m_transform;
254  WPTR(::visuVTKAdaptor::STransform) m_transformService;
255 
260  {
261  NONE,
262  SPHERE,
263  CYLINDER,
264  PLANE,
265  };
266 
267  UvGenType m_uvgen;
268 
270  TextureAppliedSignalType::sptr m_sigTextureApplied;
271 };
272 
273 } //namespace visuVTKAdaptor
274 
275 #endif // __VISUVTKADAPTOR_SMESH_HPP__
#define SPTR(_cls_)
#define CSPTR(_cls_)
This class is a helper to define the connections of a service and its data.
Definition: IService.hpp:454
TextureAppliedSignalType::sptr m_sigTextureApplied
Signal to emit when a texture must be applied on a material.
Definition: SMesh.hpp:270
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
Namespace containing fw4spl communication tools.
Definition: DumpEditor.hpp:30
#define WPTR(_cls_)
STL namespace.
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
Display a fwData::Mesh in the generic scene.
Definition: SMesh.hpp:88
Adaptor binding a TransformationMatrix3D to a vtkTransform.
Definition: STransform.hpp:44
#define fwCoreServiceClassDefinitionsMacro(_classinfo_)
Generate common code for services classes.
UvGenType
Type for generation of texture coordinates.
Definition: SMesh.hpp:259
The namespace fwRenderVTK contains classes for rendering with VTK.
Contains the representation of the data objects used in the framework.