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

geom.H

Go to the documentation of this file.
00001 #ifndef GEOM_H
00002 #define GEOM_H
00003 
00004 #include "disp/gel.H"
00005 #include "mlib/points.H"
00006 #include "net/data_item.H"
00007 #include "net/stream.H"
00008 #include "std/support.H"
00009 
00010 #include "geom/body.H"
00011 #include "geom/fsa.H"
00012 #include "geom/appear.H"
00013 
00014 // this defines a GEOMptr which inherits (sort of) from a
00015 // GELptr.  Thus, GEOMptr's can be used wherever GELptr's are.
00016 MAKE_PTR_SUBC(GEOM,GEL);
00017 
00018 #ifdef WIN32
00019 #undef min
00020 #undef max
00021 #endif
00022 
00023 class Event;
00024 typedef State_t<Event> State;
00025 class RAYhit;
00026 #define CRAYhit const RAYhit
00027 class RAYnear;
00028 #define CRAYnear const RAYnear
00029 class CAM;
00030 typedef REFptr<CAM> CAMptr;
00031 #define CCAMptr const CAMptr
00032 #define CEvent const Event
00033 class VIEWptr;
00034 #define CVIEWptr const VIEWptr
00035 class GEOMptr;
00036 #define CGEOMptr const GEOMptr
00037 
00038 /*****************************************************************
00039  * GEOMlist:
00040  *
00041  *    Instantiation of GEL_list, for GEOMs.
00042  *****************************************************************/
00043 class GEOMlist;
00044 typedef const GEOMlist CGEOMlist;
00045 class GEOMlist : public GEL_list<GEOMptr> {
00046  public :
00047    //******** MANAGERS ********
00048    GEOMlist(int n=16) : GEL_list<GEOMptr>(n) {}
00049    GEOMlist(CGEOMptr& g) { add(g); }
00050    GEOMlist(GEOM* g)     { add(g); }
00051 };
00052 
00053 //----------------------------------------------
00054 //
00055 //  GEOM -
00056 //     abstract class that defines a geometric
00057 //  entity.   This class contains a data ptr to a
00058 //  specific representation object.   The representation
00059 //  object must minimally know how to draw itself to OGl 
00060 //  or intersect a ray with itself when asked.
00061 //
00062 //  GEOM objects store color, transparency, and a transformation.
00063 //
00064 //  However, the default virtual method for drawing a GEOM
00065 //  "draws" each attribute to OGl but does NOT draw the
00066 //  BODY geometrys.   This is done in the MODELER subclass
00067 //
00068 //----------------------------------------------
00069 
00070 class GEOM : public GEL, public APPEAR {
00071  public:  // this operator must come before any reference to GEOMptr
00072           // otherwise, the instantiation of GEOMptr, which uses the
00073           // << operator on GEOM * in an inline won't know about this
00074           // method.  This only is an issue with some compilers...
00075    friend  class       GEOMlist;
00076    enum cons {
00077       NO_TRANS,
00078       TRANS_FREE,
00079       TRANS_LINE,
00080       TRANS_PLANE,
00081       SURFACE_SNAP,
00082       AXIS_ROTATE,
00083       SPHERE_ROTATE,
00084       SCREEN_TEXT,
00085       SCALE,
00086       SCALE_AXIS,
00087       LOOKUP,
00088       SCREEN_WIDGET
00089    };
00090 
00091  public: 
00092    //******** MANAGERS ********
00093    GEOM(CGEOMptr &o, Cstr_ptr &);  // copy constructor
00094    GEOM(Cstr_ptr&, CBODYptr& b = 0);
00095    GEOM();
00096    virtual ~GEOM();
00097 
00098    DEFINE_RTTI_METHODS3("GEOM", GEOM*, GEL, CDATA_ITEM *);
00099 
00100    virtual CTAGlist &tags() const;
00101 
00102    //******** DATA ACCESSORS ********
00103    Cstr_ptr &name()                     const { return _name; }
00104    virtual BODYptr   body()             const { return _body; }
00105    virtual void set_body(CBODYptr& b);
00106 
00107    // xform stored for this object
00108    // (possibly relative to some other GEOM):
00109    virtual mlib::CWtransf &xform     () const { return _xform; }
00110    virtual mlib::CWtransf &inv_xform () const;
00111 
00112    // transforms between object space and world space:
00113    virtual mlib::Wtransf obj_to_world() const { return xform(); }
00114    virtual mlib::Wtransf world_to_obj() const { return inv_xform(); }
00115 
00116    //******** GEOMETRY OPS ********
00117    virtual void write_xform    (mlib::CWtransf &, mlib::CWtransf &, CMOD &);
00118 
00119    //******** ATTRIBUTES     ********
00120    virtual void mult_by      (mlib::CWtransf &);
00121    virtual void set_color    (CCOLOR   &);
00122    virtual void unset_color  ()          ;
00123    virtual void set_texture  (CTEXTUREptr& t);
00124    virtual void unset_texture();
00125    virtual void set_xform    (mlib::CWtransf &x) { mult_by(x*inv_xform()); }
00126    void set_name     (Cstr_ptr &n) { _name       = n; }
00127    virtual void set_pickable (int f)       { PICKABLE.set(this,f);
00128    if(!f) set_transp(.8);
00129    else unset_transp(); }
00130    virtual bool needs_blend  () const { return has_transp() && transp() != 1;}
00131 
00132    /* ---  print and formatting functions --- */
00133    virtual ostream &print     (ostream  &)  const;
00134    virtual void     get_name  (TAGformat &d)       { *d >> _name; }
00135 
00136    // XXX - Loading from file can occur as an update
00137    // to a GEOM and this must be done in a way
00138    // that distributes the notifications...!
00139    virtual void     get_xf    (TAGformat &d) {
00140       mlib::Wtransf x; *d >> x; mult_by(x*inv_xform());
00141    }
00142 
00143    virtual void     put_name  (TAGformat &d) const { d.id() << _name; }
00144    virtual void     put_xf    (TAGformat &d) const { d.id() << _xform;}
00145 
00146    //******** ADDITIONAL GEOM INTERFACE ********
00147    virtual int      lookup_constraint(CEvent &, State *&, cons &) { return 0; }
00148    virtual int      interactive      (CEvent &, State *&, RAYhit * =0) const
00149       { return 0; }
00150    virtual BBOX     bbox             (int i=0)      const;
00151 
00152    //******** STATICS ********
00153 
00154    static  GEOM*        null;
00155 
00156    //******** HALOING ********
00157 
00158    // static interface:
00159    static bool do_halo_view()           { return _do_halo_view; }
00160    static bool do_halo_ref ()           { return _do_halo_ref; }
00161    static void set_do_halo_view(bool b) { _do_halo_view = b; }
00162    static void set_do_halo_ref (bool b) { _do_halo_ref  = b; }
00163    static bool toggle_do_halo_view() {
00164       return (_do_halo_view = !_do_halo_view);
00165    }
00166    static bool toggle_do_halo_ref () {
00167       return (_do_halo_ref  = !_do_halo_ref);
00168    }
00169 
00170    // virtual method for drawing a halo around the object:
00171    virtual int draw_halo(CVIEWptr& = VIEW::peek()) const { return 0; }
00172 
00173    // GEL virtual method:
00174    virtual bool is_3D()       const { return bbox().valid(); }
00175    virtual bool can_do_halo() const { return true; }
00176 
00177    //******** CAMERA INTERACTION ********
00178 
00179    // Called by camera interactor when user does double tap
00180    // (with camera button). This method finds the GEOM (if any)
00181    // tapped on by the user, and calls a virtual method of that
00182    // GEOM to animate the camera:
00183    static  bool find_cam_focus(CVIEWptr& view, mlib::CXYpt& x);
00184  protected:
00185    // Called in find_cam_focus() for the tapped-on GEOM to
00186    // animate the camera. The method is virtual so special
00187    // objects may animate the camera in special ways; the base
00188    // class offers a simple default camera animation intended
00189    // to give a better view of the tapped-on point:
00190    virtual bool   do_cam_focus(CVIEWptr& view, CRAYhit& r);
00191  public:
00192 
00193    //******** GEL VIRTUAL METHODS ********
00194    virtual RAYhit&
00195    intersect(RAYhit  &r,mlib::CWtransf&m=mlib::Identity,int uv=0)const;
00196    virtual RAYnear&
00197    nearest(RAYnear &r,mlib::CWtransf&m=mlib::Identity)         const;
00198    virtual bool cull(const VIEW *v)     const;
00199 
00200    virtual int          draw(CVIEWptr &v);
00201    virtual int          draw_vis_ref();
00202    virtual int          draw_ref_img(ref_img_t t);
00203    virtual ref_img_t    use_ref_image();
00204    virtual int          draw_final(CVIEWptr &v);
00205 
00206    //******** DATA_ITEM VIRTUAL METHODS ********
00207    virtual GEOMptr dup(Cstr_ptr &n) const { return new GEOM((GEOM*)this,n);}
00208    virtual DATA_ITEM* dup() const { return new GEOM(_name); }
00209 
00210  protected:
00211    str_ptr              _name;
00212    BBOX                 _bbox;
00213    mlib::Wtransf        _xform;
00214    BODYptr              _body;
00215    bool                 _inv_xf_dirty;
00216    mlib::Wtransf        _inv_xf;
00217    int                  _bbox_id;
00218 
00219    //******** STATICS ********
00220    static  TAGlist*     _geom_tags;
00221 
00222    // flags that enable halos globally
00223    static bool     _do_halo_view; // draw halos in main view
00224    static bool     _do_halo_ref;  // draw halos in color ref image
00225 };
00226 
00227 // for convenience, when your gel is a
00228 // derived type that contains a body:
00229 inline BODYptr 
00230 gel_to_body(CGELptr &gel)
00231 {
00232    GEOM* geom = GEOM::upcast(gel);
00233    return geom ? geom->body() : 0;
00234 }
00235 
00236 STDdstream  &operator>>(STDdstream &d, GEOMptr &p);
00237 
00238 
00239 // ---------- define observers for GEOM operations
00240 
00241 #include "geom/geom_obs.H"
00242 
00243 // ---------- define hash variables for GEOM objects
00244 
00245 class XformConstraint : public hashenum<GEOM::cons> {
00246  public :
00247    XformConstraint(Cstr_ptr &name, GEOM::cons cons, int net):
00248       hashenum<GEOM::cons>(name, cons, net) { }
00249    virtual str_ptr enum_to_str(GEOM::cons e) const { 
00250       switch (e) {
00251        case GEOM::TRANS_FREE    : return "trans_free";
00252        case GEOM::TRANS_LINE    : return "trans_line";
00253        case GEOM::TRANS_PLANE   : return "trans_plane";
00254        case GEOM::SURFACE_SNAP  : return "surface_snap";
00255        case GEOM::AXIS_ROTATE   : return "axis_rotate";
00256        case GEOM::SPHERE_ROTATE : return "sphere_rotate";
00257        case GEOM::SCREEN_TEXT   : return "screen_text";
00258        case GEOM::SCALE         : return "scale";
00259        case GEOM::SCALE_AXIS    : return "scale_axis";
00260        case GEOM::LOOKUP        : return "lookup";
00261        case GEOM::SCREEN_WIDGET : return "screen_widget";
00262        default                  : return "none";
00263       }
00264    }
00265    virtual GEOM::cons str_to_enum(Cstr_ptr &s) const { 
00266       if (s == "trans_free")    return GEOM::TRANS_FREE   ;
00267       else if (s == "trans_line")    return GEOM::TRANS_LINE   ;
00268       else if (s == "trans_plane")   return GEOM::TRANS_PLANE  ;
00269       else if (s == "surface_snap")  return GEOM::SURFACE_SNAP ;
00270       else if (s == "axis_rotate")   return GEOM::AXIS_ROTATE  ;
00271       else if (s == "sphere_rotate") return GEOM::SPHERE_ROTATE;
00272       else if (s == "screen_text")   return GEOM::SCREEN_TEXT  ;
00273       else if (s == "scale")         return GEOM::SCALE        ;
00274       else if (s == "scale_axis")    return GEOM::SCALE_AXIS   ;
00275       else if (s == "lookup")        return GEOM::LOOKUP       ;
00276       else if (s == "screen_widget") return GEOM::SCREEN_WIDGET;
00277       return GEOM::NO_TRANS;
00278    }
00279 };
00280 
00281 extern XformConstraint  CONSTRAINT;
00282 extern hashvar<int>     XFORM_ON_BODY, HIGHLIGHTED, NO_CULL;
00283 
00284 #endif

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