Developer Documentation
VolumeMeshBufferManager.hh
1/*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40\*===========================================================================*/
41
42#pragma once
43
44#include <ACG/GL/GLState.hh>
45#include <ACG/Scenegraph/DrawModes.hh>
46#include <ACG/Scenegraph/BaseNode.hh>
47#include <ACG/GL/VertexDeclaration.hh>
48
49#include "VolumeMeshDrawModesContainer.hh"
50
51#include <OpenVolumeMesh/Attribs/StatusAttrib.hh>
52#include <OpenVolumeMesh/Attribs/NormalAttrib.hh>
53#include <OpenVolumeMesh/Attribs/ColorAttrib.hh>
54#include <OpenVolumeMesh/Attribs/TexCoordAttrib.hh>
55#include <ACG/Geometry/Types/PlaneType.hh>
56
60template<class VolumeMesh>
62{
63 // typedefs for easy access
70
71 typedef typename VolumeMesh::PointT Vertex;
75
77
78public:
79
80 enum PrimitiveMode
81 {
82 PM_NONE,
83 PM_CELLS,
84 PM_FACES,
85 PM_FACES_ON_CELLS,
86 PM_HALFFACES,
87 PM_HALFFACES_ON_CELLS,
88 PM_EDGES,
89 PM_IRREGULAR_EDGES,
90 PM_EDGES_ON_CELLS,
91 PM_HALFEDGES,
92 PM_VERTICES,
93 PM_VERTICES_ON_CELLS
94 };
95
96 enum NormalMode
97 {
98 NM_NONE,
99 NM_FACE,
100 NM_HALFFACE,
101 NM_VERTEX
102 };
103
104 enum ColorMode
105 {
106 CM_NO_COLORS,
107 CM_CELL,
108 CM_FACE,
109 CM_HALFFACE,
110 CM_EDGE,
111 CM_HALFEDGE,
112 CM_VERTEX,
113 CM_PICK
114 };
115
116 enum TexCoordMode
117 {
118 TCM_NONE,
119 TCM_SINGLE_2D
120 };
121
122 VolumeMeshBufferManager(const VolumeMesh &mesh_, OpenVolumeMesh::StatusAttrib& statusAttrib_,
126 virtual ~VolumeMeshBufferManager(){ free(); }
127
128
130 void setScale(double _scale) { mScale = _scale; invalidate();}
131
133 double getScale() const { return mScale; }
134
135
137 unsigned char getStride() { return mVertexSize; }
138
140 unsigned char getColorOffset() { return mColorOffset; }
141
143 unsigned char getNormalOffset() { return mNormalOffset; }
144
146 unsigned char getTexCoordOffset() { return mTexCoordOffset; }
147
148
150 const ACG::VertexDeclaration* getVertexDeclaration() { return &mVertexDeclaration; }
151
152
154 GLuint getBuffer();
155
157 GLuint getPickBuffer(ACG::GLState &_state, unsigned int _offset);
158
159
161 void invalidate();
162
164 void invalidateGeometry();
165
167 void invalidateColors();
168
170 void invalidateNormals();
171
173 void invalidateTexCoords();
174
175
177 void free();
178
179
181 unsigned int getNumOfVertices();
182
183
185 void setDefaultColor(ACG::Vec4f _defaultColor);
186
187
190
191
193 void disableColors() { mColorMode = CM_NO_COLORS; }
194
196 void enablePerCellColors() { mColorMode = CM_CELL; }
197
199 void enablePerFaceColors() { mColorMode = CM_FACE; }
200
202 void enablePerHalffaceColors() { mColorMode = CM_HALFFACE; }
203
205 void enablePerEdgeColors() { mColorMode = CM_EDGE; }
206
208 void enablePerHalfedgeColors() { mColorMode = CM_HALFEDGE; }
209
211 void enablePerVertexColors() { mColorMode = CM_VERTEX; }
212
214 void enablePickColors() { mColorMode = CM_PICK; }
215
216
218 void disableNormals() { mNormalMode = NM_NONE; }
219
221 void enablePerFaceNormals() { mNormalMode = NM_FACE; }
222
224 void enablePerHalffaceNormals() { mNormalMode = NM_HALFFACE; }
225
227 void enablePerVertexNormals() { mNormalMode = NM_VERTEX; }
228
229
231 void disablePrimitives() { mPrimitiveMode = PM_NONE; }
232
234 void enableCellPrimitives() { mPrimitiveMode = PM_CELLS; }
235
237 void enableFacePrimitives() { mPrimitiveMode = PM_FACES; }
238
240 void enableFaceOnCellPrimitives() { mPrimitiveMode = PM_FACES_ON_CELLS; }
241
243 void enableHalffacePrimitives() { mPrimitiveMode = PM_HALFFACES; }
244
246 void enableHalffaceOnCellPrimitives() { mPrimitiveMode = PM_HALFFACES_ON_CELLS; }
247
249 void enableEdgePrimitives() { mPrimitiveMode = PM_EDGES; }
250
252 void enableIrregularEdgePrimitives() { mPrimitiveMode = PM_IRREGULAR_EDGES; }
253
255 void enableEdgeOnCellPrimitives() { mPrimitiveMode = PM_EDGES_ON_CELLS; }
256
258 void enableHalfedgePrimitives() { mPrimitiveMode = PM_HALFEDGES; }
259
261 void enableVertexPrimitives() { mPrimitiveMode = PM_VERTICES; }
262
264 void enableVertexOnCellPrimitives() { mPrimitiveMode = PM_VERTICES_ON_CELLS; }
265
266
268 void disableTextures() { mTexCoordMode = TCM_NONE; }
269
271 void enableTextureSingle() { mTexCoordMode = TCM_SINGLE_2D; }
272
273
275 bool selectionOnly() { return mSkipUnselected; }
276
278 void setSelectionOnly(bool _selectionOnly) { mSkipUnselected = _selectionOnly; }
279
280
282 void clearCutPlanes();
283
285 void addCutPlane(const ACG::Geometry::Plane& _p);
286
288 void addCutPlane(const ACG::Vec3d& _p, const ACG::Vec3d& _n, const ACG::Vec3d& _xsize, const ACG::Vec3d& _ysize);
289
290
292 void setBoundaryOnly(bool _boundaryOnly) { mBoundaryOnly = _boundaryOnly; }
293
294private:
296 bool is_inside(const ACG::Vec3d& _p);
297
299 bool is_inside(const VertexHandle& _vh);
300
302 bool is_inside(const HalfEdgeHandle& _heh);
303
305 bool is_inside(const EdgeHandle& _eh);
306
308 bool is_inside(const HalfFaceHandle& _hfh);
309
311 bool is_inside(const FaceHandle& _fh);
312
314 bool is_inside(const CellHandle& _ch);
315
318
319 bool should_render(const VertexHandle& _vh);
320 bool should_render(const HalfEdgeHandle& _heh);
321 bool should_render(const EdgeHandle& _eh);
322 bool should_render(const HalfFaceHandle& _hfh);
323 bool should_render(const FaceHandle& _fh);
324 bool should_render(const CellHandle& _ch);
325
326
328 bool optionsChanged();
329
331 void saveOptions();
332
333
335 void addFloatToBuffer( float _value, unsigned char *&_buffer );
336
338 void addUCharToBuffer( unsigned char _value, unsigned char *&_buffer );
339
341 void addPositionToBuffer(ACG::Vec3d _position, unsigned char* _buffer , unsigned int _offset);
342
344 void addColorToBuffer(ACG::Vec4uc _color, unsigned char* _buffer, unsigned int _offset);
345
347 void addColorToBuffer(ACG::Vec4f _color, unsigned char* _buffer, unsigned int _offset);
348
350 void addNormalToBuffer(ACG::Vec3d _normal, unsigned char *_buffer, unsigned int _offset);
351
353 void addTexCoordToBuffer(ACG::Vec2f _texCoord, unsigned char* _buffer, unsigned int _offset);
354
355
358
359
361 void buildVertexBuffer(unsigned char* _buffer);
362
364 void buildNormalBuffer(unsigned char* _buffer);
365
367 void buildColorBuffer(unsigned char* _buffer);
368
370 void buildTexCoordBuffer(unsigned char* _buffer);
371
373 void buildPickColorBuffer(ACG::GLState &_state, unsigned int _offset, unsigned char* _buffer);
374
375
377 ACG::Vec4f getValenceColorCode(unsigned int _valence, bool _inner) const;
378
379
381 void countNumOfVertices();
382
383
386
389
392
395
397 void calculateCOGs();
398
401
403 bool colorsNeedRebuild();
404
407
409 bool normalsNeedRebuild();
410
411private:
412 ACG::Vec4f mDefaultColor;
413
414 const VolumeMesh& mMesh;
415 OpenVolumeMesh::StatusAttrib& mStatusAttrib;
419
420 int mNumOfVertices;
421 int mCurrentNumOfVertices;
422
423 unsigned int mVertexSize;
424 ACG::VertexDeclaration mVertexDeclaration;
425
426 int mColorOffset;
427 int mNormalOffset;
428
429 double mScale;
430
431 GLuint mBuffer;
432
433 // local picking offset ?
434 unsigned int mCurrentPickOffset;
435
436 // global picking offset
437 unsigned int mGlobalPickOffset;
438
439 bool mInvalidated;
440 bool mGeometryChanged;
441 bool mNormalsChanged;
442 bool mColorsChanged;
443 bool mTexCoordsChanged;
444
445 //draw modes
447
448 //options
449 PrimitiveMode mPrimitiveMode;
450 NormalMode mNormalMode;
451 ColorMode mColorMode;
452
453 bool mSkipUnselected;
454 bool mShowIrregularInnerEdges;
455 bool mShowIrregularOuterValence2Edges;
456 bool mSkipRegularEdges;
457 bool mBoundaryOnly;
458
459 PrimitiveMode mCurrentPrimitiveMode;
460 NormalMode mCurrentNormalMode;
461 ColorMode mCurrentColorMode;
462
463 bool mCurrentSkipUnselected;
464 bool mCurrentShowIrregularInnerEdges;
465 bool mCurrentShowIrregularOuterValence2Edges;
466 bool mCurrentSkipRegularEdges;
467 bool mCurrentBoundaryOnly;
468
469 unsigned char mCurrentVertexSize;
470 unsigned char mCurrentNormalOffset;
471 unsigned char mCurrentColorOffset;
472
473 std::vector<ACG::Geometry::Plane> cut_planes_;
474
475 std::vector<ACG::Vec3d> mCogs;
476 bool mCogsValid;
477 std::vector<bool> mCellInsideness;
478 bool mCellInsidenessValid;
479
480 TexCoordMode mTexCoordMode;
481 TexCoordMode mCurrentTexCoordMode;
482 unsigned char mTexCoordOffset;
483 unsigned char mCurrentTexCoordOffset;
484
485};
486
487//=============================================================================
488#if defined(INCLUDE_TEMPLATES) && !defined(VOLUMEMESHBUFFERMANAGERT_CC)
489#include "VolumeMeshBufferManagerT_impl.hh"
490#endif
491//=============================================================================
Class to define the vertex input layout.
This class creates buffers that can be used to render open volume meshs.
void buildNormalBuffer(unsigned char *_buffer)
Adds all normals to the buffer.
double getScale() const
Return the scale used to shrink cells.
void enableCellPrimitives()
Enables cell primitives.
void setSelectionOnly(bool _selectionOnly)
Set whether only selected primitves should be added to the buffer.
void free()
Deletes the buffers on the GPU.
bool texCoordsNeedRebuild()
Checks whether texture coordinates need to be rebuild.
void saveOptions()
State that the current buffer was built with the current options.
void setDefaultColor(ACG::Vec4f _defaultColor)
Sets the default color.
unsigned char getNormalOffset()
Returns the normal's offset within the buffer.
void enableVertexOnCellPrimitives()
Enables vertex primitives that are drawn on the cells.
void calculateCellInsideness()
Calculates for all cells whether they are inside w.r.t. all cut planes.
bool optionsChanged()
Tests whether the options were changed since the last time building the buffer.
void enablePickColors()
Enables picking colors.
bool positionsNeedRebuild()
Checks whether positions need to be rebuild.
void enablePerHalffaceColors()
Enables per halfface colors.
void enablePerCellColors()
Enables per cell colors.
void enablePerFaceColors()
Enables per face colors.
void addPositionToBuffer(ACG::Vec3d _position, unsigned char *_buffer, unsigned int _offset)
Adds a position to the buffer.
bool normalsNeedRebuild()
Checks whether normals need to be rebuild.
void calculateVertexDeclaration()
Constructs a VertexDeclaration, the size and the offsets for the vertices stored in the buffer.
int getNumOfIncidentCells(OpenVolumeMesh::FaceHandle _fh)
Returns the number of cells that are incident to the given face and also inside w....
void buildPickColorBuffer(ACG::GLState &_state, unsigned int _offset, unsigned char *_buffer)
Adds all picking colors to the buffer.
ACG::Vec3d getCOG(OpenVolumeMesh::CellHandle _ch)
Returns the center of gravity of the given cell.
unsigned int getNumOfVertices()
Returns the number of vertices stored in the buffer.
void enableHalffacePrimitives()
Enables halfface primitves.
void addCutPlane(const ACG::Geometry::Plane &_p)
Adds a cut plane.
void disableColors()
Disables colors.
void setBoundaryOnly(bool _boundaryOnly)
Sets whether only the boundary primitves should be rendered.
void enablePerHalfedgeColors()
Enables per halfedge colors.
void clearCutPlanes()
Removes all cut planes.
void enableTextureSingle()
Enables textures.
void invalidateColors()
Invalidates colors.
GLuint getBuffer()
Returns the name of the buffer.
void enableEdgeOnCellPrimitives()
Enables edge primitives which are drawn on the cells.
void buildTexCoordBuffer(unsigned char *_buffer)
Adds texture coordinates to the buffer.
bool colorsNeedRebuild()
Checks whether colors need to be rebuild.
void addNormalToBuffer(ACG::Vec3d _normal, unsigned char *_buffer, unsigned int _offset)
Adds a normal to the buffer.
void invalidateNormals()
Invalidates normals.
void enableHalfedgePrimitives()
Enables per halfedge primitives.
void disableNormals()
Disables normals.
void enablePerVertexNormals()
Enables per vertex normals.
void enableFacePrimitives()
Enables face primitives.
void invalidate()
Invalidates the buffer.
void disablePrimitives()
Disables primitives (nothing will be drawn)
void invalidateTexCoords()
Invalidates texture coordinates.
void addFloatToBuffer(float _value, unsigned char *&_buffer)
Adds a float to the buffer.
bool selectionOnly()
Checks whether only selected primitives should be added to the buffer.
void enableHalffaceOnCellPrimitives()
Enables halfface primitives which are drawn on the cells.
unsigned char getTexCoordOffset()
Returns the texcoord's offset within the buffer.
void addColorToBuffer(ACG::Vec4uc _color, unsigned char *_buffer, unsigned int _offset)
Adds a color to the buffer.
const ACG::VertexDeclaration * getVertexDeclaration()
Returns a VertexDeclaration for the vertices stored in the buffer.
void calculateCOGs()
Calculates the center of gravity for all cells.
void enableIrregularEdgePrimitives()
Enables edge primitives for irregular edges.
void enableVertexPrimitives()
Enables vertex primitives.
void countNumOfVertices()
Counts the number of vertices that need to be stored in the buffer.
void enablePerHalffaceNormals()
Enables per halfface normals.
void disableTextures()
Disables textures.
unsigned char getStride()
Returns the vertex stride.
void enableFaceOnCellPrimitives()
Enables face primitives which are drawn on the cells.
void setScale(double _scale)
Sets the scale used to shrink cells.
void buildColorBuffer(unsigned char *_buffer)
Adds all colors to the buffer.
unsigned char getColorOffset()
Returns the color's offset within the buffer.
void addTexCoordToBuffer(ACG::Vec2f _texCoord, unsigned char *_buffer, unsigned int _offset)
Adds a texture coordnate to the buffer.
void enableEdgePrimitives()
Enables edge primitves.
void setOptionsFromDrawMode(ACG::SceneGraph::DrawModes::DrawMode _drawMode)
Configures the buffer manager's options from a DrawMode.
GLuint getPickBuffer(ACG::GLState &_state, unsigned int _offset)
Returns the name of the pick buffer.
bool is_inside(const ACG::Vec3d &_p)
Tests whether the given point is inside w.r.t. all cut planes.
void invalidateGeometry()
Invalidates geometry.
void enablePerVertexColors()
Enables per vertex colors.
void enablePerFaceNormals()
Enables per face normals.
ACG::Vec4f getValenceColorCode(unsigned int _valence, bool _inner) const
Returns a color code for irregular edges.
void buildVertexBuffer(unsigned char *_buffer)
Adds all vertices to the buffer.
void addUCharToBuffer(unsigned char _value, unsigned char *&_buffer)
Adds an unsigned char to the buffer.
void enablePerEdgeColors()
Enables per edge colors.
This class provides easy access to DrawModes supported by OpenVolumeMesh.