00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #include "stdafx.h"
00027 #include "renderers/aggregatetest.h"
00028 #include "progressreporter.h"
00029 #include "scene.h"
00030 #include "paramset.h"
00031 #include "montecarlo.h"
00032 #include "primitive.h"
00033 #include "intersection.h"
00034 
00035 
00036 AggregateTest::AggregateTest(int niters,
00037         const vector<Reference<Primitive> > &p) {
00038     nIterations = niters;
00039     for (uint32_t i = 0; i < p.size(); ++i)
00040         p[i]->FullyRefine(primitives);
00041     for (uint32_t i = 0; i < primitives.size(); ++i)
00042         bboxes.push_back(primitives[i]->WorldBound());
00043 }
00044 
00045 
00046 AggregateTest *CreateAggregateTestRenderer(const ParamSet ¶ms,
00047     const vector<Reference<Primitive> > &primitives) {
00048     int niters = params.FindOneInt("niters", 100000);
00049     return new AggregateTest(niters, primitives);
00050 }
00051 
00052 
00053 void AggregateTest::Render(const Scene *scene) {
00054     RNG rng;
00055     ProgressReporter prog(nIterations, "Aggregate Test");
00056     
00057     BBox bbox = scene->WorldBound();
00058     bbox.Expand(bbox.pMax[bbox.MaximumExtent()] -
00059                 bbox.pMin[bbox.MaximumExtent()]);
00060     Point lastHit;
00061     float lastEps = 0.f;
00062     for (int i = 0; i < nIterations; ++i) {
00063         
00064 
00065         
00066         Point org(Lerp(rng.RandomFloat(), bbox.pMin.x, bbox.pMax.x),
00067                   Lerp(rng.RandomFloat(), bbox.pMin.y, bbox.pMax.y),
00068                   Lerp(rng.RandomFloat(), bbox.pMin.z, bbox.pMax.z));
00069         if ((rng.RandomUInt() % 4) == 0) org = lastHit;
00070 
00071         
00072         Vector dir = UniformSampleSphere(rng.RandomFloat(), rng.RandomFloat());
00073         if ((rng.RandomUInt() % 32) == 0)      dir.x = dir.y = 0.f;
00074         else if ((rng.RandomUInt() % 32) == 0) dir.x = dir.z = 0.f;
00075         else if ((rng.RandomUInt() % 32) == 0) dir.y = dir.z = 0.f;
00076 
00077         
00078         float eps = 0.f;
00079         if (rng.RandomFloat() < .25) eps = lastEps;
00080         else if (rng.RandomFloat() < .25) eps = 1e-3f;
00081         Ray rayAccel(org, dir, eps);
00082         Ray rayAll = rayAccel;
00083 
00084         
00085         Intersection isectAccel, isectAll;
00086         bool hitAccel = scene->Intersect(rayAccel, &isectAccel);
00087         bool hitAll = false;
00088         bool inconsistentBounds = false;
00089         for (uint32_t j = 0; j < primitives.size(); ++j) {
00090             if (bboxes[j].IntersectP(rayAll))
00091                 hitAll |= primitives[j]->Intersect(rayAll, &isectAll);
00092             else if (primitives[j]->Intersect(rayAll, &isectAll))
00093                 inconsistentBounds = true;
00094         }
00095 
00096         
00097         if (!inconsistentBounds &&
00098             ((hitAccel != hitAll) || (rayAccel.maxt != rayAll.maxt)))
00099             Warning("Disagreement: t accel %.16g [%a] t exhaustive %.16g [%a]\n"
00100                     "Ray: org [%a, %a, %a], dir [%a, %a, %a], mint = %a",
00101                     rayAccel.maxt, rayAll.maxt, rayAccel.maxt, rayAll.maxt,
00102                     rayAll.o.x, rayAll.o.y, rayAll.o.z,
00103                     rayAll.d.x, rayAll.d.y, rayAll.d.z, rayAll.mint);
00104         if (hitAll) {
00105             lastHit = rayAll(rayAll.maxt);
00106             lastEps = isectAll.rayEpsilon;
00107         }
00108         prog.Update();
00109     }
00110     prog.Done();
00111 }
00112 
00113 
00114 Spectrum AggregateTest::Li(const Scene *scene, const RayDifferential &ray,
00115         const Sample *sample, RNG &rng, MemoryArena &arena, Intersection *isect,
00116         Spectrum *T) const {
00117     return 0.f;
00118 }
00119 
00120 
00121 Spectrum AggregateTest::Transmittance(const Scene *scene,
00122         const RayDifferential &ray, const Sample *sample, RNG &rng,
00123         MemoryArena &arena) const {
00124     return 0.f;
00125 }
00126 
00127