Skip to content

Commit

Permalink
SubD Iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
fraguada committed Jan 14, 2025
1 parent 02c1416 commit e34e3f5
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 34 deletions.
118 changes: 96 additions & 22 deletions src/bindings/bnd_subd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -116,14 +127,46 @@ 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);
}
BND_SubDEdgeList::BND_SubDEdgeList(ON_SubD* subd, const ON_ModelComponentReference& compref)
{
m_component_reference = compref;
m_component_ref = compref;
m_subd = subd;
}
Expand All @@ -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)
Expand All @@ -147,16 +190,23 @@ void initSubDBindings(rh3dmpymodule& m)
.def_property_readonly("EdgeCount", &BND_SubDFace::EdgeCount)
.def_property_readonly("Index", &BND_SubDFace::Index)
;

py::class_<BND_SubDEdge>(m, "SubDEdge")
.def_property_readonly("VertexCount", &BND_SubDEdge::VertexCount)
.def_property_readonly("Index", &BND_SubDEdge::Index)
;

py::class_<BND_SubDVertex>(m, "SubDVertex")
.def_property_readonly("EdgeCount", &BND_SubDVertex::EdgeCount)
.def_property_readonly("Index", &BND_SubDVertex::Index)
;
/*
py::class_<BND_SubDFaceList>(m, "SubDFaceList")
.def("__len__", &BND_SubDFaceList::Count)
.def("Find", &BND_SubDFaceList::Find, py::arg("index"))
;
*/
py::class_<BND_SubDFaceIterator>(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)
Expand All @@ -165,25 +215,49 @@ void initSubDBindings(rh3dmpymodule& m)
.def_property_readonly("FaceCount", &BND_SubDFaceIterator::FaceCount)
.def_property_readonly("CurrentFaceIndex", &BND_SubDFaceIterator::CurrentFaceIndex)
;

py::class_<BND_SubDEdgeIterator>(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_<BND_SubDVertexIterator>(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_<BND_SubDEdgeList>(m, "SubDEdgeList")
.def("__len__", &BND_SubDEdgeList::Count)
;
py::class_<BND_SubDVertexList>(m, "SubDVertexList")
.def("__len__", &BND_SubDVertexList::Count)
;

*/
py::class_<BND_SubD, BND_GeometryBase>(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)
;
}

Expand Down
47 changes: 35 additions & 12 deletions src/bindings/bnd_subd.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void initSubDBindings(rh3dmpymodule& m);
void initSubDBindings(void* m);
#endif

/*
class BND_SubDComponent
{
ON_ModelComponentReference m_component_reference;
Expand All @@ -19,6 +20,7 @@ class BND_SubDComponent
protected:
};
*/

class BND_SubDFace {

Expand All @@ -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(); }

};
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -80,7 +87,7 @@ class BND_SubDVertexList {
};
class BND_SubDEdgeList {
ON_ModelComponentReference m_component_reference;
ON_SubD* m_subd = nullptr;
public:
Expand All @@ -89,7 +96,7 @@ class BND_SubDEdgeList {
//class BND_SubDEdge* GetEdge(int i);
};
/*
class BND_SubDFaceList {
ON_SubD* m_subd = nullptr;
Expand All @@ -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(); }
Expand All @@ -126,19 +134,34 @@ 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;
public:
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(); }
Expand Down

0 comments on commit e34e3f5

Please sign in to comment.