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
00015
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
00040
00041
00042
00043 class GEOMlist;
00044 typedef const GEOMlist CGEOMlist;
00045 class GEOMlist : public GEL_list<GEOMptr> {
00046 public :
00047
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
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 class GEOM : public GEL, public APPEAR {
00071 public:
00072
00073
00074
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
00093 GEOM(CGEOMptr &o, Cstr_ptr &);
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
00103 Cstr_ptr &name() const { return _name; }
00104 virtual BODYptr body() const { return _body; }
00105 virtual void set_body(CBODYptr& b);
00106
00107
00108
00109 virtual mlib::CWtransf &xform () const { return _xform; }
00110 virtual mlib::CWtransf &inv_xform () const;
00111
00112
00113 virtual mlib::Wtransf obj_to_world() const { return xform(); }
00114 virtual mlib::Wtransf world_to_obj() const { return inv_xform(); }
00115
00116
00117 virtual void write_xform (mlib::CWtransf &, mlib::CWtransf &, CMOD &);
00118
00119
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
00133 virtual ostream &print (ostream &) const;
00134 virtual void get_name (TAGformat &d) { *d >> _name; }
00135
00136
00137
00138
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
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
00153
00154 static GEOM* null;
00155
00156
00157
00158
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
00171 virtual int draw_halo(CVIEWptr& = VIEW::peek()) const { return 0; }
00172
00173
00174 virtual bool is_3D() const { return bbox().valid(); }
00175 virtual bool can_do_halo() const { return true; }
00176
00177
00178
00179
00180
00181
00182
00183 static bool find_cam_focus(CVIEWptr& view, mlib::CXYpt& x);
00184 protected:
00185
00186
00187
00188
00189
00190 virtual bool do_cam_focus(CVIEWptr& view, CRAYhit& r);
00191 public:
00192
00193
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
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
00220 static TAGlist* _geom_tags;
00221
00222
00223 static bool _do_halo_view;
00224 static bool _do_halo_ref;
00225 };
00226
00227
00228
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
00240
00241 #include "geom/geom_obs.H"
00242
00243
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