# OgreEdgeListBuilder.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __EdgeListBuilder_H__
    00029 #define __EdgeListBuilder_H__
    00030
    00031 #include "OgrePrerequisites.h"
    00032 #include "OgreVector4.h"
    00033 #include "OgreHardwareVertexBuffer.h"
    00034 #include "OgreRenderOperation.h"
    00035
    00036 namespace Ogre {
    00051     class _OgreExport EdgeData : public EdgeDataAlloc
    00052     {
    00053     public:
    00055         struct Triangle {
    00058             size_t indexSet;
    00060             size_t vertexSet;
    00061             size_t vertIndex[3];
    00062             size_t sharedVertIndex[3];
    00063                                         // duplicates eliminated (this buffer is not exposed)
    00064
    00065             Triangle() :indexSet(0), vertexSet(0) {}
    00066         };
    00068         struct Edge {
    00072             size_t triIndex[2];
    00075             size_t vertIndex[2];
    00077             size_t sharedVertIndex[2];
    00079             bool degenerate;
    00080         };
    00081
    00082         // Array of 4D vector of triangle face normal, which is unit vector orthogonal
    00083         // to the triangles, plus distance from origin.
    00084         // Use aligned policy here because we are intended to use in SIMD optimised routines .
    00085         typedef std::vector<Vector4, STLAllocator<Vector4, CategorisedAlignAllocPolicy<MEMCATEGORY_GEOMETRY> > > TriangleFaceNormalList;
    00086
    00087         // Working vector used when calculating the silhouette.
    00088         // Use std::vector<char> instead of std::vector<bool> which might implemented
    00089         // similar bit-fields causing loss performance.
    00090         typedef vector<char>::type TriangleLightFacingList;
    00091
    00092         typedef vector<Triangle>::type TriangleList;
    00093         typedef vector<Edge>::type EdgeList;
    00094
    00096         struct EdgeGroup
    00097         {
    00099             size_t vertexSet;
    00101             const VertexData* vertexData;
    00106             size_t triStart;
    00108             size_t triCount;
    00110             EdgeList edges;
    00111
    00112         };
    00113
    00114         typedef vector<EdgeGroup>::type EdgeGroupList;
    00115
    00119         TriangleList triangles;
    00121         TriangleFaceNormalList triangleFaceNormals;
    00123         TriangleLightFacingList triangleLightFacings;
    00125         EdgeGroupList edgeGroups;
    00127         bool isClosed;
    00128
    00129
    00139         void updateTriangleLightFacing(const Vector4& lightPos);
    00145         void updateFaceNormals(size_t vertexSet, const HardwareVertexBufferSharedPtr& positionBuffer);
    00146
    00147
    00148
    00149         // Debugging method
    00150         void log(Log* log);
    00151
    00152     };
    00153
    00163     class _OgreExport EdgeListBuilder
    00164     {
    00165     public:
    00166
    00167         EdgeListBuilder();
    00168         virtual ~EdgeListBuilder();
    00174         void addVertexData(const VertexData* vertexData);
    00185         void addIndexData(const IndexData* indexData, size_t vertexSet = 0,
    00186             RenderOperation::OperationType opType = RenderOperation::OT_TRIANGLE_LIST);
    00187
    00192         EdgeData* build(void);
    00193
    00195         void log(Log* l);
    00196     protected:
    00197
    00203         struct CommonVertex {
    00204             Vector3  position;  // location of point in euclidean space
    00205             size_t index;       // place of vertex in common vertex list
    00206             size_t vertexSet;   // The vertex set this came from
    00207             size_t indexSet;    // The index set this was referenced (first) from
    00208             size_t originalIndex; // place of vertex in original vertex set
    00209         };
    00211         struct Geometry {
    00212             size_t vertexSet;           // The vertex data set this geometry data refers to
    00213             size_t indexSet;            // The index data set this geometry data refers to
    00214             const IndexData* indexData; // The index information which describes the triangles.
    00215             RenderOperation::OperationType opType;  // The operation type used to render this geometry
    00216         };
    00218         struct geometryLess {
    00219             bool operator()(const Geometry& a, const Geometry& b) const
    00220             {
    00221                 if (a.vertexSet < b.vertexSet) return true;
    00222                 if (a.vertexSet > b.vertexSet) return false;
    00223                 return a.indexSet < b.indexSet;
    00224             }
    00225         };
    00227         struct vectorLess {
    00228             bool operator()(const Vector3& a, const Vector3& b) const
    00229             {
    00230                 if (a.x < b.x) return true;
    00231                 if (a.x > b.x) return false;
    00232                 if (a.y < b.y) return true;
    00233                 if (a.y > b.y) return false;
    00234                 return a.z < b.z;
    00235             }
    00236         };
    00237
    00238         typedef vector<const VertexData*>::type VertexDataList;
    00239         typedef vector<Geometry>::type GeometryList;
    00240         typedef vector<CommonVertex>::type CommonVertexList;
    00241
    00242         GeometryList mGeometryList;
    00243         VertexDataList mVertexDataList;
    00244         CommonVertexList mVertices;
    00245         EdgeData* mEdgeData;
    00247         typedef map<Vector3, size_t, vectorLess>::type CommonVertexMap;
    00248         CommonVertexMap mCommonVertexMap;
    00252         typedef multimap< std::pair<size_t, size_t>, std::pair<size_t, size_t> >::type EdgeMap;
    00253         EdgeMap mEdgeMap;
    00254
    00255         void buildTrianglesEdges(const Geometry &geometry);
    00256
    00258         size_t findOrCreateCommonVertex(const Vector3& vec, size_t vertexSet,
    00259             size_t indexSet, size_t originalIndex);
    00261         void connectOrCreateEdge(size_t vertexSet, size_t triangleIndex, size_t vertIndex0, size_t vertIndex1,
    00262             size_t sharedVertIndex0, size_t sharedVertIndex1);
    00263     };
    00267 }
    00268 #endif
    00269

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun May 8 2011 20:28:08