About Cast process problem

I obtain a RhinoObject and want to transform it into ON_Curve.
Before I had known my curve was polyline.

When I do this.

const CRhinoObject* pCrvObj = XXX;
ON_Curve* pCrv = ON_Curve::Cast( pCrvObj->Duplicate() );

I find pCrv is not polyline.

However,I change my code like below.

const CRhinoCurveObject* CRCrvObj = CRhinoCurveObject::Cast( pCrvObj );
const ON_Curve* pCrv = CRCrvObj->Curve();

The variable of pCrv is polyline.

Therefore, I want to know why.
I think I ignore something.

Think of a CRhinoObject as a container that contains geometry, accessible by the Geometry() function. Then the geometry is returned of type ON_Geometry.

CRhinoCurveObject is a specialization of CRhinoObject, and has a new function Curve(), which returns the geometry of type ON_Curve (which is, in itself, a specialization of ON_Geometry).

So your first two lines of code can also be this:

const CRhinoObject* pCrvObj = XXX;
ON_Curve* pCrv = ON_Curve::Cast( pCrvObj->Geometry() );

Also, maybe this is known: in your first two lines you create a new object by using Duplicate(). If you do this, you must free the object when you are finished.

Thank you for help. :smile:

Due to know CRhinoObject includes ON_Geometry, I can use ON_Geometry to get ON_Curve ?

Originally, I know inherited relation, but I don’t know how to get ON_Curve. :grin:
BTW, How do you know CRhinoObject includes ON_Geometry throught inherited relation ?

ON_Object > CRhinoObject
ON_Object > CRhinoObject > CRhinoCurveObject
ON_Object > ON_Geometry > ON_Curve
ON_Object > ON_Geometry

This is probably worth reviewing.

Also, here is a sample command that “clasifies” curves.


Thanks ! :smile: