Site Tools


Differences

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

Link to this comparison view

developer:picksurfacepoint [2015/09/14]
developer:picksurfacepoint [2015/09/14] (current)
Line 1: Line 1:
 +====== Picking Surface Point ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //Discusses how to pick points on a surface.//
 +
 +===== Question =====
 +What I want to do is to pick a point on the surface of an object. How can I do this.
 +
 +===== Answer =====
 +There are a couple of ways to do this:
 +  - Use a CRhinoGetObject class.
 +  - Use a CRhinoGetPoint class.
 +
 +==== Example 1: CRhinoGetObject ====
 +When picking objects with a **CRhinoGetObject** object, the **CRhinoObjRef** returned by the object contains picking information,​ such as the location of the pick.
 +
 +<code c++>
 +CRhinoCommand::​result CCommandTestPick1::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  CRhinoGetObject go;
 +  go.SetCommandPrompt( L"​Select a surface or a polysurface"​ );
 +  go.SetGeometryFilter( CRhinoGetObject::​surface_object | CRhinoGetObject::​polysrf_object );
 +  go.EnablePreSelect( FALSE );
 +  go.GetObjects( 1, 1 );
 +  if( go.CommandResult() != CRhinoCommand::​success )
 +    return go.CommandResult();​
 +
 +  const CRhinoObjRef&​ ref = go.Object(0);​
 +
 +  // If the object was selected by picking a point on it, then
 +  // SelectionPoint() returns true and the point where the selection
 +  // occured.
 +  ON_3dPoint pt;
 +  if( ref.SelectionPoint(pt) )
 +  {
 +    context.m_doc.AddPointObject( pt );
 +    context.m_doc.Redraw();​
 +  }
 +
 +  return CRhinoCommand::​success;​
 +}
 +</​code>​
 +
 +==== Example 2: CRhinoGetPoint ====
 +When picking points with a **CRhinoGetPoint** object, you can constrain the point picking to a surface.
 +
 +<code c++>
 +CRhinoCommand::​result CCommandTestPick2::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  CRhinoGetObject go;
 +  go.SetCommandPrompt( L"​Select a surface"​ );
 +  go.SetGeometryFilter( CRhinoGetObject::​surface_object );
 +  go.EnablePreSelect( FALSE );
 +  go.GetObjects( 1, 1 );
 +  if( go.CommandResult() != CRhinoCommand::​success )
 +    return go.CommandResult();​
 +
 +  const CRhinoObjRef&​ ref = go.Object(0);​
 +  const ON_BrepFace* face = ref.Face();
 +  if( 0 == face )
 +    return CRhinoCommand::​failure;​
 +
 +  CRhinoGetPoint gp;
 +  gp.SetCommandPrompt( L"​Select point on surface"​ );
 +  gp.Constrain( *face );
 +  gp.GetPoint();​
 +  if( gp.CommandResult() != CRhinoCommand::​success )
 +    return gp.CommandResult();​
 +
 +  ON_3dPoint pt = gp.Point();
 +  context.m_doc.AddPointObject( pt );
 +  context.m_doc.Redraw();​
 +
 +  return CRhinoCommand::​success;​
 +}
 +</​code>​
 +
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
  
developer/picksurfacepoint.txt ยท Last modified: 2015/09/14 (external edit)