├── .github
└── workflows
│ └── c-cpp.yml
├── .gitmodules
├── CMakeLists.txt
├── README.html
├── README.md
├── README.tex.md
├── assignment_setup.h
├── cmake
└── FindLIBIGL.cmake
├── css
└── github-markdown.css
├── data
├── arma_6.ele
├── arma_6.node
├── armadillo.mtl
├── armadillo.obj
├── armadillo.off
├── armadillo2.obj
├── bunny_skin.mtl
├── bunny_skin.obj
├── coarse_bunny.mesh
├── coarser_bunny.mesh
├── coarser_bunny.mtl
└── coarser_bunny.obj
├── images
├── 06084bd13aad92a3f657add21d5dc25e.svg
├── 078c28f2cd5f6e3559243bd7ebf55e0e.svg
├── 07fa8f51f4cd0e31f63743c0638a3388.svg
├── 0a4b8813bf5f5396689dcc60d64ab92e.svg
├── 0a6733943ebc99bb70de1c5cda4d14c5.svg
├── 0d91a053c03a8131b1b1497899452125.svg
├── 1035a4ac6789d259e5b11678e1db3967.svg
├── 14b88c29f249c16ee64da346bc37d777.svg
├── 1606eff7b7a2241374521e03fe1b7239.svg
├── 190083ef7a1625fbc75f243cffb9c96d.svg
├── 1e9c29c7c5b33d59873273141163a333.svg
├── 1f4a642c645674854adffbaa639dd908.svg
├── 21fd4e8eecd6bdf1a4d3d6bd1fb8d733.svg
├── 22b5ccb4ca14492a9521b55a317b12a3.svg
├── 254b5869977f861ee43c7fd647de6abc.svg
├── 266058ae232163eb4de3d7537b0fe02e.svg
├── 2982880f70a8a26b2a8893ae4db190b0.svg
├── 2a1f81d7a975db283cdc9e11ae4040d9.svg
├── 2e26eb0900ac08bcaf445217a8686195.svg
├── 2f118ee06d05f3c2d98361d9c30e38ce.svg
├── 33bf811999b31b361dfb87ee222620f3.svg
├── 36b5afebdba34564d884d347484ac0c7.svg
├── 3c7cac95de837f24405a387a05e1e94e.svg
├── 3ca0fe29482c50082a90537c92bcffc0.svg
├── 3def24cf259215eefdd43e76525fb473.svg
├── 439d5b12dc6c860995693aa45e4255d1.svg
├── 445351fa1f735b7fb15f43dc67563219.svg
├── 44f83c3b5e0a3084115694e8bf6b75db.svg
├── 46e42d6ebfb1f8b50fe3a47153d01cd2.svg
├── 478350d0d864b8692fe97555bff414b3.svg
├── 47b0192f8f0819d64bce3612c46d15ea.svg
├── 48a0115fc523b1aae58ade9e16001f59.svg
├── 4970b63427124bfb7d74f64ff5e5f8a7.svg
├── 4ae0186e20725d789f0720e970fbca2b.svg
├── 4ae122305a485974b9c14dcefe22cae8.svg
├── 5229a0b816a5e512d358e842aab8f4c4.svg
├── 55a049b8f161ae7cfeb0197d75aff967.svg
├── 5cb6ebd57b9c3ef9c5bf226aa856c60d.svg
├── 5d597e98cef80f07f6aac0d8e30cc70a.svg
├── 5dc642f297e291cfdde8982599601d7e.svg
├── 5f3cc59831e6b4aef298a2dacada3fe7.svg
├── 60c7f8444e2f683eb807f4085729add6.svg
├── 634073c68b4832cc0868f0293d1d432c.svg
├── 63d88efc25d5db55efb8d46d2ca78bc2.svg
├── 661cc435e9a81c8ee162d5ae09e11595.svg
├── 6877f647e069046a8b1d839a5a801c69.svg
├── 688dbb64333e268488085f69a78728c2.svg
├── 6dec54c48a0438a5fcde6053bdb9d712.svg
├── 6e355470c45cc13b0430c284142cf243.svg
├── 74380e4b90b7786c87c490f3d94f2f68.svg
├── 74d82ca02624178772e80a255644d657.svg
├── 77a3b857d53fb44e33b53e4c8b68351a.svg
├── 7b9a0316a2fcd7f01cfd556eedf72e96.svg
├── 7ccb42e2821b2a382a72de820aaec42f.svg
├── 7cdb1bc71035910e68927b8821ecae9a.svg
├── 7e3c241c2dec821bd6c6fbd314fe4762.svg
├── 7f5d5d26767ddfc8af4bc7e06443c91a.svg
├── 81f710835c45bfaf18fe1e7bb9a8939b.svg
├── 83cdc7684deaca981967b968b88bf53b.svg
├── 846606bb011963601357e7ffbb1c2e4d.svg
├── 84c95f91a742c9ceb460a83f9b5090bf.svg
├── 8c219eedfdfdc19ae90646c92cb8da87.svg
├── 8cd34385ed61aca950a6b06d09fb50ac.svg
├── 96a0d4689a271ea009338df0fe7d3441.svg
├── 96fc02c4358bf4203e3dad5a028f50ba.svg
├── 97ab0bce852d417ba9871adc2af7bb26.svg
├── 9b01119ffd35fe6d8a8795a24fc11616.svg
├── 9b6dbadab1b122f6d297345e9d3b8dd7.svg
├── 9f2b6b0a7f3d99fd3f396a1515926eb3.svg
├── ae79425c6396a3fc7acd3d31d3bc3bc5.svg
├── armadillo.gif
├── b2cfa6fb033016e1698b121b3a85feec.svg
├── b393a71d7dbc7ba9bef53a45b498474d.svg
├── b8bc815b5e9d5177af01fd4d3d3c2f10.svg
├── bb6065b2aa874eda6d41b8b2e1951471.svg
├── c2a29561d89e139b3c7bffe51570c3ce.svg
├── c36ef0ba4721f49285945f33a25e7a45.svg
├── c83e439282bef5aadf55a91521506c1a.svg
├── c89fe8937285e2a8ec46151e34cdff69.svg
├── cbe99f908f3661c44ad20094523bbf90.svg
├── cc44391faa5e8aa1e9178dd46a4b72ae.svg
├── d05b996d2c08252f77613c25205a0f04.svg
├── d39736c0e076aef46a625c5c707477b0.svg
├── d6328eaebbcd5c358f426dbea4bdbf70.svg
├── da730e32b8911b7e9ad3398f199274a0.svg
├── e313402671b5400b40c904770c63159a.svg
├── e4a4c4648c0506be007da96bb84aa9de.svg
├── e5bb3e507ef64f233193c17770027989.svg
├── e73485aa867794d51ccd8725055d03a3.svg
├── ec7986eb29346b1eae6b36942b0fb975.svg
├── ef7188e17669f49e15672d7280b80119.svg
├── f027e3c4319ee773dd95bd75d4e0408c.svg
├── f20040204ebc8a72f628b655070e699b.svg
├── f26134068b0b67870aaea679207afc4b.svg
├── fb97d38bcc19230b0acd442e17db879c.svg
├── fba0226e6f733da0926fe0f5f7a4b81e.svg
├── fcd1de7e861cf2d0a4a5d2a72aa12161.svg
├── fe6804f6bc753bbf4631ab6c9542bec5.svg
├── fed8de6866c9a59fd93afcbfc65d0c96.svg
└── tet_mesh.png
├── include
├── T_linear_tetrahedron.h
├── V_linear_tetrahedron.h
├── V_spring_particle_particle.h
├── assemble_forces.h
├── assemble_stiffness.h
├── build_skinning_matrix.h
├── d2V_linear_tetrahedron_dq2.h
├── d2psi_neo_hookean_dq2.h
├── dV_linear_tetrahedron_dq.h
├── dV_spring_particle_particle_dq.h
├── dphi_linear_tetrahedron_dX.h
├── dpsi_neo_hookean_dF.h
├── fixed_point_constraints.h
├── implicit_euler.h
├── linearly_implicit_euler.h
├── mass_matrix_linear_tetrahedron.h
├── mass_matrix_mesh.h
├── newtons_method.h
├── phi_linear_tetrahedron.h
├── pick_nearest_vertices.h
├── psi_neo_hookean.h
└── quadrature_single_point.h
├── main.cpp
├── shared
├── include
│ ├── EigenTypes.h
│ ├── find_min_vertices.h
│ ├── init_state.h
│ ├── read_tetgen.h
│ └── visualization.h
└── src
│ ├── find_min_vertices.cpp
│ ├── init_state.cpp
│ ├── read_tetgen.cpp
│ └── visualization.cpp
├── src
├── T_linear_tetrahedron.cpp
├── V_linear_tetrahedron.cpp
├── V_spring_particle_particle.cpp
├── assemble_forces.cpp
├── assemble_stiffness.cpp
├── build_skinning_matrix.cpp
├── d2V_linear_tetrahedron_dq2.cpp
├── d2psi_neo_hookean_dF2.cpp
├── dV_linear_tetrahedron_dq.cpp
├── dV_spring_particle_particle_dq.cpp
├── dphi_linear_tetrahedron_dX.cpp
├── dpsi_neo_hookean_dF.cpp
├── fixed_point_constraints.cpp
├── mass_matrix_linear_tetrahedron.cpp
├── mass_matrix_mesh.cpp
├── phi_linear_tetrahedron.cpp
├── pick_nearest_vertices.cpp
└── psi_neo_hookean.cpp
└── tex
├── 06084bd13aad92a3f657add21d5dc25e.svg
├── 078c28f2cd5f6e3559243bd7ebf55e0e.svg
├── 07fa8f51f4cd0e31f63743c0638a3388.svg
├── 0a4b8813bf5f5396689dcc60d64ab92e.svg
├── 0a6733943ebc99bb70de1c5cda4d14c5.svg
├── 0d91a053c03a8131b1b1497899452125.svg
├── 1035a4ac6789d259e5b11678e1db3967.svg
├── 13180d53c96053c0f89607ece84c3f51.svg
├── 14b88c29f249c16ee64da346bc37d777.svg
├── 1606eff7b7a2241374521e03fe1b7239.svg
├── 190083ef7a1625fbc75f243cffb9c96d.svg
├── 1e9c29c7c5b33d59873273141163a333.svg
├── 1f4a642c645674854adffbaa639dd908.svg
├── 21fd4e8eecd6bdf1a4d3d6bd1fb8d733.svg
├── 22b5ccb4ca14492a9521b55a317b12a3.svg
├── 254b5869977f861ee43c7fd647de6abc.svg
├── 2982880f70a8a26b2a8893ae4db190b0.svg
├── 2a1f81d7a975db283cdc9e11ae4040d9.svg
├── 2e26eb0900ac08bcaf445217a8686195.svg
├── 2f118ee06d05f3c2d98361d9c30e38ce.svg
├── 33bf811999b31b361dfb87ee222620f3.svg
├── 36b5afebdba34564d884d347484ac0c7.svg
├── 3c7cac95de837f24405a387a05e1e94e.svg
├── 3ca0fe29482c50082a90537c92bcffc0.svg
├── 3def24cf259215eefdd43e76525fb473.svg
├── 439d5b12dc6c860995693aa45e4255d1.svg
├── 445351fa1f735b7fb15f43dc67563219.svg
├── 46e42d6ebfb1f8b50fe3a47153d01cd2.svg
├── 478350d0d864b8692fe97555bff414b3.svg
├── 47b0192f8f0819d64bce3612c46d15ea.svg
├── 48a0115fc523b1aae58ade9e16001f59.svg
├── 4970b63427124bfb7d74f64ff5e5f8a7.svg
├── 4ae0186e20725d789f0720e970fbca2b.svg
├── 4ae122305a485974b9c14dcefe22cae8.svg
├── 5229a0b816a5e512d358e842aab8f4c4.svg
├── 55a049b8f161ae7cfeb0197d75aff967.svg
├── 5cb6ebd57b9c3ef9c5bf226aa856c60d.svg
├── 5d597e98cef80f07f6aac0d8e30cc70a.svg
├── 5dc642f297e291cfdde8982599601d7e.svg
├── 5f3cc59831e6b4aef298a2dacada3fe7.svg
├── 60c7f8444e2f683eb807f4085729add6.svg
├── 634073c68b4832cc0868f0293d1d432c.svg
├── 63d88efc25d5db55efb8d46d2ca78bc2.svg
├── 661cc435e9a81c8ee162d5ae09e11595.svg
├── 6877f647e069046a8b1d839a5a801c69.svg
├── 688dbb64333e268488085f69a78728c2.svg
├── 6dec54c48a0438a5fcde6053bdb9d712.svg
├── 6e355470c45cc13b0430c284142cf243.svg
├── 70f5e4c764ea66c6de7bb1a14ff5399d.svg
├── 74380e4b90b7786c87c490f3d94f2f68.svg
├── 77a3b857d53fb44e33b53e4c8b68351a.svg
├── 7b9a0316a2fcd7f01cfd556eedf72e96.svg
├── 7ccb42e2821b2a382a72de820aaec42f.svg
├── 7cdb1bc71035910e68927b8821ecae9a.svg
├── 7e3c241c2dec821bd6c6fbd314fe4762.svg
├── 7f5d5d26767ddfc8af4bc7e06443c91a.svg
├── 81f710835c45bfaf18fe1e7bb9a8939b.svg
├── 83cdc7684deaca981967b968b88bf53b.svg
├── 846606bb011963601357e7ffbb1c2e4d.svg
├── 84c95f91a742c9ceb460a83f9b5090bf.svg
├── 8c219eedfdfdc19ae90646c92cb8da87.svg
├── 8cd34385ed61aca950a6b06d09fb50ac.svg
├── 90caee18717fbe3226775610fd30f8f7.svg
├── 96a0d4689a271ea009338df0fe7d3441.svg
├── 96fc02c4358bf4203e3dad5a028f50ba.svg
├── 97ab0bce852d417ba9871adc2af7bb26.svg
├── 9b01119ffd35fe6d8a8795a24fc11616.svg
├── 9b6dbadab1b122f6d297345e9d3b8dd7.svg
├── 9f2b6b0a7f3d99fd3f396a1515926eb3.svg
├── aa0e815b1c2707ddf9662d4b3abd569e.svg
├── ae79425c6396a3fc7acd3d31d3bc3bc5.svg
├── b2cfa6fb033016e1698b121b3a85feec.svg
├── b393a71d7dbc7ba9bef53a45b498474d.svg
├── b8bc815b5e9d5177af01fd4d3d3c2f10.svg
├── bb6065b2aa874eda6d41b8b2e1951471.svg
├── c2a29561d89e139b3c7bffe51570c3ce.svg
├── c36ef0ba4721f49285945f33a25e7a45.svg
├── c83e439282bef5aadf55a91521506c1a.svg
├── c89fe8937285e2a8ec46151e34cdff69.svg
├── cbe99f908f3661c44ad20094523bbf90.svg
├── cc44391faa5e8aa1e9178dd46a4b72ae.svg
├── d05b996d2c08252f77613c25205a0f04.svg
├── d39736c0e076aef46a625c5c707477b0.svg
├── d6328eaebbcd5c358f426dbea4bdbf70.svg
├── da730e32b8911b7e9ad3398f199274a0.svg
├── e313402671b5400b40c904770c63159a.svg
├── e4a4c4648c0506be007da96bb84aa9de.svg
├── e4e0ad250c3272976ab00b7ae8d3ff8f.svg
├── e5bb3e507ef64f233193c17770027989.svg
├── e73485aa867794d51ccd8725055d03a3.svg
├── ebd22d3989e7ba7b76b65d37b37eb8eb.svg
├── ec7986eb29346b1eae6b36942b0fb975.svg
├── ef7188e17669f49e15672d7280b80119.svg
├── f20040204ebc8a72f628b655070e699b.svg
├── f26134068b0b67870aaea679207afc4b.svg
├── fb97d38bcc19230b0acd442e17db879c.svg
├── fba0226e6f733da0926fe0f5f7a4b81e.svg
├── fcd1de7e861cf2d0a4a5d2a72aa12161.svg
├── fe6804f6bc753bbf4631ab6c9542bec5.svg
└── fed8de6866c9a59fd93afcbfc65d0c96.svg
/.github/workflows/c-cpp.yml:
--------------------------------------------------------------------------------
1 | name: Build-CSC2549-Assignment-Three
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 |
9 | jobs:
10 | # Linux / macOS
11 | Unix:
12 | name: ${{ matrix.name }} (${{ matrix.config }})
13 | runs-on: ${{ matrix.os }}
14 | strategy:
15 | fail-fast: false
16 | matrix:
17 | os: [ubuntu-latest, macos-latest]
18 | config: [Release]
19 | include:
20 | - os: macos-latest
21 | name: macOS
22 | - os: ubuntu-latest
23 | name: Linux
24 |
25 | env:
26 | OMP_NUM_THREADS: 1
27 |
28 | steps:
29 | - name: Checkout repository
30 | uses: actions/checkout@v2
31 | with:
32 | fetch-depth: 10
33 |
34 | - name: Checkout submodules
35 | run: git submodule update --init --recursive
36 |
37 | - name: Dependencies (Linux)
38 | if: runner.os == 'Linux'
39 | run: |
40 | sudo apt-get update
41 | sudo apt-get install \
42 | build-essential \
43 | cmake \
44 | mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev \
45 | xorg-dev \
46 | libx11-dev \
47 | libxinerama1 libxinerama-dev \
48 | libxcursor-dev libxrandr-dev libxi-dev libxmu-dev \
49 |
50 | - name: Dependencies (macOS)
51 | if: runner.os == 'macOS'
52 | run: |
53 | brew update
54 | brew info git || brew install git
55 | brew info cmake || brew install cmake
56 |
57 | - name: Configure
58 | run: |
59 | mkdir -p build
60 | cd build
61 | cmake .. -DCMAKE_BUILD_TYPE=${{ matrix.config }}
62 | - name: Build
63 | run: |
64 | cd build
65 | make
66 |
67 | # Windows
68 | Windows:
69 | runs-on: windows-latest
70 | env:
71 | CC: cl.exe
72 | CXX: cl.exe
73 | strategy:
74 | fail-fast: false
75 | matrix:
76 | config: [Release]
77 | steps:
78 | - name: Checkout repository
79 | uses: actions/checkout@v2
80 | with:
81 | fetch-depth: 10
82 |
83 | - name: Checkout submodules
84 | run: git submodule update --init --recursive
85 |
86 | - name: Configure and build
87 | shell: cmd
88 | run: |
89 | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=x64
90 | cmake -G Ninja ^
91 | -DCMAKE_BUILD_TYPE=${{ matrix.config }} ^
92 | -B build ^
93 | -S .
94 | cmake --build build
95 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "extern/libigl"]
2 | path = extern/libigl
3 | url = https://github.com/libigl/libigl.git
4 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.2)
2 |
3 | project(a3-finite-elements-3d)
4 |
5 | #Important CMAKE stuff
6 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
7 |
8 | #setup libigl properly
9 | # libigl
10 | option(LIBIGL_WITH_OPENGL "Use OpenGL" ON)
11 | option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON)
12 | option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" ON)
13 |
14 | find_package(LIBIGL REQUIRED QUIET)
15 |
16 | #include directories
17 | include_directories(${PROJECT_SOURCE_DIR}/shared/include)
18 | include_directories(${PROJECT_SOURCE_DIR}/include)
19 | include_directories(${PROJECT_SOURCE_DIR})
20 | include_directories(${LIBIGL_INCLUDE_DIR})
21 |
22 | #include source code
23 | file(GLOB H_FILES ${PROJECT_SOURCE_DIR}/include/*.h)
24 | file(GLOB H_SHARED_FILES ${PROJECT_SOURCE_DIR}/shared/include/*.h)
25 | file(GLOB CPP_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
26 | file(GLOB CPP_SHARED_FILES ${PROJECT_SOURCE_DIR}/shared/src/*.cpp)
27 |
28 | #build executable
29 | add_executable(${PROJECT_NAME} main.cpp assignment_setup.h ${H_FILES} ${H_SHARED_FILES} ${CPP_FILES} ${CPP_SHARED_FILES})
30 | target_link_libraries(${PROJECT_NAME} igl::core igl::opengl igl::opengl_glfw igl::opengl_glfw_imgui)
31 |
32 |
33 |
--------------------------------------------------------------------------------
/cmake/FindLIBIGL.cmake:
--------------------------------------------------------------------------------
1 | # - Try to find the LIBIGL library
2 | # Once done this will define
3 | #
4 | # LIBIGL_FOUND - system has LIBIGL
5 | # LIBIGL_INCLUDE_DIR - **the** LIBIGL include directory
6 | if(LIBIGL_FOUND)
7 | return()
8 | endif()
9 |
10 | find_path(LIBIGL_INCLUDE_DIR igl/readOBJ.h
11 | HINTS
12 | ENV LIBIGL
13 | ENV LIBIGLROOT
14 | ENV LIBIGL_ROOT
15 | ENV LIBIGL_DIR
16 | PATHS
17 | ${CMAKE_SOURCE_DIR}/../..
18 | ${CMAKE_SOURCE_DIR}/..
19 | ${CMAKE_SOURCE_DIR}
20 | ${CMAKE_SOURCE_DIR}/extern/libigl/include
21 | ${CMAKE_SOURCE_DIR}/../libigl
22 | ${CMAKE_SOURCE_DIR}/../../libigl
23 | /usr
24 | /usr/local
25 | /usr/local/igl/libigl
26 | PATH_SUFFIXES include
27 | )
28 |
29 | include(FindPackageHandleStandardArgs)
30 | find_package_handle_standard_args(LIBIGL
31 | "\nlibigl not found --- You can download it using:\n\tgit clone --recursive https://github.com/libigl/libigl.git ${CMAKE_SOURCE_DIR}/../libigl"
32 | LIBIGL_INCLUDE_DIR)
33 | mark_as_advanced(LIBIGL_INCLUDE_DIR)
34 |
35 | list(APPEND CMAKE_MODULE_PATH "${LIBIGL_INCLUDE_DIR}/../cmake")
36 | include(libigl)
--------------------------------------------------------------------------------
/data/armadillo.mtl:
--------------------------------------------------------------------------------
1 | # Blender MTL File: 'None'
2 | # Material Count: 1
3 |
4 | newmtl Default_OBJ.003
5 | Ns 225.000000
6 | Ka 1.000000 1.000000 1.000000
7 | Kd 0.800000 0.800000 0.800000
8 | Ks 0.500000 0.500000 0.500000
9 | Ke 0.0 0.0 0.0
10 | Ni 1.450000
11 | d 1.000000
12 | illum 2
13 |
--------------------------------------------------------------------------------
/data/bunny_skin.mtl:
--------------------------------------------------------------------------------
1 | # Blender MTL File: 'None'
2 | # Material Count: 1
3 |
4 | newmtl Default_OBJ
5 | Ns 225.000000
6 | Ka 1.000000 1.000000 1.000000
7 | Kd 0.800000 0.800000 0.800000
8 | Ks 0.500000 0.500000 0.500000
9 | Ke 0.0 0.0 0.0
10 | Ni 1.450000
11 | d 1.000000
12 | illum 2
13 |
--------------------------------------------------------------------------------
/data/coarser_bunny.mtl:
--------------------------------------------------------------------------------
1 | # Blender MTL File: 'None'
2 | # Material Count: 1
3 |
4 | newmtl Default_OBJ
5 | Ns 225.000000
6 | Ka 1.000000 1.000000 1.000000
7 | Kd 0.800000 0.800000 0.800000
8 | Ks 0.500000 0.500000 0.500000
9 | Ke 0.0 0.0 0.0
10 | Ni 1.450000
11 | d 1.000000
12 | illum 2
13 |
--------------------------------------------------------------------------------
/images/0d91a053c03a8131b1b1497899452125.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/1606eff7b7a2241374521e03fe1b7239.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/images/190083ef7a1625fbc75f243cffb9c96d.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/21fd4e8eecd6bdf1a4d3d6bd1fb8d733.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/2f118ee06d05f3c2d98361d9c30e38ce.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/36b5afebdba34564d884d347484ac0c7.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/46e42d6ebfb1f8b50fe3a47153d01cd2.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/images/47b0192f8f0819d64bce3612c46d15ea.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/55a049b8f161ae7cfeb0197d75aff967.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/5cb6ebd57b9c3ef9c5bf226aa856c60d.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/5d597e98cef80f07f6aac0d8e30cc70a.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/5dc642f297e291cfdde8982599601d7e.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/5f3cc59831e6b4aef298a2dacada3fe7.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/6877f647e069046a8b1d839a5a801c69.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/6dec54c48a0438a5fcde6053bdb9d712.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/77a3b857d53fb44e33b53e4c8b68351a.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/7b9a0316a2fcd7f01cfd556eedf72e96.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/7cdb1bc71035910e68927b8821ecae9a.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/7e3c241c2dec821bd6c6fbd314fe4762.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/84c95f91a742c9ceb460a83f9b5090bf.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/8cd34385ed61aca950a6b06d09fb50ac.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/armadillo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dilevin/CSC417-a3-finite-elements-3d/25a62624c6bb68df1c11d2d3d1ad13fd7c173b88/images/armadillo.gif
--------------------------------------------------------------------------------
/images/b8bc815b5e9d5177af01fd4d3d3c2f10.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/c89fe8937285e2a8ec46151e34cdff69.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/d05b996d2c08252f77613c25205a0f04.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/d6328eaebbcd5c358f426dbea4bdbf70.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/e73485aa867794d51ccd8725055d03a3.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/ef7188e17669f49e15672d7280b80119.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/images/fb97d38bcc19230b0acd442e17db879c.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/images/fed8de6866c9a59fd93afcbfc65d0c96.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/images/tet_mesh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dilevin/CSC417-a3-finite-elements-3d/25a62624c6bb68df1c11d2d3d1ad13fd7c173b88/images/tet_mesh.png
--------------------------------------------------------------------------------
/include/T_linear_tetrahedron.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // qdot - generalied velocity of FEM system
6 | // element - vertex indices of the element
7 | // density - material density
8 | // volume - volume of tetrahedron
9 | //Output:
10 | // T - kinetic energy of tetrahedron
11 | void T_linear_tetrahedron(double &T, Eigen::Ref qdot, Eigen::Ref element, double density, double volume);
--------------------------------------------------------------------------------
/include/V_linear_tetrahedron.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // q - generalized coordinates of FEM system
6 | // V - vertex matrix for the mesh
7 | // element - vertex indices of the element
8 | // volume - volume of tetrahedron
9 | // C,D - material parameters
10 | //Output:
11 | // energy - potential energy of tetrahedron
12 | void V_linear_tetrahedron(double &energy, Eigen::Ref q,
13 | Eigen::Ref V, Eigen::Ref element, double volume,
14 | double C, double D);
--------------------------------------------------------------------------------
/include/V_spring_particle_particle.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | //Input:
4 | // q0 - the generalized coordinates of the first node of the spring
5 | // q1 - the generalized coordinates of the second node of the spring
6 | // l0 - the undeformed length of the spring
7 | // stiffness - the stiffness constant for this spring
8 | //Output:
9 | // V - potential energy for the spring
10 | void V_spring_particle_particle(double &V, Eigen::Ref q0, Eigen::Ref q1, double l0, double stiffness);
--------------------------------------------------------------------------------
/include/assemble_forces.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | //Input:
7 | // q - generalized coordinates for the FEM system
8 | // qdot - generalized velocity for the FEM system
9 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
10 | // T - the mx4 tetrahedron connectivity matrix. Each row contains to indices into V that indicate a spring between those vertices.
11 | // v0 - the mx1 vector of undeformed tetrahedron volumes
12 | // C,D - material parameters for the Neo-Hookean model
13 | //Output:
14 | // f - the vector 3xn vector of forces acting on each node of the mass-spring system
15 | void assemble_forces(Eigen::VectorXd &f, Eigen::Ref q, Eigen::Ref qdot,
16 | Eigen::Ref V, Eigen::Ref T, Eigen::Ref v0,
17 | double C, double D);
--------------------------------------------------------------------------------
/include/assemble_stiffness.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | //Input:
7 | // q - generalized coordinates for the FEM system
8 | // qdot - generalized velocity for the FEM system
9 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
10 | // T - the mx4 tetrahedron connectivity matrix. Each row contains to indices into V that indicate a spring between those vertices.
11 | // v0 - the mx1 vector of undeformed tetrahedron volumes
12 | // C,D - material parameters for the Neo-Hookean model
13 | //Output:
14 | // K - the sparse, global stiffness matrix
15 | void assemble_stiffness(Eigen::SparseMatrixd &K, Eigen::Ref q, Eigen::Ref qdot,
16 | Eigen::Ref V, Eigen::Ref T, Eigen::Ref v0,
17 | double C, double D);
--------------------------------------------------------------------------------
/include/build_skinning_matrix.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
6 | // T - the mx4 tetrahedron connectivity matrix. Each row contains to indices into V that indicate a spring between those vertices.
7 | // V_skin - lx3 matrix of vertices of the display mesh
8 | //Output:
9 | // N - the lxn sparse skinning matrix
10 | void build_skinning_matrix(Eigen::SparseMatrixd &N, Eigen::Ref V, Eigen::Ref T,
11 | Eigen::Ref V_skin);
12 |
--------------------------------------------------------------------------------
/include/d2V_linear_tetrahedron_dq2.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // q - generalized coordinates for the FEM system
6 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
7 | // element - the 1x4 vertex indices for this tetrahedron
8 | // v0 - the undeformed tetrahedron volume
9 | // C,D - material parameters for the Neo-Hookean model
10 | //Output:
11 | // dV - the 12x12 Hessian of the potential energy for a single tetrahedron
12 | void d2V_linear_tetrahedron_dq2(Eigen::Matrix1212d &dV, Eigen::Ref q,
13 | Eigen::Ref V, Eigen::Ref element, double volume,
14 | double C, double D);
--------------------------------------------------------------------------------
/include/d2psi_neo_hookean_dq2.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // F - the dense 3x3 deformation gradient
6 | // C,D - material parameters for the Neo-Hookean model
7 | //Output:
8 | // psi - the 9x9 Hessian of the potential energy wrt to the deformation gradient
9 | void d2psi_neo_hookean_dF2(Eigen::Matrix99d &psi, Eigen::Ref F, double C, double D);
--------------------------------------------------------------------------------
/include/dV_linear_tetrahedron_dq.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // q - generalized coordinates for the FEM system
6 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
7 | // element - the 1x4 vertex indices for this tetrahedron
8 | // v0 - the undeformed tetrahedron volume
9 | // C,D - material parameters for the Neo-Hookean model
10 | //Output:
11 | // dV - the 12x1 gradient of the potential energy for a single tetrahedron
12 | void dV_linear_tetrahedron_dq(Eigen::Vector12d &dV, Eigen::Ref q,
13 | Eigen::Ref V, Eigen::Ref element, double volume,
14 | double C, double D);
--------------------------------------------------------------------------------
/include/dV_spring_particle_particle_dq.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // q0 - the generalized coordinates of the first node of the spring
6 | // q1 - the generalized coordinates of the second node of the spring
7 | // l0 - the undeformed length of the spring
8 | // stiffness - the stiffness constant for this spring
9 | //Output:
10 | // f - the 6x1 per spring generalized force vector
11 | void dV_spring_particle_particle_dq(Eigen::Ref f, Eigen::Ref q0, Eigen::Ref q1, double l0, double stiffness);
--------------------------------------------------------------------------------
/include/dphi_linear_tetrahedron_dX.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
6 | // element - the 1x4 vertex indices for this tetrahedron
7 | // X - the position in the underformed space at which to compute the energy density
8 | //Output:
9 | // dphi - the 4x3 gradient of the the basis functions wrt to X. The i'th row stores d phi_i/dX
10 | void dphi_linear_tetrahedron_dX(Eigen::Matrix43d &dphi, Eigen::Ref V, Eigen::Ref element, Eigen::Ref X);
11 |
--------------------------------------------------------------------------------
/include/dpsi_neo_hookean_dF.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // F - the dense 3x3 deformation gradient
6 | // C,D - material parameters for the Neo-Hookean model
7 | //Output:
8 | // psi - the 9x1 gradient of the potential energy wrt to the deformation gradient
9 | void dpsi_neo_hookean_dF(Eigen::Vector9d &psi, Eigen::Ref F, double C, double D);
10 |
11 |
--------------------------------------------------------------------------------
/include/fixed_point_constraints.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include
6 |
7 | //Input:
8 | // q_size - total number of scalar generalized coordinates (3n for n vertices)
9 | // indices - m indices (row ids in V) for fixed vertices
10 | //Output:
11 | // P - 3(n-m)x3n sparse matrix which projects out fixed vertices
12 | void fixed_point_constraints(Eigen::SparseMatrixd &P, unsigned int q_size, const std::vector indices);
13 |
--------------------------------------------------------------------------------
/include/implicit_euler.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | //Input:
6 | // q - generalized coordinates for the FEM system
7 | // qdot - generalized velocity for the FEM system
8 | // dt - the time step in seconds
9 | // mass - the mass matrix
10 | // energy(q, qdot) - a function that computes the energy of the FEM system. This takes q and qdot as parameters, returns the energy value.
11 | // force(f, q, qdot) - a function that computes the force acting on the FEM system. This takes q and qdot as parameters, returns the force in f.
12 | // stiffness(K, q, qdot) - a function that computes the stiffness (negative second derivative of the potential energy). This takes q and qdot as parameters, returns the stiffness matrix in K.
13 | // tmp_qdot - scratch space for storing velocities
14 | // tmp_force - scratch space to collect forces
15 | // tmp_stiffness - scratch space to collect stiffness matrix
16 | //Output:
17 | // q - set q to the updated generalized coordinate using linearly implicit time integration
18 | // qdot - set qdot to the updated generalized velocity using linearly implicit time integration
19 | template
20 | inline void implicit_euler(Eigen::VectorXd &q, Eigen::VectorXd &qdot, double dt,
21 | const Eigen::SparseMatrixd &mass, ENERGY &energy, FORCE &force, STIFFNESS &stiffness,
22 | Eigen::VectorXd &tmp_qdot, Eigen::VectorXd &tmp_force, Eigen::SparseMatrixd &tmp_stiffness) {
23 |
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/include/linearly_implicit_euler.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | //Input:
7 | // q - generalized coordinates for the FEM system
8 | // qdot - generalized velocity for the FEM system
9 | // dt - the time step in seconds
10 | // mass - the mass matrix
11 | // force(f, q, qdot) - a function that computes the force acting on the FEM system. This takes q and qdot as parameters, returns the force in f.
12 | // stiffness(K, q, qdot) - a function that computes the stiffness (negative second derivative of the potential energy). This takes q and qdot as parameters, returns the stiffness matrix in K.
13 | // tmp_force - scratch space to collect forces
14 | // tmp_stiffness - scratch space to collect stiffness matrix
15 | //Output:
16 | // q - set q to the updated generalized coordinate using linearly implicit time integration
17 | // qdot - set qdot to the updated generalized velocity using linearly implicit time integration
18 | template
19 | inline void linearly_implicit_euler(Eigen::VectorXd &q, Eigen::VectorXd &qdot, double dt,
20 | const Eigen::SparseMatrixd &mass, FORCE &force, STIFFNESS &stiffness,
21 | Eigen::VectorXd &tmp_force, Eigen::SparseMatrixd &tmp_stiffness) {
22 |
23 |
24 | }
--------------------------------------------------------------------------------
/include/mass_matrix_linear_tetrahedron.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // qdot - generalized velocity for the FEM system
6 | // element - the 1x4 vertex indices for this tetrahedron
7 | // density - density of material
8 | // volume - the undeformed tetrahedron volume
9 | //Output:
10 | // M - dense 12x12 per-tetrahedron mass matrix
11 | void mass_matrix_linear_tetrahedron(Eigen::Matrix1212d &M, Eigen::Ref qdot, Eigen::Ref element, double density, double volume);
12 |
--------------------------------------------------------------------------------
/include/mass_matrix_mesh.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // qdot - generalized velocity for the FEM system
6 | // T - the mx4 vertex indices for tet mesh
7 | // density - density of material
8 | // v0 - the undeformed tetrahedra volumes
9 | //Output:
10 | // M - Sparse mass matrix for the whole mesh.
11 | void mass_matrix_mesh(Eigen::SparseMatrixd &M, Eigen::Ref qdot, Eigen::Ref T, double density, Eigen::Ref v0);
--------------------------------------------------------------------------------
/include/newtons_method.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // x0 - initial point for newtons search
6 | // f(x) - function that evaluates and returns the cost function at x
7 | // g(dx, x) - function that evaluates and returns the gradient of the cost function in dx
8 | // H(dH, x) - function that evaluates and returns the Hessian in dH (as a sparse matrix).
9 | // max steps - the maximum newton iterations to take
10 | // tmp_g and tmp_H are scratch space to store gradients and hessians
11 | //Output:
12 | // x0 - update x0 to new value
13 | template
14 | double newtons_method(Eigen::VectorXd &x0, Objective &f, Jacobian &g, Hessian &H, unsigned int maxSteps, Eigen::VectorXd &tmp_g, Eigen::SparseMatrixd &tmp_H) {
15 |
16 | return 0.0;
17 | }
18 |
--------------------------------------------------------------------------------
/include/phi_linear_tetrahedron.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // V - the nx3 matrix of undeformed vertex positions. Each row is a single undeformed vertex position.
6 | // element - the 1x4 vertex indices for this tetrahedron
7 | // X - the position in the underformed space at which to compute the energy density
8 | //Output:
9 | // phi - the 4x1 values the basis functions
10 | void phi_linear_tetrahedron(Eigen::Vector4d &phi, Eigen::Ref V, Eigen::Ref element, Eigen::Ref x);
11 |
--------------------------------------------------------------------------------
/include/pick_nearest_vertices.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 |
6 | //Same as Assignment 2
7 | bool pick_nearest_vertices(std::vector &verts, Eigen::Ref win,
8 | Eigen::Ref view, Eigen::Ref proj, Eigen::Vector4f viewport,
9 | Eigen::Ref V, Eigen::Ref F, double radius);
--------------------------------------------------------------------------------
/include/psi_neo_hookean.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // F - the dense 3x3 deformation gradient
6 | // C,D - material parameters for the Neo-Hookean model
7 | //Output:
8 | // psi - the neohookean energy
9 | void psi_neo_hookean(double &psi, Eigen::Ref F, double C, double D);
--------------------------------------------------------------------------------
/include/quadrature_single_point.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | //Input:
5 | // q - generalized coordinates of the FEM system
6 | // element - vertex indices for the tetrahedron
7 | // volume - volume of the tetrahedron
8 | // integrand(out, q, X) - function to be integrated, returns value in out.
9 | //Output:
10 | // integrated - the value of the integrated function
11 | template
12 | inline void quadrature_single_point(Ret &&integrated, Eigen::Ref q,
13 | Eigen::Ref element, double volume,
14 | Integrand_Func integrand) {
15 |
16 |
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include
5 | #include
6 |
7 | //Simulation State
8 | Eigen::VectorXd q;
9 | Eigen::VectorXd qdot;
10 |
11 | //simulation time and time step
12 | double t = 0; //simulation time
13 | double dt = 0.01; //time step
14 |
15 | //simulation loop
16 | bool simulating = true;
17 |
18 | bool simulation_callback() {
19 |
20 | while(simulating) {
21 | simulate(q, qdot, dt, t);
22 | t += dt;
23 | }
24 |
25 | return false;
26 | }
27 |
28 | bool draw_callback(igl::opengl::glfw::Viewer &viewer) {
29 |
30 | draw(q, qdot, t);
31 |
32 | return false;
33 | }
34 |
35 | void f(int &a, int b, int c) {
36 | a = b + c;
37 |
38 |
39 | }
40 |
41 | void g(Eigen::Vector3d &a, Eigen::Vector3d b, Eigen::Vector3d c) {
42 | a = b + c;
43 | }
44 |
45 | template
46 | void h(Ret &&a, B b, C c, void (*func)(Ret, B, C)) {
47 | func(a,b,c);
48 | }
49 |
50 | int main(int argc, char **argv) {
51 |
52 | std::cout<<"Start A3\n";
53 |
54 | //assignment specific setup
55 | assignment_setup(argc, argv, q, qdot);
56 |
57 | //run simulation in seperate thread to avoid slowing down the UI
58 | std::thread simulation_thread(simulation_callback);
59 | simulation_thread.detach();
60 |
61 | //setup libigl viewer and activate
62 | Visualize::setup(q, qdot, true);
63 | Visualize::viewer().callback_post_draw = &draw_callback;
64 | Visualize::viewer().launch();
65 |
66 | /* Function pointer example code so I don't forget
67 | int a1;
68 | Eigen::Vector3d a2;
69 |
70 | h(a1, 1,2, &f);
71 | h(a2, Eigen::Vector3d(1,0,0), Eigen::Vector3d(0,1,0), &g);
72 |
73 | std::cout<
5 | #include
6 |
7 | namespace Eigen {
8 |
9 | //dense types
10 | using Vector4d = Eigen::Matrix;
11 | using Vector6d = Eigen::Matrix;
12 | using Vector9d = Eigen::Matrix;
13 | using Vector12d = Eigen::Matrix;
14 |
15 | using Matrix36d = Eigen::Matrix;
16 | using Matrix34d = Eigen::Matrix;
17 | using Matrix43d = Eigen::Matrix;
18 | using Matrix66d = Eigen::Matrix;
19 | using Matrix99d = Eigen::Matrix;
20 | using Matrix1212d = Eigen::Matrix;
21 |
22 | using Matrix44f = Eigen::Matrix;
23 |
24 | //sparse types
25 | using SparseMatrixd = Eigen::SparseMatrix;
26 |
27 | }
28 |
29 | inline double stablePow(double a, double b) {
30 | return static_cast (std::pow(std::cbrt(static_cast(a)),static_cast(b)));
31 | }
32 |
33 | inline void inverse33(Eigen::Ref result, Eigen::Ref A) {
34 | double determinant = +A(0,0)*(A(1,1)*A(2,2)-A(2,1)*A(1,2))
35 | -A(0,1)*(A(1,0)*A(2,2)-A(1,2)*A(2,0))
36 | +A(0,2)*(A(1,0)*A(2,1)-A(1,1)*A(2,0));
37 | double invdet = 1/determinant;
38 | result(0,0) = (A(1,1)*A(2,2)-A(2,1)*A(1,2))*invdet;
39 | result(1,0) = -(A(0,1)*A(2,2)-A(0,2)*A(2,1))*invdet;
40 | result(2,0) = (A(0,1)*A(1,2)-A(0,2)*A(1,1))*invdet;
41 | result(0,1) = -(A(1,0)*A(2,2)-A(1,2)*A(2,0))*invdet;
42 | result(1,1) = (A(0,0)*A(2,2)-A(0,2)*A(2,0))*invdet;
43 | result(2,1) = -(A(0,0)*A(1,2)-A(1,0)*A(0,2))*invdet;
44 | result(0,2) = (A(1,0)*A(2,1)-A(2,0)*A(1,1))*invdet;
45 | result(1,2) = -(A(0,0)*A(2,1)-A(2,0)*A(0,1))*invdet;
46 | result(2,2) = (A(0,0)*A(1,1)-A(1,0)*A(0,1))*invdet;
47 | result.transposeInPlace();
48 | }
49 |
50 |
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/shared/include/find_min_vertices.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void find_min_vertices(std::vector &indices, Eigen::Ref V, double tol = 1e-3);
--------------------------------------------------------------------------------
/shared/include/init_state.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | void init_state(Eigen::VectorXd &q, Eigen::VectorXd &qdot, Eigen::Ref V);
--------------------------------------------------------------------------------
/shared/include/read_tetgen.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | void read_tetgen(Eigen::MatrixXd &V, Eigen::MatrixXi &F, const std::string nodeFile, const std::string eleFile);
--------------------------------------------------------------------------------
/shared/include/visualization.h:
--------------------------------------------------------------------------------
1 | #ifndef VISUALIZATION_H
2 | #define VISUALIZATION_H
3 |
4 | #define IMGUI_DEFINE_MATH_OPERATORS
5 |
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | //stl
16 | #include
17 | #include
18 | #include
19 |
20 | //Eigen
21 | #include
22 |
23 | namespace Visualize {
24 |
25 | //custom phase space plot
26 | bool plot_phase_space(const char *label, ImVec2 q_bounds, ImVec2 q_dot_bounds, const Eigen::VectorXd &q, const Eigen::VectorXd &q_dot);
27 |
28 | void add_energy(float t, float T, float V);
29 | bool plot_energy(const char *label, unsigned int type, ImVec2 T_bounds, ImVec2 V_bounds, ImU32 plot_col);
30 |
31 | void setup(const Eigen::VectorXd &q, const Eigen::VectorXd &qdot, bool ps_plot = false);
32 |
33 | void add_object_to_scene(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::MatrixXd &V_skin,
34 | const Eigen::MatrixXi &F_skin, const Eigen::SparseMatrixd &N, Eigen::RowVector3d color);
35 |
36 | //animate geometry using physics simulation
37 | void rigid_transform_1d(unsigned int id, double x);
38 |
39 | void scale_x(unsigned int id, double x);
40 |
41 | void update_vertex_positions(unsigned int id, Eigen::Ref pos);
42 |
43 | void set_picking_tolerance(double);
44 |
45 | //UI methods
46 | bool mouse_down(igl::opengl::glfw::Viewer &viewer, int x, int y);
47 |
48 | bool mouse_up(igl::opengl::glfw::Viewer &viewer, int x, int y);
49 |
50 | bool mouse_move(igl::opengl::glfw::Viewer &viewer, int x, int y);
51 |
52 | igl::opengl::glfw::Viewer & viewer();
53 |
54 | igl::opengl::glfw::imgui::ImGuiMenu & viewer_menu();
55 |
56 | const Eigen::Vector3d & mouse_world();
57 |
58 | const Eigen::Vector3d & mouse_drag_world();
59 |
60 |
61 | const std::vector & picked_vertices();
62 |
63 | bool is_mouse_dragging();
64 |
65 | void toggle_skinning(bool skinning);
66 | }
67 |
68 |
69 | #endif
--------------------------------------------------------------------------------
/shared/src/find_min_vertices.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void find_min_vertices(std::vector &indices, Eigen::Ref V, double tol) {
5 |
6 | double min_vertex = V(0,1);
7 |
8 | for(unsigned int vi=0; vi
2 |
3 | //void init_state(Eigen::Ref q, Eigen::Ref qdot, Eigen::Ref V)
4 | void init_state(Eigen::VectorXd &q, Eigen::VectorXd &qdot, Eigen::Ref V) {
5 |
6 | q.resize(V.rows()*V.cols());
7 | qdot.resize(V.rows()*V.cols());
8 |
9 | Eigen::MatrixXd Vt = V.transpose();
10 | q = Eigen::Map(Vt.data(), Vt.rows()*Vt.cols());
11 | qdot.setZero();
12 | }
--------------------------------------------------------------------------------
/shared/src/read_tetgen.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | //Written by Desai Chen for SIMIT
4 | int openIfstream(std::ifstream &in, std::string filename)
5 | {
6 | in.open(filename);
7 | if(!in.good()){
8 | std::cout<<"Cannot read "<>intVal;
32 |
33 | V.resize(intVal,3); //resize vertex array
34 | std::string line;
35 | unsigned int cnt = 0;
36 | //discard rest of the first line.
37 | getline(nodeIn,line);
38 | while(1) {
39 | getline(nodeIn,line);
40 | if(nodeIn.eof()) {
41 | break;
42 | }
43 | //skip empty lines
44 | if(line.size()<3) {
45 | continue;
46 | }
47 | //skip comments
48 | if(line.at(0)=='#') {
49 | continue;
50 | }
51 | std::stringstream ss(line);
52 |
53 | ss>>intVal;
54 | for(int ii = 0;ii<3;ii++){
55 | ss>>V(cnt,ii);
56 | }
57 | cnt ++ ;
58 | if(cnt>=V.rows()){
59 | break;
60 | }
61 | }
62 |
63 | //load elements
64 | eleIn>>intVal;
65 | F.resize(intVal, 4); //resize face list
66 |
67 | int nV=0;
68 | eleIn>>nV;
69 | cnt = 0;
70 | getline(eleIn,line);
71 | while(1) {
72 | getline(eleIn,line);
73 | if(eleIn.eof()) {
74 | break;
75 | }
76 | if(line.size()<3) {
77 | continue;
78 | }
79 | if(line.at(0)=='#') {
80 | continue;
81 | }
82 | std::stringstream ss(line);
83 | ss>>intVal;
84 |
85 | //e[cnt].resize(nV);
86 | for(int ii = 0;ii>F(cnt,ii);
88 | }
89 |
90 | cnt ++ ;
91 | if(cnt>=F.rows()){
92 | break;
93 | }
94 | }
95 | return 0;
96 | }
97 |
98 | //Lions share of code borrowed from Desai Chen for SIMIT
99 | void read_tetgen(Eigen::MatrixXd &V, Eigen::MatrixXi &F, const std::string nodeFile, const std::string eleFile) {
100 |
101 | std::cout<<"Reading tetrahedral mesh from "<
2 | #include
3 | #include
4 | void T_linear_tetrahedron(double &T, Eigen::Ref qdot, Eigen::Ref element, double density, double volume) {
5 |
6 |
7 |
8 | }
--------------------------------------------------------------------------------
/src/V_linear_tetrahedron.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | void V_linear_tetrahedron(double &energy, Eigen::Ref q,
8 | Eigen::Ref V, Eigen::Ref element, double volume,
9 | double C, double D) {
10 |
11 | auto neohookean_linear_tet = [&](double &e, Eigen::Refq, Eigen::Ref element, Eigen::Ref X) {
12 |
13 |
14 | };
15 |
16 | quadrature_single_point(energy, q, element, volume, neohookean_linear_tet);
17 |
18 | }
--------------------------------------------------------------------------------
/src/V_spring_particle_particle.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | //the potential energy of a spring with 3D end points q0 and qd and undeformed length l0
4 | void V_spring_particle_particle(double &V, Eigen ::Ref q0, Eigen::Ref q1, double l0, double stiffness) {
5 |
6 |
7 |
8 | }
--------------------------------------------------------------------------------
/src/assemble_forces.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void assemble_forces(Eigen::VectorXd &f, Eigen::Ref q, Eigen::Ref qdot,
5 | Eigen::Ref V, Eigen::Ref T, Eigen::Ref v0,
6 | double C, double D) {
7 |
8 |
9 |
10 |
11 | };
--------------------------------------------------------------------------------
/src/assemble_stiffness.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void assemble_stiffness(Eigen::SparseMatrixd &K, Eigen::Ref q, Eigen::Ref qdot,
4 | Eigen::Ref V, Eigen::Ref T, Eigen::Ref v0,
5 | double C, double D) {
6 |
7 |
8 | };
9 |
--------------------------------------------------------------------------------
/src/build_skinning_matrix.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | void build_skinning_matrix(Eigen::SparseMatrixd &N, Eigen::Ref V, Eigen::Ref T,
7 | Eigen::Ref V_skin) {
8 |
9 |
10 | }
--------------------------------------------------------------------------------
/src/d2V_linear_tetrahedron_dq2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | void d2V_linear_tetrahedron_dq2(Eigen::Matrix1212d &H, Eigen::Ref q,
7 | Eigen::Ref V, Eigen::Ref element, double volume,
8 | double C, double D) {
9 |
10 | auto neohookean_linear_tet = [&](Eigen::Matrix1212d &dV, Eigen::Refq, Eigen::Ref element, Eigen::Ref X) {
11 |
12 | //Code to compute non-integrated hessian matrix goes here
13 |
14 | };
15 |
16 | //integrate the non-integrated hessian across the tetrahedral element
17 | quadrature_single_point(H, q, element, volume, neohookean_linear_tet);
18 |
19 |
20 | //DO NOT REMOVE THIS CODE This code ensures that the hessian matrix is symmetric postive definite by projecting all
21 | //negative eigenvalues to small, postive values.
22 | Eigen::SelfAdjointEigenSolver es(H);
23 |
24 | Eigen::MatrixXd DiagEval = es.eigenvalues().real().asDiagonal();
25 | Eigen::MatrixXd Evec = es.eigenvectors().real();
26 |
27 | for (int i = 0; i < 12; ++i) {
28 | if (es.eigenvalues()[i]<1e-6) {
29 | DiagEval(i,i) = 1e-3;
30 | }
31 | }
32 |
33 | H = Evec * DiagEval * Evec.transpose();
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/d2psi_neo_hookean_dF2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void d2psi_neo_hookean_dF2(Eigen::Matrix99d &ddw, Eigen::Ref F, double C, double D) {
4 |
5 |
6 | }
--------------------------------------------------------------------------------
/src/dV_linear_tetrahedron_dq.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | void dV_linear_tetrahedron_dq(Eigen::Vector12d &dV, Eigen::Ref q,
9 | Eigen::Ref V, Eigen::Ref element, double volume,
10 | double C, double D) {
11 |
12 | auto neohookean_linear_tet = [&](Eigen::Vector12d &dV, Eigen::Refq, Eigen::Ref element, Eigen::Ref X) {
13 |
14 | };
15 |
16 | quadrature_single_point(dV, q, element, volume, neohookean_linear_tet);
17 |
18 | }
--------------------------------------------------------------------------------
/src/dV_spring_particle_particle_dq.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void dV_spring_particle_particle_dq(Eigen::Ref f, Eigen::Ref q0, Eigen::Ref q1, double l0, double stiffness) {
4 |
5 |
6 |
7 | }
--------------------------------------------------------------------------------
/src/dphi_linear_tetrahedron_dX.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | void dphi_linear_tetrahedron_dX(Eigen::Matrix43d &dphi, Eigen::Ref V, Eigen::Ref element, Eigen::Ref X) {
5 |
6 | }
--------------------------------------------------------------------------------
/src/dpsi_neo_hookean_dF.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void dpsi_neo_hookean_dF(Eigen::Vector9d &dw, Eigen::Ref F, double C, double D) {
4 |
5 |
6 | }
--------------------------------------------------------------------------------
/src/fixed_point_constraints.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | void fixed_point_constraints(Eigen::SparseMatrixd &P, unsigned int q_size, const std::vector indices) {
4 |
5 |
6 |
7 | }
--------------------------------------------------------------------------------
/src/mass_matrix_linear_tetrahedron.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 |
4 | void mass_matrix_linear_tetrahedron(Eigen::Matrix1212d &M, Eigen::Ref qdot, Eigen::Ref element, double density, double volume) {
5 |
6 |
7 | }
--------------------------------------------------------------------------------
/src/mass_matrix_mesh.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void mass_matrix_mesh(Eigen::SparseMatrixd &M, Eigen::Ref qdot, Eigen::Ref