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 
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;
118 };
119 
120 
121 
126 template <class Mesh>
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 
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 
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 
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 
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 
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.cc"
588 #endif
589 //=============================================================================
590 #endif // ACG_STRIP_PROCESSOR_HH defined
591 //=============================================================================
void clear()
delete all strips
int startOffset
Start offset in the face buffer.
std::vector< ACG::Vec4f > perEdgeColorBuffer_
Per Edge color buffer.
bool stripTextureCompare(const Strip &i, const Strip &j)
Compare function for sorting Strips depending on their texture index.
std::vector< TextureRenderInfo > * textureRenderData()
get rendering information for texture data
std::vector< ACG::Vec3f > perFaceVertexBuffer_
Buffer holding vertices for per face rendering.
const std::string & indexPropertyName() const
get the name of the texture index property
unsigned int nStrips() const
returns number of strips
bool stripsValid_
This flag shows if the strips have to be regenerated.
std::vector< ACG::Vec4uc > pickFaceColorBuf_
Call this function to update the color picking array.
ACG::Vec2f * perFacePerVertexTextureCoordBuffer()
get a pointer to the per face per vertex texture coor buffer
bool updatePerHalfedgeBuffers_
This flag controls if an update is really necessary.
std::vector< ACG::Vec3f > perEdgeVertexBuffer_
Per Edge vertex buffer (glLines)
StripsIterator end() const
Access strips.
ACG::Vec4uc * pickFaceColorBuffer()
get a pointer to the per face picking color buffer
void invalidatePerFaceBuffers()
Update of the buffers.
StripsIterator begin() const
Access strips.
int textureIndex
This contains the texture index used for rendering this strip.
std::vector< OpenMesh::FaceHandle > faceMap
This map contains for each vertex in the strips a handle to the face it closes.
int faceCount
Number of faces in the render step for this texture.
std::string perFaceTextureCoordinatePropertyName_
Property for the per face texture coordinates.
std::vector< ACG::Vec4f > perFaceColorBuffer_
Buffer holding vertices for per face rendering.
ACG::Vec4uc * pickEdgeColorBuffer()
get a pointer to the per edge picking color buffer
class for managing a single triangle strip.
bool updatePerEdgeBuffers_
This flag controls if an update is really necessary.
std::vector< ACG::Vec3f > perFacePerVertexNormalBuffer_
Buffer holding vertices for per face rendering.
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
std::vector< TextureRenderInfo > textureRenderData_
Property for the per face texture index.
ACG::Vec4uc * pickVertexColorBuffer()
get a pointer to the per vertex picking color buffer
std::vector< ACG::Vec3f > perFaceNormalBuffer_
Buffer holding vertices for per face rendering.
std::vector< typename Mesh::FaceHandle > FaceHandles
This flag shows if the strips have to be regenerated.
std::vector< ACG::Vec3f > perHalfedgeVertexBuffer_
Per Edge vertex buffer (glLines)
void invalidatePerEdgeBuffers()
Update of the buffers.
void invalidateStrips()
Force a strip update.
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
void invalidatePerHalfedgeBuffers()
Update of the buffers.
std::vector< ACG::Vec4f > perHalfedgeColorBuffer_
Per Edge color buffer.
bool updatePerFaceBuffers_
This flag controls if an update is really necessary.
unsigned int perFaceVertexBufferSize()
Get the number of elements in the face picking buffers.
ACG::Vec4uc * pickAnyColorBuffer()
get a pointer to the any picking color buffer
int textureId
Id of the texture to be rendered.
std::vector< ACG::Vec2f > perFaceTextureCoordArray_
Property for the per face texture index.
std::vector< unsigned int > indexArray
This array cotains the actual triangle strip used for rendering.