~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Mesh/App/Core/Helpers.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2005 Imetric 3D GmbH                                    *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
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.      *
 
10
 *                                                                         *
 
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.                  *
 
15
 *                                                                         *
 
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                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#ifndef MESH_HELPERS_H
 
25
#define MESH_HELPERS_H
 
26
 
 
27
#include "Elements.h"
 
28
 
 
29
#include <Base/Vector3D.h>
 
30
 
 
31
namespace MeshCore {
 
32
 
 
33
 
 
34
/**
 
35
 * Helper class for points.
 
36
 */
 
37
struct MeshExport MeshHelpPoint
 
38
{
 
39
  inline void Set (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt);
 
40
 
 
41
  inline bool operator < (const MeshHelpPoint &rclObj) const;
 
42
  inline bool operator == (const MeshHelpPoint &rclObj) const;
 
43
 
 
44
  unsigned long Index (void) const
 
45
  { return _ulInd >> 2; }
 
46
 
 
47
  unsigned long Corner (void) const
 
48
  { return _ulInd & 3; }
 
49
 
 
50
  MeshPoint _clPt;
 
51
  unsigned long     _ulInd;
 
52
};
 
53
 
 
54
/**
 
55
 * Helper class for list of points.
 
56
 */
 
57
struct MeshPointBuilder: public std::vector<MeshHelpPoint>
 
58
{
 
59
  inline void Add (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt);
 
60
};
 
61
 
 
62
/**
 
63
 * Helper class for edges.
 
64
 */
 
65
struct MeshExport MeshHelpBuilderEdge
 
66
{
 
67
  unsigned long Side (void) const
 
68
  { return _ulFIndex & 3; }
 
69
 
 
70
  unsigned long Index (void) const
 
71
  { return _ulFIndex >> 2; }
 
72
 
 
73
  inline void Set (unsigned long ulInd1, unsigned long ulInd2,
 
74
                                         unsigned long ulSide, unsigned long ulFInd);
 
75
 
 
76
  inline bool operator < (const MeshHelpBuilderEdge &rclObj) const;
 
77
 
 
78
  inline bool operator == (const MeshHelpBuilderEdge &rclObj) const;
 
79
  
 
80
 
 
81
  inline bool operator != (const MeshHelpBuilderEdge &rclObj) const;
 
82
 
 
83
  unsigned long  _ulFIndex;    // facet index
 
84
  unsigned long  _aulInd[2];   // point index
 
85
};
 
86
 
 
87
/**
 
88
 * Helper class to build up list of edges.
 
89
 */
 
90
struct MeshEdgeBuilder: public std::vector<MeshHelpBuilderEdge>
 
91
{
 
92
  typedef std::vector<MeshHelpBuilderEdge>::iterator  _TIterator;
 
93
  inline void Add (unsigned long ulInd1, unsigned long ulInd2, unsigned long ulSide, unsigned long ulFInd);
 
94
};
 
95
 
 
96
inline void MeshHelpPoint::Set (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt)
 
97
{
 
98
  _ulInd = (ulFacet << 2) | ulCorner;
 
99
  _clPt  = rclPt;
 
100
};
 
101
 
 
102
inline bool MeshHelpPoint::operator < (const MeshHelpPoint &rclObj) const
 
103
{
 
104
//   if (fabs(_clPt.x - rclObj._clPt.x) < MeshDefinitions::_fMinPointDistanceD1)
 
105
//   {
 
106
//     if (fabs(_clPt.y - rclObj._clPt.y) < MeshDefinitions::_fMinPointDistanceD1)
 
107
//     {
 
108
//       if (fabs(_clPt.z - rclObj._clPt.z) < MeshDefinitions::_fMinPointDistanceD1)
 
109
//         return FALSE;
 
110
//       else
 
111
//         return _clPt.z < rclObj._clPt.z;
 
112
//     }
 
113
//     else
 
114
//       return _clPt.y < rclObj._clPt.y;
 
115
//   }
 
116
//   else
 
117
//     return _clPt.x < rclObj._clPt.x;
 
118
 
 
119
  if (_clPt.x == rclObj._clPt.x)
 
120
  {
 
121
    if (_clPt.y == rclObj._clPt.y)
 
122
      return _clPt.z < rclObj._clPt.z;
 
123
    else
 
124
      return _clPt.y < rclObj._clPt.y;
 
125
  }
 
126
  else
 
127
    return _clPt.x < rclObj._clPt.x;
 
128
}
 
129
 
 
130
inline bool MeshHelpPoint::operator == (const MeshHelpPoint &rclObj) const
 
131
{
 
132
  return Base::DistanceP2(_clPt, rclObj._clPt) < MeshDefinitions::_fMinPointDistanceP2;
 
133
/*
 
134
  if (fabs(_clPt.x - rclObj._clPt.x) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f))
 
135
  {
 
136
    if (fabs(_clPt.y - rclObj._clPt.y) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f))
 
137
    {
 
138
      if (fabs(_clPt.z - rclObj._clPt.z) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f))
 
139
        return TRUE;
 
140
      else
 
141
        return FALSE;
 
142
    }
 
143
    else
 
144
      return FALSE;
 
145
  }
 
146
  else
 
147
    return FALSE;
 
148
*/
 
149
}
 
150
 
 
151
inline void MeshPointBuilder::Add (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt)
 
152
{
 
153
  MeshHelpPoint  clObj;
 
154
  clObj.Set(ulCorner, ulFacet, rclPt);
 
155
  push_back(clObj);
 
156
}
 
157
 
 
158
inline void MeshHelpBuilderEdge::Set ( unsigned long ulInd1, unsigned long ulInd2,
 
159
                                       unsigned long ulSide, unsigned long ulFInd)
 
160
{
 
161
  if (ulInd1 < ulInd2)
 
162
  {
 
163
    _aulInd[0] = ulInd1;
 
164
    _aulInd[1] = ulInd2; 
 
165
  }
 
166
  else
 
167
  {
 
168
    _aulInd[0] = ulInd2;
 
169
    _aulInd[1] = ulInd1; 
 
170
  }
 
171
  _ulFIndex = (ulFInd << 2) | ulSide;
 
172
}
 
173
 
 
174
inline bool MeshHelpBuilderEdge::operator < (const MeshHelpBuilderEdge &rclObj) const
 
175
{
 
176
  if (_aulInd[0] == rclObj._aulInd[0])
 
177
    return _aulInd[1] < rclObj._aulInd[1];
 
178
  else
 
179
    return _aulInd[0] < rclObj._aulInd[0];
 
180
}
 
181
 
 
182
inline bool MeshHelpBuilderEdge::operator == (const MeshHelpBuilderEdge &rclObj) const
 
183
{
 
184
  return (_aulInd[0] == rclObj._aulInd[0]) && (_aulInd[1] == rclObj._aulInd[1]);
 
185
}
 
186
 
 
187
inline bool MeshHelpBuilderEdge::operator != (const MeshHelpBuilderEdge &rclObj) const
 
188
{
 
189
  return (_aulInd[0] != rclObj._aulInd[0]) || (_aulInd[1] != rclObj._aulInd[1]);
 
190
}
 
191
 
 
192
 
 
193
inline void MeshEdgeBuilder::Add (unsigned long ulInd1, unsigned long ulInd2, 
 
194
                                  unsigned long ulSide, unsigned long ulFInd)
 
195
{
 
196
  MeshHelpBuilderEdge  clObj;
 
197
  clObj.Set(ulInd1, ulInd2, ulSide, ulFInd);
 
198
  push_back(clObj);
 
199
}
 
200
 
 
201
} // namespace MeshCore
 
202
 
 
203
#endif // MESH_HELPERS_H