Package: meshlib
Welcome to the MeshLib!3D scanning is becoming more and more ubiquitous. Robotic automation, self-driving cars and multitude of other industrial, medical and scientific applications require advanced computer vision to deliver the levels of automation customers expect these days. The great rise of AI gave another boost to computer vision and the need to utilize 3D data to make machines smarter. Not only are tasks at hand becoming more complex, but the size of data grows exponentially.There is a multitude of general purpose libraries which deal with 3D data. Some stem from popular CAD packages, some are open source. The commercial ones tend to be quite expensive while open source are free though tend to be limited in functionality provided. Also those libraries value generality above other features  to allow maximum number of applications, but with the growing amounts of 3D data, performance is critical as it never has  been. Some of it can be addressed by using the scale of a commercial cloud, last generation CPU or GPU but underlying complexity of data representation makes it very hard and laborsome.The goal which we set when designing MeshLib was to value simplicity and performance while providing a wide gamut of useful computational algorithms. The library also supports the most important data structures today’s sensors can produce - pointcloud, mesh, volume and more. For example, mesh is represented by half-edge data structure and cannot be made non-manifold. Some applications may require non-manifoldness, but most practical scans can be represented as manifoldness meshes without an issue.Some useful linksMeshInspectoris a free application based on MeshLibMeshInspector online web-browser version(simple email sign-in is required)MeshInspector web-siteComparison of MeshLib vs VTK libraryMeshInspector YouTube channelMeshLib DocumentationEmail usSubmit an issueMajor featuresThis list is not full and updating each dayMath basicsMath primitives and operations support (Vectors 2D, 3D, 4D; Lines; Planes; Bounding Boxes; Matrices; Affine transformations; Quaternions; Histograms; etc.)3D data handling, creation, modification3D data various representations support: Mesh, Voxel and Point Cloud.Data creationMesh creation by given vertices and triangles,Surface primitives (e.g. tor, cube, sphere, etc).Representation conversionsTriangulation of a Point Cloud to Mesh,Mesh to Cloud Point conversion,Mesh to Voxel conversion,Voxel To Mesh conversion.DeformationsLaplassian deformation,Freeform deformation,Relax, mesh smoothing,Position Verts Smoothly, arrangement of vertices in accordance with the gradient along the neighbors.OffsetsMesh offset,Mesh partial offset.ResolutionBreaking a mesh into smaller triangles (increasing the resolution)Mesh decimation (decreasing the number of triangles, decreasing the resolution) with a specified error relative to the old mesh.Cutting a contour on a surface. The mesh is modified so that the resulting contour contains new edges cut through triangles at the specified points.SplittingSplitting mesh into sub-meshes (components)3D data operationsBoolean operations (union, intersection, difference) on 3D objects bounded by meshes. MeshLib has two independent modes:Boolean ops on meshes via intermediate conversion into voxel representation. This mode requires closed meshes without holes on input and much memory for high accuracy but tolerate for various input mesh degenerations and self-intersections.Direct Boolean ops on meshes using robust predicates, producing exact accurate result and keeping original mesh elements as is if they are not intersected. This mode supports for open meshes with holes as long as the boundary of the mesh is not intersected.According to our user reports, MeshLib direct Boolean operations are significatly faster even compared to the latest published approaches, e.g.Interactive and Robust Mesh BooleansConstruction of Convex Hull of a point cloud or a mesh.3D Data problems fixingFixing holes in meshHoles stitching (removing two holes by stitching their boundaries)Hole filling,Holes fixing metricsBasic set of triangulation metrics,Extended set of triangulation metrics,Custom triangulation metrics.Delaunay triangulation optimization, changing triangles without changing vertices, according to Delaunay criterion,Tunnels fixing,Multiple edges detectionDegenerate triangles fixing,Undercuts fixing, via voxels,Surface self-intersections fixingGuaranteed fix via voxels,Fix via Relax (mesh smoothing).Functions on 3D dataBVH hierarchies (AABB trees) for meshes and polylines to accelerate all other operationsProjectionProjecting a point onto a mesh - closest point queriesIntersectionIntersection of a ray with a mesh (ray tracing),Intersection of a plane with a mesh, result is a contour,Finding a contour representing intersection of two meshes, meshes remain unchanged,DistanceDistance from a point to a mesh,Minimal distance between two meshes,Mesh distance map (height map),2D contour distance map.SegmentationSemi-auto voxel segmentation (volumes classification).Semi-auto mesh segmentation by curvature.SamplingMesh sampling. The result is a separate thinned set of vertices, the mesh remains unchanged.Point cloud sampling. The result is a separate thinned set of points, the cloud remains unchangedUniform cloud sampling,Grid cloud sampling.PathFinding a shortest path through the mesh vertices,Finding a geodesic shortest path on the surface, not necessarily through mesh vertices.Iterative Closest Points (ICP), two meshes aligningPoint to point,Point to plane.Upcoming featuresWe plan to add computed-tomography reconstruction in MeshLib (already present in MeshInspector). Please write us if you like to see some other features.Python integrationAlthough MeshLib is written in C++, all functions are exposed to Python as well. Python code can be executed both from within a MeshLib-based C++ application (embedded mode) and from python interpreter directly, which imports MeshLib modules.Moreover, MeshLib can be easily installed as a Python 3.8 - 3.12 package usingpip install:On Windows viapy -3 -m pip install --upgrade pip
py -3 -m pip install meshlibOn Linuxes supportingmanylinux_2_31+, including Ubuntu 20+ and Fedora 32+ viasudo apt install python3-pip
python3 -m pip install --upgrade pip
python3 -m pip install meshlibOn macOS 12.0+ viapip install --upgrade pip
pip install meshlibSee Python Basic Exampleshereor search for more complex ones onstackoverflow.com.BuildWindowsMeshLib can be build on Windows using either Visual Studio 2019 or Visual Studio 2022, both of which support c++20 language standard.gitclonehttps://github.com/MeshInspector/MeshLib.gitcdMeshLib
gitsubmoduleupdate--init--recursivecd..Note: following below steps will take about 40Gb of your disk space.Preparing Third PartiesSome third parties are taken from vcpkg, while others (missing in vcpkg) are configured as git submodules.CUDAWindows version of MeshLib is configured to useCUDA v11.4 in Visual Studio 2019 andCUDA v12.0 in Visual Studio 2022.Please install CUDA from theofficial site.
If you would like to use another version of CUDA, please modifyMRCudaVersioninMeshLib/source/platform.props.VcpkgPlease installvcpkg, and integrate it into Visual Studio (note that vcpkg requires English language pack in Visual Studio, and vcpkg cannot be installed on FAT volumes, only on NTFS):gitclonehttps://github.com/Microsoft/vcpkg.gitcdvcpkg
gitcheckout2024.01.12
.\bootstrap-vcpkg.bat
.\vcpkgintegrateinstall(withadminrights)More details here:vcpkg.(Optional, but recommended) InstallAWS CLI v2. Once installed, reopen PowerShell or CMD. This will allow you to use the vcpkg binary cache from our aws s3, which will speed up the installation process and reduce the required disk space.ExecuteMeshLib/thirdparty/install.bathaving previously installedvcpkgas the current working directory (or simply addvcpkgtoPATHenvironment variable).Open solution fileMeshLib/source/MeshLib.slnin Visual Studio. Build it and run.LinuxThis installation was checked on Ubuntu 20.04.4.Use automated installation process. It takes ~40 minutes if no required packages are already installed.
This approach is useful for new MR developersInstall/Build dependencies. Build project. Run Test ApplicationRun the following in terminal:gitclonehttps://github.com/MeshInspector/MeshLib.gitcdMeshLib
sudo./scripts/build_thirdparty.sh# need sudo to check and install dependencies./scripts/install_thirdparty.sh
./scripts/build_sources.sh
./scripts/distribution.sh
sudoaptinstall./distr/meshlib-dev.debNOTE:./scripts/install*.shscripts could be used as well, but apt install is preferable.NOTE:./scripts/install*.shscripts copy MR files directly to/usr/local/lib. Remove this directory manually if exists before apt install deb package.NOTE:You could specify build type to Debug byexport MESHLIB_BUILD_TYPE=Debug. Release is default.WASM/EmscriptenThis installation was checked on Ubuntu 22.04 with Emscripten 3.1.48.Install Emscripten (find more onEmscripten official page)git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
git pull origin # optional
./emsdk install 3.1.48 # (or another version / latest)
./emsdk activate 3.1.48
source ./emsdk_env.shBuildcd ~/MeshLib
./scripts/build_thirdparty.sh # select Emscripten in the corresponding question
./scripts/build_sorces.sh # select Emscripten in the corresponding questionRunpython3 -m http.server 8000 # note that server should have specific COEP and COOP policies for multithread version
# open in browser 127.0.0.1:8000IntegrationLinux Ubuntu/FedoraYou can downloaddev packageand install it with your Linux OS package manager.
Examples of integration with cmake can be found in the./examplesdirectory.MacOSSame as for Linux, but requires brew packages to be installed:xargs brew install < /Library/Frameworks/MeshLib.framework/Versions/Current/scripts/macos.txtWindowsThere are two general options of integrating MeshLib into your project:SubmoduleDistributionCommon for both options:install thirdpartySubmoduleYou can have MeshLib as submodule in your repository, and inculde all MeshLib's projects to your solution.NOTE:You should useMeshLib/source/common.propsin other projects of your solution.NOTE:You can customize props by definingCustomMRProps.propsin directory abovecommon.propsDistributionYou can downloaddistributionand integrate it in your projects.Project settings:C/C++ -> General -> Additional Include Directoriesadddistribution\install\include;Linker -> General -> Additional Library Directoriesadddistribution\install\app\$(Configuration);Linker -> Input -> Additional Dependenciesadddistribution\install\lib\$(Configuration)\*.lib;Debug:C/C++ -> Preprocessor -> Preprocessor Defenitionsadd_ITERATOR_DEBUG_LEVEL=0;vcpkg -> Tripletsetx64-windows-meshlibMake sure you copy all dlls fromdistribution\install\app\$(Configuration);to your$(TargetDir)NOTE:MeshLib distribution has x64 build onlyNOTE:Distribution is build with ITERATOR_DEBUG_LEVEL=0 in debug so you will need to setup this for your projects