Changeset 2740


Ignore:
Timestamp:
06/05/08 18:48:10 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh

    r2738 r2740  
    1919#SCENE=../data/vienna/vienna_rep.obj 
    2020 
    21 #SCENE=../data/vienna/vienna_cropped.obj 
     21SCENE=../data/vienna/vienna_cropped.obj 
    2222VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz  
    2323VIEWPOINTS=../data/vienna/testwalk.vp 
     
    4242-gvs_samples_per_pass=1000000 \ 
    4343-gvs_initial_samples=16 \ 
    44 -gvs_max_viewcells=3 \ 
     44-gvs_max_viewcells=1 \ 
    4545-gvs_min_contribution=200 \ 
    4646-gvs_per_viewcell=true \ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp

    r2723 r2740  
    99#include "VssRay.h" 
    1010#include "IntersectableWrapper.h" 
    11  
    12  
     11#include "SimpleRay.h" 
    1312#include <cassert> 
    1413 
    1514 
     15 
    1616using namespace std; 
    1717 
    18 namespace GtpVisibilityPreprocessor { 
     18 
     19namespace GtpVisibilityPreprocessor  
     20{ 
    1921 
    2022#define FATAL Debug 
     
    26322634} 
    26332635 
    2634 } 
    2635  
     2636 
     2637Rectangle3 AxisAlignedBox3::GetNearestFace(const Vector3 &pt) const 
     2638{ 
     2639        float minDist = 1e20f; 
     2640        int face = 0; 
     2641 
     2642        if ((pt.x - mMin.x) < minDist) {minDist = (pt.x - mMin.x); face = 0;} 
     2643        if ((mMax.x - pt.x) < minDist) {minDist = (mMax.x - pt.x); face = 1;} 
     2644        if ((pt.y - mMin.y) < minDist) {minDist = (pt.y - mMin.y); face = 2;} 
     2645        if ((mMax.y - pt.y) < minDist) {minDist = (mMax.y - pt.y); face = 3;} 
     2646        if ((pt.z - mMin.z) < minDist) {minDist = (pt.z - mMin.z); face = 4;} 
     2647        if ((mMax.z - pt.z) < minDist) {minDist = (mMax.z - pt.z); face = 5;} 
     2648 
     2649        return GetFace(face); 
     2650} 
     2651 
     2652 
     2653bool AxisAlignedBox3::Intersects(const SimpleRay &ray, float &tnear, float &tfar) const 
     2654{ 
     2655        tnear = -1e20f; 
     2656        tfar = 1e20f; 
     2657 
     2658        const Vector3 origin = ray.mOrigin; 
     2659        const Vector3 dir = ray.mDirection; 
     2660 
     2661        float t1, t2; 
     2662 
     2663        // ray is parallel to the planes 
     2664        if (dir.x == 0)  
     2665        { 
     2666                if ((origin.x < mMin.x) || (origin.x > mMax.x))  
     2667                        return false; // origin not between planes 
     2668        } 
     2669        else 
     2670        { 
     2671                // time at which ray intersects minimum X plane 
     2672                t1 = (mMin.x - origin.x) / dir.x; 
     2673                // time at which ray intersects maximum X plane 
     2674                t2 = (mMax.x - origin.x) / dir.x; 
     2675                 
     2676                if (t1 > t2) 
     2677                        swap(t1, t2); 
     2678                 
     2679                if (t1 > tnear) 
     2680                        tnear = t1; 
     2681                 
     2682                if (t2 < tfar) 
     2683                        tfar = t2; 
     2684                 
     2685                if (tnear > tfar) 
     2686                        return false; 
     2687                 
     2688                if (tfar < 0) 
     2689                        return false; 
     2690        } 
     2691 
     2692        if (dir.y == 0) // ray is parallel to the planes 
     2693        { 
     2694                if ((origin.y < mMin.y) || (origin.y > mMax.y))  
     2695                        return false; // origin not between planes) 
     2696        } 
     2697        else 
     2698        { 
     2699                t1 = (mMin.y - origin.y) / dir.y;  
     2700                t2 = (mMax.y - origin.y) / dir.y;  
     2701                 
     2702                if (t1 > t2) 
     2703                        swap(t1, t2); 
     2704                 
     2705                if (t1 > tnear) 
     2706                        tnear = t1; 
     2707                 
     2708                if (t2 < tfar) 
     2709                        tfar = t2; 
     2710                 
     2711                if (tnear > tfar) 
     2712                        return false; 
     2713                 
     2714                if (tfar < 0) 
     2715                        return false; 
     2716        } 
     2717 
     2718        if (dir.z == 0) // ray is parallel to the planes 
     2719        { 
     2720                if ((origin.z < mMin.z) || (origin.z > mMax.z))  
     2721                        return false; // origin not between planes) 
     2722        } 
     2723        else 
     2724        { 
     2725                t1 = (mMin.z - origin.z) / dir.z;  
     2726                t2 = (mMax.z - origin.z) / dir.z;  
     2727                 
     2728                if (t1 > t2) 
     2729                        swap(t1, t2); 
     2730                 
     2731                if (t1 > tnear) 
     2732                        tnear = t1; 
     2733                 
     2734                if (t2 < tfar) 
     2735                        tfar = t2; 
     2736                 
     2737                if (tnear > tfar) 
     2738                        return false; 
     2739                 
     2740                if (tfar < 0) 
     2741                        return false; 
     2742        } 
     2743 
     2744        return true; 
     2745} 
     2746 
     2747} 
     2748 
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h

    r2720 r2740  
    392392                         AxisAlignedBox3 &right) const; 
    393393 
     394  bool Intersects(const SimpleRay &ray,  float &tnear, float &tfar) const; 
     395 
     396  Rectangle3 GetNearestFace(const Vector3 &pt) const; 
     397 
    394398#define __EXTENT_HACK 
    395399  // get the extent of face 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r2739 r2740  
    677677        // handle cast rays 
    678678        EnqueueRays(vssRays); 
    679          
     679 
     680 
     681#if 0 
    680682        for (size_t i = 0; i < vssRays.size(); ++ i) 
    681683        { 
     
    684686        } 
    685687 
    686 #if 0 
    687          
     688 
    688689    // recursivly subdivide each edge 
    689690        for (int i = 0; i < numBorderSamples; ++ i) 
     
    791792    if (mPerViewCell) 
    792793        { 
    793                 if (!IntersectViewCell(newOrigin, newDir)) 
     794                if (!IntersectsViewCell(newOrigin, -newDir)) 
    794795                        return false; 
    795796        } 
     
    801802 
    802803 
    803 bool GvsPreprocessor::IntersectViewCell(Vector3 &origin, Vector3 &dir) const 
    804 { 
    805         // send ray to view cell 
    806         static Ray testRay; 
    807  
    808         testRay.Clear(); 
    809         testRay.Init(origin, -dir, Ray::LOCAL_RAY); 
    810  
     804bool GvsPreprocessor::IntersectsViewCell(Vector3 &origin, const Vector3 &dir) const 
     805{ 
     806        AxisAlignedBox3 box = mCurrentViewCell->GetBox(); 
     807 
     808        if (box.IsInside(origin)) 
     809        { 
     810                //cout<<"z"; 
     811                return true; 
     812        } 
     813         
     814        // intersect ray with view cell and  
     815        SimpleRay ray(origin, dir, 0, 1.0f); 
     816 
     817        float tnear, tfar; 
     818         
    811819        // check if ray intersects view cell 
    812         if (!mCurrentViewCell->CastRay(testRay)) 
     820        if (!mCurrentViewCell->GetBox().Intersects(ray, tnear, tfar)) 
    813821                return false; 
    814822 
    815         Ray::Intersection &hit = testRay.intersections[0]; 
    816  
    817         // the ray starts from the view cell 
    818         origin = testRay.Extrap(hit.mT); 
    819  
     823        origin = origin + dir * tnear; 
     824        //cout<<"r"; 
    820825        return true; 
    821826} 
     
    20432048        size_t currentNumber = rays.size(); 
    20442049 
    2045         while ((rays.size() - currentNumber) < number) 
     2050        int tries = 0; 
     2051 
     2052        while (((rays.size() - currentNumber) < number) && (tries ++ < 20)) 
    20462053        { 
    20472054                SimpleRay ray; 
     
    20492056                        rays.push_back(ray); 
    20502057        } 
     2058 
     2059        //cout << "generated " << rays.size() << " rays" << endl; 
    20512060} 
    20522061 
     
    20572066                                                                                                 SimpleRay &ray) 
    20582067{ 
    2059         Vector3 nd = triangle.GetNormal(); 
    2060    
     2068        //Vector3 nd = triangle.GetNormal(); 
     2069        const AxisAlignedBox3 box = mCurrentViewCell->GetBox(); 
     2070        Vector3 nd = box.GetNearestFace(origin).GetNormal(); 
     2071        //cout << "pt: " << origin << " face: " << box.GetNearestFace(origin) << endl; 
     2072        nd.Normalize(); 
     2073 
    20612074        // Compute right handed coordinate system from direction 
    20622075        Vector3 U, V; 
     
    20772090        const Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V; 
    20782091 
    2079         Vector3 newOrigin = origin; 
    2080  
    2081         //cout << "t: " << termination; 
    2082         newOrigin += shift; 
    2083         //cout << " new t: " << termination << endl; 
     2092        Vector3 newOrigin = origin + shift; 
     2093        //cout << "o: " << origin << " new o: " << newOrigin << endl; 
     2094 
    20842095        Vector3 direction = termination - newOrigin; 
    20852096 
     
    20912102        direction /= len; 
    20922103 
    2093         if (!IntersectViewCell(newOrigin, direction)) 
     2104        if (!IntersectsViewCell(newOrigin, -direction)) 
     2105        { 
     2106                //cout << "x"; 
    20942107                return false; 
    2095  
     2108        } 
     2109 
     2110        //cout << "y"; 
    20962111        // $$ jb the pdf is yet not correct for all sampling methods! 
    20972112        const float pdf = 1.0f; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h

    r2739 r2740  
    8383        ObjectContainer mKdPvs; 
    8484 
    85         float RaysPerSec() const { if (!mTotalTime) return 0; return (float)(mTotalSamples / mTotalTime) * 1e-6f; } 
     85        float RaysPerSec() const  
     86        {  
     87                if (!mTotalTime) return 0;  
     88                return (float)(mTotalSamples / mTotalTime) * 1e-6f;  
     89        } 
    8690 
    8791        void Print(ostream &app) const; 
     
    304308                                                                        SimpleRay &ray); 
    305309 
    306         inline bool IntersectViewCell(Vector3 &origin, Vector3 &dir) const; 
     310        inline bool IntersectsViewCell(Vector3 &origin, const Vector3 &dir) const; 
    307311 
    308312 
Note: See TracChangeset for help on using the changeset viewer.