Skip to content

Commit bf49c2d

Browse files
committed
Initial commit: libigl submodule, docs, basic framework, demos
1 parent 0ef9c4d commit bf49c2d

21 files changed

+1996
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*/build/**
2+
*.o

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "lib/libigl"]
2+
path = lib/libigl
3+
url = https://github.com/libigl/libigl.git

demos/0_dummy/CMakeLists.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
cmake_minimum_required(VERSION 3.1)
3+
project(0_dummy)
4+
5+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
6+
set(CMAKE_CXX_FLAGS "-Wall")
7+
8+
# libigl
9+
option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF)
10+
option(LIBIGL_WITH_ANTTWEAKBAR "Use AntTweakBar" OFF)
11+
option(LIBIGL_WITH_CGAL "Use CGAL" OFF)
12+
option(LIBIGL_WITH_COMISO "Use CoMiso" OFF)
13+
option(LIBIGL_WITH_CORK "Use Cork" OFF)
14+
option(LIBIGL_WITH_EMBREE "Use Embree" OFF)
15+
option(LIBIGL_WITH_LIM "Use LIM" OFF)
16+
option(LIBIGL_WITH_MATLAB "Use Matlab" OFF)
17+
option(LIBIGL_WITH_MOSEK "Use MOSEK" OFF)
18+
option(LIBIGL_WITH_OPENGL "Use OpenGL" ON)
19+
option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON)
20+
option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" ON)
21+
option(LIBIGL_WITH_PNG "Use PNG" OFF)
22+
option(LIBIGL_WITH_PYTHON "Use Python" OFF)
23+
option(LIBIGL_WITH_TETGEN "Use Tetgen" OFF)
24+
option(LIBIGL_WITH_TRIANGLE "Use Triangle" OFF)
25+
option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON)
26+
option(LIBIGL_WITH_XML "Use XML" OFF)
27+
28+
if (NOT LIBIGL_FOUND)
29+
find_package(LIBIGL REQUIRED QUIET)
30+
endif()
31+
32+
# Add your project files
33+
file(GLOB SRCFILES *.cpp)
34+
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/../include/*.cpp)
35+
file(GLOB HFILES *.h)
36+
file(GLOB H_FILES ${PROJECT_SOURCE_DIR}/../include/*.h)
37+
38+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
39+
40+
add_definitions(-DIGL_VIEWER_VIEWER_QUIET)
41+
add_executable(${PROJECT_NAME} ${SRCFILES} ${SRC_FILES} ${HFILES} ${H_FILES})
42+
target_link_libraries(${PROJECT_NAME} igl::core igl::opengl_glfw igl::opengl_glfw_imgui)

demos/0_dummy/DummySim.h

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "Simulation.h"
2+
3+
using namespace std;
4+
/*
5+
* Example simulation that changes the colors of a cube.
6+
*/
7+
class DummySim : public Simulation {
8+
public:
9+
DummySim() : Simulation() { init(); }
10+
11+
virtual void init() override {
12+
// create a cube on [-1,1]^3
13+
// vertices
14+
m_V.resize(8, 3);
15+
m_V << -1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1,
16+
-1, 1, 1, 1, 1, 1;
17+
18+
// faces
19+
m_F.resize(12, 3);
20+
m_F << 0, 2, 1, 2, 3, 1, 1, 3, 5, 3, 7, 5, 2, 6, 3, 6, 7, 3, 5, 7, 4, 7,
21+
6, 4, 4, 6, 0, 6, 2, 0, 0, 4, 1, 4, 5, 1;
22+
23+
// face colors
24+
m_C.resize(12, 3);
25+
26+
reset();
27+
}
28+
29+
virtual void resetMembers() override {
30+
m_C.setZero();
31+
m_C.col(0).setOnes();
32+
}
33+
34+
virtual void updateRenderGeometry() override {
35+
m_renderV = m_V;
36+
m_renderF = m_F;
37+
m_renderC = m_C;
38+
}
39+
40+
virtual bool advance() override {
41+
// do next step of some color animation
42+
int speed = 60;
43+
int decColor = (m_step / speed) % 3;
44+
int incColor = (decColor + 1) % 3;
45+
46+
for (int i = 0; i < m_C.rows(); i++) {
47+
m_C(i, decColor) = (m_C(i, decColor) * speed - 1) / speed;
48+
m_C(i, incColor) = (m_C(i, incColor) * speed + 1) / speed;
49+
}
50+
51+
// advance step
52+
m_step++;
53+
return false;
54+
}
55+
56+
virtual void renderRenderGeometry(
57+
igl::opengl::glfw::Viewer &viewer) override {
58+
viewer.data().set_mesh(m_renderV, m_renderF);
59+
viewer.data().set_colors(m_renderC);
60+
}
61+
62+
private:
63+
Eigen::MatrixXd m_V; // vertex positions
64+
Eigen::MatrixXi m_F; // face indices
65+
Eigen::MatrixXd m_C; // colors per face
66+
67+
Eigen::MatrixXd m_renderV; // vertex positions for rendering
68+
Eigen::MatrixXi m_renderF; // face indices for rendering
69+
Eigen::MatrixXd m_renderC; // colors per face for rendering
70+
};

demos/0_dummy/main.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <igl/writeOFF.h>
2+
#include <thread>
3+
#include "DummySim.h"
4+
#include "Gui.h"
5+
#include "Simulator.h"
6+
7+
/*
8+
* This class is a GUI for our dummy simulation. It extends the basic GUI
9+
* defined in Gui.h. We could add more controls and visuals here, but we don't
10+
* need any additional functionality for this dummy simulation.
11+
*/
12+
class DummyGui : public Gui {
13+
public:
14+
DummySim *p_dummySim = NULL; // pointer to the dummy simulation
15+
16+
DummyGui() {
17+
// create a new dummy simulation
18+
p_dummySim = new DummySim();
19+
20+
// set this simulation as the simulation that is running in our GUI
21+
setSimulation(p_dummySim);
22+
23+
// start the GUI
24+
start();
25+
}
26+
27+
virtual void updateSimulationParameters() override{
28+
// We don't have any simulation parameters to update periodically so we
29+
// don't need to do anything here
30+
};
31+
};
32+
33+
int main(int argc, char *argv[]) {
34+
// create a new instance of the GUI for the dummy simulation
35+
new DummyGui();
36+
37+
return 0;
38+
}

demos/1_cannonball/CMakeLists.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
cmake_minimum_required(VERSION 3.1)
3+
project(1_cannonball)
4+
5+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
6+
set(CMAKE_CXX_FLAGS "-Wall")
7+
8+
# libigl
9+
option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF)
10+
option(LIBIGL_WITH_ANTTWEAKBAR "Use AntTweakBar" OFF)
11+
option(LIBIGL_WITH_CGAL "Use CGAL" OFF)
12+
option(LIBIGL_WITH_COMISO "Use CoMiso" OFF)
13+
option(LIBIGL_WITH_CORK "Use Cork" OFF)
14+
option(LIBIGL_WITH_EMBREE "Use Embree" OFF)
15+
option(LIBIGL_WITH_LIM "Use LIM" OFF)
16+
option(LIBIGL_WITH_MATLAB "Use Matlab" OFF)
17+
option(LIBIGL_WITH_MOSEK "Use MOSEK" OFF)
18+
option(LIBIGL_WITH_OPENGL "Use OpenGL" ON)
19+
option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON)
20+
option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" ON)
21+
option(LIBIGL_WITH_PNG "Use PNG" OFF)
22+
option(LIBIGL_WITH_PYTHON "Use Python" OFF)
23+
option(LIBIGL_WITH_TETGEN "Use Tetgen" OFF)
24+
option(LIBIGL_WITH_TRIANGLE "Use Triangle" OFF)
25+
option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON)
26+
option(LIBIGL_WITH_XML "Use XML" OFF)
27+
28+
if (NOT LIBIGL_FOUND)
29+
find_package(LIBIGL REQUIRED QUIET)
30+
endif()
31+
32+
# Add your project files
33+
file(GLOB SRCFILES *.cpp)
34+
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/../include/*.cpp)
35+
file(GLOB HFILES *.h)
36+
file(GLOB H_FILES ${PROJECT_SOURCE_DIR}/../include/*.h)
37+
38+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
39+
40+
add_definitions(-DIGL_VIEWER_VIEWER_QUIET)
41+
add_executable(${PROJECT_NAME} ${SRCFILES} ${SRC_FILES} ${HFILES} ${H_FILES})
42+
target_link_libraries(${PROJECT_NAME} igl::core igl::opengl_glfw igl::opengl_glfw_imgui)

demos/1_cannonball/CannonBallSim.cpp

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "CannonBallSim.h"
2+
3+
/////////////////////////////////////
4+
//////// EX 1 - PROBLEM 1 ///////////
5+
/////////////////////////////////////
6+
bool CannonBallSim::advance() {
7+
// perform time integration with different integrators
8+
9+
// use p_ball, m_dt, m_gravity
10+
switch (m_method) {
11+
case 0:
12+
{
13+
Eigen::Vector3d v = p_ball->getLinearVelocity();
14+
15+
Eigen::Vector3d pos = p_ball->getPosition();
16+
pos[0] += v[0] * m_dt;
17+
pos[1] += v[1] * m_dt + .5*m_gravity[1]*m_dt*m_dt;
18+
pos[2] += v[2] * m_dt;
19+
p_ball->setPosition(pos);
20+
21+
v[1] += m_gravity[1] * m_dt;
22+
p_ball->setLinearVelocity(v);
23+
}
24+
break;
25+
26+
case 1:
27+
// explicit euler
28+
{
29+
Eigen::Vector3d v = p_ball->getLinearVelocity();
30+
31+
Eigen::Vector3d pos = p_ball->getPosition();
32+
pos[0] += v[0] * m_dt;
33+
pos[1] += v[1] * m_dt;
34+
pos[2] += v[2] * m_dt;
35+
p_ball->setPosition(pos);
36+
37+
v[1] += m_gravity[1] * m_dt;
38+
p_ball->setLinearVelocity(v);
39+
}
40+
break;
41+
42+
case 2:
43+
// symplectic euler
44+
{
45+
Eigen::Vector3d v = p_ball->getLinearVelocity();
46+
v[1] += m_gravity[1] * m_dt;
47+
p_ball->setLinearVelocity(v);
48+
49+
Eigen::Vector3d pos = p_ball->getPosition();
50+
pos[0] += v[0] * m_dt;
51+
pos[1] += v[1] * m_dt;
52+
pos[2] += v[2] * m_dt;
53+
p_ball->setPosition(pos);
54+
}
55+
break;
56+
57+
default:
58+
std::cerr << m_method << " is not a valid integrator method."
59+
<< std::endl;
60+
}
61+
62+
// advance time
63+
m_time += m_dt;
64+
m_step++;
65+
66+
// log
67+
if ((m_step % m_log_frequency) == 0) {
68+
m_trajectories.back().push_back(p_ball->getPosition());
69+
}
70+
71+
return false;
72+
}

0 commit comments

Comments
 (0)