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

line3d.H

Go to the documentation of this file.
00001 #ifndef LINE_3D_H_IS_INCLUDED
00002 #define LINE_3D_H_IS_INCLUDED
00003 
00004 #include "disp/gel.H"
00005 
00006 /*****************************************************************
00007  * LINE3D:
00008  *
00009  *   A polyline that can be rendered and intersected.
00010  *****************************************************************/
00011 #define CLINE3D    const LINE3D
00012 #define CLINE3Dptr const LINE3Dptr
00013 
00014 MAKE_PTR_SUBC(LINE3D,GEL);
00015 class LINE3D : public GEL {
00016  public:
00017 
00018    //******** MANAGERS ********
00019 
00020    LINE3D();
00021    LINE3D(mlib::CWpt_list& pts);
00022 
00023    virtual ~LINE3D();
00024 
00025    //******** RUN-TIME TYPE ID ********
00026 
00027    DEFINE_RTTI_METHODS3("LINE3D", LINE3D*, GEL, CDATA_ITEM*);
00028 
00029    //******** BUILDING THE POLYLINE ********
00030 
00031    // Append a point to the end of the polyline:
00032    void add(mlib::CWpt &p);
00033 
00034    // Append a whole bunch of points at the end:
00035    void add(mlib::CWpt_list &p);
00036 
00037    // Clear the polyline:
00038    void clear() { _pts.clear(); }
00039 
00040    // Set the polyline:
00041    void set(mlib::CWpt_list& p) {
00042       clear();
00043       add(p);
00044    }
00045 
00046    // Redefine a given point:
00047    void set(int i, mlib::CWpt& p);
00048 
00049    //******** POLYLINE GEOMETRY ********
00050 
00051    // Returns number of points:
00052    int num()    const { return _pts.num(); }
00053 
00054    // Tells if the polyline is empty:
00055    bool empty() const { return _pts.empty(); }
00056 
00057    // Returns the Wpt_list:
00058    mlib::CWpt_list&   pts()   const   { return _pts; }
00059 
00060    // Returns point number i:
00061    mlib::CWpt& operator[](int i)      const   { return _pts[i]; }
00062    mlib::CWpt& point(int i)           const   { return _pts[i]; }
00063 
00064    // Returns the interpolated point corresponding to parameter 's',
00065    // which varies from 0 to 1 over the length of the Wpt_list:
00066    mlib::Wpt   point(double s)        const   { return _pts.interpolate(s);}
00067 
00068    // Returns tangent or normal at given point index:
00069    mlib::Wvec tangent(int i)  const { return _pts.tan(i); }
00070    mlib::Wvec normal (int i)  const { return tangent(i).perpend();}
00071 
00072    // The length of the Wpt_list:
00073    double length() const { return _pts.length();}
00074 
00075    // It's a closed loop if the first and last point are the same:
00076    bool loop() const { return (num() > 1 && (_pts[0] == _pts.last())); }
00077 
00078    //******** RENDERING ATTRIBUTES ********
00079 
00080    // The width of the polyline (for rendering):
00081    double width()               const   { return _width; }
00082    void   set_width(double w)           { _width = w; }
00083 
00084    CCOLOR& color()              const   { return _color; }
00085    void    set_color(CCOLOR& c)         { _color = c; }
00086 
00087    double alpha()               const   { return _alpha; }
00088    void   set_alpha(double a)           { _alpha = a; }
00089 
00090    void   set_do_stipple(bool b=true)   { _do_stipple = b; }
00091 
00092    bool   no_depth()            const   { return _no_depth; }
00093    void   set_no_depth(bool d)          { _no_depth = d; }
00094 
00095    //******** DRAWING ********
00096 
00097    // A regular draw() call breaks down to the following 3 calls.
00098    // Normally you don't mess with these yourself, but it can be
00099    // useful to have the option, like whe're planning to draw a lot
00100    // of LINE3Ds with the same attributes (color, thickness etc.),
00101    // you could do a single draw_start(), then call draw_pts() on
00102    // each LINE3D, and conclude with a single draw_end():
00103    void draw_start(CCOLOR& col, double a, double w, bool do_stipple);
00104    void draw_pts();
00105    void draw_end();
00106 
00107    //******** GEL VIRTUAL METHODS ********
00108 
00109    virtual RAYhit& intersect(RAYhit &r, mlib::CWtransf& = mlib::Identity, int=0) const;
00110     
00111    //******** RefImageClient METHODS ********
00112 
00113    virtual int draw(CVIEWptr&);
00114    virtual int draw_vis_ref();
00115  
00116    //******** DATA_ITEM VIRTUAL METHODS ********
00117 
00118    virtual DATA_ITEM* dup() const { return new LINE3D(); }
00119 
00120  protected:
00121 
00122    //******** MEMBER VARIABLES ********  
00123    
00124    mlib::Wpt_list     _pts;           // the polyline
00125    double       _width;         // width for rendering
00126    COLOR        _color;         // color for rendering
00127    double       _alpha;         // alpha for rendering
00128    bool         _do_stipple;    // flag for rendering stippled
00129    bool         _no_depth;      // flag for depth buffering
00130 
00131    //******** PROTECTED METHODS ********
00132 
00133    int  _draw     (CCOLOR& col, double a, double w, bool do_stipple);
00134 };
00135 
00136 /*****************************************************************
00137  * LINE3D_list:
00138  *****************************************************************/
00139 class LINE3D_list : public GEL_list<LINE3Dptr> {
00140  public:
00141 
00142    //******** CONVENIENCE ********
00143 
00144    void set_alpha(double a) const {
00145       for (int k = 0; k < _num; k++)
00146          _array[k]->set_alpha(a);
00147    }
00148    void set_color(CCOLOR& c) const {
00149       for (int k = 0; k < _num; k++)
00150          _array[k]->set_color(c);
00151    }
00152    void set_width(double w) const {
00153       for (int k = 0; k < _num; k++)
00154          _array[k]->set_width(w);
00155    }
00156    void set_do_stipple(bool b=1) const {
00157       for (int k = 0; k < _num; k++)
00158          _array[k]->set_do_stipple(b);
00159    }
00160    void draw_pts() const {
00161       for (int k = 0; k < _num; k++)
00162          _array[k]->draw_pts();
00163    }
00164    int draw(CVIEWptr &v) const {
00165       int ret = 0;
00166       for (int k = 0; k < _num; k++)
00167          ret += _array[k]->draw(v);
00168       return ret;
00169    }
00170 };
00171 
00172 #endif // LINE_3D_H_IS_INCLUDED
00173 
00174 // end of file line3d.H

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