Click here to Skip to main content
15,896,479 members
Articles / Desktop Programming / MFC

StL Data File Viewer

Rate me:
Please Sign up or sign in to vote.
4.87/5 (43 votes)
5 Mar 2003CPOL2 min read 526.5K   14.7K   60  
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 Code Project Open License (CPOL)


Written By
Product Manager Mahindra & Mahindra
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

Comments and Discussions