StripProcessorT.hh
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #ifndef ACG_STRIP_PROCESSOR_HH
00050 #define ACG_STRIP_PROCESSOR_HH
00051
00052
00053
00054
00055 #include <vector>
00056 #include <OpenMesh/Core/Utils/Property.hh>
00057 #include <OpenMesh/Core/IO/MeshIO.hh>
00058
00059 #include "../Config/ACGDefines.hh"
00060
00061 #include <ACG/GL/GLState.hh>
00062
00063
00064
00065
00066
00067
00068 namespace ACG {
00069 namespace SceneGraph {
00070
00071
00072
00073
00077 class ACGDLLEXPORT Strip {
00078
00079 public:
00080
00085 std::vector< unsigned int > indexArray;
00086
00088 std::vector< OpenMesh::FaceHandle > faceMap;
00089
00091 int textureIndex;
00092
00093 };
00094
00096 bool ACGDLLEXPORT stripTextureCompare(const Strip& i,const Strip& j);
00097
00098 class ACGDLLEXPORT TextureRenderInfo {
00099 public:
00100 TextureRenderInfo(int _textureId,int _faceCount,int _startOffset):
00101 textureId(_textureId),
00102 faceCount(_faceCount),
00103 startOffset(_startOffset)
00104 {};
00105
00107 int textureId;
00109 int faceCount;
00111 int startOffset;
00112 };
00113
00114
00115
00120 template <class Mesh>
00121 class StripProcessorT
00122 {
00123 public:
00124
00125 typedef unsigned int Index;
00126 typedef std::vector<Strip> Strips;
00127 typedef typename Strips::const_iterator StripsIterator;
00128 typedef typename Mesh::FaceHandle FaceHandle;
00129
00131 StripProcessorT(Mesh& _mesh);
00132
00134 ~StripProcessorT();
00135
00137 unsigned int stripify();
00138
00140 void clear() { Strips().swap(strips_); }
00141
00143 unsigned int nStrips() const { return strips_.size(); }
00144
00146 StripsIterator begin() const { return strips_.begin(); }
00148 StripsIterator end() const { return strips_.end(); }
00149
00150
00151 private:
00152
00153
00154
00156 void convexityTest(FaceHandle _fh);
00157
00158 OpenMesh::FPropHandleT<bool>::reference processed(typename Mesh::FaceHandle _fh) {
00159 return mesh_.property(processed_, _fh);
00160 }
00161 OpenMesh::FPropHandleT<bool>::reference used(typename Mesh::FaceHandle _fh) {
00162 return mesh_.property(used_, _fh);
00163 }
00164
00165
00166
00167 private:
00168
00169 Mesh& mesh_;
00170 Strips strips_;
00171 OpenMesh::FPropHandleT<bool> processed_, used_;
00172
00173
00176
00177 public:
00178
00183 void invalidateStrips() { stripsValid_ = false; };
00184
00185 private:
00186
00187 typedef std::vector<typename Mesh::FaceHandle> FaceHandles;
00188
00190 bool stripsValid_;
00191
00193 void buildStrips();
00194
00196 void buildStripsTriMesh();
00197
00203 void buildStripsPolyMesh();
00204
00205
00207 void buildStripTriMesh(typename Mesh::HalfedgeHandle _start_hh,
00208 Strip& _strip,
00209 FaceHandles& _faces);
00210
00212 void buildStripPolyMesh(typename Mesh::HalfedgeHandle _start_hh,
00213 Strip& _strip,
00214 FaceHandles& _faces);
00215
00218
00221
00222 public:
00227 ACG::Vec3f * perEdgeVertexBuffer();
00228
00233 ACG::Vec4f * perEdgeColorBuffer();
00234
00240 void invalidatePerEdgeBuffers(){ updatePerEdgeBuffers_ = true; };
00241
00242 private:
00247 void updatePerEdgeBuffers();
00248
00250 std::vector< ACG::Vec3f > perEdgeVertexBuffer_;
00251
00253 std::vector< ACG::Vec4f > perEdgeColorBuffer_;
00254
00256 bool updatePerEdgeBuffers_;
00257
00260
00263
00264
00265 public:
00272 ACG::Vec3f * perFaceVertexBuffer();
00273
00280 ACG::Vec3f * perFaceNormalBuffer();
00281
00288 ACG::Vec4f * perFaceColorBuffer();
00289
00292 unsigned int perFaceVertexBufferSize(){ return perFaceVertexBuffer_.size(); };
00293
00299 void invalidatePerFaceBuffers(){ updatePerFaceBuffers_ = true; };
00300
00301 private:
00306 void updatePerFaceBuffers();
00307
00309 std::vector< ACG::Vec3f > perFaceVertexBuffer_;
00310 std::vector< ACG::Vec4f > perFaceColorBuffer_;
00311 std::vector< ACG::Vec3f > perFaceNormalBuffer_;
00312
00314 bool updatePerFaceBuffers_;
00315
00318
00321
00322
00323 public:
00324
00329 void updatePickingVertices(ACG::GLState& _state , uint _offset = 0);
00330
00337 ACG::Vec4uc * pickVertexColorBuffer(){ return &(pickVertexColorBuf_)[0]; };
00338
00339 private:
00340
00342 std::vector< ACG::Vec4uc > pickVertexColorBuf_;
00343
00344
00347
00350
00351
00352 public:
00353
00358 void updatePickingEdges(ACG::GLState& _state , uint _offset = 0 );
00359
00366 ACG::Vec4uc * pickEdgeColorBuffer(){ return &(pickEdgeColorBuf_)[0]; };
00367
00368
00369
00370 private:
00371
00372 std::vector< ACG::Vec4uc > pickEdgeColorBuf_;
00373
00374
00377
00380
00381
00382 public:
00383
00385 void updatePickingFaces(ACG::GLState& _state );
00386
00393 ACG::Vec4uc * pickFaceColorBuffer(){ return &(pickFaceColorBuf_)[0]; };
00394
00395
00396
00397 private:
00398
00400 void updatePickingFacesTrimesh(ACG::GLState& _state );
00401
00403 void updatePickingFacesPolymesh(ACG::GLState& _state );
00404
00405 std::vector< ACG::Vec4uc > pickFaceColorBuf_;
00406
00409
00412
00413
00414 public:
00415
00421 void updatePickingAny(ACG::GLState& _state );
00422
00429 ACG::Vec4uc * pickAnyColorBuffer(){ return &(pickAnyColorBuf_)[0]; };
00430
00431 private:
00432
00433 std::vector< ACG::Vec4uc > pickAnyColorBuf_;
00434
00437
00440
00441
00442 public:
00449 void setIndexPropertyName( std::string _indexPropertyName );
00450
00457 void setPerFaceTextureCoordinatePropertyName( std::string _perFaceTextureCoordinatePropertyName );
00458
00463 bool perFaceTextureCoordinateAvailable() {
00464 return ( perFaceTextureCoordinateProperty_.is_valid() );
00465 }
00466
00472 bool perFaceTextureIndexAvailable() {
00473 return ( textureIndexProperty_.is_valid() );
00474 }
00475
00480 ACG::Vec2f * perFacePerVertexTextureCoordBuffer(){ return &(perFaceTextureCoordArray_)[0]; };
00481
00489 std::vector< TextureRenderInfo >* textureRenderData(){ return &textureRenderData_; };
00490
00491 private:
00492
00500 OpenMesh::FPropHandleT< int > textureIndexProperty_;
00501
00507 OpenMesh::HPropHandleT< typename Mesh::TexCoord2D > perFaceTextureCoordinateProperty_;
00508
00509 std::vector< ACG::Vec2f > perFaceTextureCoordArray_;
00510
00511 std::vector< TextureRenderInfo > textureRenderData_;
00512
00515 };
00516
00517
00518
00519 }
00520 }
00521
00522 #if defined(INCLUDE_TEMPLATES) && !defined(ACG_STRIP_PROCESSOR_C)
00523 #define ACG_STRIP_PROCESSOR_TEMPLATES
00524 #include "StripProcessorT.cc"
00525 #endif
00526
00527 #endif // ACG_STRIP_PROCESSOR_HH defined
00528