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

Ray Class Reference

#include <ray.h>

Inheritance diagram for Ray:

AverageNN FirstHitNN MaxIntensityNN Trilinear XRayNN FirstHitTRI AverageTRI MaxIntensityTRI XRayTRI List of all members.

Public Methods

 Ray ()
 ~Ray ()
bool SetViewingCondition (VECTOR lightpos, float ambient, float diffuse, float specular, int highlight)
bool Initialize (Color background, Color current, float steplength, Plane *viewingplane, Data *data, Transfunc *tf)
bool SetPosDir (VECTOR currentpos, VECTOR direction)
Color GetCurrentColor ()
float GetAlpha ()
void SetLight (bool light)
virtual bool CastNext ()
bool Reset ()

Protected Methods

virtual Color Lighting (Color color)

Protected Attributes

bool m_light
VECTOR m_lightpos
VECTOR m_currentpos
float m_ambient
float m_diffuse
float m_specular
int m_highlight
Transfuncm_tf
Datam_data
Color m_backgroundcolor
Color m_currentcolor
float m_alpha
VECTOR m_startpoint
VECTOR m_direction
float m_steplength
Planem_viewingplane
float mx
float my
float mz
float m_radius

Constructor & Destructor Documentation

Ray::Ray  
 

Definition at line 5 of file ray.cpp.

References m_alpha, m_ambient, m_backgroundcolor, m_currentcolor, m_currentpos, m_data, m_diffuse, m_direction, m_highlight, m_light, m_specular, m_startpoint, m_steplength, m_tf, m_viewingplane, mx, my, and mz.

00005          {
00006         // richtungsvektor
00007         m_direction = VECTOR(1,0,0);
00008         // aktuelle position am strahl
00009         m_currentpos = VECTOR(0,0,0);
00010         // Koeffizient für ambient lighting
00011         m_ambient = 0.2f;
00012         // Koeffizient für diffuses lighting
00013         m_diffuse = 0.2f;
00014         // Transferfubction
00015         m_tf = NULL;
00016         // datenvolumen
00017         m_data = NULL;
00018         // Hintergrundfarbe
00019         m_backgroundcolor = Color(0.0,0.0,0.0);
00020         // aktuelle Gesamtfarbe
00021         m_currentcolor = Color(0.0,0.0,0.0);
00022         // aktueller Alphawert
00023         m_alpha = 0.0;
00024         // Startpunkt
00025         m_startpoint = VECTOR(0,0,0);
00026         // Endpunkt
00027         m_steplength = 1.0;
00028         m_specular = 0.2f;
00029 
00030         m_highlight = 8;
00031 
00032         m_light = false;
00033         m_viewingplane = NULL;
00034         mx = 0.0f;
00035         my = 0.0f;
00036         mz = 0.0f;
00037 }

Ray::~Ray  
 

Definition at line 39 of file ray.cpp.

00039 {}


Member Function Documentation

bool Ray::CastNext   [virtual]
 

Reimplemented in Trilinear, FirstHitNN, FirstHitTRI, MaxIntensityNN, MaxIntensityTRI, XRayNN, XRayTRI, AverageNN, and AverageTRI.

Definition at line 110 of file ray.cpp.

References Data::GetDensity(), Transfunc::GetDensityColor(), Transfunc::GetOpacity(), VECTOR::length(), Lighting(), m_alpha, m_backgroundcolor, m_currentcolor, m_currentpos, m_data, m_direction, m_radius, m_startpoint, m_steplength, m_tf, mx, my, mz, ROUND, VECTOR::x, VECTOR::y, and VECTOR::z.

Referenced by Perspective::Raycast(), and Raycaster::Raycast().

00110               {
00111 
00112         if(m_data == NULL) return false;
00113         if(m_tf == NULL) return false;
00114                 
00115         bool first = true;
00116         int step_count = 0;
00117         VECTOR distancetomidpoint = VECTOR(mx/2.0f,my/2.0f,mz/2.0f)-m_currentpos;
00118         int steps = (int)((distancetomidpoint.length() + m_radius)/m_steplength);
00119         do {
00120                 if(m_alpha > 0.99) break;
00121                 if((m_currentpos.x >= 0.0)&&(m_currentpos.y >= 0.0)&&(m_currentpos.z >= 0.0)&&(m_currentpos.x < mx)&&(m_currentpos.y < my)&&(m_currentpos.z < mz)) {
00122                         if(first) {
00123                                 m_startpoint = VECTOR(m_currentpos.x,m_currentpos.y,m_currentpos.z);
00124                                 first = false;
00125                         }
00126                         int d = m_data->GetDensity((int)ROUND(m_currentpos.x),(int)ROUND(m_currentpos.y),(int)ROUND(m_currentpos.z));
00127                 
00128                         Color help_color = m_tf->GetDensityColor(d);
00129                         float help_alpha = m_tf->GetOpacity(d);
00130                         // lightning:
00131                         help_color = Lighting(help_color);
00132                         // calculate new currentcolor:
00133                         m_currentcolor += help_color*(1-m_alpha)*help_alpha;
00134                         // calculate new alphavalue
00135                         m_alpha += (1-m_alpha)*help_alpha;
00136                 }
00137                         // calculate new position
00138                 m_currentpos += m_steplength*m_direction;
00139                 
00140                 step_count++;
00141         }while(step_count <= steps);
00142         if(m_alpha < 1.0 ) {
00143                 m_currentcolor += m_backgroundcolor*(1.0f-m_alpha);
00144         }
00145         return true;            
00146 }

float Ray::GetAlpha   [inline]
 

Definition at line 57 of file ray.h.

00057 { return m_alpha;};

Color Ray::GetCurrentColor  
 

Definition at line 83 of file ray.cpp.

References m_currentcolor.

Referenced by Perspective::Raycast(), and Raycaster::Raycast().

00083                      {
00084         return m_currentcolor;
00085 }

bool Ray::Initialize Color    background,
Color    current,
float    steplength,
Plane   viewingplane,
Data   data,
Transfunc   tf
 

Definition at line 88 of file ray.cpp.

References Data::GetXDim(), Data::GetYDim(), Data::GetZDim(), m_backgroundcolor, m_currentcolor, m_data, m_radius, m_steplength, m_tf, m_viewingplane, mx, my, and mz.

Referenced by Perspective::Raycast(), and Raycaster::Raycast().

00088                                                                                                                 {
00089         m_backgroundcolor = background;
00090         m_currentcolor = current;
00091         m_data = data;
00092         m_tf = tf;
00093         m_steplength = steplength;
00094         m_viewingplane = viewingplane;
00095         mx = (float)m_data->GetXDim();
00096         my = (float)m_data->GetYDim();
00097         mz = (float)m_data->GetZDim();
00098         m_radius = sqrt(pow(mx/2.0f,2)+pow(my/2.0f,2)+pow(mz/2.0f,2));
00099         return true;
00100 }

Color Ray::Lighting Color    color [protected, virtual]
 

Reimplemented in Trilinear.

Definition at line 63 of file ray.cpp.

References Data::CalcGrad(), VECTOR::dot(), VECTOR::length(), m_ambient, m_currentpos, m_data, m_diffuse, m_direction, m_highlight, m_lightpos, m_specular, m_startpoint, VECTOR::normalize(), ROUND, gradient_t::x, VECTOR::x, gradient_t::y, VECTOR::y, gradient_t::z, and VECTOR::z.

Referenced by FirstHitNN::CastNext(), and CastNext().

00063                          {
00064         gradient_t grad = m_data->CalcGrad((int)ROUND(m_currentpos.x),(int)ROUND(m_currentpos.y),(int)ROUND(m_currentpos.z));
00065         VECTOR normal = VECTOR(grad.x, grad.y, grad.z);
00066         normal.normalize(); // normalize normal
00067         VECTOR len = m_currentpos - m_startpoint;
00068         Color ret;
00069         if(m_light) {
00070                 VECTOR v = -m_direction;
00071                 v.normalize();
00072                 VECTOR l = m_lightpos-m_currentpos;
00073                 l.normalize();
00074                 VECTOR h = (v+l);
00075                 h.normalize(); 
00076                 ret = color*m_ambient + color*((m_diffuse*(normal.dot(m_direction))) + (m_specular*pow(normal.dot(h),m_highlight)))+ color/(4.0f+1000000.0f*len.length()); 
00077         }
00078         else ret = color*m_ambient + color*(m_diffuse*(normal.dot(m_direction))) + color/(4.0f+1000000.0f*len.length());
00079         return ret;
00080 }

bool Ray::Reset   [inline]
 

Definition at line 60 of file ray.h.

Referenced by Perspective::Raycast(), and Raycaster::Raycast().

00060 {m_alpha = 0.0; m_currentcolor = m_backgroundcolor; return true;};

void Ray::SetLight bool    light [inline]
 

Definition at line 58 of file ray.h.

Referenced by Perspective::Raycast(), and Raycaster::Raycast().

00058 { m_light = light;};

bool Ray::SetPosDir VECTOR    currentpos,
VECTOR    direction
 

Definition at line 103 of file ray.cpp.

References m_currentpos, and m_direction.

Referenced by Perspective::Raycast(), and Raycaster::Raycast().

00103                                                   {
00104         m_currentpos = currentpos;
00105         m_direction = direction;
00106         return true;
00107 }

bool Ray::SetViewingCondition VECTOR    lightpos,
float    ambient,
float    diffuse,
float    specular,
int    highlight
 

Definition at line 42 of file ray.cpp.

References m_ambient, m_diffuse, m_highlight, and m_specular.

Referenced by Perspective::Raycast(), and Raycaster::Raycast().

00042                                                                                                      {
00043         
00044         if (ambient > 1.0) ambient = 1.0;
00045         if (ambient < 0.0) ambient = 0.0;
00046         if (diffuse > 1.0) diffuse = 1.0;
00047         if (diffuse < 0.0) diffuse = 0.0;
00048         if (specular > 1.0) specular = 1.0;
00049         if (specular < 0.0) specular = 0.0;
00050         if(highlight < 0) highlight = 0;
00051                 
00052         m_highlight = highlight;
00053         m_specular = specular;
00054         m_ambient = ambient;
00055         m_diffuse = diffuse;
00056         return true;
00057 }


Member Data Documentation

float Ray::m_alpha [protected]
 

Definition at line 39 of file ray.h.

Referenced by AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), and Ray().

float Ray::m_ambient [protected]
 

Definition at line 23 of file ray.h.

Referenced by Trilinear::Lighting(), Lighting(), Ray(), and SetViewingCondition().

Color Ray::m_backgroundcolor [protected]
 

Definition at line 35 of file ray.h.

Referenced by AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), Initialize(), and Ray().

Color Ray::m_currentcolor [protected]
 

Definition at line 37 of file ray.h.

Referenced by AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), GetCurrentColor(), Initialize(), and Ray().

VECTOR Ray::m_currentpos [protected]
 

Definition at line 21 of file ray.h.

Referenced by AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), Trilinear::Lighting(), Lighting(), Ray(), and SetPosDir().

Data* Ray::m_data [protected]
 

Definition at line 33 of file ray.h.

Referenced by Trilinear::CalcAlphaTrilinear(), Trilinear::CalcColorTrilinear(), Trilinear::CalcGradTrilinear(), AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), FirstHitTRI::GetDensity(), Initialize(), Lighting(), and Ray().

float Ray::m_diffuse [protected]
 

Definition at line 25 of file ray.h.

Referenced by Trilinear::Lighting(), Lighting(), Ray(), and SetViewingCondition().

VECTOR Ray::m_direction [protected]
 

Definition at line 43 of file ray.h.

Referenced by AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), Trilinear::Lighting(), Lighting(), Ray(), and SetPosDir().

int Ray::m_highlight [protected]
 

Definition at line 29 of file ray.h.

Referenced by Trilinear::Lighting(), Lighting(), Ray(), and SetViewingCondition().

bool Ray::m_light [protected]
 

Definition at line 15 of file ray.h.

Referenced by MaxIntensityNN::CastNext(), and Ray().

VECTOR Ray::m_lightpos [protected]
 

Definition at line 16 of file ray.h.

Referenced by Trilinear::Lighting(), and Lighting().

float Ray::m_radius [protected]
 

Definition at line 47 of file ray.h.

Referenced by AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), and Initialize().

float Ray::m_specular [protected]
 

Definition at line 27 of file ray.h.

Referenced by Trilinear::Lighting(), Lighting(), Ray(), and SetViewingCondition().

VECTOR Ray::m_startpoint [protected]
 

Definition at line 41 of file ray.h.

Referenced by AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), Trilinear::Lighting(), Lighting(), and Ray().

float Ray::m_steplength [protected]
 

Definition at line 44 of file ray.h.

Referenced by AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), Initialize(), and Ray().

Transfunc* Ray::m_tf [protected]
 

Definition at line 31 of file ray.h.

Referenced by Trilinear::CalcAlphaTrilinear(), Trilinear::CalcColorTrilinear(), AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), Initialize(), and Ray().

Plane* Ray::m_viewingplane [protected]
 

Definition at line 45 of file ray.h.

Referenced by Initialize(), and Ray().

float Ray::mx [protected]
 

Definition at line 47 of file ray.h.

Referenced by AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), Initialize(), and Ray().

float Ray::my [protected]
 

Definition at line 47 of file ray.h.

Referenced by AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), Initialize(), and Ray().

float Ray::mz [protected]
 

Definition at line 47 of file ray.h.

Referenced by AverageTRI::CastNext(), AverageNN::CastNext(), XRayTRI::CastNext(), XRayNN::CastNext(), MaxIntensityTRI::CastNext(), MaxIntensityNN::CastNext(), FirstHitTRI::CastNext(), FirstHitNN::CastNext(), Trilinear::CastNext(), CastNext(), Initialize(), and Ray().


The documentation for this class was generated from the following files:
Generated on Thu Jan 23 12:32:16 2003 by doxygen1.3-rc2