LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::draw3D< T > Class Template Reference

Tool for drawing 3D points and lines in a lti::matrix. More...

#include <ltiDraw3D.h>

Inheritance diagram for lti::draw3D< T >:
Inheritance graph
[legend]
Collaboration diagram for lti::draw3D< T >:
Collaboration graph
[legend]

List of all members.

Classes

class  hmatrix
 homogene matrix More...
class  parameters
 parameters for draw3D. More...
class  triangle
 Triangle is the base for all other polygons. More...

Public Member Functions

 draw3D ()
 ~draw3D ()
virtual const char * getTypeName () const
void use (matrix< T > &img)
bool setParameters (const parameters &opt)
const parametersgetParameters () const
parametersgetParameters ()
void setCamera (const double &x1, const double &y1, const double &z1, const double &x2, const double &y2, const double &z2)
void setCamera (const double &x1, const double &y1, const double &z1, const double &elevation, const double &azimuth)
void setCamera (const dpoint3D &x1, const dpoint3D &x2)
void setCamera (const dpoint3D &x1, const double &elevation, const double &azimuth)
void setPerspective (const double &p)
void setCenter (const double &x, const double &y)
void setCenter (const dpoint &x)
void setZoom (const double &z)
dpoint getOriginPosition () const
const hmatrixgetCameraMatrix () const
void resetDeepCtrl (const bool deep=true)
void p3Dto2D (const double &x, const double &y, const double &z, int &x2, int &y2, double &z2) const
void p3Dto2D (const dpoint3D &p3, point &p2, double &z2) const
void set3D (const dpoint3D &p)
void set2D (const int &x, const int &y, const double &z)
void marker3D (const double &x, const double &y, const double &z)
void marker3D (const double &x, const double &y, const double &z, const char *style)
void set3D (const double &x, const double &y, const double &z)
template<class U >
void set3D (const hPoint3D< U > &p)
void line3DTo (const double &x, const double &y, const double &z)
void line3DTo (const dpoint3D &p)
void line3D (const dpoint3D &a, const dpoint3D &b)
void line3D (const double &x, const double &y, const double &z, const double &x2, const double &y2, const double &z2)
void box (const dpoint3D &a, const dpoint3D &b, const bool filled=true)
void box (const dpoint3D &a, const dpoint3D &b, const T lineColor)
void ellipsoid (const vector< double > &mean, const matrix< double > &sigma, const double &cst)
void set3D (const channel &chnl, const float &height, const point &gridSize=point(5, 5), const point &sampleRate=point(1, 1), const bool onlyPoints=false, const bool useBoxes=false, const bool heightColor=false, const bool drawLines=false, const T &lineColor=T(), const bool drawContour=false, const T &contourColor=T())
void grid (const double size, const int nbSteps)
void axis (const double size)
void axis (const double size, const T &colorX, const T &colorY, const T &colorZ)

Static Public Member Functions

static T getGray (const float &val)

Protected Member Functions

bool correctLine (int &x, int &y, double &z, const int &x2, const int &y2, const double &z2)
shadingColor (const dpoint3D &nrm, const T &color) const
void set3D (const triangle &t, const bool filled=true)
void ioLine (const point &p1, const double &z1, const point &p2, const double &z2, ivector &in, ivector &out, dvector &zIn, dvector &zOut, const int firstY) const
double copysign (const double &a, const double &b)
int sign (const double &a)

Protected Attributes

parameters param
bool deepCtrl
matrix< float > deepImg
dpoint3D act
hmatrix cam
dpoint3D camTarget
dpoint center
dpoint precenter

Detailed Description

template<class T>
class lti::draw3D< T >

Tool for drawing 3D points and lines in a lti::matrix.

The template type T specifies the type of elements of the matrix. To draw in a color image you will need for example a lti::draw3D<rgbPixel> object. Use the parameters to set the camera position and direction. You can activate/deactivate a z-Buffering using the method resetDeepCtrl(bool), where the boolean should be true if you want to activate the z-Buffering, or false otherwise. The default state for the z-Buffering is off.

Example:

 double a;

 lti::image canvas;                 // the image to draw on
 lti::draw3D<lti::rgbPixel> drawer; // our draw object
 lti::viewer view;                  // a viewer to see what we do

 canvas.resize(256,256,lti::Black); // 256x256 are enough
 drawer.use(canvas);
 drawer.setZoom(50);


 // take pictures all around... (at 1/2 degree steps...)
 for (a=0;a<5*2.0*lti::Pi;a+=0.5*lti::Pi/180.0) {
   canvas.fill(lti::Black);
   drawer.resetDeepCtrl(true); // activate the z-Buffering
   drawer.setCamera(1.5*sin(a),1.5*cos(a),1,0,0,0);

   // draw a cube
   drawer.setColor(lti::White);

   // draw the lower plate
   drawer.set3D(1,1,-1);
   drawer.line3DTo(-1,1,-1);
   drawer.line3DTo(-1,-1,-1);
   drawer.line3DTo(1,-1,-1);
   drawer.line3DTo(1,1,-1);

   // draw the upper plate
   drawer.set3D(1,1,1);
   drawer.line3DTo(-1,1,1);
   drawer.line3DTo(-1,-1,1);
   drawer.line3DTo(1,-1,1);
   drawer.line3DTo(1,1,1);

   // and the edges
   drawer.setColor(lti::Red);
   drawer.line3D(-1, 1,1,-1, 1,-1);
   drawer.setColor(lti::Green);
   drawer.line3D(-1,-1,1,-1,-1,-1);
   drawer.setColor(lti::Blue);
   drawer.line3D( 1,-1,1, 1,-1,-1);
   drawer.setColor(lti::Yellow);
   drawer.line3D( 1, 1,1, 1, 1,-1);

   view.show(canvas);
 }

See also draw3D<T>::parameters for more information about the camera parameters.


Constructor & Destructor Documentation

template<class T>
lti::draw3D< T >::draw3D (  ) 

default constructor

template<class T>
lti::draw3D< T >::~draw3D (  ) 

destructor


Member Function Documentation

template<class T>
void lti::draw3D< T >::axis ( const double  size,
const T &  colorX,
const T &  colorY,
const T &  colorZ 
)

draw axis with dimension "size" and using the given color for each axis

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::axis ( const double  size  ) 

draw axis with dimension "size"

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::box ( const dpoint3D a,
const dpoint3D b,
const T  lineColor 
)

draw a filled box of the actual color with the opposite corners a and b, and with the line color given

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::box ( const dpoint3D a,
const dpoint3D b,
const bool  filled = true 
)

draw a box with the opposite corners a and b

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T >
double lti::draw3D< T >::copysign ( const double &  a,
const double &  b 
) [inline, protected]

copysign return abs(a) with the sign of b

References lti::draw3D< T >::sign().

template<class T>
bool lti::draw3D< T >::correctLine ( int &  x,
int &  y,
double &  z,
const int &  x2,
const int &  y2,
const double &  z2 
) [protected]

checks and corrects 3D line to be within the image

template<class T>
void lti::draw3D< T >::ellipsoid ( const vector< double > &  mean,
const matrix< double > &  sigma,
const double &  cst 
)

Draw an ellipsoid surface defined through a constant mahalanobis distance between the mean vector and the points of the surface, i.e.

the surface contains all points that satisfy the equation (x-mean)^T sigma^(-1) (x-mean) = cst

The color of the ellipsoid is given with the setColor() method, and the lighting conditions with the parameter "lighting".

Parameters:
mean point at the center of the ellipsoid.
sigma covariance matrix
cst mahalanobis distace from the points at the surface and the mean value

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
const hmatrix& lti::draw3D< T >::getCameraMatrix (  )  const

get a read-only reference of the transformation matrix being used.

template<class T>
static T lti::draw3D< T >::getGray ( const float &  val  )  [static]

return a grey value for the proper type T, where the input is always between 0 (black) and 1 (white).

template<class T>
dpoint lti::draw3D< T >::getOriginPosition (  )  const

get a read-only reference to the coordinate point in the current image, where the origin of the world coordinates will be projected.

template<class T>
parameters& lti::draw3D< T >::getParameters ( void   )  [inline]
template<class T>
const parameters& lti::draw3D< T >::getParameters ( void   )  const [inline]
template<class T>
virtual const char* lti::draw3D< T >::getTypeName (  )  const [virtual]

return the name of the this object

Reimplemented from lti::draw< T >.

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::grid ( const double  size,
const int  nbSteps 
)

draw a grid with dimension "size" using the actual drawnig color.

The grid lies in all three dimensions at size/2.

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::ioLine ( const point p1,
const double &  z1,
const point p2,
const double &  z2,
ivector in,
ivector out,
dvector zIn,
dvector zOut,
const int  firstY 
) const [protected]

help function for triangle.

Draws a line as io codes in the given lists. This function expects p1.y <= p2.y

template<class T>
void lti::draw3D< T >::line3D ( const double &  x,
const double &  y,
const double &  z,
const double &  x2,
const double &  y2,
const double &  z2 
)

draw a line between (x,y,z) and (x2,y2,z2)

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::line3D ( const dpoint3D a,
const dpoint3D b 
)

draw a line between a and b

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::line3DTo ( const dpoint3D p  ) 

draw a line between the last used point and (x,y,z)

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::line3DTo ( const double &  x,
const double &  y,
const double &  z 
)

draw a line between the last used point and (x,y,z)

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::marker3D ( const double &  x,
const double &  y,
const double &  z,
const char *  style 
)

sets marker with given style

template<class T>
void lti::draw3D< T >::marker3D ( const double &  x,
const double &  y,
const double &  z 
)

sets marker with selected style

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::p3Dto2D ( const dpoint3D p3,
point p2,
double &  z2 
) const

project 3D point into camera plane

template<class T>
void lti::draw3D< T >::p3Dto2D ( const double &  x,
const double &  y,
const double &  z,
int &  x2,
int &  y2,
double &  z2 
) const

project 3D point into camera plane

template<class T>
void lti::draw3D< T >::resetDeepCtrl ( const bool  deep = true  ) 

reset z-Buffer.

With this method you can activate/deactivate the z-Buffering. This allows the correct display of your drawings. Note that if you resize the used image (see use()), this object will not be able to detect it automatically (this would take too much time!) and your program could crash! To avoid problems, call again one of use or resetDeepCtrlmethods after resizing your image.

Parameters:
deep if true, the z-Buffering will be activated, otherwise the z-Buffering will be deactivated.
template<class T>
void lti::draw3D< T >::set2D ( const int &  x,
const int &  y,
const double &  z 
)

sets 2D point with the selected color if it is in front of all other points with the same projection coordinates, considering the z-buffering (if enabled) and the given z coordinate.

If the z-buffering is disabled, the pixel at (x,y) will be set.

Parameters:
x position x
y position y
z deep information

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::set3D ( const triangle t,
const bool  filled = true 
) [protected]

sets a triangle

template<class T>
void lti::draw3D< T >::set3D ( const channel chnl,
const float &  height,
const point gridSize = point(5, 5),
const point sampleRate = point(1, 1),
const bool  onlyPoints = false,
const bool  useBoxes = false,
const bool  heightColor = false,
const bool  drawLines = false,
const T &  lineColor = T(),
const bool  drawContour = false,
const T &  contourColor = T() 
)

Draw the given channel as a 3D structure, where the height of the pixel is given by its intensity.

The actual color will be shaded to produce the 3D effect. The y-axis will be inverted, to convert the image left coordinate system to the 3D right system.

Parameters:
chnl the channel with the 3D information
height the height of the value 1.0 in the channel
gridSize the number of pixels used for a "cell" in the grid. Use for example point(5,5)
sampleRate determines which pixels in the image are going to be used in the grid points. point(1,1) uses all pixels, point(2,2) each second point and so on.
onlyPoints if true, only the points will be drawn, if false, boxes or grids will be drawn.
useBoxes if true, boxes will be used to display each pixel, otherwise a triangular mesh will be used.
heightColor if true, the channel intensity will define the grey tone for the pixel, otherwise the actual color will be used.
drawLines if true, the vertical lines at each grid point will be drawn.
lineColor color for the vertical lines
drawContour if true, the contour of each triangle in the mesh will be redrawn using the countour color given.
contourColor color used to draw the contour of the triangles. Only used if drawContour is true

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
template<class U >
void lti::draw3D< T >::set3D ( const hPoint3D< U > &  p  )  [inline]

sets point with selected color

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::set3D ( const double &  x,
const double &  y,
const double &  z 
)

sets point with selected color

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

template<class T>
void lti::draw3D< T >::set3D ( const dpoint3D p  ) 

sets point with selected color

Reimplemented in lti::scene3D< T >, and lti::scene3D< rgbPixel >.

Referenced by lti::draw3D< rgbPixel >::set3D().

template<class T>
void lti::draw3D< T >::setCamera ( const dpoint3D x1,
const double &  elevation,
const double &  azimuth 
)

set position and direction of the camera

template<class T>
void lti::draw3D< T >::setCamera ( const dpoint3D x1,
const dpoint3D x2 
)

set position and target position of the camera

template<class T>
void lti::draw3D< T >::setCamera ( const double &  x1,
const double &  y1,
const double &  z1,
const double &  elevation,
const double &  azimuth 
)

set position and direction of the camera

template<class T>
void lti::draw3D< T >::setCamera ( const double &  x1,
const double &  y1,
const double &  z1,
const double &  x2,
const double &  y2,
const double &  z2 
)

set position and target position of the camera

template<class T>
void lti::draw3D< T >::setCenter ( const dpoint x  ) 

set camera plane center

These are relative coordinates, i.e. if you want to map the target camera point cam2 (see parameters) exactly at the center of your image, just setCenter(0.5,0.5).

template<class T>
void lti::draw3D< T >::setCenter ( const double &  x,
const double &  y 
)

set camera plane center.

These are relative coordinates, i.e. if you want to map the target camera point cam2 (see parameters) exactly at the center of your image, just setCenter(0.5,0.5).

template<class T>
bool lti::draw3D< T >::setParameters ( const parameters opt  ) 
template<class T>
void lti::draw3D< T >::setPerspective ( const double &  p  ) 

set perspective.

Set to zero for an orthographic projection or greater zero for perspective effects. You can consider this value as -1/f with f the focal distance. So, to get good results try always positive values

template<class T>
void lti::draw3D< T >::setZoom ( const double &  z  ) 

set zoom factor

template<class T>
T lti::draw3D< T >::shadingColor ( const dpoint3D nrm,
const T &  color 
) const [protected]

compute the shading color from "color", assuming that the light source is at z-axis in infinity, and the normal vector to the surface is given.

template<class T>
int lti::draw3D< T >::sign ( const double &  a  )  [inline, protected]

returns 1 if a >= 0.0; -1 otherwise

Referenced by lti::draw3D< T >::copysign().

template<class T>
void lti::draw3D< T >::use ( matrix< T > &  img  )  [virtual]

Indicates in which image will be drawn.

Reimplemented from lti::draw< T >.


Member Data Documentation

template<class T>
dpoint3D lti::draw3D< T >::act [protected]

actual (last used) 3D point coordinates

template<class T>
hmatrix lti::draw3D< T >::cam [protected]

camera homogene transformation matrix

template<class T>
dpoint3D lti::draw3D< T >::camTarget [protected]

camera target point

template<class T>
dpoint lti::draw3D< T >::center [protected]

camera plane center

template<class T>
bool lti::draw3D< T >::deepCtrl [protected]

true: use a Z-Buffer

template<class T>
matrix<float> lti::draw3D< T >::deepImg [protected]

Z-Buffer.

template<class T>
parameters lti::draw3D< T >::param [protected]
template<class T>
dpoint lti::draw3D< T >::precenter [protected]

camera plane center in normalized coordinates (0..1)


The documentation for this class was generated from the following file:

Generated on Sat Apr 10 15:27:14 2010 for LTI-Lib by Doxygen 1.6.1