Changeset 1328


Ignore:
Timestamp:
09/11/06 00:29:47 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
20 edited

Legend:

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

    r878 r1328  
    121121 
    122122        if (sceneGraph)  
    123           exporter->ExportScene(sceneGraph->mRoot); 
     123          exporter->ExportScene(sceneGraph->GetRoot()); 
    124124         
    125125    //exporter->ExportKdTree(*tree); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1314 r1328  
    6464                 KD_INTERSECTABLE, 
    6565                 BVH_INTERSECTABLE, 
    66                  FACE_INTERSECTABLE 
     66                 TRIANGLE_INTERSECTABLE 
    6767                }; 
    6868   
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp

    r1327 r1328  
    11#include "IntersectableWrapper.h" 
     2#include "Mesh.h" 
     3#include "Triangle3.h" 
    24 
    35 
     
    57 
    68 
    7 AxisAlignedBox3 FaceIntersectable::GetBox() const 
     9AxisAlignedBox3 TriangleIntersectable::GetBox() const 
    810{        
    911        return mItem->GetBoundingBox(); 
     
    1113 
    1214 
    13 int FaceIntersectable::CastRay(Ray &ray) 
     15int TriangleIntersectable::CastRay(Ray &ray) 
    1416{       // TODO matt 
    1517        return 0; 
    1618} 
    1719         
    18 template<typename T> 
    19 bool IntersectableWrapper<T>::IsConvex() const 
     20 
     21int TriangleIntersectable::NumberOfFaces() const 
    2022{ 
    21         return true; 
    22 } 
    23  
    24 template<typename T> 
    25 bool IntersectableWrapper<T>::IsWatertight() const 
    26 { 
    27         return true; 
    28 } 
    29  
    30 template<typename T> 
    31 float IntersectableWrapper<T>::IntersectionComplexity() 
    32 { 
    33         return 1.0f; 
    34 } 
    35  
    36 template<typename T> 
    37 int IntersectableWrapper<T>::NumberOfFaces() const 
    38 { 
    39         return 0; 
    40 } 
    41  
    42 template<typename T> 
    43 int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point, 
    44                                                                                                 Vector3 &normal) 
    45 { 
    46         return 0; 
    47 } 
    48  
    49 template<typename T> 
    50 int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point, 
    51                                                                                                            Vector3 &normal, 
    52                                                                                                            const Vector3 &viewpoint, 
    53                                                                                                            const int maxTries) 
    54 { 
    55         return 0; 
     23        return 1; 
    5624} 
    5725   
    58 template<typename T> 
    59 ostream &IntersectableWrapper<T>::Describe(ostream &s) 
    60 { 
    61         s << mItem; 
    62         return s; 
    63 } 
    6426 
    6527} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h

    r1315 r1328  
    1212class BvhNode; 
    1313struct Face; 
     14class Ray; 
     15struct Triangle3; 
     16 
    1417 
    1518 
     
    164167}; 
    165168 
    166 class FaceIntersectable: public IntersectableWrapper<Face> 
     169class TriangleIntersectable: public IntersectableWrapper<Triangle3> 
    167170{ 
    168171public: 
    169         FaceIntersectable(Face *item): 
    170         IntersectableWrapper<Face>(item) {} 
     172        TriangleIntersectable(Triangle3 *item): 
     173        IntersectableWrapper<Triangle3>(item) {} 
     174 
     175        int CastRay(Ray &ray); 
     176        AxisAlignedBox3 GetBox() const; 
     177 
     178        int NumberOfFaces() const; 
    171179 
    172180        int Type() const 
    173181        { 
    174                 return Intersectable::FACE_INTERSECTABLE; 
     182                return Intersectable::TRIANGLE_INTERSECTABLE; 
    175183        } 
    176184}; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp

    r1297 r1328  
    798798} 
    799799 
    800 } 
     800 
     801} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h

    r1327 r1328  
    5252  } 
    5353   
    54   AxisAlignedBox3 GetBoundingBox() const 
    55   { 
    56           VertexIndexContainer::const_iterator vit, vit_end = (int)mVertexIndices.size(); 
    57           AxisAlignedBox3 box; 
    58           box.Initialize(); 
    59  
    60           for (vit = mVertexIndices.begin(); vit != vit_end; ++ vit) 
    61           { 
    62                   box.Include(*vit); 
    63           } 
    64  
    65           return box; 
    66   } 
     54  //////////////////////////// 
    6755 
    6856  /// list of vertex pointers 
  • GTP/trunk/Lib/Vis/Preprocessing/src/MutualVisibility.cpp

    r863 r1328  
    519519     
    520520    exporter->SetWireframe(); 
    521     //    exporter->ExportScene(mSceneGraph->mRoot); 
     521    //    exporter->ExportScene(mSceneGraph->GetRoot()); 
    522522 
    523523    exporter->ExportBox(mSource); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp

    r1327 r1328  
    1111#include "ObjParser.h" 
    1212//#include "Material.h" 
     13#include "Triangle3.h" 
    1314#include "Environment.h" 
    1415#include "ResourceManager.h" 
     
    1819namespace GtpVisibilityPreprocessor { 
    1920 
     21#define CONNECT_SEQUENTIAL_FACES 1 
    2022#define ROTATE_SCENE 0 
     23 
    2124// HACK 
    22         static void RotateMesh(Mesh *mesh) 
    23         { 
    24                 VertexContainer::iterator it, it_end = mesh->mVertices.end(); 
    25  
    26                 const float angle = 30.0f * PI / 180.0f; 
    27                 const Matrix4x4 rot = RotationYMatrix(angle); 
    28  
    29                 for (it = mesh->mVertices.begin(); it != it_end; ++ it) 
    30                 { 
    31                         (*it) = rot * (*it);         
    32                 } 
    33         } 
    34  
    35  
    36         struct ltstr 
    37         { 
    38                 bool operator()(const string s1, const string s2) const 
    39                 { 
    40                         return s1 < s2; 
    41                 } 
    42         }; 
     25static void RotateMesh(Mesh *mesh) 
     26{ 
     27        VertexContainer::iterator it, it_end = mesh->mVertices.end(); 
     28 
     29        const float angle = 30.0f * PI / 180.0f; 
     30        const Matrix4x4 rot = RotationYMatrix(angle); 
     31 
     32        for (it = mesh->mVertices.begin(); it != it_end; ++ it) 
     33        { 
     34                (*it) = rot * (*it);         
     35        } 
     36} 
     37 
     38struct ltstr 
     39{ 
     40        bool operator()(const string s1, const string s2) const 
     41        { 
     42                return s1 < s2; 
     43        } 
     44}; 
    4345 
    4446//const static int nMaxFaces = 6; 
    4547 
    4648 
    47 Face *LoadFace(char *str,  
    48                            const VertexContainer &vertices,  
    49                            map<int, Vector3> &hashTable) 
    50 { 
    51   //    cout << "f"; 
    52  
    53         char *pch; 
    54          
    55         pch = strtok(str + 1, " "); 
     49static Face *LoadFace(char *str,  
     50                                          const VertexContainer &vertices,  
     51                                          map<int, Vector3> &hashTable) 
     52{ 
     53        char *pch = strtok(str + 1, " "); 
    5654         
    5755        VertexIndexContainer indices; 
     
    5957        { 
    6058                const int index = (int)strtol(pch, NULL, 10) - 1; 
    61  
    6259                //Debug << index << " x "; 
    6360                 
     
    7471 
    7572 
    76 Mesh *CreateMesh(FaceContainer &faces, const map<int, Vector3> &hashTable) 
     73static Triangle3 *LoadTriangle(char *str,  
     74                                                           const VertexContainer &vertices,  
     75                                                           map<int, Vector3> &hashTable) 
     76{ 
     77        char *pch = strtok(str + 1, " "); 
     78         
     79        VertexIndexContainer indices; 
     80         
     81        while (pch != NULL) 
     82        { 
     83                const int index = (int)strtol(pch, NULL, 10) - 1; 
     84                //Debug << index << " x "; 
     85                 
     86                // store vertex in hash table 
     87                hashTable[index] = vertices[index]; 
     88                indices.push_back(index); 
     89                 
     90                pch = strtok(NULL, " "); 
     91        } 
     92        //if (indices.size() > 4) return NULL; 
     93 
     94        return new Triangle3(indices[0], indices[1], indices[2]);  
     95} 
     96 
     97 
     98static Mesh *CreateMesh(FaceContainer &faces,  
     99                                                const map<int, Vector3> &hashTable) 
    77100{ 
    78101        Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 
     
    117140 
    118141// HACK: associate mesh instances with triangles 
    119 void AssociateFacesWithInstance(MeshInstance *mi, 
    120                                                                 vector<FaceParentInfo> &parents) 
     142static void AssociateFacesWithInstance(MeshInstance *mi, 
     143                                                                           vector<FaceParentInfo> &parents) 
    121144{ 
    122145  Mesh *mesh = mi->GetMesh(); 
     
    131154 
    132155 
     156static void ProcessMesh(FaceContainer &faces,  
     157                                                map<int, Vector3> &hashTable, 
     158                                                SceneGraphNode *root, 
     159                                                vector<FaceParentInfo> *parents) 
     160{ 
     161        Mesh *mesh = CreateMesh(faces, hashTable); 
     162 
     163        // make an instance of this mesh 
     164        MeshInstance *mi = new MeshInstance(mesh); 
     165                 
     166        if (parents)  
     167        { 
     168                AssociateFacesWithInstance(mi, *parents); 
     169        } 
     170 
     171        root->mGeometry.push_back(mi);   
     172 
     173        // reset tables 
     174        hashTable.clear(); 
     175        faces.clear(); 
     176} 
     177 
     178 
    133179bool ObjParser::ParseFile(const string filename, 
    134180                                                  SceneGraphNode **proot, 
     
    139185        if ((file = fopen(filename.c_str(), "rt")) == NULL) 
    140186                return false; 
    141          
     187        cout << "here2" << endl; 
    142188        map<int, Vector3> hashTable; // table associating indices with vectors 
    143189         
     
    169215                case 'f':  
    170216                        { 
     217                                cout << "f"; 
     218#if CONNECT_SEQUENTIAL_FACES 
    171219                                Face *face = LoadFace(str, vertices, hashTable); 
    172220                                if (!face) break; 
    173 #if 0 
     221 
    174222                                faces.push_back(face); 
     223 
    175224                                if (faces.size() >= nMaxFaces) 
    176225                                { 
    177                                         Mesh *mesh = CreateMesh(faces, hashTable); 
    178  
    179                                         // make an instance of this mesh 
    180                                         MeshInstance *mi = new MeshInstance(mesh); 
    181                                         root->mGeometry.push_back(mi); 
    182                                          
    183                                         if (parents)  
    184                                                 AssociateFacesWithInstance(mi, *parents); 
    185                                                                                  
    186                                         // reset tables 
    187                                         hashTable.clear(); 
    188                                         faces.clear(); 
     226                                        ProcessMesh(faces, hashTable, root, parents); 
    189227                                } 
    190228#else 
    191                                 cout << "f"; 
    192                                 root->mGeometry.push_back(new FaceIntersectable(face)); 
    193                                 hashTable.clear(); 
     229                                 
     230                                Triangle3 *triangle = LoadTriangle(str, vertices, hashTable); 
     231                                root->mGeometry.push_back(new TriangleIntersectable(triangle)); 
    194232#endif 
    195233                                break; 
     
    200238        } 
    201239 
     240#if CONNECT_SEQUENTIAL_FACES 
    202241        // there could be faces remaining 
    203242        if (!faces.empty()) 
    204243        {        
    205                 Mesh *mesh = CreateMesh(faces, hashTable); 
    206  
    207                 // make an instance of this mesh 
    208                 MeshInstance *mi = new MeshInstance(mesh); 
    209                  
    210                 if (parents)  
    211                         AssociateFacesWithInstance(mi, *parents); 
    212                  
    213                 root->mGeometry.push_back(mi);   
    214         } 
    215  
    216         // reset tables 
    217         hashTable.clear(); 
    218         faces.clear(); 
     244                ProcessMesh(faces, hashTable, root, parents); 
     245        } 
     246#endif 
    219247 
    220248        fclose(file); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp

    r1076 r1328  
    316316int Polygon3::CastRay(const Ray &ray, float &t, const float nearestT) 
    317317{ 
    318         Plane3 plane = GetSupportingPlane(); 
    319         float dot = DotProd(plane.mNormal, ray.GetDir()); 
     318        const Plane3 plane = GetSupportingPlane(); 
     319        const float dot = DotProd(plane.mNormal, ray.GetDir()); 
    320320 
    321321        // Watch for near-zero denominator 
    322322        // ONLY single sided polygons!!!!! 
    323323        if (dot > -Limits::Small) 
    324         //  if (fabs(dot) < Limits::Small) 
    325         return Ray::NO_INTERSECTION; 
     324        { 
     325                //  if (fabs(dot) < Limits::Small) 
     326                return Ray::NO_INTERSECTION; 
     327        } 
    326328 
    327329        t = (-plane.mD - DotProd(plane.mNormal, ray.GetLoc())) / dot; 
    328330 
    329331        if (t <= Limits::Small) 
    330         return Ray::INTERSECTION_OUT_OF_LIMITS; 
    331  
    332         if (t >= nearestT) { 
    333         return Ray::INTERSECTION_OUT_OF_LIMITS; // no intersection was found 
     332        { 
     333                return Ray::INTERSECTION_OUT_OF_LIMITS; 
     334        } 
     335 
     336        if (t >= nearestT)  
     337        { 
     338                return Ray::INTERSECTION_OUT_OF_LIMITS; // no intersection was found 
    334339        } 
    335340 
     
    338343        int i; 
    339344 
    340         int paxis = plane.mNormal.DrivingAxis(); 
     345        const int paxis = plane.mNormal.DrivingAxis(); 
    341346 
    342347        // Project the intersection point onto the coordinate plane 
     
    344349        ray.Extrap(t).ExtractVerts(&u, &v, paxis); 
    345350 
    346         int size = (int)mVertices.size(); 
     351        const int size = (int)mVertices.size(); 
    347352 
    348353        mVertices.back().ExtractVerts(&u1, &v1, paxis ); 
     
    354359                { 
    355360                mVertices[i].ExtractVerts(&u2, &v2, paxis); 
    356              
     361            
    357362                        // line u1, v1, u2, v2 
    358              
    359                         if ((v2 - v1)*(u1 - u) > (u2 - u1)*(v1 - v)) 
     363                        if ((v2 - v1) * (u1 - u) > (u2 - u1)*(v1 - v)) 
    360364                                return Ray::NO_INTERSECTION; 
    361365 
    362366                        u1 = u2; 
    363367                        v1 = v2; 
    364         } 
    365  
    366         return Ray::INTERSECTION; 
     368                } 
     369                 
     370                return Ray::INTERSECTION; 
    367371        } 
    368372 
     
    537541 
    538542                if ((count ++) % 2) 
     543                { 
    539544                        j = i ++; 
     545                } 
    540546                else 
     547                { 
    541548                        j = k --; 
     549                } 
    542550        } 
    543551} 
     
    575583} 
    576584 
    577 } 
     585 
     586AxisAlignedBox3 Polygon3::GetBoundingBox() const 
     587{ 
     588        VertexContainer::const_iterator vit, vit_end = mVertices.end(); 
     589         
     590        AxisAlignedBox3 box; 
     591        box.Initialize(); 
     592 
     593        for (vit = mVertices.begin(); vit != vit_end; ++ vit) 
     594        { 
     595                box.Include(*vit); 
     596        } 
     597 
     598        return box; 
     599} 
     600 
     601 
     602} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h

    r1076 r1328  
    3838        Polygon3(MeshInstance *parent); 
    3939 
    40         // creates an "infinite" polygon from this plane 
    41         //Polygon3(Plane3 plane); 
     40        ~Polygon3() {DEL_PTR(mPlane);} 
     41         
    4242        /** Copies all the vertices of the face. 
    4343        */ 
     
    6262        */ 
    6363        float GetArea() const; 
    64  
    65         /** Classify polygon with respect to the plane. 
    66             @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT 
    67         */ 
    68         //int ClassifyPlane(const Plane3 &plane) const; 
    6964         
    7065        /** Classify polygon with respect to the plane. 
     
    8782         */ 
    8883        Vector3 Center() const; 
     84 
    8985        /** Checks if the polygon is valid, i.e., not degenerated. 
    9086                @returns true if polygon is valid. 
     
    120116        Polygon3 *CreateReversePolygon() const; 
    121117 
     118        AxisAlignedBox3 GetBoundingBox() const; 
     119 
     120        //////////////////////////////////////////// 
    122121 
    123122        /** Classify polygons with respect to the plane. 
     
    127126                                                         const Plane3 &plane, 
    128127                                                         const float epsilon); 
    129  
    130128 
    131129        /** Counts the number of different intersectables associated with the polygons. 
     
    137135        static float GetArea(const PolygonContainer &cell); 
    138136 
     137        ////////////////////////////////////////////////////// 
     138 
    139139        /** 
    140140                Adds polygon to mesh description as a face 
     
    143143 
    144144 
     145        ////////////////////////////////////////// 
    145146         
    146147        /// vertices are connected in counterclockwise order. 
     
    156157        RayContainer mPiercingRays; 
    157158 
    158         ~Polygon3() {DEL_PTR(mPlane);} 
     159protected: 
     160 
    159161        Plane3 *mPlane; 
     162}; 
    160163 
    161 }; 
    162164 
    163165// Overload << operator for C++-style output 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1299 r1328  
    3838static void AddGeometry(SceneGraph *scene) 
    3939{ 
    40         scene->mRoot->UpdateBox(); 
     40        scene->GetRoot()->UpdateBox(); 
    4141 
    4242        AxisAlignedBox3 sceneBox = scene->GetBox(); 
     
    6262 
    6363                                MeshInstance *mi = new MeshInstance(mesh); 
    64                                 scene->mRoot->mGeometry.push_back(mi); 
     64                                scene->GetRoot()->mGeometry.push_back(mi); 
    6565                        } 
    6666                } 
     
    8181 
    8282                                MeshInstance *mi = new MeshInstance(mesh); 
    83                                 scene->mRoot->mGeometry.push_back(mi); 
     83                                scene->GetRoot()->mGeometry.push_back(mi); 
    8484                        } 
    8585                } 
     
    100100 
    101101                        MeshInstance *mi = new MeshInstance(mesh); 
    102                         scene->mRoot->mGeometry.push_back(mi); 
     102                        scene->GetRoot()->mGeometry.push_back(mi); 
    103103                } 
    104104 
    105                 scene->mRoot->UpdateBox(); 
     105                scene->GetRoot()->UpdateBox(); 
    106106        } 
    107107 
     
    122122 
    123123                MeshInstance *planeMi = new MeshInstance(planeMesh); 
    124                 scene->mRoot->mGeometry.push_back(planeMi); 
     124                scene->GetRoot()->mGeometry.push_back(planeMi); 
    125125        }        
    126126} 
     
    136136mRenderSimulator(NULL), 
    137137mPass(0), 
    138 mRayCastMethod(0) 
     138mRayCastMethod(0), 
     139mSceneGraph(NULL) 
    139140{ 
    140141        Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer); 
     
    242243                          parser = new UnigraphicsParser; 
    243244 
    244                 cout<<filename<<endl; 
     245                cout << filename << endl; 
     246 
     247                SceneGraphNode *sroot = mSceneGraph->GetRoot(); 
    245248 
    246249                if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) 
    247                   result = parser->ParseFile(filename, &mSceneGraph->mRoot, 
    248                                                                          mLoadPolygonsAsMeshes, 
    249                                                                          &mFaceParents); 
     250                { cout << "here5800" << endl; 
     251                        result = parser->ParseFile( 
     252                                filename,  
     253                                &sroot, 
     254                                mLoadPolygonsAsMeshes, 
     255                                &mFaceParents); 
     256                } 
    250257                else 
    251                   result = parser->ParseFile(filename, &mSceneGraph->mRoot, mLoadPolygonsAsMeshes); 
    252                  
     258                { cout << "here776645" << endl; 
     259                        result = parser->ParseFile(filename, &sroot, mLoadPolygonsAsMeshes); 
     260                } 
     261                 cout << "here98809845" << endl; 
    253262                delete parser; 
    254263 
    255264        } else { 
    256265                // root for different files 
    257                 mSceneGraph->mRoot = new SceneGraphNode; 
     266                mSceneGraph->SetRoot(new SceneGraphNode()); 
    258267                for (int i= 0; i < filenames.size(); i++) { 
    259268                  if (strstr(filenames[i].c_str(), ".x3d")) 
     
    266275                   
    267276                  if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) 
    268                         success = parser->ParseFile(filename, &node, 
    269                                                                                 mLoadPolygonsAsMeshes, 
    270                                                                                 &mFaceParents); 
     277                  { cout << "here4500" << endl; 
     278                          success = parser->ParseFile( 
     279                                  filename,  
     280                                  &node, 
     281                                  mLoadPolygonsAsMeshes, 
     282                                  &mFaceParents); 
     283                  } 
    271284                  else 
    272                         success = parser->ParseFile(filename, &node, mLoadPolygonsAsMeshes); 
    273                    
    274                   if (success) { 
    275                         mSceneGraph->mRoot->mChildren.push_back(node); 
    276                         // at least one file parsed 
    277                         result = true; 
     285                  { 
     286                          cout << "here45" << endl; 
     287                          success = parser->ParseFile(filename, &node, mLoadPolygonsAsMeshes); 
     288                  } 
     289 
     290                  if (success)  
     291                  { cout << "here4509999" << endl; 
     292                          mSceneGraph->GetRoot()->mChildren.push_back(node); 
     293                          // at least one file parsed 
     294                          result = true; 
    278295                  } 
    279296                   
     
    281298                } 
    282299        } 
    283          
    284          
     300         cout << "here8888" << endl; 
     301 
    285302        if (result)  
    286           { 
     303        { cout << "here199" << endl; 
    287304                // HACK  
    288305                if (ADDITIONAL_GEOMETRY_HACK) 
    289306                        AddGeometry(mSceneGraph); 
    290                  
     307 
    291308                mSceneGraph->AssignObjectIds(); 
    292          
     309 cout << "here99" << endl; 
    293310                int intersectables, faces; 
    294311                mSceneGraph->GetStatistics(intersectables, faces); 
    295          
     312 cout << "here999" << endl; 
    296313                cout<<filename<<" parsed successfully."<<endl; 
    297314                cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl; 
    298315                cout<<"#NUM_FACES (Total numner of faces)\n"<<faces<<endl; 
    299316                mSceneGraph->CollectObjects(&mObjects); 
    300                 mSceneGraph->mRoot->UpdateBox(); 
    301  
     317                mSceneGraph->GetRoot()->UpdateBox(); 
     318 cout << "here9999" << endl; 
    302319                if (0) 
    303320                { 
    304321                        Exporter *exporter = Exporter::GetExporter("testload.x3d"); 
    305  
    306322                        if (exporter) 
    307323                        { 
     
    311327                } 
    312328        } 
    313          
    314          
     329 
    315330        return result; 
    316331} 
     
    356371  // add mesh instances of the scene graph to the root of the tree 
    357372  KdLeaf *root = (KdLeaf *)mKdTree->GetRoot(); 
     373        cout << "here3.95" << endl; 
    358374  mSceneGraph->CollectObjects(&root->mObjects); 
    359    
     375        cout << "here3.97" << endl; 
    360376  long startTime = GetTime(); 
    361377 
     
    389405  if (exporter) { 
    390406    if (scene) 
    391       exporter->ExportScene(mSceneGraph->mRoot); 
     407      exporter->ExportScene(mSceneGraph->GetRoot()); 
    392408 
    393409    if (kdtree) { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp

    r1302 r1328  
    278278  // $$JB temporarily do not export the scene 
    279279  if (0) 
    280         exporter->ExportScene(mSceneGraph->mRoot); 
     280        exporter->ExportScene(mSceneGraph->GetRoot()); 
    281281  exporter->SetWireframe(); 
    282282 
     
    316316  // $$JB temporarily do not export the scene 
    317317  if (1) 
    318         exporter->ExportScene(mSceneGraph->mRoot); 
     318        exporter->ExportScene(mSceneGraph->GetRoot()); 
    319319  exporter->SetWireframe(); 
    320320 
     
    343343  Exporter *exporter = Exporter::GetExporter(filename); 
    344344  exporter->SetFilled(); 
    345   exporter->ExportScene(mSceneGraph->mRoot); 
     345  exporter->ExportScene(mSceneGraph->GetRoot()); 
    346346  //  exporter->SetWireframe(); 
    347347  bool result = exporter->ExportRssTree2( *tree, dir ); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp

    r1233 r1328  
    22022202        //      exporter->ExportKdTree(*mKdTree); 
    22032203        exporter->SetWireframe(); 
    2204 //      exporter->ExportScene(preprocessor->mSceneGraph->mRoot); 
     2204//      exporter->ExportScene(preprocessor->mSceneGraph->GetRoot()); 
    22052205        exporter->SetWireframe(); 
    22062206        exporter->ExportBox(box); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp

    r1194 r1328  
    2828 
    2929 
     30SceneGraphNode::~SceneGraphNode() 
     31{ 
     32        CLEAR_CONTAINER(mGeometry); 
     33         
     34        // recursivly delete all children 
     35        CLEAR_CONTAINER(mChildren); 
     36} 
     37 
     38 
     39/************************************************************/ 
     40/*                 SceneGraph implementation                */ 
     41/************************************************************/ 
     42 
     43 
     44SceneGraph::SceneGraph(): 
     45mRoot(NULL) 
     46{ 
     47} 
     48 
     49 
    3050SceneGraph::~SceneGraph() 
    3151{ 
     
    3454 
    3555 
    36 SceneGraphNode::~SceneGraphNode() 
     56SceneGraphNode *SceneGraph::GetRoot() 
    3757{ 
    38         CLEAR_CONTAINER(mGeometry); 
    39         SceneGraphNodeContainer::iterator it, it_end = mChildren.end(); 
     58        return mRoot; 
     59} 
    4060 
    41         // recursivly delete all children 
    42         CLEAR_CONTAINER(mChildren); 
     61 
     62void SceneGraph::SetRoot(SceneGraphNode *root) 
     63{ 
     64        mRoot = root; 
    4365} 
    4466 
     
    4870{ 
    4971        instances->clear(); 
    50   int number = 0; 
    51   stack<SceneGraphNode *> nodeStack; 
    52    
    53   nodeStack.push(mRoot); 
    54    
    55   while (!nodeStack.empty()) { 
    56     SceneGraphNode *node = nodeStack.top(); 
    57     nodeStack.pop(); 
     72        int number = 0; 
    5873 
    59     ObjectContainer::const_iterator mi = node->mGeometry.begin(); 
    60     for (; mi != node->mGeometry.end(); mi++) 
    61           instances->push_back(*mi); 
    62          
    63     SceneGraphNodeContainer::iterator ni = node->mChildren.begin(); 
    64     for (; ni != node->mChildren.end(); ni++) { 
    65       nodeStack.push(*ni); 
    66       number++; 
    67     } 
    68      
    69   } 
    70   return number; 
     74        stack<SceneGraphNode *> nodeStack; 
     75        nodeStack.push(mRoot); 
     76 
     77        while (!nodeStack.empty()) { 
     78                SceneGraphNode *node = nodeStack.top(); 
     79                nodeStack.pop(); 
     80                cout << "here3.958" << endl;cout << "here3.9587654" << endl; 
     81                ObjectContainer::const_iterator mi = node->mGeometry.begin();   cout << "here3.958" << endl; 
     82                for (; mi != node->mGeometry.end(); mi++) 
     83                { 
     84                        cout << "here3.9886" << endl; 
     85                        instances->push_back(*mi); 
     86                } 
     87                cout << "here3.969999" << endl; 
     88                SceneGraphNodeContainer::iterator ni = node->mChildren.begin(); 
     89                for (; ni != node->mChildren.end(); ni++) { 
     90                        nodeStack.push(*ni);    cout << "here3.959" << endl; 
     91                        number++; 
     92                } 
     93                cout << "here3.96" << endl; 
     94        } 
     95        return number; 
    7196} 
    7297 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h

    r1166 r1328  
    2828public: 
    2929 
     30        SceneGraph(); 
    3031        ~SceneGraph(); 
     32         
     33        bool Export(const string filename); 
     34   
     35        int CollectObjects(ObjectContainer *instances); 
     36   
     37        int AssignObjectIds(); 
     38   
     39        void GetStatistics(int &intersectables, int &faces) const; 
    3140 
    32   SceneGraphNode *mRoot; 
    33   bool Export(const string filename); 
     41        AxisAlignedBox3 GetBox() const { return mRoot->mBox; } 
    3442   
    35   int 
    36   CollectObjects(ObjectContainer *instances); 
    37    
    38   int 
    39   AssignObjectIds(); 
    40    
    41   void 
    42   GetStatistics(int &intersectables, int &faces) const; 
     43        /** Exports binary version of the scene. 
     44        */ 
     45        void ExportScene(const string filename); 
    4346 
    44   AxisAlignedBox3 GetBox() const { return mRoot->mBox; } 
    45    
    46   /** Exports binary version of the scene. 
    47   */ 
    48   void ExportScene(const string filename); 
     47        /** Loads binary version of the scene. 
     48        */ 
     49        void LoadScene(const string filename); 
    4950 
    50   /** Loads binary version of the scene. 
    51   */ 
    52   void LoadScene(const string filename); 
     51        SceneGraphNode *GetRoot(); 
     52 
     53        void SetRoot(SceneGraphNode *sgNnode); 
    5354 
    5455protected: 
     56 
     57         SceneGraphNode *mRoot; 
    5558}; 
    5659 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp

    r863 r1328  
    11#include "Triangle3.h" 
     2#include "Ray.h" 
     3#include "AxisAlignedBox3.h" 
     4 
    25 
    36namespace GtpVisibilityPreprocessor { 
    47 
    5 float 
    6 Triangle3::GetSpatialAngle(const Vector3 &point) const 
     8         
     9Triangle3::Triangle3(const Vector3 &a, const Vector3 &b, const Vector3 &c)  
    710{ 
    8   return 0.0f; 
     11        Init(a, b, c); 
    912} 
    1013 
     14 
     15void Triangle3::Init(const Vector3 &a, const Vector3 &b, const Vector3 &c)  
     16{ 
     17        mVertices[0] = a; 
     18        mVertices[1] = b; 
     19        mVertices[2] = c; 
     20 
    1121} 
     22 
     23 
     24float Triangle3::GetSpatialAngle(const Vector3 &point) const 
     25{ 
     26        return 0.0f; 
     27} 
     28 
     29 
     30int Triangle3::CastRay(const Ray &ray, float &t, const float nearestT) const 
     31{ 
     32        // get triangle edge vectors and plane normal 
     33        const Vector3 u = mVertices[1] - mVertices[0]; 
     34    const Vector3 v = mVertices[2] - mVertices[0]; 
     35 
     36    const Vector3 n = u * v;  // cross product 
     37 
     38    const Vector3 dir = ray.GetDir();           // ray direction vector 
     39    const Vector3 w0 = ray.GetLoc() - mVertices[0]; 
     40 
     41        // params to calc ray-plane intersect 
     42    const float a = - DotProd(n, w0); 
     43    const float b = DotProd(n, dir); 
     44 
     45        if (fabs(b) < Limits::Small)  
     46        {    
     47                // ray is parallel to triangle plane 
     48        if (a == 0) // ray lies in triangle plane 
     49                { 
     50            return Ray::INTERSECTION_OUT_OF_LIMITS; 
     51                } 
     52        else 
     53                { 
     54                        return Ray::NO_INTERSECTION; // ray disjoint from plane 
     55                } 
     56    } 
     57 
     58    // get intersect point of ray with triangle plane 
     59    t = a / b; 
     60 
     61    if (t < 0.0) // ray goes away from triangle 
     62        { 
     63        return Ray::NO_INTERSECTION; // => no intersect 
     64        } 
     65 
     66    // for a segment, also test if (r > 1.0) => no intersect 
     67 
     68        // intersect point of ray and plane 
     69    const Vector3 pt = ray.GetLoc() + t * dir;  
     70 
     71 
     72        /////////////////////////////////////////////// 
     73    //-- is point inside triangle? 
     74    
     75        const Vector3 w = pt - mVertices[0]; 
     76 
     77        const float uu = DotProd(u, u); 
     78    const float uv = DotProd(u, v); 
     79    const float vv = DotProd(v, v); 
     80     
     81        const float wu = DotProd(w, u); 
     82    const float wv = DotProd(w, v); 
     83    const float D = uv * uv - uu * vv; 
     84 
     85    // get and test parametric coords 
     86    const float s = (uv * wv - vv * wu) / D; 
     87 
     88    if (s < 0.0 || s > 1.0) // pt is outside triangle 
     89        { 
     90        return Ray::NO_INTERSECTION; 
     91        } 
     92 
     93        const float s2 = (uv * wu - uu * wv) / D; 
     94 
     95    if (s2 < 0.0 || (s + s2) > 1.0) // pt is outside triangle 
     96        { 
     97        return Ray::NO_INTERSECTION; 
     98        } 
     99 
     100        return Ray::INTERSECTION; // I is in T 
     101} 
     102 
     103 
     104AxisAlignedBox3 Triangle3::GetBoundingBox() const 
     105{ 
     106        AxisAlignedBox3 box; 
     107        box.Initialize(); 
     108 
     109        box.Include(mVertices[0]); 
     110        box.Include(mVertices[1]); 
     111        box.Include(mVertices[2]); 
     112 
     113        return box; 
     114} 
     115 
     116 
     117Vector3 Triangle3::GetNormal() const  
     118{ 
     119        const Vector3 v1 = mVertices[0] - mVertices[1]; 
     120        const Vector3 v2 = mVertices[2]-mVertices[1]; 
     121 
     122        return Normalize(CrossProd(v2, v1)); 
     123} 
     124 
     125 
     126Vector3 Triangle3::GetCenter() const  
     127{ 
     128        return (mVertices[0] + mVertices[1] + mVertices[2]) / 3.0f; 
     129} 
     130 
     131 
     132float Triangle3::GetArea() const  
     133{ 
     134        Vector3 v1=mVertices[0]-mVertices[1], v2=mVertices[2]-mVertices[1]; 
     135        return 0.5f * Magnitude(CrossProd(v2, v1)); 
     136} 
     137 
     138 
     139} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h

    r860 r1328  
    44#include "Vector3.h" 
    55 
     6 
    67namespace GtpVisibilityPreprocessor { 
    78 
    8 struct Triangle3 { 
    9    
    10   Vector3 mVertices[3]; 
    11    
    12   Triangle3() {} 
    13   Triangle3(const Vector3 &a, 
    14                  const Vector3 &b, 
    15                  const Vector3 &c 
    16                  ) { 
    17     Init(a, b, c); 
    18   } 
     9class AxisAlignedBox3; 
     10class Ray; 
    1911 
    20   void 
    21   Init(const Vector3 &a, 
    22        const Vector3 &b, 
    23        const Vector3 &c 
    24        ) { 
    25     mVertices[0] = a; 
    26     mVertices[1] = b; 
    27     mVertices[2] = c; 
    28      
    29   } 
    3012 
    31   Vector3 GetNormal() const { 
    32     Vector3 v1=mVertices[0]-mVertices[1], v2=mVertices[2]-mVertices[1]; 
    33     return Normalize(CrossProd(v2,v1)); 
    34   } 
     13struct Triangle3  
     14{ 
     15        Triangle3() {}; 
     16        Triangle3(const Vector3 &a, const Vector3 &b, const Vector3 &c); 
    3517 
    36   Vector3 GetCenter() const { 
    37     return (mVertices[0] + mVertices[1] + mVertices[2])/3.0f; 
    38   } 
     18        void Init(const Vector3 &a, const Vector3 &b, const Vector3 &c); 
    3919 
    40   float GetSpatialAngle(const Vector3 &point) const; 
     20        Vector3 GetNormal() const; 
    4121 
    42   float GetArea() const { 
    43           Vector3 v1=mVertices[0]-mVertices[1], v2=mVertices[2]-mVertices[1]; 
    44           return 0.5f * Magnitude(CrossProd(v2, v1)); 
    45   } 
     22        Vector3 GetCenter() const; 
     23 
     24        float GetSpatialAngle(const Vector3 &point) const; 
     25 
     26        float GetArea() const; 
     27 
     28        /// returns bounding box around this triangle 
     29        AxisAlignedBox3 GetBoundingBox() const; 
     30 
     31        /// Casts ray into this triangle. Returns hit 
     32        int CastRay(const Ray &ray, float &t, const float nearestT) const; 
     33 
     34        ////////////////////////////// 
     35 
     36        /// the triangle vertices 
     37        Vector3 mVertices[3]; 
    4638}; 
    4739 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.h

    r863 r1328  
    437437CrossProd (const Vector3 &A, const Vector3 &B) 
    438438{ 
    439   return Vector3(A.y * B.z - A.z * B.y, 
    440                  A.z * B.x - A.x * B.z, 
    441                  A.x * B.y - A.y * B.x); 
     439  return  
     440          Vector3(A.y * B.z - A.z * B.y, 
     441                          A.z * B.x - A.x * B.z, 
     442                          A.x * B.y - A.y * B.x); 
    442443} 
    443444 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp

    r1311 r1328  
    160160  exporter->ExportKdTree(*mKdTree); 
    161161  exporter->SetFilled(); 
    162   exporter->ExportScene(mSceneGraph->mRoot); 
     162  exporter->ExportScene(mSceneGraph->GetRoot()); 
    163163  exporter->SetWireframe(); 
    164164 
     
    190190  Exporter *exporter = Exporter::GetExporter(filename); 
    191191  exporter->SetFilled(); 
    192   exporter->ExportScene(mSceneGraph->mRoot); 
     192  exporter->ExportScene(mSceneGraph->GetRoot()); 
    193193  //  exporter->SetWireframe(); 
    194194  bool result = exporter->ExportVssTree2( *tree, dir ); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1294 r1328  
    112112  string result = filename; 
    113113 
    114   int pos = filename.rfind(a, (int)filename.size() - 1); 
     114  int pos = (int)filename.rfind(a, (int)filename.size() - 1); 
    115115  if (pos == filename.size() - a.size()) { 
    116116        result.replace(pos, a.size(), b); 
     
    149149 
    150150        if (preprocessorType == "vss") 
    151           { 
     151        { 
    152152                preprocessor = new VssPreprocessor(); 
    153           } 
     153        } 
    154154        else 
    155155        { 
     
    176176                                                preprocessor = new RenderSampler(); 
    177177                                        } 
    178                                         else { 
     178                                        else  
     179                                        { 
    179180                                                Environment::DelSingleton(); 
    180181                                                cerr<<"Unknown preprocessor type"<<endl; 
     
    186187                } 
    187188        } 
    188          
    189  
     189 
     190        //////////////////////////////////////// 
    190191        //-- load scene  
    191192 
    192193        Environment::GetSingleton()->GetStringValue("Scene.filename", buff); 
    193194        string filename(buff); 
    194         preprocessor->LoadScene(filename); 
    195          
     195 
     196        if (!preprocessor->LoadScene(filename)) 
     197        { 
     198                cout << "loading file " << filename << " failed" << endl; 
     199                Cleanup(); 
     200                exit(1); 
     201        } 
     202 
    196203        string rayCastFile = ReplaceSuffix(filename, ".obj", ".kdf"); 
    197          
     204 
    198205        //-- initialize external ray casters 
    199206        if (preprocessor->InitRayCast(rayCastFile)) 
    200           { 
     207        { 
    201208                cout << "ray casting initialized!" << endl; 
    202           } 
     209        } 
    203210        else 
    204211        { 
    205212                cout << "ray casting initialization failed" << endl; 
     213                Cleanup(); 
    206214                exit(1); 
    207215        } 
    208  
     216        cout << "here3.9" << endl; 
    209217        //-- build kd tree from scene geometry 
    210218        preprocessor->BuildKdTree(); 
    211219        preprocessor->KdTreeStatistics(cout); 
    212          
     220        cout << "here3" << endl; 
    213221        /*preprocessor->mKdTree->ExportBinTree("kd.bin.gz"); 
    214222        MeshManager::GetSingleton()->ExportEntries("meshes.bin"); 
     
    234242 
    235243        DEL_PTR(kdTree2); 
    236 */ 
     244*/cout << "here4" << endl; 
    237245        // parse view cells related options 
    238246        preprocessor->PrepareViewCells(); 
     
    243251                preprocessor->Export(filename + "-kdtree.x3d", false, true, false);      
    244252        } 
    245  
     253cout << "here5" << endl; 
    246254        // create a preprocessor thread (note: capsulates calls to boost fuctions!) 
    247255        //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor); 
Note: See TracChangeset for help on using the changeset viewer.