23
#include "PreCompiled.h"
25
#include <Base/GeometryPyCXX.h>
26
#include <Base/VectorPy.h>
44
Index(FacetIndex index)
48
friend std::ostream& operator<<(std::ostream& os, Index idx)
50
if (idx.index < MeshCore::FACET_INDEX_MAX) {
62
std::string FacetPy::representation() const
65
FacetPy::PointerType ptr = getFacetPtr();
66
std::stringstream str;
69
str << "(" << ptr->_aclPoints[0].x << ", "
70
<< ptr->_aclPoints[0].y << ", "
71
<< ptr->_aclPoints[0].z << ", Idx="
72
<< ptr->PIndex[0] << "), ";
73
str << "(" << ptr->_aclPoints[1].x << ", "
74
<< ptr->_aclPoints[1].y << ", "
75
<< ptr->_aclPoints[1].z << ", Idx="
76
<< ptr->PIndex[1] << "), ";
77
str << "(" << ptr->_aclPoints[2].x << ", "
78
<< ptr->_aclPoints[2].y << ", "
79
<< ptr->_aclPoints[2].z << ", Idx="
80
<< ptr->PIndex[2] << "), ";
81
str << "Idx=" << Index(ptr->Index) << ", ("
82
<< Index(ptr->NIndex[0]) << ", "
83
<< Index(ptr->NIndex[1]) << ", "
84
<< Index(ptr->NIndex[2]) << ")";
87
str << "(" << ptr->_aclPoints[0].x << ", "
88
<< ptr->_aclPoints[0].y << ", "
89
<< ptr->_aclPoints[0].z << "), ";
90
str << "(" << ptr->_aclPoints[1].x << ", "
91
<< ptr->_aclPoints[1].y << ", "
92
<< ptr->_aclPoints[1].z << "), ";
93
str << "(" << ptr->_aclPoints[2].x << ", "
94
<< ptr->_aclPoints[2].y << ", "
95
<< ptr->_aclPoints[2].z << ")";
103
PyObject* FacetPy::PyMake(struct _typeobject*, PyObject*, PyObject*)
106
return new FacetPy(new Facet);
110
int FacetPy::PyInit(PyObject* args, PyObject* )
112
if (!PyArg_ParseTuple(args, "")) {
118
PyObject* FacetPy::unbound(PyObject* args)
120
if (!PyArg_ParseTuple(args, "")) {
123
getFacetPtr()->Index = MeshCore::FACET_INDEX_MAX;
124
getFacetPtr()->Mesh = nullptr;
128
PyObject* FacetPy::getEdge(PyObject* args)
131
if (!PyArg_ParseTuple(args, "i", &index)) {
135
Edge edge = getFacetPtr()->getEdge(index);
136
return new EdgePy(new Edge(edge));
139
Py::Long FacetPy::getIndex() const
141
return Py::Long((long)getFacetPtr()->Index);
144
Py::Boolean FacetPy::getBound() const
146
return {getFacetPtr()->isBound()};
149
Py::Object FacetPy::getNormal() const
151
Base::VectorPy* normal = new Base::VectorPy(getFacetPtr()->GetNormal());
153
return Py::Object(normal, true);
156
PyObject* FacetPy::intersect(PyObject* args)
159
if (!PyArg_ParseTuple(args, "O!", &FacetPy::Type, &object)) {
162
FacetPy* face = static_cast<FacetPy*>(object);
163
FacetPy::PointerType face_ptr = face->getFacetPtr();
164
FacetPy::PointerType this_ptr = this->getFacetPtr();
165
Base::Vector3f p0, p1;
166
int ret = this_ptr->IntersectWithFacet(*face_ptr, p0, p1);
173
pt.setItem(0, Py::Float(p0.x));
174
pt.setItem(1, Py::Float(p0.y));
175
pt.setItem(2, Py::Float(p0.z));
180
pt.setItem(0, Py::Float(p1.x));
181
pt.setItem(1, Py::Float(p1.y));
182
pt.setItem(2, Py::Float(p1.z));
186
return Py::new_reference_to(sct);
188
catch (const Py::Exception&) {
193
PyObject* FacetPy::isDegenerated(PyObject* args)
195
float fEpsilon = MeshCore::MeshDefinitions::_fMinPointDistanceP2;
196
if (!PyArg_ParseTuple(args, "|f", &fEpsilon)) {
200
FacetPy::PointerType face = this->getFacetPtr();
201
if (!face->isBound()) {
202
throw Py::RuntimeError("Unbound facet");
205
const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
206
MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
207
return Py::new_reference_to(Py::Boolean(tria.IsDegenerated(fEpsilon)));
210
PyObject* FacetPy::isDeformed(PyObject* args)
214
if (!PyArg_ParseTuple(args, "ff", &fMinAngle, &fMaxAngle)) {
218
FacetPy::PointerType face = this->getFacetPtr();
219
if (!face->isBound()) {
220
throw Py::RuntimeError("Unbound facet");
223
float fCosOfMinAngle = cos(fMinAngle);
224
float fCosOfMaxAngle = cos(fMaxAngle);
225
const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
226
MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
227
return Py::new_reference_to(Py::Boolean(tria.IsDeformed(fCosOfMinAngle, fCosOfMaxAngle)));
230
Py::List FacetPy::getPoints() const
232
FacetPy::PointerType face = this->getFacetPtr();
235
for (const auto& vec : face->_aclPoints) {
237
pt.setItem(0, Py::Float(vec.x));
238
pt.setItem(1, Py::Float(vec.y));
239
pt.setItem(2, Py::Float(vec.z));
246
Py::Tuple FacetPy::getPointIndices() const
248
FacetPy::PointerType face = this->getFacetPtr();
249
if (!face->isBound()) {
253
Py::Tuple idxTuple(3);
254
for (int i = 0; i < 3; i++) {
255
idxTuple.setItem(i, Py::Long(face->PIndex[i]));
260
Py::Tuple FacetPy::getNeighbourIndices() const
262
FacetPy::PointerType face = this->getFacetPtr();
263
if (!face->isBound()) {
267
Py::Tuple idxTuple(3);
268
for (int i = 0; i < 3; i++) {
269
auto index = face->NIndex[i];
270
if (index < MeshCore::FACET_INDEX_MAX) {
271
idxTuple.setItem(i, Py::Long(index));
274
idxTuple.setItem(i, Py::Long(-1L));
280
Py::Float FacetPy::getArea() const
282
FacetPy::PointerType face = this->getFacetPtr();
283
if (!face->isBound()) {
284
return Py::Float(0.0);
287
const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
288
MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
289
return Py::Float(tria.Area());
292
Py::Float FacetPy::getAspectRatio() const
294
FacetPy::PointerType face = this->getFacetPtr();
295
if (!face->isBound()) {
296
return Py::Float(-1.0);
299
const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
300
MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
301
return Py::Float(tria.AspectRatio());
304
Py::Float FacetPy::getAspectRatio2() const
306
FacetPy::PointerType face = this->getFacetPtr();
307
if (!face->isBound()) {
308
return Py::Float(-1.0);
311
const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
312
MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
313
return Py::Float(tria.AspectRatio2());
316
Py::Float FacetPy::getRoundness() const
318
FacetPy::PointerType face = this->getFacetPtr();
319
if (!face->isBound()) {
320
return Py::Float(-1.0);
323
const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
324
MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
325
return Py::Float(tria.Roundness());
328
Py::Tuple FacetPy::getCircumCircle() const
330
FacetPy::PointerType face = this->getFacetPtr();
331
if (!face->isBound()) {
335
const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
336
MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
337
Base::Vector3f center;
338
float radius = tria.CenterOfCircumCircle(center);
340
tuple.setItem(0, Py::Vector(center));
341
tuple.setItem(1, Py::Float(radius));
345
Py::Tuple FacetPy::getInCircle() const
347
FacetPy::PointerType face = this->getFacetPtr();
348
if (!face->isBound()) {
352
const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
353
MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
354
Base::Vector3f center;
355
float radius = tria.CenterOfInscribedCircle(center);
357
tuple.setItem(0, Py::Vector(center));
358
tuple.setItem(1, Py::Float(radius));
362
PyObject* FacetPy::getCustomAttributes(const char* ) const
367
int FacetPy::setCustomAttributes(const char* , PyObject* )