Learn R Programming

habtools

A collection of functions for sampling and simulating 3D surfaces and objects and estimating metrics like rugosity, fractal dimension, convexity, sphericity, circularity, second moments of area and volume, and more.

Installation

The best way to install habtools is through cran.

install.packages("habtools")

You can also install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("jmadinlab/habtools")

Examples

There are vignettes demonstrating the use of habtools for digital elevation models (DEMs) and 3D meshes, as well as a vignette covering fractal dimension methods.

There are currently two data sets accompanying this package. horseshoe is a DEM of a coral reef in RasterLayer format, and mcap is a 3D mesh of a coral growing on a reef in mesh3d format.

The following example calculates height range, rugosity and fractal dimension of a 2 x 2 m plot of horseshoe.

library(habtools)
library(raster)

# Let's take a subset DEM of size = 2
dem <- dem_crop(horseshoe, x0 = -465, y0 = 1265, L = 2, plot = TRUE)

# height range
hr(dem)
#> [1] 1.368289

# rugosity
rg(dem, L0 = 0.0625)
#> [1] 1.75829

# fractal dimension
fd(dem, method = "hvar", keep_data = TRUE, plot=TRUE, diagnose = TRUE)

#> $D
#> [1] 2.159332
#> 
#> $data
#>        l          h
#> 1 0.0625 0.07207143
#> 2 0.1250 0.16465515
#> 3 0.2500 0.31394699
#> 4 0.5000 0.58224221
#> 5 1.0000 0.88901201
#> 6 2.0000 1.36828852
#> 
#> $lvec
#> [1] 0.0625 0.1250 0.2500 0.5000 1.0000 2.0000
#> 
#> $D_vec
#> [1] 1.808052 2.068927 2.108902 2.389417 2.377902
#> 
#> $var
#> [1] 0.2420993
#> 
#> $method
#> [1] "hvar"

The next example calculates height range, rugosity and fractal dimension for the coral colony mcap. Because 3D meshes can have more than one z coordinate for a given xy (i.e., they have overhangs), we use cube counting for fractal dimension.

library(rgl)
options(rgl.printRglwidget = TRUE)
plot3d(mcap)
# height range
hr(mcap)
#> [1] 0.2185397

# rugosity
rg(mcap, L0 = 0.045)
#> [1] 2.882813

# fractal dimension
fd(mcap, method = "cubes", keep_data = TRUE, plot=TRUE, diagnose = TRUE)
#> lvec is set to c(0.053, 0.106, 0.212, 0.423).

#> $D
#> [1] 2.315246
#> 
#> $data
#>            l   n
#> 4 0.05291204 134
#> 3 0.10582408  31
#> 2 0.21164817   8
#> 1 0.42329634   1
#> 
#> $lvec
#> [1] 0.42329634 0.21164817 0.10582408 0.05291204
#> 
#> $D_vec
#> [1] 2.111893 1.954196 3.000000
#> 
#> $var
#> [1] 0.5638126
#> 
#> $method
#> [1] "cubes"

Copy Link

Version

Install

install.packages('habtools')

Monthly Downloads

380

Version

1.1.1

License

MIT + file LICENSE

Maintainer

Nina Schiettekatte

Last Published

March 6th, 2025

Functions in habtools (1.1.1)

fd_hvar

Calculate fractal Dimension using the height variation method
fd_area

Calculate fractal dimension using the surface area method
fd

Calculate fractal dimension
hr

Calculate height range
horseshoe

Horseshoe reef
entropy_1d

1D Entropy
fd_boxes

Calculate fractal dimension using the box counting method
mesh_to_dem

Transform 3D mesh to DEM
mcap

Montipora capitata
hvar

Calculate height variation in cells at different scales
scale_volume

Re-scale mesh based on a fixed volume of 1
perimeter

Calculate perimeter of a 2D shape
set_origin

Set the origin of a mesh
%>%

Pipe operator
fd_cubes

Calculate fractal dimension using the cube counting method
fd_diagnose

Diagnose fractal dimension
svol_triangle

Calculate signed volume of triangle
mesh_to_points

Transform mesh to 3D point cloud
sphericity

Calculate sphericity of a 3D object
surface_area

Calculate surface area
scale_area

Re-scale mesh based on a fixed area
sa_triangle

Calculate surface area of triangle
z

Extract mean depth or elevation of a DEM
mcap2

Montipora capitata 2
mesh_to_2d

Transform 3D mesh into 2D outline
planar

Calculates planar area of a mesh
rdh_theory

Calculate metric based on geometric plane equation
rdh

Calculate rugosity, fractal dimension, and height for a DEM
mid_find

Find midpoint of a DEM
fd_sd

Calculate fractal Dimension using the standard deviation method
packing

Calculate packing of 3D object
sim_circle

Simulate a circle
sim_dem

Simulates a fractal DEM
rg

Calculate rugosity
smv

Calculate second moment of volume
sma

Calculate second moment of area
cell_count_3d

Count filled cells 3D
dem_crop

Crop DEM around points
csf

Calculate mechanical shape factor
cell_count_1d

Count filled cells in 1D
dem_sample

Sample a random DEM with specified size from a larger DEM
dem_split

Split DEM into smaller tiles
convexity

Calculate convexity of a 3D mesh
centroid

Calculate the centroid of 3D points
cell_count_2d

Count filled cells in 2D
circularity

Calculate circularity of a 2D shape
entropy

Entropy
entropy_2d

2D Entropy
entropy_3d

3D entropy
detect_drop

Detect a sudden drop, edge, or overhang in a DEM
dem_to_points

Transform DEM to 3D pointcloud of raster corners
extent

Calculate extent of a 3D object