Exploding a joined Curve C++


#1

Hi,

I was wondering how can I “extract” single curves after they have been joined. For example if I have two parallel splines connected with two straight lines at their ends and then joined…I need to select them and then somehow 1. separate them 2. recognize which ones ar the splines and which ones are the lines. I am guessing that the IsLinear method will be used for the second problem, but how do I “separate” them, or duplicate the segments?

Thanks!


(Dale Fugier) #2

Hi Milos,

Without examining the curve, my guess is, after joining, you have a polycurve, or ON_PolyCurve. Either the What or List command can verify this.

If you have a polycurve, you can march thru it like this:

const ON_PolyCurve& poly_curve = ...;
for (int i = 0; i < poly_curve.Count(); i++)
{
  const ON_Curve* segment = poly_curve.SegmentCurve(i);
  if (0 != segment)
  {
    // TODO...
  }
}

– Dale


#3

Hi Dale,

yes, I do have a ON_PolyCurve…unfortunatelly I do not know how to select it. I tried all types of casting but I do not know how to actually “extract” the ON_PolyCurve from a selected object…can you help me with that? I expected an ON_Curve::IsPolyCurve (like there is for Polyline) so I can recognize if my selected ON_Curve* is actually a ON_PolyCurve, but there is nothing like that…


(Dale Fugier) #4

How about this?

CRhinoGetObject go;
go.SetCommandPrompt(L"Select polycurve");
go.SetGeometryFilter(CRhinoGetObject::curve_object);
go.EnableSubObjectSelect(FALSE);
go.GetObjects(1, 1);
if (go.CommandResult() != CRhinoCommand::success)
  return go.CommandResult();

const ON_Curve* curve = go.Object(0).Curve();
if (0 == curve)
  return CRhinoCommand::failure;

const ON_PolyCurve* poly_curve = ON_PolyCurve::Cast(curve);
if (0 == poly_curve)
{
  RhinoApp().Print(L"Polycurve not selected.\n");
  return CRhinoCommand::cancel;
}

// TODO...

– Dale


#5

Thanks, it works…I was doing the same except I was passing the CRhinoObject* to the ON_PolyCurve::Cast…that was the mistake…I mixed CRhinoObject with ON_Object…