Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads
 
Add your own
alternative version

StL Data File Viewer

, 5 Mar 2003 GPL3
A simple StereoLithography data file viewer.
// BoundingBox.cpp: implementation of the CBoundingBox class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BoundingBox.h"
#include "Point3D.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBoundingBox::CBoundingBox()
{

}

CBoundingBox::CBoundingBox(const double& xMin, const double& xMax, 
						   const double& yMin, const double& yMax, 
						   const double& zMin, const double& zMax) : itsXMax(xMax), itsXMin(xMin),
						   itsYMax(yMax), itsYMin(yMin),
						   itsZMax(zMax), itsZMin(zMin)
{
}

CBoundingBox::~CBoundingBox()
{

}

CPoint3D CBoundingBox::Center() const
{
	CPoint3D P;
	P.SetX((XMax() + XMin())/2);
	P.SetY((YMax() + YMin())/2);
	P.SetZ((ZMax() + ZMin())/2);
	return P;
}

double CBoundingBox::BoundingRadius() const
{
	double rad;
	CPoint3D Pmax(XMax(), YMax(), ZMax());
	CPoint3D Cen = Center();
	rad = Pmax.Distance(Cen);
	return rad;
}

void CBoundingBox::SetLimits(const double& xMin, const double& xMax, 
						   const double& yMin, const double& yMax, 
						   const double& zMin, const double& zMax)
{
	itsXMax = xMax;
	itsXMin = xMin;
	itsYMax = yMax;
	itsYMin = yMin;
	itsZMax = zMax;
	itsZMin = zMin;
}

bool CBoundingBox::Contains(const CPoint3D& P) const
{
	bool bx = false, by = false, bz = false;
	bx = (P.GetX() <= XMax() && P.GetX() >= XMin());
	by = (P.GetY() <= YMax() && P.GetY() >= YMin());
	bz = (P.GetZ() <= ZMax() && P.GetZ() >= ZMin());

	return (bx && by &&bz);
}

void CBoundingBox::AddBox(const CBoundingBox& B)
{
	if(B.XMax() > XMax())
		itsXMax = B.XMax();
	if(B.XMin() < XMin())
		itsXMin = B.XMin();

	if(B.YMax() > YMax())
		itsYMax = B.YMax();
	if(B.YMin() < YMin())
		itsYMin = B.YMin();

	if(B.ZMax() > ZMax())
		itsZMax = B.ZMax();
	if(B.ZMin() < ZMin())
		itsZMin = B.ZMin();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Sharjith
Engineer Tata Technologies Ltd
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150129.1 | Last Updated 6 Mar 2003
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid