TexGen
MeshOctreeClasses.h
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#pragma once
21#include "../Octree/Octree.hpp"
22namespace TexGen
23{
24 using namespace hxa7241_graphics;
25 using namespace std;
26
27 class CMesh;
28
30 class COctreeAgentNode : public OctreeAgent<pair<int, XYZ> >
31 {
32 public:
33 COctreeAgentNode(double dTolerance = 0) : m_dTolerance(dTolerance) {};
35
36 protected:
37 bool isOverlappingCell(const pair<int, XYZ>& item, const Vector3f& lowerCorner, const Vector3f& upperCorner) const;
38 dword getSubcellOverlaps(const pair<int, XYZ>& item, const Vector3f& lower, const Vector3f& middle, const Vector3f& upper) const;
39
41 };
42
44 class COctreeVisitorMergeNodes : public OctreeVisitor<pair<int, XYZ> >
45 {
46 public:
47 COctreeVisitorMergeNodes(CMesh &Mesh, double dTolerance = 0) :
48 m_Mesh(Mesh), m_iNumMerged(0), m_dToleranceSquared(dTolerance*dTolerance) {};
50
51 int GetNumMerged() { return m_iNumMerged; }
52
53 protected:
54 void visitRoot(const OctreeCell* pRootCell, const OctreeData& octreeData);
55 void visitBranch(const OctreeCell* subCells[8], const OctreeData& octreeData);
56 void visitLeaf(const Array<const pair<int, XYZ>*>& items, const OctreeData& octreeData);
57
61 vector<vector<int*> > m_NodeElementReferences;
62// vector<bool> m_DeletedNodes;
64 };
65
68 {
69 vector<int> NodeIndices;
70 int iIndex;
71 };
72
75 {
76 public:
80 {
81 if (CopyMe.m_pOctree)
82 m_pOctree = new Octree<MESH_ELEMENT>(*CopyMe.m_pOctree);
84 }
86 {
87 if (m_pOctree)
88 delete m_pOctree;
89 }
90 void Initialise(const Vector3f& positionOfLowerCorner, float sizeOfCube, dword maxItemCountPerCell, dword maxLevelCount)
91 {
92 if (m_pOctree)
93 delete m_pOctree;
94 m_pOctree = new Octree<MESH_ELEMENT>(positionOfLowerCorner, sizeOfCube, maxItemCountPerCell, maxLevelCount);
95 }
96 Octree<MESH_ELEMENT> *GetOctree()
97 {
98 return m_pOctree;
99 }
100 const Octree<MESH_ELEMENT> *GetOctree() const
101 {
102 return m_pOctree;
103 }
104 list<MESH_ELEMENT> &GetElements()
105 {
106 return m_OctreeElements;
107 }
108 const list<MESH_ELEMENT> &GetElements() const
109 {
110 return m_OctreeElements;
111 }
112 protected:
113 Octree<MESH_ELEMENT> *m_pOctree;
114 list<MESH_ELEMENT> m_OctreeElements;
115 };
116
118 class COctreeAgentElement : public OctreeAgent<MESH_ELEMENT>
119 {
120 public:
123
124 protected:
125 bool isOverlappingCell(const MESH_ELEMENT& item, const Vector3f& lowerCorner, const Vector3f& upperCorner) const;
126 dword getSubcellOverlaps(const MESH_ELEMENT& item, const Vector3f& lower, const Vector3f& middle, const Vector3f& upper) const;
127
129 };
130
132 class COctreeVisitorElementNearLine : public OctreeVisitor<MESH_ELEMENT>
133 {
134 public:
136
142 COctreeVisitorElementNearLine(const XYZ &P1, const XYZ &P2, list< vector<int> > &Elements, pair<bool, bool> TrimLine) : m_P1(P1), m_P2(P2), m_Elements(Elements), m_TrimLine(TrimLine) {}
144
145 protected:
146 void visitRoot(const OctreeCell* pRootCell, const OctreeData& octreeData);
147 void visitBranch(const OctreeCell* subCells[8], const OctreeData& octreeData);
148 void visitLeaf(const Array<const MESH_ELEMENT*>& items, const OctreeData& octreeData);
149
150 const XYZ &m_P1;
151 const XYZ &m_P2;
152 list< vector<int> > &m_Elements;
153 pair<bool, bool> m_TrimLine;
154 vector<bool> m_Used;
155 };
156
157}; // namespace TexGen
158
#define NULL
Definition: ShinyConfig.h:50
Class to assist in storing mesh elements in an octree.
const list< MESH_ELEMENT > & GetElements() const
void Initialise(const Vector3f &positionOfLowerCorner, float sizeOfCube, dword maxItemCountPerCell, dword maxLevelCount)
Octree< MESH_ELEMENT > * m_pOctree
list< MESH_ELEMENT > m_OctreeElements
const Octree< MESH_ELEMENT > * GetOctree() const
list< MESH_ELEMENT > & GetElements()
Octree< MESH_ELEMENT > * GetOctree()
CElementsOctree(const CElementsOctree &CopyMe)
Defines the nodes and elements of a surface or volume mesh.
Definition: Mesh.h:58
Octree agent used to add elements to an octree.
dword getSubcellOverlaps(const MESH_ELEMENT &item, const Vector3f &lower, const Vector3f &middle, const Vector3f &upper) const
bool isOverlappingCell(const MESH_ELEMENT &item, const Vector3f &lowerCorner, const Vector3f &upperCorner) const
Octree agent used to add indexed nodes to an octree.
bool isOverlappingCell(const pair< int, XYZ > &item, const Vector3f &lowerCorner, const Vector3f &upperCorner) const
COctreeAgentNode(double dTolerance=0)
dword getSubcellOverlaps(const pair< int, XYZ > &item, const Vector3f &lower, const Vector3f &middle, const Vector3f &upper) const
Octree visitor used to get a list of elements near given line.
void visitBranch(const OctreeCell *subCells[8], const OctreeData &octreeData)
COctreeVisitorElementNearLine(const XYZ &P1, const XYZ &P2, list< vector< int > > &Elements, pair< bool, bool > TrimLine)
Get a list of elements that are likely to intersect with the given line.
void visitRoot(const OctreeCell *pRootCell, const OctreeData &octreeData)
void visitLeaf(const Array< const MESH_ELEMENT * > &items, const OctreeData &octreeData)
Octree visitor used to merge nodes together within a given tolerance.
void visitBranch(const OctreeCell *subCells[8], const OctreeData &octreeData)
void visitRoot(const OctreeCell *pRootCell, const OctreeData &octreeData)
void visitLeaf(const Array< const pair< int, XYZ > * > &items, const OctreeData &octreeData)
vector< vector< int * > > m_NodeElementReferences
COctreeVisitorMergeNodes(CMesh &Mesh, double dTolerance=0)
Namespace containing a series of customised math operations not found in the standard c++ library.
Elements of a given, is used in conjunction with COctreeAgentElement.
vector< int > NodeIndices
Struct for representing points in 3D space.
Definition: mymath.h:56