RTVolumeRendering/Source/MathCommon.h File Reference

Defines useful math functions, constants and types. More...

#include <cmath>
#include <assert.h>
#include "Vector3.h"
#include "Point3.h"
#include "Matrix.h"

Include dependency graph for MathCommon.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  LineSegment
 Defines a line segment. More...
struct  Ray
 Defines a ray. More...
struct  Plane
 Defines an infinite planes. More...
struct  ScreenRect
 Defines a 2D rectangular region of screen space. More...
struct  Sphere
 Defines a sphere. More...
struct  CubeDef
 Defines a cube. More...
struct  CubePlanes
 Defines the planes of a cube. More...
struct  CubeFrame
 Defines the lines that make up a cube. More...

Functions

template<class dataType, class timeType>
dataType Lerp (const dataType &d0, const dataType &d1, const timeType &t)
 Linearly interpolates between two data points.
template<class T>
void Swap (T &v1, T &v2)
 Swaps the given values.
template<class T>
Clamp (const T &val, const T &low, const T &high)
 Clamps a value to be in a given range.
CubePlanes CreatePlanes (const CubeDef &c)
 Creates a CubePlanes structure from a CubeDef.
CubeFrame CreateFrame (const CubeDef &c)
 Creates a CubeFrame from a CubeDef.
bool Inside (const Point3f &p, const Sphere &s)
 Tests if a point is inside a sphere.
bool Inside (int x, int y, const ScreenRect &rect)
 Tests if a point is inside a screen rectangle.
int Intersect (const LineSegment &line, const Plane &plane, float &t)
 Finds the intersection point between the a line and a plane.
int Intersect (const Plane &p, const CubeFrame &c, Point3f points[6])
 Intersects a Plane with a Cube.
int Intersect (const LineSegment &line, const Sphere &s, Point3f points[2])
 Intersects a Line segment with a sphere.
int Intersect (const Ray &r, const Sphere &s, Point3f points[2])
 Intersects a Ray with a sphere.
Point3f Average (const Point3f *points, int n)
 Computes the average of a set of points.
float ReferanceAngle (const Vector3f &ref, const Vector3f &v1, const Vector3f &v2)
 Computes the angle between two vectors and a mutaully perpendicular referance vector.
void SortPoints (Point3f *points, int n, const Vector3f &normal)
 Sorts a set of points into cw or ccw order.


Detailed Description

Defines useful math functions, constants and types.

Author:
Joe Forte
Date:
9/26/2008

Definition in file MathCommon.h.


Function Documentation

Point3f Average ( const Point3f points,
int  n 
) [inline]

Computes the average of a set of points.

Parameters:
[in] points the points.
[in] n the number of points.
Returns:
The average of the given points.

Definition at line 416 of file MathCommon.h.

Referenced by SortPoints().

template<class T>
T Clamp ( const T &  val,
const T &  low,
const T &  high 
) [inline]

Clamps a value to be in a given range.

Parameters:
[in] val the value to clamp.
[in] low the low end of the range.
[in] high the high end of the range.
Returns:
The clamped value in the range [low, high].

Definition at line 154 of file MathCommon.h.

Referenced by TransferFunctionPlot::MouseMove().

CubeFrame CreateFrame ( const CubeDef c  )  [inline]

Creates a CubeFrame from a CubeDef.

Parameters:
[in] c the cube.
Returns:
the equivalent CubeFrame to the given cube.

Definition at line 195 of file MathCommon.h.

References CubeDef::c, CubeDef::dim, CubeFrame::line, LineSegment::p1, and LineSegment::p2.

Referenced by Cube::Init(), and RTVolumeRenderer::RTVolumeRenderer().

CubePlanes CreatePlanes ( const CubeDef c  )  [inline]

Creates a CubePlanes structure from a CubeDef.

Parameters:
[in] c the cube.
Returns:
the equivalent CubePlanes of the given cube.

Definition at line 170 of file MathCommon.h.

References CubeDef::dim, Plane::n, Plane::p, and CubePlanes::plane.

Referenced by Cube::Init().

bool Inside ( int  x,
int  y,
const ScreenRect rect 
) [inline]

Tests if a point is inside a screen rectangle.

Parameters:
[in] x the x coordinate point.
[in] y the y coordinate point.
[in] rect the rectangle.
Returns:
true if the point is inside the screen rectangle, false otherwise.

Definition at line 249 of file MathCommon.h.

References ScreenRect::x1, ScreenRect::x2, and ScreenRect::y2.

bool Inside ( const Point3f p,
const Sphere s 
) [inline]

Tests if a point is inside a sphere.

Parameters:
[in] p the point.
[in] s the sphere.
Returns:
true if the point is inside the sphere, false otherwise.

Definition at line 234 of file MathCommon.h.

References Sphere::c, Sphere::r, and Vector3< T >::SquaredLength().

Referenced by TransferFunctionPlot::SelectPoint(), and Camera::Zoom().

int Intersect ( const Ray r,
const Sphere s,
Point3f  points[2] 
) [inline]

Intersects a Ray with a sphere.

Parameters:
[in] r the ray.
[in] s the line sphere.
[out] points the intersection points.
Returns:
the number of intersections: 0, 1 or 2.

Definition at line 369 of file MathCommon.h.

References Sphere::c, Ray::d, Lerp(), Ray::p, and Sphere::r.

int Intersect ( const LineSegment line,
const Sphere s,
Point3f  points[2] 
) [inline]

Intersects a Line segment with a sphere.

Parameters:
[in] line the line segment.
[in] s the line sphere.
[out] points the intersection points.
Returns:
the number of intersections: 0, 1 or 2.

Definition at line 313 of file MathCommon.h.

References Sphere::c, LineSegment::p1, LineSegment::p2, and Sphere::r.

int Intersect ( const Plane p,
const CubeFrame c,
Point3f  points[6] 
) [inline]

Intersects a Plane with a Cube.

Parameters:
[in] p the plane.
[in] c the cube frame.
[out] points the intersection points.
Returns:
0 if the plane doesn't intersect the cube. The number of intersections 3 to 6.

Definition at line 285 of file MathCommon.h.

References Intersect(), CubeFrame::line, LineSegment::p1, and LineSegment::p2.

int Intersect ( const LineSegment line,
const Plane plane,
float &  t 
) [inline]

Finds the intersection point between the a line and a plane.

Parameters:
[in] line the line.
[in] plane the plane.
[out] t the collision time.
Returns:
1 if the line intersects the plane. 0 if the line is parallel with the plane (t is not valid).

Definition at line 264 of file MathCommon.h.

References Plane::n, Plane::p, LineSegment::p1, and LineSegment::p2.

Referenced by Intersect(), and Camera::Zoom().

template<class dataType, class timeType>
dataType Lerp ( const dataType &  d0,
const dataType &  d1,
const timeType &  t 
) [inline]

Linearly interpolates between two data points.

Template Parameters:
dataType the type of data that is being interpolated.
timeType the type of the value that controls the amount of interpolation.
Parameters:
[in] d0 the first data point.
[in] d1 the second data point.
[in] t the amount to interpolate.
Returns:
the linearly interpolated value between the two data points.

Definition at line 125 of file MathCommon.h.

Referenced by Intersect().

float ReferanceAngle ( const Vector3f ref,
const Vector3f v1,
const Vector3f v2 
) [inline]

Computes the angle between two vectors and a mutaully perpendicular referance vector.

Parameters:
[in] ref the referance vector.
[in] v1 the first vector.
[in] v2 the second vector.
Returns:
the angle between 'v1' and 'v2' with respect to 'ref'.

Definition at line 436 of file MathCommon.h.

References Vector3< T >::Length().

Referenced by SortPoints().

void SortPoints ( Point3f points,
int  n,
const Vector3f normal 
) [inline]

Sorts a set of points into cw or ccw order.

Parameters:
[in,out] points the points to sort.
[in] n the number of points. Must be in the range [3,6].
[in] normal the polygon normal that the points lie on.

Definition at line 453 of file MathCommon.h.

References Average(), and ReferanceAngle().

template<class T>
void Swap ( T &  v1,
T &  v2 
) [inline]

Swaps the given values.

Parameters:
[in,out] v1 the first value.
[in,out] v2 the second value.

Definition at line 137 of file MathCommon.h.


Generated on Thu Jan 15 00:58:04 2009 for RTVolumeRendering by  doxygen 1.5.6