source: GTP/trunk/Lib/Vis/Preprocessing/src/Rectangle3.h @ 2176

Revision 2176, 1.5 KB checked in by mattausch, 18 years ago (diff)

removed using namespace std from .h

Line 
1#ifndef __RECTANGLE3_H
2#define __RECTANGLE3_H
3
4#include <iostream>
5//
6#include "Vector3.h"
7
8namespace GtpVisibilityPreprocessor {
9
10/// rectangle vertices
11//   3 2
12//   0 1
13class Rectangle3 {
14public:
15  Vector3 mVertices[4];
16
17  inline Vector3 GetVertex(const int i) const { return mVertices[i]; }
18  Rectangle3() {}
19 
20  Rectangle3(const Vector3 &v0,
21             const Vector3 &v1,
22             const Vector3 &v2,
23             const Vector3 &v3) {
24    mVertices[0] = v0;
25    mVertices[1] = v1;
26    mVertices[2] = v2;
27    mVertices[3] = v3;
28  }
29 
30  Vector3 GetNormal() const {
31    return Normalize(CrossProd(mVertices[0]-mVertices[1],
32                               mVertices[2]-mVertices[1]
33                               ));
34  }
35 
36  Vector3 GetCenter() const {
37    return (mVertices[0] + mVertices[1] + mVertices[2] + mVertices[3])/4.0f;
38  }
39
40  int DominantAxis() const {
41    if (SqrMagnitude(mVertices[0] - mVertices[1]) >  SqrMagnitude(mVertices[0] - mVertices[3]))
42      return 0;
43    else
44      return 1;
45  }
46     
47  float GetArea() const {
48    Vector3 v = CrossProd(mVertices[3], mVertices[0]);
49   
50    for (int i=0; i < 3; i++)
51      v += CrossProd(mVertices[i], mVertices[i+1]);
52   
53    return 0.5f*abs(DotProd(GetNormal(), v));
54  }
55 
56  void
57  Split(const int axis,
58        Rectangle3 &r1,
59        Rectangle3 &r2
60        ) const;
61
62  friend std::ostream& operator<< (std::ostream &s, const Rectangle3 &r) {
63    return s<<"Rectangle3:"<<r.mVertices[0]<<r.mVertices[1]<<r.mVertices[2]<<r.mVertices[3];
64  }
65
66};
67
68}
69
70#endif
Note: See TracBrowser for help on using the repository browser.