Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:reparameterizecrv [2015/09/14] (current)
Line 1: Line 1:
 +======Reparameterize a Curve======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]],​ [[developer:​dotnetplugins|.NET]]//​
 +> **Summary:​** //​Demonstrates how to [[rhino:​reparameterize|Reparameterize]] a curve objeect.//
 +> **NOTICE:** //The Rhino.NET SDK is deprecated in Rhino 5.  This example adapted for the new RhinoCommon SDK is [[developer:​rhinocommonsamples:​reparameterizecrv|here]]//​
 +=====Example=====
 +The following is a demonstration of how to how to reparameterize a curve objeect using the Rhino SDK.
 +
 +====C++====
 +<code c++>
 +CRhinoCommand::​result CCommandTest::​RunCommand(const CRhinoCommandContext&​ context)
 +{
 +  CRhinoCommand::​result rc = CRhinoCommand::​success;​
 +
 +  CRhinoGetObject go;
 +  go.SetCommandPrompt( L"​Select curve to reparameterize"​ );
 +  go.SetGeometryFilter( CRhinoGetObject::​curve_object );
 +  go.GetObjects( 1, 1 );
 +  rc = go.CommandResult();​
 +  if( rc != CRhinoCommand::​success )
 +    return rc;
 +
 +  CRhinoObjRef&​ objref = go.Object(0);​
 +  const ON_Curve* pC = objref.Curve();​
 +  if( !pC )
 +    return CRhinoCommand::​failure;​
 +
 +  double s0, s1;
 +  pC->​GetDomain( &s0, &s1 );
 +
 +  CRhinoGetNumber gn;
 +  gn.SetCommandPrompt( L"​Domain start" );
 +  gn.SetDefaultNumber( s0 ) ;
 +  gn.AcceptNothing();​
 +  gn.GetNumber();​
 +  rc = gn.CommandResult();​
 +  if( rc != CRhinoCommand::​success )
 +    return rc;
 +
 +  double t0 = gn.Number();​
 +
 +  gn.SetCommandPrompt( L"​Domain end" );
 +  gn.SetDefaultNumber( s1 );
 +  gn.SetLowerLimit( t0, TRUE );
 +  gn.AcceptNothing();​
 +  gn.GetNumber();​
 +  rc = gn.CommandResult();​
 +  if( rc != CRhinoCommand::​success )
 +    return rc;
 +
 +  double t1 = gn.Number();​
 +
 +  if( s0 == t0 && s1 == t1 )
 +    return CRhinoCommand::​nothing;​
 +
 +  ON_Curve *pNC = pC->​DuplicateCurve();​
 +  if( pNC )
 +  {
 +    pNC->​SetDomain( t0, t1 );
 +    CRhinoCurveObject* obj = new CRhinoCurveObject();​
 +    if( obj )
 +    {
 +      obj->​SetCurve( pNC );
 +      context.m_doc.ReplaceObject( objref, obj );
 +      context.m_doc.Redraw();​
 +   }
 +   else
 +     rc = CRhinoCommand::​failure;​
 +  }
 +  else
 +    rc = CRhinoCommand::​failure;​
 +
 +  return rc;
 +}
 +</​code>​
 +
 +====VB.NET====
 +<code vb>
 +Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) _
 +  As IRhinoCommand.result
 +
 +  Dim rc As IRhinoCommand.result = IRhinoCommand.result.success
 +  Dim go As New MRhinoGetObject()
 +  go.SetCommandPrompt("​Select curve to reparameterize"​)
 +  go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object)
 +  go.GetObjects(1,​ 1)
 +  rc = go.CommandResult()
 +  If (rc <> IRhinoCommand.result.success) Then Return rc
 +
 +  Dim objref As MRhinoObjRef = go.Object(0)
 +  Dim pC As IOnCurve = objref.Curve()
 +  If (pC Is Nothing) Then Return IRhinoCommand.result.failure
 +
 +  Dim s0 As Double
 +  Dim s1 As Double
 +  pC.GetDomain(s0,​ s1)
 +
 +  Dim gn As New MRhinoGetNumber()
 +  gn.SetCommandPrompt("​Domain start"​)
 +  gn.SetDefaultNumber(s0)
 +  gn.AcceptNothing()
 +  gn.GetNumber()
 +  rc = gn.CommandResult()
 +  If (rc <> IRhinoCommand.result.success) Then Return rc
 +  Dim t0 As Double = gn.Number()
 +
 +  gn.SetCommandPrompt("​Domain end")
 +  gn.SetDefaultNumber(s1)
 +  gn.SetLowerLimit(t0,​ True)
 +  gn.AcceptNothing()
 +  gn.GetNumber()
 +  rc = gn.CommandResult()
 +  If (rc <> IRhinoCommand.result.success) Then Return rc
 +  Dim t1 As Double = gn.Number()
 +
 +  If (s0 = t0 And s1 = t1) Then Return IRhinoCommand.result.nothing
 +
 +  Dim pNC As OnCurve = pC.DuplicateCurve()
 +  If (pNC IsNot Nothing) Then
 +    pNC.SetDomain(t0,​ t1)
 +    Dim obj As New MRhinoCurveObject
 +    obj.SetCurve(pNC)
 +    context.m_doc.ReplaceObject(objref,​ obj)
 +    context.m_doc.Redraw()
 +  Else
 +    rc = IRhinoCommand.result.failure
 +  End If
 +  Return rc
 +End Function
 +</​code>​
 +
 +====C#====
 +<code c#>
 +public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
 +{
 +  IRhinoCommand.result rc = IRhinoCommand.result.success;​
 +  MRhinoGetObject go = new MRhinoGetObject();​
 +  go.SetCommandPrompt("​Select curve to reparameterize"​);​
 +  go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);​
 +  go.GetObjects(1,​ 1);
 +  rc = go.CommandResult();​
 +  if(rc != IRhinoCommand.result.success)
 +    return rc;
 +
 +  MRhinoObjRef objref = go.Object(0);​
 +  IOnCurve pC = objref.Curve();​
 +  if(pC == null)
 +    return IRhinoCommand.result.failure;​
 +
 +  double s0=0, s1=0;
 +  pC.GetDomain(ref s0, ref s1);
 +
 +  MRhinoGetNumber gn = new MRhinoGetNumber();​
 +  gn.SetCommandPrompt("​Domain start"​);​
 +  gn.SetDefaultNumber(s0);​
 +  gn.AcceptNothing();​
 +  gn.GetNumber();​
 +  rc = gn.CommandResult();​
 +  if(rc != IRhinoCommand.result.success)
 +    return rc;
 +  double t0 = gn.Number();​
 +
 +  gn.SetCommandPrompt("​Domain end");
 +  gn.SetDefaultNumber(s1);​
 +  gn.SetLowerLimit(t0,​ true);
 +  gn.AcceptNothing();​
 +  gn.GetNumber();​
 +  rc = gn.CommandResult();​
 +  if(rc != IRhinoCommand.result.success)
 +    return rc;
 +  double t1 = gn.Number();​
 +
 +  if(s0 == t0 && s1 == t1)
 +    return IRhinoCommand.result.nothing;​
 +
 +  OnCurve pNC = pC.DuplicateCurve();​
 +  if(pNC != null)
 +  {
 +    pNC.SetDomain(t0,​ t1);
 +    MRhinoCurveObject obj = new MRhinoCurveObject();​
 +    obj.SetCurve(pNC);​
 +    context.m_doc.ReplaceObject(objref,​ obj);
 +    context.m_doc.Redraw();​
 +  }
 +  else
 +    rc = IRhinoCommand.result.failure;​
 +
 +  return rc;
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus dotnet}}
  
developer/sdksamples/reparameterizecrv.txt ยท Last modified: 2015/09/14 (external edit)