Eigene Dateien/FlowVis/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         unsigned int getGLHandle()
00185         {
00186                 if(m_hasChanged)
00187                 {
00188                         this->interpolateTransferPoints();
00189                 }
00190                 return m_FramebufferObject->getTextureHandle();
00191                 //return m_TransferFunctionHandle;
00192         }
00193 
00198         void setMainCanvas(QVolRendCanvas * maincanvas)
00199         {
00200                 m_MainCanvas = maincanvas;
00201         }
00202 
00207         void setMaxHist(float val)
00208         {
00209                 m_maxdensity = val;
00210         }
00211         
00216         bool load(std::string filename);
00217 
00222         bool save(std::string filename);
00223 
00227         void clear()
00228         {
00229                 m_FuncControlPoints.clear();
00230                 m_TransferFunction.clear();
00231                 m_TransferFunctionHandle = 0;
00232                 m_hasChanged =  true;
00233         }
00234 
00235         void renderTest()
00236         {
00237                 if(m_FramebufferObject)
00238                         m_FramebufferObject->renderToLowerLeftQuad();
00239         }
00240 
00241 private:
00242         
00246         void generateDisplayList();
00247 
00251         void interpolateTransferPoints();
00252 
00259         double round(double Zahl, int Stellen)
00260         {
00261                 double v[] = { 1, 10, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8 };  // mgl. verlängern
00262                 return floor(Zahl * v[Stellen] + 0.5) / v[Stellen];
00263         }
00264 
00265         std::map<int, vTransferFunctionPoint> m_FuncControlPoints;      
00266         std::vector<vTransferFunctionPoint> m_TransferFunction;                 
00267         //std::vector<int> * m_VolumeHistogram;                                                 /**< Histogram of Volume. */
00268         unsigned int m_VolumeHistogramDisplayList;                                              
00270         unsigned int m_TransferFunctionHandle;                                                  
00272         bool m_hasChanged;                                                                                              
00273         QVolRendCanvas * m_MainCanvas;                                                                  
00274         float m_maxdensity;                                                                                             
00276         VFramebufferObject * m_FramebufferObject;                                               
00278         float zoom_ptx;                                                                                                 
00279         bool m_zoom_active;                                                                                             
00280         bool bigzoom;                                                                                                   
00281 };
00282 
00283 #endif //__v_transfer_function_h

Generated on Mon Jan 21 01:15:16 2008 for FlowVis by  doxygen 1.5.4