home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / bondngbx.c < prev    next >
C/C++ Source or Header  |  1992-10-19  |  2KB  |  62 lines

  1. /*
  2.  * BoundingBox.C - methods for class BoundingBox.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  */
  17.  
  18. #include <values.h>
  19. #include "BoundingBox.h"
  20. #include "TransMatrix.h"
  21.  
  22. //___________________________________________________________ BoundingBox
  23.  
  24. BoundingBox::BoundingBox()
  25. : vmin(MAXDOUBLE, MAXDOUBLE, MAXDOUBLE), vmax(-MAXDOUBLE, -MAXDOUBLE, -MAXDOUBLE)
  26. {}
  27.  
  28. BoundingBox BoundingBox::transform(const TransMatrix& tmat) const
  29. {
  30.   BoundingBox retval;
  31.   
  32.   retval.expand(Vector(vmin[0], vmin[1], vmin[2])*tmat);
  33.   retval.expand(Vector(vmax[0], vmin[1], vmin[2])*tmat); 
  34.   retval.expand(Vector(vmax[0], vmax[1], vmin[2])*tmat); 
  35.   retval.expand(Vector(vmin[0], vmax[1], vmin[2])*tmat); 
  36.   retval.expand(Vector(vmin[0], vmin[1], vmax[2])*tmat); 
  37.   retval.expand(Vector(vmax[0], vmin[1], vmax[2])*tmat); 
  38.   retval.expand(Vector(vmax[0], vmax[1], vmax[2])*tmat); 
  39.   retval.expand(Vector(vmin[0], vmax[1], vmax[2])*tmat);
  40.  
  41.   return retval;
  42. }
  43.  
  44. void BoundingBox::expand(const Vector& v)
  45. {
  46.   if (v[0] < vmin[0]) vmin[0] = v[0]; if (v[0] > vmax[0]) vmax[0] = v[0];
  47.   if (v[1] < vmin[1]) vmin[1] = v[1]; if (v[1] > vmax[1]) vmax[1] = v[1];
  48.   if (v[2] < vmin[2]) vmin[2] = v[2]; if (v[2] > vmax[2]) vmax[2] = v[2];
  49. }
  50.  
  51. void BoundingBox::expand(const BoundingBox& b)
  52. {
  53.   expand(b.vmin);
  54.   expand(b.vmax);
  55. }
  56.  
  57. ostream& operator<<(ostream& os, const BoundingBox& b)
  58. {
  59.   return os << "{ min" << b.vmin << ", max" << b.vmax << " }";
  60. }
  61.  
  62.