| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| |
|
| | #include <Base/GeometryPyCXX.h>
|
| | #include <Base/VectorPy.h>
|
| |
|
| | #include "Facet.h"
|
| | #include "FacetPy.h"
|
| | #include "FacetPy.cpp"
|
| | #include "EdgePy.h"
|
| | #include "Mesh.h"
|
| |
|
| |
|
| | using namespace Mesh;
|
| |
|
| | namespace
|
| | {
|
| | class Index
|
| | {
|
| | FacetIndex index;
|
| |
|
| | public:
|
| | explicit Index(FacetIndex index)
|
| | : index {index}
|
| | {}
|
| |
|
| | friend std::ostream& operator<<(std::ostream& os, Index idx)
|
| | {
|
| | if (idx.index < MeshCore::FACET_INDEX_MAX) {
|
| | os << idx.index;
|
| | }
|
| | else {
|
| | os << -1;
|
| | }
|
| | return os;
|
| | }
|
| | };
|
| | }
|
| |
|
| |
|
| | std::string FacetPy::representation() const
|
| | {
|
| |
|
| | FacetPy::PointerType ptr = getFacetPtr();
|
| | std::stringstream str;
|
| | str << "Facet (";
|
| | if (ptr->isBound()) {
|
| | str << "(" << ptr->_aclPoints[0].x << ", "
|
| | << ptr->_aclPoints[0].y << ", "
|
| | << ptr->_aclPoints[0].z << ", Idx="
|
| | << ptr->PIndex[0] << "), ";
|
| | str << "(" << ptr->_aclPoints[1].x << ", "
|
| | << ptr->_aclPoints[1].y << ", "
|
| | << ptr->_aclPoints[1].z << ", Idx="
|
| | << ptr->PIndex[1] << "), ";
|
| | str << "(" << ptr->_aclPoints[2].x << ", "
|
| | << ptr->_aclPoints[2].y << ", "
|
| | << ptr->_aclPoints[2].z << ", Idx="
|
| | << ptr->PIndex[2] << "), ";
|
| | str << "Idx=" << Index(ptr->Index) << ", ("
|
| | << Index(ptr->NIndex[0]) << ", "
|
| | << Index(ptr->NIndex[1]) << ", "
|
| | << Index(ptr->NIndex[2]) << ")";
|
| | }
|
| | else {
|
| | str << "(" << ptr->_aclPoints[0].x << ", "
|
| | << ptr->_aclPoints[0].y << ", "
|
| | << ptr->_aclPoints[0].z << "), ";
|
| | str << "(" << ptr->_aclPoints[1].x << ", "
|
| | << ptr->_aclPoints[1].y << ", "
|
| | << ptr->_aclPoints[1].z << "), ";
|
| | str << "(" << ptr->_aclPoints[2].x << ", "
|
| | << ptr->_aclPoints[2].y << ", "
|
| | << ptr->_aclPoints[2].z << ")";
|
| | }
|
| | str << ")";
|
| |
|
| | return str.str();
|
| |
|
| | }
|
| |
|
| | PyObject* FacetPy::PyMake(struct _typeobject*, PyObject*, PyObject*)
|
| | {
|
| |
|
| | return new FacetPy(new Facet);
|
| | }
|
| |
|
| |
|
| | int FacetPy::PyInit(PyObject* args, PyObject* )
|
| | {
|
| | if (!PyArg_ParseTuple(args, "")) {
|
| | return -1;
|
| | }
|
| | return 0;
|
| | }
|
| |
|
| | PyObject* FacetPy::unbound(PyObject* args)
|
| | {
|
| | if (!PyArg_ParseTuple(args, "")) {
|
| | return nullptr;
|
| | }
|
| | getFacetPtr()->Index = MeshCore::FACET_INDEX_MAX;
|
| | getFacetPtr()->Mesh = nullptr;
|
| | Py_Return;
|
| | }
|
| |
|
| | PyObject* FacetPy::getEdge(PyObject* args)
|
| | {
|
| | int index {};
|
| | if (!PyArg_ParseTuple(args, "i", &index)) {
|
| | return nullptr;
|
| | }
|
| |
|
| | Edge edge = getFacetPtr()->getEdge(index);
|
| | return new EdgePy(new Edge(edge));
|
| | }
|
| |
|
| | Py::Long FacetPy::getIndex() const
|
| | {
|
| | return Py::Long((long)getFacetPtr()->Index);
|
| | }
|
| |
|
| | Py::Boolean FacetPy::getBound() const
|
| | {
|
| | return {getFacetPtr()->isBound()};
|
| | }
|
| |
|
| | Py::Object FacetPy::getNormal() const
|
| | {
|
| | Base::VectorPy* normal = new Base::VectorPy(getFacetPtr()->GetNormal());
|
| | normal->setConst();
|
| | return Py::Object(normal, true);
|
| | }
|
| |
|
| | PyObject* FacetPy::intersect(PyObject* args)
|
| | {
|
| | PyObject* object {};
|
| | if (!PyArg_ParseTuple(args, "O!", &FacetPy::Type, &object)) {
|
| | return nullptr;
|
| | }
|
| | FacetPy* face = static_cast<FacetPy*>(object);
|
| | FacetPy::PointerType face_ptr = face->getFacetPtr();
|
| | FacetPy::PointerType this_ptr = this->getFacetPtr();
|
| | Base::Vector3f p0, p1;
|
| | int ret = this_ptr->IntersectWithFacet(*face_ptr, p0, p1);
|
| |
|
| | try {
|
| | Py::List sct;
|
| |
|
| | if (ret > 0) {
|
| | Py::Tuple pt(3);
|
| | pt.setItem(0, Py::Float(p0.x));
|
| | pt.setItem(1, Py::Float(p0.y));
|
| | pt.setItem(2, Py::Float(p0.z));
|
| | sct.append(pt);
|
| | }
|
| | if (ret > 1) {
|
| | Py::Tuple pt(3);
|
| | pt.setItem(0, Py::Float(p1.x));
|
| | pt.setItem(1, Py::Float(p1.y));
|
| | pt.setItem(2, Py::Float(p1.z));
|
| | sct.append(pt);
|
| | }
|
| |
|
| | return Py::new_reference_to(sct);
|
| | }
|
| | catch (const Py::Exception&) {
|
| | return nullptr;
|
| | }
|
| | }
|
| |
|
| | PyObject* FacetPy::isDegenerated(PyObject* args)
|
| | {
|
| | float fEpsilon = MeshCore::MeshDefinitions::_fMinPointDistanceP2;
|
| | if (!PyArg_ParseTuple(args, "|f", &fEpsilon)) {
|
| | return nullptr;
|
| | }
|
| |
|
| | FacetPy::PointerType face = this->getFacetPtr();
|
| | if (!face->isBound()) {
|
| | throw Py::RuntimeError("Unbound facet");
|
| | }
|
| |
|
| | const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
|
| | MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
|
| | return Py::new_reference_to(Py::Boolean(tria.IsDegenerated(fEpsilon)));
|
| | }
|
| |
|
| | PyObject* FacetPy::isDeformed(PyObject* args)
|
| | {
|
| | float fMinAngle {};
|
| | float fMaxAngle {};
|
| | if (!PyArg_ParseTuple(args, "ff", &fMinAngle, &fMaxAngle)) {
|
| | return nullptr;
|
| | }
|
| |
|
| | FacetPy::PointerType face = this->getFacetPtr();
|
| | if (!face->isBound()) {
|
| | throw Py::RuntimeError("Unbound facet");
|
| | }
|
| |
|
| | float fCosOfMinAngle = cos(fMinAngle);
|
| | float fCosOfMaxAngle = cos(fMaxAngle);
|
| | const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
|
| | MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
|
| | return Py::new_reference_to(Py::Boolean(tria.IsDeformed(fCosOfMinAngle, fCosOfMaxAngle)));
|
| | }
|
| |
|
| | Py::List FacetPy::getPoints() const
|
| | {
|
| | FacetPy::PointerType face = this->getFacetPtr();
|
| |
|
| | Py::List pts;
|
| | for (const auto& vec : face->_aclPoints) {
|
| | Py::Tuple pt(3);
|
| | pt.setItem(0, Py::Float(vec.x));
|
| | pt.setItem(1, Py::Float(vec.y));
|
| | pt.setItem(2, Py::Float(vec.z));
|
| | pts.append(pt);
|
| | }
|
| |
|
| | return pts;
|
| | }
|
| |
|
| | Py::Tuple FacetPy::getPointIndices() const
|
| | {
|
| | FacetPy::PointerType face = this->getFacetPtr();
|
| | if (!face->isBound()) {
|
| | return Py::Tuple();
|
| | }
|
| |
|
| | Py::Tuple idxTuple(3);
|
| | for (int i = 0; i < 3; i++) {
|
| | idxTuple.setItem(i, Py::Long(face->PIndex[i]));
|
| | }
|
| | return idxTuple;
|
| | }
|
| |
|
| | Py::Tuple FacetPy::getNeighbourIndices() const
|
| | {
|
| | FacetPy::PointerType face = this->getFacetPtr();
|
| | if (!face->isBound()) {
|
| | return Py::Tuple();
|
| | }
|
| |
|
| | Py::Tuple idxTuple(3);
|
| | for (int i = 0; i < 3; i++) {
|
| | auto index = face->NIndex[i];
|
| | if (index < MeshCore::FACET_INDEX_MAX) {
|
| | idxTuple.setItem(i, Py::Long(index));
|
| | }
|
| | else {
|
| | idxTuple.setItem(i, Py::Long(-1L));
|
| | }
|
| | }
|
| | return idxTuple;
|
| | }
|
| |
|
| | Py::Float FacetPy::getArea() const
|
| | {
|
| | FacetPy::PointerType face = this->getFacetPtr();
|
| | if (!face->isBound()) {
|
| | return Py::Float(0.0);
|
| | }
|
| |
|
| | const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
|
| | MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
|
| | return Py::Float(tria.Area());
|
| | }
|
| |
|
| | Py::Float FacetPy::getAspectRatio() const
|
| | {
|
| | FacetPy::PointerType face = this->getFacetPtr();
|
| | if (!face->isBound()) {
|
| | return Py::Float(-1.0);
|
| | }
|
| |
|
| | const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
|
| | MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
|
| | return Py::Float(tria.AspectRatio());
|
| | }
|
| |
|
| | Py::Float FacetPy::getAspectRatio2() const
|
| | {
|
| | FacetPy::PointerType face = this->getFacetPtr();
|
| | if (!face->isBound()) {
|
| | return Py::Float(-1.0);
|
| | }
|
| |
|
| | const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
|
| | MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
|
| | return Py::Float(tria.AspectRatio2());
|
| | }
|
| |
|
| | Py::Float FacetPy::getRoundness() const
|
| | {
|
| | FacetPy::PointerType face = this->getFacetPtr();
|
| | if (!face->isBound()) {
|
| | return Py::Float(-1.0);
|
| | }
|
| |
|
| | const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
|
| | MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
|
| | return Py::Float(tria.Roundness());
|
| | }
|
| |
|
| | Py::Tuple FacetPy::getCircumCircle() const
|
| | {
|
| | FacetPy::PointerType face = this->getFacetPtr();
|
| | if (!face->isBound()) {
|
| | return Py::None();
|
| | }
|
| |
|
| | const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
|
| | MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
|
| | Base::Vector3f center;
|
| | float radius = tria.CenterOfCircumCircle(center);
|
| | Py::Tuple tuple(2);
|
| | tuple.setItem(0, Py::Vector(center));
|
| | tuple.setItem(1, Py::Float(radius));
|
| | return tuple;
|
| | }
|
| |
|
| | Py::Tuple FacetPy::getInCircle() const
|
| | {
|
| | FacetPy::PointerType face = this->getFacetPtr();
|
| | if (!face->isBound()) {
|
| | return Py::None();
|
| | }
|
| |
|
| | const MeshCore::MeshKernel& kernel = face->Mesh->getKernel();
|
| | MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index);
|
| | Base::Vector3f center;
|
| | float radius = tria.CenterOfInscribedCircle(center);
|
| | Py::Tuple tuple(2);
|
| | tuple.setItem(0, Py::Vector(center));
|
| | tuple.setItem(1, Py::Float(radius));
|
| | return tuple;
|
| | }
|
| |
|
| | PyObject* FacetPy::getCustomAttributes(const char* ) const
|
| | {
|
| | return nullptr;
|
| | }
|
| |
|
| | int FacetPy::setCustomAttributes(const char* , PyObject* )
|
| | {
|
| | return 0;
|
| | }
|
| |
|