//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_SphereDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_ISphere aCI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; char aMsg[] = "Sphere creation aborted: radius value less than 1e-07 is not acceptable"; double theAngle = aCI.GetAngle(); if (theAngle == 0.) theAngle = PI * 2.; double theVCoordStart = aCI.GetVCoordStart(); double theVCoordEnd = aCI.GetVCoordEnd(); if (aType == SPHERE_R) { double anR = aCI.GetR(); if (anR < Precision::Confusion()) Standard_ConstructionError::Raise(aMsg); //There seems to be an issue with the BRepPrimAPI_MakeSphere command concerning //the limitations on V coodinates of its parametric space ... (Will not be used for the moment) aShape = BRepPrimAPI_MakeSphere(anR /*, theVCoordStart, theVCoordEnd*/ , theAngle).Shape(); } else if (aType == SPHERE_PNT_R) { double anR = aCI.GetR(); if (anR < Precision::Confusion()) Standard_ConstructionError::Raise(aMsg); Handle(GEOM_Function) aRefPoint = aCI.GetPoint(); TopoDS_Shape aShapePnt = aRefPoint->GetValue(); if (aShapePnt.ShapeType() != TopAbs_VERTEX) Standard_ConstructionError::Raise("Invalid shape given for sphere center: it must be a point"); gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); aShape = BRepPrimAPI_MakeSphere(aP, anR/*, theVCoordStart, theVCoordEnd*/, theAngle).Shape(); } else { } if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
void occQt::testCommon() { gp_Ax2 anAxis; anAxis.SetLocation(gp_Pnt(0.0, 110.0, 0.0)); TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0); TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 2.5); TopoDS_Shape aCommonShape = BRepAlgoAPI_Common(aTopoBox, aTopoSphere); gp_Trsf aTrsf; aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0)); BRepBuilderAPI_Transform aTransform(aCommonShape, aTrsf); Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox); Handle_AIS_Shape anAisSphere = new AIS_Shape(aTopoSphere); Handle_AIS_Shape anAisCommonShape = new AIS_Shape(aTransform.Shape()); anAisBox->SetColor(Quantity_NOC_SPRINGGREEN); anAisSphere->SetColor(Quantity_NOC_STEELBLUE); anAisCommonShape->SetColor(Quantity_NOC_ROYALBLUE); mContext->Display(anAisBox); mContext->Display(anAisSphere); mContext->Display(anAisCommonShape); }
void occQt::testCut() { gp_Ax2 anAxis; anAxis.SetLocation(gp_Pnt(0.0, 90.0, 0.0)); TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0); TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 2.5); TopoDS_Shape aCuttedShape1 = BRepAlgoAPI_Cut(aTopoBox, aTopoSphere); TopoDS_Shape aCuttedShape2 = BRepAlgoAPI_Cut(aTopoSphere, aTopoBox); gp_Trsf aTrsf; aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0)); BRepBuilderAPI_Transform aTransform1(aCuttedShape1, aTrsf); aTrsf.SetTranslation(gp_Vec(16.0, 0.0, 0.0)); BRepBuilderAPI_Transform aTransform2(aCuttedShape2, aTrsf); Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox); Handle_AIS_Shape anAisSphere = new AIS_Shape(aTopoSphere); Handle_AIS_Shape anAisCuttedShape1 = new AIS_Shape(aTransform1.Shape()); Handle_AIS_Shape anAisCuttedShape2 = new AIS_Shape(aTransform2.Shape()); anAisBox->SetColor(Quantity_NOC_SPRINGGREEN); anAisSphere->SetColor(Quantity_NOC_STEELBLUE); anAisCuttedShape1->SetColor(Quantity_NOC_TAN); anAisCuttedShape2->SetColor(Quantity_NOC_SALMON); mContext->Display(anAisBox); mContext->Display(anAisSphere); mContext->Display(anAisCuttedShape1); mContext->Display(anAisCuttedShape2); }
void MainWindow::on_drawSphere() { gp_Ax2 anAxis; anAxis.SetLocation(gp_Pnt(5.0, 5, 0.0)); TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 3.0).Shape(); occView->DrawShape(aTopoSphere); }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_SphereDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_ISphere aCI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; char aMsg[] = "Sphere creation aborted: radius value less than 1e-07 is not acceptable"; if (aType == SPHERE_R) { double anR = aCI.GetR(); if (anR < Precision::Confusion()) Standard_ConstructionError::Raise(aMsg); aShape = BRepPrimAPI_MakeSphere(anR).Shape(); } else if (aType == SPHERE_PNT_R) { double anR = aCI.GetR(); if (anR < Precision::Confusion()) Standard_ConstructionError::Raise(aMsg); Handle(GEOM_Function) aRefPoint = aCI.GetPoint(); TopoDS_Shape aShapePnt = aRefPoint->GetValue(); if (aShapePnt.ShapeType() != TopAbs_VERTEX) Standard_ConstructionError::Raise("Invalid shape given for sphere center: it must be a point"); gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); aShape = BRepPrimAPI_MakeSphere(aP, anR).Shape(); } else { } if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
void occQt::makeSphere() { gp_Ax2 anAxis; anAxis.SetLocation(gp_Pnt(0.0, 20.0, 0.0)); TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 3.0); Handle_AIS_Shape anAisSphere = new AIS_Shape(aTopoSphere); anAisSphere->SetColor(Quantity_NOC_BLUE1); mContext->Display(anAisSphere); }
BRLTopo::BRLTopo(struct rt_ell_internal *ell) { #if 0 gp_Pnt v(ell->v[0], ell->v[1], ell->v[2]); gp_Pnt a(v.Coord(1)+ell->a[0], v.Coord(2)+ell->a[1], v.Coord(3)+ell->a[2]); gp_Pnt b(v.Coord(1)+ell->b[0], v.Coord(2)+ell->b[1], v.Coord(3)+ell->b[2]); gp_Pnt c(v.Coord(1)+ell->c[0], v.Coord(2)+ell->c[1], v.Coord(3)+ell->c[2]); gp_Pnt aa(v.Coord(1)-ell->a[0], v.Coord(2)-ell->a[1], v.Coord(3)-ell->a[2]); gp_Pnt bb(v.Coord(1)-ell->b[0], v.Coord(2)-ell->b[1], v.Coord(3)-ell->b[2]); gp_Pnt cc(v.Coord(1)-ell->c[0], v.Coord(2)-ell->c[1], v.Coord(3)-ell->c[2]); Handle(Geom_Ellipse) sect1=GC_MakeEllipse(a, b, v); Handle(Geom_Ellipse) sect2=GC_MakeEllipse(a, c, v); Handle(Geom_Ellipse) sect3=GC_MakeEllipse(b, c, v); TopoDS_Edge e_ab[4]; e_ab[0]=BRepBuilderAPI_MakeEdge(sect1,a,b); e_ab[1]=BRepBuilderAPI_MakeEdge(sect1,b,aa); e_ab[2]=BRepBuilderAPI_MakeEdge(sect1,aa,bb); e_ab[3]=BRepBuilderAPI_MakeEdge(sect1,bb,a); TopoDS_Edge e_ac[4]; e_ac[0]=BRepBuilderAPI_MakeEdge(sect2,c,aa); e_ac[1]=BRepBuilderAPI_MakeEdge(sect2,a,c); e_ac[2]=BRepBuilderAPI_MakeEdge(sect2,aa,cc); e_ac[3]=BRepBuilderAPI_MakeEdge(sect2,cc,a); TopoDS_Edge e_bc[4]; e_bc[0]=BRepBuilderAPI_MakeEdge(sect3,b,c); e_bc[1]=BRepBuilderAPI_MakeEdge(sect3,c,bb); e_bc[2]=BRepBuilderAPI_MakeEdge(sect3,bb,cc); e_bc[3]=BRepBuilderAPI_MakeEdge(sect3,cc,b); // FIXME, BRepFill_Filling? TopoDS_Solid sph=BRepPrimAPI_MakeSphere(v,ell->a[0]); TopoDS_Face init; for(TopExp_Explorer p(sph,TopAbs_FACE); p.More(); p.Next()) init=TopoDS::Face(p.Current()); BRepFill_Filling face1; //face1.LoadInitSurface(init); face1.Add(e_ab[0],GeomAbs_C0); face1.Add(e_ab[1],GeomAbs_C0); face1.Add(e_ac[0],GeomAbs_C0); face1.Add(e_ac[1],GeomAbs_C0); face1.Add(e_bc[0],GeomAbs_C0,false); face1.Build(); BRepFill_Filling face2; //face2.LoadInitSurface(init); face2.Add(e_ab[2],GeomAbs_C0); face2.Add(e_ab[3],GeomAbs_C0); face2.Add(e_ac[2],GeomAbs_C0); face2.Add(e_ac[3],GeomAbs_C0); face2.Add(e_bc[2],GeomAbs_C0,false); face2.Build(); BRepFill_Filling face3; //face3.LoadInitSurface(init); face3.Add(e_ab[2],GeomAbs_C0); face3.Add(e_ab[3],GeomAbs_C0); face3.Add(e_ac[0],GeomAbs_C0); face3.Add(e_ac[1],GeomAbs_C0); face3.Add(e_bc[1],GeomAbs_C0,false); face3.Build(); BRepFill_Filling face4; //face4.LoadInitSurface(init); face4.Add(e_ab[0],GeomAbs_C0); face4.Add(e_ab[1],GeomAbs_C0); face4.Add(e_ac[2],GeomAbs_C0); face4.Add(e_ac[3],GeomAbs_C0); face4.Add(e_bc[3],GeomAbs_C0,false); face4.Build(); BRep_Builder BB; TopoDS_Shell result; BB.MakeShell(result); BB.Add(result,face1.Face()); BB.Add(result,face2.Face().Reversed()); BB.Add(result,face3.Face()); BB.Add(result,face4.Face().Reversed()); shape=BRepBuilderAPI_MakeSolid(result); #else /* FIXME, we only support spheres at the moment. */ gp_Pnt v(scale*ell->v[0], scale*ell->v[1], scale*ell->v[2]); TopoDS_Solid sph=BRepPrimAPI_MakeSphere(v,scale*ell->a[0]); shape=sph; #endif }
int main(int argc, char **args) { // Create a sphere gp_Pnt center(0, 0, 0); Standard_Real radius = 100; TopoDS_Shape sphere = BRepPrimAPI_MakeSphere( center, radius ).Shape(); // Save it in STL, STEP and IGES saveInSTL(sphere, "shape.stl"); assert(saveInSTEP(sphere, "shape.stp")); assert(saveInIGES(sphere, "shape.igs")); // Load the sphere from the files TopoDS_Shape shape_from_stl = openSTL("shape.stl"); TopoDS_Shape shape_from_step = openSTEP("shape.stp"); TopoDS_Shape shape_from_iges = openIGES("shape.igs"); bool inside; clock_t stl_speed = 0; clock_t step_speed = 0; clock_t iges_speed = 0; Standard_Real count_points = 0; for (Standard_Real x = -(radius/2); x <= (radius/2); x += (radius/5)) { for (Standard_Real y = -(radius/2); y <= (radius/2); y += (radius/5)) { for (Standard_Real z = -(radius/2); z <= (radius/2); z += (radius/5)) { count_points++; TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(gp_Pnt(x, y, z)).Vertex(); Standard_Real expected_distance = fabs(sqrt( pow(center.X() - x, 2) + pow(center.Y() - y, 2) + pow(center.Z() - z, 2)) - radius); clock_t t = clock(); Standard_Real distance = distanceTwoShapes(shape_from_stl, vertex, inside); stl_speed += clock() - t; assert(almost_equal(distance, expected_distance, 0.3)); t = clock(); distance = distanceTwoShapes(shape_from_step, vertex, inside); step_speed += clock() - t; // don't check if inside if (!inside) { assert(almost_equal(distance, expected_distance, 0.0001)); } t = clock(); distance = distanceTwoShapes(shape_from_iges, vertex, inside); iges_speed += clock() - t; assert(almost_equal(distance, expected_distance, 0.0001)); } } } stl_speed /= count_points; step_speed /= count_points; iges_speed /= count_points; cout << "STL average speed: " << stl_speed << " ticks" << endl; cout << "STEP average speed: " << step_speed << " ticks" << endl; cout << "IGES average speed: " << iges_speed << " ticks" << endl; return 0; }
Handle(AIS_InteractiveContext)& ais) { DisplacementNodeX = nodeList[0]; DisplacementNodeY = nodeList[1]; RotationNode = nodeList[2]; myAISContext = ais; boolean=false; QString Dr=*(parameterList["PARIMD0"]); x=LVPS_Utility::ToDouble(Dr); Dr=*(parameterList["PARIMD1"]); y=LVPS_Utility::ToDouble(Dr); Dr=*(parameterList["PARIMD2"]); double radius=LVPS_Utility::ToDouble(Dr); Shape=BRepPrimAPI_MakeSphere(gp_Pnt(x,y,0),radius); // ======= Example of BREP file reading ============ // LVPS_LoadBREPFile LoadBREPFile(1, SolverCont); // Shape = LoadBREPFile.GetShape(); // gp_Trsf trsf; // gp_Vec n1(x,y,0.); // trsf.SetTranslation(n1); // trsf.SetScaleFactor(radius); // BRepBuilderAPI_Transform TS(Shape, trsf, Standard_False); // Shape = TS.Shape(); //================================================== myAISShape = new AIS_Shape (Shape); // myAISShape->SetColor (Quantity_NOC_WHITE);