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

« back to all changes in this revision

Viewing changes to src/Mod/Mesh/App/MeshProperties.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) Juergen Riegel         <juergen.riegel@web.de>          *
 
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_MESHPROPERTIES_H
 
25
#define MESH_MESHPROPERTIES_H
 
26
 
 
27
#include <vector>
 
28
#include <list>
 
29
#include <set>
 
30
#include <string>
 
31
#include <map>
 
32
 
 
33
#include <Base/Handle.h>
 
34
#include <Base/Matrix.h>
 
35
#include <Base/Vector3D.h>
 
36
 
 
37
#include <App/PropertyStandard.h>
 
38
#include <App/PropertyGeo.h>
 
39
 
 
40
#include "Core/MeshKernel.h"
 
41
#include "Mesh.h"
 
42
 
 
43
 
 
44
namespace Mesh
 
45
{
 
46
 
 
47
/** The normals property class.
 
48
 * Note: We need an own class for that to distinguish from the base vector list.
 
49
 * @author Werner Mayer
 
50
 */
 
51
class MeshExport PropertyNormalList : public App::PropertyVectorList
 
52
{
 
53
    TYPESYSTEM_HEADER();
 
54
 
 
55
public:
 
56
    PropertyNormalList()
 
57
    {
 
58
    }
 
59
    virtual ~PropertyNormalList()
 
60
    {
 
61
    }
 
62
    void transform(const Base::Matrix4D &rclMat);
 
63
};
 
64
 
 
65
/** Curvature information. */
 
66
struct MeshExport CurvatureInfo
 
67
{
 
68
    float fMaxCurvature, fMinCurvature;
 
69
    Base::Vector3f cMaxCurvDir, cMinCurvDir;
 
70
};
 
71
 
 
72
/** The Curvature property class.
 
73
 * @author Werner Mayer
 
74
 */
 
75
class MeshExport PropertyCurvatureList: public App::PropertyLists
 
76
{
 
77
    TYPESYSTEM_HEADER();
 
78
 
 
79
public:
 
80
    enum { 
 
81
        MeanCurvature  = 0,  /**< Mean curvature */
 
82
        GaussCurvature = 1,  /**< Gaussian curvature */
 
83
        MaxCurvature   = 2,  /**< Maximum curvature */ 
 
84
        MinCurvature   = 3,  /**< Minimum curvature */
 
85
        AbsCurvature   = 4   /**< Absolute curvature */
 
86
    };
 
87
 
 
88
public:
 
89
    PropertyCurvatureList();
 
90
    ~PropertyCurvatureList();
 
91
 
 
92
    void setSize(int newSize){_lValueList.resize(newSize);}   
 
93
    int getSize(void) const {return _lValueList.size();}   
 
94
    std::vector<float> getCurvature( int tMode) const;
 
95
    void setValue(const CurvatureInfo&);
 
96
    void setValues(const std::vector<CurvatureInfo>&);
 
97
 
 
98
    /// index operator
 
99
    const CurvatureInfo& operator[] (const int idx) const {return _lValueList.operator[] (idx);} 
 
100
    void  set1Value (const int idx, const CurvatureInfo& value){_lValueList.operator[] (idx) = value;}
 
101
    const std::vector<CurvatureInfo> &getValues(void) const{return _lValueList;}
 
102
    void transform(const Base::Matrix4D &rclMat);
 
103
 
 
104
    void Save (Base::Writer &writer) const;
 
105
    void Restore(Base::XMLReader &reader);
 
106
 
 
107
    void SaveDocFile (Base::Writer &writer) const;
 
108
    void RestoreDocFile(Base::Reader &reader);
 
109
 
 
110
    /** @name Python interface */
 
111
    //@{
 
112
    PyObject* getPyObject(void);
 
113
    void setPyObject(PyObject *value);
 
114
    //@}
 
115
 
 
116
    App::Property *Copy(void) const;
 
117
    void Paste(const App::Property &from);
 
118
 
 
119
    virtual unsigned int getMemSize (void) const{return _lValueList.size() * sizeof(CurvatureInfo);}
 
120
 
 
121
private:
 
122
    std::vector<CurvatureInfo> _lValueList;
 
123
};
 
124
 
 
125
/** The mesh kernel property class.
 
126
 * @author Werner Mayer
 
127
 */
 
128
class MeshExport PropertyMeshKernel : public App::PropertyComplexGeoData
 
129
{
 
130
    TYPESYSTEM_HEADER();
 
131
 
 
132
public:
 
133
    PropertyMeshKernel();
 
134
    ~PropertyMeshKernel();
 
135
 
 
136
    /** @name Getter/setter */
 
137
    //@{
 
138
    /** This method references the passed mesh object and takes possession of it,
 
139
     * it does NOT create a copy.
 
140
     * The currently referenced mesh object gets de-referenced and possibly deleted
 
141
     * if its reference counter becomes zero.
 
142
     * However, the mesh gets saved before if a transaction is open at this time.
 
143
     * @note Make sure not to reference the internal mesh pointer pf this class in
 
144
     * client code. This could lead to crashes if not handled properly.
 
145
     */
 
146
    void setValuePtr(MeshObject* m);
 
147
    /** This method sets the mesh by copying the data. */
 
148
    void setValue(const MeshObject& m);
 
149
    /** This method sets the mesh by copying the data. */
 
150
    void setValue(const MeshCore::MeshKernel& m);
 
151
    /** Swaps the mesh data structure. */
 
152
    void swapMesh(MeshObject&);
 
153
    /** Swaps the mesh data structure. */
 
154
    void swapMesh(MeshCore::MeshKernel&);
 
155
    /** Returns a the attached mesh object by reference. It cannot be modified 
 
156
     * from outside.
 
157
     */
 
158
    const MeshObject &getValue(void) const;
 
159
    const MeshObject *getValuePtr(void) const;
 
160
    virtual unsigned int getMemSize (void) const;
 
161
    //@}
 
162
 
 
163
    /** @name Getting basic geometric entities */
 
164
    //@{
 
165
    /** Returns the bounding box around the underlying mesh kernel */
 
166
    Base::BoundBox3d getBoundingBox() const;
 
167
    /** Get faces from object with given accuracy */
 
168
    virtual void getFaces(std::vector<Base::Vector3d> &Points,
 
169
        std::vector<Data::ComplexGeoData::FacetTopo> &Topo,
 
170
        float Accuracy, uint16_t flags=0) const;
 
171
    //@}
 
172
 
 
173
    /** @name Modification */
 
174
    //@{
 
175
    /// Transform the real mesh data
 
176
    void transform(const Base::Matrix4D &rclMat);
 
177
    void deletePointIndices ( const std::vector<unsigned long>& );
 
178
    void deleteFacetIndices ( const std::vector<unsigned long>& );
 
179
    void setPointIndices( const std::vector<std::pair<unsigned long, Base::Vector3f> >& );
 
180
    void append(const std::vector<MeshCore::MeshFacet>& rFaces,
 
181
                const std::vector<Base::Vector3f>& rPoints);
 
182
    void createSegment(const std::vector<unsigned long>& segm);
 
183
    void smooth(int iter, float d_max);
 
184
    void clear();
 
185
    //@}
 
186
 
 
187
    /** @name Mesh validation */
 
188
    //@{
 
189
    void harmonizeNormals();
 
190
    void validateIndices();
 
191
    void validateDeformations(float fMaxAngle);
 
192
    void validateDegenerations();
 
193
    void removeDuplicatedPoints();
 
194
    void removeDuplicatedFacets();
 
195
    void removeNonManifolds();
 
196
    void removeSelfIntersections();
 
197
    void removeFoldsOnSurface();
 
198
    //@}
 
199
 
 
200
    /** @name Python interface */
 
201
    //@{
 
202
    /** Returns a Python wrapper for the referenced mesh object. It does NOT 
 
203
     * create a copy. However, the Python wrapper is marked as \a immutable so
 
204
     * that the mesh object cannot be modified from outside.
 
205
     */
 
206
    PyObject* getPyObject(void);
 
207
    /** This method copies the content, hence creates an new mesh object 
 
208
     * to copy the data. The passed argument can be an instance of the Python
 
209
     * wrapper for the mesh object or simply a list of triangles, i.e. a list
 
210
     * of lists of three floats.
 
211
     */
 
212
    void setPyObject(PyObject *value);
 
213
    //@}
 
214
 
 
215
    const char* getEditorName(void) const { return "MeshGui::PropertyMeshKernelItem"; }
 
216
 
 
217
    /** @name Save/restore */
 
218
    //@{
 
219
    void Save (Base::Writer &writer) const;
 
220
    void Restore(Base::XMLReader &reader);
 
221
 
 
222
    void SaveDocFile (Base::Writer &writer) const;
 
223
    void RestoreDocFile(Base::Reader &reader);
 
224
 
 
225
    App::Property *Copy(void) const;
 
226
    void Paste(const App::Property &from);
 
227
    //@}
 
228
 
 
229
private:
 
230
    Base::Reference<MeshObject> _meshObject;
 
231
};
 
232
 
 
233
} // namespace Mesh
 
234
 
 
235
#endif // MESH_MESHPROPERTIES_H
 
236