PyObject* TopoShapeEdgePy::discretize(PyObject *args) { PyObject* defl_or_num; if (!PyArg_ParseTuple(args, "O", &defl_or_num)) return 0; try { BRepAdaptor_Curve adapt(TopoDS::Edge(getTopoShapePtr()->_Shape)); GCPnts_UniformAbscissa discretizer; if (PyInt_Check(defl_or_num)) { int num = PyInt_AsLong(defl_or_num); discretizer.Initialize (adapt, num); } else if (PyFloat_Check(defl_or_num)) { double defl = PyFloat_AsDouble(defl_or_num); discretizer.Initialize (adapt, defl); } else { PyErr_SetString(PyExc_TypeError, "Either int or float expected"); return 0; } if (discretizer.IsDone () && discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); for (int i=1; i<=nbPoints; i++) { gp_Pnt p = adapt.Value (discretizer.Parameter (i)); points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); } return Py::new_reference_to(points); } else { PyErr_SetString(PyExc_Exception, "Descretization of curve failed"); return 0; } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PyExc_Exception, e->GetMessageString()); return 0; } PyErr_SetString(PyExc_Exception, "Geometry is not a curve"); return 0; }
void ImpExpDxfWrite::exportPolyline(BRepAdaptor_Curve& c) { LWPolyDataOut pd; pd.Flag = c.IsClosed(); pd.Elev = 0.0; pd.Thick = 0.0; pd.Extr.x = 0.0; pd.Extr.y = 0.0; pd.Extr.z = 1.0; pd.nVert = 0; GCPnts_UniformAbscissa discretizer; discretizer.Initialize (c, optionMaxLength); std::vector<point3D> points; if (discretizer.IsDone () && discretizer.NbPoints () > 0) { int nbPoints = discretizer.NbPoints (); for (int i=1; i<=nbPoints; i++) { gp_Pnt p = c.Value (discretizer.Parameter (i)); pd.Verts.push_back(gPntTopoint3D(p)); } pd.nVert = discretizer.NbPoints (); writePolyline(pd); } }
PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds) { try { Handle_Geom_Geometry g = getGeometryPtr()->handle(); Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); if (c.IsNull()) { PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); return 0; } GeomAdaptor_Curve adapt(c); bool uniformAbscissaPoints = false; bool uniformAbscissaDistance = false; int numPoints = -1; double distance = -1; double first = adapt.FirstParameter(); double last = adapt.LastParameter(); // use no kwds PyObject* dist_or_num; if (PyArg_ParseTuple(args, "O", &dist_or_num)) { if (PyInt_Check(dist_or_num)) { numPoints = PyInt_AsLong(dist_or_num); uniformAbscissaPoints = true; } else if (PyFloat_Check(dist_or_num)) { distance = PyFloat_AsDouble(dist_or_num); uniformAbscissaDistance = true; } else { PyErr_SetString(PyExc_TypeError, "Either int or float expected"); return 0; } } else { // use Number kwds static char* kwds_numPoints[] = {"Number","First","Last",NULL}; PyErr_Clear(); if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_numPoints, &numPoints, &first, &last)) { uniformAbscissaPoints = true; } else { // use Abscissa kwds static char* kwds_Distance[] = {"Distance","First","Last",NULL}; PyErr_Clear(); if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Distance, &distance, &first, &last)) { uniformAbscissaDistance = true; } } } if (uniformAbscissaPoints || uniformAbscissaDistance) { GCPnts_UniformAbscissa discretizer; if (uniformAbscissaPoints) discretizer.Initialize (adapt, numPoints, first, last); else discretizer.Initialize (adapt, distance, first, last); if (discretizer.IsDone () && discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); for (int i=1; i<=nbPoints; i++) { gp_Pnt p = adapt.Value (discretizer.Parameter (i)); points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); } return Py::new_reference_to(points); } else { PyErr_SetString(PartExceptionOCCError, "Discretization of curve failed"); return 0; } } // use Deflection kwds static char* kwds_Deflection[] = {"Deflection","First","Last",NULL}; PyErr_Clear(); double deflection; if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Deflection, &deflection, &first, &last)) { GCPnts_UniformDeflection discretizer(adapt, deflection, first, last); if (discretizer.IsDone () && discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); for (int i=1; i<=nbPoints; i++) { gp_Pnt p = discretizer.Value (i); points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); } return Py::new_reference_to(points); } else { PyErr_SetString(PartExceptionOCCError, "Discretization of curve failed"); return 0; } } // use TangentialDeflection kwds static char* kwds_TangentialDeflection[] = {"Angular","Curvature","First","Last","Minimum",NULL}; PyErr_Clear(); double angular; double curvature; int minimumPoints = 2; if (PyArg_ParseTupleAndKeywords(args, kwds, "dd|ddi", kwds_TangentialDeflection, &angular, &curvature, &first, &last, &minimumPoints)) { GCPnts_TangentialDeflection discretizer(adapt, first, last, angular, curvature, minimumPoints); if (discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); for (int i=1; i<=nbPoints; i++) { gp_Pnt p = discretizer.Value (i); points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); } return Py::new_reference_to(points); } else { PyErr_SetString(PartExceptionOCCError, "Discretization of curve failed"); return 0; } } // use QuasiNumber kwds static char* kwds_QuasiNumPoints[] = {"QuasiNumber","First","Last",NULL}; PyErr_Clear(); int quasiNumPoints; if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_QuasiNumPoints, &quasiNumPoints, &first, &last)) { GCPnts_QuasiUniformAbscissa discretizer(adapt, quasiNumPoints, first, last); if (discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); for (int i=1; i<=nbPoints; i++) { gp_Pnt p = adapt.Value (discretizer.Parameter (i)); points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); } return Py::new_reference_to(points); } else { PyErr_SetString(PartExceptionOCCError, "Discretization of curve failed"); return 0; } } // use QuasiDeflection kwds static char* kwds_QuasiDeflection[] = {"QuasiDeflection","First","Last",NULL}; PyErr_Clear(); double quasiDeflection; if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_QuasiDeflection, &quasiDeflection, &first, &last)) { GCPnts_QuasiUniformDeflection discretizer(adapt, quasiDeflection, first, last); if (discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); for (int i=1; i<=nbPoints; i++) { gp_Pnt p = discretizer.Value (i); points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); } return Py::new_reference_to(points); } else { PyErr_SetString(PartExceptionOCCError, "Discretization of curve failed"); return 0; } } } catch (const Base::Exception& e) { PyErr_SetString(PartExceptionOCCError, e.what()); return 0; } PyErr_SetString(PartExceptionOCCError,"Wrong arguments"); return 0; }
DrawingLineWallCtrller::DrawingLineWallCtrller() { MeshBuf_ = nullptr; LineMeshBuf_ = nullptr; { PathMeshBuf_ = new irr::scene::SMeshBuffer; PathMeshBuf_->getMaterial().Lighting = false; PathMeshBuf_->getMaterial().ZWriteEnable = false; PathMeshBuf_->getMaterial().BackfaceCulling = false; PathMeshBuf_->getMaterial().Thickness = 3; PathMeshBuf_->getMaterial().MaterialType = IrrEngine::GetInstance()->GetShaderType(EST_LINE); PathMeshBuf_->getMaterial().DiffuseColor = s_LineColor; } { TmpRect_ = new irr::scene::SMeshBuffer; irr::core::vector3df defaultPos; auto smeshBuf = static_cast<irr::scene::SMeshBuffer*>(TmpRect_); smeshBuf->Vertices.reallocate(4); smeshBuf->Vertices.push_back(irr::video::S3DVertex(defaultPos, s_PntNormal, s_PntColor, irr::core::vector2df(0,0))); smeshBuf->Vertices.push_back(irr::video::S3DVertex(defaultPos, s_PntNormal, s_PntColor, irr::core::vector2df(1,0))); smeshBuf->Vertices.push_back(irr::video::S3DVertex(defaultPos, s_PntNormal, s_PntColor, irr::core::vector2df(1,1))); smeshBuf->Vertices.push_back(irr::video::S3DVertex(defaultPos, s_PntNormal, s_PntColor, irr::core::vector2df(0,1))); smeshBuf->Indices.reallocate(4); smeshBuf->Indices.push_back(0); smeshBuf->Indices.push_back(1); smeshBuf->Indices.push_back(2); smeshBuf->Indices.push_back(3); TmpRect_->getMaterial().Lighting = false; TmpRect_->getMaterial().ZWriteEnable = false; TmpRect_->getMaterial().BackfaceCulling = false; TmpRect_->getMaterial().Thickness = 3; TmpRect_->getMaterial().DiffuseColor = irr::video::SColor(0xFF000000); } { PntMeshBuf_ = new irr::scene::SMeshBuffer; auto smeshBuf = static_cast<irr::scene::SMeshBuffer*>(PntMeshBuf_); smeshBuf->Vertices.reallocate(4); smeshBuf->Vertices.push_back(irr::video::S3DVertex(irr::core::vector3df(-10, 0, -10), s_PntNormal, s_PathColor, irr::core::vector2df(0,0))); smeshBuf->Vertices.push_back(irr::video::S3DVertex(irr::core::vector3df(10, 0, -10), s_PntNormal, s_PathColor, irr::core::vector2df(1,0))); smeshBuf->Vertices.push_back(irr::video::S3DVertex(irr::core::vector3df(10, 0, 10), s_PntNormal, s_PathColor, irr::core::vector2df(1,1))); smeshBuf->Vertices.push_back(irr::video::S3DVertex(irr::core::vector3df(10, 0, -10), s_PntNormal, s_PathColor, irr::core::vector2df(0,1))); smeshBuf->Indices.reallocate(4); smeshBuf->Indices.push_back(0); smeshBuf->Indices.push_back(1); smeshBuf->Indices.push_back(2); smeshBuf->Indices.push_back(3); PntMeshBuf_->getMaterial().Lighting = false; PntMeshBuf_->getMaterial().ZWriteEnable = false; PntMeshBuf_->getMaterial().BackfaceCulling = false; PntMeshBuf_->getMaterial().Thickness = 3; } CircleMeshBuf_ = new irr::scene::SMeshBuffer; { auto smeshBuf = static_cast<irr::scene::SMeshBuffer*>(CircleMeshBuf_); smeshBuf->Vertices.reallocate(360); smeshBuf->Indices.reallocate(360); Handle(Geom2d_Circle) C = new Geom2d_Circle(gp::OX2d(),1); Geom2dAdaptor_Curve GAC (C); GCPnts_UniformAbscissa UA (GAC,360); assert(UA.IsDone()); gp_Pnt2d P; irr::video::SColor clr(0xFF000000); bool bClr = true; for( auto index=1, count=UA.NbPoints(); index<=count; ++index ) { if ( index % 10 == 0 ) { bClr= !bClr; } C->D0(UA.Parameter(index),P); irr::core::vector3df pos(static_cast<float>(P.X()), 0, static_cast<float>(-P.Y())); smeshBuf->Vertices.push_back(irr::video::S3DVertex(pos, s_PntNormal, bClr ? s_PntColor : clr, s_PntCoord)); smeshBuf->Indices.push_back(index-1); } CircleMeshBuf_->getMaterial().Lighting = false; CircleMeshBuf_->getMaterial().ZWriteEnable = false; CircleMeshBuf_->getMaterial().BackfaceCulling = false; CircleMeshBuf_->getMaterial().Thickness = 3; } NeedUpdateMesh_ = false; Checker_ = true; WallThickness_ = 300; LastAngle_ = 0; State_ = EDWLS_BEGIN; PolarAngle_ = 30.f; PolarAngleRange_ = 10.f; SetName("DrawingLineWallCtrller"); }