00001 #ifndef TransferFunction_H 00002 #define TransferFunction_H 00003 00004 #include <QWidget> 00005 #include <QScrollArea> 00006 #include <QColor> 00007 #include <QString> 00008 #include <set> 00009 #include "Volume.h" 00010 #include "TimeCounter.h" 00011 00012 class TransferFunction : public QWidget 00013 { 00014 Q_OBJECT 00015 00016 public: 00017 TransferFunction(QWidget *parent = 0); 00018 ~TransferFunction(); 00019 void timerEvent(QTimerEvent *event); 00020 void paintEvent(QPaintEvent* event); 00021 void TransferFunction::mousePressEvent(QMouseEvent* event); 00022 void mouseDoubleClickEvent(QMouseEvent* event); 00023 void mouseMoveEvent(QMouseEvent* event); 00024 void mouseReleaseEvent(QMouseEvent * event); 00025 QSize sizeHint() const; 00026 int width() const; 00027 void updateSize(); 00028 void updateTransferfunction(); 00029 00030 public slots: 00031 virtual void update(); 00032 void setVolume(Volume *volume); 00033 void setZoomFactor(int value); 00034 void loadTfFile(); 00035 void saveTfFile(); 00036 00037 signals: 00038 void getTransferFunction(unsigned int* transferFunction, int length); 00039 00040 private: 00041 void initHisto(); 00042 void initTransferfunction(); 00043 void updateScale(); 00044 00045 bool updateAsked; 00046 int timerIdentifier; 00047 00048 Volume *volume; 00049 QWidget *parent; 00050 int widthMax, scaledWidth, height, zoomFactor; 00051 double scaleFactor; 00052 unsigned int* normHistoVals; 00053 unsigned int* normScaledHistoVals; 00054 int marginBottom, marginRight; 00055 QString curDir; 00056 00057 struct TransferColor 00058 { 00059 unsigned char a, b, g, r; 00060 }; 00061 00062 TransferColor* transferFunction; 00063 00064 class Vertex 00065 { 00066 public: 00067 Vertex(); 00068 Vertex(int x, int xScaled, QColor color); 00069 ~Vertex(); 00070 void drawVertex(QPainter& painter); 00071 void setPos(int x, int xScaled, int y); 00072 int x, xScaled; 00073 QColor color; 00074 bool selected; 00075 static const unsigned short int DRAW_SIZE = 7; 00076 }; 00077 00078 struct lessThanVertex 00079 { 00080 bool operator()(Vertex *v1, Vertex *v2) const 00081 { 00082 return v1->x < v2->x; 00083 } 00084 }; 00085 00086 std::set<Vertex*, lessThanVertex> vertices; 00087 std::set<Vertex*, lessThanVertex> selectedVertices; 00088 void unselectAllVertices(); 00089 Vertex* addVertex(int xScaled, int y); 00090 Vertex* addVertex(int scaledX, QColor color); 00091 void addVertex(Vertex* v); 00092 void removeVertex(Vertex* v); 00093 Vertex* newVertex(int xScaled, int alpha); 00094 void select(Vertex *v); 00095 void unselect(Vertex* v); 00096 bool containsVertex(Vertex *v); 00097 void removeAllVertices(); 00098 std::set<Vertex*, lessThanVertex>::iterator containsNearVertex(Vertex *v); 00099 std::set<Vertex*, lessThanVertex>::iterator movingVertex; 00100 typedef std::set<Vertex*, lessThanVertex>::iterator IteratorVertices; 00101 }; 00102 00103 00104 00105 #endif // Volume_H