Skip to content

Commit

Permalink
[#88] : Added kd tree implementation based on PBR
Browse files Browse the repository at this point in the history
  • Loading branch information
ange-yaghi committed Sep 3, 2019
1 parent 7d9e407 commit b8ecfbe
Show file tree
Hide file tree
Showing 24 changed files with 1,229 additions and 23 deletions.
11 changes: 8 additions & 3 deletions demos/box_city_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ void manta_demo::boxCityDemo(int samplesPerPixel, int resolutionX, int resolutio
octree.initialize(100.0, math::loadVector(0, 0, 0));
octree.analyze(&boxCity, 25);

octree.writeToObjFile("../../workspace/test_results/box_city_octree.obj", nullptr);
KDTree kdtree;
kdtree.initialize(100.0, math::constants::Zero);
kdtree.analyze(&boxCity, 4);

kdtree.writeToObjFile("../../workspace/test_results/box_city_kdtree.obj");

std::cout << "Scene vertices/faces: " << boxCity.getVertexCount() << "/" << boxCity.getFaceCount() << std::endl;
std::cout << "Octree faces: " << octree.countFaces() << std::endl;
Expand All @@ -78,7 +82,7 @@ void manta_demo::boxCityDemo(int samplesPerPixel, int resolutionX, int resolutio
constexpr bool useOctree = true;

SceneObject *boxCityObject = scene.createSceneObject();
if (useOctree) boxCityObject->setGeometry(&octree);
if (useOctree) boxCityObject->setGeometry(&kdtree);
else boxCityObject->setGeometry(&boxCity);
boxCityObject->setDefaultMaterial(&wallMaterial);

Expand All @@ -101,7 +105,7 @@ void manta_demo::boxCityDemo(int samplesPerPixel, int resolutionX, int resolutio
math::Vector cameraPos = math::loadVector(15.4473, 4.59977, 13.2961);
math::Vector target = math::loadVector(2.63987, 3.55547, 2.42282);

constexpr bool regularCamera = false;
constexpr bool regularCamera = true;

CameraRayEmitterGroup *group;

Expand Down Expand Up @@ -192,6 +196,7 @@ void manta_demo::boxCityDemo(int samplesPerPixel, int resolutionX, int resolutio
boxCity.destroy();
boxCityObj.destroy();
octree.destroy();
kdtree.destroy();

std::cout << "Standard allocator memory leaks: " << StandardAllocator::Global()->getLedger() << ", " << StandardAllocator::Global()->getCurrentUsage() << std::endl;
}
24 changes: 15 additions & 9 deletions demos/complex_room_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@ void manta_demo::complexRoomDemo(int samplesPerPixel, int resolutionX, int resol
sampleRay.setDirection(dir);
sampleRay.setSource(cameraPos);

Octree stressSpidersOctree;
stressSpidersOctree.initialize(32, math::constants::Zero);
stressSpidersOctree.analyze(&stressSpiders, 10); //25
stressSpidersOctree.writeToObjFile("../../workspace/test_results/complex_room_octree.obj", &sampleRay);
//Octree stressSpidersOctree;
//stressSpidersOctree.initialize(32, math::constants::Zero);
//stressSpidersOctree.analyze(&stressSpiders, 10); //25

std::cout << "Octree faces: " << stressSpidersOctree.countFaces() << std::endl;
std::cout << "Leaf count: " << stressSpidersOctree.countLeaves() << std::endl;
KDTree kdtree;
kdtree.initialize(100.0, math::constants::Zero);
kdtree.analyze(&stressSpiders, 4);

//std::cout << "Octree faces: " << stressSpidersOctree.countFaces() << std::endl;
//std::cout << "Leaf count: " << stressSpidersOctree.countLeaves() << std::endl;

SpherePrimitive outdoorTopLightGeometry;
outdoorTopLightGeometry.setRadius((math::real)10.0);
Expand All @@ -139,7 +142,7 @@ void manta_demo::complexRoomDemo(int samplesPerPixel, int resolutionX, int resol
// Create scene objects
SceneObject *stressSpidersObject = scene.createSceneObject();
if (useOctree) {
stressSpidersObject->setGeometry(&stressSpidersOctree);
stressSpidersObject->setGeometry(&kdtree);
}
else {
stressSpidersObject->setGeometry(&stressSpiders);
Expand Down Expand Up @@ -179,6 +182,8 @@ void manta_demo::complexRoomDemo(int samplesPerPixel, int resolutionX, int resol
GridSampler sampler;
sampler.setGridWidth(3);

RandomSampler randomSampler;

if (regularCamera) {
StandardCameraRayEmitterGroup *camera = new StandardCameraRayEmitterGroup;
//camera->setSamplingWidth(3);
Expand All @@ -190,7 +195,7 @@ void manta_demo::complexRoomDemo(int samplesPerPixel, int resolutionX, int resol
camera->setResolutionX(resolutionX);
camera->setResolutionY(resolutionY);
camera->setSampleCount(samplesPerPixel);
camera->setSampler(&sampler);
camera->setSampler(&randomSampler);

group = camera;
}
Expand Down Expand Up @@ -257,8 +262,9 @@ void manta_demo::complexRoomDemo(int samplesPerPixel, int resolutionX, int resol
sceneBuffer.destroy();
rayTracer.destroy();

stressSpidersOctree.destroy();
//stressSpidersOctree.destroy();
stressSpiders.destroy();
kdtree.destroy();

std::cout << "Standard allocator memory leaks: " << StandardAllocator::Global()->getLedger() << ", " << StandardAllocator::Global()->getCurrentUsage() << std::endl;
}
1 change: 1 addition & 0 deletions demos/demos.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <random_sampler.h>
#include <simple_sampler.h>
#include <standard_camera_ray_emitter_group.h>
#include <kd_tree.h>

namespace manta_demo {

Expand Down
8 changes: 4 additions & 4 deletions demos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
using namespace manta_demo;

int main() {
//complexRoomDemo(1, 1024 * 2, 768 * 2);
//complexRoomDemo(1000, 1024 * 2, 768 * 2);
//penDemo(500, 1024 * 2, 768 * 2);
//stressSpidersDemo(1, 1024 * 2, 768 * 2); // 871 samples
stressSpidersDemo(1, 1024 * 2, 768 * 2); // 871 samples
//simpleRoomDemo(1, 1024*2, 768*2); //1024, 768
//boxCityDemo(1, 1024*2, 768*2);
//boxCityDemo(100, 1024*2, 768*2);
//teapotDemo(1, 500, 500);
teapotLampDemo(100, 1024*2, 768*2); // 10 for issue replication 1024, 768
//teapotLampDemo(2000, 1024*2, 768*2); // 10 for issue replication 1024, 768
//cubeTestDemo(1, 1024, 768);
//blocksDemo(40, 1024 * 2, 768 * 2); // 10 for issue replication 1024, 768

Expand Down
7 changes: 6 additions & 1 deletion demos/pen_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ void manta_demo::penDemo(int samplesPerPixel, int resolutionX, int resolutionY)
penOctree.analyze(&pen, 25);
penOctree.writeToObjFile("../../workspace/test_results/pen_octree.obj", nullptr);

KDTree kdtree;
kdtree.initialize(150, math::constants::Zero);
kdtree.analyze(&pen, 4);

math::real lightRadius = 10.0;

SpherePrimitive light1Geometry;
Expand All @@ -102,7 +106,7 @@ void manta_demo::penDemo(int samplesPerPixel, int resolutionX, int resolutionY)
// Create scene objects
SceneObject *penObject = scene.createSceneObject();
if (useOctree) {
penObject->setGeometry(&penOctree);
penObject->setGeometry(&kdtree);
}
else {
penObject->setGeometry(&pen);
Expand Down Expand Up @@ -237,6 +241,7 @@ void manta_demo::penDemo(int samplesPerPixel, int resolutionX, int resolutionY)
pen.destroy();

penOctree.destroy();
kdtree.destroy();

std::cout << "Standard allocator memory leaks: " << StandardAllocator::Global()->getLedger() << ", " << StandardAllocator::Global()->getCurrentUsage() << std::endl;
}
9 changes: 7 additions & 2 deletions demos/stress_spiders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ void manta_demo::stressSpidersDemo(int samplesPerPixel, int resolutionX, int res
stressSpidersOctree.analyze(&stressSpiders, 25);
//stressSpidersOctree.writeToObjFile("../../workspace/test_results/stress_spiders_octree.obj", nullptr);

KDTree kdtree;
kdtree.initialize(32.0, math::constants::Zero);
kdtree.analyze(&stressSpiders, 4);

SpherePrimitive outdoorTopLightGeometry;
outdoorTopLightGeometry.setRadius((math::real)10.0);
//outdoorTopLightGeometry.setRadius((math::real)20.0);
Expand All @@ -63,7 +67,7 @@ void manta_demo::stressSpidersDemo(int samplesPerPixel, int resolutionX, int res
// Create scene objects
SceneObject *stressSpidersObject = scene.createSceneObject();
if (useOctree) {
stressSpidersObject->setGeometry(&stressSpidersOctree);
stressSpidersObject->setGeometry(&kdtree);
}
else {
stressSpidersObject->setGeometry(&stressSpiders);
Expand All @@ -90,7 +94,7 @@ void manta_demo::stressSpidersDemo(int samplesPerPixel, int resolutionX, int res
up = math::normalize(up);

// Create the camera
constexpr bool regularCamera = false;
constexpr bool regularCamera = true;
CameraRayEmitterGroup *group;
manta::SimpleLens lens;
lens.initialize();
Expand Down Expand Up @@ -184,6 +188,7 @@ void manta_demo::stressSpidersDemo(int samplesPerPixel, int resolutionX, int res

stressSpidersOctree.destroy();
stressSpiders.destroy();
kdtree.destroy();

std::cout << "Standard allocator memory leaks: " << StandardAllocator::Global()->getLedger() << ", " << StandardAllocator::Global()->getCurrentUsage() << std::endl;
}
9 changes: 7 additions & 2 deletions demos/teapot_lamp_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ void manta_demo::teapotLampDemo(int samplesPerPixel, int resolutionX, int resolu
teapotOctree.analyze(&teapot, 25);
//teapotOctree.writeToObjFile("../../workspace/test_results/teapot_lamp_octree.obj", nullptr);

KDTree kdtree;
kdtree.initialize(4.0, math::constants::Zero);
kdtree.analyze(&teapot, 4);

SpherePrimitive bulb;
bulb.setRadius(0.25);
bulb.setPosition(math::loadVector(0.10669, 3.42135, -2.47464));
Expand Down Expand Up @@ -108,7 +112,7 @@ void manta_demo::teapotLampDemo(int samplesPerPixel, int resolutionX, int resolu

SceneObject *teapotObject = scene.createSceneObject();
if (useOctree) {
teapotObject->setGeometry(&teapotOctree);
teapotObject->setGeometry(&kdtree);
}
else {
teapotObject->setGeometry(&teapot);
Expand Down Expand Up @@ -164,7 +168,7 @@ void manta_demo::teapotLampDemo(int samplesPerPixel, int resolutionX, int resolu
// Leaks
//rayTracer.tracePixel(1281, 900, &scene, &camera);
//rayTracer.tracePixel(1456, 1230, &scene, &camera);
//rayTracer.tracePixel(616, 1459, &scene, &camera);
//rayTracer.tracePixel(1160, 1017, &scene, &camera);

rayTracer.traceAll(&scene, &camera);

Expand Down Expand Up @@ -197,6 +201,7 @@ void manta_demo::teapotLampDemo(int samplesPerPixel, int resolutionX, int resolu
teapot.destroy();
teapotObj.destroy();
teapotOctree.destroy();
kdtree.destroy();

std::cout << "Standard allocator memory leaks: " << StandardAllocator::Global()->getLedger() << ", " << StandardAllocator::Global()->getCurrentUsage() << std::endl;
}

0 comments on commit b8ecfbe

Please sign in to comment.