-
-
Save Andlon/34d9d869d5267d28d86fb36f35f72538 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.13) | |
project(ipc_toolkit_playground) | |
set(CMAKE_CXX_STANDARD 14) | |
set(SOURCE_FILES src/main.cpp src/main.cpp) | |
# IPC Toolkit | |
set(IPC_TOOLKIT_GIT_TAG "c0bfe1f") | |
include(FetchContent) | |
FetchContent_Declare( | |
ipc_toolkit | |
GIT_REPOSITORY https://github.com/ipc-sim/ipc-toolkit.git | |
GIT_TAG ${IPC_TOOLKIT_GIT_TAG} | |
GIT_SHALLOW TRUE | |
) | |
FetchContent_MakeAvailable(ipc_toolkit) | |
add_executable(playground ${SOURCE_FILES}) | |
target_link_libraries(playground PUBLIC ipc::toolkit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ipc/ipc.hpp> | |
#include <iostream> | |
#include <chrono> | |
int main() { | |
const double dhat = 1e-3; | |
const bool project_spd = false; | |
Eigen::MatrixXd rest_vertices(4, 3); | |
rest_vertices << | |
0.0, 0.0, 0.0, | |
1.0, 0.0, 0.0, | |
0.0, 1.0, 0.0, | |
0.0, 0.0, 1.0; | |
Eigen::MatrixXd deformed_vertices = rest_vertices; | |
deformed_vertices.row(3)(2) = 0.5 * dhat; | |
Eigen::MatrixXi edges(6, 2); | |
edges << 0, 1, | |
0, 2, | |
0, 3, | |
1, 2, | |
1, 3, | |
2, 3; | |
Eigen::MatrixXi faces(4, 3); | |
faces << 0, 2, 1, | |
0, 1, 3, | |
0, 3, 2, | |
1, 2, 3; | |
ipc::CollisionMesh mesh = ipc::CollisionMesh::build_from_full_mesh(rest_vertices, edges, faces); | |
ipc::CollisionConstraints constraints; | |
constraints.build(mesh, deformed_vertices, dhat); | |
// Run this several times just to demonstrate that it's not due to some initialization or similar | |
for (int i = 0; i < 5; ++i) { | |
const auto potential_begin = std::chrono::steady_clock::now(); | |
const double potential = constraints.compute_potential(mesh, deformed_vertices, dhat); | |
const Eigen::VectorXd grad = constraints.compute_potential_gradient(mesh, deformed_vertices, dhat); | |
const Eigen::SparseMatrix<double> hessian = constraints.compute_potential_hessian(mesh, deformed_vertices, dhat,project_spd); | |
const auto potential_end = std::chrono::steady_clock::now(); | |
const auto potential_duration = std::chrono::duration<double>(potential_end - potential_begin).count(); | |
std::cout << "Potential: " << potential << std::endl << std::endl; | |
std::cout << "Gradient: " << std::endl << grad << std::endl << std::endl; | |
std::cout << "Hessian (" << hessian.rows() << "x" << hessian.cols() << "): " << std::endl | |
<< hessian << std::endl << std::endl; | |
const auto ccd_begin = std::chrono::steady_clock::now(); | |
const double alpha = ipc::compute_collision_free_stepsize(mesh, rest_vertices, deformed_vertices); | |
const auto ccd_end = std::chrono::steady_clock::now(); | |
const auto ccd_duration = std::chrono::duration<double>(ccd_end - ccd_begin).count(); | |
std::cout << "Alpha: " << alpha << std::endl; | |
std::cout << "Potential duration: " << potential_duration << " seconds." << std::endl; | |
std::cout << "CCD duration: " << ccd_duration << " seconds." << std::endl; | |
std::cout << std::endl << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment