NPAL18620: Pb. of performance with MakeTranslation. Improve transformations to avoid accumulation of locations in a shape.

This commit is contained in:
jfa 2008-01-28 11:56:59 +00:00
parent e170a5ac49
commit 1124a13601
2 changed files with 185 additions and 140 deletions

View File

@ -8,7 +8,7 @@
// //
// This library is distributed in the hope that it will be useful // This library is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details. // Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public // You should have received a copy of the GNU Lesser General Public
@ -72,25 +72,25 @@ GEOMImpl_RotateDriver::GEOMImpl_RotateDriver()
//======================================================================= //=======================================================================
Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const
{ {
if(Label().IsNull()) return 0; if (Label().IsNull()) return 0;
Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
if(aFunction.IsNull()) return 0; if (aFunction.IsNull()) return 0;
GEOMImpl_IRotate RI(aFunction); GEOMImpl_IRotate RI(aFunction);
gp_Trsf aTrsf; gp_Trsf aTrsf;
gp_Pnt aCP, aP1, aP2; gp_Pnt aCP, aP1, aP2;
Standard_Integer aType = aFunction->GetType(); Standard_Integer aType = aFunction->GetType();
Handle(GEOM_Function) anOriginalFunction = RI.GetOriginal(); Handle(GEOM_Function) anOriginalFunction = RI.GetOriginal();
if(anOriginalFunction.IsNull()) return 0; if (anOriginalFunction.IsNull()) return 0;
TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue(); TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue();
if(anOriginal.IsNull()) return 0; if (anOriginal.IsNull()) return 0;
if(aType == ROTATE || aType == ROTATE_COPY) { if (aType == ROTATE || aType == ROTATE_COPY) {
Handle(GEOM_Function) anAxis = RI.GetAxis(); Handle(GEOM_Function) anAxis = RI.GetAxis();
if(anAxis.IsNull()) return 0; if (anAxis.IsNull()) return 0;
TopoDS_Shape A = anAxis->GetValue(); TopoDS_Shape A = anAxis->GetValue();
if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0; if (A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0;
TopoDS_Edge anEdge = TopoDS::Edge(A); TopoDS_Edge anEdge = TopoDS::Edge(A);
gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)); gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
@ -100,10 +100,16 @@ Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const
Standard_Real anAngle = RI.GetAngle(); Standard_Real anAngle = RI.GetAngle();
aTrsf.SetRotation(anAx1, anAngle); aTrsf.SetRotation(anAx1, anAngle);
BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False); //NPAL18620: performance problem: multiple locations are accumulated
aShape = aTransformation.Shape(); // in shape and need a great time to process
//BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
//aShape = aTransformation.Shape();
TopLoc_Location aLocOrig = anOriginal.Location();
gp_Trsf aTrsfOrig = aLocOrig.Transformation();
TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
aShape = anOriginal.Located(aLocRes);
} }
else if(aType == ROTATE_THREE_POINTS || aType == ROTATE_THREE_POINTS_COPY) { else if (aType == ROTATE_THREE_POINTS || aType == ROTATE_THREE_POINTS_COPY) {
Handle(GEOM_Function) aCentPoint = RI.GetCentPoint(); Handle(GEOM_Function) aCentPoint = RI.GetCentPoint();
Handle(GEOM_Function) aPoint1 = RI.GetPoint1(); Handle(GEOM_Function) aPoint1 = RI.GetPoint1();
Handle(GEOM_Function) aPoint2 = RI.GetPoint2(); Handle(GEOM_Function) aPoint2 = RI.GetPoint2();
@ -125,10 +131,16 @@ Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const
gp_Ax1 anAx1(aCP, aDir); gp_Ax1 anAx1(aCP, aDir);
Standard_Real anAngle = aVec1.Angle(aVec2); Standard_Real anAngle = aVec1.Angle(aVec2);
aTrsf.SetRotation(anAx1, anAngle); aTrsf.SetRotation(anAx1, anAngle);
BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False); //NPAL18620: performance problem: multiple locations are accumulated
aShape = aTransformation.Shape(); // in shape and need a great time to process
//BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
//aShape = aTransformation.Shape();
TopLoc_Location aLocOrig = anOriginal.Location();
gp_Trsf aTrsfOrig = aLocOrig.Transformation();
TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
aShape = anOriginal.Located(aLocRes);
} }
else if(aType == ROTATE_1D) { else if (aType == ROTATE_1D) {
//Get direction //Get direction
Handle(GEOM_Function) anAxis = RI.GetAxis(); Handle(GEOM_Function) anAxis = RI.GetAxis();
if(anAxis.IsNull()) return 0; if(anAxis.IsNull()) return 0;
@ -138,27 +150,34 @@ Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const
gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)); gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge)); gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
gp_Dir D(gp_Vec(aP1, aP2)) ; gp_Dir D(gp_Vec(aP1, aP2));
gp_Ax1 AX1(aP1, D) ; gp_Ax1 AX1(aP1, D);
Standard_Integer nbtimes = RI.GetNbIter1(); Standard_Integer nbtimes = RI.GetNbIter1();
Standard_Real angle = 360.0/nbtimes ; Standard_Real angle = 360.0/nbtimes;
TopoDS_Compound aCompound; TopoDS_Compound aCompound;
BRep_Builder B; BRep_Builder B;
B.MakeCompound( aCompound ); B.MakeCompound( aCompound );
TopLoc_Location aLocOrig = anOriginal.Location();
gp_Trsf aTrsfOrig = aLocOrig.Transformation();
for (int i = 0; i < nbtimes; i++ ) { for (int i = 0; i < nbtimes; i++ ) {
aTrsf.SetRotation(AX1, i*angle*PI180) ; aTrsf.SetRotation(AX1, i*angle*PI180);
BRepBuilderAPI_Transform myBRepTransformation(anOriginal, aTrsf, Standard_False) ; //NPAL18620: performance problem: multiple locations are accumulated
B.Add( aCompound, myBRepTransformation.Shape() ); // in shape and need a great time to process
//BRepBuilderAPI_Transform aBRepTransformation(anOriginal, aTrsf, Standard_False);
//B.Add(aCompound, aBRepTransformation.Shape());
TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
B.Add(aCompound, anOriginal.Located(aLocRes));
} }
aShape = aCompound ; aShape = aCompound;
} }
else if(aType == ROTATE_2D) { else if (aType == ROTATE_2D) {
Standard_Real DX, DY, DZ ; Standard_Real DX, DY, DZ;
//Get direction //Get direction
Handle(GEOM_Function) anAxis = RI.GetAxis(); Handle(GEOM_Function) anAxis = RI.GetAxis();
@ -168,39 +187,39 @@ Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const
TopoDS_Edge anEdge = TopoDS::Edge(A); TopoDS_Edge anEdge = TopoDS::Edge(A);
gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)); gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge)); gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
gp_Dir D(gp_Vec(aP1, aP2)) ; gp_Dir D(gp_Vec(aP1, aP2));
gp_Ax1 AX1(aP1, D) ; gp_Ax1 AX1(aP1, D);
gp_Trsf theTransformation1 ; gp_Trsf aTrsf1;
gp_Trsf theTransformation2 ; gp_Trsf aTrsf2;
gp_Pnt P1 ; gp_Pnt P1;
GProp_GProps System ; GProp_GProps System;
if ( anOriginal.ShapeType() == TopAbs_VERTEX) { if (anOriginal.ShapeType() == TopAbs_VERTEX) {
P1 = BRep_Tool::Pnt(TopoDS::Vertex( anOriginal )); P1 = BRep_Tool::Pnt(TopoDS::Vertex( anOriginal ));
} }
else if ( anOriginal.ShapeType() == TopAbs_EDGE || anOriginal.ShapeType() == TopAbs_WIRE ) { else if ( anOriginal.ShapeType() == TopAbs_EDGE || anOriginal.ShapeType() == TopAbs_WIRE ) {
BRepGProp::LinearProperties(anOriginal, System); BRepGProp::LinearProperties(anOriginal, System);
P1 = System.CentreOfMass() ; P1 = System.CentreOfMass();
} }
else if ( anOriginal.ShapeType() == TopAbs_FACE || anOriginal.ShapeType() == TopAbs_SHELL ) { else if ( anOriginal.ShapeType() == TopAbs_FACE || anOriginal.ShapeType() == TopAbs_SHELL ) {
BRepGProp::SurfaceProperties(anOriginal, System); BRepGProp::SurfaceProperties(anOriginal, System);
P1 = System.CentreOfMass() ; P1 = System.CentreOfMass();
} }
else { else {
BRepGProp::VolumeProperties(anOriginal, System); BRepGProp::VolumeProperties(anOriginal, System);
P1 = System.CentreOfMass() ; P1 = System.CentreOfMass();
} }
Handle(Geom_Line) Line = new Geom_Line(AX1); Handle(Geom_Line) Line = new Geom_Line(AX1);
GeomAPI_ProjectPointOnCurve aPrjTool( P1, Line ) ; GeomAPI_ProjectPointOnCurve aPrjTool( P1, Line );
gp_Pnt P2 = aPrjTool.NearestPoint(); gp_Pnt P2 = aPrjTool.NearestPoint();
if ( P1.IsEqual(P2, Precision::Confusion() ) ) return 0; if ( P1.IsEqual(P2, Precision::Confusion() ) ) return 0;
gp_Vec Vec(P1.X()-P2.X(), P1.Y()-P2.Y(), P1.Z()-P2.Z()) ; gp_Vec Vec(P1.X()-P2.X(), P1.Y()-P2.Y(), P1.Z()-P2.Z());
Vec.Normalize(); Vec.Normalize();
Standard_Integer nbtimes2 = RI.GetNbIter2(); Standard_Integer nbtimes2 = RI.GetNbIter2();
@ -208,32 +227,36 @@ Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const
Standard_Real step = RI.GetStep(); Standard_Real step = RI.GetStep();
Standard_Real ang = RI.GetAngle(); Standard_Real ang = RI.GetAngle();
gp_Vec myVec ; TopLoc_Location aLocOrig = anOriginal.Location();
gp_Trsf aTrsfOrig = aLocOrig.Transformation();
gp_Vec aVec;
TopoDS_Compound aCompound; TopoDS_Compound aCompound;
BRep_Builder B; BRep_Builder B;
B.MakeCompound( aCompound ); B.MakeCompound( aCompound );
for (int i = 0; i < nbtimes2; i++ ) { for (int i = 0; i < nbtimes2; i++ ) {
for (int j = 0; j < nbtimes1; j++ ) { for (int j = 0; j < nbtimes1; j++ ) {
DX = i * step * Vec.X() ; DX = i * step * Vec.X();
DY = i * step * Vec.Y() ; DY = i * step * Vec.Y();
DZ = i * step * Vec.Z() ; DZ = i * step * Vec.Z();
myVec.SetCoord( DX, DY, DZ ) ; aVec.SetCoord( DX, DY, DZ );
theTransformation1.SetTranslation(myVec) ; aTrsf1.SetTranslation(aVec);
theTransformation2.SetRotation(AX1, j*ang*PI180) ; aTrsf2.SetRotation(AX1, j*ang*PI180);
BRepBuilderAPI_Transform myBRepTransformation1(anOriginal, theTransformation1, Standard_False) ; //NPAL18620: performance problem: multiple locations are accumulated
BRepBuilderAPI_Transform myBRepTransformation2(myBRepTransformation1.Shape(), theTransformation2, Standard_False) ; // in shape and need a great time to process
B.Add( aCompound, myBRepTransformation2.Shape() ); //BRepBuilderAPI_Transform aBRepTrsf1 (anOriginal, aTrsf1, Standard_False);
//BRepBuilderAPI_Transform aBRepTrsf2 (aBRepTrsf1.Shape(), aTrsf2, Standard_False);
//B.Add(aCompound, aBRepTrsf2.Shape());
TopLoc_Location aLocRes (aTrsf2 * aTrsf1 * aTrsfOrig);
B.Add(aCompound, anOriginal.Located(aLocRes));
} }
} }
aShape = aCompound; aShape = aCompound;
} }
else return 0; else return 0;
if (aShape.IsNull()) return 0; if (aShape.IsNull()) return 0;
aFunction->SetValue(aShape); aFunction->SetValue(aShape);
@ -250,7 +273,6 @@ Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const
//======================================================================= //=======================================================================
Standard_EXPORT Handle_Standard_Type& GEOMImpl_RotateDriver_Type_() Standard_EXPORT Handle_Standard_Type& GEOMImpl_RotateDriver_Type_()
{ {
static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver); static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver); if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared); static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
@ -258,7 +280,6 @@ Standard_EXPORT Handle_Standard_Type& GEOMImpl_RotateDriver_Type_()
static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient); static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient); if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL}; static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_RotateDriver", static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_RotateDriver",
sizeof(GEOMImpl_RotateDriver), sizeof(GEOMImpl_RotateDriver),
@ -273,7 +294,6 @@ Standard_EXPORT Handle_Standard_Type& GEOMImpl_RotateDriver_Type_()
//function : DownCast //function : DownCast
//purpose : //purpose :
//======================================================================= //=======================================================================
const Handle(GEOMImpl_RotateDriver) Handle(GEOMImpl_RotateDriver)::DownCast(const Handle(Standard_Transient)& AnObject) const Handle(GEOMImpl_RotateDriver) Handle(GEOMImpl_RotateDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
{ {
Handle(GEOMImpl_RotateDriver) _anOtherObject; Handle(GEOMImpl_RotateDriver) _anOtherObject;
@ -284,7 +304,5 @@ const Handle(GEOMImpl_RotateDriver) Handle(GEOMImpl_RotateDriver)::DownCast(cons
} }
} }
return _anOtherObject ; return _anOtherObject;
} }

View File

@ -8,7 +8,7 @@
// //
// This library is distributed in the hope that it will be useful // This library is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details. // Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public // You should have received a copy of the GNU Lesser General Public
@ -65,10 +65,10 @@ GEOMImpl_TranslateDriver::GEOMImpl_TranslateDriver()
//======================================================================= //=======================================================================
Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
{ {
if(Label().IsNull()) return 0; if (Label().IsNull()) return 0;
Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
if(aFunction.IsNull()) return 0; if (aFunction.IsNull()) return 0;
GEOMImpl_ITranslate TI(aFunction); GEOMImpl_ITranslate TI(aFunction);
gp_Trsf aTrsf; gp_Trsf aTrsf;
@ -76,11 +76,11 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
Standard_Integer aType = aFunction->GetType(); Standard_Integer aType = aFunction->GetType();
Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal(); Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal();
if(anOriginalFunction.IsNull()) return 0; if (anOriginalFunction.IsNull()) return 0;
TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue(); TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue();
if(anOriginal.IsNull()) return 0; if (anOriginal.IsNull()) return 0;
if(aType == TRANSLATE_TWO_POINTS || aType == TRANSLATE_TWO_POINTS_COPY) { if (aType == TRANSLATE_TWO_POINTS || aType == TRANSLATE_TWO_POINTS_COPY) {
Handle(GEOM_Function) aPoint1 = TI.GetPoint1(); Handle(GEOM_Function) aPoint1 = TI.GetPoint1();
Handle(GEOM_Function) aPoint2 = TI.GetPoint2(); Handle(GEOM_Function) aPoint2 = TI.GetPoint2();
if(aPoint1.IsNull() || aPoint2.IsNull()) return 0; if(aPoint1.IsNull() || aPoint2.IsNull()) return 0;
@ -93,10 +93,16 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aV2)); aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aV2));
aTrsf.SetTranslation(aP1, aP2); aTrsf.SetTranslation(aP1, aP2);
BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False); //NPAL18620: performance problem: multiple locations are accumulated
aShape = aTransformation.Shape(); // in shape and need a great time to process
//BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
} else if(aType == TRANSLATE_VECTOR || aType == TRANSLATE_VECTOR_COPY) { //aShape = aTransformation.Shape();
TopLoc_Location aLocOrig = anOriginal.Location();
gp_Trsf aTrsfOrig = aLocOrig.Transformation();
TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
aShape = anOriginal.Located(aLocRes);
}
else if (aType == TRANSLATE_VECTOR || aType == TRANSLATE_VECTOR_COPY) {
Handle(GEOM_Function) aVector = TI.GetVector(); Handle(GEOM_Function) aVector = TI.GetVector();
if(aVector.IsNull()) return 0; if(aVector.IsNull()) return 0;
TopoDS_Shape aV = aVector->GetValue(); TopoDS_Shape aV = aVector->GetValue();
@ -107,19 +113,31 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge)); aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
aTrsf.SetTranslation(aP1, aP2); aTrsf.SetTranslation(aP1, aP2);
BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False); //NPAL18620: performance problem: multiple locations are accumulated
aShape = aTransformation.Shape(); // in shape and need a great time to process
//BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
//aShape = aTransformation.Shape();
TopLoc_Location aLocOrig = anOriginal.Location();
gp_Trsf aTrsfOrig = aLocOrig.Transformation();
TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
aShape = anOriginal.Located(aLocRes);
} }
else if(aType == TRANSLATE_XYZ || aType == TRANSLATE_XYZ_COPY) { else if (aType == TRANSLATE_XYZ || aType == TRANSLATE_XYZ_COPY) {
gp_Vec aVec(TI.GetDX(), TI.GetDY(), TI.GetDZ()); gp_Vec aVec (TI.GetDX(), TI.GetDY(), TI.GetDZ());
aTrsf.SetTranslation(aVec); aTrsf.SetTranslation(aVec);
BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False); //NPAL18620: performance problem: multiple locations are accumulated
aShape = aTransformation.Shape(); // in shape and need a great time to process
//BRepBuilderAPI_Transform aTransformation (anOriginal, aTrsf, Standard_False);
//aShape = aTransformation.Shape();
TopLoc_Location aLocOrig = anOriginal.Location();
gp_Trsf aTrsfOrig = aLocOrig.Transformation();
TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
aShape = anOriginal.Located(aLocRes);
} }
else if(aType == TRANSLATE_1D) { else if (aType == TRANSLATE_1D) {
Standard_Real DX, DY, DZ, step = TI.GetStep1(); Standard_Real DX, DY, DZ, step = TI.GetStep1();
Standard_Integer nbtimes = TI.GetNbIter1(); Standard_Integer nbtimes = TI.GetNbIter1();
gp_Vec myVec ; gp_Vec aVec;
TopoDS_Compound aCompound; TopoDS_Compound aCompound;
BRep_Builder B; BRep_Builder B;
B.MakeCompound( aCompound ); B.MakeCompound( aCompound );
@ -133,21 +151,28 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
gp_Vec Vec(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge))); gp_Vec Vec(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
Vec.Normalize(); Vec.Normalize();
for (int i = 0; i < nbtimes; i++ ) { TopLoc_Location aLocOrig = anOriginal.Location();
DX = i * step * Vec.X() ; gp_Trsf aTrsfOrig = aLocOrig.Transformation();
DY = i * step * Vec.Y() ;
DZ = i * step * Vec.Z() ; for (int i = 0; i < nbtimes; i++) {
myVec.SetCoord( DX, DY, DZ ) ; DX = i * step * Vec.X();
aTrsf.SetTranslation(myVec) ; DY = i * step * Vec.Y();
BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False) ; DZ = i * step * Vec.Z();
B.Add(aCompound , aTransformation.Shape() ); aVec.SetCoord( DX, DY, DZ );
aTrsf.SetTranslation(aVec);
//NPAL18620: performance problem: multiple locations are accumulated
// in shape and need a great time to process
//BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
//B.Add(aCompound, aTransformation.Shape());
TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
B.Add(aCompound, anOriginal.Located(aLocRes));
} }
aShape = aCompound; aShape = aCompound;
} }
else if(aType == TRANSLATE_2D) { else if (aType == TRANSLATE_2D) {
Standard_Integer nbtimes1 = TI.GetNbIter1(), nbtimes2 = TI.GetNbIter2(); Standard_Integer nbtimes1 = TI.GetNbIter1(), nbtimes2 = TI.GetNbIter2();
Standard_Real DX, DY, DZ, step1 = TI.GetStep1(), step2 = TI.GetStep2(); Standard_Real DX, DY, DZ, step1 = TI.GetStep1(), step2 = TI.GetStep2();
gp_Vec myVec ; gp_Vec aVec;
Handle(GEOM_Function) aVector = TI.GetVector(); Handle(GEOM_Function) aVector = TI.GetVector();
if(aVector.IsNull()) return 0; if(aVector.IsNull()) return 0;
TopoDS_Shape aV = aVector->GetValue(); TopoDS_Shape aV = aVector->GetValue();
@ -170,15 +195,22 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
BRep_Builder B; BRep_Builder B;
B.MakeCompound( aCompound ); B.MakeCompound( aCompound );
for (int i = 0; i < nbtimes1; i++ ) { TopLoc_Location aLocOrig = anOriginal.Location();
for (int j = 0; j < nbtimes2; j++ ) { gp_Trsf aTrsfOrig = aLocOrig.Transformation();
DX = i * step1 * Vec1.X() + j * step2 * Vec2.X() ;
DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y() ; for (int i = 0; i < nbtimes1; i++) {
DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z() ; for (int j = 0; j < nbtimes2; j++) {
myVec.SetCoord( DX, DY, DZ ) ; DX = i * step1 * Vec1.X() + j * step2 * Vec2.X();
aTrsf.SetTranslation(myVec) ; DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y();
BRepBuilderAPI_Transform myBRepTransformation(anOriginal, aTrsf, Standard_False) ; DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z();
B.Add(aCompound , myBRepTransformation.Shape() ); aVec.SetCoord( DX, DY, DZ );
aTrsf.SetTranslation(aVec);
//NPAL18620: performance problem: multiple locations are accumulated
// in shape and need a great time to process
//BRepBuilderAPI_Transform aBRepTransformation(anOriginal, aTrsf, Standard_False);
//B.Add(aCompound, aBRepTransformation.Shape());
TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
B.Add(aCompound, anOriginal.Located(aLocRes));
} }
} }
aShape = aCompound; aShape = aCompound;
@ -186,7 +218,6 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
else return 0; else return 0;
if (aShape.IsNull()) return 0; if (aShape.IsNull()) return 0;
aFunction->SetValue(aShape); aFunction->SetValue(aShape);
@ -211,7 +242,6 @@ Standard_EXPORT Handle_Standard_Type& GEOMImpl_TranslateDriver_Type_()
static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient); static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient); if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL}; static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_TranslateDriver", static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_TranslateDriver",
sizeof(GEOMImpl_TranslateDriver), sizeof(GEOMImpl_TranslateDriver),
@ -226,7 +256,6 @@ Standard_EXPORT Handle_Standard_Type& GEOMImpl_TranslateDriver_Type_()
//function : DownCast //function : DownCast
//purpose : //purpose :
//======================================================================= //=======================================================================
const Handle(GEOMImpl_TranslateDriver) Handle(GEOMImpl_TranslateDriver)::DownCast(const Handle(Standard_Transient)& AnObject) const Handle(GEOMImpl_TranslateDriver) Handle(GEOMImpl_TranslateDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
{ {
Handle(GEOMImpl_TranslateDriver) _anOtherObject; Handle(GEOMImpl_TranslateDriver) _anOtherObject;
@ -237,7 +266,5 @@ const Handle(GEOMImpl_TranslateDriver) Handle(GEOMImpl_TranslateDriver)::DownCas
} }
} }
return _anOtherObject ; return _anOtherObject;
} }