www.pudn.com > Ì廿֯Âë.rar > volume.h, change:2001-12-09,size:3196b


#ifndef __volume_h__ 
#define __volume_h__ 
 
#include "openglsupport.h" 
#include "vecmath.h" 
 
#define CLAMPX(x) ((x  0) ? 0 : ((x >= m_x) ? m_x-1 : x)) 
#define CLAMPY(y) ((y  0) ? 0 : ((y >= m_y) ? m_y-1 : y)) 
#define CLAMPZ(z) ((z  0) ? 0 : ((z >= m_z) ? m_z-1 : z)) 
#define DATA(x,y,z) z*m_xy + y*m_x + x 
#define DATAC(x,y,z) CLAMPZ(z)*m_xy + CLAMPY(y)*m_x + CLAMPX(x) 
 
#define CLAMPIX(x) ((x  0) ? 0 : ((x >= m_x) ? m_x-1 : x)) 
#define CLAMPIY(y) ((y  0) ? 0 : ((y >= m_xy) ? (m_y-1)*m_x : y)) 
#define CLAMPIZ(z) ((z  0) ? 0 : ((z >= m_xyz) ? (m_z-1)*m_xy : z)) 
#define DATAI(x,y,z) z + y + x 
#define DATAIC(x,y,z) CLAMPIZ(z) + CLAMPIY(y) + CLAMPIX(x) 
 
#define FPSH 8 
#define FPMUL (1<<FPSH) 
#define FPMASK (FPMUL-1) 
 
#define MAXDENSITY 4095 
 
typedef short data_t; 
 
#pragma pack(1) 
struct grad_t  
{ 
   float x,y,z; 
}; 
#pragma pack() 
 
grad_t operator * (grad_t g1, float s); 
grad_t operator + (grad_t g1, grad_t g2); 
bool norm(grad_t &g); 
float normlen(grad_t &g); 
float length(grad_t g); 
 
void swap4(void *p); 
 
//===== class Volume ============================================= 
 
class Volume 
{ 
private: 
   int m_x; 
   int m_y; 
   int m_z; 
   int m_xx; 
   int m_yy; 
   int m_zz; 
   int m_xy; 
   int m_xyz; 
   int m_size; 
   int m_max; 
   data_t *m_data; 
   grad_t *m_grad; 
//   float *m_gradlen; 
 
   float m_histogram[MAXDENSITY+1]; 
 
   GLuint *m_overview_xtex; 
   GLuint *m_overview_ytex; 
   GLuint *m_overview_ztex; 
   int m_overview_texsize; 
   int m_overview_draw_width; 
   int m_overview_draw_height; 
   GLuint m_overview_gllist; 
   matrix44 m_view_matrix; 
   matrix44 m_view_matrix_inv; 
    
   void SetSlicePixel(int x, int y, data_t data); 
   void CalcGradient(); 
   void CalcHistogram(); 
   void Initialise(); 
 
public: 
	Volume(); 
	~Volume(); 
 
	bool LoadDataDAT(const char *filename); 
	bool LoadDataVOL(const char *filename); 
   bool GetData(int x, int y, int z, data_t &data);  
   data_t GetData(int x, int y, int z);  
   data_t GetDataI(int x, int y, int z);  
   bool GetData(coord3 &pos, data_t &data);  
   bool GetDataTL(coord3 &pos, data_t &data);  
 
   bool GetGradient(int x, int y, int z, grad_t &grad);  
   bool GetGradient(coord3 &pos, grad_t &grad);  
   bool GetGradientTL(coord3 &pos, grad_t &grad); 
 
//   float GetGradientLength(coord3 &pos);  
//   float GetGradientLengthTL(coord3 &pos); 
 
   int GetDimX(); 
   int GetDimY(); 
   int GetDimZ(); 
   int GetMaxWidth(); 
 
   float GetHistogramValue(int i); 
   float GetHistogramRange(int min, int max); 
 
   bool GetRayEnds(coord3 &nearpos, coord3 &farpos, coord3 &pos, coord3 &dir, float &dist); 
 
   void CreateOverview(int ts); 
   void SetOverviewDrawSize(int width, int height); 
//   void SetScale(float scale); 
//	void SetDistanceNear(float near); 
//	void SetDistanceFar(float far); 
//	void SetPosition(float x, float y, float z); 
//	void SetPerspective(bool perspective); 
 
//   void ViewMatrixMul(matrix44 &m);  
 
   void GetViewMatrix(matrix44 &m); 
   void GetViewMatrixInv(matrix44 &m); 
   void ViewRotate(float angle, float x, float y, float z);  
 
   void glOverviewDraw(int threshold); 
}; 
 
#endif