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   inline void range(qreal rangeValues[2])const;
00086   virtual void range(qreal& minRange, qreal& maxRange)const=0;
00087   virtual QVariant minValue()const = 0;
00088   virtual QVariant maxValue()const = 0;
00090   virtual int insertControlPoint(const ctkControlPoint& cp) = 0;
00091 
00095   virtual void setControlPointPos(int index, qreal pos)=0;
00099   virtual void setControlPointValue(int index, const QVariant& value)=0;
00100   virtual ctkBezierControlPoint* toto();
00101 signals:
00102   void changed();
00103 };
00104 
00105 //-----------------------------------------------------------------------------
00106 QVariant ctkTransferFunction::value(int index)const
00107 {
00108   QSharedPointer<ctkControlPoint> cp(this->controlPoint(index));
00109   return cp->P.Value;
00110 }
00111 
00112 //-----------------------------------------------------------------------------
00113 void ctkTransferFunction::range(qreal rangeValues[2])const
00114 {
00115   this->range(rangeValues[0], rangeValues[1]);
00116 }
00117 
00118 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines