Py::Object wireFromSegment(const Py::Tuple& args) { PyObject *o, *m; if (!PyArg_ParseTuple(args.ptr(), "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o)) throw Py::Exception(); Py::List list(o); Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr(); std::vector<unsigned long> segm; segm.reserve(list.size()); for (unsigned int i=0; i<list.size(); i++) { segm.push_back((int)Py::Int(list[i])); } std::list<std::vector<Base::Vector3f> > bounds; MeshCore::MeshAlgorithm algo(mesh->getKernel()); algo.GetFacetBorders(segm, bounds); Py::List wires; std::list<std::vector<Base::Vector3f> >::iterator bt; for (bt = bounds.begin(); bt != bounds.end(); ++bt) { BRepBuilderAPI_MakePolygon mkPoly; for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) { mkPoly.Add(gp_Pnt(it->x,it->y,it->z)); } if (mkPoly.IsDone()) { PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire())); wires.append(Py::Object(wire, true)); } } return wires; }
App::DocumentObjectExecReturn *Prism::execute(void) { // Build a prism if (Polygon.getValue() < 3) return new App::DocumentObjectExecReturn("Polygon of prism is invalid, must have 3 or more sides"); if (Circumradius.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Circumradius of the polygon, of the prism, is too small"); if (Height.getValue() < Precision::Confusion()) return new App::DocumentObjectExecReturn("Height of prism is too small"); try { long nodes = Polygon.getValue(); Base::Matrix4D mat; mat.rotZ(Base::toRadians(360.0/nodes)); // create polygon BRepBuilderAPI_MakePolygon mkPoly; Base::Vector3d v(Circumradius.getValue(),0,0); for (long i=0; i<nodes; i++) { mkPoly.Add(gp_Pnt(v.x,v.y,v.z)); v = mat * v; } mkPoly.Add(gp_Pnt(v.x,v.y,v.z)); BRepBuilderAPI_MakeFace mkFace(mkPoly.Wire()); BRepPrimAPI_MakePrism mkPrism(mkFace.Face(), gp_Vec(0,0,Height.getValue())); this->Shape.setValue(mkPrism.Shape()); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); return new App::DocumentObjectExecReturn(e->GetMessageString()); } return App::DocumentObject::StdReturn; }
int OCCFace::createPolygonal(std::vector<OCCStruct3d> points) { try { BRepBuilderAPI_MakePolygon MP; for (unsigned i=0; i<points.size(); i++) { MP.Add(gp_Pnt(points[i].x, points[i].y, points[i].z)); } MP.Close(); if (!MP.IsDone()) { StdFail_NotDone::Raise("failed to create face");; } BRepBuilderAPI_MakeFace MF(MP.Wire(), false); this->setShape(MF.Face()); // possible fix shape if (!this->fixShape()) StdFail_NotDone::Raise("Shapes not valid"); } 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 create face"); } return 0; } return 1; }
static TopoDS_Wire mkPolygonWire(const Standard_Integer nPoints, const Standard_Real theCoords[][3], const Standard_Real aScale = 1, const gp_XYZ& aShift = gp_XYZ(0,0,0)) { BRepBuilderAPI_MakePolygon aPol; for (Standard_Integer i=0; i < nPoints; i++) { gp_XYZ aP(theCoords[i][0], theCoords[i][1], theCoords[i][2]); aPol.Add (gp_Pnt (aP * aScale + aShift)); } return aPol.Wire(); }
void occQt::makeLoft() { // bottom wire. TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(gp_Ax2(gp_Pnt(0.0, 80.0, 0.0), gp::DZ()), 1.5)); TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge); // top wire. BRepBuilderAPI_MakePolygon aPolygon; aPolygon.Add(gp_Pnt(-3.0, 77.0, 6.0)); aPolygon.Add(gp_Pnt(3.0, 77.0, 6.0)); aPolygon.Add(gp_Pnt(3.0, 83.0, 6.0)); aPolygon.Add(gp_Pnt(-3.0, 83.0, 6.0)); aPolygon.Close(); BRepOffsetAPI_ThruSections aShellGenerator; BRepOffsetAPI_ThruSections aSolidGenerator(true); aShellGenerator.AddWire(aCircleWire); aShellGenerator.AddWire(aPolygon.Wire()); aSolidGenerator.AddWire(aCircleWire); aSolidGenerator.AddWire(aPolygon.Wire()); // translate the solid. gp_Trsf aTrsf; aTrsf.SetTranslation(gp_Vec(18.0, 0.0, 0.0)); BRepBuilderAPI_Transform aTransform(aSolidGenerator.Shape(), aTrsf); Handle_AIS_Shape anAisShell = new AIS_Shape(aShellGenerator.Shape()); Handle_AIS_Shape anAisSolid = new AIS_Shape(aTransform.Shape()); anAisShell->SetColor(Quantity_NOC_OLIVEDRAB); anAisSolid->SetColor(Quantity_NOC_PEACHPUFF); mContext->Display(anAisShell); mContext->Display(anAisSolid); }
App::DocumentObjectExecReturn *Part::Polygon::execute(void) { BRepBuilderAPI_MakePolygon poly; const std::vector<Base::Vector3d> nodes = Nodes.getValues(); for (std::vector<Base::Vector3d>::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { gp_Pnt pnt(it->x, it->y, it->z); poly.Add(pnt); } if (Close.getValue()) poly.Close(); if (!poly.IsDone()) throw Base::CADKernelError("Cannot create polygon because less than two vertices are given"); TopoDS_Wire wire = poly.Wire(); this->Shape.setValue(wire); return App::DocumentObject::StdReturn; }
static PyObject * wireFromSegment(PyObject *self, PyObject *args) { PyObject *o, *m; if (!PyArg_ParseTuple(args, "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o)) return 0; Py::List list(o); Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr(); std::vector<unsigned long> segm; segm.reserve(list.size()); for (unsigned int i=0; i<list.size(); i++) { segm.push_back((int)Py::Int(list[i])); } std::list<std::vector<Base::Vector3f> > bounds; MeshCore::MeshAlgorithm algo(mesh->getKernel()); algo.GetFacetBorders(segm, bounds); Py::List wires; std::list<std::vector<Base::Vector3f> >::iterator bt; try { for (bt = bounds.begin(); bt != bounds.end(); ++bt) { BRepBuilderAPI_MakePolygon mkPoly; for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) { mkPoly.Add(gp_Pnt(it->x,it->y,it->z)); } if (mkPoly.IsDone()) { PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire())); wires.append(Py::Object(wire, true)); } } } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString()); return 0; } return Py::new_reference_to(wires); }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolyLoop* l, TopoDS_Wire& result) { IfcSchema::IfcCartesianPoint::list::ptr points = l->Polygon(); // Parse and store the points in a sequence TColgp_SequenceOfPnt polygon; for(IfcSchema::IfcCartesianPoint::list::it it = points->begin(); it != points->end(); ++ it) { gp_Pnt pnt; IfcGeom::Kernel::convert(*it, pnt); polygon.Append(pnt); } // A loop should consist of at least three vertices int original_count = polygon.Length(); if (original_count < 3) { Logger::Message(Logger::LOG_ERROR, "Not enough edges for:", l->entity); return false; } // Remove points that are too close to one another remove_redundant_points_from_loop(polygon, true); int count = polygon.Length(); if (original_count - count != 0) { std::stringstream ss; ss << (original_count - count) << " edges removed for:"; Logger::Message(Logger::LOG_WARNING, ss.str(), l->entity); } if (count < 3) { Logger::Message(Logger::LOG_ERROR, "Not enough edges for:", l->entity); return false; } BRepBuilderAPI_MakePolygon w; for (int i = 1; i <= polygon.Length(); ++i) { w.Add(polygon.Value(i)); } w.Close(); result = w.Wire(); return true; }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolyline* l, TopoDS_Wire& result) { IfcSchema::IfcCartesianPoint::list::ptr points = l->Points(); // Parse and store the points in a sequence TColgp_SequenceOfPnt polygon; for(IfcSchema::IfcCartesianPoint::list::it it = points->begin(); it != points->end(); ++ it) { gp_Pnt pnt; IfcGeom::Kernel::convert(*it, pnt); polygon.Append(pnt); } // Remove points that are too close to one another remove_redundant_points_from_loop(polygon, false); BRepBuilderAPI_MakePolygon w; for (int i = 1; i <= polygon.Length(); ++i) { w.Add(polygon.Value(i)); } result = w.Wire(); return true; }
bool DrawingLineWallCtrller::UpdateMesh() { if ( !NeedUpdateMesh_ ) { return true; } if ( Pnts_.size() > 1 ) { {//Triangle Mesh BRepBuilderAPI_MakePolygon mp; for ( const auto& curPnt : Pnts_ ) { mp.Add(gp_Pnt(curPnt.X, curPnt.Y, curPnt.Z)); } assert(mp.IsDone()); auto wallPath = mp.Wire(); assert(!wallPath.IsNull()); auto& wallPnt1 = Pnts_[0]; auto& wallPnt2 = Pnts_[1]; auto beginThickPnt = (wallPnt2 - wallPnt1).normalize().crossProduct(s_PntNormal) * WallThickness_; beginThickPnt = wallPnt1 + beginThickPnt; auto thickEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(wallPnt1.X,wallPnt1.Y, wallPnt1.Z), gp_Pnt(beginThickPnt.X,beginThickPnt.Y, beginThickPnt.Z) ).Edge(); BRepBuilderAPI_MakeWire dirWireMaker(thickEdge); TopoDS_Wire dirWire = dirWireMaker.Wire(); BRepOffsetAPI_MakePipeShell pipeMaker(wallPath); pipeMaker.SetTransitionMode(BRepBuilderAPI_RightCorner);//延切线方向缝合 pipeMaker.Add(dirWire); pipeMaker.Build(); FaceShape_ = pipeMaker.Shape(); if ( wallPath.Closed() ) { State_ = EDWLS_FINISH; return false; } if ( MeshBuf_ ) { MeshBuf_->drop(); } auto mesh = ODLTools::CreateMesh(FaceShape_); assert(mesh); MeshBuf_ = mesh->getMeshBuffer(0); MeshBuf_->grab(); auto tex = GetRenderContextSPtr()->Smgr_->getVideoDriver()->getTexture("../Data/Resource/3D/wallLine.png"); MeshBuf_->getMaterial().setTexture(0, tex); float uLen = 200; float vLen = 200; irr::core::matrix4 scaleMat,rotateMat; scaleMat.setScale(irr::core::vector3df(1/uLen, 1/vLen, 1)); rotateMat.setTextureRotationCenter(static_cast<float>(M_PI/4)); MeshBuf_->getMaterial().setTextureMatrix(0, rotateMat*scaleMat); MeshBuf_->getMaterial().Lighting = false; MeshBuf_->getMaterial().ZWriteEnable = false; MeshBuf_->getMaterial().BackfaceCulling = false; mesh->drop(); } {//Line Mesh if ( LineMeshBuf_ ) { LineMeshBuf_->drop(); } auto newSmesh = new SMeshBuffer; for ( TopExp_Explorer exp(FaceShape_, TopAbs_EDGE); exp.More(); exp.Next() ) { auto& curEdge = TopoDS::Edge(exp.Current()); auto& v1 = TopExp::FirstVertex(curEdge); auto& v2 = TopExp::LastVertex(curEdge); auto p1 = BRep_Tool::Pnt(v1); auto p2 = BRep_Tool::Pnt(v2); S3DVertex sv1(irr::core::vector3df(static_cast<float>(p1.X()), static_cast<float>(p1.Y()), static_cast<float>(p1.Z())), s_PntNormal, s_LineColor, s_PntCoord); S3DVertex sv2(irr::core::vector3df(static_cast<float>(p2.X()), static_cast<float>(p2.Y()), static_cast<float>(p2.Z())), s_PntNormal, s_LineColor, s_PntCoord); newSmesh->Vertices.push_back(sv1); newSmesh->Vertices.push_back(sv2); newSmesh->Indices.push_back(newSmesh->getIndexCount()); newSmesh->Indices.push_back(newSmesh->getIndexCount()); } LineMeshBuf_ = newSmesh; LineMeshBuf_->getMaterial().Lighting = false; LineMeshBuf_->getMaterial().ZWriteEnable = false; LineMeshBuf_->getMaterial().BackfaceCulling = false; LineMeshBuf_->getMaterial().Thickness = 3; LineMeshBuf_->getMaterial().MaterialType = IrrEngine::GetInstance()->GetShaderType(EST_LINE); LineMeshBuf_->getMaterial().DiffuseColor = s_LineColor; } } {//Path Mesh auto smeshBuf = static_cast<irr::scene::SMeshBuffer*>(PathMeshBuf_); smeshBuf->Vertices.clear(); smeshBuf->Indices.clear(); auto curCount = PathMeshBuf_->getIndexCount(); for ( const auto& curPnt : Pnts_ ) { smeshBuf->Vertices.push_back(irr::video::S3DVertex(curPnt, s_PntNormal, s_PathColor, s_PntCoord)); smeshBuf->Indices.push_back(curCount++); } } NeedUpdateMesh_ = false; return true; }