source: GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp @ 2060

Revision 2060, 20.4 KB checked in by bittner, 17 years ago (diff)

mutation parameters added

Line 
1#include "SamplingStrategy.h"
2#include "Ray.h"
3#include "Intersectable.h"
4#include "Preprocessor.h"
5#include "ViewCellsManager.h"
6#include "AxisAlignedBox3.h"
7#include "RssTree.h"
8#include "Vector2.h"
9#include "RndGauss.h"
10#include "Mutation.h"
11#include "Exporter.h"
12#include "Environment.h"
13
14#ifdef GTP_INTERNAL
15#include "ArchModeler2MLRT.hxx"
16#endif
17
18namespace GtpVisibilityPreprocessor {
19
20#define MUTATION_USE_CDF 0
21
22  //#define SIL_TERMINATION_MUTATION_PROB 0.8f
23
24#define EVALUATE_MUTATION_STATS 1
25
26  //#define Q_SEARCH_STEPS 3
27
28#define SORT_RAY_ENTRIES 1
29
30// use avg ray contribution as importance
31// if 0 the importance is evaluated from the succ of mutations
32#define USE_AVG_CONTRIBUTION 1
33
34MutationBasedDistribution::RayEntry &
35MutationBasedDistribution::GetEntry(const int index)
36{
37#if SORT_RAY_ENTRIES
38  return mRays[index];
39#else
40  return mRays[(mBufferStart+index)%mRays.size()];
41#endif
42}
43
44void
45MutationBasedDistribution::Update(VssRayContainer &vssRays)
46{
47  //  for (int i=0; i < mRays.size(); i++)
48  //    cout<<mRays[i].mMutations<<" ";
49  //  cout<<endl;
50  cerr<<"Muattion update..."<<endl;
51  cerr<<"rays = "<<mRays.size()<<endl;
52  if (mRays.size()) {
53        cerr<<"Oversampling factors = "<<
54          GetEntry(0).mMutations<<" "<<
55          GetEntry(1).mMutations<<" "<<
56          GetEntry(2).mMutations<<" "<<
57          GetEntry(3).mMutations<<" "<<
58          GetEntry(4).mMutations<<" "<<
59          GetEntry(5).mMutations<<" ... "<<
60          GetEntry(mRays.size()-6).mMutations<<" "<<
61          GetEntry(mRays.size()-5).mMutations<<" "<<
62          GetEntry(mRays.size()-4).mMutations<<" "<<
63          GetEntry(mRays.size()-3).mMutations<<" "<<
64          GetEntry(mRays.size()-2).mMutations<<" "<<
65          GetEntry(mRays.size()-1).mMutations<<endl;
66  }
67  int contributingRays = 0;
68
69  int mutationRays = 0;
70  int dummyNcMutations = 0;
71  int dummyCMutations = 0;
72
73  int reverseCandidates = 0;
74
75#if 0
76  sort(mRays.begin(), mRays.end());
77  // reset the start of the buffer
78  mBufferStart = 0;
79#endif
80
81  for (int i=0; i < vssRays.size(); i++) {
82        if (vssRays[i]->mPvsContribution) {
83          // reset the counter of unsuccsseful mutation for a generating ray (if it exists)
84          if (vssRays[i]->mDistribution == MUTATION_BASED_DISTRIBUTION &&
85                  vssRays[i]->mGeneratorId != -1
86                  ) {
87                mRays[vssRays[i]->mGeneratorId].mUnsuccessfulMutations = 0;
88#if EVALUATE_MUTATION_STATS
89                mutationRays++;
90               
91                Intersectable *newObject = vssRays[i]->mTerminationObject;
92
93                Intersectable *oldObject =mRays[vssRays[i]->mGeneratorId].mRay->mTerminationObject;
94               
95                if (oldObject == newObject)
96                  dummyCMutations++;
97#endif
98          }
99          contributingRays++;
100          if (mRays.size() < mMaxRays) {
101                VssRay *newRay = new VssRay(*vssRays[i]);
102                // add this ray
103                newRay->Ref();
104                mRays.push_back(RayEntry(newRay));
105          } else {
106                // unref the old ray
107                *mRays[mBufferStart].mRay = *vssRays[i];
108                mRays[mBufferStart].mMutations = 0;
109                mRays[mBufferStart].mUnsuccessfulMutations = 0;
110                mRays[mBufferStart].ResetReverseMutation();
111                //              mRays[mBufferStart] = RayEntry(newRay);
112                mBufferStart++;
113                if (mBufferStart >= mMaxRays)
114                  mBufferStart = 0;
115          }
116        } else {
117          if (vssRays[i]->mDistribution == MUTATION_BASED_DISTRIBUTION &&
118                  vssRays[i]->mGeneratorId != -1
119                  ) {
120                // check whether not to store a new backward mutation candidate
121                VssRay *oldRay = mRays[vssRays[i]->mGeneratorId].mRay;
122                VssRay *newRay = vssRays[i];
123
124
125                Intersectable *oldObject = oldRay->mTerminationObject;
126               
127
128                if (!mRays[newRay->mGeneratorId].HasReverseMutation()) {
129                  if (DotProd(oldRay->GetDir(), newRay->GetDir()) > 0.0f) {
130                  float oldDist = Magnitude(oldRay->mTermination - newRay->mOrigin);
131                  float newDist = Magnitude(newRay->mTermination - newRay->mOrigin);
132                 
133                  if (newDist < oldDist - oldObject->GetBox().Radius()*mReverseSamplesDistance) {
134                        Vector3 origin, termination;
135                        if (ComputeReverseMutation(*oldRay, *newRay, origin, termination)) {
136                          mRays[newRay->mGeneratorId].SetReverseMutation(origin, termination);
137                        }
138                       
139                        reverseCandidates++;
140                        //mReverseCandidates
141                  }
142                  }
143                }
144#if EVALUATE_MUTATION_STATS
145                mutationRays++;
146               
147                Intersectable *newObject = vssRays[i]->mTerminationObject;
148
149
150                if (oldObject == newObject)
151                  dummyNcMutations++;
152#endif
153          }
154        }
155  }
156 
157  if (mutationRays) {
158        cout<<"Mutated rays:"<<mutationRays<<endl;
159        cout<<"Dummy mutations ratio:"<<100.0f*(dummyCMutations + dummyNcMutations)/
160          (float)mutationRays<<"%"<<endl;
161        cout<<"Dummy NC mutations ratio:"<<100.0f*dummyNcMutations/(float)mutationRays<<"%"<<endl;
162        cout<<"Dummy C mutations ratio:"<<100.0f*dummyCMutations/(float)mutationRays<<"%"<<endl;
163        cout<<"Reverse candidates:"<<reverseCandidates<<endl;
164  }
165 
166  float pContributingRays = contributingRays/(float)vssRays.size();
167 
168  cout<<"Percentage of contributing rays:"<<pContributingRays<<endl;
169 
170  if (mUseUnsuccCountImportance) {
171        // use unsucc mutation samples as feedback on importance
172        for (int i=0; i < mRays.size(); i++) {
173          const float  minImportance = 0.1f;
174          const int minImportanceSamples = 20;
175          mRays[i].mImportance = minImportance +
176                (1-minImportance)*exp(-3.0f*mRays[i].mUnsuccessfulMutations/minImportanceSamples);
177        }
178  } else {
179        float importance = 1.0f;
180        if (mUsePassImportance)
181          importance = 1.0f/(pContributingRays + 1e-5);
182        // set this values for last contributingRays
183        int index = mBufferStart - 1;
184       
185        for (int i=0; i < contributingRays; i++, index--) {
186          if (index < 0)
187                index = mRays.size()-1;
188          mRays[index].mImportance = importance;
189        }
190  }
191 
192#if SORT_RAY_ENTRIES
193  long t1 = GetTime();
194  sort(mRays.begin(), mRays.end());
195  // reset the start of the buffer
196  mBufferStart = 0;
197  mLastIndex = mRays.size();
198  cout<<"Mutation candidates sorted in "<<TimeDiff(t1, GetTime())<<" ms."<<endl;
199#endif
200 
201#if MUTATION_USE_CDF
202  // compute cdf
203  mRays[0].mCdf = mRays[0].mImportance/(mRays[0].mMutations+1);
204  for (int i=1; i < mRays.size(); i++)
205        mRays[i].mCdf = mRays[i-1].mCdf + mRays[i].mImportance/(mRays[i].mMutations+1);
206 
207  float scale = 1.0f/mRays[i-1].mCdf;
208  for (i=0; i < mRays.size(); i++) {
209        mRays[i].mCdf *= scale;
210  }
211#endif
212 
213  cout<<"Importance = "<<
214        GetEntry(0).mImportance<<" "<<
215        GetEntry(mRays.size()-1).mImportance<<endl;
216
217  cout<<"Sampling factor = "<<
218        GetEntry(0).GetSamplingFactor()<<" "<<
219        GetEntry(mRays.size()-1).GetSamplingFactor()<<endl;
220
221  cerr<<"Mutation update done."<<endl;
222}
223
224
225Vector3
226MutationBasedDistribution::ComputeOriginMutation(const VssRay &ray,
227                                                                                                 const Vector3 &U,
228                                                                                                 const Vector3 &V,
229                                                                                                 const Vector2 vr2,
230                                                                                                 const float radius
231                                                                                                 )
232{
233#if 0
234  Vector3 v;
235  if (d.DrivingAxis() == 0)
236        v = Vector3(0, r[0]-0.5f, r[1]-0.5f);
237  else
238        if (d.DrivingAxis() == 1)
239          v = Vector3(r[0]-0.5f, 0, r[1]-0.5f);
240        else
241          v = Vector3(r[0]-0.5f, r[1]-0.5f, 0);
242  return v*(2*radius);
243#endif
244#if 0
245  return (U*(r[0] - 0.5f) + V*(r[1] - 0.5f))*(2*radius);
246#endif
247
248
249  // Output random variable
250  Vector2 gaussvec2;
251 
252  // Here we apply transform to gaussian, so 2D bivariate
253  // normal distribution
254  //  float sigma = ComputeSigmaFromRadius(radius);
255  float sigma = radius;
256  GaussianOn2D(vr2,
257                           sigma, // input
258                           gaussvec2);  // output
259
260       
261    // Here we tranform the point correctly to 3D space using base
262    // vectors of the 3D space defined by the direction
263    Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V;
264       
265        //      cout<<shift<<endl;
266        return shift;
267}
268
269Vector3
270MutationBasedDistribution::ComputeTerminationMutation(const VssRay &ray,
271                                                                                                          const Vector3 &U,
272                                                                                                          const Vector3 &V,
273                                                                                                          const Vector2 vr2,
274                                                                                                          const float radius
275                                                                                                          )
276{
277#if 0
278  Vector3 v;
279  // mutate the termination
280  if (d.DrivingAxis() == 0)
281        v = Vector3(0, r[2]-0.5f, r[3]-0.5f);
282  else
283        if (d.DrivingAxis() == 1)
284          v = Vector3(r[2]-0.5f, 0, r[3]-0.5f);
285        else
286          v = Vector3(r[2]-0.5f, r[3]-0.5f, 0);
287 
288  //   Vector3 nv;
289 
290  //   if (Magnitude(v) > Limits::Small)
291  //    nv = Normalize(v);
292  //   else
293  //    nv = v;
294 
295  //  v = nv*size + v*size;
296
297  return v*(4.0f*radius);
298#endif
299#if 0
300  return (U*(vr2.xx - 0.5f) + V*(vr2.yy - 0.5f))*(4.0f*radius);
301#endif
302  Vector2 gaussvec2;
303#if 1
304  float sigma = radius;
305  GaussianOn2D(vr2,
306                           sigma, // input
307                           gaussvec2);  // output
308  Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V;
309  //    cout<<shift<<endl;
310  return shift;
311#endif
312#if 0
313  // Here we estimate standard deviation (sigma) from radius
314  float sigma = 1.1f*ComputeSigmaFromRadius(radius);
315  Vector3 vr3(vr2.xx, vr2.yy, RandomValue(0,1));
316  PolarGaussianOnDisk(vr3,
317                                          sigma,
318                                          radius, // input
319                                          gaussvec2); // output
320 
321  // Here we tranform the point correctly to 3D space using base
322  // vectors of the 3D space defined by the direction
323  Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V;
324 
325  //    cout<<shift<<endl;
326  return shift;
327#endif
328}
329
330bool
331MutationBasedDistribution::ComputeReverseMutation(
332                                                                                                  const VssRay &oldRay,
333                                                                                                  const VssRay &newRay,
334                                                                                                  Vector3 &origin,
335                                                                                                  Vector3 &termination
336                                                                                                  )
337{
338  // first reconstruct the termination point
339  Vector3 oldDir = Normalize(oldRay.GetDir());
340  Plane3 oldPlane(oldDir, oldRay.mTermination);
341 
342  termination = oldPlane.FindIntersection(newRay.mOrigin,
343                                                                                  newRay.mTermination);
344 
345  // now find the new origin of the ray by casting ray backward from the termination and termining
346  // silhouette point with respect to the occluding object (object containing the newRay termination)
347
348  Plane3 newPlane(oldDir, newRay.mTermination);
349
350  Vector3 oldPivot = newPlane.FindIntersection(oldRay.mOrigin,
351                                                                                           oldRay.mTermination);
352
353  Vector3 newPivot = newRay.mTermination;
354  Vector3 line = 2.0f*(oldPivot - newPivot);
355
356  Intersectable *occluder = newRay.mTerminationObject;
357 
358  AxisAlignedBox3 box = occluder->GetBox();
359  box.Scale(2.0f);
360 
361  const int packetSize = 4;
362  static int hit_triangles[packetSize];
363  static float dist[packetSize];
364  static Vector3 dirs[packetSize];
365  static Vector3 shifts[packetSize];
366  // now find the silhouette along the line
367  int i;
368  float left = 0.0f;
369  float right = 1.0f;
370  // cast rays to find silhouette ray
371  for (int j=0; j < mSilhouetteSearchSteps; j++) {
372        for (i=0; i < packetSize; i++) {
373          float r = left + (i+1)*(right-left)/(packetSize+1);
374          shifts[i] = r*line;
375          dirs[i] = Normalize(newPivot + shifts[i] - termination );
376          mlrtaStoreRayASEye4(&termination.x,
377                                                  &dirs[i].x,
378                                                  i);
379        }
380       
381        mlrtaTraverseGroupASEye4(&box.Min().x,
382                                                         &box.Max().x,
383                                                         hit_triangles,
384                                                         dist);
385       
386        for (i=0; i < packetSize; i++) {
387          if (hit_triangles[i] == -1) {
388                // break on first passing ray
389                break;
390          }
391        }
392        float rr = left + (i+1)*(right-left)/(packetSize+1);
393        float rl = left + i*(right-left)/(packetSize+1);
394        left = rl;
395        right = rr;
396  }
397
398  float t = right;
399  if (right==1.0f)
400        return false;
401 
402  if (i == packetSize)
403        origin = newPivot + right*line;
404  else
405        origin = newPivot + shifts[i];
406
407  if (0) {
408       
409        static VssRayContainer rRays;
410        static int counter = 0;
411        char filename[256];
412
413        if (counter < 50) {
414          sprintf(filename, "reverse_rays_%03d.x3d", counter++);
415         
416          VssRay tRay(origin, termination, NULL, NULL);
417          rRays.push_back((VssRay *)&oldRay);
418          rRays.push_back((VssRay *)&newRay);
419          rRays.push_back(&tRay);
420         
421          Exporter *exporter = NULL;
422          exporter = Exporter::GetExporter(filename);
423         
424          exporter->SetFilled();
425         
426          Intersectable *occludee =
427                oldRay.mTerminationObject;
428         
429          exporter->SetForcedMaterial(RgbColor(0,0,1));
430          exporter->ExportIntersectable(occluder);
431          exporter->SetForcedMaterial(RgbColor(0,1,0));
432          exporter->ExportIntersectable(occludee);
433          exporter->ResetForcedMaterial();
434         
435          exporter->SetWireframe();
436         
437         
438          exporter->ExportRays(rRays, RgbColor(1, 0, 0));
439          delete exporter;
440          rRays.clear();
441        }
442  }
443
444
445 
446  return true;
447 
448  // now the origin and termination is swapped compred to the generator ray
449  // swap(origin, termination);???
450  // -> perhaps not neccessary as the reverse mutation wil only be used once!
451}
452
453Vector3
454MutationBasedDistribution::ComputeSilhouetteTerminationMutation(const VssRay &ray,
455                                                                                                                                const Vector3 &origin,
456                                                                                                                                const AxisAlignedBox3 &box,
457                                                                                                                                const Vector3 &U,
458                                                                                                                                const Vector3 &V,
459                                                                                                                                const float radius
460                                                                                                                                )
461{
462  const int packetSize = 4;
463  static int hit_triangles[packetSize];
464  static float dist[packetSize];
465  static Vector3 dirs[packetSize];
466  static Vector3 shifts[packetSize];
467  // mutate the
468  float alpha = RandomValue(0.0f, 2.0f*M_PI);
469  //float alpha = vr2.x*2.0f*M_PI;
470 
471  // direction along which we will mutate the ray
472  Vector3 line = sin(alpha)*U + cos(alpha)*V;
473 
474  //  cout<<line<<endl;
475  // create 16 rays along the selected dir
476  int i;
477  float left = 0.0f;
478  float right = radius;
479  // cast rays to find silhouette ray
480  for (int j=0; j < mSilhouetteSearchSteps; j++) {
481        for (i=0; i < packetSize; i++) {
482          float r = left + (i+1)*(right-left)/(packetSize+1);
483          shifts[i] = r*line;
484          dirs[i] = Normalize(ray.mTermination + shifts[i] - origin );
485          mlrtaStoreRayASEye4(&origin.x,
486                                                  &dirs[i].x,
487                                                  i);
488        }
489       
490        mlrtaTraverseGroupASEye4(&box.Min().x,
491                                                         &box.Max().x,
492                                                         hit_triangles,
493                                                         dist);
494       
495        for (i=0; i < packetSize; i++) {
496          if (hit_triangles[i] == -1) {
497                //        if (hit_triangles[i] == -1 || !box.IsInside(origin + dist[i]*dirs[i])) {
498                // break on first passing ray
499                break;
500          }
501        }
502        float rr = left + (i+1)*(right-left)/(packetSize+1);
503        float rl = left + i*(right-left)/(packetSize+1);
504        left = rl;
505        right = rr;
506  }
507 
508  if (i == packetSize) {
509        //      cerr<<"Warning: hit the same box here should never happen!"<<endl;
510        // shift the ray even a bit more
511        //cout<<"W"<<i<<endl;
512        //      return (RandomValue(1.0f, 1.5f)*radius)*line;
513        return right*line;
514  }
515 
516  //  cout<<i<<endl;
517  return shifts[i];
518}
519
520
521bool
522MutationBasedDistribution::GenerateSample(SimpleRay &sray)
523{
524
525  if (mRays.size() == 0) {
526        float rr[5];
527        // use direction based distribution
528        Vector3 origin, direction;
529        static HaltonSequence halton;
530       
531        halton.GetNext(5, rr);
532        mPreprocessor.mViewCellsManager->GetViewPoint(origin,
533                                                                                                  Vector3(rr[0], rr[1], rr[2]));
534       
535
536        direction = UniformRandomVector(rr[3], rr[4]);
537       
538        const float pdf = 1.0f;
539        sray = SimpleRay(origin, direction, MUTATION_BASED_DISTRIBUTION, pdf);
540        sray.mGeneratorId = -1;
541
542        return true;
543  }
544
545  int index;
546
547#if !MUTATION_USE_CDF
548#if SORT_RAY_ENTRIES
549  index = mLastIndex - 1;
550  if (index < 0 || index >= mRays.size()-1) {
551        index = mRays.size() - 1;
552  } else
553        if (
554                mRays[index].GetSamplingFactor() >= mRays[mLastIndex].GetSamplingFactor()) {
555          // make another round
556
557          //      cout<<"R2"<<endl;
558          //      cout<<mLastIndex<<endl;
559          //      cout<<index<<endl;
560          index = mRays.size() - 1;
561        }
562#else
563  // get tail of the buffer
564  index = (mLastIndex+1)%mRays.size();
565  if (mRays[index].GetSamplingFactor() >
566          mRays[mLastIndex].GetSamplingFactor()) {
567        // search back for index where this is valid
568        index = (mLastIndex - 1 + mRays.size())%mRays.size();
569        for (int i=0; i < mRays.size(); i++) {
570         
571          //      if (mRays[index].mMutations > mRays[mLastIndex].mMutations)
572          //            break;
573          if (mRays[index].GetSamplingFactor() >
574                  mRays[mLastIndex].GetSamplingFactor() )
575                break;
576          index = (index - 1 + mRays.size())%mRays.size();
577        }
578        // go one step back
579        index = (index+1)%mRays.size();
580  }
581#endif
582#else
583  static HaltonSequence iHalton;
584  iHalton.GetNext(1, rr);
585  //rr[0] = RandomValue(0,1);
586  // use binary search to find index with this cdf
587  int l=0, r=mRays.size()-1;
588  while(l<r) {
589        int i = (l+r)/2;
590        if (rr[0] < mRays[i].mCdf )
591          r = i;
592        else
593          l = i+1;
594  }
595  index = l;
596  //  if (rr[0] >= mRays[r].mCdf)
597  //    index = r;
598  //  else
599  //    index = l;
600       
601       
602#endif
603  //  cout<<index<<" "<<rr[0]<<" "<<mRays[index].mCdf<<" "<<mRays[(index+1)%mRays.size()].mCdf<<endl;
604
605  mLastIndex = index;
606  //  Debug<<index<<" "<<mRays[index].GetSamplingFactor()<<endl;
607 
608  if (mRays[index].HasReverseMutation()) {
609        //cout<<"R "<<mRays[index].mutatedOrigin<<" "<<mRays[index].mutatedTermination<<endl;
610        sray = SimpleRay(mRays[index].mutatedOrigin,
611                                         Normalize(mRays[index].mutatedTermination - mRays[index].mutatedOrigin),
612                                         MUTATION_BASED_DISTRIBUTION, 1.0f);
613        sray.mGeneratorId = index;
614        mRays[index].ResetReverseMutation();
615        mRays[index].mMutations++;
616        mRays[index].mUnsuccessfulMutations++;
617
618        return true;
619  }
620 
621  return GenerateMutation(index, sray);
622}
623
624
625
626
627
628bool
629MutationBasedDistribution::GenerateMutationCandidate(const int index,
630                                                                                                         SimpleRay &sray,
631                                                                                                         Intersectable *object,
632                                                                                                         const AxisAlignedBox3 &box
633                                                                                                         )
634{
635  float rr[4];
636
637  VssRay *ray = mRays[index].mRay;
638
639  //  rr[0] = RandomValue(0.0f,0.99999f);
640  //  rr[1] = RandomValue(0.0f,0.99999f);
641  //  rr[2] = RandomValue(0.0f,0.99999f);
642  //  rr[3] = RandomValue(0.0f,0.99999f);
643 
644  // mutate the origin
645  Vector3 d = ray->GetDir();
646 
647  float objectRadius = box.Radius();
648  //  cout<<objectRadius<<endl;
649  if (objectRadius < Limits::Small)
650        return false;
651 
652  // Compute right handed coordinate system from direction
653  Vector3 U, V;
654  Vector3 nd = Normalize(d);
655  nd.RightHandedBase(U, V);
656 
657  Vector3 origin = ray->mOrigin;
658  Vector3 termination = ray->mTermination; //box.Center(); //ray->mTermination; //box.Center();
659
660 
661  // use probabilitistic approach to decide for the type of mutation
662  float a = RandomValue(0.0f,1.0f);
663
664  if (mUseSilhouetteSamples && a < mSilhouetteProb) {
665        termination += ComputeSilhouetteTerminationMutation(*ray,
666                                                                                                                origin,
667                                                                                                                box,
668                                                                                                                U, V,
669                                                                                                                2.0f*objectRadius);
670  } else {
671        mRays[index].mHalton.GetNext(4, rr);
672        // fuzzy random mutation
673        origin += ComputeOriginMutation(*ray, U, V,
674                                                                        Vector2(rr[0], rr[1]),
675                                                                        mMutationRadiusOrigin*objectRadius);
676       
677        termination += ComputeTerminationMutation(*ray, U, V,
678                                                                                          Vector2(rr[2], rr[3]),
679                                                                                          mMutationRadiusTermination*objectRadius);
680  }
681
682  Vector3 direction = termination - origin;
683 
684  if (Magnitude(direction) < Limits::Small)
685        return false;
686 
687  // shift the origin a little bit
688  origin += direction*0.5f;
689 
690  direction.Normalize();
691 
692  // $$ jb the pdf is yet not correct for all sampling methods!
693  const float pdf = 1.0f;
694 
695  sray = SimpleRay(origin, direction, MUTATION_BASED_DISTRIBUTION, pdf);
696  sray.mGeneratorId = index;
697
698  return true;
699}
700
701bool
702MutationBasedDistribution::GenerateMutation(const int index, SimpleRay &sray)
703{
704  VssRay *ray = mRays[index].mRay;
705
706  Intersectable *object = ray->mTerminationObject;
707 
708  AxisAlignedBox3 box = object->GetBox();
709 
710  if (GenerateMutationCandidate(index, sray, object, box)) {
711    mRays[index].mMutations++;
712        mRays[index].mUnsuccessfulMutations++;
713
714        return true;
715  }
716  return false;
717}
718 
719
720
721MutationBasedDistribution::MutationBasedDistribution(Preprocessor &preprocessor
722                                                                                                         ) :
723  SamplingStrategy(preprocessor)
724{
725  mType = MUTATION_BASED_DISTRIBUTION;
726  mBufferStart = 0;
727  mLastIndex = 0;
728
729  Environment::GetSingleton()->GetIntValue("Mutation.bufferSize",
730                                                                                   mMaxRays);
731 
732  mRays.reserve(mMaxRays);
733 
734  Environment::GetSingleton()->GetFloatValue("Mutation.radiusOrigin",
735                                                                                         mMutationRadiusOrigin);
736
737  Environment::GetSingleton()->GetFloatValue("Mutation.radiusTermination",
738                                                                                         mMutationRadiusTermination);
739 
740  Environment::GetSingleton()->GetBoolValue("Mutation.useReverseSamples",
741                                                                                        mUseReverseSamples);
742 
743  Environment::GetSingleton()->GetFloatValue("Mutation.reverseSamplesDistance",
744                                                                                         mReverseSamplesDistance);
745 
746 
747  Environment::GetSingleton()->GetBoolValue("Mutation.useSilhouetteSamples",
748                                                                                        mUseSilhouetteSamples);
749
750  Environment::GetSingleton()->GetIntValue("Mutation.silhouetteSearchSteps",
751                                                                                   mSilhouetteSearchSteps);
752 
753  Environment::GetSingleton()->GetFloatValue("Mutation.silhouetteProb",
754                                                                                         mSilhouetteProb);
755
756
757  Environment::GetSingleton()->GetBoolValue("Mutation.usePassImportance",
758                                                                                        mUsePassImportance);
759 
760
761  Environment::GetSingleton()->GetBoolValue("Mutation.useUnsuccCountImportance",
762                                                                                        mUseUnsuccCountImportance);
763
764 
765 
766}
767
768
769
770}
Note: See TracBrowser for help on using the repository browser.