add new compile target for viewer
This commit is contained in:
@@ -31,44 +31,35 @@ endif()
|
|||||||
|
|
||||||
|
|
||||||
add_subdirectory(deps)
|
add_subdirectory(deps)
|
||||||
|
|
||||||
add_subdirectory(deps/glfw-3.4)
|
add_subdirectory(deps/glfw-3.4)
|
||||||
|
|
||||||
|
# --------- GLAD (global) ---------
|
||||||
|
add_library(glad STATIC ${CMAKE_CURRENT_SOURCE_DIR}/deps/libigl-glad/src/glad.c)
|
||||||
|
target_include_directories(glad PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/deps/libigl-glad/include)
|
||||||
|
# --------- VIEWER Lib (separat → nur bei src/viewer/* Änderung gebaut!) ---------
|
||||||
|
add_library(VIEWER STATIC src/viewer/simple_viewer.cpp)
|
||||||
|
target_include_directories(VIEWER PUBLIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/deps/libigl-2.6.0/include
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/deps/libigl-glad/include
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/deps/eigen-3.4.0/
|
||||||
|
)
|
||||||
|
target_link_libraries(viewer PUBLIC glad glfw)
|
||||||
# --------- Executable ---------
|
# --------- Executable ---------
|
||||||
add_executable(${PROJECT_NAME} src/apps/v0/conformallab_cli.cpp )
|
add_executable(${PROJECT_NAME} src/apps/v0/conformallab_cli.cpp)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE
|
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE
|
||||||
|
|
||||||
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/deps/single_includes
|
${CMAKE_CURRENT_SOURCE_DIR}/deps/single_includes
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/deps/eigen-3.4.0/
|
${CMAKE_CURRENT_SOURCE_DIR}/deps/eigen-3.4.0/
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/deps/CGAL-6.1.1/include
|
${CMAKE_CURRENT_SOURCE_DIR}/deps/CGAL-6.1.1/include
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/deps/boost_1_90_0/
|
${CMAKE_CURRENT_SOURCE_DIR}/deps/boost_1_90_0/
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/deps/libigl-2.6.0/include
|
${CMAKE_CURRENT_SOURCE_DIR}/deps/libigl-2.6.0/include # Core libigl
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/deps/libigl-glad/include
|
|
||||||
)
|
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
||||||
)
|
|
||||||
add_library(glad STATIC
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/deps/libigl-glad/src/glad.c
|
|
||||||
)
|
|
||||||
target_include_directories(glad PUBLIC
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/deps/libigl-glad/include
|
|
||||||
)
|
)
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
#-------- Compiler-Definitionen ---------
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE CGAL_DISABLE_GMP CGAL_DISABLE_MPFR)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE viewer)
|
||||||
|
#--------- Output-Ordner ---------
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
|
||||||
|
|
||||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
|
||||||
CGAL_DISABLE_GMP
|
|
||||||
CGAL_DISABLE_MPFR
|
|
||||||
)
|
|
||||||
|
|
||||||
# Output-Ordner
|
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin
|
|
||||||
|
|
||||||
)
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
|
||||||
PRIVATE glad glfw
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
//exmaple include hedder
|
|
||||||
#ifndef EXAMPLE_INCLUDE_HPP
|
|
||||||
#define EXAMPLE_INCLUDE_HPP
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // EXAMPLE_INCLUDE_HPP
|
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <CGAL/Surface_mesh.h>
|
#include <CGAL/Surface_mesh.h>
|
||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
#include <igl/opengl/glfw/Viewer.h>
|
|
||||||
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
|
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
|
||||||
|
|
||||||
|
|
||||||
namespace mesh_utils {
|
namespace mesh_utils {
|
||||||
|
|
||||||
template <typename Kernel>
|
template <typename Kernel>
|
||||||
void cgal_to_eigen(CGAL::Surface_mesh<typename Kernel::Point_3>& mesh,
|
void cgal_to_eigen(CGAL::Surface_mesh<typename Kernel::Point_3>& mesh,
|
||||||
Eigen::MatrixXd& V, Eigen::MatrixXi& F) {
|
Eigen::MatrixXd& V, Eigen::MatrixXi& F) {
|
||||||
|
|
||||||
|
CGAL::Polygon_mesh_processing::triangulate_faces(mesh);
|
||||||
|
|
||||||
V.resize(mesh.num_vertices(), 3);
|
V.resize(mesh.num_vertices(), 3);
|
||||||
F.resize(mesh.num_faces(), 3);
|
F.resize(mesh.num_faces(), 3);
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ void cgal_to_eigen(CGAL::Surface_mesh<typename Kernel::Point_3>& mesh,
|
|||||||
auto p = mesh.point(v);
|
auto p = mesh.point(v);
|
||||||
V.row(v.idx()) << p.x(), p.y(), p.z();
|
V.row(v.idx()) << p.x(), p.y(), p.z();
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Index face_idx = 0;
|
Eigen::Index face_idx = 0;
|
||||||
for (auto f : mesh.faces()) {
|
for (auto f : mesh.faces()) {
|
||||||
int vertex_count = 0;
|
int vertex_count = 0;
|
||||||
@@ -29,29 +30,12 @@ void cgal_to_eigen(CGAL::Surface_mesh<typename Kernel::Point_3>& mesh,
|
|||||||
face_idx++;
|
face_idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Kernel>
|
template <typename Kernel>
|
||||||
void simple_visualize_mesh( CGAL::Surface_mesh<typename Kernel::Point_3>& mesh, bool triangulate = true) {
|
void simple_visualize_mesh(Eigen::MatrixXd& V, Eigen::MatrixXi& F) {
|
||||||
if(!CGAL::is_triangle_mesh(mesh)) {
|
|
||||||
std::cerr << "Warning: Mesh is not triangulated. Visualizer expects triangles.\n";
|
|
||||||
|
|
||||||
|
|
||||||
if(triangulate){
|
|
||||||
std::cout << "Triangulating mesh for visualization...\n";
|
|
||||||
CGAL::Polygon_mesh_processing::triangulate_faces(mesh);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
std::cout << " exit without visualizetion.\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Eigen::MatrixXd V; Eigen::MatrixXi F;
|
|
||||||
cgal_to_eigen<Kernel>(mesh, V, F);
|
|
||||||
igl::opengl::glfw::Viewer viewer;
|
igl::opengl::glfw::Viewer viewer;
|
||||||
viewer.data().set_mesh(V, F);
|
viewer.data().set_mesh(V, F);
|
||||||
viewer.launch();
|
viewer.launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zero-Copy Map für V (optional)
|
// Zero-Copy Map für V (optional)
|
||||||
template <typename Kernel>
|
template <typename Kernel>
|
||||||
Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, 3, Eigen::RowMajor>>
|
Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, 3, Eigen::RowMajor>>
|
||||||
@@ -60,5 +44,4 @@ get_vertex_map(CGAL::Surface_mesh<typename Kernel::Point_3>& mesh) {
|
|||||||
double* data = reinterpret_cast<double*>(&points[0][0]);
|
double* data = reinterpret_cast<double*>(&points[0][0]);
|
||||||
return {data, static_cast<Eigen::Index>(points.size()), 3};
|
return {data, static_cast<Eigen::Index>(points.size()), 3};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
11
code/include/viewer_utils.h
Normal file
11
code/include/viewer_utils.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Eigen/Dense>
|
||||||
|
#include <igl/opengl/glfw/Viewer.h>
|
||||||
|
|
||||||
|
namespace viewer_utils {
|
||||||
|
|
||||||
|
// Deklaration (Implementation in viewer.cpp)
|
||||||
|
void simple_visualize(Eigen::MatrixXd& V, Eigen::MatrixXi& F);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
#include <CGAL/Simple_cartesian.h>
|
#include <CGAL/Simple_cartesian.h>
|
||||||
#include <CGAL/Surface_mesh.h>
|
#include <CGAL/Surface_mesh.h>
|
||||||
#include <CGAL/IO/polygon_mesh_io.h>
|
#include <CGAL/IO/polygon_mesh_io.h>
|
||||||
#include "simple_visualize.h"
|
|
||||||
|
#include "viewer_utils.h"
|
||||||
|
#include "mesh_utils.hpp"
|
||||||
|
|
||||||
|
|
||||||
#include <CLI11.hpp>
|
#include <CLI11.hpp>
|
||||||
@@ -23,7 +25,7 @@ bool parse_arguments(int argc, char* argv[], std::string& input_file, std::strin
|
|||||||
CLI::App app{"demo of conformallab"};
|
CLI::App app{"demo of conformallab"};
|
||||||
app.add_option("-i,--input", input_file, "Input OFF file")->required();
|
app.add_option("-i,--input", input_file, "Input OFF file")->required();
|
||||||
app.add_option("-o,--output", output_file, "Output OFF file (optional)");
|
app.add_option("-o,--output", output_file, "Output OFF file (optional)");
|
||||||
app.add_flag("-s,--show", show, "Show the input mesh in a viewer");
|
app.add_flag("-s,--show", show, "Show the input mesh in a viewer ");
|
||||||
app.add_flag("-v,--verbose",verbose, "Enable verbose output");
|
app.add_flag("-v,--verbose",verbose, "Enable verbose output");
|
||||||
app.set_help_flag("-h,--help", "Show this help message and exit");
|
app.set_help_flag("-h,--help", "Show this help message and exit");
|
||||||
|
|
||||||
@@ -83,7 +85,12 @@ int main(int argc, char* argv[])
|
|||||||
// CGAL -> libigl
|
// CGAL -> libigl
|
||||||
if(show){
|
if(show){
|
||||||
std::cout << "Visualizing input mesh...\n";
|
std::cout << "Visualizing input mesh...\n";
|
||||||
mesh_utils::simple_visualize_mesh<Kernel>(surface_mesh,true);
|
Eigen::MatrixXd V;
|
||||||
|
Eigen::MatrixXi F;
|
||||||
|
|
||||||
|
mesh_utils::cgal_to_eigen<Kernel>(surface_mesh, V, F);
|
||||||
|
viewer_utils::simple_visualize(V, F);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for now, we just write the input mesh to the output file as a placeholder
|
// for now, we just write the input mesh to the output file as a placeholder
|
||||||
|
|||||||
9
code/src/viewer/simple_viewer.cpp
Normal file
9
code/src/viewer/simple_viewer.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "viewer_utils.h"
|
||||||
|
|
||||||
|
namespace viewer_utils {
|
||||||
|
void simple_visualize(Eigen::MatrixXd& V, Eigen::MatrixXi& F) {
|
||||||
|
igl::opengl::glfw::Viewer viewer;
|
||||||
|
viewer.data().set_mesh(V, F);
|
||||||
|
viewer.launch();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user