FDH.h

Go to the documentation of this file.
00001 /* $Id: FDH.h,v 1.4 2002/11/05 14:31:15 anonymous Exp $ */
00002 
00003 #ifndef __FDH_H
00004 #define __FDH_H
00005 
00006 #include <esg/Definitions.h>
00007 #include <esg/SceneGraphObject.h>
00008 #include <esg/List.h>
00009 #include <esg/geometry/Geometry.h>
00010 
00011 namespace esg {
00012 
00018 class OGSCENE_EXPORT FDH : public Geometry {
00019 public:
00020         static const unsigned DIRS;        
00021         static const unsigned SIZE;        
00022         static const float    FDHMat[][3]; 
00023 
00033         struct FDHCache : public Cache {
00034                 float * dval;
00035                 float * oval;
00036         
00037                 FDHCache(unsigned dirs) {
00038                     dval = new float[dirs];
00039                     oval = new float[dirs];
00040                 }
00041         
00042                 FDHCache(const float (*mat)[3], unsigned dirs,
00043                          const Vector3& o, const Vector3& d) {
00044                     dval = new float [dirs];
00045                     oval = new float [dirs];
00046                     for (register unsigned i = 0; i < dirs; i++) {
00047                         dval[i]=mat[i][0]*d.x + mat[i][1]*d.y + mat[i][2]*d.z;
00048                         oval[i]=mat[i][0]*o.x + mat[i][1]*o.y + mat[i][2]*o.z;
00049                     }
00050                 }
00051         
00052                 virtual ~FDHCache () { delete [] oval; delete [] dval; }
00053         };
00054     
00055 protected:
00056         float*         _values;    
00057         const unsigned _dirs;      
00058         const float    (*_mat)[3]; 
00059 
00060 protected:
00061         int _cut_line (Vector3d&,  // Point of line
00062                        Vector3d&   // Line's direction, second point in output
00063                        ) const; 
00064     
00065         virtual Vector3d* _get_corners(unsigned&  numCorners,
00066                                        unsigned (*facetVert)[100],
00067                                        unsigned   nFacetCert[]) const;
00068         virtual Mesh*     _mesh(int /* not used */) const;
00069         virtual void      _duplicate_attributes (const Geometry&);
00070 
00071         // Geometric transformations
00072         // ATTENTION: There is not real rotation but FDH recreated from
00073         //            rotated FDH
00074         virtual void _rotateX   (float /* angle */);
00075         virtual void _rotateY   (float /* angle */);
00076         virtual void _rotateZ   (float /* angle */);
00077         virtual void _rotate    (float /* angle */, const Vector3& /* axis */);
00078         virtual void _rotate    (const Matrix3&);
00079         virtual void _translate (float /* x */, float /* y */, float /* z */);
00080         virtual void _transform (const Matrix4&);
00081         virtual void _scale     (float);
00082         
00083         FDH (unsigned d, const float(*m)[3]) : _dirs(d), _mat(m) {}
00084     
00085 public:
00093         FDH (unsigned          dirs,
00094              const float     (*mat)[3],
00095              SceneGraphObject& object);
00096 
00104         FDH (unsigned                dirs,
00105              const float           (*mat)[3],
00106              List<SceneGraphObject>& list);
00107 
00116         FDH (unsigned          dirs,
00117              const float     (*mat)[3],
00118              const Geometry&   geom1,
00119              const Geometry&   geom2);
00120 
00128         FDH (unsigned          dirs,
00129              const float     (*mat)[3],
00130              const Geometry&   geom);
00131 
00139         FDH (unsigned      dirs,
00140              const float (*mat)[3],
00141              const float   values[]);
00142 
00146         virtual ~FDH ();
00147 
00148         virtual void rayIntersection (PointEnv*      pPE,
00149                                       int            mask,
00150                                       const Vector3& origin,
00151                                       const Vector3& direction,
00152                                       float          maxD = MAXFLOAT);
00153 
00154         virtual bool mapToUV (const Vector3& v, Vector2& uv);
00155 
00156         virtual void randomSample (int mask, PointEnv& pe, double* pdf);
00157 
00158         virtual bool randomDirection (const Vector3& pov,
00159                                       Vector3&       dir,
00160                                       double*        pdf);
00161 
00162         virtual Interval extent (const Vector3& direction) const;
00163 
00164         virtual Vector3 centroid (void) const;
00165 
00166         virtual double radius (const Vector3& centroid) const;
00167 
00168         virtual Geometry* clone (const Matrix4* pTrMat) const;
00169 
00170         virtual bool separation (Geometry& geom, Vector3*  pDir);
00171 
00172         virtual double distance (const Geometry& geom, Vector3* pDir);
00173 
00174         virtual void dump (const char* intent, const char* tab);
00175 
00176 
00183         virtual bool checkVolume (void) const;
00184 
00188         virtual void __debug() {
00189             fprintf(stderr,"FDH Values:\n");
00190             for(unsigned i=0;i<_dirs;i++) fprintf(stderr,"%f ",_values[i]);
00191             fprintf(stderr," - ");
00192             for(unsigned i=0;i<_dirs;i++) fprintf(stderr,"%f ",-_values[i+_dirs]);
00193             fprintf(stderr,"\n");
00194         }
00195     
00196 };
00197 
00198 
00199     
00200     /**************************************************************
00201      * Macros for Liang-Barsky line clipping algorithm            *
00202      *                                                            *
00203      * t1 = -(N * P_0 + D_1) / (N * P_1)                          *
00204      * t2 = -(N * P_0 + D_2) / (N * P_1)                          *
00205      * where N is normal vector of half-space (FDH direction)     *
00206      *       P_0 is origin of ray                                 *
00207      *       P_1 is direction of ray                              *
00208      *       D_1, D_2 are plane distances (FDH values)            *
00209      **************************************************************/
00210 
00227 #ifndef FDH_CLIP_LINE_INIT
00228 #define FDH_CLIP_LINE_INIT(o, d, i1, i2) { \
00229    if (d != 0.0) { \
00230       if (d > 0.0) { \
00231           t_out = (_values[i1] - o) /  d; \
00232           if (t_out < Geometry::EPS) return; \
00233           t_in  = (_values[i2] + o) / -d; \
00234           if (t_in > maxDist)       return; \
00235       } else { \
00236           t_in  = (_values[i1] - o) /  d; \
00237           if (t_in > maxDist)       return; \
00238           t_out = (_values[i2] + o) / -d; \
00239           if (t_out < Geometry::EPS) return; \
00240       } \
00241   } else { \
00242       if ((o < -_values[i2]) || (o > _values[i1])) return; \
00243       t_in  =  -MAXFLOAT+1; \
00244       t_out =   MAXFLOAT; \
00245   } \
00246 }
00247 #endif
00248 
00265 #ifndef FDH_CLIP_LINE_CONT
00266 #define FDH_CLIP_LINE_CONT(o, d, i1, i2) { \
00267    if (d != 0.0) { \
00268       if (d > 0.0) { \
00269           t1 = (_values[i2] + o) / -d; \
00270           if (t1 > maxDist) return; \
00271           t2 = (_values[i1] - o) /  d;  \
00272       } else { \
00273           t1 = (_values[i1] - o) /  d; \
00274           if (t1 > maxDist) return; \
00275           t2 = (_values[i2] + o) / -d; \
00276       } \
00277       if (t2 < t_out) { /* optimized order of tests taken from POV-ray */ \
00278           if (t2 < Geometry::EPS) return; \
00279           if (t1 > t_in) { if (t1 > t2) return; t_in = t1; } \
00280           else if (t_in > t2) return; \
00281           t_out = t2; \
00282       } else if (t1 > t_in) { if (t1 > t_out) return; t_in = t1; } \
00283   } else  \
00284       if ((o < -_values[i2]) || (o > _values[i1])) return; \
00285 }
00286 #endif
00287 
00305 #ifndef FDH_CLIP_LINE_INDEX_INIT
00306 #define FDH_CLIP_LINE_INDEX_INIT(o, d, i1, i2) { \
00307    if (d != 0.0) { \
00308       if (d > 0.0) { \
00309           t_out = (_values[i1] - o) /  d; \
00310           if (t_out < Geometry::EPS) return; \
00311           t_in  = (_values[i2] + o) / -d; \
00312           if (t_in > maxDist)       return; \
00313           plane1 = i2; plane2 = i1; \
00314       } else { \
00315           t_in  = (_values[i1] - o) /  d; \
00316           if (t_in > maxDist)       return; \
00317           t_out = (_values[i2] + o) / -d; \
00318           if (t_out < Geometry::EPS) return; \
00319           plane1 = i1; plane2 = i2; \
00320       } \
00321   } else { \
00322       if ((o < -_values[i2]) || (o > _values[i1])) return; \
00323       t_in  = -MAXFLOAT+1; \
00324       t_out =  MAXFLOAT; \
00325   } \
00326 }
00327 #endif
00328 
00346 #ifndef FDH_CLIP_LINE_INDEX_CONT
00347 #define FDH_CLIP_LINE_INDEX_CONT(o, d, i1, i2) { \
00348    register int a1, a2; \
00349    if (d != 0.0) { \
00350       if (d > 0.0) { \
00351           t1 = (_values[i2] + o) / -d; \
00352           if (t1 > maxDist) return; \
00353           t2 = (_values[i1] - o) /  d; \
00354           a1 = i2; a2 = i1; \
00355       } else { \
00356           t1 = (_values[i1] - o) /  d; \
00357           if (t1 > maxDist) return; \
00358           t2 = (_values[i2] + o) / -d; \
00359           a1 = i1; a2 = i2; \
00360       } \
00361       if (t2 < t_out) { /* optimized order of tests taken from POV-ray */ \
00362           if (t2 < Geometry::EPS) return; \
00363           if (t1 > t_in) { if (t1 > t2) return; t_in = t1; } \
00364           else if (t_in > t2) return; \
00365           t_out = t2; plane2 = a2; \
00366       } else \
00367           if (t1 > t_in) { if (t1 > t_out) return; t_in = t1; plane1 = a1; }\
00368   } else  \
00369       if ((o < -_values[i2]) || (o > _values[i1])) return; \
00370 }
00371 #endif
00372 
00373 
00374 }; // namespace
00375 
00376 #endif // __FDH_H

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