Contour curves on trimmed faces

Hello,
I’m trying to retrieve the contour curves of a polysurface by calling CreateContourCurves on each face (brep.Face[i].ToBrep()).

Everything works fine but I noticed that the resulting curves are from the untrimmed face.

How can I get the trimmed face? I can see that the original brep has several BrepTrims that points to each face (via faceindex).

Hi @o11225669,

Can you post a 3dm file and some sample code that repeats what you are seeing?

Thanks,

– Dale

Hi @dale, thanks for the answer.

Of course. I tried to replicate all the steps since the beginning, a simple IGES file. The O11_Intersect.cs is a simplified version of my command (without safety checks and assuming we are working with the three surfaces of the PS_Top file).

PS_Top.IGS (46.0 KB)
O11_Intersect.cs (3.2 KB)

This is the final result (hiding the iso curves):

The first lines are the result from code. The bottom lines are the result from the “Intersect” command with a simple surface done via Rhino interface.

If you explode the polysurface and then untrim the borders, you can see that the result from code matches what appears to be the untrimmed surfaces.

Thanks in advance.

Hi @o11225669,

Rather than using BrepFace.ToBrep(), which creates a new Brep from the face’s underlying surface, try using BrepFace.DuplicateFace, which creates a new Brep from the face, thus including things like trims, loops, etc.

This seems to work well on your model:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var go = new GetObject();
  go.SetCommandPrompt("Please select the three surfaces");
  go.GeometryFilter = ObjectType.Surface;
  go.SubObjectSelect = false;
  go.GetMultiple(3, 3);
  if (go.CommandResult() != Result.Success)
    return go.CommandResult();

  var in_breps = new List<Brep>(3);
  foreach (var objref in go.Objects())
  {
    var in_brep = objref.Brep();
    if (null == in_brep)
      return Result.Failure;
    in_breps.Add(in_brep);
  }

  var join_tol = doc.ModelAbsoluteTolerance * 2.1;
  var out_breps = Brep.JoinBreps(in_breps, join_tol);
  if (1 != out_breps.Length)
    return Result.Failure;

  var out_brep = out_breps[0];
  var plane = new Plane(new Point3d(0, 0, -4750), Vector3d.ZAxis);
  var out_curves = new List<Curve>();
  foreach (var face in out_brep.Faces)
  {
    var brep = face.DuplicateFace(false);
    if (null != brep)
    {
      var contours = Brep.CreateContourCurves(brep, plane);
      if (null != contours && contours.Length > 0)
        out_curves.AddRange(contours);
    }
  }

  foreach (var curve in out_curves)
    doc.Objects.AddCurve(curve);

  foreach (var objref in go.Objects())
    doc.Objects.Delete(objref, true);

  doc.Objects.AddBrep(out_brep);

  doc.Views.Redraw();

  return Result.Success;
}

– Dale

This was perfect. Thanks for explaining the difference, I missed it. Thank you!