virtual void CollectStats(StatsManager& stats, int depth) { StatsCounterVariable* leafNodes = stats.GetVariable<StatsCounterVariable>("Ray Engine", "Kd Leaf Nodes"); StatsDistributionVariable* leafPrims = stats.GetVariable<StatsDistributionVariable>("Ray Engine", "Kd Leaf Prims"); StatsDistributionVariable* leafDepth = stats.GetVariable<StatsDistributionVariable>("Ray Engine", "Kd Leaf Depth"); StatsCounterVariable* memory = stats.GetVariable<StatsCounterVariable>("Ray Engine", "Kd Memory"); leafNodes->Increment(); leafPrims->Value(prims.size()); leafDepth->Value(depth); memory->Increment(static_cast<double>(sizeof(*this) + prims.size()*sizeof(RayPrimitive*))); }
_TesselatedKdTreeLeafNode(const _PreallocatedArray<_TesselatedKdTreeBoxedPrimitive*>& p, int depth) { type = _KD_LEAF; prims.resize((uint32_t)p.size()); for(uint32_t i = 0; i < prims.size(); i ++) { prims[i] = p[i]->prim; } }
void TriangleTesselationCache::AddTriangles(const carray<Vec3f>& pos, const carray<Vec3f>& normal, const carray<Vec2f>& uv, const carray<Vec3i>& triangles) { // check if they have normals if(!normal.empty()) { this->pos = pos; this->normal = normal; if(!uv.empty()) this->uv = uv; else { this->uv.resize(pos.size()); this->uv.set(0.5); } this->triangles = triangles; } else { ElementOperations::UnshareForFaceNormals(pos, (!uv.empty())?uv:carray<Vec2f>(pos.size(),Vec2f(0,0)), ElementOperations::TriangleNormals(pos, triangles), triangles, this->pos, this->normal, this->uv, this->triangles); } _UpdateBBox(); }
void fft(carray& x, carray& roots) { int N = x.size(); if (N <= 1) return; carray even = x[slice(0, N/2, 2)]; carray odd = x[slice(1, N/2, 2)]; carray rs = roots[slice(0, N/2, 2)]; fft(even, rs); fft(odd, rs); for (int k = 0; k < N / 2; ++k) { auto t = roots[k] * odd[k]; x[k ] = even[k] + t; x[k+N/2] = even[k] - t; } }
void TriangleTesselationCache::AddQuads(const carray<Vec3f>& pos, const carray<Vec3f>& normal, const carray<Vec2f>& uv, const carray<Vec4i>& quads) { // check if they have normals if(!normal.empty()) { AddTriangles(pos, normal, uv, ElementOperations::QuadsToTriangles(quads)); } else { carray<Vec4i> newQuads; ElementOperations::UnshareForFaceNormals(pos, (!uv.empty())?uv:carray<Vec2f>(pos.size(),Vec2f(0,0)), ElementOperations::QuadNormals(pos, quads), quads, this->pos, this->normal, this->uv, newQuads); this->triangles = ElementOperations::QuadsToTriangles(newQuads); } _UpdateBBox(); }
shared_ptr<Image<shared_ptr<GatherTree> > > GatherForestBuilder::Build( shared_ptr<Scene> scene, shared_ptr<RayEngine> engine, uint32_t width, uint32_t height, uint32_t samples, carray<float> &timeInstantces, shared_ptr<ReportHandler> report /*= shared_ptr<ReportHandler>()*/ ) { shared_ptr<Image<shared_ptr<GatherTree> > > forest = shared_ptr<Image<shared_ptr<GatherTree> > >(new Image<shared_ptr<GatherTree> >(width, height)); StratifiedPathSamplerMT sampler; Vec2f pixelSize(1.0f/width, 1.0f/height); _tsample = timeInstantces.size(); if(report) report->beginActivity("Build Gather Forest"); for(uint32_t j = 0; j < height; j ++) { for(uint32_t i = 0; i < width; i ++) { vector<GatherPoint> points; sampler.BeginPixel(_tsample); for (uint32_t s = 0; s < samples; s++) { Vec2f puv = (Vec2f(Vec2i(i,j)) + sampler.Pixel()) * pixelSize; uint32_t ts = clamp<uint32_t>(static_cast<uint32_t>(sampler.Time() * _tsample), 0, _tsample - 1); Ray ray = scene->MainCamera()->GenerateRay(puv, sampler.Lens(), timeInstantces[ts]); Intersection isect; if(engine->Intersect(ray, &isect)) { GatherPoint point; point.position = isect.dp.P; point.normal = isect.dp.N; point.ms = isect.m; point.timeInst = s; points.push_back(point); } sampler.NextPixelSample(); } sampler.EndPixel(); shared_ptr<GatherTree> tree = _BuildTree(points); if(report) report->progress((float)j / (float)(height)); } } if(report) report->endActivity(); return forest; }
void Print(FILE* f, int depth) { for(int i = 0; i < depth*2; i ++) fputc(' ', f); fprintf(f, "leaf with %d\n", prims.size()); }