Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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-2006 Torus Knot Software Ltd
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 
00024 You may alternatively use this source under the terms of a specific version of
00025 the OGRE Unrestricted License provided you have obtained such a license from
00026 Torus Knot Software Ltd.
00027 -----------------------------------------------------------------------------
00028 */
00029 #ifndef __EdgeListBuilder_H__
00030 #define __EdgeListBuilder_H__
00031 
00032 #include "OgrePrerequisites.h"
00033 #include "OgreVector4.h"
00034 #include "OgreHardwareVertexBuffer.h"
00035 #include "OgreRenderOperation.h"
00036 #include "OgreAlignedAllocator.h"
00037 
00038 namespace Ogre {
00039 
00040 
00047     class _OgreExport EdgeData
00048     {
00049     public:
00051         struct Triangle {
00054             size_t indexSet; 
00056             size_t vertexSet;
00057             size_t vertIndex[3];
00058             size_t sharedVertIndex[3]; 
00059                                         // duplicates eliminated (this buffer is not exposed)
00060         };
00062         struct Edge {
00066             size_t triIndex[2];
00069             size_t vertIndex[2];
00071             size_t sharedVertIndex[2];
00073             bool degenerate;
00074         };
00075 
00076         // Array of 4D vector of triangle face normal, which is unit vector othogonal
00077         // to the triangles, plus distance from origin.
00078         // Use aligned allocator here because we are intented to use in SIMD optimised routines .
00079         typedef std::vector<Vector4, AlignedAllocator<Vector4> > TriangleFaceNormalList;
00080 
00081         // Working vector used when calculating the silhouette.
00082         // Use std::vector<char> instead of std::vector<bool> which might implemented
00083         // similar bit-fields causing loss performance.
00084         typedef std::vector<char> TriangleLightFacingList;
00085 
00086         typedef std::vector<Triangle> TriangleList;
00087         typedef std::vector<Edge> EdgeList;
00088 
00090         struct EdgeGroup
00091         {
00093             size_t vertexSet;
00095             const VertexData* vertexData;
00100             size_t triStart;
00102             size_t triCount;
00104             EdgeList edges;
00105 
00106         };
00107 
00108         typedef std::vector<EdgeGroup> EdgeGroupList;
00109 
00113         TriangleList triangles;
00115         TriangleFaceNormalList triangleFaceNormals;
00117         TriangleLightFacingList triangleLightFacings;
00119         EdgeGroupList edgeGroups;
00121         bool isClosed;
00122 
00123 
00133         void updateTriangleLightFacing(const Vector4& lightPos);
00139         void updateFaceNormals(size_t vertexSet, const HardwareVertexBufferSharedPtr& positionBuffer);
00140 
00141 
00142 
00143         // Debugging method
00144         void log(Log* log);
00145         
00146     };
00147 
00157     class _OgreExport EdgeListBuilder 
00158     {
00159     public:
00160 
00161         EdgeListBuilder();
00162         virtual ~EdgeListBuilder();
00168         void addVertexData(const VertexData* vertexData);
00179         void addIndexData(const IndexData* indexData, size_t vertexSet = 0, 
00180             RenderOperation::OperationType opType = RenderOperation::OT_TRIANGLE_LIST);
00181 
00186         EdgeData* build(void);
00187 
00189         void log(Log* l);
00190     protected:
00191 
00197         struct CommonVertex {
00198             Vector3  position;  // location of point in euclidean space
00199             size_t index;       // place of vertex in common vertex list
00200             size_t vertexSet;   // The vertex set this came from
00201             size_t indexSet;    // The index set this was referenced (first) from
00202             size_t originalIndex; // place of vertex in original vertex set
00203         };
00205         struct Geometry {
00206             size_t vertexSet;           // The vertex data set this geometry data refers to
00207             size_t indexSet;            // The index data set this geometry data refers to
00208             const IndexData* indexData; // The index information which describes the triangles.
00209             RenderOperation::OperationType opType;  // The operation type used to render this geometry
00210         };
00212         struct geometryLess {
00213             bool operator()(const Geometry& a, const Geometry& b) const
00214             {
00215                 if (a.vertexSet < b.vertexSet) return true;
00216                 if (a.vertexSet > b.vertexSet) return false;
00217                 return a.indexSet < b.indexSet;
00218             }
00219         };
00221         struct vectorLess {
00222             bool operator()(const Vector3& a, const Vector3& b) const
00223             {
00224                 if (a.x < b.x) return true;
00225                 if (a.x > b.x) return false;
00226                 if (a.y < b.y) return true;
00227                 if (a.y > b.y) return false;
00228                 return a.z < b.z;
00229             }
00230         };
00231 
00232         typedef std::vector<const VertexData*> VertexDataList;
00233         typedef std::vector<Geometry> GeometryList;
00234         typedef std::vector<CommonVertex> CommonVertexList;
00235 
00236         GeometryList mGeometryList;
00237         VertexDataList mVertexDataList;
00238         CommonVertexList mVertices;
00239         EdgeData* mEdgeData;
00241         typedef std::map<Vector3, size_t, vectorLess> CommonVertexMap;
00242         CommonVertexMap mCommonVertexMap;
00246         typedef std::multimap< std::pair<size_t, size_t>, std::pair<size_t, size_t> > EdgeMap;
00247         EdgeMap mEdgeMap;
00248 
00249         void buildTrianglesEdges(const Geometry &geometry);
00250 
00252         size_t findOrCreateCommonVertex(const Vector3& vec, size_t vertexSet, 
00253             size_t indexSet, size_t originalIndex);
00255         void connectOrCreateEdge(size_t vertexSet, size_t triangleIndex, size_t vertIndex0, size_t vertIndex1, 
00256             size_t sharedVertIndex0, size_t sharedVertIndex1);
00257     };
00258 
00259 }
00260 #endif
00261 

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun May 6 10:54:21 2007