OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreOutsideMarker.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-2014 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 __OutsideMarker_H__
29 #define __OutsideMarker_H__
30 
31 #include "OgreLodPrerequisites.h"
32 #include "OgreProgressiveMeshGenerator.h"
34 #include <vector>
35 
36 namespace Ogre
37 {
38 
42 {
43 public:
49  OutsideMarker(ProgressiveMeshGenerator::VertexList & vertexList, Real boundingSphereRadius, Real walkAngle, int step);
50  void markOutside();
51  MeshPtr createConvexHullMesh(const String& meshName,
52  const String& resourceGroupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
53 
54 private:
55  typedef ProgressiveMeshGenerator::PMVertex CHVertex;
56 
57  struct CHTriangle {
58  bool removed; // Whether the triangle is excluded from hull.
59  CHVertex* vertex[3];
61  void computeNormal();
62  };
63 
64  typedef std::vector<CHTriangle> CHTriangleList;
65  typedef std::vector<CHTriangle*> CHTrianglePList;
66  typedef std::vector<std::pair<CHVertex*, CHVertex*> > CHEdgeList;
67 
68  const Real mEpsilon;
72  ProgressiveMeshGenerator::VertexList& mVertexListOrig;
75  int mStep;
76 
77  void initHull();
78  void createTriangle(CHVertex* v1, CHVertex* v2, CHVertex* v3);
79  Real getTetrahedronVolume(CHVertex* v0, CHVertex* v1, CHVertex* v2, CHVertex* v3);
80  Real getPointToLineSqraredDistance(CHVertex* x1, CHVertex* x2, CHVertex* vertex);
81  void generateHull();
82  int addVertex(CHVertex* vertex);
83  void addEdge(CHEdgeList& edges, CHVertex* a, CHVertex* b);
84  void cleanHull();
85  bool isVisible(CHTriangle* triangle, Vector3& vertex);
86  CHVertex* getFurthestVertex(CHTriangle* hull);
87  void getVisibleTriangles(const CHVertex* target, CHTrianglePList& visibleTriangles);
88  void getHorizon(const CHTrianglePList& tri, CHEdgeList& );
89  void fillHorizon(CHEdgeList& e, CHVertex* target);
90  void markVertices();
91  template<typename T>
92  void addHullTriangleVertices(std::vector<CHVertex*>& stack, T tri);
93  Real pointToLineDir(const Vector3& ptarget, const Vector3& p0, const Vector3& p1, const Vector3& p2, const Vector3& n);
95  bool isInsideTriangle(const Vector3& ptarget, const CHTriangle& tri);
96  bool isInsideLine(const Vector3& ptarget, const Vector3& p0, const Vector3& p1);
97  bool isSamePosition(const Vector3& p0, const Vector3& p1);
98 };
99 }
100 
101 #endif /* ifndef __OutsideMarker_H__ */
float Real
Software floating point type.
std::vector< std::pair< CHVertex *, CHVertex * > > CHEdgeList
int mStep
Angle limit, when walking inside for marking vertices.
This class will mark vertices of a mesh, which are visible from far away (from outside).
static String DEFAULT_RESOURCE_GROUP_NAME
Default resource group name.
std::vector< CHTriangle > CHTriangleList
CHTriangleList mHull
Amount of allowed floating point error if 4 vertices are on the same plane.
ProgressiveMeshGenerator::PMVertex CHVertex
Returns a mesh containing the Convex Hull shape.
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
#define _OgreLodExport
ProgressiveMeshGenerator::VertexList & mVertexListOrig
Temporary vector for the horizon edges, when inserting a new vertex into the hull.
std::vector< CHTriangle * > CHTrianglePList
Real mWalkAngle
Centroid of the convex hull.
_StringBase String
Definition: OgreCommon.h:53
CHEdgeList mEdges
Temporary vector for addVisibleEdges function (prevent allocation every call).
Vector3 mCentroid
Source of input and output of the algorithm.
CHTrianglePList mVisibleTriangles
Contains the current triangles of the convex hull.