1
/***************************************************************************
2
* Copyright (c) 2005 Imetric 3D GmbH *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#ifndef MESH_HELPERS_H
25
#define MESH_HELPERS_H
29
#include <Base/Vector3D.h>
35
* Helper class for points.
37
struct MeshExport MeshHelpPoint
39
inline void Set (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt);
41
inline bool operator < (const MeshHelpPoint &rclObj) const;
42
inline bool operator == (const MeshHelpPoint &rclObj) const;
44
unsigned long Index (void) const
45
{ return _ulInd >> 2; }
47
unsigned long Corner (void) const
48
{ return _ulInd & 3; }
55
* Helper class for list of points.
57
struct MeshPointBuilder: public std::vector<MeshHelpPoint>
59
inline void Add (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt);
63
* Helper class for edges.
65
struct MeshExport MeshHelpBuilderEdge
67
unsigned long Side (void) const
68
{ return _ulFIndex & 3; }
70
unsigned long Index (void) const
71
{ return _ulFIndex >> 2; }
73
inline void Set (unsigned long ulInd1, unsigned long ulInd2,
74
unsigned long ulSide, unsigned long ulFInd);
76
inline bool operator < (const MeshHelpBuilderEdge &rclObj) const;
78
inline bool operator == (const MeshHelpBuilderEdge &rclObj) const;
81
inline bool operator != (const MeshHelpBuilderEdge &rclObj) const;
83
unsigned long _ulFIndex; // facet index
84
unsigned long _aulInd[2]; // point index
88
* Helper class to build up list of edges.
90
struct MeshEdgeBuilder: public std::vector<MeshHelpBuilderEdge>
92
typedef std::vector<MeshHelpBuilderEdge>::iterator _TIterator;
93
inline void Add (unsigned long ulInd1, unsigned long ulInd2, unsigned long ulSide, unsigned long ulFInd);
96
inline void MeshHelpPoint::Set (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt)
98
_ulInd = (ulFacet << 2) | ulCorner;
102
inline bool MeshHelpPoint::operator < (const MeshHelpPoint &rclObj) const
104
// if (fabs(_clPt.x - rclObj._clPt.x) < MeshDefinitions::_fMinPointDistanceD1)
106
// if (fabs(_clPt.y - rclObj._clPt.y) < MeshDefinitions::_fMinPointDistanceD1)
108
// if (fabs(_clPt.z - rclObj._clPt.z) < MeshDefinitions::_fMinPointDistanceD1)
111
// return _clPt.z < rclObj._clPt.z;
114
// return _clPt.y < rclObj._clPt.y;
117
// return _clPt.x < rclObj._clPt.x;
119
if (_clPt.x == rclObj._clPt.x)
121
if (_clPt.y == rclObj._clPt.y)
122
return _clPt.z < rclObj._clPt.z;
124
return _clPt.y < rclObj._clPt.y;
127
return _clPt.x < rclObj._clPt.x;
130
inline bool MeshHelpPoint::operator == (const MeshHelpPoint &rclObj) const
132
return Base::DistanceP2(_clPt, rclObj._clPt) < MeshDefinitions::_fMinPointDistanceP2;
134
if (fabs(_clPt.x - rclObj._clPt.x) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f))
136
if (fabs(_clPt.y - rclObj._clPt.y) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f))
138
if (fabs(_clPt.z - rclObj._clPt.z) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f))
151
inline void MeshPointBuilder::Add (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt)
154
clObj.Set(ulCorner, ulFacet, rclPt);
158
inline void MeshHelpBuilderEdge::Set ( unsigned long ulInd1, unsigned long ulInd2,
159
unsigned long ulSide, unsigned long ulFInd)
171
_ulFIndex = (ulFInd << 2) | ulSide;
174
inline bool MeshHelpBuilderEdge::operator < (const MeshHelpBuilderEdge &rclObj) const
176
if (_aulInd[0] == rclObj._aulInd[0])
177
return _aulInd[1] < rclObj._aulInd[1];
179
return _aulInd[0] < rclObj._aulInd[0];
182
inline bool MeshHelpBuilderEdge::operator == (const MeshHelpBuilderEdge &rclObj) const
184
return (_aulInd[0] == rclObj._aulInd[0]) && (_aulInd[1] == rclObj._aulInd[1]);
187
inline bool MeshHelpBuilderEdge::operator != (const MeshHelpBuilderEdge &rclObj) const
189
return (_aulInd[0] != rclObj._aulInd[0]) || (_aulInd[1] != rclObj._aulInd[1]);
193
inline void MeshEdgeBuilder::Add (unsigned long ulInd1, unsigned long ulInd2,
194
unsigned long ulSide, unsigned long ulFInd)
196
MeshHelpBuilderEdge clObj;
197
clObj.Set(ulInd1, ulInd2, ulSide, ulFInd);
201
} // namespace MeshCore
203
#endif // MESH_HELPERS_H