Skip to content

athrva98/SDFConverter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SDF Converter

A high-performance C++ library for converting between triangle meshes and Signed Distance Fields (SDFs) using adaptive octree-based sampling and parallel processing.

Overview

The SDF Converter provides efficient tools for:

  • Converting triangle meshes (STL files) to Signed Distance Fields
  • Converting SDFs back to triangle meshes
  • Adaptive sampling using octree spatial subdivision
  • Parallel processing with OpenMP
  • Mesh smoothing and optimization
  • Boundary preservation for surface meshes

Dependencies

  • Eigen (Linear algebra)
  • VTK (Visualization Toolkit)
  • OpenVDB
  • TBB (Threading Building Blocks)
  • nanoflann (Fast KD-tree implementation)
  • OpenMP (Parallel processing)
  • HWLOC (Optional - Hardware locality)
  • vcpkg (Package manager)

Building

Prerequisites

  1. Install vcpkg
  2. Set up vcpkg:
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat  # Windows
./bootstrap-vcpkg.sh   # Linux/macOS
  1. Install required packages via vcpkg:
vcpkg install vtk:x64-windows          # Windows
vcpkg install openvdb:x64-windows
vcpkg install eigen3:x64-windows
vcpkg install tbb:x64-windows

Build Process

mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=[path_to_vcpkg]/scripts/buildsystems/vcpkg.cmake ..
cmake --build .

For Windows users, the default vcpkg path is typically:

cmake -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake ..

Usage

Command Line Interface

./sdf_converter <input_stl> <output_stl> [options]

Options

  • --upsample-factor <n>: Grid upsampling factor (default: 1)
  • --min-voxel-size <n>: Minimum voxel size (default: 0.051)
  • --max-voxel-size <n>: Maximum voxel size (default: 4.50)
  • --adaptivity-factor <n>: Controls grid refinement (default: 0.8)
  • --num-threads <n>: Number of parallel threads (default: 10)
  • --max-depth <n>: Maximum octree depth (default: 18)
  • --surface-band <n>: Surface influence range (default: 2.0)

Code Example

#include "SDFConverter.h"

// Initialize converter with custom parameters
sdf::SDFConverter::Parameters params;
params.minVoxelSize = 0.05;
params.maxVoxelSize = 4.5;
params.adaptivityFactor = 0.8;
params.numThreads = 10;

sdf::SDFConverter converter(params);

// Convert mesh to SDF
auto sdfImage = converter.polyDataToSDF(inputMesh);

// Convert SDF back to mesh
auto outputMesh = converter.sdfToPolyData(sdfImage);

Advanced Features

Adaptive Sampling

The converter uses an octree-based adaptive sampling system that:

  • Concentrates samples near surface features
  • Reduces sample density in smooth regions
  • Maintains smooth transitions between different resolution levels
  • Automatically adjusts to local geometric complexity

Distance Computation

Signed distances are computed using:

  • Fast KD-tree nearest neighbor searches
  • Weighted normal-based sign determination
  • Smooth distance field interpolation
  • Thread-safe distance caching

Mesh Processing

The output mesh generation includes:

  • Marching Cubes implementation
  • Advanced smoothing filters
  • Normal computation and optimization
  • Boundary preservation
  • Connected component analysis

Performance Considerations

  • Use appropriate min-voxel-size and max-voxel-size for your geometry
  • Adjust adaptivity-factor to balance accuracy and performance
  • Set num-threads based on available CPU cores
  • Consider enabling distance caching for repeated conversions
  • Monitor memory usage with large meshes or small voxel sizes

Limitations

  • Large meshes may require significant memory
  • Very small features might not be captured at default resolution
  • Surface offset feature is experimental and may cause instability
  • Boundary preservation only works with surface meshes

Contributing

Contributions are welcome! But it's better to fork this and do your own thing. This project is not aimed at being production ready, but if you think that this may be useful for your application, feel free to use the code.

License

See the LICENSE file in the repo. tl;dr; use however you see fit, the code is provided under the MIT License, which is extremely permissive and allows for commercial use, modification, and redistribution.

Acknowledgments

  • VTK for visualization and mesh processing functionality
  • nanoflann for efficient KD-tree implementation
  • Eigen for linear algebra operations
  • TBB for concurrent memory allocation
  • OpenMP for parallel processing support

About

An efficient parallel C++ library for computing signed distance fields (SDF) from surface meshes. Features adaptive octree-based computation, optimized distance field generation, and robust surface reconstruction using the marching cubes algorithm. Built with VTK and OpenMP for high performance on multi-core systems.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors