Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Geometry.h 15.1 KB
Newer Older
1
/*****************************************************************************
2
3
4
 * $CAMITK_LICENCE_BEGIN$
 *
 * CamiTK - Computer Assisted Medical Intervention ToolKit
5
 * (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * Visit http://camitk.imag.fr for more information
 *
 * This file is part of CamiTK.
 *
 * CamiTK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * CamiTK is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with CamiTK.  If not, see <http://www.gnu.org/licenses/>.
 *
 * $CAMITK_LICENCE_END$
 ****************************************************************************/
25
26
27
28
29
30
31
32

#ifndef GEOMETRY_H
#define GEOMETRY_H

// -- Core stuff
#include "CamiTKAPI.h"
#include "InterfaceGeometry.h"

33
34
#include <QMap>

35
36
37
38
39
//-- VTK Classes
class vtkPointSet;
class vtkAlgorithmOutput;
class vtkDataSetMapper;
class vtkActor;
40
class vtkProp;
41
42
43
44
45
46
class vtkTexture;
class vtkGlyph3D;
class vtkTransform;
class vtkTubeFilter;
class vtkCastToConcrete;
class vtkTextMapper;
47
class vtkSphereSource;
48
class vtkTransformFilter;
49

50
namespace camitk {
51
/**
52
 * @ingroup group_sdk_libraries_core_component
53
54
 *
 * @brief
55
56
57
58
59
60
61
62
63
64
65
66
 * A 3D representation of a vtkPointSet to be displayed in a InteractiveViewer,
 * this class implements the InterfaceGeometry.
 *
 * A Geometry is build out of a vtkPointSet. A single vtkDataSetMapper is created,
 * with several associated vtkActors. Each actor has specific rendering properties:
 * representation mode, color, ...
 *
 * Available actors are: surface, wireframe and points.
 *
 * An actor is visible or not according to the options of the RenderingModes associated to the Geometry
 * as well as the highlight mode (from hidden to highlighted).
 *
67
 * \note when the Geometry is instantiated the Geometry TAKES CONTROL of the given
68
69
70
71
72
73
74
75
76
 * vtkPointSet (hence, if you then delete the instance, the vtkDataSet will be deleted as well).
 *
 * This class is used as a delegate by Component (who delegates all the InterfaceGeometry
 * service implementation to Geometry),
 * according to the Object Adapter Design Pattern (Component is the adaptor, Geometry is the adaptee
 * concerning the InterfaceGeometry service).
 *
 * If you need to add your own vtk filter/algorithm pipeline to pre-process the data, you
 * need to write something like this:
77
 * \code
78
79
80
81
82
 *    vtkSomeAlgorithm *startFilter = vtkSomeAlgorithm::New();
 *    startFilter->SetInputConnection(theAbstractGeometry->getDataPort());
 *    ...
 *    ...
 *    theAbstractGeometry->setDataConnection(endFilter->GetOutputPort());
83
 * \endcode
84
85
86
87
88
 *
 *
 *  The complete Vtk Pipeline looks like this:
 *
 * \verbatim
89
90
 *                                                                                  +-----> getDataPort()
 *  +----------------+     +------------------+      +---------------------------+ /
91
 *  |  vtkPointSet   |     |vtkCastToConcrete |      |vtkTransformPolyDataFilter |/
92
93
94
 *  |                |----\|                  |----\ |                           |----\ your custom  ----\ ...
 *  |   pointSet     |----/|  concreteData    |----/ |    data in world frame    |----/  pipeline    ----/
 *  +----------------+     +------------------+      +--------------------------+|
95
96
97
98
99
 *     ^           |                                                      |
 *     |           |                                                      |
 * setPointSet()   |                                                      |
 *                 |                                                      |
 *                 v                                                      v
100
 *          getPointSet()                                       getPointSetWorldCoords()
101
102
103
104
 *
 *
 * setDataConnection(..)
 *      |
105
106
107
108
109
110
111
112
113
114
115
116
117
118
 *      |  +---OPTIONAL---+       +------------------+
 *      +->| vtkTubeFilter|       | vtkDataSetMapper |
 *... ----\|              |-----\ |                  |
 *    ----/|     tube     |-----/ |     mapper       |
 *         +--------------+       +------------------+
 *                ^                     |
 *                |                     V
 *         setLinesAsTube()        +------------------+
 *                                 |     3 actors:    |
 *                                 |   surfaceActor   |
 *                                 | wireframeActor   |
 *                                 |    pointsActor   |
 *                                 |                  |
 *                                 +------------------+
119
120
 *
 * \endverbatim
121
122
 * The other vtk (minor) ingredients not mentionned are specific vtkProp (actors, volumes and annotations)
 * By default two props are defined: label and glyph.
123
 * They can be accessed by getProp("label") and getProp("glyph").
124
 * You can also add your own additional custom props by using addProp(QString, vtkProp) and setPropVisible(QString, bool).
125
126
127
 */
class CAMITK_API Geometry : public InterfaceGeometry {

128
public:
129
    /** instantiate a Geometry using existing stuff.
130
     * \note when the Geometry is instantiated like this,
131
132
133
134
     * the object takes CONTROL of the vtkDataSet (hence, if you then delete this instance,
     * the vtkDataSet will be deleted as well).
     * dataSet thus becomes owned by the Geometry and will be deleted when necessary,
     * so do not pass the address of an object on the stack.
135
     *
136
     * @param label name to display on the label
137
     * @param pointSet the vtkDataSet to take as the vtk object to display
138
139
140
141
142
     * @param mode the default rendering mode
     */
    Geometry(QString label, vtkSmartPointer<vtkPointSet> pointSet, const InterfaceGeometry::RenderingModes mode = InterfaceGeometry::Surface);

    /// destructor
Emmanuel Promayon's avatar
Emmanuel Promayon committed
143
    ~Geometry() override;
144

145
    /// get the label of this Geometry instance
Emmanuel Promayon's avatar
Emmanuel Promayon committed
146
    const QString getLabel() const {
147
        return label;
148
    }
149

150
    /// set the label of this Geometry instance
Emmanuel Promayon's avatar
Emmanuel Promayon committed
151
    void setLabel(QString newName) {
152
153
        label = newName;
        updateLabel();
154
    }
155

156
157
158
159
160
161
    /**
      * @name InterfaceGeometry Vtk related inherited methods
      * All the implemented InterfaceGeometry methods (Geometry is the adaptee of Component)
      */
    ///@{
    /// Return the dataset associated to this object.
Emmanuel Promayon's avatar
Emmanuel Promayon committed
162
    vtkSmartPointer<vtkPointSet> getPointSet() {
163
        return pointSet;
164
165
    }

166
    /// set the input data of the Geometry, \note if there is already a vtkPointSet, this method calls DeepCopy(ds)
Emmanuel Promayon's avatar
Emmanuel Promayon committed
167
    void setPointSet(vtkSmartPointer<vtkPointSet> ds) override;
168

169
    /// Set the world transform (if the Geometry depends on another Frame)
Emmanuel Promayon's avatar
Emmanuel Promayon committed
170
    void setMeshWorldTransform(vtkSmartPointer<vtkTransform>) override;
171

172
    /// get the custom algorithm pipeline input.
Emmanuel Promayon's avatar
Emmanuel Promayon committed
173
    vtkSmartPointer<vtkAlgorithmOutput> getDataPort() const {
174
        return dataOutput;
175
176
177
    }

    /// call this method with the custom algorithm pipeline output
Emmanuel Promayon's avatar
Emmanuel Promayon committed
178
    void setDataConnection(vtkSmartPointer<vtkAlgorithmOutput>) override;
179
180

    /// set the point data (may contains a lookup table)
Emmanuel Promayon's avatar
Emmanuel Promayon committed
181
    void setPointData(vtkSmartPointer<vtkDataArray>) override;
182
183
184
185
186

    /** Return the actor representing this representation mode (return NULL if hightlight mode is Hidden).
      * If RenderingModes have a more than one possible representation, it returns in
      * priority order: the surface, wireframe or points representation.
      */
Emmanuel Promayon's avatar
Emmanuel Promayon committed
187
    vtkSmartPointer<vtkActor> getActor(const RenderingModes) override;
188

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
    /** Set a texture to this object. */
    void setTexture(vtkSmartPointer<vtkTexture> texture) override;

    /// a vtkPoint of the structured was picked (to be reimplemented in a Component inherited class if needed)
    void pointPicked(vtkIdType, bool) {};

    /// a vtkCell of the structured was picked (to be reimplemented in a Component inherited class if needed)
    void cellPicked(vtkIdType, bool) {};

    ///@}

    /// @name manage extra prop associated with a Geometry
    /// @{
    /// TODO 
    /// - put all this management into a dedicated interface 
    /// - remove it from InterfaceBitMap and InterfaceGeometry
    /// - remove it from Slice and Geometry helper classes
    /// - create a new associated helper class
    /// - update Component class and all other code using it (if needed)
    /// Note : beware that Geometry requires this to manage to at least "label" and "glyph" extra actors

210
    /// Return the vtkProp (actors, volumes and annotations) corresponding to the given name
Emmanuel Promayon's avatar
Emmanuel Promayon committed
211
    vtkSmartPointer<vtkProp> getProp(const QString&) override;
212
213

    /// return the number of additional prop
Emmanuel Promayon's avatar
Emmanuel Promayon committed
214
    unsigned int getNumberOfProp() const override;
215
216

    /// return an additional prop by its index
Emmanuel Promayon's avatar
Emmanuel Promayon committed
217
    vtkSmartPointer<vtkProp> getProp(unsigned int) override;
218
219
220
221

    /** insert an additional prop, defining it by its name (default visibility = false)
     *  @return true if the additional prop was added (i.e. another additional prop of the same name does not exist)
     */
Emmanuel Promayon's avatar
Emmanuel Promayon committed
222
    bool addProp(const QString&,  vtkSmartPointer<vtkProp>) override;
223

224
225
226
    /** remove a given additional prop.
     * @return true if effictively done
     */
Emmanuel Promayon's avatar
Emmanuel Promayon committed
227
    bool removeProp(const QString&) override;
228
229
    /// @}
    
230
231
232
233
    /// @name InterfaceGeometry Helpers inherited methods
    /// @{

    /// compute the object's bounding box [xmin,xmax, ymin,ymax, zmin,zmax]
Emmanuel Promayon's avatar
Emmanuel Promayon committed
234
    void getBounds(double* bounds) override;
235
236

    /// compute the object's bounding sphere radius
Emmanuel Promayon's avatar
Emmanuel Promayon committed
237
    double getBoundingRadius() override;
238
239

    /// set a given point position
Emmanuel Promayon's avatar
Emmanuel Promayon committed
240
    void setPointPosition(const unsigned int orderNumber, const double x, const double y, const double z) override;
241
242
243
244
245
246
247
248

    ///@}


    /// @name InterfaceGeometry rendering mode settings inherited methods
    /// @{

    /// Set the actor associated to a rendering mode visible or not.
Emmanuel Promayon's avatar
Emmanuel Promayon committed
249
    void setRenderingModes(const RenderingModes rMode) {
250
251
        renderingModes = rMode;
    }
252
253

    /// Return if the actor associated to a rendering mode is currently visible or not.
Emmanuel Promayon's avatar
Emmanuel Promayon committed
254
    const RenderingModes getRenderingModes() const {
255
256
        return renderingModes;
    }
257
258

    /// set the enhanced mode
259
    void setEnhancedModes(const EnhancedModes) override;
260
261

    /// get the current enhanced mode
Emmanuel Promayon's avatar
Emmanuel Promayon committed
262
    const EnhancedModes getEnhancedModes() const {
263
264
        return enhancedModes;
    }
265
266

    /// Set the color of given representation modes.
Emmanuel Promayon's avatar
Emmanuel Promayon committed
267
    void setActorColor(const RenderingModes, double*) override;
268
269

    /// Set the color of given representation modes.
Emmanuel Promayon's avatar
Emmanuel Promayon committed
270
    void setActorColor(const RenderingModes, const double, const double, const double) override;
271
272

    /// Get the color of given representation modes in the second parameter, i.e. double[4] (r,g,b,a)
Emmanuel Promayon's avatar
Emmanuel Promayon committed
273
    void getActorColor(const RenderingModes, double*) override;
274
275

    /// Set an (r,g,b) color to all representation modes, without changing the opacity.
Emmanuel Promayon's avatar
Emmanuel Promayon committed
276
    void setColor(const double, const double, const double) override;
277
278

    /// Set an (r,g,b,a) color to all representation modes.
Emmanuel Promayon's avatar
Emmanuel Promayon committed
279
    void setColor(const double, const double, const double, const double) override;
280
281

    /// Set the opacity of this representation modes. WARNING color field (surfaceColor, ...) are not modified!
Emmanuel Promayon's avatar
Emmanuel Promayon committed
282
    void setActorOpacity(const RenderingModes, const double) override;
283
284

    /// Return the opacity of a given renderng mode.
Emmanuel Promayon's avatar
Emmanuel Promayon committed
285
    double getActorOpacity(const RenderingModes) const override;
286
287

    /// Set the opacity of this object. WARNING color field (surfaceColor, ...) are not modified!
Emmanuel Promayon's avatar
Emmanuel Promayon committed
288
    void setOpacity(const double) override;
289
290

    /// Set the mapper scalar range
Emmanuel Promayon's avatar
Emmanuel Promayon committed
291
    void setMapperScalarRange(double min, double max) override;
292

293
    /// set the glyph information
Emmanuel Promayon's avatar
Emmanuel Promayon committed
294
    void setGlyphType(const GlyphTypes type, const double size = 0.0) override;
295
296

    /// display lines as tubes (depeding of the boolean) (<b>only work if the Geometry was defined using a vtkPolyData</b>).
Emmanuel Promayon's avatar
Emmanuel Promayon committed
297
    void setLinesAsTubes(bool tubes = false) override;
298
299
300
301

    ///@}


302
private:
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320

    /** @name VTK members (data, filters, actors, etc...)
     */
    ///@{
    /// The low-level VTK data
    vtkSmartPointer<vtkPointSet> pointSet;

    /// to be able to set external custom pipeline
    vtkSmartPointer<vtkAlgorithmOutput> dataOutput;

    /// the external custom pipeline output (equals to dataOuput if no custom pipeline plugged)
    vtkSmartPointer<vtkAlgorithmOutput> customPipelineOutput;

    /// the filter to convert the DataSet to get a correct vtkPipeline output port
    vtkSmartPointer<vtkCastToConcrete> concreteData;

    /// the VTK mapper
    vtkSmartPointer<vtkDataSetMapper> mapper;
321
    
322
323
    /// the mapper to create the text
    vtkSmartPointer<vtkTextMapper> labelActorMapper;
324

325
326
327
328
329
330
331
332
333
334
335
336
337
338
    /// the surface actor that manages the surfacic representation
    vtkSmartPointer<vtkActor> surfaceActor;

    /// the wireframe actor that manages the representation as wireframe
    vtkSmartPointer<vtkActor> wireframeActor;

    /// the point actor that manages the representation as a set of points
    vtkSmartPointer<vtkActor> pointsActor;

    /** texture of this object. */
    vtkSmartPointer<vtkTexture> texture;

    /// the tube filter (creates tubes insead of lines)
    vtkSmartPointer<vtkTubeFilter> tube;
339

340
341
    /// the transform filter to place the mesh correctly with respect to its Frame
    vtkSmartPointer<vtkTransformFilter> worldTransformFilter;
342

343
344
    /// the sphere glyph
    vtkSmartPointer<vtkSphereSource> sphereGeom;
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
    ///@}

    /// @name Other members
    ///@{
    /// Rendering mode options for this Geometry (which actors are visible/rendered)
    InterfaceGeometry::RenderingModes renderingModes;

    /// Enhanced mode options (the way actors are rendered: normal, hidden, highlighted, shaded)
    InterfaceGeometry::EnhancedModes enhancedModes;

    /// Opacity value when this object must be shaded.
    double alphaShaded;

    /// the label
    QString label;
360
361
362

    /// current size of glyph (0.0 means no glyph)
    double glyphSize;
363
364
365
366
367
368
369
370
371

    /// build the label extra prop
    void buildLabel();

    /// update position and text of the label
    void updateLabel();

    /// build the glyph extra prop (sphere glyph by default)
    void buildGlyph(const GlyphTypes type);
372

373
374
375
376
377
378
    /** force visualization of point cloud
      * If the point set does only contains a point cloud, i.e., there is no cell to visualize the points,
      * this method will add a default poly vertex cell that will enable default visualization.
      * Caveat: if the user save this component, this cell might be saved as well.
      */
    void createPointCloudVisualization();
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
    ///@}

    /** @name actor colors
     * All Colors are decribed using r, g, b, alpha (Alpha is opacity 0 = transparent, 1 = opaque)
     */
    ///@{
    double surfaceColor[4];
    double wireframeColor[4];
    double pointsColor[4];
    ///@}

    /// @name Backup states
    ///@{
    double oldAlphaSurface;
    double oldAlphaWireframe;
    double oldAlphaPoints;
    double oldPointsColor[4];
    ///@}
397
398
399
400
401
402
403
404
405
    
    /// @name manage extra prop associated with a Geometry
    /// @{
    /// TODO see extra prop management method section

    /// The additional map for prop (include at least "label" and "glyph")
    QMap<QString, vtkSmartPointer<vtkProp> > extraProp;
    ///@}

406
407
408
409
410
411
412
};



}

#endif