ctkTransferFunctionScene.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 __ctkTransferFunctionScene_h
00022 #define __ctkTransferFunctionScene_h
00023 
00025 #include <QGraphicsScene>
00026 
00028 #include "ctkPimpl.h"
00029 #include "ctkTransferFunction.h"
00030 #include "CTKWidgetsExport.h"
00031 
00032 //class ctkTransferFunction;
00033 class ctkTransferFunctionScenePrivate;
00034 //class ctkControlPoint;
00035 //class ctkPoint;
00036 
00037 //-----------------------------------------------------------------------------
00038 class CTK_WIDGETS_EXPORT ctkTransferFunctionScene: public QGraphicsScene
00039 {
00040   Q_OBJECT
00041   Q_PROPERTY(QColor VerticalGradientColor READ verticalGradientColor WRITE setVerticalGradientColor)
00042 
00043 public:
00044   ctkTransferFunctionScene(QObject* parent = 0);
00045   ctkTransferFunctionScene(ctkTransferFunction* transferFunction, QObject* parent = 0);
00046   virtual ~ctkTransferFunctionScene();
00047 
00048   void setTransferFunction(ctkTransferFunction* transferFunction);
00049   ctkTransferFunction* transferFunction()const;
00050 
00051   inline qreal posX(const ctkControlPoint* cp)const;
00052   inline qreal posY(const ctkControlPoint* cp)const;
00053   inline QColor color(const ctkControlPoint* cp) const;
00054 
00055   inline qreal posX(const ctkPoint& point)const;
00056   inline qreal posY(const ctkPoint& point)const;
00057   inline QColor color(const ctkPoint& point) const;
00058 
00059   qreal posX(const qreal& tfX)const;
00060   qreal posY(const QVariant& tfV)const;
00061   QColor color(const QVariant& tfV) const;
00062   
00063   QPointF mapPointToScene(const ctkControlPoint* cp)const;
00064   QPointF mapPointToScene(const ctkPoint& point)const;
00065   
00066  
00067   qreal mapXToScene(qreal posX)const;
00068   qreal mapYToScene(qreal posY)const;
00069   qreal mapXFromScene(qreal ScenePosX)const;
00070   qreal mapYFromScene(qreal ScenePosY)const;
00071   inline QPointF mapPointFromScene(const QPointF& point)const;
00072 
00073   QList<ctkPoint> bezierParams(ctkControlPoint* start, ctkControlPoint* end) const;
00074   QList<ctkPoint> nonLinearPoints(ctkControlPoint* start, ctkControlPoint* end) const;
00075 
00076   const QPainterPath& curve()const;
00077   const QList<QPointF>& points()const;
00078   const QGradient& gradient()const;
00079 
00080   void computeCurve();
00081   void computeGradient();
00082 
00083   QColor verticalGradientColor()const;
00084   void setVerticalGradientColor(QColor verticalGradientColor);
00085 
00086 protected slots:
00087   virtual void onTransferFunctionChanged();
00088 
00089 protected:
00090   qreal computeRangeXDiff(const QRectF& rect, qreal rangeX[2]);
00091   qreal computeRangeXOffset(qreal rangeX[2]);
00092   qreal computeRangeYDiff(const QRectF& rect, const QVariant rangeY[2]);
00093   qreal computeRangeYOffset(const QVariant rangeY[2]);
00094 private:
00095   CTK_DECLARE_PRIVATE(ctkTransferFunctionScene);
00096 };
00097 
00098 qreal ctkTransferFunctionScene::posX(const ctkControlPoint* cp)const
00099 {
00100   return this->posX(cp->x());
00101 }
00102 qreal ctkTransferFunctionScene::posY(const ctkControlPoint* cp)const
00103 {
00104   return this->posY(cp->value());
00105 }
00106 QColor ctkTransferFunctionScene::color(const ctkControlPoint* cp) const
00107 {
00108   return this->color(cp->value());
00109 }
00110 
00111 qreal ctkTransferFunctionScene::posX(const ctkPoint& point)const
00112 {
00113   return this->posX(point.X);
00114 }
00115 qreal ctkTransferFunctionScene::posY(const ctkPoint& point)const
00116 {
00117   return this->posY(point.Value);
00118 }
00119 QColor ctkTransferFunctionScene::color(const ctkPoint& point) const
00120 {
00121   return this->color(point.Value);
00122 }
00123 
00124 QPointF ctkTransferFunctionScene::mapPointFromScene(const QPointF& point)const
00125 {
00126   return QPointF(this->mapXFromScene(point.x()),
00127                  this->mapYFromScene(point.y()));
00128 }
00129 
00130 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1