Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ray.H

Go to the documentation of this file.
00001 #ifndef RAYH
00002 #define RAYH
00003 
00004 #include "std/support.H"
00005 #include "mlib/points.H"
00006 #include "disp/gel.H"
00007 
00008 class APPEAR;
00009 #define CRAYhit const RAYhit
00010 class RAYhit {
00011   protected:
00012    int       _s;
00013    mlib::Wpt       _p;
00014    mlib::Wvec      _v;
00015    int       _is_surf;
00016    double    _d;
00017    double    _d_2d;
00018    mlib::Wpt       _nearpt;
00019    GELptr    _g;
00020    mlib::Wvec      _n;
00021    mlib::Wpt       _surfl;
00022    int       _uv_valid;
00023    int       _visibility;
00024    mlib::XYpt      _uv;
00025    APPEAR   *_appear;
00026    int       _tolerance;
00027    int       _from_camera;
00028 
00029   public:
00030    RAYhit(mlib::CWpt  &p, mlib::CWvec &v):_s(false), _p(p), _v(v.normalized()),
00031                               _is_surf(0),
00032                               _d(-1),_d_2d(-1), _uv_valid(0), _visibility(1),
00033                               _appear(0), _tolerance(12),_from_camera(0) {}
00034    RAYhit(mlib::CWpt  &a, mlib::CWpt  &b):_s(false), _p(a), _v((b-a).normalized()),
00035                               _is_surf(0),
00036                               _d(-1),_d_2d(-1), _uv_valid(0), _visibility(1),
00037                               _appear(0), _tolerance(12),_from_camera(0) {}
00038    RAYhit(mlib::CXYpt &p);
00039    virtual ~RAYhit() {}
00040 
00041    RAYhit    copy        () const         { return RAYhit(point(),vec()); }
00042    int       success     () const         { return _s; }
00043    mlib::Wpt       point       () const         { return _p; }
00044    mlib::Wvec      vec         () const         { return _v; }
00045    mlib::Wline     line        () const         { return mlib::Wline(_p, _v); }
00046    mlib::XYpt      screen_point() const;
00047    int       from_camera () const         { return _from_camera; }
00048    RAYhit    invert      (mlib::CWpt &) const;
00049 
00050    // These make sense iff _s is true
00051    double    dist        () const         { return _d; }
00052    mlib::Wplane    plane       () const         { return mlib::Wplane(surf(), norm()); }
00053    mlib::Wpt       surf        () const         { return _is_surf ? _p + _d*_v : _nearpt; } 
00054    mlib::Wpt       surfl       () const         { return _surfl; } 
00055    mlib::Wvec      norm        () const         { return _n; }
00056    CGELptr  &geom        () const         { return _g; }
00057    mlib::CXYpt    &uv          () const         { return _uv;}
00058    APPEAR   *appear      () const         { return _appear; }
00059    int       get_vis     () const         { return _visibility; }
00060    int       get_tol     () const         { return _tolerance; }
00061 
00062    void      set_vis     (int  vis)       { _visibility = vis; }
00063    void      set_tol     (int  pixels)    { _tolerance = pixels; }
00064    void      set_norm    (mlib::CWvec    &n)    { _n = n; }
00065    void      set_geom    (CGELptr  &g)    { _g = g;}
00066    void      set_uv      (mlib::CXYpt    &uv)   { _uv = uv;}
00067 
00068    static  STAT_STR_RET static_name()      { RET_STAT_STR("RAYhit"); }
00069    virtual STAT_STR_RET class_name () const{ return static_name(); }
00070    virtual int          is_of_type(Cstr_ptr &t)const { return IS(t); }
00071    static  int          isa       (CRAYhit &r)       { return ISA((&r)); }
00072 
00073    void      clear       (void);
00074    int       test        (double, int, double);
00075    virtual void check    (double, int, double, CGELptr &, mlib::CWvec &,
00076                           mlib::CWpt &, mlib::CWpt &, APPEAR *a, mlib::CXYpt &);
00077 };
00078 
00079 #define CRAYnear const RAYnear
00080 class RAYnear {
00081   protected:
00082    int     _s;
00083    mlib::Wpt     _p;
00084    mlib::Wvec    _v;
00085    double  _d;
00086    double  _d_for_geom;
00087    GELptr  _g;
00088 
00089   public:
00090    RAYnear(mlib::CWpt &p, mlib::CWvec &v):_s(false), _p(p), _v(v.normalized()),
00091                                      _d_for_geom(-1) {}
00092    RAYnear(mlib::CWpt &a, mlib::CWpt &b):_s(false), _p(a), _v((b-a).normalized()),
00093                                      _d_for_geom(-1) {}
00094    RAYnear(mlib::CXYpt    &p);
00095 
00096    int     success     () const                  { return _s; }
00097    mlib::Wpt     point       () const                  { return _p; }
00098    mlib::Wvec    vec         () const                  { return _v; }
00099    double  dist        () const                  { return _d; }
00100    CGELptr&geom        () const                  { return _g; }
00101 
00102    void    set_geom    (CGELptr &g)              { _g = g; }
00103 
00104    void    clear       (void);
00105    void    check       (double d, CGELptr &g);
00106    void    check_geom  (double d, CGELptr &g);
00107 };
00108 
00109 inline int operator == (CRAYhit  &r, int b)  { return r.success() == b; }
00110 inline int operator == (CRAYnear &r, int b)  { return r.success() == b; }
00111 
00112 template <class T>
00113 inline T* 
00114 ray_geom(CRAYhit& ray, T* init) 
00115 {
00116    return T::upcast(ray.geom());
00117 }
00118 
00119 template <class T>
00120 inline T* 
00121 ray_geom(CRAYnear& ray, T* init) 
00122 {
00123    return T::upcast(ray.geom());
00124 }
00125 
00126 /*****************************************************************
00127  * GEL_list:
00128  *****************************************************************/
00129 template <class T>
00130 inline RAYhit& 
00131 GEL_list<T>::intersect(RAYhit& r, mlib::CWtransf& m) const 
00132 {
00133    for (int i=0; i<num(); i++)
00134       (*this)[i]->intersect(r, m);
00135    return r;
00136 }
00137 
00138 #endif

Generated on Mon Sep 18 11:39:33 2006 for jot by  doxygen 1.4.4