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

Revision 2575, 1.5 KB checked in by bittner, 17 years ago (diff)

big merge: preparation for havran ray caster, check if everything works

RevLine 
[191]1#ifndef __RECTANGLE3_H
2#define __RECTANGLE3_H
[863]3
[245]4#include <iostream>
[2176]5//
[191]6#include "Vector3.h"
7
[860]8namespace GtpVisibilityPreprocessor {
9
[209]10/// rectangle vertices
11//   3 2
12//   0 1
[191]13class Rectangle3 {
14public:
15  Vector3 mVertices[4];
16
[1772]17  inline Vector3 GetVertex(const int i) const { return mVertices[i]; }
[209]18  Rectangle3() {}
19 
[191]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 
[245]30  Vector3 GetNormal() const {
[191]31    return Normalize(CrossProd(mVertices[0]-mVertices[1],
32                               mVertices[2]-mVertices[1]
33                               ));
34  }
35 
[245]36  Vector3 GetCenter() const {
[191]37    return (mVertices[0] + mVertices[1] + mVertices[2] + mVertices[3])/4.0f;
38  }
39
[245]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   
[2575]53    return 0.5f * fabs(DotProd(GetNormal(), v));
[245]54  }
55 
[209]56  void
57  Split(const int axis,
58        Rectangle3 &r1,
59        Rectangle3 &r2
[223]60        ) const;
[245]61
[2176]62  friend std::ostream& operator<< (std::ostream &s, const Rectangle3 &r) {
[245]63    return s<<"Rectangle3:"<<r.mVertices[0]<<r.mVertices[1]<<r.mVertices[2]<<r.mVertices[3];
64  }
65
[191]66};
67
[860]68}
[191]69
70#endif
Note: See TracBrowser for help on using the repository browser.