ReadTAPsMBV< T > Class Template Reference

#include <TAPsReadTAPsMBV.hpp>

List of all members.

Static Public Member Functions

static bool ReadFile (const char *fileName, MultiBoundingVolume< T > *const prMBV)

Static Private Member Functions

static void ProcessNodeBOUNDING_VOLUME (char *line, MultiBoundingVolume< T > *const prMBV)

Static Private Attributes

static FILE * fileIn = NULL
static int iCounter = 0
static int iNumBoundingVolume = 0


Detailed Description

template<typename T>
class ReadTAPsMBV< T >

Create Bounding Volumes from .MBV file and put them in Multi Bounding Volume argument. Where MBV is MultiBoundingVolume.

TAPs is added to the name to clarify that the .MBV is locally defined for TAPs.

Definition at line 33 of file TAPsReadTAPsMBV.hpp.


Member Function Documentation

template<typename T>
void ReadTAPsMBV< T >::ProcessNodeBOUNDING_VOLUME ( char *  line,
MultiBoundingVolume< T > *const   prMBV 
) [inline, static, private]

Example:

A bounding cylinder example:

BOUNDING_VOLUME { ID 1 NAME "Arm One" BV_TYPE BOUNDING_CYLINDER RADIUS 2.1 HEIGHT 22 CENTER 0 2.75 9.5 TRANSLATION 0 0 21 ROTATION_AXIS_AND_ANGLE 1 0 0 25 In Degree TRANSLATION 0 0 -21 APPLY_TRANSFORMATION TRUE }

Definition at line 107 of file TAPsReadTAPsMBV.cpp.

00109 {
00110     //---------------------------------------------------------------
00111     // For Handling Transformations
00112     std::vector< std::string >  vTransformName;
00113     std::vector< T >            vTransformValue;
00114     //---------------------------------------------------------------
00115     // Example:
00116     //  BOUNDING_VOLUME {
00117     //      ID          0
00118     //      NAME        "Shaft"
00119     //      BV_TYPE     BOUNDING_CYLINDER
00120     //      RADIUS      5.25
00121     //      HEIGHT      300
00122     //      CENTER      0   0   0
00123     //      APPLY_TRANSFORMATION    TRUE
00124     //  }
00125     //---------------------------------------------------------------
00126     // Temp Data
00127     int         tempID              = iCounter;
00128     char        tempName[128];
00129     strcpy( tempName, "Unnamed" );
00130     char        tempString[128];
00131     Enum::CD    tempBoundingType    = Enum::BOUNDING_SPHERE;
00132     float       tempRadius          = 0.5;
00133     float       tempHeight          = 1;
00134     Vector3<T>  tempCenter          = Vector3<T>(0,0,0);
00135     bool        tempStatusApplyTransformation   = false;
00136     //---------------------------------------------------------------
00137     char node[128];
00138     do {
00139         fgets( line, 256, fileIn );
00140         sscanf( line, "%s", node );
00141         //std::cout << "IN: " << line;
00142         //---------------------------------------
00143         if      ( node[0] == '#' )  continue;
00144         //---------------------------------------
00145         else if ( !strncmp( node, "ID", strlen("ID") ) ) {
00146             sscanf( line, "%s %d", node, &tempID );
00147         }
00148         else if ( !strncmp( node, "NAME", strlen("NAME") ) ) {
00149             //char * strtok ( char * str, const char * delimiters );
00150             char * token;
00151             token = strtok (line, "\"");
00152             token = strtok (NULL, "\"");
00153             strcpy( tempName, token );
00154             //sscanf( line, "%s %s", node, tempName );
00155         }
00156         else if ( !strncmp( node, "BV_TYPE", strlen("BV_TYPE") ) ) {
00157             sscanf( line, "%s %s", node, tempString );
00158             //if ( !strncmp( tempString, "BOUNDING_SPHERE", strlen("BOUNDING_SPHERE") ) ) {
00159             //  tempBoundingType = Enum::BOUNDING_SPHERE;
00160             //}
00161             if ( !strncmp( tempString, "BOUNDING_BOX", strlen("BOUNDING_BOX") ) ) {
00162                 tempBoundingType = Enum::BOUNDING_BOX;
00163             }
00164             else if ( !strncmp( tempString, "BOUNDING_CYLINDER", strlen("BOUNDING_CYLINDER") ) ) {
00165                 tempBoundingType = Enum::BOUNDING_CYLINDER;
00166             }
00167             else if ( !strncmp( tempString, "BOUNDING_CONE", strlen("BOUNDING_CONE") ) ) {
00168                 tempBoundingType = Enum::BOUNDING_CONE;
00169             }
00170             else if ( !strncmp( tempString, "BOUNDING_HALF_SPHERE", strlen("BOUNDING_HALF_SPHERE") ) ) {
00171                 tempBoundingType = Enum::BOUNDING_HALF_SPHERE;
00172             }
00173             else if ( !strncmp( tempString, "BOUNDING_ELLIPSOID", strlen("BOUNDING_ELLIPSOID") ) ) {
00174                 tempBoundingType = Enum::BOUNDING_ELLIPSOID;
00175             }
00176             else if ( !strncmp( tempString, "BOUNDING_HALF_ELLIPSOID", strlen("BOUNDING_HALF_ELLIPSOID") ) ) {
00177                 tempBoundingType = Enum::BOUNDING_HALF_ELLIPSOID;
00178             }
00179             else if ( !strncmp( tempString, "BOUNDING_CAPSULE", strlen("BOUNDING_CAPSULE") ) ) {
00180                 tempBoundingType = Enum::BOUNDING_CAPSULE;
00181             }
00182             else if ( !strncmp( tempString, "BOUNDING_POLYTOPE", strlen("BOUNDING_POLYTOPE") ) ) {
00183                 tempBoundingType = Enum::BOUNDING_POLYTOPE;
00184             }
00185         }
00186         else if ( !strncmp( node, "RADIUS", strlen("RADIUS") ) ) {
00187             sscanf( line, "%s %g", node, &tempRadius );
00188         }
00189         else if ( !strncmp( node, "HEIGHT", strlen("HEIGHT") ) ) {
00190             sscanf( line, "%s %g", node, &tempHeight );
00191         }
00192         else if ( !strncmp( node, "CENTER", strlen("CENTER") ) ) {
00193             float x, y, z;
00194             sscanf( line, "%s %g %g %g", node, &x, &y, &z );
00195             tempCenter.SetXYZ( x, y, z );
00196         }
00197         else if ( !strncmp( node, "TRANSLATION", strlen("TRANSLATION") ) ) {
00198             float x, y, z;
00199             sscanf( line, "%s %g %g %g", node, &x, &y, &z );
00200             vTransformName.push_back( "TRANSLATION" );
00201             vTransformValue.push_back( x );
00202             vTransformValue.push_back( y );
00203             vTransformValue.push_back( z );
00204         }
00205         else if ( !strncmp( node, "ROTATION_AXIS_AND_ANGLE", strlen("ROTATION_AXIS_AND_ANGLE") ) ) {
00206             float x, y, z, a;
00207             sscanf( line, "%s %g %g %g %g", node, &x, &y, &z, &a );
00208             vTransformName.push_back( "ROTATION_AXIS_AND_ANGLE" );
00209             vTransformValue.push_back( x );
00210             vTransformValue.push_back( y );
00211             vTransformValue.push_back( z );
00212             vTransformValue.push_back( a );
00213         }
00214         else if ( !strncmp( node, "SCALE", strlen("SCALE") ) ) {
00215             float s;
00216             sscanf( line, "%s %g", node, &s );
00217             vTransformName.push_back( "SCALE" );
00218             vTransformValue.push_back( s );
00219         }
00220         else if ( !strncmp( node, "APPLY_TRANSFORMATION", strlen("APPLY_TRANSFORMATION") ) ) {
00221             sscanf( line, "%s %s", node, &tempString );
00222             if ( !strncmp( tempString, "TRUE", strlen("TRUE") ) ) {
00223                 tempStatusApplyTransformation = true;
00224             }
00225         }
00226     } while ( node[0] != '}' && !feof(fileIn) );
00227     //---------------------------------------------------------------
00228     // Create the bounding volume, set its properties and put it 
00229     // into the MultiBoundingVolume
00230     BoundingVolume<T> * tempBoundingVolumePtr = NULL;
00231     switch ( tempBoundingType ) {
00232         case Enum::BOUNDING_SPHERE:
00233             tempBoundingVolumePtr = new BoundingSphere<T>( tempID );
00234             tempBoundingVolumePtr->SetRadius( tempRadius );
00235             break;
00236         case Enum::BOUNDING_BOX:
00237             //tempBoundingVolumePtr = new BoundingBox<T>( tempID );
00238             break;
00239         case Enum::BOUNDING_CYLINDER:
00240             tempBoundingVolumePtr = new BoundingCylinder<T>( tempID );
00241             tempBoundingVolumePtr->SetRadius( tempRadius );
00242             tempBoundingVolumePtr->SetHeight( tempHeight );
00243             break;
00244         case Enum::BOUNDING_HALF_SPHERE:
00245             //tempBoundingVolumePtr = new Bounding<T>( tempID );
00246             break;
00247         case Enum::BOUNDING_CONE:
00248             //tempBoundingVolumePtr = new Bounding<T>( tempID );
00249             break;
00250         case Enum::BOUNDING_ELLIPSOID:
00251             //tempBoundingVolumePtr = new Bounding<T>( tempID );
00252             break;
00253         case Enum::BOUNDING_HALF_ELLIPSOID:
00254             //tempBoundingVolumePtr = new Bounding<T>( tempID );
00255             break;
00256         case Enum::BOUNDING_CAPSULE:
00257             //tempBoundingVolumePtr = new Bounding<T>( tempID );
00258             break;
00259         case Enum::BOUNDING_POLYTOPE:
00260             //tempBoundingVolumePtr = new Bounding<T>( tempID );
00261             break;
00262         default:
00263             std::cout << "ERROR: Unknown Bounding Type!" << std::endl;
00264             assert( false );
00265             break;
00266     }
00267     assert( tempBoundingVolumePtr );
00268     tempBoundingVolumePtr->SetName( tempName );
00269     tempBoundingVolumePtr->SetCenter( tempCenter );
00270     TransformationSupport<T> * transform = &(tempBoundingVolumePtr->GetTransform());
00271     transform->SetStatusApplyTransformation( tempStatusApplyTransformation );
00272     //---------------------------------------------------------------
00273     // Apply Transformations
00274     int nextPos = 0;
00275     for ( int i = 0; i < static_cast<int>( vTransformName.size() ); ++i ) {
00276         if      ( vTransformName[i].compare( "TRANSLATION" ) == 0 ) {
00277             transform->ApplyTranslation( vTransformValue[nextPos], vTransformValue[nextPos+1], vTransformValue[nextPos+2] );
00278             nextPos += 3;
00279         }
00280         else if ( vTransformName[i].compare( "ROTATION_AXIS_AND_ANGLE" ) == 0 ) {
00281             transform->ApplyRotationAxisAndAngle( 
00282                 vTransformValue[nextPos], vTransformValue[nextPos+1], vTransformValue[nextPos+2], vTransformValue[nextPos+3] );
00283             nextPos += 4;
00284         }
00285         else if ( vTransformName[i].compare( "SCALE" ) == 0 ) {
00286             transform->ApplyUniformScale( vTransformValue[nextPos] );
00287             ++nextPos;
00288         }
00289     }
00290     //---------------------------------------------------------------
00291     prMBV->GetBoundingVolumeList().push_back( tempBoundingVolumePtr );
00292     //---------------------------------------------------------------
00293     //std::cout << "End of Read BOUNDING_VOLUME Node" << std::endl;
00294 }

template<typename T>
bool ReadTAPsMBV< T >::ReadFile ( const char *  fileName,
MultiBoundingVolume< T > *const   prMBV 
) [inline, static]

Definition at line 27 of file TAPsReadTAPsMBV.cpp.

00029 {
00030     //---------------------------------------------------------------
00031     // If MultiBoundingVolume is not created yet!
00032     if ( !prMBV ) {
00033         std::cout << "The Multi Bounding Volume Object must be created first!" 
00034                   << std::endl;
00035         return false;
00036     }
00037     //---------------------------------------------------------------
00038     // Find the format of the file
00039     char *name = new char[ strlen( fileName )+1 ];
00040     char *format = new char[64];
00041     strcpy( name, fileName );
00042     char *token = strtok( name, "." );
00043     do {
00044         strcpy( format, token );
00045         token = strtok( '\0', "." );
00046     } while ( token );
00047     //---------------------------------------------------------------
00048     // If not a .MBV extension
00049     if ( strcmp( format, "MBV" ) != 0 ) {
00050         std::cout << "The input file extension must be .MBV!" << std::endl;
00051         return false;
00052     }
00053     //===============================================================
00054     // Process the file readin.
00055     //---------------------------------------------------------------
00056     // Open the input file
00057     fileIn = fopen( fileName, "r" );
00058     if ( !fileIn ) {
00059         std::perror( fileName );
00060         return false;
00061     }
00062     //---------------------------------------------------------------
00063     //std::cout << "START READING " << fileName << "\n";
00064     char line[256];
00065     char node[128];
00066     //---------------------------------------------------------------
00067     iCounter = 0;
00068     while ( !feof(fileIn) ) {
00069         fgets( line, 256, fileIn );     // read a line
00070         sscanf( line, "%s", node );
00071         //---------------------------------------
00072         // Skip A Commen Line
00073         if  ( node[0] == '#' ) {
00074             continue;
00075         }
00076         //---------------------------------------
00077         // Skip An Empty Line
00078         if  ( strlen( line ) <= 2 ) {
00079             continue;
00080         }
00081         //---------------------------------------
00082         if      ( !strncmp( node, "BOUNDING_VOLUME", 
00083                         strlen("BOUNDING_VOLUME") ) ) {
00084             //std::cout << "NODE: " << node << "\n";
00085             ProcessNodeBOUNDING_VOLUME( line, prMBV );
00086             ++iCounter;
00087         }
00088         else if ( !strncmp( node, "Number_Of_Bounding_Volumes", 
00089                         strlen("Number_Of_Bounding_Volumes") ) ) {
00090             int size;
00091             sscanf( line, "%s %d", node, &size );
00092             iNumBoundingVolume = size;
00093             //std::cout << "iNumBoundingVolume: " << iNumBoundingVolume << std::endl;
00094         }
00095 //      if ( iNumBoundingVolume == iCounter )   break;
00096     }
00097     //---------------------------------------------------------------
00098     fclose(fileIn);
00099     //std::cout << "END READING " << fileName << "\n";
00100     return true;
00101 }


Member Data Documentation

template<typename T>
FILE * ReadTAPsMBV< T >::fileIn = NULL [inline, static, private]

Definition at line 75 of file TAPsReadTAPsMBV.hpp.

template<typename T>
BEGIN_NAMESPACE_TAPs int ReadTAPsMBV< T >::iCounter = 0 [inline, static, private]

TAPs is added to the name to clarify that the .MBV is locally defined for TAPs.

Definition at line 73 of file TAPsReadTAPsMBV.hpp.

template<typename T>
int ReadTAPsMBV< T >::iNumBoundingVolume = 0 [inline, static, private]

Definition at line 74 of file TAPsReadTAPsMBV.hpp.


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

Generated on Mon Oct 13 11:45:54 2008 for TAPs by  doxygen 1.5.6