//======================================================================= //function : GetEdgeOff //purpose : //======================================================================= Standard_Boolean GEOMAlgo_Tools3D::GetEdgeOff(const TopoDS_Edge& theE1, const TopoDS_Face& theF2, TopoDS_Edge& theE2) { Standard_Boolean bFound; TopAbs_Orientation aOr1, aOr1C, aOr2; TopExp_Explorer anExp; // bFound=Standard_False; aOr1=theE1.Orientation(); aOr1C=TopAbs::Reverse(aOr1); // anExp.Init(theF2, TopAbs_EDGE); for (; anExp.More(); anExp.Next()) { const TopoDS_Edge& aEF2=TopoDS::Edge(anExp.Current()); if (aEF2.IsSame(theE1)) { aOr2=aEF2.Orientation(); if (aOr2==aOr1C) { theE2=aEF2; bFound=!bFound; return bFound; } } } return bFound; }
//======================================================================= //function :IsSplitToReverse //purpose : //======================================================================= Standard_Boolean GEOMAlgo_Tools3D::IsSplitToReverse(const TopoDS_Edge& theSplit, const TopoDS_Edge& theEdge, IntTools_Context& theContext) { Standard_Boolean bRet, aFlag, bIsDegenerated; Standard_Real aTE, aTS, aScPr, aTa, aTb, aT1, aT2; TopAbs_Orientation aOrSr, aOrSp; Handle(Geom_Curve) aCEdge, aCSplit; gp_Vec aVE, aVS; gp_Pnt aP; // bRet=Standard_False; // bIsDegenerated=(BRep_Tool::Degenerated(theSplit) || BRep_Tool::Degenerated(theEdge)); if (bIsDegenerated) { return bRet; } // aCEdge =BRep_Tool::Curve(theEdge , aT1, aT2); aCSplit=BRep_Tool::Curve(theSplit, aTa, aTb); // if (aCEdge==aCSplit) { aOrSr=theEdge.Orientation(); aOrSp=theSplit.Orientation(); bRet=(aOrSr!=aOrSp); return bRet; } // aTS=BOPTools_Tools2D::IntermediatePoint(aTa, aTb); aCSplit->D0(aTS, aP); aFlag=BOPTools_Tools2D::EdgeTangent(theSplit, aTS, aVS); gp_Dir aDTS(aVS); // aFlag=theContext.ProjectPointOnEdge(aP, theEdge, aTE); aFlag=BOPTools_Tools2D::EdgeTangent(theEdge, aTE, aVE); gp_Dir aDTE(aVE); // aScPr=aDTS*aDTE; bRet=(aScPr<0.); // return bRet; }
//======================================================================= //function : SamePnt2d //purpose : //======================================================================= static Standard_Boolean SamePnt2d(TopoDS_Vertex V, TopoDS_Edge& E1, TopoDS_Edge& E2, TopoDS_Face& F) { Standard_Real f1,f2,l1,l2; gp_Pnt2d P1,P2; TopoDS_Shape aLocalF = F.Oriented(TopAbs_FORWARD); TopoDS_Face FF = TopoDS::Face(aLocalF); Handle(Geom2d_Curve) C1 = BRep_Tool::CurveOnSurface(E1,FF,f1,l1); Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(E2,FF,f2,l2); if (E1.Orientation () == TopAbs_FORWARD) P1 = C1->Value(f1); else P1 = C1->Value(l1); if (E2.Orientation () == TopAbs_FORWARD) P2 = C2->Value(l2); else P2 = C2->Value(f2); Standard_Real Tol = 100*BRep_Tool::Tolerance(V); Standard_Real Dist = P1.Distance(P2); return Dist < Tol; }
// sometimes, we ask to replace the ending points of the curve // in gluing operations for example void OCCEdge::replaceEndingPointsInternals(GVertex *g0, GVertex *g1) { TopoDS_Vertex aV1 = *((TopoDS_Vertex*)v0->getNativePtr()); TopoDS_Vertex aV2 = *((TopoDS_Vertex*)v1->getNativePtr()); TopoDS_Vertex aVR1 = *((TopoDS_Vertex*)g0->getNativePtr()); TopoDS_Vertex aVR2 = *((TopoDS_Vertex*)g1->getNativePtr()); // printf("%p %p --- %p %p replacing %d %d by %d %d in occedge %d\n", // v0,v1,g0,g1,v0->tag(),v1->tag(),g0->tag(),g1->tag(),tag()); Standard_Boolean bIsDE = BRep_Tool::Degenerated(c); TopoDS_Edge aEx = c; aEx.Orientation(TopAbs_FORWARD); Standard_Real t1=s0; Standard_Real t2=s1; aVR1.Orientation(TopAbs_FORWARD); aVR2.Orientation(TopAbs_REVERSED); if (bIsDE) { Standard_Real aTol; BRep_Builder aBB; TopoDS_Edge E; //TopAbs_Orientation anOrE; //anOrE = c.Orientation(); aTol = BRep_Tool::Tolerance(c); E = aEx; E.EmptyCopy(); aBB.Add(E, aVR1); aBB.Add(E, aVR2); aBB.Range(E, t1, t2); aBB.Degenerated(E, Standard_True); aBB.UpdateEdge(E, aTol); _replacement=E; } else { #if (OCC_VERSION_MAJOR == 6) && (OCC_VERSION_MINOR < 6) BOPTools_Tools::MakeSplitEdge(aEx, aVR1, t1, aVR2, t2, _replacement); #else BOPTools_AlgoTools::MakeSplitEdge(aEx, aVR1, t1, aVR2, t2, _replacement); #endif } TopoDS_Edge temp = c; c = _replacement; _replacement = temp; curve = BRep_Tool::Curve(c, s0, s1); //build the reverse curve c_rev = c; c_rev.Reverse(); }
int convert_to_ifc(const TopoDS_Edge& e, IfcSchema::IfcEdge*& edge, bool advanced) { double a, b; TopExp_Explorer exp(e, TopAbs_VERTEX); if (!exp.More()) return 0; TopoDS_Vertex v1 = TopoDS::Vertex(exp.Current()); exp.Next(); if (!exp.More()) return 0; TopoDS_Vertex v2 = TopoDS::Vertex(exp.Current()); IfcSchema::IfcVertex *vertex1, *vertex2; if (!(convert_to_ifc(v1, vertex1, advanced) && convert_to_ifc(v2, vertex2, advanced))) { return 0; } Handle_Geom_Curve crv = BRep_Tool::Curve(e, a, b); if (crv.IsNull()) { return 0; } if (crv->DynamicType() == STANDARD_TYPE(Geom_Line) && !advanced) { IfcSchema::IfcEdge* edge2 = new IfcSchema::IfcEdge(vertex1, vertex2); edge = new IfcSchema::IfcOrientedEdge(edge2, true); return 1; } else { IfcSchema::IfcCurve* curve; if (!convert_to_ifc(crv, curve, advanced)) { return 0; } /// @todo probably not correct const bool sense = e.Orientation() == TopAbs_FORWARD; IfcSchema::IfcEdge* edge2 = new IfcSchema::IfcEdgeCurve(vertex1, vertex2, curve, true); edge = new IfcSchema::IfcOrientedEdge(edge2, sense); return 1; } }
bool Edgecluster::PerformEdges(gp_Pnt& point) { tMapPntEdge::iterator iter = m_vertices.find(point); if ( iter == m_vertices.end() ) return false; tEdgeVector& edges = iter->second; tEdgeVector::iterator edgeIt = edges.begin(); //no more edges. pb if ( edgeIt == edges.end() ) { //Delete also the current vertex m_vertices.erase(iter); return false; } TopoDS_Edge theEdge = *edgeIt; //we are storing the edge, so remove it from the vertex association edges.erase(edgeIt); //if no more edges, remove the vertex if ( edges.empty() ) m_vertices.erase(iter); TopoDS_Vertex V1,V2; TopExp::Vertices(theEdge,V1,V2); gp_Pnt P1 = BRep_Tool::Pnt(V1); gp_Pnt P2 = BRep_Tool::Pnt(V2); if ( theEdge.Orientation() == TopAbs_REVERSED ) { //switch the points gp_Pnt tmpP = P1; P1 = P2; P2 = tmpP; } gp_Pnt nextPoint; if ( P2.IsEqual(point,0.2) ) { //need to reverse the edge theEdge.Reverse(); nextPoint = P1; } else { nextPoint = P2; } //need to erase the edge from the second point iter = m_vertices.find(nextPoint); if ( iter != m_vertices.end() ) { tEdgeVector& nextEdges = iter->second; for ( edgeIt = nextEdges.begin() ; edgeIt != nextEdges.end(); ++edgeIt ) { if ( theEdge.IsSame(*edgeIt) ) { nextEdges.erase(edgeIt); break; } } } //put the edge at the end of the list m_edges.push_back(theEdge); //Update the point for the next do-while loop point = nextPoint; return true; }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_MeasureDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_IMeasure aCI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; if (aType == CDG_MEASURE) { Handle(GEOM_Function) aRefBase = aCI.GetBase(); TopoDS_Shape aShapeBase = aRefBase->GetValue(); if (aShapeBase.IsNull()) { Standard_NullObject::Raise("Shape for centre of mass calculation is null"); } gp_Ax3 aPos = GEOMImpl_IMeasureOperations::GetPosition(aShapeBase); gp_Pnt aCenterMass = aPos.Location(); aShape = BRepBuilderAPI_MakeVertex(aCenterMass).Shape(); } else if (aType == VERTEX_BY_INDEX) { Handle(GEOM_Function) aRefBase = aCI.GetBase(); TopoDS_Shape aShapeBase = aRefBase->GetValue(); if (aShapeBase.IsNull()) { Standard_NullObject::Raise("Shape for centre of mass calculation is null"); } int index = aCI.GetIndex(); gp_Pnt aVertex; if (aShapeBase.ShapeType() == TopAbs_VERTEX) { if ( index != 1 ) Standard_NullObject::Raise("Vertex index is out of range"); else aVertex = BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase)); } else if (aShapeBase.ShapeType() == TopAbs_EDGE) { TopoDS_Vertex aV1, aV2; TopoDS_Edge anEdgeE = TopoDS::Edge(aShapeBase); TopExp::Vertices(anEdgeE, aV1, aV2); gp_Pnt aP1 = BRep_Tool::Pnt(aV1); gp_Pnt aP2 = BRep_Tool::Pnt(aV2); if (index < 0 || index > 1) Standard_NullObject::Raise("Vertex index is out of range"); if ( ( anEdgeE.Orientation() == TopAbs_FORWARD && index == 0 ) || ( anEdgeE.Orientation() == TopAbs_REVERSED && index == 1 ) ) aVertex = aP1; else aVertex = aP2; } else if (aShapeBase.ShapeType() == TopAbs_WIRE) { TopTools_IndexedMapOfShape anEdgeShapes; TopTools_IndexedMapOfShape aVertexShapes; TopoDS_Vertex aV1, aV2; TopoDS_Wire aWire = TopoDS::Wire(aShapeBase); TopExp_Explorer exp (aWire, TopAbs_EDGE); for (; exp.More(); exp.Next()) { anEdgeShapes.Add(exp.Current()); TopoDS_Edge E = TopoDS::Edge(exp.Current()); TopExp::Vertices(E, aV1, aV2); if ( aVertexShapes.Extent() == 0) aVertexShapes.Add(aV1); if ( !aV1.IsSame( aVertexShapes(aVertexShapes.Extent()) ) ) aVertexShapes.Add(aV1); if ( !aV2.IsSame( aVertexShapes(aVertexShapes.Extent()) ) ) aVertexShapes.Add(aV2); } if (index < 0 || index > aVertexShapes.Extent()) Standard_NullObject::Raise("Vertex index is out of range"); if (aWire.Orientation() == TopAbs_FORWARD) aVertex = BRep_Tool::Pnt(TopoDS::Vertex(aVertexShapes(index+1))); else aVertex = BRep_Tool::Pnt(TopoDS::Vertex(aVertexShapes(aVertexShapes.Extent() - index))); } else { Standard_NullObject::Raise("Shape for vertex calculation is not an edge or wire"); } aShape = BRepBuilderAPI_MakeVertex(aVertex).Shape(); } else if (aType == VECTOR_FACE_NORMALE) { // Face Handle(GEOM_Function) aRefBase = aCI.GetBase(); TopoDS_Shape aShapeBase = aRefBase->GetValue(); if (aShapeBase.IsNull()) { Standard_NullObject::Raise("Face for normale calculation is null"); } if (aShapeBase.ShapeType() != TopAbs_FACE) { Standard_NullObject::Raise("Shape for normale calculation is not a face"); } TopoDS_Face aFace = TopoDS::Face(aShapeBase); // Point gp_Pnt p1 (0,0,0); Handle(GEOM_Function) aPntFunc = aCI.GetPoint(); if (!aPntFunc.IsNull()) { TopoDS_Shape anOptPnt = aPntFunc->GetValue(); if (anOptPnt.IsNull()) Standard_NullObject::Raise("Invalid shape given for point argument"); p1 = BRep_Tool::Pnt(TopoDS::Vertex(anOptPnt)); } else { gp_Ax3 aPos = GEOMImpl_IMeasureOperations::GetPosition(aFace); p1 = aPos.Location(); } // Point parameters on surface Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); Handle(ShapeAnalysis_Surface) aSurfAna = new ShapeAnalysis_Surface (aSurf); gp_Pnt2d pUV = aSurfAna->ValueOfUV(p1, Precision::Confusion()); // Normal direction gp_Vec Vec1,Vec2; BRepAdaptor_Surface SF (aFace); SF.D1(pUV.X(), pUV.Y(), p1, Vec1, Vec2); if (Vec1.Magnitude() < Precision::Confusion()) { gp_Vec tmpV; gp_Pnt tmpP; SF.D1(pUV.X(), pUV.Y()-0.1, tmpP, Vec1, tmpV); } else if (Vec2.Magnitude() < Precision::Confusion()) { gp_Vec tmpV; gp_Pnt tmpP; SF.D1(pUV.X()-0.1, pUV.Y(), tmpP, tmpV, Vec2); } gp_Vec V = Vec1.Crossed(Vec2); Standard_Real mod = V.Magnitude(); if (mod < Precision::Confusion()) Standard_NullObject::Raise("Normal vector of a face has null magnitude"); // Set length of normal vector to average radius of curvature Standard_Real radius = 0.0; GeomLProp_SLProps aProperties (aSurf, pUV.X(), pUV.Y(), 2, Precision::Confusion()); if (aProperties.IsCurvatureDefined()) { Standard_Real radius1 = Abs(aProperties.MinCurvature()); Standard_Real radius2 = Abs(aProperties.MaxCurvature()); if (Abs(radius1) > Precision::Confusion()) { radius = 1.0 / radius1; if (Abs(radius2) > Precision::Confusion()) { radius = (radius + 1.0 / radius2) / 2.0; } } else { if (Abs(radius2) > Precision::Confusion()) { radius = 1.0 / radius2; } } } // Set length of normal vector to average dimension of the face // (only if average radius of curvature is not appropriate) if (radius < Precision::Confusion()) { Bnd_Box B; Standard_Real Xmin, Xmax, Ymin, Ymax, Zmin, Zmax; BRepBndLib::Add(aFace, B); B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); radius = ((Xmax - Xmin) + (Ymax - Ymin) + (Zmax - Zmin)) / 3.0; } if (radius < Precision::Confusion()) radius = 1.0; V *= radius / mod; // consider the face orientation if (aFace.Orientation() == TopAbs_REVERSED || aFace.Orientation() == TopAbs_INTERNAL) { V = - V; } // Edge gp_Pnt p2 = p1.Translated(V); BRepBuilderAPI_MakeEdge aBuilder (p1, p2); if (!aBuilder.IsDone()) Standard_NullObject::Raise("Vector construction failed"); aShape = aBuilder.Shape(); } else { } if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
//======================================================================= //function : SelectEdge //purpose : Find the edge <NE> connected <CE> by the vertex <CV> in the list <LE>. // <NE> Is erased of the list. If <CE> is too in the list <LE> // with the same orientation, it's erased of the list //======================================================================= static Standard_Boolean SelectEdge(const TopoDS_Face& F, const TopoDS_Edge& CE, const TopoDS_Vertex& CV, TopoDS_Edge& NE, TopTools_ListOfShape& LE) { TopTools_ListIteratorOfListOfShape itl; NE.Nullify(); for ( itl.Initialize(LE); itl.More(); itl.Next()) { if (itl.Value().IsEqual(CE)) { LE.Remove(itl); break; } } if (LE.Extent() > 1) { //-------------------------------------------------------------- // Several possible edges. // - Test the edges differents of CE //-------------------------------------------------------------- Standard_Real cf, cl, f, l; TopoDS_Face FForward = F; Handle(Geom2d_Curve) Cc, C; FForward.Orientation(TopAbs_FORWARD); Cc = BRep_Tool::CurveOnSurface(CE,FForward,cf,cl); Standard_Real dist,distmin = 100*BRep_Tool::Tolerance(CV); Standard_Real uc,u; if (CE.Orientation () == TopAbs_FORWARD) uc = cl; else uc = cf; gp_Pnt2d P2,PV = Cc->Value(uc); Standard_Real delta = FindDelta(LE,FForward); for ( itl.Initialize(LE); itl.More(); itl.Next()) { const TopoDS_Edge& E = TopoDS::Edge(itl.Value()); if (!E.IsSame(CE)) { C = BRep_Tool::CurveOnSurface(E,FForward,f,l); if (E.Orientation () == TopAbs_FORWARD) u = f; else u = l; P2 = C->Value(u); dist = PV.Distance(P2); if (dist <= distmin){ distmin = dist; } } } Standard_Real anglemax = - PI; TopoDS_Edge SelectedEdge; for ( itl.Initialize(LE); itl.More(); itl.Next()) { const TopoDS_Edge& E = TopoDS::Edge(itl.Value()); if (!E.IsSame(CE)) { C = BRep_Tool::CurveOnSurface(E,FForward,f,l); if (E.Orientation () == TopAbs_FORWARD) u = f; else u = l; P2 = C->Value(u); dist = PV.Distance(P2); if (dist <= distmin + (1./3)*delta){ gp_Pnt2d PC, P; gp_Vec2d CTg1, CTg2, Tg1, Tg2; Cc->D2(uc, PC, CTg1, CTg2); C->D2(u, P, Tg1, Tg2); Standard_Real angle; if (CE.Orientation () == TopAbs_REVERSED && E.Orientation () == TopAbs_FORWARD) { angle = CTg1.Angle(Tg1.Reversed()); } else if (CE.Orientation () == TopAbs_FORWARD && E.Orientation () == TopAbs_REVERSED) { angle = (CTg1.Reversed()).Angle(Tg1); } else if (CE.Orientation () == TopAbs_REVERSED && E.Orientation () == TopAbs_REVERSED) { angle = CTg1.Angle(Tg1); } else if (CE.Orientation () == TopAbs_FORWARD && E.Orientation () == TopAbs_FORWARD) { angle = (CTg1.Reversed()).Angle(Tg1.Reversed()); } if (angle >= anglemax) { anglemax = angle ; SelectedEdge = E; } } } } for ( itl.Initialize(LE); itl.More(); itl.Next()) { const TopoDS_Edge& E = TopoDS::Edge(itl.Value()); if (E.IsEqual(SelectedEdge)) { NE = TopoDS::Edge(E); LE.Remove(itl); break; } } } else if (LE.Extent() == 1) { NE = TopoDS::Edge(LE.First()); LE.RemoveFirst(); } else { return Standard_False; } return Standard_True; }