00001 //------------------------------------------------------------------------ 00002 // 00003 // Joe Kniss 00004 // 6-20-03 00005 // ________ ____ ___ 00006 // | \ / | / / 00007 // +---+ \/ |/ / 00008 // +--+| |\ /| < 00009 // | || | \ / | |\ \ 00010 // | | \/ | | \ \ 00011 // \_____| |__| \__\ 00012 // Copyright 2003 00013 // Joe Michael Kniss 00014 // <<< jmk@cs.utah.edu >>> 00015 // "All Your Base are Belong to Us" 00016 //------------------------------------------------------------------------- 00017 00018 /// TFItem.h 00019 /// simianUI 00020 00021 #ifndef __SIMIAN_UI_TF_ITEM_DOT_H 00022 #define __SIMIAN_UI_TF_ITEM_DOT_H 00023 00024 /// from commonQT 00025 #include <canvas/CanvasItems.h> 00026 /// from simianlib 00027 #include <tf/TFBase.h> 00028 #include <tf/TFElement.h> 00029 /// vector of TFItems defined below 00030 #include <vector> 00031 00032 /// define the 2D domain type, 00033 /// tfSType defined in <simianlib>/tf/TFParams.h 00034 typedef gutz::vec2<STF::tfSType> tfVec2; 00035 const tfVec2 tfVec2_bad = tfVec2(STF::tfSType_bad); 00036 /// a transformation matrix 00037 typedef gutz::mat3<STF::tfSType> tfMat3; 00038 const tfMat3 tfMat3_bad = tfMat3(STF::tfSType_bad); 00039 00040 00041 ////////////////////////////////////////////////////////////////////////// 00042 /// TFItem, generic base class, see TFItemSTD for some concrete 00043 /// example implementations. 00044 /// This is the generic tf item that the TFView will see, for the most 00045 /// part all external interactions are through the TFItemVec. 00046 /// TFItems are the bridge between simianlib TFElements and the QT 00047 /// interface. An items behavior should be defined by the Element 00048 /// they represent, the Item's role is to comunicate changes to 00049 /// element and display them from the element. You should endevor to 00050 /// make sure "behavior" resides in the simianlib Element and 00051 /// only "interaction" and "display" stuff live in the Item. 00052 ////////////////////////////////////////////////////////////////////////// 00053 00054 class TFItem : public PolygonEdit { 00055 public: 00056 00057 TFItem(QCanvas *canvas, TFEltSP elt); 00058 virtual ~TFItem() { _elt = 0; } 00059 00060 /// transfer function element that we own 00061 TFEltSP getElt() const {return _elt;} 00062 void setElt(TFEltSP elt) {_elt = elt;} 00063 00064 /// which TF axies are we visualizing??? 00065 /// could be exteded to 3D... later 00066 void setAxisX(int elm) {_axisX = elm;} 00067 int getAxisX() const {return _axisX;} 00068 void setAxisY(int elm) {_axisY = elm;} 00069 int getAxisY() const {return _axisY;} 00070 00071 /// get/set Pos in TF element for the Current Axies 00072 tfVec2 getTFPosCA(int i); 00073 void setTFPosCA(int i, tfVec2 pos); 00074 00075 /// checks if anything in the TFElement changed 00076 /// if it has, calls updateDef() 00077 void update(); 00078 00079 /// indicate to parents or pointers that we need to 00080 /// be removed 00081 bool deleteMe() const { return _done; } 00082 00083 /// get the transformation 00084 virtual tfMat3 getXform() const { return _xform; } 00085 virtual tfMat3 getInvXform() const { return _invXform; } 00086 00087 /// transform a point (tf -> canvas) 00088 virtual tfVec2 xform(tfVec2 pt) const { return _xform.tpoint(pt); } 00089 virtual STF::tfSType xformX(STF::tfSType x) const { return x * _xform[0] + _xform[6]; } 00090 virtual STF::tfSType xformY(STF::tfSType y) const { return y * _xform[4] + _xform[7]; } 00091 00092 /// inverse transform (canvas -> tf) 00093 virtual tfVec2 invXform(tfVec2 pt) const { return _invXform.tpoint(pt); } 00094 virtual STF::tfSType invXformX(STF::tfSType x) const { return x * _invXform[0] + _invXform[6]; } 00095 virtual STF::tfSType invXformY(STF::tfSType y) const { return y * _invXform[4] + _invXform[7]; } 00096 00097 /// set the border space around tf, in pixels (canvas space) 00098 tfVec2 getBorder() const {return _border;} 00099 void setBorder(tfVec2 b) {_border = b; setTransform();} 00100 00101 /// set the scale factor to go from [0-1] tf space to "canvas space" 00102 /// and the inverse of that, ie. scale should probably just be 00103 /// the canvas width and height. 00104 tfVec2 getScale() const {return _scale;} 00105 tfVec2 getInvScale() const {return _invScale;} 00106 void setScale(tfVec2 scales); 00107 00108 protected: 00109 /// called by update, for subclasses 00110 virtual void updateDef() {} 00111 00112 TFEltSP _elt; 00113 00114 void setTransform(); 00115 00116 tfVec2 _scale; 00117 tfVec2 _invScale; 00118 tfVec2 _border; 00119 00120 tfMat3 _xform; 00121 tfMat3 _invXform; 00122 00123 int _axisX; 00124 int _axisY; 00125 00126 int _lastEltMod; /// id for last elt mod 00127 int _lastElmMod; /// id for last element mod 00128 00129 bool _done; 00130 }; 00131 00132 typedef gutz::SmartPtr<TFItem> TFItemSP; 00133 00134 ////////////////////////////////////////////////////////////////////////// 00135 /// TFItem Factory function, defined in "TFItemFactory.cpp" 00136 /// 00137 /// this simple function generates the correct TFItem for each TFElement type 00138 /// if you add a new TFElement type, you should also have a corresponding 00139 /// TFItem, modify this funciton to produce the right one. 00140 /// TODO: should this function be a static member of TFItemVec ? 00141 00142 TFItemSP genTFItem(TFEltSP elt, QCanvas *canvas); 00143 00144 /// 00145 ////////////////////////////////////////////////////////////////////////// 00146 00147 00148 ////////////////////////////////////////////////////////////////////////// 00149 /// TFItemVec, manages a bunch of transfer function elements, and 00150 /// the tf itself, as far as QT is concerned 00151 ////////////////////////////////////////////////////////////////////////// 00152 00153 class TFItemVec : public std::vector<TFItemSP> { 00154 public: 00155 00156 typedef std::vector<TFItemSP>::iterator TFItemVecIter; 00157 typedef std::vector<TFItemSP>::const_iterator TFItemVecConstIter; 00158 00159 TFItemVec(QCanvas *canvas, TFBaseSP tf); 00160 virtual ~TFItemVec(); 00161 00162 void setTF(TFBaseSP tf); 00163 TFBaseSP getTF() const { return _tf; } 00164 00165 void setCanvas(QCanvas *canvas); 00166 QCanvas *getCanvas() const { return _canvas; } 00167 00168 /// call update on all items in vector, 00169 /// also sync up with the tf... 00170 /// (check for new or deleted elements) 00171 void update(); 00172 00173 void setScale(tfVec2 scales) { _scales = scales; update(); } 00174 tfVec2 getScale() const { return _scales; } 00175 void setBorder(tfVec2 border) { _border = border; update(); } 00176 tfVec2 getBorder() const { return _border; } 00177 00178 /// get an item based on the Element it represents 00179 TFItemSP getItem(TFEltSP elt) const; 00180 00181 /// add an item, will try to figure out what "kind" 00182 /// of item based on the subclass of the elt, see 00183 /// genTFItem() factory function (above) 00184 void addItem(TFEltSP elt); 00185 00186 protected: 00187 void checkNewElts(); 00188 void checkDelElts(); 00189 00190 TFBaseSP _tf; 00191 QCanvas *_canvas; 00192 tfVec2 _scales; 00193 tfVec2 _border; 00194 }; 00195 00196 #endif 00197 00198