arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

TFView.cpp

Go to the documentation of this file.
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 
00019 ///TFView.cpp
00020 ///  simianUI
00021 
00022 #include <qcanvas.h>
00023 #include <qwmatrix.h>
00024 #include "TFView.h"
00025 #include <iostream>
00026 
00027 #include "TFItemSTD.h"
00028 #include "CanvasItems.h"
00029 
00030 using namespace std;
00031 using namespace gutz;
00032 
00033 //////////////////////////////////////////////////////////////////////////
00034 /// Construct
00035 //////////////////////////////////////////////////////////////////////////
00036 TFView::TFView(QCanvas *canvas, QWidget *parent, const char *name, WFlags wf)
00037 : QCanvasView(canvas, parent, name, wf), _picked(0), _items(canvas, TFBaseSP())
00038 {
00039 #if 0
00040 #if 0
00041    PolygonEdit* p = new PolygonEdit(canvas);
00042    const int size = canvas->width()/2;
00043    QPointArray pa(6);
00044    pa[0] = QPoint(0,0);
00045    pa[1] = QPoint(size,size/5);
00046    pa[2] = QPoint(size*4/5,size);
00047    pa[3] = QPoint(size/6,size*5/4);
00048    pa[4] = QPoint(size*3/4,size*3/4);
00049    pa[5] = QPoint(size*3/4,size/4);
00050    p->setPoints(pa);
00051    p->setPen( QColor(rand()%32*8,rand()%32*8,rand()%32*8) );
00052    p->move(rand()%canvas->width(),rand()%canvas->height());
00053    //p->setZ(rand()%256);
00054    p->show();
00055 #else
00056    TFElementBox *btf = new TFElementBox(TFElementBox::PosType(canvas->width()/2.0), 
00057                                         TFElementBox::PosType(canvas->width()/2.0));
00058    TFEltSP belt = new TFElt(btf);
00059    TFBoxItem *bi = new TFBoxItem(canvas,belt);
00060 #endif
00061 
00062 #else
00063 
00064 //   TFElementBox *btf = new TFElementBox(TFElementBox::PosType(canvas->width()/2.0), 
00065 //                                        TFElementBox::PosType(canvas->width()/2.0));
00066    TFElementBox *btf = new TFElementBox(TFElementBox::PosType(.5), 
00067                                         TFElementBox::PosType(.5));
00068 
00069    TFElementBox::tfVec2 p(.5,.5);
00070    cerr << " eval at .5, .5 = " << btf->eval(p, vec2i(0,1)) << endl;;
00071    p.x = .45f;
00072    cerr << " eval at .45, .5 = " << btf->eval(p, vec2i(0,1)) << endl;
00073    p.x = .33f;
00074    cerr << " eval at .33, .5 = " << btf->eval(p, vec2i(0,1)) << endl;
00075    p.x = .26f;
00076    cerr << " eval at .26, .5 = " << btf->eval(p, vec2i(0,1)) << endl;
00077    p.x = .25f;
00078    cerr << " eval at .25, .5 = " << btf->eval(p, vec2i(0,1)) << endl;
00079 
00080 
00081    //TFEltSP belt = new TFElt(btf);
00082    //TFBoxItem *bi = new TFBoxItem(canvas,belt);
00083 
00084    TFBaseSP tf;
00085    tf->addTFElement(btf);
00086    _items.setTF(tf);
00087 
00088    _tf = tf;
00089 
00090    TFImageSP im = tf->get2DMap(vec2i(0,1));
00091 
00092    cerr << "the map at .5,.5 = " << im->v(3,128,128) << endl;
00093 
00094 #endif
00095 }
00096 
00097 //////////////////////////////////////////////////////////////////////////
00098 /// Destruct
00099 //////////////////////////////////////////////////////////////////////////
00100 TFView::~TFView()
00101 {
00102 
00103 }
00104 
00105 
00106 //////////////////////////////////////////////////////////////////////////
00107 /// Set Volume
00108 //////////////////////////////////////////////////////////////////////////
00109 void TFView::setVolume(VolumeSP vol)
00110 {
00111    _items.update();
00112 }
00113 
00114 
00115 //////////////////////////////////////////////////////////////////////////
00116 /// contents Mouse Press Event
00117 //////////////////////////////////////////////////////////////////////////
00118 typedef QValueListIterator<QCanvasItem*> CanvasItemListIter;
00119 
00120 void TFView::contentsMousePressEvent(QMouseEvent *e)
00121 {
00122    //cerr << " Hi mouse press " << endl;
00123 
00124    QPoint p = inverseWorldMatrix().map(e->pos());
00125    QCanvasItemList l=canvas()->collisions(p);
00126    for (CanvasItemListIter li = l.begin(); li!=l.end(); ++li) 
00127    {
00128       _picked = *li;
00129       //_picked->setPen(CID::PENS[CID::PICKED]);
00130       _lastPoint = p;
00131       return;
00132    }
00133    _picked = 0;
00134 }
00135 
00136 //////////////////////////////////////////////////////////////////////////
00137 /// contents Mouse Move Event
00138 //////////////////////////////////////////////////////////////////////////
00139 void TFView::contentsMouseMoveEvent(QMouseEvent *e)
00140 {
00141    if ( _picked ) 
00142    {
00143       //cerr << " move ****************** "  << endl;
00144       QPoint p = inverseWorldMatrix().map(e->pos());
00145       _picked->moveBy(p.x() - _lastPoint.x(),
00146                       p.y() - _lastPoint.y());
00147       _lastPoint = p;
00148       canvas()->update();
00149       TFImageSP i = _tf->get2DMap(gutz::vec2i(0,1));
00150       //cerr << " end move ****************** "  << endl;
00151    }
00152 }
00153 
00154 //////////////////////////////////////////////////////////////////////////
00155 /// set TF
00156 //////////////////////////////////////////////////////////////////////////
00157 void TFView::setTF(TFBaseSP tf)
00158 {
00159    _items.setTF(tf);
00160    canvas()->update();
00161 }
00162 
00163 //////////////////////////////////////////////////////////////////////////
00164 /// resize event
00165 //////////////////////////////////////////////////////////////////////////
00166 void TFView::resizeEvent(QResizeEvent *re)
00167 {
00168    cerr << "view resize" << endl;
00169    /// TODO: this should be handled externally!!!
00170    canvas()->resize(re->size().width(), re->size().height());
00171    _items.update(); 
00172    canvas()->update();
00173 }
00174 

Send questions, comments, and bug reports to:
jmk