Developer Documentation

StripProcessorT.hh
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
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 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $Date$ *
46 * *
47 \*===========================================================================*/
48
49 //=============================================================================
50 //
51 // CLASS StripProcessorT
52 //
53 //=============================================================================
54
55
56 #ifndef ACG_STRIP_PROCESSOR_HH
57 #define ACG_STRIP_PROCESSOR_HH
58
59
60 //== INCLUDES =================================================================
61
62 #include <vector>
63 #include <OpenMesh/Core/Utils/Property.hh>
64 #include <OpenMesh/Core/IO/MeshIO.hh>
65
66 #include "../Config/ACGDefines.hh"
67
68 #include <ACG/GL/GLState.hh>
69
70 //== FORWARDDECLARATIONS ======================================================
71
72
73 //== NAMESPACES ===============================================================
74
75 namespace ACG {
76 namespace SceneGraph {
77
78
79 //== CLASS DEFINITION =========================================================
80
84 class ACGDLLEXPORT Strip {
85
86 public:
87
92 std::vector< unsigned int > indexArray;
93
95 std::vector< OpenMesh::FaceHandle > faceMap;
96
98 int textureIndex;
99
100 };
101
102 bool ACGDLLEXPORT stripTextureCompare(const Strip& i,const Strip& j);
103
104 class ACGDLLEXPORT TextureRenderInfo {
105 public:
106 TextureRenderInfo(int _textureId,int _faceCount,int _startOffset):
107 textureId(_textureId),
108 faceCount(_faceCount),
109 startOffset(_startOffset)
110 {};
111
113 int textureId;
115 int faceCount;
117 int startOffset;
118 };
119
120
121
126 template <class Mesh>
127 class StripProcessorT
128 {
129 public:
130
131 typedef unsigned int Index;
132 typedef std::vector<Strip> Strips;
133 typedef typename Strips::const_iterator StripsIterator;
134 typedef typename Mesh::FaceHandle FaceHandle;
135
137 StripProcessorT(Mesh& _mesh);
138
140 ~StripProcessorT();
141
143 unsigned int stripify();
144
146 void clear() { Strips().swap(strips_); }
147
149 unsigned int nStrips() const { return strips_.size(); }
150
152 StripsIterator begin() const { return strips_.begin(); }
154 StripsIterator end() const { return strips_.end(); }
155
156
157 private:
158
159
160
162 void convexityTest(FaceHandle _fh);
163
164 OpenMesh::FPropHandleT<bool>::reference processed(typename Mesh::FaceHandle _fh) {
165 return mesh_.property(processed_, _fh);
166 }
167 OpenMesh::FPropHandleT<bool>::reference used(typename Mesh::FaceHandle _fh) {
168 return mesh_.property(used_, _fh);
169 }
170
171
172
173 private:
174
175 Mesh& mesh_;
176 Strips strips_;
177 OpenMesh::FPropHandleT<bool> processed_, used_;
178
179 //===========================================================================
182 //===========================================================================
183 public:
184
189 void invalidateStrips() { stripsValid_ = false; };
190
191 private:
192
193 typedef std::vector<typename Mesh::FaceHandle> FaceHandles;
194
196 bool stripsValid_;
197
199 void buildStrips();
200
202 void buildStripsTriMesh();
203
209 void buildStripsPolyMesh();
210
211
213 void buildStripTriMesh(typename Mesh::HalfedgeHandle _start_hh,
214 Strip& _strip,
215 FaceHandles& _faces);
216
218 void buildStripPolyMesh(typename Mesh::HalfedgeHandle _start_hh,
219 Strip& _strip,
220 FaceHandles& _faces);
221
224 //===========================================================================
227 //===========================================================================
228 public:
233 ACG::Vec3f * perEdgeVertexBuffer();
234
239 ACG::Vec4f * perEdgeColorBuffer();
240
246 void invalidatePerEdgeBuffers(){ updatePerEdgeBuffers_ = true; };
247
248 private:
253 void updatePerEdgeBuffers();
254
256 std::vector< ACG::Vec3f > perEdgeVertexBuffer_;
257
259 std::vector< ACG::Vec4f > perEdgeColorBuffer_;
260
262 bool updatePerEdgeBuffers_;
263
267 //===========================================================================
270 //===========================================================================
271 public:
276 ACG::Vec3f * perHalfedgeVertexBuffer();
277
282 ACG::Vec4f * perHalfedgeColorBuffer();
283
289 void invalidatePerHalfedgeBuffers(){ updatePerHalfedgeBuffers_ = true; };
290
291 private:
296 void updatePerHalfedgeBuffers();
297
298
302 typename Mesh::Point halfedge_point(const typename Mesh::HalfedgeHandle _heh);
303
305 std::vector< ACG::Vec3f > perHalfedgeVertexBuffer_;
306
308 std::vector< ACG::Vec4f > perHalfedgeColorBuffer_;
309
311 bool updatePerHalfedgeBuffers_;
312
315 //===========================================================================
318 //===========================================================================
319
320 public:
327 ACG::Vec3f * perFaceVertexBuffer();
328
335 ACG::Vec3f * perFaceNormalBuffer();
336
343 ACG::Vec3f * perFacePerVertexNormalBuffer();
344
351 ACG::Vec4f * perFaceColorBuffer();
352
355 unsigned int perFaceVertexBufferSize(){ return perFaceVertexBuffer_.size(); };
356
362 void invalidatePerFaceBuffers(){ updatePerFaceBuffers_ = true; };
363
364 private:
369 void updatePerFaceBuffers();
370
372 std::vector< ACG::Vec3f > perFaceVertexBuffer_;
373 std::vector< ACG::Vec4f > perFaceColorBuffer_;
374 std::vector< ACG::Vec3f > perFaceNormalBuffer_;
375 std::vector< ACG::Vec3f > perFacePerVertexNormalBuffer_;
376
378 bool updatePerFaceBuffers_;
379
382 //===========================================================================
385 //===========================================================================
386
387 public:
388
393 void updatePickingVertices(ACG::GLState& _state , uint _offset = 0);
394
401 ACG::Vec4uc * pickVertexColorBuffer(){ return &(pickVertexColorBuf_)[0]; };
402
403 private:
404
406 std::vector< ACG::Vec4uc > pickVertexColorBuf_;
407
408
411 //===========================================================================
414 //===========================================================================
415
416 public:
417
422 void updatePickingEdges(ACG::GLState& _state , uint _offset = 0 );
423
430 ACG::Vec4uc * pickEdgeColorBuffer(){ return &(pickEdgeColorBuf_)[0]; };
431
432
433
434 private:
435
436 std::vector< ACG::Vec4uc > pickEdgeColorBuf_;
437
438
441 //===========================================================================
444 //===========================================================================
445
446 public:
447
449 void updatePickingFaces(ACG::GLState& _state );
450
457 ACG::Vec4uc * pickFaceColorBuffer(){ return &(pickFaceColorBuf_)[0]; };
458
459
460
461 private:
462
464 void updatePickingFacesTrimesh(ACG::GLState& _state );
465
467 void updatePickingFacesPolymesh(ACG::GLState& _state );
468
469 std::vector< ACG::Vec4uc > pickFaceColorBuf_;
470
473 //===========================================================================
476 //===========================================================================
477
478 public:
479
485 void updatePickingAny(ACG::GLState& _state );
486
493 ACG::Vec4uc * pickAnyColorBuffer(){ return &(pickAnyColorBuf_)[0]; };
494
495 private:
496
497 std::vector< ACG::Vec4uc > pickAnyColorBuf_;
498
501 //===========================================================================
504 //===========================================================================
505
506 public:
513 void setIndexPropertyName( std::string _indexPropertyName );
514
516 const std::string& indexPropertyName() const { return textureIndexPropertyName_; };
517
524 void setPerFaceTextureCoordinatePropertyName( std::string _perFaceTextureCoordinatePropertyName );
525
530 bool perFaceTextureCoordinateAvailable();
531
537 bool perFaceTextureIndexAvailable();
538
543 ACG::Vec2f * perFacePerVertexTextureCoordBuffer(){ return &(perFaceTextureCoordArray_)[0]; };
544
552 std::vector< TextureRenderInfo >* textureRenderData(){ return &textureRenderData_; };
553
554 private:
555
563 std::string textureIndexPropertyName_;
564
570 std::string perFaceTextureCoordinatePropertyName_;
571
572 std::vector< ACG::Vec2f > perFaceTextureCoordArray_;
573
574 std::vector< TextureRenderInfo > textureRenderData_;
575
578 };
579
580
581 //=============================================================================
582 } // namespace SceneGraph
583 } // namespace ACG
584 //=============================================================================
585 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_STRIP_PROCESSOR_C)
586 #define ACG_STRIP_PROCESSOR_TEMPLATES
587 #include "StripProcessorT_impl.hh"
588 #endif
589 //=============================================================================
590 #endif // ACG_STRIP_PROCESSOR_HH defined
591 //=============================================================================
ACG::SceneGraph::StripProcessorT::perFaceColorBuffer_
std::vector< ACG::Vec4f > perFaceColorBuffer_
Buffer holding vertices for per face rendering.
Definition: StripProcessorT.hh:373
ACG::SceneGraph::StripProcessorT::perFaceNormalBuffer_
std::vector< ACG::Vec3f > perFaceNormalBuffer_
Buffer holding vertices for per face rendering.
Definition: StripProcessorT.hh:374
ACG::SceneGraph::StripProcessorT::indexPropertyName
const std::string & indexPropertyName() const
get the name of the texture index property
Definition: StripProcessorT.hh:516
ACG::SceneGraph::StripProcessorT::pickEdgeColorBuffer
ACG::Vec4uc * pickEdgeColorBuffer()
get a pointer to the per edge picking color buffer
Definition: StripProcessorT.hh:430
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::SceneGraph::StripProcessorT::textureRenderData_
std::vector< TextureRenderInfo > textureRenderData_
Property for the per face texture index.
Definition: StripProcessorT.hh:574
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:112
ACG::SceneGraph::Strip::textureIndex
int textureIndex
This contains the texture index used for rendering this strip.
Definition: StripProcessorT.hh:98
OpenMesh::TriMesh_ArrayKernelT< CustomTraits >
ACG::SceneGraph::StripProcessorT::begin
StripsIterator begin() const
Access strips.
Definition: StripProcessorT.hh:152
ACG::SceneGraph::ACG::GLState
Definition: MeshNode2T_impl.hh:213
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::TextureRenderInfo
Definition: StripProcessorT.hh:104
ACG::SceneGraph::StripProcessorT::textureRenderData
std::vector< TextureRenderInfo > * textureRenderData()
get rendering information for texture data
Definition: StripProcessorT.hh:552
ACG::SceneGraph::StripProcessorT::perEdgeVertexBuffer_
std::vector< ACG::Vec3f > perEdgeVertexBuffer_
Per Edge vertex buffer (glLines)
Definition: StripProcessorT.hh:256
ACG::SceneGraph::StripProcessorT::perFacePerVertexTextureCoordBuffer
ACG::Vec2f * perFacePerVertexTextureCoordBuffer()
get a pointer to the per face per vertex texture coor buffer
Definition: StripProcessorT.hh:543
SceneGraph
Definition: QtPrincipalAxisDialog.hh:67
ACG::SceneGraph::StripProcessorT::perFacePerVertexNormalBuffer_
std::vector< ACG::Vec3f > perFacePerVertexNormalBuffer_
Buffer holding vertices for per face rendering.
Definition: StripProcessorT.hh:375
ACG::SceneGraph::StripProcessorT::clear
void clear()
delete all strips
Definition: StripProcessorT.hh:146
ACG::SceneGraph::TextureRenderInfo::startOffset
int startOffset
Start offset in the face buffer.
Definition: StripProcessorT.hh:117
ACG::SceneGraph::StripProcessorT::perEdgeColorBuffer_
std::vector< ACG::Vec4f > perEdgeColorBuffer_
Per Edge color buffer.
Definition: StripProcessorT.hh:259
ACG::SceneGraph::StripProcessorT::pickFaceColorBuf_
std::vector< ACG::Vec4uc > pickFaceColorBuf_
Call this function to update the color picking array.
Definition: StripProcessorT.hh:469
ACG::SceneGraph::StripProcessorT::pickAnyColorBuffer
ACG::Vec4uc * pickAnyColorBuffer()
get a pointer to the any picking color buffer
Definition: StripProcessorT.hh:493
ACG::SceneGraph::StripProcessorT::end
StripsIterator end() const
Access strips.
Definition: StripProcessorT.hh:154
ACG::SceneGraph::StripProcessorT::perFaceTextureCoordArray_
std::vector< ACG::Vec2f > perFaceTextureCoordArray_
Property for the per face texture index.
Definition: StripProcessorT.hh:572
ACG::SceneGraph::TextureRenderInfo::textureId
int textureId
Id of the texture to be rendered.
Definition: StripProcessorT.hh:110
ACG::SceneGraph::Strip::faceMap
std::vector< OpenMesh::FaceHandle > faceMap
This map contains for each vertex in the strips a handle to the face it closes.
Definition: StripProcessorT.hh:95
ACG::SceneGraph::StripProcessorT::perHalfedgeVertexBuffer_
std::vector< ACG::Vec3f > perHalfedgeVertexBuffer_
Per Edge vertex buffer (glLines)
Definition: StripProcessorT.hh:305
ACG::SceneGraph::StripProcessorT::FaceHandles
std::vector< typename Mesh::FaceHandle > FaceHandles
This flag shows if the strips have to be regenerated.
Definition: StripProcessorT.hh:189
ACG::SceneGraph::StripProcessorT::invalidateStrips
void invalidateStrips()
Force a strip update.
Definition: StripProcessorT.hh:189
ACG::SceneGraph::StripProcessorT::updatePerFaceBuffers_
bool updatePerFaceBuffers_
This flag controls if an update is really necessary.
Definition: StripProcessorT.hh:378
ACG::SceneGraph::StripProcessorT::pickVertexColorBuffer
ACG::Vec4uc * pickVertexColorBuffer()
get a pointer to the per vertex picking color buffer
Definition: StripProcessorT.hh:401
ACG::SceneGraph::StripProcessorT::pickFaceColorBuffer
ACG::Vec4uc * pickFaceColorBuffer()
get a pointer to the per face picking color buffer
Definition: StripProcessorT.hh:457
ACG::SceneGraph::stripTextureCompare
bool stripTextureCompare(const Strip &i, const Strip &j)
Compare function for sorting Strips depending on their texture index.
Definition: StripProcessor.cc:68
ACG::SceneGraph::StripProcessorT::updatePerEdgeBuffers_
bool updatePerEdgeBuffers_
This flag controls if an update is really necessary.
Definition: StripProcessorT.hh:262
ACG::SceneGraph::StripProcessorT::perFaceTextureCoordinatePropertyName_
std::string perFaceTextureCoordinatePropertyName_
Property for the per face texture coordinates.
Definition: StripProcessorT.hh:570
ACG::SceneGraph::StripProcessorT::invalidatePerEdgeBuffers
void invalidatePerEdgeBuffers()
Update of the buffers.
Definition: StripProcessorT.hh:246
ACG::SceneGraph::StripProcessorT::invalidatePerHalfedgeBuffers
void invalidatePerHalfedgeBuffers()
Update of the buffers.
Definition: StripProcessorT.hh:289
ACG::SceneGraph::Strip::indexArray
std::vector< unsigned int > indexArray
This array cotains the actual triangle strip used for rendering.
Definition: StripProcessorT.hh:92
ACG::SceneGraph::Strip
class for managing a single triangle strip.
Definition: StripProcessorT.hh:84
ACG::SceneGraph::StripProcessorT
Definition: StripProcessorT.hh:127
ACG::SceneGraph::TextureRenderInfo::faceCount
int faceCount
Number of faces in the render step for this texture.
Definition: StripProcessorT.hh:115
OpenMesh::FPropHandleT< bool >
ACG::SceneGraph::StripProcessorT::nStrips
unsigned int nStrips() const
returns number of strips
Definition: StripProcessorT.hh:149
ACG::SceneGraph::StripProcessorT::stripsValid_
bool stripsValid_
This flag shows if the strips have to be regenerated.
Definition: StripProcessorT.hh:196
ACG::SceneGraph::StripProcessorT::updatePerHalfedgeBuffers_
bool updatePerHalfedgeBuffers_
This flag controls if an update is really necessary.
Definition: StripProcessorT.hh:311
ACG::SceneGraph::StripProcessorT::invalidatePerFaceBuffers
void invalidatePerFaceBuffers()
Update of the buffers.
Definition: StripProcessorT.hh:362
ACG::SceneGraph::StripProcessorT::perFaceVertexBuffer_
std::vector< ACG::Vec3f > perFaceVertexBuffer_
Buffer holding vertices for per face rendering.
Definition: StripProcessorT.hh:372
ACG::SceneGraph::StripProcessorT::perHalfedgeColorBuffer_
std::vector< ACG::Vec4f > perHalfedgeColorBuffer_
Per Edge color buffer.
Definition: StripProcessorT.hh:308
ACG::SceneGraph::StripProcessorT::perFaceVertexBufferSize
unsigned int perFaceVertexBufferSize()
Get the number of elements in the face picking buffers.
Definition: StripProcessorT.hh:355