Skip to content

Commit

Permalink
Rework export_mesh() function (issue #17)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanmorales committed Jan 27, 2025
1 parent b4f3ccd commit cfe678d
Show file tree
Hide file tree
Showing 15 changed files with 870 additions and 358 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
export(box_dimension)
export(cluster_cloud)
export(correct_radii)
export(export_blender)
export(export_mat)
export(export_mesh)
export(import_leaves)
Expand Down
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## New Features

- `import_leaves()`: a new function to import leaves from [QSM-FaNNI](https://github.com/InverseTampere/qsm-fanni-matlab). The leaves are stored as an `rgl` `mesh3d()` object.
- `export_blender()`: a new function to export a QSM to [Blender](https://www.blender.org/) using the [QSM Blender Addons](https://github.com/InverseTampere/qsm-blender-addons) format.
- `export_mesh()`: The function now supports multiple 3d mesh formats including, `.ply`, `.obj` and `.stl`. It also supports exporting a QSM to [Blender](https://www.blender.org/) using the [QSM Blender Addons](https://github.com/InverseTampere/qsm-blender-addons) format `.txt`.
- New database called `twigs_index`. This is based on qualitative size classes supported by the literature, making it easier to select a twig radius for tree species without twig measurements. More info can be found in the `Twigs` vignette.
- `plot_qsm()`:
- Leaf meshes from `import_leaves()` or `aRchi::add_leaves()` can now be plotted with the `leaves` parameter. Leaf color and transparency can be controlled with `lf_color` and `lf_alpha` respectively.
Expand All @@ -21,7 +21,9 @@

## Improvements

- Function names now use British English to be consistent with R standards. American spelling will still work interchangeably (e.g. `standardize_qsm()` vs `standardise_qsm()`.
- `export_mesh()`: The function was entirely reworked using `Rcpp` for fast and efficient mesh export. All functionality that was dependent on `rgl` has been implemented in custom C++ functions.

- unction names now use British English to be consistent with R standards. American spelling will still work interchangeably (e.g. `standardize_qsm()` vs `standardise_qsm()`.

- Some functions have been renamed to follow tidy guidelines and have consistency within rTwig and other R packages (e.g. `qsm_summary()` -\> `summarise_qsm()`).

Expand Down
72 changes: 70 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,76 @@ which_rcpp <- function(condition) {
.Call(`_rTwig_which_rcpp`, condition)
}

read_obj_cpp <- function(file_path) {
.Call(`_rTwig_read_obj_cpp`, file_path)
#' @title Calculate Normals
#'
#' @description Calculate normals per cylinder vertex
#'
#' @param vertices NumericMatrix
#' @return NumericMatrix
#'
#' @noRd
#'
calculate_normals <- function(vertices) {
.Call(`_rTwig_calculate_normals`, vertices)
}

#' @title Write PLY
#'
#' @description Export a QSM cylinder mesh to .ply
#'
#' @param vertices NumericMatrix
#' @param colors NumericMatrix
#' @param normals NumericMatrix
#' @param filename string
#' @return ply
#'
#' @noRd
#'
write_ply <- function(vertices, colors, normals, filename) {
invisible(.Call(`_rTwig_write_ply`, vertices, colors, normals, filename))
}

#' @title Write OBJ
#'
#' @description Export a QSM cylinder mesh to .obj
#'
#' @param vertices NumericMatrix
#' @param normals NumericMatrix
#' @param filename string
#' @return obj
#'
#' @noRd
#'
write_obj <- function(vertices, normals, filename) {
invisible(.Call(`_rTwig_write_obj`, vertices, normals, filename))
}

#' @title Write STL
#'
#' @description Export a QSM cylinder mesh to .stl
#'
#' @param vertices NumericMatrix
#' @param normals NumericMatrix
#' @param filename string
#' @return stl
#'
#' @noRd
#'
write_stl <- function(vertices, normals, filename) {
invisible(.Call(`_rTwig_write_stl`, vertices, normals, filename))
}

#' @title Read OBJ
#'
#' @description Import leaf meshes from QSM-FaNNI
#'
#' @param filename string
#' @return ply
#'
#' @noRd
#'
read_obj <- function(filename) {
.Call(`_rTwig_read_obj`, filename)
}

#' @title Normalize View
Expand Down
147 changes: 0 additions & 147 deletions R/export_blender.R

This file was deleted.

Loading

0 comments on commit cfe678d

Please sign in to comment.