FreeCAD

Форк
0
/
MeshFeaturePyImp.cpp 
289 строк · 7.9 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net>     *
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
#include "PreCompiled.h"
24

25
#include "MeshFeature.h"
26
// inclusion of the generated files (generated out of MeshFeaturePy.xml)
27
// clang-format off
28
#include <Mod/Mesh/App/MeshPy.h>
29
#include <Mod/Mesh/App/MeshFeaturePy.h>
30
#include <Mod/Mesh/App/MeshFeaturePy.cpp>
31
// clang-format on
32

33

34
using namespace Mesh;
35

36

37
// returns a string which represent the object e.g. when printed in python
38
std::string MeshFeaturePy::representation() const
39
{
40
    std::stringstream str;
41
    str << getFeaturePtr()->getTypeId().getName() << " object at " << getFeaturePtr();
42

43
    return str.str();
44
}
45

46
PyObject* MeshFeaturePy::countPoints(PyObject* /*args*/)
47
{
48
    return Py_BuildValue("i", getFeaturePtr()->Mesh.getValue().countPoints());
49
}
50

51
PyObject* MeshFeaturePy::countFacets(PyObject* /*args*/)
52
{
53
    return Py_BuildValue("i", getFeaturePtr()->Mesh.getValue().countFacets());
54
}
55

56
PyObject* MeshFeaturePy::harmonizeNormals(PyObject* args)
57
{
58
    if (!PyArg_ParseTuple(args, "")) {
59
        return nullptr;
60
    }
61

62
    PY_TRY
63
    {
64
        Mesh::MeshObject* mesh = getFeaturePtr()->Mesh.startEditing();
65
        mesh->harmonizeNormals();
66
        getFeaturePtr()->Mesh.finishEditing();
67
    }
68
    PY_CATCH;
69

70
    Py_Return;
71
}
72

73
PyObject* MeshFeaturePy::smooth(PyObject* args)
74
{
75
    int iter = 1;
76
    float d_max = FLOAT_MAX;
77
    if (!PyArg_ParseTuple(args, "|if", &iter, &d_max)) {
78
        return nullptr;
79
    }
80

81
    PY_TRY
82
    {
83
        Mesh::Feature* obj = getFeaturePtr();
84
        MeshObject* kernel = obj->Mesh.startEditing();
85
        kernel->smooth(iter, d_max);
86
        obj->Mesh.finishEditing();
87
    }
88
    PY_CATCH;
89

90
    Py_Return;
91
}
92

93
PyObject* MeshFeaturePy::decimate(PyObject* args)
94
{
95
    float fTol {};
96
    float fRed {};
97
    if (PyArg_ParseTuple(args, "ff", &fTol, &fRed)) {
98
        PY_TRY
99
        {
100
            Mesh::Feature* obj = getFeaturePtr();
101
            MeshObject* kernel = obj->Mesh.startEditing();
102
            kernel->decimate(fTol, fRed);
103
            obj->Mesh.finishEditing();
104
        }
105
        PY_CATCH;
106

107
        Py_Return;
108
    }
109

110
    PyErr_Clear();
111
    int targetSize {};
112
    if (PyArg_ParseTuple(args, "i", &targetSize)) {
113
        PY_TRY
114
        {
115
            Mesh::Feature* obj = getFeaturePtr();
116
            MeshObject* kernel = obj->Mesh.startEditing();
117
            kernel->decimate(targetSize);
118
            obj->Mesh.finishEditing();
119
        }
120
        PY_CATCH;
121

122
        Py_Return;
123
    }
124

125
    PyErr_SetString(PyExc_ValueError,
126
                    "decimate(tolerance=float, reduction=float) or decimate(targetSize=int)");
127
    return nullptr;
128
}
129

130
PyObject* MeshFeaturePy::removeNonManifolds(PyObject* args)
131
{
132
    if (!PyArg_ParseTuple(args, "")) {
133
        return nullptr;
134
    }
135
    Mesh::Feature* obj = getFeaturePtr();
136
    MeshObject* kernel = obj->Mesh.startEditing();
137
    kernel->removeNonManifolds();
138
    obj->Mesh.finishEditing();
139
    Py_Return;
140
}
141

142
PyObject* MeshFeaturePy::removeNonManifoldPoints(PyObject* args)
143
{
144
    if (!PyArg_ParseTuple(args, "")) {
145
        return nullptr;
146
    }
147
    Mesh::Feature* obj = getFeaturePtr();
148
    MeshObject* kernel = obj->Mesh.startEditing();
149
    kernel->removeNonManifoldPoints();
150
    obj->Mesh.finishEditing();
151
    Py_Return;
152
}
153

154
PyObject* MeshFeaturePy::fixIndices(PyObject* args)
155
{
156
    if (!PyArg_ParseTuple(args, "")) {
157
        return nullptr;
158
    }
159

160
    PY_TRY
161
    {
162
        Mesh::Feature* obj = getFeaturePtr();
163
        MeshObject* kernel = obj->Mesh.startEditing();
164
        kernel->validateIndices();
165
        obj->Mesh.finishEditing();
166
    }
167
    PY_CATCH;
168

169
    Py_Return;
170
}
171

172
PyObject* MeshFeaturePy::fixDegenerations(PyObject* args)
173
{
174
    float fEpsilon = MeshCore::MeshDefinitions::_fMinPointDistanceP2;
175
    if (!PyArg_ParseTuple(args, "|f", &fEpsilon)) {
176
        return nullptr;
177
    }
178

179
    PY_TRY
180
    {
181
        Mesh::Feature* obj = getFeaturePtr();
182
        MeshObject* kernel = obj->Mesh.startEditing();
183
        kernel->validateDegenerations(fEpsilon);
184
        obj->Mesh.finishEditing();
185
    }
186
    PY_CATCH;
187

188
    Py_Return;
189
}
190

191
PyObject* MeshFeaturePy::removeDuplicatedFacets(PyObject* args)
192
{
193
    if (!PyArg_ParseTuple(args, "")) {
194
        return nullptr;
195
    }
196

197
    PY_TRY
198
    {
199
        Mesh::Feature* obj = getFeaturePtr();
200
        MeshObject* kernel = obj->Mesh.startEditing();
201
        kernel->removeDuplicatedFacets();
202
        obj->Mesh.finishEditing();
203
    }
204
    PY_CATCH;
205

206
    Py_Return;
207
}
208

209
PyObject* MeshFeaturePy::removeDuplicatedPoints(PyObject* args)
210
{
211
    if (!PyArg_ParseTuple(args, "")) {
212
        return nullptr;
213
    }
214

215
    PY_TRY
216
    {
217
        Mesh::Feature* obj = getFeaturePtr();
218
        MeshObject* kernel = obj->Mesh.startEditing();
219
        kernel->removeDuplicatedPoints();
220
        obj->Mesh.finishEditing();
221
    }
222
    PY_CATCH;
223

224
    Py_Return;
225
}
226

227
PyObject* MeshFeaturePy::fixSelfIntersections(PyObject* args)
228
{
229
    if (!PyArg_ParseTuple(args, "")) {
230
        return nullptr;
231
    }
232
    try {
233
        Mesh::Feature* obj = getFeaturePtr();
234
        MeshObject* kernel = obj->Mesh.startEditing();
235
        kernel->removeSelfIntersections();
236
        obj->Mesh.finishEditing();
237
    }
238
    catch (const Base::Exception& e) {
239
        e.setPyException();
240
        return nullptr;
241
    }
242
    Py_Return;
243
}
244

245
PyObject* MeshFeaturePy::removeFoldsOnSurface(PyObject* args)
246
{
247
    if (!PyArg_ParseTuple(args, "")) {
248
        return nullptr;
249
    }
250
    try {
251
        Mesh::Feature* obj = getFeaturePtr();
252
        MeshObject* kernel = obj->Mesh.startEditing();
253
        kernel->removeFoldsOnSurface();
254
        obj->Mesh.finishEditing();
255
    }
256
    catch (const Base::Exception& e) {
257
        e.setPyException();
258
        return nullptr;
259
    }
260
    Py_Return;
261
}
262

263
PyObject* MeshFeaturePy::removeInvalidPoints(PyObject* args)
264
{
265
    if (!PyArg_ParseTuple(args, "")) {
266
        return nullptr;
267
    }
268
    try {
269
        Mesh::Feature* obj = getFeaturePtr();
270
        MeshObject* kernel = obj->Mesh.startEditing();
271
        kernel->removeInvalidPoints();
272
        obj->Mesh.finishEditing();
273
    }
274
    catch (const Base::Exception& e) {
275
        e.setPyException();
276
        return nullptr;
277
    }
278
    Py_Return;
279
}
280

281
PyObject* MeshFeaturePy::getCustomAttributes(const char* /*attr*/) const
282
{
283
    return nullptr;
284
}
285

286
int MeshFeaturePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
287
{
288
    return 0;
289
}
290

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.