1
/***************************************************************************
2
* Copyright (c) Juergen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
24
#ifndef MESH_MESHPROPERTIES_H
25
#define MESH_MESHPROPERTIES_H
33
#include <Base/Handle.h>
34
#include <Base/Matrix.h>
35
#include <Base/Vector3D.h>
37
#include <App/PropertyStandard.h>
38
#include <App/PropertyGeo.h>
40
#include "Core/MeshKernel.h"
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
51
class MeshExport PropertyNormalList : public App::PropertyVectorList
59
virtual ~PropertyNormalList()
62
void transform(const Base::Matrix4D &rclMat);
65
/** Curvature information. */
66
struct MeshExport CurvatureInfo
68
float fMaxCurvature, fMinCurvature;
69
Base::Vector3f cMaxCurvDir, cMinCurvDir;
72
/** The Curvature property class.
73
* @author Werner Mayer
75
class MeshExport PropertyCurvatureList: public App::PropertyLists
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 */
89
PropertyCurvatureList();
90
~PropertyCurvatureList();
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>&);
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);
104
void Save (Base::Writer &writer) const;
105
void Restore(Base::XMLReader &reader);
107
void SaveDocFile (Base::Writer &writer) const;
108
void RestoreDocFile(Base::Reader &reader);
110
/** @name Python interface */
112
PyObject* getPyObject(void);
113
void setPyObject(PyObject *value);
116
App::Property *Copy(void) const;
117
void Paste(const App::Property &from);
119
virtual unsigned int getMemSize (void) const{return _lValueList.size() * sizeof(CurvatureInfo);}
122
std::vector<CurvatureInfo> _lValueList;
125
/** The mesh kernel property class.
126
* @author Werner Mayer
128
class MeshExport PropertyMeshKernel : public App::PropertyComplexGeoData
133
PropertyMeshKernel();
134
~PropertyMeshKernel();
136
/** @name Getter/setter */
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.
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
158
const MeshObject &getValue(void) const;
159
const MeshObject *getValuePtr(void) const;
160
virtual unsigned int getMemSize (void) const;
163
/** @name Getting basic geometric entities */
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;
173
/** @name Modification */
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);
187
/** @name Mesh validation */
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();
200
/** @name Python interface */
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.
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.
212
void setPyObject(PyObject *value);
215
const char* getEditorName(void) const { return "MeshGui::PropertyMeshKernelItem"; }
217
/** @name Save/restore */
219
void Save (Base::Writer &writer) const;
220
void Restore(Base::XMLReader &reader);
222
void SaveDocFile (Base::Writer &writer) const;
223
void RestoreDocFile(Base::Reader &reader);
225
App::Property *Copy(void) const;
226
void Paste(const App::Property &from);
230
Base::Reference<MeshObject> _meshObject;
235
#endif // MESH_MESHPROPERTIES_H