Search code examples
c++geometrycadopencascade

How can I change the underlying geometry of a TopoDS_Shape in OpenCASCADE


I am trying to change the geometry of an existing TopoDS_Shape in OpenCASCADE. A possible application is for modifying an edge of a body without the need to reconstruct the whole body (e.g. change the radius of one cap of a cylinder, shift a control point in a Bspline curve/surface).

  • Is there a standard approach to do this in OpenCASCADE?
  • Is it possible to update geometry without creating a new shape?

I already tried to use BRepAdaptor_HCurve instead, but this did not really help.

Handle(Geom_Circle) aCircle = new Geom_Circle(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), 5); // create a circle in the xy plane, origin (0,0,0) radius 5;
TopoDS_Edge circ = BRepBuilderAPI_MakeEdge(aCircle); // switch to topological description;

STEPControl_Writer writer;

writer.Transfer(circ,STEPControl_AsIs); // access topology for output   

BRepAdaptor_Curve theAdaptor = BRepAdaptor_Curve(circ); // create an adaptor    
gp_Circ mod_circ = theAdaptor.Circle();
mod_circ.SetRadius(1); // change radius to 1

// I dont want to create a new circle, but reuse the old one with the updated geometry:
// writer.Transfer(circ, STEPControl_AsIs); // access topology for output

// in order to output the updated geometry, we also have to create a new edge
TopoDS_Edge another_circ = BRepBuilderAPI_MakeEdge(mod_circ);

writer.Transfer(another_circ, STEPControl_AsIs); // access topology for output
writer.Write("debug.stp");

Original and modified geometry, created by writing circ and another_circ Original and modified geometry


Solution

  • As i understood from the OpenCASCADE forum and the documentation you can not to change the subshapes of a shape directly. But you can create a new subshape and replace the old.

    See OpenCASCADE forum topics below. Hope it helps.

    How to modify sub-shapes of a given shape without copy

    Modify shape

    Replacing a face with X faces

    Edit topology