gp_GTrsf nonuniform scaling shape crash after version 7.6

Ok, everybody, please ask. When I was in version 7.4, the uneven scaling of topds_shape by gp_GTrsf was all right, but when I upgraded to version 7.6, the same operation prompted an error.

gkv311 n's picture

Which error? Where is the code snippet?

w d's picture

it prompted an error: gp_GTrsf::Trsf() - non-orthogonal GTrsf。then i find the error in gp_GTrsf.lxx gp_GTrsf::Trsf()。

gkv311 n's picture

Method gp_GTrsf::Trsf() converts gp_GTrsf into gp_Trsf, and the latter supports only uniform scale factor.

w d's picture

Yes, I can understand the cause of the error through this prompt. However, in version 7.4.0, I can transform the model unevenly through gp_GTrsf without this error.

Mikhail Sazonov's picture

Could you put here a snippet of your code that calls cascade functions for transformation?

w d's picture

Here is the code I used to move, rotate and scale the model.

TopoDS_Shape CStepUtilTransformEdit::getShape(const TransformEdit &transformEdit, const TopoDS_Shape &originshape,const gp_GTrsf &trsf_beforemove, const gp_GTrsf &trsf_aftermove, int i) const {
	
	//	move transform
    gp_GTrsf trsf_move;
    trsf_move.SetTranslationPart(gp_XYZ(transformEdit.mFloatMoveX * i, transformEdit.mFloatMoveY * i, transformEdit.mFloatMoveZ * i));
   
    //	rotate transform
	gp_Trsf trsf_rotate_x;
    trsf_rotate_x.SetRotation(gp_Ax1(gp::Origin(), gp::DX()), transformEdit.mFloatRotateX * 1 * M_PI / 180);
    gp_Trsf trsf_rotate_y;
    trsf_rotate_y.SetRotation(gp_Ax1(gp::Origin(), gp::DY()), transformEdit.mFloatRotateY * 1 * M_PI / 180);
    gp_Trsf trsf_rotate_z;
    trsf_rotate_z.SetRotation(gp_Ax1(gp::Origin(), gp::DZ()), transformEdit.mFloatRotateZ * 1 * M_PI / 180);
    gp_Trsf trsf_rotate_ = trsf_rotate_x.Multiplied(trsf_rotate_y).Multiplied(trsf_rotate_z);
    gp_GTrsf trsf_rotate;
    trsf_rotate.SetTrsf(trsf_rotate_);
    
	//	scale transform
	gp_GTrsf trsf_scale;
    gp_Mat rot(Pow(transformEdit.mFloatScaleX, 1), 0, 0, 0, Pow(transformEdit.mFloatScaleY, 1), 0, 0, 0, Pow(transformEdit.mFloatScaleZ, 1));
    trsf_scale.SetVectorialPart(rot);
    
	//	gtrsf transform
	gp_GTrsf gtrsf;
    gtrsf.PreMultiply(trsf_scale);
    gtrsf.PreMultiply(trsf_rotate);
    gtrsf.PreMultiply(trsf_move);
	
	//	the last gtrsf transform
    gp_GTrsf gTrsfMulti;
    gTrsfMulti.PreMultiply(trsf_beforemove);
    gTrsfMulti.PreMultiply(gtrsf);
    gTrsfMulti.PreMultiply(trsf_aftermove);
	
    BRepBuilderAPI_GTransform transform(originshape, gTrsfMulti, true);
    TopoDS_Shape newshape = transform.Shape();
    return newshape;
}
Manuel Koch's picture

I have a similar problem, just using a non-uniform scaling on a shape with pythonocc-core==7.7.2:

scale_transform = gp_GTrsf()
scale_transform.SetVectorialPart(
  gp_Mat(
    1,    0,       0,
    0,    0.1,    0,
    0,    0,       1    )
)
brep_transform_builder = BRepBuilderAPI_GTransform(
    shape, scale_transform, False  # fails too if I use "True" here
)

which raises this runtime error

RuntimeError: Standard_ConstructionErrorgp_GTrsf::Trsf() - non-orthogonal GTrsf raised from method BRepBuilderAPI_GTransform of class BRepBuilderAPI_GTransform

How can I know what the detailed error is ? E.g. what does non-orthogonal GTrsf mean for the transformation matrix and/or the shape I try to transform ?

When looking at the shape ( it is basically a y-axis-stretched cube I want to revert back to a cube by applying the reversed-scale-along-y-axis ) with the built-in 3D viewer, I can see that the shape is not exactly axis aligned. I.e. some of the faces would not be scaled uniformly by the scale I want to apply along y-axis. Could this be the issue, that the shape is not properly aligned to the non-uniform scaling I want to apply ?

Dmitrii Pasukhin's picture

Hello, BRepBuilderAPI_GTransform had some problem (on c++ side). That was fixed in 7.8.0 release.

Best regards, Dmitrii.