Ignore:
Timestamp:
04/20/06 13:25:41 (18 years ago)
Author:
mattausch
Message:

after rendering workshop submissioin
x3dparser can use def - use constructs
implemented improved evaluation (samples are only stored in leaves, only propagate pvs size)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp

    r726 r752  
    100100  string element(lname.LocalForm()); 
    101101   
     102  // only create new mesh instance if define mechanism was not used 
    102103  if (element == "Shape") 
    103104    EndShape(); 
    104   if (1) 
     105 
    105106  if (element == "Transform") 
    106107          EndTransform(); 
     
    138139 
    139140        const int len = attributes.getLength(); 
     141    Matrix4x4 *rotm = NULL; 
     142        Matrix4x4 *scalem = NULL; 
     143        Matrix4x4 *translm = NULL; 
    140144     
    141145        for (int i = 0; i < len; ++ i)  
     
    153157                        if (sscanf(ptr, "%f %f %f %f", &axis.x, &axis.y, &axis.z, &angle) == 4) 
    154158                        { 
    155                                 Matrix4x4 rot = RotationAxisMatrix(axis, angle); 
    156                                 currentTransform *= rot; 
     159                                rotm = new Matrix4x4(RotationAxisMatrix(axis, angle)); 
    157160                        } 
    158161                } 
     
    163166                        if (sscanf(ptr, "%f %f %f %f", &transl.x, &transl.y, &transl.z) == 3) 
    164167                        { 
    165                                 Matrix4x4 tm = TranslationMatrix(transl); 
    166  
    167                                 currentTransform *= tm; 
     168                                translm = new Matrix4x4(TranslationMatrix(transl)); 
    168169                        } 
    169170                } 
     171                else if (attrName == "scale") 
     172                { 
     173                        Vector3 scale; 
     174 
     175                        if (sscanf(ptr, "%f %f %f %f", &scale.x, &scale.y, &scale.z) == 3) 
     176                        { 
     177                                scalem = new Matrix4x4(ScaleMatrix(scale.x, scale.y, scale.z)); 
     178                        } 
     179                } 
     180                // todo: scale orientation 
    170181        } 
    171182         
     183        if (scalem) 
     184                currentTransform *= (*scalem); 
     185        if (rotm) 
     186                currentTransform *= (*rotm); 
     187        if (translm) 
     188                currentTransform *= (*translm); 
     189 
     190        DEL_PTR(scalem); 
     191        DEL_PTR(rotm); 
     192        DEL_PTR(translm); 
     193 
    172194        mTransformations.push(currentTransform); 
    173195} 
     
    180202 
    181203 
    182 void 
    183 X3dParseHandlers::EndShape() 
    184 { 
     204void X3dParseHandlers::EndShape() 
     205{ 
     206        // this shape is a definition => don't create mesh instance 
     207        if (mIsMeshDefinition)  
     208{ 
     209                mMeshDefinitions[mCurrentMeshName.c_str()] = mCurrentMesh; 
     210                //cout << "new definition: " << mCurrentMeshName << endl; 
     211                 
     212                return; 
     213        } 
     214 
     215        // each polygon is one single mesh 
    185216        if (mLoadPolygonsAsMeshes) 
    186217        { 
    187                 vector<VertexIndexContainer>::const_iterator it, it_end = mCurrentVertexIndices.end(); 
     218                 
     219                /*vector<VertexIndexContainer>::const_iterator it,  
     220                        it_end = mCurrentVertexIndices.end(); 
    188221 
    189222                for (it = mCurrentVertexIndices.begin(); it != it_end; ++ it) 
     
    211244                        mCurrentNode->mGeometry.push_back(mi); 
    212245 
    213                 } 
    214  
    215                 delete mCurrentMesh; 
    216                 mCurrentVertices.clear(); 
    217                 mCurrentVertexIndices.clear(); 
     246                }*/ 
     247 
     248                //if (mCurrentMesh->mFaces.empty())     cout << "error!" << endl; 
     249 
     250                FaceContainer::const_iterator fit, fit_end = mCurrentMesh->mFaces.end(); 
     251 
     252                cout << "m"; 
     253                //cout << "m: " << mCurrentMesh->mFaces.size() << endl; 
     254                for (fit = mCurrentMesh->mFaces.begin(); fit != fit_end; ++ fit) 
     255                { 
     256                        cout << "f"; 
     257 
     258                        Face *face = *fit; 
     259                        // only one face per mesh 
     260                        Mesh *mesh = new Mesh(); 
     261                        VertexIndexContainer vc; 
     262                                         
     263                        VertexIndexContainer::const_iterator vit, vit_end = face->mVertexIndices.end(); 
     264                         
     265                        int i = 0; 
     266                        for (vit = face->mVertexIndices.begin(); vit != vit_end; ++ vit, ++ i) 
     267                        { 
     268                                cout << "i"; 
     269                                int index = (*vit); 
     270                                // add vertices 
     271                                mesh->mVertices.push_back(mCurrentMesh->mVertices[index]); 
     272                                vc.push_back(i); 
     273                        } 
     274 
     275                        mesh->mFaces.push_back(new Face(vc)); 
     276 
     277                        // NOTE: should rather be written into trafo of mesh instance 
     278                        ApplyTransformations(mTransformations, mesh); 
     279 
     280                        mesh->Preprocess(); 
     281                                 
     282                        // make an instance of this mesh 
     283                        MeshInstance *mi = new MeshInstance(mesh); 
     284                        mCurrentNode->mGeometry.push_back(mi); 
     285                } 
     286 
     287                // LEAK!! TODO: delete if not defd 
     288                if (!mUsingMeshDefinition) 
     289                        delete mCurrentMesh; 
     290 
     291                //mCurrentVertices.clear(); 
     292                //mCurrentVertexIndices.clear(); 
    218293        } 
    219294        else 
    220295        {  
    221                 if (mCurrentMesh->mFaces.size())  
     296                if (!mCurrentMesh->mFaces.empty())  
    222297                { 
    223298                        // should rather be written into the transformation 
     
    228303                        // make an instance of this mesh 
    229304                        MeshInstance *mi = new MeshInstance(mCurrentMesh); 
     305 
    230306                        mCurrentNode->mGeometry.push_back(mi); 
    231307                        // set the object id to a unique value 
     
    234310                else  
    235311                { 
     312                        // empty mesh => discard 
    236313                        cout<<"X"; 
     314 
    237315                        delete mCurrentMesh; 
    238316                } 
     
    243321 
    244322 
    245 void 
    246 X3dParseHandlers::StartIndexedFaceSet( 
    247                                                                           AttributeList&  attributes) 
     323void X3dParseHandlers::StartIndexedFaceSet(AttributeList&  attributes) 
    248324{ 
    249325  int len = attributes.getLength(); 
     326 
    250327  int i; 
    251328  VertexIndexContainer vertices; 
    252329   
    253   for (i=0; i < len; i++) { 
    254     string attrName(StrX(attributes.getName(i)).LocalForm()); 
    255     if (attrName == "coordIndex") { 
    256       StrX attrValue(attributes.getValue(i)); 
    257       // handle coordIndex 
    258       vertices.clear(); 
    259       const char *ptr = attrValue.LocalForm(); 
    260       char *endptr; 
    261       while(1) { 
    262         int index = strtol(ptr, &endptr, 10); 
    263         if (ptr == endptr || index == -1) { 
    264           if (vertices.size() > 2) { 
    265                   Face *face = new Face(vertices); 
    266  
    267                    if (!mLoadPolygonsAsMeshes) 
    268                    { 
    269                            mCurrentMesh->mFaces.push_back(face); 
    270                    } 
    271                    else 
    272                    // every polygon is a mesh 
    273                    { 
    274                            mCurrentVertexIndices.push_back(vertices); 
    275                    } 
    276           } 
    277  
    278           vertices.clear(); 
    279           if (ptr == endptr) 
    280             break; 
    281         } else { 
    282           vertices.push_back(index); 
    283         } 
    284         ptr = endptr; 
    285           } 
    286     } 
    287   } 
    288 } 
     330        mIsMeshDefinition = false; 
     331        mUsingMeshDefinition = false; 
     332        for (i = 0; i < len; ++ i)  
     333        { 
     334                string attrName(StrX(attributes.getName(i)).LocalForm()); 
     335           
     336                // this is a definition of a mesh 
     337                if (attrName == "DEF") 
     338                { 
     339                        mIsMeshDefinition = true; 
     340                        StrX attrValue(attributes.getValue(i)); 
     341                        const char *ptr = attrValue.LocalForm(); 
     342                        mCurrentMeshName = ptr; 
     343 
     344                        cout << "d"; 
     345                } 
     346                 
     347                // we use an already defined mesh 
     348                if (attrName == "USE") 
     349                { 
     350                        StrX attrValue(attributes.getValue(i)); 
     351 
     352                        // discard new mesh and assign defined mesh 
     353                        DEL_PTR(mCurrentMesh); 
     354                        const char *ptr = attrValue.LocalForm(); 
     355 
     356                        mCurrentMesh = mMeshDefinitions[ptr]; 
     357                        mUsingMeshDefinition = true; 
     358                        cout << "u"; 
     359                } 
     360                 
     361                if (attrName == "coordIndex")  
     362                { 
     363                        StrX attrValue(attributes.getValue(i)); 
     364                        // handle coordIndex 
     365                        vertices.clear(); 
     366                        const char *ptr = attrValue.LocalForm(); 
     367                   
     368                        char *endptr; 
     369           
     370                        while (1)  
     371                        { 
     372                                int index = strtol(ptr, &endptr, 10); 
     373                                   
     374                                if (ptr == endptr || index == -1)  
     375                                { 
     376                                        if (vertices.size() > 2)  
     377                                        { 
     378                                                Face *face = new Face(vertices);                  
     379                                                mCurrentMesh->mFaces.push_back(face); 
     380                                        }  
     381                           
     382                                        vertices.clear(); 
     383                   
     384                                        if (ptr == endptr) 
     385                                                break; 
     386                           
     387                                  }  
     388                                  else  
     389                                  { 
     390                                          vertices.push_back(index); 
     391                                  } 
     392                                  ptr = endptr; 
     393                        } 
     394                } 
     395        } 
     396} 
     397 
    289398 
    290399void 
     
    358467                                vertices.push_back(v); 
    359468                        } 
    360                         if (mLoadPolygonsAsMeshes) 
    361                         { 
    362                                 mCurrentVertices = vertices; 
    363                         } 
    364                         else 
    365                         { 
    366                                 mCurrentMesh->mVertices = vertices; 
    367                         } 
     469                         
     470                        mCurrentMesh->mVertices = vertices; 
    368471                } 
    369472        } 
     
    388491  } 
    389492   
    390   if (element == "Coordinate") { 
     493  if (element == "Coordinate")  
     494  { 
    391495    if (mCurrentMesh) 
    392496      StartCoordinate(attributes); 
     
    396500    StartMaterial(attributes); 
    397501  } 
    398 if (1) 
     502   
    399503  if (element == "Transform") { 
    400504          StartTransform(attributes); 
     
    599703X3dViewCellsParseHandlers::EndShape() 
    600704{ 
     705        // currently processing no shape 
    601706} 
    602707 
     
    607712        int len = attributes.getLength(); 
    608713        int i; 
     714         
    609715        // clear previous vertex indices 
    610716        mCurrentVertexIndices.clear(); 
     717 
     718 
    611719        for (i=0; i < len; i++)  
    612720        { 
    613721                string attrName(StrX(attributes.getName(i)).LocalForm()); 
    614722             
     723 
    615724                if (attrName == "coordIndex")  
    616725                { 
Note: See TracChangeset for help on using the changeset viewer.