developer:sdksamples:extractisocurve


Extracting Isoparametric Curves from Surfaces

C++, .NET

Summary: Demonstrates how to extract isoparametric curves from surfaces using the Rhino SDK.

Example:

The following sample code demonstrates how to extract isoparametric curves from surfaces using the Rhino SDK.

C++

CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
{
  // Select the surface to extract isocurve
  CRhinoGetObject go;
  go.SetCommandPrompt( L"Select surface" );
  go.SetGeometryFilter( CRhinoGetObject::surface_object );
  go.GetObjects( 1, 1 );
  if( go.CommandResult() != success )
    return go.CommandResult();
 
  // Validate selection
  const CRhinoObjRef& ref = go.Object(0);
  const ON_Surface* srf = ref.Surface();
  if( !srf )
    return failure;
 
  ON_3dPoint pt( ON_UNSET_POINT );
  BOOL dir = FALSE;
 
  // Pick a point on the surface
  CRhinoGetPoint gp;
  gp.SetCommandPrompt( L"Point on surface" );
  gp.AddCommandOptionToggle( 
            RHCMDOPTNAME(L"Direction"), 
            RHCMDOPTVALUE(L"U"), 
            RHCMDOPTVALUE(L"V"), 
            dir, &dir );
  gp.Constrain( *srf );
  for(;;)
  {
    CRhinoGet::result res = gp.GetPoint();
    if( res == CRhinoGet::point )
    {
      pt = gp.Point();
      break;
    }
    else if( res == CRhinoGet::option )
      continue;
    else
      return cancel;
  }
 
  // Get the parameters of the point on
  // the surface that is closest to pt.
  double u, v;
  if( srf->GetClosestPoint(pt, &u, &v) )
  {
    // Get the isoparametric curve. ON_Surface::IsoCurve
    // allocates memory for the resulting curve that we
    // will be responsible for.
    ON_Curve* crv = srf->IsoCurve( dir, dir ? u : v );
    if( crv )
    {
      context.m_doc.AddCurveObject( *crv );
 
      // CRhinoDoc::AddCurveObject make a copy of the input curve.
      // So, we need to delete crv otherwise we will leak memory.
      delete crv;
      crv = 0;
 
      context.m_doc.Redraw();
    }
  }
 
  return success;
}

C#

      public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
      {
          // Select the surface to extract isocurve
          MRhinoGetObject go = new MRhinoGetObject ();
          go.SetCommandPrompt("Select surface" );
          go.SetGeometryFilter( IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object );
          go.GetObjects( 1, 1 );
          if( go.CommandResult() != IRhinoCommand.result.success )
            return go.CommandResult();
 
          // Validate selection
          IRhinoObjRef objref = go.Object(0);
          IOnSurface srf = objref.Surface();
          if(srf == null)
          {
            RhUtil.RhinoApp().Print("Null Surface selected.\n");
            return IRhinoCommand.result.nothing;
          }
          On3dPoint pt = new On3dPoint ();
 
          // Pick a point on the surface
          MRhinoGetPoint gp= new MRhinoGetPoint ();
          gp.SetCommandPrompt( "Point on surface" );
          MRhinoGet.BooleanOption bDir = new MRhinoGet.BooleanOption(false);
          int index =gp.AddCommandOptionToggle(
                    new MRhinoCommandOptionName("Direction"), 
                    new MRhinoCommandOptionValue("U"), 
                    new MRhinoCommandOptionValue("V"),
                    bDir.Value, bDir);
          gp.Constrain(srf);
          for(;;)
          {
            IRhinoGet.result res=gp.GetPoint();
            if (res==IRhinoGet.result.point) 
            {
              pt = gp.Point();
              break;
            }
            else{
                if( res == IRhinoGet.result.option )
                     continue;
                else
                     return IRhinoCommand.result.cancel;
            }
          }
 
          // Get the parameters of the point on
          // the surface that is closest to pt.
          double u = 0;
          double v=0;
          if( srf.GetClosestPoint(pt, ref u, ref v) )
          {
              // Get the isoparametric curve. OnSurface.IsoCurve
              // input the direction in which the parameter varies (0,1)(the other parameter is held constant) then input the value of the constant parameter 
              OnCurve crv = srf.IsoCurve(bDir.Value ? 1 : 0, bDir.Value ? u : v);
              if (crv != null)
                {
                  context.m_doc.AddCurveObject(crv);
                  context.m_doc.Redraw();
                }
          }
          return IRhinoCommand.result.success;
      }
developer/sdksamples/extractisocurve.txt · Last modified: 2010/01/26 16:37 (external edit) Driven by DokuWiki Recent changes RSS feed

 © 1997-2012 

McNeel North America Europe Latin AmericaAsia