Surface.h

Go to the documentation of this file.
00001 /* $Id: Surface.h,v 1.4 2002/11/05 14:31:15 anonymous Exp $ */
00002 
00003 #ifndef __SURFACE_H
00004 #define __SURFACE_H
00005 
00006 #include <esg/geometry/Geometry.h>
00007 #include <esg/spacesorting/SDS.h>
00008 #include <esg/iterator/IteratorSDS.h>
00009 #include <esg/Intersector.h>
00010 #include <esg/AutoPtr.h>
00011 #include <esg/AutoArray.h>
00012 #include <esg/mesh/Mesh.h>
00013 #include <esg/geometry/_Surface.h>
00014 
00015 namespace esg {
00016 
00050 class OGSCENE_EXPORT Surface : public Geometry {
00051     friend class NurbsSurface;
00052     
00053 public:
00054     enum VertOrder {
00055         TRIANGLES,
00056         TRIANGLE_STRIP,
00057         TRIANGLE_FAN,
00058         QUADS,
00059         QUAD_STRIP
00060     };
00061 
00062 protected:
00063     AutoArray<Vertex3> *   _pAutoVertices; // array of vertices
00064     AutoArray<Vector3> *   _pAutoNormals;  // array of vertex normals
00065     AutoArray<Vector2> *   _pAutoUVCoords; // array of vertex normals
00066     unsigned               _nVert;         // number of vertices
00067     unsigned               _nNorm;         // number of normals
00068     unsigned               _nUVCoords;     // number of normals
00069     SDS *                  _pRepository;   // space sub-division structure
00070     bool                   _created;       // is the whole structure finished?
00071     VertOrder              _vertOrder;     // how to interpret vertices
00072     IteratorSDS *          _pIterator;     // used for repository inspection
00073     AutoPtr<Intersector> * _pAutoInter;
00074     bool                   _fastMesh;
00075     unsigned               _nSurfaces;
00076 
00077     // abbreviations for auto pointers
00078     Vertex3 *      _vertices;   // array of vertices
00079     Vector3 *      _normals;    // array of vertex normals
00080     Vector2 *      _uvCoords;    // array of vertex normals
00081     Intersector *  _pIntersector;
00082 
00083     // attributes used only during creation
00084     Vector3   _auxPlaneNormal;   // normal verctor of next plane
00085     bool      _havePlaneNormal;  // its validity
00086     unsigned  _primVertIndices [4];  // array of indices
00087     unsigned  _primNormIndices [4];
00088     unsigned  _primUVIndices   [4];
00089     unsigned  _primVertices;     // number of primitives' corners (3 or 4)
00090     unsigned  _primActVert;      // actually processing corner
00091 
00092     // attributes used during inspection
00093     unsigned _vertIndex;
00094 
00095     // Speed up of ray intersection tests. When new ray originates at the point
00096     // of previous intersection then the test can be improved. The HitPoint
00097     // is just the structure remembering the sucessufull intersection
00098     // of previous pass.
00099     struct HitPoint {
00100         Vector3     point;
00101         const void* pSDSLeaf;
00102         HitPoint () : pSDSLeaf(NULL) {}
00103     } * _pPreviousHit;
00104     
00105 
00106 protected:
00107             bool  _check_vertex (void);
00108     virtual Mesh* _mesh         (int /* not used */) const;
00109     virtual void  _duplicate_attributes (const Geometry&);
00110     virtual void  _rotateX      (float /* angle */);
00111     virtual void  _rotateY      (float /* angle */);
00112     virtual void  _rotateZ      (float /* angle */);
00113     virtual void  _rotate       (float /* angle */, const Vector3& /* axis */);
00114     virtual void  _rotate       (const Matrix3&);
00115     virtual void  _translate    (float /* x */, float /* y */, float /* z */);
00116     virtual void  _transform    (const Matrix4&);
00117     virtual void  _scale        (float);
00118     Surface () {}
00119     
00120 public:
00121 
00136         Surface (const SDS&             ss,
00137                  AutoArray<Vertex3> *   va,
00138                  unsigned               nv,
00139                  AutoArray<Vector3> *   na,
00140                  unsigned               nn,
00141                  AutoArray<Vector2> *   uva,
00142                  unsigned               uvn,
00143                  enum VertOrder         vo,
00144                  AutoPtr<Intersector> * it,
00145                  bool                   fm);
00146 
00150         virtual ~Surface ();
00151 
00152         /********************************************************************/
00153         /* "local" methods of the Surface                                   */
00154         /********************************************************************/
00155 
00161         void normal (const Vector3& v);
00162 
00169         bool vertex (unsigned index);
00170 
00178         bool vertex (unsigned vindex, unsigned nindex);
00179 
00188         bool vertex (unsigned vindex, unsigned nindex, unsigned uvindex);
00189 
00197         bool vertexUV (unsigned vindex, unsigned uvindex);
00198 
00205         bool done (void);
00206 
00212         const _Surface* firstPlane (void);
00213 
00219         const _Surface* nextPlane  (void);
00220 
00226         inline unsigned numPlanes (void) const { return _nSurfaces; }
00227 
00234         inline bool firstVertex (void) {
00235             _vertIndex = 0;
00236             return ((_nVert) ? true : false);
00237         }
00238 
00245         inline bool nextVertex (void) {
00246             return ((++_vertIndex < _nVert) ? true : false);
00247         }
00248 
00254         inline Vertex3  actVertex (void) const {
00255             return _vertices[_vertIndex];
00256         }
00257 
00263         inline unsigned numVertices (void) const { return _nVert; }
00264 
00269         unsigned numEdges (void) const;
00270 
00271 
00272         /********************************************************************/
00273         /* methods of Geometry                                              */
00274         /********************************************************************/
00275 
00276         virtual void rayIntersection (PointEnv*      pPE,
00277                                       int            mask,
00278                                       const Vector3& origin,
00279                                       const Vector3& direction,
00280                                       float          maxD = MAXFLOAT);
00281 
00282         virtual bool mapToUV (const Vector3& v, Vector2& uv);
00283         
00284         virtual void randomSample (int mask, PointEnv& pe, double* pdf);
00285 
00286         virtual bool randomDirection (const Vector3& pov,
00287                                       Vector3&       dir,
00288                                       double*        pdf);
00289 
00290         virtual Interval extent (const Vector3& direction) const;
00291 
00292         virtual Vector3 centroid (void) const;
00293 
00294         virtual double radius (void) const { return radius(centroid()); }
00295 
00296         virtual double radius (const Vector3& centroid) const;
00297 
00298         virtual Geometry* clone (const Matrix4* pTrMat) const;
00299 
00300         virtual bool separation (Geometry& geom, Vector3*  pDir) {
00301             return false; // TO DO
00302         }
00303 
00304         virtual double distance (const Geometry& geom, Vector3* pDir) {
00305             return DBL_MIN; // TO DO
00306         }
00307 
00308         virtual void dump (const char* intent, const char* tab);
00309 
00310 
00311 
00315         virtual void __debug() {
00316             fprintf(stderr,"Surface:\n");
00317             if (_pRepository) _pRepository->__debug();
00318         }
00319 
00323         SDS* __get_repository() { return _pRepository; }
00324 };
00325 
00326 /*
00327  * speed up of ray intersection test when new ray originates at the point
00328  * of previous intersection
00329  */
00330 
00331 }; // namespace
00332 
00333 #endif // __SURFACE_H

Generated on Wed Jun 28 12:24:28 2006 for esg by  doxygen 1.4.6