Builder.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2005 Berthold Grupp                                     *
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 #ifndef MESH_BUILDER_H
00024 #define MESH_BUILDER_H
00025 
00026 #include <set>
00027 #include <vector>
00028 
00029 #include "MeshKernel.h"
00030 #include <Base/Vector3D.h>
00031 
00032 namespace Base {
00033 class SequencerLauncher;
00034 }
00035 
00036 namespace MeshCore
00037 {
00038 class MeshKernel;
00039 class MeshPoint;
00040 class MeshGeomFacet;
00041 
00059 class MeshExport MeshBuilder
00060 {
00061 private:
00064     class Edge
00065     {
00066         public:
00067         unsigned long   pt1, pt2, facetIdx;
00068 
00069         Edge (unsigned long p1, unsigned long p2, unsigned long idx)
00070         {
00071             facetIdx = idx;
00072             if (p1 > p2)
00073             {
00074                 pt1 = p2;
00075                 pt2 = p1;
00076             }
00077             else
00078             {
00079                 pt1 = p1;
00080                 pt2 = p2;
00081             }
00082         }
00083 
00084         bool operator < (const Edge &e) const
00085         {
00086             return (pt1 == e.pt1) ? (pt2 < e.pt2) : (pt1 < e.pt1);
00087         }
00088 
00089         bool operator > (const Edge &e) const
00090         {
00091             return (pt1 == e.pt1) ? (pt2 > e.pt2) : (pt1 > e.pt1);
00092         }
00093 
00094         bool operator == (const Edge &e) const
00095         {
00096             return (pt1 == e.pt1) && (pt2 == e.pt2);
00097         }
00098     };
00100 
00101     MeshKernel& _meshKernel;
00102     std::set<MeshPoint> _points;
00103     Base::SequencerLauncher* _seq;
00104 
00105     // keep an array of iterators pointing to the vertex inside the set to save memory
00106     typedef std::pair<std::set<MeshPoint>::iterator, bool> MeshPointIterator;
00107     std::vector<MeshPointIterator> _pointsIterator;
00108     unsigned long                               _ptIdx; 
00109 
00110     void SetNeighbourhood  ();
00111     // As it's forbidden to insert a degenerated facet but insert its vertices anyway we must remove them 
00112     void RemoveUnreferencedPoints();
00113 
00114 public:
00115     MeshBuilder(MeshKernel &rclM);
00116     ~MeshBuilder(void);
00117 
00121     void SetTolerance(float);
00122 
00131     void Initialize (unsigned long ctFacets, bool deletion = true);
00132 
00139     void AddFacet (const MeshGeomFacet& facet, bool takeFlag = false, bool takeProperty = false);
00142     void AddFacet (const Base::Vector3f& pt1, const Base::Vector3f& pt2, const Base::Vector3f& pt3, const Base::Vector3f& normal, unsigned char flag = 0, unsigned long prop = 0);
00149     void AddFacet (Base::Vector3f* facetPoints, unsigned char flag = 0, unsigned long prop = 0);
00150 
00159     void Finish (bool freeMemory=false);
00160 
00161     friend class MeshKernel;
00162 
00163 private:
00164     float _fSaveTolerance;
00165 };
00166 
00167 } // namespace MeshCore
00168 
00169 #endif 

Generated on Wed Nov 23 18:59:59 2011 for FreeCAD by  doxygen 1.6.1