ctkTransferFunction.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 __ctkTransferFunction_h
00022 #define __ctkTransferFunction_h
00023 
00025 #include <QObject>
00026 #include <QtGlobal>
00027 #include <QSharedPointer>
00028 #include <QVariant>
00029 
00031 #include "CTKCoreExport.h"
00032 
00033 //-----------------------------------------------------------------------------
00034 struct CTK_CORE_EXPORT ctkPoint
00035 {
00036   ctkPoint(){}
00037   ctkPoint(qreal x, const QVariant& v)
00038     :X(x),Value(v)
00039   {  
00040   }
00041   qreal X;
00042   // QColor or qreal.
00043   QVariant Value;
00044 };
00045 
00046 //-----------------------------------------------------------------------------
00049 struct CTK_CORE_EXPORT ctkControlPoint
00050 {
00051   virtual ~ctkControlPoint();
00052   inline const qreal& x()const {return this->P.X;}
00053   inline const QVariant& value()const {return this->P.Value;}
00054   ctkPoint P;
00055 };
00056 
00057 //-----------------------------------------------------------------------------
00058 struct CTK_CORE_EXPORT ctkBezierControlPoint : public ctkControlPoint
00059 {
00060   virtual ~ctkBezierControlPoint();
00061   ctkPoint P1;
00062   ctkPoint P2;
00063 };
00064 
00065 //-----------------------------------------------------------------------------
00066 struct CTK_CORE_EXPORT ctkNonLinearControlPoint : public ctkControlPoint
00067 {
00068   virtual ~ctkNonLinearControlPoint();
00069   QList<ctkPoint> SubPoints;
00070 };
00071 
00072 //-----------------------------------------------------------------------------
00073 class CTK_CORE_EXPORT ctkTransferFunction: public QObject
00074 {
00075   Q_OBJECT
00076 public:
00077   ctkTransferFunction(QObject* parent = 0);
00078   virtual ~ctkTransferFunction();
00079   
00080   virtual ctkControlPoint* controlPoint(int index)const = 0;
00081   inline QVariant value(int index)const;
00082   virtual QVariant value(qreal pos)const = 0;
00083   
00084   virtual int count()const = 0;
00085   virtual bool isDiscrete()const = 0;
00086   virtual bool isEditable()const = 0;
00087 
00088   inline void range(qreal rangeValues[2])const;
00089   virtual void range(qreal& minRange, qreal& maxRange)const=0;
00090   virtual QVariant minValue()const = 0;
00091   virtual QVariant maxValue()const = 0;
00092   inline void valueRange(QVariant range[2])const;
00094   virtual int insertControlPoint(const ctkControlPoint& cp) = 0;
00095   virtual int insertControlPoint(qreal pos) = 0;
00096 
00100   virtual void setControlPointPos(int index, qreal pos)=0;
00104   virtual void setControlPointValue(int index, const QVariant& value)=0;
00105 signals:
00106   void changed();
00107 };
00108 
00109 //-----------------------------------------------------------------------------
00110 QVariant ctkTransferFunction::value(int index)const
00111 {
00112   QSharedPointer<ctkControlPoint> cp(this->controlPoint(index));
00113   return cp->P.Value;
00114 }
00115 
00116 //-----------------------------------------------------------------------------
00117 void ctkTransferFunction::range(qreal rangeValues[2])const
00118 {
00119   this->range(rangeValues[0], rangeValues[1]);
00120 }
00121 
00122 //-----------------------------------------------------------------------------
00123 void ctkTransferFunction::valueRange(QVariant rangeValues[2])const
00124 {
00125   rangeValues[0] = this->minValue();
00126   rangeValues[1] = this->maxValue();
00127 }
00128 
00129 #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