├── .gitignore ├── Dockerfile ├── LICENSE.txt ├── README.md ├── example_config.sh ├── main_surface.sh ├── remesher ├── Makefile.inc ├── Makefile.linux ├── cmdremesher │ ├── Makefile │ ├── Makefile.dep │ ├── cmdremesher │ ├── main.cc │ ├── main.o │ └── main_backup.cc ├── libgmm │ ├── gmm.h │ ├── gmm_MUMPS_interface.h │ ├── gmm_algobase.h │ ├── gmm_blas.h │ ├── gmm_blas_interface.h │ ├── gmm_condition_number.h │ ├── gmm_conjugated.h │ ├── gmm_def.h │ ├── gmm_dense_Householder.h │ ├── gmm_dense_lu.h │ ├── gmm_dense_qr.h │ ├── gmm_dense_sylvester.h │ ├── gmm_domain_decomp.h │ ├── gmm_except.h │ ├── gmm_inoutput.h │ ├── gmm_interface.h │ ├── gmm_interface_bgeot.h │ ├── gmm_iter.h │ ├── gmm_iter_solvers.h │ ├── gmm_kernel.h │ ├── gmm_lapack_interface.h │ ├── gmm_least_squares_cg.h │ ├── gmm_matrix.h │ ├── gmm_modified_gram_schmidt.h │ ├── gmm_opt.h │ ├── gmm_precond.h │ ├── gmm_precond_diagonal.h │ ├── gmm_precond_ildlt.h │ ├── gmm_precond_ildltt.h │ ├── gmm_precond_ilu.h │ ├── gmm_precond_ilut.h │ ├── gmm_precond_ilutp.h │ ├── gmm_precond_mr_approx_inverse.h │ ├── gmm_real_part.h │ ├── gmm_ref.h │ ├── gmm_scaled.h │ ├── gmm_solver_Newton.h │ ├── gmm_solver_Schwarz_additive.h │ ├── gmm_solver_bfgs.h │ ├── gmm_solver_bicgstab.h │ ├── gmm_solver_cg.h │ ├── gmm_solver_constrained_cg.h │ ├── gmm_solver_gmres.h │ ├── gmm_solver_idgmres.h │ ├── gmm_solver_qmr.h │ ├── gmm_std.h │ ├── gmm_sub_index.h │ ├── gmm_sub_matrix.h │ ├── gmm_sub_vector.h │ ├── gmm_superlu_interface.h │ ├── gmm_transposed.h │ ├── gmm_tri_solve.h │ ├── gmm_vector.h │ └── gmm_vector_to_matrix.h └── libremesh │ ├── Makefile │ ├── Makefile.dep │ ├── averageplane.cc │ ├── averageplane.h │ ├── averageplane.o │ ├── cvtstats.cc │ ├── cvtstats.h │ ├── cvtstats.o │ ├── defines.h │ ├── delaunayflips.cc │ ├── delaunayflips.h │ ├── delaunayflips.o │ ├── densityfield.cc │ ├── densityfield.h │ ├── densityfield.o │ ├── densitytriangle2.h │ ├── edgeflips.cc │ ├── edgeflips.h │ ├── edgeflips.o │ ├── elapsedtimer.h │ ├── exception.h │ ├── featureedges.cc │ ├── featureedges.h │ ├── featureedges.o │ ├── gslhelpers.h │ ├── gslpolysolve.cc │ ├── gslpolysolve.h │ ├── gslpolysolve.o │ ├── halfedge.h │ ├── helpers.cc │ ├── helpers.h │ ├── helpers.o │ ├── hrtimer.h │ ├── incdelaunay.cc │ ├── incdelaunay.h │ ├── incdelaunay.o │ ├── interface.cc │ ├── interface.h │ ├── interface.o │ ├── libremesh.a │ ├── logging.h │ ├── mathhelpers.h │ ├── matrix2.h │ ├── matrix3.h │ ├── matrix4.h │ ├── meshcleanup.cc │ ├── meshcleanup.h │ ├── meshcleanup.o │ ├── meshdecimation.cc │ ├── meshdecimation.h │ ├── meshdecimation.o │ ├── meshoptimize.cc │ ├── meshoptimize.h │ ├── meshoptimize.o │ ├── meshskeleton.cc │ ├── meshskeleton.h │ ├── meshskeleton.o │ ├── meshslicing.cc │ ├── meshslicing.h │ ├── meshslicing.o │ ├── meshstats.cc │ ├── meshstats.h │ ├── meshstats.o │ ├── microdelaunay.cc │ ├── microdelaunay.h │ ├── microdelaunay.o │ ├── micropatch.cc │ ├── micropatch.h │ ├── micropatch.o │ ├── modelloader.cc │ ├── modelloader.h │ ├── modelloader.o │ ├── modelwriter.cc │ ├── modelwriter.h │ ├── modelwriter.o │ ├── oversampling.cc │ ├── oversampling.h │ ├── oversampling.o │ ├── patch2d.cc │ ├── patch2d.h │ ├── patch2d.o │ ├── patch2d_fb.cc │ ├── patch2d_fb.h │ ├── patch2d_fb.o │ ├── patch3d.cc │ ├── patch3d.h │ ├── patch3d.o │ ├── patchcache.cc │ ├── patchcache.h │ ├── patchcache.o │ ├── permute.h │ ├── plane.h │ ├── pntriangle.cc │ ├── pntriangle.h │ ├── pntriangle.o │ ├── polygon2.cc │ ├── polygon2.h │ ├── polygon2.o │ ├── quaternion.h │ ├── refptr.h │ ├── refptr_mt.h │ ├── refptr_st.h │ ├── refptrarray.h │ ├── relaxanglesmooth.cc │ ├── relaxanglesmooth.h │ ├── relaxanglesmooth.o │ ├── relaxarea.h │ ├── relaxation.cc │ ├── relaxation.h │ ├── relaxation.o │ ├── relaxlloyd.h │ ├── relocation.cc │ ├── relocation.h │ ├── relocation.o │ ├── resampling.cc │ ├── resampling.h │ ├── resampling.o │ ├── simplification.cc │ ├── simplification.h │ ├── simplification.o │ ├── straightline2.h │ ├── straightline3.h │ ├── subdivbase.cc │ ├── subdivbase.h │ ├── subdivbase.o │ ├── subdivlinear.cc │ ├── subdivlinear.h │ ├── subdivlinear.o │ ├── subdivloop.cc │ ├── subdivloop.h │ ├── subdivloop.o │ ├── test.cc │ ├── thread.h │ ├── thread_posix.h │ ├── thread_win32.h │ ├── triangle2.h │ ├── triangle3.h │ ├── trianglemesh.cc │ ├── trianglemesh.h │ ├── trianglemesh.o │ ├── triangulator.cc │ ├── triangulator.h │ ├── triangulator.o │ ├── vec2.h │ ├── vec3.h │ ├── vec4.h │ ├── vertexinfo.cc │ ├── vertexinfo.h │ ├── vertexinfo.o │ ├── vertexref.cc │ ├── vertexref.h │ └── vertexref.o ├── share ├── lh.HCP-MMP1.annot ├── lh.Yeo_17nets.annot ├── lh.Yeo_7nets.annot ├── reference_table_HCP-MMP.csv ├── reference_table_Yeo-17nets.csv ├── reference_table_Yeo-7nets.csv ├── reference_table_desikan.csv ├── reference_table_destrieux.csv ├── rh.HCP-MMP1.annot ├── rh.Yeo_17nets.annot └── rh.Yeo_7nets.annot ├── tests ├── README.MD ├── __pycache__ │ ├── test_pipeline.cpython-35-PYTEST.pyc │ └── test_pipeline.cpython-35.pyc ├── test_pipeline.sh └── test_test.sh └── util ├── HCP_pre_scripts.sh ├── aseg2srf ├── check_region_mapping.py ├── compute_connectivity_files.py ├── compute_connectivity_sub.py ├── compute_luts.py ├── correct_region_mapping.py ├── extract_bem.py ├── extract_high.py ├── list_subcortical.py ├── off2txt.py ├── region_mapping.py ├── region_mapping_other_parcellations.py ├── reunify_both_regions.py ├── subparcel.py └── txt2off.py /.gitignore: -------------------------------------------------------------------------------- 1 | # temp save 2 | *~ 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # To build this image, you'll need to download FreeSurfer, MNE 2 | # and have a valid FreeSurfer license file, and put them into your scripts directory. 3 | # To build: cd path_to_scripts; docker build -t docker_scripts . 4 | # To run: docker run -it -v :/opt/processing docker_scripts /bin/bash 5 | # Then run scripts as usual: bash main_surface -c /opt/processing/ 6 | # delete container and image: docker ps -a; docker rm ; docker rmi 7 | # also you can use: docker images 8 | 9 | FROM ubuntu:16.04 10 | MAINTAINER timpx 11 | 12 | # /opt used during installation, but 13 | # /opt/scripts is final workdir, set below 14 | WORKDIR /opt 15 | 16 | # system packages 17 | RUN apt-get update && apt-get install -y wget \ 18 | && wget -O- http://neuro.debian.net/lists/xenial.de-m.full | tee /etc/apt/sources.list.d/neurodebian.sources.list \ 19 | && apt-get update \ 20 | && apt-get install -y --allow-unauthenticated g++ libeigen3-dev git python \ 21 | python-numpy zlib1g-dev fsl-complete gcc make cmake libopenblas-dev liblapacke-dev \ 22 | libhdf5-dev libhdf5-serial-dev libmatio-dev python-dev swig libvtk6-dev doxygen \ 23 | libcgal-dev libgsl-dev gsl-bin libgsl2 unzip zip 24 | 25 | # external packages 26 | ADD freesurfer*.tar.gz /opt/ 27 | ADD license.txt /opt/freesurfer/license.txt 28 | ADD MNE*.tar.gz /opt/ 29 | 30 | # FS, FSL, MNE env vars 31 | ENV FIX_VERTEX_AREA= \ 32 | FREESURFER_HOME=/opt/freesurfer \ 33 | FSFAST_HOME=/opt/freesurfer/fsfast \ 34 | FSF_OUTPUT_FORMAT=nii.gz \ 35 | FS_OVERRIDE=0 \ 36 | LOCAL_DIR=/opt/freesurfer/local \ 37 | MINC_BIN_DIR=/opt/freesurfer/mni/bin \ 38 | MINC_LIB_DIR=/opt/freesurfer/mni/lib \ 39 | SUBJECTS_DIR=/opt/freesurfer/subjects \ 40 | MNI_DATAPATH=/opt/freesurfer/mni/data \ 41 | MNI_DIR=/opt/freesurfer/mni \ 42 | MNI_PERL5LIB=/opt/freesurfer/mni/share/perl5 \ 43 | OS=Linux \ 44 | PERL5LIB=/opt/freesurfer/mni/share/perl5 \ 45 | MNE_ROOT=/opt/MNE-2.7.0-3106-Linux-x86_64 \ 46 | MNE_BIN_PATH=/opt/MNE-2.7.0-3106-Linux-x86_64/bin \ 47 | MNE_LIB_PATH=/opt/MNE-2.7.0-3106-Linux-x86_64/lib \ 48 | MNE_ROOT=/opt/MNE-2.7.0-3106-Linux-x86_64 \ 49 | XUSERFILESEARCHPATH=/opt/MNE-2.7.0-3106-Linux-x86_64/share/app-defaults/%N \ 50 | LD_LIBRARY_PATH=/usr/lib/fsl/5.0:/opt/MNE-2.7.0-3106-Linux-x86_64/lib \ 51 | PATH=/usr/lib/fsl/5.0:/usr/share/fsl/5.0/bin:/opt/MNE-2.7.0-3106-Linux-x86_64/bin:/opt/freesurfer/bin:/opt/freesurfer/fsfast/bin:/opt/freesurfer/tktools:/opt/freesurfer/mni/bin:$PATH \ 52 | FSLDIR=/usr/share/fsl/5.0 \ 53 | FSLBROWSER=/etc/alternatives/x-www-browser \ 54 | FSLLOCKDIR= \ 55 | FSLMACHINELIST= \ 56 | FSLMULTIFILEQUIT=TRUE \ 57 | FSLOUTPUTTYPE=NIFTI_GZ \ 58 | FSLREMOTECALL= \ 59 | FSLTCLSH=/usr/bin/tclsh \ 60 | FSLWISH=/usr/bin/wish \ 61 | POSSUMDIR=/usr/share/fsl/5.0 62 | 63 | # Mrtrix3 64 | RUN git clone https://github.com/mrtrix3/mrtrix3 && cd mrtrix3 \ 65 | && git checkout 3.0_RC2 && ./configure -nogui && NUMBER_OF_PROCESSORS=1 ./build 66 | ENV MRT3=/opt/mrtrix3 67 | ENV PATH=/opt/mrtrix3/bin:$PATH 68 | 69 | # OpenMEEG 70 | RUN git clone https://github.com/openmeeg/openmeeg \ 71 | && cd openmeeg/OpenMEEG \ 72 | && git checkout 2.4.prerelease \ 73 | && mkdir build && cd build && \ 74 | cmake -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release \ 75 | -DENABLE_PYTHON=OFF -DCMAKE_INSTALL_PREFIX=/usr/local \ 76 | -DBLASLAPACK_IMPLEMENTATION="OpenBLAS" \ 77 | -DBUILD_DOCUMENTATION=OFF -DBUILD_TUTORIALS=OFF .. && \ 78 | make -j && \ 79 | make test && \ 80 | make install 81 | ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH 82 | 83 | # Py 3 stack 84 | RUN curl -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh 85 | RUN bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/conda 86 | ENV PATH=/opt/conda/bin:$PATH 87 | RUN conda install -c conda-forge jupyterlab \ 88 | && conda install numpy matplotlib \ 89 | && pip install nibabel mne 90 | 91 | # Scripts and remesher 92 | RUN git clone https://github.com/ins-amu/scripts 93 | RUN cd /opt/scripts/remesher/cmdremesher && make 94 | WORKDIR /opt/scripts 95 | RUN mkdir /opt/processing 96 | 97 | #TODO for compatibility with tvb-make 98 | # ENTRYPOINT ["make"] -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) [2014] [The SCRIPTS developers] 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Surface and Connectivity Reconstruction: Imaging Pipeline for TVB Simulations 2 | ## SCRIPTS 0.4.1 3 | 4 | Please see the [wiki](https://github.com/ins-amu/scripts/wiki) 5 | 6 | #### New in 0.4.1: 7 | - Remove need for Matlab 8 | - new subparcellation scheme where arbitrary number of subregions can be chosen 9 | 10 | #### New in 0.4: 11 | - Dockerfile for easy installation with Docker. 12 | - Tests. 13 | - Reorganization and simplification of the code => compatibility with tvb-make. 14 | - 2 new parcellations: Destrieux, and HCP-MMP1 15 | 16 | #### Features 17 | - prepare data for TVB: surface reconstruction, region mapping, connectome. 18 | - mrtrix 3.0 RC3: SIFT/SIFT2, ACT, 3 types of registration structural/diffusion, denoising, topup/eddy corrections, bias field corrections, mask upsampling and dilatation, multi-shell multi-tissue, dhollander algo, fsl subcortical structure parcellation, tractogram and tdi generation, multi-threaded. 19 | - automatic config checks. 20 | - convenience script for HCP datasets. 21 | - handle automatically reverse phase-encoding DWI in most cases. 22 | - subparcellation in any number of regions along with corresponding region mapping. 23 | - MNE forward model. 24 | - python 3.5. 25 | 26 | #### License 27 | This poject use the MIT License. 28 | The full license is in LICENSE.txt in the SCRIPTS distribution. 29 | 30 | Copyright (c) [2014] [The SCRIPTS Developers] 31 | 32 | #### How to cite 33 | 34 | When citing SCRIPTS, please cite this work: 35 | 36 | Proix T, Spiegler A, Schirner M, Rothmeier S, Ritter P, Jirsa, VK. How do parcellation size and short-range connectivity affect dynamics in large-scale brain network models? NeuroImage, 2016, 142:135-149 37 | -------------------------------------------------------------------------------- /remesher/Makefile.inc: -------------------------------------------------------------------------------- 1 | SHELL = /bin/sh 2 | 3 | ifeq (${OS},Windows_NT) 4 | PLATFORM = win32 5 | else 6 | PLATFORM = $(shell uname|tr '[:upper:]' '[:lower:]') 7 | endif 8 | include ../Makefile.$(PLATFORM) 9 | -------------------------------------------------------------------------------- /remesher/Makefile.linux: -------------------------------------------------------------------------------- 1 | COMPILER = g++ 2 | CORES = $(shell grep processor /proc/cpuinfo | wc -l) 3 | GCC_FLAGS = -Wall -W -ansi -pedantic -Wcast-align -Wcast-qual -Wpointer-arith -Wundef -Wconversion -g -O3 4 | -------------------------------------------------------------------------------- /remesher/cmdremesher/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.inc 2 | 3 | SOURCES = main.cc 4 | OBJECTS = $(foreach file,$(SOURCES),$(subst .cc,.o,$(file))) 5 | BINARY = cmdremesher 6 | 7 | GCC_INCL = -I.. 8 | GCC_LINK = -L../libremesh -lremesh -lpthread 9 | GSL_LIBS = $(shell pkg-config --libs gsl) 10 | 11 | all: libraries ${OBJECTS} 12 | ${COMPILER} -o ${BINARY} ${OBJECTS} ${GCC_LINK} ${GSL_LIBS} 13 | 14 | multicore: 15 | $(MAKE) -j${CORES} all 16 | 17 | depend: 18 | ${COMPILER} ${GCC_INCL} -MM ${SOURCES} > Makefile.dep 19 | 20 | %.o: %.cc 21 | ${COMPILER} -c -o $@ $< ${GCC_FLAGS} ${GCC_INCL} 22 | 23 | clean: FORCE 24 | rm -f ${BINARY} ${OBJECTS} 25 | 26 | libraries: FORCE 27 | $(MAKE) -C ../libremesh 28 | 29 | FORCE: 30 | 31 | include Makefile.dep 32 | -------------------------------------------------------------------------------- /remesher/cmdremesher/Makefile.dep: -------------------------------------------------------------------------------- 1 | main.o: main.cc ../libremesh/modelwriter.h ../libremesh/defines.h \ 2 | ../libremesh/trianglemesh.h ../libremesh/refptr.h \ 3 | ../libremesh/refptr_mt.h ../libremesh/thread.h \ 4 | ../libremesh/thread_posix.h ../libremesh/vec3.h ../libremesh/defines.h \ 5 | ../libremesh/hrtimer.h ../libremesh/interface.h \ 6 | ../libremesh/vertexinfo.h ../libremesh/refptrarray.h \ 7 | ../libremesh/vertexref.h ../libremesh/vec2.h \ 8 | ../libremesh/simplification.h ../libremesh/plane.h \ 9 | ../libremesh/densityfield.h ../libremesh/featureedges.h \ 10 | ../libremesh/oversampling.h ../libremesh/resampling.h \ 11 | ../libremesh/meshskeleton.h ../libremesh/meshdecimation.h \ 12 | ../libremesh/meshcleanup.h ../libremesh/relaxlloyd.h \ 13 | ../libremesh/microdelaunay.h ../libremesh/polygon2.h \ 14 | ../libremesh/micropatch.h ../libremesh/relaxation.h \ 15 | ../libremesh/relocation.h ../libremesh/triangle2.h \ 16 | ../libremesh/matrix2.h ../libremesh/patchcache.h ../libremesh/patch2d.h \ 17 | ../libremesh/patch3d.h ../libremesh/relaxarea.h 18 | -------------------------------------------------------------------------------- /remesher/cmdremesher/cmdremesher: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/cmdremesher/cmdremesher -------------------------------------------------------------------------------- /remesher/cmdremesher/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/cmdremesher/main.o -------------------------------------------------------------------------------- /remesher/libgmm/gmm.h: -------------------------------------------------------------------------------- 1 | // -*- c++ -*- (enables emacs c++ mode) 2 | //=========================================================================== 3 | // 4 | // Copyright (C) 2002-2008 Yves Renard 5 | // 6 | // This file is a part of GETFEM++ 7 | // 8 | // Getfem++ is free software; you can redistribute it and/or modify it 9 | // under the terms of the GNU Lesser General Public License as published 10 | // by the Free Software Foundation; either version 2.1 of the License, or 11 | // (at your option) any later version. 12 | // This program is distributed in the hope that it will be useful, but 13 | // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | // License for more details. 16 | // You should have received a copy of the GNU Lesser General Public License 17 | // along with this program; if not, write to the Free Software Foundation, 18 | // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 19 | // 20 | // As a special exception, you may use this file as it is a part of a free 21 | // software library without restriction. Specifically, if other files 22 | // instantiate templates or use macros or inline functions from this file, 23 | // or you compile this file and link it with other files to produce an 24 | // executable, this file does not by itself cause the resulting executable 25 | // to be covered by the GNU Lesser General Public License. This exception 26 | // does not however invalidate any other reasons why the executable file 27 | // might be covered by the GNU Lesser General Public License. 28 | // 29 | //=========================================================================== 30 | 31 | /**@file gmm.h 32 | @author Yves Renard 33 | @date October 13, 2002. 34 | @brief Include common gmm files. 35 | */ 36 | #ifndef GMM_H__ 37 | #define GMM_H__ 38 | 39 | #include "gmm_kernel.h" 40 | #include "gmm_dense_lu.h" 41 | #include "gmm_dense_qr.h" 42 | 43 | #include "gmm_iter_solvers.h" 44 | #include "gmm_condition_number.h" 45 | #include "gmm_inoutput.h" 46 | 47 | #include "gmm_lapack_interface.h" 48 | #include "gmm_superlu_interface.h" 49 | 50 | 51 | #include "gmm_domain_decomp.h" 52 | 53 | #endif // GMM_H__ 54 | -------------------------------------------------------------------------------- /remesher/libgmm/gmm_interface_bgeot.h: -------------------------------------------------------------------------------- 1 | // -*- c++ -*- (enables emacs c++ mode) 2 | //=========================================================================== 3 | // 4 | // Copyright (C) 2002-2008 Yves Renard 5 | // 6 | // This file is a part of GETFEM++ 7 | // 8 | // Getfem++ is free software; you can redistribute it and/or modify it 9 | // under the terms of the GNU Lesser General Public License as published 10 | // by the Free Software Foundation; either version 2.1 of the License, or 11 | // (at your option) any later version. 12 | // This program is distributed in the hope that it will be useful, but 13 | // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | // License for more details. 16 | // You should have received a copy of the GNU Lesser General Public License 17 | // along with this program; if not, write to the Free Software Foundation, 18 | // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 19 | // 20 | // As a special exception, you may use this file as it is a part of a free 21 | // software library without restriction. Specifically, if other files 22 | // instantiate templates or use macros or inline functions from this file, 23 | // or you compile this file and link it with other files to produce an 24 | // executable, this file does not by itself cause the resulting executable 25 | // to be covered by the GNU Lesser General Public License. This exception 26 | // does not however invalidate any other reasons why the executable file 27 | // might be covered by the GNU Lesser General Public License. 28 | // 29 | //=========================================================================== 30 | 31 | /**@file gmm_interface_bgeot.h 32 | @author Yves Renard 33 | @date October 13, 2002. 34 | @brief interface for bgeot::small_vector 35 | */ 36 | #ifndef GMM_INTERFACE_BGEOT_H__ 37 | #define GMM_INTERFACE_BGEOT_H__ 38 | 39 | 40 | namespace gmm { 41 | 42 | /* ********************************************************************* */ 43 | /* */ 44 | /* Traits for bgeot objects */ 45 | /* */ 46 | /* ********************************************************************* */ 47 | 48 | template struct linalg_traits > { 49 | typedef bgeot::small_vector this_type; 50 | typedef this_type origin_type; 51 | typedef linalg_false is_reference; 52 | typedef abstract_vector linalg_type; 53 | typedef T value_type; 54 | typedef T& reference; 55 | typedef typename this_type::iterator iterator; 56 | typedef typename this_type::const_iterator const_iterator; 57 | typedef abstract_dense storage_type; 58 | typedef linalg_true index_sorted; 59 | static size_type size(const this_type &v) { return v.size(); } 60 | static iterator begin(this_type &v) { return v.begin(); } 61 | static const_iterator begin(const this_type &v) { return v.begin(); } 62 | static iterator end(this_type &v) { return v.end(); } 63 | static const_iterator end(const this_type &v) { return v.end(); } 64 | static origin_type* origin(this_type &v) { return &v; } 65 | static const origin_type* origin(const this_type &v) { return &v; } 66 | static void clear(origin_type* o, const iterator &it, const iterator &ite) 67 | { std::fill(it, ite, value_type(0)); } 68 | static void do_clear(this_type &v) 69 | { std::fill(v.begin(), v.end(), value_type(0)); } 70 | static value_type access(const origin_type *, const const_iterator &it, 71 | const const_iterator &, size_type i) 72 | { return it[i]; } 73 | static reference access(origin_type *, const iterator &it, 74 | const iterator &, size_type i) 75 | { return it[i]; } 76 | static void resize(this_type &v, size_type n) { v.resize(n); } 77 | }; 78 | 79 | } 80 | 81 | 82 | #endif // GMM_INTERFACE_BGEOT_H__ 83 | -------------------------------------------------------------------------------- /remesher/libgmm/gmm_kernel.h: -------------------------------------------------------------------------------- 1 | // -*- c++ -*- (enables emacs c++ mode) 2 | //=========================================================================== 3 | // 4 | // Copyright (C) 2002-2008 Yves Renard 5 | // 6 | // This file is a part of GETFEM++ 7 | // 8 | // Getfem++ is free software; you can redistribute it and/or modify it 9 | // under the terms of the GNU Lesser General Public License as published 10 | // by the Free Software Foundation; either version 2.1 of the License, or 11 | // (at your option) any later version. 12 | // This program is distributed in the hope that it will be useful, but 13 | // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | // License for more details. 16 | // You should have received a copy of the GNU Lesser General Public License 17 | // along with this program; if not, write to the Free Software Foundation, 18 | // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 19 | // 20 | // As a special exception, you may use this file as it is a part of a free 21 | // software library without restriction. Specifically, if other files 22 | // instantiate templates or use macros or inline functions from this file, 23 | // or you compile this file and link it with other files to produce an 24 | // executable, this file does not by itself cause the resulting executable 25 | // to be covered by the GNU Lesser General Public License. This exception 26 | // does not however invalidate any other reasons why the executable file 27 | // might be covered by the GNU Lesser General Public License. 28 | // 29 | //=========================================================================== 30 | 31 | /**@file gmm_kernel.h 32 | @author Yves Renard 33 | @date November 15, 2003. 34 | @brief Include the base gmm files. 35 | */ 36 | 37 | #ifndef GMM_KERNEL_H__ 38 | #define GMM_KERNEL_H__ 39 | 40 | #include "gmm_def.h" 41 | #include "gmm_blas.h" 42 | #include "gmm_real_part.h" 43 | #include "gmm_interface.h" 44 | #include "gmm_sub_vector.h" 45 | #include "gmm_sub_matrix.h" 46 | #include "gmm_vector_to_matrix.h" 47 | #include "gmm_vector.h" 48 | #include "gmm_matrix.h" 49 | #include "gmm_tri_solve.h" 50 | #include "gmm_blas_interface.h" 51 | 52 | 53 | #endif // GMM_KERNEL_H__ 54 | -------------------------------------------------------------------------------- /remesher/libgmm/gmm_least_squares_cg.h: -------------------------------------------------------------------------------- 1 | // -*- c++ -*- (enables emacs c++ mode) 2 | //=========================================================================== 3 | // 4 | // Copyright (C) 2002-2008 Yves Renard 5 | // 6 | // This file is a part of GETFEM++ 7 | // 8 | // Getfem++ is free software; you can redistribute it and/or modify it 9 | // under the terms of the GNU Lesser General Public License as published 10 | // by the Free Software Foundation; either version 2.1 of the License, or 11 | // (at your option) any later version. 12 | // This program is distributed in the hope that it will be useful, but 13 | // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | // License for more details. 16 | // You should have received a copy of the GNU Lesser General Public License 17 | // along with this program; if not, write to the Free Software Foundation, 18 | // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 19 | // 20 | // As a special exception, you may use this file as it is a part of a free 21 | // software library without restriction. Specifically, if other files 22 | // instantiate templates or use macros or inline functions from this file, 23 | // or you compile this file and link it with other files to produce an 24 | // executable, this file does not by itself cause the resulting executable 25 | // to be covered by the GNU Lesser General Public License. This exception 26 | // does not however invalidate any other reasons why the executable file 27 | // might be covered by the GNU Lesser General Public License. 28 | // 29 | //=========================================================================== 30 | 31 | /**@file gmm_leastsquares_cg.h 32 | @author Benjamin Schleimer 33 | @date January 23, 2007. 34 | @brief Conjugate gradient least squares algorithm. 35 | Algorithm taken from http://www.stat.washington.edu/wxs/Stat538-w05/Notes/conjugate-gradients.pdf page 6 36 | */ 37 | #ifndef GMM_LEAST_SQUARES_CG_H__ 38 | #define GMM_LEAST_SQUARES_CG_H__ 39 | 40 | #include "gmm_kernel.h" 41 | #include "gmm_iter.h" 42 | #include "gmm_conjugated.h" 43 | 44 | namespace gmm { 45 | 46 | template 47 | void least_squares_cg(const Matrix& C, Vector1& x, const Vector2& y, 48 | iteration &iter) { 49 | 50 | typedef typename temporary_dense_vector::vector_type temp_vector; 51 | typedef typename linalg_traits::value_type T; 52 | 53 | T rho, rho_1(0), a; 54 | temp_vector p(vect_size(x)), q(vect_size(y)), g(vect_size(x)); 55 | temp_vector r(vect_size(y)); 56 | iter.set_rhsnorm(gmm::sqrt(gmm::abs(vect_hp(y, y)))); 57 | 58 | if (iter.get_rhsnorm() == 0.0) 59 | clear(x); 60 | else { 61 | mult(C, scaled(x, T(-1)), y, r); 62 | mult(conjugated(C), r, g); 63 | rho = vect_hp(g, g); 64 | copy(g, p); 65 | 66 | while (!iter.finished_vect(g)) { 67 | 68 | if (!iter.first()) { 69 | rho = vect_hp(g, g); 70 | add(g, scaled(p, rho / rho_1), p); 71 | } 72 | 73 | mult(C, p, q); 74 | 75 | a = rho / vect_hp(q, q); 76 | add(scaled(p, a), x); 77 | add(scaled(q, -a), r); 78 | // NOTE: how do we minimize the impact to the transpose? 79 | mult(conjugated(C), r, g); 80 | rho_1 = rho; 81 | 82 | ++iter; 83 | } 84 | } 85 | } 86 | 87 | template inline 89 | void least_squares_cg(const Matrix& C, const Vector1& x, const Vector2& y, 90 | iteration &iter) 91 | { least_squares_cg(C, linalg_const_cast(x), y, iter); } 92 | } 93 | 94 | 95 | #endif // GMM_SOLVER_CG_H__ 96 | -------------------------------------------------------------------------------- /remesher/libgmm/gmm_modified_gram_schmidt.h: -------------------------------------------------------------------------------- 1 | // -*- c++ -*- (enables emacs c++ mode) 2 | //=========================================================================== 3 | // 4 | // Copyright (C) 1997-2008 Yves Renard 5 | // 6 | // This file is a part of GETFEM++ 7 | // 8 | // Getfem++ is free software; you can redistribute it and/or modify it 9 | // under the terms of the GNU Lesser General Public License as published 10 | // by the Free Software Foundation; either version 2.1 of the License, or 11 | // (at your option) any later version. 12 | // This program is distributed in the hope that it will be useful, but 13 | // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | // License for more details. 16 | // You should have received a copy of the GNU Lesser General Public License 17 | // along with this program; if not, write to the Free Software Foundation, 18 | // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 19 | // 20 | // As a special exception, you may use this file as it is a part of a free 21 | // software library without restriction. Specifically, if other files 22 | // instantiate templates or use macros or inline functions from this file, 23 | // or you compile this file and link it with other files to produce an 24 | // executable, this file does not by itself cause the resulting executable 25 | // to be covered by the GNU Lesser General Public License. This exception 26 | // does not however invalidate any other reasons why the executable file 27 | // might be covered by the GNU Lesser General Public License. 28 | // 29 | //=========================================================================== 30 | 31 | /**@file gmm_modified_gram_schmidt.h 32 | @author Andrew Lumsdaine , Lie-Quan Lee 33 | @date October 13, 2002. 34 | @brief Modified Gram-Schmidt orthogonalization 35 | */ 36 | 37 | #ifndef GMM_MODIFIED_GRAM_SCHMIDT_H 38 | #define GMM_MODIFIED_GRAM_SCHMIDT_H 39 | 40 | #include "gmm_kernel.h" 41 | 42 | namespace gmm { 43 | 44 | template 45 | class modified_gram_schmidt { 46 | protected: 47 | typedef dense_matrix MAT; 48 | MAT M; 49 | 50 | public: 51 | 52 | modified_gram_schmidt(int restart, size_t s) : M(s, restart+1) {} 53 | 54 | typename linalg_traits::const_sub_col_type 55 | operator[](size_t i) const { return mat_const_col(M, i); } 56 | 57 | typename linalg_traits::sub_col_type 58 | operator[](size_t i) { return mat_col(M, i); } 59 | 60 | inline size_type nrows(void) const { return M.nrows(); } 61 | inline size_type ncols(void) const { return M.ncols(); } 62 | MAT &mat(void) { return M; } 63 | const MAT &mat(void) const { return M; } 64 | 65 | }; 66 | 67 | template inline 68 | void orthogonalize(modified_gram_schmidt& V, const VecHi& Hi_, size_t i) { 69 | VecHi& Hi = const_cast(Hi_); 70 | 71 | for (size_t k = 0; k <= i; k++) { 72 | Hi[k] = gmm::vect_hp(V[i+1], V[k]); 73 | gmm::add(gmm::scaled(V[k], -Hi[k]), V[i+1]); 74 | } 75 | } 76 | 77 | template 78 | void orthogonalize_with_refinment(modified_gram_schmidt& V, 79 | const VecHi& Hi_, size_t i) { 80 | VecHi& Hi = const_cast(Hi_); 81 | orthogonalize(V, Hi_, i); 82 | 83 | sub_interval SUBI(0, V.nrows()), SUBJ(0, i+1); 84 | std::vector corr(i+1); 85 | gmm::mult(conjugated(sub_matrix(V.mat(), SUBI, SUBJ)), 86 | V[i+1], corr); 87 | gmm::mult(sub_matrix(V.mat(), SUBI, SUBJ), 88 | scaled(corr, T(-1)), V[i+1],V[i+1]); 89 | gmm::add(corr, sub_vector(Hi, SUBJ)); 90 | } 91 | 92 | template 93 | void combine(modified_gram_schmidt& V, const VecS& s, VecX& x, size_t i) 94 | { for (size_t j = 0; j < i; ++j) gmm::add(gmm::scaled(V[j], s[j]), x); } 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /remesher/libgmm/gmm_precond.h: -------------------------------------------------------------------------------- 1 | // -*- c++ -*- (enables emacs c++ mode) 2 | //=========================================================================== 3 | // 4 | // Copyright (C) 2004-2008 Yves Renard 5 | // 6 | // This file is a part of GETFEM++ 7 | // 8 | // Getfem++ is free software; you can redistribute it and/or modify it 9 | // under the terms of the GNU Lesser General Public License as published 10 | // by the Free Software Foundation; either version 2.1 of the License, or 11 | // (at your option) any later version. 12 | // This program is distributed in the hope that it will be useful, but 13 | // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | // License for more details. 16 | // You should have received a copy of the GNU Lesser General Public License 17 | // along with this program; if not, write to the Free Software Foundation, 18 | // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 19 | // 20 | // As a special exception, you may use this file as it is a part of a free 21 | // software library without restriction. Specifically, if other files 22 | // instantiate templates or use macros or inline functions from this file, 23 | // or you compile this file and link it with other files to produce an 24 | // executable, this file does not by itself cause the resulting executable 25 | // to be covered by the GNU Lesser General Public License. This exception 26 | // does not however invalidate any other reasons why the executable file 27 | // might be covered by the GNU Lesser General Public License. 28 | // 29 | //=========================================================================== 30 | #ifndef GMM_PRECOND_H 31 | #define GMM_PRECOND_H 32 | 33 | #include "gmm_kernel.h" 34 | 35 | /** @file gmm_precond.h 36 | @author Yves Renard 37 | @date March 29, 2004. 38 | @brief gmm preconditioners. 39 | */ 40 | 41 | /* Preconditioner concept : */ 42 | /* */ 43 | /* A the matrix, P the preconditioner PA well conditioned. */ 44 | /* PRECOND precontioner type. */ 45 | /* mult(P, v, w) : w <- P v */ 46 | /* transposed_mult(P, v, w) : w <- transposed(P) v */ 47 | /* left_mult(P, v, w) : see qmr solver */ 48 | /* right_mult(P, v, w) : see qmr solver */ 49 | /* transposed_left_mult(P, v, w) : see qmr solver */ 50 | /* transposed_right_mult(P, v, w) : see qmr solver */ 51 | /* */ 52 | /* PRECOND P() : empty preconditioner. */ 53 | /* PRECOND P(A, ...) : preconditioner for the matrix A, with optional */ 54 | /* parameters */ 55 | /* PRECOND(...) : empty precondtioner with parameters set. */ 56 | /* P.build_with(A) : build a precondtioner for A. */ 57 | /* */ 58 | /* *********************************************************************** */ 59 | 60 | 61 | 62 | 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /remesher/libgmm/gmm_solver_idgmres.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libgmm/gmm_solver_idgmres.h -------------------------------------------------------------------------------- /remesher/libremesh/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.inc 2 | 3 | SOURCES = interface.cc \ 4 | modelwriter.cc modelloader.cc trianglemesh.cc \ 5 | helpers.cc averageplane.cc micropatch.cc microdelaunay.cc \ 6 | relocation.cc polygon2.cc triangulator.cc \ 7 | simplification.cc meshcleanup.cc meshoptimize.cc \ 8 | oversampling.cc meshslicing.cc relaxation.cc relaxanglesmooth.cc \ 9 | subdivbase.cc subdivlinear.cc subdivloop.cc meshdecimation.cc \ 10 | edgeflips.cc delaunayflips.cc resampling.cc incdelaunay.cc \ 11 | vertexinfo.cc vertexref.cc patch3d.cc patch2d_fb.cc patch2d.cc \ 12 | densityfield.cc featureedges.cc meshskeleton.cc patchcache.cc \ 13 | pntriangle.cc meshstats.cc cvtstats.cc gslpolysolve.cc 14 | 15 | OBJECTS = $(foreach file,$(SOURCES),$(subst .cc,.o,$(file))) 16 | LIBRARY = libremesh.a 17 | GCC_INCL = -I.. 18 | 19 | all: ${OBJECTS} 20 | ar rcs ${LIBRARY} ${OBJECTS} 21 | chmod a+x ${LIBRARY} 22 | 23 | test: ${OBJECTS} test.cc test.o 24 | ${COMPILER} -o test test.o ${OBJECTS} -lpthread 25 | 26 | multicore: 27 | $(MAKE) -j${CORES} all 28 | 29 | depend: 30 | ${COMPILER} ${GCC_INCL} -MM ${SOURCES} > Makefile.dep 31 | 32 | %.o: %.cc 33 | ${COMPILER} -c -o $@ $< ${GCC_FLAGS} ${GCC_INCL} -Wno-deprecated 34 | 35 | clean: FORCE 36 | rm -f ${OBJECTS} ${LIBRARY} test.o test 37 | 38 | FORCE: 39 | 40 | include Makefile.dep 41 | -------------------------------------------------------------------------------- /remesher/libremesh/averageplane.cc: -------------------------------------------------------------------------------- 1 | #include "exception.h" 2 | #include "averageplane.h" 3 | 4 | #if AVG_PLANE_USE_GMM 5 | # define GETFEM_PARA_LEVEL 0 6 | # include "libgmm/gmm_matrix.h" 7 | # include "libgmm/gmm_dense_qr.h" 8 | #else 9 | # include 10 | # include 11 | # include 12 | #endif 13 | 14 | REMESHER_NAMESPACE_BEGIN 15 | 16 | Plane3f 17 | AveragePlane::get_average (std::vector const& points) 18 | { 19 | if (points.size() < 3) 20 | throw Exception("AveragePlane: Expected at least 3 points!"); 21 | 22 | /* Calculate centroid. */ 23 | Vec3f c(0.0f, 0.0f, 0.0f); 24 | for (std::size_t i = 0; i < points.size(); ++i) 25 | c += points[i]; 26 | c /= (float)points.size(); 27 | 28 | #if AVG_PLANE_USE_GMM 29 | 30 | /* 31 | * This version always creates a 3x3 Matrix and solves for eigenvalues. 32 | */ 33 | 34 | float a00 = 0.0f; 35 | float a11 = 0.0f; 36 | float a22 = 0.0f; 37 | float a01 = 0.0f; 38 | float a02 = 0.0f; 39 | float a12 = 0.0f; 40 | 41 | for (std::size_t i = 0; i < points.size(); ++i) 42 | { 43 | a00 += (points[i][0] - c[0]) * (points[i][0] - c[0]); 44 | a11 += (points[i][1] - c[1]) * (points[i][1] - c[1]); 45 | a22 += (points[i][2] - c[2]) * (points[i][2] - c[2]); 46 | a01 += (points[i][0] - c[0]) * (points[i][1] - c[1]); 47 | a02 += (points[i][0] - c[0]) * (points[i][2] - c[2]); 48 | a12 += (points[i][1] - c[1]) * (points[i][2] - c[2]); 49 | } 50 | 51 | /* Setup matrix. */ 52 | gmm::dense_matrix matrix_m(3, 3); 53 | matrix_m(0, 0) = a00; matrix_m(0, 1) = a01; matrix_m(0, 2) = a02; 54 | matrix_m(1, 0) = a01; matrix_m(1, 1) = a11; matrix_m(1, 2) = a12; 55 | matrix_m(2, 0) = a02; matrix_m(2, 1) = a12; matrix_m(2, 2) = a22; 56 | 57 | /* Solve for eigenvalues and eigenvectors. */ 58 | std::vector vec_ev(3); 59 | gmm::dense_matrix matrix_ev(3, 3); 60 | gmm::symmetric_qr_algorithm(matrix_m, vec_ev, matrix_ev, MY_FLT_EPS); 61 | 62 | int min_elem = 0; 63 | for (int i = 1; i < 3; ++i) 64 | if (std::abs(vec_ev[i]) < std::abs(vec_ev[min_elem])) 65 | min_elem = i; 66 | 67 | Vec3f normal(matrix_ev(0, min_elem), 68 | matrix_ev(1, min_elem), 69 | matrix_ev(2, min_elem)); 70 | 71 | #else /* Use GSL */ 72 | 73 | /* 74 | * This version always creates a Nx3 Matrix and performes SVD. 75 | */ 76 | 77 | /* Create Matrix M */ 78 | gsl_matrix* matrix_m = gsl_matrix_alloc(points.size(), 3); 79 | for (std::size_t i = 0; i < points.size(); ++i) 80 | { 81 | Vec3f p = points[i] - c; 82 | //std::cout << p[0] << " " << p[1] << " " << p[2] << std::endl; 83 | gsl_matrix_set(matrix_m, i, 0, p[0]); 84 | gsl_matrix_set(matrix_m, i, 1, p[1]); 85 | gsl_matrix_set(matrix_m, i, 2, p[2]); 86 | } 87 | 88 | /* Singular Value Decomposition of M = U S V^T. */ 89 | gsl_matrix* matrix_v = gsl_matrix_alloc(3, 3); 90 | gsl_vector* vector_s = gsl_vector_alloc(3); 91 | gsl_vector* gsl_work = gsl_vector_alloc(3); 92 | 93 | /* Singular value decomposition, M = USV^T. M is replaced by U. */ 94 | gsl_linalg_SV_decomp(matrix_m, matrix_v, vector_s, gsl_work); 95 | 96 | //gsl_matrix_fprintf(stdout, matrix_v, "%f"); 97 | //std::cout << std::endl; 98 | //gsl_vector_fprintf(stdout, vector_s, "%f"); 99 | 100 | gsl_matrix_free(matrix_m); 101 | gsl_vector_free(gsl_work); 102 | 103 | /* Retrieve plane normal. */ 104 | Vec3f normal; 105 | 106 | { 107 | /* Find singular vector for smallest singular value. */ 108 | std::size_t sidx = 0; 109 | double sval = 0.0; 110 | for (std::size_t i = 0; i < 3; ++i) 111 | { 112 | double si = gsl_vector_get(vector_s, i); 113 | if (i == 0 || sval > si) 114 | { 115 | sidx = i; 116 | sval = si; 117 | } 118 | } 119 | 120 | normal[0] = (float)gsl_matrix_get(matrix_v, 0, sidx); 121 | normal[1] = (float)gsl_matrix_get(matrix_v, 1, sidx); 122 | normal[2] = (float)gsl_matrix_get(matrix_v, 2, sidx); 123 | } 124 | 125 | gsl_matrix_free(matrix_v); 126 | gsl_vector_free(vector_s); 127 | 128 | #endif 129 | 130 | /* Set plane from centroid and normal. */ 131 | return Plane3f(normal, c); 132 | } 133 | 134 | REMESHER_NAMESPACE_END 135 | -------------------------------------------------------------------------------- /remesher/libremesh/averageplane.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_AVERAGE_PLANE_HEADER 2 | #define REMESHER_AVERAGE_PLANE_HEADER 3 | 4 | #include 5 | 6 | #include "vec3.h" 7 | #include "plane.h" 8 | #include "defines.h" 9 | 10 | /* Use GSL or GMM to solve the system. */ 11 | #define AVG_PLANE_USE_GMM 1 12 | 13 | REMESHER_NAMESPACE_BEGIN 14 | 15 | class AveragePlane 16 | { 17 | private: 18 | std::vector points; 19 | 20 | public: 21 | /* Copying points to this class. */ 22 | void set_points (std::vector const& points); 23 | void add_point (Vec3f const& point); 24 | void clear_points (void); 25 | 26 | /* Calculate average plane from copied points. */ 27 | Plane3f get_average (void); 28 | 29 | /* Calculate average plane from a given set of points. */ 30 | Plane3f get_average (std::vector const& points); 31 | }; 32 | 33 | /* ---------------------------------------------------------------- */ 34 | 35 | inline void 36 | AveragePlane::set_points (std::vector const& points) 37 | { 38 | this->points = points; 39 | } 40 | 41 | inline void 42 | AveragePlane::clear_points (void) 43 | { 44 | this->points.clear(); 45 | } 46 | 47 | inline void 48 | AveragePlane::add_point (Vec3f const& point) 49 | { 50 | this->points.push_back(point); 51 | } 52 | 53 | inline Plane3f 54 | AveragePlane::get_average (void) 55 | { 56 | return this->get_average(this->points); 57 | } 58 | 59 | REMESHER_NAMESPACE_END 60 | 61 | #endif /* REMESHER_AVERAGE_PLANE_HEADER */ 62 | -------------------------------------------------------------------------------- /remesher/libremesh/averageplane.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/averageplane.o -------------------------------------------------------------------------------- /remesher/libremesh/cvtstats.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "microdelaunay.h" 7 | #include "cvtstats.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | void 12 | CvtStats::calc_stats (std::string const& gp_filename) 13 | { 14 | MeshVertexList const& everts(this->emesh->get_vertices()); 15 | 16 | //if (this->evinfo.get() == 0 || this->evinfo->size() != everts.size()) 17 | // this->evinfo = VertexInfoList::create(this->emesh); 18 | 19 | std::vector > meshinfo; 20 | 21 | /* Calc the mass for each Voronoi region. */ 22 | for (std::size_t i = 0; i < everts.size(); ++i) 23 | { 24 | if (this->evinfo[i].vclass != VERTEX_CLASS_SIMPLE) 25 | continue; 26 | 27 | VertexInfo::VertexList vlist; 28 | this->evinfo->get_adjacent_vertices(i, vlist); 29 | 30 | /* Build micro patch. */ 31 | MicroDelaunay md; 32 | md.set_center_vertex(everts[i]); 33 | for (std::size_t j = 0; j < vlist.size(); ++j) 34 | md.append_adjacent_vertex(everts[vlist[j]]); 35 | md.calculate_patch(); 36 | 37 | /* Set density values if available. */ 38 | if (this->rdens.get() != 0 && !this->rdens->empty()) 39 | { 40 | bool valid_density = true; 41 | { 42 | VertexRef const& ref = this->evref[i]; 43 | VertexDensity vd = this->rdens->get_density(ref.face, ref.bary); 44 | md.set_center_density(vd.density); 45 | valid_density = valid_density && vd.valid; 46 | } 47 | for (std::size_t i = 0; i < vlist.size(); ++i) 48 | { 49 | VertexRef const& ref = this->evref[vlist[i]]; 50 | VertexDensity vd = this->rdens->get_density(ref.face, ref.bary); 51 | md.append_adjacent_density(vd.density); 52 | valid_density = valid_density && vd.valid; 53 | } 54 | if (!valid_density) 55 | md.clear_adjacent_density(); 56 | } 57 | 58 | /* Get mass of the Voronoi cell. */ 59 | float area, mass; 60 | md.get_voronoi_area_and_mass(area, mass); 61 | meshinfo.push_back(std::make_pair(area, mass)); 62 | } 63 | 64 | if (gp_filename.empty()) 65 | return; 66 | 67 | std::ofstream out_a((gp_filename + "_area").c_str()); 68 | std::ofstream out_m((gp_filename + "_mass").c_str()); 69 | for (std::size_t i = 0; i < meshinfo.size(); ++i) 70 | { 71 | out_a << i << " " << meshinfo[i].first << std::endl; 72 | out_m << i << " " << meshinfo[i].second << std::endl; 73 | } 74 | std::cout << "Wrote " << meshinfo.size() << " values to file" << std::endl; 75 | out_a.close(); 76 | out_m.close(); 77 | } 78 | 79 | REMESHER_NAMESPACE_END 80 | -------------------------------------------------------------------------------- /remesher/libremesh/cvtstats.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_CVT_STATS_HEADER 2 | #define REMESHER_CVT_STATS_HEADER 3 | 4 | #include "trianglemesh.h" 5 | #include "densityfield.h" 6 | #include "vertexref.h" 7 | #include "vertexinfo.h" 8 | #include "defines.h" 9 | 10 | REMESHER_NAMESPACE_BEGIN 11 | 12 | class CvtStats 13 | { 14 | private: 15 | TriangleMeshPtr rmesh; 16 | DensityFieldPtr rdens; 17 | 18 | TriangleMeshPtr emesh; 19 | VertexInfoListPtr evinfo; 20 | VertexRefListPtr evref; 21 | 22 | public: 23 | void set_ref_mesh (TriangleMeshPtr rmesh); 24 | void set_ref_density (DensityFieldPtr rdens); 25 | 26 | void set_evo_mesh (TriangleMeshPtr emesh); 27 | void set_evo_vinfo (VertexInfoListPtr evinfo); 28 | void set_evo_vref (VertexRefListPtr evref); 29 | 30 | void calc_stats (std::string const& gp_outfile); 31 | }; 32 | 33 | /* ---------------------------------------------------------------- */ 34 | 35 | inline void 36 | CvtStats::set_ref_mesh (TriangleMeshPtr rmesh) 37 | { 38 | this->rmesh = rmesh; 39 | } 40 | 41 | inline void 42 | CvtStats::set_ref_density (DensityFieldPtr rdens) 43 | { 44 | this->rdens = rdens; 45 | } 46 | 47 | inline void 48 | CvtStats::set_evo_mesh (TriangleMeshPtr emesh) 49 | { 50 | this->emesh = emesh; 51 | } 52 | 53 | inline void 54 | CvtStats::set_evo_vinfo (VertexInfoListPtr evinfo) 55 | { 56 | this->evinfo = evinfo; 57 | } 58 | 59 | inline void 60 | CvtStats::set_evo_vref (VertexRefListPtr evref) 61 | { 62 | this->evref = evref; 63 | } 64 | 65 | 66 | REMESHER_NAMESPACE_END 67 | 68 | #endif /* REMESHER_CVT_STATS_HEADER */ 69 | -------------------------------------------------------------------------------- /remesher/libremesh/cvtstats.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/cvtstats.o -------------------------------------------------------------------------------- /remesher/libremesh/defines.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_DEFINES_HEADER 2 | #define REMESHER_DEFINES_HEADER 3 | 4 | /* 5 | * Library compile-time configuration. 6 | */ 7 | 8 | /* Checks for NAN values. This is not very expensive. */ 9 | #define REMESHER_NAN_CHECKS 1 10 | #if REMESHER_NAN_CHECKS 11 | # ifdef WIN32 12 | namespace std 13 | { 14 | template 15 | inline bool isnan (T const& x) 16 | { return (x != x); } 17 | } 18 | # endif 19 | # define REMESHER_NAN_CHECK(x) if (std::isnan(x)) { \ 20 | std::cout << "NAN error in " << __FILE__ \ 21 | << ":" << __LINE__ << std::endl; } 22 | #else 23 | # define REMESHER_NAN_CHECK(x) /* x */ 24 | #endif 25 | 26 | /* Caching of patches improves performance A LOT. */ 27 | #define REMESHER_PATCH_CACHING 1 28 | #define REMESHER_PATCH_CACHE_SIZE (1 * 1024 * 1024 * 1024) // 1GB 29 | 30 | /* Fast cache lookup requires more memory. Essential for parallelization. */ 31 | #define REMESHER_FAST_PATCH_LOOKUP 1 32 | 33 | /* Parallelization of the Lloyd relaxation. */ 34 | #define REMESHER_PARALLELIZATION 1 // 0 = no threads, 1 = threads 35 | #define REMESHER_RELAXATION_THREADS 8 36 | 37 | /* The namespace definition the library uses. */ 38 | #define REMESHER_NAMESPACE_BEGIN namespace Remesher { 39 | #define REMESHER_NAMESPACE_END } 40 | 41 | /* Error checks. */ 42 | #if REMESHER_PARALLELIZATION \ 43 | && REMESHER_PATCH_CACHING \ 44 | && !REMESHER_FAST_PATCH_LOOKUP 45 | # error "Parallelization without fast patch lookup performs very bad!" 46 | #endif 47 | 48 | #if REMESHER_PARALLELIZATION && REMESHER_RELAXATION_THREADS == 1 49 | # error "Parallelization is active for a single thread!" 50 | #endif 51 | 52 | /* Parametrization with free boundary or not? */ 53 | #define REMESHER_FB_PARAMETRIZATION 0 54 | 55 | /* 56 | * Sexy math. 57 | * Note that arguments for MY_MAX and MY_MIN should NOT be an 58 | * expensive expression, because either x or y is evaluated twice. 59 | */ 60 | #define MY_MAX(x, y) (x < y ? y : x) 61 | #define MY_MIN(x, y) (x < y ? x : y) 62 | #define MY_PI 3.14159265358979323846 63 | #define MY_2PI (2.0 * MY_PI) 64 | #define MY_PI2 (MY_PI / 2.0) 65 | #define MY_RAD2DEG(x) (x*360.0/(2.0*MY_PI)) 66 | #define MY_DEG2RAD(x) (x*(2.0*MY_PI/360.0)) 67 | #define MY_FLT_ROUND(x) ((float)((int)(x + 0.5f))) 68 | #define MY_DBL_ROUND(x) ((double)((int)(x + 0.5))) 69 | 70 | /* Floating point epsilon comparisons. */ 71 | #define MACHINE_FLT_EPSILON 1.1920928955078125e-07 72 | #define MACHINE_DBL_EPSILON 2.2204460492503131e-16 73 | #define MY_FLT_EPS (MACHINE_FLT_EPSILON * 10.0f) 74 | #define MY_DBL_EPS (MACHINE_DBL_EPSILON * 10.0) 75 | #define EPSILON_EQ(x,v,eps) (((v - eps) <= x) && (x <= (v + eps))) 76 | #define FLOAT_EQ(x,v) EPSILON_EQ(x,v,MY_FLT_EPS) 77 | #define DOUBLE_EQ(x,v) EPSILON_EQ(x,v,MY_DBL_EPS) 78 | 79 | /* Other useful defines and constants. */ 80 | #define MAX_SIZE_T ((std::size_t)-1) 81 | #define UNUSED(arg) /* arg */ 82 | 83 | #endif /* REMESHER_DEFINES_HEADER */ 84 | -------------------------------------------------------------------------------- /remesher/libremesh/delaunayflips.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "delaunayflips.h" 4 | 5 | REMESHER_NAMESPACE_BEGIN 6 | 7 | bool 8 | DelaunayFlips::check_flip_edge (std::size_t v1idx, 9 | std::size_t v2idx, std::size_t v0idx, std::size_t v3idx, 10 | std::size_t /* face1 */, std::size_t /* face2 */) 11 | { 12 | MeshVertexList const& verts = this->mesh->get_vertices(); 13 | 14 | /* Check angle: If the sum of the two opposite angles is >= 180, flip! */ 15 | float angle; 16 | { 17 | Vec3f e1 = (verts[v1idx] - verts[v0idx]).norm(); 18 | Vec3f e2 = (verts[v2idx] - verts[v0idx]).norm(); 19 | float scalar = e1.scalar(e2); 20 | scalar = MY_MIN(1.0f, scalar); 21 | scalar = MY_MAX(-1.0f, scalar); 22 | angle = std::acos(scalar); 23 | 24 | e1 = (verts[v1idx] - verts[v3idx]).norm(); 25 | e2 = (verts[v2idx] - verts[v3idx]).norm(); 26 | scalar = e1.scalar(e2); 27 | scalar = MY_MIN(1.0f, scalar); 28 | scalar = MY_MAX(-1.0f, scalar); 29 | angle += std::acos(scalar); 30 | } 31 | 32 | REMESHER_NAN_CHECK(angle) 33 | 34 | /* No need to flip. */ 35 | if (angle < MY_PI || FLOAT_EQ(angle, MY_PI)) 36 | return false; 37 | 38 | /* Check if flipping would destroy topology. */ 39 | if (this->vinfo->is_mesh_edge(v0idx, v3idx)) 40 | { 41 | //std::cout << "Flip denied! " << v0idx << " -> " << v3idx << std::endl; 42 | return false; 43 | } 44 | 45 | return true; 46 | } 47 | 48 | REMESHER_NAMESPACE_END 49 | -------------------------------------------------------------------------------- /remesher/libremesh/delaunayflips.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_DELAUNAY_FLIPS_HEADER 2 | #define REMESHER_DELAUNAY_FLIPS_HEADER 3 | 4 | #include "defines.h" 5 | #include "edgeflips.h" 6 | #include "vertexinfo.h" 7 | 8 | REMESHER_NAMESPACE_BEGIN 9 | 10 | /* 11 | * This class performs edge flips directly on the 3D mesh to 12 | * obtain a delaunay triangulation of the mesh. 13 | * Edge flips are performed if the sum of the angles opposite 14 | * to the edge sum up to less than 180 degrees. 15 | */ 16 | class DelaunayFlips : public EdgeFlipsBase 17 | { 18 | protected: 19 | bool check_flip_edge (std::size_t v1idx, 20 | std::size_t v2idx, std::size_t v0idx, std::size_t v3idx, 21 | std::size_t face1, std::size_t face2); 22 | 23 | public: 24 | DelaunayFlips (void); 25 | DelaunayFlips (TriangleMeshPtr mesh, VertexInfoListPtr vinfo); 26 | }; 27 | 28 | /* ---------------------------------------------------------------- */ 29 | 30 | inline 31 | DelaunayFlips::DelaunayFlips (void) 32 | { 33 | this->set_max_iterations(30); 34 | this->set_max_const_flips_iterations(3); 35 | } 36 | 37 | inline 38 | DelaunayFlips::DelaunayFlips (TriangleMeshPtr mesh, VertexInfoListPtr vinfo) 39 | { 40 | this->set_mesh(mesh); 41 | this->set_vertex_info(vinfo); 42 | this->set_max_iterations(30); 43 | this->set_max_const_flips_iterations(3); 44 | } 45 | 46 | REMESHER_NAMESPACE_END 47 | 48 | #endif /* REMESHER_DELAUNAY_FLIPS_HEADER */ 49 | -------------------------------------------------------------------------------- /remesher/libremesh/delaunayflips.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/delaunayflips.o -------------------------------------------------------------------------------- /remesher/libremesh/densityfield.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/densityfield.o -------------------------------------------------------------------------------- /remesher/libremesh/densitytriangle2.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_DENSITY_TRIANGLE_2_HEADER 2 | #define REMESHER_DENSITY_TRIANGLE_2_HEADER 3 | 4 | #include "defines.h" 5 | #include "triangle2.h" 6 | #include "vec2.h" 7 | #include "vec3.h" 8 | #include "matrix3.h" 9 | 10 | REMESHER_NAMESPACE_BEGIN 11 | 12 | template class DensityTriangle2; 13 | typedef DensityTriangle2 DensityTriangle2f; 14 | typedef DensityTriangle2 DensityTriangle2d; 15 | 16 | template 17 | class DensityTriangle2 : public Triangle2 18 | { 19 | public: 20 | Vec3 dens; 21 | 22 | public: 23 | DensityTriangle2 (void); 24 | DensityTriangle2 (Vec2 const& a, Vec2 const& b, 25 | Vec2 const& c, Vec3 const& dens); 26 | 27 | void set_dens (Vec3 const& dens); 28 | 29 | /* Returns the mass of the triangle, which is the non-uniform 30 | * area of the triangle using the density values at the vertices. */ 31 | T get_mass (void); 32 | 33 | Vec2 get_centroid (void); 34 | }; 35 | 36 | /* ---------------------------------------------------------------- */ 37 | 38 | template 39 | inline 40 | DensityTriangle2::DensityTriangle2 (void) 41 | { 42 | } 43 | 44 | template 45 | inline 46 | DensityTriangle2::DensityTriangle2 (Vec2 const& a, Vec2 const& b, 47 | Vec2 const& c, Vec3 const& dens) 48 | : Triangle2(a, b, c), dens(dens) 49 | { 50 | } 51 | 52 | template 53 | inline void 54 | DensityTriangle2::set_dens (Vec3 const& dens) 55 | { 56 | this->dens = dens; 57 | } 58 | 59 | template 60 | inline T 61 | DensityTriangle2::get_mass (void) 62 | { 63 | T area = this->get_area(); 64 | return area * (dens[0] + dens[1] + dens[2]) / (T)3; 65 | } 66 | 67 | template 68 | inline Vec2 69 | DensityTriangle2::get_centroid (void) 70 | { 71 | T area = this->get_area(); 72 | T mass3 = area * (dens[0] + dens[1] + dens[2]); 73 | 74 | Vec2 const& a = this->a; 75 | Vec2 const& b = this->b; 76 | Vec2 const& c = this->c; 77 | 78 | T cx = dens[0] * a[0] + dens[1] * b[0] + dens[2] * c[0] 79 | + (dens[0] * b[0] + dens[1] * a[0] 80 | + dens[0] * c[0] + dens[2] * a[0] 81 | + dens[1] * c[0] + dens[2] * b[0]) / 2.0f; 82 | T cy = dens[0] * a[1] + dens[1] * b[1] + dens[2] * c[1] 83 | + (dens[0] * b[1] + dens[1] * a[1] 84 | + dens[0] * c[1] + dens[2] * a[1] 85 | + dens[1] * c[1] + dens[2] * b[1]) / 2.0f; 86 | 87 | return Vec2(cx * area / ((T)2 * mass3), cy * area / ((T)2 * mass3)); 88 | } 89 | 90 | REMESHER_NAMESPACE_END 91 | 92 | #endif /* REMESHER_DENSITY_TRIANGLE_2_HEADER */ 93 | -------------------------------------------------------------------------------- /remesher/libremesh/edgeflips.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_EDGE_FLIPS_HEADER 2 | #define REMESHER_EDGE_FLIPS_HEADER 3 | 4 | #include "defines.h" 5 | #include "trianglemesh.h" 6 | #include "vertexinfo.h" 7 | #include "featureedges.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | /* 12 | * This class acts as base class for edge flipping algorithms. 13 | * It iterates over all edges (but no boundary edges) once and 14 | * calls a polymorph method to actually check if a flip is to 15 | * be performed. This is repeated until no more edge flips are 16 | * performed, or a iteration maximum is reached. 17 | */ 18 | class EdgeFlipsBase 19 | { 20 | protected: 21 | std::size_t max_iter; 22 | std::size_t max_const_flips_iter; 23 | std::size_t const_flips_iter; 24 | std::size_t last_flips; 25 | 26 | TriangleMeshPtr mesh; 27 | VertexInfoListPtr vinfo; 28 | FeatureEdgesPtr features; 29 | 30 | protected: 31 | /* Iterates over all edges and passes the edge to check_flip_edge 32 | * for edge flip tests. If the edge is OK to be flipped, the 33 | * check_flip_edge method is called. */ 34 | std::size_t check_flip_edges (void); 35 | 36 | /* This method must be overwritten. The arguments contain valid 37 | * vertices and faces, and the edge is safe to be flipped. 38 | * If the method should return true if the flip should be 39 | * performed, or return false otherweise, skipping the edge. */ 40 | virtual bool check_flip_edge (std::size_t v1idx, 41 | std::size_t v2idx, std::size_t v0idx, std::size_t v3idx, 42 | std::size_t face1, std::size_t face2) = 0; 43 | 44 | /* Actually performs the edge flip updating the data structures. */ 45 | void edge_flip (std::size_t v1idx, std::size_t v2idx, 46 | std::size_t v0idx, std::size_t v3idx, 47 | std::size_t face1, std::size_t face2); 48 | 49 | public: 50 | EdgeFlipsBase (void); 51 | 52 | void set_max_iterations (std::size_t max_iter); 53 | void set_max_const_flips_iterations (std::size_t iterations); 54 | void set_mesh (TriangleMeshPtr mesh); 55 | void set_vertex_info (VertexInfoListPtr vinfo); 56 | void set_feature_edges (FeatureEdgesPtr features); 57 | 58 | void flip_edges (void); 59 | }; 60 | 61 | /* ---------------------------------------------------------------- */ 62 | 63 | inline 64 | EdgeFlipsBase::EdgeFlipsBase (void) 65 | { 66 | this->max_iter = 0; 67 | this->max_const_flips_iter = 0; 68 | } 69 | 70 | inline void 71 | EdgeFlipsBase::set_max_iterations (std::size_t max_iter) 72 | { 73 | this->max_iter = max_iter; 74 | } 75 | 76 | inline void 77 | EdgeFlipsBase::set_max_const_flips_iterations (std::size_t iterations) 78 | { 79 | this->max_const_flips_iter = iterations; 80 | } 81 | 82 | inline void 83 | EdgeFlipsBase::set_mesh (TriangleMeshPtr mesh) 84 | { 85 | this->mesh = mesh; 86 | } 87 | 88 | inline void 89 | EdgeFlipsBase::set_vertex_info (VertexInfoListPtr vinfo) 90 | { 91 | this->vinfo = vinfo; 92 | } 93 | 94 | inline void 95 | EdgeFlipsBase::set_feature_edges (FeatureEdgesPtr features) 96 | { 97 | this->features = features; 98 | } 99 | 100 | REMESHER_NAMESPACE_END 101 | 102 | #endif /* REMESHER_EDGE_FLIPS_HEADER */ 103 | -------------------------------------------------------------------------------- /remesher/libremesh/edgeflips.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/edgeflips.o -------------------------------------------------------------------------------- /remesher/libremesh/elapsedtimer.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_ELAPSED_TIMER_HEADER 2 | #define REMESHER_ELAPSED_TIMER_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | 8 | REMESHER_NAMESPACE_BEGIN 9 | 10 | /** 11 | * Very simple timer class to take execution times. The reported 12 | * float values are in seconds, the integer values are in milli seconds. 13 | * The functions that provide milli seconds should be preferred. 14 | * 15 | * This class should not be used for timings that rely on the 16 | * actual real world time but rather for computational timings. 17 | * The timings here are pure processing times which may vary from 18 | * real time if the application is scheduled or sleeps. 19 | * 20 | * FIXME: What is the impact of I/O on the timings? 21 | */ 22 | class ElapsedTimer 23 | { 24 | private: 25 | std::size_t start; 26 | 27 | public: 28 | ElapsedTimer (void); 29 | void reset (void); 30 | 31 | static float now_sec (void); 32 | static std::size_t now (void); 33 | 34 | std::size_t get_elapsed (void) const; 35 | float get_elapsed_sec (void) const; 36 | }; 37 | 38 | /* ---------------------------------------------------------------- */ 39 | 40 | inline 41 | ElapsedTimer::ElapsedTimer (void) 42 | { 43 | this->reset(); 44 | } 45 | 46 | inline void 47 | ElapsedTimer::reset (void) 48 | { 49 | this->start = ElapsedTimer::now(); 50 | } 51 | 52 | inline float 53 | ElapsedTimer::now_sec (void) 54 | { 55 | return (float)std::clock() / (float)CLOCKS_PER_SEC; 56 | } 57 | 58 | inline std::size_t 59 | ElapsedTimer::now (void) 60 | { 61 | return ((std::size_t)(std::clock()) * 1000) / (std::size_t)CLOCKS_PER_SEC; 62 | } 63 | 64 | inline float 65 | ElapsedTimer::get_elapsed_sec (void) const 66 | { 67 | return (1.0f / 1000.0f) * (float)this->get_elapsed(); 68 | } 69 | 70 | inline std::size_t 71 | ElapsedTimer::get_elapsed (void) const 72 | { 73 | return ElapsedTimer::now() - start; 74 | } 75 | 76 | REMESHER_NAMESPACE_END 77 | 78 | #endif /* REMESHER_ELAPSED_TIMER_HEADER */ 79 | -------------------------------------------------------------------------------- /remesher/libremesh/exception.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_EXCEPTION_HEADER 2 | #define REMESHER_EXCEPTION_HEADER 3 | 4 | #include 5 | #include 6 | 7 | #include "defines.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | /* Universal simple exception class. */ 12 | class Exception : public std::exception, public std::string 13 | { 14 | public: 15 | Exception (void) throw() 16 | { } 17 | 18 | Exception (std::string const& msg) throw() : std::string(msg) 19 | { } 20 | 21 | virtual ~Exception (void) throw() 22 | { } 23 | 24 | virtual const char* what (void) const throw() 25 | { return this->c_str(); } 26 | }; 27 | 28 | REMESHER_NAMESPACE_END 29 | 30 | #endif /* REMESHER_EXCEPTION_HEADER */ 31 | -------------------------------------------------------------------------------- /remesher/libremesh/featureedges.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/featureedges.o -------------------------------------------------------------------------------- /remesher/libremesh/gslhelpers.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_GSL_HELPERS_HEADER 2 | #define REMESHER_GSL_HELPERS_HEADER 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace GSL 11 | { 12 | void 13 | pretty_print_matrix (gsl_matrix* m, std::string const& name) 14 | { 15 | std::cout << name << " = ["; 16 | for (std::size_t i = 0; i < m->size2; ++i) 17 | { 18 | if (i != 0) std::cout << ";" << std::endl << " "; 19 | for (std::size_t j = 0; j < m->size1; ++j) 20 | { 21 | if (j != 0) std::cout << ", "; 22 | std::cout << std::setw(6) << std::fixed << std::setprecision(2) 23 | << gsl_matrix_get(m, i, j); 24 | } 25 | } 26 | std::cout << "];" << std::endl; 27 | } 28 | 29 | void 30 | pretty_print_vector (gsl_vector* v, std::string const& name) 31 | { 32 | std::cout << name << " = ["; 33 | for (std::size_t i = 0; i < v->size; ++i) 34 | { 35 | if (i != 0) std::cout << "; "; 36 | std::cout << std::setw(6) << std::fixed << std::setprecision(2) 37 | << gsl_vector_get(v, i); 38 | } 39 | std::cout << "];" << std::endl; 40 | } 41 | 42 | } 43 | 44 | #endif /* REMESHER_GSL_HELPERS_HEADER */ 45 | -------------------------------------------------------------------------------- /remesher/libremesh/gslpolysolve.h: -------------------------------------------------------------------------------- 1 | #ifndef GSL_POLY_SOLVE_HEADER 2 | #define GSL_POLY_SOLVE_HEADER 3 | 4 | int 5 | gsl_poly_solve_quadratic (double a, double b, double c, 6 | double *x0, double *x1); 7 | 8 | int 9 | gsl_poly_solve_cubic (double a, double b, double c, 10 | double *x0, double *x1, double *x2); 11 | 12 | #endif /* GSL_POLY_SOLVE_HEADER */ 13 | -------------------------------------------------------------------------------- /remesher/libremesh/gslpolysolve.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/gslpolysolve.o -------------------------------------------------------------------------------- /remesher/libremesh/halfedge.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_HALFEDGE_HEADER 2 | #define REMESHER_HALFEDGE_HEADER 3 | 4 | #include "defines.h" 5 | 6 | REMESHER_NAMESPACE_BEGIN 7 | 8 | struct HEEdge; // Forward declaration of half edges 9 | 10 | struct HEVertex 11 | { 12 | std::size_t id; // ID of the vertex 13 | HEEdge* edge; // One of the emantating half edges 14 | 15 | HEVertex (void) : id(MAX_SIZE_T), edge(0) {} 16 | HEVertex (std::size_t id) : id(id), edge(0) {} 17 | HEVertex (std::size_t id, HEEdge* edge) : id(id), edge(edge) {} 18 | }; 19 | 20 | struct HEFace 21 | { 22 | HEEdge* edge; // One of the adjacent half edges 23 | 24 | HEFace (void) : edge(0) {} 25 | HEFace (HEEdge* edge) : edge(edge) {} 26 | }; 27 | 28 | struct HEEdge 29 | { 30 | HEVertex* vert; // Vertex at the end of the half edge 31 | HEEdge* pair; // Oppositely oriented adjacent half-edge 32 | HEFace* face; // Face adjacent to the half edge 33 | HEEdge* next; // Next half edge in ccw orientation around the face 34 | 35 | HEEdge (void) : vert(0), pair(0), face(0), next(0) {} 36 | HEEdge (HEVertex* v, HEEdge* p, HEFace* f, HEEdge* n) 37 | : vert(v), pair(p), face(f), next(n) {} 38 | }; 39 | 40 | /* ---------------------------------------------------------------- */ 41 | 42 | class HalfEdge 43 | { 44 | public: 45 | typedef std::vector VertexList; 46 | typedef std::vector EdgeList; 47 | typedef std::vector FaceList; 48 | 49 | protected: 50 | VertexList he_verts; 51 | EdgeList he_edges; 52 | FaceList he_faces; 53 | 54 | public: 55 | HalfEdge (void); 56 | ~HalfEdge (void); 57 | 58 | void push_back (HEVertex* vert); 59 | void push_back (HEEdge* edge); 60 | void push_back (HEFace* face); 61 | 62 | VertexList const& get_vertices (void) const; 63 | EdgeList const& get_edges (void) const; 64 | FaceList const& get_faces (void) const; 65 | }; 66 | 67 | /* ---------------------------------------------------------------- */ 68 | 69 | inline 70 | HalfEdge::HalfEdge (void) 71 | { 72 | } 73 | 74 | inline 75 | HalfEdge::~HalfEdge (void) 76 | { 77 | for (std::size_t i = 0; i < this->he_verts.size(); ++i) 78 | delete this->he_verts[i]; 79 | for (std::size_t i = 0; i < this->he_faces.size(); ++i) 80 | delete this->he_faces[i]; 81 | for (std::size_t i = 0; i < this->he_edges.size(); ++i) 82 | delete this->he_edges[i]; 83 | } 84 | 85 | inline void 86 | HalfEdge::push_back (HEVertex* vert) 87 | { 88 | this->he_verts.push_back(vert); 89 | } 90 | 91 | inline void 92 | HalfEdge::push_back (HEEdge* edge) 93 | { 94 | this->he_edges.push_back(edge); 95 | } 96 | 97 | inline void 98 | HalfEdge::push_back (HEFace* face) 99 | { 100 | this->he_faces.push_back(face); 101 | } 102 | 103 | inline HalfEdge::VertexList const& 104 | HalfEdge::get_vertices (void) const 105 | { 106 | return this->he_verts; 107 | } 108 | 109 | inline HalfEdge::EdgeList const& 110 | HalfEdge::get_edges (void) const 111 | { 112 | return this->he_edges; 113 | } 114 | 115 | inline HalfEdge::FaceList const& 116 | HalfEdge::get_faces (void) const 117 | { 118 | return this->he_faces; 119 | } 120 | 121 | REMESHER_NAMESPACE_END 122 | 123 | #endif /* REMESHER_HALFEDGE_HEADER */ 124 | -------------------------------------------------------------------------------- /remesher/libremesh/helpers.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_HELPERS_HEADER 2 | #define REMESHER_HELPERS_HEADER 3 | 4 | #include 5 | #include 6 | 7 | #include "defines.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | typedef std::vector StringVector; 12 | 13 | class Helpers 14 | { 15 | public: 16 | static std::string get_string (int value); 17 | static std::string get_string (unsigned int value); 18 | static std::string get_string (float value, int digits); 19 | static std::string get_string (double value, int digits); 20 | #if __WORDSIZE==64 21 | static std::string get_string (std::size_t value); 22 | #endif 23 | 24 | static unsigned int get_uint_from_string (std::string const& value); 25 | static std::size_t get_sizet_from_string (std::string const& value); 26 | static int get_int_from_string (std::string const& value); 27 | static float get_float_from_string (std::string const& value); 28 | static double get_double_from_string (std::string const& value); 29 | 30 | static std::string get_dotted_str (int value); 31 | static std::string get_dotted_str (unsigned int value); 32 | #if __WORDSIZE==64 33 | static std::string get_dotted_str (std::size_t value); 34 | #endif 35 | static std::string get_dotted_str (std::string const& str); 36 | 37 | static StringVector split_string (std::string const& str, char delim); 38 | static void chop_string (std::string& str); 39 | static void clip_string (std::string& str); 40 | static void normalize_string (std::string& str); 41 | 42 | template 43 | static void swap_endianess (T& subject); 44 | }; 45 | 46 | REMESHER_NAMESPACE_END 47 | 48 | #endif /* REMESHER_HELPERS_HEADER */ 49 | -------------------------------------------------------------------------------- /remesher/libremesh/helpers.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/helpers.o -------------------------------------------------------------------------------- /remesher/libremesh/hrtimer.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_HR_TIMER_HEADER 2 | #define REMESHER_HR_TIMER_HEADER 3 | 4 | #ifdef WIN32 5 | # define NOMINMAX 6 | # include "windows.h" 7 | #else 8 | # include 9 | #endif 10 | 11 | #include "defines.h" 12 | 13 | REMESHER_NAMESPACE_BEGIN 14 | 15 | /** 16 | * Cross-platform high-resolution real-time timer. 17 | * This implementation returns milli seconds as smallest unit. 18 | * The windows implementation uses functions with poor precision (~15ms). 19 | */ 20 | class HRTimer 21 | { 22 | private: 23 | #ifdef WIN32 24 | std::size_t start; 25 | #else 26 | struct timeval start; 27 | #endif 28 | 29 | public: 30 | HRTimer (void); 31 | 32 | /** Returns the milli seconds timer creation. */ 33 | std::size_t get_elapsed (void) const; 34 | 35 | /** Returns the seconds since timer creation. */ 36 | float get_elapsed_sec (void) const; 37 | }; 38 | 39 | /* ---------------------------------------------------------------- */ 40 | 41 | inline 42 | HRTimer::HRTimer (void) 43 | { 44 | #ifdef WIN32 45 | // FIXME: ::GetTickCount has poor precision (~10 - 16ms) 46 | start = ::GetTickCount(); 47 | #else 48 | ::gettimeofday(&start, 0); 49 | #endif 50 | } 51 | 52 | inline std::size_t 53 | HRTimer::get_elapsed (void) const 54 | { 55 | #ifdef WIN32 56 | return ::GetTickCount() - start; 57 | #else 58 | struct timeval curTime; 59 | ::gettimeofday(&curTime, 0); 60 | std::size_t ret = (curTime.tv_sec - start.tv_sec) * 1000; 61 | std::size_t cur_ms = curTime.tv_usec / 1000; 62 | std::size_t start_ms = start.tv_usec / 1000; 63 | if (cur_ms >= start_ms) 64 | ret += (cur_ms - start_ms); 65 | else 66 | ret -= (start_ms - cur_ms); 67 | return ret; 68 | #endif 69 | } 70 | 71 | inline float 72 | HRTimer::get_elapsed_sec (void) const 73 | { 74 | return (1.0f / 1000.0f) * (float)this->get_elapsed(); 75 | } 76 | 77 | REMESHER_NAMESPACE_END 78 | 79 | #endif /* REMESHER_TIMER_HEADER */ 80 | -------------------------------------------------------------------------------- /remesher/libremesh/incdelaunay.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_INCDELAUNAY_HEADER 2 | #define REMESHER_INCDELAUNAY_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "vec2.h" 8 | #include "vec3.h" 9 | #include "halfedge.h" 10 | 11 | REMESHER_NAMESPACE_BEGIN 12 | 13 | /* Internal vertex represenation. */ 14 | struct IDVertex 15 | { 16 | Vec2f pos; 17 | Vec2f bary; 18 | 19 | IDVertex (Vec2f const& pos, Vec2f const& bary) : pos(pos), bary(bary) {} 20 | }; 21 | 22 | /* ---------------------------------------------------------------- */ 23 | 24 | /* 25 | * Creates an incremental delaunay triangulation for a triangle in 3D. 26 | * The master triangle is passed to the constructor, samples are 27 | * inserted with barycentric coordinates w.r.t. the master triangle. 28 | */ 29 | class IncDelaunay : public HalfEdge 30 | { 31 | public: 32 | typedef std::vector IDVertexList; 33 | 34 | private: 35 | IDVertexList verts; 36 | float ins_eps; 37 | 38 | private: 39 | Vec3f get_bary_for_face (HEFace const* face, Vec2f const& pos) const; 40 | bool is_inside_face (Vec3f const& bary) const; 41 | void delaunay_insert (HEFace* face); 42 | void restore_delaunay (HEEdge* edge); 43 | 44 | public: 45 | IncDelaunay (Vec3f const& v1, Vec3f const& v2, Vec3f const& v3); 46 | void set_insert_epsilon (float epsilon); 47 | 48 | bool insert_sample (Vec2f const& bary); 49 | 50 | IDVertexList const& get_vertices (void) const; 51 | 52 | void write_debug_mesh (std::string const& filename); 53 | }; 54 | 55 | /* ---------------------------------------------------------------- */ 56 | 57 | inline void 58 | IncDelaunay::set_insert_epsilon (float epsilon) 59 | { 60 | this->ins_eps = epsilon; 61 | } 62 | 63 | inline bool 64 | IncDelaunay::is_inside_face (Vec3f const& bary) const 65 | { 66 | return (bary[0] >= 0.0f && bary[1] >= 0.0f && bary[2] >= 0.0f); 67 | } 68 | 69 | inline IncDelaunay::IDVertexList const& 70 | IncDelaunay::get_vertices (void) const 71 | { 72 | return this->verts; 73 | } 74 | 75 | REMESHER_NAMESPACE_END 76 | 77 | #endif /* REMESHER_INCDELAUNAY_HEADER */ 78 | -------------------------------------------------------------------------------- /remesher/libremesh/incdelaunay.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/incdelaunay.o -------------------------------------------------------------------------------- /remesher/libremesh/interface.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/interface.o -------------------------------------------------------------------------------- /remesher/libremesh/libremesh.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/libremesh.a -------------------------------------------------------------------------------- /remesher/libremesh/logging.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_LOGGING_HEADER 2 | #define REMESHER_LOGGING_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | 8 | REMESHER_NAMESPACE_BEGIN 9 | 10 | /* 11 | * A pretty simple logging facility. Logging is done with a simple call: 12 | * 13 | * LOG(LOG_ERROR) << "Some number: " << 12; 14 | * 15 | * A newline is automatically inserted. Log instructions above the 16 | * REPORTING_LEVEL are not printed and instructions are completely 17 | * erased at compile time if the specified level is a compile time 18 | * constant, thus make sure you don't call functions with side effects 19 | * in a logging statement. 20 | */ 21 | 22 | enum LogLevel 23 | { 24 | LOG_ERROR, 25 | LOG_WARNING, 26 | LOG_INFO, 27 | LOG_DEBUG, 28 | LOG_DEBUG1, 29 | LOG_DEBUG2, 30 | LOG_DEBUG3, 31 | LOG_DEBUG4 32 | }; 33 | 34 | /* ---------------------------------------------------------------- */ 35 | 36 | #define REPORTING_LEVEL LOG_DEBUG2 37 | #define LOG(level) if (level <= REPORTING_LEVEL) Log(level).get() 38 | 39 | /* ---------------------------------------------------------------- */ 40 | 41 | class Log 42 | { 43 | protected: 44 | LogLevel level; 45 | 46 | protected: 47 | char const* level_str (void); 48 | 49 | public: 50 | std::stringstream out; 51 | 52 | public: 53 | Log (LogLevel level); 54 | virtual ~Log (void); 55 | std::stringstream& get (void); 56 | }; 57 | 58 | /* ---------------------------------------------------------------- */ 59 | 60 | inline 61 | Log::Log (LogLevel level) 62 | : level(level) 63 | { 64 | this->out << this->level_str(); 65 | } 66 | 67 | inline 68 | Log::~Log (void) 69 | { 70 | std::cout << this->out.str() << std::endl << std::flush; 71 | } 72 | 73 | inline std::stringstream& 74 | Log::get (void) 75 | { 76 | return this->out; 77 | } 78 | 79 | inline char const* 80 | Log::level_str (void) 81 | { 82 | switch (this->level) 83 | { 84 | case LOG_ERROR: return "Error: "; 85 | case LOG_WARNING: return "Warning: "; 86 | case LOG_INFO: return "Info: "; 87 | case LOG_DEBUG: return "Debug: "; 88 | case LOG_DEBUG1: return "Debug1: "; 89 | case LOG_DEBUG2: return "Debug2: "; 90 | case LOG_DEBUG3: return "Debug3: "; 91 | case LOG_DEBUG4: return "Debug4: "; 92 | default: return "Message: "; 93 | } 94 | } 95 | 96 | REMESHER_NAMESPACE_END 97 | 98 | #endif /* REMESHER_LOGGING_HEADER */ 99 | -------------------------------------------------------------------------------- /remesher/libremesh/mathhelpers.h: -------------------------------------------------------------------------------- 1 | #ifndef MATH_HELPERS_HEADER 2 | #define MATH_HELPERS_HEADER 3 | 4 | #include "defines.h" 5 | 6 | REMESHER_NAMESPACE_BEGIN 7 | 8 | REMESHER_NAMESPACE_END 9 | 10 | #endif /* MATH_HELPERS_HEADER */ 11 | -------------------------------------------------------------------------------- /remesher/libremesh/matrix2.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MATRIX2_HEADER 2 | #define REMESHER_MATRIX2_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "vec2.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | template class Matrix2; 12 | 13 | typedef Matrix2 Matrix2f; 14 | typedef Matrix2 Matrix2d; 15 | typedef Matrix2 Matrix2i; 16 | typedef Matrix2 Matrix2ui; 17 | typedef Matrix2 Matrix2c; 18 | 19 | template 20 | class Matrix2 21 | { 22 | public: 23 | T m[4]; 24 | 25 | Matrix2 (void) {} 26 | Matrix2 (T* matrix) 27 | { for (std::size_t i = 0; i < 4; ++i) m[i] = matrix[i]; } 28 | 29 | Matrix2 plus (Matrix2 const& rhs) const 30 | { 31 | Matrix2 ret; 32 | for (std::size_t i = 0; i < 4; ++i) ret[i] = m[i] + rhs[i]; 33 | return ret; 34 | } 35 | 36 | Matrix2 minus (Matrix2 const& rhs) const 37 | { 38 | Matrix2 ret; 39 | for (std::size_t i = 0; i < 4; ++i) ret[i] = m[i] - rhs[i]; 40 | return ret; 41 | } 42 | 43 | Matrix2 mult (Matrix2 const& rhs) const 44 | { 45 | Matrix2 ret; 46 | for (std::size_t i = 0; i < 4; ++i) 47 | { 48 | ret[i] = (T)0; 49 | for (std::size_t j = 0; j < 2; ++j) 50 | ret[i] += m[i-i%2 + j] * rhs[i%2 + j*2]; 51 | } 52 | return ret; 53 | } 54 | 55 | Matrix2 mult (T const& rhs) const 56 | { 57 | Matrix2 ret; 58 | for (std::size_t i = 0; i < 4; ++i) ret[i] = m[i] * rhs; 59 | return ret; 60 | } 61 | 62 | Vec2 mult (Vec2 const& rhs) const 63 | { 64 | return Vec2(m[0] * rhs.x + m[1] * rhs.y, m[2] * rhs.x + m[3] * rhs.y); 65 | } 66 | 67 | Matrix2 div (T const& rhs) const 68 | { 69 | Matrix2 ret; 70 | for (std::size_t i = 0; i < 4; ++i) ret[i] = m[i] / rhs; 71 | return ret; 72 | } 73 | 74 | Matrix2 neg (void) const 75 | { 76 | Matrix2 ret; 77 | for (std::size_t i = 0; i < 4; ++i) ret[i] = -m[i]; 78 | return ret; 79 | } 80 | 81 | Matrix2 invert (void) const 82 | { 83 | Matrix2 ret; 84 | T det = m[0] * m[3] - m[1] * m[2]; 85 | ret[0] = m[3] / det; 86 | ret[1] = -m[1] / det; 87 | ret[2] = -m[2] / det; 88 | ret[3] = m[0] / det; 89 | return ret; 90 | } 91 | 92 | T const* array (void) const 93 | { return m; } 94 | 95 | T* array (void) 96 | { return m; } 97 | 98 | Matrix2 operator+ (Matrix2 const& rhs) const 99 | { return plus(rhs); } 100 | 101 | Matrix2 operator- (Matrix2 const& rhs) const 102 | { return minus(rhs); } 103 | 104 | Matrix2 operator* (Matrix2 const& rhs) const 105 | { return mult(rhs); } 106 | 107 | Matrix2 operator* (T const& rhs) const 108 | { return mult(rhs); } 109 | 110 | Vec2 operator* (Vec2 const& rhs) const 111 | { return mult(rhs); } 112 | 113 | T const& operator[] (std::size_t i) const 114 | { return m[i]; } 115 | 116 | T& operator[] (std::size_t i) 117 | { return m[i]; } 118 | 119 | Matrix2& operator= (Matrix2 const& rhs) 120 | { 121 | for (std::size_t i = 0; i < 4; ++i) m[i] = rhs[i]; 122 | return *this; 123 | } 124 | 125 | friend std::ostream& operator<< (std::ostream& os, Matrix2 const& x) 126 | { 127 | return os << "[" << x[0] << ", " << x[1] 128 | << "; " << x[2] << ", " << x[3] 129 | << "]"; 130 | } 131 | }; 132 | 133 | REMESHER_NAMESPACE_END 134 | 135 | #endif /* REMESHER_MATRIX2_HEADER */ 136 | -------------------------------------------------------------------------------- /remesher/libremesh/matrix3.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MATRIX3_HEADER 2 | #define REMESHER_MATRIX3_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "vec3.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | template class Matrix3; 12 | 13 | typedef Matrix3 Matrix3f; 14 | typedef Matrix3 Matrix3d; 15 | typedef Matrix3 Matrix3i; 16 | typedef Matrix3 Matrix3ui; 17 | typedef Matrix3 Matrix3c; 18 | 19 | template 20 | class Matrix3 21 | { 22 | public: 23 | T m[9]; 24 | 25 | Matrix3 (void) {} 26 | Matrix3 (T* matrix) 27 | { for (std::size_t i = 0; i < 9; ++i) m[i] = matrix[i]; } 28 | 29 | Matrix3 plus (Matrix3 const& rhs) const 30 | { 31 | Matrix3 ret; 32 | for (std::size_t i = 0; i < 9; ++i) ret[i] = m[i] + rhs[i]; 33 | return ret; 34 | } 35 | 36 | Matrix3 minus (Matrix3 const& rhs) const 37 | { 38 | Matrix3 ret; 39 | for (std::size_t i = 0; i < 9; ++i) ret[i] = m[i] - rhs[i]; 40 | return ret; 41 | } 42 | 43 | Matrix3 mult (Matrix3 const& rhs) const 44 | { 45 | Matrix3 ret; 46 | for (std::size_t i = 0; i < 9; ++i) 47 | { 48 | ret[i] = (T)0; 49 | for (std::size_t j = 0; j < 3; ++j) 50 | ret[i] += m[i-i%3 + j] * rhs[i%3 + j*3]; 51 | } 52 | return ret; 53 | } 54 | 55 | Matrix3 mult (T const& rhs) const 56 | { 57 | Matrix3 ret; 58 | for (std::size_t i = 0; i < 9; ++i) ret[i] = m[i] * rhs; 59 | return ret; 60 | } 61 | 62 | Vec3 mult (Vec3 const& rhs) const 63 | { 64 | return Vec3(m[0] * rhs.x + m[1] * rhs.y + m[2] * rhs.z, 65 | m[3] * rhs.x + m[4] * rhs.y + m[5] * rhs.z, 66 | m[6] * rhs.x + m[7] * rhs.y + m[8] * rhs.z); 67 | } 68 | 69 | Matrix3 div (T const& rhs) const 70 | { 71 | Matrix3 ret; 72 | for (std::size_t i = 0; i < 9; ++i) ret[i] = m[i] / rhs; 73 | return ret; 74 | } 75 | 76 | Matrix3 neg (void) const 77 | { 78 | Matrix3 ret; 79 | for (std::size_t i = 0; i < 9; ++i) ret[i] = -m[i]; 80 | return ret; 81 | } 82 | 83 | Matrix3 transpose (void) const 84 | { 85 | Matrix3 ret; 86 | ret[0] = m[0]; ret[1] = m[3]; ret[2] = m[6]; 87 | ret[3] = m[1]; ret[4] = m[4]; ret[5] = m[7]; 88 | ret[6] = m[2]; ret[7] = m[5]; ret[8] = m[8]; 89 | return ret; 90 | } 91 | 92 | T const* array (void) const 93 | { return m; } 94 | 95 | T* array (void) 96 | { return m; } 97 | 98 | Matrix3 operator+ (Matrix3 const& rhs) const 99 | { return plus(rhs); } 100 | 101 | Matrix3 operator- (Matrix3 const& rhs) const 102 | { return minus(rhs); } 103 | 104 | Matrix3 operator* (Matrix3 const& rhs) const 105 | { return mult(rhs); } 106 | 107 | Matrix3 operator* (T const& rhs) const 108 | { return mult(rhs); } 109 | 110 | Vec3 operator* (Vec3 const& rhs) const 111 | { return mult(rhs); } 112 | 113 | T const& operator[] (std::size_t i) const 114 | { return m[i]; } 115 | 116 | T& operator[] (std::size_t i) 117 | { return m[i]; } 118 | 119 | Matrix3& operator= (Matrix3 const& rhs) 120 | { 121 | for (std::size_t i = 0; i < 9; ++i) m[i] = rhs[i]; 122 | return *this; 123 | } 124 | 125 | //Matrix3& operator, (T const& rhs) 126 | //{} 127 | 128 | friend std::ostream& operator<< (std::ostream& os, Matrix3 const& x) 129 | { 130 | return os << "[" << x[0] << "," << x[1] << "," << x[2] 131 | << "; " << x[3] << "," << x[4] << "," << x[5] 132 | << "; " << x[6] << "," << x[7] << "," << x[8] 133 | << "]"; 134 | } 135 | }; 136 | 137 | REMESHER_NAMESPACE_END 138 | 139 | #endif /* REMESHER_MATRIX3_HEADER */ 140 | -------------------------------------------------------------------------------- /remesher/libremesh/matrix4.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MATRIX4_HEADER 2 | #define REMESHER_MATRIX4_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "vec3.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | template class Matrix4; 12 | 13 | typedef Matrix4 Matrix4f; 14 | typedef Matrix4 Matrix4d; 15 | typedef Matrix4 Matrix4i; 16 | typedef Matrix4 Matrix4ui; 17 | typedef Matrix4 Matrix4c; 18 | 19 | template 20 | class Matrix4 21 | { 22 | public: 23 | T m[16]; 24 | 25 | Matrix4 (void) {} 26 | Matrix4 (T* matrix) 27 | { for (std::size_t i = 0; i < 16; ++i) m[i] = matrix[i]; } 28 | 29 | Matrix4 plus (Matrix4 const& rhs) const 30 | { 31 | Matrix4 ret; 32 | for (std::size_t i = 0; i < 16; ++i) ret[i] = m[i] + rhs[i]; 33 | return ret; 34 | } 35 | 36 | Matrix4 minus (Matrix4 const& rhs) const 37 | { 38 | Matrix4 ret; 39 | for (std::size_t i = 0; i < 16; ++i) ret[i] = m[i] - rhs[i]; 40 | return ret; 41 | } 42 | 43 | Matrix4 mult (Matrix4 const& rhs) const 44 | { 45 | Matrix4 ret; 46 | for (std::size_t i = 0; i < 16; ++i) 47 | { 48 | ret[i] = (T)0; 49 | for (std::size_t j = 0; j < 4; ++j) 50 | ret[i] += m[i-i%4 + j] * rhs[i%4 + j*4]; 51 | } 52 | return ret; 53 | } 54 | 55 | Matrix4 mult (T const& rhs) const 56 | { 57 | Matrix4 ret; 58 | for (std::size_t i = 0; i < 16; ++i) ret[i] = m[i] * rhs; 59 | return ret; 60 | } 61 | 62 | Vec3 mult (Vec3 const& rhs) const 63 | { 64 | return Vec3(m[0] * rhs.x + m[1] * rhs.y + m[2] * rhs.z + m[3], 65 | m[4] * rhs.x + m[5] * rhs.y + m[6] * rhs.z + m[7], 66 | m[8] * rhs.x + m[9] * rhs.y + m[10] * rhs.z + m[11]); 67 | } 68 | 69 | Matrix4 div (T const& rhs) const 70 | { 71 | Matrix4 ret; 72 | for (std::size_t i = 0; i < 16; ++i) ret[i] = m[i] / rhs; 73 | return ret; 74 | } 75 | 76 | Matrix4 neg (void) const 77 | { 78 | Matrix4 ret; 79 | for (std::size_t i = 0; i < 16; ++i) ret[i] = -m[i]; 80 | return ret; 81 | } 82 | 83 | Matrix4 transpose (void) const 84 | { 85 | Matrix4 ret; 86 | ret[0] = m[0]; ret[1] = m[4]; ret[2] = m[8]; ret[3] = m[12]; 87 | ret[4] = m[1]; ret[5] = m[5]; ret[6] = m[9]; ret[7] = m[13]; 88 | ret[8] = m[2]; ret[9] = m[6]; ret[10] = m[10]; ret[11] = m[14]; 89 | ret[12] = m[3]; ret[13] = m[7]; ret[14] = m[11]; ret[15] = m[15]; 90 | return ret; 91 | } 92 | 93 | T const* array (void) const 94 | { return m; } 95 | 96 | T* array (void) 97 | { return m; } 98 | 99 | Matrix4 operator+ (Matrix4 const& rhs) const 100 | { return plus(rhs); } 101 | 102 | Matrix4 operator- (Matrix4 const& rhs) const 103 | { return minus(rhs); } 104 | 105 | Matrix4 operator* (Matrix4 const& rhs) const 106 | { return mult(rhs); } 107 | 108 | Matrix4 operator* (T const& rhs) const 109 | { return mult(rhs); } 110 | 111 | Vec3 operator* (Vec3 const& rhs) const 112 | { return mult(rhs); } 113 | 114 | T const& operator[] (std::size_t i) const 115 | { return m[i]; } 116 | 117 | T& operator[] (std::size_t i) 118 | { return m[i]; } 119 | 120 | Matrix4& operator= (Matrix4 const& rhs) 121 | { 122 | for (std::size_t i = 0; i < 16; ++i) m[i] = rhs[i]; 123 | return *this; 124 | } 125 | 126 | //Matrix4& operator, (T const& rhs) 127 | //{} 128 | 129 | friend std::ostream& operator<< (std::ostream& os, Matrix4 const& x) 130 | { 131 | return os << "[" << x[0] << "," << x[1] << "," << x[2] << "," << x[3] 132 | << "; " << x[4] << "," << x[5] << "," << x[6] << "," << x[7] 133 | << "; " << x[8] << "," << x[9] << "," << x[10] << "," << x[11] 134 | << "; " << x[12] << "," << x[13] << "," << x[14] << "," << x[15] 135 | << "]"; 136 | } 137 | }; 138 | 139 | REMESHER_NAMESPACE_END 140 | 141 | #endif /* REMESHER_MATRIX4_HEADER */ 142 | -------------------------------------------------------------------------------- /remesher/libremesh/meshcleanup.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MESH_CLEANUP_HEADER 2 | #define REMESHER_MESH_CLEANUP_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "trianglemesh.h" 8 | #include "vertexinfo.h" 9 | 10 | REMESHER_NAMESPACE_BEGIN 11 | 12 | /* 13 | * This class cleans up a triangle mesh. Cleanup requires vertex 14 | * inforation. This vertex information is invalidated during cleanup. 15 | * 16 | * It can be used to remove vertices and faces which are marked as deleted. 17 | * In this case the "cleanup_deleted" method is to be used. 18 | * This method removes all vertices from the data structure that are marked 19 | * as deleted in the passed argument. It also removes all triangles 20 | * indexing vertex 0, i.e. set all three vertex indices to 0 to remove a 21 | * face. The list of deleted vertices is invalidated during cleanup. 22 | * Since vector resizing is used after cleanup, the mesh must be copied 23 | * to actually free up memory as a result from the cleanup. 24 | * 25 | * The class can also be used to remove duplicated vertices (that is 26 | * vertices that are very close to each other, depending on epsilon). The 27 | * triangulation is fixed and some faces are deleted (common faces for the 28 | * vertices to be merged). Unreferenced vertices are also removed. 29 | * Method "cleanup_mesh" is to be used for this feature. 30 | * Note that close vertices are ONLY removed IF there is a face 31 | * connecting the two vertices in question. 32 | * 33 | * The class offers to supply a vertex index relocation list. After 34 | * cleanup, this list maps the index of a vertex to its old position 35 | * and vertices can still be associated with the original mesh. 36 | * No such strucure is created by default. 37 | */ 38 | 39 | class MeshCleanup 40 | { 41 | public: 42 | typedef std::vector VertexIndexRelocList; 43 | typedef std::vector VertexDeletedList; 44 | 45 | private: 46 | TriangleMeshPtr mesh; 47 | VertexInfoListPtr vinfo; 48 | VertexIndexRelocList* ireloc; 49 | 50 | private: 51 | /* Merges two vertices and deletes all zero-area faces resulting 52 | * from the merge. The amount of removed triangles is returned. 53 | * If no triangle was removed, the vertices could not be merged, 54 | * otherwise the vertex `b' is unused should be deleted. */ 55 | std::size_t merge_vertices (std::size_t a, std::size_t b); 56 | 57 | /* Deletes a face and removes this face from adjacent vertices. */ 58 | bool delete_invalid_face (std::size_t face); 59 | 60 | public: 61 | MeshCleanup (TriangleMeshPtr mesh); 62 | 63 | /* Moving vertices requires fixing faces. The vertex info 64 | * is neccessary for fast operation of the algorithm. */ 65 | void set_vertex_info (VertexInfoListPtr vinfo); 66 | 67 | /* The vertex relocation list is filled during cleanup. 68 | * It maps vertex indices to their old positions in the mesh. */ 69 | void set_vertex_reloc_list (VertexIndexRelocList* irlist); 70 | void unset_vertex_reloc_list (void); 71 | 72 | /* 73 | * The main algorithms. 74 | */ 75 | 76 | /* Cleanup of deleted vertices. Note that also normals are deleted. */ 77 | void cleanup_deleted (VertexDeletedList& dlist); 78 | 79 | /* Cleans up duplicated (connected) and unreferenced vertices. */ 80 | void cleanup_mesh (float epsilon = MY_FLT_EPS); 81 | 82 | /* Cleans up duplicated (unconnected) vertices. A bit expensive. */ 83 | void cleanup_duplicated (float epsilon = MY_FLT_EPS); 84 | }; 85 | 86 | /* ---------------------------------------------------------------- */ 87 | 88 | inline 89 | MeshCleanup::MeshCleanup (TriangleMeshPtr mesh) 90 | { 91 | this->mesh = mesh; 92 | this->ireloc = 0; 93 | } 94 | 95 | inline void 96 | MeshCleanup::set_vertex_info (VertexInfoListPtr vinfo) 97 | { 98 | this->vinfo = vinfo; 99 | } 100 | 101 | inline void 102 | MeshCleanup::set_vertex_reloc_list (VertexIndexRelocList* irlist) 103 | { 104 | this->ireloc = irlist; 105 | } 106 | 107 | inline void 108 | MeshCleanup::unset_vertex_reloc_list (void) 109 | { 110 | this->ireloc = 0; 111 | } 112 | 113 | REMESHER_NAMESPACE_END 114 | 115 | #endif /* REMESHER_MESH_CLEANUP_HEADER */ 116 | -------------------------------------------------------------------------------- /remesher/libremesh/meshcleanup.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/meshcleanup.o -------------------------------------------------------------------------------- /remesher/libremesh/meshdecimation.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MESH_DECIMATION_HEADER 2 | #define REMESHER_MESH_DECIMATION_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "trianglemesh.h" 8 | #include "featureedges.h" 9 | #include "meshcleanup.h" 10 | #include "vertexinfo.h" 11 | 12 | REMESHER_NAMESPACE_BEGIN 13 | 14 | /* The mesh decimation algorithm takes as input a mesh and 15 | * feature edges of the mesh and decimates vertices given 16 | * by a vertex delete list. */ 17 | class MeshDecimation 18 | { 19 | public: 20 | typedef std::vector DeleteList; 21 | typedef MeshCleanup::VertexIndexRelocList RelocList; 22 | 23 | private: 24 | typedef std::pair SplitLine; 25 | 26 | private: 27 | TriangleMeshPtr mesh; 28 | FeatureEdgesPtr features; 29 | VertexInfoListPtr vinfo; 30 | std::size_t vertex_amount; 31 | std::size_t vertex_budget; 32 | DeleteList* dlist; 33 | RelocList* reloc; 34 | 35 | private: 36 | bool delete_vertex (std::size_t index); 37 | void replace_faces (VertexInfo::FaceList aflist, 38 | MeshFaceList const& flist); 39 | 40 | public: 41 | MeshDecimation (void); 42 | 43 | /* Sets the mesh and features to be decimated (in-place decimation). */ 44 | void set_mesh (TriangleMeshPtr mesh); 45 | void set_features (FeatureEdgesPtr features); 46 | 47 | /* Sets the list of vertices to delete. This list may be altered. */ 48 | void set_delete_list (DeleteList& dlist); 49 | 50 | /* Sets an exact vertex budget that the decimation tries to match. */ 51 | void set_exact_budget (std::size_t vertex_amount); 52 | 53 | /* Request a relocation list mapping new to old indices. */ 54 | void fill_vertex_reloc_list (RelocList& reloc); 55 | 56 | /* Run the decimation. */ 57 | void start_decimation (void); 58 | 59 | /* Acquire the final result (note: decimation is in-place). */ 60 | TriangleMeshPtr get_mesh (void) const; 61 | FeatureEdgesPtr get_features (void) const; 62 | }; 63 | 64 | /* ---------------------------------------------------------------- */ 65 | 66 | inline 67 | MeshDecimation::MeshDecimation (void) 68 | { 69 | this->vertex_budget = 0; 70 | this->dlist = 0; 71 | this->reloc = 0; 72 | } 73 | 74 | inline void 75 | MeshDecimation::set_mesh (TriangleMeshPtr mesh) 76 | { 77 | this->mesh = mesh; 78 | } 79 | 80 | inline void 81 | MeshDecimation::set_features (FeatureEdgesPtr features) 82 | { 83 | this->features = features; 84 | } 85 | 86 | inline void 87 | MeshDecimation::set_delete_list (MeshDecimation::DeleteList& dlist) 88 | { 89 | this->dlist = &dlist; 90 | } 91 | 92 | inline void 93 | MeshDecimation::set_exact_budget (std::size_t vertex_amount) 94 | { 95 | this->vertex_budget = vertex_amount; 96 | } 97 | 98 | inline void 99 | MeshDecimation::fill_vertex_reloc_list (MeshDecimation::RelocList& reloc) 100 | { 101 | this->reloc = &reloc; 102 | } 103 | 104 | 105 | inline TriangleMeshPtr 106 | MeshDecimation::get_mesh (void) const 107 | { 108 | return this->mesh; 109 | } 110 | 111 | inline FeatureEdgesPtr 112 | MeshDecimation::get_features (void) const 113 | { 114 | return this->features; 115 | } 116 | 117 | REMESHER_NAMESPACE_END 118 | 119 | #endif /* REMESHER_MESH_DECIMATION_HEADER */ 120 | -------------------------------------------------------------------------------- /remesher/libremesh/meshdecimation.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/meshdecimation.o -------------------------------------------------------------------------------- /remesher/libremesh/meshoptimize.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MESH_OPTIMIZE_HEADER 2 | #define REMESHER_MESH_OPTIMIZE_HEADER 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "trianglemesh.h" 9 | #include "vertexinfo.h" 10 | #include "defines.h" 11 | 12 | REMESHER_NAMESPACE_BEGIN 13 | 14 | /* 15 | * The algorithm in this class optimizes a mesh by reordering 16 | * faces and vertices for vertex locality. This makes efficient 17 | * use of cache, e.g. to accelerate rendering on the graphics card 18 | * and for the dynamic patch-wise appraoch that uses patch caching. 19 | * The implementation is based on the method described in the paper: 20 | * 21 | * Pedro V. Sander, Diego Nehab, Joshua Barczak 22 | * Fast Triangle Reordering for Vertex Locality and Reduced Overdraw 23 | * 24 | * The algorithm is very fast, runs in linear time with linear 25 | * memory usage and can even be used interactively. 26 | */ 27 | 28 | class MeshOptimize 29 | { 30 | public: 31 | typedef std::vector VertexIndexRelocList; 32 | 33 | private: 34 | typedef std::vector VertexLiveFaceCounts; 35 | typedef std::vector VertexCacheTimes; 36 | typedef std::stack DeadEndStack; 37 | typedef std::vector FaceEmittedFlags; 38 | typedef std::set VertexCandidates; 39 | 40 | private: 41 | TriangleMeshPtr mesh; 42 | VertexInfoListPtr vinfo; 43 | VertexIndexRelocList* irlist; 44 | 45 | private: 46 | void optimize_face_ordering (std::size_t cache_size); 47 | void optimize_vertex_ordering (void); 48 | 49 | std::size_t get_next_vertex (std::size_t& cur, std::size_t cache_size, 50 | VertexCandidates const& next, VertexCacheTimes const& cts, 51 | std::size_t ts, VertexLiveFaceCounts const& live, 52 | DeadEndStack& dead); 53 | 54 | std::size_t skip_dead_end (VertexLiveFaceCounts const& live, 55 | DeadEndStack& dead, std::size_t& cur); 56 | 57 | public: 58 | MeshOptimize (void); 59 | 60 | /* Sets mesh and vertex info, which is needed to operate. */ 61 | void set_mesh (TriangleMeshPtr mesh); 62 | void set_vertex_info (VertexInfoListPtr vinfo); 63 | 64 | /* Requests an index relocation list, which gives a permutation 65 | * of the vertex indices, mapping old positions to new positions. */ 66 | void fill_vertex_reloc_list (VertexIndexRelocList& irlist); 67 | void unset_vertex_reloc_list (void); 68 | 69 | void optimize (std::size_t cache_size = 24); 70 | void randomize (void); 71 | }; 72 | 73 | /* ---------------------------------------------------------------- */ 74 | 75 | inline 76 | MeshOptimize::MeshOptimize (void) 77 | { 78 | this->irlist = 0; 79 | } 80 | 81 | inline void 82 | MeshOptimize::set_mesh (TriangleMeshPtr mesh) 83 | { 84 | this->mesh = mesh; 85 | } 86 | 87 | inline void 88 | MeshOptimize::set_vertex_info (VertexInfoListPtr vinfo) 89 | { 90 | this->vinfo = vinfo; 91 | } 92 | 93 | inline void 94 | MeshOptimize::fill_vertex_reloc_list (VertexIndexRelocList& irlist) 95 | { 96 | this->irlist = &irlist; 97 | } 98 | 99 | inline void 100 | MeshOptimize::unset_vertex_reloc_list (void) 101 | { 102 | this->irlist = 0; 103 | } 104 | 105 | REMESHER_NAMESPACE_END 106 | 107 | #endif /* REMESHER_MESH_OPTIMIZE_HEADER */ 108 | -------------------------------------------------------------------------------- /remesher/libremesh/meshoptimize.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/meshoptimize.o -------------------------------------------------------------------------------- /remesher/libremesh/meshskeleton.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MESH_SKELETON_HEADER 2 | #define REMESHER_MESH_SKELETON_HEADER 3 | 4 | #include 5 | #include 6 | 7 | #include "defines.h" 8 | #include "refptr.h" 9 | #include "featureedges.h" 10 | #include "vertexinfo.h" 11 | 12 | REMESHER_NAMESPACE_BEGIN 13 | 14 | /* 15 | * This structure represents a backbone. It may be either closed 16 | * or open, and it contains all vertices of the backbone in order. 17 | */ 18 | struct MeshBackbone 19 | { 20 | typedef std::list Vertices; 21 | typedef Vertices::const_iterator Iter; 22 | 23 | bool closed; 24 | Vertices verts; 25 | }; 26 | 27 | typedef std::list::const_iterator BackboneIter; 28 | 29 | /* ---------------------------------------------------------------- */ 30 | 31 | /* 32 | * This class extracts the feature skeleton of a mesh for sequential access. 33 | * It basically takes the default feature represenation and converts 34 | * it into data structures better suited for resampling. 35 | * 36 | * Two different types of backbones are recognized: Closed backbones which 37 | * are cyclic, and open backbones between two corner vertices. 38 | */ 39 | 40 | class MeshSkeleton; 41 | typedef RefPtrArray MeshSkeletonPtr; 42 | 43 | class MeshSkeleton : public std::vector 44 | { 45 | protected: 46 | typedef std::pair FeatureEdge; 47 | 48 | private: 49 | TriangleMeshPtr mesh; 50 | VertexInfoListPtr vinfo; 51 | FeatureEdgesPtr features; 52 | float max_angle; 53 | std::size_t num_closed; 54 | std::size_t num_open; 55 | 56 | protected: 57 | MeshSkeleton (void); 58 | 59 | /* Finds the next edge for the given feature edge. The function returns 60 | * true on success, or false if advancing is not possible. */ 61 | bool advance_edge (FeatureEdge& edge) const; 62 | 63 | /* Starts collecting from a given seed edge. 64 | * Removes consumed edges from the pool data structure. */ 65 | void collect (FeatureEdge edge, FeatureEdgesPtr pool); 66 | 67 | public: 68 | static MeshSkeletonPtr create (void); 69 | 70 | void set_mesh (TriangleMeshPtr mesh); 71 | void set_vertex_info (VertexInfoListPtr vinfo); 72 | void set_feature_edges (FeatureEdgesPtr features); 73 | 74 | /* Sets a maximum angle between two subsequent edges on a feature 75 | * crease. If the angle is exceeded, a corner is inserted. */ 76 | void set_max_angle (float angle); 77 | 78 | void extract (void); 79 | 80 | /* Returns the amount of closed backbones. */ 81 | std::size_t get_closed_amount (void) const; 82 | /* Returns the amount of open backbones. */ 83 | std::size_t get_open_amount (void) const; 84 | /* Returns the amount of corner vertices. */ 85 | std::size_t get_corner_amount (void) const; 86 | 87 | void debug_print (void) const; 88 | }; 89 | 90 | /* ---------------------------------------------------------------- */ 91 | 92 | inline 93 | MeshSkeleton::MeshSkeleton (void) 94 | { 95 | this->num_closed = 0; 96 | this->num_open = 0; 97 | this->max_angle = 0.0f; 98 | } 99 | 100 | inline MeshSkeletonPtr 101 | MeshSkeleton::create (void) 102 | { 103 | return MeshSkeletonPtr(new MeshSkeleton); 104 | } 105 | 106 | inline void 107 | MeshSkeleton::set_mesh (TriangleMeshPtr mesh) 108 | { 109 | this->mesh = mesh; 110 | } 111 | 112 | inline void 113 | MeshSkeleton::set_vertex_info (VertexInfoListPtr vinfo) 114 | { 115 | this->vinfo = vinfo; 116 | } 117 | 118 | inline void 119 | MeshSkeleton::set_feature_edges (FeatureEdgesPtr features) 120 | { 121 | this->features = features; 122 | } 123 | 124 | inline void 125 | MeshSkeleton::set_max_angle (float angle) 126 | { 127 | this->max_angle = angle; 128 | } 129 | 130 | inline std::size_t 131 | MeshSkeleton::get_closed_amount (void) const 132 | { 133 | return this->num_closed; 134 | } 135 | 136 | inline std::size_t 137 | MeshSkeleton::get_open_amount (void) const 138 | { 139 | return this->num_open; 140 | } 141 | 142 | REMESHER_NAMESPACE_END 143 | 144 | #endif /* REMESHER_MESH_SKELETON_HEADER */ 145 | -------------------------------------------------------------------------------- /remesher/libremesh/meshskeleton.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/meshskeleton.o -------------------------------------------------------------------------------- /remesher/libremesh/meshslicing.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MESH_SLICING_HEADER 2 | #define REMESHER_MESH_SLICING_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "trianglemesh.h" 8 | #include "vertexinfo.h" 9 | #include "plane.h" 10 | 11 | REMESHER_NAMESPACE_BEGIN 12 | 13 | struct MeshSlicingConf 14 | { 15 | float vertex_snapping; 16 | float edge_snapping; 17 | }; 18 | 19 | /* ---------------------------------------------------------------- */ 20 | 21 | class MeshSlicing 22 | { 23 | protected: 24 | /* Data structures for immediate slicing. */ 25 | typedef std::map, std::size_t> NewV; 26 | 27 | /* Data structures for lazy slicing. */ 28 | typedef std::vector EdgeVertices; 29 | typedef std::map, 30 | EdgeVertices > EdgeMap; 31 | 32 | protected: 33 | MeshSlicingConf conf; 34 | TriangleMeshPtr mesh; 35 | 36 | /* Data structure for immediate slicing. */ 37 | NewV new_verts; 38 | 39 | /* Data structure for lazy slicing. */ 40 | EdgeMap edge_info; 41 | 42 | /* This methods cuts a single edge against the cut plane. The 43 | * resulting vertex is returned for immediate triangulation. 44 | * The returned vertex is unique for the edge (and was possibly 45 | * created at a previous intersecion operation). */ 46 | std::size_t get_intersection (std::size_t v1idx, 47 | std::size_t v2idx, Plane3f const& plane); 48 | 49 | /* This method lazy-cuts a single edge against the cut plane. 50 | * The new vertex is added to the mesh only if a similar 51 | * vertex for that edge is not present. */ 52 | void process_intersection (std::size_t v1idx, 53 | std::size_t v2idx, Plane3f const& plane); 54 | 55 | public: 56 | MeshSlicing (void); 57 | 58 | void set_config (MeshSlicingConf const& config); 59 | void set_mesh (TriangleMeshPtr mesh); 60 | 61 | /* Slices the mesh with the given plane and immediately 62 | * creates a new triangulation for each triangle. This results 63 | * in bad triangles if there are a lot of skinny triangles. */ 64 | void slice (Plane3f const& plane); 65 | 66 | /* Lazy slicing only calculates intersections with edges but 67 | * does not triangulate immediately. Only new vertices are 68 | * created and added to the mesh. */ 69 | void lazy_slice (Plane3f const& plane); 70 | 71 | /* After lazy slicing, each triangle in the mesh must be 72 | * triangulated using the new intersection vertices. */ 73 | void triangulate (void); 74 | }; 75 | 76 | /* ---------------------------------------------------------------- */ 77 | 78 | inline 79 | MeshSlicing::MeshSlicing (void) 80 | { 81 | } 82 | 83 | inline void 84 | MeshSlicing::set_config (MeshSlicingConf const& config) 85 | { 86 | this->conf = config; 87 | } 88 | 89 | inline void 90 | MeshSlicing::set_mesh (TriangleMeshPtr mesh) 91 | { 92 | this->mesh = mesh; 93 | } 94 | 95 | REMESHER_NAMESPACE_END 96 | 97 | #endif /* REMESHER_MESH_SLICING_HEADER */ 98 | -------------------------------------------------------------------------------- /remesher/libremesh/meshslicing.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/meshslicing.o -------------------------------------------------------------------------------- /remesher/libremesh/meshstats.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "meshstats.h" 4 | 5 | REMESHER_NAMESPACE_BEGIN 6 | 7 | void 8 | MeshStats::print_stats (void) 9 | { 10 | MeshVertexList& verts = this->mesh->get_vertices(); 11 | MeshFaceList& faces = this->mesh->get_faces(); 12 | 13 | /* Collect information regarding vertex regularity. */ 14 | std::size_t total_verts = 0; 15 | std::size_t low_degree = 0; 16 | std::size_t high_degree = 0; 17 | 18 | for (std::size_t i = 0; i < verts.size(); ++i) 19 | { 20 | switch (vinfo[i].vclass) 21 | { 22 | case VERTEX_CLASS_SIMPLE: 23 | if (vinfo[i].adj_faces.size() > 6) 24 | high_degree += 1; 25 | else if (vinfo[i].adj_faces.size() < 6) 26 | low_degree += 1; 27 | total_verts += 1; 28 | break; 29 | 30 | case VERTEX_CLASS_BORDER: 31 | if (vinfo[i].adj_faces.size() > 4) 32 | high_degree += 1; 33 | else if (vinfo[i].adj_faces.size() < 4) 34 | low_degree += 1; 35 | total_verts += 1; 36 | break; 37 | 38 | default: 39 | total_verts += 1; 40 | break; 41 | } 42 | } 43 | 44 | std::size_t irregular = low_degree + high_degree; 45 | std::size_t regular = total_verts - irregular; 46 | 47 | /* Collect information regarding triangle angles. */ 48 | float min_angle = (float)MY_2PI; 49 | float max_angle = 0.0f; 50 | float avg_angle = 0.0f; 51 | std::size_t min_angle_tri_id = MAX_SIZE_T; 52 | std::size_t max_angle_tri_id = MAX_SIZE_T; 53 | 54 | std::size_t face_amount = faces.size() / 3; 55 | for (std::size_t i = 0; i < face_amount; ++i) 56 | { 57 | Vec3f v[3]; 58 | v[0] = verts[faces[i * 3 + 0]]; 59 | v[1] = verts[faces[i * 3 + 1]]; 60 | v[2] = verts[faces[i * 3 + 2]]; 61 | 62 | float smallest_angle = (float)MY_2PI; 63 | for (std::size_t j = 0; j < 3; ++j) 64 | { 65 | Vec3f e1 = (v[(j + 1) % 3] - v[j]).norm(); 66 | Vec3f e2 = (v[(j + 2) % 3] - v[j]).norm(); 67 | float scalar = e1 * e2; 68 | scalar = MY_MAX(-1.0f, scalar); 69 | scalar = MY_MIN(1.0f, scalar); 70 | float angle = std::acos(scalar); 71 | 72 | if (angle < min_angle) 73 | { 74 | min_angle = angle; 75 | min_angle_tri_id = i; 76 | } 77 | if (angle > max_angle) 78 | { 79 | max_angle = angle; 80 | max_angle_tri_id = i; 81 | } 82 | if (angle < smallest_angle) 83 | smallest_angle = angle; 84 | } 85 | 86 | avg_angle += smallest_angle; 87 | } 88 | 89 | avg_angle /= (float)face_amount; 90 | 91 | /* Print information. */ 92 | std::cout << "Mesh statistics (" << verts.size() << " vertices, " 93 | << face_amount << " faces)" << std::endl 94 | << " Vertices with degree: " << total_verts << std::endl 95 | << " Vertices with high degree: " << high_degree << std::endl 96 | << " Vertices with low degree: " << low_degree << std::endl 97 | << " Irregular vertices: " << irregular 98 | << " (" << (100.0f * (float)irregular / (float)total_verts) 99 | << "%), regular vertices: " << regular 100 | << " (" << (100.0f * (float)regular / (float)total_verts) 101 | << "%)" << std::endl 102 | << std::endl 103 | << " Minimum angle: " << MY_RAD2DEG(min_angle) 104 | << " (Triangle " << min_angle_tri_id << ")" << std::endl 105 | << " Maximum angle: " << MY_RAD2DEG(max_angle) 106 | << " (Triangle " << max_angle_tri_id << ")" << std::endl 107 | << " Average minimum angle: " << MY_RAD2DEG(avg_angle) 108 | << std::endl; 109 | } 110 | 111 | REMESHER_NAMESPACE_END 112 | -------------------------------------------------------------------------------- /remesher/libremesh/meshstats.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MESH_STATS_HEADER 2 | #define REMESHER_MESH_STATS_HEADER 3 | 4 | #include "defines.h" 5 | #include "trianglemesh.h" 6 | #include "vertexinfo.h" 7 | 8 | REMESHER_NAMESPACE_BEGIN 9 | 10 | class MeshStats 11 | { 12 | private: 13 | TriangleMeshPtr mesh; 14 | VertexInfoListPtr vinfo; 15 | 16 | public: 17 | MeshStats (TriangleMeshPtr mesh, VertexInfoListPtr vinfo); 18 | void print_stats (void); 19 | }; 20 | 21 | /* ---------------------------------------------------------------- */ 22 | 23 | inline 24 | MeshStats::MeshStats (TriangleMeshPtr mesh, VertexInfoListPtr vinfo) 25 | : mesh(mesh), vinfo(vinfo) 26 | { 27 | } 28 | 29 | REMESHER_NAMESPACE_END 30 | 31 | #endif /* REMESHER_MESH_STATS_HEADER */ 32 | -------------------------------------------------------------------------------- /remesher/libremesh/meshstats.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/meshstats.o -------------------------------------------------------------------------------- /remesher/libremesh/microdelaunay.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MICRO_DELAUNAY_HEADER 2 | #define REMESHER_MICRO_DELAUNAY_HEADER 3 | 4 | #include "defines.h" 5 | #include "polygon2.h" 6 | #include "micropatch.h" 7 | 8 | REMESHER_NAMESPACE_BEGIN 9 | 10 | /* 11 | * This class takes a center vertex and surrounding vertices in 2D. 12 | * It calculates the voronoi centroid with or without guidance by 13 | * a density function and feature edges. The density values need 14 | * to be specified for each vertex in the micro patch. 15 | */ 16 | class MicroDelaunay : public MicroPatch 17 | { 18 | private: 19 | typedef std::vector AdjacentDensity; 20 | typedef std::vector PolygonEdges; 21 | typedef std::vector PolygonDensity; 22 | 23 | private: 24 | float center_density; 25 | AdjacentDensity adj_density; 26 | PolygonEdges features; 27 | 28 | private: 29 | void fill_polygon_values (Polygon2& poly, PolygonDensity& poly_dens) const; 30 | 31 | public: 32 | void set_center_density (float density); 33 | void append_adjacent_density (float density); 34 | void set_feature_edge (std::size_t index); 35 | void clear_adjacent_density (void); 36 | 37 | /* Makes a sanity check if the pach is delaunay. Since due to 38 | * distortion the patch might not be delaunay, don't use it! */ 39 | bool is_delaunay (void) const; 40 | 41 | /* Returns the Voronoi centroid, that is for Lloyd relaxation. */ 42 | Vec2f get_voronoi_centroid (void) const; 43 | 44 | /* Returns area based optimal center vertex for Area Based remeshing. */ 45 | Vec2f get_area_optimal_center (void) const; 46 | 47 | /* Returns the area and the mass of the Voronoi cell. */ 48 | void get_voronoi_area_and_mass (float& area, float& mass); 49 | 50 | /* Returns the face ID and fills bary with the barycentric coordinate. */ 51 | std::size_t get_face_and_bary (Vec2f const& pnt, Vec2f& bary) const; 52 | 53 | void debug_bary_coords (Vec2f const& pnt) const; 54 | }; 55 | 56 | /* ---------------------------------------------------------------- */ 57 | 58 | inline void 59 | MicroDelaunay::set_center_density (float density) 60 | { 61 | this->center_density = density; 62 | } 63 | 64 | inline void 65 | MicroDelaunay::append_adjacent_density (float density) 66 | { 67 | this->adj_density.push_back(density); 68 | } 69 | 70 | inline void 71 | MicroDelaunay::set_feature_edge (std::size_t index) 72 | { 73 | if (features.empty()) 74 | features.resize(this->adj3d.size(), false); 75 | features[index] = true; 76 | } 77 | 78 | inline void 79 | MicroDelaunay::clear_adjacent_density (void) 80 | { 81 | this->adj_density.clear(); 82 | } 83 | 84 | REMESHER_NAMESPACE_END 85 | 86 | #endif /* REMESHER_MICRO_DELAUNAY_HEADER */ 87 | -------------------------------------------------------------------------------- /remesher/libremesh/microdelaunay.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/microdelaunay.o -------------------------------------------------------------------------------- /remesher/libremesh/micropatch.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "exception.h" 4 | #include "micropatch.h" 5 | 6 | REMESHER_NAMESPACE_BEGIN 7 | 8 | void 9 | MicroPatch::calculate_patch (void) 10 | { 11 | /* At least four vertices are required, the center and three adjacent. */ 12 | if (this->adj3d.size() < 3) 13 | throw Exception("Invalid patch with too few vertices"); 14 | 15 | /* A list of edge length values is cached. */ 16 | std::vector edge_length; 17 | for (std::size_t i = 0; i < this->adj3d.size(); ++i) 18 | edge_length.push_back((this->adj3d[i] - this->center).length()); 19 | 20 | /* Sum up all angles between the edges. */ 21 | float total_angle = 0.0f; 22 | for (std::size_t i = 0; i < this->adj3d.size(); ++i) 23 | { 24 | std::size_t ip1 = (i + 1) % this->adj3d.size(); 25 | Vec3f e1(this->adj3d[i] - this->center); 26 | Vec3f e2(this->adj3d[ip1] - this->center); 27 | float cosa = e1 * e2 / (edge_length[i] * edge_length[ip1]); 28 | //std::cout << "Angle is: " << MY_RAD2DEG(std::acos(cosa)) << std::endl; 29 | total_angle += std::acos(cosa); 30 | } 31 | 32 | //std::cout << "Total angle is: " << MY_RAD2DEG(total_angle) << std::endl; 33 | 34 | /* Create new patch vertices. */ 35 | this->adj2d.clear(); 36 | float angle_factor = (float)MY_2PI / total_angle; 37 | float current_angle = 0.0f; 38 | for (std::size_t i = 0; i < this->adj3d.size(); ++i) 39 | { 40 | /* Place first vertex. We create a vector (x, 0) 41 | * and rotate it with the current angle. */ 42 | this->adj2d.push_back(Vec2f(edge_length[i] * std::cos(current_angle), 43 | edge_length[i] * std::sin(current_angle))); 44 | 45 | /* Calculate the angle between edges and add it to current angle. */ 46 | std::size_t ip1 = (i + 1) % this->adj3d.size(); 47 | Vec3f e1(this->adj3d[i] - this->center); 48 | Vec3f e2(this->adj3d[ip1] - this->center); 49 | float cosa = e1 * e2 / (edge_length[i] * edge_length[ip1]); 50 | float angle2d = angle_factor * std::acos(cosa); 51 | current_angle += angle2d; 52 | } 53 | } 54 | 55 | /* ---------------------------------------------------------------- */ 56 | 57 | TriangleMeshPtr 58 | MicroPatch::get_debug_mesh (void) const 59 | { 60 | TriangleMeshPtr mesh(TriangleMesh::create()); 61 | MeshVertexList& verts = mesh->get_vertices(); 62 | MeshFaceList& faces = mesh->get_faces(); 63 | 64 | #define BOTH_MICRO_PATCHES 0 65 | #if BOTH_MICRO_PATCHES 66 | float xmin = 999999.0f; 67 | float xmax = -999999.0f; 68 | for (std::size_t i = 0; i < this->adj2d.size(); ++i) 69 | { 70 | xmin = (this->adj2d[i][0] < xmin ? this->adj2d[i][0] : xmin); 71 | xmax = (this->adj2d[i][0] > xmax ? this->adj2d[i][0] : xmax); 72 | } 73 | float xoff = (xmax - xmin) / 2.0f; 74 | 75 | verts.push_back(Vec3f(-xoff, 0.0f, 0.0f)); 76 | for (std::size_t i = 0; i < this->adj3d.size(); ++i) 77 | { 78 | verts.push_back(this->adj3d[i] - this->center); 79 | verts.back()[0] -= xoff; 80 | } 81 | 82 | verts.push_back(Vec3f(xoff, 0.0f, 0.0f)); 83 | for (std::size_t i = 0; i < this->adj2d.size(); ++i) 84 | { 85 | verts.push_back(Vec3f(this->adj2d[i][0], this->adj2d[i][1], 0.0f)); 86 | verts.back()[0] += xoff; 87 | } 88 | 89 | for (std::size_t i = 1; i < this->adj3d.size() + 1; ++i) 90 | { 91 | faces.push_back(0); 92 | faces.push_back(i); 93 | faces.push_back(1 + i % this->adj3d.size()); 94 | } 95 | 96 | std::size_t ioff = this->adj3d.size() + 1; 97 | for (std::size_t i = 1; i < this->adj2d.size() + 1; ++i) 98 | { 99 | faces.push_back(0 + ioff); 100 | faces.push_back(i + ioff); 101 | faces.push_back(1 + i % this->adj2d.size() + ioff); 102 | } 103 | #else 104 | verts.push_back(Vec3f(0.0f, 0.0f, 0.0f)); 105 | for (std::size_t i = 0; i < this->adj2d.size(); ++i) 106 | verts.push_back(Vec3f(this->adj2d[i][0], this->adj2d[i][1], 0.0f)); 107 | 108 | for (std::size_t i = 1; i < this->adj2d.size() + 1; ++i) 109 | { 110 | faces.push_back(0); 111 | faces.push_back((MeshVIndex)i); 112 | faces.push_back(1 + (MeshVIndex)(i % this->adj2d.size())); 113 | } 114 | #endif 115 | 116 | return mesh; 117 | } 118 | 119 | REMESHER_NAMESPACE_END 120 | -------------------------------------------------------------------------------- /remesher/libremesh/micropatch.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MICRO_PATCH_HEADER 2 | #define REMESHER_MICRO_PATCH_HEADER 3 | 4 | #include 5 | 6 | #include "trianglemesh.h" 7 | #include "defines.h" 8 | #include "vec2.h" 9 | #include "vec3.h" 10 | 11 | REMESHER_NAMESPACE_BEGIN 12 | 13 | /* 14 | * This class calculates a very small patch consisting of a center 15 | * vertex and neighboring vertices that form a loop around the center 16 | * vertex. Neighboring vertices need to be specified in order and 17 | * form a single loop aroung the center vertex. 18 | * 19 | * The resulting parametrization to 2D preserves the length of edges 20 | * and the relative angles between edges incident to the center vertex. 21 | * Each angle "a_i" results in an angle "alpha * a_i" such that 22 | * 23 | * alpha * sum(a_i) = 2 PI <==> alpha = 2 PI / sum(a_i) 24 | * 25 | * The position of the center vertex is mapped to the origin. 26 | */ 27 | class MicroPatch 28 | { 29 | public: 30 | typedef std::vector AdjacentVertices2D; 31 | typedef std::vector AdjacentVertices3D; 32 | 33 | protected: 34 | Vec3f center; 35 | AdjacentVertices3D adj3d; 36 | AdjacentVertices2D adj2d; 37 | 38 | public: 39 | /* The center vertex and the vertex neighbors need to be set. */ 40 | void set_center_vertex (Vec3f const& center); 41 | void append_adjacent_vertex (Vec3f const& ajdacent); 42 | 43 | /* Clears all information to reuse the object for a new patch. */ 44 | void clear (void); 45 | 46 | /* This creates the patch from the vertices. */ 47 | void calculate_patch (void); 48 | 49 | /* After the patch is created, these methods provide information. */ 50 | AdjacentVertices2D const& get_adjacent_vertices (void) const; 51 | AdjacentVertices2D& get_adjacent_vertices (void); 52 | 53 | /* Creates debug triangle mesh from both, the 2D and the 3D patch. */ 54 | TriangleMeshPtr get_debug_mesh (void) const; 55 | }; 56 | 57 | /* ---------------------------------------------------------------- */ 58 | 59 | inline void 60 | MicroPatch::set_center_vertex (Vec3f const& center) 61 | { 62 | this->center = center; 63 | } 64 | 65 | inline void 66 | MicroPatch::append_adjacent_vertex (Vec3f const& adjacent) 67 | { 68 | this->adj3d.push_back(adjacent); 69 | } 70 | 71 | inline MicroPatch::AdjacentVertices2D const& 72 | MicroPatch::get_adjacent_vertices (void) const 73 | { 74 | return this->adj2d; 75 | } 76 | 77 | inline MicroPatch::AdjacentVertices2D& 78 | MicroPatch::get_adjacent_vertices (void) 79 | { 80 | return this->adj2d; 81 | } 82 | 83 | inline void 84 | MicroPatch::clear (void) 85 | { 86 | this->adj3d.clear(); 87 | this->adj3d.clear(); 88 | } 89 | 90 | REMESHER_NAMESPACE_END 91 | 92 | #endif /* REMESHER_MICRO_PATCH_HEADER */ 93 | -------------------------------------------------------------------------------- /remesher/libremesh/micropatch.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/micropatch.o -------------------------------------------------------------------------------- /remesher/libremesh/modelloader.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MODEL_LOADER_HEADER 2 | #define REMESHER_MODEL_LOADER_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "trianglemesh.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | class ModelLoader 12 | { 13 | public: 14 | static TriangleMeshPtr load_model (std::string const& filename); 15 | 16 | static TriangleMeshPtr load_off_model (std::string const& filename); 17 | static TriangleMeshPtr load_ply_model (std::string const& filename); 18 | static TriangleMeshPtr load_obj_model (std::string const& filename); 19 | static TriangleMeshPtr load_m_model (std::string const& filename); 20 | }; 21 | 22 | REMESHER_NAMESPACE_END 23 | 24 | #endif /* REMESHER_MODEL_LOADER_HEADER */ 25 | -------------------------------------------------------------------------------- /remesher/libremesh/modelloader.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/modelloader.o -------------------------------------------------------------------------------- /remesher/libremesh/modelwriter.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_MODEL_WRITER_HEADER 2 | #define REMESHER_MODEL_WRITER_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "trianglemesh.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | class ModelWriter 12 | { 13 | public: 14 | /* Save model by filename extension. */ 15 | static void save_model (std::string const& filename, 16 | TriangleMeshPtr mesh, bool with_normals = false); 17 | 18 | /* Save model regardless of filename. */ 19 | static void save_off_model (std::string const& filename, 20 | TriangleMeshPtr mesh, bool with_normals = false); 21 | static void save_ply_model (std::string const& filename, 22 | TriangleMeshPtr mesh, bool with_normals = false); 23 | static void save_svg_file (std::string const& filename, 24 | TriangleMeshPtr mesh); 25 | }; 26 | 27 | REMESHER_NAMESPACE_END 28 | 29 | #endif /* REMESHER_MODEL_WRITER_HEADER */ 30 | -------------------------------------------------------------------------------- /remesher/libremesh/modelwriter.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/modelwriter.o -------------------------------------------------------------------------------- /remesher/libremesh/oversampling.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "meshslicing.h" 4 | #include "subdivloop.h" 5 | #include "subdivlinear.h" 6 | #include "elapsedtimer.h" 7 | #include "oversampling.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | void 12 | Oversampling::start_oversampling (void) 13 | { 14 | if (this->config.use_loop_subdiv) 15 | { 16 | this->run_loop_subdiv(); 17 | } 18 | 19 | if (this->config.use_linear_subdiv) 20 | { 21 | this->run_linear_subdiv(); 22 | } 23 | 24 | if (this->config.use_slicing) 25 | { 26 | this->run_grid_slicing(); 27 | } 28 | } 29 | 30 | /* ---------------------------------------------------------------- */ 31 | 32 | void 33 | Oversampling::run_loop_subdiv (void) 34 | { 35 | SubdivLoop subdiv; 36 | subdiv.set_mesh(this->mesh); 37 | subdiv.set_vertex_info(this->vinfo); 38 | subdiv.set_feature_edges(this->features); 39 | subdiv.start_subdiv(); 40 | } 41 | 42 | /* ---------------------------------------------------------------- */ 43 | 44 | void 45 | Oversampling::run_linear_subdiv (void) 46 | { 47 | /* Invalidate features if set. */ 48 | if (this->features.get() != 0) 49 | this->features->clear(); 50 | 51 | SubdivLinear subdiv; 52 | subdiv.set_mesh(this->mesh); 53 | subdiv.set_vertex_info(this->vinfo); 54 | subdiv.start_subdiv(); 55 | } 56 | 57 | /* ---------------------------------------------------------------- */ 58 | 59 | void 60 | Oversampling::run_grid_slicing (void) 61 | { 62 | /* Invalidate features if set. */ 63 | if (this->features.get() != 0) 64 | this->features->clear(); 65 | 66 | /* Setup mesh slicer. */ 67 | MeshSlicingConf msc; 68 | msc.vertex_snapping = 0.0001f; 69 | msc.edge_snapping = 0.2f; 70 | 71 | MeshSlicing ms; 72 | ms.set_config(msc); 73 | ms.set_mesh(this->mesh); 74 | 75 | /* Setup grid slicing. */ 76 | Vec3f axis[3]; 77 | axis[0] = Vec3f(1.0f, 0.0f, 0.0f); 78 | axis[1] = Vec3f(0.0f, 1.0f, 0.0f); 79 | axis[2] = Vec3f(0.0f, 0.0f, 1.0f); 80 | 81 | std::size_t slices[3]; 82 | slices[0] = this->config.slices_x; 83 | slices[1] = this->config.slices_y; 84 | slices[2] = this->config.slices_z; 85 | 86 | for (std::size_t i = 0; i < 3; ++i) 87 | { 88 | Vec3f const& pn = axis[i]; 89 | std::size_t num = slices[i]; 90 | 91 | for (std::size_t j = 1; j <= num; ++j) 92 | { 93 | std::cout << "Slicing layer " << j << " of " << num << std::endl; 94 | float pos = (float)j / ((float)num + 1) - 0.5f; 95 | 96 | /* Determine if we use lazy or immediate triangulation. */ 97 | if (this->config.lazy_triangulation) 98 | ms.lazy_slice(Plane3f(pn, pos)); 99 | else 100 | ms.slice(Plane3f(pn, pos)); 101 | } 102 | } 103 | 104 | /* Finally triangulate if lazy slicing is enabled. */ 105 | if (this->config.lazy_triangulation) 106 | ms.triangulate(); 107 | } 108 | 109 | REMESHER_NAMESPACE_END 110 | -------------------------------------------------------------------------------- /remesher/libremesh/oversampling.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_OVERSAMPLING_HEADER 2 | #define REMESHER_OVERSAMPLING_HEADER 3 | 4 | #include "defines.h" 5 | #include "trianglemesh.h" 6 | #include "densityfield.h" 7 | #include "vertexinfo.h" 8 | #include "vertexref.h" 9 | #include "featureedges.h" 10 | 11 | REMESHER_NAMESPACE_BEGIN 12 | 13 | struct OversamplingConf 14 | { 15 | bool use_loop_subdiv; 16 | bool use_linear_subdiv; 17 | 18 | bool use_slicing; 19 | bool lazy_triangulation; 20 | std::size_t slices_x; 21 | std::size_t slices_y; 22 | std::size_t slices_z; 23 | 24 | OversamplingConf (void); 25 | }; 26 | 27 | /* ---------------------------------------------------------------- */ 28 | 29 | class Oversampling 30 | { 31 | private: 32 | OversamplingConf config; 33 | 34 | TriangleMeshPtr mesh; 35 | DensityFieldPtr density; 36 | FeatureEdgesPtr features; 37 | VertexInfoListPtr vinfo; 38 | 39 | protected: 40 | void run_loop_subdiv (void); 41 | void run_linear_subdiv (void); 42 | void run_grid_slicing (void); 43 | 44 | public: 45 | Oversampling (void); 46 | 47 | void set_config (OversamplingConf const& conf); 48 | void set_mesh (TriangleMeshPtr mesh); 49 | void set_vertex_info (VertexInfoListPtr vinfo); 50 | void set_density_field (DensityFieldPtr density); 51 | void set_feature_edges (FeatureEdgesPtr features); 52 | 53 | void start_oversampling (void); 54 | }; 55 | 56 | /* ---------------------------------------------------------------- */ 57 | 58 | inline 59 | OversamplingConf::OversamplingConf (void) 60 | { 61 | this->use_loop_subdiv = true; 62 | this->use_linear_subdiv = false; 63 | 64 | this->use_slicing = false; 65 | this->lazy_triangulation = true; 66 | this->slices_x = 10; 67 | this->slices_y = 10; 68 | this->slices_z = 10; 69 | } 70 | 71 | inline 72 | Oversampling::Oversampling (void) 73 | { 74 | } 75 | 76 | inline void 77 | Oversampling::set_config (OversamplingConf const& conf) 78 | { 79 | this->config = conf; 80 | } 81 | 82 | inline void 83 | Oversampling::set_mesh (TriangleMeshPtr mesh) 84 | { 85 | this->mesh = mesh; 86 | } 87 | 88 | inline void 89 | Oversampling::set_vertex_info (VertexInfoListPtr vinfo) 90 | { 91 | this->vinfo = vinfo; 92 | } 93 | 94 | inline void 95 | Oversampling::set_density_field (DensityFieldPtr density) 96 | { 97 | this->density = density; 98 | } 99 | 100 | inline void 101 | Oversampling::set_feature_edges (FeatureEdgesPtr features) 102 | { 103 | this->features = features; 104 | } 105 | 106 | REMESHER_NAMESPACE_END 107 | 108 | #endif /* REMESHER_OVERSAMPLING_HEADER */ 109 | -------------------------------------------------------------------------------- /remesher/libremesh/oversampling.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/oversampling.o -------------------------------------------------------------------------------- /remesher/libremesh/patch2d.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/patch2d.o -------------------------------------------------------------------------------- /remesher/libremesh/patch2d_fb.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/patch2d_fb.o -------------------------------------------------------------------------------- /remesher/libremesh/patch3d.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_PATCH_3D_HEADER 2 | #define REMESHER_PATCH_3D_HEADER 3 | 4 | #include 5 | #include 6 | 7 | #include "refptr.h" 8 | #include "vertexinfo.h" 9 | #include "trianglemesh.h" 10 | #include "defines.h" 11 | 12 | REMESHER_NAMESPACE_BEGIN 13 | 14 | /* 15 | * The classes in this file are capable of creating triangle patches 16 | * in three dimensions. Different strategies on how to collect the 17 | * triangles can be implemented. If the patch is to be flattened 18 | * to a circular boundary, the 3d patch should similarly be circular 19 | * for optimal results. 20 | */ 21 | 22 | class Patch3d; 23 | typedef RefPtr Patch3dPtr; 24 | 25 | class Patch3d 26 | { 27 | public: 28 | typedef std::set MeshFaceSet; 29 | 30 | protected: 31 | TriangleMeshPtr mesh; 32 | VertexInfoListPtr vinfo; 33 | MeshFaceSet faces; 34 | 35 | protected: 36 | Patch3d (void); 37 | void set_data (TriangleMeshPtr mesh, VertexInfoListPtr vinfo); 38 | 39 | public: 40 | TriangleMeshPtr get_mesh (void) const; 41 | MeshFaceSet const& get_face_set (void) const; 42 | 43 | /* This is inefficient! Stores all vertices and only a subset of faces. */ 44 | void write_debug_mesh (std::string const& filename); 45 | }; 46 | 47 | /* ---------------------------------------------------------------- */ 48 | 49 | /* 50 | * This class is capable of creating a dynamic patch of triangles 51 | * from a 3D mesh. The patch is created using a method from 52 | * 53 | * Vitaly Surazhsky and Craig Gotsman 54 | * Explicit Surface Remeshing 55 | * 56 | * A patch is specified with three face indices on a reference mesh. 57 | * Triangles are collected in a breadth-first search over the faces 58 | * until the three given triangles are visited. The resulting 59 | * patch is circular and contails the "triangle" specified by the 60 | * three faces. 61 | */ 62 | 63 | class Patch3dTriangle; 64 | typedef RefPtr Patch3dTrianglePtr; 65 | 66 | class Patch3dTriangle : public Patch3d 67 | { 68 | protected: 69 | Patch3dTriangle (void); 70 | 71 | void add_faces (std::size_t f1, std::size_t f2, std::size_t f3); 72 | bool add_face (std::size_t f); 73 | 74 | public: 75 | static Patch3dTrianglePtr create (TriangleMeshPtr mesh, 76 | VertexInfoListPtr vinfo); 77 | 78 | void create_patch (std::size_t f1, std::size_t f2, std::size_t f3); 79 | }; 80 | 81 | /* ---------------------------------------------------------------- */ 82 | 83 | /* 84 | * Simple patch class that creates a 3D patch for a vertex and 85 | * a certain neighborhood (1-ring, 2-ring, etc) of the vertex. 86 | */ 87 | class Patch3dNRing; 88 | typedef RefPtr Patch3dNRingPtr; 89 | 90 | class Patch3dNRing : public Patch3d 91 | { 92 | public: 93 | static Patch3dNRingPtr create (TriangleMeshPtr mesh, 94 | VertexInfoListPtr vinfo); 95 | 96 | void create_patch (std::size_t index, std::size_t n_rings); 97 | }; 98 | 99 | /* ---------------------------------------------------------------- */ 100 | 101 | inline 102 | Patch3d::Patch3d (void) 103 | { 104 | } 105 | 106 | inline void 107 | Patch3d::set_data (TriangleMeshPtr mesh, VertexInfoListPtr vinfo) 108 | { 109 | this->mesh = mesh; 110 | this->vinfo = vinfo; 111 | } 112 | 113 | inline TriangleMeshPtr 114 | Patch3d::get_mesh (void) const 115 | { 116 | return this->mesh; 117 | } 118 | 119 | inline Patch3d::MeshFaceSet const& 120 | Patch3d::get_face_set (void) const 121 | { 122 | return this->faces; 123 | } 124 | 125 | inline 126 | Patch3dTriangle::Patch3dTriangle (void) 127 | { 128 | } 129 | 130 | inline Patch3dTrianglePtr 131 | Patch3dTriangle::create (TriangleMeshPtr mesh, VertexInfoListPtr vinfo) 132 | { 133 | Patch3dTrianglePtr ret(new Patch3dTriangle); 134 | ret->set_data(mesh, vinfo); 135 | return ret; 136 | } 137 | 138 | inline Patch3dNRingPtr 139 | Patch3dNRing::create (TriangleMeshPtr mesh, VertexInfoListPtr vinfo) 140 | { 141 | Patch3dNRingPtr ret(new Patch3dNRing); 142 | ret->set_data(mesh, vinfo); 143 | return ret; 144 | } 145 | 146 | REMESHER_NAMESPACE_END 147 | 148 | #endif /* REMESHER_PATCH_3D_HEADER */ 149 | -------------------------------------------------------------------------------- /remesher/libremesh/patch3d.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/patch3d.o -------------------------------------------------------------------------------- /remesher/libremesh/patchcache.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_PATCH_CACHE 2 | #define REMESHER_PATCH_CACHE 3 | 4 | #include 5 | #include 6 | 7 | #include "defines.h" 8 | #include "refptr.h" 9 | #include "thread.h" 10 | 11 | #if REMESHER_FB_PARAMETRIZATION 12 | # include "patch2d_fb.h" 13 | #else 14 | # include "patch2d.h" 15 | #endif 16 | 17 | REMESHER_NAMESPACE_BEGIN 18 | 19 | class PatchCache; 20 | typedef RefPtr PatchCachePtr; 21 | 22 | class PatchCache 23 | { 24 | private: 25 | #if REMESHER_FAST_PATCH_LOOKUP 26 | typedef std::pair CacheEntry; 27 | typedef std::vector CachedPatches; 28 | typedef std::vector PatchCacheDS; 29 | 30 | static bool entry_cmp (CacheEntry const* c1, CacheEntry const* c2) 31 | { return c1->second > c2->second; } 32 | 33 | PatchCacheDS cache; 34 | CachedPatches patches; 35 | std::size_t clock; 36 | #else 37 | typedef std::list PatchCacheDS; 38 | PatchCacheDS cache; 39 | #endif 40 | 41 | std::size_t cache_size; 42 | std::size_t max_cache_size; 43 | 44 | #if REMESHER_PARALLELIZATION 45 | /* The data structure is locked for some cache operations. */ 46 | ReadWriteLock cache_lock; 47 | #endif 48 | 49 | /* Caching statistics. */ 50 | std::size_t p_created; 51 | std::size_t p_created_size; 52 | std::size_t p_deleted; 53 | std::size_t p_deleted_size; 54 | std::size_t cache_hits; 55 | std::size_t cache_misses; 56 | 57 | protected: 58 | PatchCache (void); 59 | 60 | public: 61 | ~PatchCache (void); 62 | static PatchCachePtr create (std::size_t max_cache_size); 63 | 64 | Patch2dPtr lookup_patch (std::size_t f1, std::size_t f2, std::size_t f3); 65 | void cache_patch (Patch2dPtr patch2d); 66 | 67 | void print_statistics (void); 68 | void clear_statistics (void); 69 | }; 70 | 71 | /* ---------------------------------------------------------------- */ 72 | 73 | inline PatchCachePtr 74 | PatchCache::create (std::size_t max_cache_size) 75 | { 76 | PatchCachePtr ret = PatchCachePtr(new PatchCache); 77 | ret->max_cache_size = max_cache_size; 78 | return ret; 79 | } 80 | 81 | REMESHER_NAMESPACE_END 82 | 83 | #endif /* REMESHER_PATCH_CACHE */ 84 | -------------------------------------------------------------------------------- /remesher/libremesh/patchcache.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/patchcache.o -------------------------------------------------------------------------------- /remesher/libremesh/permute.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_PERMUTE_HEADER 2 | #define REMESHER_PERMUTE_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "exception.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | /* 12 | * This class permutes a vector of elements v using a permutation 13 | * given by vector p, calculating v' = p(v). Vector p can be specified 14 | * by using a mapping from old indices to new indices, 15 | * 16 | * v'_p[i] = v_i e.g. v = [a, b, c], p = [1, 2, 0], v' = [c, a, b]. 17 | * 18 | * which is better called a index-based relocation of the elements. 19 | * Each element is copied two times, from the original vector to 20 | * a temporary variable, and back to the vector. 21 | * This is available using the "permute_reloc" function. 22 | * 23 | * Another way of defining p is mathematically more natural and 24 | * also computationally more efficient: 25 | * 26 | * v'_i = v_p[i] e.g. v = [a, b, c], p = [1, 2, 0], v' = [b, c, a] 27 | * 28 | * This is available using the "permute_math" function. Each element 29 | * is copied only once inside the vector, and elements at the beginning 30 | * of a cycle are copied twice. 31 | * 32 | * "permute_reloc" performs the inverse permutation of "permute_math". 33 | */ 34 | 35 | template 36 | class Permute 37 | { 38 | public: 39 | typedef std::vector VecV; 40 | typedef std::vector

VecP; 41 | typedef std::vector VecB; 42 | 43 | public: 44 | static void permute_reloc (VecV& v, VecP const& p); 45 | static void permute_math (VecV& v, VecP const& p); 46 | }; 47 | 48 | /* ---------------------------------------------------------------- */ 49 | 50 | template 51 | inline void 52 | Permute::permute_reloc (typename Permute::VecV& v, 53 | typename Permute::VecP const& p) 54 | { 55 | if (v.size() != p.size()) 56 | throw Exception("Invalid permutation arguments"); 57 | 58 | if (v.empty()) 59 | return; 60 | 61 | VecB visited(v.size(), false); 62 | std::size_t i = 0; 63 | std::size_t seek = 0; 64 | do 65 | { 66 | /* Permute a cycle using index-based relocation permutation. */ 67 | V tmp[2]; 68 | bool idx = false; 69 | tmp[idx] = v[i]; 70 | while (!visited[i]) 71 | { 72 | tmp[!idx] = v[p[i]]; 73 | v[p[i]] = tmp[idx]; 74 | idx = !idx; 75 | visited[i] = true; 76 | i = p[i]; 77 | } 78 | 79 | /* Seek for an unvisited element. */ 80 | i = MAX_SIZE_T; 81 | for (; seek < visited.size(); ++seek) 82 | if (!visited[seek]) 83 | { 84 | i = seek; 85 | break; 86 | } 87 | } 88 | while (i != MAX_SIZE_T); 89 | } 90 | 91 | /* ---------------------------------------------------------------- */ 92 | 93 | template 94 | inline void 95 | Permute::permute_math (typename Permute::VecV& v, 96 | typename Permute::VecP const& p) 97 | { 98 | if (v.size() != p.size()) 99 | throw Exception("Invalid permutation arguments"); 100 | 101 | if (v.empty()) 102 | return; 103 | 104 | VecB visited(v.size(), false); 105 | std::size_t i = 0; 106 | std::size_t seek = 0; 107 | do 108 | { 109 | /* Permute a cycle using mathematical permutation. */ 110 | visited[i] = true; 111 | if (i != p[i]) 112 | { 113 | V tmp = v[i]; 114 | while (!visited[p[i]]) 115 | { 116 | v[i] = v[p[i]]; 117 | visited[p[i]] = true; 118 | i = p[i]; 119 | } 120 | v[i] = tmp; 121 | } 122 | 123 | /* Seek for an unvisited element. */ 124 | i = MAX_SIZE_T; 125 | for (; seek < visited.size(); ++seek) 126 | if (!visited[seek]) 127 | { 128 | i = seek; 129 | break; 130 | } 131 | } 132 | while (i != MAX_SIZE_T); 133 | } 134 | 135 | REMESHER_NAMESPACE_END 136 | 137 | #endif /* REMESHER_PERMUTE_HEADER */ 138 | -------------------------------------------------------------------------------- /remesher/libremesh/plane.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_PLANE_HEADER 2 | #define REMESHER_PLANE_HEADER 3 | 4 | #include "vec3.h" 5 | #include "defines.h" 6 | 7 | REMESHER_NAMESPACE_BEGIN 8 | 9 | template class Plane; 10 | 11 | typedef Plane Plane3f; 12 | typedef Plane Plane3d; 13 | typedef Plane Plane3i; 14 | typedef Plane Plane3ui; 15 | typedef Plane Plane3s; 16 | typedef Plane Plane3us; 17 | typedef Plane Plane3c; 18 | typedef Plane Plane3uc; 19 | 20 | /* Class that represents a plane. The normal is expected to be normalized. */ 21 | template 22 | class Plane 23 | { 24 | public: 25 | Vec3 n; 26 | T d; 27 | 28 | public: 29 | Plane (void) {} 30 | /* Creates a plane with normal n and distance d from the origin. */ 31 | Plane (Vec3 const& n, T const& d) : n(n), d(d) {} 32 | /* Creates a plane containing p with normal n. */ 33 | Plane (Vec3 const& n, Vec3 const& p) : n(n) { d = p * n; } 34 | 35 | /* Returns the signed distance from a point to the plane. */ 36 | T point_dist (Vec3 const& p) const 37 | { return p * n - d; } 38 | }; 39 | 40 | REMESHER_NAMESPACE_END 41 | 42 | #endif /* REMESHER_PLANE_HEADER */ 43 | -------------------------------------------------------------------------------- /remesher/libremesh/pntriangle.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "exception.h" 3 | #include "pntriangle.h" 4 | 5 | REMESHER_NAMESPACE_BEGIN 6 | 7 | void 8 | PNTriangle::init (std::size_t face_id) 9 | { 10 | if (this->mesh.get() == 0) 11 | throw Exception("No mesh set!"); 12 | 13 | MeshFaceList const& faces(this->mesh->get_faces()); 14 | MeshVertexList const& verts(this->mesh->get_vertices()); 15 | MeshNormalList const& normals(this->mesh->get_vertex_normals()); 16 | 17 | for (int i = 0; i < 3; ++i) 18 | { 19 | std::size_t vid(faces[face_id * 3 + i]); 20 | this->v[i] = verts[vid]; 21 | this->n[i] = normals[vid]; 22 | } 23 | 24 | /* Fix some normals if features are given. */ 25 | if (this->features.get() != 0 && !this->features->empty()) 26 | { 27 | Vec3f const& fnormal = this->mesh->get_face_normals()[face_id]; 28 | for (int i = 0; i < 3; ++i) 29 | { 30 | int ip1 = (i + 1) % 3; 31 | std::size_t vid_i(faces[face_id * 3 + i]); 32 | std::size_t vid_ip1(faces[face_id * 3 + ip1]); 33 | 34 | if (this->features->is_feature_edge(vid_i, vid_ip1)) 35 | { 36 | std::cout << "Setting face normal to vertex normal!" << std::endl; 37 | this->n[i] = fnormal; 38 | this->n[ip1] = fnormal; 39 | } 40 | } 41 | } 42 | } 43 | 44 | /* ---------------------------------------------------------------- */ 45 | 46 | Vec3f 47 | PNTriangle::get_position (Vec3f const& bary) 48 | { 49 | float w12 = (v[1] - v[0]).scalar(n[0]); 50 | float w21 = (v[0] - v[1]).scalar(n[1]); 51 | float w23 = (v[2] - v[1]).scalar(n[1]); 52 | float w32 = (v[1] - v[2]).scalar(n[2]); 53 | float w31 = (v[0] - v[2]).scalar(n[2]); 54 | float w13 = (v[2] - v[0]).scalar(n[0]); 55 | 56 | Vec3f const& b300(v[0]); 57 | Vec3f const& b030(v[1]); 58 | Vec3f const& b003(v[2]); 59 | Vec3f b210 = (v[0] * 2.0f + v[1] - n[0] * w12) / 3.0f; 60 | Vec3f b120 = (v[1] * 2.0f + v[0] - n[1] * w21) / 3.0f; 61 | Vec3f b021 = (v[1] * 2.0f + v[2] - n[1] * w23) / 3.0f; 62 | Vec3f b012 = (v[2] * 2.0f + v[1] - n[2] * w32) / 3.0f; 63 | Vec3f b102 = (v[2] * 2.0f + v[0] - n[2] * w31) / 3.0f; 64 | Vec3f b201 = (v[0] * 2.0f + v[2] - n[0] * w13) / 3.0f; 65 | Vec3f E = (b210 + b120 + b021 + b012 + b102 + b201) / 6.0f; 66 | Vec3f V = (v[0] + v[1] + v[2]) / 3.0f; 67 | Vec3f b111 = E + (E - V) / 2.0f; 68 | 69 | Vec3f b200 = b300 * bary[0] + b210 * bary[1] + b201 * bary[2]; 70 | Vec3f b110 = b210 * bary[0] + b120 * bary[1] + b111 * bary[2]; 71 | Vec3f b101 = b201 * bary[0] + b111 * bary[1] + b102 * bary[2]; 72 | Vec3f b020 = b120 * bary[0] + b030 * bary[1] + b021 * bary[2]; 73 | Vec3f b011 = b111 * bary[0] + b021 * bary[1] + b012 * bary[2]; 74 | Vec3f b002 = b102 * bary[0] + b012 * bary[1] + b003 * bary[2]; 75 | 76 | Vec3f b100 = b200 * bary[0] + b110 * bary[1] + b101 * bary[2]; 77 | Vec3f b010 = b110 * bary[0] + b020 * bary[1] + b011 * bary[2]; 78 | Vec3f b001 = b101 * bary[0] + b011 * bary[1] + b002 * bary[2]; 79 | 80 | return b100 * bary[0] + b010 * bary[1] + b001 * bary[2]; 81 | } 82 | 83 | REMESHER_NAMESPACE_END 84 | -------------------------------------------------------------------------------- /remesher/libremesh/pntriangle.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_PN_TRIANGLE_HEADER 2 | #define REMESHER_PN_TRIANGLE_HEADER 3 | 4 | #include "defines.h" 5 | #include "trianglemesh.h" 6 | #include "featureedges.h" 7 | #include "vec2.h" 8 | #include "vec3.h" 9 | 10 | REMESHER_NAMESPACE_BEGIN 11 | 12 | class PNTriangle 13 | { 14 | private: 15 | TriangleMeshPtr mesh; 16 | FeatureEdgesPtr features; 17 | VertexInfoListPtr vinfo; 18 | 19 | Vec3f v[3]; 20 | Vec3f n[3]; 21 | 22 | public: 23 | PNTriangle (void); 24 | 25 | /* The mesh is required if init(face_id) is used. */ 26 | void set_mesh (TriangleMeshPtr mesh); 27 | /* Surface no considered smooth on feature edges if set. */ 28 | void set_features (FeatureEdgesPtr features); 29 | /* Vertex info is required if features are set. */ 30 | void set_vertex_info (VertexInfoListPtr vinfo); 31 | 32 | /* Requires valid mesh with set_mesh(). */ 33 | void init (std::size_t face_id); 34 | /* No requirements. */ 35 | void init (Vec3f const& v1, Vec3f const& v2, Vec3f const& v3, 36 | Vec3f const& n1, Vec3f const& n2, Vec3f const& n3); 37 | 38 | /* Returns PN position given by barycentric coordinate. 39 | * Requires that one of the init functions has been called. */ 40 | Vec3f get_position (Vec3f const& bary); 41 | Vec3f get_position (Vec2f const& bary); 42 | }; 43 | 44 | /* ---------------------------------------------------------------- */ 45 | 46 | inline 47 | PNTriangle::PNTriangle (void) 48 | { 49 | } 50 | 51 | inline void 52 | PNTriangle::set_mesh (TriangleMeshPtr mesh) 53 | { 54 | this->mesh = mesh; 55 | } 56 | 57 | inline void 58 | PNTriangle::set_features (FeatureEdgesPtr features) 59 | { 60 | this->features = features; 61 | } 62 | 63 | inline void 64 | PNTriangle::set_vertex_info (VertexInfoListPtr vinfo) 65 | { 66 | this->vinfo = vinfo; 67 | } 68 | 69 | inline void 70 | PNTriangle::init (Vec3f const& v1, Vec3f const& v2, Vec3f const& v3, 71 | Vec3f const& n1, Vec3f const& n2, Vec3f const& n3) 72 | { 73 | this->v[0] = v1; this->v[1] = v2; this->v[2] = v3; 74 | this->n[0] = n1; this->n[1] = n2; this->n[2] = n3; 75 | } 76 | 77 | inline Vec3f 78 | PNTriangle::get_position (Vec2f const& bary) 79 | { 80 | return this->get_position(Vec3f(bary[0], bary[1], 1.0f - bary[0] - bary[1])); 81 | } 82 | 83 | REMESHER_NAMESPACE_END 84 | 85 | #endif /* REMESHER_PN_TRIANGLE_HEADER */ 86 | -------------------------------------------------------------------------------- /remesher/libremesh/pntriangle.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/pntriangle.o -------------------------------------------------------------------------------- /remesher/libremesh/polygon2.cc: -------------------------------------------------------------------------------- 1 | #include "exception.h" 2 | #include "straightline2.h" 3 | #include "polygon2.h" 4 | 5 | REMESHER_NAMESPACE_BEGIN 6 | 7 | void 8 | Polygon2::clip_with_line (Vec2f const& s1, Vec2f const& s2) 9 | { 10 | /* We create a new resulting polygon during clipping. */ 11 | Polygon2 p; 12 | 13 | /* Create a parameter line representation for the clipping line. 14 | * s1 is the base point, u is the direction vector. */ 15 | Vec2f u = s2 - s1; 16 | StraightLine2f clip_line(s1, s2); 17 | 18 | /* Iterate over all polygon edges and create the new polygon. */ 19 | for (std::size_t i = 0; i < this->size(); ++i) 20 | { 21 | std::size_t ip1 = (i + 1) % this->size(); 22 | 23 | /* Create a parameter line representation for the polygon edge. */ 24 | Vec2f const& e1 = this->at(i); 25 | Vec2f const& e2 = this->at(ip1); 26 | 27 | /* Solve edge equation to determine relative position. */ 28 | float eeq1 = clip_line.edge_equation(e1); 29 | float eeq2 = clip_line.edge_equation(e2); 30 | 31 | /* If both polygon vertices are on the right side, skip that edge. */ 32 | if (eeq1 > 0.0f && eeq2 > 0.0f) 33 | continue; 34 | 35 | /* If the first vertex is on the left side, append it to the polygon. */ 36 | if (eeq1 <= 0.0f) 37 | p.push_back(e1); 38 | 39 | /* If there is a intersection with the clip line, add the intersection. */ 40 | if ((eeq1 < 0.0f && eeq2 > 0.0f) || (eeq1 > 0.0f && eeq2 < 0.0f)) 41 | { 42 | /* This is the direction of the polygon edge to be clipped. */ 43 | Vec2f v = e2 - e1; 44 | 45 | /* Calculate the inverse determinante (of the 2x2 LSE). */ 46 | float idet = u[1] * v[0] - u[0] * v[1]; 47 | if (idet == 0.0f) 48 | throw Exception("Intersection of parallel lines"); 49 | 50 | /* Calculate the intersection parameters. */ 51 | Vec2f es = e1 - s1; 52 | //float lambda_s = (v[0] * es[1] - v[1] * es[0]) / idet; 53 | float lambda_e = (u[0] * es[1] - u[1] * es[0]) / idet; 54 | 55 | Vec2f intersection = e1 + v * lambda_e; 56 | p.push_back(intersection); 57 | } 58 | } 59 | 60 | (*this) = p; 61 | } 62 | 63 | REMESHER_NAMESPACE_END 64 | -------------------------------------------------------------------------------- /remesher/libremesh/polygon2.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_POLYGON_2_HEADER 2 | #define REMESHER_POLYGON_2_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "vec2.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | /* 12 | * This class represents a polygon in two dimenstions. 13 | */ 14 | class Polygon2 : public std::vector 15 | { 16 | public: 17 | /* Clips the polygon along an edge specified with two points. 18 | * All polygon vertices on the right side of the line are removed 19 | * (so the ordering of clipping vertices matters), new polygon 20 | * vertices are introduced at the intersections. */ 21 | void clip_with_line (Vec2f const& s1, Vec2f const& s2); 22 | }; 23 | 24 | REMESHER_NAMESPACE_END 25 | 26 | #endif /* REMESHER_POLYGON_2_HEADER */ 27 | -------------------------------------------------------------------------------- /remesher/libremesh/polygon2.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/polygon2.o -------------------------------------------------------------------------------- /remesher/libremesh/refptr.h: -------------------------------------------------------------------------------- 1 | #include "defines.h" 2 | 3 | #if REMESHER_PARALLELIZATION 4 | # include "refptr_mt.h" 5 | #else 6 | # include "refptr_st.h" 7 | #endif 8 | -------------------------------------------------------------------------------- /remesher/libremesh/refptrarray.h: -------------------------------------------------------------------------------- 1 | #ifndef REF_PTR_ARRAY_HEADER 2 | #define REF_PTR_ARRAY_HEADER 3 | 4 | #include "refptr.h" 5 | 6 | template 7 | class RefPtrArray : public RefPtr 8 | { 9 | public: 10 | /* Ctor: Default one. */ 11 | RefPtrArray (void) 12 | { } 13 | 14 | /* Ctor: From pointer. */ 15 | explicit RefPtrArray (T* p) : RefPtr(p) 16 | { } 17 | 18 | /* Ctor: Copy from other RefPtr. */ 19 | RefPtrArray (RefPtrArray const& src) : RefPtr(src) 20 | { } 21 | 22 | /* Element access const operator. */ 23 | E const& operator[] (std::size_t index) const 24 | { return (*this->ptr)[index]; } 25 | 26 | /* Element access operator. */ 27 | E& operator[] (std::size_t index) 28 | { return (*this->ptr)[index]; } 29 | }; 30 | 31 | #endif /* REF_PTR_ARRAY_HEADER */ 32 | -------------------------------------------------------------------------------- /remesher/libremesh/relaxanglesmooth.cc: -------------------------------------------------------------------------------- 1 | #include "relaxanglesmooth.h" 2 | 3 | REMESHER_NAMESPACE_BEGIN 4 | 5 | Vec2f 6 | AngleSmoothing::micropatch_relocate (MicroDelaunay const& md) 7 | { 8 | MicroPatch::AdjacentVertices2D const& verts = md.get_adjacent_vertices(); 9 | Vec2f center(0.0f, 0.0f); 10 | 11 | Vec2f newpos(0.0f, 0.0f); 12 | for (std::size_t i = 0; i < verts.size(); ++i) 13 | { 14 | std::size_t im1 = (i + verts.size() - 1) % verts.size(); 15 | std::size_t ip1 = (i + 1) % verts.size(); 16 | 17 | Vec2f const& vm1 = verts[im1]; 18 | Vec2f const& vi = verts[i]; 19 | Vec2f const& vp1 = verts[ip1]; 20 | 21 | Vec2f pos = (vm1.norm() + vp1.norm()) * vi.length() / 2.0f; 22 | newpos += pos; 23 | } 24 | 25 | newpos /= (float)verts.size(); 26 | return newpos; 27 | } 28 | 29 | REMESHER_NAMESPACE_END 30 | -------------------------------------------------------------------------------- /remesher/libremesh/relaxanglesmooth.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_ANGLE_SMOOTHING_HEADER 2 | #define REMESHER_ANGLE_SMOOTHING_HEADER 3 | 4 | #include "defines.h" 5 | #include "relaxation.h" 6 | 7 | REMESHER_NAMESPACE_BEGIN 8 | 9 | class AngleSmoothing : public Relaxation 10 | { 11 | protected: 12 | Vec2f micropatch_relocate (MicroDelaunay const& md); 13 | 14 | public: 15 | AngleSmoothing (void); 16 | }; 17 | 18 | /* ---------------------------------------------------------------- */ 19 | 20 | inline 21 | AngleSmoothing::AngleSmoothing (void) 22 | { 23 | } 24 | 25 | REMESHER_NAMESPACE_END 26 | 27 | #endif /* REMESHER_ANGLE_BASED_SMOOTHING_HEADER */ 28 | -------------------------------------------------------------------------------- /remesher/libremesh/relaxanglesmooth.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/relaxanglesmooth.o -------------------------------------------------------------------------------- /remesher/libremesh/relaxarea.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_AREA_BASED_RELAXATION 2 | #define REMESHER_AREA_BASED_RELAXATION 3 | 4 | #include "defines.h" 5 | #include "vec2.h" 6 | #include "microdelaunay.h" 7 | #include "relaxation.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | class AreaBasedRelaxation : public Relaxation 12 | { 13 | protected: 14 | Vec2f micropatch_relocate (MicroDelaunay const& md); 15 | 16 | public: 17 | AreaBasedRelaxation (void); 18 | }; 19 | 20 | /* ---------------------------------------------------------------- */ 21 | 22 | inline 23 | AreaBasedRelaxation::AreaBasedRelaxation (void) 24 | { 25 | } 26 | 27 | inline Vec2f 28 | AreaBasedRelaxation::micropatch_relocate (MicroDelaunay const& md) 29 | { 30 | return md.get_area_optimal_center(); 31 | } 32 | 33 | REMESHER_NAMESPACE_END 34 | 35 | #endif /* REMESHER_AREA_BASED_RELAXATION */ 36 | -------------------------------------------------------------------------------- /remesher/libremesh/relaxation.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/relaxation.o -------------------------------------------------------------------------------- /remesher/libremesh/relaxlloyd.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_LLOYD_RELAXATION 2 | #define REMESHER_LLOYD_RELAXATION 3 | 4 | #include "defines.h" 5 | #include "vec2.h" 6 | #include "microdelaunay.h" 7 | #include "relaxation.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | class LloydRelaxation : public Relaxation 12 | { 13 | protected: 14 | Vec2f micropatch_relocate (MicroDelaunay const& md); 15 | 16 | public: 17 | LloydRelaxation (void); 18 | }; 19 | 20 | /* ---------------------------------------------------------------- */ 21 | 22 | inline 23 | LloydRelaxation::LloydRelaxation (void) 24 | { 25 | } 26 | 27 | inline Vec2f 28 | LloydRelaxation::micropatch_relocate (MicroDelaunay const& md) 29 | { 30 | return md.get_voronoi_centroid(); 31 | } 32 | 33 | REMESHER_NAMESPACE_END 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /remesher/libremesh/relocation.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_RELOCATION_HEADER 2 | #define REMESHER_RELOCATION_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "trianglemesh.h" 8 | #include "vertexinfo.h" 9 | #include "vertexref.h" 10 | #include "triangle2.h" 11 | #include "patchcache.h" 12 | 13 | #if REMESHER_FB_PARAMETRIZATION 14 | # include "patch2d_fb.h" 15 | #else 16 | # include "patch2d.h" 17 | #endif 18 | 19 | REMESHER_NAMESPACE_BEGIN 20 | 21 | /* 22 | * These classes are capable of relocating a single vertex. Given three 23 | * point references and a barycentric coordinate regaring the three 24 | * points, the algorithm finds a triangle on the reference mesh that 25 | * contains the new point and a barycentric coordinate that uniquely 26 | * defines the new point. The class implements a technique from: 27 | * 28 | * Vitaly Surazhsky and Craig Gotsman 29 | * Explicit Surface Remeshing 30 | * 31 | * The actual relocation is done using a parametrization created 32 | * with the Patch2d class. 33 | */ 34 | 35 | /* ---------------------------------------------------------------- */ 36 | 37 | class Relocation 38 | { 39 | #if REMESHER_PATCH_CACHING 40 | private: 41 | PatchCachePtr cache; 42 | #endif 43 | 44 | private: 45 | /* Reference mesh data structures. */ 46 | TriangleMeshPtr rmesh; 47 | VertexInfoListPtr vinfo; 48 | 49 | private: 50 | Patch2dPtr get_patch (std::size_t f1, std::size_t f2, std::size_t f3); 51 | std::size_t find_opposite_face (std::size_t face, std::size_t fvidx); 52 | 53 | public: 54 | Relocation (void); 55 | ~Relocation (void); 56 | 57 | void set_data (TriangleMeshPtr ref_mesh, VertexInfoListPtr ref_vinfo); 58 | 59 | VertexRef relocate (VertexRef const& v1, VertexRef const& v2, 60 | VertexRef const& v3, Vec2f const& bary_coords); 61 | }; 62 | 63 | /* ---------------------------------------------------------------- */ 64 | 65 | inline 66 | Relocation::Relocation (void) 67 | { 68 | #if REMESHER_PATCH_CACHING 69 | this->cache = PatchCache::create(REMESHER_PATCH_CACHE_SIZE); 70 | #endif 71 | } 72 | 73 | inline 74 | Relocation::~Relocation (void) 75 | { 76 | this->cache->print_statistics(); 77 | } 78 | 79 | inline void 80 | Relocation::set_data (TriangleMeshPtr ref_mesh, VertexInfoListPtr ref_vinfo) 81 | { 82 | this->rmesh = ref_mesh; 83 | this->vinfo = ref_vinfo; 84 | } 85 | 86 | REMESHER_NAMESPACE_END 87 | 88 | #endif /* REMESHER_RELOCATION_HEADER */ 89 | -------------------------------------------------------------------------------- /remesher/libremesh/relocation.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/relocation.o -------------------------------------------------------------------------------- /remesher/libremesh/resampling.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/resampling.o -------------------------------------------------------------------------------- /remesher/libremesh/simplification.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/simplification.o -------------------------------------------------------------------------------- /remesher/libremesh/straightline2.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_STRAIGHT_LINE_2_HEADER 2 | #define REMESHER_STRAIGHT_LINE_2_HEADER 3 | 4 | #include "defines.h" 5 | #include "vec2.h" 6 | 7 | REMESHER_NAMESPACE_BEGIN 8 | 9 | template class StraightLine2; 10 | typedef StraightLine2 StraightLine2f; 11 | typedef StraightLine2 StraightLine2d; 12 | typedef StraightLine2 StraightLine2i; 13 | typedef StraightLine2 StraightLine2ui; 14 | typedef StraightLine2 StraightLine2s; 15 | typedef StraightLine2 StraightLine2us; 16 | typedef StraightLine2 StraightLine2c; 17 | typedef StraightLine2 StraightLine2uc; 18 | 19 | template 20 | class StraightLine2 21 | { 22 | private: 23 | Vec2 a, b; 24 | 25 | public: 26 | StraightLine2 (void); 27 | StraightLine2 (Vec2 const& a, Vec2 const& b); 28 | 29 | /* The edge equation. Returns a positive value if (x,y) is right of 30 | * line a -> b, a nevative value if (x,y) is left of the line, and 31 | * zero if (x,y) is on the line. */ 32 | T edge_equation (T const& x, T const& y); 33 | T edge_equation (Vec2 const& p); 34 | 35 | /* Calculates the square point distance to the line. */ 36 | T point_qdist (Vec2 const& p); 37 | }; 38 | 39 | /* ---------------------------------------------------------------- */ 40 | 41 | template 42 | inline 43 | StraightLine2::StraightLine2 (void) 44 | { 45 | } 46 | 47 | template 48 | inline 49 | StraightLine2::StraightLine2 (Vec2 const& a, Vec2 const& b) 50 | : a(a), b(b) 51 | { 52 | } 53 | 54 | template 55 | inline T 56 | StraightLine2::edge_equation (T const& x, T const& y) 57 | { 58 | return (T)((x - a[0]) * (b[1] - a[1]) - (y - a[1]) * (b[0] - a[0])); 59 | } 60 | 61 | template 62 | inline T 63 | StraightLine2::edge_equation (Vec2 const& p) 64 | { 65 | return this->edge_equation(p[0], p[1]); 66 | } 67 | 68 | template 69 | inline T 70 | StraightLine2::point_qdist (Vec2 const& p) 71 | { 72 | Vec2 r = b - a; 73 | T lambda = r.scalar(p - a) / r.scalar(r); 74 | Vec2 c = a + r * lambda; 75 | return (p - c).qlength(); 76 | } 77 | 78 | REMESHER_NAMESPACE_END 79 | 80 | #endif /* REMESHER_STRAIGHT_LINE_2_HEADER */ 81 | -------------------------------------------------------------------------------- /remesher/libremesh/straightline3.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_STRAIGHT_LINE_3_HEADER 2 | #define REMESHER_STRAIGHT_LINE_3_HEADER 3 | 4 | #include "defines.h" 5 | #include "vec3.h" 6 | 7 | REMESHER_NAMESPACE_BEGIN 8 | 9 | template class StraightLine3; 10 | typedef StraightLine3 StraightLine3f; 11 | typedef StraightLine3 StraightLine3d; 12 | typedef StraightLine3 StraightLine3i; 13 | typedef StraightLine3 StraightLine3ui; 14 | typedef StraightLine3 StraightLine3s; 15 | typedef StraightLine3 StraightLine3us; 16 | typedef StraightLine3 StraightLine3c; 17 | typedef StraightLine3 StraightLine3uc; 18 | 19 | template 20 | class StraightLine3 21 | { 22 | private: 23 | Vec3 a, b; 24 | 25 | public: 26 | StraightLine3 (void); 27 | StraightLine3 (Vec3 const& a, Vec3 const& b); 28 | 29 | T point_dist (Vec3 const& p) const; 30 | }; 31 | 32 | /* ---------------------------------------------------------------- */ 33 | 34 | template 35 | inline 36 | StraightLine3::StraightLine3 (void) 37 | { 38 | } 39 | 40 | template 41 | inline 42 | StraightLine3::StraightLine3 (Vec3 const& a, Vec3 const& b) 43 | : a(a), b(b) 44 | { 45 | } 46 | 47 | template 48 | inline T 49 | StraightLine3::point_dist (Vec3 const& p) const 50 | { 51 | return (b - a).cross(a - p).length() / (b - a).length(); 52 | } 53 | 54 | REMESHER_NAMESPACE_END 55 | 56 | #endif /* REMESHER_STRAIGHT_LINE_3_HEADER */ 57 | -------------------------------------------------------------------------------- /remesher/libremesh/subdivbase.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "elapsedtimer.h" 4 | #include "subdivbase.h" 5 | 6 | REMESHER_NAMESPACE_BEGIN 7 | 8 | void 9 | SubdivBase::start_subdiv (void) 10 | { 11 | ElapsedTimer t; 12 | 13 | this->subdiv_impl(); 14 | 15 | std::cout << "Subdivision took " << t.get_elapsed() << "ms. "; 16 | std::cout << "New mesh has " << (this->mesh->get_faces().size() / 3) 17 | << " faces and " << this->mesh->get_vertices().size() 18 | << " vertices." << std::endl; 19 | } 20 | 21 | /* ---------------------------------------------------------------- */ 22 | 23 | void 24 | SubdivBase::insert_faces (NewVertexIndices const& newvi) 25 | { 26 | /* Vertex info is invalidated. Clear it to save memory. */ 27 | this->vinfo->clear(); 28 | 29 | MeshFaceList& faces = this->mesh->get_faces(); 30 | std::size_t face_amount = faces.size() / 3; 31 | 32 | /* All vertices are inserted now. Triangles are inserted now, 33 | * subdividing each existing triangle. */ 34 | for (std::size_t i = 0; i < face_amount; ++i) 35 | { 36 | std::size_t new_faces = 0; 37 | for (std::size_t j = 0; j < 3; ++j) 38 | if (newvi[i * 3 + j] != MAX_SIZE_T) 39 | new_faces += 1; 40 | 41 | if (new_faces == 0) 42 | continue; 43 | 44 | if (new_faces == 1) 45 | { 46 | /* Find edge with the new vertex. */ 47 | std::size_t eidx = MAX_SIZE_T; 48 | for (std::size_t j = 0; j < 3; ++j) 49 | if (newvi[i * 3 + j] != MAX_SIZE_T) 50 | eidx = j; 51 | 52 | std::size_t v0idx = faces[i * 3 + eidx]; 53 | std::size_t v1idx = newvi[i * 3 + eidx]; 54 | std::size_t v2idx = faces[i * 3 + (eidx + 1) % 3]; 55 | std::size_t v3idx = faces[i * 3 + (eidx + 2) % 3]; 56 | 57 | faces[i * 3 + 0] = (MeshVIndex)v0idx; 58 | faces[i * 3 + 1] = (MeshVIndex)v1idx; 59 | faces[i * 3 + 2] = (MeshVIndex)v3idx; 60 | 61 | faces.push_back((MeshVIndex)v1idx); 62 | faces.push_back((MeshVIndex)v2idx); 63 | faces.push_back((MeshVIndex)v3idx); 64 | } 65 | else if (new_faces == 2) 66 | { 67 | /* Find edge without the new vertex. */ 68 | std::size_t eidx = MAX_SIZE_T; 69 | for (std::size_t j = 0; j < 3; ++j) 70 | if (newvi[i * 3 + j] == MAX_SIZE_T) 71 | eidx = j; 72 | 73 | std::size_t v0idx = faces[i * 3 + (eidx + 1) % 3]; 74 | std::size_t v1idx = newvi[i * 3 + (eidx + 1) % 3]; 75 | std::size_t v2idx = faces[i * 3 + (eidx + 2) % 3]; 76 | std::size_t v3idx = newvi[i * 3 + (eidx + 2) % 3]; 77 | std::size_t v4idx = faces[i * 3 + eidx]; 78 | 79 | faces[i * 3 + 0] = (MeshVIndex)v0idx; 80 | faces[i * 3 + 1] = (MeshVIndex)v1idx; 81 | faces[i * 3 + 2] = (MeshVIndex)v4idx; 82 | 83 | faces.push_back((MeshVIndex)v1idx); 84 | faces.push_back((MeshVIndex)v2idx); 85 | faces.push_back((MeshVIndex)v3idx); 86 | 87 | faces.push_back((MeshVIndex)v3idx); 88 | faces.push_back((MeshVIndex)v4idx); 89 | faces.push_back((MeshVIndex)v1idx); 90 | } 91 | else if (new_faces == 3) 92 | { 93 | /* Shorthands for the vertex indices. */ 94 | std::size_t v0idx = faces[i * 3 + 0]; 95 | std::size_t v2idx = faces[i * 3 + 1]; 96 | std::size_t v4idx = faces[i * 3 + 2]; 97 | std::size_t v1idx = newvi[i * 3 + 0]; 98 | std::size_t v3idx = newvi[i * 3 + 1]; 99 | std::size_t v5idx = newvi[i * 3 + 2]; 100 | 101 | faces[i * 3 + 0] = (MeshVIndex)v0idx; 102 | faces[i * 3 + 1] = (MeshVIndex)v1idx; 103 | faces[i * 3 + 2] = (MeshVIndex)v5idx; 104 | 105 | faces.push_back((MeshVIndex)v1idx); 106 | faces.push_back((MeshVIndex)v2idx); 107 | faces.push_back((MeshVIndex)v3idx); 108 | 109 | faces.push_back((MeshVIndex)v3idx); 110 | faces.push_back((MeshVIndex)v4idx); 111 | faces.push_back((MeshVIndex)v5idx); 112 | 113 | faces.push_back((MeshVIndex)v1idx); 114 | faces.push_back((MeshVIndex)v3idx); 115 | faces.push_back((MeshVIndex)v5idx); 116 | } 117 | } 118 | } 119 | 120 | REMESHER_NAMESPACE_END 121 | -------------------------------------------------------------------------------- /remesher/libremesh/subdivbase.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_SUBDIV_BASE_HEADER 2 | #define REMESHER_SUBDIV_BASE_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "trianglemesh.h" 8 | #include "vertexinfo.h" 9 | #include "featureedges.h" 10 | 11 | REMESHER_NAMESPACE_BEGIN 12 | 13 | class SubdivBase 14 | { 15 | protected: 16 | typedef std::vector NewVertexIndices; 17 | 18 | protected: 19 | TriangleMeshPtr mesh; 20 | VertexInfoListPtr vinfo; 21 | FeatureEdgesPtr features; 22 | 23 | protected: 24 | virtual void subdiv_impl (void) = 0; 25 | void insert_faces (NewVertexIndices const& newvi); 26 | 27 | public: 28 | /* Information for subdivision. All required. */ 29 | void set_mesh (TriangleMeshPtr mesh); 30 | void set_vertex_info (VertexInfoListPtr vinfo); 31 | void set_feature_edges (FeatureEdgesPtr features); 32 | 33 | /* Start the algorithm. */ 34 | virtual void start_subdiv (void); 35 | }; 36 | 37 | /* ---------------------------------------------------------------- */ 38 | 39 | inline void 40 | SubdivBase::set_mesh (TriangleMeshPtr mesh) 41 | { 42 | this->mesh = mesh; 43 | } 44 | 45 | inline void 46 | SubdivBase::set_vertex_info (VertexInfoListPtr vinfo) 47 | { 48 | this->vinfo = vinfo; 49 | } 50 | 51 | inline void 52 | SubdivBase::set_feature_edges (FeatureEdgesPtr features) 53 | { 54 | this->features = features; 55 | } 56 | 57 | REMESHER_NAMESPACE_END 58 | 59 | #endif /* REMESHER_SUBDIV_BASE_HEADER */ 60 | -------------------------------------------------------------------------------- /remesher/libremesh/subdivbase.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/subdivbase.o -------------------------------------------------------------------------------- /remesher/libremesh/subdivlinear.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "exception.h" 4 | #include "subdivlinear.h" 5 | 6 | REMESHER_NAMESPACE_BEGIN 7 | 8 | void 9 | SubdivLinear::subdiv_impl (void) 10 | { 11 | MeshFaceList& faces = this->mesh->get_faces(); 12 | MeshVertexList& verts = this->mesh->get_vertices(); 13 | 14 | /* Every edge in the mesh is subdivided and a new vertex in inserted. 15 | * The indices of the vertices are stored in this temp list. */ 16 | NewVertexIndices newvidx; 17 | newvidx.resize(faces.size(), MAX_SIZE_T); 18 | 19 | /* Walk over all triangles. Get the three neighboring triangles. 20 | * Subdivide the three edges if not done yet. Register the 21 | * new vertices in the temporary list to mark the edge as divided. */ 22 | std::size_t face_amount = faces.size() / 3; 23 | for (std::size_t i = 0; i < face_amount; ++i) 24 | { 25 | std::size_t fidx = i * 3; 26 | 27 | for (std::size_t j = 0; j < 3; ++j) 28 | { 29 | std::size_t jp1 = (j + 1) % 3; 30 | std::size_t v1idx = faces[fidx + j]; 31 | std::size_t v2idx = faces[fidx + jp1]; 32 | 33 | std::size_t face1, face2, v0idx, v3idx; 34 | bool unique = this->vinfo->get_edge_info(v1idx, v2idx, 35 | face1, face2, v0idx, v3idx); 36 | 37 | if (!unique) 38 | continue; 39 | 40 | if (face1 == MAX_SIZE_T) 41 | throw Exception("Subdivision: Face1 was not identified"); 42 | 43 | if (face2 != MAX_SIZE_T) 44 | { 45 | std::size_t jf2 = MAX_SIZE_T; 46 | for (std::size_t k = 0; k < 3; ++k) 47 | if (faces[face2 * 3 + k] == v2idx) 48 | jf2 = k; 49 | 50 | if (jf2 == MAX_SIZE_T) 51 | throw Exception("Subdivision: Error finding face2 index"); 52 | 53 | if (newvidx[face1 * 3 + j] != newvidx[face2 * 3 + jf2]) 54 | throw Exception("Subdivision: Edge info does not match"); 55 | 56 | if (newvidx[face1 * 3 + j] != MAX_SIZE_T) 57 | continue; 58 | 59 | newvidx[face2 * 3 + jf2] = verts.size(); 60 | } 61 | 62 | newvidx[face1 * 3 + j] = verts.size(); 63 | Vec3f newvert = (verts[v1idx] + verts[v2idx]) / 2.0f; 64 | verts.push_back(newvert); 65 | 66 | //std::cout << "Inserted new vertex " << verts.size() - 1 << std::endl; 67 | } 68 | } 69 | 70 | this->insert_faces(newvidx); 71 | } 72 | 73 | REMESHER_NAMESPACE_END 74 | -------------------------------------------------------------------------------- /remesher/libremesh/subdivlinear.h: -------------------------------------------------------------------------------- 1 | #ifndef REMEHSER_SUBDIV_LINEAR_HEADER 2 | #define REMEHSER_SUBDIV_LINEAR_HEADER 3 | 4 | #include "defines.h" 5 | #include "subdivbase.h" 6 | 7 | REMESHER_NAMESPACE_BEGIN 8 | 9 | class SubdivLinear : public SubdivBase 10 | { 11 | protected: 12 | void subdiv_impl (void); 13 | 14 | public: 15 | SubdivLinear (void); 16 | }; 17 | 18 | /* ---------------------------------------------------------------- */ 19 | 20 | inline 21 | SubdivLinear::SubdivLinear (void) 22 | { 23 | } 24 | 25 | REMESHER_NAMESPACE_END 26 | 27 | #endif /* REMEHSER_SUBDIV_LINEAR_HEADER */ 28 | -------------------------------------------------------------------------------- /remesher/libremesh/subdivlinear.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/subdivlinear.o -------------------------------------------------------------------------------- /remesher/libremesh/subdivloop.h: -------------------------------------------------------------------------------- 1 | #ifndef REMEHSER_SUBDIV_LOOP_HEADER 2 | #define REMEHSER_SUBDIV_LOOP_HEADER 3 | 4 | #include "defines.h" 5 | #include "featureedges.h" 6 | #include "subdivbase.h" 7 | 8 | REMESHER_NAMESPACE_BEGIN 9 | 10 | /* 11 | * Implements the Loop Subdivision scheme. 12 | */ 13 | class SubdivLoop : public SubdivBase 14 | { 15 | protected: 16 | enum LoopVClass 17 | { 18 | LVC_SMOOTH, 19 | LVC_DART, 20 | LVC_CREASE_REG, 21 | LVC_CREASE_NONREG, 22 | LVC_CORNER 23 | }; 24 | 25 | protected: 26 | std::vector vclasses; 27 | 28 | protected: 29 | void subdiv_impl (void); 30 | 31 | /* Classification of all vertices into LoopVClass classes. */ 32 | void classify_vertices (void); 33 | 34 | /* Three edge subdivision masks. */ 35 | void smooth_subdiv (std::size_t v0idx, std::size_t v1idx, 36 | std::size_t v2idx, std::size_t v3idx); 37 | void regular_crease_subdiv(std::size_t v1idx, std::size_t v2idx); 38 | void nonregular_crease_subdiv(std::size_t v1idx, std::size_t v2idx); 39 | 40 | public: 41 | SubdivLoop (void); 42 | }; 43 | 44 | /* ---------------------------------------------------------------- */ 45 | 46 | inline 47 | SubdivLoop::SubdivLoop (void) 48 | { 49 | } 50 | 51 | REMESHER_NAMESPACE_END 52 | 53 | #endif /* REMEHSER_SUBDIV_LOOP_HEADER */ 54 | -------------------------------------------------------------------------------- /remesher/libremesh/subdivloop.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/subdivloop.o -------------------------------------------------------------------------------- /remesher/libremesh/thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of GtkEveMon. 3 | * 4 | * GtkEveMon is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * You should have received a copy of the GNU General Public License 10 | * along with GtkEveMon. If not, see . 11 | */ 12 | 13 | #ifndef THREAD_HEADER 14 | #define THREAD_HEADER 15 | 16 | #ifndef _WIN32 17 | # include 18 | #endif 19 | 20 | #ifdef _WIN32 21 | # include "thread_win32.h" 22 | #elif defined(_POSIX_THREADS) 23 | # include "thread_posix.h" 24 | #else 25 | # error "Thread abstraction not available. PLEASE REPORT THIS!" 26 | #endif 27 | 28 | /* ---------------------------------------------------------------- */ 29 | 30 | /* 31 | * Exception safe lock for the mutex. 32 | */ 33 | class MutexLock 34 | { 35 | private: 36 | Mutex* m; 37 | 38 | public: 39 | MutexLock (Mutex& mutex) 40 | { this->m = &mutex; this->m->lock(); } 41 | 42 | ~MutexLock (void) 43 | { if (this->m) this->m->unlock(); } 44 | 45 | void unlock (void) 46 | { this->m->unlock(); this->m = 0; } 47 | }; 48 | 49 | /* ---------------------------------------------------------------- */ 50 | 51 | /* 52 | * Exception safe read lock for the reader/writer lock. 53 | */ 54 | class ReadLock 55 | { 56 | private: 57 | ReadWriteLock* rwl; 58 | 59 | public: 60 | ReadLock (ReadWriteLock& rwlock) 61 | { this->rwl = &rwlock; this->rwl->read_lock(); } 62 | 63 | ~ReadLock (void) 64 | { if (this->rwl) this->rwl->unlock(); } 65 | 66 | void unlock (void) 67 | { this->rwl->unlock(); this->rwl = 0; } 68 | }; 69 | 70 | /* ---------------------------------------------------------------- */ 71 | 72 | /* 73 | * Exception safe write lock for the reader/writer lock. 74 | */ 75 | class WriteLock 76 | { 77 | private: 78 | ReadWriteLock* rwl; 79 | 80 | public: 81 | WriteLock (ReadWriteLock& rwlock) 82 | { this->rwl = &rwlock; this->rwl->write_lock(); } 83 | 84 | ~WriteLock (void) 85 | { if (this->rwl) this->rwl->unlock(); } 86 | 87 | void unlock (void) 88 | { this->rwl->unlock(); this->rwl = 0; } 89 | }; 90 | 91 | #endif /* THREAD_HEADER */ 92 | -------------------------------------------------------------------------------- /remesher/libremesh/trianglemesh.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/trianglemesh.o -------------------------------------------------------------------------------- /remesher/libremesh/triangulator.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_TRIANGULATOR_HEADER 2 | #define REMESHER_TRIANGULATOR_HEADER 3 | 4 | #include "defines.h" 5 | #include "trianglemesh.h" 6 | #include "vertexinfo.h" 7 | 8 | REMESHER_NAMESPACE_BEGIN 9 | 10 | /* 11 | * This class is capable of triangulating a set of vertices given 12 | * as vertex loop, i.e. a polygon of vertices. The vertices are 13 | * indices to a reference mesh. The 3D positions of the vertices 14 | * to calculate the triangulation is taken from the mesh. 15 | * 16 | * The method in question is a recursive loop-splitting procedure 17 | * that is used in a simplification algorithm described in: 18 | * 19 | * William J. Schroeder, Jonathan A. Zarge, William E. Lorensen 20 | * Decimation of Triangle Meshes 21 | * 22 | * An initial splitline can be specified, if there is a constrain 23 | * on a certain edge (i.e. a feature edge that is simplified). 24 | */ 25 | class Triangulator 26 | { 27 | public: 28 | typedef std::pair SplitLine; 29 | 30 | protected: 31 | TriangleMeshPtr mesh; 32 | VertexInfoListPtr vinfo; 33 | 34 | protected: 35 | /* Checks the quality of the split line. If the split line is 36 | * invalid, quality is negative. Otherwise quality is positive. */ 37 | float check_splitline_quality (SplitLine const& sl, 38 | VertexInfo::VertexList const& vl, Vec3f const& ap_normal); 39 | 40 | public: 41 | Triangulator (void); 42 | Triangulator (TriangleMeshPtr mesh); 43 | 44 | void set_mesh (TriangleMeshPtr mesh); 45 | 46 | /* Setting the vertex info enables checks to avoid "invalid" 47 | * triangulations (those that change genus and so on) to happen. */ 48 | void set_vertex_info (VertexInfoListPtr vinfo); 49 | 50 | /* Meshes the given loop of vertices by recursive loop splitting. 51 | * The overlapping check needs the normal of the average plane, 52 | * the normal may not be normalized. A splitline may be specified 53 | * for the first split. */ 54 | bool triangulate (VertexInfo::VertexList const& vlist, 55 | MeshFaceList& flist, Vec3f const& ap_normal, 56 | SplitLine const& sline); 57 | }; 58 | 59 | /* ---------------------------------------------------------------- */ 60 | 61 | inline 62 | Triangulator::Triangulator (void) 63 | { 64 | } 65 | 66 | inline 67 | Triangulator::Triangulator (TriangleMeshPtr mesh) 68 | { 69 | this->mesh = mesh; 70 | } 71 | 72 | inline void 73 | Triangulator::set_mesh (TriangleMeshPtr mesh) 74 | { 75 | this->mesh = mesh; 76 | } 77 | 78 | inline void 79 | Triangulator::set_vertex_info (VertexInfoListPtr vinfo) 80 | { 81 | this->vinfo = vinfo; 82 | } 83 | 84 | REMESHER_NAMESPACE_END 85 | 86 | #endif /* REMESHER_TRIANGULATOR_HEADER */ 87 | -------------------------------------------------------------------------------- /remesher/libremesh/triangulator.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/triangulator.o -------------------------------------------------------------------------------- /remesher/libremesh/vec2.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_VEC2_HEADER 2 | #define REMESHER_VEC2_HEADER 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "defines.h" 9 | 10 | REMESHER_NAMESPACE_BEGIN 11 | 12 | template class Vec2; 13 | 14 | typedef Vec2 Vec2f; 15 | typedef Vec2 Vec2d; 16 | typedef Vec2 Vec2i; 17 | typedef Vec2 Vec2ui; 18 | typedef Vec2 Vec2s; 19 | typedef Vec2 Vec2us; 20 | typedef Vec2 Vec2c; 21 | typedef Vec2 Vec2uc; 22 | 23 | template 24 | class Vec2 25 | { 26 | public: 27 | T x, y; 28 | 29 | public: 30 | Vec2 (void) {} 31 | Vec2 (T* v) : x(v[0]), y(v[1]) {} 32 | Vec2 (T _x, T _y) : x(_x), y(_y) {} 33 | 34 | Vec2 plus (Vec2 const& c) const 35 | { return Vec2(x + c.x, y + c.y); } 36 | 37 | Vec2 minus (Vec2 const& c) const 38 | { return Vec2(x - c.x, y - c.y); } 39 | 40 | Vec2 mult (T const& f) const 41 | { return Vec2(x * f, y * f); } 42 | 43 | Vec2 div (T const& f) const 44 | { return Vec2(x / f, y / f); } 45 | 46 | T scalar (Vec2 const& c) const 47 | { return x * c.x + y * c.y; } 48 | 49 | Vec2 neg (void) const 50 | { return Vec2(-x, -y); } 51 | 52 | T length (void) const 53 | { return std::sqrt(x * x + y * y); } 54 | 55 | T qlength (void) const 56 | { return x * x + y * y; } 57 | 58 | T* array (void) 59 | { return &x; } 60 | 61 | T const* array (void) const 62 | { return &x; } 63 | 64 | Vec2 norm (void) const 65 | { T len = length(); return Vec2(x / len, y / len); } 66 | 67 | void norm_self (void) 68 | { T len = length(); x /= len; y /= len; } 69 | 70 | bool eps_equals (Vec2 const& c) const; 71 | 72 | Vec2 operator+ (Vec2 const& rhs) const 73 | { return plus(rhs); } 74 | 75 | Vec2& operator+= (Vec2 const& rhs) 76 | { x += rhs.x; y += rhs.y; return *this; } 77 | 78 | T const& operator[] (std::size_t i) const 79 | { return (&x)[i]; } 80 | 81 | T& operator[] (std::size_t i) 82 | { return (&x)[i]; } 83 | 84 | Vec2 operator- (void) const 85 | { return neg(); } 86 | 87 | Vec2 operator- (Vec2 const& rhs) const 88 | { return minus(rhs); } 89 | 90 | Vec2& operator-= (Vec2 const& rhs) 91 | { x -= rhs.x; y -= rhs.y; return *this; } 92 | 93 | Vec2 operator* (T const& rhs) const 94 | { return mult(rhs); } 95 | 96 | T operator* (Vec2 const& rhs) const 97 | { return scalar(rhs); } 98 | 99 | Vec2& operator*= (T const& rhs) 100 | { x *= rhs; y *= rhs; return *this; } 101 | 102 | Vec2 operator/ (T const& rhs) const 103 | { return div(rhs); } 104 | 105 | Vec2& operator/= (T const& rhs) 106 | { x /= rhs; y /= rhs; return *this; } 107 | 108 | // Not compatible with STL containers 109 | //T* operator& (void) { return &x; } 110 | 111 | friend std::ostream& operator<< (std::ostream& os, Vec2 const& v) 112 | { return os << "(" << v.x << "," << v.y << ")"; } 113 | }; 114 | 115 | /* ---------------------------------------------------------------- */ 116 | 117 | template 118 | inline bool 119 | Vec2::eps_equals (Vec2 const& c) const 120 | { 121 | return x == c.x && y == c.y; 122 | } 123 | 124 | template <> 125 | inline bool 126 | Vec2::eps_equals (Vec2 const& c) const 127 | { 128 | return FLOAT_EQ(x, c.x) && FLOAT_EQ(y, c.y); 129 | } 130 | 131 | template <> 132 | inline bool 133 | Vec2::eps_equals (Vec2 const& c) const 134 | { 135 | return DOUBLE_EQ(x, c.x) && DOUBLE_EQ(y, c.y); 136 | } 137 | 138 | REMESHER_NAMESPACE_END 139 | 140 | #endif /* REMESHER_VEC2_HEADER */ 141 | -------------------------------------------------------------------------------- /remesher/libremesh/vec3.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_VEC3_HEADER 2 | #define REMESHER_VEC3_HEADER 3 | 4 | #include 5 | #include 6 | 7 | #include "defines.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | template class Vec3; 12 | 13 | typedef Vec3 Vec3f; 14 | typedef Vec3 Vec3d; 15 | typedef Vec3 Vec3i; 16 | typedef Vec3 Vec3ui; 17 | typedef Vec3 Vec3s; 18 | typedef Vec3 Vec3us; 19 | typedef Vec3 Vec3c; 20 | typedef Vec3 Vec3uc; 21 | 22 | template 23 | class Vec3 24 | { 25 | public: 26 | T x, y, z; 27 | 28 | public: 29 | Vec3 (void) {} 30 | Vec3 (T* v) : x(v[0]), y(v[1]), z(v[2]) {} 31 | Vec3 (T _x, T _y, T _z) : x(_x), y(_y), z(_z) {} 32 | 33 | Vec3 plus (Vec3 const& c) const 34 | { return Vec3(x + c.x, y + c.y, z + c.z); } 35 | 36 | Vec3 minus (Vec3 const& c) const 37 | { return Vec3(x - c.x, y - c.y, z - c.z); } 38 | 39 | Vec3 mult (T const& f) const 40 | { return Vec3(x * f, y * f, z * f); } 41 | 42 | Vec3 div (T const& f) const 43 | { return Vec3(x / f, y / f, z / f); } 44 | 45 | Vec3 cross (Vec3 const& c) const 46 | { return Vec3(y * c.z - z * c.y, c.x * z - x * c.z, x * c.y - c.x * y); } 47 | 48 | T scalar (Vec3 const& c) const 49 | { return x * c.x + y * c.y + z * c.z; } 50 | 51 | Vec3 neg (void) const 52 | { return Vec3(-x, -y, -z); } 53 | 54 | T length (void) const 55 | { return std::sqrt(x * x + y * y + z * z); } 56 | 57 | T qlength (void) const 58 | { return x * x + y * y + z * z; } 59 | 60 | T* array (void) 61 | { return &x; } 62 | 63 | T const* array (void) const 64 | { return &x; } 65 | 66 | Vec3 norm (void) const 67 | { T len = length(); return Vec3(x / len, y / len, z / len); } 68 | 69 | void norm_self (void) 70 | { T len = length(); x /= len; y /= len; z /= len; } 71 | 72 | Vec3 operator+ (Vec3 const& rhs) const 73 | { return plus(rhs); } 74 | 75 | Vec3& operator+= (Vec3 const& rhs) 76 | { x += rhs.x; y += rhs.y; z += rhs.z; return *this; } 77 | 78 | T const& operator[] (std::size_t i) const 79 | { return (&x)[i]; } 80 | 81 | T& operator[] (std::size_t i) 82 | { return (&x)[i]; } 83 | 84 | Vec3 operator- (void) const 85 | { return neg(); } 86 | 87 | Vec3 operator- (Vec3 const& rhs) const 88 | { return minus(rhs); } 89 | 90 | Vec3& operator-= (Vec3 const& rhs) 91 | { x -= rhs.x; y -= rhs.y; z -= rhs.z; return *this; } 92 | 93 | Vec3 operator* (T const& rhs) const 94 | { return mult(rhs); } 95 | 96 | T operator* (Vec3 const& rhs) const 97 | { return scalar(rhs); } 98 | 99 | Vec3& operator*= (T const& rhs) 100 | { x *= rhs; y *= rhs; z *= rhs; return *this; } 101 | 102 | Vec3 operator/ (T const& rhs) const 103 | { return div(rhs); } 104 | 105 | Vec3& operator/= (T const& rhs) 106 | { x /= rhs; y /= rhs; z /= rhs; return *this; } 107 | 108 | bool operator== (Vec3 const& rhs) 109 | { return (x == rhs.x && y == rhs.y && z == rhs.z); } 110 | 111 | bool operator!= (Vec3 const& rhs) 112 | { return (x != rhs.x || y != rhs.y || z != rhs.z); } 113 | 114 | // Not compatible with STL containers 115 | //T* operator& (void) { return &x; } 116 | 117 | friend std::ostream& operator<< (std::ostream& os, Vec3 const& v) 118 | { return os << "(" << v.x << "," << v.y << "," << v.z << ")"; } 119 | }; 120 | 121 | REMESHER_NAMESPACE_END 122 | 123 | #endif /* REMESHER_VEC3_HEADER */ 124 | -------------------------------------------------------------------------------- /remesher/libremesh/vec4.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_VEC4_HEADER 2 | #define REMESHER_VEC4_HEADER 3 | 4 | #include 5 | #include 6 | 7 | #include "defines.h" 8 | 9 | REMESHER_NAMESPACE_BEGIN 10 | 11 | template class Vec4; 12 | 13 | typedef Vec4 Vec4f; 14 | typedef Vec4 Vec4d; 15 | typedef Vec4 Vec4i; 16 | typedef Vec4 Vec4ui; 17 | typedef Vec4 Vec4s; 18 | typedef Vec4 Vec4us; 19 | typedef Vec4 Vec4c; 20 | typedef Vec4 Vec4uc; 21 | 22 | template 23 | class Vec4 24 | { 25 | public: 26 | T x, y, z, w; 27 | 28 | public: 29 | Vec4 (void) {} 30 | Vec4 (T* v) : x(v[0]), y(v[1]), z(v[2]), w(v[3]) {} 31 | Vec4 (T _x, T _y, T _z, T _w) : x(_x), y(_y), z(_z), w(_w) {} 32 | 33 | Vec4 plus (Vec4 const& c) const 34 | { return Vec4(x + c.x, y + c.y, z + c.z, w + c.w); } 35 | 36 | Vec4 minus (Vec4 const& c) const 37 | { return Vec4(x - c.x, y - c.y, z - c.z, w - c.w); } 38 | 39 | Vec4 mult (T const& f) const 40 | { return Vec4(x * f, y * f, z * f, w * f); } 41 | 42 | Vec4 div (T const& f) const 43 | { return Vec4(x / f, y / f, z / f, w / f); } 44 | 45 | T scalar (Vec4 const& c) const 46 | { return x * c.x + y * c.y + z * c.z + w * c.w; } 47 | 48 | Vec4 neg (void) const 49 | { return Vec4(-x, -y, -z, -w); } 50 | 51 | T length (void) const 52 | { return std::sqrt(x * x + y * y + z * z + w * w); } 53 | 54 | T* array (void) 55 | { return &x; } 56 | 57 | T const* array (void) const 58 | { return &x; } 59 | 60 | Vec4 norm (void) const 61 | { T len = length(); return Vec4(x / len, y / len, z / len, w / len); } 62 | 63 | void norm_self (void) 64 | { T len = length(); x /= len; y /= len; z /= len; w /= len; } 65 | 66 | Vec4 operator+ (Vec4 const& rhs) const 67 | { return plus(rhs); } 68 | 69 | Vec4& operator+= (Vec4 const& rhs) 70 | { x += rhs.x; y += rhs.y; z += rhs.z; w += rhs.w; return *this; } 71 | 72 | T const& operator[] (std::size_t i) const 73 | { return (&x)[i]; } 74 | 75 | T& operator[] (std::size_t i) 76 | { return (&x)[i]; } 77 | 78 | Vec4 operator- (void) const 79 | { return neg(); } 80 | 81 | Vec4 operator- (Vec4 const& rhs) const 82 | { return minus(rhs); } 83 | 84 | Vec4& operator-= (Vec4 const& rhs) 85 | { x -= rhs.x; y -= rhs.y; z -= rhs.z; w -= rhs.w; return *this; } 86 | 87 | Vec4 operator* (T const& rhs) const 88 | { return mult(rhs); } 89 | 90 | T operator* (Vec4 const& rhs) const 91 | { return scalar(rhs); } 92 | 93 | Vec4& operator*= (T const& rhs) 94 | { x *= rhs; y *= rhs; z *= rhs; w *= rhs; return *this; } 95 | 96 | Vec4 operator/ (T const& rhs) const 97 | { return div(rhs); } 98 | 99 | Vec4& operator/= (T const& rhs) 100 | { x /= rhs; y /= rhs; z /= rhs; w /= rhs; return *this; } 101 | 102 | // Not compatible with STL containers 103 | //T* operator& (void) { return &x; } 104 | 105 | friend std::ostream& operator<< (std::ostream& os, Vec4 const& v) 106 | { return os << "(" << v.x << "," << v.y << "," << v.z << "," << v.w << ")"; } 107 | }; 108 | 109 | REMESHER_NAMESPACE_END 110 | 111 | #endif /* REMESHER_VEC4_HEADER */ 112 | -------------------------------------------------------------------------------- /remesher/libremesh/vertexinfo.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/vertexinfo.o -------------------------------------------------------------------------------- /remesher/libremesh/vertexref.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "exception.h" 4 | #include "vertexref.h" 5 | 6 | REMESHER_NAMESPACE_BEGIN 7 | 8 | void 9 | VertexRefList::init_identity (TriangleMeshPtr mesh, VertexInfoListPtr vinfo) 10 | { 11 | if (mesh->get_vertices().size() != vinfo->size()) 12 | throw Exception("Vertex info does not match with the mesh!"); 13 | 14 | this->clear(); 15 | this->resize(vinfo->size()); 16 | 17 | for (std::size_t i = 0; i < vinfo->size(); ++i) 18 | { 19 | VertexInfo::FaceList const& adj_faces = vinfo[i].adj_faces; 20 | if (adj_faces.empty()) 21 | { 22 | std::cout << "Warning: No info for unreferenced vertex" << std::endl; 23 | continue; 24 | } 25 | 26 | std::size_t face = adj_faces[0]; 27 | std::size_t off = MAX_SIZE_T; 28 | for (std::size_t j = 0; j < 3; ++j) 29 | if (mesh->get_faces()[face * 3 + j] == i) 30 | off = j; 31 | 32 | if (off == MAX_SIZE_T) 33 | throw Exception("Error: Adjacent face without vertex"); 34 | 35 | this->at(i).face = face; 36 | this->at(i).bary = Vec2f(off == 0 ? 1.0f : 0.0f, off == 1 ? 1.0f : 0.0f); 37 | } 38 | } 39 | 40 | REMESHER_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /remesher/libremesh/vertexref.h: -------------------------------------------------------------------------------- 1 | #ifndef REMESHER_VERTEX_REF_HEADER 2 | #define REMESHER_VERTEX_REF_HEADER 3 | 4 | #include 5 | 6 | #include "defines.h" 7 | #include "refptrarray.h" 8 | #include "trianglemesh.h" 9 | #include "vertexinfo.h" 10 | #include "vec2.h" 11 | 12 | REMESHER_NAMESPACE_BEGIN 13 | 14 | struct VertexRef 15 | { 16 | std::size_t face; 17 | Vec2f bary; 18 | 19 | VertexRef (void); 20 | VertexRef (std::size_t face, Vec2f const& bary); 21 | }; 22 | 23 | /* ---------------------------------------------------------------- */ 24 | 25 | /* 26 | * This class is a proxy class for a vector that holds a reference 27 | * point on a reference mesh for each vertex. The reference point 28 | * is given with a face index and a barycentric coordinate for that 29 | * face. This uniquely defines a point on the reference mesh. 30 | */ 31 | 32 | class VertexRefList; 33 | typedef RefPtrArray VertexRefListPtr; 34 | 35 | class VertexRefList : public std::vector 36 | { 37 | protected: 38 | VertexRefList (void); 39 | 40 | public: 41 | static VertexRefListPtr create (void); 42 | VertexRefListPtr create_copy (void) const; 43 | 44 | /* Initializes the vertex references with identity mapping. */ 45 | void init_identity (TriangleMeshPtr mesh, VertexInfoListPtr vinfo); 46 | 47 | std::size_t get_memory_usage (void) const; 48 | }; 49 | 50 | /* ---------------------------------------------------------------- */ 51 | 52 | inline 53 | VertexRef::VertexRef (void) 54 | { 55 | } 56 | 57 | inline 58 | VertexRef::VertexRef (std::size_t face, Vec2f const& bary) 59 | : face(face), bary(bary) 60 | { 61 | } 62 | 63 | inline VertexRefListPtr 64 | VertexRefList::create (void) 65 | { 66 | return VertexRefListPtr(new VertexRefList); 67 | } 68 | 69 | inline 70 | VertexRefList::VertexRefList (void) 71 | { 72 | } 73 | 74 | inline VertexRefListPtr 75 | VertexRefList::create_copy (void) const 76 | { 77 | return VertexRefListPtr(new VertexRefList(*this)); 78 | } 79 | 80 | inline std::size_t 81 | VertexRefList::get_memory_usage (void) const 82 | { 83 | return this->capacity() * sizeof(VertexRef); 84 | } 85 | 86 | REMESHER_NAMESPACE_END 87 | 88 | #endif /* REMESHER_VERTEX_REF_HEADER */ 89 | -------------------------------------------------------------------------------- /remesher/libremesh/vertexref.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/remesher/libremesh/vertexref.o -------------------------------------------------------------------------------- /share/lh.HCP-MMP1.annot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/share/lh.HCP-MMP1.annot -------------------------------------------------------------------------------- /share/lh.Yeo_17nets.annot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/share/lh.Yeo_17nets.annot -------------------------------------------------------------------------------- /share/lh.Yeo_7nets.annot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/share/lh.Yeo_7nets.annot -------------------------------------------------------------------------------- /share/reference_table_Yeo-17nets.csv: -------------------------------------------------------------------------------- 1 | label,name,c1,c2,c3,id,val_fs,cortical,alpha 2 | 0,Unknown,0,0,0,0,0,0,0 3 | 16,Brain-Stem,119,159,176,1,11575159,0,0 4 | 8,Left-Cerebellum-Cortex,230,148,34,2,2266342,0,0 5 | 10,Left-Thalamus-Proper,0,118,14,3,947712,0,0 6 | 11,Left-Caudate,122,186,220,4,14465658,0,0 7 | 12,Left-Putamen,236,13,176,5,11537900,0,0 8 | 13,Left-Pallidum,12,48,255,6,16723980,0,0 9 | 17,Left-Hippocampus,220,216,20,7,1366236,0,0 10 | 18,Left-Amygdala,103,255,255,8,16777063,0,0 11 | 26,Left-Accumbens-area,255,165,0,9,42495,0,0 12 | ,FreeSurfer_Defined_Medial_Wall,1,1,1,10,65793,1,0 13 | ,17Networks_1,120,18,134,11,8786552,1,0 14 | ,17Networks_2,255,0,0,12,255,1,0 15 | ,17Networks_3,70,130,180,13,11829830,1,0 16 | ,17Networks_4,42,204,164,14,10800170,1,0 17 | ,17Networks_5,74,155,60,15,3971914,1,0 18 | ,17Networks_6,0,118,14,16,947712,1,0 19 | ,17Networks_7,196,58,250,17,16399044,1,0 20 | ,17Networks_8,255,152,213,18,13998335,1,0 21 | ,17Networks_9,220,248,164,19,10811612,1,0 22 | ,17Networks_10,122,135,50,20,3311482,1,0 23 | ,17Networks_11,119,140,176,21,11570295,1,0 24 | ,17Networks_12,230,148,34,22,2266342,1,0 25 | ,17Networks_13,135,50,74,23,4862599,1,0 26 | ,17Networks_14,12,48,255,24,16723980,1,0 27 | ,17Networks_15,0,0,130,25,8519680,1,0 28 | ,17Networks_16,255,255,0,26,65535,1,0 29 | ,17Networks_17,205,62,78,27,5127885,1,0 30 | 47,Right-Cerebellum-Cortex23014834,230,148,34,28,2266342,0,0 31 | 49,Right-Thalamus-Proper011814,0,118,14,29,947712,0,0 32 | 50,Right-Caudate122186220,122,186,220,30,14465658,0,0 33 | 51,Right-Putamen23613176,236,13,176,31,11537900,0,0 34 | 52,Right-Pallidum1348255,13,48,255,32,16723981,0,0 35 | 53,Right-Hippocampus22021620,220,216,20,33,1366236,0,0 36 | 54,Right-Amygdala103255255,103,255,255,34,16777063,0,0 37 | 58,Right-Accumbens-area2551650,255,165,0,35,42495,0,0 38 | ,FreeSurfer_Defined_Medial_Wall,1,1,1,36,65793,1,0 39 | ,17Networks_1,120,18,134,37,8786552,1,0 40 | ,17Networks_2,255,0,0,38,255,1,0 41 | ,17Networks_3,70,130,180,39,11829830,1,0 42 | ,17Networks_4,42,204,164,40,10800170,1,0 43 | ,17Networks_5,74,155,60,41,3971914,1,0 44 | ,17Networks_6,0,118,14,42,947712,1,0 45 | ,17Networks_7,196,58,250,43,16399044,1,0 46 | ,17Networks_8,255,152,213,44,13998335,1,0 47 | ,17Networks_9,220,248,164,45,10811612,1,0 48 | ,17Networks_10,122,135,50,46,3311482,1,0 49 | ,17Networks_11,119,140,176,47,11570295,1,0 50 | ,17Networks_12,230,148,34,48,2266342,1,0 51 | ,17Networks_13,135,50,74,49,4862599,1,0 52 | ,17Networks_14,12,48,255,50,16723980,1,0 53 | ,17Networks_15,0,0,130,51,8519680,1,0 54 | ,17Networks_16,255,255,0,52,65535,1,0 55 | ,17Networks_17,205,62,78,53,5127885,1,0 56 | -------------------------------------------------------------------------------- /share/reference_table_Yeo-7nets.csv: -------------------------------------------------------------------------------- 1 | label,name,c1,c2,c3,id,val+AF8-fs,cortical,alpha 2 | 0,Unknown,0,0,0,0,0,0,0 3 | 16,Brain+AC0-Stem,119,159,176,1,11575159,0,0 4 | 8,Left+AC0-Cerebellum+AC0-Cortex,230,148,34,2,2266342,0,0 5 | 10,Left+AC0-Thalamus+AC0-Proper,0,118,14,3,947712,0,0 6 | 11,Left+AC0-Caudate,122,186,220,4,14465658,0,0 7 | 12,Left+AC0-Putamen,236,13,176,5,11537900,0,0 8 | 13,Left+AC0-Pallidum,12,48,255,6,16723980,0,0 9 | 17,Left+AC0-Hippocampus,220,216,20,7,1366236,0,0 10 | 18,Left+AC0-Amygdala,103,255,255,8,16777063,0,0 11 | 26,Left+AC0-Accumbens+AC0-area,255,165,0,9,42495,0,0 12 | ,FreeSurfer+AF8-Defined+AF8-Medial+AF8-Wall,1,1,1,10,65793,0,0 13 | ,7Networks+AF8-1,120,18,134,11,8786552,1,0 14 | ,7Networks+AF8-2,70,130,180,12,11829830,1,0 15 | ,7Networks+AF8-3,0,118,14,13,947712,1,0 16 | ,7Networks+AF8-4,196,58,250,14,16399044,1,0 17 | ,7Networks+AF8-5,220,248,164,15,10811612,1,0 18 | ,7Networks+AF8-6,230,148,34,16,2266342,1,0 19 | ,7Networks+AF8-7,205,62,78,17,5127885,1,0 20 | 47,Right+AC0-Cerebellum+AC0-Cortex23014834,230,148,34,18,2266342,0,0 21 | 49,Right+AC0-Thalamus+AC0-Proper011814,0,118,14,19,947712,0,0 22 | 50,Right+AC0-Caudate122186220,122,186,220,20,14465658,0,0 23 | 51,Right+AC0-Putamen23613176,236,13,176,21,11537900,0,0 24 | 52,Right+AC0-Pallidum1348255,13,48,255,22,16723981,0,0 25 | 53,Right+AC0-Hippocampus22021620,220,216,20,23,1366236,0,0 26 | 54,Right+AC0-Amygdala103255255,103,255,255,24,16777063,0,0 27 | 58,Right+AC0-Accumbens+AC0-area2551650,255,165,0,25,42495,0,0 28 | ,FreeSurfer+AF8-Defined+AF8-Medial+AF8-Wall,1,1,1,26,65793,0,0 29 | ,7Networks+AF8-1,120,18,134,27,8786552,1,0 30 | ,7Networks+AF8-2,70,130,180,28,11829830,1,0 31 | ,7Networks+AF8-3,0,118,14,29,947712,1,0 32 | ,7Networks+AF8-4,196,58,250,30,16399044,1,0 33 | ,7Networks+AF8-5,220,248,164,31,10811612,1,0 34 | ,7Networks+AF8-6,230,148,34,32,2266342,1,0 35 | ,7Networks+AF8-7,205,62,78,33,5127885,1,0 36 | -------------------------------------------------------------------------------- /share/rh.HCP-MMP1.annot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/share/rh.HCP-MMP1.annot -------------------------------------------------------------------------------- /share/rh.Yeo_17nets.annot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/share/rh.Yeo_17nets.annot -------------------------------------------------------------------------------- /share/rh.Yeo_7nets.annot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/share/rh.Yeo_7nets.annot -------------------------------------------------------------------------------- /tests/README.MD: -------------------------------------------------------------------------------- 1 | #### Tests 2 | 3 | To run the tests, first run a subject on either your data or with HCP data with the default configuration file> 4 | 5 | Then cd to the script directory, and run 6 | 7 | ```bash 8 | 9 | bash tests/test_pipeline.sh -c path_to_config_file 10 | 11 | ``` 12 | 13 | -------------------------------------------------------------------------------- /tests/__pycache__/test_pipeline.cpython-35-PYTEST.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/tests/__pycache__/test_pipeline.cpython-35-PYTEST.pyc -------------------------------------------------------------------------------- /tests/__pycache__/test_pipeline.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ins-amu/scripts/eab2f88284dcb1aba0e70cedc636fcc4fbb8a6da/tests/__pycache__/test_pipeline.cpython-35.pyc -------------------------------------------------------------------------------- /tests/test_pipeline.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # run with bash tests/test_pipeline -c /path/to/config_file 3 | 4 | # import and check config 5 | while getopts "c:e" opt; do 6 | case $opt in 7 | c) 8 | CONFIG=$OPTARG 9 | if [ ! -f "$CONFIG" -a "$CONFIG" != "test" ];then 10 | echo "Config file "$CONFIG" does not exist." >&2 11 | exit 1 12 | elif [ $CONFIG = "test" ]; then 13 | echo "test mode" 14 | else 15 | echo "Using config file $CONFIG." >&2 16 | source "$CONFIG" 17 | fi 18 | ;; 19 | e) 20 | set -e 21 | ;; 22 | \?) 23 | echo "Invalid option: -$OPTARG" >&2 24 | exit 1 25 | ;; 26 | esac 27 | done 28 | 29 | if [ -z "$CONFIG" ]; then 30 | echo "You must provide a config file." 31 | exit 1 32 | fi 33 | 34 | setUp() { 35 | set +e 36 | mkdir -p "$PRD"/test_"$NAME_TEST" 37 | cp -rn "$PRD"/data "$PRD"/test_"$NAME_TEST"/data 38 | if [ "$HCP" = "yes" ]; then 39 | cp "$PRD"/100307_3T_Diffusion_preproc.zip \ 40 | "$PRD"/100307_3T_Structural_preproc.zip \ 41 | "$PRD"/100307_3T_Structural_preproc_extended.zip "$PRD"/test_"$NAME_TEST" 42 | fi 43 | PRD="$PRD"/test_"$NAME_TEST" 44 | } 45 | 46 | Teardown() { 47 | if [ "$CLEAN_AFTER_TEST" = 1 ]; then 48 | rm -r "$PRD" 49 | fi 50 | } 51 | 52 | 53 | test_function() { 54 | bash ./main_surface.sh -c "test" -e -q -f > /dev/null && out="success" || out="fail" 55 | printf "\n >>> Test "$NAME_TEST" output is : "$out" <<< \n" 56 | } 57 | 58 | # Variables to change from config file: 59 | export TOPUP="no" # to accelerate things a little, eddy takes several hours 60 | export NB_THREADS=2 61 | export CLEAN_AFTER_TEST=0 62 | 63 | ( export NAME_TEST="fsl_5"; export FSL="fsl5.0-"; setUp; test_function ) & 64 | ( export NAME_TEST="registration_boundary"; export REGISTRATION="boundary"; setUp; test_function; Teardown ) & 65 | ( export NAME_TEST="registration_pseudo"; export REGISTRATION="pseudo"; setUp; test_function; Teardown ) & 66 | ( export NAME_TEST="region_mapping_corr"; export REGION_MAPPING_COOR="0.5"; setUp; test_function; Teardown ) & 67 | ( export NAME_TEST="n_subregions_list"; export N_SUBREGIONS_LIST="100 200"; setUp; test_function; Teardown ) & 68 | ( export NAME_TEST="no_subregions_list"; export N_SUBREGIONS_LIST=""; setUp; test_function; Teardown ) & 69 | ( export NAME_TEST="number_tracks"; export NUMBER_TRACKS=10000; setUp; test_function; Teardown ) & 70 | ( export NAME_TEST="parcel_destrieux"; PARCEL="destrieux"; setUp; test_function; Teardown ) & 71 | ( export NAME_TEST="parcel_HCP"; export PARCEL="HCP-MMP"; setUp; test_function; Teardown ) & 72 | ( export NAME_TEST="parcel_Yeo7"; export PARCEL="Yeo-7nets"; setUp; test_function; Teardown) & 73 | ( export NAME_TEST="parcel_Yeo17"; export PARCEL="Yeo-17nets"; setUp; test_function; Teardown ) & 74 | ( export NAME_TEST="no_topup"; export TOPUP="no"; setUp; test_function; Teardown ) & 75 | ( export NAME_TEST="no_act"; export ACT="no"; setUp; test_function; Teardown ) & 76 | ( export NAME_TEST="no_sift"; export SIFT="no"; setUp; test_function; Teardown ) & 77 | ( export NAME_TEST="sift"; export SIFT="sift"; setUp; test_function; Teardown ) & 78 | ( export NAME_TEST="sift_multiplier"; export SIFT="sift"; export SIFT_MULTIPLIER=2; setUp; test_function; Teardown ) & 79 | ( export NAME_TEST="seed_dynamic"; export SEED="dynamic"; setUp; test_function; Teardown ) & 80 | ( export NAME_TEST="aseg_fs"; export ASEG="fs"; setUp; test_function; Teardown ) & 81 | ( export NAME_TEST="5ttgen_fs"; export FTTGEN="fs"; setUp; test_function; Teardown ) & 82 | ( export NAME_TEST="no_mne"; export MNE="no"; setUp; test_function; Teardown ) & 83 | ( export NAME_TEST="nb_threads_2"; export NB_THREADS="3"; setUp; test_function; Teardown ) & 84 | 85 | exit -------------------------------------------------------------------------------- /tests/test_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | setUp() { 4 | source /disk2/Work/Processed_data/brown/scripts/cf-p08/config_cf-p08.sh 5 | set +e 6 | name_dir=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 10) 7 | mkdir -p "$PRD"/test_"$name_dir" 8 | cp -r "$PRD"/data "$PRD"/test_"$name_dir"/data 9 | PRD="$PRD"/test_"$name_dir" 10 | } 11 | 12 | Teardown() { 13 | rm -r "$PRD" 14 | } 15 | 16 | test_test_false() { 17 | false > /dev/null && out="success" || out="fail" 18 | printf "\n >>> Test test_test_false output is : "$out" <<< \n" 19 | } 20 | 21 | test_test_true() { 22 | true > /dev/null && out="success" || out="fail" 23 | printf "\n >>> Test test_test_true output is : "$out" <<< \n" 24 | } 25 | 26 | ( setUp; test_test_false; Teardown ) & 27 | ( setUp; test_test_true ; Teardown ) & 28 | 29 | exit 30 | -------------------------------------------------------------------------------- /util/HCP_pre_scripts.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # check mandatory variables 4 | if [ -z "$PRD" ]; then 5 | echo "PRD path missing" 6 | exit 1 7 | fi 8 | 9 | if [ -z "$SUBJ_ID" ]; then 10 | echo "SUBJ_ID path missing" 11 | exit 1 12 | fi 13 | 14 | # unzip data dowloaded from HCP connectomeDB 15 | unzip "$PRD"/"$SUBJ_ID"_3T_Diffusion_preproc.zip -d "$PRD" 16 | unzip "$PRD"/"$SUBJ_ID"_3T_Structural_preproc.zip -d "$PRD" 17 | unzip "$PRD"/"$SUBJ_ID"_3T_Structural_preproc_extended.zip -d "$PRD" 18 | 19 | ## prepare surface files 20 | mkdir -p "$PRD"/data/T1 "$PRD"/surface 21 | mkdir -p "$FS"/"$SUBJ_ID" 22 | 23 | touch "$PRD"/data/T1/T1.nii.gz 24 | 25 | mv "$PRD"/"$SUBJ_ID"/T1w/"$SUBJ_ID"/* "$FS"/"$SUBJ_ID"/ 26 | 27 | ## prepare connectivity files 28 | 29 | mkdir -p "$PRD"/connectivity 30 | 31 | # TODO: FS files or HCP files? 32 | 33 | cp "$PRD"/"$SUBJ_ID"/T1w/aparc+aseg.nii.gz "$PRD"/connectivity/aparc+aseg.nii.gz 34 | cp "$PRD"/"$SUBJ_ID"/T1w/aparc+aseg.nii.gz "$PRD"/connectivity/aparc+aseg_reorient.nii.gz 35 | cp "$PRD"/"$SUBJ_ID"/T1w/aparc+aseg.nii.gz "$PRD"/connectivity/aparcaseg_2_diff.nii.gz 36 | cp "$PRD"/"$SUBJ_ID"/T1w/T1w_acpc_dc_restore_brain.nii.gz "$PRD"/connectivity/brain.nii.gz 37 | cp "$PRD"/"$SUBJ_ID"/T1w/T1w_acpc_dc_restore_brain.nii.gz "$PRD"/connectivity/brain_2_diff.nii.gz 38 | cp "$PRD"/"$SUBJ_ID"/T1w/Diffusion/bvecs "$PRD"/connectivity/bvecs 39 | cp "$PRD"/"$SUBJ_ID"/T1w/Diffusion/bvals "$PRD"/connectivity/bvals 40 | 41 | # Crop HCP data to avoid RAM issues 42 | gunzip "$PRD"/"$SUBJ_ID"/T1w/Diffusion/data.nii.gz 43 | mrcrop "$PRD"/"$SUBJ_ID"/T1w/Diffusion/data.nii \ 44 | "$PRD"/connectivity/data_crop.nii.gz \ 45 | -mask "$PRD"/"$SUBJ_ID"/T1w/Diffusion/nodif_brain_mask.nii.gz -force 46 | mrcrop "$PRD"/"$SUBJ_ID"/T1w/Diffusion/nodif_brain_mask.nii.gz \ 47 | "$PRD"/connectivity/nodif_brain_mask_crop.nii.gz \ 48 | -mask "$PRD"/"$SUBJ_ID"/T1w/Diffusion/nodif_brain_mask.nii.gz -force 49 | 50 | 51 | mrconvert "$PRD"/connectivity/data_crop.nii.gz \ 52 | "$PRD"/connectivity/predwi.mif \ 53 | -fslgrad "$PRD"/connectivity/bvecs "$PRD"/connectivity/bvals \ 54 | -datatype float32 -force 55 | mrconvert "$PRD"/connectivity/data_crop.nii.gz \ 56 | "$PRD"/connectivity/predwi_denoised.mif \ 57 | -fslgrad "$PRD"/connectivity/bvecs "$PRD"/connectivity/bvals \ 58 | -datatype float32 -force 59 | mrconvert "$PRD"/connectivity/data_crop.nii.gz \ 60 | "$PRD"/connectivity/predwi_denoised_preproc.mif \ 61 | -fslgrad "$PRD"/connectivity/bvecs "$PRD"/connectivity/bvals \ 62 | -datatype float32 -force 63 | mrconvert "$PRD"/connectivity/data_crop.nii.gz \ 64 | "$PRD"/connectivity/predwi_denoised_preproc_bias.mif \ 65 | -fslgrad "$PRD"/connectivity/bvecs "$PRD"/connectivity/bvals \ 66 | -datatype float32 -force 67 | mrconvert "$PRD"/connectivity/data_crop.nii.gz \ 68 | "$PRD"/connectivity/predwi_denoised_preproc_bias.mif \ 69 | -fslgrad "$PRD"/connectivity/bvecs "$PRD"/connectivity/bvals \ 70 | -datatype float32 -force 71 | mrconvert "$PRD"/connectivity/nodif_brain_mask_crop.nii.gz \ 72 | "$PRD"/connectivity/mask_native.mif -datatype float32 \ 73 | -force 74 | 75 | rm -r "$PRD"/"$SUBJ_ID"/ -------------------------------------------------------------------------------- /util/aseg2srf: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Print usage if no argument is given 4 | if [ -z "$1" ]; then 5 | cat < [-l ] [-d] 11 | 12 | Options: 13 | -s : Specify a list of subjects between quotes, 14 | e.g. -s "john bill mary mark" or a text file 15 | containing one subject per line. 16 | -l : Specify a list of labels between quotes, 17 | e.g. "10 11 14 52 253", or a text file 18 | containing one label per line, or ignore 19 | this option to convert all labels. 20 | -d Debug mode. Leave all temporary files. 21 | 22 | Requirements: 23 | FreeSurfer must have been configured and the variables 24 | FREESURFER_HOME and SUBJECTS_DIR must have been correctly set. 25 | 26 | _____________________________________ 27 | Anderson M. Winkler 28 | Institute of Living / Yale University 29 | Jul/2009 30 | http://brainder.org 31 | EOU 32 | exit 33 | fi 34 | 35 | # List of labels to be converted if no list is specified 36 | LABLIST="4 5 7 8 10 11 12 13 14 15 16 17 18 26 28 43 44 46 47 49 50 51 52 53 54 58 60 251 252 253 254 255" 37 | 38 | # Check and accept arguments 39 | SBJLIST="" 40 | DEBUG=N 41 | while getopts 's:l:d' OPTION 42 | do 43 | case ${OPTION} in 44 | s) SBJLIST=$( [[ -f ${OPTARG} ]] && cat ${OPTARG} || echo "${OPTARG}" ) ;; 45 | l) LABLIST=$( [[ -f ${OPTARG} ]] && cat ${OPTARG} || echo "${OPTARG}" ) ;; 46 | d) DEBUG=Y ;; 47 | esac 48 | done 49 | 50 | # Prepare a random string to save temporary files 51 | #if hash md5 2> /dev/null ; then 52 | # RND0=$(head -n 1 /dev/random | md5) 53 | #elif hash md5sum 2> /dev/null ; then 54 | # RND0=$(head -n 1 /dev/random | md5sum) 55 | #fi 56 | #RNDSTR=${RND0:0:12} 57 | RNDSTR=${RANDOM:0:12} 58 | 59 | # Define a function for Ctrl+C as soon as the RNDSTR is defined 60 | trap bashtrap INT 61 | bashtrap() 62 | { 63 | break ; break 64 | [[ "${s}" != "" ]] && rm -rf ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR} # try to delete temp files 65 | exit 1 66 | } 67 | 68 | # For each subject 69 | for s in ${SBJLIST} ; do 70 | 71 | # Create directories for temp files and results 72 | mkdir -p ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR} 73 | mkdir -p ${SUBJECTS_DIR}/${s}/ascii 74 | 75 | # For each label 76 | for lab in ${LABLIST} ; do 77 | 78 | # Label string 79 | lab0=$(printf %03d ${lab}) 80 | 81 | # Pre-tessellate 82 | echo "==> Pre-tessellating: ${s}, ${lab0}" 83 | ${FREESURFER_HOME}/bin/mri_pretess \ 84 | ${SUBJECTS_DIR}/${s}/mri/aseg.mgz ${lab} \ 85 | ${SUBJECTS_DIR}/${s}/mri/norm.mgz \ 86 | ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}_filled.mgz >/dev/null 2>/dev/null 87 | 88 | # Tessellate 89 | echo "==> Tessellating: ${s}, ${lab0}" 90 | ${FREESURFER_HOME}/bin/mri_tessellate \ 91 | ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}_filled.mgz \ 92 | ${lab} ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}_notsmooth >/dev/null 2>/dev/null 93 | 94 | # Smooth 95 | echo "==> Smoothing: ${s}, ${lab0}" 96 | ${FREESURFER_HOME}/bin/mris_smooth -nw \ 97 | ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}_notsmooth \ 98 | ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0} >/dev/null 2>/dev/null 99 | 100 | # Convert to ASCII 101 | echo "==> Converting to ASCII: ${s}, ${lab0}" 102 | ${FREESURFER_HOME}/bin/mris_convert \ 103 | ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0} \ 104 | ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}.asc >/dev/null 2>/dev/null 105 | mv ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}/aseg_${lab0}.asc \ 106 | ${SUBJECTS_DIR}/${s}/ascii/aseg_${lab0}.srf 107 | done 108 | 109 | # Get rid of temp files 110 | if [ "${DEBUG}" == "Y" ] ; then 111 | echo "==> Temporary files for ${s} saved at:" 112 | echo "${SUBJECTS_DIR}/${s}/tmp/${RNDSTR}" 113 | else 114 | echo "==> Removing temporary files for ${s}" 115 | rm -rf ${SUBJECTS_DIR}/${s}/tmp/${RNDSTR} 116 | fi 117 | echo "==> Done: ${s}" 118 | done 119 | exit 0 120 | -------------------------------------------------------------------------------- /util/compute_connectivity_sub.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import sys 3 | 4 | # save connectivity and tract length matrices 5 | weights = np.loadtxt(sys.argv[1]) 6 | tract_lengths = np.loadtxt(sys.argv[2]) 7 | weights = weights + weights.transpose() - np.diag(np.diag(weights)) # to avoid twice diag 8 | tract_lengths = tract_lengths + tract_lengths.transpose() # because diagonal nul 9 | np.savetxt(sys.argv[3], weights, fmt='%d') 10 | np.savetxt(sys.argv[4], tract_lengths, fmt='%.3f') 11 | 12 | 13 | -------------------------------------------------------------------------------- /util/compute_luts.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | 4 | """compute lut_in and lut_out for labelconvert from reference_table """ 5 | 6 | PRD = os.environ['PRD'] 7 | PARCEL = os.environ['PARCEL'] 8 | 9 | lut_in_names = np.loadtxt(open(os.path.join('share', 'reference_table_' + PARCEL + ".csv"), "r"), delimiter=",", skiprows=1, usecols=(1,), dtype='str') 10 | lut_in_vals = np.loadtxt(open(os.path.join('share', 'reference_table_' + PARCEL + ".csv"), "r"), delimiter=",", skiprows=1, usecols=(0, 2, 3, 4, 8), dtype='int') 11 | 12 | f = open(os.path.join(PRD, 'connectivity/lut_in.txt'), 'w') 13 | for i, row in enumerate(lut_in_vals): 14 | f.write(str(row[0]) + ' ') 15 | f.write(lut_in_names[i]+' ') 16 | for j in range(1,5): 17 | f.write(str(row[j]) + ' ') 18 | f.write('\n') 19 | f.close() 20 | 21 | 22 | 23 | lut_out_names = np.loadtxt(open(os.path.join('share', 'reference_table_' + PARCEL + ".csv"), "r"), delimiter=",", skiprows=1, usecols=(1,), dtype='str') 24 | lut_out_vals = np.loadtxt(open(os.path.join('share', 'reference_table_' + PARCEL + ".csv"), "r"), delimiter=",", skiprows=1, usecols=(5, 2, 3, 4, 8), dtype='int') 25 | 26 | f = open(os.path.join(PRD, 'connectivity/lut_out.txt'), 'w') 27 | for i, row in enumerate(lut_out_vals): 28 | f.write(str(row[0]) + ' ') 29 | f.write(lut_out_names[i]+' ') 30 | for j in range(1,5): 31 | f.write(str(row[j]) + ' ') 32 | f.write('\n') 33 | f.close() 34 | 35 | #lut_out = np.loadtxt(open(os.path.join('share', 'reference_table_' + PARCEL + ".csv"), "r"), delimiter=",", skiprows=1, usecols=(0, 5), dtype='int') 36 | #np.savetxt(os.path.join(PRD, 'connectivity', 'lut_out.txt'), lut_out, fmt='%d %d') 37 | -------------------------------------------------------------------------------- /util/correct_region_mapping.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | from copy import deepcopy 4 | from collections import Counter 5 | import numpy as np 6 | 7 | rl = sys.argv[1] 8 | PRD = os.environ['PRD'] 9 | region_mapping_corr = float(os.environ['REGION_MAPPING_CORR']) 10 | os.chdir(os.path.join(PRD, 'surface')) 11 | 12 | 13 | texture = np.loadtxt(rl + '_region_mapping_low_not_corrected.txt') 14 | vert = np.loadtxt(rl + '_vertices_low.txt') 15 | trian = np.loadtxt(rl + '_triangles_low.txt') 16 | for _ in range(10): 17 | new_texture = deepcopy(texture) 18 | labels = np.unique(texture) 19 | for ilab in labels: 20 | iverts = (np.nonzero(texture==ilab)[0]).tolist() 21 | if len(iverts)>0: 22 | for inode in iverts: 23 | iall = trian[np.nonzero(trian==inode)[0]].flatten().tolist() 24 | #import pdb; pdb.set_trace() 25 | ineig = np.unique(list(filter(lambda x: x!=inode, iall))).astype('int') 26 | ivals = np.array(Counter(texture[ineig]).most_common()).astype('int') 27 | if ivals[np.nonzero(ivals[:,0]==ilab), 1].shape[1]==0: 28 | new_texture[inode] = Counter(texture[ineig]).most_common(1)[0][0] 29 | elif ivals[np.nonzero(ivals[:,0] == ilab), 1][0,0] < region_mapping_corr * len(ineig): 30 | new_texture[inode] = Counter(texture[ineig]).most_common(1)[0][0] 31 | texture = deepcopy(new_texture) 32 | 33 | np.savetxt(rl + '_region_mapping_low.txt', new_texture) 34 | -------------------------------------------------------------------------------- /util/extract_bem.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import os 3 | import sys 4 | 5 | name_file = sys.argv[1] 6 | PRD = os.environ['PRD'] 7 | FS = os.environ['FS'] 8 | SUBJ_ID = os.environ['SUBJ_ID'] 9 | os.chdir(os.path.join(PRD, 'surface')) 10 | 11 | with open(os.path.join(FS, SUBJ_ID, 'bem', name_file + '.asc'), 'r') as f: 12 | f.readline() 13 | nb_vert = f.readline().split(' ')[0] 14 | read_data = [[np.double(line.rstrip('\n').split()[0]), 15 | np.double(line.rstrip('\n').split()[1]), 16 | np.double(line.rstrip('\n').split()[2])] for line in f] 17 | 18 | a = np.array(read_data) 19 | vert = a[0:int(nb_vert), 0:3] 20 | np.savetxt(os.path.join(PRD, SUBJ_ID, 'surface', name_file +'_vertices.txt'), vert, fmt='%.6f %.6f %.6f') 21 | tri = a[int(nb_vert):, 0:3] 22 | np.savetxt(os.path.join(PRD, SUBJ_ID, 'surface', name_file +'_triangles.txt'), tri, fmt='%d %d %d') 23 | -------------------------------------------------------------------------------- /util/extract_high.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import os 3 | import sys 4 | 5 | rl = sys.argv[1] 6 | PRD = os.environ['PRD'] 7 | os.chdir(os.path.join(PRD, 'surface')) 8 | 9 | # read lh_info 10 | with open(rl + 'info.txt', 'r') as f: 11 | lines = f.readlines() 12 | 13 | c_ras_line = lines[32] 14 | ista = c_ras_line.index(' (') + 2 15 | iend = c_ras_line.index(')\n') 16 | lc_ras = c_ras_line[ista:iend].split(',') 17 | c_ras = np.array(lc_ras).astype('float') 18 | 19 | with open(rl + '.pial.asc', 'r') as f: 20 | f.readline() 21 | nb_vert = f.readline().split(' ')[0] 22 | read_data = [[np.double(line.rstrip('\n').split()[0]), 23 | np.double(line.rstrip('\n').split()[1]), 24 | np.double(line.rstrip('\n').split()[2])] for line in f] 25 | 26 | a = np.array(read_data) 27 | vert_high = a[0:int(nb_vert), 0:3] + c_ras 28 | np.savetxt(rl + '_vertices_high.txt', vert_high, fmt='%.6f %.6f %.6f') 29 | tri_high = a[int(nb_vert):, 0:3] 30 | np.savetxt(rl +'_triangles_high.txt', tri_high, fmt='%d %d %d') 31 | -------------------------------------------------------------------------------- /util/list_subcortical.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import os 3 | 4 | PRD = os.environ['PRD'] 5 | os.chdir(os.path.join(PRD, 'surface', 'subcortical')) 6 | 7 | for val in ['16','08','10','11','12','13','17','18','26','47','49','50','51','52','53','54','58']: 8 | val 9 | f = open('aseg_0'+val+'.srf', 'r') 10 | f.readline() 11 | data = f.readline() 12 | g = data.split(' ') 13 | nb_vert = int(g[0]) 14 | nb_tri = int(g[1].split('\n')[0]) 15 | f.close() 16 | a = np.loadtxt('aseg_0'+str(val)+'.srf', skiprows=2, usecols=(0,1,2)) 17 | vert = a[:nb_vert] 18 | tri = a[nb_vert:].astype('int') 19 | np.savetxt('aseg_0'+str(val)+'_vert.txt', vert) 20 | np.savetxt('aseg_0'+str(val)+'_tri.txt', tri) 21 | -------------------------------------------------------------------------------- /util/off2txt.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import sys 3 | 4 | name_file = sys.argv[1] 5 | 6 | with open(name_file) as f: 7 | f.readline() 8 | num = f.readline().split(' ') 9 | 10 | vert = np.loadtxt(name_file, skiprows=2, usecols=(0,1,2)) 11 | vert = vert[:int(num[0]), :] 12 | tri = np.loadtxt(name_file, skiprows=int(num[0])+2, usecols=(1,2,3)) 13 | 14 | np.savetxt(sys.argv[2], vert, fmt='%.4f') 15 | np.savetxt(sys.argv[3], tri, fmt='%d') 16 | 17 | -------------------------------------------------------------------------------- /util/reunify_both_regions.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | 4 | PRD = os.environ['PRD'] 5 | SUBJ_ID = os.environ['SUBJ_ID'] 6 | os.chdir(os.path.join(PRD, 'surface')) 7 | 8 | lh_reg_map = np.loadtxt('lh_region_mapping_low.txt') 9 | lh_vert = np.loadtxt('lh_vertices_low.txt') 10 | lh_trian = np.loadtxt('lh_triangles_low.txt') 11 | rh_reg_map = np.loadtxt('rh_region_mapping_low.txt') 12 | rh_vert = np.loadtxt('rh_vertices_low.txt') 13 | rh_trian = np.loadtxt('rh_triangles_low.txt') 14 | vertices = np.vstack([lh_vert, rh_vert]) 15 | triangles = np.vstack([lh_trian, rh_trian + lh_vert.shape[0]]) 16 | region_mapping = np.hstack([lh_reg_map, rh_reg_map]) 17 | np.savetxt(PRD+'/'+SUBJ_ID+'/surface/region_mapping.txt', region_mapping, fmt='%d', newline=" ") 18 | np.savetxt(PRD+'/'+SUBJ_ID+'/surface/vertices.txt', vertices, fmt='%.2f') 19 | np.savetxt(PRD+'/'+SUBJ_ID+'/surface/triangles.txt', triangles, fmt='%d %d %d') 20 | -------------------------------------------------------------------------------- /util/txt2off.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import numpy as np 3 | 4 | vert = np.loadtxt(sys.argv[1]) 5 | tri = np.loadtxt(sys.argv[2]) 6 | 7 | with open(sys.argv[3], 'w') as f: 8 | f.write('OFF\n') 9 | f.write('{} {} {}\n'.format(int(vert.shape[0]), int(tri.shape[0]), 0)) 10 | 11 | with open(sys.argv[3], 'ab') as f: 12 | np.savetxt(f, vert, fmt='%.6f') 13 | np.savetxt(f, np.hstack([np.ones((tri.shape[0],1))*3, tri]), fmt='%d') 14 | 15 | --------------------------------------------------------------------------------