1
/***************************************************************************
2
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
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
***************************************************************************/
23
#include "PreCompiled.h"
25
#include "MeshFeature.h"
26
// inclusion of the generated files (generated out of MeshFeaturePy.xml)
28
#include <Mod/Mesh/App/MeshPy.h>
29
#include <Mod/Mesh/App/MeshFeaturePy.h>
30
#include <Mod/Mesh/App/MeshFeaturePy.cpp>
37
// returns a string which represent the object e.g. when printed in python
38
std::string MeshFeaturePy::representation() const
40
std::stringstream str;
41
str << getFeaturePtr()->getTypeId().getName() << " object at " << getFeaturePtr();
46
PyObject* MeshFeaturePy::countPoints(PyObject* /*args*/)
48
return Py_BuildValue("i", getFeaturePtr()->Mesh.getValue().countPoints());
51
PyObject* MeshFeaturePy::countFacets(PyObject* /*args*/)
53
return Py_BuildValue("i", getFeaturePtr()->Mesh.getValue().countFacets());
56
PyObject* MeshFeaturePy::harmonizeNormals(PyObject* args)
58
if (!PyArg_ParseTuple(args, "")) {
64
Mesh::MeshObject* mesh = getFeaturePtr()->Mesh.startEditing();
65
mesh->harmonizeNormals();
66
getFeaturePtr()->Mesh.finishEditing();
73
PyObject* MeshFeaturePy::smooth(PyObject* args)
76
float d_max = FLOAT_MAX;
77
if (!PyArg_ParseTuple(args, "|if", &iter, &d_max)) {
83
Mesh::Feature* obj = getFeaturePtr();
84
MeshObject* kernel = obj->Mesh.startEditing();
85
kernel->smooth(iter, d_max);
86
obj->Mesh.finishEditing();
93
PyObject* MeshFeaturePy::decimate(PyObject* args)
97
if (PyArg_ParseTuple(args, "ff", &fTol, &fRed)) {
100
Mesh::Feature* obj = getFeaturePtr();
101
MeshObject* kernel = obj->Mesh.startEditing();
102
kernel->decimate(fTol, fRed);
103
obj->Mesh.finishEditing();
112
if (PyArg_ParseTuple(args, "i", &targetSize)) {
115
Mesh::Feature* obj = getFeaturePtr();
116
MeshObject* kernel = obj->Mesh.startEditing();
117
kernel->decimate(targetSize);
118
obj->Mesh.finishEditing();
125
PyErr_SetString(PyExc_ValueError,
126
"decimate(tolerance=float, reduction=float) or decimate(targetSize=int)");
130
PyObject* MeshFeaturePy::removeNonManifolds(PyObject* args)
132
if (!PyArg_ParseTuple(args, "")) {
135
Mesh::Feature* obj = getFeaturePtr();
136
MeshObject* kernel = obj->Mesh.startEditing();
137
kernel->removeNonManifolds();
138
obj->Mesh.finishEditing();
142
PyObject* MeshFeaturePy::removeNonManifoldPoints(PyObject* args)
144
if (!PyArg_ParseTuple(args, "")) {
147
Mesh::Feature* obj = getFeaturePtr();
148
MeshObject* kernel = obj->Mesh.startEditing();
149
kernel->removeNonManifoldPoints();
150
obj->Mesh.finishEditing();
154
PyObject* MeshFeaturePy::fixIndices(PyObject* args)
156
if (!PyArg_ParseTuple(args, "")) {
162
Mesh::Feature* obj = getFeaturePtr();
163
MeshObject* kernel = obj->Mesh.startEditing();
164
kernel->validateIndices();
165
obj->Mesh.finishEditing();
172
PyObject* MeshFeaturePy::fixDegenerations(PyObject* args)
174
float fEpsilon = MeshCore::MeshDefinitions::_fMinPointDistanceP2;
175
if (!PyArg_ParseTuple(args, "|f", &fEpsilon)) {
181
Mesh::Feature* obj = getFeaturePtr();
182
MeshObject* kernel = obj->Mesh.startEditing();
183
kernel->validateDegenerations(fEpsilon);
184
obj->Mesh.finishEditing();
191
PyObject* MeshFeaturePy::removeDuplicatedFacets(PyObject* args)
193
if (!PyArg_ParseTuple(args, "")) {
199
Mesh::Feature* obj = getFeaturePtr();
200
MeshObject* kernel = obj->Mesh.startEditing();
201
kernel->removeDuplicatedFacets();
202
obj->Mesh.finishEditing();
209
PyObject* MeshFeaturePy::removeDuplicatedPoints(PyObject* args)
211
if (!PyArg_ParseTuple(args, "")) {
217
Mesh::Feature* obj = getFeaturePtr();
218
MeshObject* kernel = obj->Mesh.startEditing();
219
kernel->removeDuplicatedPoints();
220
obj->Mesh.finishEditing();
227
PyObject* MeshFeaturePy::fixSelfIntersections(PyObject* args)
229
if (!PyArg_ParseTuple(args, "")) {
233
Mesh::Feature* obj = getFeaturePtr();
234
MeshObject* kernel = obj->Mesh.startEditing();
235
kernel->removeSelfIntersections();
236
obj->Mesh.finishEditing();
238
catch (const Base::Exception& e) {
245
PyObject* MeshFeaturePy::removeFoldsOnSurface(PyObject* args)
247
if (!PyArg_ParseTuple(args, "")) {
251
Mesh::Feature* obj = getFeaturePtr();
252
MeshObject* kernel = obj->Mesh.startEditing();
253
kernel->removeFoldsOnSurface();
254
obj->Mesh.finishEditing();
256
catch (const Base::Exception& e) {
263
PyObject* MeshFeaturePy::removeInvalidPoints(PyObject* args)
265
if (!PyArg_ParseTuple(args, "")) {
269
Mesh::Feature* obj = getFeaturePtr();
270
MeshObject* kernel = obj->Mesh.startEditing();
271
kernel->removeInvalidPoints();
272
obj->Mesh.finishEditing();
274
catch (const Base::Exception& e) {
281
PyObject* MeshFeaturePy::getCustomAttributes(const char* /*attr*/) const
286
int MeshFeaturePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)