Ignore:
Timestamp:
12/12/06 17:25:53 (18 years ago)
Author:
bittner
Message:

mixture distribution initial coding

File:
1 edited

Legend:

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

    r1877 r1883  
    7070bool ObjectBasedDistribution::GenerateSample(SimpleRay &ray) 
    7171{ 
    72         Vector3 origin, direction;  
    73  
    74         float r[5]; 
    75         mHalton.GetNext(5, r); 
    76  
    77         mPreprocessor.mViewCellsManager->GetViewPoint(origin, Vector3(r[2],r[3],r[4])); 
    78          
    79         Vector3 point; 
    80         Vector3 normal; 
    81  
    82         r[0] *= mPreprocessor.mObjects.size()-1; 
    83         const int i = (int)r[0]; 
    84  
    85         Intersectable *object = mPreprocessor.mObjects[i]; 
    86  
    87         // take the remainder as a parameter over objects surface 
    88         r[0] -= (float)i; 
    89          
    90         object->GetRandomSurfacePoint(r[0], r[1], point, normal); 
    91  
    92         direction = point - origin; 
    93          
    94         const float c = Magnitude(direction); 
    95          
    96         if (c <= Limits::Small)  
    97                 return false; 
    98  
    99         // $$ jb the pdf is yet not correct for all sampling methods! 
    100         const float pdf = 1.0f; 
    101          
    102         direction *= 1.0f / c; 
    103         ray = SimpleRay(origin, direction, pdf); 
    104  
    105         return true; 
    106 } 
    107  
    108  
    109 bool ObjectDirectionBasedDistribution::GenerateSample(SimpleRay &ray) 
     72  Vector3 origin, direction;  
     73   
     74  float r[5]; 
     75  mHalton.GetNext(5, r); 
     76   
     77  mPreprocessor.mViewCellsManager->GetViewPoint(origin, 
     78                                                                                                Vector3(r[2],r[3],r[4])); 
     79   
     80 
     81  Vector3 point, normal; 
     82   
     83  r[0] *= mPreprocessor.mObjects.size()-1; 
     84  const int i = (int)r[0]; 
     85   
     86  Intersectable *object = mPreprocessor.mObjects[i]; 
     87   
     88  // take the remainder as a parameter over objects surface 
     89  r[0] -= (float)i; 
     90   
     91  object->GetRandomSurfacePoint(r[0], r[1], point, normal); 
     92   
     93  direction = point - origin; 
     94   
     95  const float c = Magnitude(direction); 
     96   
     97  if (c <= Limits::Small)  
     98        return false; 
     99   
     100  // $$ jb the pdf is yet not correct for all sampling methods! 
     101  const float pdf = 1.0f; 
     102   
     103  direction *= 1.0f / c; 
     104  ray = SimpleRay(origin, direction, OBJECT_BASED_DISTRIBUTION, pdf); 
     105   
     106  return true; 
     107} 
     108 
     109 
     110bool 
     111ObjectDirectionBasedDistribution::GenerateSample(SimpleRay &ray) 
    110112{        
    111         Vector3 origin, direction;  
    112     const int i = (int)RandomValue(0, (Real)mPreprocessor.mObjects.size() - 0.5f); 
    113         Intersectable *object = mPreprocessor.mObjects[i]; 
    114          
    115         Vector3 normal; 
    116         //cout << "x"; 
    117         object->GetRandomSurfacePoint(origin, normal); 
    118         direction = UniformRandomVector(normal); 
    119          
    120         origin += 0.1f * direction; 
    121  
    122         const float c = Magnitude(direction); 
    123  
    124         if (c <= Limits::Small)  
    125                 return false; 
    126          
    127         // $$ jb the pdf is yet not correct for all sampling methods! 
    128         const float pdf = 1.0f; 
    129          
    130         direction *= 1.0f / c; 
    131         ray = SimpleRay(origin, direction, pdf); 
    132  
    133         return true; 
     113  Vector3 origin, direction;  
     114 
     115 
     116  float r[4]; 
     117  mHalton.GetNext(4, r); 
     118 
     119  r[0] *= mPreprocessor.mObjects.size()-1; 
     120  const int i = (int)r[0]; 
     121   
     122  Intersectable *object = mPreprocessor.mObjects[i]; 
     123   
     124  // take the remainder as a parameter over objects surface 
     125  r[0] -= (float)i; 
     126 
     127  Vector3 normal; 
     128 
     129  object->GetRandomSurfacePoint(r[0], r[1], origin, normal); 
     130   
     131  direction = Normalize(CosineRandomVector(r[2], r[3], normal)); 
     132   
     133  origin += 1e-2*direction; 
     134   
     135  // $$ jb the pdf is yet not correct for all sampling methods! 
     136  const float pdf = 1.0f; 
     137   
     138  ray = SimpleRay(origin, direction, OBJECT_DIRECTION_BASED_DISTRIBUTION, pdf); 
     139   
     140  return true; 
    134141} 
    135142 
     
    149156 
    150157        direction *= 1.0f / c; 
    151         ray = SimpleRay(origin, direction, pdf); 
     158        ray = SimpleRay(origin, direction, DIRECTION_BASED_DISTRIBUTION, pdf); 
    152159 
    153160        return true; 
     
    173180 
    174181        direction *= 1.0f / c; 
    175         ray = SimpleRay(origin, direction, pdf); 
     182        ray = SimpleRay(origin, direction, DIRECTION_BOX_BASED_DISTRIBUTION, pdf); 
    176183 
    177184        return true; 
     
    200207   
    201208  direction *= 1.0f / c; 
    202   ray = SimpleRay(origin, direction, pdf); 
     209  ray = SimpleRay(origin, direction, SPATIAL_BOX_BASED_DISTRIBUTION, pdf); 
    203210   
    204211  return true; 
     
    238245        point += direction * 0.001f; 
    239246 
    240         ray = SimpleRay(point, direction, pdf); 
     247        ray = SimpleRay(point, direction, REVERSE_OBJECT_BASED_DISTRIBUTION, pdf); 
    241248         
    242249        return true; 
     
    279286        //cout << "p: " << point << " "; 
    280287        direction *= 1.0f / c; 
    281         ray = SimpleRay(origin, direction, pdf); 
     288        ray = SimpleRay(origin, direction, VIEWCELL_BORDER_BASED_DISTRIBUTION, pdf); 
    282289 
    283290        //cout << "ray: " << ray.mOrigin << " " << ray.mDirection << endl; 
     
    352359        point += direction * 0.001f; 
    353360 
    354         ray = SimpleRay(point, direction, pdf); 
     361        ray = SimpleRay(point, direction, REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION, pdf); 
    355362         
    356363        return true; 
     
    388395        origin += direction * 0.001f; 
    389396 
    390         ray = SimpleRay(origin, direction, pdf); 
     397        ray = SimpleRay(origin, direction, VIEWSPACE_BORDER_BASED_DISTRIBUTION, pdf); 
    391398 
    392399        return true; 
     
    415422        mHalton.GetNext(4, r); 
    416423         
    417 #if 0 
    418 #if 0 
    419         r[0] = RandomValue(0,1); 
    420         r[1] = RandomValue(0,1); 
    421         r[2] = RandomValue(0,1); 
    422         r[3] = RandomValue(0,1); 
    423 #else 
    424         r[0] = mHalton.GetNumber(1); 
    425         r[1] = mHalton.GetNumber(2); 
    426         r[2] = mHalton.GetNumber(3); 
    427         r[3] = mHalton.GetNumber(4); 
    428         mHalton.GenerateNext(); 
    429 #endif 
    430 #endif 
    431424        origin = center + (radius*UniformRandomVector(r[0], r[1])); 
    432425        termination = center + (radius*UniformRandomVector(r[2], r[3])); 
    433426         
    434427        direction = termination - origin; 
    435         //direction = UniformRandomVector(); 
    436428         
    437429         
     
    458450         
    459451         
    460         ray = SimpleRay(origin, direction, pdf); 
     452        ray = SimpleRay(origin, direction, GLOBAL_LINES_DISTRIBUTION, pdf); 
    461453        ray.mType = Ray::GLOBAL_RAY; 
    462454        return true; 
     
    466458} 
    467459 
    468 } 
    469  
    470  
     460 
     461  // has to called before first usage 
     462void 
     463MixtureDistribution::Init() 
     464{ 
     465   
     466} 
     467   
     468  // Generate a new sample according to a mixture distribution 
     469bool 
     470MixtureDistribution::GenerateSample(SimpleRay &ray) 
     471{ 
     472 
     473  return false; 
     474} 
     475 
     476  // add contributions of the sample to the strategies 
     477void 
     478MixtureDistribution::UpdateContributions(VssRayContainer &vssRays) 
     479{ 
     480 
     481} 
     482 
     483} 
     484 
     485 
Note: See TracChangeset for help on using the changeset viewer.