Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Raycaster Class Reference

#include <raycaster.h>

List of all members.

Public Methods

 Raycaster ()
 ~Raycaster ()
bool SetViewingCondition (VECTOR lightpos, Color background, float ambient, float diffuse, float specular, int highlight)
virtual bool Initialize (int width, int height, float steplength, Data *data, Transfunc *tf)
virtual bool Raycast ()
bool SetTreshold (int treshold)
bool SetRaytype (int type)
bool SetRendermode (int rendermode)
bool SetPreCalcGradients (bool pc)
bool Zoom (float zoom)
void SetWidth (int width)
void SetHeight (int height)
void SetStepLength (float steplength)
void SetAmbient (float ambient)
void SetDiffuse (float diffuse)
void SetSpecular (float specular)
void SetHighlight (int highlight)
void SetLightpos (VECTOR lightpos)
void SetLight (bool light)
void SetBackgroundColor (unsigned char r, unsigned char g, unsigned char b)
void SetDensRange (int mindens, int maxdens)
virtual bool RotateX (float alpha)
virtual bool RotateY (float alpha)
virtual bool RotateZ (float alpha)
bool Render (int width, int height)
rgbGetScreenShotImage (int &width, int &height)

Public Attributes

int m_dOwnType

Protected Methods

bool SetViewingMatrix ()

Protected Attributes

bool ready
bool m_light
VECTOR m_lightpos
float m_ambient
float m_diffuse
float m_steplength
float m_specular
int m_treshold
int m_highlight
int m_width
int m_height
Matrix4x4m_viewingtoworld
Matrix4x4m_viewingtoworld_inv
int m_raytype
int m_rendermode
rgbm_image
Datam_data
Transfuncm_tf
Color m_background
bool m_precalc
float m_zoom
float m_stepX
float m_stepY
VECTOR m_xdir
VECTOR m_ydir
int m_dMinDens
int m_dMaxDens


Constructor & Destructor Documentation

Raycaster::Raycaster  
 

raycaster.cpp implementiert den Raycaster der für jeden Bildpunkt einen Strahl initialisiert und die von dem Strahl berechnete Farbe im Bild speichert

Definition at line 11 of file raycaster.cpp.

References m_ambient, m_data, m_diffuse, m_dMaxDens, m_dMinDens, m_dOwnType, m_height, m_highlight, m_image, m_light, m_lightpos, m_precalc, m_raytype, m_rendermode, m_specular, m_stepX, m_stepY, m_tf, m_treshold, m_viewingtoworld, m_width, m_xdir, m_ydir, m_zoom, NN, RAYCASTER, ready, and STANDARD.

00011                      {
00012         ready = false;
00013         
00014         m_specular = 0.2f;
00015         m_highlight = 8;
00016         m_lightpos = VECTOR(300,300,300);
00017         m_light = false;
00018         m_image = NULL;
00019         m_ambient = 0.2f;
00020         m_diffuse = 0.2f;
00021         m_height = 0;
00022         m_width = 0;
00023         m_viewingtoworld = NULL;
00024         m_stepX = 1.0;
00025         m_stepY = 1.0;
00026         m_data = NULL;
00027         m_tf = NULL;
00028         m_xdir = VECTOR(1,0,0);
00029         m_ydir = VECTOR(0,1,0);
00030         m_treshold = 1500;
00031         m_rendermode = STANDARD;
00032         m_raytype = NN;
00033         m_precalc = false;
00034         m_zoom = 1.0;
00035 
00036         m_dOwnType = RAYCASTER;
00037 
00038         m_dMaxDens = 4095;
00039         m_dMinDens = 0;
00040 }

Raycaster::~Raycaster  
 

Definition at line 42 of file raycaster.cpp.

References m_image, and m_viewingtoworld.

00042                       {
00043         if(m_image != NULL) delete m_image;
00044         if(m_viewingtoworld != NULL) delete m_viewingtoworld;
00045         m_image = NULL;
00046         m_viewingtoworld = NULL;
00047 }


Member Function Documentation

rgb* Raycaster::GetScreenShotImage int &    width,
int &    height
[inline]
 

Definition at line 77 of file raycaster.h.

Referenced by CMy3dvisView::OnFileSaveImage(), and CVolumeDialog::OnShowWindow().

00077                                                          { width = m_width;
00078                                                                                                                 height = m_height;
00079                                                                                                                 return m_image; };

bool Raycaster::Initialize int    width,
int    height,
float    steplength,
Data   data,
Transfunc   tf
[virtual]
 

Definition at line 78 of file raycaster.cpp.

References m_data, m_height, m_steplength, m_tf, and m_width.

00078                                                                                         {
00079         m_data = data;
00080         m_tf = tf;
00081         m_width = width;
00082         m_height = height;
00083         m_steplength = steplength;
00084         return true;
00085 }

bool Raycaster::Raycast   [virtual]
 

Definition at line 105 of file raycaster.cpp.

References Ray::CastNext(), FH, Ray::GetCurrentColor(), Data::GetXDim(), Data::GetYDim(), Data::GetZDim(), Ray::Initialize(), m_data, m_height, m_image, m_raytype, m_viewingtoworld_inv, m_width, m_xdir, m_ydir, MI, NN, Plane::normal, ready, Ray::Reset(), Ray::SetDensRange(), Ray::SetLight(), Ray::SetPosDir(), Data::SetPreCalc(), Ray::SetViewingCondition(), STANDARD, Color::toRGB(), Matrix4x4::translate(), TRI, VECTOR::x, XRAY, VECTOR::y, and VECTOR::z.

Referenced by volumebar::OnButtonRenderVolume().

00105                    {
00106 
00107         CWnd* pFrame = AfxGetMainWnd();
00108 
00109 
00110         m_data->SetPreCalc(m_precalc);
00111         m_image = new rgb[m_width*m_height];
00112         
00113         int maxX = m_data->GetXDim();
00114         int maxY = m_data->GetYDim();
00115         int maxZ = m_data->GetZDim();
00116 
00117         VECTOR pos =  VECTOR(0,0,0);
00118         Matrix4x4 trans;
00119         trans.translate(VECTOR(-maxX/2,-maxY/2,-maxZ/2));
00120         pos = trans * pos;
00121         pos = *m_viewingtoworld_inv * pos;
00122         trans.translate(VECTOR(maxX/2,maxY/2,maxZ/2));
00123         pos = trans*pos;
00124         VECTOR backup = pos;
00125 
00126         VECTOR normal = VECTOR(0,0,0)-pos;
00127         if(normal.x == 0 && normal.y == 0 && normal.z == 0)
00128                 normal.z = 1.0;
00129 
00130         Plane *viewingplane = new Plane(normal,pos);
00131         m_xdir = *m_viewingtoworld_inv * m_xdir;
00132         m_ydir = *m_viewingtoworld_inv * m_ydir;
00133         
00134         int loadSize = (m_height * m_width) / 100;
00135         int counter = loadSize / 100;
00136         int progPos = 0;
00137 
00138 
00139 
00140         Ray *r;
00141         switch (m_rendermode) {
00142                 case STANDARD:
00143                         if (m_raytype == NN)
00144                                 r = new Ray();
00145                         else if (m_raytype == TRI)
00146                                 r = new Trilinear();
00147                         break;
00148                 case FH:
00149                         if (m_raytype == NN) {
00150                                 r = new FirstHitNN();
00151                                 ((FirstHitNN *)r)->SetTreshold(m_treshold);
00152                         }
00153                         else if (m_raytype == TRI) {
00154                                 r = new FirstHitTRI();
00155                                 ((FirstHitTRI *)r)->SetTreshold(m_treshold);
00156                         }
00157                         break;
00158                 case MI:
00159                         if (m_raytype == NN)
00160                                 r = new MaxIntensityNN();
00161                         else if (m_raytype == TRI)
00162                                 r = new MaxIntensityTRI();
00163                         break;
00164                 case XRAY:
00165                         if (m_raytype == NN)
00166                                 r = new XRayNN();
00167                         else if (m_raytype == TRI)
00168                                 r = new XRayTRI();
00169                         
00170                         r->SetDensRange(m_dMinDens, m_dMaxDens);
00171                         break;
00172         }
00173 
00174         r->SetViewingCondition(m_lightpos, m_ambient, m_diffuse, m_specular, m_highlight);
00175         r->Initialize(m_background,m_background,m_steplength,viewingplane,m_data,m_tf);
00176         r->SetLight(m_light);
00177 
00178         for(int j = 0; j < m_height; j++) {
00179                 for(int i = 0; i < m_width; i++) {
00180                         r->Reset();
00181                         r->SetPosDir(pos, viewingplane->normal);
00182                         r->CastNext();
00183                         m_image[j * m_width + i] = r->GetCurrentColor().toRGB();
00184 
00185                         pos += m_xdir;
00186 
00187                         if ((counter-- <= 0) && (progPos < 100)) {
00188                                 counter = loadSize;
00189                                 pFrame->SendMessage(MYWM_PROGRESS, progPos++);
00190                         }
00191 
00192 
00193                 } // inner for
00194                 pos = backup;
00195                 pos += j*m_ydir;
00196 
00197                 pFrame->SendMessage(MYWM_PROGRESS, 0);
00198         
00199         }
00200 
00201         
00202 
00203         if (r)
00204                 delete r;
00205         
00206         ready = true;
00207         return true;
00208 }

bool Raycaster::Render int    width,
int    height
 

Definition at line 62 of file raycaster.cpp.

References m_height, m_width, and ready.

Referenced by CMy3dvisView::RenderScene().

00062                                        {
00063 
00064         int m_x = width / 2 - m_width / 2;
00065         int m_y = height / 2 - m_height / 2;
00066 
00067 
00068         if (!ready)
00069                 return false;
00070 
00071         glRasterPos2i(m_x, m_y);
00072         glPixelStorei(GL_UNPACK_ALIGNMENT,1);
00073         glDrawPixels(m_width, m_height, GL_RGB, GL_UNSIGNED_BYTE, m_image);
00074         return true;
00075 }

bool Raycaster::RotateX float    alpha [virtual]
 

Definition at line 243 of file raycaster.cpp.

References m_viewingtoworld, m_viewingtoworld_inv, Matrix4x4::mul(), and Matrix4x4::rotateX().

Referenced by CVolumeDialog::OnButtonXPlus().

00243                               {
00244         Matrix4x4 rotmat1;
00245         Matrix4x4 rotmat2;
00246         rotmat1.rotateX(alpha);
00247         rotmat2.rotateX(-alpha);
00248         
00249         *m_viewingtoworld = m_viewingtoworld->mul(rotmat1);
00250         *m_viewingtoworld_inv = m_viewingtoworld_inv->mul(rotmat2);
00251         return true;
00252 }

bool Raycaster::RotateY float    alpha [virtual]
 

Definition at line 255 of file raycaster.cpp.

References m_viewingtoworld, m_viewingtoworld_inv, Matrix4x4::mul(), and Matrix4x4::rotateY().

00255                               {
00256         Matrix4x4 rotmat1;
00257         Matrix4x4 rotmat2;
00258         rotmat1.rotateY(alpha);
00259         rotmat2.rotateY(-alpha);
00260         
00261         *m_viewingtoworld = m_viewingtoworld->mul(rotmat1);
00262         *m_viewingtoworld_inv = m_viewingtoworld_inv->mul(rotmat2);
00263         return true;
00264 }

bool Raycaster::RotateZ float    alpha [virtual]
 

Definition at line 267 of file raycaster.cpp.

References m_viewingtoworld, m_viewingtoworld_inv, Matrix4x4::mul(), and Matrix4x4::rotateZ().

00267                               {
00268         Matrix4x4 rotmat1;
00269         Matrix4x4 rotmat2;
00270         rotmat1.rotateZ(alpha);
00271         rotmat2.rotateZ(-alpha);
00272         
00273         *m_viewingtoworld = m_viewingtoworld->mul(rotmat1);
00274         *m_viewingtoworld_inv = m_viewingtoworld_inv->mul(rotmat2);
00275         return true;
00276 }

void Raycaster::SetAmbient float    ambient [inline]
 

Definition at line 59 of file raycaster.h.

Referenced by CVolumeDialog::OnChangeEditAmbient().

00059 { m_ambient = ambient; };

void Raycaster::SetBackgroundColor unsigned char    r,
unsigned char    g,
unsigned char    b
[inline]
 

Definition at line 65 of file raycaster.h.

Referenced by CVolumeDialog::OnButtonBgcolor().

00065                                                                                    {
00066                                                                                                                 m_background = Color(r, g, b); };

void Raycaster::SetDensRange int    mindens,
int    maxdens
[inline]
 

Definition at line 68 of file raycaster.h.

Referenced by CVolumeDialog::OnChangeEditXrayMax(), and CVolumeDialog::OnChangeEditXrayMin().

00068 { m_dMinDens = mindens; m_dMaxDens = maxdens; };

void Raycaster::SetDiffuse float    diffuse [inline]
 

Definition at line 60 of file raycaster.h.

Referenced by CVolumeDialog::OnChangeEditDiffuse().

00060 { m_diffuse = diffuse; };

void Raycaster::SetHeight int    height [inline]
 

Definition at line 56 of file raycaster.h.

Referenced by CVolumeDialog::OnChangeEditHeight().

00056 { m_height = height; };

void Raycaster::SetHighlight int    highlight [inline]
 

Definition at line 62 of file raycaster.h.

Referenced by CVolumeDialog::OnChangeEditHighlight().

00062 {m_highlight = highlight;};

void Raycaster::SetLight bool    light [inline]
 

Definition at line 64 of file raycaster.h.

Referenced by CVolumeDialog::OnCheckLight(), and CVolumeDialog::OnRadioStandard().

00064 {m_light = light;};

void Raycaster::SetLightpos VECTOR    lightpos [inline]
 

Definition at line 63 of file raycaster.h.

Referenced by CVolumeDialog::OnChangeEditLightposX(), CVolumeDialog::OnChangeEditLightposY(), and CVolumeDialog::OnChangeEditLightposZ().

00063 { m_lightpos = lightpos;};

bool Raycaster::SetPreCalcGradients bool    pc [inline]
 

Definition at line 52 of file raycaster.h.

00052 { m_precalc = pc; return true;};

bool Raycaster::SetRaytype int    type [inline]
 

Definition at line 50 of file raycaster.h.

Referenced by volumebar::OnRadioVolumeNn(), and volumebar::OnRadioVolumeTri().

00050 { m_raytype = type; return true;};

bool Raycaster::SetRendermode int    rendermode [inline]
 

Definition at line 51 of file raycaster.h.

Referenced by CVolumeDialog::OnRadioFirsthit(), CVolumeDialog::OnRadioMip(), CVolumeDialog::OnRadioStandard(), and CVolumeDialog::OnRadioXray().

00051 { m_rendermode = rendermode; return true;};

void Raycaster::SetSpecular float    specular [inline]
 

Definition at line 61 of file raycaster.h.

Referenced by CVolumeDialog::OnChangeEditSpecular().

00061 { m_specular = specular;};

void Raycaster::SetStepLength float    steplength [inline]
 

Definition at line 57 of file raycaster.h.

00057 { m_steplength = steplength; };

bool Raycaster::SetTreshold int    treshold [inline]
 

Definition at line 49 of file raycaster.h.

Referenced by CVolumeDialog::OnChangeEditFhThreshold().

00049 { m_treshold = treshold; return true;};

bool Raycaster::SetViewingCondition VECTOR    lightpos,
Color    background,
float    ambient,
float    diffuse,
float    specular,
int    highlight
 

Definition at line 50 of file raycaster.cpp.

References m_ambient, m_background, m_diffuse, m_highlight, m_lightpos, and m_specular.

00050                                                                                                                              {
00051         m_ambient = ambient;
00052         m_diffuse = diffuse;
00053         m_background = background;
00054         m_specular = specular;
00055         m_highlight = highlight;
00056         m_lightpos = lightpos;
00057         return true;
00058 }

bool Raycaster::SetViewingMatrix   [protected]
 

Definition at line 227 of file raycaster.cpp.

References Matrix4x4::identity(), m_stepX, m_stepY, m_viewingtoworld, m_viewingtoworld_inv, m_xdir, and m_ydir.

Referenced by Zoom().

00227                             {
00228         VECTOR zaxis = VECTOR(0,0,1);
00229         m_viewingtoworld = new Matrix4x4();
00230         m_viewingtoworld->identity();
00231         m_viewingtoworld_inv = new Matrix4x4();
00232         m_viewingtoworld_inv->identity();
00233         m_xdir = VECTOR(1,0,0);
00234         m_ydir = VECTOR(0,1,0);
00235 
00236         m_xdir = m_stepX * m_xdir;
00237         m_ydir = m_stepY * m_ydir;
00238 
00239         return true;
00240 }

void Raycaster::SetWidth int    width [inline]
 

Definition at line 55 of file raycaster.h.

Referenced by CVolumeDialog::OnChangeEditWidth().

00055 { m_width = width; };

bool Raycaster::Zoom float    zoom
 

Definition at line 212 of file raycaster.cpp.

References Data::GetXDim(), Data::GetYDim(), Data::GetZDim(), m_data, m_height, m_stepX, m_stepY, m_width, m_zoom, and SetViewingMatrix().

Referenced by CVolumeDialog::OnChangeEditZoom().

00212                           {
00213         int maxX = m_data->GetXDim()-1;
00214         int maxY = m_data->GetYDim()-1;
00215         int maxZ = m_data->GetZDim()-1;
00216         m_zoom = zoom;
00217         float maxlength = sqrtf(powf((float)maxX,2.0)+powf((float)maxY,2.0)+powf((float)maxZ,2.0));
00218         m_stepX = (1/m_zoom)*maxlength/(m_width-1);
00219         m_stepY = (1/m_zoom)*maxlength/(m_height-1);
00220 
00221         SetViewingMatrix();
00222         return true;
00223 }


Member Data Documentation

float Raycaster::m_ambient [protected]
 

Definition at line 24 of file raycaster.h.

Referenced by Raycaster(), and SetViewingCondition().

Color Raycaster::m_background [protected]
 

Definition at line 32 of file raycaster.h.

Referenced by SetViewingCondition().

Data* Raycaster::m_data [protected]
 

Definition at line 30 of file raycaster.h.

Referenced by Initialize(), Raycast(), Raycaster(), and Zoom().

float Raycaster::m_diffuse [protected]
 

Definition at line 24 of file raycaster.h.

Referenced by Raycaster(), and SetViewingCondition().

int Raycaster::m_dMaxDens [protected]
 

Definition at line 38 of file raycaster.h.

Referenced by Raycaster().

int Raycaster::m_dMinDens [protected]
 

Definition at line 38 of file raycaster.h.

Referenced by Raycaster().

int Raycaster::m_dOwnType
 

Definition at line 75 of file raycaster.h.

Referenced by Raycaster().

int Raycaster::m_height [protected]
 

Definition at line 26 of file raycaster.h.

Referenced by Initialize(), Raycast(), Raycaster(), Render(), and Zoom().

int Raycaster::m_highlight [protected]
 

Definition at line 25 of file raycaster.h.

Referenced by Raycaster(), and SetViewingCondition().

rgb* Raycaster::m_image [protected]
 

Definition at line 29 of file raycaster.h.

Referenced by Raycast(), Raycaster(), and ~Raycaster().

bool Raycaster::m_light [protected]
 

Definition at line 21 of file raycaster.h.

Referenced by Raycaster().

VECTOR Raycaster::m_lightpos [protected]
 

Definition at line 22 of file raycaster.h.

Referenced by Raycaster(), and SetViewingCondition().

bool Raycaster::m_precalc [protected]
 

Definition at line 33 of file raycaster.h.

Referenced by Raycaster().

int Raycaster::m_raytype [protected]
 

Definition at line 28 of file raycaster.h.

Referenced by Raycast(), and Raycaster().

int Raycaster::m_rendermode [protected]
 

Definition at line 28 of file raycaster.h.

Referenced by Raycaster().

float Raycaster::m_specular [protected]
 

Definition at line 24 of file raycaster.h.

Referenced by Raycaster(), and SetViewingCondition().

float Raycaster::m_steplength [protected]
 

Definition at line 24 of file raycaster.h.

Referenced by Initialize().

float Raycaster::m_stepX [protected]
 

Definition at line 35 of file raycaster.h.

Referenced by Raycaster(), SetViewingMatrix(), and Zoom().

float Raycaster::m_stepY [protected]
 

Definition at line 35 of file raycaster.h.

Referenced by Raycaster(), SetViewingMatrix(), and Zoom().

Transfunc* Raycaster::m_tf [protected]
 

Definition at line 31 of file raycaster.h.

Referenced by Initialize(), and Raycaster().

int Raycaster::m_treshold [protected]
 

Definition at line 25 of file raycaster.h.

Referenced by Raycaster().

Matrix4x4* Raycaster::m_viewingtoworld [protected]
 

Definition at line 27 of file raycaster.h.

Referenced by Raycaster(), RotateX(), RotateY(), RotateZ(), SetViewingMatrix(), and ~Raycaster().

Matrix4x4 * Raycaster::m_viewingtoworld_inv [protected]
 

Definition at line 27 of file raycaster.h.

Referenced by Raycast(), RotateX(), RotateY(), RotateZ(), and SetViewingMatrix().

int Raycaster::m_width [protected]
 

Definition at line 26 of file raycaster.h.

Referenced by Initialize(), Raycast(), Raycaster(), Render(), and Zoom().

VECTOR Raycaster::m_xdir [protected]
 

Definition at line 36 of file raycaster.h.

Referenced by Raycast(), Raycaster(), and SetViewingMatrix().

VECTOR Raycaster::m_ydir [protected]
 

Definition at line 36 of file raycaster.h.

Referenced by Raycast(), Raycaster(), and SetViewingMatrix().

float Raycaster::m_zoom [protected]
 

Definition at line 34 of file raycaster.h.

Referenced by Raycaster(), and Zoom().

bool Raycaster::ready [protected]
 

Definition at line 20 of file raycaster.h.

Referenced by Raycast(), Raycaster(), and Render().


The documentation for this class was generated from the following files:
Generated on Thu Jan 30 21:35:44 2003 for 3DVis by doxygen1.3-rc2