Eigene Dateien/Vis/src/VTransferFunction.h

Go to the documentation of this file.
00001 #pragma once
00002 
00003 #ifndef __v_transfer_function_h
00004 #define __v_transfer_function_h
00005 
00006 #include <map>
00007 #include <vector>
00008 
00009 #include "VVector.h"
00010 #include "VFramebufferObject.h"
00011 
00012 class QVolRendCanvas;
00013 
00017 struct vTransferFunctionPoint
00018 {
00019         vTransferFunctionPoint() : m_Color(), m_Alpha(1.0f)
00020         {
00021 
00022         }
00023 
00024         VVector m_Color;        
00025         float m_Alpha;          
00026 };
00027 
00032 class VTransferFunction
00033 {
00034 public:
00035 
00039         VTransferFunction() :   m_VolumeHistogram(0), 
00040                                                         m_VolumeHistogramDisplayList(0), 
00041                                                         m_hasChanged(true), 
00042                                                         bigzoom(true),
00043                                                         m_TransferFunctionHandle(0), 
00044                                                         m_FramebufferObject(NULL)
00045         {
00046                 
00047         }
00048 
00052         ~VTransferFunction();
00053 
00057         void draw1d();
00058 
00063         void setHistogram(std::vector<int> * volumeHistogram)
00064         {
00065                 this->clear();
00066                 m_VolumeHistogram = volumeHistogram;
00067                 generateDisplayList();
00068         }
00069 
00076         void setZoomPoint(bool zoom_active, float x, bool bigcanvas)
00077         {
00078                 zoom_ptx = x;
00079                 m_zoom_active = zoom_active;
00080                 bigzoom = !bigcanvas;
00081 
00082         }
00083 
00089         float getAlpha(int index)
00090         {
00091                 return m_FuncControlPoints[index].m_Alpha;
00092         }
00093 
00094 
00100         void addTransferFunctionPoint(int density, vTransferFunctionPoint newPoint);
00101 
00109         int transferFunctionPointInRange(int selectedDensity, float alpha, int range)
00110         {
00111                 int searchStart;
00112                 int searchEnd;
00113                 if(selectedDensity - range < 0)
00114                 {
00115                         searchStart = 0;
00116                 }
00117                 else
00118                 {
00119                         searchStart = selectedDensity - range;
00120                 }
00121                 if((selectedDensity + range) > 4095)
00122                 {
00123                         searchEnd = 4095;
00124                 }
00125                 else 
00126                 {
00127                         searchEnd = selectedDensity + range;
00128                 }
00129 
00130                 float a_range = 5.0f*(float)range/4095.0f;
00131                 alpha = (alpha+0.8f)/1.8f;
00132                 alpha = (alpha-a_range < 0.0f) ? 0.0f :alpha;
00133                 alpha = (alpha+a_range > 1.0f) ? 1.0f :alpha;
00134 
00135                 int position = selectedDensity;
00136                 int upperbound  = max( (searchEnd - position), (position - searchStart));
00137                 for(int i = 0; i <= upperbound; i++)
00138                 {
00139                         position = selectedDensity - i;
00140 
00141                         if( position >= searchStart && 
00142                                 m_FuncControlPoints.find( position ) != m_FuncControlPoints.end() && 
00143                                 abs( m_FuncControlPoints[ position ].m_Alpha - alpha) < a_range )
00144                         {
00145                                 return position;
00146                                 
00147                         }
00148 
00149                         position = selectedDensity + i;
00150 
00151                         if( position >= searchStart && 
00152                                 m_FuncControlPoints.find(position) != m_FuncControlPoints.end() &&
00153                                 abs(m_FuncControlPoints[position].m_Alpha - alpha) < a_range )
00154                         {
00155                                 return position;
00156                         }
00157                 }
00158 
00159                 
00160 
00161                 
00162                 return -1;
00163         }
00164 
00169         vTransferFunctionPoint getTransferFunctionPoint(int density)
00170         {
00171                 return m_FuncControlPoints[density];
00172         }
00173 
00178         void removeTransferFunctionPoint(int density);
00179 
00184         std::vector<vTransferFunctionPoint> getFullTransferFunction()
00185         {
00186                 if(m_hasChanged)
00187                 {
00188                         this->interpolateTransferPoints();
00189                 }
00190                 return m_TransferFunction;
00191         }
00192 
00197         unsigned int getGLHandle()
00198         {
00199                 if(m_hasChanged)
00200                 {
00201                         this->interpolateTransferPoints();
00202                 }
00203                 return m_FramebufferObject->getTextureHandle();
00204                 //return m_TransferFunctionHandle;
00205         }
00206 
00211         void setMainCanvas(QVolRendCanvas * maincanvas)
00212         {
00213                 m_MainCanvas = maincanvas;
00214         }
00215 
00220         void setMaxHist(float val)
00221         {
00222                 m_maxdensity = val;
00223         }
00224         
00229         bool load(std::string filename);
00230 
00235         bool save(std::string filename);
00236 
00240         void clear()
00241         {
00242                 m_FuncControlPoints.clear();
00243                 m_TransferFunction.clear();
00244                 m_TransferFunctionHandle = 0;
00245                 m_hasChanged =  true;
00246         }
00247 
00248 private:
00249         
00253         void generateDisplayList();
00254         void generateDisplayList2D();
00255 
00259         void interpolateTransferPoints();
00260 
00267         double round(double Zahl, int Stellen)
00268         {
00269                 double v[] = { 1, 10, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8 };  // mgl. verlängern
00270                 return floor(Zahl * v[Stellen] + 0.5) / v[Stellen];
00271         }
00272 
00273         std::map<int, vTransferFunctionPoint> m_FuncControlPoints;      
00274         std::vector<vTransferFunctionPoint> m_TransferFunction;                 
00275         std::vector<int> * m_VolumeHistogram;                                                   
00276         unsigned int m_VolumeHistogramDisplayList;                                              
00278         unsigned int m_TransferFunctionHandle;                                                  
00280         bool m_hasChanged;                                                                                              
00281         QVolRendCanvas * m_MainCanvas;                                                                  
00282         float m_maxdensity;                                                                                             
00284         VFramebufferObject * m_FramebufferObject;                                               
00286         float zoom_ptx;                                                                                                 
00287         bool m_zoom_active;                                                                                             
00288         bool bigzoom;                                                                                                   
00289 };
00290 
00291 #endif //__v_transfer_function_h

Generated on Wed Dec 5 05:15:09 2007 for VolRendering by  doxygen 1.5.4