Bounding Box with C++

I have some “big algorithm” in C++ with many .cpp files and also header files and I am actually supposed to do my homework, which I honestly can’t get it done at the moment. That’s why, I appreciate any tipps and help to get started.
So here comes the one of the many .cpp files:

/////////////////////////////////////////////////////////////////////////////
// cmdCiEBBox,cpp
//

#include "stdafx.h"

#include "LinAlg_Global.h"
#include "LinAlg_Matrix.h"
#include "LinAlg_Vector.h"
#include "LinAlg_MatrixOp.h"
#include "LinAlg_VectorOp.h"

#include "TGFRhinoPluginGlobal.h"
#include "TGFRhinoPlugin_BBox.h"
#include "TGFRhinoPlugin_ALLBBox.h"

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// BEGIN cmdCiEBBox command
//

class CCommandCiEBBox : public CRhinoCommand
{
public:
    CCommandCiEBBox() {}
    ~CCommandCiEBBox() {}

    UUID CommandUUID()
    {
        // {94E40A57-10C2-4606-872B-D469DE6D0B1A}
        static const GUID OrientedBBoxCommand_UUID =
        { 0x94E40A57, 0x10C2, 0x4606, { 0x87, 0x2B, 0xD4, 0x39, 0xDE, 0x6D, 0x0B, 0x1A } };
        return OrientedBBoxCommand_UUID;
    }

    const wchar_t* EnglishCommandName() { return L"CiEBBox"; }
    const wchar_t* LocalCommandName() { return L"CiEBBox"; }

    CRhinoCommand::result RunCommand( const CRhinoCommandContext& );

    
};

static class CCommandCiEBBox theCiEBBoxCommand;

CRhinoCommand::result CCommandCiEBBox::RunCommand( const CRhinoCommandContext& context )
{

    // get type of desired bbox (oriented or axis aligned)
    // http://wiki.mcneel.com/developer/sdksamples/commandlineoptions
    // http://wiki.mcneel.com/developer/sdksamples/setactiveview
    
    // *** Get options for BBox generation ***
    BBoxType desBBoxType = ALL_BBOX;
    double BBoxEps = 0.001;
    CiEPlg_BBox* pCiEBBOX = 0;
    bool DoVisualBBox = true;

    // strings with the names of possible bbox types
    int nboxT = 2;
    ON_wString ALLBoxString;
    ALLBoxString.Format( L"AxisAlignedBBox");
    ON_wString OrientBoxString;
    OrientBoxString.Format( L"OrientedBBox");

    CRhinoCommandOptionValue Typelist_items[2];
    Typelist_items[0] = RHCMDOPTVALUE(ALLBoxString);
    Typelist_items[1] = RHCMDOPTVALUE(OrientBoxString);

    // names of bbox types    
    ON_ClassArray<ON_wString> bboxtype_names;
    bboxtype_names.Append(ALLBoxString);
    bboxtype_names.Append(OrientBoxString);
    CRhinoGetOption  BBOpt;
    BBOpt.SetCommandPrompt(  L"CiE BBox Options" );
    BBOpt.AcceptNothing();
    // add the command options
    int m_list_index = 0;
    double m_epsVal = EPS;
    double maxEps = 1.0;
    double minEps = 1.0E-10;
    int    doVisualFlag = 1;
    for(;;)
    {
        BBOpt.ClearCommandOptions();
        int nOpts_BboxType = BBOpt.AddCommandOptionList( RHCMDOPTNAME(L"BBoxType"), 2, Typelist_items,m_list_index );
        int nOpts_BboxEPS = BBOpt.AddCommandOptionNumber( RHCMDOPTNAME(L"BBoxEPS"), &m_epsVal, L"BBox epsilon", FALSE, minEps, maxEps, 0 );
        int nOpts_BboxVisual = BBOpt.AddCommandOptionInteger( RHCMDOPTNAME(L"doVisualize"), &doVisualFlag, L"BBox visualization", 0, 1 );
    

        // Do the getstring
        CRhinoGet::result res = BBOpt.GetOption();

        // User pressed ESC
        if( res == CRhinoGet::cancel )
            return CRhinoCommand::cancel;

        // User pressed ENTER
        if( res == CRhinoGet::nothing )
        {
            break;
        }

        if( res != CRhinoGet::option )
          return CRhinoCommand::cancel;

        // get option index
        const CRhinoCommandOption* option = BBOpt.Option();
        if( !option )
          return CRhinoCommand::failure;
        int option_index = option->m_option_index;

        // eps value was modified
        if( option_index == nOpts_BboxEPS )
        {            

            continue;
        }

        // visualization flag was modified
        if( option_index == nOpts_BboxVisual )
        {
            if (! (doVisualFlag > 0 && doVisualFlag < 1))
                doVisualFlag = 0;
            continue;
        }

        // type of bbox was modified
        if( option_index == nOpts_BboxType )
        {
            m_list_index = option->m_list_option_current;
            if (! (m_list_index > 0 && m_list_index < bboxtype_names.Count()))
                m_list_index = 0;            
            continue;
        }
    }

    // evaluate final option settings
    if(doVisualFlag == 0) DoVisualBBox = false;
    if(doVisualFlag == 1) DoVisualBBox = true;
    
    if (m_list_index >= 0 && m_list_index <= 1)
                desBBoxType = BBoxType(m_list_index);

    if (m_epsVal >= minEps && m_epsVal <= maxEps)
                BBoxEps = m_epsVal;


    // *** Seelct faces for BBox generation ***

    // array with faces to analyse
    ON_SimpleArray<const CRhinoObject*> Objects;

    // first the user should select objects
    CRhinoGetObject GetO;
    GetO.EnablePreSelect( TRUE );    
    // only faces selectable
    GetO.SetGeometryFilter( CRhinoGetObject::surface_object );
    GetO.SetCommandPrompt( L"Select faces to compute bbox on" );
    // select some
    CRhinoGet::result res = GetO.GetObjects(1,0 );
    if( res != CRhinoGet::object )
    {
        // failed
        return GetO.CommandResult();
    }
    else
    {
        // store select objects
        int i, count = GetO.ObjectCount();
        for( i = 0; i < count; i++ )
        {
             const CRhinoObjRef& obj_ref = GetO.Object( i );
             const CRhinoObject* obj = obj_ref.Object();
            if( obj )
            {
                // add to object array
                Objects.Append(obj);
            }
        }        
        // loop over all objects
        count = Objects.Count();
        for( int i = 0; i < count; i++ )
        {
            // ok lets create a BBox instance
            if(desBBoxType == ALL_BBOX) pCiEBBOX = new CiEPlg_ALLBBox(BBoxEps);
            if(desBBoxType == ORIENT_BBOX) pCiEBBOX = new CiEPlg_OrientBBox(BBoxEps);
            if(pCiEBBOX == 0)
                return CRhinoCommand::failure;
            // compute bounding box
            const CRhinoObject* aObj = Objects[i];
            if(aObj){
                // call routine to compute box of those selected shapes
                // ********* YOUR JOB ***
                if(pCiEBBOX->computeBBox(aObj) != CRhinoCommand::success)
                    return CRhinoCommand::failure;
                // ********* YOUR JOB ***
            
                // add to shape
                // first get objects uuid: http://wiki.mcneel.com/developer/sdksamples/getuuid
                ON_UUID uuid = aObj->Attributes().m_uuid;
                // add
                CiEPlg_Shape* pCiEPlg_Shape = CiEPlg_Shape::get_Instance();
                if( pCiEPlg_Shape->addBBox2Shape(uuid,pCiEBBOX) != CRhinoCommand::success)
                    return CRhinoCommand::failure;

                // visualize if desired
                // ********* YOUR JOB ***
                if(DoVisualBBox) {
                    if(pCiEBBOX->doVisualBBox() != CRhinoCommand::success)
                        return CRhinoCommand::failure;
                }
                // ********* YOUR JOB ***                
            }
        }    


        
    }
    

    // return
    return CRhinoCommand::success;
}
//
// END CiEBBox command
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

So my first question is about this piece of code:

// get type of desired bbox (oriented or axis aligned)
// http://wiki.mcneel.com/developer/sdksamples/commandlineoptions
// http://wiki.mcneel.com/developer/sdksamples/setactiveview

How am I supposed to do that in this context? … I know … It isn’t easy … Thanks for anything!!!

Hi Ahmed,

Are you having a problem? What are you trying to do?

– Dale

1 Like

Hi Dale,

yes, I have a problem of understanding the problem. Basically the homework is to complete the missing parts of a plugin project for rhino written in c++ so that a bounding box as a result for a given surface is generated… Tomorrow I will be at university and I will have access to the files. I will try to engineer my problem in such a way, that you might be able to help me out. I still have no clue, what I am actually trying to accomplish here … Thanks in advance!!!

Ahmed

So how can I visualize a box in Rhino by given corner points? …

See if this example is is helpful.

https://github.com/mcneel/Rhino5Samples_CPP/blob/master/SampleCommands/cmdSampleBoundingBox.cpp

1 Like

Thank you Dale, this looks nice, but I need some guidance here to understand the problem, because I can’t blick through this at the moment.

So the first task is to visualize a box in rhino given some corner points.

My problem is, I don’t know, where in the code I should implement this! I will look at it again on friday…, Right now I gotta work ,

I am still not able to visualize a box …

Did the sample code work for you? What problem are you having?

1 Like

The problem is that I don’t know, where in the code, that I have got, which code comes?

I don’t even know, where to start or what to start with!

Could you help me with understanding, what’s going on around here:

So THIS:

class CCommandCiEBBox : public CRhinoCommand
{
public:
    CCommandCiEBBox() {}
    ~CCommandCiEBBox() {}

    UUID CommandUUID()
    {
        // {94E40A57-10C2-4606-872B-D469DE6D0B1A}
        static const GUID OrientedBBoxCommand_UUID =
        { 0x94E40A57, 0x10C2, 0x4606, { 0x87, 0x2B, 0xD4, 0x39, 0xDE, 0x6D, 0x0B, 0x1A } };
        return OrientedBBoxCommand_UUID;
    }

    const wchar_t* EnglishCommandName() { return L"CiEBBox"; }
    const wchar_t* LocalCommandName() { return L"CiEBBox"; }

    CRhinoCommand::result RunCommand( const CRhinoCommandContext& );

    
};

is doing WHAT?

100 errors!

No help? I need some explanations to start with …

I cannot tell, from your screen captures, what version of Visual Studio you have. But to write 64-bit plug-ins for Rhino 5, you need Visual C++ 2010 Professional - the free versions of Visual C++ do not work…

1 Like

I have Microsoft Visual Studio 2010 Ultimate

That should work. During the installation, did you install ALL of the C++ components? Looks like you might not have installed MFC…

1 Like











What is MFC?
I don’t have a laptop. I (ab)use the computers at university.

Visual Studio 2010 cannot build 32-bit plug-ins for Rhino 5. Visual Studio 2010 can only build 64-bit plug-ins for Rhino 5. So, change your target platform from 32-bit to 64-bit and rebuild.

1 Like

Ok, thanks. I will try that on thursday, when I am at university.

What comes next? …

I did that, but still there are some errors …