Helpers.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2005 Imetric 3D GmbH                                    *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef MESH_HELPERS_H
00025 #define MESH_HELPERS_H
00026 
00027 #include "Elements.h"
00028 
00029 #include <Base/Vector3D.h>
00030 
00031 namespace MeshCore {
00032 
00033 
00037 struct MeshExport MeshHelpPoint
00038 {
00039   inline void Set (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt);
00040 
00041   inline bool operator < (const MeshHelpPoint &rclObj) const;
00042   inline bool operator == (const MeshHelpPoint &rclObj) const;
00043 
00044   unsigned long Index (void) const
00045   { return _ulInd >> 2; }
00046 
00047   unsigned long Corner (void) const
00048   { return _ulInd & 3; }
00049 
00050   MeshPoint _clPt;
00051   unsigned long     _ulInd;
00052 };
00053 
00057 struct MeshPointBuilder: public std::vector<MeshHelpPoint>
00058 {
00059   inline void Add (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt);
00060 };
00061 
00065 struct MeshExport MeshHelpBuilderEdge
00066 {
00067   unsigned long Side (void) const
00068   { return _ulFIndex & 3; }
00069 
00070   unsigned long Index (void) const
00071   { return _ulFIndex >> 2; }
00072 
00073   inline void Set (unsigned long ulInd1, unsigned long ulInd2,
00074                                          unsigned long ulSide, unsigned long ulFInd);
00075 
00076   inline bool operator < (const MeshHelpBuilderEdge &rclObj) const;
00077 
00078   inline bool operator == (const MeshHelpBuilderEdge &rclObj) const;
00079   
00080 
00081   inline bool operator != (const MeshHelpBuilderEdge &rclObj) const;
00082 
00083   unsigned long  _ulFIndex;    // facet index
00084   unsigned long  _aulInd[2];   // point index
00085 };
00086 
00090 struct MeshEdgeBuilder: public std::vector<MeshHelpBuilderEdge>
00091 {
00092   typedef std::vector<MeshHelpBuilderEdge>::iterator  _TIterator;
00093   inline void Add (unsigned long ulInd1, unsigned long ulInd2, unsigned long ulSide, unsigned long ulFInd);
00094 };
00095 
00096 inline void MeshHelpPoint::Set (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt)
00097 {
00098   _ulInd = (ulFacet << 2) | ulCorner;
00099   _clPt  = rclPt;
00100 };
00101 
00102 inline bool MeshHelpPoint::operator < (const MeshHelpPoint &rclObj) const
00103 {
00104 //   if (fabs(_clPt.x - rclObj._clPt.x) < MeshDefinitions::_fMinPointDistanceD1)
00105 //   {
00106 //     if (fabs(_clPt.y - rclObj._clPt.y) < MeshDefinitions::_fMinPointDistanceD1)
00107 //     {
00108 //       if (fabs(_clPt.z - rclObj._clPt.z) < MeshDefinitions::_fMinPointDistanceD1)
00109 //         return FALSE;
00110 //       else
00111 //         return _clPt.z < rclObj._clPt.z;
00112 //     }
00113 //     else
00114 //       return _clPt.y < rclObj._clPt.y;
00115 //   }
00116 //   else
00117 //     return _clPt.x < rclObj._clPt.x;
00118 
00119   if (_clPt.x == rclObj._clPt.x)
00120   {
00121     if (_clPt.y == rclObj._clPt.y)
00122       return _clPt.z < rclObj._clPt.z;
00123     else
00124       return _clPt.y < rclObj._clPt.y;
00125   }
00126   else
00127     return _clPt.x < rclObj._clPt.x;
00128 }
00129 
00130 inline bool MeshHelpPoint::operator == (const MeshHelpPoint &rclObj) const
00131 {
00132   return Base::DistanceP2(_clPt, rclObj._clPt) < MeshDefinitions::_fMinPointDistanceP2;
00133 /*
00134   if (fabs(_clPt.x - rclObj._clPt.x) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f))
00135   {
00136     if (fabs(_clPt.y - rclObj._clPt.y) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f))
00137     {
00138       if (fabs(_clPt.z - rclObj._clPt.z) < (MeshDefinitions::_fMinPointDistanceD1 + 1.0e-2f))
00139         return TRUE;
00140       else
00141         return FALSE;
00142     }
00143     else
00144       return FALSE;
00145   }
00146   else
00147     return FALSE;
00148 */
00149 }
00150 
00151 inline void MeshPointBuilder::Add (unsigned long ulCorner, unsigned long ulFacet, const Base::Vector3f &rclPt)
00152 {
00153   MeshHelpPoint  clObj;
00154   clObj.Set(ulCorner, ulFacet, rclPt);
00155   push_back(clObj);
00156 }
00157 
00158 inline void MeshHelpBuilderEdge::Set ( unsigned long ulInd1, unsigned long ulInd2,
00159                                        unsigned long ulSide, unsigned long ulFInd)
00160 {
00161   if (ulInd1 < ulInd2)
00162   {
00163     _aulInd[0] = ulInd1;
00164     _aulInd[1] = ulInd2; 
00165   }
00166   else
00167   {
00168     _aulInd[0] = ulInd2;
00169     _aulInd[1] = ulInd1; 
00170   }
00171   _ulFIndex = (ulFInd << 2) | ulSide;
00172 }
00173 
00174 inline bool MeshHelpBuilderEdge::operator < (const MeshHelpBuilderEdge &rclObj) const
00175 {
00176   if (_aulInd[0] == rclObj._aulInd[0])
00177     return _aulInd[1] < rclObj._aulInd[1];
00178   else
00179     return _aulInd[0] < rclObj._aulInd[0];
00180 }
00181 
00182 inline bool MeshHelpBuilderEdge::operator == (const MeshHelpBuilderEdge &rclObj) const
00183 {
00184   return (_aulInd[0] == rclObj._aulInd[0]) && (_aulInd[1] == rclObj._aulInd[1]);
00185 }
00186 
00187 inline bool MeshHelpBuilderEdge::operator != (const MeshHelpBuilderEdge &rclObj) const
00188 {
00189   return (_aulInd[0] != rclObj._aulInd[0]) || (_aulInd[1] != rclObj._aulInd[1]);
00190 }
00191 
00192 
00193 inline void MeshEdgeBuilder::Add (unsigned long ulInd1, unsigned long ulInd2, 
00194                                   unsigned long ulSide, unsigned long ulFInd)
00195 {
00196   MeshHelpBuilderEdge  clObj;
00197   clObj.Set(ulInd1, ulInd2, ulSide, ulFInd);
00198   push_back(clObj);
00199 }
00200 
00201 } // namespace MeshCore
00202 
00203 #endif // MESH_HELPERS_H 

Generated on Wed Nov 23 19:00:17 2011 for FreeCAD by  doxygen 1.6.1