Changeset 2124


Ignore:
Timestamp:
02/19/07 02:51:22 (17 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis
Files:
4 deleted
29 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h

    r2123 r2124  
    99namespace  GtpVisibilityPreprocessor { 
    1010class Intersectable; 
     11class Preprocessor; 
    1112} 
    1213 
     
    3132        Ogre::SceneManager *mSceneManager; 
    3233        GtpVisibilityPreprocessor::ObjectContainer mPvsObjects; 
     34        GtpVisibilityPreprocessor::Preprocessor *mPreprocessor; 
    3335}; 
    3436 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp

    r2123 r2124  
    1313 
    1414ObjReader::ObjReader(Ogre::SceneManager *sceneManager): 
    15 mSceneManager(sceneManager) 
    16 {} 
     15mSceneManager(sceneManager), mPreprocessor(NULL) 
     16{ 
     17} 
    1718 
    1819 
     
    2021{ 
    2122        CLEAR_CONTAINER(mPvsObjects); 
     23         
     24        DEL_PTR(mPreprocessor); 
    2225} 
    2326 
     
    2932        GtpVisibilityPreprocessor::Debug.open("debug.log"); 
    3033        // HACK: get any preprocessor to load file 
    31         GtpVisibilityPreprocessor::Preprocessor *preprocessor =  
     34        // note should be preserved to allow manual mesh reloading, 
     35        // but then geometry has to be stored two times 
     36        mPreprocessor =  
    3237                GtpVisibilityPreprocessor::PreprocessorFactory::CreatePreprocessor("vss"); 
    3338 
    3439        // hack 
    35         preprocessor->mLoadMeshes = false; 
     40        mPreprocessor->mLoadMeshes = false; 
    3641 
    3742        Ogre::LogManager::getSingleton().logMessage("loading obj scene"); 
    3843 
    39         if (preprocessor->LoadScene(sceneName)) 
     44        if (mPreprocessor->LoadScene(sceneName)) 
    4045        { 
    4146                Ogre::LogManager::getSingleton().logMessage("scene loaded, loading objects"); 
    4247                // form objects from the scene triangles 
    43                 if (!preprocessor->LoadObjects(visibilitySolution, mPvsObjects, preprocessor->mObjects)) 
     48                if (!mPreprocessor->LoadObjects(visibilitySolution, mPvsObjects, mPreprocessor->mObjects)) 
    4449                { 
    4550                        Ogre::LogManager::getSingleton().logMessage("objects cannot be loaded"); 
     
    5459 
    5560        std::stringstream d;  
    56         d << "successfully loaded " << mPvsObjects.size() << " objects from " << preprocessor->mObjects.size() << " preprocessor objects"; 
     61        d << "successfully loaded " << (int)mPvsObjects.size()  
     62          << " objects from " << (int)mPreprocessor->mObjects.size() << " preprocessor objects"; 
    5763 
    5864        Ogre::LogManager::getSingleton().logMessage(d.str()); 
     
    6571                if (i % 5000 == 4999) 
    6672                { 
    67                         d << i << " objects created" << endl; 
     73                        d << i << " objects created"; 
     74                        Ogre::LogManager::getSingleton().logMessage(d.str()); 
    6875                } 
    6976         
     
    8491        } 
    8592 
    86         delete preprocessor; 
     93        //delete preprocessor; 
    8794 
    8895        return true; 
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocess_visibility.sh

    r2099 r2124  
    11#!/bin/sh 
    22 
    3 PREPROCESSOR=../bin/release/preprocessor.exe 
    4 #PREPROCESSOR=../bin/debug/preprocessor.exe 
     3#PREPROCESSOR=../bin/release/preprocessor.exe 
     4PREPROCESSOR=../bin/debug/preprocessor.exe 
    55 
    66if [ $# -ne 3 ] 
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp

    r2070 r2124  
    209209int 
    210210AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, 
    211                                 float *tmin, 
    212                                 float *tmax) const 
     211                                                                float *tmin, 
     212                                                                float *tmax) const 
    213213{ 
    214214  float minx, maxx, miny, maxy, minz, maxz; 
     
    301301int 
    302302AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, 
    303                                 float *tmin, 
    304                                 float *tmax) const 
     303                                                                float *tmin, 
     304                                                                float *tmax) const 
    305305{ 
    306306  const float dirEps = 1e-8f; 
     
    396396// of intersection with the ray; it returns 1 if the ray hits 
    397397// the bounding box and 0 if it does not. 
    398 int 
    399 AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, float *tmin, float *tmax, 
    400                                 EFaces &entryFace, EFaces &exitFace) const 
     398int AxisAlignedBox3::ComputeMinMaxT(const Ray &ray, float *tmin, float *tmax, 
     399                                                                        EFaces &entryFace, EFaces &exitFace) const 
    401400{ 
    402401  float minx, maxx, miny, maxy, minz, maxz; 
     
    532531 
    533532// computes the signed distances for case tmin<tmax and tmax>0 
    534 int 
    535 AxisAlignedBox3::GetMinMaxT(const Ray &ray, float *tmin, float *tmax, 
    536                             EFaces &entryFace, EFaces &exitFace) const 
     533int AxisAlignedBox3::GetMinMaxT(const Ray &ray,  
     534                                                                float *tmin,  
     535                                                                float *tmax, 
     536                                                                EFaces &entryFace, 
     537                                                                EFaces &exitFace) const 
    537538{ 
    538539  if (!ComputeMinMaxT(ray, tmin, tmax, entryFace, exitFace)) 
     
    583584      b.mMax.y <= mMax.y && 
    584585      b.mMax.z <= mMax.z); 
    585  
    586586} 
    587587 
    588588 
    589589// compute the coordinates of one vertex of the box 
    590 Vector3 
    591 AxisAlignedBox3::GetVertex(int xAxis, int yAxis, int zAxis) const 
     590Vector3 AxisAlignedBox3::GetVertex(int xAxis, int yAxis, int zAxis) const 
    592591{ 
    593592  Vector3 p; 
     
    23892388 } 
    23902389 
    2391 /* 
    2392 int inline GetIntersection(const float fDst1,  
    2393                                                    const float fDst2,  
    2394                                                    const Vector3 p1,  
    2395                                                    const Vector3 p2,  
    2396                                                    const Vector3 &hit)  
    2397 { 
    2398         if ((fDst1 * fDst2) >= 0.0f)  
    2399                 return 0; 
    2400      
    2401         if (fDst1 == fDst2)  
    2402                 return 0;  
    2403      
    2404         hit = p1 + (p2 - p1) * (-fDst1 / (fDst2 - fDst1)); 
    2405          
    2406         return 1; 
    2407 } 
    2408  
    2409  
    2410 int inline InBox( CVec3 Hit, CVec3 B1, CVec3 B2, const int Axis) { 
    2411 if ( Axis==1 && Hit.z > B1.z && Hit.z < B2.z && Hit.y > B1.y && Hit.y < B2.y) return 1; 
    2412 if ( Axis==2 && Hit.z > B1.z && Hit.z < B2.z && Hit.x > B1.x && Hit.x < B2.x) return 1; 
    2413 if ( Axis==3 && Hit.x > B1.x && Hit.x < B2.x && Hit.y > B1.y && Hit.y < B2.y) return 1; 
    2414 return 0; 
    2415 } 
    2416  
    2417 // returns true if line (L1, L2) intersects with the box (B1, B2) 
    2418 // returns intersection point in Hit 
    2419 int CheckLineBox( CVec3 B1, CVec3 B2, CVec3 L1, CVec3 L2, CVec3 &Hit) 
    2420 { 
    2421 if (L2.x < B1.x && L1.x < B1.x) return false; 
    2422 if (L2.x > B2.x && L1.x > B2.x) return false; 
    2423 if (L2.y < B1.y && L1.y < B1.y) return false; 
    2424 if (L2.y > B2.y && L1.y > B2.y) return false; 
    2425 if (L2.z < B1.z && L1.z < B1.z) return false; 
    2426 if (L2.z > B2.z && L1.z > B2.z) return false; 
    2427 if (L1.x > B1.x && L1.x < B2.x && 
    2428     L1.y > B1.y && L1.y < B2.y && 
    2429     L1.z > B1.z && L1.z < B2.z)  
    2430     {Hit = L1;  
    2431     return true;} 
    2432 if ( (GetIntersection( L1.x-B1.x, L2.x-B1.x, L1, L2, Hit) && InBox( Hit, B1, B2, 1 )) 
    2433   || (GetIntersection( L1.y-B1.y, L2.y-B1.y, L1, L2, Hit) && InBox( Hit, B1, B2, 2 ))  
    2434   || (GetIntersection( L1.z-B1.z, L2.z-B1.z, L1, L2, Hit) && InBox( Hit, B1, B2, 3 ))  
    2435   || (GetIntersection( L1.x-B2.x, L2.x-B2.x, L1, L2, Hit) && InBox( Hit, B1, B2, 1 ))  
    2436   || (GetIntersection( L1.y-B2.y, L2.y-B2.y, L1, L2, Hit) && InBox( Hit, B1, B2, 2 ))  
    2437   || (GetIntersection( L1.z-B2.z, L2.z-B2.z, L1, L2, Hit) && InBox( Hit, B1, B2, 3 ))) 
    2438         return true; 
    2439  
    2440 return false; 
    2441 } 
    2442 */ 
    2443  
    2444 } 
    2445  
     2390 
     2391bool AxisAlignedBox3::Intersects(const Vector3 &lStart,  
     2392                                                                 const Vector3 &lEnd) const 
     2393{ 
     2394   float st, et, fst = 0, fet = 1; 
     2395   float const *bmin = &mMin.x; 
     2396   float const *bmax = &mMax.x; 
     2397   float const *si = &lStart.x; 
     2398   float const *ei = &lEnd.x; 
     2399 
     2400   for (int i = 0; i < 3; ++ i)  
     2401   { 
     2402      if (*si < *ei)  
     2403          { 
     2404                  if (*si > *bmax || *ei < *bmin) 
     2405                          return false; 
     2406 
     2407         const float di = *ei - *si; 
     2408                  
     2409                 st = (*si < *bmin)? (*bmin - *si) / di : 0; 
     2410         et = (*ei > *bmax)? (*bmax - *si) / di : 1; 
     2411      } 
     2412          else  
     2413          { 
     2414                  if (*ei > *bmax || *si < *bmin) 
     2415                          return false; 
     2416                   
     2417                  const float di = *ei - *si; 
     2418                   
     2419                  st = (*si > *bmax)? (*bmax - *si) / di : 0; 
     2420                  et = (*ei < *bmin)? (*bmin - *si) / di : 1; 
     2421      } 
     2422 
     2423      if (st > fst) fst = st; 
     2424      if (et < fet) fet = et; 
     2425      if (fet < fst) 
     2426                  return false; 
     2427           
     2428          ++ bmin; ++ bmax; 
     2429      ++ si; ++ ei; 
     2430   } 
     2431 
     2432   //*time = fst; 
     2433   return true; 
     2434} 
     2435 
     2436} 
     2437 
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h

    r2070 r2124  
    7272  void Reduce(int axis, int right, float value);  
    7373   
     74  bool Intersects(const Vector3 &lStart, const Vector3 &lEnd) const; 
    7475 
    7576  // the size of the box along all the axes 
     
    9394  void Include(const int &axis, const float &newBound); 
    9495 
    95  
    96   int 
    97   Side(const Plane3 &plane) const; 
     96  int Side(const Plane3 &plane) const; 
    9897 
    9998  // Overlap returns 1 if the two axis-aligned boxes overlap .. even weakly 
     
    121120  bool Includes(const AxisAlignedBox3 &b) const; 
    122121 
     122  /** Returns true if this point is inside box. 
     123  */ 
    123124  virtual int IsInside(const Vector3 &v) const; 
    124125   
     126  /** Returns true if start and endpoint of the ray is inside box. 
     127  */ 
    125128  virtual int IsInside(const VssRay &v) const; 
    126129 
     
    203206  // Returns the intersection of two axis-aligned boxes. 
    204207  friend inline AxisAlignedBox3 Intersect(const AxisAlignedBox3 &x, 
    205                                 const AxisAlignedBox3 &y); 
     208                                                                                  const AxisAlignedBox3 &y); 
    206209 
    207210  // Given 4x4 matrix, transform the current box to new one. 
    208211  friend inline AxisAlignedBox3 Transform(const AxisAlignedBox3 &box, 
    209                                           const Matrix4x4 &tform); 
     212                                                                                  const Matrix4x4 &tform); 
    210213 
    211214   
    212215  // returns true when two boxes are completely equal 
    213   friend inline int operator== (const AxisAlignedBox3 &A, const AxisAlignedBox3 &B); 
     216  friend inline int operator== (const AxisAlignedBox3 &A,  
     217                                                                const AxisAlignedBox3 &B); 
    214218   
    215219  virtual float SurfaceArea() const; 
    216   virtual float GetVolume() const { 
    217     return (mMax.x - mMin.x) * (mMax.y - mMin.y) * (mMax.z - mMin.z); 
     220  virtual float GetVolume() const  
     221  { 
     222          return (mMax.x - mMin.x) * (mMax.y - mMin.y) * (mMax.z - mMin.z); 
    218223  } 
    219224 
    220225  // Six faces are distuinguished by their name. 
    221   enum EFaces { ID_Back = 0, ID_Left = 1, ID_Bottom = 2, ID_Front = 3, 
    222                 ID_Right = 4, ID_Top = 5}; 
    223    
    224   int 
    225   ComputeMinMaxT(const Vector3 &origin, 
    226                                  const Vector3 &direction, 
    227                                  float *tmin, 
    228                                  float *tmax) const; 
     226  enum EFaces {ID_Back = 0,  
     227                           ID_Left = 1,  
     228                           ID_Bottom = 2,  
     229                           ID_Front = 3, 
     230                           ID_Right = 4,  
     231                           ID_Top = 5}; 
     232   
     233  int  ComputeMinMaxT(const Vector3 &origin, 
     234                                          const Vector3 &direction, 
     235                                          float *tmin, 
     236                                          float *tmax) const; 
    229237         
    230238  // Compute tmin and tmax for a ray, whenever required .. need not pierce box 
     
    243251  // computes the signed distances for case: tmin < tmax and tmax > 0 
    244252  int GetMinMaxT(const Ray &ray, float *tmin, float *tmax, 
    245                 EFaces &entryFace, EFaces &exitFace) const; 
     253                                EFaces &entryFace, EFaces &exitFace) const; 
    246254   
    247255  // Writes a brief description of the object, indenting by the given 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp

    r2093 r2124  
    335335        Debug << "use surface area heuristics: " << mUseSah << endl; 
    336336        Debug << "subdivision stats log: " << subdivisionStatsLog << endl; 
    337         Debug << "split borders: " << mSplitBorder << endl; 
     337        //Debug << "split borders: " << mSplitBorder << endl; 
    338338        Debug << "render cost decrease weight: " << mRenderCostDecreaseWeight << endl; 
    339339        Debug << "use global sort: " << mUseGlobalSorting << endl; 
     
    14391439        if (sortEntries) 
    14401440        {       // no presorted candidate list 
    1441                 //stable_sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 
    1442                 sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 
     1441                stable_sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 
     1442                //sort((*subdivisionCandidates)->begin(), (*subdivisionCandidates)->end()); 
    14431443        } 
    14441444} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r2119 r2124  
    10091009        int mCreatedLeaves; 
    10101010        /// represents min and max band for sweep 
    1011         float mSplitBorder; 
     1011        //float mSplitBorder; 
    10121012        /// weight between render cost decrease and node render cost 
    10131013        float mRenderCostDecreaseWeight; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r2076 r2124  
    13781378 
    13791379        RegisterOption("ViewCells.type", 
    1380                         optString, 
    1381                         "view_cells_type=", 
    1382                         "vspBspTree"); 
     1380                                        optString, 
     1381                                        "view_cells_type=", 
     1382                                        "vspBspTree"); 
    13831383 
    13841384        RegisterOption("ViewCells.samplingType", 
    1385                         optString, 
    1386                         "view_cells_sampling_type=", 
    1387                         "box"); 
     1385                                        optString, 
     1386                                        "view_cells_sampling_type=", 
     1387                                        "box"); 
    13881388 
    13891389        RegisterOption("ViewCells.mergeStats", 
     
    21822182 
    21832183        RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio", 
    2184                 optFloat, 
    2185                 "vsp_bsp_term_axis_aligned_max_cost_ratio=", 
    2186                 "1.5"); 
     2184                                        optFloat, 
     2185                                        "vsp_bsp_term_axis_aligned_max_cost_ratio=", 
     2186                                        "1.5"); 
    21872187 
    21882188        RegisterOption("VspBspTree.useCostHeuristics", 
    2189                 optBool, 
    2190                 "vsp_bsp_use_cost_heuristics=", 
    2191                 "false"); 
     2189                                        optBool, 
     2190                                        "vsp_bsp_use_cost_heuristics=", 
     2191                                        "false"); 
    21922192 
    21932193        RegisterOption("VspBspTree.Termination.maxViewCells", 
    2194                 optInt, 
    2195                 "vsp_bsp_term_max_view_cells=", 
    2196                 "10000"); 
     2194                                        optInt, 
     2195                                        "vsp_bsp_term_max_view_cells=", 
     2196                                        "10000"); 
    21972197 
    21982198        RegisterOption("VspBspTree.Termination.maxCostRatio", 
    2199                 optFloat, 
    2200                 "vsp_bsp_term_max_cost_ratio=", 
    2201                 "1.5"); 
     2199                                        optFloat, 
     2200                                        "vsp_bsp_term_max_cost_ratio=", 
     2201                                        "1.5"); 
    22022202 
    22032203        RegisterOption("VspBspTree.Termination.missTolerance", 
    2204                 optInt, 
    2205                 "vsp_bsp_term_miss_tolerance=", 
    2206                 "4"); 
     2204                                        optInt, 
     2205                                        "vsp_bsp_term_miss_tolerance=", 
     2206                                        "4"); 
    22072207 
    22082208        RegisterOption("VspBspTree.splitPlaneStrategy", 
     
    27852785                                        "99990.0"); 
    27862786         
     2787 
     2788        /////////////////////////////////////////////////////// 
     2789 
     2790         RegisterOption("TraversalTree.Termination.minCost", 
     2791                                 optInt, 
     2792                                 "kd_term_min_cost=", 
     2793                                 "1"); 
     2794   
     2795  RegisterOption("TraversalTree.Termination.maxNodes", 
     2796                                 optInt, 
     2797                                 "kd_term_max_nodes=", 
     2798                                 "200000"); 
     2799   
     2800  RegisterOption("TraversalTree.Termination.maxDepth", 
     2801                                 optInt, 
     2802                                 "kd_term_max_depth=", 
     2803                                 "20"); 
     2804 
     2805  RegisterOption("TraversalTree.Termination.maxCostRatio", 
     2806                                 optFloat, 
     2807                                 "kd_term_max_cost_ratio=", 
     2808                                 "1.5"); 
     2809 
     2810  RegisterOption("TraversalTree.Termination.ct_div_ci", 
     2811                                 optFloat, 
     2812                                 "kd_term_ct_div_ci=", 
     2813                                 "1.0"); 
     2814 
     2815  RegisterOption("TraversalTree.splitMethod", 
     2816                                 optString, 
     2817                                 "kd_split_method=", 
     2818                                 "spatialMedian"); 
     2819 
     2820  RegisterOption("TraversalTree.splitBorder", 
     2821                                 optFloat, 
     2822                                 "kd_split_border=", 
     2823                                 "0.1"); 
     2824 
     2825  RegisterOption("TraversalTree.sahUseFaces", 
     2826                                 optBool, 
     2827                                 "kd_sah_use_faces=", 
     2828                                 "true"); 
     2829 
    27872830        ///////////////////////////////////////////////////////////////// 
    27882831 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp

    r2072 r2124  
    77#include "Triangle3.h" 
    88#include "Polygon3.h" 
     9#include "TraversalTree.h" 
    910 
    1011 
     
    305306 
    306307 
    307  
    308 } 
     308bool Exporter::ExportTraversalTree(const TraversalTree &tree,  
     309                                                                          const bool exportGeometry) 
     310{ 
     311        stack<TraversalNode *> tStack; 
     312 
     313        tStack.push(tree.GetRoot()); 
     314 
     315        Mesh *mesh = new Mesh; 
     316 
     317        SetWireframe(); 
     318 
     319        while (!tStack.empty())  
     320        { 
     321                TraversalNode *node = tStack.top(); 
     322                tStack.pop(); 
     323                const AxisAlignedBox3 box = tree.GetBox(node); 
     324 
     325                // add 6 vertices of the box 
     326                const int index = (int)mesh->mVertices.size(); 
     327 
     328                SetForcedMaterial(RandomMaterial()); 
     329 
     330                for (int i=0; i < 8; i++)  
     331                { 
     332                        Vector3 v; 
     333                        box.GetVertex(i, v); 
     334                        mesh->mVertices.push_back(v); 
     335                } 
     336 
     337                mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) ); 
     338                mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) ); 
     339                mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) ); 
     340 
     341                mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) ); 
     342                mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 
     343                mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 
     344 
     345                if (!node->IsLeaf())  
     346                { 
     347                        TraversalInterior *interior = static_cast<TraversalInterior *>(node); 
     348 
     349                        tStack.push(interior->mFront); 
     350                        tStack.push(interior->mBack); 
     351                } 
     352                else if (exportGeometry) 
     353                { 
     354                        SetFilled(); 
     355                        SetForcedMaterial(RandomMaterial()); 
     356 
     357                        ExportViewCells(static_cast<TraversalLeaf *>(node)->mViewCells);         
     358                        SetWireframe(); 
     359                } 
     360        } 
     361 
     362        ExportMesh(mesh); 
     363        delete mesh; 
     364 
     365        return true; 
     366} 
     367 
     368 
     369} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h

    r2116 r2124  
    99#include "Material.h" 
    1010#include "Containers.h" 
    11 //#include "VssRay.h" 
    1211#include "AxisAlignedBox3.h" 
    1312 
     
    3231class MeshInstance; 
    3332class VssRay; 
    34 //class Material; 
     33class TraversalTree; 
     34 
    3535 
    3636struct VssRayContainer; 
     
    6464  virtual bool 
    6565  ExportKdTree(const KdTree &tree, const bool exportGeometry = false) = 0; 
     66 
     67  virtual bool 
     68  ExportTraversalTree(const TraversalTree &tree, const bool exportViewCells); 
    6669 
    6770  virtual bool 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r2117 r2124  
    383383        } 
    384384 
    385         // hack: should be different parameter name 
     385        // hack 
    386386        if (mUseMultiLevelConstruction) 
    387387        { 
    388388                cout << "starting optimizing multilevel ... " << endl; 
    389                 // try to optimize on the above hierarchy 
     389                // try to optimize the hierarchy from above 
    390390                OptimizeMultiLevel(sampleRays, objects, forcedViewSpace); 
    391391                 
     
    398398        } 
    399399 
    400         if (0) CreateTraversalTree(); 
     400        // create a traversal tree which is optimized for view cell casting  
     401        if (1)  
     402        { 
     403                CreateTraversalTree(); 
     404        } 
    401405} 
    402406 
     
    24882492 
    24892493        ViewCellContainer viewCells; 
    2490  
    2491         // add mesh instances of the scene graph to the root of the tree 
    2492         TraversalLeaf *root = (TraversalLeaf *)mTraversalTree->GetRoot(); 
    2493  
    2494         //mVspTree->CollectViewCells(root->mViewCells, false); 
    2495          
    2496         const long startTime = GetTime(); 
     2494        mVspTree->CollectViewCells(viewCells, false); 
     2495 
     2496        const long startTime = GetTime(); 
     2497         
    24972498        cout << "building traversal tree ... " << endl; 
    24982499 
    2499         mTraversalTree->Construct(); 
    2500  
    2501         cout << "finished kd tree construction in " << TimeDiff(startTime, GetTime()) * 1e-3  
     2500        mTraversalTree->Construct(viewCells); 
     2501 
     2502        cout << "finished traversal tree construction in " << TimeDiff(startTime, GetTime()) * 1e-3  
    25022503                 << " secs " << endl; 
     2504 
     2505        Debug << "*** TraversalTree Stats ***" << endl; 
     2506        Debug << mTraversalTree->GetStatistics() << endl; 
     2507 
     2508        if (1)  
     2509        { 
     2510                Exporter *exporter = Exporter::GetExporter("traversal.wrl"); 
     2511                exporter->ExportTraversalTree(*mTraversalTree, true); 
     2512                delete exporter; 
     2513        } 
    25032514} 
    25042515 
     
    25102521{ 
    25112522        if (!mTraversalTree) 
     2523        { 
    25122524                return mVspTree->CastLineSegment(origin,termination, viewcells, useMailboxing); 
     2525        } 
    25132526        else 
     2527        { 
    25142528                return mTraversalTree->CastLineSegment(origin,termination, viewcells, useMailboxing); 
    2515 } 
    2516  
    2517  
    2518 } 
     2529        } 
     2530} 
     2531 
     2532 
     2533} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r2116 r2124  
    188188class HierarchyManager 
    189189{ 
     190        friend class VspOspViewCellsManager; 
     191 
    190192public: 
     193         
    191194        /** Constructor with the view space partition tree and 
    192195                the object space hierarchy type as argument. 
    193196        */ 
    194197        HierarchyManager(const int objectSpaceHierarchyType); 
     198         
    195199        /** Hack: OspTree will copy the content from this kd tree. 
    196200                Only view space hierarchy will be constructed. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r2117 r2124  
    188188  
    189189        if (criteriaMet) 
    190                 cerr<<"\n OBJECTS="<<leaf->mObjects.size()<<endl; 
     190                cerr<<"\n OBJECTS="<<(int)leaf->mObjects.size()<<endl; 
    191191 
    192192        return criteriaMet; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp

    r2123 r2124  
    186186        for (int i=0; i < contributingRays; i++, index--) { 
    187187          if (index < 0) 
    188                 index = mRays.size()-1; 
     188                index = (int)mRays.size()-1; 
    189189          mRays[index].mImportance = importance; 
    190190        } 
     
    196196  // reset the start of the buffer 
    197197  mBufferStart = 0; 
    198   mLastIndex = mRays.size(); 
     198  mLastIndex = (int)mRays.size(); 
    199199  cout<<"Mutation candidates sorted in "<<TimeDiff(t1, GetTime())<<" ms."<<endl; 
    200200#endif 
     
    214214  cout<<"Importance = "<< 
    215215        GetEntry(0).mImportance<<" "<< 
    216         GetEntry(mRays.size()-1).mImportance<<endl; 
     216        GetEntry((int)mRays.size()-1).mImportance<<endl; 
    217217 
    218218  cout<<"Sampling factor = "<< 
    219219        GetEntry(0).GetSamplingFactor()<<" "<< 
    220         GetEntry(mRays.size()-1).GetSamplingFactor()<<endl; 
     220        GetEntry((int)mRays.size()-1).GetSamplingFactor()<<endl; 
    221221 
    222222  cerr<<"Mutation update done."<<endl; 
     
    564564  index = mLastIndex - 1; 
    565565  if (index < 0 || index >= mRays.size()-1) { 
    566         index = mRays.size() - 1; 
     566        index = (int)mRays.size() - 1; 
    567567  } else 
    568568        if ( 
     
    573573          //      cout<<mLastIndex<<endl; 
    574574          //      cout<<index<<endl; 
    575           index = mRays.size() - 1; 
     575          index = (int)mRays.size() - 1; 
    576576        } 
    577577#else 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.cpp

    r2105 r2124  
    4040  mz.SetColumns(sx, sy, sd); 
    4141   
    42   double det = md.Det3x3(); 
     42  const float det = md.Det3x3(); 
    4343 
    4444  if (abs(det)<TRASH) 
     
    4646 
    4747  result.SetValue(mx.Det3x3()/det, 
    48                   my.Det3x3()/det, 
    49                   mz.Det3x3()/det); 
     48                                  my.Det3x3()/det, 
     49                                  mz.Det3x3()/det); 
    5050   
    5151  return true; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r2122 r2124  
    747747                if (0) LoadObjects(buf, pvsObjects, mObjects); 
    748748 
     749                const bool finalizeViewCells = true; 
    749750                cout << "loading view cells from " << buf << endl; 
    750751 
     
    752753                                                                                                                        pvsObjects, 
    753754                                                                                                                        mObjects,  
    754                                                                                                                         true,  
     755                                                                                                                        finalizeViewCells,  
    755756                                                                                                                        NULL); 
    756757 
     
    13661367         
    13671368                if ((int)rays.size() > 100000 && i % 100000 == 0) 
    1368                         //cout << "here2 " << vssRays.size()<<endl; 
    13691369                        cout<<"\r"<<i<<"/"<<(int)rays.size()<<"\r"; 
    13701370        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorFactory.cpp

    r2119 r2124  
    1414Preprocessor *PreprocessorFactory::CreatePreprocessor(const string &preprocessorType) 
    1515{ 
    16         Debug << "here9191" << endl; 
    1716        if (preprocessorType == "vss") 
    18         {Debug << "here21112" << endl; 
     17        { 
    1918                return new VssPreprocessor(); 
    2019        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/TraversalTree.cpp

    r2094 r2124  
    77#include "ViewCell.h" 
    88#include "Beam.h" 
     9#include "Exporter.h" 
    910 
    1011 
     
    5960 
    6061 
    61 void TraversalInterior::ReplaceChildLink(TraversalNode *oldChild, TraversalNode *newChild)  
     62void TraversalInterior::ReplaceChildLink(TraversalNode *oldChild,  
     63                                                                                 TraversalNode *newChild)  
    6264{ 
    6365        if (mBack == oldChild) 
     
    7173TraversalNode(parent) 
    7274{ 
    73         mObjects.reserve(objects); 
     75        mViewCells.reserve(objects); 
    7476} 
    7577 
     
    8890TraversalTree::TraversalTree() 
    8991{  
    90         mRoot = new TraversalLeaf(NULL, 0); 
     92        TraversalLeaf *leaf = new TraversalLeaf(NULL, 0); 
     93        leaf->mDepth = 0; 
     94        mRoot = leaf; 
    9195 
    9296        Environment::GetSingleton()->GetIntValue("TraversalTree.Termination.maxNodes", mTermMaxNodes); 
     
    102106        Environment::GetSingleton()->GetStringValue("TraversalTree.splitMethod", splitType); 
    103107 
     108        splitCandidates = NULL; 
    104109        mSplitMethod = SPLIT_SPATIAL_MEDIAN; 
     110 
    105111        if (strcmp(splitType, "spatialMedian") == 0) 
    106112        { 
     
    121127                        else  
    122128                        { 
    123                                 cerr<<"Wrong kd split type "<<splitType<<endl; 
     129                                cerr << "Wrong kd split type " << splitType << endl; 
    124130                                exit(1); 
    125131                        } 
    126                          
    127                         splitCandidates = NULL; 
    128                 } 
    129         } 
     132                } 
     133        } 
     134        cout << "Traversal Tree Split method: " << mSplitMethod << endl; 
    130135} 
    131136 
     
    137142 
    138143 
    139 bool 
    140 TraversalTree::Construct() 
    141 { 
    142  
     144bool TraversalTree::Construct(const ViewCellContainer &viewCells) 
     145{ 
    143146        if (!splitCandidates) 
    144147        { 
     
    149152        TraversalLeaf *leaf = static_cast<TraversalLeaf *>(mRoot); 
    150153 
     154        leaf->mViewCells = viewCells; 
    151155        mStat.nodes = 1; 
    152  
    153156        mBox.Initialize(); 
    154157 
    155         ObjectContainer::const_iterator mi; 
    156         for ( mi = leaf->mObjects.begin(); mi != leaf->mObjects.end(); ++ mi)  
     158        ViewCellContainer::const_iterator mi; 
     159 
     160        for ( mi = leaf->mViewCells.begin(); mi != leaf->mViewCells.end(); ++ mi)  
    157161        { 
    158162                mBox.Include((*mi)->GetBox()); 
     
    163167         
    164168        // remove the allocated array 
    165         CLEAR_CONTAINER(*splitCandidates); 
    166         delete splitCandidates; 
    167  
     169        if (splitCandidates) 
     170        { 
     171                CLEAR_CONTAINER(*splitCandidates); 
     172                delete splitCandidates; 
     173        } 
     174         
    168175        return true; 
    169176} 
     
    182189        while (!tStack.empty())  
    183190        { 
    184                 //      cout<<mStat.Nodes() << " " << mTermMaxNodes << endl; 
    185191                if (mStat.Nodes() > mTermMaxNodes)  
    186192                { 
     
    226232bool TraversalTree::TerminationCriteriaMet(const TraversalLeaf *leaf) 
    227233{ 
    228         const bool criteriaMet = 
    229                 ((int)leaf->mObjects.size() <= mTermMinCost) || 
    230                 (leaf->mDepth >= mTermMaxDepth); 
     234        const bool criteriaMet = ( 
     235                ((int)leaf->mViewCells.size() <= mTermMinCost) || 
     236                 (leaf->mDepth >= mTermMaxDepth)  
     237                 || (GetBox(leaf).SurfaceArea() < 0.00001f) 
     238                 ); 
    231239 
    232240        if (criteriaMet) 
    233                 cerr<< "\n OBJECTS=" << (int)leaf->mObjects.size() << endl; 
     241        { 
     242                cerr << "\nOBJECTS=" << (int)leaf->mViewCells.size() << endl; 
     243                cerr << "\nDEPTH=" << (int)leaf->mDepth << endl; 
     244        } 
    234245 
    235246        return criteriaMet; 
     
    248259                { 
    249260                        axis = box.Size().DrivingAxis(); 
    250                         position = (box.Min()[axis] + box.Max()[axis])*0.5f; 
     261                        position = (box.Min()[axis] + box.Max()[axis]) * 0.5f; 
    251262                        break; 
    252263                } 
     
    254265                { 
    255266                        int objectsBack, objectsFront; 
    256                         float costRatio; 
    257                         bool mOnlyDrivingAxis = true; 
    258  
    259                         if (mOnlyDrivingAxis)  
    260                         { 
    261                                 axis = box.Size().DrivingAxis(); 
    262                                 costRatio = BestCostRatio(leaf, 
    263                                         box, 
    264                                         axis, 
    265                                         position, 
    266                                         objectsBack, 
    267                                         objectsFront); 
    268                         }  
    269                         else  
    270                         { 
    271                                 costRatio = MAX_FLOAT; 
    272  
    273                                 for (int i=0; i < 3; i++)  
     267                        float costRatio = 99999;//MAX_FLOAT; 
     268 
     269                        for (int i=0; i < 3; ++ i)  
     270                        { 
     271                                float p; 
     272                                float r = BestCostRatio(leaf, 
     273                                                                                box, 
     274                                                                                i, 
     275                                                                                p, 
     276                                                                                objectsBack, 
     277                                                                                objectsFront); 
     278         
     279                                if (r < costRatio)  
    274280                                { 
    275                                         float p; 
    276                                         float r = BestCostRatio(leaf, 
    277                                                 box, 
    278                                                 i, 
    279                                                 p, 
    280                                                 objectsBack, 
    281                                                 objectsFront); 
    282          
    283                                         if (r < costRatio)  
    284                                         { 
    285                                                 costRatio = r; 
    286                                                 axis = i; 
    287                                                 position = p; 
    288                                         } 
     281                                        costRatio = r; 
     282                                        axis = i; 
     283                                        position = p; 
    289284                                } 
    290285                        } 
     
    292287                        if (costRatio > mMaxCostRatio)  
    293288                        { 
    294                                 //cout<<"Too big cost ratio "<<costRatio<<endl; 
     289                                cout << "Too big cost ratio " << costRatio << endl; 
    295290                                axis = -1; 
    296291                        } 
     
    318313 
    319314        if (axis == -1) { 
     315                cout << "terminate on cost ratio" << endl; 
    320316                return leaf; 
    321317        } 
     
    341337        frontBBox.SetMin(axis, position); 
    342338 
    343         ObjectContainer::const_iterator mi; 
    344  
    345         for ( mi = leaf->mObjects.begin(); 
    346                 mi != leaf->mObjects.end(); 
    347                 mi++) 
     339        ViewCellContainer::const_iterator mi, mi_end = leaf->mViewCells.end(); 
     340 
     341        for (mi = leaf->mViewCells.begin(); mi != mi_end; ++ mi) 
    348342        { 
    349343                // determine the side of this ray with respect to the plane 
    350344                AxisAlignedBox3 box = (*mi)->GetBox(); 
    351                 if (box.Max(axis) > position )  
    352                         objectsFront++; 
    353  
    354                 if (box.Min(axis) < position ) 
     345                if (box.Max(axis) > position)  
     346                        ++ objectsFront; 
     347 
     348                if (box.Min(axis) < position) 
    355349                        ++ objectsBack; 
    356350        } 
    357  
    358351 
    359352        TraversalLeaf *back = new TraversalLeaf(node, objectsBack); 
    360353        TraversalLeaf *front = new TraversalLeaf(node, objectsFront); 
    361354 
     355        back->mDepth = front->mDepth = leaf->mDepth + 1; 
    362356 
    363357        // replace a link from node's parent 
     
    370364        node->SetupChildLinks(back, front); 
    371365 
    372         for (mi = leaf->mObjects.begin(); mi != leaf->mObjects.end(); ++ mi)  
     366        for (mi = leaf->mViewCells.begin(); mi != mi_end; ++ mi)  
    373367        { 
    374368                // determine the side of this ray with respect to the plane 
     
    377371                if (box.Max(axis) >= position ) 
    378372                { 
    379                         front->mObjects.push_back(*mi); 
     373                        front->mViewCells.push_back(*mi); 
    380374                } 
    381375 
    382376                if (box.Min(axis) < position ) 
    383377                { 
    384                         back->mObjects.push_back(*mi); 
    385                 } 
    386  
    387                 mStat.objectRefs -= (int)leaf->mObjects.size(); 
     378                        back->mViewCells.push_back(*mi); 
     379                } 
     380 
     381                mStat.objectRefs -= (int)leaf->mViewCells.size(); 
    388382                mStat.objectRefs += objectsBack + objectsFront; 
    389383        } 
     
    404398 
    405399        app << "#N_SPLITS ( Number of splits in axes x y z dx dy dz)\n"; 
    406         for (int i=0; i<7; i++) 
    407                 app << splits[i] <<" "; 
    408         app <<endl; 
    409  
    410         app << "#N_RAYREFS ( Number of rayRefs )\n" << 
    411                 rayRefs << "\n"; 
    412  
    413         app << "#N_RAYRAYREFS  ( Number of rayRefs / ray )\n" << 
    414                 rayRefs/(double)rays << "\n"; 
    415  
    416         app << "#N_LEAFRAYREFS  ( Number of rayRefs / leaf )\n" << 
    417                 rayRefs/(double)Leaves() << "\n"; 
     400 
     401        for (int i = 0; i < 7; ++ i) 
     402                app << splits[i] << " "; 
     403        app << endl; 
    418404 
    419405        app << "#N_MAXOBJECTREFS  ( Max number of object refs / leaf )\n" << 
    420406                maxObjectRefs << "\n"; 
    421407 
    422         app << "#N_NONEMPTYRAYREFS  ( Number of rayRefs in nonEmpty leaves / non empty leaf )\n" << 
    423                 rayRefsNonZeroQuery/(double)(Leaves() - zeroQueryNodes) << "\n"; 
     408        app << "#N_AVGOBJECTREFS  ( Avg number of object refs / leaf )\n" << 
     409                totalObjectRefs / (double)Leaves() << "\n"; 
    424410 
    425411        app << "#N_LEAFDOMAINREFS  ( Number of query domain Refs / leaf )\n" << 
    426                 objectRefs/(double)Leaves() << "\n"; 
     412                objectRefs / (double)Leaves() << "\n"; 
     413 
     414        app << "#N_PEMPTYLEAVES  ( Percentage of leaves with zero query domains )\n"<< 
     415                zeroQueryNodes * 100 / (double)Leaves() << endl; 
     416 
     417        app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n"<< 
     418                maxDepthNodes * 100 / (double)Leaves() << endl; 
     419 
     420        app << "#N_PMINCOSTLEAVES  ( Percentage of leaves with minCost )\n"<< 
     421                minCostNodes * 100 / (double)Leaves() << endl; 
    427422 
    428423        //  app << setprecision(4); 
    429  
    430         app << "#N_PEMPTYLEAVES  ( Percentage of leaves with zero query domains )\n"<< 
    431                 zeroQueryNodes*100/(double)Leaves()<<endl; 
    432  
    433         app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n"<< 
    434                 maxDepthNodes*100/(double)Leaves()<<endl; 
    435  
    436         app << "#N_PMINCOSTLEAVES  ( Percentage of leaves with minCost )\n"<< 
    437                 minCostNodes*100/(double)Leaves()<<endl; 
    438  
    439         app << "#N_ADDED_RAYREFS  (Number of dynamically added ray references )\n"<< 
    440                 addedRayRefs<<endl; 
    441  
    442         app << "#N_REMOVED_RAYREFS  (Number of dynamically removed ray references )\n"<< 
    443                 removedRayRefs<<endl; 
    444  
    445         //  app << setprecision(4); 
    446  
    447424        //  app << "#N_CTIME  ( Construction time [s] )\n" 
    448425        //      << Time() << " \n"; 
    449426 
    450         app << "===== END OF TraversalTree statistics ==========\n"; 
    451  
     427        app << "======= END OF TraversalTree statistics ========\n"; 
    452428} 
    453429 
     
    455431void TraversalTree::EvaluateLeafStats(const TraversalData &data) 
    456432{ 
    457  
    458   // the node became a leaf -> evaluate stats for leafs 
    459   TraversalLeaf *leaf = (TraversalLeaf *)data.mNode; 
    460  
    461   if (data.mDepth > mTermMaxDepth) 
    462     mStat.maxDepthNodes++; 
    463    
    464   if ( (int)(leaf->mObjects.size()) < mTermMinCost) 
    465     mStat.minCostNodes++; 
    466    
    467    
    468   if ( (int)(leaf->mObjects.size()) > mStat.maxObjectRefs) 
    469     mStat.maxObjectRefs = (int)leaf->mObjects.size(); 
    470    
    471 } 
    472  
     433        // the node became a leaf -> evaluate stats for leafs 
     434        TraversalLeaf *leaf = (TraversalLeaf *)data.mNode; 
     435 
     436        if (data.mDepth > mTermMaxDepth) 
     437                ++ mStat.maxDepthNodes; 
     438 
     439        if ((int)(leaf->mViewCells.size()) < mTermMinCost) 
     440                ++ mStat.minCostNodes; 
     441 
     442        mStat.totalObjectRefs += (int)leaf->mViewCells.size(); 
     443 
     444        if ((int)(leaf->mViewCells.size()) > mStat.maxObjectRefs) 
     445                mStat.maxObjectRefs = (int)leaf->mViewCells.size(); 
     446} 
    473447 
    474448 
     
    480454        //splitCandidates->clear(); 
    481455 
    482     int requestedSize = 2*(int)node->mObjects.size(); 
     456    int requestedSize = 2 * (int)node->mViewCells.size(); 
    483457         
    484458        // creates a sorted split candidates array 
    485459        if (splitCandidates->capacity() > 500000 && 
    486                 requestedSize < (int)(splitCandidates->capacity()/10) )  
     460                requestedSize < (int)(splitCandidates->capacity() / 10) )  
    487461        {                
    488462                delete splitCandidates; 
     
    492466        splitCandidates->reserve(requestedSize); 
    493467 
     468         
    494469        // insert all queries  
    495         for(ObjectContainer::const_iterator mi = node->mObjects.begin(); 
    496                 mi != node->mObjects.end(); 
     470        for(ViewCellContainer::const_iterator mi = node->mViewCells.begin(); 
     471                mi != node->mViewCells.end(); 
     472                mi++)  
     473        { 
     474                AxisAlignedBox3 box = (*mi)->GetBox(); 
     475 
     476                splitCandidates->push_back(new SortableEntry(SortableEntry::BOX_MAX, 
     477                        box.Max(axis), 
     478                        *mi) 
     479                        ); 
     480        } 
     481 
     482        // insert all queries  
     483        for(ViewCellContainer::const_iterator mi = node->mViewCells.begin(); 
     484                mi != node->mViewCells.end(); 
    497485                mi++)  
    498486        { 
     
    503491                        *mi) 
    504492                        ); 
    505  
    506                 splitCandidates->push_back(new SortableEntry(SortableEntry::BOX_MAX, 
     493                /*splitCandidates->push_back(new SortableEntry(SortableEntry::BOX_MAX, 
    507494                        box.Max(axis), 
    508495                        *mi) 
    509                         ); 
     496                        );*/ 
    510497        } 
    511498 
     
    550537        // C = ct_div_ci  + (ol + or)/queries 
    551538 
    552         float totalIntersections = 0.0f; 
    553539        vector<SortableEntry *>::const_iterator ci; 
    554540 
    555         for(ci = splitCandidates->begin(); ci < splitCandidates->end(); ++ ci)  
    556         if ((*ci)->type == SortableEntry::BOX_MIN)  
    557         { 
    558                 totalIntersections += (*ci)->intersectable->IntersectionComplexity(); 
    559         } 
    560  
    561         float intersectionsLeft = 0; 
    562         float intersectionsRight = totalIntersections; 
    563  
    564         int objectsLeft = 0, objectsRight = (int)node->mObjects.size(); 
     541        int objectsLeft = 0, objectsRight = (int)node->mViewCells.size(); 
     542 
     543        int dummy1 = objectsLeft, dummy2 = objectsRight; 
    565544 
    566545        float minBox = box.Min(axis); 
     
    578557                { 
    579558                case SortableEntry::BOX_MIN: 
    580                         objectsLeft++; 
    581                         intersectionsLeft += (*ci)->intersectable->IntersectionComplexity(); 
     559                        ++ objectsLeft; 
    582560                        break; 
    583561                case SortableEntry::BOX_MAX: 
    584                         objectsRight--; 
    585                         intersectionsRight -= (*ci)->intersectable->IntersectionComplexity(); 
     562                        -- objectsRight; 
    586563                        break; 
    587564                } 
    588565 
    589                 if ((*ci)->value > minBand && (*ci)->value < maxBand)  
     566                if ((*ci)->value >= minBand && (*ci)->value <= maxBand)  
    590567                { 
    591568                        AxisAlignedBox3 lbox = box; 
    592569                        AxisAlignedBox3 rbox = box; 
     570 
    593571                        lbox.SetMax(axis, (*ci)->value); 
    594572                        rbox.SetMin(axis, (*ci)->value); 
    595573 
    596                         float sum; 
    597                  
    598                         if (mSahUseFaces) 
    599                                 sum = intersectionsLeft*lbox.SurfaceArea() + intersectionsRight*rbox.SurfaceArea(); 
    600                         else 
    601                                 sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 
    602  
    603                         //      cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 
    604                         //      cout<<"cost= "<<sum<<endl; 
     574                        const float sum = objectsLeft * lbox.SurfaceArea() + objectsRight * rbox.SurfaceArea(); 
     575 
     576                        // cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 
     577                        // cout<<"cost= "<<sum<<endl; 
    605578 
    606579#if DEBUG_COST 
    607580                        if (nodeId < 100)  
    608581                        { 
    609                                 float oldCost = mSahUseFaces ? totalIntersections : node->mObjects.size(); 
     582                                float oldCost = (float)node->mViewCells.size(); 
    610583                                float newCost = mCt_div_ci + sum/boxArea; 
    611                                 float ratio = newCost/oldCost; 
     584                                float ratio = newCost / oldCost; 
    612585                                costStream<<(*ci)->value<<" "<<ratio<<endl; 
    613586                        } 
     
    625598        } 
    626599 
    627         const float oldCost = mSahUseFaces ? totalIntersections : node->mObjects.size(); 
    628         const float newCost = mCt_div_ci + minSum/boxArea; 
    629         const float ratio = newCost/oldCost; 
    630  
     600        const float oldCost = (float)node->mViewCells.size(); 
     601        const float newCost = mCt_div_ci + minSum / boxArea; 
     602        const float ratio = newCost / oldCost; 
     603 
     604        //if (boxArea == 0) 
     605        //      cout << "error: " << boxArea << endl; 
     606        if (ratio > 2) 
     607        { 
     608                cout << "costratio: " << ratio << " oldcost: " << oldCost << " box area: " << boxArea << " new: " << newCost << endl; 
     609                cout << "obj left: " <<objectsBack<< " obj right: " << objectsFront << endl; 
     610                cout << "dummy1: " << dummy1 << " dummy2: " << dummy2 << endl; 
     611        } 
    631612#if 0 
    632613        cout<<"===================="<<endl; 
     
    634615                        <<"\t o=("<<objectsBack<<","<<objectsFront<<")"<<endl; 
    635616#endif 
     617 
    636618        return ratio; 
     619} 
     620 
     621 
     622int TraversalTree::FindViewCellIntersections(const Vector3 &lStart,  
     623                                                                                         const Vector3 &lEnd, 
     624                                                                                         const ViewCellContainer &viewCells, 
     625                                                                                         ViewCellContainer &hitViewCells, 
     626                                                                                         const bool useMailboxing) 
     627{ 
     628        int hits = 0; 
     629        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     630 
     631        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     632        { 
     633                ViewCell *viewCell = *vit; 
     634                // don't have to mail if each view cell belongs to exactly one leaf 
     635                if (!useMailboxing || !viewCell->Mailed()) 
     636                { 
     637                        if (useMailboxing) 
     638                viewCell->Mail(); 
     639 
     640                        // hack: assume that we use vsp tree,  
     641                        //P so we can just test intersection with bounding boxes 
     642                        if (viewCell->GetBox().Intersects(lStart, lEnd)); 
     643                        { 
     644                                hitViewCells.push_back(viewCell); 
     645                                ++ hits; 
     646                        } 
     647                } 
     648        } 
     649 
     650        return hits; 
    637651} 
    638652 
     
    640654int TraversalTree::CastLineSegment(const Vector3 &origin, 
    641655                                                                   const Vector3 &termination, 
    642                                                                    ViewCellContainer &viewcells, 
     656                                                                   ViewCellContainer &viewCells, 
    643657                                                                   const bool useMailboxing) 
    644658{ 
     
    709723                        // compute intersection with all objects in this leaf 
    710724                        TraversalLeaf *leaf = static_cast<TraversalLeaf *>(node); 
    711                         ViewCell *viewCell = NULL; 
    712  
    713 #if TODO 
    714                         if (0) 
    715                                 viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell()); 
    716                         else 
    717                                 viewCell = leaf->mViewCell; 
    718 #endif 
    719                         // don't have to mail if each view cell belongs to exactly one leaf 
    720                         if (!useMailboxing || !viewCell->Mailed()) 
    721                         { 
    722                                 if (useMailboxing) 
    723                                         viewCell->Mail(); 
    724  
    725                                 viewcells.push_back(viewCell); 
    726                                 ++ hits; 
    727                         } 
    728  
     725 
     726                        hits += FindViewCellIntersections(origin,  
     727                                                                                          termination,  
     728                                                                                          leaf->mViewCells, 
     729                                                                                          viewCells, 
     730                                                                                          useMailboxing); 
     731                         
    729732                        // get the next node from the stack 
    730733                        if (tStack.empty()) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/TraversalTree.h

    r2116 r2124  
    88#include "AxisAlignedBox3.h" 
    99#include "Ray.h" 
    10 //#include "ObjectPvs.h" 
    11 //#include "Viewcell.h" 
    12 //#include "VssRay.h" 
    13 //#include "IntersectableWrapper.h" 
    1410 
    1511 
     
    2521class TraversalTree; 
    2622   
    27 //  TraversalTree *SceneTraversalTree; 
    2823 
    2924// -------------------------------------------------------------- 
     
    5550  // max number of rays per node 
    5651  int maxObjectRefs; 
     52  // max number of rays per node 
     53  int totalObjectRefs; 
    5754  // number of dynamically added ray refs 
    5855  int addedRayRefs; 
     
    8380          minCostNodes = 0; 
    8481          maxObjectRefs = 0; 
     82          totalObjectRefs = 0; 
    8583          addedRayRefs = removedRayRefs = 0; 
    8684  } 
     
    121119        } 
    122120 
    123         /** Parent of the node - the parent is a little overhead for maintanance of the tree, 
    124                 but allows various optimizations of tree traversal algorithms  
     121        /** Parent of the node - the parent is a little overhead for  
     122                maintanance of the tree, but allows various optimizations  
     123                of tree traversal algorithms  
    125124        */ 
    126125        TraversalInterior *mParent; 
     
    217216 
    218217        // pointers to view cells contained in this node 
    219         ObjectContainer mObjects; 
     218        ViewCellContainer mViewCells; 
    220219 
    221220        short mDepth; 
     
    237236                float mPriority; 
    238237 
    239                 TraversalData() {} 
     238                TraversalData(): mNode(NULL), mPriority(0), mDepth(0) {} 
    240239 
    241240                TraversalData(TraversalNode *n, const float p): 
    242                 mNode(n), mPriority(p) 
     241                mNode(n), mPriority(p), mDepth(0) 
    243242                {} 
    244243 
    245244                TraversalData(TraversalNode *n, 
    246                         const AxisAlignedBox3 &b, 
    247                         const int d): 
    248                 mNode(n), mBox(b), mDepth(d) {} 
     245                                          const AxisAlignedBox3 &b, 
     246                                          const int d): 
     247                mNode(n), mBox(b), mDepth(d)  
     248                {} 
    249249 
    250250 
     
    255255                         
    256256                        return  
    257                                 leafa->mObjects.size() * mBox.SurfaceArea() 
     257                                leafa->mViewCells.size() * mBox.SurfaceArea() 
    258258                                < 
    259                                 leafb->mObjects.size() * b.mBox.SurfaceArea(); 
     259                                leafb->mViewCells.size() * b.mBox.SurfaceArea(); 
    260260                } 
    261261 
    262262 
    263                         // comparator for the  
    264                         struct less_priority: public  
     263                // comparator for the  
     264                struct less_priority: public  
    265265                                binary_function<const TraversalData, const TraversalData, bool>  
     266                { 
     267                        bool operator()(const TraversalData a, const TraversalData b)  
    266268                        { 
    267                 bool operator()(const TraversalData a, const TraversalData b)  
    268                                 { 
    269                                         return a.mPriority < b.mPriority; 
    270                                 } 
    271             }; 
     269                                return a.mPriority < b.mPriority; 
     270                        } 
     271                }; 
    272272        }; 
    273273 
     
    292292                                                const bool useMailboxing); 
    293293 
    294         virtual bool Construct(); 
     294        virtual bool Construct(const ViewCellContainer &viewCells); 
    295295 
    296296        /** Check whether subdivision criteria are met for the given subtree. 
    297297                If not subdivide the leafs of the subtree. The criteria are specified in 
    298                         the environment as well as the subdivision method. By default surface area 
     298                the environment as well as the subdivision method. By default surface area 
    299299                heuristics is used. 
    300300 
     
    372372                {} 
    373373 
    374                 bool operator<(const SortableEntry &b) const  
     374                /*bool operator<(const SortableEntry &b) const  
    375375                { 
     376                        // view cells usually adjacent  
     377                        if (EpsilonEqual(value, b.value, 0.001)) 
     378                                return (type == BOX_MAX); 
     379                         
    376380                        return value < b.value; 
    377                 } 
     381                }*/ 
    378382        }; 
    379383 
    380384        inline static bool iltS(SortableEntry *a, SortableEntry *b) 
    381385        { 
     386                // view cells usually adjacent  
     387                //if (EpsilonEqual(a->value, b->value)) 
     388                //      return false; 
     389                //      return (a->type == SortableEntry::BOX_MAX); 
     390                         
    382391                return a->value < b->value; 
    383392        } 
     
    409418                                        float &position); 
    410419 
     420        int FindViewCellIntersections(const Vector3 &lStart,  
     421                                                                  const Vector3 &lEnd, 
     422                                                                  const ViewCellContainer &viewCells, 
     423                                                                  ViewCellContainer &hitViewCells, 
     424                                                                  const bool useMailboxing); 
    411425 
    412426        //////////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r2117 r2124  
    261261                                                        float &contribution) 
    262262{  
    263         const bool result = mPvs.AddSample(sample, pdf);//, contribution); 
     263        const bool result = mPvs.AddSample(sample, pdf); 
    264264        // have to recompute pvs size 
    265265        mPvsSizeValid = false; 
     
    23762376                Intersectable *obj = it.Next(); 
    23772377 
    2378                 // hack: just output full pvs 
     2378                // hack: just output all the "elementary" objects 
    23792379                if (0 && (obj->Type() == Intersectable::BVH_INTERSECTABLE)) 
    23802380                { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r2117 r2124  
    203203        */ 
    204204        void SetMesh(Mesh *mesh); 
    205  
    206205        /** Sets this view cell to be a valid view cell according to some criteria. 
    207206        */ 
     
    291290        void SetFilteredPvsSize(const int s) { 
    292291                mFilteredPvsSize = s; 
    293   } 
     292        } 
     293 
     294        //virtual int ViewCellType; 
    294295 
    295296protected: 
     
    321322        bool mPvsSizeValid; 
    322323 
    323  
    324324        /// Filter cost of the pvs 
    325325        int mFilteredPvsSize; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2123 r2124  
    10511051                                                                                                   bconverter); 
    10521052 
    1053         //Debug << " view cells parsed in " 
    1054         //        << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
    1055          
    1056  
    10571053        if (!success) 
    10581054        { 
     
    10631059        } 
    10641060         
    1065         //cout << "viewcells parsed " <<endl; 
    1066  
    10671061        if (0) 
    10681062        { 
     
    10901084        if (finalizeViewCells) 
    10911085        { 
    1092                 // create the meshes and compute volumes 
     1086                // create the meshes and compute view cell volumes 
    10931087                const bool createMeshes = true; 
    1094                 //const bool createMeshes = false; 
    1095  
    10961088                vm->FinalizeViewCells(createMeshes); 
    10971089        } 
     
    70257017#endif 
    70267018 
    7027  
    7028  
    7029 } 
     7019void VspOspViewCellsManager::FinalizeViewCells(const bool createMesh) 
     7020{        
     7021        ViewCellsManager::FinalizeViewCells(createMesh); 
     7022 
     7023        if (1) 
     7024        {       // create a traversal tree for optimal view cell casting 
     7025                mHierarchyManager->CreateTraversalTree(); 
     7026        } 
     7027} 
     7028 
     7029 
     7030} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r2123 r2124  
    12881288        float UpdateObjectCosts(); 
    12891289 
     1290        virtual void FinalizeViewCells(const bool createMesh); 
     1291 
    12901292protected: 
    12911293 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.h

    r1486 r2124  
    3939  ~VrmlExporter(); 
    4040 
    41  
    42 //    bool 
    43 //    ExportRays(const vector<Ray> &rays, 
    44 //           const float length=1000, 
    45 //           const RgbColor &color = RgbColor(1,1,1)); 
    46  
    47  
    4841  bool 
    4942  ExportKdTree(const KdTree &tree, const bool exportGeometry = false); 
    50  
    51   //bool ExportOspTree(const OspTree &tree); 
    5243 
    5344  bool 
     
    141132  void ExportViewpoint(const Vector3 &point, const Vector3 &direction); 
    142133 
     134  //virtual bool ExportTraversalTree(const KdTree &tree, const bool exportViewCells); 
    143135}; 
    144136 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r2072 r2124  
    13411341        } 
    13421342 
    1343         sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 
     1343        stable_sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 
    13441344} 
    13451345 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r2123 r2124  
    10971097        } 
    10981098 
    1099         //stable_sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 
    1100         sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 
     1099        stable_sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 
     1100        //sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end()); 
    11011101} 
    11021102 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r2073 r2124  
    827827                         
    828828                @param tData data object holding, e.g., a pointer to the leaf 
    829                 @param frontData returns the data (e.g.,  pointer to the leaf) in front of the split plane 
    830                 @param backData returns the data (e.g.,  pointer to the leaf) in the back of the split plane 
     829                @param frontData returns the data (e.g., pointer to the leaf) in front of the split plane 
     830                @param backData returns the data (e.g., pointer to the leaf) in the back of the split plane 
    831831                 
    832832                @param rays the polygons to be filtered 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp

    r2017 r2124  
    12111211 
    12121212 
    1213 } 
    1214  
     1213 
     1214 
     1215 
     1216} 
     1217 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h

    r1404 r2124  
    2929class X3dExporter : public Exporter 
    3030{ 
    31   std::ofstream stream; 
     31        std::ofstream stream; 
    3232 
    3333public: 
    3434 
    35   X3dExporter(const string filename); 
     35        X3dExporter(const string filename); 
    3636 
    37   ~X3dExporter(); 
     37        ~X3dExporter(); 
    3838 
     39        bool 
     40                ExportKdTree(const KdTree &tree, const bool exportGeometry = false); 
    3941 
    40 //    bool 
    41 //    ExportRays(const vector<Ray> &rays, 
    42 //           const float length=1000, 
    43 //           const RgbColor &color = RgbColor(1,1,1)); 
     42        bool 
     43                ExportVssTree(const VssTree &tree); 
    4444 
     45        bool 
     46                ExportVssTree2(const VssTree &tree, 
     47                const Vector3 direction); 
    4548 
    46   bool 
    47   ExportKdTree(const KdTree &tree, const bool exportGeometry = false); 
     49        virtual bool 
     50                ExportRssTree2(const RssTree &tree, 
     51                const Vector3 direction); 
    4852 
    49   bool 
    50   ExportVssTree(const VssTree &tree); 
     53        bool ExportBspTree(const BspTree &tree); 
    5154 
    52   bool 
    53   ExportVssTree2(const VssTree &tree, 
    54                                  const Vector3 direction 
    55                                  ); 
     55        bool 
     56                ExportScene(SceneGraphNode *root) 
     57        { 
     58                ExportSceneNode(root); 
     59                return true; 
     60        } 
    5661 
    57   virtual bool 
    58   ExportRssTree2(const RssTree &tree, 
    59                                  const Vector3 direction 
    60                                  ); 
     62        virtual void 
     63                ExportPolygon(Polygon3 *poly); 
    6164 
    62   // bool ExportOspTree(const OspTree &tree); 
     65        virtual void 
     66                ExportPolygons(const PolygonContainer &polys); 
    6367 
    64   bool ExportBspTree(const BspTree &tree); 
     68        virtual bool 
     69                ExportBox(const AxisAlignedBox3 &box); 
    6570 
    66   bool 
    67   ExportScene(SceneGraphNode *root) 
    68   { 
    69     ExportSceneNode(root); 
    70     return true; 
    71   } 
     71        virtual void 
     72                ExportMesh(Mesh *mesh); 
    7273 
    73   virtual void 
    74   ExportPolygon(Polygon3 *poly); 
     74        virtual void 
     75                ExportViewCell(ViewCell *viewCell); 
    7576 
    76   virtual void 
    77   ExportPolygons(const PolygonContainer &polys); 
     77        bool 
     78                ExportRays(const RayContainer &rays, 
     79                const float length=1000, 
     80                const RgbColor &color = RgbColor(1,1,1)); 
    7881 
    79   virtual bool 
    80   ExportBox(const AxisAlignedBox3 &box); 
     82        bool 
     83                ExportRays(const VssRayContainer &rays, 
     84                const RgbColor &color = RgbColor(1,1,1)); 
    8185 
    82   virtual void 
    83   ExportMesh(Mesh *mesh); 
     86        virtual void 
     87                ExportBspSplitPlanes(const BspTree &tree); 
    8488 
    85   virtual void 
    86   ExportViewCell(ViewCell *viewCell); 
     89        virtual void 
     90                ExportBspSplits(const BspTree &tree, const bool exportDepth); 
    8791 
    88   bool 
    89   ExportRays(const RayContainer &rays, 
    90                          const float length=1000, 
    91                          const RgbColor &color = RgbColor(1,1,1)); 
     92        virtual void 
     93                ExportLeavesGeometry(const BspTree &tree, const vector<BspLeaf *> &leaves); 
    9294 
    93   bool 
    94   ExportRays(const VssRayContainer &rays, 
    95                          const RgbColor &color = RgbColor(1,1,1)); 
     95        virtual void ExportBspLeaves(const BspTree &tree, const int maxPvs = 0); 
    9696 
    97   virtual void 
    98   ExportBspSplitPlanes(const BspTree &tree); 
     97        virtual void ExportBspSplits(const VspBspTree &tree, const bool exportDepth); 
    9998 
    100   virtual void 
    101   ExportBspSplits(const BspTree &tree, const bool exportDepth); 
     99        virtual void ExportBeam(const Beam &beam, const AxisAlignedBox3 &box); 
    102100 
    103   virtual void 
    104   ExportLeavesGeometry(const BspTree &tree, const vector<BspLeaf *> &leaves); 
     101        bool ExportRaySets(const vector<VssRayContainer> &rays, 
     102                                           const RgbColor &color); 
    105103 
    106   virtual void 
    107   ExportBspLeaves(const BspTree &tree, const int maxPvs = 0); 
    108  
    109   virtual void 
    110   ExportBspSplits(const VspBspTree &tree, const bool exportDepth); 
    111  
    112   virtual void ExportBeam(const Beam &beam, const AxisAlignedBox3 &box); 
    113  
    114   bool 
    115   ExportRaySets(const vector<VssRayContainer> &rays, 
    116                                 const RgbColor &color); 
    117104 
    118105protected: 
    119106 
    120   virtual void 
    121   ExportSceneNode(SceneGraphNode *node); 
     107        virtual void ExportSceneNode(SceneGraphNode *node); 
    122108 
    123   bool 
    124   ExportKdTreeRayDensity(const KdTree &tree); 
     109        bool ExportKdTreeRayDensity(const KdTree &tree); 
    125110 
    126   bool 
    127   ExportBspTreeRayDensity(const BspTree &tree); 
     111        bool ExportBspTreeRayDensity(const BspTree &tree); 
    128112 
    129   void ExportBspNodeSplits(BspNode *root, 
    130                                                   const AxisAlignedBox3 &box, 
    131                                                   const bool exportDepth, 
    132                                                   const bool epsilon); 
     113        void ExportBspNodeSplits(BspNode *root, 
     114                                                        const AxisAlignedBox3 &box, 
     115                                                        const bool exportDepth, 
     116                                                        const bool epsilon); 
    133117 
    134  
    135   void ExportViewpoint(const Vector3 &point, const Vector3 &direction); 
    136  
     118        void ExportViewpoint(const Vector3 &point, const Vector3 &direction); 
    137119}; 
    138120 
Note: See TracChangeset for help on using the changeset viewer.