From 71598a83cd792e14f681b46794bd7036878515f7 Mon Sep 17 00:00:00 2001 From: pdn Date: Mon, 22 Sep 2014 16:54:59 +0400 Subject: [PATCH] 0025252: Slow down in reading of .brep on VS2011 Reading of .brep is slow down on VS2011 due to problems in realization reading ASCII strings to real. Implementation of dedicated function for reading of reals was implemented --- src/BRepTools/BRepTools_ShapeSet.cxx | 50 +++++++++++++++++--------- src/GeomTools/GeomTools.cdl | 5 +++ src/GeomTools/GeomTools.cxx | 19 ++++++++++ src/GeomTools/GeomTools_Curve2dSet.cxx | 32 +++++++++++------ src/GeomTools/GeomTools_CurveSet.cxx | 34 ++++++++++++------ src/GeomTools/GeomTools_SurfaceSet.cxx | 39 +++++++++++++------- src/TopTools/TopTools_LocationSet.cxx | 18 ++++++++-- 7 files changed, 143 insertions(+), 54 deletions(-) diff --git a/src/BRepTools/BRepTools_ShapeSet.cxx b/src/BRepTools/BRepTools_ShapeSet.cxx index c7c225c8b4..286b2aa2db 100644 --- a/src/BRepTools/BRepTools_ShapeSet.cxx +++ b/src/BRepTools/BRepTools_ShapeSet.cxx @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -837,8 +838,10 @@ void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, TopoDS_Vertex& V = TopoDS::Vertex(S); // Read the point geometry - IS >> tol; - IS >> X >> Y >> Z; + GeomTools::GetReal(IS, tol); + GeomTools::GetReal(IS, X); + GeomTools::GetReal(IS, Y); + GeomTools::GetReal(IS, Z); myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol); Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape()); @@ -846,7 +849,8 @@ void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, TopLoc_Location L; do { - IS >> p1 >> val; + GeomTools::GetReal(IS, p1); + IS >> val; Handle(BRep_PointRepresentation) PR; switch (val) { @@ -889,7 +893,8 @@ void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, case 3 : { - IS >> p2 >> s; + GeomTools::GetReal(IS, p2); + IS >> s; // Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin if (mySurfaces.Surface(s).IsNull()) @@ -931,7 +936,7 @@ void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, myBuilder.MakeEdge(E); // Read the curve geometry - IS >> tol; + GeomTools::GetReal(IS, tol); IS >> val; myBuilder.SameParameter(E,(val == 1)); IS >> val; @@ -949,7 +954,8 @@ void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, myBuilder.UpdateEdge(E,myCurves.Curve(c), Locations().Location(l),tol); } - IS >> first >> last; + GeomTools::GetReal(IS, first); + GeomTools::GetReal(IS, last); if (!myCurves.Curve(c).IsNull()) { Standard_Boolean Only3d = Standard_True; myBuilder.Range(E,first,last,Only3d); @@ -970,12 +976,16 @@ void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, IS >> s >> l; // range - IS >> first >> last; + GeomTools::GetReal(IS, first); + GeomTools::GetReal(IS, last); // read UV Points // for XML Persistence higher performance if (FormatNb() == 2) { - IS >> PfX >> PfY >> PlX >> PlY; + GeomTools::GetReal(IS, PfX); + GeomTools::GetReal(IS, PfY); + GeomTools::GetReal(IS, PlX); + GeomTools::GetReal(IS, PlY); aPf = gp_Pnt2d(PfX,PfY); aPl = gp_Pnt2d(PlX,PlY); } @@ -1106,7 +1116,8 @@ void BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, IS >> val; // natural restriction if (val == 0 || val == 1) { - IS >> tol >> s >> l; + GeomTools::GetReal(IS, tol); + IS >> s >> l; // Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin if (!mySurfaces.Surface(s).IsNull()) { // Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End @@ -1310,12 +1321,12 @@ void BRepTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS) IS >> buffer; // if (!strcasecmp(buffer, "p")) { Standard_Real def; - IS >> def; + GeomTools::GetReal(IS, def); IS >> hasparameters; if (hasparameters) { TColStd_Array1OfReal Param1(1, nbnodes); for (j = 1; j <= nbnodes; j++) { - IS >> par; + GeomTools::GetReal(IS, par); Param1(j) = par; } Poly = new Poly_PolygonOnTriangulation(Nodes, Param1); @@ -1436,15 +1447,17 @@ void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS) IS >> nbnodes; IS >> hasparameters; TColgp_Array1OfPnt Nodes(1, nbnodes); - IS >> d; + GeomTools::GetReal(IS, d); for (j = 1; j <= nbnodes; j++) { - IS >> x >> y >> z; + GeomTools::GetReal(IS, x); + GeomTools::GetReal(IS, y); + GeomTools::GetReal(IS, z); Nodes(j).SetCoord(x,y,z); } if (hasparameters) { TColStd_Array1OfReal Param(1,nbnodes); for (p = 1; p <= nbnodes; p++) { - IS >> Param(p); + GeomTools::GetReal(IS, Param(p)); } P = new Poly_Polygon3D(Nodes, Param); } @@ -1586,19 +1599,22 @@ void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS) for (i=1; i<=nbtri && PS.More();i++, PS.Next()) { IS >> nbNodes >> nbTriangles >> hasUV; - IS >> d; + GeomTools::GetReal(IS, d); TColgp_Array1OfPnt Nodes(1, nbNodes); TColgp_Array1OfPnt2d UVNodes(1, nbNodes); for (j = 1; j <= nbNodes; j++) { - IS >> x >> y >> z; + GeomTools::GetReal(IS, x); + GeomTools::GetReal(IS, y); + GeomTools::GetReal(IS, z); Nodes(j).SetCoord(x,y,z); } if (hasUV) { for (j = 1; j <= nbNodes; j++) { - IS >> x >> y; + GeomTools::GetReal(IS, x); + GeomTools::GetReal(IS, y); UVNodes(j).SetCoord(x,y); } } diff --git a/src/GeomTools/GeomTools.cdl b/src/GeomTools/GeomTools.cdl index 1fbe341b90..51a0f2014f 100644 --- a/src/GeomTools/GeomTools.cdl +++ b/src/GeomTools/GeomTools.cdl @@ -79,6 +79,11 @@ is GetUndefinedTypeHandler returns UndefinedTypeHandler from GeomTools; + GetReal(IS : out IStream from Standard; theValue : out Real from Standard); + ---Purpose: Reads the Standard_Real value from the stream. Zero is read + --- in case of error + + end GeomTools; diff --git a/src/GeomTools/GeomTools.cxx b/src/GeomTools/GeomTools.cxx index 92958a2834..feb2592e28 100644 --- a/src/GeomTools/GeomTools.cxx +++ b/src/GeomTools/GeomTools.cxx @@ -88,3 +88,22 @@ Handle(GeomTools_UndefinedTypeHandler) GeomTools::GetUndefinedTypeHandler() { return theActiveHandler; } + +//======================================================================= +//function : GetReal +//purpose : +//======================================================================= + +void GeomTools::GetReal(Standard_IStream& IS,Standard_Real& theValue) +{ + theValue = 0.; + if (IS.eof()) + return; + + char buffer[256]; + buffer[0] = '\0'; + std::streamsize anOldWide = IS.width(256); + IS >> buffer; + IS.width(anOldWide); + theValue = Strtod(buffer, NULL); +} diff --git a/src/GeomTools/GeomTools_Curve2dSet.cxx b/src/GeomTools/GeomTools_Curve2dSet.cxx index 7897e4b7f7..e089f0bdd7 100644 --- a/src/GeomTools/GeomTools_Curve2dSet.cxx +++ b/src/GeomTools/GeomTools_Curve2dSet.cxx @@ -519,7 +519,8 @@ void GeomTools_Curve2dSet::Write(Standard_OStream& OS)const static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt2d& P) { Standard_Real X=0.,Y=0.; - IS >> X >> Y; + GeomTools::GetReal(IS, X); + GeomTools::GetReal(IS, Y); P.SetCoord(X,Y); return IS; } @@ -532,7 +533,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt2d& P) static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir2d& D) { Standard_Real X=0.,Y=0.; - IS >> X >> Y; + GeomTools::GetReal(IS, X); + GeomTools::GetReal(IS, Y); D.SetCoord(X,Y); return IS; } @@ -564,7 +566,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt2d P(0.,0.); gp_Dir2d AX(1.,0.),AY(1.,0.); Standard_Real R=0.; - IS >> P >> AX >> AY >> R; + IS >> P >> AX >> AY; + GeomTools::GetReal(IS, R); C = new Geom2d_Circle(gp_Ax22d(P,AX,AY),R); return IS; } @@ -580,7 +583,9 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt2d P(0.,0.); gp_Dir2d AX(1.,0.),AY(1.,0.); Standard_Real R1=0.,R2=0.; - IS >> P >> AX >> AY >> R1 >> R2; + IS >> P >> AX >> AY; + GeomTools::GetReal(IS, R1); + GeomTools::GetReal(IS, R2); E = new Geom2d_Ellipse(gp_Ax22d(P,AX,AY),R1,R2); return IS; } @@ -596,7 +601,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt2d P(0.,0.); gp_Dir2d AX(1.,0.),AY(1.,0.); Standard_Real R1=0.; - IS >> P >> AX >> AY >> R1; + IS >> P >> AX >> AY; + GeomTools::GetReal(IS, R1); C = new Geom2d_Parabola(gp_Ax22d(P,AX,AY),R1); return IS; } @@ -612,7 +618,9 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt2d P(0.,0.); gp_Dir2d AX(1.,0.),AY(1.,0.); Standard_Real R1=0.,R2=0.; - IS >> P >> AX >> AY >> R1 >> R2; + IS >> P >> AX >> AY; + GeomTools::GetReal(IS, R1); + GeomTools::GetReal(IS, R2); H = new Geom2d_Hyperbola(gp_Ax22d(P,AX,AY),R1,R2); return IS; } @@ -638,7 +646,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, for (i = 1; i <= degree+1; i++) { IS >> poles(i); if (rational) - IS >> weights(i); + GeomTools::GetReal(IS, weights(i)); } if (rational) @@ -670,14 +678,15 @@ static Standard_IStream& operator>>(Standard_IStream& IS, for (i = 1; i <= nbpoles; i++) { IS >> poles(i); if (rational) - IS >> weights(i); + GeomTools::GetReal(IS, weights(i)); } TColStd_Array1OfReal knots(1,nbknots); TColStd_Array1OfInteger mults(1,nbknots); for (i = 1; i <= nbknots; i++) { - IS >> knots(i) >> mults(i); + GeomTools::GetReal(IS, knots(i)); + IS >> mults(i); } if (rational) @@ -697,7 +706,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom2d_TrimmedCurve)& C) { Standard_Real p1=0.,p2=0.; - IS >> p1 >> p2; + GeomTools::GetReal(IS, p1); + GeomTools::GetReal(IS, p2); Handle(Geom2d_Curve) BC; GeomTools_Curve2dSet::ReadCurve2d(IS,BC); C = new Geom2d_TrimmedCurve(BC,p1,p2); @@ -713,7 +723,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom2d_OffsetCurve)& C) { Standard_Real p=0.; - IS >> p; + GeomTools::GetReal(IS, p); Handle(Geom2d_Curve) BC; GeomTools_Curve2dSet::ReadCurve2d(IS,BC); C = new Geom2d_OffsetCurve(BC,p); diff --git a/src/GeomTools/GeomTools_CurveSet.cxx b/src/GeomTools/GeomTools_CurveSet.cxx index 3d8cd71a77..a7e98385f8 100644 --- a/src/GeomTools/GeomTools_CurveSet.cxx +++ b/src/GeomTools/GeomTools_CurveSet.cxx @@ -536,7 +536,9 @@ void GeomTools_CurveSet::Write(Standard_OStream& OS)const static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt& P) { Standard_Real X=0.,Y=0.,Z=0.; - IS >> X >> Y >> Z; + GeomTools::GetReal(IS, X); + GeomTools::GetReal(IS, Y); + GeomTools::GetReal(IS, Z); P.SetCoord(X,Y,Z); return IS; } @@ -549,7 +551,9 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt& P) static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir& D) { Standard_Real X=0.,Y=0.,Z=0.; - IS >> X >> Y >> Z; + GeomTools::GetReal(IS, X); + GeomTools::GetReal(IS, Y); + GeomTools::GetReal(IS, Z); D.SetCoord(X,Y,Z); return IS; } @@ -581,7 +585,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt P(0.,0.,0.); gp_Dir A(1.,0.,0.),AX(1.,0.,0.),AY(1.,0.,0.); Standard_Real R=0.; - IS >> P >> A >> AX >> AY >> R; + IS >> P >> A >> AX >> AY; + GeomTools::GetReal(IS, R); C = new Geom_Circle(gp_Ax2(P,A,AX),R); return IS; } @@ -597,7 +602,9 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt P(0.,0.,0.); gp_Dir A(1.,0.,0.),AX(1.,0.,0.),AY(1.,0.,0.); Standard_Real R1=0.,R2=0.; - IS >> P >> A >> AX >> AY >> R1 >> R2; + IS >> P >> A >> AX >> AY; + GeomTools::GetReal(IS, R1); + GeomTools::GetReal(IS, R2); E = new Geom_Ellipse(gp_Ax2(P,A,AX),R1,R2); return IS; } @@ -613,7 +620,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt P(0.,0.,0.); gp_Dir A(1.,0.,0.),AX(1.,0.,0.),AY(1.,0.,0.); Standard_Real R1=0.; - IS >> P >> A >> AX >> AY >> R1; + IS >> P >> A >> AX >> AY; + GeomTools::GetReal(IS, R1); C = new Geom_Parabola(gp_Ax2(P,A,AX),R1); return IS; } @@ -629,7 +637,9 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt P(0.,0.,0.); gp_Dir A(1.,0.,0.),AX(1.,0.,0.),AY(1.,0.,0.); Standard_Real R1=0.,R2=0.; - IS >> P >> A >> AX >> AY >> R1 >> R2; + IS >> P >> A >> AX >> AY; + GeomTools::GetReal(IS, R1); + GeomTools::GetReal(IS, R2); H = new Geom_Hyperbola(gp_Ax2(P,A,AX),R1,R2); return IS; } @@ -655,7 +665,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, for (i = 1; i <= degree+1; i++) { IS >> poles(i); if (rational) - IS >> weights(i); + GeomTools::GetReal(IS, weights(i)); } if (rational) @@ -688,14 +698,15 @@ static Standard_IStream& operator>>(Standard_IStream& IS, for (i = 1; i <= nbpoles; i++) { IS >> poles(i); if (rational) - IS >> weights(i); + GeomTools::GetReal(IS, weights(i)); } TColStd_Array1OfReal knots(1,nbknots); TColStd_Array1OfInteger mults(1,nbknots); for (i = 1; i <= nbknots; i++) { - IS >> knots(i) >> mults(i); + GeomTools::GetReal(IS, knots(i)); + IS >> mults(i); } if (rational) @@ -715,7 +726,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_TrimmedCurve)& C) { Standard_Real p1=0.,p2=0.; - IS >> p1 >> p2; + GeomTools::GetReal(IS, p1); + GeomTools::GetReal(IS, p2); Handle(Geom_Curve) BC; GeomTools_CurveSet::ReadCurve(IS,BC); C = new Geom_TrimmedCurve(BC,p1,p2); @@ -731,7 +743,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_OffsetCurve)& C) { Standard_Real p=0.; - IS >> p; + GeomTools::GetReal(IS, p); gp_Dir D(1.,0.,0.); IS >> D; Handle(Geom_Curve) BC; diff --git a/src/GeomTools/GeomTools_SurfaceSet.cxx b/src/GeomTools/GeomTools_SurfaceSet.cxx index bda21b0a68..5bb8c8f1f7 100644 --- a/src/GeomTools/GeomTools_SurfaceSet.cxx +++ b/src/GeomTools/GeomTools_SurfaceSet.cxx @@ -656,7 +656,9 @@ void GeomTools_SurfaceSet::Write(Standard_OStream& OS)const static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt& P) { Standard_Real X=0.,Y=0.,Z=0.; - IS >> X >> Y >> Z; + GeomTools::GetReal(IS, X); + GeomTools::GetReal(IS, Y); + GeomTools::GetReal(IS, Z); P.SetCoord(X,Y,Z); return IS; } @@ -669,7 +671,9 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt& P) static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir& D) { Standard_Real X=0.,Y=0.,Z=0.; - IS >> X >> Y >> Z; + GeomTools::GetReal(IS, X); + GeomTools::GetReal(IS, Y); + GeomTools::GetReal(IS, Z); D.SetCoord(X,Y,Z); return IS; } @@ -716,7 +720,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, { gp_Ax3 A; Standard_Real R=0.; - IS >> A >> R; + IS >> A; + GeomTools::GetReal(IS, R); S = new Geom_CylindricalSurface(A,R); return IS; } @@ -731,7 +736,9 @@ static Standard_IStream& operator>>(Standard_IStream& IS, { gp_Ax3 A; Standard_Real R=0.,Ang=0.; - IS >> A >> R >> Ang; + IS >> A; + GeomTools::GetReal(IS, R); + GeomTools::GetReal(IS, Ang); S = new Geom_ConicalSurface(A,Ang,R); return IS; } @@ -746,7 +753,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, { gp_Ax3 A; Standard_Real R=0.; - IS >> A >> R; + IS >> A; + GeomTools::GetReal(IS, R); S = new Geom_SphericalSurface(A,R); return IS; } @@ -761,7 +769,9 @@ static Standard_IStream& operator>>(Standard_IStream& IS, { gp_Ax3 A; Standard_Real R1=0.,R2=0.; - IS >> A >> R1 >> R2; + IS >> A; + GeomTools::GetReal(IS, R1); + GeomTools::GetReal(IS, R2); S = new Geom_ToroidalSurface(A,R1,R2); return IS; } @@ -819,7 +829,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, for (j = 1; j <= vdegree+1; j++) { IS >> poles(i,j); if (urational || vrational) - IS >> weights(i,j); + GeomTools::GetReal(IS, weights(i,j)); } } @@ -855,20 +865,22 @@ static Standard_IStream& operator>>(Standard_IStream& IS, for (j = 1; j <= nbvpoles; j++) { IS >> poles(i,j); if (urational || vrational) - IS >> weights(i,j); + GeomTools::GetReal(IS, weights(i,j)); } } TColStd_Array1OfReal uknots(1,nbuknots); TColStd_Array1OfInteger umults(1,nbuknots); for (i = 1; i <= nbuknots; i++) { - IS >> uknots(i) >> umults(i); + GeomTools::GetReal(IS, uknots(i)); + IS >> umults(i); } TColStd_Array1OfReal vknots(1,nbvknots); TColStd_Array1OfInteger vmults(1,nbvknots); for (i = 1; i <= nbvknots; i++) { - IS >> vknots(i) >> vmults(i); + GeomTools::GetReal(IS, vknots(i)); + IS >> vmults(i); } if (urational || vrational) @@ -889,7 +901,10 @@ static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_RectangularTrimmedSurface)& S) { Standard_Real U1=0.,U2=0.,V1=0.,V2=0.; - IS >> U1 >> U2 >> V1 >> V2; + GeomTools::GetReal(IS, U1); + GeomTools::GetReal(IS, U2); + GeomTools::GetReal(IS, V1); + GeomTools::GetReal(IS, V2); Handle(Geom_Surface) BS; GeomTools_SurfaceSet::ReadSurface(IS,BS); S = new Geom_RectangularTrimmedSurface(BS,U1,U2,V1,V2); @@ -905,7 +920,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS, Handle(Geom_OffsetSurface)& S) { Standard_Real O=0.; - IS >> O; + GeomTools::GetReal(IS, O); Handle(Geom_Surface) BS; GeomTools_SurfaceSet::ReadSurface(IS,BS); S = new Geom_OffsetSurface(BS,O); diff --git a/src/TopTools/TopTools_LocationSet.cxx b/src/TopTools/TopTools_LocationSet.cxx index 23e16d901b..1c015a8e2d 100644 --- a/src/TopTools/TopTools_LocationSet.cxx +++ b/src/TopTools/TopTools_LocationSet.cxx @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -219,9 +220,20 @@ static void ReadTrsf(gp_Trsf& T, Standard_Real V1[3],V2[3],V3[3]; Standard_Real V[3]; - IS >> V1[0] >> V1[1] >> V1[2] >> V[0]; - IS >> V2[0] >> V2[1] >> V2[2] >> V[1]; - IS >> V3[0] >> V3[1] >> V3[2] >> V[2]; + GeomTools::GetReal(IS, V1[0]); + GeomTools::GetReal(IS, V1[1]); + GeomTools::GetReal(IS, V1[2]); + GeomTools::GetReal(IS, V[0]); + + GeomTools::GetReal(IS, V2[0]); + GeomTools::GetReal(IS, V2[1]); + GeomTools::GetReal(IS, V2[2]); + GeomTools::GetReal(IS, V[1]); + + GeomTools::GetReal(IS, V3[0]); + GeomTools::GetReal(IS, V3[1]); + GeomTools::GetReal(IS, V3[2]); + GeomTools::GetReal(IS, V[2]); T.SetValues(V1[0],V1[1],V1[2],V[0], V2[0],V2[1],V2[2],V[1],