How to scale or mirror a shape

With older occ versions i mirrored (maybe rather clumpsy) shapes by setting a TopLoc_Location with a scale of -1.0, f.e. such a transformation matrix:

1  0 0
0 -1 0
0  0 1

or simply uniformly scaled shapes (mostly with values > 0).

Newer versions don't don't allow this because of this fix (0027457: Modeling - Raise exception if scaled transformation is used for shape location)

The fact is that use of transformations with non-unit scale factor in shape locations (e.g. method TopoDS_Shape::Moved()) is not well supported in OCCT: in most cases (especially if underlying geometry is elementary) this will lead to invalid shape, and most algorithms will fail due to being not able to handle effect of scaling on parameterization. It is quite regular that users get confused by this possibility (see e.g. https://github.com/tpaviot/oce/issues/615).

To prevent confusion, we can raise exception when scaled transformation is used for shape (e.g. in TopLoc_Location).

with this new source code which throws a domain error exception for such cases:

  void Location (const TopLoc_Location& theLoc, const Standard_Boolean theRaiseExc = Standard_True)
  {
    const gp_Trsf& aTrsf = theLoc.Transformation();
    if ((Abs(Abs(aTrsf.ScaleFactor()) - 1.) > TopLoc_Location::ScalePrec() || aTrsf.IsNegative()) && theRaiseExc)
    {
      //Exception
      throw Standard_DomainError("Location with scaling transformation is forbidden");
    }
    else
    {
      myLocation = theLoc;
    }
  }

Is there another way to scale shapes (maybe also along X, Y, Z or even arbitrary axes) or, which might be a simpler case, "mirror" along X, Y, or Z?

Dmitrii Pasukhin's picture

Hello,

To make any tranformation on shape you can use "BRepBuilderAPI_Transform" which get gp_Trsf or "BRepBuilderAPI_GTransform" which get "gp_GTrsf".

Best regards, Dmitrii.

Mikhail Sazonov's picture

Use BRepBuilderAPI_Transform and BRepBuilderAPI_GTransform algorithms to perform such transformations.

Minh Hiếu Vũ's picture

Hi, when I read a step file into a label, get shape from label and scale my shape with BRepBuilderAPI_GTransform then assign it to the label, now all the attribute (name, material,..) is loss, how do I do it correctly?

Dmitrii Pasukhin's picture

Hello, replace operation for label is not accepted in general case.

When you get shape, you extract cascade labels. Modifications of shapes changes their cache code. As I know there is no fast solution for replace object in CAF. I think recreate tree will be better. And when you perform modification it is better to work with deep copy in that case.

Best regards, Dmitrii.

Dmitrii Pasukhin's picture

For modification transformation of label, please check XCAFDoc_Editor.

Best regards, Dmitrii.

Minh Hiếu Vũ's picture

Thank you very much!!!

Minh Hiếu Vũ's picture