Inherit On_SpaceMorph?

bool MyMorphObj(ON_Curve* crv, CRhinoObject* obj)
{
	MySpaceMorph morph(0.0, true, false, crv);
	return true;
}

class MySpaceMorph : public ON_SpaceMorph
{
public:
	MySpaceMorph(double tolerance, bool quickpreview, bool preserveStructure, ON_Curve* crv)
	{
		SetTolerance(tolerance);
		SetQuickPreview(quickpreview);
		SetPreserveStructure(preserveStructure);
		mcrv = crv;
	}

	virtual ON_3dPoint MorphPoint(ON_3dPoint point) const
	{
		double *t;
		mcrv->GetClosestPoint(point, t, -1);
		return mcrv->PointAt(*t);
	}

private:
	ON_Curve* mcrv;
};

Is this written incorrectly? Why do undeclared identifiers appear? Please provide an example. Thank you

Hi @Huang,

Maybe this?

class MySpaceMorph : public ON_SpaceMorph
{
public:
  MySpaceMorph(double tolerance, bool quickpreview, bool preserveStructure, ON_Curve* crv)
  {
    SetTolerance(tolerance);
    SetQuickPreview(quickpreview);
    SetPreserveStructure(preserveStructure);
    mcrv = crv;
  }

  ON_3dPoint MorphPoint(ON_3dPoint point) const override
  {
    if (mcrv)
    {
      double t = ON_UNSET_VALUE;
      if (mcrv->GetClosestPoint(point, &t))
        return mcrv->PointAt(t);
    }
    return ON_3dPoint::UnsetPoint;
  }

private:
  ON_Curve* mcrv = nullptr;
};

bool MyMorphObj(ON_Curve* crv, CRhinoObject* obj)
{
  MySpaceMorph morph(0.0, true, false, crv);
  return true;
}

– Dale

Thank you very much. Allow me to ask one final question. When I call the Morph function in C # and try to read or write to protected memory, it usually indicates that other memory is damaged. Do I need to manually release the memory? I have no problem using MooseAddPoint

Hi @Huang,

SpaceMorph is an abstract class in RhinoCommon. Why don’t you implement your custom morphing tool there and and forget the interop stuff?

— Dale

I actually hope to put some things in C++, but I can’t convert the spacemorph type (including its subclasses) to intptr for C++in Rhinocommon, can I?

Hi @Huang,

I don’t see a way of doing this. Again, just implement your spacemorph in RhinoCommon.

– Dale

Okay, I will take your advice. Thank you for your reply. Thank you