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

« back to all changes in this revision

Viewing changes to src/Mod/Mesh/App/Core/SetOperations.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) Berthold Grupp          2005                            *
 
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_SETOPERATIONS_H
 
25
#define MESH_SETOPERATIONS_H
 
26
 
 
27
#include <list>
 
28
#include <map>
 
29
#include <set>
 
30
 
 
31
#include "MeshKernel.h"
 
32
#include "Elements.h"
 
33
#include "Iterator.h"
 
34
#include "Visitor.h"
 
35
 
 
36
#include <Base/Builder3D.h>
 
37
 
 
38
// forward declarations
 
39
 
 
40
namespace MeshCore
 
41
{
 
42
 
 
43
class MeshGeomFacet;
 
44
class MeshGeomEdge;
 
45
class MeshBuilder;
 
46
class MeshKernel;
 
47
class MeshFacetGrid;
 
48
class MeshFacetArray;
 
49
class MeshFacetIterator;
 
50
 
 
51
/**
 
52
 * The MeshAlgorithm class provides algorithms base on meshes.
 
53
 */
 
54
class MeshExport SetOperations
 
55
{
 
56
public:
 
57
  enum OperationType { Union, Intersect, Difference, Inner, Outer };
 
58
 
 
59
  /// Construction
 
60
  SetOperations (const MeshKernel &cutMesh1, const MeshKernel &cutMesh2, MeshKernel &result, OperationType opType, float minDistanceToPoint = 1e-5f);
 
61
  /// Destruction
 
62
  virtual ~SetOperations (void);
 
63
 
 
64
public:
 
65
 
 
66
  /** Cut this mesh with another one. The result is a list of polylines
 
67
   * If the distance of the polyline to one of the points is less than minDistanceToPoint the polyline goes direct to the point
 
68
   */
 
69
  void Do ();
 
70
 
 
71
protected:
 
72
  const MeshKernel   &_cutMesh0;             /** Mesh for set operations source 1 */
 
73
  const MeshKernel   &_cutMesh1;             /** Mesh for set operations source 2 */
 
74
  MeshKernel         &_resultMesh;           /** Result mesh */
 
75
  OperationType       _operationType;        /** Set Operation Type */
 
76
  float               _minDistanceToPoint;   /** Minimal distance to facet corner points */
 
77
  float               _saveMinMeshDistance;
 
78
 
 
79
private:
 
80
  // Helper class cutting edge to his two attached facets
 
81
  class Edge
 
82
  {
 
83
    public:
 
84
      MeshPoint         pt1, pt2;              // edge
 
85
 
 
86
      Edge ()
 
87
      {
 
88
      }
 
89
 
 
90
      Edge (MeshPoint p1, MeshPoint p2)
 
91
      {
 
92
        if (p1 < p2)
 
93
        {
 
94
          pt1 = p1;
 
95
          pt2 = p2;
 
96
        }
 
97
        else
 
98
        {
 
99
          pt2 = p1;
 
100
          pt1 = p2;
 
101
        }
 
102
      }
 
103
 
 
104
      bool operator == (const Edge &edge) const
 
105
      {
 
106
        return (pt1 == edge.pt1) && (pt2 == edge.pt2);
 
107
      }
 
108
 
 
109
      bool operator < (const Edge &edge) const
 
110
      {
 
111
        return (pt1 == edge.pt1) ? (pt2 < edge.pt2) : (pt1 < edge.pt1);
 
112
      }
 
113
  };
 
114
 
 
115
  class EdgeInfo
 
116
  {
 
117
    public:
 
118
      int               fcounter[2];           // counter of facets attacted to the edge
 
119
      MeshGeomFacet     facets[2][2];          // Geom-Facets attached to the edge
 
120
      unsigned long     facet[2];              // underlying Facet-Index
 
121
 
 
122
      EdgeInfo ()
 
123
      {
 
124
        fcounter[0] = 0;
 
125
        fcounter[1] = 0;
 
126
      }
 
127
  };
 
128
 
 
129
  //class CollectFacetVisitor : public MeshFacetVisitor
 
130
  //{
 
131
  //  public:
 
132
  //    std::vector<unsigned long> &_facets;
 
133
  //    MeshKernel                 &_mesh;
 
134
  //    std::map<Edge, EdgeInfo>   &_edges;
 
135
  //    int                         _side;
 
136
  //    float                       _mult;
 
137
  //    int                         _addFacets; // 0: add facets to the result 1: do not add facets to the result
 
138
  //    Base::Builder3D& _builder;
 
139
 
 
140
  //    CollectFacetVisitor (MeshKernel& mesh, std::vector<unsigned long>& facets, std::map<Edge, EdgeInfo>& edges, int side, float mult, Base::Builder3D& builder);
 
141
  //    bool Visit (MeshFacet &rclFacet, const MeshFacet &rclFrom, unsigned long ulFInd, unsigned long ulLevel);
 
142
  //    bool AllowVisit (MeshFacet& rclFacet, MeshFacet& rclFrom, unsigned long ulFInd, unsigned long ulLevel, unsigned short neighbourIndex);
 
143
  //};
 
144
 
 
145
  class CollectFacetVisitor : public MeshFacetVisitor
 
146
  {
 
147
    public:
 
148
      std::vector<unsigned long> &_facets;
 
149
      const MeshKernel           &_mesh;
 
150
      std::map<Edge, EdgeInfo>   &_edges;
 
151
      int                         _side;
 
152
      float                       _mult;
 
153
      int                         _addFacets; // 0: add facets to the result 1: do not add facets to the result
 
154
      Base::Builder3D& _builder;
 
155
 
 
156
      CollectFacetVisitor (const MeshKernel& mesh, std::vector<unsigned long>& facets, std::map<Edge, EdgeInfo>& edges, int side, float mult, Base::Builder3D& builder);
 
157
      bool Visit (const MeshFacet &rclFacet, const MeshFacet &rclFrom, unsigned long ulFInd, unsigned long ulLevel);
 
158
      bool AllowVisit (const MeshFacet& rclFacet, const MeshFacet& rclFrom, unsigned long ulFInd, unsigned long ulLevel, unsigned short neighbourIndex);
 
159
  };
 
160
 
 
161
  /** all points from cut */
 
162
  std::set<MeshPoint>       _cutPoints;
 
163
  /** all edges */
 
164
  std::map<Edge, EdgeInfo>  _edges;
 
165
  /** map from facet index to his cutted points (mesh 1 and mesh 2) Key: Facet-Index  Value: List of iterators of set<MeshPoint> */
 
166
  std::map<unsigned long, std::list<std::set<MeshPoint>::iterator> > _facet2points[2];
 
167
  /** Facets collected from region growing */
 
168
  std::vector<MeshGeomFacet> _facetsOf[2];
 
169
 
 
170
  std::vector<MeshGeomFacet> _newMeshFacets[2];
 
171
 
 
172
  /** Cut mesh 1 with mesh 2 */
 
173
  void Cut (std::set<unsigned long>& facetsNotCuttingEdge0, std::set<unsigned long>& facetsCuttingEdge1);
 
174
  /** Trianglute each facets cutted with his cutting points */
 
175
  void TriangulateMesh (const MeshKernel &cutMesh, int side);
 
176
  /** search facets for adding (with region growing) */
 
177
  void CollectFacets (int side, float mult);
 
178
  /** close gap in the mesh */
 
179
  void CloseGaps (MeshBuilder& meshBuilder);
 
180
 
 
181
  /** visual debugger */
 
182
  Base::Builder3D _builder;
 
183
 
 
184
};
 
185
 
 
186
 
 
187
}; // namespace MeshCore
 
188
 
 
189
#endif  // MESH_SETOPERATIONS_H