diff --git a/src/main.cpp b/src/main.cpp index 229c861..112b621 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,11 +34,11 @@ int main(int argc, char *argv[]) { Timer timer; tick(timer); std::cout << "Parsing and constructing scene " << filename << "." << std::endl; - Scene scene = parse_scene(filename, embree_device); + std::unique_ptr scene = parse_scene(filename, embree_device); std::cout << "Done. Took " << tick(timer) << " seconds." << std::endl; std::cout << "Rendering..." << std::endl; - Image3 img = render(scene); - if (outputfile.compare("") == 0) {outputfile = scene.output_filename;} + Image3 img = render(*scene); + if (outputfile.compare("") == 0) {outputfile = scene->output_filename;} std::cout << "Done. Took " << tick(timer) << " seconds." << std::endl; imwrite(outputfile, img); std::cout << "Image written to " << outputfile << std::endl; diff --git a/src/parsers/parse_scene.cpp b/src/parsers/parse_scene.cpp index 67bab84..17a8213 100644 --- a/src/parsers/parse_scene.cpp +++ b/src/parsers/parse_scene.cpp @@ -1406,7 +1406,7 @@ Shape parse_shape(pugi::xml_node node, return shape; } -Scene parse_scene(pugi::xml_node node, const RTCDevice &embree_device) { +std::unique_ptr parse_scene(pugi::xml_node node, const RTCDevice &embree_device) { RenderOptions options; Camera camera(Matrix4x4::identity(), c_default_fov, @@ -1586,19 +1586,20 @@ Scene parse_scene(pugi::xml_node node, const RTCDevice &embree_device) { } } } - return Scene{embree_device, - camera, - materials, - shapes, - lights, - media, - envmap_light_id, - texture_pool, - options, - filename}; + return std::make_unique( + embree_device, + camera, + materials, + shapes, + lights, + media, + envmap_light_id, + texture_pool, + options, + filename); } -Scene parse_scene(const fs::path &filename, const RTCDevice &embree_device) { +std::unique_ptr parse_scene(const fs::path &filename, const RTCDevice &embree_device) { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file(filename.c_str()); if (!result) { @@ -1609,7 +1610,7 @@ Scene parse_scene(const fs::path &filename, const RTCDevice &embree_device) { // back up the current working directory and switch to the parent folder of the file fs::path old_path = fs::current_path(); fs::current_path(filename.parent_path()); - Scene scene = parse_scene(doc.child("scene"), embree_device); + std::unique_ptr scene = parse_scene(doc.child("scene"), embree_device); // switch back to the old current working directory fs::current_path(old_path); return scene; diff --git a/src/parsers/parse_scene.h b/src/parsers/parse_scene.h index 4e4f2f8..506017c 100644 --- a/src/parsers/parse_scene.h +++ b/src/parsers/parse_scene.h @@ -6,4 +6,4 @@ #include /// Parse Mitsuba's XML scene format. -Scene parse_scene(const fs::path &filename, const RTCDevice &embree_device); +std::unique_ptr parse_scene(const fs::path &filename, const RTCDevice &embree_device); diff --git a/src/scene.cpp b/src/scene.cpp index d03f3aa..f5d241d 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -52,18 +52,6 @@ Scene::Scene(const RTCDevice &embree_device, light_dist = make_table_dist_1d(power); } -Scene::Scene(const Scene& t) : - embree_device(t.embree_device), embree_scene(t.embree_scene), - camera(t.camera), materials(t.materials), - shapes(t.shapes), lights(t.lights), media(t.media), - envmap_light_id(t.envmap_light_id), - texture_pool(t.texture_pool), bounds(t.bounds), options(t.options), - output_filename(t.output_filename), light_dist(t.light_dist) { - // embree_scene is managed by Embree using reference counting. - // it's crucial for us to also maintain the reference count when copying scenes. - rtcRetainScene(t.embree_scene); -} - Scene::~Scene() { // This decreses the reference count of embree_scene in Embree, // if it reaches zero, Embree will deallocate the scene. diff --git a/src/scene.h b/src/scene.h index dedb9b4..b3d67b0 100644 --- a/src/scene.h +++ b/src/scene.h @@ -52,7 +52,7 @@ struct Scene { const RenderOptions &options, const std::string &output_filename); ~Scene(); - Scene(const Scene& t); + Scene(const Scene& t) = delete; Scene& operator=(const Scene& t) = delete; RTCDevice embree_device;