% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/openfoam_terrain.R
\name{prepare_foam_geometry}
\alias{prepare_foam_geometry}
\title{Build terrain, canopy and terrain-based building geometry for a case}
\usage{
prepare_foam_geometry(
  case_dir,
  fused_dsm = NULL,
  building_height = NULL,
  canopy_height = NULL,
  buildings = NULL,
  height_col = NULL,
  domain = NULL,
  terrain_res = NULL,
  canopy_res = 5,
  min_tree_height = 2,
  base_cell_size = 10,
  skirt = 30,
  quiet = FALSE
)
}
\arguments{
\item{case_dir}{Character. OpenFOAM case directory.}

\item{fused_dsm, building_height, canopy_height}{SpatRaster or path or NULL.
Typically \code{foam_inputs$files$fused_dsm},
\code{...$building_height_raster}, \code{...$canopy_height_raster}.}

\item{buildings}{sf polygons in local coordinates, or NULL to leave the
existing building STL alone.  Usually
\code{readRDS(foam_inputs$files$buildings_rds)}.}

\item{height_col}{Character. Building height column.}

\item{domain}{Named list with xmin/xmax/ymin/ymax/zmin/zmax; used to crop.}

\item{terrain_res}{Numeric. Resolution (m) to resample terrain to before
triangulating.  One vertex per cell, so a 1 m DEM over 1 km2 is a million
vertices; default \code{max(5, base_cell_size / 2)}.}

\item{canopy_res}{Numeric. Resolution (m) for the canopy box cloud.
Default 5.}

\item{min_tree_height}{Numeric. Canopy cells below this are ignored.
Default 2.}

\item{base_cell_size}{Numeric. Background mesh cell size, used only to pick
\code{terrain_res}. Default 10.}

\item{skirt}{Numeric. Metres the terrain solid extends below its minimum.
Default 30.}

\item{quiet}{Logical.}
}
\value{
Invisibly, a list with \code{terrain_stl}, \code{canopy_stl},
\code{building_stl}, \code{dem} (SpatRaster) and \code{dem_file} - feed
these straight to \code{\link{prepare_foam_case}}.
}
\description{
Turns the rasters written by \code{\link{prepare_openfoam_inputs}} into the
STL geometry \code{\link{prepare_foam_case}} needs.  Everything is optional:
supply what you have and the rest is skipped.

Terrain is recovered from the fused DSM rather than used directly, because
the fused DSM is terrain + buildings + canopy and meshing it as ground under
a separate building STL would double-count every building.  Given how
\code{get_fused_dsm()} builds it, bare earth comes back exactly as
\code{fused_dsm - max(building_height, canopy_height, 0)}.
}
