ctkTransferFunctionItems.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Library:   CTK
00004  
00005   Copyright (c) 2010  Kitware Inc.
00006 
00007   Licensed under the Apache License, Version 2.0 (the "License");
00008   you may not use this file except in compliance with the License.
00009   You may obtain a copy of the License at
00010 
00011       http://www.commontk.org/LICENSE
00012 
00013   Unless required by applicable law or agreed to in writing, software
00014   distributed under the License is distributed on an "AS IS" BASIS,
00015   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016   See the License for the specific language governing permissions and
00017   limitations under the License.
00018  
00019 =========================================================================*/
00020 
00021 #ifndef __ctkTransferFunctionItems_h
00022 #define __ctkTransferFunctionItems_h
00023 
00025 #include <QGraphicsObject>
00026 
00028 #include "CTKWidgetsExport.h"
00029 #include "ctkPimpl.h"
00030 #include "ctkTransferFunction.h"
00031 
00032 class ctkControlPoint;
00033 class ctkTransferFunctionItemPrivate;
00034 //class ctkTransferFunctionGradientItemPrivate;
00035 class ctkTransferFunctionControlPointsItemPrivate;
00036 
00039 class CTK_WIDGETS_EXPORT ctkTransferFunctionItem: public QGraphicsObject
00040 {
00041   Q_OBJECT
00042 public:
00043   ctkTransferFunctionItem(QGraphicsItem* parent = 0);
00044   ctkTransferFunctionItem(ctkTransferFunction* transferFunction, 
00045                                   QGraphicsItem* parent = 0);
00046   virtual ~ctkTransferFunctionItem();
00047 
00048   void setTransferFunction(ctkTransferFunction* transferFunction);
00049   ctkTransferFunction* transferFunction()const;
00050 
00051   inline void setRect(qreal x, qreal y, qreal width, qreal height);
00052   void setRect(const QRectF& rectangle);
00053   QRectF rect()const;
00054   virtual QRectF boundingRect()const;
00055 protected:
00056   qreal y(const QVariant& value)const;
00057   inline qreal y(const ctkPoint& point)const;
00058 
00059   QColor color(const QVariant& value)const;
00060   inline QColor color(const ctkPoint& point)const;
00061 
00062 
00063 
00064   QList<ctkPoint> bezierParams(ctkControlPoint* start, ctkControlPoint* end)const;
00065   QList<ctkPoint> nonLinearPoints(ctkControlPoint* start, ctkControlPoint* end)const;
00066 protected slots:
00067   virtual void onTransferFunctionChanged();
00068 private:
00069   CTK_DECLARE_PRIVATE(ctkTransferFunctionItem);
00070 };
00071 
00072 void ctkTransferFunctionItem::setRect(qreal x, qreal y, qreal width, qreal height)
00073 {
00074   this->setRect(QRectF(x,y,width,height));
00075 }
00076 
00077 qreal ctkTransferFunctionItem::y(const ctkPoint& p)const
00078 {
00079   return this->y(p.Value);
00080 }
00081 
00082 QColor ctkTransferFunctionItem::color(const ctkPoint& p)const
00083 {
00084   return this->color(p.Value);
00085 }
00086 
00087 
00088 //-----------------------------------------------------------------------------
00089 class CTK_WIDGETS_EXPORT ctkTransferFunctionGradientItem: public ctkTransferFunctionItem
00090 {
00091   Q_OBJECT
00092 public:
00093   ctkTransferFunctionGradientItem(QGraphicsItem* parent = 0);
00094   ctkTransferFunctionGradientItem(ctkTransferFunction* transferFunction, 
00095                                   QGraphicsItem* parent = 0);
00096   virtual ~ctkTransferFunctionGradientItem();
00097 
00098   virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
00099 };
00100 
00101 
00102 //-----------------------------------------------------------------------------
00103 class CTK_WIDGETS_EXPORT ctkTransferFunctionControlPointsItem: public ctkTransferFunctionItem
00104 {
00105   Q_OBJECT
00106 public:
00107   explicit ctkTransferFunctionControlPointsItem(QGraphicsItem* parent = 0);
00108   ctkTransferFunctionControlPointsItem(ctkTransferFunction* transferFunction, 
00109                                        QGraphicsItem* parent = 0);
00110   virtual ~ctkTransferFunctionControlPointsItem();
00111 
00112   virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
00113 protected:
00114   virtual void mousePressEvent(QGraphicsSceneMouseEvent* e);
00115   virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* e);
00116   virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* e);
00117 private:
00118   CTK_DECLARE_PRIVATE(ctkTransferFunctionControlPointsItem);
00119 };
00120 
00121 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines