Sfoglia il codice sorgente

ENH: Add ctkTransferFunction

Julien Finet 15 anni fa
parent
commit
76e0f83299

+ 3 - 0
Libs/Core/CMakeLists.txt

@@ -60,6 +60,8 @@ SET(KIT_SRCS
   ctkModelTester.cpp
   ctkModelTester.h
   ctkPimpl.h
+  ctkTransferFunction.cpp
+  ctkTransferFunction.h
   ctkUtils.cpp
   ctkUtils.h
   )
@@ -74,6 +76,7 @@ ENDIF()
 # Headers that should run through moc
 SET(KIT_MOC_SRCS
   ctkModelTester.h
+  ctkTransferFunction.h
   )
 
 # UI files

+ 32 - 0
Libs/Core/ctkTransferFunction.cpp

@@ -0,0 +1,32 @@
+/*=========================================================================
+
+  Library:   ctk
+
+  Copyright (c) Kitware Inc. 
+  All rights reserved.
+  Distributed under a BSD License. See LICENSE.txt file.
+
+  This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the above copyright notice for more information.
+
+=========================================================================*/
+/// CTK includes
+#include "ctkTransferFunction.h"
+
+//-----------------------------------------------------------------------------
+ctkTransferFunction::ctkTransferFunction(QObject* parentObject)
+  :QObject(parentObject)
+{
+}
+
+//-----------------------------------------------------------------------------
+ctkTransferFunction::~ctkTransferFunction()
+{
+  // foreach(ctkControlPoint* cp, this->ControlPoints)
+  //   {
+  //   delete cp;
+  //   }
+  // this->ControlPoints->clear();
+  // emit changed();
+}

+ 93 - 0
Libs/Core/ctkTransferFunction.h

@@ -0,0 +1,93 @@
+/*=========================================================================
+
+  Library:   ctk
+
+  Copyright (c) Kitware Inc. 
+  All rights reserved.
+  Distributed under a BSD License. See LICENSE.txt file.
+
+  This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the above copyright notice for more information.
+
+=========================================================================*/
+
+#ifndef __ctkTransferFunction_h
+#define __ctkTransferFunction_h
+
+/// Qt includes
+#include <QObject>
+#include <QtGlobal>
+#include <QSharedPointer>
+#include <QVariant>
+
+/// CTK includes
+#include "CTKCoreExport.h"
+
+/// assumes the mapping is linear by default, if not, then subclasses must be 
+/// used
+//-----------------------------------------------------------------------------
+struct ctkControlPoint
+{
+  virtual ~ctkControlPoint(){}
+  // QColor or qreal.
+  QVariant Value;
+  qreal    Pos;
+};
+
+//-----------------------------------------------------------------------------
+struct ctkBezierControlPoint : public ctkControlPoint
+{
+  qreal P1;
+  QVariant ValueP1;
+  qreal P2;
+  QVariant ValueP2;
+};
+
+//-----------------------------------------------------------------------------
+class CTK_CORE_EXPORT ctkTransferFunction: public QObject
+{
+  Q_OBJECT
+public:
+  ctkTransferFunction(QObject* parent = 0);
+  virtual ~ctkTransferFunction();
+  
+  virtual ctkControlPoint* controlPoint(int index)const =0;
+  inline QVariant value(int index)const;
+  virtual QVariant value(qreal pos)const =0;
+  
+  virtual int count()const = 0;
+  inline void range(qreal rangeValues[2])const;
+  virtual void range(qreal& minRange, qreal& maxRange)const=0;
+  virtual QVariant minValue()const = 0;
+  virtual QVariant maxValue()const = 0;
+  ///
+  virtual int insertControlPoint(const ctkControlPoint& cp) = 0;
+
+  /// 
+  /// be careful with it, as changing the value might require
+  /// more changes to ctkControlPoint.
+  virtual void setControlPointPos(int index, qreal pos)=0;
+  /// 
+  /// be careful with it, as changing the value might require
+  /// more changes to ctkControlPoint.
+  virtual void setControlPointValue(int index, const QVariant& value)=0;
+
+signals:
+  void changed();
+};
+
+//-----------------------------------------------------------------------------
+QVariant ctkTransferFunction::value(int index)const
+{
+  QSharedPointer<ctkControlPoint> cp(this->controlPoint(index));
+  return cp->Value;
+}
+
+//-----------------------------------------------------------------------------
+void ctkTransferFunction::range(qreal rangeValues[2])const
+{
+  this->range(rangeValues[0], rangeValues[1]);
+}
+
+#endif