Permalink
Browse files

Add project method to Vertex

  • Loading branch information...
1 parent 7e2537b commit 8e9ba91a8d1549c27ccbbd808496e1e2c45efc39 Runar Tenfjord committed Jan 5, 2013
View
4 Makefile
@@ -27,7 +27,7 @@ $(LIB): $(LIBOBJ)
pylib: $(LIB)
@echo lib Makefile - building python extension
- $(PYTHON) setup_build.py build_ext --inplace
+ $(PYTHON) setup_build.py build_ext --inplace --force
docs: pylib
@echo lib Makefile - building documentation
@@ -61,4 +61,4 @@ clean:
-find occmodel -iname '*.so' -exec rm {} \;
-find occmodel -iname '*.pyc' -exec rm {} \;
-find occmodel -iname '*.pyo' -exec rm {} \;
- -find occmodel -iname '*.pyd' -exec rm {} \;
+ -find occmodel -iname '*.pyd' -exec rm {} \;
View
1 occmodel/@src/OCCIncludes.h
@@ -158,4 +158,5 @@ using std::iostream;
#include <BRepFilletAPI_MakeFillet.hxx>
#include <BRepFilletAPI_MakeChamfer.hxx>
#include <BRepFilletAPI_MakeFillet2d.hxx>
+#include <BRepExtrema_DistShapeShape.hxx>
#include <Message_ProgressIndicator.hxx>
View
55 occmodel/@src/OCCModel.cpp
@@ -42,6 +42,59 @@ unsigned int decutf8(unsigned int* state, unsigned int* codep, unsigned int byte
return *state;
}
+int OCCVertex::project(OCCBase *target) {
+ Standard_Real First,Last,Best = 1e200;
+ try {
+ gp_Pnt pnt = BRep_Tool::Pnt(vertex);
+ if (target->shapeType() == TopAbs_EDGE) {
+ Handle(Geom_Curve) Curve = BRep_Tool::Curve(TopoDS::Edge(target->getShape()), First, Last);
+ GeomAPI_ProjectPointOnCurve proj;
+ proj.Init(pnt, Curve, First, Last);
+ gp_Pnt aPnt = proj.NearestPoint();
+ BRepBuilderAPI_MakeVertex mkVertex(aPnt);
+ this->setShape(mkVertex.Vertex());
+ } else if (target->shapeType() == TopAbs_WIRE) {
+ BRepTools_WireExplorer exWire;
+ for (exWire.Init(TopoDS::Wire(target->getShape())); exWire.More(); exWire.Next()) {
+ const TopoDS_Edge& edge = exWire.Current();
+ const Handle(Geom_Curve)& Curve = BRep_Tool::Curve(edge, First, Last);
+ GeomAPI_ProjectPointOnCurve proj;
+ proj.Init(pnt, Curve);
+ gp_Pnt aPnt = proj.NearestPoint();
+ if (proj.LowerDistance() < Best) {
+ Best = proj.LowerDistance();
+ pnt = aPnt;
+ }
+ }
+ BRepBuilderAPI_MakeVertex mkVertex(pnt);
+ this->setShape(mkVertex.Vertex());
+ } else {
+ gp_Pnt org = BRep_Tool::Pnt(vertex);
+ BRepExtrema_DistShapeShape proj(this->getShape(), target->getShape());
+ proj.Perform();
+ for (int i = 1; i <= proj.NbSolution(); i++) {
+ gp_Pnt aPnt = proj.PointOnShape2(i);
+ if (org.Distance(aPnt) < Best) {
+ Best = org.Distance(aPnt);
+ pnt = aPnt;
+ }
+ }
+ BRepBuilderAPI_MakeVertex mkVertex(pnt);
+ this->setShape(mkVertex.Vertex());
+ }
+ } catch(Standard_Failure &err) {
+ Handle_Standard_Failure e = Standard_Failure::Caught();
+ const Standard_CString msg = e->GetMessageString();
+ if (msg != NULL && strlen(msg) > 1) {
+ setErrorMessage(msg);
+ } else {
+ setErrorMessage("Failed to project vertex");
+ }
+ return 0;
+ }
+ return 1;
+}
+
int OCCMesh::extractFaceMesh(const TopoDS_Face& face, bool qualityNormals = false)
{
int vsize = this->vertices.size();
@@ -456,4 +509,4 @@ float MeshOptimizer::calcCacheEfficiency(OCCMesh *mesh,
// 1.0 is theoretical optimum, meaning that each vertex is just transformed exactly one time
float atvr = (float)(3*nindices + misses) / (3*nindices);
return atvr;
-}
+}
View
2 occmodel/@src/OCCModel.h
@@ -53,6 +53,7 @@ struct OptFace
enum BoolOpType {BOOL_FUSE, BOOL_CUT, BOOL_COMMON};
class OCCBase;
+class OCCEdge;
class OCCSolid;
extern char errorMessage[256];
@@ -149,6 +150,7 @@ class OCCVertex : public OCCBase {
gp_Pnt pnt = BRep_Tool::Pnt(vertex);
return pnt.Z();
}
+ int project(OCCBase *target);
bool canSetShape(const TopoDS_Shape& shape) {
return shape.ShapeType() == TopAbs_VERTEX;
}
View
1 occmodel/@src/OCCModelLib.pxd
@@ -85,6 +85,7 @@ cdef extern from "OCCModel.h":
double X()
double Y()
double Z()
+ int project(c_OCCBase *target)
cdef cppclass c_OCCVertexIterator "OCCVertexIterator":
c_OCCVertexIterator(c_OCCBase *arg)
View
15 occmodel/@src/OCCVertex.pxi
@@ -58,6 +58,19 @@ cdef class Vertex(Base):
cpdef double Z(self):
cdef c_OCCVertex *occ = <c_OCCVertex *>self.thisptr
return occ.Z()
+
+ cpdef project(self, Base target):
+ '''
+ Project vertex towards edge.
+ '''
+ cdef c_OCCVertex *occ = <c_OCCVertex *>self.thisptr
+ cdef int ret
+
+ ret = occ.project(<c_OCCBase *>target.thisptr)
+ if not ret:
+ raise OCCError(errorMessage)
+
+ return self
cdef class VertexIterator:
'''
@@ -110,4 +123,4 @@ cdef class VertexIterator:
cpdef reset(self):
'''Restart iteration'''
- self.thisptr.reset()
+ self.thisptr.reset()

0 comments on commit 8e9ba91

Please sign in to comment.