00001
00002
00004
00005 #if !defined(AFX_TMYVOLMOD_H__AC5171CD_1CE3_48B6_A11A_3A0F5A6EA413__INCLUDED_)
00006 #define AFX_TMYVOLMOD_H__AC5171CD_1CE3_48B6_A11A_3A0F5A6EA413__INCLUDED_
00007
00008 #if _MSC_VER > 1000
00009 #pragma once
00010 #endif // _MSC_VER > 1000
00011
00012 #include "TVolModell.h"
00013 #include "TTrilinearFilter.h"
00014 #include <stdio.h>
00015 #include <math.h>
00016
00017 #include "bitfieldstruct.h"
00018 #include "progressdialog.h"
00019 #include <QProgressDialog.h>
00020 #include "viewWidgetImpl.h"
00021 #include "TModelSettingsImpl.h"
00022 #include <QLineEdit.h>
00023
00024 #include <Qdial.h>
00025
00026 #define round(x) ((fmod(x,1.0)>=0.5)?(1+(int)x):(int)x)
00027 #define PI 3.1415926535
00028
00029 struct TDataStr
00030 {
00031 unsigned short int density;
00032 unsigned char shading;
00033 };
00034 class TMyVolMod : public TVolModell
00035 {
00036 private:
00037 TStdPlane<float> boundingPlanes[6];
00038 float ambCoeff;
00039 float diffCoeff;
00040 float specCoeff;
00041 int specExp;
00042 int horAngle;
00043 int vertAngle;
00044 int pixelMode;
00045 TFilterInterface* filter;
00046
00047 unsigned int calcSliceCol(unsigned int winS, unsigned int winE, unsigned int val);
00048 unsigned int getHistVal(int from, int to);
00049 unsigned short int dim[3];
00050
00051 TKoo3d<float>* gradient;
00052 TDataStr* data;
00053
00054 unsigned int histogram[0xfff+1];
00055 TMemBmp* histBmp;
00056 void calcHistogram();
00057 void calcHistBmp();
00058 TKoo3d<float> lightDir;
00059 unsigned int transferFunc[0xfff];
00060 bool windowing;
00061 public:
00062 TKoo3d<float> getLightDir();
00063 virtual unsigned int* getTransF();
00064 virtual TFilterInterface* getFilter();
00065 virtual void getBoundingPlanes(TStdPlane<float>* array);
00066 virtual float getAmbientCoeff();
00067 virtual float getSpecularCoeff();
00068 virtual float getDiffuseCoeff();
00069 virtual int getSpecularExp();
00070 virtual void setTransferFunction(TTransferFuncInterface* tf);
00071 virtual void setLighting(float ambient, float diffuse, float specular, int exponent);
00072 virtual void calcShading(bool askUser);
00073 virtual void setTransferFunction(unsigned int* transf);
00074 virtual TKoo3d<float> getGradient(int x, int y, int z);
00075 virtual unsigned int getPixelFilteredAt(float x, float y, float z, int type);
00076 TMyVolMod();
00077 TMyVolMod(QString& name);
00078 virtual void setLightDir(TKoo3d<float>& dir);
00079 virtual ~TMyVolMod();
00080
00081 virtual int getPixelMode();
00082 virtual void setPixelMode(int mode);
00083
00084 virtual void getHistogrammArray(unsigned int* a, int size);
00085 virtual unsigned int* getHistogrammArray(int size);
00086 virtual int getMaximum ();
00087 virtual void loadFromFile(QString& name);
00088 inline unsigned int getPixelAt(int x, int y, int z)
00089 {
00090
00091 if (x>0&&x<dim[0]&&y>0&&y<dim[1]&&z>0&&z<dim[2])
00092 {
00093 switch (pixelMode)
00094 {
00095 case VOL_MOD_PIXELMODE_DENSITY:
00096 return data[(dim[2]-z-1)*dim[0]*dim[1] +y*dim[0] +x].density;
00097 case VOL_MOD_PIXELMODE_SHADED:
00098 {
00099 TColorBitfield* cp;
00100 unsigned int color=transferFunc[data[(dim[2]-z-1)*dim[0]*dim[1] +y*dim[0] +x].density];
00101 cp=(TColorBitfield*)&color;
00102 cp->r=data[(dim[2]-z-1)*dim[0]*dim[1] +y*dim[0] +x].shading*cp->r/0xff;
00103 cp->g=data[(dim[2]-z-1)*dim[0]*dim[1] +y*dim[0] +x].shading*cp->g/0xff;
00104 cp->b=data[(dim[2]-z-1)*dim[0]*dim[1] +y*dim[0] +x].shading*cp->b/0xff;
00105 return color;
00106 }
00107 case VOL_MOD_PIXELMODE_TRANSFERF:
00108 return transferFunc[data[(dim[2]-z-1)*dim[0]*dim[1] +y*dim[0] +x].density];
00109 case VOL_MOD_PIXELMODE_GRADIENT:
00110 {
00111 TColorBitfield* cp;
00112 unsigned int color;
00113 cp=(TColorBitfield*)&color;
00114 cp->r=(unsigned char)(((float)abs(getGradient(x,y,z).v[0])/(float)getMaximum())*256);
00115 cp->g=(unsigned char)(((float)abs(getGradient(x,y,z).v[1])/(float)getMaximum())*256);
00116 cp->b=(unsigned char)(((float)abs(getGradient(x,y,z).v[2])/(float)getMaximum())*256);
00117 return color;
00118 }
00119 default:
00120 return 0;
00121 }
00122 }
00123 else
00124 return 0;
00125 }
00126
00127
00128
00129
00130 virtual bool setPixelAt(int x, int y, int z, int val);
00131 virtual QImage* getXSlice(QImage& imgBuff,QPoint& offs, int pos, int winS=0, int winE=0xfff);
00132 virtual QImage* getYSlice(QImage& imgBuff,QPoint& offs, int pos, int winS=0, int winE=0xfff);
00133 virtual QImage* getZSlice(QImage& imgBuff,QPoint& offs, int pos, int winS=0, int winE=0xfff);
00134 virtual QImage* getXSlice(QImage& imgBuff, int pos, int renderMode=0, int sizeX=0, int sizeY=0, int winS=0, int winE=0xfff);
00135 virtual QImage* getYSlice(QImage& imgBuff, int pos, int renderMode=0, int sizeX=0, int sizeY=0, int winS=0, int winE=0xfff);
00136 virtual QImage* getZSlice(QImage& imgBuff, int pos, int renderMode=0, int sizeX=0, int sizeY=0, int winS=0, int winE=0xfff);
00137 virtual int getSizeX();
00138 virtual int getSizeY();
00139 virtual int getSizeZ();
00140 virtual TMemBmp* getHistogramBmp();
00141 virtual void getMaxValues(int* d);
00142 virtual void setFilter(TFilterInterface* f);
00143 virtual TKoo3d<float> getGradientInterpolated(float x, float y, float z);
00144 };
00145
00146 #endif // !defined(AFX_TMYVOLMOD_H__AC5171CD_1CE3_48B6_A11A_3A0F5A6EA413__INCLUDED_)