From e34e3f5b21a6914578346c17a04f07fd56b9f600 Mon Sep 17 00:00:00 2001 From: fraguada Date: Tue, 14 Jan 2025 17:54:46 +0100 Subject: [PATCH] SubD Iterators --- src/bindings/bnd_subd.cpp | 118 +++++++++++++++++++++++++++++++------- src/bindings/bnd_subd.h | 47 +++++++++++---- 2 files changed, 131 insertions(+), 34 deletions(-) diff --git a/src/bindings/bnd_subd.cpp b/src/bindings/bnd_subd.cpp index 632096fa..4ae48950 100644 --- a/src/bindings/bnd_subd.cpp +++ b/src/bindings/bnd_subd.cpp @@ -16,19 +16,30 @@ BND_SubD::BND_SubD() SetTrackedPointer(new ON_SubD(), nullptr); } - +/* BND_SubDComponent::BND_SubDComponent(ON_SubD* subd, int index, const ON_ModelComponentReference& compref) { - m_component_reference = compref; + m_component_ref = compref; m_subd = subd; m_index = index; } - +*/ // SubDFace -BND_SubDFaceIterator::BND_SubDFaceIterator(ON_SubD* subd) +BND_SubDFace::BND_SubDFace(const class ON_SubDFace* face) { + m_subdface = face; +} + +BND_SubDFaceIterator BND_SubD::GetFaceIterator() const +{ + return BND_SubDFaceIterator(m_subd, m_component_ref); +} + +BND_SubDFaceIterator::BND_SubDFaceIterator(ON_SubD* subd, const ON_ModelComponentReference& compref) +{ + m_component_reference = compref; m_it = subd->FaceIterator(); } @@ -52,16 +63,11 @@ BND_SubDFace* BND_SubDFaceIterator::CurrentFace() const return new BND_SubDFace(m_it.CurrentFace()); } -BND_SubDFace::BND_SubDFace(const class ON_SubDFace* face) -{ - m_subdface = face; -} - /* BND_SubDFace::BND_SubDFace(ON_SubD* subd, int index, const ON_ModelComponentReference& compref) { - m_component_reference = compref; + m_component_ref = compref; m_subd = subd; m_index = index; m_subdface = m_subd->FaceFromId(index); @@ -76,19 +82,24 @@ BND_SubDFaceList BND_SubD::GetFaces() BND_SubDFaceList::BND_SubDFaceList(ON_SubD* subd, const ON_ModelComponentReference& compref) { - m_component_reference = compref; + m_component_ref = compref; m_subd = subd; } BND_SubDFace* BND_SubDFaceList::Find(int index) { - return new BND_SubDFace(m_subd, index, m_component_reference); + return new BND_SubDFace(m_subd, index, m_component_ref); } */ // SubDEdge +BND_SubDEdge::BND_SubDEdge(const class ON_SubDEdge* edge) +{ + m_subdedge = edge; +} + BND_SubDEdgeIterator::BND_SubDEdgeIterator(ON_SubD* subd) { m_it = subd->EdgeIterator(); @@ -116,6 +127,38 @@ BND_SubDEdge* BND_SubDEdgeIterator::CurrentEdge() const // SubDVertex +BND_SubDVertex::BND_SubDVertex(const class ON_SubDVertex* vertex) +{ + m_subdvertex = vertex; +} + +BND_SubDVertexIterator::BND_SubDVertexIterator(ON_SubD* subd) +{ + m_it = subd->VertexIterator(); +} + +BND_SubDVertex* BND_SubDVertexIterator::FirstVertex() +{ + return new BND_SubDVertex(m_it.FirstVertex()); +} + +BND_SubDVertex* BND_SubDVertexIterator::LastVertex() +{ + return new BND_SubDVertex(m_it.LastVertex()); +} + +BND_SubDVertex* BND_SubDVertexIterator::NextVertex() +{ + return new BND_SubDVertex(m_it.NextVertex()); +} + +BND_SubDVertex* BND_SubDVertexIterator::CurrentVertex() const +{ + return new BND_SubDVertex(m_it.CurrentVertex()); +} + +// +/* BND_SubDEdgeList BND_SubD::GetEdges() { return BND_SubDEdgeList(m_subd, m_component_ref); @@ -123,7 +166,7 @@ BND_SubDEdgeList BND_SubD::GetEdges() BND_SubDEdgeList::BND_SubDEdgeList(ON_SubD* subd, const ON_ModelComponentReference& compref) { - m_component_reference = compref; + m_component_ref = compref; m_subd = subd; } @@ -134,11 +177,11 @@ BND_SubDVertexList BND_SubD::GetVertices() BND_SubDVertexList::BND_SubDVertexList(ON_SubD* subd, const ON_ModelComponentReference& compref) { - m_component_reference = compref; + m_component_ref = compref; m_subd = subd; } - +*/ #if defined(ON_PYTHON_COMPILE) void initSubDBindings(rh3dmpymodule& m) @@ -147,6 +190,16 @@ void initSubDBindings(rh3dmpymodule& m) .def_property_readonly("EdgeCount", &BND_SubDFace::EdgeCount) .def_property_readonly("Index", &BND_SubDFace::Index) ; + + py::class_(m, "SubDEdge") + .def_property_readonly("VertexCount", &BND_SubDEdge::VertexCount) + .def_property_readonly("Index", &BND_SubDEdge::Index) + ; + + py::class_(m, "SubDVertex") + .def_property_readonly("EdgeCount", &BND_SubDVertex::EdgeCount) + .def_property_readonly("Index", &BND_SubDVertex::Index) + ; /* py::class_(m, "SubDFaceList") .def("__len__", &BND_SubDFaceList::Count) @@ -154,9 +207,6 @@ void initSubDBindings(rh3dmpymodule& m) ; */ py::class_(m, "SubDFaceIterator") - //.def("CurrentFace", &BND_SubDFaceIterator::CurrentFace) - //.def("NextFace", &BND_SubDFaceIterator::NextFace) - //.def("LastFace", &BND_SubDFaceIterator::LastFace) .def("__len__", &BND_SubDFaceIterator::FaceCount) .def("FirstFace", &BND_SubDFaceIterator::FirstFace) .def("NextFace", &BND_SubDFaceIterator::NextFace) @@ -165,7 +215,27 @@ void initSubDBindings(rh3dmpymodule& m) .def_property_readonly("FaceCount", &BND_SubDFaceIterator::FaceCount) .def_property_readonly("CurrentFaceIndex", &BND_SubDFaceIterator::CurrentFaceIndex) ; + + py::class_(m, "SubDEdgeIterator") + .def("__len__", &BND_SubDEdgeIterator::EdgeCount) + .def("FirstEdge", &BND_SubDEdgeIterator::FirstEdge) + .def("NextEdge", &BND_SubDEdgeIterator::NextEdge) + .def("LastEdge", &BND_SubDEdgeIterator::LastEdge) + .def("CurrentEdge", &BND_SubDEdgeIterator::CurrentEdge) + .def_property_readonly("EdgeCount", &BND_SubDEdgeIterator::EdgeCount) + .def_property_readonly("CurrentEdgeIndex", &BND_SubDEdgeIterator::CurrentEdgeIndex) + ; + py::class_(m, "SubDVertexIterator") + .def("__len__", &BND_SubDVertexIterator::VertexCount) + .def("FirstVertex", &BND_SubDVertexIterator::FirstVertex) + .def("NextVertex", &BND_SubDVertexIterator::NextVertex) + .def("LastVertex", &BND_SubDVertexIterator::LastVertex) + .def("CurrentVertex", &BND_SubDVertexIterator::CurrentVertex) + .def_property_readonly("VertexCount", &BND_SubDVertexIterator::VertexCount) + .def_property_readonly("CurrentVertexIndex", &BND_SubDVertexIterator::CurrentVertexIndex) + ; +/* py::class_(m, "SubDEdgeList") .def("__len__", &BND_SubDEdgeList::Count) ; @@ -173,17 +243,21 @@ void initSubDBindings(rh3dmpymodule& m) py::class_(m, "SubDVertexList") .def("__len__", &BND_SubDVertexList::Count) ; - +*/ py::class_(m, "SubD") .def(py::init<>()) .def_property_readonly("IsSolid", &BND_SubD::IsSolid) .def("ClearEvaluationCache", &BND_SubD::ClearEvaluationCache) .def("UpdateAllTagsAndSectorCoefficients", &BND_SubD::UpdateAllTagsAndSectorCoefficients) .def("Subdivide", &BND_SubD::Subdivide, py::arg("count")) - //.def_property_readonly("Faces", &BND_SubD::GetFaces) + .def_property_readonly("FaceIterator", &BND_SubD::GetFaceIterator) - .def_property_readonly("Edges", &BND_SubD::GetEdges) - .def_property_readonly("Vertices", &BND_SubD::GetVertices) + .def_property_readonly("EdgeIterator", &BND_SubD::GetEdgeIterator) + .def_property_readonly("VertexIterator", &BND_SubD::GetVertexIterator) + + //.def_property_readonly("Faces", &BND_SubD::GetFaces) + //.def_property_readonly("Edges", &BND_SubD::GetEdges) + //.def_property_readonly("Vertices", &BND_SubD::GetVertices) ; } diff --git a/src/bindings/bnd_subd.h b/src/bindings/bnd_subd.h index 4a93f35c..21dff144 100644 --- a/src/bindings/bnd_subd.h +++ b/src/bindings/bnd_subd.h @@ -8,6 +8,7 @@ void initSubDBindings(rh3dmpymodule& m); void initSubDBindings(void* m); #endif +/* class BND_SubDComponent { ON_ModelComponentReference m_component_reference; @@ -19,6 +20,7 @@ class BND_SubDComponent protected: }; +*/ class BND_SubDFace { @@ -28,7 +30,7 @@ class BND_SubDFace { //BND_SubDFace() = default; //BND_SubDFace(ON_SubD* subd, int index, const ON_ModelComponentReference& compref); BND_SubDFace(const ON_SubDFace* face); - int Index() const { return m_subdface->FaceId(); } + unsigned int Index() const { return m_subdface->FaceId(); } int EdgeCount() const { return m_subdface->EdgeCount(); } }; @@ -39,15 +41,20 @@ class BND_SubDEdge { public: BND_SubDEdge(const ON_SubDEdge* edge); - int Index() const { return m_subdedge->EdgeId(); } + unsigned int Index() const { return m_subdedge->EdgeId(); } + int VertexCount() const { return m_subdedge->VertexCount(); } }; -class BND_SubDVertex : public BND_SubDComponent { +class BND_SubDVertex { - ON_SubDVertex* m_subdvertex = nullptr; + const ON_SubDVertex* m_subdvertex = nullptr; public: + BND_SubDVertex(const ON_SubDVertex* vertex); + + unsigned int Index() const { return m_subdvertex->VertexId(); } + // properties @@ -68,9 +75,9 @@ class BND_SubDVertex : public BND_SubDComponent { //public bool SetControlNetPoint(Point3d position, bool bClearNeighborhoodCache) }; - +/* class BND_SubDVertexList { - ON_ModelComponentReference m_component_reference; + ON_SubD* m_subd = nullptr; public: @@ -80,7 +87,7 @@ class BND_SubDVertexList { }; class BND_SubDEdgeList { - ON_ModelComponentReference m_component_reference; + ON_SubD* m_subd = nullptr; public: @@ -89,7 +96,7 @@ class BND_SubDEdgeList { //class BND_SubDEdge* GetEdge(int i); }; -/* + class BND_SubDFaceList { ON_SubD* m_subd = nullptr; @@ -101,9 +108,10 @@ class BND_SubDFaceList { */ class BND_SubDFaceIterator { + ON_ModelComponentReference m_component_reference; ON_SubDFaceIterator m_it; public: - BND_SubDFaceIterator(ON_SubD* subd); + BND_SubDFaceIterator(ON_SubD* subd, const ON_ModelComponentReference& compref); class BND_SubDFace* CurrentFace() const;// { return m_it->CurrentFace(); } class BND_SubDFace* NextFace(); //{ return m_it->NextFace(); } @@ -126,6 +134,19 @@ class BND_SubDEdgeIterator { unsigned int CurrentEdgeIndex() { return m_it.CurrentEdgeIndex(); } }; +class BND_SubDVertexIterator { + ON_SubDVertexIterator m_it; + public: + BND_SubDVertexIterator(ON_SubD* subd); + + class BND_SubDVertex* CurrentVertex() const; + class BND_SubDVertex* NextVertex(); + class BND_SubDVertex* LastVertex(); + class BND_SubDVertex* FirstVertex(); + unsigned int VertexCount() { return m_it.VertexCount(); } + unsigned int CurrentVertexIndex() { return m_it.CurrentVertexIndex(); } +}; + class BND_SubD : public BND_GeometryBase { ON_SubD* m_subd = nullptr; @@ -133,12 +154,14 @@ class BND_SubD : public BND_GeometryBase BND_SubD(ON_SubD* subd, const ON_ModelComponentReference* compref); BND_SubD(); - BND_SubDEdgeList GetEdges(); - BND_SubDVertexList GetVertices(); + //BND_SubDEdgeList GetEdges(); + //BND_SubDVertexList GetVertices(); //BND_SubDFaceList GetFaces(); // iterators - BND_SubDFaceIterator GetFaceIterator() { return BND_SubDFaceIterator(m_subd); } + BND_SubDFaceIterator GetFaceIterator() const;// { return BND_SubDFaceIterator(m_subd, m_component_ref); } + BND_SubDEdgeIterator GetEdgeIterator() { return BND_SubDEdgeIterator(m_subd); } + BND_SubDVertexIterator GetVertexIterator() { return BND_SubDVertexIterator(m_subd); } bool IsSolid() const { return m_subd->IsSolid(); } void ClearEvaluationCache() const { m_subd->ClearEvaluationCache(); }