void draw_custom_window()

in code/cpp/tools/scene_annotation_tool/main.cpp [1547:2086]


void draw_custom_window() {

    auto indent_width = 6.0;

    ImGui::SetNextWindowPos(ImVec2(10, 10), ImGuiCond_FirstUseEver);
    ImGui::SetNextWindowSize(ImVec2(300, 880), ImGuiCond_FirstUseEver);
    ImGui::Begin("Hypersim Scene Annotation Tool", nullptr, 0);
    ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, indent_width);

    auto content_region_available_width = ImGui::GetContentRegionAvailWidth();
    auto button_not_centered_offset = 0.0;

    if (ImGui::Button(ICON_FA_FOLDER_OPEN " Load scene...", ImVec2(content_region_available_width/2.0 - ImGui::GetStyle().ItemSpacing.x/2.0 - button_not_centered_offset, 0.0f))) {
        auto dir = open_directory_dialog();
        g_mouse_ignore_counter = 2; // ignore the next 2 mouse move events because the mouse locations will be buggy
        if (filesystem_exists(dir)) {
            if (filesystem_exists(dir + "/_detail/mesh")) { // TODO: use portable paths
                std::cout << "[HYPERSIM: SCENE_ANNOTATION_TOOL] Selected folder appears to be a top-level Hypersim scene folder, attempting to load meshes from " + dir + "/_detail/mesh..." << std::endl;
                dir = dir + "/_detail/mesh"; // TODO: use portable paths
            }
            load_scene(dir);
            g_updated_collapse_state_segmentation = true;
        }
    }

    ImGui::SameLine();

    if (!g_scene_loaded) {
        ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
        ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
    }

    if (ImGui::Button(ICON_FA_FOLDER_OPEN " Load segmentation...", ImVec2(content_region_available_width/2.0 - ImGui::GetStyle().ItemSpacing.x/2.0 + button_not_centered_offset, 0.0f))) {
        auto dir = open_directory_dialog();
        g_mouse_ignore_counter = 2; // ignore the next 2 mouse move events because the mouse locations will be buggy
        if (filesystem_exists(dir)) {
            if (filesystem_exists(dir + "/_detail/mesh")) { // TODO: use portable paths
                std::cout << "[HYPERSIM: SCENE_ANNOTATION_TOOL] Selected folder appears to be a top-level Hypersim scene folder, attempting to load segmentation from " + dir + "/_detail/mesh..." << std::endl;
                dir = dir + "/_detail/mesh"; // TODO: use portable paths
            }
            load_segmentation(dir, true); // dir, can undo
        }
    }

    if (ImGui::Button(ICON_FA_SAVE " Save segmentation", ImVec2(content_region_available_width/2.0 - ImGui::GetStyle().ItemSpacing.x/2.0 - button_not_centered_offset, 0.0f))) {
        save_segmentation(g_scene_dir);
    }

    ImGui::SameLine();

    if (ImGui::Button(ICON_FA_SAVE " Save segmentation as...", ImVec2(content_region_available_width/2.0 - ImGui::GetStyle().ItemSpacing.x/2.0 + button_not_centered_offset, 0.0f))) {
        auto dir = open_directory_dialog();
        g_mouse_ignore_counter = 2; // ignore the next 2 mouse move events because the mouse locations will be buggy
        if (filesystem_exists(dir)) {
            if (filesystem_exists(dir + "/_detail/mesh")) { // TODO: use portable paths
                std::cout << "[HYPERSIM: SCENE_ANNOTATION_TOOL] Selected folder appears to be a top-level Hypersim scene folder, attempting to save segmentation to " + dir + "/_detail/mesh..." << std::endl;
                dir = dir + "/_detail/mesh"; // TODO: use portable paths
            }
            save_segmentation(dir);
        }
    }

    if (!g_scene_loaded) {
        ImGui::PopItemFlag();
        ImGui::PopStyleVar();
    }

    ImGui::Checkbox(ICON_FA_TRASH " Decimate mesh immediately after loading", &g_decimate_mesh_on_load);

    ImGui::Separator();

    if (ImGui::BeginTabBar("imgui_tab_bar", ImGuiTabBarFlags_None)) {

        //
        // Segmentation
        //

        if (ImGui::BeginTabItem("Segmentation Editor")) {

            if (!g_scene_loaded) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }

            ImGui::Indent();

            TOOL tool_curr;
            std::string label_curr;
            bool tool_curr_selected;

            tool_curr          = TOOL_PEN;
            label_curr         = ICON_FA_PEN " Pen";
            tool_curr_selected = g_tool == tool_curr;
            if (tool_curr_selected) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(15.0f/255.0f, 135.0f/255.0f, 250.0f/255.0f, 255.0f/255.0f));
            if (ImGui::Button(label_curr.c_str())) g_tool = tool_curr; ImGui::SameLine();
            if (tool_curr_selected) ImGui::PopStyleColor();

            tool_curr          = TOOL_LINE;
            label_curr         = ICON_FA_RULER " Line";
            tool_curr_selected = g_tool == tool_curr;
            if (tool_curr_selected) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(15.0f/255.0f, 135.0f/255.0f, 250.0f/255.0f, 255.0f/255.0f));
            if (ImGui::Button(label_curr.c_str())) g_tool = tool_curr; ImGui::SameLine();
            if (tool_curr_selected) ImGui::PopStyleColor();

            tool_curr          = TOOL_RECTANGLE;
            label_curr         = ICON_FA_RULER_COMBINED " Rectangle";
            tool_curr_selected = g_tool == tool_curr;
            if (tool_curr_selected) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(15.0f/255.0f, 135.0f/255.0f, 250.0f/255.0f, 255.0f/255.0f));
            if (ImGui::Button(label_curr.c_str())) g_tool = tool_curr; ImGui::SameLine();
            if (tool_curr_selected) ImGui::PopStyleColor();

            tool_curr          = TOOL_EYEDROPPER;
            label_curr         = ICON_FA_EYE_DROPPER " Eyedropper";
            tool_curr_selected = g_tool == tool_curr;
            if (tool_curr_selected) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(15.0f/255.0f, 135.0f/255.0f, 250.0f/255.0f, 255.0f/255.0f));
            if (ImGui::Button(label_curr.c_str())) g_tool = tool_curr;
            if (tool_curr_selected) ImGui::PopStyleColor();

            auto content_region_available_width                              = ImGui::GetContentRegionAvailWidth();
            auto can_undo                                                    = g_can_undo;
            auto can_redo                                                    = g_can_redo;
            auto can_erase                                                   = g_tool != TOOL_EYEDROPPER;
            auto can_assign_unique_semantic_instance_ids_to_each_mesh_object = g_tool != TOOL_EYEDROPPER && g_segmentation_layer == SEGMENTATION_LAYER_SEMANTIC_INSTANCE;

            if (g_scene_loaded && !can_erase) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }
            if (ImGui::Checkbox(ICON_FA_ERASER " Erase", &g_erase_mode)) {
                g_assign_unique_semantic_instance_ids_to_each_mesh_object = false;
            }
            if (g_scene_loaded && !can_erase) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            if (g_scene_loaded && !can_assign_unique_semantic_instance_ids_to_each_mesh_object) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }
            if (ImGui::Checkbox(ICON_FA_RAINBOW " Assign unique semantic instance IDs", &g_assign_unique_semantic_instance_ids_to_each_mesh_object)) {
                g_erase_mode = false;
            }
            if (g_scene_loaded && !can_assign_unique_semantic_instance_ids_to_each_mesh_object) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            if (g_scene_loaded && !can_undo) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }
            if (ImGui::Button(ICON_FA_UNDO " Undo", ImVec2((content_region_available_width-indent_width)/2.0 - (ImGui::GetStyle().ItemSpacing.x/2.0), 0.0f))) {
                undo();
            }
            if (g_scene_loaded && !can_undo) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            ImGui::SameLine();

            if (g_scene_loaded && !can_redo) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }
            if (ImGui::Button(ICON_FA_REDO " Redo", ImVec2((content_region_available_width-indent_width)/2.0 - (ImGui::GetStyle().ItemSpacing.x/2.0), 0.0f))) {
                redo();
            }
            if (g_scene_loaded && !can_redo) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            if (ImGui::Button(ICON_FA_CAMERA " Reset camera look-at position", ImVec2(content_region_available_width - indent_width, 0.0f))) {
                reset_camera_lookat_position();
            }

            if (ImGui::Button(ICON_FA_TRASH " Decimate mesh", ImVec2((content_region_available_width-indent_width)/2.0 - (ImGui::GetStyle().ItemSpacing.x/2.0), 0.0f))) {
                remove_vertices_and_faces(g_prefer_remove_small_vertices, g_prefer_remove_distant_vertices, g_remove_orphaned_vertices);
            }
            ImGui::SameLine();
            if (ImGui::Button(ICON_FA_TRASH_RESTORE " Restore mesh", ImVec2((content_region_available_width-indent_width)/2.0 - (ImGui::GetStyle().ItemSpacing.x/2.0), 0.0f))) {
                reset_vertices_and_faces();
            }

            ImGui::Separator();

            if (ImGui::RadioButton("Edit semantic instance segmentation layer", (int*)&g_segmentation_layer, (int)SEGMENTATION_LAYER_SEMANTIC_INSTANCE)) {
                set_viewer_mesh_colors();
                g_updated_collapse_state_segmentation = true;
            }
            if (ImGui::RadioButton("Edit semantic segmentation layer", (int*)&g_segmentation_layer, (int)SEGMENTATION_LAYER_SEMANTIC)) {
                set_viewer_mesh_colors();
                g_updated_collapse_state_segmentation = true;
            }

            ImGui::Separator();

            auto can_edit_selection_logic = g_tool != TOOL_EYEDROPPER;

            if (!can_edit_selection_logic) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }
            ImGui::RadioButton("Prefer to select faces by mesh object ID",       (int*)&g_prefer_select_faces_by_mode, PREFER_SELECT_FACES_BY_MODE_OBJECT_MESH_ID);
            ImGui::RadioButton("Prefer to select faces by semantic instance ID", (int*)&g_prefer_select_faces_by_mode, PREFER_SELECT_FACES_BY_MODE_SEMANTIC_INSTANCE_ID);
            ImGui::RadioButton("Prefer to select faces by semantic ID",          (int*)&g_prefer_select_faces_by_mode, PREFER_SELECT_FACES_BY_MODE_SEMANTIC_ID);
            if (!can_edit_selection_logic) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            ImGui::Separator();

            if (!can_edit_selection_logic) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }
            if (ImGui::Checkbox("Only select faces with no semantic instance ID", &g_select_only_null_semantic_instance_id)) {
                g_select_only_valid_semantic_instance_id = false;
            }
            if (ImGui::Checkbox("Only select faces with valid semantic instance ID", &g_select_only_valid_semantic_instance_id)) {
                g_select_only_null_semantic_instance_id = false;
            }
            if (ImGui::Checkbox("Only select faces with no semantic ID", &g_select_only_null_semantic_id)) {            
                g_select_only_valid_semantic_id = false;
            }
            if (ImGui::Checkbox("Only select faces with valid semantic ID", &g_select_only_valid_semantic_id)) {
                g_select_only_null_semantic_id = false;
            }
            if (!can_edit_selection_logic) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            //
            // Semantic Instance Segmentation IDs
            //

            if (g_updated_collapse_state_segmentation) {
                ImGui::SetNextTreeNodeOpen(g_scene_loaded && g_segmentation_layer == SEGMENTATION_LAYER_SEMANTIC_INSTANCE);
            }
            if (g_scene_loaded && g_segmentation_layer != SEGMENTATION_LAYER_SEMANTIC_INSTANCE) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }
            if (ImGui::CollapsingHeader("Semantic Instance Segmentation IDs", ImGuiTreeNodeFlags_DefaultOpen)) {

                ImGui::Indent();

                if (ImGui::Button(ICON_FA_PLUS_SQUARE " Create new semantic instance ID", ImVec2(ImGui::GetContentRegionAvailWidth() - indent_width, 0.0f))) {
                    g_semantic_instance_id         = create_new_semantic_instance_segmentation_id();
                    g_updated_semantic_instance_id = true;
                }

                // Create child region so it will have its own scroll bar
                ImGui::BeginChild("imgui_semantic_instance_child", ImVec2(ImGui::GetContentRegionAvailWidth() - indent_width, 100), false, 0);
                ImGui::Columns(2, "imgui_semantic_instance_columns", false);  // count, id, border
                for (auto d : g_semantic_instance_descs) {
                    std::string selectable_name     = "##_selectable_" + std::get<0>(d.second);
                    int         selectable_val      = d.first;
                    bool        selectable_selected = g_semantic_instance_id == d.first;
                    std::string color_button_name   = "##_color_" + std::get<0>(d.second);
                    ImVec4      color_button_color  = ImVec4(std::get<1>(d.second)(0) / 255.0f, std::get<1>(d.second)(1) / 255.0f, std::get<1>(d.second)(2) / 255.0f, 1.0f);
                    std::string text_label          = std::get<0>(d.second);

                    if (ImGui::Selectable(selectable_name.c_str(), selectable_selected)) {
                        g_semantic_instance_id = selectable_val;
                    }
                    ImGui::SameLine();
                    ImGui::ColorButton(color_button_name.c_str(), color_button_color, ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoTooltip, ImVec2(12,12));
                    ImGui::SameLine();
                    ImGui::TextUnformatted(text_label.c_str());
                    ImGui::NextColumn();
                    if (g_updated_semantic_instance_id && selectable_val == g_semantic_instance_id) {
                        ImGui::SetScrollHereY();
                        g_updated_semantic_instance_id = false;
                    }
                }
                ImGui::Columns(1);
                ImGui::EndChild();

                ImGui::Unindent();
            }
            if (g_scene_loaded && g_segmentation_layer != SEGMENTATION_LAYER_SEMANTIC_INSTANCE) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            //
            // Semantic Segmentation IDs
            //

            if (g_updated_collapse_state_segmentation) {
                ImGui::SetNextTreeNodeOpen(g_scene_loaded && g_segmentation_layer == SEGMENTATION_LAYER_SEMANTIC);
            }
            if (g_scene_loaded && g_segmentation_layer != SEGMENTATION_LAYER_SEMANTIC) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }
            if (ImGui::CollapsingHeader("Semantic Segmentation IDs", ImGuiTreeNodeFlags_DefaultOpen)) {

                ImGui::Indent();

                // Create child region to match Semantic Instance IDs region above (338 is the height in pixels required by all the NYU40 labels)
                ImGui::BeginChild("imgui_semantic_child", ImVec2(ImGui::GetContentRegionAvailWidth() - indent_width, 338), false, 0);
                ImGui::Columns(2, "imgui_semantic_columns", false);  // count, id, border
                for (auto d : g_semantic_descs) {
                    std::string selectable_name     = "##_selectable_" + std::get<0>(d.second);
                    int         selectable_val      = d.first;
                    bool        selectable_selected = g_semantic_id == d.first;
                    std::string color_button_name   = "##_color_" + std::get<0>(d.second);
                    ImVec4      color_button_color  = ImVec4(std::get<1>(d.second)(0) / 255.0f, std::get<1>(d.second)(1) / 255.0f, std::get<1>(d.second)(2) / 255.0f, 1.0f);
                    std::string text_label          = std::get<0>(d.second);

                    if (ImGui::Selectable(selectable_name.c_str(), selectable_selected)) {
                        g_semantic_id = selectable_val;
                    }
                    ImGui::SameLine();
                    ImGui::ColorButton(color_button_name.c_str(), color_button_color, ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoTooltip, ImVec2(12,12));
                    ImGui::SameLine();
                    ImGui::TextUnformatted(text_label.c_str());
                    ImGui::NextColumn();
                }
                ImGui::Columns(1);
                ImGui::EndChild();

                ImGui::Unindent();
            }
            if (g_scene_loaded && g_segmentation_layer != SEGMENTATION_LAYER_SEMANTIC) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            if (g_updated_collapse_state_segmentation) {
                g_updated_collapse_state_segmentation = false;
            }

            ImGui::Unindent();

            if (!g_scene_loaded) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            ImGui::EndTabItem();
        }

        // //
        // // Camera Poses
        // //

        // if (ImGui::BeginTabItem("Camera Pose Editor")) {
        //     ImGui::EndTabItem();
        // }

        //
        // Viewer Options
        //

        if (ImGui::BeginTabItem("Viewer Options")) {

            if (!g_scene_loaded) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }

            ImGui::Indent();

            auto content_region_available_width = ImGui::GetContentRegionAvailWidth();

            ImGui::BeginChild("imgui_viewer_child_camera", ImVec2(ImGui::GetContentRegionAvailWidth() - indent_width, 32), false, 0); // 32 is height required for camera text
            ImGui::Columns(2, "imgui_viewer_columns_camera", false);  // count, id, border

            ImGui::Text("Camera look-from pos."); ImGui::NextColumn(); ImGui::Text("[%0.1f  %0.1f  %0.1f]", g_viewer.core().camera_eye(0),    g_viewer.core().camera_eye(1),    g_viewer.core().camera_eye(2));    ImGui::NextColumn();
            ImGui::Text("Camera look-at pos.");  ImGui::NextColumn(); ImGui::Text("[%0.1f  %0.1f  %0.1f]", g_viewer.core().camera_center(0), g_viewer.core().camera_center(1), g_viewer.core().camera_center(2)); ImGui::NextColumn();

            ImGui::Columns(1);
            ImGui::EndChild();

            if (ImGui::Button(ICON_FA_CAMERA " Reset camera look-at position", ImVec2(content_region_available_width - indent_width, 0.0f))) {
                reset_camera_lookat_position();
            }

            ImGui::PushItemWidth(content_region_available_width-indent_width);
            ImGui::DragFloat("##_sensitivity", &g_navigation_sensitivity, 0.1, 0.1f, 10.0f, "Navigation sensitivity = %.1f");
            ImGui::PopItemWidth();

            ImGui::PushItemWidth((content_region_available_width-indent_width)/2.0 - (ImGui::GetStyle().ItemSpacing.x/2.0));
            ImGui::DragFloat("##_near_plane", &g_viewer.core().camera_dnear, 0.1f,   0.1f,   100.0f,    "Near plane = %.1f");
            ImGui::SameLine();
            ImGui::DragFloat("##_far_plane",  &g_viewer.core().camera_dfar,  100.0f, 100.0f, 100000.0f, "Far plane = %.1f");
            ImGui::PopItemWidth();

            ImGui::Separator();

            ImGui::BeginChild("imgui_viewer_child_mesh", ImVec2(ImGui::GetContentRegionAvailWidth() - indent_width, 64), false, 0); // 64 is height required for mesh text
            ImGui::Columns(4, "imgui_viewer_columns_mesh", false);  // count, id, border

            ImGui::Text("Orig. verts."); ImGui::NextColumn(); ImGui::Text("%d",         (int)g_vertices_orig.n_rows);                        ImGui::NextColumn(); ImGui::Text("Orig. faces");  ImGui::NextColumn(); ImGui::Text("%d",         (int)g_faces_vi_orig.n_rows);                        ImGui::NextColumn();
            ImGui::Text("");             ImGui::NextColumn(); ImGui::Text("(%0.1f MB)", (float)(4*3*g_vertices_orig.n_rows)/(float)1000000); ImGui::NextColumn(); ImGui::Text("");             ImGui::NextColumn(); ImGui::Text("(%0.1f MB)", (float)(4*4*g_faces_vi_orig.n_rows)/(float)1000000); ImGui::NextColumn();
            ImGui::Text("Curr. verts."); ImGui::NextColumn(); ImGui::Text("%d",         (int)g_vertices_curr.n_rows);                        ImGui::NextColumn(); ImGui::Text("Curr. faces");  ImGui::NextColumn(); ImGui::Text("%d",         (int)g_faces_vi_curr.n_rows);                        ImGui::NextColumn();
            ImGui::Text("");             ImGui::NextColumn(); ImGui::Text("(%0.1f MB)", (float)(4*3*g_vertices_curr.n_rows)/(float)1000000); ImGui::NextColumn(); ImGui::Text("");             ImGui::NextColumn(); ImGui::Text("(%0.1f MB)", (float)(4*4*g_faces_vi_curr.n_rows)/(float)1000000); ImGui::NextColumn();

            ImGui::Columns(1);
            ImGui::EndChild();

            if (ImGui::Button(ICON_FA_TRASH " Decimate mesh", ImVec2((content_region_available_width-indent_width)/2.0 - (ImGui::GetStyle().ItemSpacing.x/2.0), 0.0f))) {
                remove_vertices_and_faces(g_prefer_remove_small_vertices, g_prefer_remove_distant_vertices, g_remove_orphaned_vertices);
            }
            ImGui::SameLine();
            if (ImGui::Button(ICON_FA_TRASH_RESTORE " Restore mesh", ImVec2((content_region_available_width-indent_width)/2.0 - (ImGui::GetStyle().ItemSpacing.x/2.0), 0.0f))) {
                reset_vertices_and_faces();
            }

           ImGui::PushItemWidth((content_region_available_width-indent_width)/2.0 - (ImGui::GetStyle().ItemSpacing.x/2.0));
            ImGui::DragInt("##_max_num_vertices", &g_max_num_vertices, 10000, 100000, 100000000, "Max. verts. = %d");
            ImGui::PopItemWidth();

            ImGui::SameLine();

            ImGui::PushItemWidth((content_region_available_width-indent_width)/2.0 - (ImGui::GetStyle().ItemSpacing.x/2.0));
            ImGui::DragInt("##_max_num_faces", &g_max_num_faces, 10000, 100000, 10000000, "Max. faces = %d");
            ImGui::PopItemWidth();

            ImGui::PushItemWidth(content_region_available_width-indent_width);
            ImGui::DragInt("##_max_num_iters", &g_max_num_iters, 1, 1, 100, "Maximum decimation iterations = %d");
            ImGui::PopItemWidth();

            if (g_scene_loaded && !g_prefer_remove_small_vertices) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }
            ImGui::PushItemWidth(content_region_available_width-indent_width);
            ImGui::DragFloat("##_face_score_area_half_life", &g_face_score_area_half_life, 0.01f, 0.01f, 10.0f, "Half-life with respect to face area = %.2f");
            ImGui::PopItemWidth();
            if (g_scene_loaded && !g_prefer_remove_small_vertices) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            if (g_scene_loaded && !g_prefer_remove_distant_vertices) {
                ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
                ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
            }
            ImGui::PushItemWidth(content_region_available_width-indent_width);
            ImGui::DragFloat("##_face_score_distance_half_life", &g_face_score_distance_half_life, 1.0f, 1.0f, 1000.0f, "Half-life with respect to camera distance = %.1f");
            ImGui::PopItemWidth();
            if (g_scene_loaded && !g_prefer_remove_distant_vertices) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            ImGui::Separator();

            ImGui::Checkbox("Prefer to decimate small faces and vertices", &g_prefer_remove_small_vertices);
            ImGui::Checkbox("Prefer to decimate distant faces and vertices", &g_prefer_remove_distant_vertices);
            ImGui::Checkbox("Remove orphaned vertices", &g_remove_orphaned_vertices);

            ImGui::Separator();

            ImGui::Checkbox("Show wireframe overlay", (bool*)(&g_viewer.data().show_lines));

            if (!g_scene_loaded) {
                ImGui::PopItemFlag();
                ImGui::PopStyleVar();
            }

            static bool show_imgui_demo_window = false;
            ImGui::Checkbox("Show ImGui demo window", &show_imgui_demo_window);
            if (show_imgui_demo_window) {
                ImGui::ShowDemoWindow();
            }

            ImGui::Unindent();

            ImGui::EndTabItem();
        }

        ImGui::EndTabBar();
    }

    ImGui::PopStyleVar();
    ImGui::End();

    if (g_scene_loaded) {

        float x_scale, y_scale;
        GLFWwindow* window = glfwGetCurrentContext();
        glfwGetWindowContentScale(window, &x_scale, &y_scale);

        ImU32 color;
        if (g_erase_mode || (g_assign_unique_semantic_instance_ids_to_each_mesh_object && (g_segmentation_layer == SEGMENTATION_LAYER_SEMANTIC_INSTANCE))) {
            ImVec4 color_ = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
            color = ImColor(color_);
        } else {
            if (g_segmentation_layer == SEGMENTATION_LAYER_SEMANTIC_INSTANCE) {
                auto desc = g_semantic_instance_descs.at(g_semantic_instance_id);
                ImVec4 color_ = ImVec4(std::get<1>(desc)(0) / 255.0f, std::get<1>(desc)(1) / 255.0f, std::get<1>(desc)(2) / 255.0f, 0.5f);
                color = ImColor(color_);
            }
            if (g_segmentation_layer == SEGMENTATION_LAYER_SEMANTIC) {
                auto desc = g_semantic_descs.at(g_semantic_id);
                ImVec4 color_ = ImVec4(std::get<1>(desc)(0) / 255.0f, std::get<1>(desc)(1) / 255.0f, std::get<1>(desc)(2) / 255.0f, 0.5f);
                color = ImColor(color_);
            }
        }

        if (g_tool == TOOL_PEN) {
            if (g_mouse_drawing_positions.size() > 0) {
                for (arma::ivec p : g_mouse_drawing_positions) {
                    ImGui::GetBackgroundDrawList()->AddCircleFilled(ImVec2(p(0)/x_scale, p(1)/y_scale), 2, color, 20); // screen pos, size, color, num_edges
                }
                for (int i = 0; i < g_mouse_drawing_positions.size() - 1; i++) {
                    arma::ivec p0 = g_mouse_drawing_positions.at(i);
                    arma::ivec p1 = g_mouse_drawing_positions.at(i+1);
                    ImGui::GetBackgroundDrawList()->AddLine(ImVec2(p0(0)/x_scale, p0(1)/y_scale), ImVec2(p1(0)/x_scale, p1(1)/y_scale), color, 4); // screen pos 0, screen pos 1, color, width
                }
            }
        }
        if (g_tool == TOOL_LINE) {
            if (g_mouse_drawing_positions.size() > 0) {
                arma::ivec p0 = g_mouse_drawing_positions.front();
                arma::ivec p1 = g_mouse_drawing_positions.back();
                ImGui::GetBackgroundDrawList()->AddCircleFilled(ImVec2(p0(0)/x_scale, p0(1)/y_scale), 2, color, 20); // screen pos, size, color, num_edges
                ImGui::GetBackgroundDrawList()->AddCircleFilled(ImVec2(p1(0)/x_scale, p1(1)/y_scale), 2, color, 20); // screen pos, size, color, num_edges
                ImGui::GetBackgroundDrawList()->AddLine(ImVec2(p0(0)/x_scale, p0(1)/y_scale), ImVec2(p1(0)/x_scale, p1(1)/y_scale), color, 4); // screen pos 0, screen pos 1, color, width
            }
        }
        if (g_tool == TOOL_RECTANGLE) {
            if (g_mouse_drawing_positions.size() > 0) {
                arma::ivec p0 = g_mouse_drawing_positions.front();
                arma::ivec p1 = g_mouse_drawing_positions.back();
                ImDrawCornerFlags corners_none = 0;
                ImGui::GetBackgroundDrawList()->AddRectFilled(ImVec2(p0(0)/x_scale, p0(1)/y_scale), ImVec2(p1(0)/x_scale, p1(1)/y_scale), color, 4, corners_none); // screen pos 0, screen pos 1, color, ?, corner flags
            }
        }
    }
}