OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreEdgeListBuilder.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __EdgeListBuilder_H__
29 #define __EdgeListBuilder_H__
30 
31 #include "OgrePrerequisites.h"
32 #include "OgreVector4.h"
34 #include "OgreRenderOperation.h"
35 
36 namespace Ogre {
52  {
53  public:
55  struct Triangle {
58  size_t indexSet;
60  size_t vertexSet;
61  size_t vertIndex[3];
62  size_t sharedVertIndex[3];
63  // duplicates eliminated (this buffer is not exposed)
64 
65  Triangle() :indexSet(0), vertexSet(0) {}
66  };
68  struct Edge {
72  size_t triIndex[2];
75  size_t vertIndex[2];
77  size_t sharedVertIndex[2];
79  bool degenerate;
80  };
81 
82  // Array of 4D vector of triangle face normal, which is unit vector orthogonal
83  // to the triangles, plus distance from origin.
84  // Use aligned policy here because we are intended to use in SIMD optimised routines .
85  typedef std::vector<Vector4, STLAllocator<Vector4, CategorisedAlignAllocPolicy<MEMCATEGORY_GEOMETRY> > > TriangleFaceNormalList;
86 
87  // Working vector used when calculating the silhouette.
88  // Use std::vector<char> instead of std::vector<bool> which might implemented
89  // similar bit-fields causing loss performance.
91 
94 
96  struct EdgeGroup
97  {
99  size_t vertexSet;
106  size_t triStart;
108  size_t triCount;
111 
112  };
113 
115 
127  bool isClosed;
128 
129 
139  void updateTriangleLightFacing(const Vector4& lightPos);
145  void updateFaceNormals(size_t vertexSet, const HardwareVertexBufferSharedPtr& positionBuffer);
146 
147 
148 
149  // Debugging method
150  void log(Log* log);
151 
152  };
153 
164  {
165  public:
166 
167  EdgeListBuilder();
168  virtual ~EdgeListBuilder();
174  void addVertexData(const VertexData* vertexData);
185  void addIndexData(const IndexData* indexData, size_t vertexSet = 0,
187 
192  EdgeData* build(void);
193 
195  void log(Log* l);
196  protected:
197 
203  struct CommonVertex {
204  Vector3 position; // location of point in euclidean space
205  size_t index; // place of vertex in common vertex list
206  size_t vertexSet; // The vertex set this came from
207  size_t indexSet; // The index set this was referenced (first) from
208  size_t originalIndex; // place of vertex in original vertex set
209  };
211  struct Geometry {
212  size_t vertexSet; // The vertex data set this geometry data refers to
213  size_t indexSet; // The index data set this geometry data refers to
214  const IndexData* indexData; // The index information which describes the triangles.
215  RenderOperation::OperationType opType; // The operation type used to render this geometry
216  };
218  struct geometryLess {
219  bool operator()(const Geometry& a, const Geometry& b) const
220  {
221  if (a.vertexSet < b.vertexSet) return true;
222  if (a.vertexSet > b.vertexSet) return false;
223  return a.indexSet < b.indexSet;
224  }
225  };
227  struct vectorLess {
228  bool operator()(const Vector3& a, const Vector3& b) const
229  {
230  if (a.x < b.x) return true;
231  if (a.x > b.x) return false;
232  if (a.y < b.y) return true;
233  if (a.y > b.y) return false;
234  return a.z < b.z;
235  }
236  };
237 
241 
252  typedef multimap< std::pair<size_t, size_t>, std::pair<size_t, size_t> >::type EdgeMap;
254 
255  void buildTrianglesEdges(const Geometry &geometry);
256 
258  size_t findOrCreateCommonVertex(const Vector3& vec, size_t vertexSet,
259  size_t indexSet, size_t originalIndex);
261  void connectOrCreateEdge(size_t vertexSet, size_t triangleIndex, size_t vertIndex0, size_t vertIndex1,
262  size_t sharedVertIndex0, size_t sharedVertIndex1);
263  };
267 }
268 #endif
269 
map< Vector3, size_t, vectorLess >::type CommonVertexMap
Map for identifying common vertices.
multimap< std::pair< size_t, size_t >, std::pair< size_t, size_t > >::type EdgeMap
Edge map, used to connect edges.
#define _OgreExport
Definition: OgrePlatform.h:233
Basic triangle structure.
const VertexData * vertexData
Pointer to vertex data used by this edge group.
VertexDataList mVertexDataList
Triangle()
Vertex indexes, relative to a shared vertex buffer with.
size_t indexSet
The set of indexes this triangle came from (NB it is possible that the triangles on one side of an ed...
Comparator for sorting geometries by vertex set.
size_t triStart
Index to main triangles array, indicate the first triangle of this edge group, and all triangles of t...
CommonVertexMap mCommonVertexMap
vector< const VertexData * >::type VertexDataList
bool operator()(const Vector3 &a, const Vector3 &b) const
vector< EdgeGroup >::type EdgeGroupList
General utility class for building edge lists for geometry.
Shared pointer implementation used to share index buffers.
vector< Geometry >::type GeometryList
EdgeList edges
The edges themselves.
A set of indexed geometry data.
bool operator()(const Geometry &a, const Geometry &b) const
A group of edges sharing the same vertex data.
vector< Edge >::type EdgeList
vector< char >::type TriangleLightFacingList
EdgeGroupList edgeGroups
All edge groups of this edge list.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Summary class collecting together index data source information.
bool isClosed
Flag indicate the mesh is manifold.
std::vector< Vector4, STLAllocator< Vector4, CategorisedAlignAllocPolicy< MEMCATEGORY_GEOMETRY > > > TriangleFaceNormalList
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Comparator for unique vertex list.
Summary class collecting together vertex source information.
TriangleFaceNormalList triangleFaceNormals
All triangle face normals.
RenderOperation::OperationType opType
vector< CommonVertex >::type CommonVertexList
A vertex can actually represent several vertices in the final model, because vertices along texture s...
size_t vertexSet
The vertex set these vertices came from.
This class contains the information required to describe the edge connectivity of a given set of vert...
vector< Triangle >::type TriangleList
size_t vertexSet
The vertex set index that contains the vertices for this edge group.
A list of triangles, 3 vertices per triangle.
bool degenerate
Indicates if this is a degenerate edge, ie it does not have 2 triangles.
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
CommonVertexList mVertices
TriangleList triangles
Main triangles array, stores all triangles of this edge list.
size_t triCount
Number triangles of this edge group.
TriangleLightFacingList triangleLightFacings
Triangle light facing states.
OperationType
The rendering operation type to perform.