DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes
DGtal::DGtalInventor< TSpace > Class Template Reference

#include <DGtalInventor.h>

Collaboration diagram for DGtal::DGtalInventor< TSpace >:
Collaboration graph
[legend]

Public Types

typedef TSpace Space
typedef TSpace::Point Point
typedef TSpace::Dimension Dimension
typedef TSpace::Integer Integer
typedef std::map< std::string,
std::string > 
ModeMapping
typedef SbVec3f Vec3f
typedef Vec3f Color
typedef std::map< Point, bool > CellSet
typedef std::map< Point, Vec3fColorMapping
typedef std::map< Point, ColorNormalMapping

Public Member Functions

 ~DGtalInventor ()
 DGtalInventor ()
void setLattice (const Lattice< Space > &l)
void clear ()
std::string getMode (const std::string &objectName) const
void setDiffuseColor (const float *color)
void setDiffuseColor (const Color &color)
void drawCell (const Point &c, bool orient, const float *n=0)
void drawPoint (const Point &c, const float *n=0)
void generate (SoGroup *result) const
void selfDisplay (std::ostream &out) const
bool isValid () const

Private Member Functions

 BOOST_CONCEPT_ASSERT ((CSpace< TSpace >))
 DGtalInventor (const DGtalInventor &other)
DGtalInventoroperator= (const DGtalInventor &other)

Private Attributes

Lattice< SpacemyLattice
ModeMapping myModes
Color myDiffuseColor
CellSet myCells [3]
ColorMapping myColors
NormalMapping myNormals

Detailed Description

template<typename TSpace>
class DGtal::DGtalInventor< TSpace >

Aim: A stream object based on Open Inventor for exporting or displaying DGtal objects.

Description of template class 'DGtalInventor'

Digital points, cells and objects may be outputed in that kind of object. The user may then ask to view the object or simply export its content.

Template Parameters:
TSpacethe type of digital space (should realize a CSpace).

Definition at line 83 of file DGtalInventor.h.


Member Typedef Documentation

template<typename TSpace>
typedef std::map< Point, bool > DGtal::DGtalInventor< TSpace >::CellSet

Definition at line 103 of file DGtalInventor.h.

template<typename TSpace>
typedef Vec3f DGtal::DGtalInventor< TSpace >::Color

Definition at line 102 of file DGtalInventor.h.

template<typename TSpace>
typedef std::map< Point, Vec3f > DGtal::DGtalInventor< TSpace >::ColorMapping

Definition at line 104 of file DGtalInventor.h.

template<typename TSpace>
typedef TSpace::Dimension DGtal::DGtalInventor< TSpace >::Dimension

Definition at line 92 of file DGtalInventor.h.

template<typename TSpace>
typedef TSpace::Integer DGtal::DGtalInventor< TSpace >::Integer

Definition at line 93 of file DGtalInventor.h.

template<typename TSpace>
typedef std::map< std::string, std::string > DGtal::DGtalInventor< TSpace >::ModeMapping

The associated map type for storing possible modes used for displaying for digital objects.

Definition at line 99 of file DGtalInventor.h.

template<typename TSpace>
typedef std::map< Point, Color > DGtal::DGtalInventor< TSpace >::NormalMapping

Definition at line 105 of file DGtalInventor.h.

template<typename TSpace>
typedef TSpace::Point DGtal::DGtalInventor< TSpace >::Point

Definition at line 91 of file DGtalInventor.h.

template<typename TSpace>
typedef TSpace DGtal::DGtalInventor< TSpace >::Space

Definition at line 90 of file DGtalInventor.h.

template<typename TSpace>
typedef SbVec3f DGtal::DGtalInventor< TSpace >::Vec3f

Definition at line 101 of file DGtalInventor.h.


Constructor & Destructor Documentation

template<typename TSpace >
DGtal::DGtalInventor< TSpace >::~DGtalInventor ( )
inline

Destructor.

Definition at line 46 of file DGtalInventor.ih.

{
}
template<typename TSpace >
DGtal::DGtalInventor< TSpace >::DGtalInventor ( )
inline

Constructor. Creates a default lattice for display.

Constructor.

Definition at line 55 of file DGtalInventor.ih.

References DGtal::Lattice< TSpace >::init(), and DGtal::DGtalInventor< TSpace >::myLattice.

{
myLattice.init( Space::dimension, 3 );
}
template<typename TSpace>
DGtal::DGtalInventor< TSpace >::DGtalInventor ( const DGtalInventor< TSpace > &  other)
private

Copy constructor.

Parameters:
otherthe object to clone. Forbidden by default.

Member Function Documentation

template<typename TSpace>
DGtal::DGtalInventor< TSpace >::BOOST_CONCEPT_ASSERT ( (CSpace< TSpace >)  )
private
template<typename TSpace >
void DGtal::DGtalInventor< TSpace >::clear ( )
inline

Clears everything. The object is ready for a new visualization and keeps its lattice.

Definition at line 98 of file DGtalInventor.ih.

References DGtal::DGtalInventor< TSpace >::clear().

Referenced by DGtal::DGtalInventor< TSpace >::clear().

{
myCells[ 0 ].clear();
myCells[ 1 ].clear();
myCells[ 2 ].clear();
myNormals.clear();
myColors.clear();
}
template<typename TSpace >
void DGtal::DGtalInventor< TSpace >::drawCell ( const Point c,
bool  orient,
const float *  n = 0 
)
inline

Adds a cell for visualisation. Gives an optional normal. Nb : if a cell has dimension greater than 2, the boundary of the cell is taken and this method is recursively called.

Parameters:
cthe cell to visualize (in Khalimsky coordinates).
nthe (optional) normal to the cell as a 3D vector.

Definition at line 141 of file DGtalInventor.ih.

{
// while cells are "volumic", extracts their boundary.
Dimension cdim = 0;
for ( typename Point::ConstIterator it = c.begin(); it != c.end(); ++it )
if ( *it & 0x1 ) ++cdim;
if ( cdim > 2 )
{
Point p( c );
for ( typename Point::Iterator it = p.begin(); it != p.end(); ++it )
if ( *it & 0x1 )
{
--(*it);
drawCell( p, false, n );
*it += 2;
drawCell( p, true, n );
--(*it);
}
}
else
{
myCells[ cdim ].insert( std::make_pair( c, orient ) );
if ( n != 0 ) myNormals[ c ] = n;
}
}
template<typename TSpace >
void DGtal::DGtalInventor< TSpace >::drawPoint ( const Point c,
const float *  n = 0 
)
inline

Adds a Zn-point for visualisation. Gives an optional normal.

Parameters:
pthe point to visualize.
nthe (optional) normal to the cell as a 3D vector.

Definition at line 177 of file DGtalInventor.ih.

{
Point q;
for ( Dimension i = 0; i < c.dimension; ++i )
q[ i ] = 2*c[ i ] + 1;
drawCell( q, n );
}
template<typename TSpace >
void DGtal::DGtalInventor< TSpace >::generate ( SoGroup *  result) const

Generates the IV surface/lines/points with children rooted at the SoGroup [result].

Parameters:
result(returns) an updated IV node.

Definition at line 225 of file DGtalInventor.ih.

{
typedef float vec3[ 3 ];
typedef DGtal::int32_t int32;
typedef DGtal::uint32_t uint32;
SoShapeHints *myShapeHints = new SoShapeHints;
myShapeHints->vertexOrdering = SoShapeHints::UNKNOWN_ORDERING;//COUNTERCLOCKWISE; //UNKNOWN_ORDERING; //COUNTERCLOCKWISE;
myShapeHints->shapeType =
false ? SoShapeHints::SOLID : SoShapeHints::UNKNOWN_SHAPE_TYPE;
myShapeHints->faceType = SoShapeHints::CONVEX;
myShapeHints->creaseAngle = 1.0;
result->addChild( myShapeHints );
// some initialization
uint32 nb_vtx; // number of vertices to display
uint32 nb_cells; // number of cells
vec3* coords; // array of vertex coordinates
vec3* xyz; // pointer to fill array [coords]
SoCoordinate3 *myCoords; // structure to store coordinates
typename CellSet::const_iterator ip;
typename CellSet::const_iterator ip_end;
int32* indices;// for each face, gives the number of vertices
vec3* normals;// array of normal vectors
vec3* colors; // array of color vectors
typename ColorMapping::const_iterator itc;
typename NormalMapping::const_iterator itn;
int idx;
// Taking care of 2-cells
nb_cells = myCells[ 2 ].size();
nb_vtx = 4 * nb_cells;
if ( nb_vtx != 0 )
{
cout << "2-cells = " << nb_vtx << endl;
SoGroup* node_squares = new SoGroup;
myCoords = new SoCoordinate3;
coords = new vec3[ nb_vtx ];
ip = myCells[ 2 ].begin();
ip_end = myCells[ 2 ].end();
xyz = coords;
indices = new int32[ nb_cells ];
normals = new vec3[ nb_cells ];
colors = new vec3[ nb_cells ];
idx = 0;
SbVec3f uv1;
SbVec3f uv2;
SbVec3f n;
while ( ip != ip_end )
{
unsigned int d = 0;
Point c = ip->first;
bool orient = ip->second;
Point e;
Dimension dirs[ 2 ];
for ( Dimension i = 0; i < c.dimension; ++i )
{
if ( c[ i ] & 0x1 )
dirs[ d++ ] = i;
e[ i ] = c[ i ] >> 1;
}
// creating face coordinates
myLattice.immerse( e, *xyz );
uv1.setValue( *xyz );
uv2.setValue( *xyz );
++xyz;
e[ dirs[ 0 ] ] ++;
myLattice.immerse( e, *xyz );
uv1 -= SbVec3f( *xyz );
++xyz;
e[ dirs[ 1 ] ] ++;
myLattice.immerse( e, *xyz );
++xyz;
e[ dirs[ 0 ] ] --;
myLattice.immerse( e, *xyz );
uv2 -= SbVec3f( *xyz );
++xyz;
indices[ idx ] = 4;
// retracts( xyz - 4, 4 );
// Creating face normals
itn = myNormals.find( c );
n = uv1.cross( uv2 );
if ( orient )
{
if ( n[ 0 ] < 0.0 ) n[ 0 ] = -n[ 0 ];
if ( n[ 1 ] < 0.0 ) n[ 1 ] = -n[ 1 ];
if ( n[ 2 ] < 0.0 ) n[ 2 ] = -n[ 2 ];
}
else
{
if ( n[ 0 ] > 0.0 ) n[ 0 ] = -n[ 0 ];
if ( n[ 1 ] > 0.0 ) n[ 1 ] = -n[ 1 ];
if ( n[ 2 ] > 0.0 ) n[ 2 ] = -n[ 2 ];
}
if ( itn != myNormals.end() )
{
n = itn->second;
double dot = uv1[0]*n[0]+uv1[1]*n[1]+uv1[2]*n[2];
if ( dot < 0.0 )
{
vec3* xyz1 = xyz - 3;
vec3* xyz2 = xyz - 1;
std::swap( (*xyz1)[0], (*xyz2)[0] );
std::swap( (*xyz1)[1], (*xyz2)[1] );
std::swap( (*xyz1)[2], (*xyz2)[2] );
}
}
n.getValue( normals[ idx ][ 0 ],
normals[ idx ][ 1 ],
normals[ idx ][ 2 ] );
// Creating face colors
itc = myColors.find( c );
if ( itc != myColors.end() )
n = itc->second;
n.getValue( colors[ idx ][ 0 ],
colors[ idx ][ 1 ],
colors[ idx ][ 2 ] );
++idx;
++ip;
}
// Coordinates
myCoords->point.setValues( 0, nb_vtx, coords );
node_squares->addChild( myCoords );
// Normals
SoNormal* iNormals = new SoNormal;
iNormals->vector.setValues( 0, idx, normals );
delete[] normals;
node_squares->addChild( iNormals );
SoNormalBinding *iNormalBinding = new SoNormalBinding;
iNormalBinding->value = SoNormalBinding::PER_FACE;
// instead of SoNormalBinding::PER_VERTEX_INDEXED;
node_squares->addChild( iNormalBinding );
// Colors
SoMaterial* iMaterials = new SoMaterial;
iMaterials->diffuseColor.setValues( 0, idx, colors );
delete[] colors;
node_squares->addChild( iMaterials );
SoMaterialBinding* iMaterialBinding = new SoMaterialBinding;
iMaterialBinding->value = SoMaterialBinding::PER_FACE;
node_squares->addChild( iMaterialBinding );
// Faces
SoFaceSet* face_set = new SoFaceSet;
face_set->numVertices.setValues( 0, idx, indices );
node_squares->addChild( face_set );
result->addChild( node_squares );
delete[] indices;
}
}
template<typename TSpace >
std::string DGtal::DGtalInventor< TSpace >::getMode ( const std::string &  objectName) const
inline
Parameters:
objectNamethe name of the object (generally obtained with a 'object.className()').
Returns:
the current mode for the given object name or "" if no specific mode has been set.
the current mode for the given object name or "" if no specific mode has been set.

Definition at line 68 of file DGtalInventor.ih.

{
ModeMapping::const_iterator itm = myModes.find( objectName );
return itm == myModes.end() ? "" : itm->second;
}
template<typename TSpace >
bool DGtal::DGtalInventor< TSpace >::isValid ( ) const
inline

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.

Definition at line 207 of file DGtalInventor.ih.

{
return true;
}
template<typename TSpace>
DGtalInventor& DGtal::DGtalInventor< TSpace >::operator= ( const DGtalInventor< TSpace > &  other)
private

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'. Forbidden by default.
template<typename TSpace >
void DGtal::DGtalInventor< TSpace >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 195 of file DGtalInventor.ih.

{
out << "[DGtalInventor]";
}
template<typename TSpace >
void DGtal::DGtalInventor< TSpace >::setDiffuseColor ( const float *  color)
inline
Parameters:
colorthe diffuse color.
colorthe (optional) diffuse color.

Definition at line 113 of file DGtalInventor.ih.

{
myDiffuseColor = Color( color );
}
template<typename TSpace >
void DGtal::DGtalInventor< TSpace >::setDiffuseColor ( const Color color)
inline
Parameters:
colorthe diffuse color.

Definition at line 124 of file DGtalInventor.ih.

{
myDiffuseColor = color;
}
template<typename TSpace >
void DGtal::DGtalInventor< TSpace >::setLattice ( const Lattice< Space > &  l)
inline

All further operations are immersed in Inventor 3D space with the lattice [l].

Parameters:
lthe lattice space which should be of dimension TSpace::dimension.

Definition at line 84 of file DGtalInventor.ih.

References DGtal::Lattice< TSpace >::n().

{
ASSERT( l.n() == Space::dimension );
myLattice = l;
}

Field Documentation

template<typename TSpace>
CellSet DGtal::DGtalInventor< TSpace >::myCells[3]
private

Definition at line 221 of file DGtalInventor.h.

template<typename TSpace>
ColorMapping DGtal::DGtalInventor< TSpace >::myColors
private

Definition at line 222 of file DGtalInventor.h.

template<typename TSpace>
Color DGtal::DGtalInventor< TSpace >::myDiffuseColor
private

Definition at line 220 of file DGtalInventor.h.

template<typename TSpace>
Lattice<Space> DGtal::DGtalInventor< TSpace >::myLattice
private

lattice for embedding of digital space.

Definition at line 208 of file DGtalInventor.h.

Referenced by DGtal::DGtalInventor< TSpace >::DGtalInventor().

template<typename TSpace>
ModeMapping DGtal::DGtalInventor< TSpace >::myModes
private

May associate a current mode for a given class. myModes[ "HyperRectDomain" ] = "Paving".

Next display of a HyperRectDomain object will used the mode "Paving". Modes may only be used in objects implementing the concept CDrawableWithBoard2D.

Definition at line 218 of file DGtalInventor.h.

template<typename TSpace>
NormalMapping DGtal::DGtalInventor< TSpace >::myNormals
private

Definition at line 223 of file DGtalInventor.h.


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