- Timestamp:
- 06/10/08 13:15:59 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 2 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.cpp
r2747 r2751 6 6 using namespace std; 7 7 8 //namespace CHCDemo 9 //{ 10 11 // AxisAlignedBox3 implementations 8 namespace CHCDemo 9 { 12 10 13 11 // Overload << operator for C++-style output … … 27 25 >> A.mMax.x >> a >> A.mMax.y >> a >> A.mMax.z >> a; 28 26 } 27 28 29 AxisAlignedBox3::AxisAlignedBox3() 30 { } 31 32 33 AxisAlignedBox3::AxisAlignedBox3(const Vector3 &nMin, const Vector3 &nMax) 34 : mMin(nMin), mMax(nMax) 35 {} 36 29 37 30 38 … … 246 254 ext.x * ext.z + 247 255 ext.y * ext.z); 256 } 257 258 259 float AxisAlignedBox3::GetVolume() const 260 { 261 return (mMax.x - mMin.x) * (mMax.y - mMin.y) * (mMax.z - mMin.z); 248 262 } 249 263 … … 947 961 Vector3 size = Size(); 948 962 949 return GetRandomPoint(Vector3(RandomValue(0.0f, 1.0f), 950 RandomValue(0.0f, 1.0f), 951 RandomValue(0.0f, 1.0f))); 952 } 953 954 955 Vector3 AxisAlignedBox3::GetRandomPoint(const Vector3 &r) const 956 { 957 return mMin + Size()*r; 963 return mMin + Vector3(RandomValue(0.0f, 1.0f), 964 RandomValue(0.0f, 1.0f), 965 RandomValue(0.0f, 1.0f)) * Size(); 958 966 } 959 967 … … 1004 1012 } 1005 1013 1006 //} 1007 1014 1015 Vector3 AxisAlignedBox3::GetVertex(const int N) const 1016 { 1017 Vector3 v; 1018 GetVertex(N, v); 1019 1020 return v; 1021 } 1022 1023 1024 float AxisAlignedBox3::GetExtent(int face) const 1025 { 1026 if (face < 3) 1027 return mMin[face]; 1028 else 1029 return mMax[face - 3]; 1030 } 1031 1032 1033 } 1034 -
GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.h
r2749 r2751 10 10 11 11 12 //namespace CHCDemo13 //{12 namespace CHCDemo 13 { 14 14 15 15 struct Triangle3; 16 16 17 17 /** Axis alignedd box class. 18 This is a box in 3-space, defined by min and max 19 corner vectors. Many useful operations are defined 20 on this 18 This is a box in 3-space, defined by min and max 19 corner vectors. Many useful operations are defined. 21 20 */ 22 21 class AxisAlignedBox3 … … 25 24 public: 26 25 27 // Constructors. 28 AxisAlignedBox3() { } 29 30 AxisAlignedBox3(const Vector3 &nMin, const Vector3 &nMax) 31 { 32 mMin = nMin; mMax = nMax; 33 } 34 26 /////////// 27 //-- Constructors. 28 29 AxisAlignedBox3(); 30 31 AxisAlignedBox3(const Vector3 &nMin, const Vector3 &nMax); 35 32 /** initialization to the non existing bounding box 36 33 */ … … 131 128 */ 132 129 void Translate(const Vector3 &shift); 133 134 130 /** Returns the square of the minimal and maximal distance to 135 a point on the box. 136 */ 137 void 138 GetSqrDistances(const Vector3 &point, 139 float &minDistance, 140 float &maxDistance 141 ) const; 142 143 144 145 Vector3 GetRandomPoint(const Vector3 &r) const; 131 a point on the box. 132 */ 133 void GetSqrDistances(const Vector3 &point, 134 float &minDistance, 135 float &maxDistance) const; 136 /** return random point in box. 137 */ 146 138 Vector3 GetRandomPoint() const; 147 148 Vector3 GetPoint(const Vector3 &p) const 149 { 150 return mMin + p*Size(); 151 } 152 153 154 protected: 155 Vector3 mMin, mMax; 156 157 public: 158 159 // Returns the smallest axis-aligned box that includes all points 160 // inside the two given boxes. 161 friend inline AxisAlignedBox3 Union(const AxisAlignedBox3 &x, 162 const AxisAlignedBox3 &y); 163 164 // Returns the intersection of two axis-aligned boxes. 165 friend inline AxisAlignedBox3 Intersect(const AxisAlignedBox3 &x, 166 const AxisAlignedBox3 &y); 167 168 // Given 4x4 matrix, transform the current box to new one. 169 friend inline AxisAlignedBox3 Transform(const AxisAlignedBox3 &box, 170 const Matrix4x4 &tform); 171 172 173 // returns true when two boxes are completely equal 174 friend inline int operator== (const AxisAlignedBox3 &A, 175 const AxisAlignedBox3 &B); 176 177 virtual float SurfaceArea() const; 178 virtual float GetVolume() const 179 { 180 return (mMax.x - mMin.x) * (mMax.y - mMin.y) * (mMax.z - mMin.z); 181 } 139 /** Returns surface area of the box. 140 */ 141 float SurfaceArea() const; 142 /** Returns volume of the box. 143 */ 144 float GetVolume() const; 182 145 183 146 // Six faces are distuinguished by their name. … … 194 157 195 158 // For edge .. number <0..11> returns two incident vertices 196 void GetEdge( constint edge, Vector3 *a, Vector3 *b) const;159 void GetEdge(int edge, Vector3 *a, Vector3 *b) const; 197 160 198 161 // Compute the coordinates of one vertex of the box for 0/1 in each axis … … 203 166 // x,y,z are either 0 or 1; (0 .. lower coordinate, 1 .. large coordinate) 204 167 // (xmin,ymin, zmin) .. N = 0, (xmax, ymax, zmax) .. N= 7 205 void GetVertex(const int N, Vector3 &vertex) const; 206 207 Vector3 GetVertex(const int N) const { 208 Vector3 v; 209 GetVertex(N, v); 210 return v; 211 } 212 213 // Returns 1, if the box includes on arbitrary face a given box 168 void GetVertex(int N, Vector3 &vertex) const; 169 170 Vector3 GetVertex(int N) const; 171 /** get the extent of face. 172 */ 173 float GetExtent(int face) const; 174 /** Returns 1, if the box includes on arbitrary face a given box 175 */ 214 176 int IsPiercedByBox(const AxisAlignedBox3 &box, int &axis) const; 215 216 177 217 178 int GetFaceVisibilityMask(const Vector3 &position) const; … … 219 180 */ 220 181 //Plane3 GetPlane(const int face) const; 221 222 223 182 /** Returns vertex indices of edge. 224 183 */ … … 226 185 227 186 228 // get the extent of face 229 float GetExtent(const int &face) const 230 { 231 if (face < 3) 232 return mMin[face]; 233 else 234 return mMax[face - 3]; 235 } 187 188 //////////// 189 //-- friend functions 190 191 // Returns the smallest axis-aligned box that includes all points 192 // inside the two given boxes. 193 friend inline AxisAlignedBox3 Union(const AxisAlignedBox3 &x, 194 const AxisAlignedBox3 &y); 195 196 // Returns the intersection of two axis-aligned boxes. 197 friend inline AxisAlignedBox3 Intersect(const AxisAlignedBox3 &x, 198 const AxisAlignedBox3 &y); 199 200 // Given 4x4 matrix, transform the current box to new one. 201 friend inline AxisAlignedBox3 Transform(const AxisAlignedBox3 &box, 202 const Matrix4x4 &tform); 203 204 205 // returns true when two boxes are completely equal 206 friend inline int operator== (const AxisAlignedBox3 &A, 207 const AxisAlignedBox3 &B); 208 209 // input and output operator with stream 210 friend std::ostream& operator<<(std::ostream &s, const AxisAlignedBox3 &A); 211 friend std::istream& operator>>(std::istream &s, AxisAlignedBox3 &A); 212 213 236 214 237 215 // The vertices that form boundaries of the projected bounding box … … 272 250 static const int fsvertices[27][9]; 273 251 274 // input and output operator with stream 275 friend std::ostream& operator<<(std::ostream &s, const AxisAlignedBox3 &A); 276 friend std::istream& operator>>(std::istream &s, AxisAlignedBox3 &A); 252 protected: 253 254 Vector3 mMin, mMax; 255 277 256 }; 278 257 … … 385 364 386 365 387 //}366 } 388 367 389 368 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
r2746 r2751 13 13 #include "Viewer.h" 14 14 15 16 15 #include <fstream> 17 16 #include <iostream> 18 17 #include <iomanip> 19 18 19 20 21 namespace CHCDemo 22 { 23 20 24 #define INVALID_TEST ((unsigned int)-1) 21 #define MAX_FLOAT 1e20f22 25 23 26 #define TYPE_INTERIOR -2 … … 324 327 float Bvh::SelectPlaneSah(BvhLeaf *leaf, int &axis, float &minCost) 325 328 { 326 minCost = MAX _FLOAT;329 minCost = MAXFLOAT; 327 330 float bestPos = minCost; 328 331 int bestAxis = 0; … … 584 587 pos = SelectPlaneSah(leaf, axis, cost); 585 588 586 if (pos != MAX _FLOAT)589 if (pos != MAXFLOAT) 587 590 { 588 591 split = SortTriangles(leaf, axis, pos); 589 592 } 590 593 591 if ((pos == MAX _FLOAT) || (split == leaf->mLast))594 if ((pos == MAXFLOAT) || (split == leaf->mLast)) 592 595 { 593 596 split = -1; … … 608 611 pos = SelectPlaneSah(leaf, axis, cost); 609 612 610 if (pos != MAX _FLOAT)613 if (pos != MAXFLOAT) 611 614 split = SortTriangles(leaf, axis, pos); 612 615 else … … 2590 2593 } 2591 2594 2595 } 2596 2592 2597 #endif -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
r2746 r2751 3 3 #ifndef __BVH_H 4 4 #define __BVH_H 5 5 6 6 7 #if TOIMPLEMENT … … 12 13 #include "HierarchyNode.h" 13 14 #include "FlexibleHeap.h" 15 16 17 18 namespace CHCDemo 19 { 14 20 15 21 … … 894 900 }; 895 901 902 } 903 896 904 #endif 897 905 #endif // __BVH_H -
GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.cpp
r2746 r2751 1 #if 0 2 3 1 4 #include "Geometry.h" 2 5 #include "glInterface.h" … … 5 8 6 9 #include <math.h> 10 11 12 namespace CHCDemo 13 { 7 14 8 15 #define NO_LIST -1 … … 547 554 glFrontFace(GL_CCW); 548 555 } 556 557 } 558 559 #endif -
GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.h
r2746 r2751 2 2 #define GEOMETRY_H 3 3 4 extern "C" 4 5 namespace CHCDemo 5 6 { 6 #include "MathStuff.h"7 }8 7 9 /** Represents a drawable geometry. It can draw simple objects (teapot, 10 torus, shere. It also contains the object transformation and 11 the material .An AAB is used as bouning volume. 8 /** Represents drawable geometry consisting of triangles 12 9 */ 13 10 class Geometry 14 11 { 15 12 public: 16 Geometry(); 17 Geometry(Vector3 translation, float xRot, float yRot, float zRot, float scale, int objectType); 18 //! Renders this geometry 19 void Render(); 20 //! sets rotations in degree : executed in the order x, y, and z rotation 21 void SetRotations(float xRot, float yRot, float zRot); 22 //! sets the rotation matrix 23 void SetTranslation(Vector3 translation); 24 //! a uniform scale 25 void SetScale(float scale); 26 //! returns current scale 27 float GetScale(); 28 29 //! returns translation 30 void GetTranslation(Vector3 translation); 31 //! returns rotation 32 void GetRotations(float &xRot, float &yRot, float &zRot); 33 34 //! Set pointer to the material 35 void SetMaterial(Material *mat); 36 //! Returns the bounding box 37 const AABox& GetBoundingVolume(); 38 //! last visited flag, important for rendering each geometry only once 39 void SetLastVisited(int lastVisited); 40 //! returns lastvisited flag 41 int GetLastVisited(); 42 // --- sets the object type to one of teapot, torus, sphere 43 void SetObjectType(int type); 44 45 46 47 static int sDisplayList[NUM_OBJECTS]; 48 49 //! cleans static members 50 static void CleanUp(); 51 //! returns the triangle count of the specified object type 52 static int CountTriangles(int objectType); 53 //! initialises display lists 54 static void ResetLists(); 13 /** Constructor taking a triangle container. 14 */ 15 Geometry(const TriangleContainer &triangles); 55 16 56 17 protected: 57 18 58 //! generates the display list this a object 59 void GenerateList(); 19 AxisAlignedBox3 mBoundingBox; 20 TriangleContainer mTriangles; 21 } 60 22 61 //! calculates accumulated transformation matrix62 void CalcTransform();63 //! applies tranformations64 void Transform();65 23 66 // --- statistics 67 static int CountTorusTriangles(); 68 static int CountSphereTriangles(); 69 static int CountTeapotTriangles(); 24 /** Class representing a scene entity. 25 A scene entity basicly consists of geometry, transformation, and a material 26 */ 27 class SceneEntity 28 { 29 /** Create scene entity. 30 */ 31 SceneEntity(Geometry *geometry, Matrix4x4 *trafo, Material *mat); 32 /** Renders this geometry. 33 */ 34 void Render(); 35 /** Set pointer to the geometry 36 */ 37 void SetGeometry(Geometry *geom); 38 /** Set pointer to the geometry 39 */ 40 void SetTransformation(const Matrix4x4 *trafo); 41 /** Set pointer to the material 42 */ 43 void SetMaterial(Material *mat); 44 /** Returns the transformed bounding box. 45 */ 46 const AxisAlignedBox3& GetBoundingVolume(); 47 /** set frame where we last visitied this node 48 */ 49 void SetLastVisited(int lastVisited); 50 /** returns frame where we last visited this node 51 */ 52 int GetLastVisited() const; 70 53 71 //! 72 static void CreateTorus(float innerRadius, float outerRadius, int precision); 54 protected: 73 55 74 //! calculates the bounding volume of this geometry 75 void CalcBoundingVolume(); 76 // the size of the bounging box is calculated using the radius of the sphere 77 void CalcSphereBoundingVolume(); 78 // the standard bounding volume calculation having an array of vertices 79 void CalcBoundingVolume(float *vertices, const int num_vertices); 56 /// transform matrix 57 Matrix4x4 *mTransform; 58 Geometry *mGeometry; 59 Material *mMaterial; 80 60 81 // initialises static members 82 static bool Init(); 83 84 // --- drawing routines 85 static void RenderTeapot(); 86 static void RenderSphere(); 87 static void RenderTorus(); 88 89 // --- transformations 90 float mXRotation; 91 float mYRotation; 92 float mZRotation; 93 94 float mScale; 95 96 Vector3 mTranslation; 97 98 //! accumulated transform matrix 99 Matrix4x4 mTransform; 100 101 // --- material 102 float mAmbientColor[3]; 103 float mDiffuseColor[3]; 104 float mSpecularColor[3]; 105 106 AABox mBoundingBox; 107 //! type of the rendered object (teapot, sphere ...) 108 int mObjectType; 61 AxisAlignedBox3 mBoundingBox; 109 62 110 63 int mLastVisited; 111 112 // --- static members113 114 static bool sIsInitialised;115 116 static float const sphere_radius;117 118 static int num_torus_indices;119 static int num_torus_vertices;120 static int num_torus_normals;121 122 static float *torus_vertices;123 static float *torus_normals;124 static int *torus_indices;125 126 static const int torus_precision;127 static const int sphere_precision;128 static const float torus_inner_radius;129 static const float torus_outer_radius;130 64 }; 131 65 132 66 } 133 67 #endif // GEOMETRY_H -
GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp
r2747 r2751 2 2 #include "Material.h" 3 3 4 //namespace CHCDemo5 //{4 namespace CHCDemo 5 { 6 6 7 7 RgbColor RandomColor(const float a, const float b) … … 22 22 } 23 23 24 25 26 //} 24 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h
r2747 r2751 2 2 #define __MATERIAL_H 3 3 4 //namespace CHCDemo5 //{6 4 5 namespace CHCDemo 6 { 7 7 8 8 class RgbColor … … 80 80 extern Material RandomMaterial(); 81 81 82 //}82 } 83 83 84 84 #endif -
GTP/trunk/App/Demos/Vis/CHC_revisited/Matrix4x4.cpp
r2746 r2751 6 6 using namespace std; 7 7 8 //namespace GtpVisibilityPreprocessor { 8 namespace CHCDemo 9 { 10 11 Matrix4x4::Matrix4x4() 12 {} 9 13 10 14 … … 85 89 x[3][3] = x44; 86 90 } 91 92 93 float Matrix4x4::Det3x3() const 94 { 95 return (x[0][0]*x[1][1]*x[2][2] + \ 96 x[1][0]*x[2][1]*x[0][2] + \ 97 x[2][0]*x[0][1]*x[1][2] - \ 98 x[2][0]*x[1][1]*x[0][2] - \ 99 x[0][0]*x[2][1]*x[1][2] - \ 100 x[1][0]*x[0][1]*x[2][2]); 101 } 102 87 103 88 104 … … 167 183 } 168 184 185 169 186 // Invert the given matrix using the above inversion routine. 170 Matrix4x4 171 Invert(const Matrix4x4& M) 187 Matrix4x4 Invert(const Matrix4x4& M) 172 188 { 173 189 Matrix4x4 InvertMe = M; … … 178 194 179 195 // Transpose the matrix. 180 void 181 Matrix4x4::Transpose() 196 void Matrix4x4::Transpose() 182 197 { 183 198 for (int i = 0; i < 4; i++) … … 190 205 } 191 206 207 192 208 // Transpose the given matrix using the transpose routine above. 193 Matrix4x4 194 Transpose(const Matrix4x4& M) 209 Matrix4x4 Transpose(const Matrix4x4& M) 195 210 { 196 211 Matrix4x4 TransposeMe = M; … … 199 214 } 200 215 216 201 217 // Construct an identity matrix. 202 Matrix4x4 203 IdentityMatrix() 218 Matrix4x4 IdentityMatrix() 204 219 { 205 220 Matrix4x4 M; … … 211 226 } 212 227 228 213 229 // Construct a zero matrix. 214 Matrix4x4 215 ZeroMatrix() 230 Matrix4x4 ZeroMatrix() 216 231 { 217 232 Matrix4x4 M; … … 635 650 } 636 651 637 //}652 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Matrix4x4.h
r2746 r2751 5 5 6 6 7 //namespace GtpVisibilityPreprocessor { 7 namespace CHCDemo 8 { 9 8 10 9 11 class Vector3; … … 14 16 { 15 17 public: 16 float x[4][4]; // first index is column [x], the second is row [y]17 18 Matrix4x4() { }19 20 // here xXY - 'X' is row, and 'Y' is column - classical mathematical notation18 /** Default constructor initialising nothig. 19 */ 20 Matrix4x4(); 21 /** here xXY - 'X' is row, and 'Y' is column - classical mathematical notation 22 */ 21 23 Matrix4x4(float x11, float x12, float x13, float x14, 22 float x21, float x22, float x23, float x24, 23 float x31, float x32, float x33, float x34, 24 float x41, float x42, float x43, float x44); 25 24 float x21, float x22, float x23, float x24, 25 float x31, float x32, float x33, float x34, 26 float x41, float x42, float x43, float x44); 27 /** Constructor setting the columns of the 3x3 part of the matrix. 28 */ 26 29 Matrix4x4(const Vector3 &a, const Vector3 &b, const Vector3 &c); 27 30 28 31 29 // Assignment operators 32 //////////////// 33 //-- Assignment operators 34 30 35 Matrix4x4& operator+= (const Matrix4x4 &A); // add-to 31 36 Matrix4x4& operator-= (const Matrix4x4 &A); // subtract-from … … 33 38 Matrix4x4& operator*= (float A); // scale by scalar 34 39 35 // Fundamental operations 36 /// Invert the matrix .. returns 0 = regular 40 41 //////////////// 42 //-- Fundamental operations 43 44 /** Invert the matrix .. returns 0 = regular 45 */ 37 46 int Invert(); 38 /// Transpose the matrix 47 /** Transpose the matrix 48 */ 39 49 void Transpose(); 50 /** Sets the columns of the 3x3 part of the matrix. 51 */ 52 void SetColumns(const Vector3 &a, const Vector3 &b, const Vector3 &c); 40 53 41 void 42 SetColumns(const Vector3 &a, const Vector3 &b, const Vector3 &c); 43 44 float Det3x3() const { 45 return (x[0][0]*x[1][1]*x[2][2] + \ 46 x[1][0]*x[2][1]*x[0][2] + \ 47 x[2][0]*x[0][1]*x[1][2] - \ 48 x[2][0]*x[1][1]*x[0][2] - \ 49 x[0][0]*x[2][1]*x[1][2] - \ 50 x[1][0]*x[0][1]*x[2][2]); 51 } 54 float Det3x3() const; 52 55 53 56 54 friend Matrix4x4 Invert(const Matrix4x4 &M); // Invert a given matrix55 friend Matrix4x4 Transpose(const Matrix4x4 &M); // Transpose a given matrix57 //////////// 58 //-- members 56 59 57 // Create various types of matrix. 60 float x[4][4]; // first index is column [x], the second is row [y] 61 62 63 //////////////////// 64 65 // Invert a given matrix 66 friend Matrix4x4 Invert(const Matrix4x4 &M); 67 // Transpose a given matrix 68 friend Matrix4x4 Transpose(const Matrix4x4 &M); 69 70 71 /////////// 72 //-- Create various types of matrix. 73 58 74 friend Matrix4x4 IdentityMatrix(); 59 75 friend Matrix4x4 ZeroMatrix(); … … 94 110 friend Vector3 GetTranslation(const Matrix4x4 &M); 95 111 96 // Construct rotation description according VRML'97 specification97 // const CVector4D SFRotation(void) const;98 99 100 101 112 // Overloaded output operator. 102 113 friend std::ostream& operator<< (std::ostream &s, const Matrix4x4 &M); 103 114 }; 104 115 105 // forward declaration 116 117 ///////// 118 //-- forward declaration 119 120 106 121 Matrix4x4 IdentityMatrix(); 107 Matrix4x4 Invert(const Matrix4x4 &M); // Invert a given matrix 108 Matrix4x4 Transpose(const Matrix4x4 &M); // Transpose a given matrix 109 110 // Create various types of matrix. 122 Matrix4x4 Invert(const Matrix4x4 &M); 123 Matrix4x4 Transpose(const Matrix4x4 &M); 111 124 Matrix4x4 IdentityMatrix(); 112 125 Matrix4x4 ZeroMatrix(); … … 116 129 Matrix4x4 RotationZMatrix(float Angle); 117 130 Matrix4x4 RotationYPRMatrix(float Yaw, float Pitch, float Roll); 118 // about axis 'axis' by angle 'Angle'119 131 Matrix4x4 RotationAxisMatrix(const Vector3 &axis, float Angle); 120 // create the rotation matrix that rotates 'vecFrom' to 'vecTo'121 132 Matrix4x4 RotationVectorsMatrix(const Vector3 &vecFrom, 122 133 const Vector3 &vecTo); 123 124 134 Matrix4x4 ScaleMatrix(float X, float Y, float Z); 125 135 Matrix4x4 GenRotation(const Vector3 &x, const Vector3 &y, … … 127 137 Matrix4x4 QuadricMatrix(float a, float b, float c, float d, float e, 128 138 float f, float g, float h, float j, float k); 129 // returns matrix for transforming normal130 139 Matrix4x4 NormalTransformMatrix(const Matrix4x4 &M); 131 132 140 Matrix4x4 MirrorX(); 133 141 Matrix4x4 MirrorY(); 134 142 Matrix4x4 MirrorZ(); 135 143 Matrix4x4 RotationOnly(const Matrix4x4 &x); 136 137 // Binary operators138 144 Matrix4x4 operator+ (const Matrix4x4 &A, const Matrix4x4 &B); 139 145 Matrix4x4 operator- (const Matrix4x4 &A, const Matrix4x4 &B); 140 146 Matrix4x4 operator* (const Matrix4x4 &A, float B); 141 147 Matrix4x4 operator* (const Matrix4x4 &A, const Matrix4x4 &B); 142 143 // friends returning Vector3144 148 Vector3 operator*(const Matrix4x4 &M, const Vector3 &v); 145 149 Vector3 RotateOnly(const Matrix4x4 &M, const Vector3 &v); … … 148 152 149 153 150 //} 151 154 } 152 155 153 156 -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
r2746 r2751 1 1 #ifndef RENDERTRAVERSER_H 2 2 #define RENDERTRAVERSER_H 3 4 3 5 4 6 #if TOIMPLEMENT … … 10 12 #include <stack> 11 13 12 14 namespace CHCDemo 15 { 13 16 14 17 typedef stack<HierarchyNode *> TraversalStack; … … 131 134 bool mUseOptimization; 132 135 }; 136 137 } 138 133 139 #endif 140 141 134 142 #endif // RENDERTRAVERSER_H -
GTP/trunk/App/Demos/Vis/CHC_revisited/Timers.cpp
r2642 r2751 107 107 108 108 #else 109 110 if (hasHRTimer == 1) { 111 LARGE_INTEGER counter; 112 QueryPerformanceCounter(&counter); 113 // return in usec 114 return (long) (1000000*counter.QuadPart/(hrFreq.QuadPart)); 115 } else { 116 static struct _timeb mtime; 117 _ftime(&mtime); 118 119 return 1000*(1000*mtime.time + mtime.millitm); 120 } 109 110 if (hasHRTimer == 1) 111 { 112 LARGE_INTEGER counter; 113 QueryPerformanceCounter(&counter); 114 // return in usec 115 return (long) (1000000*counter.QuadPart/(hrFreq.QuadPart)); 116 } else { 117 static struct _timeb mtime; 118 _ftime(&mtime); 119 120 return 1000 * (1000 * mtime.time + mtime.millitm); 121 } 121 122 #endif 122 123 } … … 138 139 time_t t; 139 140 time(&t); 141 140 142 return ctime(&t); 141 143 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Timers.h
r2746 r2751 18 18 19 19 /** Example of usage: 20 see timers.h for diffirent possibilities of what is really measured. .20 see timers.h for diffirent possibilities of what is really measured. 21 21 22 22 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Triangle3.cpp
r2750 r2751 1 1 #include "Triangle3.h" 2 #include "Ray.h"3 #include "SimpleRay.h"4 2 #include "AxisAlignedBox3.h" 5 #include " Containers.h"6 #include "P olygon3.h"3 #include "common.h" 4 #include "Plane3.h" 7 5 8 6 9 7 using namespace std; 10 8 11 namespace GtpVisibilityPreprocessor { 9 10 namespace CHCDemo { 12 11 13 12 … … 25 24 } 26 25 27 28 float Triangle3::GetSpatialAngle(const Vector3 &point) const29 {30 return 0.0f;31 }32 33 34 int35 Triangle3::CastRay(const Ray &ray,36 float &t,37 const float nearestT,38 Vector3 &normal) const39 {40 //////////////41 // specialised triangle ray casting version42 // using ray-plane intersection43 44 // get triangle edge vectors and plane normal45 const Vector3 u = mVertices[0] - mVertices[1];46 const Vector3 v = mVertices[2] - mVertices[1];47 48 // cross product49 normal = Normalize(CrossProd(v, u));50 51 // ray direction vector52 const Vector3 dir = ray.GetDir();53 const Vector3 w0 = ray.GetLoc() - mVertices[1];54 55 // params to calc ray-plane intersect56 const float a = -DotProd(normal, w0);57 const float b = DotProd(normal, dir);58 59 // check for division by zero60 if (fabs(b) < Limits::Small)61 {62 // ray is parallel to triangle plane63 if (a == 0)64 {65 // ray lies in triangle plane66 return Ray::INTERSECTION_OUT_OF_LIMITS;67 }68 else69 {70 // ray disjoint from plane71 return Ray::NO_INTERSECTION;72 }73 }74 75 // distance from origin of ray to plane76 t = a / b;77 78 if (t <= Limits::Small) // ray goes away from triangle79 {80 return Ray::INTERSECTION_OUT_OF_LIMITS;81 }82 // already found nearer intersection83 else if ((ray.GetType() == Ray::LOCAL_RAY) && (t >= nearestT))84 {85 return Ray::NO_INTERSECTION;86 }87 88 /////////////////89 //-- found intersection point90 //-- check if it is inside triangle91 92 const Vector3 pt = ray.GetLoc() + t * dir;93 #if GTP_DEBUG94 if (!pt.CheckValidity())95 {96 cout << "tr: " << *this << endl;97 cout << "v: " << pt << " t: " << t << " a: " << a << " b: " << b << " n: " << normal << endl;98 }99 #endif100 const Vector3 w = pt - mVertices[1];101 102 const float uu = DotProd(u, u);103 const float uv = DotProd(u, v);104 const float vv = DotProd(v, v);105 106 const float wu = DotProd(w, u);107 const float wv = DotProd(w, v);108 109 110 const float D = uv * uv - uu * vv;111 112 // get and test parametric coords113 const float s = (uv * wv - vv * wu) / D;114 115 if ((s < -Limits::Small) || (s > 1.0f + Limits::Small)) // pt is outside triangle116 {117 return Ray::NO_INTERSECTION;118 }119 120 const float s2 = (uv * wu - uu * wv) / D;121 122 if ((s2 < -Limits::Small) || ((s + s2) > 1.0f + Limits::Small)) // pt is outside triangle123 {124 return Ray::NO_INTERSECTION;125 }126 127 return Ray::INTERSECTION; // I is in T128 }129 130 131 int132 Triangle3::CastSimpleRay(const SimpleRay &ray,133 float &t,134 const float nearestT) const135 {136 //////////////137 // specialised triangle ray casting version138 // using ray-plane intersection139 140 // get triangle edge vectors and plane normal141 const Vector3 u = mVertices[0] - mVertices[1];142 const Vector3 v = mVertices[2] - mVertices[1];143 144 // cross product145 const Vector3 normal = Normalize(CrossProd(v, u));146 147 // ray direction vector148 const Vector3 dir = ray.mDirection;149 const Vector3 w0 = ray.mOrigin - mVertices[1];150 151 // params to calc ray-plane intersect152 const float a = -DotProd(normal, w0);153 const float b = DotProd(normal, dir);154 155 // check for division by zero156 if (fabs(b) < Limits::Small)157 {158 // ray is parallel to triangle plane159 if (a == 0)160 {161 // ray lies in triangle plane162 return Ray::INTERSECTION_OUT_OF_LIMITS;163 }164 else {165 // ray disjoint from plane166 return Ray::NO_INTERSECTION;167 }168 }169 170 // distance from origin of ray to plane171 t = a / b;172 173 if (t <= Limits::Small) // ray goes away from triangle174 {175 return Ray::INTERSECTION_OUT_OF_LIMITS;176 }177 178 // already found nearer intersection179 if (t > nearestT + 1e-5)180 {181 return Ray::NO_INTERSECTION;182 }183 184 /////////////////185 //-- found intersection point186 //-- check if it is inside triangle187 188 const Vector3 pt = ray.mOrigin + t * dir;189 #if GTP_DEBUG190 if (!pt.CheckValidity())191 {192 cout << "tr: " << *this << endl;193 cout << "v: " << pt << " t: " << t << " a: " << a << " b: " << b << " n: " << normal << endl;194 }195 #endif196 const Vector3 w = pt - mVertices[1];197 198 const float uu = DotProd(u, u);199 const float uv = DotProd(u, v);200 const float vv = DotProd(v, v);201 202 const float wu = DotProd(w, u);203 const float wv = DotProd(w, v);204 205 206 const float D = uv * uv - uu * vv;207 208 // get and test parametric coords209 const float s = (uv * wv - vv * wu) / D;210 211 if ((s < -Limits::Small) ||212 (s > 1.0f + Limits::Small)) // pt is outside triangle213 {214 return Ray::NO_INTERSECTION;215 }216 217 const float s2 = (uv * wu - uu * wv) / D;218 219 if ((s2 < -Limits::Small) ||220 ((s + s2) > 1.0f + Limits::Small)) // pt is outside triangle221 {222 return Ray::NO_INTERSECTION;223 }224 225 return Ray::INTERSECTION; // I is in T226 }227 228 26 229 27 AxisAlignedBox3 Triangle3::GetBoundingBox() const … … 282 80 // compute distance from plane 283 81 for (int i = 0; i < 3; ++ i) 284 {285 82 side[i] = plane.Side(mVertices[i], Limits::Small); 286 }287 83 288 84 ///// … … 324 120 { 325 121 intersectA = mVertices[i] + t * (mVertices[i_2] - mVertices[i]); 326 327 122 foundA = true; 328 123 } … … 330 125 { 331 126 intersectB = mVertices[i] + t * (mVertices[i_2] - mVertices[i]); 332 333 127 return true; 334 128 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Triangle3.h
r2750 r2751 5 5 6 6 7 namespace GtpVisibilityPreprocessor { 7 namespace CHCDemo 8 { 8 9 9 10 class AxisAlignedBox3; 10 class Ray;11 struct SimpleRay;12 11 class Plane3; 12 13 13 14 14 struct Triangle3 … … 26 26 27 27 float GetArea() const; 28 29 /// returns bounding box around this triangle28 /** returns bounding box around this triangle 29 */ 30 30 AxisAlignedBox3 GetBoundingBox() const; 31 32 /// Casts ray into this triangle. Returns hit33 int CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const;34 35 int CastSimpleRay(const SimpleRay &ray, float &t, const float nearestT) const;36 37 friend std::ostream& operator<< (std::ostream &s, const Triangle3 &A);38 friend std::istream& operator>> (std::istream &s, Triangle3 &A);39 40 31 /** Checks if this triangle is ill-defined. 41 32 */ 42 33 bool CheckValidity() const; 43 44 34 /** Intersects triangle with plane, returns intersection points 45 35 if intersection is happening. … … 50 40 Vector3 &intersectA, 51 41 Vector3 &intersectB) const; 42 43 44 friend std::ostream& operator<< (std::ostream &s, const Triangle3 &A); 45 friend std::istream& operator>> (std::istream &s, Triangle3 &A); 46 52 47 53 48 /////////////////// -
GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.cpp
r2746 r2751 5 5 6 6 7 //namespace CHCDemo8 //{7 namespace CHCDemo 8 { 9 9 10 10 // Given min a vector to minimize and a candidate vector, replace … … 263 263 sinTheta*cos(fi)); 264 264 265 Matrix4x4 m = RotationVectorsMatrix( 266 normal, 267 Vector3(0,1,0)); 265 Matrix4x4 m = RotationVectorsMatrix(normal, Vector3(0,1,0)); 268 266 Matrix4x4 mi = Invert(m); 269 m = m*RotationVectorsMatrix( 270 Vector3(0,1,0), 271 Normalize(dir))*mi; 267 268 m = m*RotationVectorsMatrix(Vector3(0, 1, 0), Normalize(dir)) * mi; 272 269 273 270 return TransformNormal(m, normal); … … 282 279 return !(isnan(x) || isnan(y) || isnan(z)); 283 280 #endif 284 //return ((x != x) || (y != y) || (z != z)); 285 } 286 287 //} 281 } 282 283 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.h
r2746 r2751 11 11 12 12 13 namespace CHCDemo 14 { 13 15 14 16 /** Vector class. … … 358 360 359 361 if (signedAngle < 0) 360 return 2 * PI + signedAngle;362 return 2 * M_PI + signedAngle; 361 363 362 364 return signedAngle; … … 530 532 531 533 532 533 //} 534 } 534 535 535 536 #endif -
GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj
r2746 r2751 46 46 BasicRuntimeChecks="3" 47 47 RuntimeLibrary="3" 48 RuntimeTypeInfo="false" 48 49 UsePrecompiledHeader="0" 49 50 WarningLevel="3" … … 119 120 <Tool 120 121 Name="VCCLCompilerTool" 122 InlineFunctionExpansion="2" 123 EnableIntrinsicFunctions="true" 124 FavorSizeOrSpeed="1" 125 OmitFramePointers="true" 126 EnableFiberSafeOptimizations="true" 121 127 AdditionalIncludeDirectories="GL" 122 128 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" 123 129 RuntimeLibrary="2" 130 RuntimeTypeInfo="false" 124 131 UsePrecompiledHeader="0" 125 132 WarningLevel="3" … … 182 189 > 183 190 <File 184 RelativePath=".\AxisAlignedBox3.cpp" 185 > 186 </File> 187 <File 188 RelativePath=".\common.cpp" 189 > 190 </File> 191 <File 192 RelativePath=".\HierarchyNode.cpp" 193 > 194 </File> 195 <File 196 RelativePath=".\Material.cpp" 197 > 198 </File> 199 <File 200 RelativePath=".\Matrix4x4.cpp" 191 RelativePath=".\Bvh.cpp" 192 > 193 </File> 194 <File 195 RelativePath=".\Geometry.cpp" 201 196 > 202 197 </File> 203 198 <File 204 199 RelativePath=".\occquery.cpp" 205 >206 </File>207 <File208 RelativePath=".\RenderTraverser.cpp"209 >210 </File>211 <File212 RelativePath=".\Timers.cpp"213 200 > 214 201 </File> … … 220 207 > 221 208 <File 209 RelativePath=".\Bvh.h" 210 > 211 </File> 212 <File 213 RelativePath=".\Geometry.h" 214 > 215 </File> 216 <File 217 RelativePath=".\Material.h" 218 > 219 </File> 220 </Filter> 221 <Filter 222 Name="utils" 223 > 224 <File 225 RelativePath=".\AxisAlignedBox3.cpp" 226 > 227 </File> 228 <File 222 229 RelativePath=".\AxisAlignedBox3.h" 223 230 > 224 231 </File> 225 232 <File 226 RelativePath=".\Bvh.cpp" 227 > 228 </File> 229 <File 230 RelativePath=".\Bvh.h" 233 RelativePath=".\common.cpp" 231 234 > 232 235 </File> … … 240 243 </File> 241 244 <File 242 RelativePath=".\Material.h" 245 RelativePath=".\Material.cpp" 246 > 247 </File> 248 <File 249 RelativePath=".\Matrix4x4.cpp" 243 250 > 244 251 </File> … … 248 255 </File> 249 256 <File 257 RelativePath=".\Plane3.cpp" 258 > 259 </File> 260 <File 261 RelativePath=".\Plane3.h" 262 > 263 </File> 264 <File 265 RelativePath=".\Timers.cpp" 266 > 267 </File> 268 <File 269 RelativePath=".\Timers.h" 270 > 271 </File> 272 <File 273 RelativePath=".\Triangle3.cpp" 274 > 275 </File> 276 <File 277 RelativePath=".\Triangle3.h" 278 > 279 </File> 280 <File 281 RelativePath=".\Vector3.cpp" 282 > 283 </File> 284 <File 285 RelativePath=".\Vector3.h" 286 > 287 </File> 288 </Filter> 289 <Filter 290 Name="traversal" 291 > 292 <File 293 RelativePath=".\RenderTraverser.cpp" 294 > 295 </File> 296 <File 250 297 RelativePath=".\RenderTraverser.h" 251 >252 </File>253 <File254 RelativePath=".\Timers.h"255 >256 </File>257 <File258 RelativePath=".\Vector3.cpp"259 >260 </File>261 <File262 RelativePath=".\Vector3.h"263 298 > 264 299 </File> -
GTP/trunk/App/Demos/Vis/CHC_revisited/common.cpp
r2746 r2751 25 25 using namespace std; 26 26 27 //namespace CHCDemo { 27 28 namespace CHCDemo 29 { 28 30 29 31 … … 337 339 #endif 338 340 339 //}341 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/common.h
r2746 r2751 1 /** 2 3 This file contains various macros, templates and constants for the ERS system. 4 5 @author Jiri Bittner 1 /** This file contains various macros, templates and constants for the ERS system. 2 @author Jiri Bittner 6 3 */ 7 4 … … 19 16 20 17 21 //namespace GtpVisibilityPreprocessor { 22 18 namespace CHCDemo 19 { 20 21 struct Triangle3; 23 22 24 23 #if defined(_MSC_VER) … … 54 53 #include <values.h> 55 54 #else // __WATCOMC__ 56 #define M_PI 3.14159265358979323846 55 #define M_PI 3.14159265358979323846F 57 56 #define MAXFLOAT 3.40282347e+37F 58 57 #endif // __WATCOMC__ … … 119 118 #endif // NULL 120 119 121 //ostream& operator<<(ostream &s,const BaseC &c);122 123 120 typedef float Real; 124 121 typedef unsigned char byte; 125 122 126 //#ifndef FALSE127 //#define FALSE 0128 //#define TRUE !0129 //#endif130 131 #ifndef __GNUG__132 // typedef int bool;133 #endif134 123 135 124 #ifndef getch … … 137 126 #endif 138 127 139 140 128 #define TRASH 1.0e-5 141 129 142 #ifndef PI 143 #define PI 3.14159265358979323846f 144 #endif 145 146 #define MIN_FLOAT -1e30f 147 #define MAX_FLOAT 1e30f 148 149 150 // tolerance value for polygon area 151 #define AREA_LIMIT 0.0001f 152 130 // delete a pointer and set to NULL 153 131 #ifndef DEL_PTR 154 132 #define DEL_PTR(ptr) do {if (ptr) { \ … … 157 135 while (0) 158 136 #endif 137 138 159 139 // Clears a container (i.e., a vector of pointers) and deletes the pointers 160 #if 0161 140 #ifndef CLEAR_CONTAINER 162 #define CLEAR_CONTAINER(co) do { while (!(co).empty()) { \ 163 DEL_PTR((co).back()); \ 164 (co).pop_back();}} \ 165 while (0) 166 #endif 167 168 #else 169 170 #ifndef CLEAR_CONTAINER 171 #define CLEAR_CONTAINER(co) do { for (int _i = 0; _i < (int)(co).size(); ++ _i) { \ 141 #define CLEAR_CONTAINER(co) do { for (size_t _i = 0; _i < (int)(co).size(); ++ _i) { \ 172 142 DEL_PTR((co)[_i]);} \ 173 143 (co).clear(); } \ … … 175 145 #endif 176 146 177 #endif 178 179 180 inline 181 int signum(const Real a, const Real thresh = TRASH) 147 148 inline int signum(const Real a, const Real thresh = TRASH) 182 149 { 183 150 if (a>thresh) … … 320 287 inline Real Deg2Rad(const Real a) 321 288 { 322 return a * ( PI / 180.0f);289 return a * (M_PI / 180.0f); 323 290 } 324 291 325 292 inline Real Rad2Deg(const Real a) { 326 return a *(180.0f/PI);293 return a * (180.0f/M_PI); 327 294 } 328 295 … … 335 302 336 303 337 // ------------------------------------------------------------------- 338 // Limits. 339 // This class encapsulates all the concessions to Realing-point 340 // error made by ray tracers. 341 // ------------------------------------------------------------------- 342 343 class Limits { 304 /** Limits. 305 This class encapsulates all the concessions to Realing-point 306 error made by ray tracers. 307 */ 308 class Limits 309 { 344 310 public: 345 346 347 348 349 350 351 352 353 354 355 356 357 358 311 // This is the number used to reject too-close intersections. 312 // The default value is 1.0. 313 static Real Threshold; 314 315 // This is a "small" number. Less than this number is assumed to 316 // be 0, when such things matter. 317 // The default value is 0.1. 318 static Real Small; 319 320 // This is an impractically "large" number, used for intersection 321 // parameters out to infinity (e.g. the span resulting from an 322 // FindAllIntersections operation on a plane). 323 // The default value is 100000. 324 static Real Infinity; 359 325 }; 360 326 … … 488 454 489 455 490 //} 491 492 #endif 493 494 495 496 497 498 499 500 456 typedef std::vector<Triangle3> TriangleContainer; 457 458 } 459 460 #endif 461 462 463 464 465 466 467 468
Note: See TracChangeset
for help on using the changeset viewer.