ON_BOOL32 ON_Geometry::GetBoundingBox( // returns true if successful ON_3dPoint& boxmin, ON_3dPoint& boxmax, ON_BOOL32 bGrowBox ) const { ON_Workspace ws; const int dim = Dimension(); double *bmin, *bmax; if ( dim <= 3 ) { bmin = &boxmin.x; bmax = &boxmax.x; } else { bmin = ws.GetDoubleMemory(dim*2); bmax = bmin+dim; memset( bmin, 0, 2*dim*sizeof(*bmin) ); if ( bGrowBox ) { bmin[0] = boxmin.x; bmin[1] = boxmin.y; bmin[1] = boxmin.z; bmax[0] = boxmax.x; bmax[1] = boxmax.y; bmax[1] = boxmax.z; } } // Treat invalid box on input as empty bool invalid=false; //input box invalid=empty if(bGrowBox) invalid = boxmin.x>boxmax.x || boxmin.y>boxmax.y|| boxmin.z>boxmax.z; if(bGrowBox && invalid) bGrowBox=false; const ON_BOOL32 rc = GetBBox( bmin, bmax, bGrowBox ); if ( dim > 3 ) { boxmin.x = bmin[0]; boxmin.y = bmin[1]; boxmin.z = bmin[2]; boxmax.x = bmax[0]; boxmax.y = bmax[1]; boxmax.z = bmax[2]; } else if ( dim <= 2 ) { boxmin.z = 0.0; boxmax.z = 0.0; if ( dim <= 1 ) { boxmin.y = 0.0; boxmax.y = 0.0; } } return rc; }
CRhinoCommand::result CCommandSampleCageEdit::RunCommand( const CRhinoCommandContext& context ) { ON_Workspace ws; CRhinoCommand::result rc = CRhinoCommand::success; // Get the captive object CRhinoGetObject go; go.SetCommandPrompt( L"Select captive surface or polysurface" ); go.SetGeometryFilter( CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object ); go.GetObjects( 1, 1 ); rc = go.CommandResult(); if( CRhinoCommand::success != rc ) return rc; const CRhinoObject* captive = go.Object(0).Object(); if( 0 == captive ) return CRhinoCommand::failure; // Define the control line ON_Line line; CArgsRhinoGetLine args; rc = RhinoGetLine( args, line ); if( CRhinoCommand::success != rc ) return rc; // Get the curve parameters int degree = 3; int cv_count = 4; for(;;) { CRhinoGetOption gl; gl.SetCommandPrompt( L"NURBS Parameters" ); gl.AcceptNothing(); int d_opt = gl.AddCommandOptionInteger( RHCMDOPTNAME(L"Degree"), °ree, L"Curve degree", 1.0, 100.0 ); int p_opt = gl.AddCommandOptionInteger( RHCMDOPTNAME(L"PointCount"), &cv_count, L"Number of control points", 2.0, 100.0 ); gl.GetOption(); rc = gl.CommandResult(); if( CRhinoCommand::success != rc ) return rc; if( CRhinoGet::nothing == gl.Result() ) break; if( cv_count <= degree ) { if( CRhinoGet::option != gl.Result() ) continue; const CRhinoCommandOption* opt = go.Option(); if( 0 == opt ) continue; if( d_opt == opt->m_option_index ) cv_count = degree + 1; else degree = cv_count - 1; } } // Set up morph control ON_MorphControl* control = new ON_MorphControl(); control->m_varient = 1; // 1= curve // Specify the source line curve control->m_nurbs_curve0.Create( 3, false, 2, 2 ); control->m_nurbs_curve0.MakeClampedUniformKnotVector(); control->m_nurbs_curve0.SetCV( 0, line.from ); control->m_nurbs_curve0.SetCV( 1, line.to ); // Specify the destination NURBS curve control->m_nurbs_curve.Create( 3, false, degree + 1, cv_count ); control->m_nurbs_curve.MakeClampedUniformKnotVector(); double* g = ws.GetDoubleMemory( control->m_nurbs_curve.m_cv_count ); control->m_nurbs_curve.GetGrevilleAbcissae( g ); ON_Interval d = control->m_nurbs_curve.Domain(); double s = 0.0; int i; for( i = 0; i < control->m_nurbs_curve.m_cv_count; i++ ) { s = d.NormalizedParameterAt( g[i] ); control->m_nurbs_curve.SetCV( i, line.PointAt(s) ); } // Make sure domains match s = line.Length(); if( s > ON_SQRT_EPSILON ) control->m_nurbs_curve0.SetDomain( 0.0, s ); d = control->m_nurbs_curve0.Domain(); control->m_nurbs_curve.SetDomain( d[0], d[1] ); // Create the morph control object CRhinoMorphControl* control_object = new CRhinoMorphControl(); control_object->SetControl( control ); context.m_doc.AddObject( control_object ); // Set up the capture RhinoCaptureObject( control_object, const_cast<CRhinoObject*>(captive) ); // Clean up display context.m_doc.UnselectAll(); // Turn on the control grips control_object->EnableGrips( true ); context.m_doc.Redraw( CRhinoView::mark_display_hint ); return rc; }