Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

mitkFDKSpeedUsingGpu.h

00001 /*=========================================================================
00002 
00003   Program:   3DMed
00004   Date:      $Date: 2014-02-25 18:30:00 +0800 $
00005   Version:   $Version: 4.6.0 $
00006   Copyright: MIPG, Institute of Automation, Chinese Academy of Sciences
00007 
00008 =========================================================================*/
00009 
00010 
00011 #ifndef __mitkFDKSpeedUsingGpu_h
00012 #define __mitkFDKSpeedUsingGpu_h
00013 
00014 #include <math.h>
00015 #include <vector>
00016 
00017 #include <GL/glew.h>
00018 #include <GL/glut.h>
00019 #include <Cg/cgGL.h>
00020 #include "mitkProjectDataToVolumeFilter.h"
00021 #include "mitkConeBeamProjectData.h"
00022 #include "mitkVolume.h"
00023 #include "mitkICVolume.h"
00024 #include "mitkOoCVolume.h"
00025 #include "mitkReconstructionCGIncludes.h"
00026 
00027 #include "mitkSIMD.h"
00028 #include <math.h>
00029 
00030 #ifdef USE_SIMD
00031 #pragma pack(push,16)    /* Must ensure class & union 16-B aligned */
00032 #endif
00033 
00034 #define PI 3.14159265358979
00035 #define TEXTURECHANNEL 8
00036 #define COLORATTACHMENTNUM 2
00037 #define WINDOWSIZE 8
00041 // using GPU for acceleration, and NVIDIA card is required,  and 8800series or up is better.
00042 // ************************************************************************************************
00043 // This implementation is not our fasted version, if you want to get the fasted one, please mail to
00044 // tian@ieee.org
00045 
00046 
00047 class MITK_RECONSTRUCTION_CG_API mitkFDKSpeedUsingGpu : public mitkProjectDataToVolumeFilter  
00048 {
00049 public:
00050 
00051     template<class Ty>  friend int  t_ExecuteFDKSpeedUsingGpu(mitkConeBeamProjectData *input,mitkVolume *outdata,mitkFDKSpeedUsingGpu *self, Ty *a);
00052 
00053     MITK_TYPE(mitkFDKSpeedUsingGpu , mitkProjectDataToVolumeFilter)
00054     
00055     virtual void PrintSelf(ostream& os);
00056 
00057     mitkFDKSpeedUsingGpu();
00058 
00059     void SetFov(float m[6]);
00060 
00061     void SetVolumeBlockNum(int m) { volumeBlockNum = m;}
00062 
00063     int GetVolumeBlockNum(){return volumeBlockNum;}
00064 
00065 protected:
00066     virtual bool Execute();
00067 
00068     virtual ~mitkFDKSpeedUsingGpu();
00069 
00070 private:
00071     void SetDtheta(float m) {dthetaDegree = m;}
00072 
00073     void initWindow();
00074 
00075     void initFBO();
00076 
00077     void Bind();
00078     
00079     bool CheckFBOStatus();
00080     
00081     void initCG();
00082 
00083     void CheckForCgError(const char *situation);
00084 
00085     bool CreateTexture();
00086 
00087     void AttachFBO(int layer);
00088 
00089     void InputPrjectData(float *data);
00090 
00091     void ReadData(int i,float *fresult);
00092 
00093     void SetTexMatrix(float angle);
00094 
00095     void EnableFshader();
00096 
00097     void EnableVshader();
00098 
00099     void DrawQuad(int h);
00100     
00101     void DestroyALL();
00102 
00103     void SetVolumeBlockSize(int m) {volumeBlockSize = m; volumeBlockSizeAddOne = m+1;};
00104 
00105     void SetFrustum(float offsetX, float offsetZ, float D, float cdetectorLengthx, float cdetectorLengthz);
00106 
00107     void SetXrayNumx(int m){xrayNumx = m;}
00108     void SetXrayNumz(int m){xrayNumz = m;}
00109     void SetAngleNum(int m){angleNum = m;}
00110 
00111     void SetWidth(int m){width = m;}
00112     void SetHeight(int m){height = m;}
00113     void SetImgslice(int m){imgslice = m;}
00114 
00115 private:
00116     int xrayNumx;
00117     int xrayNumz;
00118     int angleNum;
00119 
00120     int width;
00121     int height;
00122     int imgslice;
00123 
00124 
00125     struct TexParam 
00126     {
00127         const char *name;
00128         int unit;
00129         int target;
00130         int tex;
00131     };
00132     std::vector<TexParam> m_texParams;
00133 
00134     void _scanTexParams(CGprogram m_prog);
00135     void _setTexture(char *name, GLuint tex);
00136     void _bindTextures();
00137 
00138     float v[6];
00139     float hvz;
00140     float sz ;
00141     float cz ;
00142     float dthetaDegree;
00143 
00144     float zNear;
00145     float zFar;     //L
00146     float zCenter;  //D
00147     float nearDetectorLengthX;
00148     float nearDetectorLengthZ;
00149     GLfloat frustum[16];
00150 
00151     float zCenter2;
00152     GLuint windowHandle;    
00153     CGcontext cgContext;
00154     CGprofile fProfile ,vProfile;
00155     CGprogram fProgram ,vProgram;
00156     CGparameter mvpMatrixParam,
00157         layerParam,WParam,HParam,flagParam,
00158         texMatrixParam[TEXTURECHANNEL];
00159     
00160     GLuint projectDataID, ResultID;
00161     GLuint fbotex;
00162     GLuint fb;
00163     GLint m_preFboId;
00164 
00165     int volumeBlockNum;
00166     int volumeBlockSize;
00167     int volumeBlockSizeAddOne;
00168 
00169     int head;
00170     int flag;
00171 
00172     void _bindCurrentFBO();
00173     void _unBind();
00174     mitkFDKSpeedUsingGpu(const mitkFDKSpeedUsingGpu &);
00175     void operator = (const mitkFDKSpeedUsingGpu&);
00176 
00177 };
00178 
00179 //#define DEFINED_mitkFDKSpeedUsingGpu
00180 
00181 #endif 
00182 

Generated on Tue Feb 25 15:00:37 2014 for MITK (Medical Imaging ToolKit) by  doxygen 1.4.3