00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 #ifndef __TRANSFER_FUNCTION_ELEMENT_DOT_H
00021 #define __TRANSFER_FUNCTION_ELEMENT_DOT_H
00022 
00023 #include <smartptr.h>
00024 #include <simBase/simBase.h>
00025 #include <list>
00026 #include "TFParams.h"
00027 #include "TFEval.h"
00028 #include "TFBlend.h"
00029 #include <nrro/nrro.h>
00030 
00031 
00032 class TFEltView;
00033 
00034 
00035 
00036 typedef TFBlendSum  RGBBlendType;
00037 typedef TFBlendSum  AlphaBlendType;
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 class TFElement : 
00050    public SimBase, 
00051    public gutz::Counted
00052 {
00053 public:
00054    virtual ~TFElement() {}
00055 
00056    typedef STF::tfSType      SType; 
00057    typedef STF::tfDomainType PosType;
00058    typedef STF::tfDomainVec  PosVecType;
00059    typedef STF::tfRangeType  ValType;
00060    typedef STF::tfRangeVec   ValVecType;
00061    typedef STF::tfVec2       tfVec2;
00062    typedef STF::tfRangeVec4  tfVec4;
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073    virtual TFEltView *getView(const gutz::vec2i &axes) = 0; 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082    virtual ValType eval(const PosType &tfpos) const = 0;
00083 
00084 
00085 
00086    
00087    
00088    
00089    
00090    
00091    
00092    
00093    
00094    
00095 
00096    
00097    
00098    
00099    
00100    
00101    
00102    
00103    
00104    
00105    
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114    ValType getZeroVal() const            {return _zeroVal;}
00115    void    setZeroVal(const ValType &zv) { _zeroVal = zv; }
00116 
00117 
00118 
00119 
00120 
00121    TFEvalSP getEvaluator() const     {return _eval;}
00122    void     setEvaluator(TFEvalSP e) {_eval = e;}
00123 
00124 
00125 
00126    
00127    
00128    
00129    
00130    
00131    
00132 
00133 
00134 
00135 
00136 
00137 
00138    PosVecType &getPosVec()               { return _posVec; }
00139    PosVecType  getPosVec() const         { return _posVec; }
00140    void        setPosVec(PosVecType &pv) { _posVec = pv; }
00141    PosType    &getPos(int i)             { return _posVec[i]; }
00142    PosType     getPos(int i) const       { return _posVec[i]; }
00143    void        setPos(int i, PosType p)  { _posVec[i] = p; }
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151    virtual PosType  getMinBox() const
00152    {
00153       PosType ret(STF::tfDomainType_max);
00154       for(int i=0; i<int(_posVec.size()); ++i)
00155          vs_min(ret, _posVec[i]);
00156       return ret;
00157    }
00158    virtual PosType  getMaxBox() const
00159    {
00160       PosType ret(STF::tfDomainType_min);
00161       for(int i=0; i<int(_posVec.size()); ++i)
00162          vs_max(ret, _posVec[i]);
00163       return ret;
00164    }
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173    ValVecType &getValVec()       { return _valVec; }
00174    ValVecType  getValVec() const { return _valVec; }
00175 
00176 
00177 
00178 
00179    bool  needRemove() const {return _remove;}
00180 
00181 
00182 
00183 
00184    virtual void rasterize2D(NrroSP n, 
00185                             const gutz::vec2i &posIdx,
00186                             const int kind = STF::TF_RGBA) = 0;
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 protected:
00201    TFElement() : _remove(false), _eval(new TFEvalGaus()) {}
00202 
00203    PosVecType _posVec; 
00204    ValVecType _valVec; 
00205 
00206    ValType    _zeroVal;
00207 
00208    TFEvalSP   _eval;
00209 
00210 
00211    bool _remove;
00212 
00213 };
00214 
00215 typedef gutz::SmartPtr<TFElement> TFElementSP;
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 class TFEltSP : public gutz::SmartPtrRef<TFElement>, public SimBase
00225 {
00226 public:
00227    typedef gutz::SmartPtrRef<TFElement> btype;
00228 
00229    TFEltSP(TFElement *e) : btype(e), _lastChanged(e->getChangeID()) {}
00230    TFEltSP(const TFEltSP &tfe) : btype(), _lastChanged(tfe._lastChanged)
00231    { assign(const_cast<btype::type*>(tfe._ref)); }
00232 
00233    TFEltSP &operator=(const TFEltSP &tfe)
00234    { 
00235       assign(const_cast<btype::type*>(tfe._ref));
00236       setChanged();
00237       _lastChanged = -1;
00238       return *this;
00239    }
00240 
00241 
00242 
00243 
00244 
00245    virtual int  getChangeID()               
00246    {
00247       if(_lastChanged != (*_ref)->getChangeID())
00248          setChanged();
00249       _lastChanged = (*_ref)->getChangeID();
00250       return SimBase::getChangeID();
00251    }
00252 
00253 
00254    bool elementChanged() const { return _lastChanged != (*_ref)->getChangeID(); }
00255 
00256    void updateChanged()  { _lastChanged = (*_ref)->getChangeID(); }
00257 
00258    virtual ~TFEltSP() {}
00259 
00260 protected:
00261    TFEltSP() {}
00262    int _lastChanged;
00263 };
00264 
00265 
00266 
00267 
00268 class TFElementList : 
00269    public std::list<TFEltSP>, 
00270    public gutz::Counted 
00271 {
00272 public:
00273    typedef TFElementList::iterator Iter;
00274 
00275    TFElementList() {}   
00276    virtual ~TFElementList() {}
00277 
00278    void addElement(TFElement *e)
00279    { push_back(TFEltSP(e)); }
00280 
00281 
00282    bool elementChanged()
00283    {
00284       bool ret = false;
00285       for(Iter i = begin(); i!=end(); ++i)
00286       {
00287          ret |= (*i).elementChanged();
00288       }
00289       return ret;
00290    }
00291    
00292 
00293    void updateChanged()
00294    {
00295       for(Iter i=begin(); i!=end(); ++i)
00296       {
00297          (*i).updateChanged();
00298       }
00299    }
00300 
00301 protected:
00302 
00303 };
00304 
00305 typedef TFElementList::iterator       TFElementListIter;
00306 typedef TFElementList::const_iterator TFElementListConstIter;
00307 
00308 typedef gutz::SmartPtr<TFElementList> TFElementListSP;
00309 
00310 
00311 #endif
00312