Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

functions::Importer Class Reference
[Functions]

Write brief comment for Importer here. More...

#include <Importer.h>

List of all members.

Public Member Functions

 Importer ()
 ~Importer ()
 Write brief comment for ~Importer here.
bool importModel (const char *filename, ExampleModel *am)
bool importDirectory (const char *dirname, vector< ExampleModel * > vem)

Private Member Functions

void readElements (TiXmlNode *doc, ExampleModel *em)
void readAttributes (TiXmlElement *pElement, ExampleModel *em)

Private Attributes

char * m_dir
int globalCIndex
int globalNIndex
vector< int > globalCoordIndexs
vector< int > globalNormalIndexs
vector< float > translation
vector< float > rotation
vector< float > scale
vector< float > scaleOrientation
vector< float > center


Detailed Description

Write brief comment for Importer here.

Write detailed description for Importer here.

Remarks:
Write remarks for Importer here.
See also:
Separate items with the '|' character.

Definition at line 38 of file Importer.h.


Constructor & Destructor Documentation

Importer::Importer  ) 
 

Write brief comment for Importer here.

Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for Importer here.

Remarks:
Write remarks for Importer here.
See also:
Separate items with the '|' character.

Definition at line 22 of file Importer.cpp.

00022                    {
00023 
00024 }

functions::Importer::~Importer  )  [inline]
 

Write brief comment for ~Importer here.

Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for ~Importer here.

Remarks:
Write remarks for ~Importer here.
See also:
Separate items with the '|' character.

Definition at line 65 of file Importer.h.

00065 {};


Member Function Documentation

bool functions::Importer::importDirectory const char *  dirname,
vector< ExampleModel * >  vem
 

bool Importer::importModel const char *  filename,
ExampleModel em
 

Write brief comment for importModel here.

Parameters:
filename Description of parameter filename.
am Description of parameter am.
Returns:
Write description of return value here.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for importModel here.

Remarks:
Write remarks for importModel here.
See also:
Separate items with the '|' character.

Definition at line 49 of file Importer.cpp.

References center, globalCIndex, globalNIndex, readElements(), rotation, scale, scaleOrientation, and translation.

Referenced by Batch::importData(), Batch::importModel(), and main().

00049                                                                  {
00050         //ExampleModel* em = new ExampleModel();
00051         globalCIndex=0;
00052         globalNIndex=0;
00053         translation = vector<float>(4,0);
00054         rotation = vector<float>(4,0);
00055         rotation[2] = 1;
00056         scale = vector<float>(4,1);
00057         scaleOrientation = vector<float>(4,0);
00058         scaleOrientation[2] = 1;
00059         center = vector<float>(4,0);
00060 
00061         //New code
00062         TiXmlDocument doc(filename);
00063         bool loadOkay = doc.LoadFile();
00064         if (loadOkay)
00065         {
00066                 //printf("\n%s:\n", filename);
00067                 readElements(&doc,em);
00068         }
00069         else
00070         {
00071                 printf("Failed to load file \"%s\"\n", filename);
00072         }
00073 
00074         return loadOkay;
00075 }

Here is the call graph for this function:

void Importer::readAttributes TiXmlElement *  pElement,
ExampleModel em
[private]
 

Write brief comment for readAttributes here.

Parameters:
pElement Description of parameter pElement.
em Description of parameter em.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for readAttributes here.

Remarks:
Write remarks for readAttributes here.
See also:
Separate items with the '|' character.

Definition at line 140 of file Importer.cpp.

References model::Model::addFace(), model::Model::addVertex(), center, model::Model::getFace(), model::Face::getVertex(), model::Model::getVertex(), globalCIndex, globalCoordIndexs, globalNIndex, globalNormalIndexs, rotation, scale, scaleOrientation, model::Vertex::setNormal(), Tokenize(), and translation.

Referenced by readElements().

00141 {
00142         if ( pElement ) {
00143 
00144                 TiXmlAttribute* pAttrib=pElement->FirstAttribute();
00145 
00146 
00147                 while (pAttrib)
00148                 {
00149                         if(!strcmp(pAttrib->Name(),"coordIndex")) {
00150                                 globalCoordIndexs.clear();
00151                                 vector<string> tokens;
00152                                 string s = string(pAttrib->Value());
00153                                 //cout << "String: " << s << "\n";
00154                                 Tokenize(s,tokens,",");
00155                                 //printf("Tokens: %d\n",tokens.size());
00156                                 for(int i=0;i<(int)tokens.size();i++) {
00157                                         //cout << i << " | " << tokens[i] << "\n";
00158                                         globalCoordIndexs.push_back(convertTo<int>(tokens[i]));
00159                                 }
00160                         } else if(!strcmp(pAttrib->Name(),"normalIndex")) {
00161                                 globalNormalIndexs.clear();
00162                                 vector<string> tokens;
00163                                 string s = string(pAttrib->Value());
00164                                 Tokenize(s,tokens,",");
00165                                 //printf("Tokens: %d\n",tokens.size());
00166                                 for(int i=0;i<(int)tokens.size();i++) {
00167                                         //cout << i << " | " << tokens[i] << "\n";
00168                                         globalNormalIndexs.push_back(convertTo<int>(tokens[i]));
00169                                 }
00170                         } else if(!strcmp(pAttrib->Name(),"point")) {
00171                                 vector<string> tokens;
00172                                 string str = string(pAttrib->Value());
00173                                 Tokenize(str,tokens,",");
00174                                 Matrix vertexs;
00175                                 //printf("Tokens: %d\n",tokens.size());
00176                                 for(int i=0;i<(int)tokens.size();i++) {
00177                                         vector<string> tokens2;
00178                                         Tokenize(tokens[i],tokens2," ");
00179                                         //printf("Tokens: %d - ",tokens2.size());
00180                                         //cout << i << " | " << tokens[i] << "\n";
00181         
00182                                         Matrix tmp(4,1);
00183                                         tmp << convertTo<float>(tokens2[0]) << convertTo<float>(tokens2[1]) << convertTo<float>(tokens2[2]) << 1.0;
00184                                         if(i==0) {
00185                                                 vertexs = tmp;
00186                                         } else {
00187                                                 vertexs = vertexs | tmp;
00188                                         }
00189                                 }
00190                                 //Generate transforamtion matrix
00191                                 Matrix translationMatrix(4,4);
00192                                 Matrix rotationMatrix(4,4);
00193                                 Matrix scaleMatrix(4,4);
00194                                 Matrix centerMatrix(4,4);
00195                                 Matrix scaleOrientationMatrix(4,4);
00196                                 Matrix minusCenterMatrix(4,4);
00197                                 Matrix minusScaleOrientationMatrix(4,4);
00198 
00199                                 //Translation
00200                                 translationMatrix       << 1.0 << 0.0 << 0.0 << translation[0]
00201                                                                         << 0.0 << 1.0 << 0.0 << translation[1]
00202                                                                         << 0.0 << 0.0 << 1.0 << translation[2]
00203                                                                         << 0.0 << 0.0 << 0.0 << 1.0;
00204                                 
00205                                 //Rotation
00206                                 //float angle = (rotation[3]*(180/3.14159265))/2;
00207                                 //float w = cos((angle*3.14159265)/180);
00208                                 float w = rotation[3];
00209                                 float x = rotation[0];
00210                                 float y = rotation[1];
00211                                 float z = rotation[2];
00212                                 float c = cos(w);
00213                                 float s = sin(w);
00214                                 float t = 1 - c;
00215 
00216 
00217                                 rotationMatrix  << t*pow(x,2)+c << t*x*y-s*z    << t*x*z+s*y    << 0.0
00218                                                                 << t*x*y+s*z    << t*pow(y,2)+c << t*y*z-s*x    << 0.0
00219                                                                 << t*x*z-s*y    << t*y*z+s*x    << t*pow(z,2)+c << 0.0
00220                                                                 << 0.0                  << 0.0                  << 0.0                  << 1.0;
00221 
00222                                 //Scale
00223                                 scaleMatrix     = 0.0;
00224                                 scaleMatrix(1,1) = scale[0];
00225                                 scaleMatrix(2,2) = scale[1];
00226                                 scaleMatrix(3,3) = scale[2];
00227                                 scaleMatrix(4,4) = 1.0;
00228 
00229                                 //centerMatrix 
00230                                 centerMatrix    << 1.0 << 0.0 << 0.0 << center[0]
00231                                                                 << 0.0 << 1.0 << 0.0 << center[1]
00232                                                                 << 0.0 << 0.0 << 1.0 << center[2]
00233                                                                 << 0.0 << 0.0 << 0.0 << 1.0;
00234 
00235                                 //MinuScenterMatrix 
00236                                 minusCenterMatrix       << 1.0 << 0.0 << 0.0 << -center[0]
00237                                                                         << 0.0 << 1.0 << 0.0 << -center[1]
00238                                                                         << 0.0 << 0.0 << 1.0 << -center[2]
00239                                                                         << 0.0 << 0.0 << 0.0 << 1.0;
00240 
00241                                 //scaleOrientationMatrix 
00242                                 scaleOrientationMatrix  << 1.0 << 0.0 << 0.0 << scaleOrientation[0]
00243                                                                                 << 0.0 << 1.0 << 0.0 << scaleOrientation[1]
00244                                                                                 << 0.0 << 0.0 << 1.0 << scaleOrientation[2]
00245                                                                                 << 0.0 << 0.0 << 0.0 << 1.0;
00246 
00247                                 //MinusScaleOrientationMatrix 
00248                                 minusScaleOrientationMatrix     << 1.0 << 0.0 << 0.0 << -scaleOrientation[0]
00249                                                                                         << 0.0 << 1.0 << 0.0 << -scaleOrientation[1]
00250                                                                                         << 0.0 << 0.0 << 1.0 << -scaleOrientation[2]
00251                                                                                         << 0.0 << 0.0 << 0.0 << 1.0;
00252                                 //vertexs = vertexs.t();
00253                                 //multiply the matrixs
00254                                 //P' = T * C * R * SR * S * -SR * -C * P
00255                                 vertexs = translationMatrix * centerMatrix * rotationMatrix * scaleOrientationMatrix * scaleMatrix * minusScaleOrientationMatrix * minusCenterMatrix * vertexs;
00256                                 //vertexs =   rotationMatrix * scaleMatrix* vertexs;
00257                                 //vertexs =    rotationMatrix* vertexs;
00258 
00259 
00260 
00261 
00262                                 //vertexs = translationMatrix * rotationMatrix *  scaleMatrix  * vertexs;
00263                                 //vertexs = vertexs * minusCenterMatrix * minusScaleOrientationMatrix  * scaleMatrix  * scaleOrientationMatrix * rotationMatrix * centerMatrix * translationMatrix;
00264                                 //vertexs = centerMatrix * rotationMatrix * scaleOrientationMatrix * scaleMatrix * minusScaleOrientationMatrix * minusCenterMatrix * vertexs;
00265                                 //vertexs = translationMatrix * vertexs;
00266                                 /*cout << "Scale:\n";
00267                                 cout << setw(10) << setprecision(5) << scaleMatrix;
00268                                 cout << "Rotate:\n";
00269                                 cout << setw(10) << setprecision(5) << rotationMatrix;
00270                                 cout << "Translation:\n";
00271                                 cout << setw(10) << setprecision(5) << translationMatrix;*/
00272                                 //vertexs = vertexs.t();
00273 
00274 
00275 
00276                                 //Extract each vertex
00277                                 for(int i=1; i<=vertexs.Ncols();i++) {
00278                                         //printf("Vertex add %d\n",i);
00279                                         Vertex* v = new Vertex((float)vertexs(1,i),(float)vertexs(2,i),(float)vertexs(3,i));
00280                                         em->addVertex(v);
00281                                 }
00282                                 //printf("Adding faces - %d\n",globalCoordIndexs.size());
00283                                 for(int i=0;i<(int)globalCoordIndexs.size();i=i+4) {
00284                                         //printf("Face: %d < %d\n",i,globalCoordIndexs.size());
00285                                         //printf("VertexI: %d,%d,%d\n",globalCoordIndexs[i],globalCoordIndexs[i+1],globalCoordIndexs[i+2]);
00286                                         Face* f = new Face(em->getVertex(globalCIndex+globalCoordIndexs[i]),em->getVertex(globalCIndex+globalCoordIndexs[i+1]),em->getVertex(globalCIndex+globalCoordIndexs[i+2]));
00287                                         em->addFace(f);
00288                                 }
00289                                 globalCIndex += tokens.size();
00290                                 translation = vector<float>(4,0);
00291                                 rotation = vector<float>(4,0);
00292                                 rotation[2] = 1;
00293                                 scale = vector<float>(4,1);
00294                                 scaleOrientation = vector<float>(4,0);
00295                                 scaleOrientation[2] = 1;
00296                                 center = vector<float>(4,0);
00297                         } else if(!strcmp(pAttrib->Name(),"vector")) {
00298                                 vector<IvVector3*> normals;
00299                                 vector<string> tokens;
00300                                 string s = string(pAttrib->Value());
00301                                 Tokenize(s,tokens,",");
00302                                 //printf("Tokens: %d\n",tokens.size());
00303                                 for(int i=0;i<(int)tokens.size();i++) {
00304                                         vector<string> tokens2;
00305                                         Tokenize(tokens[i],tokens2," ");
00306                                         //printf("Tokens: %d - ",tokens2.size());
00307                                         //cout << i << " | " << tokens[i] << "\n";
00308                                         IvVector3* tempVector = new IvVector3(convertTo<float>(tokens2[0]),convertTo<float>(tokens2[1]),convertTo<float>(tokens2[2]));
00309                                         normals.push_back(tempVector);
00310                                 }
00311                                 //printf("Adding normals - %d - %d\n",globalNormalIndexs.size(),normals.size());
00312                                 for(int i=0;i<(int)globalNormalIndexs.size();i=i+4) {
00313                                         //printf("Normal: %d < %d --- %d < %d\n",i,globalNormalIndexs.size(),globalNIndex+i/4,em->getFaces().size());
00314                                         //printf("globalNormalIndexs: %d < %d\n",globalNormalIndexs[i+0],normals.size());
00315                                         //printf("globalNormalIndexs: %d < %d\n",globalNormalIndexs[i+1],normals.size());
00316                                         //printf("globalNormalIndexs: %d < %d\n",globalNormalIndexs[i+2],normals.size());
00317                                         em->getFace(globalNIndex+i/4)->getVertex(0)->setNormal(normals[globalNormalIndexs[i+0]]);
00318                                         em->getFace(globalNIndex+i/4)->getVertex(1)->setNormal(normals[globalNormalIndexs[i+1]]);
00319                                         em->getFace(globalNIndex+i/4)->getVertex(2)->setNormal(normals[globalNormalIndexs[i+2]]);
00320                                 }
00321                                 globalNIndex += tokens.size();
00322                                 //printf("Index: %d\n",globalNIndex);
00323                         } else if(      !strcmp(pAttrib->Name(),"translation")  ||
00324                                                 !strcmp(pAttrib->Name(),"rotation")             ||
00325                                                 !strcmp(pAttrib->Name(),"scale")                ||
00326                                                 !strcmp(pAttrib->Name(),"center")               ||
00327                                                 !strcmp(pAttrib->Name(),"scaleOrientation")) {
00328                                 vector<string> tokens;
00329                                 string s = string(pAttrib->Value());
00330                                 Tokenize(s,tokens," ");
00331                                 //printf("Tokens: %d\n",tokens.size());
00332                                 for(int i=0;i<(int)tokens.size();i++) {
00333                                         if(!strcmp(pAttrib->Name(),"translation")) {
00334                                                 translation[i] = convertTo<float>(tokens[i]);
00335                                         } else if(!strcmp(pAttrib->Name(),"rotation")) {
00336                                                 rotation[i] = convertTo<float>(tokens[i]);
00337                                         }else if(!strcmp(pAttrib->Name(),"scale")) {
00338                                                 scale[i] = convertTo<float>(tokens[i]);
00339                                         }else if(!strcmp(pAttrib->Name(),"center")) {
00340                                                 center[i] = convertTo<float>(tokens[i]);
00341                                         }else if(!strcmp(pAttrib->Name(),"scaleOrientation")) {
00342                                                 scaleOrientation[i] = convertTo<float>(tokens[i]);
00343                                         }
00344                                 }
00345                         }                       
00346                         pAttrib=pAttrib->Next();
00347                 }       
00348         }
00349 }

Here is the call graph for this function:

void Importer::readElements TiXmlNode *  pParent,
ExampleModel em
[private]
 

Write brief comment for readElements here.

Parameters:
doc Description of parameter doc.
em Description of parameter em.
Exceptions:
<exception class> Description of criteria for throwing this exception.
Write detailed description for readElements here.

Remarks:
Write remarks for readElements here.
See also:
Separate items with the '|' character.

Definition at line 97 of file Importer.cpp.

References readAttributes().

Referenced by importModel().

00097                                                                 {
00098         if ( !pParent ) return;
00099 
00100         TiXmlNode* pChild;
00101         int t = pParent->Type();
00102 
00103         if(t == TiXmlNode::ELEMENT) {
00104                 //printf( "Element [%s]\n", pParent->Value() );
00105 
00106                 if(     !strcmp(pParent->Value(),"IndexedFaceSet") || 
00107                         !strcmp(pParent->Value(),"Coordinate") || 
00108                         !strcmp(pParent->Value(),"Normal")) {
00109                         readAttributes(pParent->ToElement(),em);
00110                 } else if(!strcmp(pParent->Value(),"Transform")) {
00111                         readAttributes(pParent->ToElement(),em);
00112                 }
00113         }
00114         for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) 
00115         {
00116                 readElements( pChild, em );
00117         }
00118 }

Here is the call graph for this function:


Member Data Documentation

vector<float> functions::Importer::center [private]
 

Definition at line 44 of file Importer.h.

Referenced by importModel(), and readAttributes().

int functions::Importer::globalCIndex [private]
 

Definition at line 41 of file Importer.h.

Referenced by importModel(), and readAttributes().

vector<int> functions::Importer::globalCoordIndexs [private]
 

Definition at line 42 of file Importer.h.

Referenced by readAttributes().

int functions::Importer::globalNIndex [private]
 

Definition at line 41 of file Importer.h.

Referenced by importModel(), and readAttributes().

vector<int> functions::Importer::globalNormalIndexs [private]
 

Definition at line 43 of file Importer.h.

Referenced by readAttributes().

char* functions::Importer::m_dir [private]
 

Definition at line 40 of file Importer.h.

vector<float> functions::Importer::rotation [private]
 

Definition at line 44 of file Importer.h.

Referenced by importModel(), and readAttributes().

vector<float> functions::Importer::scale [private]
 

Definition at line 44 of file Importer.h.

Referenced by importModel(), and readAttributes().

vector<float> functions::Importer::scaleOrientation [private]
 

Definition at line 44 of file Importer.h.

Referenced by importModel(), and readAttributes().

vector<float> functions::Importer::translation [private]
 

Definition at line 44 of file Importer.h.

Referenced by importModel(), and readAttributes().


The documentation for this class was generated from the following files:
Generated on Tue Apr 17 09:39:53 2007 for PCG Library by  doxygen 1.3.9.1