diff --git a/include/scene/objects/bounding.hpp b/include/scene/objects/bounding.hpp index e600a00..b27cea7 100644 --- a/include/scene/objects/bounding.hpp +++ b/include/scene/objects/bounding.hpp @@ -64,6 +64,10 @@ class bounding { return children; } + inline bool is_terminal_bd() const { + return is_terminal; + } + /* Auxiliary function to scene::find_closest_object_bounding : Places the children of the bounding on the bounding_stack if the box is hit, or determines the closest to the objects from the content if the bounding is terminal diff --git a/scene.txt b/scene.txt index 360b0b2..769a87a 100644 --- a/scene.txt +++ b/scene.txt @@ -1,7 +1,7 @@ -resolution width:800 height:600 -camera position:(0, 4.5, 8) direction:(0, -0.35, -1) rightdir:(1, 0, 0) fov_width:2.5 distance:3 +resolution width:1920 height:1080 +camera position:(0, 5, 8) direction:(0, -0.4, -1) rightdir:(1, 0, 0) fov_width:2.5 distance:3 background_color 190 235 255 -polygons_per_bounding 1 +polygons_per_bounding 60 material white_light (color:(255, 255, 255) emitted_color:(255, 255, 255) reflectivity:0 emission:2 specular_p:0 reflects_color:false transparency:0 scattering:0 refraction_index:1) # material red_light (color:(255, 255, 255) emitted_color:(255, 0, 0) reflectivity:0 emission:5 specular_p:0 reflects_color:false transparency:0 scattering:0 refraction_index:1) @@ -9,8 +9,8 @@ material white_light (color:(255, 255, 255) emitted_color:(255, 255, 255) reflec # material green_light (color:(255, 255, 255) emitted_color:(0, 255, 0) reflectivity:0 emission:5 specular_p:0 reflects_color:false transparency:0 scattering:0 refraction_index:1) # material yellow_light (color:(255, 255, 255) emitted_color:(255, 255, 0) reflectivity:0 emission:5 specular_p:0 reflects_color:false transparency:0 scattering:0 refraction_index:1) -# load_texture wood_floor ../../../raytracer_project/texture_assets/parquet.bmp -load_texture wood_floor ../../../raytracer_project/texture_assets/stripes.bmp +load_texture wood_floor ../../../raytracer_project/texture_assets/parquet.bmp +# load_texture wood_floor ../../../raytracer_project/texture_assets/stripes.bmp load_texture stool_wood ../../../raytracer_project/3d_models/stool/Textures/wooden_stool_texture(F).bmp material Wooden_stool_texture (color:(255, 255, 255) emitted_color:(0, 0, 0) reflectivity:0.8 emission:0 specular_p:0.2 reflects_color:false transparency:0 scattering:0 refraction_index:1) diff --git a/src/auxiliary/clustering.cpp b/src/auxiliary/clustering.cpp index 5797b44..cb0e7d0 100644 --- a/src/auxiliary/clustering.cpp +++ b/src/auxiliary/clustering.cpp @@ -196,10 +196,14 @@ const bounding* create_bounding_hierarchy(const std::vector& cont /* Splitting the objects into groups of polygons_per_bounding polygons (on average) */ const unsigned int k = 1 + content.size() / polygons_per_bounding; + + // printf("1 Calling k_means: %u elements, k = %u\n", content.size(), k); const std::vector> groups = k_means(get_element_vector(content), k); /** Creating the hierarchy **/ + // unsigned int cpt = 0; + /* Creating terminal nodes */ std::vector term_nodes; for (unsigned int i = 0; i < k; i++) { @@ -210,28 +214,37 @@ const bounding* create_bounding_hierarchy(const std::vector& cont else { term_nodes.push_back(containing_objects(get_object_vector(groups.at(i)))); } + // cpt ++; } } + // printf("1 non-empty nodes: %u, empty nodes: %u\n", cpt, k - cpt); std::vector nodes = get_element_vector(term_nodes); - - printf("nodes.size() = %u\n", nodes.size()); + // printf("nodes.size() = %u\n", nodes.size()); while (nodes.size() > CARDINAL_OF_BOX_GROUP) { const unsigned int k = 1 + nodes.size() / CARDINAL_OF_BOX_GROUP; + + // printf("2 Calling k_means: %u elements, k = %u\n", nodes.size(), k); const std::vector> groups = k_means(nodes, k); std::vector new_bd_nodes; + + // cpt = 0; for (unsigned int i = 0; i < k; i++) { + if (groups.at(i).size() != 0) { new_bd_nodes.push_back(containing_bounding_any(get_bounding_vector(groups.at(i)))); + // cpt ++; } } + // printf("2 non-empty nodes: %u, empty nodes: %u\n", cpt, k - cpt); nodes.clear(); nodes = get_element_vector(new_bd_nodes); - printf("nodes.size() = %u\n", nodes.size()); + + // printf("nodes.size() = %u\n", nodes.size()); } return containing_bounding_any(get_bounding_vector(nodes)); @@ -251,7 +264,7 @@ void display_hierarchy_properties(const bounding* bd0) { printf("Level 0: arity = %u\n", bd0->get_children().size()); while (not bds.empty()) { - printf("bds.size() = %u\n", bds.size()); + // printf("bds.size() = %u\n", bds.size()); /* Computing min, max and average arity of the nodes on the stack If one node is terminal, its arity counts as zero. */ @@ -264,7 +277,10 @@ void display_hierarchy_properties(const bounding* bd0) { while(not bds.empty()) { const bounding* bd = bds.top(); bds.pop(); - if (bd->get_content().size() != 0) { + if (bd->is_terminal_bd()) { + terminal_nodes ++; + } + else { unsigned int arity = bd->get_children().size(); if (arity > max) {max = arity;} if (arity < min) {min = arity;} @@ -273,9 +289,6 @@ void display_hierarchy_properties(const bounding* bd0) { next_bds.push(bd->get_children().at(j)); } } - else { - terminal_nodes ++; - } } /* Displaying the statistics */ @@ -292,6 +305,8 @@ void display_hierarchy_properties(const bounding* bd0) { bds.push(next_bds.top()); next_bds.pop(); } + + level++; } printf("===============================================================================\n"); } \ No newline at end of file diff --git a/src/file_readers/obj_parser.cpp b/src/file_readers/obj_parser.cpp index acd9cc6..9cd2573 100644 --- a/src/file_readers/obj_parser.cpp +++ b/src/file_readers/obj_parser.cpp @@ -87,6 +87,10 @@ bool parse_obj_file(const char* file_name, std::vector& obj_set, is placed in a box that is added to the children vector */ if (bounding_enabled && strcmp(s, "o") == 0 && content.size() != 0) { + // First method: put the whole group in one bounding + // const bounding* bd = containing_objects(content); + + // Second method: create a bounding hierarchy containing all the nodes /* Heuristic: each group is a depth 1 node in the global bounding box hierarchy */ const bounding* bd = create_bounding_hierarchy(content, polygons_per_bounding); display_hierarchy_properties(bd); @@ -304,6 +308,7 @@ bool parse_obj_file(const char* file_name, std::vector& obj_set, if (bounding_enabled) { /* Placing the last group into a bounding */ + // const bounding* bd = containing_objects(content); const bounding* bd = create_bounding_hierarchy(content, polygons_per_bounding); display_hierarchy_properties(bd); children.push_back(bd);