//pmn 26/09/97 Add parameters of approximation in BuildCurve3d
// Modified by skv - Thu Jun 3 12:39:19 2004 OCC5898
-#include <BRepLib.ixx>
-#include <BRepAdaptor_Surface.hxx>
-#include <BRepAdaptor_HSurface.hxx>
-#include <BRepAdaptor_HCurve2d.hxx>
-#include <BRep_Tool.hxx>
+#include <Adaptor3d_CurveOnSurface.hxx>
+#include <AdvApprox_ApproxAFunction.hxx>
+#include <AppParCurves_MultiBSpCurve.hxx>
+#include <AppParCurves_MultiCurve.hxx>
+#include <Approx_CurvilinearParameter.hxx>
+#include <Approx_SameParameter.hxx>
+#include <Bnd_Box.hxx>
#include <BRep_Builder.hxx>
-#include <Geom_Surface.hxx>
-#include <Geom_RectangularTrimmedSurface.hxx>
-#include <Geom_Plane.hxx>
-#include <Geom_Curve.hxx>
-#include <Geom_BSplineCurve.hxx>
-#include <Geom_TrimmedCurve.hxx>
+#include <BRep_CurveRepresentation.hxx>
+#include <BRep_GCurve.hxx>
+#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
+#include <BRep_ListOfCurveRepresentation.hxx>
+#include <BRep_TEdge.hxx>
+#include <BRep_TFace.hxx>
+#include <BRep_Tool.hxx>
+#include <BRep_TVertex.hxx>
+#include <BRepAdaptor_HCurve.hxx>
+#include <BRepAdaptor_HCurve2d.hxx>
+#include <BRepAdaptor_HSurface.hxx>
+#include <BRepAdaptor_Surface.hxx>
+#include <BRepBndLib.hxx>
+#include <BRepClass3d_SolidClassifier.hxx>
+#include <BRepLib.hxx>
+#include <BSplCLib.hxx>
+#include <ElSLib.hxx>
+#include <Extrema_LocateExtPC.hxx>
+#include <GCPnts_QuasiUniformDeflection.hxx>
+#include <Geom2d_BSplineCurve.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
-#include <Geom2d_BSplineCurve.hxx>
+#include <Geom2dAdaptor.hxx>
+#include <Geom2dAdaptor_Curve.hxx>
+#include <Geom2dAdaptor_HCurve.hxx>
+#include <Geom2dConvert.hxx>
+#include <Geom_BSplineCurve.hxx>
+#include <Geom_BSplineSurface.hxx>
+#include <Geom_Curve.hxx>
+#include <Geom_Plane.hxx>
+#include <Geom_RectangularTrimmedSurface.hxx>
+#include <Geom_Surface.hxx>
+#include <Geom_TrimmedCurve.hxx>
+#include <GeomAdaptor_Curve.hxx>
+#include <GeomAdaptor_HCurve.hxx>
+#include <GeomAdaptor_HSurface.hxx>
+#include <GeomAdaptor_Surface.hxx>
#include <GeomLib.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopoDS.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopTools_MapOfShape.hxx>
-#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
-#include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <TopExp.hxx>
+#include <GeomLProp_SLProps.hxx>
#include <gp.hxx>
#include <gp_Ax2.hxx>
#include <gp_Pln.hxx>
-#include <Standard_Real.hxx>
+#include <Poly_PolygonOnTriangulation.hxx>
+#include <Poly_Triangulation.hxx>
#include <Precision.hxx>
-#include <BRep_GCurve.hxx>
-#include <BRep_TEdge.hxx>
-#include <BRep_TFace.hxx>
-#include <AppParCurves_MultiCurve.hxx>
-#include <AppParCurves_MultiBSpCurve.hxx>
-#include <BRep_ListOfCurveRepresentation.hxx>
-#include <BRep_CurveRepresentation.hxx>
-#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
-#include <BRep_TVertex.hxx>
-#include <AdvApprox_ApproxAFunction.hxx>
-#include <Approx_SameParameter.hxx>
+#include <ProjLib_ProjectedCurve.hxx>
+#include <Standard_Real.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_MapOfTransient.hxx>
-#include <GeomAdaptor_Curve.hxx>
-#include <GeomAdaptor_HCurve.hxx>
-#include <GeomAdaptor_Surface.hxx>
-#include <GeomAdaptor_HSurface.hxx>
-#include <Geom2dAdaptor_Curve.hxx>
-#include <Geom2dAdaptor_HCurve.hxx>
-#include <Geom2dAdaptor.hxx>
-#include <Geom2dConvert.hxx>
-#include <GCPnts_QuasiUniformDeflection.hxx>
-#include <BSplCLib.hxx>
-#include <ElSLib.hxx>
-#include <Adaptor3d_CurveOnSurface.hxx>
-#include <Extrema_LocateExtPC.hxx>
-#include <ProjLib_ProjectedCurve.hxx>
-#include <BRepClass3d_SolidClassifier.hxx>
-#include <Bnd_Box.hxx>
-#include <BRepBndLib.hxx>
-#include <Approx_CurvilinearParameter.hxx>
-#include <Geom_BSplineSurface.hxx>
-
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Solid.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TShort_HArray1OfShortReal.hxx>
+#include <TColgp_Array1OfXY.hxx>
// TODO - not thread-safe static variables
static Standard_Real thePrecision = Precision::Confusion();
Standard_Real First, Last;
BRep_Builder B;
- Standard_Boolean is_closed ;
- is_closed = AnEdge.Closed() ;
-
B.UpdateEdge(AnEdge,C3d,LocalLoc,0.0e0);
BRep_Tool::Range(AnEdge, S, LC, First, Last);
B.Range(AnEdge, First, Last); //Do not forget 3D range.(PRO6412)
- TopoDS_Edge E = AnEdge ;
- E.Closed(is_closed) ;
-
}
else {
//
max_deviation = Max( tolerance, Tolerance );
if (NewCurvePtr.IsNull())
return Standard_False;
- Standard_Boolean is_closed ;
- is_closed = AnEdge.Closed() ;
B.UpdateEdge(TopoDS::Edge(AnEdge),
NewCurvePtr,
L[0],
max_deviation) ;
- TopoDS_Edge E = AnEdge ;
- E.Closed(is_closed) ;
if (jj == 1 ) {
//
// if there is only one curve on surface attached to the edge
new Geom2dAdaptor_HCurve(AnAdaptor3dCurve2d) ;
Handle(GeomAdaptor_HSurface) AnAdaptor3dSurfacePtr =
new GeomAdaptor_HSurface (AnAdaptor3dSurface) ;
- curve_on_surface_reference.Load( AnAdaptor3dCurve2dPtr) ;
- curve_on_surface_reference.Load( AnAdaptor3dSurfacePtr) ;
+ curve_on_surface_reference.Load (AnAdaptor3dCurve2dPtr, AnAdaptor3dSurfacePtr);
a_sampler.Initialize(curve_on_surface_reference,
MinToleranceRequested * factor,
current_first,
gp_Pnt Pc3d = HC->Value(u);
gp_Pnt2d p2d = pc->Value(u);
gp_Pnt Pcons = ElSLib::Value(p2d.X(),p2d.Y(),pln);
+ Standard_Real eps = Max(Pc3d.XYZ().SquareModulus(), Pcons.XYZ().SquareModulus());
+ eps = Epsilon(eps);
Standard_Real temp = Pc3d.SquareDistance(Pcons);
+ if(temp <= eps)
+ {
+ temp = 0.;
+ }
if(temp > d2) d2 = temp;
}
d2 = 1.5*sqrt(d2);
Handle(Standard_Type) TheType = C3d->DynamicType();
if( TheType == STANDARD_TYPE(Geom_TrimmedCurve))
{
- const Handle(Geom_Curve)& gtC = (*((Handle(Geom_TrimmedCurve)*)&C3d))->BasisCurve();
+ Handle(Geom_Curve) gtC (Handle(Geom_TrimmedCurve)::DownCast (C3d)->BasisCurve());
m_TrimmedPeriodical = gtC->IsPeriodic();
}
// modified by NIZHNY-OCC486 Tue Aug 27 17:15:17 2002 .
if(goodpc){
// Approx_SameParameter SameP(HC,HC2d,HS,Tolerance);
Standard_Real aTol = (isANA && isBSP) ? 1.e-7 : Tolerance;
- Approx_SameParameter SameP(HC,HC2d,HS,aTol);
+ const Handle(Adaptor3d_HCurve)& aHCurv = HC; // to avoid ambiguity
+ const Handle(Adaptor2d_HCurve2d)& aHCurv2d = HC2d; // to avoid ambiguity
+ Approx_SameParameter SameP(aHCurv,aHCurv2d,HS,aTol);
if (SameP.IsSameParameter()) {
maxdist = Max(maxdist,SameP.TolReached());
else GCurve->PCurve2(curPC);
}
}
- else IsSameP = 0;
+ else
+ {
+ //Approx_SameParameter has failed.
+ //Consequently, the situation might be,
+ //when 3D and 2D-curve do not have same-range.
+ GeomLib::SameRange( Tol2d, PC[i],
+ GCurve->First(), GCurve->Last(),
+ f3d,l3d,curPC);
+
+ if (i == 0) GCurve->PCurve(curPC);
+ else GCurve->PCurve2(curPC);
+
+ IsSameP = 0;
+ }
}
else IsSameP = 0;
aB.SetVoid();
BRepBndLib::Add(curf,aB);
if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
- S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface();
+ S = Handle(Geom_RectangularTrimmedSurface)::DownCast (S)->BasisSurface();
}
GeomAdaptor_Surface AS(S);
switch (AS.GetType()) {
}
}
+//=======================================================================
+//function : UpdateInnerTolerances
+//purpose :
+//=======================================================================
+void BRepLib::UpdateInnerTolerances(const TopoDS_Shape& aShape)
+{
+ TopTools_IndexedDataMapOfShapeListOfShape EFmap;
+ TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, EFmap);
+ BRep_Builder BB;
+ for (Standard_Integer i = 1; i <= EFmap.Extent(); i++)
+ {
+ TopoDS_Edge anEdge = TopoDS::Edge(EFmap.FindKey(i));
+ TopoDS_Vertex V1, V2;
+ TopExp::Vertices(anEdge, V1, V2);
+ Standard_Real fpar, lpar;
+ BRep_Tool::Range(anEdge, fpar, lpar);
+ Standard_Real TolEdge = BRep_Tool::Tolerance(anEdge);
+ gp_Pnt Pnt1, Pnt2;
+ Handle(BRepAdaptor_HCurve) anHCurve = new BRepAdaptor_HCurve();
+ anHCurve->ChangeCurve().Initialize(anEdge);
+ if (!V1.IsNull())
+ Pnt1 = BRep_Tool::Pnt(V1);
+ if (!V2.IsNull())
+ Pnt2 = BRep_Tool::Pnt(V2);
+
+ if (!BRep_Tool::Degenerated(anEdge) &&
+ EFmap(i).Extent() > 0)
+ {
+ NCollection_Sequence<Handle(Adaptor3d_HCurve)> theRep;
+ theRep.Append(anHCurve);
+ TopTools_ListIteratorOfListOfShape itl(EFmap(i));
+ for (; itl.More(); itl.Next())
+ {
+ const TopoDS_Face& aFace = TopoDS::Face(itl.Value());
+ Handle(BRepAdaptor_HCurve) anHCurvOnSurf = new BRepAdaptor_HCurve();
+ anHCurvOnSurf->ChangeCurve().Initialize(anEdge, aFace);
+ theRep.Append(anHCurvOnSurf);
+ }
+
+ const Standard_Integer NbSamples = (BRep_Tool::SameParameter(anEdge))? 23 : 2;
+ Standard_Real delta = (lpar - fpar)/(NbSamples-1);
+ Standard_Real MaxDist = 0.;
+ for (Standard_Integer j = 2; j <= theRep.Length(); j++)
+ {
+ for (Standard_Integer k = 0; k <= NbSamples; k++)
+ {
+ Standard_Real ParamOnCenter = (k == NbSamples)? lpar :
+ fpar + k*delta;
+ gp_Pnt Center = theRep(1)->Value(ParamOnCenter);
+ Standard_Real ParamOnCurve = (BRep_Tool::SameParameter(anEdge))? ParamOnCenter
+ : ((k == 0)? theRep(j)->FirstParameter() : theRep(j)->LastParameter());
+ gp_Pnt aPoint = theRep(j)->Value(ParamOnCurve);
+ Standard_Real aDist = Center.Distance(aPoint);
+ //aDist *= 1.1;
+ aDist += 2.*Epsilon(aDist);
+ if (aDist > MaxDist)
+ MaxDist = aDist;
+
+ //Update tolerances of vertices
+ if (k == 0 && !V1.IsNull())
+ {
+ Standard_Real aDist1 = Pnt1.Distance(aPoint);
+ aDist1 += 2.*Epsilon(aDist1);
+ BB.UpdateVertex(V1, aDist1);
+ }
+ if (k == NbSamples && !V2.IsNull())
+ {
+ Standard_Real aDist2 = Pnt2.Distance(aPoint);
+ aDist2 += 2.*Epsilon(aDist2);
+ BB.UpdateVertex(V2, aDist2);
+ }
+ }
+ }
+ BB.UpdateEdge(anEdge, MaxDist);
+ }
+ TolEdge = BRep_Tool::Tolerance(anEdge);
+ if (!V1.IsNull())
+ {
+ gp_Pnt End1 = anHCurve->Value(fpar);
+ Standard_Real dist1 = Pnt1.Distance(End1);
+ dist1 += 2.*Epsilon(dist1);
+ BB.UpdateVertex(V1, Max(dist1, TolEdge));
+ }
+ if (!V2.IsNull())
+ {
+ gp_Pnt End2 = anHCurve->Value(lpar);
+ Standard_Real dist2 = Pnt2.Distance(End2);
+ dist2 += 2.*Epsilon(dist2);
+ BB.UpdateVertex(V2, Max(dist2, TolEdge));
+ }
+ }
+}
+
//=======================================================================
//function : OrientClosedSolid
//purpose :
return Standard_True;
}
-
//=======================================================================
//function : tgtfaces
//purpose : check the angle at the border between two squares.
// Two shares should have a shared front edge.
//=======================================================================
-
-static Standard_Boolean tgtfaces(const TopoDS_Edge& Ed,
+static GeomAbs_Shape tgtfaces(const TopoDS_Edge& Ed,
const TopoDS_Face& F1,
const TopoDS_Face& F2,
- const Standard_Real ta,
+ const Standard_Real theAngleTol,
const Standard_Boolean couture)
{
// Check if pcurves exist on both faces of edge
Handle(Geom2d_Curve) aCurve;
aCurve = BRep_Tool::CurveOnSurface(Ed,F1,aFirst,aLast);
if(aCurve.IsNull())
- return Standard_False;
+ return GeomAbs_C0;
aCurve = BRep_Tool::CurveOnSurface(Ed,F2,aFirst,aLast);
if(aCurve.IsNull())
- return Standard_False;
-
+ return GeomAbs_C0;
+
Standard_Real u;
TopoDS_Edge E = Ed;
BRepAdaptor_Surface aBAS1(F1,Standard_False);
BRepAdaptor_Surface aBAS2(F2,Standard_False);
- Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface(aBAS1);
+
+ // seam edge on elementary surface is always CN
+ Standard_Boolean isElementary =
+ (aBAS1.Surface().Surface()->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) &&
+ aBAS1.Surface().Surface()->IsKind(STANDARD_TYPE(Geom_ElementarySurface)));
+ if (couture && isElementary)
+ {
+ return GeomAbs_CN;
+ }
+
+ Handle(BRepAdaptor_HSurface) HS1 = new BRepAdaptor_HSurface (aBAS1);
Handle(BRepAdaptor_HSurface) HS2;
if(couture) HS2 = HS1;
else HS2 = new BRepAdaptor_HSurface(aBAS2);
-
+ //case when edge lies on the one face
+
E.Orientation(TopAbs_FORWARD);
Handle(BRepAdaptor_HCurve2d) HC2d1 = new BRepAdaptor_HCurve2d();
HC2d1->ChangeCurve2d().Initialize(E,F1);
Standard_Boolean rev1 = (F1.Orientation() == TopAbs_REVERSED);
Standard_Boolean rev2 = (F2.Orientation() == TopAbs_REVERSED);
- Standard_Real f,l,eps, angmax = -M_PI;
- Standard_Real ang =0.;
+ Standard_Real f,l,eps;
BRep_Tool::Range(E,f,l);
Extrema_LocateExtPC ext;
Standard_Boolean IsInitialized = Standard_False;
l -= eps; // points of pointed squares.
gp_Pnt2d p;
gp_Pnt pp1,pp2;//,PP;
- gp_Vec du,dv;
+ gp_Vec du1, dv1, d2u1, d2v1, d2uv1;
+ gp_Vec du2, dv2, d2u2, d2v2, d2uv2;
gp_Vec d1,d2;
Standard_Real uu, vv, norm;
Standard_Integer i;
- Standard_Boolean Nok;
- for(i = 0; (i<= 20) && (angmax<=ta) ; i++){
+ GeomAbs_Shape aCont = (isElementary ? GeomAbs_CN : GeomAbs_C2);
+ for(i = 0; i<= 20 && aCont > GeomAbs_C0; i++)
+ {
// First suppose that this is sameParameter
- Nok = Standard_True;
u = f + (l-f)*i/20;
+
+ // take derivatives of surfaces at the same u, and compute normals
HC2d1->D0(u,p);
- HS1->D1(p.X(),p.Y(),pp1,du,dv);
- d1 = (du.Crossed(dv));
+ HS1->D2 (p.X(), p.Y(), pp1, du1, dv1, d2u1, d2v1, d2uv1);
+ d1 = (du1.Crossed(dv1));
norm = d1.Magnitude();
if (norm > 1.e-12) d1 /= norm;
- else Nok=Standard_False;
+ else continue; // skip degenerated point
if(rev1) d1.Reverse();
HC2d2->D0(u,p);
- HS2->D1(p.X(), p.Y(), pp2, du, dv);
- d2 = (du.Crossed(dv));
+ HS2->D2 (p.X(), p.Y(), pp2, du2, dv2, d2u2, d2v2, d2uv2);
+ d2 = (du2.Crossed(dv2));
norm = d2.Magnitude();
- if (norm> 1.e-12) d2 /= norm;
- else Nok=Standard_False;
+ if (norm > 1.e-12) d2 /= norm;
+ else continue; // skip degenerated point
if(rev2) d2.Reverse();
- if (Nok) ang = d1.Angle(d2);
- if (Nok &&(ang > ta)) { // Refine by projection
+ // check
+ Standard_Real ang = d1.Angle(d2);
+
+ // check special case of precise equality of derivatives,
+ // occurring when edge connects two faces built on equally
+ // defined surfaces (e.g. seam-like edges on periodic surfaces,
+ // or planar faces on the same plane)
+ if (aCont >= GeomAbs_C2 && ang < Precision::Angular() &&
+ d2u1 .IsEqual (d2u2, Precision::PConfusion(), Precision::Angular()) &&
+ d2v1 .IsEqual (d2v2, Precision::PConfusion(), Precision::Angular()) &&
+ d2uv1.IsEqual (d2uv2, Precision::PConfusion(), Precision::Angular()))
+ {
+ continue;
+ }
+
+ aCont = GeomAbs_G1;
+
+ // Refine by projection
+ if (ang > theAngleTol)
+ {
if (! IsInitialized ) {
ext.Initialize(C2,f,l,Precision::PConfusion());
IsInitialized = Standard_True;
HC2d2->D0(v,p);
p.Coord(uu,vv);
- HS2->D1(p.X(), p.Y(), pp2, du, dv);
- d2 = (du.Crossed(dv));
+ HS2->D1(p.X(), p.Y(), pp2, du2, dv2);
+ d2 = (du2.Crossed(dv2));
norm = d2.Magnitude();
if (norm> 1.e-12) d2 /= norm;
- else Nok = Standard_False;
+ else continue; // degenerated point
if(rev2) d2.Reverse();
- if (Nok) ang = d1.Angle(d2);
+ ang = d1.Angle(d2);
}
+ if (ang > theAngleTol)
+ return GeomAbs_C0;
}
- if(ang >= angmax) angmax = ang;
}
- return (angmax<=ta);
-
+ return aCont;
}
if(BRep_Tool::Continuity(E,F1,F2)<=GeomAbs_C0){
try {
- if(tgtfaces(E, F1, F2, TolAng, couture)){
- B.Continuity(E,F1,F2,GeomAbs_G1);
- }
+ GeomAbs_Shape aCont = tgtfaces(E, F1, F2, TolAng, couture);
+ B.Continuity(E,F1,F2,aCont);
}
catch(Standard_Failure)
{
BRep_Builder B;
if(BRep_Tool::Continuity(E,F1,F2)<=GeomAbs_C0){
try {
- if( tgtfaces(E, F1, F2, TolAng, F1.IsEqual(F2))) {
- B.Continuity(E,F1,F2,GeomAbs_G1);
- }
+ GeomAbs_Shape aCont = tgtfaces(E, F1, F2, TolAng, F1.IsEqual(F2));
+ B.Continuity(E,F1,F2,aCont);
+
}
catch(Standard_Failure)
{
}
}
+//=======================================================================
+// function : EnsureNormalConsistency
+// purpose : Corrects the normals in Poly_Triangulation of faces.
+// Returns TRUE if any correction is done.
+//=======================================================================
+Standard_Boolean BRepLib::
+ EnsureNormalConsistency(const TopoDS_Shape& theShape,
+ const Standard_Real theAngTol,
+ const Standard_Boolean theForceComputeNormals)
+{
+ const Standard_Real aThresDot = cos(theAngTol);
+
+ Standard_Boolean aRetVal = Standard_False, isNormalsFound = Standard_False;
+
+ // compute normals if they are absent
+ TopExp_Explorer anExpFace(theShape,TopAbs_FACE);
+ for (; anExpFace.More(); anExpFace.Next())
+ {
+ const TopoDS_Face& aFace = TopoDS::Face(anExpFace.Current());
+ const Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+ if(aSurf.IsNull())
+ continue;
+ TopLoc_Location aLoc;
+ const Handle(Poly_Triangulation)& aPT = BRep_Tool::Triangulation(aFace, aLoc);
+ if(aPT.IsNull())
+ continue;
+ if (!theForceComputeNormals && aPT->HasNormals())
+ {
+ isNormalsFound = Standard_True;
+ continue;
+ }
+
+ GeomLProp_SLProps aSLP(aSurf, 2, Precision::Confusion());
+ const Standard_Integer anArrDim = 3*aPT->NbNodes();
+ Handle(TShort_HArray1OfShortReal) aNormArr = new TShort_HArray1OfShortReal(1, anArrDim);
+ Standard_Integer anNormInd = aNormArr->Lower();
+ for(Standard_Integer i = aPT->UVNodes().Lower(); i <= aPT->UVNodes().Upper(); i++)
+ {
+ const gp_Pnt2d &aP2d = aPT->UVNodes().Value(i);
+ aSLP.SetParameters(aP2d.X(), aP2d.Y());
+
+ gp_XYZ aNorm(0.,0.,0.);
+ if(!aSLP.IsNormalDefined())
+ {
+#ifdef OCCT_DEBUG
+ cout << "BRepLib::EnsureNormalConsistency(): Cannot find normal!" << endl;
+#endif
+ }
+ else
+ {
+ aNorm = aSLP.Normal().XYZ();
+ if (aFace.Orientation() == TopAbs_REVERSED)
+ aNorm.Reverse();
+ }
+ aNormArr->ChangeValue(anNormInd++) = static_cast<Standard_ShortReal>(aNorm.X());
+ aNormArr->ChangeValue(anNormInd++) = static_cast<Standard_ShortReal>(aNorm.Y());
+ aNormArr->ChangeValue(anNormInd++) = static_cast<Standard_ShortReal>(aNorm.Z());
+ }
+
+ aRetVal = Standard_True;
+ isNormalsFound = Standard_True;
+ aPT->SetNormals(aNormArr);
+ }
+
+ if(!isNormalsFound)
+ {
+ return aRetVal;
+ }
+
+ // loop by edges
+ TopTools_IndexedDataMapOfShapeListOfShape aMapEF;
+ TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,aMapEF);
+ for(Standard_Integer anInd = 1; anInd <= aMapEF.Extent(); anInd++)
+ {
+ const TopoDS_Edge& anEdg = TopoDS::Edge(aMapEF.FindKey(anInd));
+ const TopTools_ListOfShape& anEdgList = aMapEF.FindFromIndex(anInd);
+ if (anEdgList.Extent() != 2)
+ continue;
+ TopTools_ListIteratorOfListOfShape anItF(anEdgList);
+ const TopoDS_Face aFace1 = TopoDS::Face(anItF.Value());
+ anItF.Next();
+ const TopoDS_Face aFace2 = TopoDS::Face(anItF.Value());
+ TopLoc_Location aLoc1, aLoc2;
+ const Handle(Poly_Triangulation)& aPT1 = BRep_Tool::Triangulation(aFace1, aLoc1);
+ const Handle(Poly_Triangulation)& aPT2 = BRep_Tool::Triangulation(aFace2, aLoc2);
+
+ if(aPT1.IsNull() || aPT2.IsNull())
+ continue;
+
+ if(!aPT1->HasNormals() || !aPT2->HasNormals())
+ continue;
+
+ const Handle(Poly_PolygonOnTriangulation)& aPTEF1 =
+ BRep_Tool::PolygonOnTriangulation(anEdg, aPT1, aLoc1);
+ const Handle(Poly_PolygonOnTriangulation)& aPTEF2 =
+ BRep_Tool::PolygonOnTriangulation(anEdg, aPT2, aLoc2);
+
+ TShort_Array1OfShortReal& aNormArr1 = aPT1->ChangeNormals();
+ TShort_Array1OfShortReal& aNormArr2 = aPT2->ChangeNormals();
+
+ for(Standard_Integer anEdgNode = aPTEF1->Nodes().Lower();
+ anEdgNode <= aPTEF1->Nodes().Upper(); anEdgNode++)
+ {
+ //Number of node
+ const Standard_Integer aFNodF1 = aPTEF1->Nodes().Value(anEdgNode);
+ const Standard_Integer aFNodF2 = aPTEF2->Nodes().Value(anEdgNode);
+
+ const Standard_Integer aFNorm1FirstIndex = aNormArr1.Lower() + 3*
+ (aFNodF1 - aPT1->Nodes().Lower());
+ const Standard_Integer aFNorm2FirstIndex = aNormArr2.Lower() + 3*
+ (aFNodF2 - aPT2->Nodes().Lower());
+
+ gp_XYZ aNorm1(aNormArr1.Value(aFNorm1FirstIndex),
+ aNormArr1.Value(aFNorm1FirstIndex+1),
+ aNormArr1.Value(aFNorm1FirstIndex+2));
+ gp_XYZ aNorm2(aNormArr2.Value(aFNorm2FirstIndex),
+ aNormArr2.Value(aFNorm2FirstIndex+1),
+ aNormArr2.Value(aFNorm2FirstIndex+2));
+ const Standard_Real aDot = aNorm1 * aNorm2;
+
+ if(aDot > aThresDot)
+ {
+ gp_XYZ aNewNorm = (aNorm1 + aNorm2).Normalized();
+ aNormArr1.ChangeValue(aFNorm1FirstIndex) =
+ aNormArr2.ChangeValue(aFNorm2FirstIndex) =
+ static_cast<Standard_ShortReal>(aNewNorm.X());
+ aNormArr1.ChangeValue(aFNorm1FirstIndex+1) =
+ aNormArr2.ChangeValue(aFNorm2FirstIndex+1) =
+ static_cast<Standard_ShortReal>(aNewNorm.Y());
+ aNormArr1.ChangeValue(aFNorm1FirstIndex+2) =
+ aNormArr2.ChangeValue(aFNorm2FirstIndex+2) =
+ static_cast<Standard_ShortReal>(aNewNorm.Z());
+ aRetVal = Standard_True;
+ }
+ }
+ }
+
+ return aRetVal;
+}
+
//=======================================================================
//function : SortFaces
//purpose :
S = BRep_Tool::Surface(F, l);
if (!S.IsNull()) {
if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
- S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface();
+ S = Handle(Geom_RectangularTrimmedSurface)::DownCast (S)->BasisSurface();
}
GeomAdaptor_Surface AS(S);
switch (AS.GetType()) {
S = BRep_Tool::Surface(F, l);
if (!S.IsNull()) {
if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
- S = (*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface();
+ S = Handle(Geom_RectangularTrimmedSurface)::DownCast (S)->BasisSurface();
}
GeomAdaptor_Surface AS(S);
switch (AS.GetType()) {