Click here to Skip to main content
12,823,725 members (64,225 online)
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads

Stats

297.9K views
11.3K downloads
53 bookmarked
Posted 5 Mar 2003

StL Data File Viewer

, 5 Mar 2003 CPOL
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)

Share

About the Author

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

You may also be interested in...

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