Mesh.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Juergen Riegel         <juergen.riegel@web.de>          *
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_MESH_H
00025 #define MESH_MESH_H
00026 
00027 #include <vector>
00028 #include <list>
00029 #include <set>
00030 #include <string>
00031 #include <map>
00032 
00033 #include <Base/Matrix.h>
00034 #include <Base/Vector3D.h>
00035 
00036 #include <App/PropertyStandard.h>
00037 #include <App/PropertyGeo.h>
00038 #include <App/ComplexGeoData.h>
00039 
00040 #include "Core/MeshKernel.h"
00041 #include "Core/MeshIO.h"
00042 #include "Core/Iterator.h"
00043 #include "MeshPoint.h"
00044 #include "Facet.h"
00045 #include "MeshPoint.h"
00046 #include "Segment.h"
00047 
00048 namespace Py {
00049 class List;
00050 }
00051 
00052 namespace MeshCore {
00053 class AbstractPolygonTriangulator;
00054 }
00055 
00056 namespace Mesh
00057 {
00064 class MeshExport MeshObject : public Data::ComplexGeoData
00065 {
00066     TYPESYSTEM_HEADER();
00067 
00068 public:
00069     enum Type {PLANE, CYLINDER, SPHERE};
00070 
00071     // typedef needed for cross-section
00072     typedef std::pair<Base::Vector3f, Base::Vector3f> TPlane;
00073     typedef std::list<std::vector<Base::Vector3f> > TPolylines;
00074 
00075     MeshObject();
00076     explicit MeshObject(const MeshCore::MeshKernel& Kernel);
00077     explicit MeshObject(const MeshCore::MeshKernel& Kernel, const Base::Matrix4D &Mtrx);
00078     MeshObject(const MeshObject&);
00079     ~MeshObject();
00080 
00081     void operator = (const MeshObject&);
00082 
00089     virtual std::vector<const char*> getElementTypes(void) const;
00090     virtual unsigned long countSubElements(const char* Type) const;
00092     virtual Data::Segment* getSubElement(const char* Type, unsigned long) const;
00094     virtual void getFacesFromSubelement(
00095         const Data::Segment*,
00096         std::vector<Base::Vector3d> &Points,
00097         std::vector<Base::Vector3d> &PointNormals,
00098         std::vector<Facet> &faces) const;
00100 
00101     void setTransform(const Base::Matrix4D& rclTrf);
00102     Base::Matrix4D getTransform(void) const;
00103     void transformGeometry(const Base::Matrix4D &rclMat);
00104 
00108     void swap(MeshCore::MeshKernel& Kernel);
00109     void swap(MeshObject& mesh);
00110 
00113     std::string representation() const;
00114     std::string topologyInfo() const;
00115     unsigned long countPoints() const;
00116     unsigned long countFacets() const;
00117     unsigned long countEdges () const;
00118     unsigned long countSegments() const;
00119     bool isSolid() const;
00120     MeshPoint getPoint(unsigned long) const;
00121     Mesh::Facet getFacet(unsigned long) const;
00122     double getSurface() const;
00123     double getVolume() const;
00124     void getFaces(std::vector<Base::Vector3d> &Points,std::vector<Facet> &Topo,
00125         float Accuracy, uint16_t flags=0) const;
00127 
00128     void setKernel(const MeshCore::MeshKernel& m);
00129     MeshCore::MeshKernel& getKernel(void)
00130     { return _kernel; }
00131     const MeshCore::MeshKernel& getKernel(void) const
00132     { return _kernel; }
00133 
00134     virtual Base::BoundBox3d getBoundBox(void)const;
00135 
00138     // Implemented from Persistence
00139     unsigned int getMemSize (void) const;
00140     void Save (Base::Writer &writer) const;
00141     void SaveDocFile (Base::Writer &writer) const;
00142     void Restore(Base::XMLReader &reader);
00143     void RestoreDocFile(Base::Reader &reader);
00144     void save(const char* file,MeshCore::MeshIO::Format f=MeshCore::MeshIO::Undefined,
00145         const MeshCore::Material* mat = 0) const;
00146     void save(std::ostream&) const;
00147     bool load(const char* file);
00148     void load(std::istream&);
00150 
00153     void addFacet(const MeshCore::MeshGeomFacet& facet);
00154     void addFacets(const std::vector<MeshCore::MeshGeomFacet>& facets);
00155     void addFacets(const std::vector<MeshCore::MeshFacet> &facets);
00156     void addFacets(const std::vector<MeshCore::MeshFacet> &facets,
00157                    const std::vector<Base::Vector3f>& points);
00158     void addFacets(const std::vector<Data::ComplexGeoData::Facet> &facets,
00159                    const std::vector<Base::Vector3d>& points);
00160     void setFacets(const std::vector<MeshCore::MeshGeomFacet>& facets);
00161     void setFacets(const std::vector<Data::ComplexGeoData::Facet> &facets,
00162                    const std::vector<Base::Vector3d>& points);
00168     void addMesh(const MeshObject&);
00174     void addMesh(const MeshCore::MeshKernel&);
00175     void deleteFacets(const std::vector<unsigned long>& removeIndices);
00176     void deletePoints(const std::vector<unsigned long>& removeIndices);
00177     std::vector<std::vector<unsigned long> > getComponents() const;
00178     unsigned long countComponents() const;
00179     void removeComponents(unsigned long);
00180     void fillupHoles(unsigned long, int, MeshCore::AbstractPolygonTriangulator&);
00181     void offset(float fSize);
00182     void offsetSpecial2(float fSize);
00183     void offsetSpecial(float fSize, float zmax, float zmin);
00185     void clear(void);
00186     void transformToEigenSystem();
00187     void movePoint(unsigned long, const Base::Vector3d& v);
00188     void setPoint(unsigned long, const Base::Vector3d& v);
00189     void smooth(int iterations, float d_max);
00190     Base::Vector3d getPointNormal(unsigned long) const;
00191     void crossSections(const std::vector<TPlane>&, std::vector<TPolylines> &sections,
00192                        float fMinEps = 1.0e-2f, bool bConnectPolygons = false) const;
00194 
00197     void deleteSelectedFacets();
00198     void deleteSelectedPoints();
00199     void addFacetsToSelection(const std::vector<unsigned long>&) const;
00200     void addPointsToSelection(const std::vector<unsigned long>&) const;
00201     void removeFacetsFromSelection(const std::vector<unsigned long>&) const;
00202     void removePointsFromSelection(const std::vector<unsigned long>&) const;
00203     void getFacetsFromSelection(std::vector<unsigned long>&) const;
00204     void getPointsFromSelection(std::vector<unsigned long>&) const;
00205     void clearFacetSelection() const;
00206     void clearPointSelection() const;
00208 
00211     MeshObject* unite(const MeshObject&) const;
00212     MeshObject* intersect(const MeshObject&) const;
00213     MeshObject* subtract(const MeshObject&) const;
00214     MeshObject* inner(const MeshObject&) const;
00215     MeshObject* outer(const MeshObject&) const;
00217 
00220     void refine();
00221     void optimizeTopology(float);
00222     void optimizeEdges();
00223     void splitEdges();
00224     void splitEdge(unsigned long, unsigned long, const Base::Vector3f&);
00225     void splitFacet(unsigned long, const Base::Vector3f&, const Base::Vector3f&);
00226     void swapEdge(unsigned long, unsigned long);
00227     void collapseEdge(unsigned long, unsigned long);
00228     void collapseFacet(unsigned long);
00229     void collapseFacets(const std::vector<unsigned long>&);
00230     void insertVertex(unsigned long, const Base::Vector3f& v);
00231     void snapVertex(unsigned long, const Base::Vector3f& v);
00233 
00236     unsigned long countNonUniformOrientedFacets() const;
00237     void flipNormals();
00238     void harmonizeNormals();
00239     void validateIndices();
00240     void validateDeformations(float fMaxAngle);
00241     void validateDegenerations();
00242     void removeDuplicatedPoints();
00243     void removeDuplicatedFacets();
00244     bool hasNonManifolds() const;
00245     void removeNonManifolds();
00246     bool hasSelfIntersections() const;
00247     void removeSelfIntersections();
00248     void removeSelfIntersections(const std::vector<unsigned long>&);
00249     void removeFoldsOnSurface();
00250     void removeFullBoundaryFacets();
00252 
00255     void addSegment(const Segment&);
00256     void addSegment(const std::vector<unsigned long>&);
00257     const Segment& getSegment(unsigned long) const;
00258     Segment& getSegment(unsigned long);
00259     MeshObject* meshFromSegment(const std::vector<unsigned long>&) const;
00260     std::vector<Segment> getSegmentsFromType(Type, const Segment& aSegment, float dev) const;
00262 
00265     static MeshObject* createMeshFromList(Py::List& list);
00266     static MeshObject* createSphere(float, int);
00267     static MeshObject* createEllipsoid(float, float, int);
00268     static MeshObject* createCylinder(float, float, int, float, int);
00269     static MeshObject* createCone(float, float, float, int, float, int);
00270     static MeshObject* createTorus(float, float, int);
00271     static MeshObject* createCube(float, float, float);
00272     static MeshObject* createCube(float, float, float, float);
00274 
00275 public:
00276     class MeshExport const_point_iterator
00277     {
00278     public:
00279         const_point_iterator(const MeshObject*, unsigned long index);
00280         const_point_iterator(const const_point_iterator& pi);
00281         ~const_point_iterator();
00282 
00283         const_point_iterator& operator=(const const_point_iterator& fi);
00284         const MeshPoint& operator*();
00285         const MeshPoint* operator->();
00286         bool operator==(const const_point_iterator& fi) const;
00287         bool operator!=(const const_point_iterator& fi) const;
00288         const_point_iterator& operator++();
00289         const_point_iterator& operator--();
00290     private:
00291         void dereference();
00292         const MeshObject* _mesh;
00293         MeshPoint _point;
00294         MeshCore::MeshPointIterator _p_it;
00295     };
00296 
00297     class MeshExport const_facet_iterator
00298     {
00299     public:
00300         const_facet_iterator(const MeshObject*, unsigned long index);
00301         const_facet_iterator(const const_facet_iterator& fi);
00302         ~const_facet_iterator();
00303 
00304         const_facet_iterator& operator=(const const_facet_iterator& fi);
00305         Mesh::Facet& operator*();
00306         Mesh::Facet* operator->();
00307         bool operator==(const const_facet_iterator& fi) const;
00308         bool operator!=(const const_facet_iterator& fi) const;
00309         const_facet_iterator& operator++();
00310         const_facet_iterator& operator--();
00311     private:
00312         void dereference();
00313         const MeshObject* _mesh;
00314         Mesh::Facet _facet;
00315         MeshCore::MeshFacetIterator _f_it;
00316     };
00317 
00320     const_point_iterator points_begin() const
00321     { return const_point_iterator(this, 0); }
00322     const_point_iterator points_end() const
00323     { return const_point_iterator(this, countPoints()); }
00324 
00325     const_facet_iterator facets_begin() const
00326     { return const_facet_iterator(this, 0); }
00327     const_facet_iterator facets_end() const
00328     { return const_facet_iterator(this, countFacets()); }
00329 
00330     typedef std::vector<Segment>::const_iterator const_segment_iterator;
00331     const_segment_iterator segments_begin() const
00332     { return _segments.begin(); }
00333     const_segment_iterator segments_end() const
00334     { return _segments.end(); }
00336 
00337     // friends
00338     friend class Segment;
00339 
00340 private:
00341     void deletedFacets(const std::vector<unsigned long>& remFacets);
00342     void updateMesh(const std::vector<unsigned long>&);
00343     void updateMesh();
00344 
00345 private:
00346     Base::Matrix4D _Mtrx;
00347     MeshCore::MeshKernel _kernel;
00348     std::vector<Segment> _segments;
00349     static float Epsilon;
00350 };
00351 
00352 } // namespace Mesh
00353 
00354 
00355 #endif // MESH_MESH_H

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