[Brlcad-commits] CVS: rt^3/include/Geometry Geometry.h,NONE,1.1 Makefile.am,NONE,1.1 Primitive.h,NONE,1.1 Scene.h,NONE,1.1 SceneFactory.h,NONE,1.1 Triangle.h,NONE,1.1 View.h,NONE,1.1 From: Sean Morrison - 2004-11-22 06:37:25 ```Update of /cvsroot/brlcad/rt^3/include/Geometry In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24414/include/Geometry Added Files: Geometry.h Makefile.am Primitive.h Scene.h SceneFactory.h Triangle.h View.h Log Message: initial import --- NEW FILE: Geometry.h --- #ifndef __GEOMETRY_H__ #define __GEOMETRY_H__ namespace Geometry { int init(); } #include "Geometry/Triangle.h" #include "Geometry/SceneFactory.h" #include "Geometry/Scene.h" #include "Geometry/Primitive.h" #endif /* __GEOMETRY_H__ */ // Local Variables: *** // mode: C++ *** // tab-width: 8 *** // c-basic-offset: 2 *** // indent-tabs-mode: t *** // End: *** // ex: shiftwidth=2 tabstop=8 --- NEW FILE: Makefile.am --- noinst_HEADERS = \ Geometry.h \ SceneFactory.h \ Triangle.h \ View.h CLOBBER_FILES = \ Makefile.in --- NEW FILE: Primitive.h --- #ifndef __PRIMITIVE_H__ #define __PRIMITIVE_H__ #include namespace Geometry { class Primitive { private: protected: /* Primitive() {}; virtual ~Primitive() = 0; */ public: virtual bool intersect(double position[3], double direction[3], double *t, double *u, double *v) = 0; }; } #endif /* __PRIMITIVE_H__ */ // Local Variables: *** // mode: C++ *** // tab-width: 8 *** // c-basic-offset: 2 *** // indent-tabs-mode: t *** // End: *** // ex: shiftwidth=2 tabstop=8 --- NEW FILE: Scene.h --- #ifndef __SCENE_H__ #define __SCENE_H__ #include #include #include "Geometry/Triangle.h" #include "Geometry/View.h" namespace Geometry { class Scene { private: protected: std::vector _geometry; std::vector _views; public: Scene(); ~Scene(); void add(Scene& scene); void add(std::vector geometry); void add(std::vector views); std::vector getGeometry() const; std::vector getViews() const; }; } #endif /* __SCENE_H__ */ // Local Variables: *** // mode: C++ *** // tab-width: 8 *** // c-basic-offset: 2 *** // indent-tabs-mode: t *** // End: *** // ex: shiftwidth=2 tabstop=8 --- NEW FILE: SceneFactory.h --- #ifndef __SCENEFACTORY_H__ #define __SCENEFACTORY_H__ // system headers #include #include // interface headers #include "Scene.h" namespace Geometry { class SceneFactory { private: Scene *_scene; static bool noCaseCompare(char c1, char c2) { return toupper(c1) == toupper(c2); } protected: std::vector _filesLoaded; public: SceneFactory(std::string filename = ""); ~SceneFactory(); bool loadFromFile(std::string filename); Scene* getScene() { return _scene; } }; } #endif /* __SCENEFACTORY_H__ */ // Local Variables: *** // mode: C++ *** // tab-width: 8 *** // c-basic-offset: 2 *** // indent-tabs-mode: t *** // End: *** // ex: shiftwidth=2 tabstop=8 --- NEW FILE: Triangle.h --- #ifndef __TRIANGLE_H__ #define __TRIANGLE_H__ // system headers #include // interface headers #include "Geometry/Primitive.h" #define EPSILON 0.000001 #define CROSS(dest,v1,v2) \ dest[0]=v1[1]*v2[2]-v1[2]*v2[1]; \ dest[1]=v1[2]*v2[0]-v1[0]*v2[2]; \ dest[2]=v1[0]*v2[1]-v1[1]*v2[0]; #define DOT(v1,v2) (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2]) #define SUB(dest,v1,v2) \ dest[0]=v1[0]-v2[0]; \ dest[1]=v1[1]-v2[1]; \ dest[2]=v1[2]-v2[2]; namespace Geometry { // 128 bytes typedef struct _triangle { double vertexA[3]; double vertexB[3]; double vertexC[3]; double normal[3]; unsigned long int padding[8]; } Triangle; // 64 bytes typedef struct _robustTriangle { double position[3]; double normal[3]; unsigned long int vertex[3]; // vertex index lookup unsigned long int padding; } RobustTriangle; // 32 bytes typedef struct _traditionalTriangle { float position[3]; float normal[3]; unsigned short int vertex[3]; // vertex index lookup unsigned short int padding; } TraditionalTriangle; // 16 bytes typedef struct _compactTriangle { float dotProduct; // precomputed dot (position*normal) signed short int normal[3]; unsigned short int vertex[3]; } CompactTriangle; inline bool intersectTriangle(Triangle &triangle, double orig[3], double dir[3], double *t, double *u, double *v) { double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3]; double det,inv_det; /* find vectors for two edges sharing vert0 */ SUB(edge1, triangle.vertexB, triangle.vertexA); SUB(edge2, triangle.vertexC, triangle.vertexA); /* begin calculating determinant - also used to calculate U parameter */ CROSS(pvec, dir, edge2); /* if determinant is near zero, ray lies in plane of triangle */ det = DOT(edge1, pvec); if (det > -EPSILON && det < EPSILON) return 0; inv_det = 1.0 / det; /* calculate distance from vert0 to ray origin */ SUB(tvec, orig, triangle.vertexA); /* calculate U parameter and test bounds */ *u = DOT(tvec, pvec) * inv_det; if (*u < 0.0 || *u > 1.0) return 0; /* prepare to test V parameter */ CROSS(qvec, tvec, edge1); /* calculate V parameter and test bounds */ *v = DOT(dir, qvec) * inv_det; if (*v < 0.0 || *u + *v > 1.0) return 0; /* calculate t, ray intersects triangle */ *t = DOT(edge2, qvec) * inv_det; return 1; } } #endif /* __TRIANGLE_H__ */ // Local Variables: *** // mode: C++ *** // tab-width: 8 *** // c-basic-offset: 2 *** // indent-tabs-mode: t *** // End: *** // ex: shiftwidth=2 tabstop=8 --- NEW FILE: View.h --- #ifndef __VIEW_H__ #define __VIEW_H__ #include #include #include "Geometry/Triangle.h" #include "Geometry/View.h" namespace Geometry { class View { private: double _from[3]; double _at[3]; double _up[3]; double _angle; double _hither; double _x; double _y; protected: public: View(double from[3], double at[3], double up[3], double angle, double hither); ~View(); void setResolution(unsigned long int x, unsigned long int y) { _x = x; _y = y; } }; } #endif /* __VIEW_H__ */ // Local Variables: *** // mode: C++ *** // tab-width: 8 *** // c-basic-offset: 2 *** // indent-tabs-mode: t *** // End: *** // ex: shiftwidth=2 tabstop=8 ```