00001
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;
00064 AutoArray<Vector3> * _pAutoNormals;
00065 AutoArray<Vector2> * _pAutoUVCoords;
00066 unsigned _nVert;
00067 unsigned _nNorm;
00068 unsigned _nUVCoords;
00069 SDS * _pRepository;
00070 bool _created;
00071 VertOrder _vertOrder;
00072 IteratorSDS * _pIterator;
00073 AutoPtr<Intersector> * _pAutoInter;
00074 bool _fastMesh;
00075 unsigned _nSurfaces;
00076
00077
00078 Vertex3 * _vertices;
00079 Vector3 * _normals;
00080 Vector2 * _uvCoords;
00081 Intersector * _pIntersector;
00082
00083
00084 Vector3 _auxPlaneNormal;
00085 bool _havePlaneNormal;
00086 unsigned _primVertIndices [4];
00087 unsigned _primNormIndices [4];
00088 unsigned _primUVIndices [4];
00089 unsigned _primVertices;
00090 unsigned _primActVert;
00091
00092
00093 unsigned _vertIndex;
00094
00095
00096
00097
00098
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 ) const;
00109 virtual void _duplicate_attributes (const Geometry&);
00110 virtual void _rotateX (float );
00111 virtual void _rotateY (float );
00112 virtual void _rotateZ (float );
00113 virtual void _rotate (float , const Vector3& );
00114 virtual void _rotate (const Matrix3&);
00115 virtual void _translate (float , float , float );
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
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
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;
00302 }
00303
00304 virtual double distance (const Geometry& geom, Vector3* pDir) {
00305 return DBL_MIN;
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
00328
00329
00330
00331 };
00332
00333 #endif // __SURFACE_H