How to create a BoundingBox?

Hi All

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
	CRhinoGetObject GetObj;
	GetObj.EnablePreSelect(FALSE);
	GetObj.SetCommandPrompt(L"Select objects to frame with a box");
	GetObj.SetGeometryFilter(
		CRhinoGetObject::surface_object |
		CRhinoGetObject::polysrf_object |
		CRhinoGetObject::mesh_object
	);
	/*
	GetObj.SetGeometryAttributeFilter(
		CRhinoGetObject::closed_surface |
		CRhinoGetObject::closed_polysrf |
		CRhinoGetObject::closed_mesh
	);
	*/
	GetObj.EnableSubObjectSelect(false);
	GetObj.EnableGroupSelect(true);
	GetObj.GetObjects(1, 0);
	if (GetObj.CommandResult() != CRhinoCommand::success)
		return GetObj.CommandResult();

	int i, count = GetObj.ObjectCount();
	for (i = 0; i < count; i++)
	{
		if (GetObj.Object(i).Object())
		{
			ON_BoundingBox bbox;
			GetObj.Object(i).Geometry()->GetTightBoundingBox(bbox, bbox.IsValid());

			ON_3dPointArray boxcorners;

			boxcorners.Append(ON_3dPoint(bbox.Corner(0, 0, 0)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(1, 0, 0)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(1, 1, 0)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(0, 1, 0)));

			boxcorners.Append(ON_3dPoint(bbox.Corner(0, 0, 1)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(1, 0, 1)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(1, 1, 1)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(0, 1, 1)));

			ON_Brep* pBrep = ON_BrepBox(boxcorners);
			if (pBrep)
			{
				CRhinoBrepObject* BrepObject = new CRhinoBrepObject();
				BrepObject->SetBrep(pBrep);
				if (context.m_doc.AddObject(BrepObject))
					context.m_doc.Redraw();
				else
					delete BrepObject;
			}
		}
	}
	return CRhinoCommand::success;
}

why is there more of a boundingbox when I remove the “SetGeometryFilter” condition ?

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
	CRhinoGetObject GetObj;
	GetObj.EnablePreSelect(FALSE);
	GetObj.SetCommandPrompt(L"Select objects to frame with a box");
	/*
	GetObj.SetGeometryFilter(
		CRhinoGetObject::surface_object |
		CRhinoGetObject::polysrf_object |
		CRhinoGetObject::mesh_object
	);
	GetObj.SetGeometryAttributeFilter(
		CRhinoGetObject::closed_surface |
		CRhinoGetObject::closed_polysrf |
		CRhinoGetObject::closed_mesh
	);
	*/
	GetObj.EnableSubObjectSelect(false);
	GetObj.EnableGroupSelect(true);
	GetObj.GetObjects(1, 0);
	if (GetObj.CommandResult() != CRhinoCommand::success)
		return GetObj.CommandResult();

	int i, count = GetObj.ObjectCount();
	for (i = 0; i < count; i++)
	{
		if (GetObj.Object(i).Object())
		{
			ON_BoundingBox bbox;
			GetObj.Object(i).Geometry()->GetTightBoundingBox(bbox, bbox.IsValid());

			ON_3dPointArray boxcorners;

			boxcorners.Append(ON_3dPoint(bbox.Corner(0, 0, 0)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(1, 0, 0)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(1, 1, 0)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(0, 1, 0)));

			boxcorners.Append(ON_3dPoint(bbox.Corner(0, 0, 1)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(1, 0, 1)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(1, 1, 1)));
			boxcorners.Append(ON_3dPoint(bbox.Corner(0, 1, 1)));

			ON_Brep* pBrep = ON_BrepBox(boxcorners);
			if (pBrep)
			{
				CRhinoBrepObject* BrepObject = new CRhinoBrepObject();
				BrepObject->SetBrep(pBrep);
				if (context.m_doc.AddObject(BrepObject))
					context.m_doc.Redraw();
				else
					delete BrepObject;
			}
		}
	}
	return CRhinoCommand::success;
}

more is obtained precisely on a “closed extrusion”??
– Karlos

Hi @ccx07,

Use RhinoGetTightBoundingBox. See RhinoSdkUtilities.h for details.

cmdSampleBoundingBox.cpp

– Dale

Thank you very much Dale