From 0be83d894215099e506ab073da1a803ce0dfaaab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Guimar=C3=A3es?= Date: Wed, 9 Jul 2025 16:33:05 -0300 Subject: [PATCH 1/7] chore(project): Overhaul project structure and build system This commit introduces a major refactoring of the project's structure and CMake build system to establish 'Prism' as the core library product, with the application serving as a self-contained demo. Key Changes: - **Project Restructure**: Reorganized directories to be "Prism-centric" (`libs/Prism` -> `src`, executable -> `demo`). This clarifies the project's identity and improves modularity. - **CMake Overhaul**: All `CMakeLists.txt` files have been rewritten to use modern, target-oriented CMake practices. This improves encapsulation and makes the library easier to reuse. - **Optional Demo App**: The demo application in `app/` is now optional and can be disabled with the `PRISM_BUILD_DEMO` flag, making it easier for consumers to build only the library. --- CMakeLists.txt | 51 +++++++++------- CMakePresets.json | 6 +- demo/CMakeLists.txt | 29 +++++++++ {data => demo/data}/input/cubo.mtl | 0 {data => demo/data}/input/cubo.obj | 0 {data => demo/data}/input/scene.yml | 2 +- {src => demo/src}/main.cpp | 0 libs/CMakeLists.txt | 4 -- libs/Prism/CMakeLists.txt | 26 -------- src/CMakeLists.txt | 59 +++++++++++++++---- {libs/Prism => src}/include/Prism.hpp | 0 .../Prism => src}/include/Prism/Colormap.hpp | 0 .../Prism => src}/include/Prism/ObjReader.hpp | 0 {libs/Prism => src}/include/Prism/camera.hpp | 0 {libs/Prism => src}/include/Prism/color.hpp | 0 .../Prism => src}/include/Prism/material.hpp | 0 {libs/Prism => src}/include/Prism/matrix.hpp | 0 {libs/Prism => src}/include/Prism/mesh.hpp | 0 {libs/Prism => src}/include/Prism/objects.hpp | 0 {libs/Prism => src}/include/Prism/plane.hpp | 0 {libs/Prism => src}/include/Prism/point.hpp | 0 {libs/Prism => src}/include/Prism/ray.hpp | 0 {libs/Prism => src}/include/Prism/scene.hpp | 0 .../include/Prism/scene_parser.hpp | 0 {libs/Prism => src}/include/Prism/sphere.hpp | 0 {libs/Prism => src}/include/Prism/style.hpp | 0 .../Prism => src}/include/Prism/triangle.hpp | 0 {libs/Prism => src}/include/Prism/utils.hpp | 0 {libs/Prism => src}/include/Prism/vector.hpp | 0 {libs/Prism => src}/src/camera.cpp | 0 {libs/Prism => src}/src/color.cpp | 0 {libs/Prism => src}/src/init.cpp | 0 {libs/Prism => src}/src/matrix.cpp | 0 {libs/Prism => src}/src/mesh.cpp | 0 {libs/Prism => src}/src/plane.cpp | 0 {libs/Prism => src}/src/point.cpp | 0 {libs/Prism => src}/src/ray.cpp | 0 {libs/Prism => src}/src/scene.cpp | 0 {libs/Prism => src}/src/scene_parser.cpp | 7 ++- {libs/Prism => src}/src/sphere.cpp | 0 {libs/Prism => src}/src/triangle.cpp | 0 {libs/Prism => src}/src/utils.cpp | 0 {libs/Prism => src}/src/vector.cpp | 0 tests/CMakeLists.txt | 20 ++++++- 44 files changed, 136 insertions(+), 68 deletions(-) create mode 100644 demo/CMakeLists.txt rename {data => demo/data}/input/cubo.mtl (100%) rename {data => demo/data}/input/cubo.obj (100%) rename {data => demo/data}/input/scene.yml (98%) rename {src => demo/src}/main.cpp (100%) delete mode 100644 libs/CMakeLists.txt delete mode 100644 libs/Prism/CMakeLists.txt rename {libs/Prism => src}/include/Prism.hpp (100%) rename {libs/Prism => src}/include/Prism/Colormap.hpp (100%) rename {libs/Prism => src}/include/Prism/ObjReader.hpp (100%) rename {libs/Prism => src}/include/Prism/camera.hpp (100%) rename {libs/Prism => src}/include/Prism/color.hpp (100%) rename {libs/Prism => src}/include/Prism/material.hpp (100%) rename {libs/Prism => src}/include/Prism/matrix.hpp (100%) rename {libs/Prism => src}/include/Prism/mesh.hpp (100%) rename {libs/Prism => src}/include/Prism/objects.hpp (100%) rename {libs/Prism => src}/include/Prism/plane.hpp (100%) rename {libs/Prism => src}/include/Prism/point.hpp (100%) rename {libs/Prism => src}/include/Prism/ray.hpp (100%) rename {libs/Prism => src}/include/Prism/scene.hpp (100%) rename {libs/Prism => src}/include/Prism/scene_parser.hpp (100%) rename {libs/Prism => src}/include/Prism/sphere.hpp (100%) rename {libs/Prism => src}/include/Prism/style.hpp (100%) rename {libs/Prism => src}/include/Prism/triangle.hpp (100%) rename {libs/Prism => src}/include/Prism/utils.hpp (100%) rename {libs/Prism => src}/include/Prism/vector.hpp (100%) rename {libs/Prism => src}/src/camera.cpp (100%) rename {libs/Prism => src}/src/color.cpp (100%) rename {libs/Prism => src}/src/init.cpp (100%) rename {libs/Prism => src}/src/matrix.cpp (100%) rename {libs/Prism => src}/src/mesh.cpp (100%) rename {libs/Prism => src}/src/plane.cpp (100%) rename {libs/Prism => src}/src/point.cpp (100%) rename {libs/Prism => src}/src/ray.cpp (100%) rename {libs/Prism => src}/src/scene.cpp (100%) rename {libs/Prism => src}/src/scene_parser.cpp (95%) rename {libs/Prism => src}/src/sphere.cpp (100%) rename {libs/Prism => src}/src/triangle.cpp (100%) rename {libs/Prism => src}/src/utils.cpp (100%) rename {libs/Prism => src}/src/vector.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5ee1d9..bbabe9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,42 @@ -cmake_minimum_required(VERSION 3.14.0) -cmake_policy(SET CMP0135 NEW) # Policy to modern FetchContent behavior +# =================================================================== +# Prism Library | Root CMakeLists.txt +# +# This is the main project file that orchestrates the entire build. +# It sets global settings and includes the sub-projects (library, app, tests). +# =================================================================== +cmake_minimum_required(VERSION 3.22) +project(Prism VERSION 1.0.0 LANGUAGES CXX) -project(PG_Project VERSION 0.0.1 LANGUAGES C CXX) +# Set the policy for FetchContent to use modern, safer behavior. +cmake_policy(SET CMP0135 NEW) +# --- Global Project Settings --- set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -enable_testing() +# --- Build Options --- +# Add an option to control whether the demo application is built. +# Defaults to ON for typical development, but can be turned off. +option(PRISM_BUILD_DEMO "Build the Prism demo application" ON) +# Set a common output directory for all executables. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -add_subdirectory(libs) -add_subdirectory(src) -if(BUILD_TESTING) - ### include GoogleTest via FetchContent - include(FetchContent) - FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/v1.14.0.zip - ) +# --- Sub-projects --- +add_subdirectory(src) # The Prism library +add_subdirectory(demo) # The demo application - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(googletest) - ### - add_subdirectory(tests) -endif() +# --- Testing --- +enable_testing() +if(BUILD_TESTING) + # Fetch GoogleTest only when tests are enabled. + include(FetchContent) + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/v1.14.0.zip + ) + FetchContent_MakeAvailable(googletest) -install(TARGETS ${PROJECT_NAME} DESTINATION bin) -install(DIRECTORY data DESTINATION bin) \ No newline at end of file + add_subdirectory(tests) +endif() \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index 7c8bf60..c367c02 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -9,7 +9,8 @@ "installDir": "${sourceDir}/install/debug", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", - "BUILD_TESTING": "ON" + "BUILD_TESTING": "ON", + "PRISM_BUILD_DEMO": "ON" } }, { @@ -20,7 +21,8 @@ "installDir": "${sourceDir}/install/release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", - "BUILD_TESTING": "OFF" + "BUILD_TESTING": "OFF", + "PRISM_BUILD_DEMO": "OFF" } } ], diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt new file mode 100644 index 0000000..8969925 --- /dev/null +++ b/demo/CMakeLists.txt @@ -0,0 +1,29 @@ +# =================================================================== +# Prism Demo Application +# +# This CMakeLists.txt file defines the demo application that uses the Prism library. +# It sets up the executable target, links against the Prism library, and handles installation. +# =================================================================== + +add_executable(prism_demo src/main.cpp) + +target_link_libraries(prism_demo PRIVATE Prism) + +# --- Installation --- +install(TARGETS prism_demo DESTINATION bin) + +# This command is now much cleaner. It copies the 'data' directory +# from this subdirectory into the install directory. +install(DIRECTORY data/ DESTINATION .) + +# --- Development/Debugging Support --- + +# This is the key command that solves the debugging issue. +# It copies the 'data' directory into the build output directory +# *after* the executable is built. +add_custom_command(TARGET prism_demo POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_SOURCE_DIR}/data + $/data + COMMENT "Copying data folder for debug/run..." +) \ No newline at end of file diff --git a/data/input/cubo.mtl b/demo/data/input/cubo.mtl similarity index 100% rename from data/input/cubo.mtl rename to demo/data/input/cubo.mtl diff --git a/data/input/cubo.obj b/demo/data/input/cubo.obj similarity index 100% rename from data/input/cubo.obj rename to demo/data/input/cubo.obj diff --git a/data/input/scene.yml b/demo/data/input/scene.yml similarity index 98% rename from data/input/scene.yml rename to demo/data/input/scene.yml index 260ba1f..1572623 100644 --- a/data/input/scene.yml +++ b/demo/data/input/scene.yml @@ -69,7 +69,7 @@ objects: - name: Malha de Cubo Metálico type: mesh - path: "./data/input/cubo.obj" # Caminho para o arquivo .obj + path: "./cubo.obj" # Caminho para o arquivo .obj material: *material_cubo_metalico # Reutiliza o material metálico # Múltiplas transformações são aplicadas em ordem transform: diff --git a/src/main.cpp b/demo/src/main.cpp similarity index 100% rename from src/main.cpp rename to demo/src/main.cpp diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt deleted file mode 100644 index 8a36e9a..0000000 --- a/libs/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -add_library(include INTERFACE) - -add_subdirectory(Prism) -target_link_libraries(include INTERFACE Prism) diff --git a/libs/Prism/CMakeLists.txt b/libs/Prism/CMakeLists.txt deleted file mode 100644 index 957ee2a..0000000 --- a/libs/Prism/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -include(FetchContent) -FetchContent_Declare( - yaml-cpp - GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git - GIT_TAG 0.8.0 -) -FetchContent_MakeAvailable(yaml-cpp) - -file(GLOB_RECURSE PRISM_SOURCES CONFIGURE_DEPENDS "src/*.cpp") -add_library(Prism SHARED ${PRISM_SOURCES}) - -include(GenerateExportHeader) -generate_export_header(Prism) - -target_include_directories(Prism PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/include" - "${CMAKE_CURRENT_BINARY_DIR}" -) - -target_link_libraries(Prism PUBLIC yaml-cpp) - -install(TARGETS Prism - RUNTIME DESTINATION bin # Para .dll no Windows - LIBRARY DESTINATION lib # Para .so no Linux, .dylib no macOS - ARCHIVE DESTINATION lib # Para .lib no Windows (bibliotecas de importação) -) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9cb43e8..cc6e755 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,14 +1,51 @@ -add_executable(${PROJECT_NAME}) +# =================================================================== +# Prism Library | Library Target +# +# This CMakeLists.txt file defines the main shared library target, +# manages its dependencies, and sets up installation rules. +# =================================================================== -target_sources(${PROJECT_NAME} PRIVATE main.cpp) +# --- Dependencies --- +include(FetchContent) +FetchContent_Declare( + yaml-cpp + GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git + # Pinned to a specific commit to fix build issues with modern compilers. + GIT_TAG 2f86d13775d119edbb69af52e5f566fd65c6953b +) +FetchContent_MakeAvailable(yaml-cpp) -target_link_libraries(${PROJECT_NAME} PRIVATE include) +# --- Target Definition --- -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${PROJECT_SOURCE_DIR}/data - "$/data" - COMMENT "Copying data for Debug build..." - ) -endif() +# Collect all source files for the library. +file(GLOB_RECURSE PRISM_SOURCES CONFIGURE_DEPENDS "src/*.cpp") + +# Define the library target as a shared library. +add_library(Prism SHARED ${PRISM_SOURCES}) + +# Automatically generate export headers for Windows/Linux/macOS. +include(GenerateExportHeader) +generate_export_header(Prism) + +# --- Target Properties --- + +# Define the public and private include directories. +target_include_directories(Prism + PUBLIC + $ + $ + $ +) + +# Link the library against its dependencies. +target_link_libraries(Prism PUBLIC yaml-cpp) + +# --- Installation --- +install(TARGETS Prism + EXPORT PrismTargets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) +# Install the public headers. +install(DIRECTORY include/Prism/ DESTINATION include/Prism) \ No newline at end of file diff --git a/libs/Prism/include/Prism.hpp b/src/include/Prism.hpp similarity index 100% rename from libs/Prism/include/Prism.hpp rename to src/include/Prism.hpp diff --git a/libs/Prism/include/Prism/Colormap.hpp b/src/include/Prism/Colormap.hpp similarity index 100% rename from libs/Prism/include/Prism/Colormap.hpp rename to src/include/Prism/Colormap.hpp diff --git a/libs/Prism/include/Prism/ObjReader.hpp b/src/include/Prism/ObjReader.hpp similarity index 100% rename from libs/Prism/include/Prism/ObjReader.hpp rename to src/include/Prism/ObjReader.hpp diff --git a/libs/Prism/include/Prism/camera.hpp b/src/include/Prism/camera.hpp similarity index 100% rename from libs/Prism/include/Prism/camera.hpp rename to src/include/Prism/camera.hpp diff --git a/libs/Prism/include/Prism/color.hpp b/src/include/Prism/color.hpp similarity index 100% rename from libs/Prism/include/Prism/color.hpp rename to src/include/Prism/color.hpp diff --git a/libs/Prism/include/Prism/material.hpp b/src/include/Prism/material.hpp similarity index 100% rename from libs/Prism/include/Prism/material.hpp rename to src/include/Prism/material.hpp diff --git a/libs/Prism/include/Prism/matrix.hpp b/src/include/Prism/matrix.hpp similarity index 100% rename from libs/Prism/include/Prism/matrix.hpp rename to src/include/Prism/matrix.hpp diff --git a/libs/Prism/include/Prism/mesh.hpp b/src/include/Prism/mesh.hpp similarity index 100% rename from libs/Prism/include/Prism/mesh.hpp rename to src/include/Prism/mesh.hpp diff --git a/libs/Prism/include/Prism/objects.hpp b/src/include/Prism/objects.hpp similarity index 100% rename from libs/Prism/include/Prism/objects.hpp rename to src/include/Prism/objects.hpp diff --git a/libs/Prism/include/Prism/plane.hpp b/src/include/Prism/plane.hpp similarity index 100% rename from libs/Prism/include/Prism/plane.hpp rename to src/include/Prism/plane.hpp diff --git a/libs/Prism/include/Prism/point.hpp b/src/include/Prism/point.hpp similarity index 100% rename from libs/Prism/include/Prism/point.hpp rename to src/include/Prism/point.hpp diff --git a/libs/Prism/include/Prism/ray.hpp b/src/include/Prism/ray.hpp similarity index 100% rename from libs/Prism/include/Prism/ray.hpp rename to src/include/Prism/ray.hpp diff --git a/libs/Prism/include/Prism/scene.hpp b/src/include/Prism/scene.hpp similarity index 100% rename from libs/Prism/include/Prism/scene.hpp rename to src/include/Prism/scene.hpp diff --git a/libs/Prism/include/Prism/scene_parser.hpp b/src/include/Prism/scene_parser.hpp similarity index 100% rename from libs/Prism/include/Prism/scene_parser.hpp rename to src/include/Prism/scene_parser.hpp diff --git a/libs/Prism/include/Prism/sphere.hpp b/src/include/Prism/sphere.hpp similarity index 100% rename from libs/Prism/include/Prism/sphere.hpp rename to src/include/Prism/sphere.hpp diff --git a/libs/Prism/include/Prism/style.hpp b/src/include/Prism/style.hpp similarity index 100% rename from libs/Prism/include/Prism/style.hpp rename to src/include/Prism/style.hpp diff --git a/libs/Prism/include/Prism/triangle.hpp b/src/include/Prism/triangle.hpp similarity index 100% rename from libs/Prism/include/Prism/triangle.hpp rename to src/include/Prism/triangle.hpp diff --git a/libs/Prism/include/Prism/utils.hpp b/src/include/Prism/utils.hpp similarity index 100% rename from libs/Prism/include/Prism/utils.hpp rename to src/include/Prism/utils.hpp diff --git a/libs/Prism/include/Prism/vector.hpp b/src/include/Prism/vector.hpp similarity index 100% rename from libs/Prism/include/Prism/vector.hpp rename to src/include/Prism/vector.hpp diff --git a/libs/Prism/src/camera.cpp b/src/src/camera.cpp similarity index 100% rename from libs/Prism/src/camera.cpp rename to src/src/camera.cpp diff --git a/libs/Prism/src/color.cpp b/src/src/color.cpp similarity index 100% rename from libs/Prism/src/color.cpp rename to src/src/color.cpp diff --git a/libs/Prism/src/init.cpp b/src/src/init.cpp similarity index 100% rename from libs/Prism/src/init.cpp rename to src/src/init.cpp diff --git a/libs/Prism/src/matrix.cpp b/src/src/matrix.cpp similarity index 100% rename from libs/Prism/src/matrix.cpp rename to src/src/matrix.cpp diff --git a/libs/Prism/src/mesh.cpp b/src/src/mesh.cpp similarity index 100% rename from libs/Prism/src/mesh.cpp rename to src/src/mesh.cpp diff --git a/libs/Prism/src/plane.cpp b/src/src/plane.cpp similarity index 100% rename from libs/Prism/src/plane.cpp rename to src/src/plane.cpp diff --git a/libs/Prism/src/point.cpp b/src/src/point.cpp similarity index 100% rename from libs/Prism/src/point.cpp rename to src/src/point.cpp diff --git a/libs/Prism/src/ray.cpp b/src/src/ray.cpp similarity index 100% rename from libs/Prism/src/ray.cpp rename to src/src/ray.cpp diff --git a/libs/Prism/src/scene.cpp b/src/src/scene.cpp similarity index 100% rename from libs/Prism/src/scene.cpp rename to src/src/scene.cpp diff --git a/libs/Prism/src/scene_parser.cpp b/src/src/scene_parser.cpp similarity index 95% rename from libs/Prism/src/scene_parser.cpp rename to src/src/scene_parser.cpp index d6a9f83..03c03c5 100644 --- a/libs/Prism/src/scene_parser.cpp +++ b/src/src/scene_parser.cpp @@ -170,8 +170,11 @@ Scene SceneParser::parse() { parsePoint(obj_node["p3"]), material); } else if (type == "mesh") { - std::string path = obj_node["path"].as(); - object = std::make_unique(path); + std::filesystem::path scene_dir = std::filesystem::path(filePath).parent_path(); + std::string mesh_path_str = obj_node["path"].as(); + std::filesystem::path full_mesh_path = scene_dir / mesh_path_str; + + object = std::make_unique(full_mesh_path); // Overrides the .obj material with the one from the .yml, if specified if(obj_node["material"]) { auto mesh_ptr = static_cast(object.get()); diff --git a/libs/Prism/src/sphere.cpp b/src/src/sphere.cpp similarity index 100% rename from libs/Prism/src/sphere.cpp rename to src/src/sphere.cpp diff --git a/libs/Prism/src/triangle.cpp b/src/src/triangle.cpp similarity index 100% rename from libs/Prism/src/triangle.cpp rename to src/src/triangle.cpp diff --git a/libs/Prism/src/utils.cpp b/src/src/utils.cpp similarity index 100% rename from libs/Prism/src/utils.cpp rename to src/src/utils.cpp diff --git a/libs/Prism/src/vector.cpp b/src/src/vector.cpp similarity index 100% rename from libs/Prism/src/vector.cpp rename to src/src/vector.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fd3869a..6c27f03 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,23 @@ +# =================================================================== +# Prism Unit Tests +# +# This CMakeLists.txt file sets up the unit tests for the Prism library. +# It defines the test runner executable, links it against the Prism library, +# and registers the tests with CTest. +# =================================================================== + +# Collect all test source files. file(GLOB_RECURSE TEST_SOURCES "src/*.cpp") + +# Define the test runner executable. add_executable(runTests ${TEST_SOURCES}) -target_link_libraries(runTests PRIVATE include gtest_main) -target_include_directories(runTests PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include) +# Add the local `include` directory for test helpers. +target_include_directories(runTests PRIVATE include) + +# Link the test runner against the library being tested (Prism) +# and the GoogleTest framework. +target_link_libraries(runTests PRIVATE Prism GTest::gtest_main) +# Register the executable with CTest. add_test(NAME UnitTests COMMAND runTests) \ No newline at end of file From 1565c4f968b6e7f99402cfc112178d099a9e6fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Guimar=C3=A3es?= Date: Wed, 9 Jul 2025 16:39:34 -0300 Subject: [PATCH 2/7] refactor(style): format everything acording to clang-format --- CMakeLists.txt | 4 +- README.MD | 4 +- demo/CMakeLists.txt | 5 +- demo/src/main.cpp | 2 +- src/include/Prism.hpp | 4 +- src/include/Prism/Colormap.hpp | 2 +- src/include/Prism/ObjReader.hpp | 2 +- src/include/Prism/style.hpp | 128 ++++++++++++++++---------------- src/src/scene.cpp | 7 +- src/src/scene_parser.cpp | 96 ++++++++++++------------ tests/CMakeLists.txt | 6 +- 11 files changed, 132 insertions(+), 128 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbabe9f..f65caa6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,10 @@ # Prism Library | Root CMakeLists.txt # # This is the main project file that orchestrates the entire build. -# It sets global settings and includes the sub-projects (library, app, tests). +# It sets global settings and includes the sub-projects. # =================================================================== cmake_minimum_required(VERSION 3.22) -project(Prism VERSION 1.0.0 LANGUAGES CXX) +project(Prism VERSION 0.1.0 LANGUAGES CXX) # Set the policy for FetchContent to use modern, safer behavior. cmake_policy(SET CMP0135 NEW) diff --git a/README.MD b/README.MD index e6eafb8..ffed762 100644 --- a/README.MD +++ b/README.MD @@ -5,7 +5,7 @@ To build and run this project, you will need: * **Git** -* **CMake** (version 3.15 or higher recommended) +* **CMake** (version 3.22 or higher recommended) * A **C++17 compliant compiler** (e.g., GCC, Clang, MSVC) ## Building the Project @@ -74,7 +74,7 @@ sudo apt install clang-format To format all `.hpp` and `.cpp` files in the `src`, `libs`, and `tests` directories at once, run the following command from the **root directory of the project**: ```sh -find src libs tests -name "*.cpp" -o -name "*.hpp" | xargs clang-format -i +find src demo tests -name "*.cpp" -o -name "*.hpp" | xargs clang-format -i ``` **What this command does:** diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt index 8969925..54e21f9 100644 --- a/demo/CMakeLists.txt +++ b/demo/CMakeLists.txt @@ -1,8 +1,9 @@ # =================================================================== # Prism Demo Application # -# This CMakeLists.txt file defines the demo application that uses the Prism library. -# It sets up the executable target, links against the Prism library, and handles installation. +# This CMakeLists.txt file defines the demo application that uses the +# Prism library. It sets up the executable target, links against the +# Prism library, and handles installation. # =================================================================== add_executable(prism_demo src/main.cpp) diff --git a/demo/src/main.cpp b/demo/src/main.cpp index ac573fc..0b8fe66 100644 --- a/demo/src/main.cpp +++ b/demo/src/main.cpp @@ -4,7 +4,7 @@ int main() { try { Prism::SceneParser("./data/input/scene.yml").parse().render(); - + } catch (const std::exception& e) { Prism::Style::logError(e.what()); return 1; diff --git a/src/include/Prism.hpp b/src/include/Prism.hpp index f4eb640..70f6ddc 100644 --- a/src/include/Prism.hpp +++ b/src/include/Prism.hpp @@ -10,9 +10,9 @@ #include "Prism/point.hpp" #include "Prism/ray.hpp" #include "Prism/scene.hpp" +#include "Prism/scene_parser.hpp" #include "Prism/sphere.hpp" +#include "Prism/style.hpp" #include "Prism/triangle.hpp" #include "Prism/utils.hpp" #include "Prism/vector.hpp" -#include "Prism/scene_parser.hpp" -#include "Prism/style.hpp" \ No newline at end of file diff --git a/src/include/Prism/Colormap.hpp b/src/include/Prism/Colormap.hpp index 6e93f11..0f504e8 100644 --- a/src/include/Prism/Colormap.hpp +++ b/src/include/Prism/Colormap.hpp @@ -18,6 +18,7 @@ A classe precisa ser instânciada passando o caminho do arquivo .mtl corresponde */ #include "Prism/material.hpp" +#include "Prism/style.hpp" #include "Prism/vector.hpp" #include "prism_export.h" #include @@ -26,7 +27,6 @@ A classe precisa ser instânciada passando o caminho do arquivo .mtl corresponde #include #include #include -#include "Prism/style.hpp" using namespace std; namespace Prism { diff --git a/src/include/Prism/ObjReader.hpp b/src/include/Prism/ObjReader.hpp index 3281010..7f92bad 100644 --- a/src/include/Prism/ObjReader.hpp +++ b/src/include/Prism/ObjReader.hpp @@ -4,9 +4,9 @@ #include "Prism/Colormap.hpp" #include "Prism/material.hpp" #include "Prism/point.hpp" +#include "Prism/style.hpp" #include "Prism/triangle.hpp" #include "Prism/vector.hpp" -#include "Prism/style.hpp" #include "prism_export.h" #include #include diff --git a/src/include/Prism/style.hpp b/src/include/Prism/style.hpp index 4bc034d..3864057 100644 --- a/src/include/Prism/style.hpp +++ b/src/include/Prism/style.hpp @@ -2,8 +2,8 @@ #define PRISM_STYLE_HPP_ #include "prism_export.h" -#include #include +#include namespace Prism { @@ -16,78 +16,80 @@ namespace Prism { */ namespace Style { - // --- Basic Colors --- - const std::string RESET = "\033[0m"; - const std::string YELLOW = "\033[0;33m"; - const std::string GREEN = "\033[0;32m"; - const std::string CYAN = "\033[0;36m"; - const std::string GRAY = "\033[0;90m"; - const std::string RED = "\033[0;31m"; +// --- Basic Colors --- +const std::string RESET = "\033[0m"; +const std::string YELLOW = "\033[0;33m"; +const std::string GREEN = "\033[0;32m"; +const std::string CYAN = "\033[0;36m"; +const std::string GRAY = "\033[0;90m"; +const std::string RED = "\033[0;31m"; - // --- Bold Variants --- - const std::string BOLD_CYAN = "\033[1;36m"; - const std::string BOLD_GREEN = "\033[1;32m"; - const std::string BOLD_RED = "\033[1;31m"; - const std::string BOLD_YELLOW= "\033[1;33m"; +// --- Bold Variants --- +const std::string BOLD_CYAN = "\033[1;36m"; +const std::string BOLD_GREEN = "\033[1;32m"; +const std::string BOLD_RED = "\033[1;31m"; +const std::string BOLD_YELLOW = "\033[1;33m"; - /** - * @brief Logs a formatted informational message to std::clog. - * @param message The message to display. - */ - inline void logInfo(const std::string& message) { - std::clog << YELLOW << "[INFO] " << RESET << message << std::endl; - } +/** + * @brief Logs a formatted informational message to std::clog. + * @param message The message to display. + */ +inline void logInfo(const std::string& message) { + std::clog << YELLOW << "[INFO] " << RESET << message << std::endl; +} - /** - * @brief Logs a formatted completion message to std::clog. - * @param message The message to display. - */ - inline void logDone(const std::string& message) { - std::clog << GREEN << "[DONE] " << RESET << message << std::endl; - } +/** + * @brief Logs a formatted completion message to std::clog. + * @param message The message to display. + */ +inline void logDone(const std::string& message) { + std::clog << GREEN << "[DONE] " << RESET << message << std::endl; +} - /** - * @brief Logs a formatted error message to std::cerr. - * @param message The error message to display. - */ - inline void logError(const std::string& message) { - std::cerr << BOLD_RED << "[ERROR] " << RESET - << RED << message << RESET << std::endl; - } +/** + * @brief Logs a formatted error message to std::cerr. + * @param message The error message to display. + */ +inline void logError(const std::string& message) { + std::cerr << BOLD_RED << "[ERROR] " << RESET << RED << message << RESET << std::endl; +} - /** - * @brief Logs a formatted warning message to std::clog. - * @param message The warning message to display. - */ - inline void logWarning(const std::string& message) { - std::clog << BOLD_YELLOW << "[WARNING] " << RESET - << YELLOW << message << RESET << std::endl; - } +/** + * @brief Logs a formatted warning message to std::clog. + * @param message The warning message to display. + */ +inline void logWarning(const std::string& message) { + std::clog << BOLD_YELLOW << "[WARNING] " << RESET << YELLOW << message << RESET << std::endl; +} - /** - * @brief Displays a dynamic status bar on the current line in std::clog. - * @param progress A value between 0.0 and 1.0 indicating completion. - * @param width The total character width of the bar itself. - */ - inline void logStatusBar(double progress, int width = 25) { - if (progress < 0.0) progress = 0.0; - if (progress > 1.0) progress = 1.0; +/** + * @brief Displays a dynamic status bar on the current line in std::clog. + * @param progress A value between 0.0 and 1.0 indicating completion. + * @param width The total character width of the bar itself. + */ +inline void logStatusBar(double progress, int width = 25) { + if (progress < 0.0) + progress = 0.0; + if (progress > 1.0) + progress = 1.0; - int bar_fill = static_cast(progress * width); - int percentage = static_cast(progress * 100.0); + int bar_fill = static_cast(progress * width); + int percentage = static_cast(progress * 100.0); - // \r (carriage return) move o cursor para o início da linha - std::clog << GREEN << "\rProgress: [" << RESET; - for (int i = 0; i < width; ++i) { - if (i < bar_fill) std::clog << "="; - else std::clog << " "; - } - std::clog << GREEN << "] " << percentage << "%" << RESET << std::flush; + // \r (carriage return) move o cursor para o início da linha + std::clog << GREEN << "\rProgress: [" << RESET; + for (int i = 0; i < width; ++i) { + if (i < bar_fill) + std::clog << "="; + else + std::clog << " "; + } + std::clog << GREEN << "] " << percentage << "%" << RESET << std::flush; - if (progress >= 1.0) { - std::clog << '\n' << std::endl; - } + if (progress >= 1.0) { + std::clog << '\n' << std::endl; } +} } // namespace Style } // namespace Prism diff --git a/src/src/scene.cpp b/src/src/scene.cpp index 020b21e..66e5d79 100644 --- a/src/src/scene.cpp +++ b/src/src/scene.cpp @@ -70,7 +70,7 @@ void Scene::render() const { } auto clean_path = std::filesystem::weakly_canonical(output_dir); - + Style::logInfo("Output directory: " + Prism::Style::CYAN + clean_path.string()); Style::logInfo("Starting render...\n"); @@ -106,14 +106,15 @@ void Scene::render() const { image_file << pixel_color << '\n'; pixels_done++; - int current_progress_percent = static_cast((static_cast(pixels_done) / total_pixels) * 100.0); + int current_progress_percent = + static_cast((static_cast(pixels_done) / total_pixels) * 100.0); if (current_progress_percent > last_progress_percent) { last_progress_percent = current_progress_percent; Style::logStatusBar(static_cast(current_progress_percent) / 100.0); } } - + image_file.close(); Style::logDone("Rendering complete."); diff --git a/src/src/scene_parser.cpp b/src/src/scene_parser.cpp index 03c03c5..ccb181a 100644 --- a/src/src/scene_parser.cpp +++ b/src/src/scene_parser.cpp @@ -1,23 +1,23 @@ #include "Prism/scene_parser.hpp" -#include -#include -#include -#include -#include -#include "Prism/scene.hpp" #include "Prism/camera.hpp" +#include "Prism/color.hpp" #include "Prism/material.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" #include "Prism/matrix.hpp" +#include "Prism/mesh.hpp" #include "Prism/objects.hpp" -#include "Prism/sphere.hpp" #include "Prism/plane.hpp" -#include "Prism/triangle.hpp" -#include "Prism/mesh.hpp" -#include "Prism/color.hpp" +#include "Prism/point.hpp" +#include "Prism/scene.hpp" +#include "Prism/sphere.hpp" #include "Prism/style.hpp" +#include "Prism/triangle.hpp" +#include "Prism/vector.hpp" #include +#include +#include +#include +#include +#include #ifndef M_PI #define M_PI 3.14159265358979323846 // Define M_PI if not already defined @@ -46,21 +46,31 @@ Vector3 parseVector(const YAML::Node& node) { // Converts a YAML node with material properties to a Material std::shared_ptr parseMaterial(const YAML::Node& node) { auto mat = std::make_shared(); - - if (node["color"]) {Vector3 v = parseVector(node["color"]); mat->color = Color(v.x, v.y, v.z);} - if (node["ka"]) mat->ka = parseVector(node["ka"]); - if (node["ks"]) mat->ks = parseVector(node["ks"]); - if (node["ke"]) mat->ke = parseVector(node["ke"]); - if (node["ns"]) mat->ns = node["ns"].as(); - if (node["ni"]) mat->ni = node["ni"].as(); - if (node["d"]) mat->d = node["d"].as(); + + if (node["color"]) { + Vector3 v = parseVector(node["color"]); + mat->color = Color(v.x, v.y, v.z); + } + if (node["ka"]) + mat->ka = parseVector(node["ka"]); + if (node["ks"]) + mat->ks = parseVector(node["ks"]); + if (node["ke"]) + mat->ke = parseVector(node["ke"]); + if (node["ns"]) + mat->ns = node["ns"].as(); + if (node["ni"]) + mat->ni = node["ni"].as(); + if (node["d"]) + mat->d = node["d"].as(); return mat; } // Converts a YAML list of transformations into a single transformation matrix Matrix parseTransformations(const YAML::Node& node) { Matrix final_transform = Matrix::identity(4); - if (!node) return final_transform; + if (!node) + return final_transform; // Transformations are applied in the reverse order of the list (standard in computer graphics) for (int i = node.size() - 1; i >= 0; --i) { @@ -79,7 +89,8 @@ Matrix parseTransformations(const YAML::Node& node) { Vector3 v = parseVector(transform_node["factors"]); current_transform = Matrix::scaling(v.x, v.y, v.z); } else { - Style::logWarning("Unknown transformation type: " + type + ". Skipping this transformation."); + Style::logWarning("Unknown transformation type: " + type + + ". Skipping this transformation."); continue; // Skip unknown transformation types } final_transform = final_transform * current_transform; @@ -89,7 +100,8 @@ Matrix parseTransformations(const YAML::Node& node) { // --- SceneParser Class Implementation --- -SceneParser::SceneParser(const std::string& sceneFilePath) : filePath(sceneFilePath) {} +SceneParser::SceneParser(const std::string& sceneFilePath) : filePath(sceneFilePath) { +} Scene SceneParser::parse() { YAML::Node root; @@ -106,16 +118,10 @@ Scene SceneParser::parse() { throw std::runtime_error("'camera' node not found in the scene file."); } const auto& cam_node = root["camera"]; - Camera camera( - parsePoint(cam_node["lookfrom"]), - parsePoint(cam_node["lookat"]), - parseVector(cam_node["vup"]), - cam_node["screen_distance"].as(), - cam_node["viewport_height"].as(), - cam_node["viewport_width"].as(), - cam_node["image_height"].as(), - cam_node["image_width"].as() - ); + Camera camera(parsePoint(cam_node["lookfrom"]), parsePoint(cam_node["lookat"]), + parseVector(cam_node["vup"]), cam_node["screen_distance"].as(), + cam_node["viewport_height"].as(), cam_node["viewport_width"].as(), + cam_node["image_height"].as(), cam_node["image_width"].as()); Scene scene(std::move(camera)); @@ -135,7 +141,7 @@ Scene SceneParser::parse() { for (const auto& obj_node : root["objects"]) { std::string type = obj_node["type"].as(); - + // Find the material (whether defined inline or by reference) std::shared_ptr material; if (obj_node["material"].IsMap()) { @@ -154,21 +160,15 @@ Scene SceneParser::parse() { std::unique_ptr object; if (type == "sphere") { - object = std::make_unique( - parsePoint(obj_node["center"]), - obj_node["radius"].as(), - material); + object = std::make_unique(parsePoint(obj_node["center"]), + obj_node["radius"].as(), material); } else if (type == "plane") { - object = std::make_unique( - parsePoint(obj_node["point_on_plane"]), - parseVector(obj_node["normal"]), - material); + object = std::make_unique(parsePoint(obj_node["point_on_plane"]), + parseVector(obj_node["normal"]), material); } else if (type == "triangle") { - object = std::make_unique( - parsePoint(obj_node["p1"]), - parsePoint(obj_node["p2"]), - parsePoint(obj_node["p3"]), - material); + object = + std::make_unique(parsePoint(obj_node["p1"]), parsePoint(obj_node["p2"]), + parsePoint(obj_node["p3"]), material); } else if (type == "mesh") { std::filesystem::path scene_dir = std::filesystem::path(filePath).parent_path(); std::string mesh_path_str = obj_node["path"].as(); @@ -176,7 +176,7 @@ Scene SceneParser::parse() { object = std::make_unique(full_mesh_path); // Overrides the .obj material with the one from the .yml, if specified - if(obj_node["material"]) { + if (obj_node["material"]) { auto mesh_ptr = static_cast(object.get()); // (A material setter would be needed in the Mesh class here) } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6c27f03..e1c74a9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,9 +1,9 @@ # =================================================================== # Prism Unit Tests # -# This CMakeLists.txt file sets up the unit tests for the Prism library. -# It defines the test runner executable, links it against the Prism library, -# and registers the tests with CTest. +# This CMakeLists.txt file sets up the unit tests for the Prism +# library. It defines the test runner executable, links it against +# the Prism library and registers the tests with CTest. # =================================================================== # Collect all test source files. From 4af479e8a41a75df35f70a12a5419b39efa8352f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Guimar=C3=A3es?= Date: Wed, 9 Jul 2025 16:43:19 -0300 Subject: [PATCH 3/7] refactor(style): changed extension to lower --- README.MD => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.MD => README.md (100%) diff --git a/README.MD b/README.md similarity index 100% rename from README.MD rename to README.md From 3a754b79bec45a233d8717540d32272fbb0cbb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Guimar=C3=A3es?= Date: Wed, 9 Jul 2025 17:13:21 -0300 Subject: [PATCH 4/7] modular --- ARCHITECTURE.md | 112 +++++++++++++++++++ README.md | 93 ++++++++++----- src/CMakeLists.txt | 79 +++++++++++-- src/include/Prism/{ => core}/color.hpp | 0 src/include/Prism/{ => core}/matrix.hpp | 0 src/include/Prism/{ => core}/point.hpp | 0 src/include/Prism/{ => core}/ray.hpp | 0 src/include/Prism/{ => core}/style.hpp | 0 src/include/Prism/{ => core}/utils.hpp | 0 src/include/Prism/{ => core}/vector.hpp | 0 src/include/Prism/{ => io}/Colormap.hpp | 0 src/include/Prism/{ => io}/ObjReader.hpp | 0 src/include/Prism/{ => io}/scene_parser.hpp | 0 src/include/Prism/{ => objects}/mesh.hpp | 0 src/include/Prism/{ => objects}/objects.hpp | 0 src/include/Prism/{ => objects}/plane.hpp | 0 src/include/Prism/{ => objects}/sphere.hpp | 0 src/include/Prism/{ => objects}/triangle.hpp | 0 src/include/Prism/{ => scene}/camera.hpp | 0 src/include/Prism/{ => scene}/material.hpp | 0 src/include/Prism/{ => scene}/scene.hpp | 0 src/src/{ => core}/color.cpp | 0 src/src/{ => core}/init.cpp | 0 src/src/{ => core}/matrix.cpp | 0 src/src/{ => core}/point.cpp | 0 src/src/{ => core}/ray.cpp | 0 src/src/{ => core}/utils.cpp | 0 src/src/{ => core}/vector.cpp | 0 src/src/{ => objects}/mesh.cpp | 0 src/src/{ => objects}/plane.cpp | 0 src/src/{ => objects}/scene_parser.cpp | 0 src/src/{ => objects}/sphere.cpp | 0 src/src/{ => objects}/triangle.cpp | 0 src/src/{ => scene}/camera.cpp | 0 src/src/{ => scene}/scene.cpp | 0 35 files changed, 247 insertions(+), 37 deletions(-) create mode 100644 ARCHITECTURE.md rename src/include/Prism/{ => core}/color.hpp (100%) rename src/include/Prism/{ => core}/matrix.hpp (100%) rename src/include/Prism/{ => core}/point.hpp (100%) rename src/include/Prism/{ => core}/ray.hpp (100%) rename src/include/Prism/{ => core}/style.hpp (100%) rename src/include/Prism/{ => core}/utils.hpp (100%) rename src/include/Prism/{ => core}/vector.hpp (100%) rename src/include/Prism/{ => io}/Colormap.hpp (100%) rename src/include/Prism/{ => io}/ObjReader.hpp (100%) rename src/include/Prism/{ => io}/scene_parser.hpp (100%) rename src/include/Prism/{ => objects}/mesh.hpp (100%) rename src/include/Prism/{ => objects}/objects.hpp (100%) rename src/include/Prism/{ => objects}/plane.hpp (100%) rename src/include/Prism/{ => objects}/sphere.hpp (100%) rename src/include/Prism/{ => objects}/triangle.hpp (100%) rename src/include/Prism/{ => scene}/camera.hpp (100%) rename src/include/Prism/{ => scene}/material.hpp (100%) rename src/include/Prism/{ => scene}/scene.hpp (100%) rename src/src/{ => core}/color.cpp (100%) rename src/src/{ => core}/init.cpp (100%) rename src/src/{ => core}/matrix.cpp (100%) rename src/src/{ => core}/point.cpp (100%) rename src/src/{ => core}/ray.cpp (100%) rename src/src/{ => core}/utils.cpp (100%) rename src/src/{ => core}/vector.cpp (100%) rename src/src/{ => objects}/mesh.cpp (100%) rename src/src/{ => objects}/plane.cpp (100%) rename src/src/{ => objects}/scene_parser.cpp (100%) rename src/src/{ => objects}/sphere.cpp (100%) rename src/src/{ => objects}/triangle.cpp (100%) rename src/src/{ => scene}/camera.cpp (100%) rename src/src/{ => scene}/scene.cpp (100%) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md new file mode 100644 index 0000000..b8ade65 --- /dev/null +++ b/ARCHITECTURE.md @@ -0,0 +1,112 @@ +# 🏛️ Prism Project Architecture + +This document provides a visual overview of the dependency structure of the Prism rendering engine, from a high-level view down to the internal class relationships. + +## High-Level Project Dependency Graph + +This graph shows how the main project components (the demo application, the core library, and the unit tests) interact with each other and with external libraries. + +```mermaid +graph TD; + subgraph "External Dependencies" + YAML_CPP["📚 yaml-cpp"]; + GTEST["🧪 GoogleTest"]; + end + + subgraph "Prism Project" + DEMO["💻 prism_demo (Demo App)"]; + PRISM_LIB["🎨 Prism (Library)"]; + TESTS["⚙️ runTests (Unit Tests)"]; + end + + DEMO --> PRISM_LIB; + TESTS --> PRISM_LIB; + TESTS --> GTEST; + PRISM_LIB --> YAML_CPP; + + style DEMO fill:#cce5ff,stroke:#333,stroke-width:2px; + style TESTS fill:#d5e8d4,stroke:#333,stroke-width:2px; + style PRISM_LIB fill:#ffcce5,stroke:#333,stroke-width:2px; + style YAML_CPP fill:#fff2cc,stroke:#333,stroke-width:2px; + style GTEST fill:#fff2cc,stroke:#333,stroke-width:2px; +``` + +## Internal Library Dependencies + +This graph shows the relationships between the major classes within the Prism library itself. + +```mermaid +graph TD; + subgraph "High-Level Management" + SCENE_PARSER["📄 SceneParser"]; + SCENE["🎬 Scene"]; + CAMERA["📷 Camera"]; + end + + subgraph "Geometric Objects (Hittables)" + OBJECT["🧩 Object (Base)"]; + SPHERE["⚪ Sphere"]; + PLANE["🌐 Plane"]; + TRIANGLE["🔺 Triangle"]; + MESH["🧊 Mesh"]; + end + + subgraph "Core Math & Data Structures" + RAY["➡️ Ray"]; + POINT3["📍 Point3"]; + VECTOR3["📏 Vector3"]; + MATRIX["🧮 Matrix"]; + MATERIAL["✨ Material"]; + COLOR["🌈 Color"]; + OBJ_READER["📑 ObjReader"]; + end + + %% High-level dependencies + SCENE_PARSER --> SCENE; + SCENE_PARSER --> CAMERA; + SCENE_PARSER --> MESH; + SCENE_PARSER --> SPHERE; + SCENE_PARSER --> PLANE; + SCENE_PARSER --> TRIANGLE; + SCENE_PARSER --> MATERIAL; + + SCENE --> CAMERA; + SCENE --> OBJECT; + SCENE --> RAY; + SCENE --> COLOR; + + CAMERA --> RAY; + CAMERA --> MATRIX; + CAMERA --> POINT3; + CAMERA --> VECTOR3; + + %% Geometric object dependencies + MESH --> OBJECT; + MESH --> OBJ_READER; + MESH --> TRIANGLE; + MESH --> MATERIAL; + + SPHERE --> OBJECT; + PLANE --> OBJECT; + TRIANGLE --> OBJECT; + + OBJECT --> RAY; + OBJECT --> MATRIX; + OBJECT --> MATERIAL; + + OBJ_READER --> MATERIAL; + OBJ_READER --> COLOR; + OBJ_READER --> VECTOR3; + OBJ_READER --> POINT3; + + %% Core math dependencies + RAY --> POINT3; + RAY --> VECTOR3; + RAY --> MATRIX; + + MATRIX --> POINT3; + MATRIX --> VECTOR3; + + POINT3 --> VECTOR3; + VECTOR3 --> POINT3; +``` diff --git a/README.md b/README.md index ffed762..187a199 100644 --- a/README.md +++ b/README.md @@ -55,36 +55,6 @@ The following presets are available: --- -## Code Formatting - -This project uses `clang-format` to maintain a consistent code style across the entire codebase. A configuration file (`.clang-format`) is included in the project root to define the style rules. - -Before committing any changes, please format your code. - -### Installing clang-format - -You must have `clang-format` installed on your system. On Debian/Ubuntu-based systems, you can install it with: - -```sh -sudo apt install clang-format -``` - -### Formatting the Entire Project - -To format all `.hpp` and `.cpp` files in the `src`, `libs`, and `tests` directories at once, run the following command from the **root directory of the project**: - -```sh -find src demo tests -name "*.cpp" -o -name "*.hpp" | xargs clang-format -i -``` - -**What this command does:** - -* `find src libs tests ...`: Searches for files within the `src`, `libs`, and `tests` folders. -* `-name "*.cpp" -o -name "*.hpp"`: Finds files that end in `.cpp` OR `.hpp`. -* `| xargs clang-format -i`: For every file found, it runs the command `clang-format -i` to format it in-place. - ---- - ## Running the Application The executable (`PG_Project`) will be located in the `bin` subdirectory of your build folder. @@ -128,3 +98,66 @@ This project includes rules to create a clean, distributable package in a local ``` The `install/release` folder will then contain the `PG_Project` executable and the `libPrism.so` (or `Prism.dll`) library, ready to be run together. + +## Code Formatting + +This project uses `clang-format` to maintain a consistent code style across the entire codebase. A configuration file (`.clang-format`) is included in the project root to define the style rules. + +Before committing any changes, please format your code. + +### Installing clang-format + +You must have `clang-format` installed on your system. On Debian/Ubuntu-based systems, you can install it with: + +```sh +sudo apt install clang-format +``` + +### Formatting the Entire Project + +To format all `.hpp` and `.cpp` files in the `src`, `libs`, and `tests` directories at once, run the following command from the **root directory of the project**: + +```sh +find src demo tests -name "*.cpp" -o -name "*.hpp" | xargs clang-format -i +``` + +**What this command does:** + +* `find src libs tests ...`: Searches for files within the `src`, `libs`, and `tests` folders. +* `-name "*.cpp" -o -name "*.hpp"`: Finds files that end in `.cpp` OR `.hpp`. +* `| xargs clang-format -i`: For every file found, it runs the command `clang-format -i` to format it in-place. + +--- + +## 🏛️ Project Architecture + +The project is organized into three main components: the core `Prism` library, a `prism_demo` application that uses the library, and a `runTests` executable for unit testing. The dependencies are managed by CMake and are visualized below. + +```mermaid +graph TD; + subgraph "External Dependencies" + YAML_CPP["📚 yaml-cpp"]; + GTEST["🧪 GoogleTest"]; + end + + subgraph "Prism Project" + DEMO["💻 prism_demo (Demo App)"]; + PRISM_LIB["🎨 Prism (Library)"]; + TESTS["⚙️ runTests (Unit Tests)"]; + end + + DEMO --> PRISM_LIB; + TESTS --> PRISM_LIB; + TESTS --> GTEST; + PRISM_LIB --> YAML_CPP; + + style DEMO fill:#cce5ff,stroke:#333,stroke-width:2px; + style TESTS fill:#d5e8d4,stroke:#333,stroke-width:2px; + style PRISM_LIB fill:#ffcce5,stroke:#333,stroke-width:2px; + style YAML_CPP fill:#fff2cc,stroke:#333,stroke-width:2px; + style GTEST fill:#fff2cc,stroke:#333,stroke-width:2px; +``` + +For a more detailed breakdown of the internal library dependencies, please see the ARCHITECTURE.md file. + +--- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc6e755..0ce7826 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,7 @@ # =================================================================== # --- Dependencies --- + include(FetchContent) FetchContent_Declare( yaml-cpp @@ -15,18 +16,64 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(yaml-cpp) -# --- Target Definition --- +# --- Build Options --- + +# Option to build the core math and data structures (mandatory) +option(PRISM_BUILD_CORE "Build the Core module (math, etc.)" ON) + +# Optional modules +option(PRISM_BUILD_OBJECTS "Build the Objects module (Sphere, Plane, Mesh, etc.)" ON) +option(PRISM_BUILD_IO "Build the I/O module (SceneParser, ObjReader)" ON) +option(PRISM_BUILD_SCENE "Build the Scene module (Scene, Camera)" ON) + +# The CORE module is essential for all other parts of the library. +if(NOT PRISM_BUILD_CORE) + message(FATAL_ERROR "PRISM_BUILD_CORE is a required module and cannot be disabled.") +endif() + + +# --- Build Source File Collection --- + +# Start with an empty list for our library's source files. +set(PRISM_SOURCES "") + +# Always add the core source files. +if(PRISM_BUILD_CORE) + file(GLOB CORE_SOURCES CONFIGURE_DEPENDS "src/core/*.cpp") + list(APPEND PRISM_SOURCES ${CORE_SOURCES}) +endif() + +# Conditionally add sources for the other modules. +if(PRISM_BUILD_OBJECTS) + file(GLOB GEOMETRY_SOURCES CONFIGURE_DEPENDS "src/objects/*.cpp") + list(APPEND PRISM_SOURCES ${GEOMETRY_SOURCES}) +endif() + +if(PRISM_BUILD_IO) + file(GLOB IO_SOURCES CONFIGURE_DEPENDS "src/io/*.cpp") + list(APPEND PRISM_SOURCES ${IO_SOURCES}) +endif() -# Collect all source files for the library. -file(GLOB_RECURSE PRISM_SOURCES CONFIGURE_DEPENDS "src/*.cpp") +if(PRISM_BUILD_SCENE) + file(GLOB SCENE_SOURCES CONFIGURE_DEPENDS "src/scene/*.cpp") + list(APPEND PRISM_SOURCES ${SCENE_SOURCES}) +endif() -# Define the library target as a shared library. +# Add any remaining top-level source files (e.g., init.cpp) +file(GLOB OTHER_SOURCES CONFIGURE_DEPENDS "src/*.cpp") +list(APPEND PRISM_SOURCES ${OTHER_SOURCES}) + + +# --- Target Definition --- + +# Define the library target using the conditionally populated source list. add_library(Prism SHARED ${PRISM_SOURCES}) # Automatically generate export headers for Windows/Linux/macOS. include(GenerateExportHeader) generate_export_header(Prism) + # --- Target Properties --- # Define the public and private include directories. @@ -38,14 +85,32 @@ target_include_directories(Prism ) # Link the library against its dependencies. -target_link_libraries(Prism PUBLIC yaml-cpp) +# The yaml-cpp dependency is only needed if the IO module is built. +if(PRISM_BUILD_IO) + target_link_libraries(Prism PUBLIC yaml-cpp) +endif() + # --- Installation --- + install(TARGETS Prism EXPORT PrismTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) -# Install the public headers. -install(DIRECTORY include/Prism/ DESTINATION include/Prism) \ No newline at end of file + +# Install the public headers, preserving the subdirectory structure. +install(DIRECTORY + include/Prism/core + include/Prism/objects + include/Prism/io + include/Prism/scene + DESTINATION include/Prism +) + +# Install any top-level header files like Prism.hpp +install(FILES + include/Prism.hpp + DESTINATION include +) \ No newline at end of file diff --git a/src/include/Prism/color.hpp b/src/include/Prism/core/color.hpp similarity index 100% rename from src/include/Prism/color.hpp rename to src/include/Prism/core/color.hpp diff --git a/src/include/Prism/matrix.hpp b/src/include/Prism/core/matrix.hpp similarity index 100% rename from src/include/Prism/matrix.hpp rename to src/include/Prism/core/matrix.hpp diff --git a/src/include/Prism/point.hpp b/src/include/Prism/core/point.hpp similarity index 100% rename from src/include/Prism/point.hpp rename to src/include/Prism/core/point.hpp diff --git a/src/include/Prism/ray.hpp b/src/include/Prism/core/ray.hpp similarity index 100% rename from src/include/Prism/ray.hpp rename to src/include/Prism/core/ray.hpp diff --git a/src/include/Prism/style.hpp b/src/include/Prism/core/style.hpp similarity index 100% rename from src/include/Prism/style.hpp rename to src/include/Prism/core/style.hpp diff --git a/src/include/Prism/utils.hpp b/src/include/Prism/core/utils.hpp similarity index 100% rename from src/include/Prism/utils.hpp rename to src/include/Prism/core/utils.hpp diff --git a/src/include/Prism/vector.hpp b/src/include/Prism/core/vector.hpp similarity index 100% rename from src/include/Prism/vector.hpp rename to src/include/Prism/core/vector.hpp diff --git a/src/include/Prism/Colormap.hpp b/src/include/Prism/io/Colormap.hpp similarity index 100% rename from src/include/Prism/Colormap.hpp rename to src/include/Prism/io/Colormap.hpp diff --git a/src/include/Prism/ObjReader.hpp b/src/include/Prism/io/ObjReader.hpp similarity index 100% rename from src/include/Prism/ObjReader.hpp rename to src/include/Prism/io/ObjReader.hpp diff --git a/src/include/Prism/scene_parser.hpp b/src/include/Prism/io/scene_parser.hpp similarity index 100% rename from src/include/Prism/scene_parser.hpp rename to src/include/Prism/io/scene_parser.hpp diff --git a/src/include/Prism/mesh.hpp b/src/include/Prism/objects/mesh.hpp similarity index 100% rename from src/include/Prism/mesh.hpp rename to src/include/Prism/objects/mesh.hpp diff --git a/src/include/Prism/objects.hpp b/src/include/Prism/objects/objects.hpp similarity index 100% rename from src/include/Prism/objects.hpp rename to src/include/Prism/objects/objects.hpp diff --git a/src/include/Prism/plane.hpp b/src/include/Prism/objects/plane.hpp similarity index 100% rename from src/include/Prism/plane.hpp rename to src/include/Prism/objects/plane.hpp diff --git a/src/include/Prism/sphere.hpp b/src/include/Prism/objects/sphere.hpp similarity index 100% rename from src/include/Prism/sphere.hpp rename to src/include/Prism/objects/sphere.hpp diff --git a/src/include/Prism/triangle.hpp b/src/include/Prism/objects/triangle.hpp similarity index 100% rename from src/include/Prism/triangle.hpp rename to src/include/Prism/objects/triangle.hpp diff --git a/src/include/Prism/camera.hpp b/src/include/Prism/scene/camera.hpp similarity index 100% rename from src/include/Prism/camera.hpp rename to src/include/Prism/scene/camera.hpp diff --git a/src/include/Prism/material.hpp b/src/include/Prism/scene/material.hpp similarity index 100% rename from src/include/Prism/material.hpp rename to src/include/Prism/scene/material.hpp diff --git a/src/include/Prism/scene.hpp b/src/include/Prism/scene/scene.hpp similarity index 100% rename from src/include/Prism/scene.hpp rename to src/include/Prism/scene/scene.hpp diff --git a/src/src/color.cpp b/src/src/core/color.cpp similarity index 100% rename from src/src/color.cpp rename to src/src/core/color.cpp diff --git a/src/src/init.cpp b/src/src/core/init.cpp similarity index 100% rename from src/src/init.cpp rename to src/src/core/init.cpp diff --git a/src/src/matrix.cpp b/src/src/core/matrix.cpp similarity index 100% rename from src/src/matrix.cpp rename to src/src/core/matrix.cpp diff --git a/src/src/point.cpp b/src/src/core/point.cpp similarity index 100% rename from src/src/point.cpp rename to src/src/core/point.cpp diff --git a/src/src/ray.cpp b/src/src/core/ray.cpp similarity index 100% rename from src/src/ray.cpp rename to src/src/core/ray.cpp diff --git a/src/src/utils.cpp b/src/src/core/utils.cpp similarity index 100% rename from src/src/utils.cpp rename to src/src/core/utils.cpp diff --git a/src/src/vector.cpp b/src/src/core/vector.cpp similarity index 100% rename from src/src/vector.cpp rename to src/src/core/vector.cpp diff --git a/src/src/mesh.cpp b/src/src/objects/mesh.cpp similarity index 100% rename from src/src/mesh.cpp rename to src/src/objects/mesh.cpp diff --git a/src/src/plane.cpp b/src/src/objects/plane.cpp similarity index 100% rename from src/src/plane.cpp rename to src/src/objects/plane.cpp diff --git a/src/src/scene_parser.cpp b/src/src/objects/scene_parser.cpp similarity index 100% rename from src/src/scene_parser.cpp rename to src/src/objects/scene_parser.cpp diff --git a/src/src/sphere.cpp b/src/src/objects/sphere.cpp similarity index 100% rename from src/src/sphere.cpp rename to src/src/objects/sphere.cpp diff --git a/src/src/triangle.cpp b/src/src/objects/triangle.cpp similarity index 100% rename from src/src/triangle.cpp rename to src/src/objects/triangle.cpp diff --git a/src/src/camera.cpp b/src/src/scene/camera.cpp similarity index 100% rename from src/src/camera.cpp rename to src/src/scene/camera.cpp diff --git a/src/src/scene.cpp b/src/src/scene/scene.cpp similarity index 100% rename from src/src/scene.cpp rename to src/src/scene/scene.cpp From 6823c453d49ebc9f9629a2c8213f2a71adf6f853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Guimar=C3=A3es?= Date: Wed, 9 Jul 2025 21:31:48 -0300 Subject: [PATCH 5/7] Refactor include structure and modularize Prism library Reorganized header includes to use module-specific paths, moved material and IO headers to more appropriate locations, and updated CMake configuration for modular builds and shared library support. Added a dependencies overview document, improved RPATH and install settings, and updated tests to use the new include structure. This refactor improves modularity, maintainability, and clarity of the codebase. --- ARCHITECTURE.md | 146 +++++++++++------- CMakeLists.txt | 4 + demo/CMakeLists.txt | 6 +- src/CMakeLists.txt | 64 ++++++-- src/include/Prism.hpp | 44 +++--- .../Prism/{scene => core}/material.hpp | 5 +- src/include/Prism/core/matrix.hpp | 6 +- src/include/Prism/core/point.hpp | 3 +- src/include/Prism/core/ray.hpp | 11 +- src/include/Prism/core/style.hpp | 1 + src/include/Prism/core/utils.hpp | 8 +- src/include/Prism/core/vector.hpp | 7 +- .../Prism/{io => objects}/Colormap.hpp | 11 +- .../Prism/{io => objects}/ObjReader.hpp | 9 +- src/include/Prism/objects/mesh.hpp | 13 +- src/include/Prism/objects/objects.hpp | 10 +- src/include/Prism/objects/plane.hpp | 8 +- src/include/Prism/objects/sphere.hpp | 8 +- src/include/Prism/objects/triangle.hpp | 9 +- src/include/Prism/scene/camera.hpp | 10 +- src/include/Prism/scene/scene.hpp | 8 +- .../Prism/{io => scene}/scene_parser.hpp | 9 +- src/src/core/color.cpp | 2 +- src/src/core/init.cpp | 3 +- src/src/core/matrix.cpp | 3 +- src/src/core/point.cpp | 7 +- src/src/core/ray.cpp | 9 +- src/src/core/utils.cpp | 3 +- src/src/core/vector.cpp | 6 +- src/src/objects/mesh.cpp | 6 +- src/src/objects/plane.cpp | 10 +- src/src/objects/sphere.cpp | 8 +- src/src/objects/triangle.cpp | 8 +- src/src/scene/camera.cpp | 10 +- src/src/scene/scene.cpp | 10 +- src/src/{objects => scene}/scene_parser.cpp | 34 ++-- tests/include/TestHelpers.hpp | 5 +- tests/src/CameraTest.cpp | 10 +- tests/src/MatrixTest.cpp | 9 +- tests/src/PlaneTest.cpp | 5 +- tests/src/Point3Test.cpp | 7 +- tests/src/RayTest.cpp | 8 +- tests/src/SphereTest.cpp | 5 +- tests/src/TransformationsTest.cpp | 10 +- tests/src/UtilsTest.cpp | 7 +- tests/src/Vector3Test.cpp | 5 +- 46 files changed, 354 insertions(+), 236 deletions(-) rename src/include/Prism/{scene => core}/material.hpp (96%) rename src/include/Prism/{io => objects}/Colormap.hpp (96%) rename src/include/Prism/{io => objects}/ObjReader.hpp (94%) rename src/include/Prism/{io => scene}/scene_parser.hpp (90%) rename src/src/{objects => scene}/scene_parser.cpp (93%) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index b8ade65..978acb1 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -2,6 +2,8 @@ This document provides a visual overview of the dependency structure of the Prism rendering engine, from a high-level view down to the internal class relationships. +--- + ## High-Level Project Dependency Graph This graph shows how the main project components (the demo application, the core library, and the unit tests) interact with each other and with external libraries. @@ -23,90 +25,114 @@ graph TD; TESTS --> PRISM_LIB; TESTS --> GTEST; PRISM_LIB --> YAML_CPP; - - style DEMO fill:#cce5ff,stroke:#333,stroke-width:2px; - style TESTS fill:#d5e8d4,stroke:#333,stroke-width:2px; - style PRISM_LIB fill:#ffcce5,stroke:#333,stroke-width:2px; - style YAML_CPP fill:#fff2cc,stroke:#333,stroke-width:2px; - style GTEST fill:#fff2cc,stroke:#333,stroke-width:2px; ``` +--- + ## Internal Library Dependencies -This graph shows the relationships between the major classes within the Prism library itself. +This section details the dependencies within the Prism library, divided into different levels of abstraction for greater clarity and understanding of the project's architecture. + +--- + +### 1. Dependencies between Modules (High-Level Overview) + +This graph shows the high-level dependencies between the main modules of the Prism library. An arrow from A to B indicates that Module A depends on Module B. ```mermaid graph TD; - subgraph "High-Level Management" - SCENE_PARSER["📄 SceneParser"]; - SCENE["🎬 Scene"]; - CAMERA["📷 Camera"]; - end + CORE["🔧 Core"]; + OBJECTS["🧩 Objects"]; + SCENE["🎬 Scene"]; - subgraph "Geometric Objects (Hittables)" - OBJECT["🧩 Object (Base)"]; - SPHERE["⚪ Sphere"]; - PLANE["🌐 Plane"]; - TRIANGLE["🔺 Triangle"]; - MESH["🧊 Mesh"]; - end + OBJECTS --> CORE; + SCENE --> CORE; + SCENE --> OBJECTS; +``` + +--- - subgraph "Core Math & Data Structures" +### 2. Internal Dependencies by Module + +These graphs detail the relationships between the classes within each module. To simplify, common dependencies to basic types from other modules (like the Core classes) are abstracted and not explicitly shown here. + +#### 2.1. Module: Core + +This graph focuses on the internal dependencies of the fundamental math and data type classes within the Core module. + +```mermaid +graph TD; + subgraph "Core" RAY["➡️ Ray"]; POINT3["📍 Point3"]; VECTOR3["📏 Vector3"]; MATRIX["🧮 Matrix"]; MATERIAL["✨ Material"]; COLOR["🌈 Color"]; - OBJ_READER["📑 ObjReader"]; + STYLE["🎨 Style"]; + INIT["🔧 Init"]; + UTILS["🛠️ Utils"]; end - %% High-level dependencies - SCENE_PARSER --> SCENE; - SCENE_PARSER --> CAMERA; - SCENE_PARSER --> MESH; - SCENE_PARSER --> SPHERE; - SCENE_PARSER --> PLANE; - SCENE_PARSER --> TRIANGLE; - SCENE_PARSER --> MATERIAL; + INIT --> STYLE; + MATRIX --> POINT3; + MATRIX --> VECTOR3; + POINT3 --> VECTOR3; + VECTOR3 --> POINT3; + RAY --> POINT3; + RAY --> VECTOR3; + RAY --> MATRIX; + UTILS --> MATRIX; + UTILS --> POINT3; + UTILS --> VECTOR3; +``` + +--- + +#### 2.2. Module: Objects + +This graph illustrates the dependencies between the objects and the associated I/O classes, excluding dependencies on basic Core types. + +```mermaid +graph TD; + subgraph " Objects" + OBJECT["🧩 Object (Base)"]; + SPHERE["⚪ Sphere"]; + PLANE["🌐 Plane"]; + TRIANGLE["🔺 Triangle"]; + MESH["🧊 Mesh"]; + OBJ_READER["📑 ObjReader"]; + COLORMAP["🌈 ColorMap"]; + end - SCENE --> CAMERA; - SCENE --> OBJECT; - SCENE --> RAY; - SCENE --> COLOR; - - CAMERA --> RAY; - CAMERA --> MATRIX; - CAMERA --> POINT3; - CAMERA --> VECTOR3; - - %% Geometric object dependencies MESH --> OBJECT; MESH --> OBJ_READER; - MESH --> TRIANGLE; - MESH --> MATERIAL; - + OBJ_READER --> COLORMAP; SPHERE --> OBJECT; PLANE --> OBJECT; TRIANGLE --> OBJECT; +``` - OBJECT --> RAY; - OBJECT --> MATRIX; - OBJECT --> MATERIAL; +--- - OBJ_READER --> MATERIAL; - OBJ_READER --> COLOR; - OBJ_READER --> VECTOR3; - OBJ_READER --> POINT3; +#### 2.3. Module: Scene - %% Core math dependencies - RAY --> POINT3; - RAY --> VECTOR3; - RAY --> MATRIX; - - MATRIX --> POINT3; - MATRIX --> VECTOR3; - - POINT3 --> VECTOR3; - VECTOR3 --> POINT3; +This graph details the relationships within the scene module, including the interaction with the external YAML dependency. + +```mermaid +graph TD; + subgraph "Scene Management" + SCENE["🎬 Scene"]; + CAMERA["📷 Camera"]; + SCENE_PARSER["📄 SceneParser"]; + end + + subgraph "External Dependency" + YAML_CPP["📄 yaml-cpp"]; + end + + SCENE --> CAMERA; + SCENE_PARSER --> CAMERA; + SCENE_PARSER --> YAML_CPP; + SCENE_PARSER --> SCENE; ``` diff --git a/CMakeLists.txt b/CMakeLists.txt index f65caa6..3ca556e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) # --- Build Options --- # Add an option to control whether the demo application is built. # Defaults to ON for typical development, but can be turned off. +set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries" FORCE) option(PRISM_BUILD_DEMO "Build the Prism demo application" ON) # Set a common output directory for all executables. @@ -36,7 +37,10 @@ if(BUILD_TESTING) googletest URL https://github.com/google/googletest/archive/v1.14.0.zip ) + set(INSTALL_GTEST OFF CACHE BOOL "Disable GTest installation" FORCE) + set(BUILD_GTEST_INSTALL OFF CACHE BOOL "Disable GTest installation" FORCE) FetchContent_MakeAvailable(googletest) + add_subdirectory(tests) endif() \ No newline at end of file diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt index 54e21f9..1459dfa 100644 --- a/demo/CMakeLists.txt +++ b/demo/CMakeLists.txt @@ -10,12 +10,16 @@ add_executable(prism_demo src/main.cpp) target_link_libraries(prism_demo PRIVATE Prism) +set_target_properties(prism_demo PROPERTIES + INSTALL_RPATH "$ORIGIN/../lib" +) + # --- Installation --- install(TARGETS prism_demo DESTINATION bin) # This command is now much cleaner. It copies the 'data' directory # from this subdirectory into the install directory. -install(DIRECTORY data/ DESTINATION .) +install(DIRECTORY data/ DESTINATION ./bin/data) # --- Development/Debugging Support --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0ce7826..fba2e22 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,12 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(yaml-cpp) +set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "Disable building yaml-cpp contrib tools" FORCE) +set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "Disable building yaml-cpp parse tools" FORCE) +set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Disable building yaml-cpp tests" FORCE) +set(YAML_CPP_FORMAT_SOURCE OFF CACHE BOOL "Disable yaml-cpp source formatting" FORCE) + + # --- Build Options --- # Option to build the core math and data structures (mandatory) @@ -23,7 +29,6 @@ option(PRISM_BUILD_CORE "Build the Core module (math, etc.)" ON) # Optional modules option(PRISM_BUILD_OBJECTS "Build the Objects module (Sphere, Plane, Mesh, etc.)" ON) -option(PRISM_BUILD_IO "Build the I/O module (SceneParser, ObjReader)" ON) option(PRISM_BUILD_SCENE "Build the Scene module (Scene, Camera)" ON) # The CORE module is essential for all other parts of the library. @@ -49,11 +54,6 @@ if(PRISM_BUILD_OBJECTS) list(APPEND PRISM_SOURCES ${GEOMETRY_SOURCES}) endif() -if(PRISM_BUILD_IO) - file(GLOB IO_SOURCES CONFIGURE_DEPENDS "src/io/*.cpp") - list(APPEND PRISM_SOURCES ${IO_SOURCES}) -endif() - if(PRISM_BUILD_SCENE) file(GLOB SCENE_SOURCES CONFIGURE_DEPENDS "src/scene/*.cpp") list(APPEND PRISM_SOURCES ${SCENE_SOURCES}) @@ -84,10 +84,39 @@ target_include_directories(Prism $ ) +# +set_target_properties(Prism PROPERTIES + # Define the library's version. + VERSION "${PROJECT_VERSION}" + # Define the SOVERSION, which is used for shared libraries. + # This should match the major version of the library. + SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" + # Identify debug and release builds. + DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}" +) + +# Define the RPATH settings for the library. +set_target_properties(Prism PROPERTIES + INSTALL_RPATH "$ORIGIN/." +) + # Link the library against its dependencies. # The yaml-cpp dependency is only needed if the IO module is built. -if(PRISM_BUILD_IO) - target_link_libraries(Prism PUBLIC yaml-cpp) +if(PRISM_BUILD_OBJECTS) + target_link_libraries(Prism PRIVATE yaml-cpp::yaml-cpp) +endif() +# Set Submodule flags for the library. +# This ensures that the library is built with the correct visibility settings. +if (PRISM_BUILD_CORE) + target_compile_definitions(Prism PUBLIC PRISM_BUILD_CORE) +endif() + +if (PRISM_BUILD_OBJECTS) + target_compile_definitions(Prism PUBLIC PRISM_BUILD_OBJECTS) +endif() + +if (PRISM_BUILD_SCENE) + target_compile_definitions(Prism PUBLIC PRISM_BUILD_SCENE) endif() @@ -104,7 +133,6 @@ install(TARGETS Prism install(DIRECTORY include/Prism/core include/Prism/objects - include/Prism/io include/Prism/scene DESTINATION include/Prism ) @@ -113,4 +141,20 @@ install(DIRECTORY install(FILES include/Prism.hpp DESTINATION include -) \ No newline at end of file +) + +# Install yaml-cpp headers and library if the OBJECTS module is built. +if(PRISM_BUILD_OBJECTS) + + install(DIRECTORY ${yaml-cpp_SOURCE_DIR}/include/yaml-cpp + DESTINATION include + ) + + if(YAML_BUILD_SHARED_LIBS) + install(TARGETS yaml-cpp + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + ) + endif() +endif() \ No newline at end of file diff --git a/src/include/Prism.hpp b/src/include/Prism.hpp index 70f6ddc..5476f47 100644 --- a/src/include/Prism.hpp +++ b/src/include/Prism.hpp @@ -1,18 +1,26 @@ -#include "Prism/Colormap.hpp" -#include "Prism/ObjReader.hpp" -#include "Prism/camera.hpp" -#include "Prism/color.hpp" -#include "Prism/material.hpp" -#include "Prism/matrix.hpp" -#include "Prism/mesh.hpp" -#include "Prism/objects.hpp" -#include "Prism/plane.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/scene.hpp" -#include "Prism/scene_parser.hpp" -#include "Prism/sphere.hpp" -#include "Prism/style.hpp" -#include "Prism/triangle.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" +#ifdef PRISM_BUILD_CORE +#include "Prism/core/color.hpp" +#include "Prism/core/material.hpp" +#include "Prism/core/matrix.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/core/style.hpp" +#include "Prism/core/utils.hpp" +#include "Prism/core/vector.hpp" +#endif // PRISM_CORE + +#ifdef PRISM_BUILD_OBJECTS +#include "Prism/objects/Colormap.hpp" +#include "Prism/objects/ObjReader.hpp" +#include "Prism/objects/mesh.hpp" +#include "Prism/objects/objects.hpp" +#include "Prism/objects/plane.hpp" +#include "Prism/objects/sphere.hpp" +#include "Prism/objects/triangle.hpp" +#endif // PRISM_BUILD_OBJECTS + +#ifdef PRISM_BUILD_SCENE +#include "Prism/scene/camera.hpp" +#include "Prism/scene/scene.hpp" +#include "Prism/scene/scene_parser.hpp" +#endif diff --git a/src/include/Prism/scene/material.hpp b/src/include/Prism/core/material.hpp similarity index 96% rename from src/include/Prism/scene/material.hpp rename to src/include/Prism/core/material.hpp index 726f964..6908211 100644 --- a/src/include/Prism/scene/material.hpp +++ b/src/include/Prism/core/material.hpp @@ -1,10 +1,11 @@ #ifndef PRISM_MATERIAL_HPP_ #define PRISM_MATERIAL_HPP_ -#include "Prism/color.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" +#include "Prism/core/color.hpp" +#include "Prism/core/vector.hpp" + namespace Prism { /** diff --git a/src/include/Prism/core/matrix.hpp b/src/include/Prism/core/matrix.hpp index d5440a7..d9ec7fc 100644 --- a/src/include/Prism/core/matrix.hpp +++ b/src/include/Prism/core/matrix.hpp @@ -3,15 +3,15 @@ #include "prism_export.h" +#include "Prism/core/point.hpp" +#include "Prism/core/vector.hpp" + #include #include #include #include #include -#include "Prism/point.hpp" -#include "Prism/vector.hpp" - namespace Prism { class Matrix; // Forward declaration for proxy classes diff --git a/src/include/Prism/core/point.hpp b/src/include/Prism/core/point.hpp index d1b1556..77e148c 100644 --- a/src/include/Prism/core/point.hpp +++ b/src/include/Prism/core/point.hpp @@ -2,11 +2,12 @@ #define PRISM_POINT_HPP_ #include "prism_export.h" + #include + namespace Prism { class Vector3; // Forward declaration of Vector3 class -class Matrix; // Forward declaration of Matrix class /** * @class Point3 diff --git a/src/include/Prism/core/ray.hpp b/src/include/Prism/core/ray.hpp index 75e945f..f41fa6a 100644 --- a/src/include/Prism/core/ray.hpp +++ b/src/include/Prism/core/ray.hpp @@ -1,16 +1,17 @@ #ifndef PRISM_RAY_HPP_ #define PRISM_RAY_HPP_ -#include "Prism/point.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" + +#include "Prism/core/point.hpp" +#include "Prism/core/vector.hpp" +#include "Prism/core/matrix.hpp" + #include #include #include -namespace Prism { -class Object; // Forward declaration of Object class -struct HitRecord; // Forward declaration of HitRecord struct +namespace Prism { /** * @class Ray diff --git a/src/include/Prism/core/style.hpp b/src/include/Prism/core/style.hpp index 3864057..4b53364 100644 --- a/src/include/Prism/core/style.hpp +++ b/src/include/Prism/core/style.hpp @@ -2,6 +2,7 @@ #define PRISM_STYLE_HPP_ #include "prism_export.h" + #include #include diff --git a/src/include/Prism/core/utils.hpp b/src/include/Prism/core/utils.hpp index 5530d46..53bd7f7 100644 --- a/src/include/Prism/core/utils.hpp +++ b/src/include/Prism/core/utils.hpp @@ -1,10 +1,12 @@ #ifndef PRISM_UTILS_HPP_ #define PRISM_UTILS_HPP_ -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" + +#include "Prism/core/matrix.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/vector.hpp" + #include namespace Prism { diff --git a/src/include/Prism/core/vector.hpp b/src/include/Prism/core/vector.hpp index 38dcd8e..b88fb08 100644 --- a/src/include/Prism/core/vector.hpp +++ b/src/include/Prism/core/vector.hpp @@ -2,17 +2,12 @@ #define PRISM_VECTOR_HPP_ #include "prism_export.h" -#include -/** - * @file vector.hpp - * @brief Defines the Vector class for 3D vector operations in the Prism namespace. - */ +#include namespace Prism { class Point3; // Forward declaration of Point3 class -class Matrix; // Forward declaration of Matrix class /** * @class Vector3 diff --git a/src/include/Prism/io/Colormap.hpp b/src/include/Prism/objects/Colormap.hpp similarity index 96% rename from src/include/Prism/io/Colormap.hpp rename to src/include/Prism/objects/Colormap.hpp index 0f504e8..24075ed 100644 --- a/src/include/Prism/io/Colormap.hpp +++ b/src/include/Prism/objects/Colormap.hpp @@ -17,16 +17,19 @@ A saber que: A classe precisa ser instânciada passando o caminho do arquivo .mtl correspondente */ -#include "Prism/material.hpp" -#include "Prism/style.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" + +#include "Prism/core/material.hpp" +#include "Prism/core/style.hpp" +#include "Prism/core/vector.hpp" + #include #include #include #include #include #include + using namespace std; namespace Prism { @@ -36,7 +39,7 @@ class colormap { map mp; // Construtor - colormap(){}; + colormap() {}; colormap(string input) { // construtor: lê arquivo cores.mtl e guarda valores RGB associados a cada nome diff --git a/src/include/Prism/io/ObjReader.hpp b/src/include/Prism/objects/ObjReader.hpp similarity index 94% rename from src/include/Prism/io/ObjReader.hpp rename to src/include/Prism/objects/ObjReader.hpp index 7f92bad..929f725 100644 --- a/src/include/Prism/io/ObjReader.hpp +++ b/src/include/Prism/objects/ObjReader.hpp @@ -1,13 +1,10 @@ #ifndef PRISM_OBJREADER_HPP_ #define PRISM_OBJREADER_HPP_ -#include "Prism/Colormap.hpp" -#include "Prism/material.hpp" -#include "Prism/point.hpp" -#include "Prism/style.hpp" -#include "Prism/triangle.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" + +#include "Prism/objects/Colormap.hpp" + #include #include #include diff --git a/src/include/Prism/objects/mesh.hpp b/src/include/Prism/objects/mesh.hpp index 3571a59..21e26d7 100644 --- a/src/include/Prism/objects/mesh.hpp +++ b/src/include/Prism/objects/mesh.hpp @@ -1,12 +1,15 @@ #ifndef PRISM_MESH_HPP_ #define PRISM_MESH_HPP_ -#include "Prism/ObjReader.hpp" -#include "Prism/material.hpp" -#include "Prism/objects.hpp" -#include "Prism/point.hpp" -#include "Prism/triangle.hpp" #include "prism_export.h" + +#include "Prism/core/material.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/objects/objects.hpp" +#include "Prism/objects/triangle.hpp" +#include "Prism/objects/ObjReader.hpp" + #include #include #include diff --git a/src/include/Prism/objects/objects.hpp b/src/include/Prism/objects/objects.hpp index e008491..3206e19 100644 --- a/src/include/Prism/objects/objects.hpp +++ b/src/include/Prism/objects/objects.hpp @@ -1,11 +1,13 @@ #ifndef PRISM_OBJECT_HPP_ #define PRISM_OBJECT_HPP_ -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" + +#include "Prism/core/matrix.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/core/vector.hpp" + #include namespace Prism { diff --git a/src/include/Prism/objects/plane.hpp b/src/include/Prism/objects/plane.hpp index ee02017..5715646 100644 --- a/src/include/Prism/objects/plane.hpp +++ b/src/include/Prism/objects/plane.hpp @@ -1,11 +1,13 @@ #ifndef PRISM_PLANE_HPP_ #define PRISM_PLANE_HPP_ -#include "Prism/objects.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" +#include "Prism/objects/objects.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/core/material.hpp" + namespace Prism { /** diff --git a/src/include/Prism/objects/sphere.hpp b/src/include/Prism/objects/sphere.hpp index 867806d..5227362 100644 --- a/src/include/Prism/objects/sphere.hpp +++ b/src/include/Prism/objects/sphere.hpp @@ -1,11 +1,13 @@ #ifndef PRISM_SPHERE_HPP_ #define PRISM_SPHERE_HPP_ -#include "Prism/objects.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" +#include "Prism/objects/objects.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/core/material.hpp" + namespace Prism { /** diff --git a/src/include/Prism/objects/triangle.hpp b/src/include/Prism/objects/triangle.hpp index a7de231..38ffc6b 100644 --- a/src/include/Prism/objects/triangle.hpp +++ b/src/include/Prism/objects/triangle.hpp @@ -1,10 +1,13 @@ #ifndef PRISM_TRIANGLE_HPP_ #define PRISM_TRIANGLE_HPP_ -#include "Prism/material.hpp" -#include "Prism/objects.hpp" -#include "Prism/point.hpp" #include "prism_export.h" + +#include "Prism/core/material.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/objects/objects.hpp" + #include #include diff --git a/src/include/Prism/scene/camera.hpp b/src/include/Prism/scene/camera.hpp index 1119b3b..e084892 100644 --- a/src/include/Prism/scene/camera.hpp +++ b/src/include/Prism/scene/camera.hpp @@ -1,11 +1,13 @@ #ifndef PRISM_CAMERA_HPP_ #define PRISM_CAMERA_HPP_ -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" + +#include "Prism/core/matrix.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/core/vector.hpp" + #include #include namespace Prism { diff --git a/src/include/Prism/scene/scene.hpp b/src/include/Prism/scene/scene.hpp index 68359c5..97f767d 100644 --- a/src/include/Prism/scene/scene.hpp +++ b/src/include/Prism/scene/scene.hpp @@ -1,11 +1,11 @@ #ifndef PRISM_SCENE_HPP_ #define PRISM_SCENE_HPP_ -#include "Prism/camera.hpp" -#include "Prism/color.hpp" -#include "Prism/objects.hpp" -#include "Prism/ray.hpp" #include "prism_export.h" + +#include "Prism/objects/objects.hpp" +#include "Prism/scene/camera.hpp" + #include #include #include diff --git a/src/include/Prism/io/scene_parser.hpp b/src/include/Prism/scene/scene_parser.hpp similarity index 90% rename from src/include/Prism/io/scene_parser.hpp rename to src/include/Prism/scene/scene_parser.hpp index 52f195b..45f9623 100644 --- a/src/include/Prism/io/scene_parser.hpp +++ b/src/include/Prism/scene/scene_parser.hpp @@ -1,8 +1,12 @@ +#ifdef PRISM_BUILD_SCENE + #ifndef PRISM_SCENEPARSER_HPP_ #define PRISM_SCENEPARSER_HPP_ -#include "Prism/scene.hpp" #include "prism_export.h" + +#include "Prism/scene/scene.hpp" + #include namespace Prism { @@ -34,4 +38,5 @@ class PRISM_EXPORT SceneParser { } // namespace Prism -#endif // PRISM_SCENEPARSER_HPP_ \ No newline at end of file +#endif // PRISM_SCENEPARSER_HPP_ +#endif // PRISM_BUILD_SCENE \ No newline at end of file diff --git a/src/src/core/color.cpp b/src/src/core/color.cpp index 5ab9e8c..b8e69f2 100644 --- a/src/src/core/color.cpp +++ b/src/src/core/color.cpp @@ -1,4 +1,4 @@ -#include "Prism/color.hpp" +#include "Prism/core/color.hpp" namespace Prism { diff --git a/src/src/core/init.cpp b/src/src/core/init.cpp index a661694..d5b2860 100644 --- a/src/src/core/init.cpp +++ b/src/src/core/init.cpp @@ -1,4 +1,5 @@ -#include "Prism/style.hpp" +#include "Prism/core/style.hpp" + #include namespace Prism { diff --git a/src/src/core/matrix.cpp b/src/src/core/matrix.cpp index a1f6546..71c3b5c 100644 --- a/src/src/core/matrix.cpp +++ b/src/src/core/matrix.cpp @@ -1,4 +1,5 @@ -#include "Prism/matrix.hpp" +#include "Prism/core/matrix.hpp" + #include #include #include diff --git a/src/src/core/point.cpp b/src/src/core/point.cpp index 428d19c..adf5a46 100644 --- a/src/src/core/point.cpp +++ b/src/src/core/point.cpp @@ -1,6 +1,7 @@ -#include "Prism/point.hpp" -#include "Prism/matrix.hpp" -#include "Prism/vector.hpp" +#include "Prism/core/point.hpp" + +#include "Prism/core/vector.hpp" + #include namespace Prism { diff --git a/src/src/core/ray.cpp b/src/src/core/ray.cpp index 8769fae..b6030db 100644 --- a/src/src/core/ray.cpp +++ b/src/src/core/ray.cpp @@ -1,10 +1,5 @@ -#include "Prism/ray.hpp" -#include "Prism/camera.hpp" -#include "Prism/matrix.hpp" -#include "Prism/objects.hpp" -#include "Prism/point.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" +#include "Prism/core/ray.hpp" + #include #include diff --git a/src/src/core/utils.cpp b/src/src/core/utils.cpp index d73d091..81c1976 100644 --- a/src/src/core/utils.cpp +++ b/src/src/core/utils.cpp @@ -1,4 +1,5 @@ -#include "Prism/utils.hpp" +#include "Prism/core/utils.hpp" + #include #include diff --git a/src/src/core/vector.cpp b/src/src/core/vector.cpp index 543b725..e078ffd 100644 --- a/src/src/core/vector.cpp +++ b/src/src/core/vector.cpp @@ -1,6 +1,6 @@ -#include "Prism/vector.hpp" -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" +#include "Prism/core/vector.hpp" + +#include "Prism/core/point.hpp" #include #include diff --git a/src/src/objects/mesh.cpp b/src/src/objects/mesh.cpp index cb6bcc4..8b0a54b 100644 --- a/src/src/objects/mesh.cpp +++ b/src/src/objects/mesh.cpp @@ -1,5 +1,7 @@ -#include "Prism/mesh.hpp" -#include "Prism/matrix.hpp" +#include "Prism/objects/mesh.hpp" + +#include "Prism/core/matrix.hpp" + #include namespace Prism { diff --git a/src/src/objects/plane.cpp b/src/src/objects/plane.cpp index 98e8260..9e7f881 100644 --- a/src/src/objects/plane.cpp +++ b/src/src/objects/plane.cpp @@ -1,9 +1,7 @@ -#include "Prism/plane.hpp" -#include "Prism/material.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" +#include "Prism/objects/plane.hpp" + +#include "Prism/core/matrix.hpp" + #include namespace Prism { diff --git a/src/src/objects/sphere.cpp b/src/src/objects/sphere.cpp index 749dfc5..203e875 100644 --- a/src/src/objects/sphere.cpp +++ b/src/src/objects/sphere.cpp @@ -1,6 +1,8 @@ -#include "Prism/sphere.hpp" -#include "Prism/ray.hpp" -#include "Prism/utils.hpp" +#include "Prism/objects/sphere.hpp" + +#include "Prism/core/matrix.hpp" +#include "Prism/core/utils.hpp" + #include namespace Prism { diff --git a/src/src/objects/triangle.cpp b/src/src/objects/triangle.cpp index f3e487a..03f8de1 100644 --- a/src/src/objects/triangle.cpp +++ b/src/src/objects/triangle.cpp @@ -1,7 +1,7 @@ -#include "Prism/triangle.hpp" -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" +#include "Prism/objects/triangle.hpp" + +#include "Prism/core/matrix.hpp" + #include namespace Prism { diff --git a/src/src/scene/camera.cpp b/src/src/scene/camera.cpp index 542a9ce..04bff16 100644 --- a/src/src/scene/camera.cpp +++ b/src/src/scene/camera.cpp @@ -1,9 +1,7 @@ -#include "Prism/camera.hpp" -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" +#include "Prism/scene/camera.hpp" + +#include "Prism/core/utils.hpp" + #include #include diff --git a/src/src/scene/scene.cpp b/src/src/scene/scene.cpp index 66e5d79..8e6dd2f 100644 --- a/src/src/scene/scene.cpp +++ b/src/src/scene/scene.cpp @@ -1,7 +1,9 @@ -#include "Prism/scene.hpp" -#include "Prism/color.hpp" -#include "Prism/material.hpp" -#include "Prism/style.hpp" +#include "Prism/scene/scene.hpp" + +#include "Prism/core/color.hpp" +#include "Prism/core/material.hpp" +#include "Prism/core/style.hpp" + #include #include #include diff --git a/src/src/objects/scene_parser.cpp b/src/src/scene/scene_parser.cpp similarity index 93% rename from src/src/objects/scene_parser.cpp rename to src/src/scene/scene_parser.cpp index ccb181a..4ee4210 100644 --- a/src/src/objects/scene_parser.cpp +++ b/src/src/scene/scene_parser.cpp @@ -1,17 +1,19 @@ -#include "Prism/scene_parser.hpp" -#include "Prism/camera.hpp" -#include "Prism/color.hpp" -#include "Prism/material.hpp" -#include "Prism/matrix.hpp" -#include "Prism/mesh.hpp" -#include "Prism/objects.hpp" -#include "Prism/plane.hpp" -#include "Prism/point.hpp" -#include "Prism/scene.hpp" -#include "Prism/sphere.hpp" -#include "Prism/style.hpp" -#include "Prism/triangle.hpp" -#include "Prism/vector.hpp" +#ifdef PRISM_BUILD_SCENE + +#include "Prism/scene/scene_parser.hpp" + +#include "Prism/core/color.hpp" +#include "Prism/core/material.hpp" +#include "Prism/core/matrix.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/style.hpp" +#include "Prism/core/vector.hpp" +#include "Prism/objects/mesh.hpp" +#include "Prism/objects/plane.hpp" +#include "Prism/objects/sphere.hpp" +#include "Prism/objects/triangle.hpp" +#include "Prism/scene/camera.hpp" + #include #include #include @@ -194,4 +196,6 @@ Scene SceneParser::parse() { return scene; } -} // namespace Prism \ No newline at end of file +} // namespace Prism + +#endif // PRISM_BUILD_SCENE \ No newline at end of file diff --git a/tests/include/TestHelpers.hpp b/tests/include/TestHelpers.hpp index 7e91376..093990f 100644 --- a/tests/include/TestHelpers.hpp +++ b/tests/include/TestHelpers.hpp @@ -1,9 +1,8 @@ #ifndef TESTS_TESTHELPERS_HPP #define TESTS_TESTHELPERS_HPP -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include namespace Prism { diff --git a/tests/src/CameraTest.cpp b/tests/src/CameraTest.cpp index 0232be8..9b5ce5a 100644 --- a/tests/src/CameraTest.cpp +++ b/tests/src/CameraTest.cpp @@ -1,11 +1,9 @@ -#include "Prism/camera.hpp" -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" + #include + #include using namespace Prism; diff --git a/tests/src/MatrixTest.cpp b/tests/src/MatrixTest.cpp index 8f38d55..255b3d3 100644 --- a/tests/src/MatrixTest.cpp +++ b/tests/src/MatrixTest.cpp @@ -1,10 +1,11 @@ -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" -#include + #include +#include + #ifndef M_PI #define M_PI 3.14159265358979323846 #endif diff --git a/tests/src/PlaneTest.cpp b/tests/src/PlaneTest.cpp index 282cecf..93ee9de 100644 --- a/tests/src/PlaneTest.cpp +++ b/tests/src/PlaneTest.cpp @@ -1,7 +1,10 @@ #include "Prism.hpp" + #include "TestHelpers.hpp" + #include -#include // Incluído para std::shared_ptr + +#include using namespace Prism; diff --git a/tests/src/Point3Test.cpp b/tests/src/Point3Test.cpp index 2e067ec..80d02da 100644 --- a/tests/src/Point3Test.cpp +++ b/tests/src/Point3Test.cpp @@ -1,8 +1,7 @@ -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" + #include using Prism::Matrix; diff --git a/tests/src/RayTest.cpp b/tests/src/RayTest.cpp index 95ad687..1aa2a61 100644 --- a/tests/src/RayTest.cpp +++ b/tests/src/RayTest.cpp @@ -1,9 +1,9 @@ -#include "Prism/ray.hpp" -#include "Prism/objects.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" + #include + #include #include diff --git a/tests/src/SphereTest.cpp b/tests/src/SphereTest.cpp index a2971b9..91db57e 100644 --- a/tests/src/SphereTest.cpp +++ b/tests/src/SphereTest.cpp @@ -1,7 +1,10 @@ #include "Prism.hpp" + #include "TestHelpers.hpp" -#include + #include + +#include #include using namespace Prism; diff --git a/tests/src/TransformationsTest.cpp b/tests/src/TransformationsTest.cpp index 0e608d5..d8b446c 100644 --- a/tests/src/TransformationsTest.cpp +++ b/tests/src/TransformationsTest.cpp @@ -1,14 +1,16 @@ -#include +#include "Prism.hpp" + +#include "TestHelpers.hpp" + #include + +#include #include #ifndef M_PI #define M_PI 3.14159265358979323846 #endif -#include "Prism.hpp" -#include "TestHelpers.hpp" // Para comparações de ponto flutuante - using namespace Prism; // Testa a transformação de um raio diff --git a/tests/src/UtilsTest.cpp b/tests/src/UtilsTest.cpp index 2f065c8..330ae06 100644 --- a/tests/src/UtilsTest.cpp +++ b/tests/src/UtilsTest.cpp @@ -1,8 +1,9 @@ -#include "Prism/utils.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" + #include + #include using Prism::centroid; diff --git a/tests/src/Vector3Test.cpp b/tests/src/Vector3Test.cpp index e578d78..e9a88c3 100644 --- a/tests/src/Vector3Test.cpp +++ b/tests/src/Vector3Test.cpp @@ -1,6 +1,7 @@ -#include "Prism/matrix.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" + #include using Prism::Matrix; From be8f4b1d7190905b85e2f382cecf8a24a0efb76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Guimar=C3=A3es?= Date: Wed, 9 Jul 2025 21:35:39 -0300 Subject: [PATCH 6/7] Reorder include directives for consistency Adjusted the order of #include statements in several header files to improve consistency and maintain coding standards. No functional changes were made. --- src/include/Prism/core/ray.hpp | 2 +- src/include/Prism/objects/Colormap.hpp | 2 +- src/include/Prism/objects/mesh.hpp | 2 +- src/include/Prism/objects/plane.hpp | 4 ++-- src/include/Prism/objects/sphere.hpp | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/include/Prism/core/ray.hpp b/src/include/Prism/core/ray.hpp index f41fa6a..24fa619 100644 --- a/src/include/Prism/core/ray.hpp +++ b/src/include/Prism/core/ray.hpp @@ -3,9 +3,9 @@ #include "prism_export.h" +#include "Prism/core/matrix.hpp" #include "Prism/core/point.hpp" #include "Prism/core/vector.hpp" -#include "Prism/core/matrix.hpp" #include #include diff --git a/src/include/Prism/objects/Colormap.hpp b/src/include/Prism/objects/Colormap.hpp index 24075ed..2938691 100644 --- a/src/include/Prism/objects/Colormap.hpp +++ b/src/include/Prism/objects/Colormap.hpp @@ -39,7 +39,7 @@ class colormap { map mp; // Construtor - colormap() {}; + colormap(){}; colormap(string input) { // construtor: lê arquivo cores.mtl e guarda valores RGB associados a cada nome diff --git a/src/include/Prism/objects/mesh.hpp b/src/include/Prism/objects/mesh.hpp index 21e26d7..9796cf4 100644 --- a/src/include/Prism/objects/mesh.hpp +++ b/src/include/Prism/objects/mesh.hpp @@ -6,9 +6,9 @@ #include "Prism/core/material.hpp" #include "Prism/core/point.hpp" #include "Prism/core/ray.hpp" +#include "Prism/objects/ObjReader.hpp" #include "Prism/objects/objects.hpp" #include "Prism/objects/triangle.hpp" -#include "Prism/objects/ObjReader.hpp" #include #include diff --git a/src/include/Prism/objects/plane.hpp b/src/include/Prism/objects/plane.hpp index 5715646..7f15390 100644 --- a/src/include/Prism/objects/plane.hpp +++ b/src/include/Prism/objects/plane.hpp @@ -3,10 +3,10 @@ #include "prism_export.h" -#include "Prism/objects/objects.hpp" +#include "Prism/core/material.hpp" #include "Prism/core/point.hpp" #include "Prism/core/ray.hpp" -#include "Prism/core/material.hpp" +#include "Prism/objects/objects.hpp" namespace Prism { diff --git a/src/include/Prism/objects/sphere.hpp b/src/include/Prism/objects/sphere.hpp index 5227362..94afeda 100644 --- a/src/include/Prism/objects/sphere.hpp +++ b/src/include/Prism/objects/sphere.hpp @@ -3,10 +3,10 @@ #include "prism_export.h" -#include "Prism/objects/objects.hpp" +#include "Prism/core/material.hpp" #include "Prism/core/point.hpp" #include "Prism/core/ray.hpp" -#include "Prism/core/material.hpp" +#include "Prism/objects/objects.hpp" namespace Prism { From bbece3f99636f5ae931edc306a8824870924d70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Guimar=C3=A3es?= Date: Wed, 9 Jul 2025 21:44:02 -0300 Subject: [PATCH 7/7] Change Mesh constructor to use std::filesystem::path Updated the Mesh class constructor to accept a std::filesystem::path reference instead of a std::string for improved type safety and flexibility when handling file paths. --- src/include/Prism/objects/mesh.hpp | 3 ++- src/src/objects/mesh.cpp | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/include/Prism/objects/mesh.hpp b/src/include/Prism/objects/mesh.hpp index 9796cf4..b400f8a 100644 --- a/src/include/Prism/objects/mesh.hpp +++ b/src/include/Prism/objects/mesh.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace Prism { @@ -32,7 +33,7 @@ class PRISM_EXPORT Mesh : public Object { * This constructor initializes the Mesh by reading points and triangles from the specified OBJ * file. */ - explicit Mesh(std::string path); + explicit Mesh(std::filesystem::path& path); /** * @brief Constructs a Mesh object from an ObjReader. diff --git a/src/src/objects/mesh.cpp b/src/src/objects/mesh.cpp index 8b0a54b..9cb88ee 100644 --- a/src/src/objects/mesh.cpp +++ b/src/src/objects/mesh.cpp @@ -1,14 +1,13 @@ #include "Prism/objects/mesh.hpp" #include "Prism/core/matrix.hpp" - #include namespace Prism { // TODO: Implementar BVH aqui -Mesh::Mesh(std::string path) { - ObjReader reader(path); +Mesh::Mesh(std::filesystem::path& path) { + ObjReader reader(path.string()); material = std::move(reader.curMaterial); for (auto& point : reader.vertices) {