Main Page   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

transfer.h

00001 //---------------------------------------------------------------------------
00002 
00003 #ifndef transferH
00004 #define transferH
00005 
00006 #include <list>
00007 #include <string>
00008 #include <Classes.hpp>
00009 #include <Controls.hpp>
00010 #include <ExtCtrls.hpp>
00011 #include <Types.hpp>
00012 #include <XMLDoc.hpp>
00013 #include <Dialogs.hpp>
00014 #include "histo.h"
00015 #include "data.h"
00016 #include "xmltags.h"
00017 
00018 // History range:
00019 #define HSIZE           4096
00020 
00025 #define DEF_DIST        5
00026 
00029 #define DEF_DIST_SQR    25
00030 #define DEF_POINT_DIST  2*DEF_DIST
00031 
00032 #define FABS(a)         ((a)<0.0 ? (a)*-1.0 : (a))
00033 
00034 struct TData {
00035         rgba col;
00036         int name;
00037         double alpha;
00038 };
00039 
00040 rgba TColor2RGBA(TColor c);
00041 
00042 TColor RGBA2TColor(rgba c);
00043 
00044 rgb TColor2RGB(TColor c);
00045 
00046 //---------------------------------------------------------------------------
00047 
00053 class TLinePoint
00054 {
00055 
00056         private:
00057 
00063                 int _x;
00069                 int _y;
00073                 rgba _c;
00074                 bool _selected;
00075 
00079                 TColor _getTColor() { return RGBA2TColor(_c); }
00083                 void _setTColor(TColor c) { _c = TColor2RGBA(c); }
00084 
00085 
00086         public:
00087 
00091                 TLinePoint(const TLinePoint &p)
00092                 : _x(p._x),
00093                   _y(p._y),
00094                   _c(p._c),
00095                   _selected(false)
00096                 {}
00097 
00101                 TLinePoint(int x, int y)
00102                 : _x(x),
00103                   _y(y),
00104                   _c(TColor2RGBA(clBlack)),
00105                   _selected(false)
00106                 {}
00107 
00111                 TLinePoint(int x, int y, const TColor &c)
00112                 : _x(x),
00113                   _y(y),
00114                   _c(TColor2RGBA(c)),
00115                   _selected(false)
00116                 {}
00117 
00122                 TLinePoint(int x, int y, const rgba &c)
00123                 : _x(x),
00124                   _y(y),
00125                   _c(c)
00126                 {}
00127 
00131                 const TLinePoint &operator=(const TLinePoint &p);
00132 
00133 
00137                 __property int X = { read=_x, write=_x };
00141                 __property int Y = { read=_y, write=_y };
00145                 __property rgba C = { read=_c, write=_c };
00149                 __property TColor TC = { read=_getTColor, write=_setTColor };
00153                 __property bool Selected = { read=_selected, write=_selected };
00154 
00155 };
00156 
00163 class TLine
00164 {
00165 
00166         private:
00167 
00171                 TLinePoint _start;
00175                 TLinePoint _end;
00179                 bool _selected;
00183                 int _name;
00184 
00185                 THistogram *_histo;
00186                 int _distPoint; // Distance from cursor to a line end point
00187 
00192                 void __fastcall _drawMarker(TCanvas *c, TColor col,
00193                                             int x, int y, int width);
00197                 void __fastcall _drawCross(TCanvas *c, TColor col,
00198                                            int x, int y);
00199 
00200         public:
00201 
00205                 TLine(TLinePoint s, TLinePoint e,
00206                       THistogram *h, int pd, int name)
00207                 : _start(s),
00208                   _end(e),
00209                   _histo(h),
00210                   _distPoint(pd),
00211                   _name(name)
00212                 {}
00213 
00217                 TLine(TLine &l)
00218                 : _start(l._start),
00219                   _end(l._end),
00220                   _histo(l._histo),
00221                   _distPoint(l._distPoint),
00222                   _name(l._name)
00223                 {}
00224 
00228                 TLine(const TLine &l)
00229                 : _start(l._start),
00230                   _end(l._end),
00231                   _histo(l._histo),
00232                   _distPoint(l._distPoint),
00233                   _name(l._name)
00234                 {}
00235 
00236                 ~TLine()
00237                 {}
00238 
00242                 const TLine &operator=(const TLine &l)
00243                 {
00244                         if (&l != this) {
00245                                 _start = l._start;
00246                                 _end = l._end;
00247                                 _histo = l._histo;
00248                                 _distPoint = l._distPoint;
00249                                 _name = l._name;
00250                         }
00251                         return *this;
00252                 }
00253 
00254 
00258                 __property TLinePoint Start = { read=_start, write=_start };
00262                 __property TLinePoint End = { read=_end, write=_end };
00266                 __property bool Selected = { read=_selected, write=_selected };
00267 
00271                 __property int Name = { read=_name, write=_name };
00272 
00276                 int __fastcall getStartX(TPaintBox *pb);
00280                 int __fastcall getStartY(TPaintBox *pb);
00284                 int __fastcall getEndX(TPaintBox *pb);
00288                 int __fastcall getEndY(TPaintBox *pb);
00289                 int __fastcall getY(TPaintBox *pb, int x);
00290                 int __fastcall getX(TPaintBox *pb, int y);
00294                 float __fastcall getSlope(TPaintBox *pb);
00298                 bool __fastcall highSlope(TPaintBox *pb); // true if slope > 1;
00303                 bool __fastcall isNear(TPaintBox *pb, int x, int y); // true,
00304                                 // if distance to line is smaler than DEF_DIST
00305 
00306                 rgba __fastcall interpolate(float d);
00307 
00311                 void __fastcall drawTo(TPaintBox *pb);
00312 
00313 }; /* TLine */
00314 
00315 #define TTRANS_INIT_SIZE        10
00316 
00326 class TTransfer
00327 {
00328 
00329     private:
00330 
00334         int _size;
00338         int _hsize;
00342         int _fill;
00346         TLine **_lines;
00351         THistogram *_histo;
00356         TData **_TDataCache;
00360         TStringList *_areaNames;
00361 
00362         int _distance;  // Distance from cursor to line
00363         int _distPoint; // Distance from cursor to a line end point
00364         bool _dirty;    // indicates a change in the function
00365 
00366         void _resize(int s);
00370         void _addLine(TLine *l);
00374         void _insertLine(TLine *l, int pos);
00378         void _cleanTDataCache()
00379         {
00380                 for(int i=0; i<_hsize; ++i) {
00381                         if (_TDataCache[i]) delete _TDataCache[i];
00382                         _TDataCache[i] = 0;
00383                 }
00384         }
00385 
00389         bool _setupTDataCache(__int16 data)
00390         {
00391                 if (_dirty) {
00392                         _cleanTDataCache();
00393                         _dirty = false;
00394                 }
00395                 if (data <= _histo->size) {
00396                         if (!_TDataCache[data]) {
00397                                 int i = 0;
00398                                 while(_lines[i]->End.X<=data && i<_fill) i++;
00399                                 if (i>_fill) return false;
00400                                 int xs = _lines[i]->Start.X;
00401                                 int dx = _lines[i]->End.X - xs;
00402                                 int ys = _lines[i]->Start.Y;
00403                                 int dy = _lines[i]->End.Y - ys;
00404                                 float d = (float)dy/(float)dx;
00405                                 _TDataCache[data] = new TData;
00406                                 _TDataCache[data]->col = _lines[i]->interpolate((float)(data-xs)/(float)dx);
00407                                 _TDataCache[data]->col.a = ys+(int)((float)(data-xs)*d);
00408                                 _TDataCache[data]->name = _lines[i]->Name;
00409                         }
00410                         return true;
00411                 }
00412                 // We should not reach this, but if we do ...
00413                 return false;
00414         }
00415 
00416 public:
00420         TTransfer(THistogram *h)
00421         : _histo(h),
00422           _hsize(h->size),
00423           _distance(DEF_DIST),
00424           _distPoint(DEF_POINT_DIST),
00425           _dirty(true)
00426         {
00427                 _size = 0;
00428                 _fill = 0;
00429                 _lines = 0;
00430                 _addLine(new TLine(TLinePoint(0, 0, clBlack),
00431                                    TLinePoint(350, 0, clBlack),
00432                                    h, DEF_POINT_DIST, -1));
00433                 _addLine(new TLine(TLinePoint(350, 0, clBlack),
00434                                    TLinePoint(350, 10,
00435                                               (TColor)0xff0000),
00436                                    h, DEF_POINT_DIST, -1));
00437                 _addLine(new TLine(TLinePoint(350, 10,
00438                                               (TColor)0xff0000),
00439                                    TLinePoint(1200, 10,
00440                                               (TColor)0xff0000),
00441                                    h, DEF_POINT_DIST, -1));
00442                 _addLine(new TLine(TLinePoint(1200, 10,
00443                                               (TColor)0xff0000),
00444                                    TLinePoint(1200, 255,
00445                                               (TColor)0x0000ff),
00446                                    h, DEF_POINT_DIST, -1));
00447                 _addLine(new TLine(TLinePoint(1200, 255,
00448                                               (TColor)0x0000ff),
00449                                    TLinePoint(4096, 255,
00450                                               (TColor)0x0000ff),
00451                                    h, DEF_POINT_DIST, -1));
00452                 _TDataCache = new TData*[h->size];
00453                 for(int i=0; i<_histo->size; ++i) _TDataCache[i] = 0;
00454                 _areaNames = new TStringList();
00455                 _areaNames->Sorted = true;
00456         }
00457 
00461         ~TTransfer()
00462         {
00463                 for(int i=0; i<_fill; ++i) delete _lines[i];
00464                 delete [] _lines;
00465                 _cleanTDataCache();
00466                 delete [] _TDataCache;
00467         }
00468 
00469         __property int Distance = { read=_distance, write=_distance };
00470         __property int DistPoint = { read=_distance, write=_distance };
00471 
00475         __property int numLines = { read=_fill };
00479         __property bool Dirty = { write=_dirty };
00483         __property TStringList* areaNames = { read=_areaNames };
00484 
00489         int split(TPaintBox *pb, int x, int y);
00493         void clear();
00498         bool select(TPaintBox *pb, int x, int y);
00502         void select(int idx);
00506         void selectStart(int idx);
00510         void selectEnd(int idx);
00514         TLine *getSelected();
00518         int getSelIdx();
00522         TLine *getLine(int idx);
00526         void unselect();
00530         void drawTo(TPaintBox *pb);
00535         int __fastcall lineNear(TPaintBox *pb, int x, int y);
00540         bool __fastcall nearStart(int idx, TPaintBox *pb, int x, int y);
00545         bool __fastcall nearEnd(int idx, TPaintBox *pb, int x, int y);
00546 
00550         int __fastcall getName(double data);
00551 
00555         rgba __fastcall getColor(__int16 data);
00556 
00560         //TData __fastcall getData(__int16 data);
00561 
00565         TData __fastcall getData(double data);
00566 
00567 
00571         bool loadFromXLM(_di_IXMLNode doc);
00572 
00576         bool saveToXML(_di_IXMLNode doc);
00577 
00578 
00582         int addName(AnsiString &name);
00583 
00584 };
00585 
00586 #endif

Generated on Thu Jan 23 06:17:39 2003 for Vol by doxygen1.2.18