Changeset 426 for trunk


Ignore:
Timestamp:
11/22/05 17:43:29 (19 years ago)
Author:
mattausch
Message:

fixed ray bug in vspkdtree
added visualizations

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r425 r426  
    6262 
    6363Sampling { 
    64         totalSamples    300000 
     64        totalSamples    1000000 
    6565        samplesPerPass  3 
    6666} 
     
    152152        Termination { 
    153153                # parameters used for autopartition 
    154                 maxRays 200 
    155                 maxPolygons -1 
     154                minRays 200 
     155                minPolygons -1 
    156156                maxDepth 40 
    157157                minPvs 35 
     
    159159                maxRayContribution 0.005 
    160160                #maxAccRayLength 100 
     161                 
    161162                # used for pvs criterium 
    162163                ct_div_ci 0.0 
     
    164165                # axis aligned splits 
    165166                AxisAligned { 
    166                         maxPolys 5000 
    167                         maxRays 500 
    168                         maxObjects 10 
     167                        minPolys 5000 
     168                        minRays 500 
     169                        minObjects 10 
    169170                        maxCostRatio 0.9 
    170171                        ct_div_ci 0.5 
     
    218219 
    219220        Construction { 
    220                 samples 200000 
    221         } 
    222          
    223         Termination { 
    224                 maxDepth        20 
    225                 minPvs          200 
    226                 minRays         100 
    227                 minSize         0.001 
     221                samples 1000000 
     222        } 
     223         
     224        Termination { 
     225                maxDepth        30 
     226                minPvs          50 
     227                minRays         10 
     228                minSize         0.1 
    228229                maxCostRatio    0.95 
    229                 maxRayContribution 0.1 
     230                maxRayContribution 0.2 
    230231        } 
    231232         
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r424 r426  
    12401240          "0.002"); 
    12411241 
    1242   RegisterOption("BspTree.Termination.maxPolygons", 
    1243                  optInt, 
    1244                  "-bsp_term_max_polygons=", 
     1242  RegisterOption("BspTree.Termination.minPolygons", 
     1243                 optInt, 
     1244                 "-bsp_term_min_polygons=", 
    12451245                 "5"); 
    12461246 
     
    12601260                 "0.005"); 
    12611261 
    1262   RegisterOption("BspTree.Termination.maxAccRayLenght", 
    1263                  optFloat, 
    1264                  "-bsp_term_max_acc_ray_length=", 
     1262  RegisterOption("BspTree.Termination.minAccRayLenght", 
     1263                 optFloat, 
     1264                 "-bsp_term_min_acc_ray_length=", 
    12651265                 "50"); 
    12661266 
    1267    RegisterOption("BspTree.Termination.maxRays", 
    1268                  optInt, 
    1269                  "-bsp_term_max_rays=", 
     1267   RegisterOption("BspTree.Termination.minRays", 
     1268                 optInt, 
     1269                 "-bsp_term_min_rays=", 
    12701270                 "-1"); 
    12711271 
     
    12951295                 "0.1"); 
    12961296 
    1297   RegisterOption("BspTree.Termination.AxisAligned.maxPolys", 
     1297  RegisterOption("BspTree.Termination.AxisAligned.minPolys", 
    12981298                 optInt, 
    12991299                 "-bsp_term_axis_aligned_max_polygons=", 
    13001300                 "50"); 
    13011301 
    1302    RegisterOption("BspTree.Termination.AxisAligned.maxObjects", 
    1303                  optInt, 
    1304                  "-bsp_term_max_objects=", 
     1302   RegisterOption("BspTree.Termination.AxisAligned.minObjects", 
     1303                 optInt, 
     1304                 "-bsp_term_min_objects=", 
    13051305                 "3"); 
    13061306 
    1307   RegisterOption("BspTree.Termination.AxisAligned.maxRays", 
    1308                  optInt, 
    1309                  "-bsp_term_axis_aligned_max_rays=", 
     1307  RegisterOption("BspTree.Termination.AxisAligned.minRays", 
     1308                 optInt, 
     1309                 "-bsp_term_axis_aligned_min_rays=", 
    13101310                 "-1"); 
    13111311 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp

    r406 r426  
    11#include "Ray.h" 
    22#include "Plane3.h" 
     3#include "VssRay.h" 
    34 
    45// ========================================================= 
     
    219220  return s; 
    220221} 
     222 
     223Ray::Ray(const VssRay &vssRay): 
     224loc(vssRay.mOrigin), 
     225sourceObject(0, vssRay.mOriginObject, 0), 
     226dir(vssRay.GetDir()) 
     227{ 
     228        intersections.push_back(Intersection(vssRay.mT, vssRay.mTerminationObject, 0)); 
     229} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h

    r406 r426  
    1313class ViewCell; 
    1414class BspLeaf; 
     15class VssRay; 
    1516 
    1617// ------------------------------------------------------------------- 
     
    101102  // dummy constructor 
    102103  Ray() {} 
     104 
     105  /** Construct ray from a vss ray. 
     106  */ 
     107  Ray(const VssRay &vssRay);     
    103108         
    104109  Intersectable *GetIntersectionObject(const int i) const { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r425 r426  
    591591                                //exporter->ExportBspViewCellPartition(*mBspTree, 0); 
    592592                                 
    593                                 if (1) // export scene geometry 
    594                                 { 
    595                                         Material m;//= RandomMaterial(); 
    596                                         m.mDiffuseColor = RgbColor(0, 1, 0); 
    597                                         exporter->SetForcedMaterial(m); 
    598                                         exporter->SetWireframe(); 
    599          
    600                                         for (int j = 0; j < objects.size(); ++ j) 
    601                                                 exporter->ExportIntersectable(objects[j]); 
    602                                 } 
     593                                if (1) 
     594                                        ExportSceneGeometry(exporter, objects); 
    603595                                         
    604596                                delete exporter; 
     
    676668        { 
    677669                Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d");  
    678                 exporter->SetWireframe(); 
    679                 exporter->ExportVspKdTree(*mVspKdTree, 300); 
     670                //exporter->SetWireframe(); 
     671                exporter->ExportVspKdTree(*mVspKdTree, mVspKdTree->GetStatistics().maxPvsSize); 
     672 
     673                Debug << "average PVS size: " << mVspKdTree->GetAvgPvsSize() << endl; 
     674 
     675                if (1) ExportSceneGeometry(exporter, objects); 
     676 
     677                bool exportRays = false; 
     678 
     679                if (exportRays)  
     680                { 
     681                        int raysSize = 500; 
     682                        float prob = raysSize / (float)mVspSampleRays.size(); 
     683                 
     684                        exporter->SetWireframe(); 
     685                         
     686                        VssRayContainer rays; 
     687                        for (int i = 0; i < mVspSampleRays.size(); ++ i) 
     688                        { 
     689                                if (RandomValue(0,1) < prob) 
     690                                        rays.push_back(mVspSampleRays[i]); 
     691                        } 
     692 
     693                        exporter->ExportRays(rays, RgbColor(1, 0, 0)); 
     694                } 
     695 
    680696                delete exporter; 
    681697        } 
     
    758774                        // also add origin to sample 
    759775                        sRay->mOriginObject = object; 
     776                        sRay->mOrigin = ray.GetLoc(); 
    760777                } 
    761778                else 
     
    872889 
    873890        return merged; 
     891} 
     892 
     893// export scene geometry 
     894void SamplingPreprocessor::ExportSceneGeometry(Exporter *exporter, const ObjectContainer &objects) 
     895{ 
     896        Material m;//= RandomMaterial(); 
     897        m.mDiffuseColor = RgbColor(0, 1, 0); 
     898        exporter->SetForcedMaterial(m); 
     899        exporter->SetWireframe(); 
     900 
     901        for (int j = 0; j < objects.size(); ++ j) 
     902                exporter->ExportIntersectable(objects[j]); 
    874903} 
    875904 
     
    911940                } 
    912941 
    913                 // export scene geometry 
    914942                if (1) 
    915                 { 
    916                         Material m;//= RandomMaterial(); 
    917                         m.mDiffuseColor = RgbColor(0, 1, 0); 
    918                         exporter->SetForcedMaterial(m); 
    919             exporter->SetWireframe(); 
    920  
    921                         for (int j = 0; j < objects.size(); ++ j) 
    922                                 exporter->ExportIntersectable(objects[j]); 
    923                 } 
     943                        ExportSceneGeometry(exporter, objects); 
    924944 
    925945                delete exporter; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h

    r411 r426  
    77#include "Preprocessor.h" 
    88#include "VssRay.h" 
     9 
     10class Exporter; 
    911 
    1012/** Sampling based visibility preprocessing. The implementation is based on heuristical 
     
    8587        void ExportBspPvs(const ObjectContainer &objects); 
    8688 
     89        /** Export scene geometry. 
     90        */ 
     91        void ExportSceneGeometry(Exporter *exporter, const ObjectContainer &objects); 
     92 
    8793        /** Post processes view cells (i.e., merges or subdivides view cells based 
    8894                on the PVS and the ray sets. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r424 r426  
    282282        environment->GetIntValue("BspTree.Termination.maxDepth", mTermMaxDepth); 
    283283        environment->GetIntValue("BspTree.Termination.minPvs", mTermMinPvs); 
    284         environment->GetIntValue("BspTree.Termination.maxPolygons", mTermMaxPolygons); 
    285         environment->GetIntValue("BspTree.Termination.maxRays", mTermMaxRays); 
     284        environment->GetIntValue("BspTree.Termination.minPolygons", mTermMinPolys); 
     285        environment->GetIntValue("BspTree.Termination.minRays", mTermMinRays); 
    286286        environment->GetFloatValue("BspTree.Termination.minArea", mTermMinArea);         
    287287        environment->GetFloatValue("BspTree.Termination.maxRayContribution", mTermMaxRayContribution); 
    288         environment->GetFloatValue("BspTree.Termination.maxAccRayLenght", mTermMaxAccRayLength); 
     288        environment->GetFloatValue("BspTree.Termination.minAccRayLenght", mTermMinAccRayLength); 
    289289 
    290290        //-- factors for bsp tree split plane heuristics 
     
    303303        environment->GetFloatValue("BspTree.Termination.AxisAligned.ct_div_ci", mAaCtDivCi); 
    304304        environment->GetFloatValue("BspTree.Termination.AxisAligned.maxCostRatio", mMaxCostRatio); 
    305         environment->GetIntValue("BspTree.Termination.AxisAligned.maxPolys",  
    306                                                          mTermMaxPolysForAxisAligned); 
     305        environment->GetIntValue("BspTree.Termination.AxisAligned.minPolys",  
     306                                                         mTermMinPolysForAxisAligned); 
    307307        environment->GetIntValue("BspTree.Termination.AxisAligned.maxRays",  
    308                                                          mTermMaxRaysForAxisAligned); 
     308                                                         mTermMinRaysForAxisAligned); 
    309309        environment->GetIntValue("BspTree.Termination.AxisAligned.maxObjects",  
    310                                                          mTermMaxObjectsForAxisAligned); 
     310                                                         mTermMinObjectsForAxisAligned); 
    311311        //-- partition criteria 
    312312        environment->GetIntValue("BspTree.maxPolyCandidates", mMaxPolyCandidates); 
     
    326326        Debug << "BSP min PVS: " << mTermMinPvs << endl; 
    327327        Debug << "BSP min area: " << mTermMinArea << endl; 
    328         Debug << "BSP max polys: " << mTermMaxPolygons << endl; 
    329         Debug << "BSP max rays: " << mTermMaxRays << endl; 
     328        Debug << "BSP max polys: " << mTermMinPolys << endl; 
     329        Debug << "BSP max rays: " << mTermMinRays << endl; 
    330330        Debug << "BSP max polygon candidates: " << mMaxPolyCandidates << endl; 
    331331        Debug << "BSP max plane candidates: " << mMaxRayCandidates << endl; 
     
    403403        app << "#N_SPLITS ( Number of splits )\n" << splits << "\n"; 
    404404 
    405         app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n"<< 
    406         maxDepthNodes * 100 / (double)Leaves() << endl; 
     405        app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maximum depth )\n"  
     406                <<      maxDepthNodes * 100 / (double)Leaves() << endl; 
     407 
     408        app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maximum depth )\n"  
     409                <<      maxDepthNodes * 100 / (double)Leaves() << endl; 
     410 
     411        app << "#N_PMINPVSLEAVES  ( Percentage of leaves with mininimal PVS )\n"  
     412                << minPvsNodes * 100 / (double)Leaves() << endl; 
     413 
     414        app << "#N_PMINRAYSLEAVES  ( Percentage of leaves with minimal number of rays)\n"  
     415                <<      minRaysNodes * 100 / (double)Leaves() << endl; 
     416 
     417        app << "#N_PMINAREALEAVES  ( Percentage of leaves with mininum area )\n" 
     418                << minAreaNodes * 100 / (double)Leaves() << endl; 
     419 
     420        app << "#N_PMAXRAYCONTRIBLEAVES  ( Percentage of leaves with maximal ray contribution )\n"  
     421                <<      maxRayContribNodes * 100 / (double)Leaves() << endl; 
    407422 
    408423        app << "#N_PMAXDEPTH ( Maximal reached depth )\n" << maxDepth << endl; 
     
    735750{ 
    736751        return  
    737                 (((int)data.mPolygons->size() <= mTermMaxPolygons) ||  
    738                  ((int)data.mRays->size() <= mTermMaxRays) || 
     752                (((int)data.mPolygons->size() <= mTermMinPolys) ||  
     753                 ((int)data.mRays->size() <= mTermMinRays) || 
    739754                 (data.mPvs <= mTermMinPvs) || 
    740755                 (data.mArea <= mTermMinArea) || 
     
    11051120         
    11061121        if ((mSplitPlaneStrategy & AXIS_ALIGNED) && 
    1107                 ((int)data.mPolygons->size() > mTermMaxPolysForAxisAligned) && 
    1108                 ((int)data.mRays->size() > mTermMaxRaysForAxisAligned) && 
    1109                 ((mTermMaxObjectsForAxisAligned < 0) ||  
    1110                   (Polygon3::ParentObjectsSize(*data.mPolygons) > mTermMaxObjectsForAxisAligned))) 
     1122                ((int)data.mPolygons->size() > mTermMinPolysForAxisAligned) && 
     1123                ((int)data.mRays->size() > mTermMinRaysForAxisAligned) && 
     1124                ((mTermMinObjectsForAxisAligned < 0) ||  
     1125                  (Polygon3::ParentObjectsSize(*data.mPolygons) > mTermMinObjectsForAxisAligned))) 
    11111126        { 
    11121127                Plane3 plane; 
     
    16991714        BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode); 
    17001715 
    1701         if (data.mDepth >= mTermMaxDepth) 
    1702                 ++ mStat.maxDepthNodes; 
    1703          
    17041716        // store maximal and minimal depth 
    17051717        if (data.mDepth > mStat.maxDepth) 
     
    17121724        mStat.accumDepth += data.mDepth; 
    17131725         
     1726 
     1727        if (data.mDepth >= mTermMaxDepth) 
     1728                ++ mStat.maxDepthNodes; 
     1729 
     1730        if (data.mPvs < mTermMinPvs) 
     1731                ++ mStat.minPvsNodes; 
     1732 
     1733        if ((int)data.mRays->size() < mTermMinRays) 
     1734                ++ mStat.minRaysNodes; 
     1735 
     1736        if (data.GetAvgRayContribution() > mTermMaxRayContribution) 
     1737                ++ mStat.maxRayContribNodes; 
     1738         
     1739        if (data.mGeometry->GetArea() <= mTermMinArea)  
     1740                ++ mStat.minAreaNodes; 
     1741 
    17141742#ifdef _DEBUG 
    17151743        Debug << "BSP stats: " 
     
    17171745                  << "PVS: " << data.mPvs << " (min: " << mTermMinPvs << "), " 
    17181746                  << "Area: " << data.mArea << " (min: " << mTermMinArea << "), " 
    1719                   << "#polygons: " << (int)data.mPolygons->size() << " (max: " << mTermMaxPolygons << "), " 
    1720                   << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMaxRays << "), "  
     1747                  << "#polygons: " << (int)data.mPolygons->size() << " (max: " << mTermMinPolys << "), " 
     1748                  << "#rays: " << (int)data.mRays->size() << " (max: " << mTermMinRays << "), "  
    17211749                  << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "=, " 
    17221750                  << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r424 r426  
    8585        // minimal depth 
    8686        int minDepth; 
     87         
    8788        // max depth nodes 
    8889        int maxDepthNodes; 
     90        // minimum depth nodes 
     91        int minDepthNodes; 
     92        // max depth nodes 
     93        int minPvsNodes; 
     94        // nodes with minimum PVS 
     95        int minRaysNodes; 
     96        // max ray contribution nodes 
     97        int maxRayContribNodes; 
     98        // minimum area nodes 
     99        int minAreaNodes; 
     100 
    89101        // max number of rays per node 
    90102        int maxObjectRefs; 
     
    117129                nodes = 0; 
    118130                splits = 0; 
    119                 maxDepthNodes = 0; 
     131                 
    120132                maxDepth = 0; 
    121133                minDepth = 99999; 
     
    123135                accumDepth = 0; 
    124136         
     137                maxDepthNodes = 0; 
     138                minPvsNodes = 0; 
     139                minRaysNodes = 0; 
     140                maxRayContribNodes = 0; 
     141                minAreaNodes = 0; 
     142 
    125143                contributingSamples = 0; 
    126144                sampleContributions = 0; 
     
    783801 
    784802        /// maximal number of polygons before subdivision termination 
    785         int mTermMaxPolygons; 
     803        int mTermMinPolys; 
    786804        /// maximal number of rays before subdivision termination 
    787         int mTermMaxRays; 
     805        int mTermMinRays; 
    788806        /// maximal possible depth 
    789807        int mTermMaxDepth; 
     
    792810        /// mininum PVS 
    793811        int mTermMinPvs; 
     812 
     813        /// minimal number of polygons for axis aligned split 
     814        int mTermMinPolysForAxisAligned; 
     815        /// minimal number of rays for axis aligned split 
     816        int mTermMinRaysForAxisAligned; 
     817        /// minimal number of objects for axis aligned split 
     818        int mTermMinObjectsForAxisAligned; 
     819        /// maximal contribution per ray 
     820        float mTermMaxRayContribution; 
     821        /// minimal accumulated ray length 
     822        float mTermMinAccRayLength; 
     823 
     824 
    794825        /// strategy to get the best split plane 
    795826        int mSplitPlaneStrategy; 
     
    799830        int mMaxRayCandidates; 
    800831         
    801         /// maximal number of polygons for axis aligned split 
    802         int mTermMaxPolysForAxisAligned; 
    803         /// maximal number of rays for axis aligned split 
    804         int mTermMaxRaysForAxisAligned; 
    805         /// maximal number of objects for axis aligned split 
    806         int mTermMaxObjectsForAxisAligned; 
    807         /// maximal contribution per ray 
    808         float mTermMaxRayContribution; 
    809         /// maximal accumulated ray length 
    810         float mTermMaxAccRayLength; 
    811  
    812832        float mCtDivCi; 
    813833 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r425 r426  
    241241} 
    242242 
     243RayInfoContainer &VspKdTreeLeaf::GetRays() 
     244{ 
     245        return mRays; 
     246} 
    243247/*********************************************************/ 
    244248/*            class VspKdTree implementation             */ 
     
    313317void VspKdStatistics::Print(ostream &app) const 
    314318{ 
    315   app << "===== VspKdTree statistics ===============\n"; 
    316  
    317   app << "#N_RAYS ( Number of rays )\n" 
    318       << rays <<endl; 
    319    
    320   app << "#N_INITPVS ( Initial PVS size )\n" 
    321       << initialPvsSize <<endl; 
    322    
    323   app << "#N_NODES ( Number of nodes )\n" << nodes << "\n"; 
    324  
    325   app << "#N_LEAVES ( Number of leaves )\n" << Leaves() << "\n"; 
    326  
    327   app << "#N_SPLITS ( Number of splits in axes x y z dx dy dz \n"; 
    328   for (int i=0; i<7; i++) 
    329     app << splits[i] <<" "; 
    330   app <<endl; 
    331  
    332   app << "#N_RAYREFS ( Number of rayRefs )\n" << 
    333     rayRefs << "\n"; 
    334  
    335   app << "#N_RAYRAYREFS  ( Number of rayRefs / ray )\n" << 
    336     rayRefs/(double)rays << "\n"; 
    337  
    338   app << "#N_LEAFRAYREFS  ( Number of rayRefs / leaf )\n" << 
    339     rayRefs/(double)Leaves() << "\n"; 
    340  
    341   app << "#N_MAXRAYREFS  ( Max number of rayRefs / leaf )\n" << 
    342     maxRayRefs << "\n"; 
    343  
     319        app << "===== VspKdTree statistics ===============\n"; 
     320 
     321        app << "#N_RAYS ( Number of rays )\n" 
     322                << rays << endl; 
     323   
     324        app << "#N_INITPVS ( Initial PVS size )\n" 
     325                << initialPvsSize << endl; 
     326   
     327        app << "#N_NODES ( Number of nodes )\n" << nodes << "\n"; 
     328 
     329        app << "#N_LEAVES ( Number of leaves )\n" << Leaves() << "\n"; 
     330 
     331        app << "#N_SPLITS ( Number of splits in axes x y z dx dy dz \n"; 
     332   
     333        for (int i=0; i<7; i++) 
     334                app << splits[i] <<" "; 
     335        app << endl; 
     336 
     337        app << "#N_RAYREFS ( Number of rayRefs )\n" << 
     338                rayRefs << "\n"; 
     339 
     340        app << "#N_RAYRAYREFS  ( Number of rayRefs / ray )\n" << 
     341                rayRefs / (double)rays << "\n"; 
     342 
     343        app << "#N_LEAFRAYREFS  ( Number of rayRefs / leaf )\n" << 
     344                rayRefs / (double)Leaves() << "\n"; 
     345 
     346        app << "#N_MAXRAYREFS  ( Max number of rayRefs / leaf )\n" << 
     347                maxRayRefs << "\n"; 
    344348 
    345349  //  app << setprecision(4); 
    346350 
    347   app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n"<< 
    348     maxDepthNodes*100/(double)Leaves()<<endl; 
    349  
    350   app << "#N_PMINPVSLEAVES  ( Percentage of leaves with minCost )\n"<< 
    351     minPvsNodes*100/(double)Leaves()<<endl; 
    352  
    353   app << "#N_PMINRAYSLEAVES  ( Percentage of leaves with minCost )\n"<< 
    354     minRaysNodes*100/(double)Leaves()<<endl; 
    355          
     351        app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n" << 
     352                maxDepthNodes * 100 / (double)Leaves() << endl; 
     353 
     354        app << "#N_PMINPVSLEAVES  ( Percentage of leaves with mininimal PVS )\n" << 
     355                minPvsNodes * 100 / (double)Leaves() << endl; 
     356 
     357        app << "#N_PMINRAYSLEAVES  ( Percentage of leaves with minimal number of rays)\n" << 
     358                minRaysNodes * 100 / (double)Leaves() << endl; 
     359 
    356360        app << "#N_PMINSIZELEAVES  ( Percentage of leaves with minSize )\n"<< 
    357     minSizeNodes*100/(double)Leaves()<<endl; 
    358  
    359         app << "#N_PMAXRAYCONTRIBLEAVES  ( Percentage of leaves with maximal ray contribution )\n"<< 
    360     maxRayContribNodes*100/(double)Leaves()<<endl; 
    361  
    362   app << "#N_ADDED_RAYREFS  (Number of dynamically added ray references )\n"<< 
    363     addedRayRefs<<endl; 
    364  
    365   app << "#N_REMOVED_RAYREFS  (Number of dynamically removed ray references )\n"<< 
    366     removedRayRefs<<endl; 
    367  
    368   //  app << setprecision(4); 
    369  
    370   app << "#N_CTIME  ( Construction time [s] )\n" 
    371       << Time() << " \n"; 
    372  
    373   app << "===== END OF VspKdTree statistics ==========\n"; 
    374  
     361                minSizeNodes * 100 / (double)Leaves() << endl; 
     362 
     363        app << "#N_PMAXRAYCONTRIBLEAVES  ( Percentage of leaves with maximal ray contribution )\n" << 
     364                maxRayContribNodes * 100 / (double)Leaves() << endl; 
     365 
     366        app << "#N_ADDED_RAYREFS  ( Number of dynamically added ray references )\n"<< 
     367                addedRayRefs << endl; 
     368 
     369        app << "#N_REMOVED_RAYREFS  ( Number of dynamically removed ray references )\n"<< 
     370                removedRayRefs << endl; 
     371 
     372        //  app << setprecision(4); 
     373 
     374        app << "#N_MAXPVS ( Maximal PVS size / leaf)\n" 
     375                << maxPvsSize << endl; 
     376 
     377        app << "#N_CTIME  ( Construction time [s] )\n" 
     378                << Time() << " \n"; 
     379 
     380        app << "===== END OF VspKdTree statistics ==========\n"; 
    375381} 
    376382 
     
    876882        VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(data.mNode); 
    877883 
     884        if (leaf->GetPvsSize() > mStat.maxPvsSize) 
     885                mStat.maxPvsSize = leaf->GetPvsSize(); 
     886 
     887        if ((int)(leaf->mRays.size()) > mStat.maxRayRefs) 
     888                mStat.maxRayRefs = (int)leaf->mRays.size(); 
     889 
     890 
    878891        if (data.mDepth >= mTermMaxDepth) 
    879892                ++ mStat.maxDepthNodes; 
    880893   
    881         //  if ( (int)(leaf->mRays.size()) < termMinCost) 
    882         //    stat.minCostNodes++; 
    883894        if (leaf->GetPvsSize() < mTermMinPvs) 
    884895                ++ mStat.minPvsNodes; 
    885896 
    886         if (leaf->GetPvsSize() < mTermMinRays) 
     897        if ((int)leaf->GetRays().size() < mTermMinRays) 
    887898                ++ mStat.minRaysNodes; 
    888899 
    889         if (0 && leaf->GetAvgRayContribution() > mTermMaxRayContribution) 
     900        if (leaf->GetAvgRayContribution() > mTermMaxRayContribution) 
    890901                ++ mStat.maxRayContribNodes; 
    891902         
    892903        if (SqrMagnitude(data.mBox.Size()) <= mTermMinSize)  
    893904                ++ mStat.minSizeNodes; 
    894  
    895 //      if ((int)(leaf->mRays.size()) > stat.maxRayRefs) 
    896 //              mStat.maxRayRefs = (int)leaf->mRays.size(); 
    897905} 
    898906 
     
    902910{ 
    903911        return ((leaf->GetPvsSize() < mTermMinPvs) ||  
    904                     //(leaf->mRays.size() < mTermMinRays) || 
    905                         // (leaf->GetAvgRayContribution() > termMaxRayContribution ) || 
     912                    (leaf->mRays.size() < mTermMinRays) || 
     913                        (leaf->GetAvgRayContribution() > mTermMaxRayContribution ) || 
    906914                        (leaf->mDepth >= mTermMaxDepth) ||  
    907915                        (SqrMagnitude(box.Size()) <= mTermMinSize)); 
     
    923931                                Debug << "Bbox: " << GetBBox(leaf) << endl; 
    924932                        } 
    925                  
    926                         Debug << "depth: " << (int)leaf->mDepth << " pvs: " << leaf->GetPvsSize() << " rays: " << leaf->mRays.size() << endl; 
     933                        //Debug << "depth: " << (int)leaf->mDepth << " pvs: " << leaf->GetPvsSize() << " rays: " << leaf->mRays.size() << endl; 
    927934                } 
    928935                return leaf; 
     
    939946        const int axis = SelectPlane(leaf, box, position, raysBack, raysFront, pvsBack, pvsFront); 
    940947 
    941         Debug << "rays back=" << raysBack << " rays front=" << raysFront << " pvs back=" << pvsBack << " pvs front=" << pvsFront << endl; 
     948        //Debug << "rays back=" << raysBack << " rays front=" << raysFront << " pvs back=" << pvsBack << " pvs front=" <<       pvsFront << endl; 
    942949 
    943950        if (axis == -1)  
     
    16951702} 
    16961703 
    1697 int VspKdTree::ComputePvsSize(VspKdTreeNode *node, const RayInfoContainer &globalRays) const 
     1704int VspKdTree::ComputePvsSize(VspKdTreeNode *node,  
     1705                                                          const RayInfoContainer &globalRays) const 
    16981706{ 
    16991707        int pvsSize = 0; 
     
    17031711        RayInfoContainer::const_iterator it, it_end = globalRays.end(); 
    17041712 
     1713        // warning: implicit conversion from VssRay to Ray 
    17051714        for (it = globalRays.begin(); it != globalRays.end(); ++ it) 
    1706                 ;//pvsSize += box.GetMinMaxT((*it).mRay, NULL, NULL); 
    1707  
     1715                pvsSize += box.GetMinMaxT(*(*it).mRay, NULL, NULL); 
     1716         
    17081717        return pvsSize; 
    17091718} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h

    r425 r426  
    5757        // max depth nodes 
    5858        int minPvsNodes; 
     59        // nodes with minimum PVS 
    5960        int minRaysNodes; 
    6061        // max ray contribution nodes 
     
    6566        // max number of rays per node 
    6667        int maxRayRefs; 
     68        // maximal PVS size / leaf 
     69        int maxPvsSize; 
     70 
    6771        // number of dynamically added ray refs 
    6872        int addedRayRefs; 
     
    8690                rays = queryDomains = 0; 
    8791                rayRefs = 0; 
     92                 
    8893                maxDepthNodes = 0; 
    8994                minPvsNodes = 0; 
    90                 minRaysNodes = 0;  
     95                minRaysNodes = 0; 
     96                maxRayContribNodes = 0; 
     97                minSizeNodes = 0; 
     98 
    9199                maxRayRefs = 0; 
    92100                addedRayRefs = removedRayRefs = 0; 
     101                 
    93102                initialPvsSize = 0; 
    94                 maxRayContribNodes = 0; 
    95                 minSizeNodes = 0; 
     103                maxPvsSize = 0; 
    96104        } 
    97105 
     
    146154        */ 
    147155        VspKdTreeInterior *GetParent() const; 
     156 
    148157        /** Sets parent node. 
    149158        */ 
     
    251260        */ 
    252261        int GetPvsSize() const; 
    253         void SetPvsSize(const int s); 
    254262 
    255263        /** If PVS is not valid, this function recomputes the leaf  
     
    258266        void UpdatePvsSize(); 
    259267 
     268        RayInfoContainer &GetRays(); 
     269 
    260270        /** Returns average contribution of a ray to the PVS 
    261271        */ 
     
    278288 
    279289protected: 
    280          
     290 
     291        /** Manually sets PVS size. 
     292                @param s the PVS size 
     293        */ 
     294        void SetPvsSize(const int s); 
     295 
    281296        int mMailbox; 
    282297   
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h

    r422 r426  
    6262         
    6363        VssRay(const Ray &ray): 
    64                 mOrigin(ray.GetLoc()),  
    65                 mOriginObject(ray.sourceObject.mObject), 
    6664                mRefCount(0), 
    6765                mFlags(0), 
    68                 mMailbox(-1) 
     66                mMailbox(-1), 
     67                mOriginObject(ray.sourceObject.mObject) 
    6968        { 
     69                if (ray.sourceObject.mObject) 
     70                        mOrigin = ray.Extrap(ray.sourceObject.mT); 
     71                else 
     72                        mOrigin = ray.GetLoc();  
     73 
    7074                if (!ray.intersections.empty()) 
    7175                { 
    72                         mTermination = ray.intersections[0].mT; 
     76                        mTermination = ray.Extrap(ray.intersections[0].mT); 
    7377                        mTerminationObject = ray.intersections[0].mObject; 
    7478                } 
    7579                else 
    7680                { 
    77                         mTermination = Limits::Infinity; 
     81                        mTermination = 1e6; 
    7882                        mTerminationObject = NULL; 
    7983                } 
     84 
     85                Precompute(); 
    8086        } 
    8187 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r425 r426  
    154154  for (; ri != rays.end(); ri++) { 
    155155    Vector3 a = (*ri)->GetOrigin(); 
    156      
    157     Vector3 b = (*ri)->GetTermination(); 
     156        Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize(b - a); 
     157         
    158158    stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,"; 
    159     stream<<b.x<<" "<<b.y<<" "<<b.z<<" ,\n"; 
     159        stream<<b.x<<" "<<b.y<<" "<<b.z<<" ,\n"; 
    160160  } 
    161161   
     
    585585bool X3dExporter::ExportVspKdTree(const VspKdTree &tree, const int maxPvs) 
    586586{ 
    587          //if (mExportRayDensity) {       
    588          //return ExportKdTreeRayDensity(tree); } 
    589  
    590587        stack<VspKdTreeNode *> tStack; 
    591588 
     
    602599     
    603600                tStack.pop(); 
    604                 AxisAlignedBox3 box = tree.GetBBox(node); 
    605  
    606                 Mesh *mesh = new Mesh; 
    607  
    608                 // add 6 vertices of the box 
    609                 int index = (int)mesh->mVertices.size(); 
    610  
    611                 for (int i=0; i < 8; ++ i)  
    612                 { 
    613                         Vector3 v; 
    614                         box.GetVertex(i, v); 
    615                         mesh->mVertices.push_back(v); 
    616                 } 
    617  
    618                 mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) ); 
    619                 mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) ); 
    620                 mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) ); 
    621  
    622                 mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) ); 
    623                 mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 
    624                 mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 
    625  
    626                 if (maxPvs > 0) 
    627                 { 
    628             mForcedMaterial.mDiffuseColor.b = 1.0f; 
    629                         const float importance = maxPvs; 
    630                         //float importance = (float)(*it)->GetPvs().GetSize() / (float)maxPvs; 
    631  
    632                         mForcedMaterial.mDiffuseColor.r = importance; 
    633                         mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r; 
    634                 } 
    635  
    636                 ExportMesh(mesh); 
    637                 DEL_PTR(mesh); 
    638  
    639         if (!node->IsLeaf())  
     601 
     602                if (node->IsLeaf()) 
     603                { 
     604                        AxisAlignedBox3 box = tree.GetBBox(node); 
     605 
     606                        Mesh *mesh = new Mesh; 
     607 
     608                        // add 6 vertices of the box 
     609                        int index = (int)mesh->mVertices.size(); 
     610 
     611                        for (int i=0; i < 8; ++ i)  
     612                        { 
     613                                Vector3 v; 
     614                                box.GetVertex(i, v); 
     615                                mesh->mVertices.push_back(v); 
     616                        } 
     617 
     618                        mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) ); 
     619                        mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) ); 
     620                        mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) ); 
     621 
     622                        mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) ); 
     623                        mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 
     624                        mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 
     625 
     626                        if (maxPvs > 0) 
     627                        { 
     628                                VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(node); 
     629 
     630                                mForcedMaterial.mDiffuseColor.b = 1.0f; 
     631                                 
     632                                leaf->UpdatePvsSize(); 
     633                         
     634                                const float importance = (float)leaf->GetPvsSize() / (float)maxPvs; 
     635                                mForcedMaterial.mDiffuseColor.r = importance; 
     636                                mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r; 
     637                        } 
     638 
     639                        ExportMesh(mesh); 
     640                        DEL_PTR(mesh); 
     641                } 
     642                else   
    640643                { 
    641644                        VspKdTreeInterior *interior = dynamic_cast<VspKdTreeInterior *>(node); 
Note: See TracChangeset for help on using the changeset viewer.