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

gel.H

Go to the documentation of this file.
00001 #ifndef GEL_H_IS_INCLUDED
00002 #define GEL_H_IS_INCLUDED
00003 
00004 #include "std/support.H"
00005 #include "net/data_item.H"
00006 #include "net/stream.H"
00007 #include "mlib/points.H"
00008 #include "disp/bbox.H"
00009 #include "disp/ref_img_client.H"
00010 
00011 
00012 class   RAYhit;
00013 #define CRAYhit const RAYhit
00014 class   RAYnear;
00015 #define CRAYnear const RAYnear
00016 class VIEWptr;
00017 #define CVIEWptr  const VIEWptr
00018 class VIEW;
00019 
00020 
00021 #define CFRAMEobslist const FRAMEobslist
00022 #define CFRAMEobsptr  const FRAMEobsptr
00023 //--------------------------------------------
00024 // FRAMEobs, FRAMEobslist  -
00025 //   An object that can be notified when each
00026 // frame occurs.  The return value of the tick()
00027 // function determines whether the observer
00028 // should be put back onto the observing queue
00029 // or not.  A value of -1 indicates that the
00030 // observer should be removed from the queue.
00031 //--------------------------------------------
00032 MAKE_PTR_BASEC(FRAMEobs);
00033 class FRAMEobs: public REFcounter {
00034    protected:
00035       // index of this FRAMEobs in
00036       // SCHEDULER::_scheduled list (below):
00037       int _index;      
00038 
00039    public :
00040       FRAMEobs() : _index(-1) {}
00041       virtual     ~FRAMEobs()        { }
00042 
00043       virtual int  tick()            { return -1; }
00044       virtual void setIndex(int idx) { _index = idx; }
00045       virtual int  getIndex() const  { return _index; }
00046 };
00047 
00048 typedef LIST<FRAMEobsptr> FRAMEobslist;
00049 
00050 
00051 #define CSCHEDULERptr const SCHEDULERptr
00052 #define CSCHEDULER    const SCHEDULER
00053 //---------------------------------------------
00054 // SCHEDULER, SCHEDULEptr
00055 // This class is a subclass of GEL, which implements calling the
00056 // GEL::tick() methods on objects that have been schedule()'d on it.
00057 //
00058 // Usually the WORLD::tick() function is called from a window system
00059 // callback, and all the other schedulers and GEL objects are called
00060 // from there in a cascade of tick()'s...
00061 //---------------------------------------------
00062 MAKE_PTR_SUBC(SCHEDULER, FRAMEobs);
00063 class SCHEDULER: public FRAMEobs {
00064    protected:
00065       FRAMEobslist  _scheduled;  // List of scheduled objects
00066       FRAMEobslist  _unscheduled;// list of objects to unschedule 
00067                                  //   at the end of this tick
00068       bool          _ticking;    // currently ticking
00069 
00070    public :
00071    SCHEDULER() : _ticking(0) { }
00072    virtual ~SCHEDULER() {}
00073 
00074    virtual int tick(void);
00075 
00076    bool is_scheduled(CFRAMEobsptr& o) const;
00077    int  get_index   (CFRAMEobsptr& o) const;
00078 
00079    virtual void    schedule  (CFRAMEobsptr& o);
00080    virtual void    unschedule(CFRAMEobsptr& o);
00081 
00082    static  STAT_STR_RET static_name() {RET_STAT_STR("SCHEDULER");} 
00083    virtual STAT_STR_RET class_name ()          const{ return static_name(); }
00084    virtual int          is_of_type (Cstr_ptr &n)const{ return IS (n);}
00085    static  int          isa        (CSCHEDULERptr &o){ return ISA(o); }
00086 };
00087 
00088 // This defines the GELptr class and the auxiliary GELsubc class
00089 // that is used for subclassing GELptr's.
00090 MAKE_PTR_BASEC(GEL);
00091 typedef const GELptr CGELptr;
00092 
00093 // -------------------------------------------------------------
00094 /*! GEL, GELptr:
00095  *  The virtual base class for "graphic elements" that can be 
00096  *  displayed in a view.   These objects are intended to be 
00097  *  lightweight, ref-counted geometric elements that support
00098  *  a minimal but important interface including methods for:
00099  *   intersection, nearest, transformations, naming, serializing,
00100  *   and drawing
00101  */
00102 // -------------------------------------------------------------
00103 class GEL: public REFcounter, 
00104            public DATA_ITEM,
00105            public RefImageClient 
00106 { 
00107  public:  
00108    GEL();
00109    virtual ~GEL();
00110 
00111    DEFINE_RTTI_METHODS3("GEL", GEL*, DATA_ITEM, CDATA_ITEM*);
00112 
00113    virtual CTAGlist& tags() const {
00114       return _gel_tags ? *_gel_tags : *(_gel_tags = new TAGlist);
00115    }
00116    virtual RAYhit& intersect
00117    (RAYhit  &r,mlib::CWtransf&m=mlib::Identity,int uv=0)const;
00118    virtual RAYnear& nearest
00119    (RAYnear &r,mlib::CWtransf&m=mlib::Identity)         const;
00120    virtual bool inside(mlib::CXYpt_list&)const  { return false; }
00121    virtual bool needs_blend()           const   { return false; }
00122    virtual BBOX bbox(int =0)            const   { return BBOX(); }
00123    virtual bool cull(const VIEW *)      const   { return 0; }
00124    virtual int  draw(CVIEWptr &)                { return 0; }
00125 
00126    virtual bool is_3D()                 const   { return false; }
00127    virtual bool can_do_halo()           const   { return false; }
00128 
00129    virtual Cstr_ptr&  name ()           const   { return _name; }
00130 
00131    virtual ostream&   print(ostream &s) const   { return s; }
00132    virtual DATA_ITEM* dup  ()           const = 0;
00133 
00134  private:
00135    static Cstr_ptr _name;
00136  protected:
00137    GEL(CGELptr &g);
00138    static TAGlist* _gel_tags;
00139 };
00140 
00141 STDdstream     &operator>>(STDdstream &d,      GELptr &p);
00142 STDdstream     &operator<<(STDdstream &d,const GEL    *p);
00143 inline ostream &operator<<(ostream    &d,const GEL *p) {return p?p->print(d):d;}
00144 
00145 /*****************************************************************
00146  * GEL_list:
00147  *
00148  *    A templated list class to be used with GELs, 
00149  *    or with types derived from GEL.
00150  *****************************************************************/
00151 template <class T>
00152 class GEL_list : public RIC_list<T> { 
00153 public :
00154   //******** MANAGERS ********
00155   GEL_list(int n=0) : RIC_list<T>(n) {}
00156   
00157   //******** CONVENIENCE ********
00158   bool cull(const VIEW * v) const{
00159     bool ret = true;
00160     for (int i=0; i<num(); i++)
00161       ret = ret && (*this)[i]->cull(v);
00162     return ret;    
00163   }
00164 
00165   int draw(CVIEWptr& v) const {
00166     int ret = 0;
00167     for (int i=0; i<num(); i++)
00168       ret += (*this)[i]->draw(v);
00169     return ret;
00170   }
00171 
00172    BBOX bbox() const {
00173       BBOX ret;
00174       for (int i=0; i<num(); i++)
00175          ret += (*this)[i]->bbox();
00176       return ret;
00177    }
00178 
00179    // return true if any need blend
00180    bool needs_blend() const {
00181       for (int i=0; i<num(); i++)
00182          if ((*this)[i]->needs_blend())
00183             return true;
00184       return false;
00185    }
00186 
00187    // defined in ray.H to placate VS .NET compiler:
00188    RAYhit& intersect(RAYhit& r, mlib::CWtransf& m=mlib::Identity) const;
00189 
00190   using RIC_list<T>::num;
00191 };
00192 
00193 /*****************************************************************
00194  * GELlist:
00195  *
00196  *    Instantiation of above, for GELs.
00197  *****************************************************************/
00198 class GELFILT;
00199 class GELlist;
00200 typedef const GELlist CGELlist;
00201 class GELlist : public GEL_list<GELptr> {
00202  public :
00203    //******** MANAGERS ********
00204    GELlist(int n=16) : GEL_list<GELptr>(n) {}
00205    GELlist(CGELptr &g) { add(g); }
00206    GELlist(GEL     *g) { add(g); }
00207 
00208    // Returns the subset of this list made up of GELs 
00209    // that are accepted by the given filter:
00210    GELlist filter(GELFILT&) const;        
00211 };
00212 
00213 // ------- define additional variables
00214 
00215 class DrawnList : public GELlist {   
00216    protected :
00217      class DispOp {
00218         public:
00219            GELptr _gel;
00220            bool   _op;
00221            DispOp(CGELptr &g, bool op = true) : _gel(g), _op(op) {}
00222            DispOp() : _op(false) {}
00223            int operator==(const DispOp &c) const {
00224               return _gel == c._gel && _op == c._op;
00225            }
00226      };
00227      ARRAY<DispOp> _dispq;
00228      bool          _buffering;
00229    public :
00230             DrawnList() { }
00231     void    add   (CGELptr &g);
00232     void    rem   (CGELptr &g);
00233     GELptr  lookup(Cstr_ptr &n) const;
00234 
00235    virtual void buffer()      { _buffering = 1;}
00236    virtual int  buffering()   { return _buffering; }
00237    virtual void flush();
00238 };
00239 
00240 class ExistList : public GELlist {   
00241    public :
00242             ExistList() { }
00243     void    add           (CGELptr &g);
00244     void    rem           (CGELptr &g);
00245     GELptr  lookup        (Cstr_ptr &n) const;
00246     str_ptr unique_dupname(Cstr_ptr &) const;
00247     str_ptr unique_name   (Cstr_ptr &) const;
00248     bool    allocated() const { return _array != 0; }
00249 };
00250 
00251 extern ExistList    EXIST;
00252 extern DrawnList    DRAWN;
00253 
00254 // -------- define observers for GEL operations
00255 #include "disp/gel_obs.H" 
00256 #include "disp/hash_types.H"
00257 
00258 // -------- define hash variables for GEL objects
00259 extern GrabVar      GRABBED;
00260 extern hashvar<int> NO_COLOR_MOD, NO_XFORM_MOD, NO_DISP_MOD, NO_COPY,
00261                               PICKABLE,
00262                               NETWORK,       // list of networked objects
00263                               NO_CONSTRAINT_MOD,
00264                               NO_SCALE_MOD,  // Don't scale object
00265                               NO_EXTNETWORK, // Don't do external geometry 
00266                                              // for this obj
00267                               NO_SAVE;       // Network, but don't send whole
00268                                              // object
00269 extern hashvar<mlib::Wpt>  CONSTRAINT_POINT;
00270 extern hashvar<mlib::Wvec> CONSTRAINT_VECTOR;
00271 
00272 #endif // GEL_H_IS_INCLUDED
00273 
00274 

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