├── .gitignore ├── .gitmodules ├── README.md ├── cpp ├── CMakeLists.txt ├── cmake │ ├── FindLIBIGL.cmake │ ├── FindMatlab.cmake │ ├── FindPackageHandleStandardArgs.cmake │ ├── FindPackageMessage.cmake │ └── vem.cmake ├── include │ ├── BartelsTypes.h │ ├── EigenTypes.h │ ├── d2psi_neohookean_dF2.h │ ├── dpsi_neohookean_dF.h │ ├── flatten.h │ ├── flatten_multiply.h │ ├── linesearch_backtracking_bisection.h │ ├── optimization_gradient_based.h │ ├── parse_matlab_cells.h │ ├── psi_neohookean_F.h │ ├── vem3d_neohookean_dq2.h │ ├── vem3d_neohookean_q.h │ ├── vem3dmesh_neohookean_dq.h │ ├── vem3dmesh_neohookean_dq2.h │ ├── vem3dmesh_neohookean_q.h │ ├── vem3dmesh_polynomial_coefficients.h │ ├── vem3dmesh_simulate_one_step.h │ ├── vem_error_matrix.h │ ├── vem_ext_force.h │ └── vem_mass_matrix.h └── src │ ├── d2psi_neohookean_dF2.cpp │ ├── dpsi_neohookean_dF.cpp │ ├── flatten_multiply.cpp │ ├── linesearch_backtracking_bisection.cpp │ ├── optimization_gradient_based.cpp │ ├── psi_neohookean_F.cpp │ ├── vem3d_neohookean_dq2.cpp │ ├── vem3dmesh_neohookean_dq.cpp │ ├── vem3dmesh_neohookean_dq2.cpp │ ├── vem3dmesh_neohookean_q.cpp │ ├── vem3dmesh_polynomial_coefficients.cpp │ ├── vem3dmesh_simulate_one_step.cpp │ ├── vem_error_matrix.cpp │ ├── vem_ext_force.cpp │ └── vem_mass_matrix.cpp ├── examples ├── README.md ├── beam_twist.m ├── grumpy.m ├── linear_lamppost.m ├── linear_mug.m ├── linear_mug_implicit.m ├── linear_rocket.m ├── linear_rocket_with_collision.m ├── linear_rocket_with_nose.m ├── linear_rounded_cube.m ├── linear_subD_puft_body.m ├── linear_subD_rocket.m ├── linear_subD_torus.m ├── linear_trimmed_cylinder.m ├── linear_trimmed_cylinder_with_collision.m ├── linear_trimmed_mug.m ├── linear_trimmed_mug_with_collision.m ├── linear_trimmed_wrench.m ├── linear_trimmed_wrench_with_collision.m ├── octopus.m ├── quadratic_beam.m ├── quadratic_castle_cut_with_collision.m ├── quadratic_castle_with_collision.m ├── quadratic_chicken_with_collision.m ├── quadratic_puft_with_collision.m ├── quadratic_rigid_mug_with_collision.m ├── quadratic_rocket_soft_with_collision.m ├── quadratic_rounded_cube.m ├── quadratic_trimmed_mug_with_collision.m ├── starship_collision.m ├── tire_multi_material.m └── vem_sim_2d.m ├── figures ├── deflection_test.m ├── deflection_test_step.m ├── patch_test_2d.m ├── plot_distance_weight.m ├── raycasting_integrate_volume.m ├── render_puft_distance_weight.m ├── scalability_test.m ├── scalability_test_step.m ├── slice_distance_weight.m └── test_slice_tets.m ├── matlab ├── .gitignore ├── CMakeLists.txt ├── basis_size.m ├── blending_weights_2d.m ├── build_weight_matrix.m ├── cantileaver_sim.m ├── compute_shape_matrices.m ├── cutoff_heuristic.m ├── deprecated │ ├── cube_anim_example.m │ ├── experiments │ │ ├── fitting_girrafe.m │ │ ├── mincut.m │ │ ├── test_cutoff_heuristic.m │ │ ├── test_flow.m │ │ ├── test_hcs.m │ │ ├── test_normals.m │ │ ├── test_nurbs_cube_animation.m │ │ ├── test_nurbs_quadrature.m │ │ ├── test_raycast_mug.m │ │ ├── test_trimmed_nurbs.m │ │ ├── test_trimmed_nurbs_2.m │ │ ├── test_weight_grad.m │ │ ├── vem_2d_test_matching.m │ │ ├── vem_fitting_test.m │ │ ├── vem_fitting_test2.m │ │ ├── vem_fitting_test_beam.m │ │ ├── vem_fitting_test_beam_to_fem.m │ │ ├── vem_fitting_test_beam_to_fem2.m │ │ └── vem_sim_2d_test_lowrank.m │ ├── vem3dmesh_neohookean_dq_matlab.m │ ├── vem_error_matrix_matlab.m │ ├── vem_mass_matrix_matlab.m │ ├── vem_sim_cube_anim.m │ ├── vem_sim_gumby.m │ ├── vem_sim_lamppost.m │ ├── vem_sim_tire.m │ ├── vem_simulate_nurbs_constraint.m │ ├── vem_simulate_nurbs_fmincon_debug.m │ ├── vem_simulate_nurbs_implicit.m │ ├── vem_simulate_nurbs_with_collision.m │ ├── vem_simulate_nurbs_with_collision_debug.m │ ├── vem_simulate_nurbs_with_collision_old.m │ └── write_obj_per_part.m ├── distance_weights.m ├── generate_com.m ├── mex │ ├── ray_mesh_intersections.cpp │ ├── ray_mesh_intersections.m │ ├── vem3dmesh_neohookean_dq.cpp │ ├── vem3dmesh_neohookean_dq.m │ ├── vem3dmesh_neohookean_dq2.cpp │ ├── vem3dmesh_neohookean_dq2.m │ ├── vem3dmesh_neohookean_q.cpp │ ├── vem3dmesh_neohookean_q.m │ ├── vem3dmesh_polynomial_coefficients.cpp │ ├── vem3dmesh_simulate_one_step.cpp │ ├── vem3dmesh_simulate_one_step.m │ ├── vem_error_matrix.cpp │ ├── vem_error_matrix.m │ ├── vem_ext_force.cpp │ ├── vem_ext_force.m │ ├── vem_mass_matrix.cpp │ └── vem_mass_matrix.m ├── monomial_basis.m ├── monomial_basis_grad.m ├── nurbs_utils │ ├── IGES Toolbox │ │ ├── IGESfiles │ │ │ ├── example.igs │ │ │ ├── example2.igs │ │ │ ├── piece.igs │ │ │ └── srfOfRev.igs │ │ ├── LScrvApp.c │ │ ├── LScrvApp.mexw64 │ │ ├── closestNrbLinePointIGES.c │ │ ├── closestNrbLinePointIGES.mexw64 │ │ ├── createDVGtree.c │ │ ├── createDVGtree.mexw64 │ │ ├── crvPntsSrfNURBS.c │ │ ├── crvPntsSrfNURBS.mexw64 │ │ ├── example.m │ │ ├── example2.m │ │ ├── exampleAll.m │ │ ├── exampleICP.m │ │ ├── examplePerspectiveProjection.m │ │ ├── exampleProjection.m │ │ ├── exampleProjection2.m │ │ ├── exampleProjection2b.m │ │ ├── exampleSphericalProjection.m │ │ ├── findEntityIGES.m │ │ ├── getDVGtree.m │ │ ├── getSurfaceDistributedPoints.m │ │ ├── icpDVGpnt2plnLS.c │ │ ├── icpDVGpnt2plnLS.mexw64 │ │ ├── icpDVGpnt2plnTu.c │ │ ├── icpDVGpnt2plnTu.mexw64 │ │ ├── icpDVGpnt2pntLS.c │ │ ├── icpDVGpnt2pntLS.mexw64 │ │ ├── icpDVGpnt2pntTu.c │ │ ├── icpDVGpnt2pntTu.mexw64 │ │ ├── icpSrfLinRep.m │ │ ├── iges2matlab.m │ │ ├── igesToolBoxGUI.fig │ │ ├── igesToolBoxGUI.m │ │ ├── linAppSrfIGES.m │ │ ├── makeIGESmex.m │ │ ├── mexSourceFiles │ │ │ ├── BasisFuns.c │ │ │ ├── BspEval.c │ │ │ ├── BspEval2.c │ │ │ ├── FindSpan.c │ │ │ ├── FindSpanIncSeq.c │ │ │ ├── LScurveApp.c │ │ │ ├── NURBScurveEval.c │ │ │ ├── NURBSsurfaceEval.c │ │ │ ├── NURBSsurfaceRegularEval.c │ │ │ ├── constrainingFcn.c │ │ │ ├── findBoundary.c │ │ │ ├── genzCGM.c │ │ │ ├── linalgR6x6.c │ │ │ ├── linesearchPenalty.c │ │ │ ├── linesearchRcprBarrier.c │ │ │ ├── nrbD1D2eval.c │ │ │ ├── nrbD1D2eval2.c │ │ │ ├── offsetNURBSsrf.c │ │ │ ├── rotMatrixCCOV.c │ │ │ ├── rotmatCmptns.c │ │ │ ├── trfExpPenalty.c │ │ │ ├── trfRcprclBarrier.c │ │ │ ├── trustRegionFuncExpPenalty.c │ │ │ └── trustRegionFuncRcprclBarrier.c │ │ ├── nrbDerivativesIGES.m │ │ ├── nrbSrfRegularEvalIGES.c │ │ ├── nrbSrfRegularEvalIGES.mexw64 │ │ ├── nrbevalIGES.c │ │ ├── nrbevalIGES.mexw64 │ │ ├── offsetIGES.m │ │ ├── offsetNURBSsurface.c │ │ ├── plotAxis.m │ │ ├── plotIGES.m │ │ ├── plotIGESentity.m │ │ ├── plotNURBS.m │ │ ├── plotSTL.m │ │ ├── projIGES.m │ │ ├── projpartIGES.m │ │ ├── projpartPerspectiveIGES.m │ │ ├── projpartSphericalIGES.m │ │ ├── readme.txt │ │ ├── resources │ │ │ ├── addons_core.xml │ │ │ ├── matlab_path_entries.xml │ │ │ └── screenshot.png │ │ ├── retSrfCrvPnt.m │ │ ├── srfRepInProjection.m │ │ ├── stl2matlab.m │ │ ├── transformIGES.m │ │ ├── transformSTL.m │ │ └── xyz2matlab.m │ ├── README.md │ ├── dersbasisfuns.m │ ├── iges2matlab.m │ ├── igesout.m │ ├── lglnodes.m │ ├── lgwt.m │ ├── nurbs_assemble_coords.m │ ├── nurbs_blending_weights.m │ ├── nurbs_coords.m │ ├── nurbs_from_iges.m │ ├── nurbs_grad.m │ ├── nurbs_normals.m │ ├── nurbs_plot.m │ ├── nurbs_sample.m │ ├── nurbs_toolbox │ │ ├── Contents.m │ │ ├── basisfun.m │ │ ├── bspdegelev.m │ │ ├── bspderiv.m │ │ ├── bspeval.m │ │ ├── bspkntins.m │ │ ├── deg2rad.m │ │ ├── demo4surf.m │ │ ├── democirc.m │ │ ├── democoons.m │ │ ├── democurve.m │ │ ├── democylind.m │ │ ├── demodegelev.m │ │ ├── demodercrv.m │ │ ├── demodersrf.m │ │ ├── demoellip.m │ │ ├── demogeom.m │ │ ├── demohelix.m │ │ ├── demokntins.m │ │ ├── demoline.m │ │ ├── demorect.m │ │ ├── demorevolve.m │ │ ├── demoruled.m │ │ ├── demos.m │ │ ├── demotorus.m │ │ ├── findspan.m │ │ ├── nrb4surf.m │ │ ├── nrbcirc.m │ │ ├── nrbcoons.m │ │ ├── nrbcylind.m │ │ ├── nrbdegelev.m │ │ ├── nrbderiv.m │ │ ├── nrbdeval.m │ │ ├── nrbeval.m │ │ ├── nrbextrude.m │ │ ├── nrbkntins.m │ │ ├── nrbline.m │ │ ├── nrbmak.m │ │ ├── nrbplot.m │ │ ├── nrbrect.m │ │ ├── nrbreverse.m │ │ ├── nrbrevolve.m │ │ ├── nrbruled.m │ │ ├── nrbtestcrv.m │ │ ├── nrbtestsrf.m │ │ ├── nrbtform.m │ │ ├── nrbtransp.m │ │ ├── rad2deg.m │ │ ├── vecangle.m │ │ ├── veccross.m │ │ ├── vecdot.m │ │ ├── vecmag.m │ │ ├── vecmag2.m │ │ ├── vecnormalize.m │ │ ├── vecrotx.m │ │ ├── vecroty.m │ │ ├── vecrotz.m │ │ ├── vecscale.m │ │ └── vectrans.m │ ├── nurbs_triangulate.m │ ├── nurbs_write_iges.m │ ├── nurbs_write_obj.m │ ├── sample_spline.m │ └── subd_assemble_coords.m ├── pointTriangleDistance │ ├── license.txt │ └── pointTriangleDistance.m ├── raycast_quadrature.m ├── simulate_twist.m ├── symbolic │ ├── SNH_dF.m │ ├── SNH_dF2.m │ ├── SNH_tet_dF.m │ ├── SNH_tet_dF2.m │ ├── neohookean_dF.m │ ├── neohookean_dF2.m │ ├── neohookean_func.m │ ├── neohookean_tet_dF.m │ ├── neohookean_tet_dF2.m │ ├── vem_A_func.m │ ├── vem_dF_func.m │ └── vem_mass_matrix_func.m ├── vem3dmesh_energy_matlab.m ├── vem_dF_dc.m ├── vem_dx_dc.m ├── vem_preprocess.m ├── vem_simulate_nurbs.m ├── vem_simulate_nurbs_fmincon.m ├── vem_simulate_nurbs_newtons.m ├── vem_simulate_nurbs_with_collision.m └── vem_simulate_subd.m ├── models ├── README.md ├── T.iges ├── beams │ ├── beam.iges │ ├── beam_cmp1.iges │ ├── beam_cmp2.iges │ ├── beam_cmp3.iges │ ├── beam_cmp3_b.iges │ ├── beam_cmp4.iges │ ├── cube.iges │ ├── cubes │ │ ├── cube1.igs │ │ ├── cube10.iges │ │ ├── cube100.iges │ │ ├── cube15.iges │ │ ├── cube2.iges │ │ ├── cube20.iges │ │ ├── cube25.iges │ │ ├── cube3.iges │ │ ├── cube30.iges │ │ ├── cube4.iges │ │ ├── cube40.iges │ │ ├── cube5.iges │ │ ├── cube50.iges │ │ └── cube75.iges │ ├── perf │ │ ├── b1.igs │ │ ├── b1.igsbak │ │ ├── b10.igs │ │ ├── b2.igs │ │ ├── b2.igsbak │ │ ├── b3.igs │ │ ├── b4.igs │ │ ├── b5.igs │ │ ├── b6.igs │ │ └── b7.igs │ └── tetmeshes │ │ ├── vem_beam_tet0.mesh │ │ ├── vem_beam_tet1.mesh │ │ ├── vem_beam_tet2.mesh │ │ └── vem_beam_tet3.mesh ├── castle │ ├── castle.iges │ ├── castle_cut_nowall.iges │ ├── castle_simple.iges │ ├── castle_simple_smaller_flip.iges │ ├── castle_simple_smaller_flip_cut.iges │ └── castle_super_simple.iges ├── chicken │ ├── chicken.iges │ ├── chicken_from_autodesk_gallery.iges │ ├── chicken_little.iges │ ├── chicken_simple_closed.iges │ └── chicken_simple_closed_small.iges ├── cylinder.iges ├── grumpy.iges ├── lamppost.iges ├── mugs │ ├── mug.iges │ ├── mug_complex.iges │ ├── mug_trimmed.iges │ ├── mug_trimmed_complex.iges │ ├── mug_trimmed_complex_bad.iges │ └── mugs_rhino │ │ ├── mug_floating_handle.3dm │ │ ├── mug_floating_handle.igs │ │ ├── mug_intersect_1.3dm │ │ ├── mug_intersect_1.igs │ │ ├── mug_intersect_2.3dm │ │ ├── mug_intersect_2.igs │ │ ├── mug_solid.3dm │ │ └── mug_solid.igs ├── obj │ ├── bowl.obj │ ├── cube.obj │ ├── plane.obj │ ├── sphere.obj │ └── vem_beam.obj ├── puft │ ├── puft.iges │ ├── puft_full_simple.iges │ ├── puft_full_simpler.iges │ ├── puft_no_collar.iges │ ├── puft_simple.iges │ ├── puft_subD.iges │ └── puft_without_head_subd.iges ├── rocket │ ├── rocket.iges │ ├── rocket_small.iges │ └── rocket_with_nose.iges ├── rounded_cube.iges ├── squid.iges ├── starship │ ├── starship.igs │ ├── starship_fall.igs │ ├── starship_fall_collide.igs │ ├── starship_fall_simpler.igs │ └── surface.obj ├── tire.iges ├── trident.iges └── wrench.iges ├── output ├── gifs │ ├── cube.gif │ ├── gifsicle.exe │ └── gifsicle_remove2.sh └── img │ └── .gitignore └── paper ├── .gitignore ├── castle.png ├── figures ├── astronauts.pdf ├── beam_twist.pdf ├── beams.pdf ├── chicken.pdf ├── deflection.pdf ├── deflection_full.pdf ├── deprecated │ ├── distance_weight_old.pdf │ ├── distance_weighting.png │ ├── error_energy.png │ ├── nurbs_surface.png │ ├── plot_distance_weight.pdf │ └── raycasting_quadrature.png ├── distance_weight_puft.pdf ├── export_iges.pdf ├── independent_movement.pdf ├── mug_overlap.pdf ├── nurbs_patch.pdf ├── octopus.pdf ├── origin_network.pdf ├── patch_test.pdf ├── plot_distance_weight_both.pdf ├── projection_operator_solve.pdf ├── raycasting_quadrature.pdf ├── representative.jpg ├── representative.png ├── rocket.pdf ├── scalability.pdf ├── scalability_old.pdf ├── starship.pdf ├── starship_short.pdf ├── stiffness_sparsity.pdf ├── teaser_castle.pdf └── tire.pdf ├── main.tex ├── references.bib └── sections ├── conclusion.tex ├── intro.tex ├── methods.tex ├── methods_ty.tex ├── pre.tex ├── related.tex └── results.tex /.gitignore: -------------------------------------------------------------------------------- 1 | *.gif 2 | *.swp 3 | *.mat 4 | *.asv 5 | extern/ 6 | 7 | *.poly 8 | *.neigh 9 | *.m~ 10 | *.mexmaci64 11 | 12 | *.fdb_latexmk 13 | *.fls 14 | *.blend 15 | 16 | output/* 17 | figures/*.pdf 18 | blender/* 19 | matlab/libigl/ 20 | *.igesbak 21 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "extern/libigl"] 2 | path = extern/libigl 3 | url = https://github.com/libigl/libigl.git -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Shape Matching Element Method 2 | 3 | vem_sim_2d is a minimal example that *should* only depend on gptoolbox... So see if that runs! 4 | 5 | [Project Page](https://www.dgp.toronto.edu/projects/shape-matching-element-method/) 6 | 7 | ### External Dependencies ### 8 | 1. [GPToolbox](https://github.com/alecjacobson/gptoolbox) 9 | 2. OpenMP (OPTIONAL) 10 | 11 | ### Included Submodules (Installed Automatically) ### 12 | 1. Libigl https://github.com/libigl/libigl 13 | 2. Eigen >= 3.2 (uses the libigl Eigen install) 14 | 15 | > **To get started:** Clone this repository and all its [submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) dependencies using: 16 | > 17 | > git clone --recursive https://github.com/tytrusty/virtual-element-method.git 18 | 19 | ### MATLAB Setup 20 | To let MATLAB recognize the scripts, we need to add this folder and all the project's subfolders to the MATLAB path. Assuming your installation directory `/usr/local/virtual-element-method/`, then you could issue the following command in the MATLAB command prompt: 21 | 22 | addpath(genpath('/usr/local/virtual-element-method/')) 23 | savepath 24 | 25 | ### C++ MEX Compilation 26 | Costly functions are implemented in C++ and executed from Matlab via the C++ MEX API. Compiling these is **required** for the NURBs simulation example. The following steps may be used to compile the C++ files: 27 | 28 | cd ${SOURCE_DIRECTORY}/matlab 29 | mkdir build 30 | cd build 31 | cmake .. 32 | make all 33 | 34 | -------------------------------------------------------------------------------- /cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | if(${CMAKE_VERSION} VERSION_LESS 3.12) 4 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 5 | endif() 6 | 7 | project(vem VERSION 1.0 LANGUAGES CXX) 8 | 9 | set(CMAKE_CXX_STANDARD 14) 10 | set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) 11 | set(CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR/cmake}" ${CMAKE_PREFIX_PATH}) 12 | 13 | include(${PROJECT_SOURCE_DIR}/cpp/cmake/vem.cmake) 14 | 15 | -------------------------------------------------------------------------------- /cpp/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 | ${LIBIGL_DIR} 13 | ENV LIBIGL_DIR 14 | PATHS 15 | ${CMAKE_SOURCE_DIR}/../.. 16 | ${CMAKE_SOURCE_DIR}/.. 17 | ${CMAKE_SOURCE_DIR} 18 | ${CMAKE_SOURCE_DIR}/libigl 19 | ${CMAKE_SOURCE_DIR}/extern/libigl 20 | ${CMAKE_SOURCE_DIR}/../extern/libigl 21 | ${CMAKE_SOURCE_DIR}/../../libigl 22 | /usr 23 | /usr/local 24 | /usr/local/igl/libigl 25 | PATH_SUFFIXES include 26 | ) 27 | 28 | include(FindPackageHandleStandardArgs) 29 | find_package_handle_standard_args(LIBIGL 30 | "\nlibigl not found --- You can download it using:\n\tgit clone https://github.com/libigl/libigl.git ${CMAKE_SOURCE_DIR}/../libigl" 31 | LIBIGL_INCLUDE_DIR) 32 | mark_as_advanced(LIBIGL_INCLUDE_DIR) 33 | 34 | list(APPEND CMAKE_MODULE_PATH "${LIBIGL_INCLUDE_DIR}/../cmake") 35 | include(libigl) 36 | 37 | -------------------------------------------------------------------------------- /cpp/cmake/FindPackageMessage.cmake: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 | # file Copyright.txt or https://cmake.org/licensing for details. 3 | 4 | #[=======================================================================[.rst: 5 | FindPackageMessage 6 | ------------------ 7 | 8 | .. code-block:: cmake 9 | 10 | find_package_message( "message for user" "find result details") 11 | 12 | This function is intended to be used in FindXXX.cmake modules files. 13 | It will print a message once for each unique find result. This is 14 | useful for telling the user where a package was found. The first 15 | argument specifies the name (XXX) of the package. The second argument 16 | specifies the message to display. The third argument lists details 17 | about the find result so that if they change the message will be 18 | displayed again. The macro also obeys the QUIET argument to the 19 | find_package command. 20 | 21 | Example: 22 | 23 | .. code-block:: cmake 24 | 25 | if(X11_FOUND) 26 | find_package_message(X11 "Found X11: ${X11_X11_LIB}" 27 | "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") 28 | else() 29 | ... 30 | endif() 31 | #]=======================================================================] 32 | 33 | function(find_package_message pkg msg details) 34 | # Avoid printing a message repeatedly for the same find result. 35 | if(NOT ${pkg}_FIND_QUIETLY) 36 | string(REPLACE "\n" "" details "${details}") 37 | set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) 38 | if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") 39 | # The message has not yet been printed. 40 | message(STATUS "${msg}") 41 | 42 | # Save the find details in the cache to avoid printing the same 43 | # message again. 44 | set("${DETAILS_VAR}" "${details}" 45 | CACHE INTERNAL "Details about finding ${pkg}") 46 | endif() 47 | endif() 48 | endfunction() 49 | -------------------------------------------------------------------------------- /cpp/cmake/vem.cmake: -------------------------------------------------------------------------------- 1 | #this file setups up targets 2 | #can be imported into other projects to use vem 3 | 4 | # vem Options 5 | set(vem_ROOT "${CMAKE_CURRENT_LIST_DIR}/..") 6 | set(vem_SOURCE_DIR "${vem_ROOT}") 7 | set(vem_INCLUDE_DIR ${vem_ROOT}/include) 8 | 9 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${vem_SOURCE_DIR}/cmake) 10 | 11 | option(VEM_USE_OPENMP OFF) 12 | if(NOT APPLE) 13 | option(LIBIGL_WITH_EMBREE ON) 14 | else () 15 | option(LIBIGL_WITH_EMBREE "Use Embree" ON) 16 | endif() 17 | 18 | find_package(LIBIGL REQUIRED) 19 | 20 | if(VEM_USE_OPENMP) 21 | find_package(OpenMP REQUIRED) 22 | endif() 23 | 24 | add_library(vem INTERFACE) 25 | 26 | include_directories(${vem_INCLUDE_DIR}) 27 | 28 | target_include_directories(vem INTERFACE ${vem_INCLUDE_DIR}) 29 | target_compile_definitions(vem INTERFACE -DSIM_DATA_DIRECTORY=${vem_ROOT}/models) 30 | target_link_libraries(vem INTERFACE igl::core;igl::embree) 31 | 32 | if(OpenMP_CXX_FOUND) 33 | 34 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 35 | execute_process( 36 | COMMAND brew --prefix libomp 37 | RESULT_VARIABLE BREW_OMP 38 | OUTPUT_VARIABLE BREW_OMP_PREFIX 39 | OUTPUT_STRIP_TRAILING_WHITESPACE 40 | ) 41 | 42 | include_directories(${BREW_OMP_PREFIX}/include) 43 | 44 | target_link_libraries(vem INTERFACE OpenMP::OpenMP_CXX) 45 | target_compile_definitions(vem INTERFACE -DVEM_USE_OPENMP) 46 | 47 | elseif() 48 | include_directories(${OpenMP_CXX_INCLUDE_DIRS}) 49 | 50 | target_link_libraries(vem INTERFACE OpenMP::OpenMP_CXX) 51 | target_compile_definitions(vem INTERFACE -DVEM_USE_OPENMP) 52 | endif() 53 | 54 | endif() -------------------------------------------------------------------------------- /cpp/include/BartelsTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_BARTELS_TYPES 2 | #define SIM_BARTELS_TYPES 3 | 4 | namespace sim { 5 | 6 | enum SolverExitStatus { 7 | CONVERGED, 8 | MAX_ITERATIONS_REACHED 9 | }; 10 | 11 | auto default_optimization_callback = [](auto &x, auto &g, auto &H, SolverExitStatus &searchstatus) {}; 12 | 13 | } 14 | #endif -------------------------------------------------------------------------------- /cpp/include/d2psi_neohookean_dF2.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_D2PSI_NEO_HOOKEAN_DF2_H 2 | #define SIM_D2PSI_NEO_HOOKEAN_DF2_H 3 | 4 | #include 5 | #include 6 | 7 | namespace sim { 8 | 9 | template 10 | void d2psi_neohookean_dF2(Eigen::MatrixBase &ddw, const Eigen::MatrixBase &F, const Eigen::MatrixBase ¶ms); 11 | 12 | } 13 | 14 | #ifndef SIM_STATIC_LIBRARY 15 | # include<../src/d2psi_neohookean_dF2.cpp> 16 | #endif 17 | 18 | #endif -------------------------------------------------------------------------------- /cpp/include/dpsi_neohookean_dF.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_DPSI_NEO_HOOKEAN_DF_H 2 | #define SIM_DPSI_NEO_HOOKEAN_DF_H 3 | 4 | #include 5 | #include 6 | 7 | namespace sim { 8 | 9 | template 10 | void dpsi_neohookean_dF(Eigen::MatrixBase &dw, const Eigen::MatrixBase &F, const Eigen::MatrixBase ¶ms); 11 | 12 | } 13 | 14 | #ifndef SIM_STATIC_LIBRARY 15 | # include<../src/dpsi_neohookean_dF.cpp> 16 | #endif 17 | 18 | #endif -------------------------------------------------------------------------------- /cpp/include/linesearch_backtracking_bisection.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_LINESEARCH_BACKTRACKING_BISECTION_H 2 | #define SIM_LINESEARCH_BACKTRACKING_BISECTION_H 3 | 4 | #include 5 | #include 6 | 7 | //Implementation of simple backtracking linesearch using bisection 8 | //Input: 9 | // x - initial point 10 | // d - search direction 11 | // f - the optimization objective function f(x) 12 | // g - gradient of function at initial point 13 | // max_iterations - max line search iterations 14 | // alpha - max proportion of line search 15 | // c- sufficient decrease parameter 16 | // p - bisection ratio 17 | // Callback - callback that executes each line search iteration 18 | //Output: 19 | // x - contains point to which linesearch converged, or final accepted point before termination 20 | // SolverExitStatus - exit code for solver 21 | namespace sim { 22 | 23 | template 24 | SolverExitStatus linesearch_backtracking_bisection( 25 | Eigen::MatrixBase &x, 26 | Eigen::MatrixBase &d, 27 | const Objective &f, 28 | Eigen::MatrixBase &g, 29 | unsigned int max_iterations, 30 | Scalar alpha, 31 | Scalar c, 32 | Scalar p, 33 | const Callback func = default_linesearch_callback); 34 | } 35 | 36 | #ifndef SIM_STATIC_LIBRARY 37 | # include <../src/linesearch_backtracking_bisection.cpp> 38 | #endif 39 | 40 | #endif -------------------------------------------------------------------------------- /cpp/include/parse_matlab_cells.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_PARSE_MATLAB_CELLS 2 | #define SIM_PARSE_MATLAB_CELLS 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace sim { 10 | 11 | // Parse cells composed of dense matrices 12 | template 13 | void parse_cell(const mxArray *prhs[], int index, EigenMatrixList& V) { 14 | const mxArray *cell = prhs[index]; 15 | const mwSize *dims = mxGetDimensions(prhs[index]); 16 | const mxArray *cellElement; 17 | mwIndex jcell; 18 | for (jcell = 0; jcell < dims[0]; jcell++) { 19 | cellElement = mxGetCell(cell, jcell); 20 | Eigen::MatrixXx element; 21 | igl::matlab::parse_rhs_double(&cellElement, element); 22 | 23 | V.emplace_back(element); 24 | } 25 | } 26 | 27 | // Parse cells composed of dense vectors 28 | template 29 | void parse_cell_index(const mxArray *prhs[], int index, EigenVectorList& V) { 30 | const mxArray *cell = prhs[index]; 31 | const mwSize *dims = mxGetDimensions(prhs[index]); 32 | const mxArray *cellElement; 33 | mwIndex jcell; 34 | for (jcell = 0; jcell < dims[0]; jcell++) { 35 | cellElement = mxGetCell(cell, jcell); 36 | Eigen::VectorXx element; 37 | igl::matlab::parse_rhs_index(&cellElement, element); 38 | V.emplace_back(element); 39 | } 40 | } 41 | 42 | // Parse cells composed of sparse matrices 43 | template 44 | void parse_cell_sparse(const mxArray *prhs[], int index, EigenSparseMatrixList& V) { 45 | const mxArray *cell = prhs[index]; 46 | const mwSize *dims = mxGetDimensions(prhs[index]); 47 | const mxArray *cellElement; 48 | mwIndex jcell; 49 | for (jcell = 0; jcell < dims[0]; jcell++) { 50 | cellElement = mxGetCell(cell, jcell); 51 | Eigen::SparseMatrix element; 52 | igl::matlab::parse_rhs(&cellElement, element); 53 | V.emplace_back(element); 54 | } 55 | } 56 | 57 | } 58 | 59 | #endif // SIM_PARSE_MATLAB_CELLS -------------------------------------------------------------------------------- /cpp/include/psi_neohookean_F.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_PSI_NEO_HOOKEAN_F_H 2 | #define SIM_PSI_NEO_HOOKEAN_F_H 3 | 4 | #include 5 | #include 6 | 7 | namespace sim { 8 | 9 | template 10 | typename DefoType::Scalar psi_neohookean_F(const Eigen::MatrixBase &F, const Eigen::MatrixBase ¶ms); 11 | 12 | } 13 | 14 | #ifndef SIM_STATIC_LIBRARY 15 | # include<../src/psi_neohookean_F.cpp> 16 | #endif 17 | 18 | #endif -------------------------------------------------------------------------------- /cpp/include/vem3d_neohookean_dq2.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_VEM3D_NEOHOOKEAN_DQ2_H 2 | #define SIM_VEM3D_NEOHOOKEAN_DQ2_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace sim { 10 | 11 | template 12 | void vem3d_neohookean_dq2(Eigen::MatrixXx &g, 13 | const Eigen::MatrixXx &A, 14 | const Eigen::MatrixXx &dF_dq, 15 | const Eigen::MatrixXx &dM_dq, 16 | DerivedVol volume, 17 | const Eigen::MatrixXx ¶ms, 18 | int k, int n, 19 | const Eigen::MatrixXd &dF_dq_sp); 20 | 21 | } 22 | 23 | #ifndef SIM_STATIC_LIBRARY 24 | # include <../src/vem3d_neohookean_dq2.cpp> 25 | #endif 26 | 27 | #endif -------------------------------------------------------------------------------- /cpp/include/vem3d_neohookean_q.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_VEM3D_NEOHOOKEAN_Q_H 2 | #define SIM_VEM3D_NEOHOOKEAN_Q_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace sim { 10 | 11 | template 12 | void vem3d_neohookean_q(Eigen::MatrixXx &g, 13 | const Eigen::MatrixXx &A, 14 | const Eigen::MatrixXx &dF_dq, 15 | const Eigen::MatrixXx &dM_dq, 16 | DerivedVol volume, 17 | const Eigen::MatrixXx ¶ms, 18 | int k, int n, 19 | const Eigen::MatrixXd &dF_dq_sp); 20 | 21 | } 22 | 23 | #ifndef SIM_STATIC_LIBRARY 24 | # include <../src/vem3d_neohookean_q.cpp> 25 | #endif 26 | 27 | #endif -------------------------------------------------------------------------------- /cpp/include/vem3dmesh_neohookean_dq.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_VEM3DMESH_NEOHOOKEAN_DQ_H 2 | #define SIM_VEM3DMESH_NEOHOOKEAN_DQ_H 3 | 4 | #include 5 | #include 6 | 7 | #include // TODO remove and replace with neohookean dq2 8 | 9 | 10 | namespace sim { 11 | 12 | template 13 | void vem3dmesh_neohookean_dq(Eigen::VectorXx &g, 14 | const Eigen::MatrixXx &x, 15 | const Eigen::VectorXx &c, 16 | const Eigen::VectorXx &volume, 17 | const Eigen::MatrixXx ¶ms, 18 | const std::vector > & dF_dc, 19 | const std::vector, Eigen::aligned_allocator> > & dF_dc_S, 20 | const Eigen::MatrixXd &ME, 21 | const Eigen::SparseMatrix &L, 22 | int k, int n, int d, int x0_coms_size, double k_stability); 23 | } 24 | 25 | #ifndef SIM_STATIC_LIBRARY 26 | # include <../src/vem3dmesh_neohookean_dq.cpp> 27 | #endif 28 | 29 | #endif -------------------------------------------------------------------------------- /cpp/include/vem3dmesh_neohookean_dq2.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_VEM3DMESH_NEOHOOKEAN_DQ2_H 2 | #define SIM_VEM3DMESH_NEOHOOKEAN_DQ2_H 3 | 4 | #include 5 | #include 6 | 7 | //#include 8 | #include // TODO remove and replace with neohookean dq2 9 | 10 | namespace sim { 11 | 12 | template 13 | void vem3dmesh_neohookean_dq2(Eigen::MatrixXx &g, 14 | const Eigen::VectorXx &c, 15 | const Eigen::VectorXx &volume, 16 | const Eigen::MatrixXx ¶ms, 17 | const std::vector > & dF_dc, 18 | const std::vector > & W_I, 19 | int k, int n, int m); 20 | } 21 | 22 | #ifndef SIM_STATIC_LIBRARY 23 | # include <../src/vem3dmesh_neohookean_dq2.cpp> 24 | #endif 25 | 26 | #endif -------------------------------------------------------------------------------- /cpp/include/vem3dmesh_neohookean_q.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_VEM3DMESH_NEOHOOKEAN_Q_H 2 | #define SIM_VEM3DMESH_NEOHOOKEAN_Q_H 3 | 4 | #include 5 | #include 6 | 7 | #include // TODO remove and replace with neohookean dq2 8 | 9 | 10 | namespace sim { 11 | 12 | template 13 | double vem3dmesh_neohookean_q(const Eigen::VectorXx &c, 14 | const Eigen::VectorXx &volume, 15 | const Eigen::MatrixXx ¶ms, 16 | const std::vector > & dF_dc, 17 | const std::vector, Eigen::aligned_allocator> > & dF_dc_S, 18 | int d); 19 | } 20 | 21 | #ifndef SIM_STATIC_LIBRARY 22 | # include <../src/vem3dmesh_neohookean_q.cpp> 23 | #endif 24 | 25 | #endif -------------------------------------------------------------------------------- /cpp/include/vem3dmesh_polynomial_coefficients.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_VEM3DMESH_POLYNOMIAL_COEFFICIENTS_H 2 | #define SIM_VEM3DMESH_POLYNOMIAL_COEFFICIENTS_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace sim { 9 | 10 | template 11 | void vem3dmesh_polynomial_coefficients(Eigen::VectorXx &c, 12 | const Eigen::MatrixXx &x, 13 | const Eigen::SparseMatrix &L, 14 | const std::vector > & E); 15 | } 16 | 17 | #ifndef SIM_STATIC_LIBRARY 18 | # include <../src/vem3dmesh_polynomial_coefficients.cpp> 19 | #endif 20 | 21 | #endif -------------------------------------------------------------------------------- /cpp/include/vem3dmesh_simulate_one_step.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_VEM3DMESH_SIMULATE_ONE_STEP_H 2 | #define SIM_VEM3DMESH_SIMULATE_ONE_STEP_H 3 | 4 | #include 5 | #include 6 | 7 | // VEM energy, gradient and hessian 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | // Bartels 14 | #include 15 | 16 | namespace sim { 17 | 18 | template 19 | void vem3dmesh_simulate_one_step(Eigen::VectorXx &qdot_new, 20 | const Eigen::VectorXx &q, 21 | const Eigen::VectorXx &qdot, 22 | const Eigen::VectorXx &f_ext, 23 | const Eigen::MatrixXd &x_fixed, 24 | const Eigen::VectorXx &volume, 25 | const Eigen::MatrixXx ¶ms, 26 | const std::vector > & dF_dc, 27 | const std::vector, Eigen::aligned_allocator> > & dF_dc_S, 28 | const std::vector > & W_I, 29 | const std::vector > & E, 30 | const Eigen::MatrixXd &M, 31 | const Eigen::MatrixXd &ME, 32 | const Eigen::SparseMatrix &L, 33 | const Eigen::SparseMatrix &P, 34 | const Eigen::SparseMatrix &J, 35 | int k, int n, int d, int x0_coms_size, double k_stability, double dt); 36 | } 37 | 38 | #ifndef SIM_STATIC_LIBRARY 39 | # include <../src/vem3dmesh_simulate_one_step.cpp> 40 | #endif 41 | 42 | #endif -------------------------------------------------------------------------------- /cpp/include/vem_error_matrix.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_VEM_ERROR_MATRIX_H 2 | #define SIM_VEM_ERROR_MATRIX_H 3 | 4 | #include 5 | #include 6 | 7 | namespace sim { 8 | 9 | template 10 | void vem_error_matrix(Eigen::MatrixXx &g, 11 | const EigenMatrixList& Y, 12 | const Eigen::SparseMatrix & L, 13 | const EigenVectorList& W_I, 14 | const EigenVectorList& C_I, 15 | int d, int k, int n); 16 | } 17 | 18 | #include <../src/vem_error_matrix.cpp> 19 | 20 | #endif // SIM_VEM_ERROR_MATRIX_H -------------------------------------------------------------------------------- /cpp/include/vem_ext_force.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_VEM_EXT_FORCE_H 2 | #define SIM_VEM_EXT_FORCE_H 3 | 4 | #include 5 | #include 6 | 7 | namespace sim { 8 | 9 | template 10 | void vem_ext_force(Eigen::VectorXx &g, 11 | const Eigen::VectorXx& ext, 12 | const Eigen::VectorXx& mass, 13 | const EigenMatrixList& Y, 14 | const EigenSparseMatrixList& Y_S); 15 | } 16 | 17 | #include <../src/vem_ext_force.cpp> 18 | 19 | #endif // SIM_VEM_EXT_FORCE_H -------------------------------------------------------------------------------- /cpp/include/vem_mass_matrix.h: -------------------------------------------------------------------------------- 1 | #ifndef SIM_VEM_MASS_MATRIX_H 2 | #define SIM_VEM_MASS_MATRIX_H 3 | 4 | #include 5 | #include 6 | 7 | namespace sim { 8 | 9 | template 10 | void vem_mass_matrix(Eigen::MatrixXx &g, 11 | const EigenMatrixList& Y, 12 | const Eigen::SparseMatrix & L, 13 | const Eigen::VectorXx& mass, 14 | const EigenVectorList& W_I, 15 | const EigenVectorList& C_I, 16 | int d, int k, int n); 17 | } 18 | 19 | #include <../src/vem_mass_matrix.cpp> 20 | 21 | #endif // SIM_VEM_MASS_MATRIX_H -------------------------------------------------------------------------------- /cpp/src/flatten_multiply.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/cpp/src/flatten_multiply.cpp -------------------------------------------------------------------------------- /cpp/src/linesearch_backtracking_bisection.cpp: -------------------------------------------------------------------------------- 1 | #ifdef SIM_STATIC_LIBRARY 2 | # include<../include/linesearch_backtracking_bisection.h> 3 | #endif 4 | 5 | template 6 | sim::SolverExitStatus sim::linesearch_backtracking_bisection(Eigen::MatrixBase &x, 7 | Eigen::MatrixBase &d, 8 | const Objective &f, 9 | Eigen::MatrixBase &g, 10 | unsigned int max_iterations, 11 | Scalar alpha, 12 | Scalar c, 13 | Scalar p, 14 | const Callback func) { 15 | 16 | 17 | unsigned int iteration_count = 0; 18 | 19 | Scalar f0 = f(x); 20 | 21 | while((f(x+alpha*d) > f(x) + c*g.transpose()*d) && iteration_count < max_iterations) { 22 | 23 | alpha *= p; 24 | iteration_count++; 25 | func(x); 26 | } 27 | 28 | x += alpha*d; 29 | 30 | return (iteration_count == max_iterations ? SolverExitStatus::MAX_ITERATIONS_REACHED : SolverExitStatus::CONVERGED); 31 | } -------------------------------------------------------------------------------- /cpp/src/optimization_gradient_based.cpp: -------------------------------------------------------------------------------- 1 | #ifdef SIM_STATIC_LIBRARY 2 | # include<../include/optimization_gradient_based.h> 3 | #endif -------------------------------------------------------------------------------- /cpp/src/psi_neohookean_F.cpp: -------------------------------------------------------------------------------- 1 | #ifdef SIM_STATIC_LIBRARY 2 | # include<../include/psi_neohookean_F.h> 3 | #endif 4 | 5 | template 6 | typename DefoType::Scalar sim::psi_neohookean_F(const Eigen::MatrixBase &F, const Eigen::MatrixBase ¶ms) { 7 | 8 | // using Scalar = typename DefoType::Scalar; 9 | // Scalar detF = F.determinant(); 10 | // Scalar J23 = stablePow(detF,2.0); 11 | // J23=1.0/J23; 12 | // Eigen::Matrix Cbar = J23*F.transpose()*F; 13 | 14 | // return params(0)*(Cbar.trace() - 3.0) + params(1)*(detF - 1)*(detF - 1); 15 | 16 | typename DefoType::Scalar F1_1, F1_2, F1_3, F2_1, F2_2, F2_3,F3_1, F3_2, F3_3; 17 | 18 | typename DefoType::Scalar params1 = params(0); 19 | typename DefoType::Scalar params2 = params(1); 20 | 21 | F1_1 = F(0,0); 22 | F1_2 = F(0,1); 23 | F1_3 = F(0,2); 24 | F2_1 = F(1,0); 25 | F2_2 = F(1,1); 26 | F2_3 = F(1,2); 27 | F3_1 = F(2,0); 28 | F3_2 = F(2,1); 29 | F3_3 = F(2,2); 30 | 31 | // return params1*(1.0/pow(F1_1*F2_2*F3_3-F1_1*F2_3*F3_2-F1_2*F2_1*F3_3+F1_2*F2_3*F3_1+F1_3*F2_1*F3_2-F1_3*F2_2*F3_1,2.0/3.0)*(F1_1*F1_1+F1_2*F1_2+F1_3*F1_3+F2_1*F2_1+F2_2*F2_2+F2_3*F2_3+F3_1*F3_1+F3_2*F3_2+F3_3*F3_3)-3.0)+params2*pow(-F1_1*F2_2*F3_3+F1_1*F2_3*F3_2+F1_2*F2_1*F3_3-F1_2*F2_3*F3_1-F1_3*F2_1*F3_2+F1_3*F2_2*F3_1+1.0,2.0); 32 | 33 | return params1*(log(F1_1*F2_2*F3_3-F1_1*F2_3*F3_2-F1_2*F2_1*F3_3+F1_2*F2_3*F3_1+F1_3*F2_1*F3_2-F1_3*F2_2*F3_1)*-2.0+F1_1*F1_1+F1_2*F1_2+F1_3*F1_3+F2_1*F2_1+F2_2*F2_2+F2_3*F2_3+F3_1*F3_1+F3_2*F3_2+F3_3*F3_3-3.0)+params2*pow(-F1_1*F2_2*F3_3+F1_1*F2_3*F3_2+F1_2*F2_1*F3_3-F1_2*F2_3*F3_1-F1_3*F2_1*F3_2+F1_3*F2_2*F3_1+1.0,2.0); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /cpp/src/vem3d_neohookean_dq2.cpp: -------------------------------------------------------------------------------- 1 | #ifdef SIM_STATIC_LIBRARY 2 | # include<../include/vem3d_neohookean_dq2.h> 3 | #endif 4 | 5 | template 6 | void sim::vem3d_neohookean_dq2(Eigen::MatrixXx &g, 7 | const Eigen::MatrixXx &A, 8 | const Eigen::MatrixXx &dF_dq, 9 | const Eigen::MatrixXx &dM_dq, 10 | DerivedVol volume, 11 | const Eigen::MatrixXx ¶ms, 12 | int k, int n, 13 | const Eigen::MatrixXd &dF_dq_sp) { 14 | 15 | Eigen::Matrix d2psi_dF2; 16 | Eigen::Map> dMi(dM_dq.data(), k, 3); 17 | 18 | d2psi_neohookean_dF2(d2psi_dF2, unflatten<3, 3>((A * dMi).eval()), params); 19 | g = dF_dq_sp.transpose() * d2psi_dF2 * dF_dq_sp * volume; 20 | 21 | } -------------------------------------------------------------------------------- /cpp/src/vem3dmesh_neohookean_q.cpp: -------------------------------------------------------------------------------- 1 | #ifdef SIM_STATIC_LIBRARY 2 | # include<../include/vem3dmesh_neohookean_q.h> 3 | #endif 4 | 5 | #ifdef VEM_USE_OPENMP 6 | #include 7 | #endif 8 | 9 | template 10 | double sim::vem3dmesh_neohookean_q(const Eigen::VectorXx &c, 11 | const Eigen::VectorXx &volume, 12 | const Eigen::MatrixXx ¶ms, 13 | const std::vector > & dF_dc, 14 | const std::vector, Eigen::aligned_allocator> > & dF_dc_S, 15 | int d) { 16 | 17 | double energy = 0; 18 | 19 | // TODO move this to separate file 20 | for (int i = 0; i < dF_dc.size(); ++i) { 21 | Eigen::MatrixXx CD = params.row(i); 22 | 23 | // std::cout << "CD = " << CD << std::endl; 24 | // std::cout << "dF_dc[i] = " << dF_dc[i] << std::endl; 25 | // std::cout << "dF_dc_S[i] = " << dF_dc_S[i] << std::endl; 26 | 27 | Eigen::MatrixXd F_flat = dF_dc[i] * dF_dc_S[i] * c; 28 | // std::cout << "F_flat = " << F_flat << std::endl; 29 | 30 | Eigen::Matrix3d F = unflatten<3, 3>(F_flat); 31 | 32 | // std::cout << "F = " << F << std::endl; 33 | // std::cout << "volume(i) = " << volume(i) << std::endl; 34 | // std::cout << "psi = " << psi_neohookean_F(F, params) << std::endl; 35 | 36 | energy += psi_neohookean_F(F, params) * volume(i); 37 | } 38 | 39 | // std::cout << "c = " << c << std::endl; 40 | // std::cout << "energy = " << energy << std::endl; 41 | 42 | return energy; 43 | } 44 | 45 | #include -------------------------------------------------------------------------------- /cpp/src/vem3dmesh_polynomial_coefficients.cpp: -------------------------------------------------------------------------------- 1 | #ifdef SIM_STATIC_LIBRARY 2 | # include<../include/vem3dmesh_polynomial_coefficients.h> 3 | #endif 4 | 5 | #ifdef VEM_USE_OPENMP 6 | #include 7 | #endif 8 | 9 | template 10 | void sim::vem3dmesh_polynomial_coefficients(Eigen::VectorXx &c, 11 | const Eigen::MatrixXx &x, 12 | const Eigen::SparseMatrix &L, 13 | const std::vector > & E){ 14 | 15 | // std::cout << "start polynomial_coefficients" << std::endl; 16 | Eigen::MatrixXd B(x.rows(), x.cols()); 17 | B.setZero(); 18 | int col_start = 0; 19 | Eigen::MatrixXd x_slice; 20 | // std::cout << "1 polynomial_coefficients" << std::endl; 21 | for (int i = 0; i < E.size(); i++) { 22 | igl::slice(x, E[i], 2, x_slice); 23 | // std::cout << "2 polynomial_coefficients" << std::endl; 24 | B.block(0, col_start, 3, E[i].rows()) = x_slice; 25 | // std::cout << "3 polynomial_coefficients" << std::endl; 26 | 27 | col_start += E[i].rows(); 28 | // std::cout << "4 polynomial_coefficients" << std::endl; 29 | } 30 | // std::cout << "5 polynomial_coefficients" << std::endl; 31 | Eigen::VectorXd b = Eigen::Map(B.data(), B.size()); 32 | // std::cout << "6 polynomial_coefficients" << std::endl; 33 | 34 | // Solve for polynomial coefficients (projection operators). 35 | c = L * b; 36 | // std::cout << "pass polynomial_coefficients" << std::endl; 37 | } 38 | 39 | #include -------------------------------------------------------------------------------- /cpp/src/vem_ext_force.cpp: -------------------------------------------------------------------------------- 1 | #ifdef SIM_STATIC_LIBRARY 2 | # include<../include/vem3dmesh_neohookean_dq.h> 3 | #endif 4 | 5 | #ifdef VEM_USE_OPENMP 6 | #include 7 | #endif 8 | 9 | template 10 | void sim::vem_ext_force(Eigen::VectorXx &g, 11 | const Eigen::VectorXx& ext, 12 | const Eigen::VectorXx& mass, 13 | const EigenMatrixList& Y, 14 | const EigenSparseMatrixList& Y_S) { 15 | 16 | int sz = Y_S[0].cols(); 17 | g.resize(sz); 18 | g.setZero(); 19 | 20 | for (int i = 0; i < Y.size(); ++i) { 21 | g += Y_S[i].transpose() * (Y[i].transpose() * ext * mass(i)); 22 | } 23 | } -------------------------------------------------------------------------------- /cpp/src/vem_mass_matrix.cpp: -------------------------------------------------------------------------------- 1 | #ifdef VEM_USE_OPENMP 2 | #include 3 | #endif 4 | 5 | template 6 | void sim::vem_mass_matrix(Eigen::MatrixXx &g, 7 | const EigenMatrixList& Y, 8 | const Eigen::SparseMatrix & L, 9 | const Eigen::VectorXx& mass, 10 | const EigenVectorList& W_I, 11 | const EigenVectorList& C_I, 12 | int d, int k, int n) { 13 | 14 | int sz = L.rows(); 15 | g.resize(sz,sz); 16 | g.setZero(); 17 | 18 | int dk = d * k; 19 | int dkn = dk * n; 20 | 21 | auto assembly_idx = [=](int idx, int dkm, int i) { 22 | int ret; 23 | if (idx < dkm) { 24 | ret = W_I[i](idx / dk) * dk + idx % dk; 25 | } 26 | else { 27 | ret = dkn + C_I[i]((idx - dkm) / d) * d + idx % d; 28 | } 29 | return ret; 30 | }; 31 | 32 | for (int i = 0; i < Y.size(); ++i) { 33 | Eigen::MatrixXd tmp = Y[i].transpose() * Y[i] * mass(i); 34 | 35 | int dkm = dk * W_I[i].rows(); // number of associated parts 36 | 37 | // Assembly 38 | for (int jj = 0; jj < tmp.cols(); ++jj) { 39 | for (int ii = 0; ii < tmp.rows(); ++ii) { 40 | int r = assembly_idx(ii, dkm, i); 41 | int c = assembly_idx(jj, dkm, i); 42 | g.coeffRef(r, c) += tmp(ii, jj); 43 | } 44 | } 45 | } 46 | g = L.transpose() * g * L; 47 | } -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | This folder contains script with configuration for different models and orders of deformation. Each example contains a prefix (linear, quadratic, etc.) indicating the order of deformation. -------------------------------------------------------------------------------- /examples/beam_twist.m: -------------------------------------------------------------------------------- 1 | function beam_twist 2 | 3 | iges_file = 'beam_cmp3_b.iges'; 4 | part = nurbs_from_iges(iges_file); 5 | 6 | % cutoff_distance=cutoff_heuristic(part, 0.9,40) 7 | 8 | %material properties 9 | YM = 1e6; %in Pascals 10 | pr = 0.45; 11 | [lambda, mu] = emu_to_lame(YM, pr); 12 | 13 | options.dt = 0.02; 14 | options.order = 2; 15 | options.pin_function = @pin_function; 16 | options.gravity = 0; 17 | options.lambda = lambda; 18 | options.mu = mu; 19 | options.rho = 1e3; 20 | options.distance_cutoff = 0.51; 21 | options.k_stability = 2e6; 22 | options.enable_secondary_rays = 1; 23 | options.fitting_mode = 'hierarchical'; 24 | options.save_output = 0; 25 | options.save_obj = 0; 26 | % options.plot_points = 1; 27 | options.x_samples = 15; 28 | options.y_samples = 3; 29 | options.z_samples = 3; 30 | simulate_twist(part, options); 31 | end -------------------------------------------------------------------------------- /examples/grumpy.m: -------------------------------------------------------------------------------- 1 | function not_gumby 2 | 3 | function pinned_ids = pin_function(x) 4 | %gumby_2 5 | % pinned_ids = find(x(1,:) > -0.05 & x(1,:) < 0.4 & x(3,:) > 1.8 & x(3,:) < 3 & x(2,:) > 0); 6 | % gumby 4 7 | % pinned_ids = find(x(1,:) > -.3 & x(1,:) < 0.4 & x(3,:) > 1.5 & x(3,:) < 3.3 & x(2,:) > 0); 8 | % excl = find(x(1,:) < 0 & x(3,:) < 1.6); 9 | 10 | % For the arm 11 | pinned_ids = find(x(1,:) > -.3 & x(1,:) < 0.4 & x(3,:) > 1.5 & x(3,:) < 3.3); 12 | excl = find(x(3,:) < 2.35 & x(3,:) > 2.1 & x(1,:) > 0.1223); 13 | 14 | % pinned_ids(pinned_ids & excl) = []; 15 | pinned_ids = setdiff(pinned_ids, excl); 16 | pinned_ids = pinned_ids(1:3:end); 17 | % pinned_ids=[]; 18 | end 19 | 20 | iges_file = 'grumpy.iges'; 21 | 22 | % iges_file = 'rounded_cube.iges'; 23 | 24 | part = nurbs_from_iges(iges_file); 25 | % YM = 1e4; %in Pascals 26 | YM = 1e4; % leg 1e3; %in Pascals 27 | pr = 0.4; 28 | 29 | cutoff_distance=cutoff_heuristic(part, 0.75); 30 | 31 | [lambda, mu] = emu_to_lame(YM, pr); 32 | options.order = 2; 33 | options.rho = 1e3; 34 | options.gravity=0; 35 | options.distance_cutoff = 1;%cutoff_distance; 36 | options.distance_cutoff = 2;%cutoff_distance; 37 | options.distance_cutoff = 0.6;%cutoff_distance; 38 | options.pin_function = @pin_function; 39 | options.lambda = lambda; 40 | options.mu = mu; 41 | options.plot_points = 1; 42 | options.plot_com = 1; 43 | options.k_stability=YM; 44 | options.k_stability=1e9; 45 | options.k_stability= 1e2; % leg 1e2; 46 | options.enable_secondary_rays=1; 47 | options.collision_ratio = 1e3; 48 | % options.y_samples = 1; 49 | % options.x_samples = 2; 50 | % options.z_samples = 25; 51 | options.y_samples = 1; 52 | options.x_samples = 2; 53 | options.z_samples = 41; 54 | options.save_obj=1; 55 | vem_sim_gumby(part, options); 56 | 57 | end -------------------------------------------------------------------------------- /examples/linear_lamppost.m: -------------------------------------------------------------------------------- 1 | function linear_lamppost 2 | 3 | function pinned_ids = pin_function(x) 4 | verts_to_pin = 64; 5 | [~,I] = mink(x(3,:),verts_to_pin); 6 | pinned_ids = I(1:3:verts_to_pin); 7 | end 8 | 9 | iges_file = 'lamppost.iges'; 10 | 11 | % To avoid singular nurbs jacobian with excessive pinning, I up the sample 12 | % density to ensure we have enough unpinned samples. 13 | sample_density=2; 14 | part = nurbs_from_iges(iges_file, sample_density); 15 | 16 | YM = 1e6; %in Pascals 17 | pr = 0.4; 18 | % YM = 2e11; %in Pascals 19 | % pr = 0.32; 20 | [lambda, mu] = emu_to_lame(YM, pr); 21 | 22 | options.dt = 0.02; 23 | options.order = 2; 24 | options.gravity = 0; 25 | options.rho = 3e3; 26 | % options.rho = 1.27e3; 27 | % options.rho = 8e3; 28 | options.pin_function = @pin_function; 29 | options.lambda = lambda; 30 | options.mu = mu; 31 | options.distance_cutoff = 1.0; 32 | options.k_stability = 5e5; 33 | options.plot_points = 1; 34 | options.x_samples = 2; 35 | options.y_samples = 5; 36 | options.z_samples = 35; 37 | options.save_iges=1; 38 | cutoff_distance=cutoff_heuristic(part, 0.8); 39 | options.distance_cutoff = 0.8; 40 | 41 | options.f_external = [-1e1 0 0]; 42 | options.f_external_time = 2.0; 43 | 44 | % vem_simulate_nurbs_newtons(part, options); 45 | vem_simulate_nurbs(part, options); 46 | 47 | end -------------------------------------------------------------------------------- /examples/linear_mug.m: -------------------------------------------------------------------------------- 1 | function linear_mug 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = find(x(1,:) > 6 & x(3,:) > 6 & x(3,:) < 7); 5 | end 6 | 7 | iges_file = 'mug.iges'; 8 | 9 | part = nurbs_from_iges(iges_file); 10 | 11 | %material properties 12 | YM = 5e2; %in Pascals 13 | pr = 0.15; 14 | [lambda, mu] = emu_to_lame(YM, pr); 15 | 16 | options.order = 1; 17 | options.gravity = -10; 18 | options.rho = .2; 19 | options.pin_function = @pin_function; 20 | options.lambda = lambda; 21 | options.mu = mu; 22 | options.sample_interior = 0; % only sample on boundary 23 | options.distance_cutoff = 1; 24 | options.fitting_mode = 'hierarchical'; 25 | vem_simulate_nurbs(part, options); 26 | 27 | 28 | end -------------------------------------------------------------------------------- /examples/linear_mug_implicit.m: -------------------------------------------------------------------------------- 1 | function linear_mug_implicit 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = find(x(1,:) > 6 & x(3,:) > 6 & x(3,:) < 7); 5 | end 6 | 7 | iges_file = 'mug.iges'; 8 | 9 | part = nurbs_from_iges(iges_file); 10 | 11 | %material properties 12 | YM = 5e2; %in Pascals 13 | pr = 0.15; 14 | [lambda, mu] = emu_to_lame(YM, pr); 15 | 16 | options.dt = 0.1; % higher timestep works great! 17 | options.order = 1; 18 | options.gravity = -10; 19 | options.rho = .2; 20 | options.pin_function = @pin_function; 21 | options.lambda = lambda; 22 | options.mu = mu; 23 | options.sample_interior = 0; % only sample on boundary 24 | options.distance_cutoff = 1; 25 | vem_simulate_nurbs_newtons(part, options); 26 | 27 | 28 | end -------------------------------------------------------------------------------- /examples/linear_rocket.m: -------------------------------------------------------------------------------- 1 | function linear_rocket 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = find(x(3,:) < 0.1); 5 | end 6 | 7 | iges_file = 'rocket_small.iges'; 8 | 9 | part = nurbs_from_iges(iges_file); 10 | 11 | YM = 3e2; %in Pascals 12 | pr = 0.25; 13 | [lambda, mu] = emu_to_lame(YM, pr); 14 | 15 | % options.dt = 0.1; 16 | options.order = 1; 17 | options.gravity = -25.95; 18 | options.rho = 1e-3; 19 | options.pin_function = @pin_function; 20 | options.lambda = lambda; 21 | options.mu = mu; 22 | options.distance_cutoff = 1; 23 | % options.k_stability = YM*1e8; 24 | options.plot_points = 1; 25 | options.x_samples = 2; 26 | options.z_samples = 15; 27 | 28 | % vem_simulate_nurbs_newtons(part, options); 29 | vem_simulate_nurbs(part, options); 30 | 31 | end -------------------------------------------------------------------------------- /examples/linear_rocket_with_collision.m: -------------------------------------------------------------------------------- 1 | function linear_rocket_with_collision 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = []; 5 | end 6 | 7 | iges_file = 'rocket.iges'; 8 | 9 | part = nurbs_from_iges(iges_file); 10 | 11 | YM = 2e11; %in Pascals 12 | pr = 0.32; 13 | [lambda, mu] = emu_to_lame(YM, pr); 14 | 15 | options.order = 1; 16 | options.gravity = -9.8; 17 | options.rho = 8e3; 18 | options.pin_function = @pin_function; 19 | options.lambda = lambda; 20 | options.mu = mu; 21 | 22 | options.distance_cutoff = 10; % use 5 for a single com; 23 | 24 | options.save_obj = true; 25 | options.save_obj_path = 'output/obj_rocket_hard_2/'; 26 | 27 | options.k_stability = 1e9; 28 | options.collision_ratio = 5e7; 29 | 30 | options.x_samples = 5; 31 | options.y_samples = 5; 32 | options.z_samples = 15; % we want more samples along vertical axis 33 | 34 | % If you want centers of mass on the legs of the rocket, you'll need to 35 | % make sure points are sampled on the legs. You can fidget with the above 36 | % numbers to try to change it, if you need. 37 | % options.plot_points=true; % Enable to see all the equadrature points. 38 | 39 | options.collision_with_other = false; 40 | options.self_collision = false; 41 | options.collision_with_plane = true; 42 | options.collision_plane_z = -20.0; 43 | options.initial_velocity = [0 0 -10]; 44 | 45 | vem_simulate_nurbs_with_collision(part, options); 46 | end -------------------------------------------------------------------------------- /examples/linear_rocket_with_nose.m: -------------------------------------------------------------------------------- 1 | function linear_rocket_with_nose 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = find(x(3,:) == max(x(3,:))); 5 | end 6 | 7 | iges_file = 'rocket_with_nose.iges'; 8 | part = nurbs_from_iges(iges_file); 9 | 10 | YM = 3e1; %in Pascals 11 | pr = 0.15; 12 | [lambda, mu] = emu_to_lame(YM, pr); 13 | 14 | options.order = 1; 15 | options.gravity = -25.95; 16 | options.rho = 1e-4; 17 | options.pin_function = @pin_function; 18 | options.lambda = lambda; 19 | options.mu = mu; 20 | 21 | vem_simulate_nurbs(part, options); 22 | 23 | end -------------------------------------------------------------------------------- /examples/linear_rounded_cube.m: -------------------------------------------------------------------------------- 1 | function linear_rounded_cube 2 | 3 | function pinned_ids = pin_function(x) 4 | verts_to_pin = 4; 5 | [~,I] = mink(x(3,:),verts_to_pin); 6 | pinned_ids = I(1:verts_to_pin); 7 | end 8 | 9 | iges_file = 'rounded_cube.iges'; 10 | part = nurbs_from_iges(iges_file); 11 | 12 | YM = 1e2; %in Pascals 13 | pr = 0.15; 14 | [lambda, mu] = emu_to_lame(YM, pr); 15 | 16 | options.order = 1; 17 | options.rho = 1e-1; 18 | options.gravity = -10; 19 | options.pin_function = @pin_function; 20 | options.lambda = lambda; 21 | options.mu = mu; 22 | 23 | vem_simulate_nurbs_newtons(part, options); 24 | % vem_simulate_nurbs(part, options); 25 | 26 | end -------------------------------------------------------------------------------- /examples/linear_subD_puft_body.m: -------------------------------------------------------------------------------- 1 | function linear_subD_puft 2 | function pinned_ids = pin_function(x) 3 | verts_to_pin = 2; 4 | [~,I] = mink(x(1,:),verts_to_pin); 5 | pinned_ids = I(1:verts_to_pin); 6 | end 7 | 8 | iges_file = 'puft_without_head_subd.iges'; 9 | % iges_file = 'puft_subD.iges'; 10 | 11 | part = nurbs_from_iges(iges_file); 12 | 13 | options.order = 1; 14 | options.gravity = -10; 15 | % options.rho = .2; 16 | options.pin_function = @pin_function; 17 | options.lambda = 10*3; 18 | options.mu = 150*3; 19 | % options.sample_interior = 0; % only sample on boundary 20 | % options.distance_cutoff = 1; 21 | % options.enable_secondary_rays = false; 22 | options.save_obj = false; 23 | axis equal 24 | vem_simulate_subd(part, options); 25 | 26 | end -------------------------------------------------------------------------------- /examples/linear_subD_rocket.m: -------------------------------------------------------------------------------- 1 | function linear_subD_rocket 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = find(x(3,:) < 2); 5 | end 6 | 7 | iges_file = 'rocket_subd.iges'; 8 | 9 | part = nurbs_from_iges(iges_file); 10 | 11 | YM = 3e1; %in Pascals 12 | pr = 0.15; 13 | [lambda, mu] = emu_to_lame(YM, pr); 14 | 15 | options.order = 1; 16 | options.gravity = -25.95; 17 | options.rho = 1e-4; 18 | options.pin_function = @pin_function; 19 | options.lambda = lambda; 20 | options.mu = mu; 21 | options.distance_cutoff = 10; 22 | 23 | vem_simulate_subd(part, options); 24 | 25 | end -------------------------------------------------------------------------------- /examples/linear_subD_torus.m: -------------------------------------------------------------------------------- 1 | function linear_subD_torus 2 | function pinned_ids = pin_function(x) 3 | verts_to_pin = 2; 4 | [~,I] = mink(x(1,:),verts_to_pin); 5 | pinned_ids = I(1:verts_to_pin); 6 | end 7 | 8 | iges_file = 'torus_subd.igs'; 9 | 10 | part = nurbs_from_iges(iges_file); 11 | 12 | options.order = 1; 13 | options.gravity = -10; 14 | % options.rho = .2; 15 | options.pin_function = @pin_function; 16 | % options.lambda = 100; 17 | % options.mu = 1500; 18 | % options.sample_interior = 0; % only sample on boundary 19 | % options.distance_cutoff = 1; 20 | options.enable_secondary_rays = false; 21 | options.save_obj = true; 22 | axis equal 23 | vem_simulate_nurbs(part, options); 24 | 25 | end -------------------------------------------------------------------------------- /examples/linear_trimmed_cylinder.m: -------------------------------------------------------------------------------- 1 | function linear_trimmed_cylinder 2 | 3 | function pinned_ids = pin_function(x) 4 | verts_to_pin = 2; 5 | [~,I] = mink(x(3,:),verts_to_pin); 6 | pinned_ids = I(1:verts_to_pin); 7 | end 8 | 9 | iges_file = 'cylinder.iges'; 10 | 11 | part = nurbs_from_iges(iges_file); 12 | 13 | YM = 1e2; %in Pascals 14 | pr = 0.15; 15 | [lambda, mu] = emu_to_lame(YM, pr); 16 | 17 | options.order = 1; 18 | options.rho = 0.1; 19 | options.gravity = -10; 20 | options.lambda = lambda; 21 | options.mu = mu; 22 | options.pin_function = @pin_function; 23 | 24 | vem_simulate_nurbs_newtons(part, options); 25 | 26 | end -------------------------------------------------------------------------------- /examples/linear_trimmed_cylinder_with_collision.m: -------------------------------------------------------------------------------- 1 | function linear_trimmed_cylinder_with_collision 2 | 3 | function pinned_ids = pin_function(x) 4 | verts_to_pin = 2; 5 | [~,I] = mink(x(3,:),verts_to_pin); 6 | pinned_ids = I(1:verts_to_pin); 7 | end 8 | 9 | iges_file = 'cylinder.iges'; 10 | 11 | part = nurbs_from_iges(iges_file); 12 | 13 | YM = 1e2; %in Pascals 14 | pr = 0.15; 15 | [lambda, mu] = emu_to_lame(YM, pr); 16 | 17 | options.order = 1; 18 | options.rho = 0.1; 19 | options.gravity = -10; 20 | options.lambda = lambda; 21 | options.mu = mu; 22 | options.pin_function = @pin_function; 23 | 24 | options.collision_ratio = 0.1; 25 | options.collision_with_other = true; 26 | options.self_collision = false; 27 | options.collision_with_plane = true; 28 | vem_simulate_nurbs_with_collision(part, options); 29 | 30 | end -------------------------------------------------------------------------------- /examples/linear_trimmed_mug.m: -------------------------------------------------------------------------------- 1 | function linear_trimmed_mug 2 | 3 | function pinned_ids = pin_function(x) 4 | verts_to_pin = 4; 5 | [~,I] = maxk(x(1,:),verts_to_pin); 6 | pinned_ids = I(1:verts_to_pin); 7 | end 8 | 9 | iges_file = 'mug_complex.iges'; 10 | 11 | part = nurbs_from_iges(iges_file); 12 | 13 | YM = 2e3; %in Pascals 14 | pr = 0.45; 15 | [lambda, mu] = emu_to_lame(YM, pr); 16 | 17 | options.rho = 1e-5; 18 | options.order = 1; 19 | options.pin_function = @pin_function; 20 | options.gravity = -10; 21 | options.lambda = lambda; 22 | options.mu = mu; 23 | % options.plot_points = 1; 24 | options.fitting_mode = 'hierarchical'; 25 | 26 | options.x_samples = 3; 27 | options.y_samples = 5; 28 | options.z_samples = 5; 29 | 30 | options.distance_cutoff = 100; 31 | options.dt = 0.1; 32 | 33 | vem_simulate_nurbs_newtons(part, options); 34 | % vem_simulate_nurbs(part, options); 35 | 36 | end -------------------------------------------------------------------------------- /examples/linear_trimmed_mug_with_collision.m: -------------------------------------------------------------------------------- 1 | function linear_trimmed_mug_with_collision 2 | 3 | function pinned_ids = pin_function(x) 4 | % % verts_to_pin = 3; 5 | % verts_to_pin = 10; 6 | % [~,I] = maxk(x(1,:),verts_to_pin); 7 | % pinned_ids = I(1:verts_to_pin); 8 | pinned_ids = []; 9 | end 10 | 11 | iges_file = 'mug_complex.iges'; 12 | 13 | part = nurbs_from_iges(iges_file); 14 | 15 | YM = 2.9e7; 16 | pr = 0.32; 17 | [lambda, mu] = emu_to_lame(YM, pr); 18 | 19 | options.rho = 0.1; 20 | options.order = 1; 21 | options.pin_function = @pin_function; 22 | options.gravity = -100; 23 | options.enable_secondary_rays = false; 24 | options.lambda = lambda; 25 | options.mu = mu; 26 | options.sample_interior = 0; 27 | 28 | % options.save_obj = true; 29 | 30 | options.collision_ratio = 0.1; 31 | options.collision_with_other = false; 32 | options.self_collision = false; 33 | options.collision_with_plane = true; 34 | options.collision_plane_z = -40.0; 35 | vem_simulate_nurbs_with_collision(part, options); 36 | 37 | end -------------------------------------------------------------------------------- /examples/linear_trimmed_wrench.m: -------------------------------------------------------------------------------- 1 | function linear_trimmed_wrench 2 | 3 | function pinned_ids = pin_function(x) 4 | verts_to_pin = 2; 5 | [~,I] = mink(x(1,:),verts_to_pin); 6 | pinned_ids = I(1:verts_to_pin); 7 | end 8 | 9 | iges_file = 'wrench.iges'; 10 | 11 | part = nurbs_from_iges(iges_file); 12 | 13 | YM = 2e3; %in Pascals 14 | pr = 0.25; 15 | [lambda, mu] = emu_to_lame(YM, pr); 16 | 17 | options.order = 1; 18 | options.rho = 1; 19 | options.pin_function = @pin_function; 20 | options.gravity = -10; 21 | options.lambda = lambda; 22 | options.mu = mu; 23 | 24 | options.plot_points=1; 25 | vem_simulate_nurbs(part, options); 26 | 27 | end -------------------------------------------------------------------------------- /examples/linear_trimmed_wrench_with_collision.m: -------------------------------------------------------------------------------- 1 | function linear_trimmed_wrench_with_collision 2 | 3 | function pinned_ids = pin_function(x) 4 | verts_to_pin = 2; 5 | [~,I] = mink(x(1,:),verts_to_pin); 6 | pinned_ids = I(1:verts_to_pin); 7 | end 8 | 9 | iges_file = 'wrench.iges'; 10 | 11 | part = nurbs_from_iges(iges_file); 12 | 13 | 14 | YM = 2e3; %in Pascals 15 | pr = 0.25; 16 | [lambda, mu] = emu_to_lame(YM, pr); 17 | 18 | options.order = 1; 19 | options.rho = 1; 20 | options.pin_function = @pin_function; 21 | options.lambda = lambda; 22 | options.mu = mu; 23 | options.gravity = 0; 24 | 25 | options.sample_interior = 0; 26 | options.collision_ratio = 1.0; 27 | options.collision_with_other = true; 28 | options.self_collision = false; 29 | options.collision_with_plane = true; 30 | options.collision_plane_z = -40.0; 31 | 32 | vem_simulate_nurbs_with_collision(part, options); 33 | end -------------------------------------------------------------------------------- /examples/octopus.m: -------------------------------------------------------------------------------- 1 | function octopus 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = []; 5 | end 6 | 7 | % iges_file = 'octopus4.iges'; 8 | iges_file = 'squid.iges'; 9 | 10 | part = nurbs_from_iges(iges_file); 11 | 12 | % cutoff_distance=cutoff_heuristic(part, 0.9,40) 13 | 14 | % YM = 2e3; %in Pascals 15 | % pr = 0.25; 16 | % YM = 1e5; 17 | % YM = 1.5e4; 18 | YM = 2e4;%2e4; 19 | pr = 0.40; 20 | [lambda, mu] = emu_to_lame(YM, pr); 21 | 22 | options.dt=0.01; 23 | options.rho = 1e3; 24 | 25 | options.order = 2; 26 | options.pin_function = @pin_function; 27 | options.gravity = -10; 28 | options.enable_secondary_rays = true; 29 | options.lambda = lambda; 30 | options.mu = mu; 31 | options.sample_interior = 1; 32 | options.save_output=0; % save imgs 33 | options.plot_points=1; 34 | options.plot_com=1; 35 | 36 | % Not too bad % 37 | options.x_samples=4;%2; 38 | options.y_samples=16; 39 | options.z_samples=16; 40 | 41 | options.x_samples=6;%4; 42 | options.y_samples=40; 43 | options.z_samples=50; 44 | 45 | % options.distance_cutoff=0.70; octupus1 46 | % options.distance_cutoff=0.25;%0.2;% octopus4 47 | options.distance_cutoff=0.08;%0.12;%0.25;%0.2;% octopus4 48 | options.save_obj = 1; 49 | % options.k_stability = YM;%5e3; 50 | options.k_stability = 1e4;% CHANGED 6e3; 51 | % options.k_stability = 2e3; 52 | 53 | % changed sampling 8->10, k_stability, and collision ratio 54 | options.collision_ratio = 0.02;%0.5; 55 | options.collision_with_other = false; 56 | options.self_collision = false; 57 | options.collision_with_plane = true; 58 | options.collision_plane_z = 0.1; 59 | vem_simulate_nurbs_with_collision(part, options); 60 | 61 | end -------------------------------------------------------------------------------- /examples/quadratic_beam.m: -------------------------------------------------------------------------------- 1 | function quadratic_beam 2 | 3 | function pinned_ids = pin_function(x) 4 | % pinned_ids1 = find(x(1,:) == min(x(1,:)) & x(2,:) > 0.6 & (x(3,:) > 0.8 | x(3,:) < 0.2)); 5 | % pinned_ids2 = find(x(1,:) == min(x(1,:)) & x(2,:) < 0.4 & (x(3,:) > 0.8 | x(3,:) < 0.2)); 6 | % pinned_ids = [pinned_ids2 pinned_ids1]; 7 | end 8 | 9 | iges_file = 'beam_cmp3.iges'; 10 | 11 | % To avoid singular nurbs jacobian with excessive pinning, I up the sample 12 | % density to ensure we have enough unpinned samples. 13 | part = nurbs_from_iges(iges_file); 14 | 15 | % cutoff_distance=cutoff_heuristic(part, 0.9,40) 16 | 17 | 18 | %material properties 19 | % YM = 5e3; %in Pascals 20 | YM = 5e6; %in Pascals 21 | pr = 0.45; 22 | [lambda, mu] = emu_to_lame(YM, pr); 23 | 24 | options.dt = 0.02; 25 | options.order = 1; 26 | options.pin_function = @pin_function; 27 | options.gravity = -10; 28 | options.lambda = lambda; 29 | options.mu = mu; 30 | options.rho = 1e3; 31 | % options.distance_cutoff = 1; 32 | % options.distance_cutoff = 0.6; 33 | options.distance_cutoff = 0.51; 34 | % options.k_stability = 1e6; 35 | options.k_stability = 1e6; 36 | options.enable_secondary_rays = 1; 37 | options.fitting_mode = 'hierarchical'; 38 | options.save_output = 0; 39 | options.save_obj = 0; 40 | % options.plot_points = 1; 41 | options.x_samples = 50; 42 | options.y_samples = 2; 43 | options.z_samples = 2; 44 | options.x_samples = 25; 45 | options.y_samples = 1; 46 | options.z_samples = 1; 47 | % options.x_samples = 25; 48 | % options.y_samples = 5; 49 | % options.z_samples = 5; 50 | % vem_simulate_nurbs_newtons(part, options); 51 | vem_simulate_nurbs(part, options); 52 | 53 | end -------------------------------------------------------------------------------- /examples/quadratic_chicken_with_collision.m: -------------------------------------------------------------------------------- 1 | function quadratic_chicken_with_collision 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = []; 5 | end 6 | 7 | % iges_file = 'chicken.iges'; % complex version 8 | iges_file = 'chicken_simple_closed_small.iges'; % simplified version 9 | 10 | part = nurbs_from_iges(iges_file); 11 | 12 | % YM = 2e3; %in Pascals 13 | % pr = 0.25; 14 | % YM = 1e5; 15 | YM = 1e4; 16 | pr = 0.47; 17 | [lambda, mu] = emu_to_lame(YM, pr); 18 | 19 | options.dt=0.01; 20 | options.rho = 1.27e3; 21 | 22 | options.order = 2; 23 | options.pin_function = @pin_function; 24 | options.gravity = -10; 25 | options.enable_secondary_rays = true; 26 | options.lambda = lambda; 27 | options.mu = mu; 28 | % options.sample_interior = 1; 29 | 30 | options.plot_points=1; 31 | options.x_samples=3; %2 on regular 3 on bad 32 | options.y_samples=6; 33 | options.z_samples=6; 34 | % options.z_samples=11; 35 | 36 | % New cutoff heuristic thing. The second argument is the "sparsity" which 37 | % is a 0 to 1 value for how local you want deformations to be. 38 | % So 0.9 yields a cutoff distance value that is very local. 39 | cutoff_distance=cutoff_heuristic(part, 0.9); 40 | 41 | options.distance_cutoff = cutoff_distance; 42 | % options.distance_cutoff=0.2; 43 | options.save_obj = true; 44 | options.save_obj_path = 'output/chicken_closed_soft/'; 45 | options.k_stability = 1e7; 46 | 47 | % options.collision_ratio = 4e-1; 48 | options.collision_ratio = 6e-3; 49 | options.collision_with_other = false; 50 | options.self_collision = false; 51 | options.collision_with_plane = true; 52 | options.collision_plane_z = -0.2; 53 | options.initial_velocity = 0.1 * [-10 0 -4]; 54 | vem_simulate_nurbs_with_collision(part, options); 55 | 56 | end -------------------------------------------------------------------------------- /examples/quadratic_puft_with_collision.m: -------------------------------------------------------------------------------- 1 | function quadratic_puft_with_collision 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = []; 5 | end 6 | 7 | iges_file = 'puft_full_simpler.iges'; % simplified version 8 | 9 | sample_density=2; 10 | part = nurbs_from_iges(iges_file,sample_density); 11 | 12 | % YM = 2e3; %in Pascals 13 | % pr = 0.25; 14 | % YM = 1e5; 15 | YM = 1e6; 16 | pr = 0.47; 17 | [lambda, mu] = emu_to_lame(YM, pr); 18 | 19 | options.dt=0.01; 20 | options.rho = 1.27e3; 21 | 22 | options.order = 2; 23 | options.pin_function = @pin_function; 24 | options.gravity = 0; 25 | options.enable_secondary_rays = true; 26 | options.lambda = lambda; 27 | options.mu = mu; 28 | % options.sample_interior = 1; 29 | 30 | options.plot_points=0; 31 | options.x_samples=3; %2 on regular 3 on bad 32 | options.y_samples=8; 33 | options.z_samples=15; 34 | % options.z_samples=11; 35 | 36 | % New cutoff heuristic thing. The second argument is the "sparsity" which 37 | % is a 0 to 1 value for how local you want deformations to be. 38 | % So 0.9 yields a cutoff distance value that is very local. 39 | cutoff_distance=cutoff_heuristic(part, 0.9); 40 | 41 | options.distance_cutoff = cutoff_distance; 42 | % options.distance_cutoff=0.2; 43 | options.save_obj = true; 44 | options.save_obj_path = 'output/puft_with_puft/'; 45 | options.k_stability = 3e7;%1e10; 46 | 47 | % options.collision_ratio = 4e-1; 48 | options.collision_ratio = 5e4; 49 | options.collision_with_other = true; 50 | options.collision_other_position = [20 0 0]; 51 | options.self_collision = false; 52 | options.collision_with_plane = false; 53 | options.collision_plane_z = -20; 54 | options.initial_velocity = [10 0 0]; 55 | vem_simulate_nurbs_with_collision(part, options); 56 | 57 | end -------------------------------------------------------------------------------- /examples/quadratic_rigid_mug_with_collision.m: -------------------------------------------------------------------------------- 1 | function quadratic_rigid_mug_with_collision 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = []; 5 | end 6 | 7 | % iges_file = 'mug_trimmed.iges'; 8 | iges_file = 'mug_trimmed_rot2.iges'; 9 | 10 | part = nurbs_from_iges(iges_file); 11 | 12 | % YM = 2e3; %in Pascals 13 | % pr = 0.25; 14 | % YM = 1e5; 15 | YM = 4e7; 16 | pr = 0.40; 17 | [lambda, mu] = emu_to_lame(YM, pr); 18 | 19 | options.dt=0.01; 20 | options.rho = 1e3; 21 | 22 | options.order = 2; 23 | options.pin_function = @pin_function; 24 | options.gravity = -10; 25 | options.enable_secondary_rays = true; 26 | options.lambda = lambda; 27 | options.mu = mu; 28 | options.sample_interior = 1; 29 | 30 | % options.plot_points=1; 31 | options.x_samples=2; %2 on regular 3 on bad 32 | % options.y_samples=5; 33 | % options.y_samples=5; 34 | options.z_samples=15; 35 | 36 | options.distance_cutoff=0.1; 37 | options.distance_cutoff=0.3; %0.5; 38 | % options.distance_cutoff=5.6; 39 | options.save_obj = 1; 40 | % options.k_stability = 1e9; 41 | 42 | options.initial_velocity = [1.5 0.1 -2]; 43 | 44 | 45 | % options.collision_ratio = 4e-1; 46 | options.collision_ratio = 8e1; 47 | options.collision_with_other = false; 48 | options.self_collision = false; 49 | options.collision_with_plane = true; 50 | options.collision_plane_z = -0.8; 51 | vem_simulate_nurbs_with_collision(part, options); 52 | 53 | end -------------------------------------------------------------------------------- /examples/quadratic_rocket_soft_with_collision.m: -------------------------------------------------------------------------------- 1 | function linear_rocket_soft_with_collision 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = []; 5 | end 6 | 7 | iges_file = 'rocket.iges'; 8 | 9 | part = nurbs_from_iges(iges_file); 10 | 11 | YM = 7e6; %in Pascals 12 | pr = 0.4; 13 | [lambda, mu] = emu_to_lame(YM, pr); 14 | 15 | options.order = 2; 16 | options.gravity = -9.8; 17 | options.rho = 1.27e3; 18 | options.pin_function = @pin_function; 19 | options.lambda = lambda; 20 | options.mu = mu; 21 | options.distance_cutoff = 10; 22 | 23 | options.save_obj = true; 24 | options.save_obj_path = 'output/obj_rocket_soft_quadratic/'; 25 | 26 | options.k_stability = YM*1e5; 27 | options.collision_ratio = 1e5; 28 | 29 | options.x_samples = 5; 30 | options.y_samples = 9; 31 | options.z_samples = 15; % we want more samples along vertical axis 32 | 33 | options.collision_with_other = false; 34 | options.self_collision = false; 35 | options.collision_with_plane = true; 36 | options.collision_plane_z = -20.0; 37 | options.initial_velocity = [0 0 -10]; 38 | 39 | vem_simulate_nurbs_with_collision(part, options); 40 | 41 | end -------------------------------------------------------------------------------- /examples/quadratic_rounded_cube.m: -------------------------------------------------------------------------------- 1 | function quadratic_rounded_cube 2 | 3 | function pinned_ids = pin_function(x) 4 | % pinning corner points of the cube 5 | x_min = 0.4; 6 | y_min = 0.4; 7 | pinned_ids = find(x(1,:) > x_min & x(2,:) > y_min); 8 | end 9 | 10 | iges_file = 'rounded_cube.iges'; 11 | part = nurbs_from_iges(iges_file); 12 | YM = 1e6; %in Pascals 13 | pr = 0.45; 14 | [lambda, mu] = emu_to_lame(YM, pr); 15 | options.order = 2; 16 | options.rho = 1e3; 17 | options.gravity = -10; 18 | options.pin_function = @pin_function; 19 | options.lambda = lambda; 20 | options.mu = mu; 21 | options.k_stability=YM; 22 | options.distance_cutoff=cutoff_heuristic(part, 0.9); 23 | 24 | % vem_simulate_nurbs_newtons(part, options); 25 | vem_simulate_nurbs(part, options); 26 | 27 | end -------------------------------------------------------------------------------- /examples/quadratic_trimmed_mug_with_collision.m: -------------------------------------------------------------------------------- 1 | function quadratic_trimmed_mug_with_collision 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = []; 5 | end 6 | 7 | % iges_file = 'mug_complex4_bad.igs'; 8 | iges_file = 'mug_complex.iges'; 9 | 10 | part = nurbs_from_iges(iges_file); 11 | 12 | % YM = 2e3; %in Pascals 13 | % pr = 0.25; 14 | % YM = 1e5; 15 | YM = 1e4; 16 | pr = 0.47; 17 | [lambda, mu] = emu_to_lame(YM, pr); 18 | 19 | options.dt=0.01; 20 | options.rho = 1e3; 21 | 22 | options.order = 2; 23 | options.pin_function = @pin_function; 24 | options.gravity = -10; 25 | options.enable_secondary_rays = true; 26 | options.lambda = lambda; 27 | options.mu = mu; 28 | options.sample_interior = 1; 29 | 30 | options.plot_points=1; 31 | options.x_samples=3; %2 on regular 3 on bad 32 | % options.y_samples=5; 33 | % options.y_samples=5; 34 | options.z_samples=11; 35 | 36 | options.distance_cutoff=0.1; 37 | options.distance_cutoff=0.2; 38 | options.save_obj = 1; 39 | % options.k_stability = 1e7; 40 | 41 | % options.collision_ratio = 4e-1; 42 | options.collision_ratio = 1; 43 | options.collision_with_other = false; 44 | options.self_collision = false; 45 | options.collision_with_plane = true; 46 | options.collision_plane_z = -0.4; 47 | vem_simulate_nurbs_with_collision(part, options); 48 | 49 | end -------------------------------------------------------------------------------- /examples/starship_collision.m: -------------------------------------------------------------------------------- 1 | function starship_collision 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = []; 5 | end 6 | 7 | % iges_file = 'starship_fall_simpler.igs'; 8 | iges_file = 'starship_fall_collide.igs'; 9 | 10 | part = nurbs_from_iges(iges_file, 1); 11 | 12 | YM = 2e10; %in Pascals 13 | pr = 0.32; 14 | [lambda, mu] = emu_to_lame(YM, pr); 15 | 16 | options.dt = 0.01; 17 | options.order = 1; 18 | options.gravity = -10; 19 | options.rho = 4e3; 20 | options.pin_function = @pin_function; 21 | options.lambda = lambda; 22 | options.mu = mu; 23 | 24 | % cutoff_distance=cutoff_heuristic(part, 0.9); 25 | 26 | options.distance_cutoff = 0.7; % use 5 for a single com; 27 | 28 | options.save_obj = true; 29 | 30 | options.k_stability = 1e7; 31 | 32 | % Increase this would give a larger penalty force for collision and 33 | % bounces back to a higher position 34 | options.collision_ratio = 9.5e5; % Decrease to 9e5 or 8e5 to make it bounce back lower 35 | % options.collision_ratio = 7.5e5; % Decrease to 9e5 or 8e5 to make it bounce back lower 36 | 37 | options.x_samples = 10; 38 | options.y_samples = 7; 39 | options.z_samples = 10; % we want more samples along vertical axis 40 | 41 | % If you want centers of mass on the legs of the rocket, you'll need to 42 | % make sure points are sampled on the legs. You can fidget with the above 43 | % numbers to try to change it, if you need. 44 | % options.plot_points=true; % Enable to see all the equadrature points. 45 | 46 | options.collision_with_other = true; 47 | options.self_collision = false; 48 | options.collision_with_plane = false; 49 | options.collision_plane_z = 0; 50 | options.initial_velocity = [15 4 -10]; 51 | 52 | vem_simulate_nurbs_with_collision(part, options); 53 | end -------------------------------------------------------------------------------- /examples/tire_multi_material.m: -------------------------------------------------------------------------------- 1 | function tire_multi_material 2 | 3 | function pinned_ids = pin_function(x) 4 | pinned_ids = []; 5 | end 6 | 7 | iges_file = 'tire_5.iges'; 8 | 9 | part = nurbs_from_iges(iges_file, 1); 10 | 11 | YM = 1e6; %in Pascals 12 | % YM = 4e5; %in Pascals 13 | pr = 0.47; 14 | [lambda, mu] = emu_to_lame(YM, pr); 15 | 16 | options.dt = 0.01; 17 | options.order = 2; 18 | options.gravity = -10; 19 | options.rho = 2e3; 20 | options.pin_function = @pin_function; 21 | options.lambda = lambda; 22 | options.mu = mu; 23 | 24 | % cutoff_distance=cutoff_heuristic(part, 0.9); 25 | options.distance_cutoff = 1.1;%1.2%0.9;%0.7; % 0.75 use 5 for a single com; 26 | 27 | options.save_obj = false; 28 | 29 | options.k_stability = 1e9; %3e7 30 | 31 | % Increase this would give a larger penalty force for collision and 32 | % bounces back to a higher position 33 | options.collision_ratio = 3e2; % Decrease to 9e5 or 8e5 to make it bounce back lower 34 | options.collision_ratio = 5e3; % Decrease to 9e5 or 8e5 to make it bounce back lower 35 | % options.collision_ratio = 3e4; % Decrease to 9e5 or 8e5 to make it bounce back lower 36 | % options.collision_ratio = 4e4; % Decrease to 9e5 or 8e5 to make it bounce back lower 37 | 38 | options.x_samples = 4; 39 | options.y_samples = 9; 40 | options.z_samples = 9; % we want more samples along vertical axis 41 | % If you want centers of mass on the legs of the rocket, you'll need to 42 | % make sure points are sampled on the legs. You can fidget with the above 43 | % numbers to try to change it, if you need. 44 | % options.plot_points=true; % Enable to see all the equadrature points. 45 | 46 | options.collision_with_other = false; 47 | options.self_collision = false; 48 | options.collision_with_plane = true; 49 | options.collision_plane_z = -7; 50 | options.initial_velocity = [5 0 -5]; 51 | options.save_output=0; 52 | 53 | vem_sim_tire(part, options); 54 | end -------------------------------------------------------------------------------- /figures/deflection_test.m: -------------------------------------------------------------------------------- 1 | function deflection_test 2 | 3 | 4 | % Read in cube mesh 5 | files={'b1.igs', 'b2.igs', 'b3.igs', 'b4.igs', 'b5.igs', 'b6.igs','b7.igs','b8.igs','b9.igs','b10.igs'};%, ... 6 | % 'b7.igs', 'b8.igs'};%, 'b9.igs', 'b10.igs'};%, 'b20.igs'}; 7 | n = numel(files); 8 | dofs=zeros(n,1); 9 | nparts=zeros(n,1); 10 | def=zeros(n,1); 11 | 12 | YM = 1e6; %in Pascals 13 | pr = 0.45; 14 | [lambda, mu] = emu_to_lame(YM, pr); 15 | 16 | options.dt = 0.1; 17 | options.order = 2; 18 | options.pin_function = @pin_function; 19 | options.gravity = -10; 20 | options.lambda = lambda; 21 | options.mu = mu; 22 | options.rho = 1e3; 23 | options.distance_cutoff = 0.501; 24 | % options.distance_cutoff = 1; 25 | options.k_stability = 1e7; 26 | options.enable_secondary_rays = 1; 27 | options.fitting_mode = 'hierarchical'; 28 | options.save_output = 0; 29 | options.save_obj = 0; 30 | options.plot_com=1; 31 | % options.plot_points = 1; 32 | options.x_samples = 100; 33 | options.y_samples = 3; 34 | options.z_samples = 3; 35 | 36 | iters=20; 37 | for i=1:n 38 | parts = nurbs_from_iges(files{i}); 39 | dofs(i) = numel(parts{1}.p)*numel(parts); 40 | [def(i),deflections] = deflection_test_step(parts,options); 41 | nparts(i) = numel(parts); 42 | figure(3); 43 | plot(1:iters, deflections); 44 | hold on; 45 | end 46 | figure(4); 47 | plot(nparts, abs(def ./ -4.1579),'LineWidth',2); 48 | xlabel('DOFs'); 49 | ylabel('m'); 50 | title('Max Deflection'); 51 | % yline(-4.1579,'Color','r'); 52 | end -------------------------------------------------------------------------------- /figures/plot_distance_weight.m: -------------------------------------------------------------------------------- 1 | clear; 2 | cut_off = 50; % threshold 3 | [d1, total] = meshgrid(0:3:150, 0:3:150); 4 | dist_w_func = @(d1, d2) (max(1.0 - d1 ./ min(d2, cut_off), 0.0)) .* (d1 <= d2); 5 | dist_w = dist_w_func(d1, total-d1); 6 | % dist_w(d1 > total - d1) = NaN; 7 | % dist_w(total - d1 < 0) = NaN; 8 | 9 | figure(1); 10 | t = surf(d1, total, dist_w); 11 | colormap summer 12 | alpha(0.5) 13 | set(t, 'edgealpha', 0.6) 14 | % shading interp 15 | xlabel('Primary Ray Length') 16 | ylabel('Total Ray Length') 17 | zlabel('Distance Weight') 18 | set(gca, 'FontName', 'Linux Biolinum') 19 | % set(gca,'XTickLabel',[]); 20 | % set(gca,'YTickLabel',[]); 21 | % set(gca,'ZTickLabel',[]); 22 | view(45, 20) 23 | 24 | print(1, './plot_distance_weight_label.pdf', '-dpdf', '-r600'); 25 | -------------------------------------------------------------------------------- /figures/raycasting_integrate_volume.m: -------------------------------------------------------------------------------- 1 | function raycasting_integrate_volume 2 | iges_file = 'trident.iges'; 3 | % iges_file = 'puft_head.iges'; 4 | % iges_file = 'sphere.iges'; 5 | 6 | figure(1); 7 | clf; 8 | parts = nurbs_from_iges(iges_file); 9 | 10 | cm=jet(numel(parts)); 11 | for ii = 1:numel(parts) 12 | plt = patch('Faces',parts{ii}.hires_T,'Vertices',parts{ii}.hires_x0', ... 13 | 'FaceAlpha',0.3,'EdgeColor','none','FaceColor',cm(ii,:)); 14 | hold on; 15 | parts{ii}.plt=plt; 16 | end 17 | 18 | set(gcf,'color','w'); 19 | axis equal 20 | lighting gouraud; 21 | lightangle(gca,0, 40) 22 | xlabel('x'); 23 | zlabel('z'); 24 | view(-15,30); 25 | 26 | nsamples = 20; 27 | x_vals = 1:nsamples; 28 | errors = zeros(size(x_vals)); 29 | true_vol = 11774.6564; % mm^3 for the trident 30 | % true_vol = 1.17697114 ; % rounded cube 31 | % true_vol = 5; % mm^3 for the beam 32 | % true_vol = 267.11 33 | 34 | i=2; 35 | [V, ~] = raycast_quadrature(parts, [i i], 5); 36 | 37 | V_plt = plot3(V(1,:),V(2,:),V(3,:),'.','Color','m','MarkerSize',20); 38 | V([2 3],:) = V([3 2],:); 39 | F = 1:size(V,2); 40 | writePLY('samples.ply', V', F', 'ascii'); 41 | 42 | for i = 1:nsamples 43 | [V, vols] = raycast_quadrature(parts, [i i], 5); 44 | e = abs(sum(vols) - true_vol) / true_vol; 45 | errors(i) = e; 46 | if i == 1 47 | V_plt = plot3(V(1,:),V(2,:),V(3,:),'.','Color','m','MarkerSize',20); 48 | else 49 | V_plt.XData=V(1,:); 50 | V_plt.YData=V(2,:); 51 | V_plt.ZData=V(3,:); 52 | end 53 | end 54 | 55 | clf; 56 | % semilogy(x_vals,errors); 57 | plot(x_vals,errors); 58 | title('Error as the number of samples increase in each direction'); 59 | ylabel('Relative Absolute Error'); 60 | xlabel('# Samples'); 61 | xlim([1 20]) 62 | end -------------------------------------------------------------------------------- /figures/render_puft_distance_weight.m: -------------------------------------------------------------------------------- 1 | clear; 2 | iges_file = 'puft_no_collar.iges'; 3 | parts = nurbs_from_iges(iges_file); 4 | [V,F,N,C] = triangulate_iges(parts); 5 | 6 | save_path = ['../output/']; 7 | mkdir(save_path); 8 | clf; 9 | figure(1); 10 | t = tsurf(F,V,'CData', C, 'VertexNormals', N, 'EdgeColor', 'none',... 11 | fsoft, 'FaceAlpha', 0.9, ... 12 | 'AmbientStrength', 0.8, 'SpecularStrength', 0.2, 'DiffuseStrength', 0.4); 13 | hold on 14 | CM = cbrewer('RdYlBu',20); 15 | colormap(CM); 16 | shading(gca,'interp') 17 | axis equal 18 | set(gca,'Visible','off'); 19 | bg_color = [1.0 1.0 1.0]; 20 | set(gcf,'Color',bg_color); 21 | camlight; 22 | camproj('persp'); 23 | view(0, 25); 24 | l = light('Position',[4 -4 10],'Style','infinite'); 25 | add_shadow(t,l,'Color',bg_color*0.9,'BackgroundColor',bg_color,'Fade','infinite'); 26 | apply_ambient_occlusion(t,'AddLights',false,'SoftLighting',false,'Factor',0.75); 27 | hold off 28 | 29 | print(1, [save_path iges_file(1:end-5) '.png'], '-dpng', '-r400'); 30 | 31 | %% triangulate the nurbs parts 32 | function [verts,faces,normals,colors] = triangulate_iges(parts) 33 | faces=[]; 34 | verts=[]; 35 | normals=[]; 36 | colors=[]; 37 | 38 | perm = randperm(numel(parts)); 39 | for ii=1:numel(parts) 40 | if isfield(parts{ii}, 'hires_T') 41 | F = parts{ii}.hires_T; 42 | V = parts{ii}.hires_x0'; 43 | N = nurbs_normals(parts{ii}.srf.nurbs, parts{ii}.hires_UV, parts{ii}.p); 44 | else 45 | F = parts{ii}.T; 46 | V = parts{ii}.x0'; 47 | N = nurbs_normals(parts{ii}.srf.nurbs, parts{ii}.UV, parts{ii}.p); 48 | end 49 | F = F + size(verts,1); 50 | faces=[faces; F]; 51 | verts=[verts; V]; 52 | normals=[normals; N]; 53 | colors = [colors; repmat(perm(ii), size(V,1), 1)]; 54 | end 55 | % check and remove degenerate faces 56 | dblA = doublearea(verts,faces); 57 | deg_fid = find(dblA <= 0); 58 | faces(deg_fid, :) = []; 59 | end 60 | -------------------------------------------------------------------------------- /figures/test_slice_tets.m: -------------------------------------------------------------------------------- 1 | % Tet mesh in (V,T) 2 | [SV, SF] = readOBJ('/Users/honglin/Documents/MATLAB/chordal-coarsening/admm_yifan_test/test/data/input/common-3d-test-models/data/spot.obj'); 3 | [V,T,F] = tetgen(SV,SF); 4 | F = boundary_faces(T); 5 | % Solve poisson equation for interesting function inside 6 | L = cotmatrix(V,T); 7 | M = massmatrix(V,T); 8 | b = unique(F); 9 | int = setdiff(1:size(V,1),b); 10 | H = zeros(size(V,1),1); 11 | H(int) = (-L(int,int))\(M(int,int)*ones(numel(int),1)); 12 | clf; 13 | t = tsurf(F,V,'FaceColor',[0.8 0.8 0.8],'FaceAlpha',0.2,'EdgeAlpha',0.2); 14 | hold on; 15 | s = tsurf([1 1 1],V,'EdgeColor','none',fphong); 16 | BB = bounding_box(V(:,1:2)); 17 | BB = BB([1 2 4 3 1],:); 18 | p = plot3(BB(:,1),BB(:,2),min(V(:,3))*[1;1;1;1;1],'-','LineWidth',3); 19 | hold off; 20 | caxis([min(H) max(H)]); 21 | axis equal; 22 | for z = linspace(min(V(:,3)),max(V(:,3))) 23 | [U,G,J,BC] = slice_tets(V,T,[0 0 1 -z]); 24 | set(s,'Vertices',U,'Faces',G,'CData',BC*H); 25 | p.ZData = z*[1;1;1;1;1]; 26 | drawnow; 27 | end -------------------------------------------------------------------------------- /matlab/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | mex/Release/ 3 | -------------------------------------------------------------------------------- /matlab/basis_size.m: -------------------------------------------------------------------------------- 1 | function k = basis_size(d, order) 2 | k=0; 3 | % Iteration starts at 1 (rather than 0) because our monomial basis 4 | % excludes the constant term (we globally solve for 1 constant term) 5 | for i=1:order 6 | k=k+nchoosek(d+i-1,i); 7 | end 8 | end -------------------------------------------------------------------------------- /matlab/build_weight_matrix.m: -------------------------------------------------------------------------------- 1 | function [W,W_I,W_S] = build_weight_matrix(w, d, k, varargin) 2 | p = inputParser; 3 | addParameter(p, 'Truncate', true); 4 | addParameter(p, 'Threshold', 1e-2); 5 | parse(p,varargin{:}); 6 | 7 | truncate = p.Results.Truncate; 8 | threshold = p.Results.Threshold; 9 | 10 | m = size(w,1); % number of points 11 | n = size(w,2); % number of shapes 12 | 13 | W = cell(m,1); 14 | W_I = cell(m,1); 15 | W_S = cell(m,1); 16 | 17 | for i = 1:m 18 | 19 | if truncate 20 | ToKeep = w(i,:) > threshold; 21 | else 22 | ToKeep = ones(1,n); 23 | end 24 | 25 | % Shape indices for weights above the threshold. 26 | W_I{i} = find(ToKeep)'; 27 | t = numel(W_I{i}); 28 | 29 | % Forming selection and weight matrices. 30 | W{i} = zeros(d*k, d*k*t); 31 | W_S{i} = zeros(d*k*t, d*(k)*n); 32 | for j = 1:t 33 | I = W_I{i}(j); 34 | 35 | col_range = d*k*(j-1)+1:d*k*j; 36 | W{i}(:, col_range) = eye(d*k)*w(i,I); 37 | 38 | 39 | row_range = d*k*(j-1)+1 : d*k*j; 40 | col_range = d*k*(I-1)+1:d*k*I; 41 | W_S{i}(row_range, col_range) = eye(d*k); 42 | end 43 | end 44 | end -------------------------------------------------------------------------------- /matlab/cantileaver_sim.m: -------------------------------------------------------------------------------- 1 | %cantileaver simulation 2 | [V,T,F] = readMESH('vem_beam_tet2.mesh'); 3 | 4 | writeOBJ('vem_2.obj',V,F); 5 | %setup simulation variables 6 | 7 | %tet volumes 8 | vol = volume(V,T); 9 | 10 | %triangle gradients 11 | dphidX = linear_tetmesh_dphi_dX(V,T); 12 | 13 | %Mass Matrix 14 | rho = 1000.0*ones(size(T,1),1); 15 | M = linear_tetmesh_mass_matrix(V,T, rho, vol); 16 | 17 | %material properties 18 | YM = 1e6; %in Pascals 19 | pr = 0.45; 20 | [lambda, mu] = emu_to_lame(YM*ones(size(T,1),1), pr*ones(size(T,1),1)); 21 | 22 | %boundary conditions are fun 23 | min_I = find(V(:,1) == min(V(:,1))); 24 | P = fixed_point_constraint_matrix(V, sort(min_I)); 25 | 26 | %external forces 27 | gravity = [0 -10 0]'; % We are on krypton 28 | gravity = P*M*repmat(gravity, size(V,1),1); 29 | 30 | %project mass matrix down 31 | M = P*M*P'; 32 | 33 | %warm up the display 34 | [~,p] = nice_plot(V,F); 35 | 36 | %simulation setup and loop 37 | energy_func = @(a,b, c, d, e) linear_tetmesh_neohookean_q(a,b,c,d,e,[0.5*mu, 0.5*lambda]); 38 | gradient_func = @(a,b, c, d, e) linear_tetmesh_neohookean_dq(a,b,c,d,e,[0.5*mu, 0.5*lambda]); 39 | hessian_func = @(a,b, c, d, e) linear_tetmesh_neohookean_dq2(a,b,c,d,e,[0.5*mu, 0.5*lambda], 'fixed'); 40 | 41 | dt = 0.1; 42 | 43 | qt = reshape(V', 3*size(V,1),1); 44 | 45 | %setup all thw variables I need using bc projection matrix 46 | b = qt - P'*P*qt; 47 | qt = P*qt; 48 | vt = 0*qt; 49 | 50 | 51 | disp('Press SPACEBAR to CONTINUE'); 52 | pause 53 | 54 | h = text(0.5*(max(V(:,1)) + min(V(:,1))), 0.9*max(V(:,2)), num2str(0)); 55 | h.FontSize = 28; 56 | 57 | for ti=1:500 58 | if ti == 200 59 | writeOBJ('vem_200.obj',p.Vertices,F); 60 | end 61 | h.String = num2str(ti); 62 | 63 | g = -M*vt + ... 64 | dt*P*gradient_func(V,T, P'*qt+b, dphidX, vol) + ... 65 | - dt*gravity; 66 | 67 | H = M + dt*dt*P*hessian_func(V,T, P'*qt+b, dphidX, vol)*P'; 68 | 69 | vt = -H\g; 70 | qt = qt + dt*vt; 71 | 72 | p.Vertices = reshape(P'*qt + b, 3, size(V,1))'; 73 | drawnow; 74 | end 75 | -------------------------------------------------------------------------------- /matlab/cutoff_heuristic.m: -------------------------------------------------------------------------------- 1 | function cutoff_distance=cutoff_heuristic(parts, T, n, X) 2 | % Choose cutoff distance based on desired level of sparsity of blending 3 | % weights. 4 | % 5 | % Given a target sparsity, T, heuristic searches for the distance 6 | % cutoff that produces the desired level of sparsity, meaning that the 7 | % ratio of nonzeros to total elements in the set of blending equals T. 8 | % 9 | % Arguments: 10 | % parts: cell array containing each part of model 11 | % T: the target sparsity ratio in (0, 1] 12 | % n (optional): the number of cutoff distance candidates to generate 13 | % X (optional): the set of points on which distance weights are computed 14 | % 15 | if nargin < 3 16 | n = 20; 17 | end 18 | 19 | if nargin < 4 20 | YZ_samples = [9 9]; 21 | X_samples = 5; 22 | [X, ~] = raycast_quadrature(parts, YZ_samples, X_samples); 23 | X = X'; 24 | end 25 | 26 | % Find max possible cutoff 27 | x = []; 28 | for i=1:numel(parts) 29 | x = [x parts{i}.x0]; 30 | end 31 | min_bnd = min(x, [], 2); 32 | max_bnd = max(x, [], 2); 33 | max_d = max(max_bnd-min_bnd); 34 | 35 | % candidate cutoff values 36 | cutoff_vals = linspace(0,max_d, n+1); 37 | cutoff_vals = cutoff_vals(2:end); 38 | 39 | % Binary search for clostest distance cutoff that satifies the 40 | % sparsity objective. 41 | L = 1; 42 | R = numel(cutoff_vals); 43 | eps = 1e-5; 44 | sparsity = zeros(numel(cutoff_vals),1); 45 | 46 | T = 1 - T; 47 | while L <= R 48 | index = floor((L + R) / 2); 49 | 50 | c = cutoff_vals(index); 51 | 52 | w = distance_weights(parts, X, c, true); 53 | sparsity(index) = sum(w(:) > eps) / numel(w); 54 | 55 | if sparsity(index) < T 56 | L = index + 1; 57 | elseif sparsity(index) > T 58 | R = index - 1; 59 | else 60 | break; 61 | end 62 | end 63 | cutoff_distance = cutoff_vals(index); 64 | end -------------------------------------------------------------------------------- /matlab/deprecated/cube_anim_example.m: -------------------------------------------------------------------------------- 1 | function quadratic_rounded_cube 2 | 3 | function pinned_ids = pin_function(x) 4 | % pinning corner points of the cube 5 | x_min = 0.4; 6 | y_min = 0.4; 7 | pinned_ids = find(x(1,:) > x_min & x(2,:) > y_min); 8 | 9 | % verts_to_pin = 9; 10 | % [~,I] = mink(x(3,:),verts_to_pin); 11 | % pinned_ids = I(1:verts_to_pin); 12 | end 13 | 14 | iges_file = 'rounded_cube.iges'; 15 | part = nurbs_from_iges(iges_file); 16 | YM = 1e5; %in Pascals 17 | % YM = 1e6; %in Pascals 18 | pr = 0.45; 19 | [lambda, mu] = emu_to_lame(YM, pr); 20 | options.order = 2; 21 | options.rho = 1e2; % for compression example 22 | options.rho = 1e1; 23 | options.pin_function = @pin_function; 24 | options.lambda = lambda; 25 | options.mu = mu; 26 | 27 | options.distance_cutoff=cutoff_heuristic(part, 0.9); 28 | 29 | % uncomment to effectively perform single shape matching 30 | % options.enable_secondary_rays = 0; 31 | % options.distance_cutoff = 100; 32 | % options.gravity = -400; % for compression 33 | 34 | % options.save_obj=1; 35 | vem_simulate_nurbs_cube_anim(part, options); 36 | 37 | end -------------------------------------------------------------------------------- /matlab/deprecated/experiments/test_hcs.m: -------------------------------------------------------------------------------- 1 | function test_hcs 2 | parts = nurbs_from_iges('puft_head.iges'); 3 | parts = nurbs_from_iges('beam2.igs'); 4 | % parts = nurbs_from_iges('rounded_cube.iges'); 5 | figure(1) 6 | clf; 7 | parts=nurbs_plot(parts); 8 | 9 | n = numel(parts); 10 | % Assembles global generalized coordinates 11 | [~, ~, ~, E, x0] = nurbs_assemble_coords(parts); 12 | 13 | com_threshold = 50; 14 | distance_cutoff = 50; 15 | distance_cutoff = 1.5; 16 | 17 | % Generating centers of mass. Temporary method! 18 | x0_coms = generate_com(parts, x0, E, com_threshold, n); 19 | 20 | plot3(x0_coms(1,:),x0_coms(2,:),x0_coms(3,:), ... 21 | '.','Color','r','MarkerSize',20); 22 | hold on; 23 | 24 | [V, ~] = raycast_quadrature(parts, [3 3], 10); 25 | Vplot=plot3(V(1,:),V(2,:),V(3,:),'.','Color','m','MarkerSize',10); 26 | 27 | [w, w_I] = nurbs_blending_weights(parts, V', distance_cutoff); 28 | % [w, w_I] = nurbs_blending_weights(parts, x0', distance_cutoff); 29 | 30 | g = zeros(n,n); % creat a graph 31 | 32 | [wids, ~, ic] = unique(w > 1e-4, 'rows'); 33 | w_vals = zeros(size(wids)); 34 | w_num = sum(wids,2) 35 | for i=1:size(w,2) 36 | w_vals(:,i) = accumarray(ic, w(:,i), [], @mean); 37 | end 38 | 39 | for i=1:size(wids,1) 40 | ids = find(wids(i,:)); 41 | if numel(ids) > 1 42 | edges = nchoosek(ids,2); 43 | w_val = w_vals(i,edges(:,1)) + w_vals(i,edges(:,2)); 44 | idx1= sub2ind(size(g),edges(:,1),edges(:,2)); 45 | idx2= sub2ind(size(g),edges(:,2),edges(:,1)); 46 | g(idx1) = g(idx1) + w_val'; 47 | g(idx2) = g(idx2) + w_val'; 48 | % g(idx1) = 1; 49 | % g(idx2) = 1; 50 | end 51 | end 52 | 53 | G = graph(g); 54 | [mv, mw] = mincut(g) 55 | % H = plot(G,'Layout','layered'); 56 | % [mf,asdf,cs,ct] = maxflow(G,n+1,n+2) 57 | % highlight(H,cs,'NodeColor','red') 58 | % highlight(H,ct,'NodeColor','green') 59 | end -------------------------------------------------------------------------------- /matlab/deprecated/experiments/test_normals.m: -------------------------------------------------------------------------------- 1 | function test_normals 2 | clf; 3 | parts=nurbs_from_iges('rounded_cube.iges'); 4 | parts=nurbs_plot(parts); 5 | 6 | N = nurbs_normals(parts{1}.srf.nurbs, parts{1}.UV, parts{1}.p); 7 | 8 | % Create line segment along normal 9 | p1 = parts{1}.x0; 10 | p2 = parts{1}.x0 + 10*N'; 11 | 12 | % Plotting normals 13 | plot3([p1(1,:); p2(1,:)],[p1(2,:); p2(2,:)],[p1(3,:); p2(3,:)], ... 14 | 'LineWidth', 3); 15 | end 16 | -------------------------------------------------------------------------------- /matlab/deprecated/experiments/test_raycast_mug.m: -------------------------------------------------------------------------------- 1 | function test_raycast_mug 2 | iges_file = 'mug_models/mug_intersect_2.igs'; 3 | % iges_file = 'beams/beam2.igs'; 4 | iges_file = 'starship.iges'; 5 | % iges_file = 'trident.iges'; 6 | % iges_file = 'wrench.iges'; 7 | 8 | fig=figure(1); 9 | clf; 10 | parts = nurbs_from_iges(iges_file); 11 | 12 | cm=jet(numel(parts)); 13 | for ii = 1:numel(parts) 14 | plt = patch('Faces',parts{ii}.hires_T,'Vertices',parts{ii}.hires_x0', ... 15 | 'FaceAlpha',0.2,'EdgeColor','none','FaceColor',cm(ii,:)); 16 | hold on; 17 | parts{ii}.plt=plt; 18 | end 19 | 20 | set(gcf,'color','w'); 21 | axis equal 22 | lighting gouraud; 23 | lightangle(gca,0, 40) 24 | xlabel('x'); 25 | zlabel('z'); 26 | view(-15,30); 27 | 28 | 29 | [V, ~] = raycast_quadrature(parts, [1 20], 5); 30 | [V, ~] = raycast_quadrature(parts, [3 3], 5); 31 | plot3(V(1,:),V(2,:),V(3,:),'.','Color','m','MarkerSize',20); 32 | end -------------------------------------------------------------------------------- /matlab/deprecated/experiments/vem_2d_test_matching.m: -------------------------------------------------------------------------------- 1 | function vem_2d_test_matching 2 | % Simulation parameters 3 | order = 1; % (1 or 2) linear or quadratic deformation 4 | d = 2; % dimension (2 or 3) 5 | save_output = 0; % (0 or 1) whether to output images of simulation 6 | 7 | % The number of elements in the monomial basis. 8 | k = basis_size(1, order); 9 | 10 | % Shape matching modes: 11 | % mode = 'global'; % global solve with regular inverse 12 | % mode = 'global_pinv'; % global solve with pseudoinverse 13 | % mode = 'global_svd_truncated'; % global solve with truncated svd inv 14 | % mode = 'local'; 15 | mode = 'local_pinv'; 16 | % mode = 'local_svd_truncated'; 17 | 18 | offset = 0; 19 | shape_func = @(a,n) ((a - offset).^n); 20 | 21 | range = [0 1]; 22 | samples = [20 30]; 23 | n = 1; 24 | n_end = 5; 25 | x = linspace(range(1), range(2), samples(1)); 26 | y = shape_func(x,n); 27 | 28 | y_com = mean(y); 29 | L = compute_shape_matrices(y, y_com, {1:samples(1)}, order, mode); 30 | 31 | c = L * y(:); 32 | 33 | x0 = linspace(range(1), range(2), samples(2)); 34 | x0_com = mean(x0); 35 | 36 | M = monomial_basis(x0, x0_com, order); 37 | 38 | y0 = c(1:k)' * M + c(end); 39 | 40 | clf; 41 | plot(x,y); 42 | hold on; 43 | plot(x0,y0,'.','MarkerSize',20); 44 | axis equal; 45 | 46 | deformations=100; 47 | n_vals = linspace(n,n_end, deformations); 48 | 49 | 50 | for i=1:deformations 51 | clf; 52 | y_new = shape_func(x, n_vals(i)); 53 | c = L * y_new(:); 54 | y_pred = c(1:k)' * M + c(end); 55 | plot(x,y_new); 56 | hold on; 57 | plot(x0,y_pred,'.','MarkerSize',20); 58 | axis equal; 59 | legend('Deformed Positions', 'Predicted positions','Location','northwest'); 60 | drawnow; 61 | end 62 | 63 | end -------------------------------------------------------------------------------- /matlab/deprecated/experiments/vem_fitting_test2.m: -------------------------------------------------------------------------------- 1 | function vem_fitting_test2 2 | %polynomial fitting test 3 | %define quadratic projection for 3 point line 4 | %idea: shape match should minimize deformation 5 | %conjecture: corresponsds to keeping higher order terms as close to zero 6 | %as possible 7 | %requirement: surface patch must at least be able to uniquely determine 8 | % the linear term (deformation gradient) 9 | % this requires explcitly setting the constant term as we've been doing 10 | 11 | V = [-1 1; 0 1; 1 1]; 12 | 13 | V_hires = [linspace(-1,1, 100)' linspace(1,1, 100)']; 14 | q = igl2bart(V); 15 | 16 | COM = [0 0.9]; 17 | 18 | L = compute_shape_matrices(V', COM', {[1 2 3]}, 2, 'hierarchical'); 19 | Y = monomial_basis_matrix(V_hires', COM', 2, 5); 20 | 21 | for jj = 1:50 22 | 23 | q(3) = q(3) + 0.01; 24 | q(4) = q(4) + 0.1; 25 | 26 | c = L*(q); 27 | 28 | q_outx = squeeze(Y(:,1,:)) * c(1:end-2) + c(end-1); 29 | q_outy = squeeze(Y(:,2,:)) * c(1:end-2) + c(end); 30 | q_out = [q_outx'; q_outy']; 31 | q_out = q_out(:); 32 | 33 | plot(q_out(1:2:end), q_out(2:2:end)); 34 | axis([-1 1 0 5]); 35 | hold on 36 | plot(q_out(1:2:end), q_out(2:2:end), 'b*'); 37 | 38 | plot(q(1:2:end), q(2:2:end), 'g'); 39 | plot(q(1:2:end), q(2:2:end), 'g*'); 40 | hold off 41 | 42 | pause(0.1) 43 | drawnow 44 | 45 | end 46 | end -------------------------------------------------------------------------------- /matlab/deprecated/vem3dmesh_neohookean_dq_matlab.m: -------------------------------------------------------------------------------- 1 | function [f] = vem3dmesh_neohookean_dq_matlab(x, c, vol, params, dF_dc, dF_dc_S, ME, L, ... 2 | k, n, d, m, x0_coms_size, k_stability) 3 | 4 | % Force vector 5 | dV_dq = zeros(d*(k*n + x0_coms_size),1); 6 | 7 | % Computing force dV/dq for each point. 8 | % TODO: move this to C++ :) 9 | for i = 1:m 10 | % Deformation Gradient 11 | F = dF_dc{i} * dF_dc_S{i} * c; 12 | F = reshape(F,d,d); 13 | 14 | % Force vector 15 | dV_dF = neohookean_tet_dF(F, params(i,1), params(i,2)); 16 | dV_dq = dV_dq + dF_dc_S{i}' * dF_dc{i}' * dV_dF * vol(i); 17 | end 18 | dV_dq = L' * dV_dq; 19 | 20 | % Error correction force 21 | f_error = - 2 * ME * x(:); 22 | f_error = k_stability*f_error(:); 23 | 24 | % Force from potential energy. 25 | f_internal = -dV_dq; 26 | 27 | f = f_internal + f_error; 28 | end 29 | 30 | -------------------------------------------------------------------------------- /matlab/deprecated/vem_error_matrix_matlab.m: -------------------------------------------------------------------------------- 1 | function ME = vem_error_matrix(Y, Y_S, L, d) 2 | m = size(Y,1); 3 | M1 = zeros(size(L,1),size(L,1)); 4 | M2 = zeros(size(L,1),size(L,2)); 5 | M3 = eye(size(L,2)); 6 | for i=1:m 7 | M1 = M1 + Y_S{i}'*(Y{i}'*Y{i})*Y_S{i}; 8 | M2(:,d*(i-1)+1:d*i) = Y_S{i}'*Y{i}'; 9 | end 10 | ME = L'*M1*L - L'*M2 - M2'*L + M3; 11 | end -------------------------------------------------------------------------------- /matlab/deprecated/vem_mass_matrix_matlab.m: -------------------------------------------------------------------------------- 1 | function M = vem_mass_matrix(Y, Y_S, L, mass) 2 | m = size(Y,1); 3 | M = zeros(size(L,1), size(L,1)); 4 | for i=1:m 5 | M = M + Y_S{i}'*(Y{i}'*Y{i})*Y_S{i} * mass(i); 6 | end 7 | M = L' * M * L; 8 | end -------------------------------------------------------------------------------- /matlab/deprecated/write_obj_per_part.m: -------------------------------------------------------------------------------- 1 | function nurbs_write_obj(q, parts, path, ii) 2 | faces=[]; 3 | verts=[]; 4 | normals = []; 5 | 6 | q_idx = 0; 7 | for i=1:numel(parts) 8 | 9 | qi = q(q_idx+1:q_idx+numel(parts{i}.p)); 10 | xi = squeeze(sum(parts{i}.hires_J .* qi,1)); 11 | 12 | % faces_i = parts{i}.hires_T + size(verts,1); 13 | % normals_i = nurbs_normals(parts{i}.srf.nurbs, parts{i}.hires_UV, parts{i}.p); 14 | % faces=[faces; faces_i]; 15 | % verts=[verts; xi']; 16 | % normals=[normals; normals_i]; 17 | 18 | obj_fn = "output/obj/part_" + i + "_" + int2str(ii) + ".obj"; 19 | writeOBJ(obj_fn, xi', parts{i}.hires_T); 20 | q_idx = q_idx + numel(parts{i}.p); 21 | end 22 | 23 | % you better have gptoolbox, son 24 | % writeOBJ(path, verts, faces);%;, [], zeros(size(faces,1),3), normals, zeros(size(faces,1),3)); 25 | end 26 | 27 | -------------------------------------------------------------------------------- /matlab/distance_weights.m: -------------------------------------------------------------------------------- 1 | function w = distance_weights(parts, X, alpha, enable_secondary_rays) 2 | m=size(X,1); 3 | n=numel(parts); 4 | 5 | % Weights 6 | w = zeros(m,n); 7 | 8 | % Compute per-shape distance weights 9 | for i = 1:n 10 | if isfield(parts{i}, 'hires_T') 11 | F = parts{i}.hires_T; 12 | V = parts{i}.hires_x0'; 13 | else 14 | F = parts{i}.T; 15 | V = parts{i}.x0'; 16 | end 17 | 18 | % Find closest points on the surface for each point. 19 | [sqrD,~,surf_X] = point_mesh_squared_distance(X,V,F); 20 | dist = sqrt(sqrD); 21 | 22 | if enable_secondary_rays 23 | rays = X - surf_X; 24 | rays = rays ./ vecnorm(rays,2,2); 25 | 26 | faces=[]; 27 | verts=[]; 28 | for j = [ [1:i-1] [i+1:n] ] 29 | if isfield(parts{j}, 'hires_T') 30 | F = parts{j}.hires_T; 31 | V = parts{j}.hires_x0'; 32 | else 33 | F = parts{j}.T; 34 | V = parts{j}.x0'; 35 | end 36 | F = F + size(verts,1); 37 | faces=[faces; F]; 38 | verts=[verts; V]; 39 | end 40 | 41 | % Shoot rays from each surface point through the query points. 42 | % If the hit points are within the cutoff distance, use the 43 | % distance between the surface point (surf_X) and the hit 44 | % point. 45 | [~, t] = ray_mesh_intersect(surf_X, rays, verts, faces); 46 | min_ray_dist = t; 47 | 48 | bound = min(alpha, min_ray_dist); 49 | else 50 | bound = alpha; 51 | end 52 | w(:,i) = min(max(1 - (abs(dist) ./ bound), 0), 1); 53 | end 54 | 55 | end -------------------------------------------------------------------------------- /matlab/mex/ray_mesh_intersections.m: -------------------------------------------------------------------------------- 1 | % RAY_MESH_INTERSECTIONS Find all hits (if it exists) for each ray. 2 | % 3 | % [flag, t] = ray_mesh_intersections(src, dir, V, F, k); 4 | % 5 | % Input: 6 | % src #rays by 3 list of 3D vector ray origins 7 | % dir #rays by 3 list of 3D vector ray directions 8 | % V #V by 3 list of vertex positions 9 | % F #F by 3 list of triangle indices 10 | % Output: 11 | % id #rays by k list of indices into F (0 if no hit) 12 | % t #rays by k list of distances from the ray origin (inf if no hit) 13 | % 14 | -------------------------------------------------------------------------------- /matlab/mex/vem3dmesh_neohookean_dq.m: -------------------------------------------------------------------------------- 1 | % VEM2DMESH_NEOHOOKEAN_Q Compute the energy of Neohookean potential 2 | % energy for a virtual element mesh 3 | % 4 | % 5 | % Inputs: 6 | % A 2 by k shape matching matrix where k is the size of the 7 | % monomial vectors 8 | % dF_dq M by (2*2 * 2*N) gradient of deformation energy (F) with 9 | % respect to the elements' configuration 10 | % vectors (N is the # of points for this 11 | % element) 12 | % dM_dX M by (k*2) energy of the monomial basis vector with respect 13 | % to the undeformed positions. 14 | % w M by 1 list of weights 15 | % volume M by 1 list of per point volumes 16 | % [C,D] M by 2 material parameters matrix. 17 | % k scalar size of the monomial vectors 18 | % N scalar the # of points for this element 19 | % 20 | % Outputs: 21 | % g 2*N by 1 energy vector 22 | % 23 | % Example: 24 | % % mesh (V,T) 25 | % vol = volume(V,T); %using gptoolbox volume command 26 | % dphidX = linear_tetmesh_dphi_dphidX(V,T); 27 | % q = reshape(V', 3*size(V,1), 1) %initial mesh position 28 | % YM = 2e6; %in Pascals 29 | % pr = 0.45 30 | % [lambda, mu] = emu_to_lame(YM*ones(size(T,1),1), pr*ones(size(T,1),1)); 31 | % g = vem2dmesh_neohookean_dq(V,T,q,dphidX,vol,[0.5*mu,0.5*lambda]); -------------------------------------------------------------------------------- /matlab/mex/vem3dmesh_neohookean_dq2.m: -------------------------------------------------------------------------------- 1 | % VEM2DMESH_NEOHOOKEAN_DQ Compute the gradient of Neohookean potential 2 | % energy for a virtual element mesh 3 | % 4 | % 5 | % Inputs: 6 | % A 2 by k shape matching matrix where k is the size of the 7 | % monomial vectors 8 | % dF_dq M by (2*2 * 2*N) gradient of deformation gradient (F) with 9 | % respect to the elements' configuration 10 | % vectors (N is the # of points for this 11 | % element) 12 | % dM_dX M by (k*2) gradient of the monomial basis vector with respect 13 | % to the undeformed positions. 14 | % w M by 1 list of weights 15 | % volume M by 1 list of per point volumes 16 | % [C,D] M by 2 material parameters matrix. 17 | % k scalar size of the monomial vectors 18 | % N scalar the # of points for this element 19 | % 20 | % Outputs: 21 | % g 2*N by 1 gradient vector 22 | % 23 | % Example: 24 | % % mesh (V,T) 25 | % vol = volume(V,T); %using gptoolbox volume command 26 | % dphidX = linear_tetmesh_dphi_dphidX(V,T); 27 | % q = reshape(V', 3*size(V,1), 1) %initial mesh position 28 | % YM = 2e6; %in Pascals 29 | % pr = 0.45 30 | % [lambda, mu] = emu_to_lame(YM*ones(size(T,1),1), pr*ones(size(T,1),1)); 31 | % g = vem2dmesh_neohookean_dq(V,T,q,dphidX,vol,[0.5*mu,0.5*lambda]); -------------------------------------------------------------------------------- /matlab/mex/vem3dmesh_neohookean_q.m: -------------------------------------------------------------------------------- 1 | % VEM2DMESH_NEOHOOKEAN_Q Compute the energy of Neohookean potential 2 | % energy for a virtual element mesh 3 | % 4 | % 5 | % Inputs: 6 | % A 2 by k shape matching matrix where k is the size of the 7 | % monomial vectors 8 | % dF_dq M by (2*2 * 2*N) gradient of deformation energy (F) with 9 | % respect to the elements' configuration 10 | % vectors (N is the # of points for this 11 | % element) 12 | % dM_dX M by (k*2) energy of the monomial basis vector with respect 13 | % to the undeformed positions. 14 | % w M by 1 list of weights 15 | % volume M by 1 list of per point volumes 16 | % [C,D] M by 2 material parameters matrix. 17 | % k scalar size of the monomial vectors 18 | % N scalar the # of points for this element 19 | % 20 | % Outputs: 21 | % g 2*N by 1 energy vector 22 | % 23 | % Example: 24 | % % mesh (V,T) 25 | % vol = volume(V,T); %using gptoolbox volume command 26 | % dphidX = linear_tetmesh_dphi_dphidX(V,T); 27 | % q = reshape(V', 3*size(V,1), 1) %initial mesh position 28 | % YM = 2e6; %in Pascals 29 | % pr = 0.45 30 | % [lambda, mu] = emu_to_lame(YM*ones(size(T,1),1), pr*ones(size(T,1),1)); 31 | % g = vem2dmesh_neohookean_dq(V,T,q,dphidX,vol,[0.5*mu,0.5*lambda]); -------------------------------------------------------------------------------- /matlab/mex/vem3dmesh_simulate_one_step.m: -------------------------------------------------------------------------------- 1 | % VEM2DMESH_NEOHOOKEAN_Q Compute the energy of Neohookean potential 2 | % energy for a virtual element mesh 3 | % 4 | % 5 | % Inputs: 6 | % A 2 by k shape matching matrix where k is the size of the 7 | % monomial vectors 8 | % dF_dq M by (2*2 * 2*N) gradient of deformation energy (F) with 9 | % respect to the elements' configuration 10 | % vectors (N is the # of points for this 11 | % element) 12 | % dM_dX M by (k*2) energy of the monomial basis vector with respect 13 | % to the undeformed positions. 14 | % w M by 1 list of weights 15 | % volume M by 1 list of per point volumes 16 | % [C,D] M by 2 material parameters matrix. 17 | % k scalar size of the monomial vectors 18 | % N scalar the # of points for this element 19 | % 20 | % Outputs: 21 | % g 2*N by 1 energy vector 22 | % 23 | % Example: 24 | % % mesh (V,T) 25 | % vol = volume(V,T); %using gptoolbox volume command 26 | % dphidX = linear_tetmesh_dphi_dphidX(V,T); 27 | % q = reshape(V', 3*size(V,1), 1) %initial mesh position 28 | % YM = 2e6; %in Pascals 29 | % pr = 0.45 30 | % [lambda, mu] = emu_to_lame(YM*ones(size(T,1),1), pr*ones(size(T,1),1)); 31 | % g = vem2dmesh_neohookean_dq(V,T,q,dphidX,vol,[0.5*mu,0.5*lambda]); -------------------------------------------------------------------------------- /matlab/mex/vem_error_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //matlab hooks from libigl (taken directly from gptoolbox) 4 | #include 5 | #include 6 | #undef assert 7 | #define assert( isOK ) ( (isOK) ? (void)0 : (void) mexErrMsgTxt(C_STR(__FILE__<<":"<<__LINE__<<": failed assertion `"<<#isOK<<"'"< 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | /* The gateway function */ 20 | void mexFunction(int nlhs, mxArray *plhs[], 21 | int nrhs, const mxArray *prhs[]) { 22 | /* variable declarations here */ 23 | Eigen::MatrixXd g; 24 | 25 | Eigen::SparseMatrix L; 26 | EigenMatrixList Y; 27 | EigenVectorList W_I, C_I; 28 | 29 | sim::parse_cell(prhs, 0, Y); 30 | igl::matlab::parse_rhs(prhs + 1, L); 31 | sim::parse_cell_index(prhs, 2, W_I); 32 | sim::parse_cell_index(prhs, 3, C_I); 33 | int d = (int)*mxGetPr(prhs[4]); 34 | int k = (int)*mxGetPr(prhs[5]); 35 | int n = (int)*mxGetPr(prhs[6]); 36 | 37 | sim::vem_error_matrix(g, Y, L, W_I, C_I, d, k, n); 38 | 39 | igl::matlab::prepare_lhs_double(g, plhs); 40 | } -------------------------------------------------------------------------------- /matlab/mex/vem_error_matrix.m: -------------------------------------------------------------------------------- 1 | % VEM_EXT_FORCE Compute external forces for a specificed constant force 2 | % vector 3 | % 4 | % Inputs: 5 | % ext_f 3 by 1 force vector 6 | % mass M by 1 list of per point masses 7 | % Y M by 3kn gradient of deformed positions with respect to their 8 | % polynomial coefficients. 9 | % 10 | % Outputs: 11 | % g 3kn by 1 force vector for the set of coefficients where k is the 12 | % size of the monomial basis and n is the number of parts. 13 | % -------------------------------------------------------------------------------- /matlab/mex/vem_ext_force.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //matlab hooks from libigl (taken directly from gptoolbox) 4 | #include 5 | #include 6 | #undef assert 7 | #define assert( isOK ) ( (isOK) ? (void)0 : (void) mexErrMsgTxt(C_STR(__FILE__<<":"<<__LINE__<<": failed assertion `"<<#isOK<<"'"< 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | /* The gateway function */ 20 | void mexFunction(int nlhs, mxArray *plhs[], 21 | int nrhs, const mxArray *prhs[]) { 22 | /* variable declarations here */ 23 | Eigen::VectorXd g; 24 | 25 | Eigen::VectorXd ext_force, mass; 26 | 27 | EigenMatrixList Y; 28 | EigenSparseMatrixList Y_S; 29 | 30 | igl::matlab::parse_rhs_double(prhs+0, ext_force); 31 | igl::matlab::parse_rhs_double(prhs+1, mass); 32 | sim::parse_cell(prhs, 2, Y); 33 | sim::parse_cell_sparse(prhs, 3, Y_S); 34 | 35 | //sim::vem3dmesh_neohookean_dq(g, x, c, volumes, params, dF_dc, dF_dc_S, ME, L, k, n, d, x0_coms_size, k_stability); 36 | sim::vem_ext_force(g, ext_force, mass, Y, Y_S); 37 | 38 | igl::matlab::prepare_lhs_double(g, plhs); 39 | } -------------------------------------------------------------------------------- /matlab/mex/vem_ext_force.m: -------------------------------------------------------------------------------- 1 | % VEM_EXT_FORCE Compute external forces for a specificed constant force 2 | % vector 3 | % 4 | % Inputs: 5 | % ext_f 3 by 1 force vector 6 | % mass M by 1 list of per point masses 7 | % Y M by 3kn gradient of deformed positions with respect to their 8 | % polynomial coefficients. 9 | % 10 | % Outputs: 11 | % g 3kn by 1 force vector for the set of coefficients where k is the 12 | % size of the monomial basis and n is the number of parts. 13 | % -------------------------------------------------------------------------------- /matlab/mex/vem_mass_matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //matlab hooks from libigl (taken directly from gptoolbox) 4 | #include 5 | #include 6 | #undef assert 7 | #define assert( isOK ) ( (isOK) ? (void)0 : (void) mexErrMsgTxt(C_STR(__FILE__<<":"<<__LINE__<<": failed assertion `"<<#isOK<<"'"< 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | /* The gateway function */ 20 | void mexFunction(int nlhs, mxArray *plhs[], 21 | int nrhs, const mxArray *prhs[]) { 22 | /* variable declarations here */ 23 | Eigen::MatrixXd g; 24 | 25 | Eigen::VectorXd mass; 26 | Eigen::SparseMatrix L; 27 | EigenMatrixList Y; 28 | EigenVectorList W_I, C_I; 29 | 30 | sim::parse_cell(prhs, 0, Y); 31 | igl::matlab::parse_rhs(prhs+1, L); 32 | igl::matlab::parse_rhs_double(prhs + 2, mass); 33 | sim::parse_cell_index(prhs, 3, W_I); 34 | sim::parse_cell_index(prhs, 4, C_I); 35 | int d = (int)*mxGetPr(prhs[5]); 36 | int k = (int)*mxGetPr(prhs[6]); 37 | int n = (int)*mxGetPr(prhs[7]); 38 | 39 | 40 | sim::vem_mass_matrix(g, Y, L, mass, W_I, C_I, d, k, n); 41 | igl::matlab::prepare_lhs_double(g, plhs); 42 | } -------------------------------------------------------------------------------- /matlab/mex/vem_mass_matrix.m: -------------------------------------------------------------------------------- 1 | % VEM_EXT_FORCE Compute external forces for a specificed constant force 2 | % vector 3 | % 4 | % Inputs: 5 | % ext_f 3 by 1 force vector 6 | % mass M by 1 list of per point masses 7 | % Y M by 3kn gradient of deformed positions with respect to their 8 | % polynomial coefficients. 9 | % 10 | % Outputs: 11 | % g 3kn by 1 force vector for the set of coefficients where k is the 12 | % size of the monomial basis and n is the number of parts. 13 | % -------------------------------------------------------------------------------- /matlab/monomial_basis.m: -------------------------------------------------------------------------------- 1 | function Q = monomial_basis(x, x_com, order) 2 | d = size(x,1); 3 | 4 | Q = x - x_com; 5 | 6 | % TODO -- make this general 7 | if order == 2 8 | if d==1 9 | Q(2,:) = Q(1,:).^2; 10 | elseif d==2 11 | Q(3,:) = Q(1,:).^2; 12 | Q(4,:) = Q(2,:).^2; 13 | Q(5,:) = Q(1,:).*Q(2,:); 14 | else 15 | Q(4,:) = Q(1,:).^2; 16 | Q(5,:) = Q(2,:).^2; 17 | Q(6,:) = Q(3,:).^2; 18 | Q(7,:) = Q(1,:).*Q(2,:); 19 | Q(8,:) = Q(2,:).*Q(3,:); 20 | Q(9,:) = Q(3,:).*Q(1,:); 21 | end 22 | end 23 | end 24 | 25 | -------------------------------------------------------------------------------- /matlab/monomial_basis_grad.m: -------------------------------------------------------------------------------- 1 | function dM_dX = monomial_basis_grad(x, x_com, order) 2 | d = size(x,1); % dimension 3 | m = size(x,2); 4 | 5 | % Compute number of monomials 6 | k = basis_size(d, order); 7 | 8 | dM_dX = zeros(m, k, d); 9 | Q = x - x_com; 10 | 11 | % TODO -- make this general 12 | for ii = 1:m 13 | dMi_dX = zeros(k,d); 14 | dMi_dX(1:d,:) = eye(d); 15 | if order == 2 16 | if d==2 17 | dMi_dX(3,:) = [2*Q(1,ii) 0]; 18 | dMi_dX(4,:) = [0 2*Q(2,ii)]; 19 | dMi_dX(5,:) = [Q(2,ii) Q(1,ii)]; 20 | else 21 | dMi_dX(4,:) = [2*Q(1,ii) 0 0]; 22 | dMi_dX(5,:) = [0 2*Q(2,ii) 0]; 23 | dMi_dX(6,:) = [0 0 2*Q(3,ii)]; 24 | dMi_dX(7,:) = [Q(2,ii) Q(1,ii) 0]; 25 | dMi_dX(8,:) = [0 Q(3,ii) Q(2,ii)]; 26 | dMi_dX(9,:) = [Q(3,ii) 0 Q(1,ii)]; 27 | end 28 | end 29 | dM_dX(ii,:,:) = dMi_dX; 30 | end 31 | end 32 | 33 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/LScrvApp.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/LScrvApp.mexw64 -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/closestNrbLinePointIGES.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/closestNrbLinePointIGES.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/closestNrbLinePointIGES.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/closestNrbLinePointIGES.mexw64 -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/createDVGtree.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/createDVGtree.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/createDVGtree.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/createDVGtree.mexw64 -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/crvPntsSrfNURBS.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/crvPntsSrfNURBS.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/crvPntsSrfNURBS.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/crvPntsSrfNURBS.mexw64 -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/example.m: -------------------------------------------------------------------------------- 1 | % example.m plots an IGES CAD-object 2 | 3 | % Compile the c-files 4 | makeIGESmex; 5 | 6 | % Load parameter data from IGES-file. 7 | [ParameterData,EntityType,numEntityType,unknownEntityType,numunknownEntityType]=iges2matlab('IGESfiles/example.igs'); 8 | 9 | % Plot the IGES object 10 | plotIGES(ParameterData, 0, 1, 10); 11 | %FacePlot=plotIGES(ParameterData,1,1,1000,1,10,1,'r') -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/example2.m: -------------------------------------------------------------------------------- 1 | % example2.m plots an IGES CAD-object 2 | 3 | % Compile the c-files (if necessary) 4 | % makeIGESmex; 5 | 6 | % Load parameter data from IGES-file. 7 | [ParameterData,EntityType,numEntityType,unknownEntityType,numunknownEntityType]=iges2matlab('IGESfiles/example2.igs'); 8 | 9 | 10 | % Plot the IGES object 11 | plotIGES(ParameterData,2,1,30); 12 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/getDVGtree.m: -------------------------------------------------------------------------------- 1 | function DVGdata=getDVGtree(normal,pdir,sdir,MODEL,DIRVEC,MINDIRsq,MNORMAL,gridSpacingL0,newGridsMaxDist,Nvertex) 2 | % getDVGtree returns a DVG tree 3 | % 4 | % Usage: 5 | % 6 | % DVGdata=getDVGtree(normal,pdir,sdir,MODEL,DIRVEC,MINDIRsq,MNORMAL,gridSpacingL0,newGridsMaxDist,Nvertex) 7 | % 8 | % Input: 9 | % 10 | % normal - the normal vector 11 | % pdir - primary direction 12 | % sdir - secondary direction 13 | % MODEL - The model points 14 | % DIRVEC - (output from icpSrfLinRep) 15 | % MINDIRsq - (output from icpSrfLinRep) 16 | % MNORMAL - (output from icpSrfLinRep) 17 | % gridSpacingL0 - the grid spacing in tree level 0 18 | % newGridsMaxDist - the maximal distance to the model points for new grid systems 19 | % Nvertex - size of new grids. Nvertex=[N1,N2,...,Nk], size of new grids 20 | % will be [N1^3,N2^3,...,Nk^3] 21 | % 22 | % Output: 23 | % 24 | % DVGdata - A data structure 25 | % 26 | % m-file can be downloaded at 27 | % http://www.mathworks.com/matlabcentral/fileexchange/13253-iges-toolbox 28 | % 29 | % written by Per Bergstr�m 2012-03-15 30 | % 31 | % Reference 32 | % 33 | % Authors: Per Bergstr�m, Ove Edlund, and Inge S�derkvist 34 | % Title: Repeated surface registration for on-line use 35 | % Journal: The International Journal of Advanced Manufacturing Technology 36 | % Cover Date: 2011-05-01 37 | % Publisher: Springer London 38 | % Issn: 0268-3768 39 | % Pages: 677-689 40 | % Volume: 54 41 | % Issue: 5 42 | % Url: http://dx.doi.org/10.1007/s00170-010-2950-6 43 | % Doi: 10.1007/s00170-010-2950-6 44 | % 45 | 46 | 47 | ON=[normal,pdir,sdir]; 48 | 49 | T=ON'*MODEL; 50 | 51 | P0=min(T,[],2); 52 | Pb=max(T,[],2); 53 | 54 | clear T; 55 | 56 | nf=(Pb-P0)/gridSpacingL0; 57 | N0=floor(nf); 58 | P0=P0+0.5*(nf-N0)*gridSpacingL0; 59 | N0=N0+1; 60 | 61 | P0=ON*P0; 62 | 63 | clear ON Pb nf 64 | clear functions 65 | 66 | DT=delaunayTriangulation(MODEL'); 67 | Tes=uint32(DT.ConnectivityList)-1; 68 | clear DT 69 | 70 | DVGdata=createDVGtree(normal,pdir,sdir,P0,N0,gridSpacingL0,Nvertex,newGridsMaxDist,MODEL,DIRVEC,MINDIRsq,MNORMAL,Tes); 71 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2plnLS.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2plnLS.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2plnLS.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2plnLS.mexw64 -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2plnTu.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2plnTu.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2plnTu.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2plnTu.mexw64 -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2pntLS.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2pntLS.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2pntLS.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2pntLS.mexw64 -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2pntTu.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2pntTu.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2pntTu.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/icpDVGpnt2pntTu.mexw64 -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/igesToolBoxGUI.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/igesToolBoxGUI.fig -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/makeIGESmex.m: -------------------------------------------------------------------------------- 1 | function makeIGESmex() 2 | % Makefile 3 | % run 4 | % >> makeIGESmex 5 | % in MATLAB to compile the source code in the IGES-toolbox 6 | % 7 | % Remark! The compilation might take a couple of minutes 8 | 9 | listing = dir('*.c'); 10 | 11 | for i=1:length(listing) 12 | try 13 | mex(listing(i).name) 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/BasisFuns.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/BasisFuns.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/BspEval.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/BspEval.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/BspEval2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/BspEval2.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/FindSpan.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/FindSpan.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/FindSpanIncSeq.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/FindSpanIncSeq.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/LScurveApp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/LScurveApp.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/NURBScurveEval.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/NURBScurveEval.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/NURBSsurfaceEval.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/NURBSsurfaceEval.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/NURBSsurfaceRegularEval.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/NURBSsurfaceRegularEval.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/constrainingFcn.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/constrainingFcn.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/findBoundary.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/findBoundary.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/genzCGM.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/genzCGM.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/linalgR6x6.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/linalgR6x6.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/linesearchPenalty.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/linesearchPenalty.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/linesearchRcprBarrier.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/linesearchRcprBarrier.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/nrbD1D2eval.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/nrbD1D2eval.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/nrbD1D2eval2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/nrbD1D2eval2.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/offsetNURBSsrf.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/offsetNURBSsrf.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/rotMatrixCCOV.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/rotMatrixCCOV.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/rotmatCmptns.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/rotmatCmptns.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/trfExpPenalty.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/trfExpPenalty.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/trfRcprclBarrier.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/trfRcprclBarrier.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/trustRegionFuncExpPenalty.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/trustRegionFuncExpPenalty.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/trustRegionFuncRcprclBarrier.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/mexSourceFiles/trustRegionFuncRcprclBarrier.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/nrbSrfRegularEvalIGES.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/nrbSrfRegularEvalIGES.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/nrbSrfRegularEvalIGES.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/nrbSrfRegularEvalIGES.mexw64 -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/nrbevalIGES.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/nrbevalIGES.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/nrbevalIGES.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/nrbevalIGES.mexw64 -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/offsetNURBSsurface.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/offsetNURBSsurface.c -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/plotAxis.m: -------------------------------------------------------------------------------- 1 | function hA = plotAxis(OP,le,lw,fosi) 2 | % Plot of xyz-coordinate axis 3 | % 4 | % OP - point where coordinate axis starts 5 | % le - length of coordinate axis 6 | % lw - line width 7 | % fosi - font size 8 | % 9 | % hA - cell array of handle to graphical objects created by plotAxis 10 | % 11 | % m-file can be downloaded at 12 | % http://www.mathworks.com/matlabcentral/fileexchange/13253-iges-toolbox 13 | % 14 | % written by Per Bergstr�m 2015-11-22 15 | % 16 | 17 | if nargin<4 18 | fosi=14; 19 | if nargin<3 20 | lw=1.75; 21 | end 22 | end 23 | 24 | rd=[0.8500, 0.3250, 0.0980]; 25 | gr=[0.4660, 0.6740, 0.1880]; 26 | bl=[0, 0.4470, 0.7410]; 27 | 28 | textSpace=1.25; 29 | 30 | hA1=quiver3(OP(1),OP(2),OP(3),le,0,0,0,'Color',rd,'LineWidth',lw,'MaxHeadSize',0.45,'AutoScaleFactor',1.0,'AutoScale','off'); 31 | hA2=quiver3(OP(1),OP(2),OP(3),0,le,0,0,'Color',gr,'LineWidth',lw,'MaxHeadSize',0.45,'AutoScaleFactor',1.0,'AutoScale','off'); 32 | hA3=quiver3(OP(1),OP(2),OP(3),0,0,le,0,'Color',bl,'LineWidth',lw,'MaxHeadSize',0.45,'AutoScaleFactor',1.0,'AutoScale','off'); 33 | 34 | hA4=text('String','x','Position',[OP(1)+textSpace*le,OP(2),OP(3)],'HorizontalAlignment','center','VerticalAlignment','middle','FontSize',fosi,'Color',rd); 35 | hA5=text('String','y','Position',[OP(1),OP(2)+textSpace*le,OP(3)],'HorizontalAlignment','center','VerticalAlignment','middle','FontSize',fosi,'Color',gr); 36 | hA6=text('String','z','Position',[OP(1),OP(2),OP(3)+textSpace*le],'HorizontalAlignment','center','VerticalAlignment','middle','FontSize',fosi,'Color',bl); 37 | 38 | if nargout>0 39 | 40 | hA=cell(6,1); 41 | hA{1}=hA1; 42 | hA{2}=hA2; 43 | hA{3}=hA3; 44 | hA{4}=hA4; 45 | hA{5}=hA5; 46 | hA{6}=hA6; 47 | 48 | end 49 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/resources/addons_core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1.7 5 | Toolbox 6 | e5520973-4a80-11e4-9553-005056977bd0 7 | Toolbox for working with IGES CAD-models in Matlab 8 | The Matlab function "iges2matlab" extracts parameter data in an IGES file into Matlab. Other functions in the toolbox do plots, transformations, projections etc. All users must first compile the C-source code. This is done in Matlab by running 9 | makeIGESmex 10 | 11 | and the mex-functions are compiled. 12 | 13 | Other Requirements 14 | 15 | Some C-compiler must be installed. 16 | 17 | resources/screenshot.png 18 | 19 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/resources/matlab_path_entries.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | . 4 | mexSourceFiles 5 | IGESfiles 6 | 7 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/resources/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/matlab/nurbs_utils/IGES Toolbox/resources/screenshot.png -------------------------------------------------------------------------------- /matlab/nurbs_utils/IGES Toolbox/transformSTL.m: -------------------------------------------------------------------------------- 1 | function VertexData=transformSTL(VertexData,R,T) 2 | % TRANSFORMSTL transform vertices in VertexData from a STL file 3 | % using a rotation or a reflection and a translation. 4 | % 5 | % Usage: 6 | % 7 | % VertexData=transformSTL(VertexData,R,T) 8 | % 9 | % Input: 10 | % 11 | % VertexData - Vertex data from STL file. VertexData 12 | % is the output from STL2MATLAB. 13 | % R - Rotation/reflection matrix. eye(3) default. 14 | % T - Translation vector. zeros(3,1) default. 15 | % 16 | % Output: 17 | % 18 | % VertexData - Transformed vertex data. 19 | % 20 | % vertex=R*vertex+T 21 | % 22 | % m-file can be downloaded at 23 | % http://www.mathworks.com/matlabcentral/fileexchange/13253-iges-toolbox 24 | % 25 | % written by Per Bergstr�m 2012-02-16 26 | % 27 | 28 | if nargin<3 29 | T=zeros(3,1); 30 | if nargin<2 31 | R=eye(3); 32 | if nargin <1 33 | error('transformSTL must have inputs!'); 34 | end 35 | end 36 | end 37 | 38 | if not(iscell(VertexData)) 39 | error('VertexData must be a cell array!'); 40 | end 41 | 42 | [mR,nR]=size(R); 43 | 44 | if or(mR~=nR,mR~=3) 45 | mR=3; 46 | nR=3; 47 | R=eye(3); 48 | elseif or(norm(R'*R-eye(3),'fro')>1e-12,not(or(abs(det(R)-1)<1e-12,abs(det(R)+1)<1e-12))) 49 | error('R must be a rotation matrix or a reflection matrix'); 50 | end 51 | 52 | [mT,nT]=size(T); 53 | 54 | if or(mT==0,nT==0) 55 | T=zeros(3,1); 56 | elseif mTeps 29 | xold=x; 30 | 31 | P(:,1)=1; P(:,2)=x; 32 | 33 | for k=2:N 34 | P(:,k+1)=( (2*k-1)*x.*P(:,k)-(k-1)*P(:,k-1) )/k; 35 | end 36 | 37 | x=xold-( x.*P(:,N1)-P(:,N) )./( N1*P(:,N1) ); 38 | 39 | end 40 | % Linear map from[-1,1] to [a,b] 41 | x=(a*(1-x)+b*(1+x))/2; 42 | w=(b-a)./(N*N1*P(:,N1).^2); -------------------------------------------------------------------------------- /matlab/nurbs_utils/lgwt.m: -------------------------------------------------------------------------------- 1 | function [x,w]=lgwt(N,a,b) 2 | % lgwt.m 3 | % 4 | % This script is for computing definite integrals using Legendre-Gauss 5 | % Quadrature. Computes the Legendre-Gauss nodes and weights on an interval 6 | % [a,b] with truncation order N 7 | % 8 | % Suppose you have a continuous function f(x) which is defined on [a,b] 9 | % which you can evaluate at any x in [a,b]. Simply evaluate it at all of 10 | % the values contained in the x vector to obtain a vector f. Then compute 11 | % the definite integral using sum(f.*w); 12 | % 13 | % Written by Greg von Winckel - 02/25/2004 14 | N=N-1; 15 | N1=N+1; N2=N+2; 16 | xu=linspace(-1,1,N1)'; 17 | % Initial guess 18 | y=cos((2*(0:N)'+1)*pi/(2*N+2))+(0.27/N1)*sin(pi*xu*N/N2); 19 | % Legendre-Gauss Vandermonde Matrix 20 | L=zeros(N1,N2); 21 | % Derivative of LGVM 22 | Lp=zeros(N1,N2); 23 | % Compute the zeros of the N+1 Legendre Polynomial 24 | % using the recursion relation and the Newton-Raphson method 25 | y0=2; 26 | % Iterate until new points are uniformly within epsilon of old points 27 | while max(abs(y-y0))>eps 28 | 29 | 30 | L(:,1)=1; 31 | Lp(:,1)=0; 32 | 33 | L(:,2)=y; 34 | Lp(:,2)=1; 35 | 36 | for k=2:N1 37 | L(:,k+1)=( (2*k-1)*y.*L(:,k)-(k-1)*L(:,k-1) )/k; 38 | end 39 | 40 | Lp=(N2)*( L(:,N1)-y.*L(:,N2) )./(1-y.^2); 41 | 42 | y0=y; 43 | y=y0-L(:,N2)./Lp; 44 | 45 | end 46 | % Linear map from[-1,1] to [a,b] 47 | x=(a*(1-y)+b*(1+y))/2; 48 | % Compute the weights 49 | w=(b-a)./((1-y.^2).*Lp.^2)*(N2/N1)^2; -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_blending_weights.m: -------------------------------------------------------------------------------- 1 | function [w,w_I] = nurbs_blending_weights(parts, X, alpha, varargin) 2 | p = inputParser; 3 | addParameter(p, 'Truncate', true); 4 | addParameter(p, 'Threshold', 1e-4); 5 | addParameter(p, 'Enable_Secondary_Rays', true); 6 | parse(p,varargin{:}); 7 | 8 | truncate = p.Results.Truncate; 9 | threshold = p.Results.Threshold; 10 | enable_secondary_rays = p.Results.Enable_Secondary_Rays; 11 | 12 | m=size(X,1); 13 | n=numel(parts); 14 | w_I = cell(m,1); 15 | 16 | % Compute per-shape distance weights 17 | w = distance_weights(parts, X, alpha, enable_secondary_rays); 18 | 19 | % Compute weighting coefficients with constraints 20 | options = optimoptions('quadprog','Display', 'off'); 21 | 22 | % Quadratic program for each point that solves for the final blending 23 | % weights. 24 | for i = 1:m 25 | H = diag(1./w(i,:)); 26 | H(isinf(H)) = 1e8; 27 | f = zeros(n,1); 28 | 29 | Aeq = ones(1,n); 30 | beq = 1; 31 | 32 | ub = ones(n,1); 33 | lb = zeros(n,1); 34 | w(i,:) = quadprog(H, f, [], [], Aeq, beq, lb, ub, [], options); 35 | 36 | % If truncate is enabled, make all weights above the threshold. 37 | % This will simplify other terms, making things much faster. 38 | if truncate 39 | ToKeep = w(i,:) > threshold; 40 | else 41 | ToKeep = ones(1,n); 42 | end 43 | 44 | % Shape indices for weights above the threshold. 45 | w_I{i} = find(ToKeep)'; 46 | end 47 | end -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_coords.m: -------------------------------------------------------------------------------- 1 | function [q, J] = nurbs_coords(srf, UV) 2 | % generalized coordinates 3 | q = zeros(3*size(srf.coefs,2)*size(srf.coefs,3), 1); 4 | 5 | for i=1:size(srf.coefs,2) 6 | for j = 1:size(srf.coefs,3) 7 | idx = 3*(size(srf.coefs,3)*(i-1) + (j-1)) + 1; 8 | q(idx:idx+2) = srf.coefs(1:3,i,j); 9 | end 10 | end 11 | 12 | n = size(UV,2); 13 | J = zeros(n, 3, 3 * prod(srf.number)); 14 | degree = srf.order-1; 15 | % Building J matrices (one for each u,v pair) 16 | for i=1:n 17 | u = UV(1,i); 18 | v = UV(2,i); 19 | si = findspan(srf.number(1)-1, degree(1), u, srf.knots{1}); 20 | Ni = basisfun(si, u, degree(1), srf.knots{1}); 21 | 22 | sj = findspan(srf.number(2)-1, degree(2), v, srf.knots{2}); 23 | Nj = basisfun(sj, v, degree(2), srf.knots{2}); 24 | 25 | % outerproduct of B spline values in u & v directions 26 | % row-wise ordering of matrices in J with u being the row index 27 | Nij = Ni'*Nj; 28 | w = srf.coefs(4, si+1-degree(1):si+1, sj+1-degree(2):sj+1); 29 | 30 | % Nij is (degree(1)+1 x degree(2)+1) matrix. 31 | % Bspline decays to zero outside its local support so Nij 32 | % contains only these nonzero values. 33 | Nij = Nij .* squeeze(w); 34 | Nij = Nij ./ sum(Nij,'all'); 35 | for ki=1:size(Nij,1) 36 | for kj=1:size(Nij,2) 37 | Jij = diag(repelem(Nij(ki,kj),3)); 38 | k = 3*((si-degree(1)+ki-1) * srf.number(2) + (sj-degree(2)+kj-1))+1; 39 | J(i,:,k:k+2) = Jij; 40 | end 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_from_iges.m: -------------------------------------------------------------------------------- 1 | function [nurbs_objects] = nurbs_from_iges(filename, sample_density) 2 | if nargin < 2 3 | sample_density=2; 4 | end 5 | data=iges2matlab(filename); 6 | 7 | % TODO: need to return weights of each sample on the surface. 8 | enable_trimming = 1; 9 | use_triangle = 1; 10 | generate_hires = 1; 11 | % trimmed_hires_res = 3; 12 | trimmed_hires_res = 10; 13 | nurbs_objects = nurbs_sample(data, enable_trimming, sample_density); 14 | disp('Done Generating samples'); 15 | 16 | for i=1:numel(nurbs_objects) 17 | % Computed generalized coordinates 18 | srf = data{nurbs_objects{i}.surf_ptr}; 19 | nurbs_objects{i}.srf = srf; 20 | 21 | [p, J] = nurbs_coords(srf.nurbs, nurbs_objects{i}.UV); 22 | J = permute(J,[3 2 1]); 23 | 24 | %Ji = J(:,:)'; 25 | %JJ = Ji'*Ji; 26 | %cond(JJ) % check conditioning if things are singular 27 | 28 | nurbs_objects{i}.p = p; 29 | nurbs_objects{i}.pdot=zeros(size(p)); 30 | nurbs_objects{i}.J = J; 31 | nurbs_objects{i}.x0 = squeeze(sum(J .* p,1)); 32 | 33 | [T,~] = nurbs_triangulate(nurbs_objects{i}); 34 | nurbs_objects{i}.T = T; 35 | 36 | if generate_hires 37 | [T,TUV] = nurbs_triangulate(nurbs_objects{i}, ... 38 | use_triangle, trimmed_hires_res); 39 | [~, J] = nurbs_coords(srf.nurbs, TUV); 40 | J = permute(J,[3 2 1]); 41 | nurbs_objects{i}.hires_T = T; 42 | nurbs_objects{i}.hires_J = J; 43 | nurbs_objects{i}.hires_x0 = squeeze(sum(J .* p,1)); 44 | nurbs_objects{i}.hires_UV = TUV; 45 | end 46 | end 47 | end -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_normals.m: -------------------------------------------------------------------------------- 1 | function [normals, areas] = nurbs_normals(srf, UV, p) 2 | [f, f_grad, g, g_grad] = nurbs_grad(srf, UV); 3 | 4 | n = size(UV,2); 5 | areas = zeros(n, 1); 6 | normals = zeros(n, 3); 7 | 8 | % What was i thinking when i wrote this 9 | for i=1:n 10 | fij = squeeze(f(i,:,:)) * p; 11 | fij_ugrad = squeeze(f_grad(i,1,:,:)) * p; 12 | fij_vgrad = squeeze(f_grad(i,2,:,:)) * p; 13 | g2 = g(i)*g(i); 14 | u_jac = (g(i) * fij_ugrad - fij * g_grad(i,1)) / g2; 15 | v_jac = (g(i) * fij_vgrad - fij * g_grad(i,2)) / g2; 16 | jac = [u_jac v_jac]; 17 | normals(i,:) = cross(u_jac, v_jac); 18 | areas(i) = sqrt(det(jac'*jac)); 19 | end 20 | normals = normals ./ vecnorm(normals,2,2); 21 | 22 | % TODO use this version of computing nurbs gradients. It's much faster 23 | % than my crummy version. 24 | % dcrv = nrbderiv(srf); 25 | % [pnts,jac] = nrbdeval(srf, dcrv, UV); 26 | % C = cross(jac{1}, jac{2}); 27 | % lengths = vecnorm(C,2,1)'; 28 | % normals = C ./ lengths; 29 | end -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_plot.m: -------------------------------------------------------------------------------- 1 | function nurbs = nurbs_plot(nurbs) 2 | cm=jet(numel(nurbs)); 3 | for ii = 1:numel(nurbs) 4 | % plt = patch('Faces',nurbs{ii}.hires_T,'Vertices',nurbs{ii}.hires_x0', ... 5 | 6 | plt = patch('Faces',nurbs{ii}.T,'Vertices',nurbs{ii}.x0', ... 7 | 'FaceAlpha',0.5,'EdgeColor','none','FaceColor',cm(ii,:)); 8 | hold on; 9 | nurbs{ii}.plt=plt; 10 | end 11 | 12 | set(gcf,'color','w'); 13 | axis equal 14 | lighting gouraud; 15 | 16 | lightangle(gca,0, 20) 17 | % lightangle(gca,0, 40) 18 | % zlim([-30 50]); 19 | % ylim([-20 20]); 20 | xlabel('x'); 21 | zlabel('z'); 22 | view(-15,30); 23 | % view(0,0); 24 | % view(28,13); 25 | end -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/deg2rad.m: -------------------------------------------------------------------------------- 1 | function rad = deg2rad(deg) 2 | % 3 | % Function Name: 4 | % 5 | % deg2rad - Convert degrees to radians. 6 | % 7 | % Calling Sequence: 8 | % 9 | % rad = deg2rad(deg); 10 | % 11 | % Parameters: 12 | % 13 | % deg : Angle in degrees. 14 | % 15 | % rad : Angle in radians. 16 | % 17 | % Description: 18 | % 19 | % Convenient utility function for converting degrees to radians, which are 20 | % often the required angular units for functions in the NURBS toolbox. 21 | % 22 | % Examples: 23 | % 24 | % // Convert 35 degrees to radians 25 | % rad = deg2rad(35); 26 | 27 | % D.M. Spink 28 | % Copyright (c) 2000. 29 | 30 | rad = pi*deg/180.0; 31 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demo4surf.m: -------------------------------------------------------------------------------- 1 | function demo4surf 2 | % Demonstration of a bilinear surface. 3 | % 4 | 5 | % D.M. Spink 6 | % Copyright (c) 2000 7 | 8 | srf = nrb4surf([0.0 0.0 0.5],[1.0 0.0 -0.5],[0.0 1.0 -0.5],[1.0 1.0 0.5]); 9 | nrbplot(srf,[10,10]); 10 | title('Construction of a bilinear surface.'); 11 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/democirc.m: -------------------------------------------------------------------------------- 1 | function democirc 2 | % Demonstration of a circle and arcs in the x-y plane. 3 | % 4 | 5 | % D.M. Spink 6 | % Copyright (c) 2000 7 | 8 | for r = 1:9 9 | crv = nrbcirc(r,[],deg2rad(45),deg2rad(315)); 10 | nrbplot(crv,50); 11 | hold on; 12 | end 13 | hold off; 14 | axis equal; 15 | title('NURBS construction of a 2D circle and arc.'); 16 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/democoons.m: -------------------------------------------------------------------------------- 1 | % Construction of a bilinearly blended Coons surface 2 | % 3 | 4 | % D.M. Spink 5 | % Copyright (c) 2000. 6 | 7 | % Boundary curve 1 8 | pnts = [ 0.0 3.0 4.5 6.5 8.0 10.0; 9 | 0.0 0.0 0.0 0.0 0.0 0.0; 10 | 2.0 2.0 7.0 4.0 7.0 9.0]; 11 | crv1 = nrbmak(pnts, [0 0 0 1/3 0.5 2/3 1 1 1]); 12 | 13 | % Boundary curve 2 14 | pnts= [ 0.0 3.0 5.0 8.0 10.0; 15 | 10.0 10.0 10.0 10.0 10.0; 16 | 3.0 5.0 8.0 6.0 10.0]; 17 | crv2 = nrbmak(pnts, [0 0 0 1/3 2/3 1 1 1]); 18 | 19 | % Boundary curve 3 20 | pnts= [ 0.0 0.0 0.0 0.0; 21 | 0.0 3.0 8.0 10.0; 22 | 2.0 0.0 5.0 3.0]; 23 | crv3 = nrbmak(pnts, [0 0 0 0.5 1 1 1]); 24 | 25 | % Boundary curve 4 26 | pnts= [ 10.0 10.0 10.0 10.0 10.0; 27 | 0.0 3.0 5.0 8.0 10.0; 28 | 9.0 7.0 7.0 10.0 10.0]; 29 | crv4 = nrbmak(pnts, [0 0 0 0.25 0.75 1 1 1]); 30 | 31 | srf = nrbcoons(crv1, crv2, crv3, crv4); 32 | 33 | % Draw the surface 34 | nrbplot(srf,[20 20]); 35 | title('Construction of a bilinearly blended Coons surface.'); 36 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/democurve.m: -------------------------------------------------------------------------------- 1 | function democurve 2 | % Shows a simple test curve. 3 | % 4 | 5 | % D.M. Spink 6 | % Copyright (c) 2000 7 | 8 | crv = nrbtestcrv; 9 | 10 | % plot the control points 11 | plot(crv.coefs(1,:),crv.coefs(2,:),'ro'); 12 | title('Arbitrary Test 2D Curve.'); 13 | hold on; 14 | plot(crv.coefs(1,:),crv.coefs(2,:),'r--'); 15 | 16 | % plot the nurbs curve 17 | nrbplot(crv,48); 18 | hold off; 19 | 20 | crv.knots(3)=0.1; 21 | figure 22 | % plot the control points 23 | plot(crv.coefs(1,:),crv.coefs(2,:),'ro'); 24 | title('Arbitrary Test 2D Curve.'); 25 | hold on; 26 | plot(crv.coefs(1,:),crv.coefs(2,:),'r--'); 27 | 28 | % plot the nurbs curve 29 | nrbplot(crv,48); 30 | hold off; 31 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/democylind.m: -------------------------------------------------------------------------------- 1 | function democylind 2 | % Demonstration of the construction of a cylinder. 3 | % 4 | 5 | % D.M. Spink 6 | % Copyright (c) 2000 7 | 8 | srf = nrbcylind(3,1,[],deg2rad(270),deg2rad(180)); 9 | nrbplot(srf,[20,20]); 10 | axis equal; 11 | title('Cylinderical section by extrusion of a circular arc.'); 12 | 13 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demodegelev.m: -------------------------------------------------------------------------------- 1 | % Demonstration of the degree elevation algorithm. 2 | % 3 | 4 | crv = nrbtestcrv; 5 | 6 | % plot the control points 7 | plot(crv.coefs(1,:),crv.coefs(2,:),'bo') 8 | title('Degree elevation of test curve by 1'); 9 | hold on; 10 | plot(crv.coefs(1,:),crv.coefs(2,:),'b--'); 11 | 12 | % draw nurbs curve 13 | nrbplot(crv,48); 14 | 15 | % degree elevate the curve by 1 16 | icrv = nrbdegelev(crv, 1); 17 | 18 | % insert new knots and plot new control points 19 | plot(icrv.coefs(1,:),icrv.coefs(2,:),'ro') 20 | plot(icrv.coefs(1,:),icrv.coefs(2,:),'r--'); 21 | 22 | hold off; 23 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demodercrv.m: -------------------------------------------------------------------------------- 1 | function demodercrv 2 | % Demonstrates the construction of a general 3 | % curve and determine of the derivative. 4 | % 5 | 6 | % D.M. Spink 7 | % Copyright (c) 2000 8 | 9 | % make and draw nurbs test curve 10 | crv = nrbtestcrv; 11 | nrbplot(crv,48); 12 | title('First derivatives along a test curve.'); 13 | 14 | npts = 9; 15 | tt = linspace(0.0,1.0,npts); 16 | 17 | dcrv = nrbderiv(crv); 18 | 19 | % first derivative 20 | [p1, dp] = nrbdeval(crv,dcrv,tt); 21 | 22 | p2 = vecnormalize(dp); 23 | 24 | hold on; 25 | plot(p1(1,:),p1(2,:),'ro'); 26 | h = quiver(p1(1,:),p1(2,:),p2(1,:),p2(2,:),0); 27 | set(h,'Color','black'); 28 | hold off; 29 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demodersrf.m: -------------------------------------------------------------------------------- 1 | function demodersrf 2 | % Demonstrates the construction of a general 3 | % surface derivatives. 4 | % 5 | 6 | % D.M. Spink 7 | % Copyright (c) 2000 8 | 9 | % make and draw a test surface 10 | srf = nrbtestsrf; 11 | p = nrbeval(srf,{linspace(0.0,1.0,20) linspace(0.0,1.0,20)}); 12 | h = surf(squeeze(p(1,:,:)),squeeze(p(2,:,:)),squeeze(p(3,:,:))); 13 | set(h,'FaceColor','blue','EdgeColor','blue'); 14 | title('First derivatives over a test surface.'); 15 | 16 | npts = 5; 17 | tt = linspace(0.0,1.0,npts); 18 | 19 | dsrf = nrbderiv(srf); 20 | 21 | [p1, dp] = nrbdeval(srf, dsrf, {tt, tt}); 22 | 23 | up2 = vecnormalize(dp{1}); 24 | vp2 = vecnormalize(dp{2}); 25 | 26 | hold on; 27 | plot3(p1(1,:),p1(2,:),p1(3,:),'ro'); 28 | h1 = quiver3(p1(1,:),p1(2,:),p1(3,:),up2(1,:),up2(2,:),up2(3,:)); 29 | h2 = quiver3(p1(1,:),p1(2,:),p1(3,:),vp2(1,:),vp2(2,:),vp2(3,:)); 30 | set(h1,'Color','black'); 31 | set(h2,'Color','black'); 32 | 33 | hold off; 34 | 35 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demoellip.m: -------------------------------------------------------------------------------- 1 | function demoellip 2 | % Demonstration of a unit circle transformed to a inclined ellipse 3 | % by first scaling, then rotating and finally translating. 4 | % 5 | 6 | % D.M. Spink 7 | % Copyright (c) 2000 8 | 9 | xx = vectrans([2.0 1.0])*vecroty(pi/8)*vecrotx(pi/4)*vecscale([1.0 2.0]); 10 | c0 = nrbtform(nrbcirc, xx); 11 | nrbplot(c0,50); 12 | title('Construction of an ellipse by transforming a unit circle.'); 13 | grid on; 14 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demogeom.m: -------------------------------------------------------------------------------- 1 | function demogeom 2 | % Demonstration of how to construct a 2D geometric 3 | % shape from a piece-wise set of NURBSs 4 | % 5 | 6 | % D.M. Spink 7 | % Copyright (c) 2000. 8 | 9 | coefs = [0.0 7.5 15.0 25.0 35.0 30.0 27.5 30.0; 10 | 0.0 2.5 0.0 -5.0 5.0 15.0 22.5 30.0]; 11 | knots = [0.0 0.0 0.0 1/6 1/3 1/2 2/3 5/6 1.0 1.0 1.0]; 12 | 13 | % Geometric boundary curve 14 | geom = [ 15 | nrbmak(coefs,knots) 16 | nrbline([30.0 30.0],[20.0 30.0]) 17 | nrbline([20.0 30.0],[20.0 20.0]) 18 | nrbcirc(10.0,[10.0 20.0],1.5*pi,0.0) 19 | nrbline([10.0 10.0],[0.0 10.0]) 20 | nrbline([0.0 10.0],[0.0 0.0]) 21 | nrbcirc(5.0,[22.5 7.5]) 22 | ]; 23 | 24 | ng = length(geom); 25 | for i = 1:ng 26 | nrbplot(geom(i),50); 27 | hold on; 28 | end 29 | hold off; 30 | axis equal; 31 | title('2D Geometry formed by a series of NURBS curves'); 32 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demohelix.m: -------------------------------------------------------------------------------- 1 | function demohelix 2 | % Demonstration of a 3D helical curve 3 | % 4 | 5 | % D.M. Spink 6 | % Copyright (c) 2000 7 | 8 | coefs =[ 6.0 0.0 6.0 1; 9 | -5.5 0.5 5.5 1; 10 | -5.0 1.0 -5.0 1; 11 | 4.5 1.5 -4.5 1; 12 | 4.0 2.0 4.0 1; 13 | -3.5 2.5 3.5 1; 14 | -3.0 3.0 -3.0 1; 15 | 2.5 3.5 -2.5 1; 16 | 2.0 4.0 2.0 1; 17 | -1.5 4.5 1.5 1; 18 | -1.0 5.0 -1.0 1; 19 | 0.5 5.5 -0.5 1; 20 | 0.0 6.0 0.0 1]'; 21 | knots = [0 0 0 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 1 1 1]; 22 | 23 | crv = nrbmak(coefs,knots); 24 | nrbplot(crv,100); 25 | title('3D helical curve.'); 26 | grid on; 27 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demokntins.m: -------------------------------------------------------------------------------- 1 | function demokntins 2 | % Demonstration of the knot insertion algorithm. 3 | % 4 | 5 | % D.M. Spink 6 | % Copyright (c) 2000. 7 | 8 | crv = nrbtestcrv; 9 | 10 | % plot the control points 11 | plot(crv.coefs(1,:),crv.coefs(2,:),'bo') 12 | title('Knot insertion along test curve.'); 13 | hold on; 14 | plot(crv.coefs(1,:),crv.coefs(2,:),'b--'); 15 | 16 | % draw nurbs curve 17 | nrbplot(crv,48); 18 | 19 | % insert new knots and plot new control points 20 | icrv = nrbkntins(crv,[0.125 0.375 0.625 0.875] ); 21 | plot(icrv.coefs(1,:),icrv.coefs(2,:),'ro') 22 | plot(icrv.coefs(1,:),icrv.coefs(2,:),'r--'); 23 | 24 | hold off; 25 | 26 | 27 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demoline.m: -------------------------------------------------------------------------------- 1 | function demoline 2 | % Demonstration of a 3D straight line 3 | % 4 | 5 | % D.M. Spink 6 | % Copyright (c) 2000. 7 | 8 | crv = nrbline([0.0 0.0 0.0]',[5.0 4.0 2.0]'); 9 | nrbplot(crv,1); 10 | title('3D straight line.'); 11 | grid on; 12 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demorect.m: -------------------------------------------------------------------------------- 1 | function demorect 2 | % Demonstrate of rectangluar curve 3 | % 4 | 5 | % D.M. Spink 6 | % Copyright (c) 2000 7 | 8 | crv = nrbtform(nrbrect(2,1), vecrotz(deg2rad(35))); 9 | nrbplot(crv,4); 10 | title('Construction and rotation of a rectangle.'); 11 | axis equal; 12 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demorevolve.m: -------------------------------------------------------------------------------- 1 | function demorevolve 2 | % Demonstration of surface construction by revolving a 3 | % profile curve. 4 | 5 | % D.M. Spink 6 | % Copyright (c) 2000 7 | 8 | % Construct a test profile in the x-z plane 9 | pnts = [3.0 5.5 5.5 1.5 1.5 4.0 4.5; 10 | 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 11 | 0.5 1.5 4.5 3.0 7.5 6.0 8.5]; 12 | crv = nrbmak(pnts,[0 0 0 1/4 1/2 3/4 3/4 1 1 1]); 13 | 14 | % rotate and vectrans by some arbitrary amounts. 15 | xx = vecrotz(deg2rad(25))*vecroty(deg2rad(15))*vecrotx(deg2rad(20)); 16 | nrb = nrbtform(crv,vectrans([5 5])*xx); 17 | 18 | % define axes of rotation 19 | pnt = [5 5 0]'; 20 | vec = xx*[0 0 1 1]'; 21 | srf = nrbrevolve(nrb,pnt,vec(1:3)); 22 | 23 | % make and draw nurbs curve 24 | p = nrbeval(srf,{linspace(0.0,1.0,20) linspace(0.0,1.0,20)}); 25 | surfl(squeeze(p(1,:,:)),squeeze(p(2,:,:)),squeeze(p(3,:,:))); 26 | title('Construct of a 3D surface by revolution of a curve.'); 27 | shading interp; 28 | colormap(copper); 29 | axis equal; 30 | 31 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demoruled.m: -------------------------------------------------------------------------------- 1 | % Demonstration of ruled surface construction. 2 | % 3 | 4 | % D.M. Spink 5 | % Copyright (c) 2000. 6 | 7 | % clear all recorded graphics and the current window 8 | title('Ruled surface construction from two NURBS curves.'); 9 | 10 | crv1 = nrbtestcrv; 11 | crv2 = nrbtform(nrbcirc(4,[4.5;0],pi,0.0),vectrans([0.0 4.0 -4.0])); 12 | srf = nrbruled(crv1,crv2); 13 | nrbplot(srf,[40 20]); 14 | title('Ruled surface construction from two NURBS curves.'); 15 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demos.m: -------------------------------------------------------------------------------- 1 | function tbxStruct=Demos 2 | % Demos Demo List infomation for NURBS Toolbox 3 | 4 | % D.M. Spink 5 | % Copyright (c) 2000 6 | 7 | if nargout == 0; demo toolbox; return; end 8 | 9 | tbxStruct.Name='nurbs'; 10 | tbxStruct.Type='Toolbox'; 11 | 12 | tbxStruct.Help= ... 13 | {' The NURBS Toolbox provides commands for the construction' 14 | ' and use of Non-Uniform Rational B-Splines (NURBS).' 15 | ' '}; 16 | 17 | tbxStruct.DemoList={ 18 | '3D Line','demoline', 19 | 'Rectangle','demorect', 20 | 'Circle and Arc','democirc', 21 | 'Helix','demohelix', 22 | 'Ellipse', 'demoellip', 23 | 'Test Curve','democurve', 24 | 'Test Surface','demosurf', 25 | 'Bilinear Surface','demo4surf', 26 | 'Knot Insertion','demokntins', 27 | 'Degree Elevation','demodegelev', 28 | 'Curve derivatives','demodercrv', 29 | 'Surface derivatives','demodersrf' 30 | 'Cylinderical arc','democylind', 31 | 'Ruled Surface','demoruled', 32 | 'Coons Surface','democoons', 33 | 'Test Extrusion','demoextrude', 34 | 'Test Revolution - Cup','demorevolve', 35 | 'Test Revolution - Ball & Torus','demotorus', 36 | '2D Geomtery','demogeom'}; 37 | 38 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/demotorus.m: -------------------------------------------------------------------------------- 1 | function demotorus 2 | % A second demonstration of surface construction 3 | % by revolution. 4 | % 5 | 6 | % D.M. Spink 7 | % Copyright (c) 2000 8 | 9 | sphere = nrbrevolve(nrbcirc(1,[],0.0,pi),[0.0 0.0 0.0],[1.0 0.0 0.0]); 10 | nrbplot(sphere,[20 20],'light','on'); 11 | title('Ball and torus - surface construction by revolution'); 12 | hold on; 13 | torus = nrbrevolve(nrbcirc(0.2,[0.9 1.0]),[0.0 0.0 0.0],[1.0 0.0 0.0]); 14 | nrbplot(torus,[20 10],'light','on'); 15 | nrbplot(nrbtform(torus,vectrans([-1.8])),[20 10],'light','on'); 16 | hold off; 17 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrb4surf.m: -------------------------------------------------------------------------------- 1 | function srf = nrb4surf(p11,p12,p21,p22) 2 | % 3 | % Function Name: 4 | % 5 | % nrb4surf - Constructs a NURBS bilinear surface. 6 | % 7 | % Calling Sequence: 8 | % 9 | % srf = nrb4surf(p11,p12,p21,p22) 10 | % 11 | % Parameters: 12 | % 13 | % p11 : Cartesian coordinate of the lhs bottom corner point. 14 | % 15 | % p12 : Cartesian coordinate of the rhs bottom corner point. 16 | % 17 | % p21 : Cartesian coordinate of the lhs top corner point. 18 | % 19 | % p22 : Cartesian coordinate of the rhs top corner point. 20 | % 21 | % srf : NURBS bilinear surface, see nrbmak. 22 | % 23 | % Description: 24 | % 25 | % Constructs a bilinear surface defined by four coordinates. 26 | % 27 | % The position of the corner points 28 | % 29 | % ^ V direction 30 | % | 31 | % ---------------- 32 | % |p21 p22| 33 | % | | 34 | % | SRF | 35 | % | | 36 | % |p11 p12| 37 | % -------------------> U direction 38 | % 39 | 40 | % D.M. Spink 41 | % Copyright (c) 2000. 42 | 43 | if nargin < 4 44 | error('Four corner points must be defined'); 45 | end 46 | 47 | coefs = [zeros(3,2,2); ones(1,2,2)]; 48 | coefs(1:length(p11),1,1) = p11(:); 49 | coefs(1:length(p12),1,2) = p12(:); 50 | coefs(1:length(p21),2,1) = p21(:); 51 | coefs(1:length(p22),2,2) = p22(:); 52 | 53 | knots = {[0 0 1 1] [0 0 1 1]}; 54 | srf = nrbmak(coefs, knots); 55 | 56 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrbcylind.m: -------------------------------------------------------------------------------- 1 | function surf = nrbcylind(height,radius,center,sang,eang) 2 | % 3 | % Function Name: 4 | % 5 | % nrbcylind - Construct a cylinder or cylindrical patch. 6 | % 7 | % Calling Sequence: 8 | % 9 | % srf = nrbcylind() 10 | % srf = nrbcylind(height) 11 | % srf = nrbcylind(height,radius) 12 | % srf = nrbcylind(height,radius,center) 13 | % srf = nrbcylind(height,radius,center,sang,eang) 14 | % 15 | % Parameters: 16 | % 17 | % height : Height of the cylinder along the axis, default 1.0 18 | % 19 | % radius : Radius of the cylinder, default 1.0 20 | % 21 | % center : Center of the cylinder, default (0,0,0) 22 | % 23 | % sang : Start angle relative to the origin, default 0. 24 | % 25 | % eang : End angle relative to the origin, default 2*pi. 26 | % 27 | % 28 | % Description: 29 | % 30 | % Construct a cylinder or cylindrical patch by extruding a circular arc. 31 | 32 | % D.M. Spink 33 | % Copyright (c) 2000. 34 | 35 | if nargin < 1 36 | height = 1; 37 | end 38 | 39 | if nargin < 2 40 | radius = 1; 41 | end 42 | 43 | if nargin < 3 44 | center = []; 45 | end 46 | 47 | if nargin < 5 48 | sang = 0; 49 | eang = 2*pi; 50 | end 51 | 52 | surf = nrbextrude(nrbcirc(radius,center,sang,eang),[0.0 0.0 height]); 53 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrbdeval.m: -------------------------------------------------------------------------------- 1 | function [pnt,jac] = nrbdeval(nurbs, dnurbs, tt) 2 | % Evaluation of the derivative NURBS curve or surface. 3 | % 4 | % [pnt, jac] = nrbdeval(crv, dcrv, tt) 5 | % [pnt, jac] = nrbdeval(srf, dsrf, {tu tv}) 6 | % 7 | % INPUTS: 8 | % 9 | % crv - original NURBS curve. 10 | % 11 | % srf - original NUBRS surface 12 | % 13 | % dcrv - NURBS derivative represention of crv 14 | % 15 | % dsrf - NURBS derivative represention of surface 16 | % 17 | % tt - parametric evaluation points 18 | % If the nurbs is a surface then tt is a cell 19 | % {tu, tv} are the parametric coordinates 20 | % 21 | % pnt - evaluated points. 22 | % jac - evaluated first derivatives (Jacobian). 23 | % 24 | % Examples: 25 | % 26 | % // Determine the first derivatives a NURBS curve at 9 points for 0.0 to 27 | % // 1.0 28 | % tt = linspace(0.0, 1.0, 9); 29 | % dcrv = nrbderiv(crv); 30 | % [pnts,jac] = nrbdeval(crv, dcrv, tt); 31 | 32 | % D.M. Spink 33 | % Copyright (c) 2000. 34 | 35 | if ~isstruct(nurbs) 36 | error('NURBS representation is not structure!'); 37 | end 38 | 39 | if ~strcmp(nurbs.form,'B-NURBS') 40 | error('Not a recognised NURBS representation'); 41 | end 42 | 43 | [cp,cw] = nrbeval(nurbs, tt); 44 | 45 | if iscell(nurbs.knots) 46 | 47 | % NURBS structure represents a surface 48 | temp = cw(ones(3,1),:,:); 49 | pnt = cp./temp; 50 | 51 | [cup,cuw] = nrbeval(dnurbs{1}, tt); 52 | tempu = cuw(ones(3,1),:,:); 53 | jac{1} = (cup-tempu.*pnt)./temp; 54 | 55 | [cvp,cvw] = nrbeval(dnurbs{2}, tt); 56 | tempv = cvw(ones(3,1),:,:); 57 | jac{2} = (cvp-tempv.*pnt)./temp; 58 | 59 | else 60 | 61 | % NURBS is a curve 62 | temp = cw(ones(3,1),:); 63 | pnt = cp./temp; 64 | 65 | % first derivative 66 | [cup,cuw] = nrbeval(dnurbs,tt); 67 | temp1 = cuw(ones(3,1),:); 68 | jac = (cup-temp1.*pnt)./temp; 69 | 70 | end 71 | 72 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrbextrude.m: -------------------------------------------------------------------------------- 1 | function srf = nrbextrude(curve,vector) 2 | % 3 | % Function Name: 4 | % 5 | % nrbextrude - Construct a NURBS surface by extruding a NURBS curve. 6 | % 7 | % Calling Sequence: 8 | % 9 | % srf = nrbextrude(crv,vec); 10 | % 11 | % Parameters: 12 | % 13 | % crv : NURBS curve to extrude, see nrbmak. 14 | % 15 | % vec : Vector along which the curve is extruded. 16 | % 17 | % srf : NURBS surface constructed. 18 | % 19 | % Description: 20 | % 21 | % Constructs a NURBS surface by extruding a NURBS curve along a defined 22 | % vector. The NURBS curve forms the U direction of the surface edge, and 23 | % extruded along the vector in the V direction. Note NURBS surfaces cannot 24 | % be extruded. 25 | % 26 | % Examples: 27 | % 28 | % Form a hollow cylinder by extruding a circle along the z-axis. 29 | % 30 | % srf = nrbextrude(nrbcirc, [0,0,1]); 31 | 32 | % D.M. Spink 33 | % Copyright (c) 2000. 34 | 35 | if iscell(curve.knots) 36 | error('Nurb surfaces cannot be extruded!'); 37 | end 38 | 39 | if nargin < 2 40 | error('Error too few input arguments!'); 41 | end 42 | 43 | if nargin == 3 44 | dz = 0.0; 45 | end 46 | 47 | coefs = cat(3,curve.coefs,vectrans(vector)*curve.coefs); 48 | srf = nrbmak(coefs,{curve.knots [0 0 1 1]}); 49 | 50 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrbline.m: -------------------------------------------------------------------------------- 1 | function curve = nrbline(p1,p2) 2 | % 3 | % Function Name: 4 | % 5 | % nrbline - Construct a straight line. 6 | % 7 | % Calling Sequence: 8 | % 9 | % crv = nrbline() 10 | % crv = nrbline(p1,p2) 11 | % 12 | % Parameters: 13 | % 14 | % p1 : 2D or 3D cartesian coordinate of the start point. 15 | % 16 | % p2 : 2D or 3D cartesian coordinate of the end point. 17 | % 18 | % crv : NURBS curve for a straight line. 19 | % 20 | % Description: 21 | % 22 | % Constructs NURBS data structure for a straight line. If no rhs 23 | % coordinates are included the function returns a unit straight 24 | % line along the x-axis. 25 | 26 | % D.M. Spink 27 | % Copyright (c) 2000. 28 | 29 | coefs = [zeros(3,2); ones(1,2)]; 30 | 31 | if nargin < 2 32 | coefs(1,2) = 1.0; 33 | else 34 | coefs(1:length(p1),1) = p1(:); 35 | coefs(1:length(p2),2) = p2(:); 36 | end 37 | 38 | curve = nrbmak(coefs, [0 0 1 1]); 39 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrbrect.m: -------------------------------------------------------------------------------- 1 | function curve = nrbrect(w,h) 2 | % 3 | % Function Name: 4 | % 5 | % nrbrect - Construct NURBS representation of a rectangle. 6 | % 7 | % Calling Sequence: 8 | % 9 | % crv = nrbrect() 10 | % crv = nrbrect(size) 11 | % crv = nrbrect(width, height) 12 | % 13 | % Parameters: 14 | % 15 | % size : Size of the square (width = height). 16 | % 17 | % width : Width of the rectangle (along x-axis). 18 | % 19 | % height : Height of the rectangle (along y-axis). 20 | % 21 | % crv : NURBS curve, see nrbmak. 22 | % 23 | % 24 | % Description: 25 | % 26 | % Construct a rectangle or square in the x-y plane with the bottom 27 | % lhs corner at (0,0,0). If no rhs arguments provided the function 28 | % constructs a unit square. 29 | 30 | % D.M. Spink 31 | % Copyright (c) 2000. 32 | 33 | if nargin < 1 34 | w = 1; 35 | h = 1; 36 | end 37 | 38 | if nargin < 2 39 | h = w; 40 | end 41 | 42 | coefs = [0 w w w w 0 0 0; 43 | 0 0 0 h h h h 0; 44 | 0 0 0 0 0 0 0 0; 45 | 1 1 1 1 1 1 1 1]; 46 | 47 | knots = [0 0 0.25 0.25 0.5 0.5 0.75 0.75 1 1]; 48 | 49 | curve = nrbmak(coefs, knots); 50 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrbreverse.m: -------------------------------------------------------------------------------- 1 | function rnrb = nrbreverse(nrb) 2 | % 3 | % Function Name: 4 | % 5 | % nrbreverse - Reverse the evaluation direction of a NURBS curve or surface. 6 | % 7 | % Calling Sequence: 8 | % 9 | % rnrb = nrbreverse(nrb); 10 | % 11 | % Parameters: 12 | % 13 | % nrb : NURBS data structure, see nrbmak. 14 | % 15 | % rnrb : Reversed NURBS. 16 | % 17 | % Description: 18 | % 19 | % Utility function to reverse the evaluation direction of a NURBS 20 | % curve or surface. 21 | 22 | % D.M. Spink 23 | % Copyright (c) 2000. 24 | 25 | if nargin ~= 1 26 | error('Incorrect number of input arguments'); 27 | end 28 | 29 | if iscell(nrb.knots) 30 | 31 | % reverse a NURBS surface 32 | coefs = nrb.coefs(:,:,end:-1:1); 33 | rnrb = nrbmak(coefs(:,end:-1:1,:), {1.0-fliplr(nrb.knots{1}),... 34 | 1.0-fliplr(nrb.knots{2})}); 35 | 36 | else 37 | 38 | % reverse a NURBS curve 39 | rnrb = nrbmak(fliplr(nrb.coefs), 1.0-fliplr(nrb.knots)); 40 | 41 | end 42 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrbruled.m: -------------------------------------------------------------------------------- 1 | function srf = nrbruled(crv1, crv2) 2 | % 3 | % Function Name: 4 | % 5 | % nrbruled - Constructs a ruled surface between two NURBS curves. 6 | % 7 | % Calling Sequence: 8 | % 9 | % srf = nrbruled(crv1, crv2) 10 | % 11 | % Parameters: 12 | % 13 | % crv1 : First NURBS curve, see nrbmak. 14 | % 15 | % crv2 : Second NURBS curve, see nrbmak. 16 | % 17 | % srf : Ruled NURBS surface. 18 | % 19 | % Description: 20 | % 21 | % Constructs a ruled surface between two NURBS curves. The ruled surface is 22 | % ruled along the V direction. 23 | % 24 | % Examples: 25 | % 26 | % Construct a ruled surface between a semicircle and a straight line. 27 | % 28 | % cir = nrbcirc(1,[0 0 0],0,pi); 29 | % line = nrbline([-1 0.5 1],[1 0.5 1]); 30 | % srf = nrbruled(cir,line); 31 | % nrbplot(srf,[20 20]); 32 | 33 | % D.M. Spink 34 | % Copyright (c) 2000. 35 | 36 | if iscell(crv1.knots) | iscell(crv2.knots) 37 | error('Both NURBS must be curves'); 38 | end 39 | 40 | % ensure both curves have a common degree 41 | d = max([crv1.order, crv2.order]); 42 | crv1 = nrbdegelev(crv1, d - crv1.order); 43 | crv2 = nrbdegelev(crv2, d - crv2.order); 44 | 45 | % merge the knot vectors, to obtain a common knot vector 46 | k1 = crv1.knots; 47 | k2 = crv2.knots; 48 | ku = unique([k1 k2]); 49 | n = length(ku); 50 | ka = []; 51 | kb = []; 52 | for i = 1:n 53 | i1 = length(find(k1 == ku(i))); 54 | i2 = length(find(k2 == ku(i))); 55 | m = max(i1, i2); 56 | ka = [ka ku(i)*ones(1,m-i1)]; 57 | kb = [kb ku(i)*ones(1,m-i2)]; 58 | end 59 | crv1 = nrbkntins(crv1, ka); 60 | crv2 = nrbkntins(crv2, kb); 61 | 62 | coefs(:,:,1) = crv1.coefs; 63 | coefs(:,:,2) = crv2.coefs; 64 | srf = nrbmak(coefs, {crv1.knots [0 0 1 1]}); 65 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrbtestcrv.m: -------------------------------------------------------------------------------- 1 | function crv = nrbtestcrv 2 | % Constructs a simple test curve. 3 | 4 | % D.M. Spink 5 | % Copyright (c) 2000 6 | 7 | pnts = [0.5 1.5 4.5 3.0 7.5 6.0 8.5; 8 | 3.0 5.5 5.5 1.5 1.5 4.0 4.5; 9 | 0.0 0.0 0.0 0.0 0.0 0.0 0.0]; 10 | crv = nrbmak(pnts,[0 0 0 1/4 1/2 3/4 3/4 1 1 1]); 11 | 12 | 13 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrbtestsrf.m: -------------------------------------------------------------------------------- 1 | function srf = nrbtestsrf 2 | % Constructs a simple test surface. 3 | 4 | % D.M. Spink 5 | % Copyright (c) 2000. 6 | 7 | % allocate multi-dimensional array of control points 8 | pnts = zeros(3,5,5); 9 | 10 | % define a grid of control points 11 | % in this case a regular grid of u,v points 12 | % pnts(3,u,v) 13 | % 14 | 15 | pnts(:,:,1) = [ 0.0 3.0 5.0 8.0 10.0; % w*x 16 | 0.0 0.0 0.0 0.0 0.0; % w*y 17 | 2.0 2.0 7.0 7.0 8.0]; % w*z 18 | 19 | pnts(:,:,2) = [ 0.0 3.0 5.0 8.0 10.0; 20 | 3.0 3.0 3.0 3.0 3.0; 21 | 0.0 0.0 5.0 5.0 7.0]; 22 | 23 | pnts(:,:,3) = [ 0.0 3.0 5.0 8.0 10.0; 24 | 5.0 5.0 5.0 5.0 5.0; 25 | 0.0 0.0 5.0 5.0 7.0]; 26 | 27 | pnts(:,:,4) = [ 0.0 3.0 5.0 8.0 10.0; 28 | 8.0 8.0 8.0 8.0 8.0; 29 | 5.0 5.0 8.0 8.0 10.0]; 30 | 31 | pnts(:,:,5) = [ 0.0 3.0 5.0 8.0 10.0; 32 | 10.0 10.0 10.0 10.0 10.0; 33 | 5.0 5.0 8.0 8.0 10.0]; 34 | 35 | % knots 36 | knots{1} = [0 0 0 1/3 2/3 1 1 1]; % knots along u 37 | knots{2} = [0 0 0 1/3 2/3 1 1 1]; % knots along v 38 | 39 | % make and draw nurbs surface 40 | srf = nrbmak(pnts,knots); 41 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrbtform.m: -------------------------------------------------------------------------------- 1 | function nurbs = nrbtform(nurbs,tmat) 2 | % 3 | % Function Name: 4 | % 5 | % nrbtform - Apply transformation matrix to the NURBS. 6 | % 7 | % Calling Sequence: 8 | % 9 | % tnurbs = nrbtform(nurbs,tmatrix); 10 | % 11 | % Parameters: 12 | % 13 | % nurbs : NURBS data structure (see nrbmak for details). 14 | % 15 | % tmatrix : Transformation matrix, a matrix of size (4,4) defining 16 | % a single or multiple transformations. 17 | % 18 | % tnurbs : The return transformed NURBS data structure. 19 | % 20 | % Description: 21 | % 22 | % The NURBS is transform as defined a transformation matrix of size (4,4), 23 | % such as a rotation, translation or change in scale. The transformation 24 | % matrix can define a single transformation or multiple series of 25 | % transformations. The matrix can be simple constructed by the functions 26 | % vecscale, vectrans, vecrotx, vecroty, and vecrotz. 27 | % 28 | % Examples: 29 | % 30 | % Rotate a square by 45 degrees about the z axis. 31 | % 32 | % rsqr = nrbtform(nrbrect(), vecrotz(deg2rad(45))); 33 | % nrbplot(rsqr, 10); 34 | % 35 | % See: 36 | % 37 | % vecscale, vectrans, vecrotx, vecroty, vecrotz 38 | 39 | % D.M. Spink 40 | % Copyright (c) 2000 41 | 42 | if nargin < 2 43 | error('Not enough input arguments!'); 44 | end; 45 | 46 | if iscell(nurbs.knots) 47 | % NURBS is a surface 48 | [dim,nu,nv] = size(nurbs.coefs); 49 | nurbs.coefs = reshape(tmat*reshape(nurbs.coefs,dim,nu*nv),[dim nu nv]); 50 | else 51 | % NURBS is a curve 52 | nurbs.coefs = tmat*nurbs.coefs; 53 | end 54 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/nrbtransp.m: -------------------------------------------------------------------------------- 1 | function tsrf = nrbtransp(srf) 2 | % 3 | % Function Name: 4 | % 5 | % nrbtransp - Transpose a NURBS surface, by swapping U and V directions. 6 | % 7 | % Calling Sequence: 8 | % 9 | % tsrf = nrbtransp(srf) 10 | % 11 | % Parameters: 12 | % 13 | % srf : NURBS surface, see nrbmak. 14 | % 15 | % tsrf : NURBS surface with U and V diretions transposed. 16 | % 17 | % Description: 18 | % 19 | % Utility function that transposes a NURBS surface, by swapping U and 20 | % V directions. NURBS curves cannot be transposed. 21 | 22 | % D.M. Spink 23 | % Copyright (c) 2000. 24 | 25 | if ~iscell(srf.knots) 26 | error(' A NURBSs curve cannot be transposed.'); 27 | end 28 | 29 | tsrf = nrbmak(permute(srf.coefs,[1 3 2]), fliplr(srf.knots)); 30 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/rad2deg.m: -------------------------------------------------------------------------------- 1 | function deg = rad2deg(rad) 2 | % 3 | % Function Name: 4 | % 5 | % rad2deg - Convert radians to degrees. 6 | % 7 | % Calling Sequence: 8 | % 9 | % rad = rad2deg(deg); 10 | % 11 | % Parameters: 12 | % 13 | % rad : Angle in radians. 14 | % 15 | % deg : Angle in degrees. 16 | % 17 | % Description: 18 | % 19 | % Convenient utility function for converting radians to degrees, which are 20 | % often the required angular units for functions in the NURBS toolbox. 21 | % 22 | % Examples: 23 | % 24 | % Convert 0.3 radians to degrees 25 | % 26 | % rad = deg2rad(0.3); 27 | 28 | % D.M. Spink 29 | % Copyright (c) 2000. 30 | 31 | deg = 180.0*rad/pi; 32 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/vecangle.m: -------------------------------------------------------------------------------- 1 | function ang = vecangle(num,den) 2 | % 3 | % Function Name: 4 | % 5 | % vecangle - An alternative to atan, returning an arctangent in the 6 | % range 0 to 2*pi. 7 | % 8 | % Calling Sequence: 9 | % 10 | % ang = vecmag2(num,dum) 11 | % 12 | % Parameters: 13 | % 14 | % num : Numerator, vector of size (1,nv). 15 | % dem : Denominator, vector of size (1,nv). 16 | % ang : Arctangents, row vector of angles. 17 | % 18 | % Description: 19 | % 20 | % The components of the vector ang are the arctangent of the corresponding 21 | % enties of num./dem. This function is an alternative for 22 | % atan, returning an angle in the range 0 to 2*pi. 23 | % 24 | % Examples: 25 | % 26 | % Find the atan(1.2,2.0) and atan(1.5,3.4) using vecangle 27 | % 28 | % ang = vecangle([1.2 1.5], [2.0 3.4]); 29 | 30 | % D.M. Spink 31 | % Copyright (c) 2000. 32 | 33 | ang = atan2(num,den); 34 | index = find(ang < 0.0); 35 | ang(index) = 2*pi+ang(index); 36 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/veccross.m: -------------------------------------------------------------------------------- 1 | function cross = veccross(vec1,vec2) 2 | % 3 | % Function Name: 4 | % 5 | % veccross - The cross product of two vectors. 6 | % 7 | % Calling Sequence: 8 | % 9 | % cross = veccross(vec1,vec2); 10 | % 11 | % Parameters: 12 | % 13 | % vec1 : An array of column vectors represented by a matrix of 14 | % vec2 size (dim,nv), where is the dimension of the vector and 15 | % nv the number of vectors. 16 | % 17 | % cross : Array of column vectors, each element is corresponding 18 | % to the cross product of the respective components in vec1 19 | % and vec2. 20 | % 21 | % Description: 22 | % 23 | % Cross product of two vectors. 24 | % 25 | % Examples: 26 | % 27 | % Determine the cross products of: 28 | % (2.3,3.4,5.6) and (1.2,4.5,1.2) 29 | % (5.1,0.0,2.3) and (2.5,3.2,4.0) 30 | % 31 | % cross = veccross([2.3 5.1; 3.4 0.0; 5.6 2.3],[1.2 2.5; 4.5 3.2; 1.2 4.0]); 32 | 33 | % D.M. Spink 34 | % Copyright (c) 2000. 35 | 36 | if size(vec1,1) == 2 37 | % 2D vector 38 | cross = zeros(size(vec1)); 39 | cross(3,:) = vec1(1,:).*vec2(2,:)-vec1(2,:).*vec2(1,:); 40 | else 41 | % 3D vector 42 | cross = [vec1(2,:).*vec2(3,:)-vec1(3,:).*vec2(2,:); 43 | vec1(3,:).*vec2(1,:)-vec1(1,:).*vec2(3,:); 44 | vec1(1,:).*vec2(2,:)-vec1(2,:).*vec2(1,:)]; 45 | end 46 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/vecdot.m: -------------------------------------------------------------------------------- 1 | function dot = vecdot(vec1,vec2) 2 | % 3 | % Function Name: 4 | % 5 | % vecdot - The dot product of two vectors. 6 | % 7 | % Calling Sequence: 8 | % 9 | % dot = vecdot(vec1,vec2); 10 | % 11 | % Parameters: 12 | % 13 | % vec1 : An array of column vectors represented by a matrix of 14 | % vec2 size (dim,nv), where is the dimension of the vector and 15 | % nv the number of vectors. 16 | % 17 | % dot : Row vector of scalars, each element corresponding to 18 | % the dot product of the respective components in vec1 and 19 | % vec2. 20 | % 21 | % Description: 22 | % 23 | % Scalar dot product of two vectors. 24 | % 25 | % Examples: 26 | % 27 | % Determine the dot product of 28 | % (2.3,3.4,5.6) and (1.2,4.5,1.2) 29 | % (5.1,0.0,2.3) and (2.5,3.2,4.0) 30 | % 31 | % dot = vecdot([2.3 5.1; 3.4 0.0; 5.6 2.3],[1.2 2.5; 4.5 3.2; 1.2 4.0]); 32 | 33 | % D.M. Spink 34 | % Copyright (c) 2000 35 | 36 | dot = sum(vec1.*vec2); 37 | 38 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/vecmag.m: -------------------------------------------------------------------------------- 1 | function mag = vecmag(vec) 2 | % 3 | % Function Name: 4 | % 5 | % vecmag - Magnitude of the vectors 6 | % 7 | % Calling Sequence: 8 | % 9 | % mvec = vecmag(vec) 10 | % 11 | % Parameters: 12 | % 13 | % vec : An array of column vectors represented by a matrix of 14 | % size (dim,nv), where is the dimension of the vector and 15 | % nv the number of vectors. 16 | % 17 | % mvec : Magnitude of the vectors, vector of size (1,nv). 18 | % 19 | % Description: 20 | % 21 | % Determines the magnitude of the vectors. 22 | % 23 | % Examples: 24 | % 25 | % Find the magnitude of the two vectors (0.0,2.0,1.3) and (1.5,3.4,2.3) 26 | % 27 | % mvec = vecmag([0.0 1.5; 2.0 3.4; 1.3 2.3]); 28 | 29 | % D.M. Spink 30 | % Copyright (c) 2000. 31 | 32 | mag = sqrt(sum(vec.^2)); 33 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/vecmag2.m: -------------------------------------------------------------------------------- 1 | function mag = vecmag2(vec) 2 | % 3 | % Function Name: 4 | % 5 | % vecmag - Squared magnitude of the vectors 6 | % 7 | % Calling Sequence: 8 | % 9 | % mvec = vecmag2(vec) 10 | % 11 | % Parameters: 12 | % 13 | % vec : An array of column vectors represented by a matrix of 14 | % size (dim,nv), where is the dimension of the vector and 15 | % nv the number of vectors. 16 | % 17 | % mvec : Squared magnitude of the vectors, vector of size (1,nv). 18 | % 19 | % Description: 20 | % 21 | % Determines the squared magnitude of the vectors. 22 | % 23 | % Examples: 24 | % 25 | % Find the squared magnitude of the two vectors (0.0,2.0,1.3) 26 | % and (1.5,3.4,2.3) 27 | % 28 | % mvec = vecmag2([0.0 1.5; 2.0 3.4; 1.3 2.3]); 29 | 30 | % D.M. Spink 31 | % Copyright (c) 2000. 32 | 33 | mag = sum(vec.^2); 34 | 35 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/vecnormalize.m: -------------------------------------------------------------------------------- 1 | function nvec = vecnormalize(vec) 2 | % 3 | % Function Name: 4 | % 5 | % vecnorm - Normalise the vectors. 6 | % 7 | % Calling Sequence: 8 | % 9 | % nvec = vecnorn(vec); 10 | % 11 | % Parameters: 12 | % 13 | % vec : An array of column vectors represented by a matrix of 14 | % size (dim,nv), where is the dimension of the vector and 15 | % nv the number of vectors. 16 | % 17 | % nvec : Normalised vectors, matrix the smae size as vec. 18 | % 19 | % Description: 20 | % 21 | % Normalises the array of vectors, returning the unit vectors. 22 | % 23 | % Examples: 24 | % 25 | % Normalise the two vectors (0.0,2.0,1.3) and (1.5,3.4,2.3) 26 | % 27 | % nvec = vecnorm([0.0 1.5; 2.0 3.4; 1.3 2.3]); 28 | 29 | % D.M. Spink 30 | % Copyright (c) 2000. 31 | 32 | nvec = vec./repmat(sqrt(sum(vec.^2)),[size(vec,1) ones(1,ndims(vec)-1)]); 33 | 34 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/vecrotx.m: -------------------------------------------------------------------------------- 1 | function rx = vecrotx(angle) 2 | % 3 | % Function Name: 4 | % 5 | % vecrotx - Transformation matrix for a rotation around the x axis. 6 | % 7 | % Calling Sequence: 8 | % 9 | % rx = vecrotx(angle); 10 | % 11 | % Parameters: 12 | % 13 | % angle : rotation angle defined in radians 14 | % 15 | % rx : (4x4) Transformation matrix. 16 | % 17 | % 18 | % Description: 19 | % 20 | % Return the (4x4) Transformation matrix for a rotation about the x axis 21 | % by the defined angle. 22 | % 23 | % The matrix is: 24 | % 25 | % [ 1 0 0 0] 26 | % [ 0 cos(angle) -sin(angle) 0] 27 | % [ 0 sin(angle) cos(angle) 0] 28 | % [ 0 0 0 1] 29 | % 30 | % Examples: 31 | % 32 | % Rotate the NURBS line (0.0 0.0 0.0) - (3.0 3.0 3.0) by 45 degrees 33 | % around the x-axis 34 | % 35 | % line = nrbline([0.0 0.0 0.0],[3.0 3.0 3.0]); 36 | % trans = vecrotx(%pi/4); 37 | % rline = nrbtform(line, trans); 38 | % 39 | % See: 40 | % 41 | % nrbtform 42 | 43 | % Dr D.M. Spink 44 | % Copyright (c) 2000. 45 | 46 | sn = sin(angle); 47 | cn = cos(angle); 48 | rx = [1 0 0 0; 0 cn -sn 0; 0 sn cn 0; 0 0 0 1]; 49 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/vecroty.m: -------------------------------------------------------------------------------- 1 | function ry = vecroty(angle) 2 | % 3 | % Function Name: 4 | % 5 | % vecroty - Transformation matrix for a rotation around the y axis. 6 | % 7 | % Calling Sequence: 8 | % 9 | % ry = vecroty(angle); 10 | % 11 | % Parameters: 12 | % 13 | % angle : rotation angle defined in radians 14 | % 15 | % ry : (4x4) Transformation matrix. 16 | % 17 | % 18 | % Description: 19 | % 20 | % Return the (4x4) Transformation matrix for a rotation about the y axis 21 | % by the defined angle. 22 | % 23 | % The matrix is: 24 | % 25 | % [ cos(angle) 0 sin(angle) 0] 26 | % [ 0 1 0 0] 27 | % [ -sin(angle) 0 cos(angle) 0] 28 | % [ 0 0 0 1] 29 | % 30 | % Examples: 31 | % 32 | % Rotate the NURBS line (0.0 0.0 0.0) - (3.0 3.0 3.0) by 45 degrees 33 | % around the y-axis 34 | % 35 | % line = nrbline([0.0 0.0 0.0],[3.0 3.0 3.0]); 36 | % trans = vecroty(%pi/4); 37 | % rline = nrbtform(line, trans); 38 | % 39 | % See: 40 | % 41 | % nrbtform 42 | 43 | % Dr D.M. Spink 44 | % Copyright (c) 2000. 45 | 46 | sn = sin(angle); 47 | cn = cos(angle); 48 | ry = [cn 0 sn 0; 0 1 0 0; -sn 0 cn 0; 0 0 0 1]; 49 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/vecrotz.m: -------------------------------------------------------------------------------- 1 | function rz = vecrotz(angle) 2 | % 3 | % Function Name: 4 | % 5 | % vecrotz - Transformation matrix for a rotation around the z axis. 6 | % 7 | % Calling Sequence: 8 | % 9 | % rz = vecrotz(angle); 10 | % 11 | % Parameters: 12 | % 13 | % angle : rotation angle defined in radians 14 | % 15 | % rz : (4x4) Transformation matrix. 16 | % 17 | % 18 | % Description: 19 | % 20 | % Return the (4x4) Transformation matrix for a rotation about the z axis 21 | % by the defined angle. 22 | % 23 | % The matrix is: 24 | % 25 | % [ cos(angle) -sin(angle) 0 0] 26 | % [ -sin(angle) cos(angle) 0 0] 27 | % [ 0 0 1 0] 28 | % [ 0 0 0 1] 29 | % 30 | % Examples: 31 | % 32 | % Rotate the NURBS line (0.0 0.0 0.0) - (3.0 3.0 3.0) by 45 degrees 33 | % around the z-axis 34 | % 35 | % line = nrbline([0.0 0.0 0.0],[3.0 3.0 3.0]); 36 | % trans = vecrotz(%pi/4); 37 | % rline = nrbtform(line, trans); 38 | % 39 | % See: 40 | % 41 | % nrbtform 42 | 43 | % Dr D.M. Spink 44 | % Copyright (c) 2000. 45 | 46 | sn = sin(angle); 47 | cn = cos(angle); 48 | rz = [cn -sn 0 0; sn cn 0 0; 0 0 1 0; 0 0 0 1]; 49 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/vecscale.m: -------------------------------------------------------------------------------- 1 | function ss = vecscale(vector) 2 | % 3 | % Function Name: 4 | % 5 | % vecscale - Transformation matrix for a scaling. 6 | % 7 | % Calling Sequence: 8 | % 9 | % ss = vecscale(svec) 10 | % 11 | % Parameters: 12 | % 13 | % svec : A vectors defining the scaling along the x,y and z axes. 14 | % i.e. [sx, sy, sy] 15 | % 16 | % ss : Scaling Transformation Matrix 17 | % 18 | % Description: 19 | % 20 | % Returns a (4x4) Transformation matrix for scaling. 21 | % 22 | % The matrix is: 23 | % 24 | % [ sx 0 0 0] 25 | % [ 0 sy 0 0] 26 | % [ 0 0 sz 0] 27 | % [ 0 0 0 1] 28 | % 29 | % Example: 30 | % 31 | % Scale up the NURBS line (0.0,0.0,0.0) - (1.0,1.0,1.0) by 3 along 32 | % the x-axis, 2 along the y-axis and 4 along the z-axis. 33 | % 34 | % line = nrbline([0.0 0.0 0.0],[1.0 1.0 1.0]); 35 | % trans = vecscale([3.0 2.0 4.0]); 36 | % sline = nrbtform(line, trans); 37 | % 38 | % See: 39 | % 40 | % nrbtform 41 | 42 | % Dr D.M. Spink 43 | % Copyright (c) 2000. 44 | 45 | if nargin < 1 46 | error('Scaling vector not specified'); 47 | end 48 | 49 | s = [vector(:);0;0]; 50 | ss = [s(1) 0 0 0; 0 s(2) 0 0; 0 0 s(3) 0; 0 0 0 1]; 51 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_toolbox/vectrans.m: -------------------------------------------------------------------------------- 1 | function dd = vectrans(vector) 2 | % 3 | % Function Name: 4 | % 5 | % vectrans - Transformation matrix for a translation. 6 | % 7 | % Calling Sequence: 8 | % 9 | % st = vectrans(tvec) 10 | % 11 | % Parameters: 12 | % 13 | % tvec : A vectors defining the translation along the x,y and 14 | % z axes. i.e. [tx, ty, ty] 15 | % 16 | % st : Translation Transformation Matrix 17 | % 18 | % Description: 19 | % 20 | % Returns a (4x4) Transformation matrix for translation. 21 | % 22 | % The matrix is: 23 | % 24 | % [ 1 0 0 tx ] 25 | % [ 0 0 0 ty ] 26 | % [ 0 0 0 tz ] 27 | % [ 0 0 0 1 ] 28 | % 29 | % Examples: 30 | % 31 | % Translate the NURBS line (0.0,0.0,0.0) - (1.0,1.0,1.0) by 3 along 32 | % the x-axis, 2 along the y-axis and 4 along the z-axis. 33 | % 34 | % line = nrbline([0.0 0.0 0.0],[1.0 1.0 1.0]); 35 | % trans = vectrans([3.0 2.0 4.0]); 36 | % tline = nrbtform(line, trans); 37 | % 38 | % See: 39 | % 40 | % nrbtform 41 | 42 | % Dr D.M. Spink 43 | % Copyright (c) 2000. 44 | 45 | if nargin < 1 46 | error('Translation vector required'); 47 | end 48 | 49 | v = [vector(:);0;0]; 50 | dd = [1 0 0 v(1); 0 1 0 v(2); 0 0 1 v(3); 0 0 0 1]; 51 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_write_iges.m: -------------------------------------------------------------------------------- 1 | function nurbs_write_iges(q, parts, path) 2 | 3 | nurbs_objects=cell(numel(parts),1); 4 | q_idx = 0; 5 | for i=1:numel(parts) 6 | srf = parts{i}.srf; 7 | 8 | qi = q(q_idx+1:q_idx+numel(parts{i}.p)); 9 | qi = reshape(qi, [3 size(srf.nurbs.coefs,3) size(srf.nurbs.coefs,2)]); 10 | qi = permute(qi, [1 3 2]); 11 | 12 | 13 | srf.q = qi(:); 14 | nurbs_objects{i} = srf; 15 | q_idx = q_idx + numel(parts{i}.p); 16 | end 17 | 18 | igesout(nurbs_objects, path) 19 | end 20 | 21 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/nurbs_write_obj.m: -------------------------------------------------------------------------------- 1 | function nurbs_write_obj(q, parts, path, ii) 2 | faces=[]; 3 | verts=[]; 4 | normals = []; 5 | 6 | q_idx = 0; 7 | for i=1:numel(parts) 8 | 9 | qi = q(q_idx+1:q_idx+numel(parts{i}.p)); 10 | xi = squeeze(sum(parts{i}.hires_J .* qi,1)); 11 | 12 | faces_i = parts{i}.hires_T + size(verts,1); 13 | % normals_i = nurbs_normals(parts{i}.srf.nurbs, parts{i}.hires_UV, parts{i}.p); 14 | faces=[faces; faces_i]; 15 | verts=[verts; xi']; 16 | % normals=[normals; normals_i]; 17 | 18 | % obj_fn = "output/obj/part_" + i + "_" + int2str(ii) + ".obj"; 19 | % writeOBJ(obj_fn, fvc.vertices, fvc.faces); 20 | q_idx = q_idx + numel(parts{i}.p); 21 | end 22 | 23 | % you better have gptoolbox, son 24 | writeOBJ(path, verts, faces);%;, [], zeros(size(faces,1),3), normals, zeros(size(faces,1),3)); 25 | end 26 | 27 | -------------------------------------------------------------------------------- /matlab/nurbs_utils/sample_spline.m: -------------------------------------------------------------------------------- 1 | % function [t,w] = sample_spline(u, degree, alpha) 2 | % u = u(degree+1:end-degree); 3 | % t = []; 4 | % w = []; 5 | % for i=1:numel(u)-1 6 | % s_b = u(i); 7 | % s_e = u(i+1); 8 | % N = degree + alpha; 9 | % ti = linspace(s_b, s_e, N); 10 | % t = [t ti(1:end-1)]; 11 | % wi = (s_e-s_b)/N; 12 | % w = [w repelem(wi, N-1)]; 13 | % end 14 | % t = [t ti(end)]; 15 | % w = [w wi]; 16 | % fprintf('numel %d ... sum %f\n', numel(w), sum(w)); 17 | % end 18 | function [t,w] = sample_spline(u, degree, alpha) 19 | u = u(degree+1:end-degree); 20 | t = []; 21 | w = []; 22 | for i=1:numel(u)-1 23 | s_b = u(i); 24 | s_e = u(i+1); 25 | N = degree + alpha; 26 | [samples,w_new]=lglnodes(N, s_e, s_b); 27 | t = [t; samples]; 28 | w = [w; -w_new]; 29 | end 30 | t = t'; 31 | w = w'; 32 | %fprintf('numel %d ... sum %f\n', numel(w), sum(w)); 33 | end -------------------------------------------------------------------------------- /matlab/pointTriangleDistance/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009, Gwendolyn Fischer 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /matlab/symbolic/SNH_dF.m: -------------------------------------------------------------------------------- 1 | function g = SNH_dF(in1,Mu,La) 2 | %SNH_DF 3 | % G = SNH_DF(IN1,MU,LA) 4 | 5 | % This function was generated by the Symbolic Math Toolbox version 8.5. 6 | % 02-Apr-2021 04:12:06 7 | 8 | %Version: 1.0 9 | F1_1 = in1(1); 10 | F1_2 = in1(4); 11 | F1_3 = in1(7); 12 | F2_1 = in1(2); 13 | F2_2 = in1(5); 14 | F2_3 = in1(8); 15 | F3_1 = in1(3); 16 | F3_2 = in1(6); 17 | F3_3 = in1(9); 18 | t2 = F1_1.^2; 19 | t3 = F1_2.^2; 20 | t4 = F1_3.^2; 21 | t5 = F2_1.^2; 22 | t6 = F2_2.^2; 23 | t7 = F2_3.^2; 24 | t8 = F3_1.^2; 25 | t9 = F3_2.^2; 26 | t10 = F3_3.^2; 27 | t11 = F1_1.*F2_2.*F3_3; 28 | t12 = F1_1.*F2_3.*F3_2; 29 | t13 = F1_2.*F2_1.*F3_3; 30 | t14 = F1_2.*F2_3.*F3_1; 31 | t15 = F1_3.*F2_1.*F3_2; 32 | t16 = F1_3.*F2_2.*F3_1; 33 | t17 = 1.0./La; 34 | t18 = -t11; 35 | t19 = -t14; 36 | t20 = -t15; 37 | t21 = Mu.*t17.*(3.0./4.0); 38 | t22 = t2+t3+t4+t5+t6+t7+t8+t9+t10+1.0; 39 | t23 = 1.0./t22; 40 | t24 = t12+t13+t16+t18+t19+t20+t21+1.0; 41 | g = [F1_1.*Mu.*2.0-La.*t24.*(F2_2.*F3_3-F2_3.*F3_2).*2.0-F1_1.*Mu.*t23.*2.0;F2_1.*Mu.*2.0+La.*t24.*(F1_2.*F3_3-F1_3.*F3_2).*2.0-F2_1.*Mu.*t23.*2.0;F3_1.*Mu.*2.0-La.*t24.*(F1_2.*F2_3-F1_3.*F2_2).*2.0-F3_1.*Mu.*t23.*2.0;F1_2.*Mu.*2.0+La.*t24.*(F2_1.*F3_3-F2_3.*F3_1).*2.0-F1_2.*Mu.*t23.*2.0;F2_2.*Mu.*2.0-La.*t24.*(F1_1.*F3_3-F1_3.*F3_1).*2.0-F2_2.*Mu.*t23.*2.0;F3_2.*Mu.*2.0+La.*t24.*(F1_1.*F2_3-F1_3.*F2_1).*2.0-F3_2.*Mu.*t23.*2.0;F1_3.*Mu.*2.0-La.*t24.*(F2_1.*F3_2-F2_2.*F3_1).*2.0-F1_3.*Mu.*t23.*2.0;F2_3.*Mu.*2.0+La.*t24.*(F1_1.*F3_2-F1_2.*F3_1).*2.0-F2_3.*Mu.*t23.*2.0;F3_3.*Mu.*2.0-La.*t24.*(F1_1.*F2_2-F1_2.*F2_1).*2.0-F3_3.*Mu.*t23.*2.0]; 42 | -------------------------------------------------------------------------------- /matlab/symbolic/SNH_dF2.m: -------------------------------------------------------------------------------- 1 | function H = SNH_dF2(in1,C,D) 2 | %SNH_DF2 3 | % H = SNH_DF2(IN1,C,D) 4 | 5 | % This function was generated by the Symbolic Math Toolbox version 8.5. 6 | % 20-Nov-2020 15:38:57 7 | 8 | %Version: 1.0 9 | F1_1 = in1(1); 10 | F1_2 = in1(3); 11 | F2_1 = in1(2); 12 | F2_2 = in1(4); 13 | t2 = C.*2.0; 14 | t3 = F1_1.*F2_2; 15 | t4 = F1_2.*F2_1; 16 | t5 = -C; 17 | t6 = D.*F1_1.*F1_2.*2.0; 18 | t7 = D.*F1_1.*F2_1.*2.0; 19 | t10 = D.*F1_2.*F2_2.*2.0; 20 | t11 = D.*F2_1.*F2_2.*2.0; 21 | t8 = D.*t3.*2.0; 22 | t9 = D.*t4.*2.0; 23 | t12 = -t3; 24 | t13 = -t6; 25 | t14 = -t7; 26 | t15 = -t10; 27 | t16 = -t11; 28 | t17 = t4+t12+1.0; 29 | t18 = D.*t17.*2.0; 30 | t19 = -t18; 31 | t20 = C+t9+t18; 32 | t21 = t5+t8+t19; 33 | H = reshape([t2+D.*F2_2.^2.*2.0,t15,t16,t21,t15,t2+D.*F1_2.^2.*2.0,t20,t13,t16,t20,t2+D.*F2_1.^2.*2.0,t14,t21,t13,t14,t2+D.*F1_1.^2.*2.0],[4,4]); 34 | -------------------------------------------------------------------------------- /matlab/symbolic/SNH_tet_dF.m: -------------------------------------------------------------------------------- 1 | function g = SNH_tet_dF(in1,C,D) 2 | %SNH_TET_DF 3 | % G = SNH_TET_DF(IN1,C,D) 4 | 5 | % This function was generated by the Symbolic Math Toolbox version 8.5. 6 | % 18-Nov-2020 21:19:27 7 | 8 | %Version: 1.0 9 | F1_1 = in1(1); 10 | F1_2 = in1(4); 11 | F1_3 = in1(7); 12 | F2_1 = in1(2); 13 | F2_2 = in1(5); 14 | F2_3 = in1(8); 15 | F3_1 = in1(3); 16 | F3_2 = in1(6); 17 | F3_3 = in1(9); 18 | t2 = F1_1.*F2_2; 19 | t3 = F1_2.*F2_1; 20 | t4 = F1_1.*F2_3; 21 | t5 = F1_3.*F2_1; 22 | t6 = F1_2.*F2_3; 23 | t7 = F1_3.*F2_2; 24 | t8 = F1_1.*F3_2; 25 | t9 = F1_2.*F3_1; 26 | t10 = F1_1.*F3_3; 27 | t11 = F1_3.*F3_1; 28 | t12 = F1_2.*F3_3; 29 | t13 = F1_3.*F3_2; 30 | t14 = F2_1.*F3_2; 31 | t15 = F2_2.*F3_1; 32 | t16 = F2_1.*F3_3; 33 | t17 = F2_3.*F3_1; 34 | t18 = F2_2.*F3_3; 35 | t19 = F2_3.*F3_2; 36 | t20 = F3_3.*t2; 37 | t21 = F3_2.*t4; 38 | t22 = F3_3.*t3; 39 | t23 = F3_1.*t6; 40 | t24 = F3_2.*t5; 41 | t25 = F3_1.*t7; 42 | t26 = -t3; 43 | t27 = -t5; 44 | t28 = -t7; 45 | t29 = -t9; 46 | t30 = -t11; 47 | t31 = -t13; 48 | t32 = -t15; 49 | t33 = -t17; 50 | t34 = -t19; 51 | t35 = -t20; 52 | t36 = -t23; 53 | t37 = -t24; 54 | t38 = t2+t26; 55 | t39 = t4+t27; 56 | t40 = t6+t28; 57 | t41 = t8+t29; 58 | t42 = t10+t30; 59 | t43 = t12+t31; 60 | t44 = t14+t32; 61 | t45 = t16+t33; 62 | t46 = t18+t34; 63 | t47 = t21+t22+t25+t35+t36+t37+1.0; 64 | g = [-C.*t46+C.*F1_1.*2.0-D.*t46.*t47.*2.0;C.*t43+C.*F2_1.*2.0+D.*t43.*t47.*2.0;-C.*t40+C.*F3_1.*2.0-D.*t40.*t47.*2.0;C.*t45+C.*F1_2.*2.0+D.*t45.*t47.*2.0;-C.*t42+C.*F2_2.*2.0-D.*t42.*t47.*2.0;C.*t39+C.*F3_2.*2.0+D.*t39.*t47.*2.0;-C.*t44+C.*F1_3.*2.0-D.*t44.*t47.*2.0;C.*t41+C.*F2_3.*2.0+D.*t41.*t47.*2.0;-C.*t38+C.*F3_3.*2.0-D.*t38.*t47.*2.0]; 65 | -------------------------------------------------------------------------------- /matlab/symbolic/neohookean_dF.m: -------------------------------------------------------------------------------- 1 | function g = neohookean_dF(in1,C,D) 2 | %NEOHOOKEAN_DF 3 | % G = NEOHOOKEAN_DF(IN1,C,D) 4 | 5 | % This function was generated by the Symbolic Math Toolbox version 8.5. 6 | % 08-Nov-2020 13:01:11 7 | 8 | %Version: 1.0 9 | F1_1 = in1(1); 10 | F1_2 = in1(3); 11 | F2_1 = in1(2); 12 | F2_2 = in1(4); 13 | t2 = F1_1.^2; 14 | t3 = F1_2.^2; 15 | t4 = F2_1.^2; 16 | t5 = F2_2.^2; 17 | t6 = F1_1.*F2_2; 18 | t7 = F1_2.*F2_1; 19 | t8 = -t6; 20 | t9 = -t7; 21 | t12 = t2+t3+t4+t5; 22 | t10 = t6+t9; 23 | t11 = t7+t8+1.0; 24 | t13 = 1.0./t10.^(2.0./3.0); 25 | t14 = 1.0./t10.^(5.0./3.0); 26 | g = [C.*(F1_1.*t13.*2.0-F2_2.*t12.*t14.*(2.0./3.0))-D.*F2_2.*t11.*2.0;C.*(F2_1.*t13.*2.0+F1_2.*t12.*t14.*(2.0./3.0))+D.*F1_2.*t11.*2.0;C.*(F1_2.*t13.*2.0+F2_1.*t12.*t14.*(2.0./3.0))+D.*F2_1.*t11.*2.0;C.*(F2_2.*t13.*2.0-F1_1.*t12.*t14.*(2.0./3.0))-D.*F1_1.*t11.*2.0]; 27 | -------------------------------------------------------------------------------- /matlab/symbolic/neohookean_func.m: -------------------------------------------------------------------------------- 1 | function neohookean_func 2 | d=3; 3 | F=sym('F', [d,d]); 4 | assume(F,'real'); 5 | J=det(F); 6 | I3=trace(F'*F)/J^(2/3); 7 | 8 | syms C D 9 | % neohookean 10 | psi=C*(I3-3)+D*(J-1)^2; 11 | 12 | % % stable neohookean 13 | % I3=det(F); 14 | % I2=trace(F'*F); 15 | % psi=C*(I2-3)-2*C*(I3-1)+D*(I3-1)^2; 16 | 17 | % SNH 18 | syms Mu La 19 | J = det(F); 20 | IC = trace(F'*F); 21 | a = 1.0 + (Mu/La) - (Mu / (4*La)); 22 | psi = Mu*(IC-3) + La*(J-a)^2 - Mu*log(IC+1); 23 | 24 | g = gradient(psi,F(:)); 25 | H = hessian(psi,F(:)); 26 | % ccode(psi) 27 | ccode(g) 28 | ccode(H) 29 | matlabFunction(g, 'vars', {F,Mu,La},'File','SNH_dF','Comments','Version: 1.0') 30 | 31 | % matlabFunction(g, 'vars', {F,C,D},'File','SNH_dF','Comments','Version: 1.0') 32 | % matlabFunction(H, 'vars', {F,C,D},'File','SNH_dF2','Comments','Version: 1.0') 33 | end -------------------------------------------------------------------------------- /matlab/symbolic/vem_A_func.m: -------------------------------------------------------------------------------- 1 | function A = vem_A_func(n,ne) 2 | if nargin < 1 3 | n=4; 4 | ne = 2; 5 | end 6 | % n = numel(B); 7 | qdot=sym('qdot',[2*n,1]); 8 | assume(qdot,'real'); 9 | BM=sym('BM',[ne,1]); 10 | assume(BM,'real') 11 | 12 | E = zeros(2*ne,2*n); 13 | E(1:2,3:4) = eye(2); 14 | E(3:4,5:6) = eye(2); 15 | 16 | ONE=repmat([1 0; 0 1], 1, n); 17 | x_com=(1/n)*ONE*qdot; 18 | x_com = sym('x_com',[2,1]); 19 | 20 | qE = E * qdot; 21 | P=sym(zeros(2, ne)); 22 | for i=1:ne 23 | %P(:,i) = qdot(2*i-1:2*i)-x_com; 24 | P(:,i) = qE(2*i-1:2*i)-x_com; 25 | end 26 | 27 | C=([qdot(3) qdot(4)]' - (P*BM + x_com)); % Error matrix term 28 | % C=(P*BM + x_com); % Mass matrix term 29 | dT_dqdot = jacobian(C,qdot) 30 | % M = jacobian(dT_dqdot,qdot) 31 | % M = double(subs(M, BM, B)); 32 | % matlabFunction(M, 'vars', {BM}, 'File','mass_matrix_36','Comments','Version: 1.0') 33 | end -------------------------------------------------------------------------------- /matlab/symbolic/vem_dF_func.m: -------------------------------------------------------------------------------- 1 | function dF = vem_dF_func(n,ne) 2 | if nargin < 1 3 | n=4; 4 | ne = 2; 5 | k=5; 6 | end 7 | % n = numel(B); 8 | qdot=sym('qdot',[2*n,1]); 9 | assume(qdot,'real'); 10 | 11 | 12 | B=sym('B',[ne,k]); 13 | assume(B,'real') 14 | 15 | dM_dX=sym('dM_dX',[k,2]); 16 | assume(dM_dX,'real'); 17 | 18 | E = zeros(2*ne,2*n); 19 | E(1:2,3:4) = eye(2); 20 | E(3:4,5:6) = eye(2); 21 | 22 | ONE=repmat([1 0; 0 1], 1, n); 23 | x_com=(1/n)*ONE*qdot; 24 | x_com = sym('x_com',[2,1]); 25 | qE = E * qdot; 26 | P=sym(zeros(2, ne)); 27 | for i=1:ne 28 | P(:,i) = qdot(2*i-1:2*i)-x_com; 29 | P(:,i) = qE(2*i-1:2*i)-x_com; 30 | end 31 | 32 | C = P * B * dM_dX; 33 | C1=C(:) 34 | dT_dqdot = jacobian(C(:),qdot) 35 | % M = jacobian(dT_dqdot,qdot) 36 | % M = double(subs(M, BM, B)); 37 | % matlabFunction(M, 'vars', {BM}, 'File','mass_matrix_36','Comments','Version: 1.0') 38 | end -------------------------------------------------------------------------------- /matlab/symbolic/vem_mass_matrix_func.m: -------------------------------------------------------------------------------- 1 | function M = vem_mass_matrix_func(n) 2 | if nargin < 1 3 | n=4; 4 | end 5 | % n = numel(B); 6 | qdot=sym('qdot',[2*n,1]); 7 | pred=sym('pred',[2,1]); 8 | assume(qdot,'real'); 9 | BM=sym('BM',[n,1]); 10 | assume(BM,'real') 11 | 12 | ONE=repmat([1 0; 0 1], 1, n); 13 | x_com=(1/n)*ONE*qdot; 14 | % XCOM_q = (1/(n/2))*ONE'*ONE*qdot; 15 | 16 | P=sym(zeros(2, n)); 17 | for i=1:n 18 | P(:,i) = qdot(2*i-1:2*i)-x_com; 19 | end 20 | 21 | C=([qdot(1) qdot(2)]' - (P*BM + x_com)); % Error matrix term 22 | % C=(P*BM + x_com); % Mass matrix term 23 | T=C'*C; 24 | dT_dqdot = gradient(T,qdot); 25 | M = jacobian(dT_dqdot,qdot) 26 | % M = double(subs(M, BM, B)); 27 | % matlabFunction(M, 'vars', {BM}, 'File','mass_matrix_36','Comments','Version: 1.0') 28 | end -------------------------------------------------------------------------------- /matlab/vem3dmesh_energy_matlab.m: -------------------------------------------------------------------------------- 1 | function [e, g, H] = vem3dmesh_energy_matlab(qdot_new, q, qdot, f_ext, x_fixed, ... 2 | vol, params, dF_dc, dF_dc_S, w_I, E, ... 3 | M, ME, L, P, J, ... 4 | k, n, d, x0_coms_size, k_stability, dt) 5 | %%%%% 6 | % objective needs to return energy, gradient and hessian values 7 | %% 8 | % Update position 9 | q_new = q + dt*qdot_new; 10 | x_new = reshape(P'*J*q_new,3,[]) + x_fixed; 11 | 12 | % Solve for polynomial coefficients (projection operators). 13 | c = vem3dmesh_polynomial_coefficients(x_new, L, E); 14 | 15 | neohookean_e = vem3dmesh_neohookean_q(c, vol, params, dF_dc, dF_dc_S, d); 16 | 17 | PMP = P*M*P'; 18 | 19 | e = 0.5*qdot_new'*J'*PMP*J*qdot_new - qdot_new'*J'*PMP*J*qdot + ... 20 | k_stability * x_new(:)' * ME * x_new(:) + ... 21 | 0.5 * neohookean_e - ... 22 | qdot_new'*J'*f_ext; 23 | 24 | if nargout > 1 25 | g_neohookean = vem3dmesh_neohookean_dq(x_new, c, vol, params, dF_dc, dF_dc_S, ME, L, ... 26 | k, n, d, x0_coms_size, k_stability); 27 | 28 | g = J' * (PMP*J*(qdot_new - qdot) + ... 29 | + dt*P*g_neohookean + ... 30 | - f_ext); 31 | 32 | if nargout > 2 33 | K = -vem3dmesh_neohookean_dq2(c, vol, params, dF_dc, w_I, k, n, ... 34 | x0_coms_size); 35 | K = L' * K * L; 36 | 37 | H = J' * (PMP + dt*dt*P*K*P') * J; 38 | end 39 | end 40 | end 41 | 42 | -------------------------------------------------------------------------------- /matlab/vem_dF_dc.m: -------------------------------------------------------------------------------- 1 | function [dF_dc, S] = vem_dF_dc(x, x_coms, w, W_I, com_map, order, k) 2 | d = size(x,1); 3 | n = size(x,2); 4 | 5 | dF_dc = cell(n,1); 6 | S = cell(n,1); 7 | 8 | for ii=1:n 9 | m = numel(W_I{ii}); 10 | 11 | dF_dc_i = zeros(d*d, d*k*m); 12 | S_i = zeros(d*k*m, d*(k*size(w,2) + size(x_coms,2))); 13 | for jj=1:m 14 | idx = W_I{ii}(jj); 15 | dYij = squeeze(monomial_basis_grad(x(:,ii), x_coms(:,com_map(idx)), order)); 16 | 17 | for i = 1:d 18 | for j = 1:d 19 | row = d*(i-1)+j; 20 | col_b = d*k*(jj-1)+k*(j-1)+1; 21 | col_e = d*k*(jj-1)+k*j; 22 | dF_dc_i(row,col_b:col_e) = w(ii,idx)*dYij(:,i)'; 23 | end 24 | end 25 | 26 | rows = d*k*(jj-1)+1:d*k*jj; 27 | cols = d*k*(idx-1)+1:d*k*idx; 28 | S_i(rows,cols) = eye(d*k); 29 | end 30 | dF_dc{ii}=dF_dc_i; 31 | S{ii} = sparse(S_i); 32 | end 33 | end 34 | 35 | -------------------------------------------------------------------------------- /matlab/vem_dx_dc.m: -------------------------------------------------------------------------------- 1 | function [Y,S,C_I] = vem_dx_dc(x, x_coms, w, W_I, com_map, order, k) 2 | d = size(x,1); 3 | n = size(x,2); 4 | 5 | Y = cell(n,1); 6 | S = cell(n,1); 7 | C_I = cell(n,1); 8 | 9 | for ii=1:n 10 | m = numel(W_I{ii}); 11 | 12 | [C,~,ic] = unique(com_map(W_I{ii})); 13 | ncoms = numel(C); 14 | 15 | Yi = zeros(d, d*(k*m + ncoms)); 16 | S_i = zeros(d*(k*m+ncoms), d*(k*size(w,2) + size(x_coms,2))); 17 | 18 | I1 = d*k*m; 19 | I2 = d*k*size(w,2); 20 | for i=1:m 21 | idx = W_I{ii}(i); 22 | Yij = monomial_basis(x(:,ii), x_coms(:,com_map(idx)), order); 23 | for j = 1:d 24 | col_b = d*k*(i-1)+k*(j-1)+1; 25 | col_e = d*k*(i-1)+k*j; 26 | 27 | Yi(j,col_b:col_e) = w(ii,idx)*Yij; 28 | end 29 | I_range = I1+d*(ic(i)-1)+1 : I1+d*ic(i); 30 | Yi(:,I_range) = Yi(:,I_range) + w(ii,idx)*eye(d); 31 | 32 | % Setting selection matrix terms. 33 | rows = d*k*(i-1)+1:d*k*i; 34 | cols = d*k*(idx-1)+1:d*k*idx; 35 | S_i(rows,cols) = eye(d*k); 36 | 37 | cols = I2+d*(com_map(idx)-1)+1 : I2+d*com_map(idx); 38 | S_i(I_range, cols) = eye(d); 39 | end 40 | Y{ii} = Yi; 41 | S{ii} = sparse(S_i); 42 | C_I{ii} = C; 43 | end 44 | end 45 | 46 | -------------------------------------------------------------------------------- /models/README.md: -------------------------------------------------------------------------------- 1 | ## Some models I use for testing. Each model has an associated png to give you an idea of what it looks like. 2 | 3 | Models with "simple" at the end means they use a fewer number of controls point than the original version. It's reccomended that you use these simple version since simulation will be much faster. 4 | -------------------------------------------------------------------------------- /models/mugs/mugs_rhino/mug_floating_handle.3dm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/models/mugs/mugs_rhino/mug_floating_handle.3dm -------------------------------------------------------------------------------- /models/mugs/mugs_rhino/mug_intersect_1.3dm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/models/mugs/mugs_rhino/mug_intersect_1.3dm -------------------------------------------------------------------------------- /models/mugs/mugs_rhino/mug_intersect_2.3dm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/models/mugs/mugs_rhino/mug_intersect_2.3dm -------------------------------------------------------------------------------- /models/mugs/mugs_rhino/mug_solid.3dm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/models/mugs/mugs_rhino/mug_solid.3dm -------------------------------------------------------------------------------- /output/gifs/cube.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/output/gifs/cube.gif -------------------------------------------------------------------------------- /output/gifs/gifsicle.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/output/gifs/gifsicle.exe -------------------------------------------------------------------------------- /output/gifs/gifsicle_remove2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This script will take an animated GIF and delete every other frame 3 | # Accepts two parameters: input file and output file 4 | # Usage: ./ input.gif output.gif 5 | 6 | # Make a copy of the file 7 | cp $1 $2 8 | echo "copy completed" 9 | # Get the number of frames 10 | numframes=`./gifsicle.exe $1 -I | grep -P "\d+ images" --only-matching | grep -P "\d+" --only-matching` 11 | echo "numframes completed" 12 | # Deletion 13 | # ./gifsicle.exe "$1" --colors 250 --unoptimize $(seq -f "#%g" 0 2 $numframes) -O2 -o "$2" 14 | ./gifsicle.exe "$1" $(seq -f "#%g" 0 2 $numframes) -o "$2" 15 | echo "script completed" 16 | -------------------------------------------------------------------------------- /output/img/.gitignore: -------------------------------------------------------------------------------- 1 | *.png 2 | *.gif -------------------------------------------------------------------------------- /paper/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.aux 3 | *.bbl 4 | *.out 5 | *.blg 6 | *.synctex.gz 7 | acmart.cls 8 | acmart.dtx 9 | main.pdf 10 | -------------------------------------------------------------------------------- /paper/castle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/castle.png -------------------------------------------------------------------------------- /paper/figures/astronauts.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/astronauts.pdf -------------------------------------------------------------------------------- /paper/figures/beam_twist.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/beam_twist.pdf -------------------------------------------------------------------------------- /paper/figures/beams.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/beams.pdf -------------------------------------------------------------------------------- /paper/figures/chicken.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/chicken.pdf -------------------------------------------------------------------------------- /paper/figures/deflection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/deflection.pdf -------------------------------------------------------------------------------- /paper/figures/deflection_full.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/deflection_full.pdf -------------------------------------------------------------------------------- /paper/figures/deprecated/distance_weight_old.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/deprecated/distance_weight_old.pdf -------------------------------------------------------------------------------- /paper/figures/deprecated/distance_weighting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/deprecated/distance_weighting.png -------------------------------------------------------------------------------- /paper/figures/deprecated/error_energy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/deprecated/error_energy.png -------------------------------------------------------------------------------- /paper/figures/deprecated/nurbs_surface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/deprecated/nurbs_surface.png -------------------------------------------------------------------------------- /paper/figures/deprecated/plot_distance_weight.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/deprecated/plot_distance_weight.pdf -------------------------------------------------------------------------------- /paper/figures/deprecated/raycasting_quadrature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/deprecated/raycasting_quadrature.png -------------------------------------------------------------------------------- /paper/figures/distance_weight_puft.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/distance_weight_puft.pdf -------------------------------------------------------------------------------- /paper/figures/export_iges.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/export_iges.pdf -------------------------------------------------------------------------------- /paper/figures/independent_movement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/independent_movement.pdf -------------------------------------------------------------------------------- /paper/figures/mug_overlap.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/mug_overlap.pdf -------------------------------------------------------------------------------- /paper/figures/nurbs_patch.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/nurbs_patch.pdf -------------------------------------------------------------------------------- /paper/figures/octopus.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/octopus.pdf -------------------------------------------------------------------------------- /paper/figures/origin_network.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/origin_network.pdf -------------------------------------------------------------------------------- /paper/figures/patch_test.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/patch_test.pdf -------------------------------------------------------------------------------- /paper/figures/plot_distance_weight_both.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/plot_distance_weight_both.pdf -------------------------------------------------------------------------------- /paper/figures/projection_operator_solve.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/projection_operator_solve.pdf -------------------------------------------------------------------------------- /paper/figures/raycasting_quadrature.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/raycasting_quadrature.pdf -------------------------------------------------------------------------------- /paper/figures/representative.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/representative.jpg -------------------------------------------------------------------------------- /paper/figures/representative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/representative.png -------------------------------------------------------------------------------- /paper/figures/rocket.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/rocket.pdf -------------------------------------------------------------------------------- /paper/figures/scalability.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/scalability.pdf -------------------------------------------------------------------------------- /paper/figures/scalability_old.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/scalability_old.pdf -------------------------------------------------------------------------------- /paper/figures/starship.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/starship.pdf -------------------------------------------------------------------------------- /paper/figures/starship_short.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/starship_short.pdf -------------------------------------------------------------------------------- /paper/figures/stiffness_sparsity.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/stiffness_sparsity.pdf -------------------------------------------------------------------------------- /paper/figures/teaser_castle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/teaser_castle.pdf -------------------------------------------------------------------------------- /paper/figures/tire.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tytrusty/Shape-Matching-Element-Method/6aebe3fb7768fb240b8ea465c5fad6d0397d9e8d/paper/figures/tire.pdf --------------------------------------------------------------------------------