Skip to content

Commit

Permalink
Merge pull request #87 from j9ac9k/apply-fwd-all
Browse files Browse the repository at this point in the history
Add scale and offset args for pointcloud registration
  • Loading branch information
j9ac9k authored Apr 18, 2024
2 parents 584f3a0 + cc0526f commit ceab1ae
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
95 changes: 94 additions & 1 deletion src/codem/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import warnings
from contextlib import ContextDecorator
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Tuple
Expand Down Expand Up @@ -74,6 +73,12 @@ class CodemRunConfig:
ICP_RMSE_THRESHOLD: float = 0.0001
ICP_ROBUST: bool = True
ICP_SOLVE_SCALE: bool = True
OFFSET_X: str= 'auto'
OFFSET_Y: str = 'auto'
OFFSET_Z: str = 'auto'
SCALE_X: str = "0.01"
SCALE_Y: str = "0.01"
SCALE_Z: str = "0.01"
VERBOSE: bool = False
ICP_SAVE_RESIDUALS: bool = False
OUTPUT_DIR: Optional[str] = None
Expand Down Expand Up @@ -137,6 +142,25 @@ def __post_init__(self) -> None:
raise ValueError(
"ICP minimum change in RMSE convergence threshold must be greater than 0."
)
for offset in [self.OFFSET_X, self.OFFSET_Y, self.OFFSET_Z]:
if (
offset != "auto"
and not offset.isnumeric()
):
raise ValueError(
"Offset values need to be set to 'auto' or an integer"
)
for scale in [self.SCALE_X, self.SCALE_Y, self.SCALE_Z]:
if (
isinstance(scale, str)
and scale != "auto"
):
try:
float(scale)
except ValueError as e:
raise ValueError(
"Offset values need to be set to 'auto' or an float"
) from e

# dump config
config_path = os.path.join(self.OUTPUT_DIR, "config.yml")
Expand Down Expand Up @@ -272,6 +296,69 @@ def get_args() -> argparse.Namespace:
action="store_true",
help="Write ICP residual information",
)
ap.add_argument(
"--offset-x",
type=str,
default='auto',
help=(
"Offset to be subtracted from the X nominal value, before "
"the value is scaled. The special value auto can be specified, which causes "
"the writer to set the offset to the minimum value of the dimension. "
)
)
ap.add_argument(
"--offset-y",
type=str,
default='auto',
help=(
"Offset to be subtracted from the Y nominal value, before "
"the value is scaled. The special value auto can be specified, which causes "
"the writer to set the offset to the minimum value of the dimension. "
)
)
ap.add_argument(
"--offset-z",
type=str,
default='auto',
help=(
"Offset to be subtracted from the Z nominal value, before "
"the value is scaled. The special value auto can be specified, which causes "
"the writer to set the offset to the minimum value of the dimension. "
)
)
ap.add_argument(
"--scale-x",
type=str,
default='.01',
help=(
"Scale to be divided from the X nominal value, "
"after the offset has been applied. The special value auto can be specified, "
"which causes the writer to select a scale to set the stored values of the "
"dimensions to range from [0, 2147483647]."
)
)
ap.add_argument(
"--scale-y",
type=str,
default='.01',
help=(
"Scale to be divided from the Y nominal value, "
"after the offset has been applied. The special value auto can be specified, "
"which causes the writer to select a scale to set the stored values of the "
"dimensions to range from [0, 2147483647]."
)
)
ap.add_argument(
"--scale-z",
type=str,
default='.01',
help=(
"Scale to be divided from the Z nominal value, "
"after the offset has been applied. The special value auto can be specified, "
"which causes the writer to select a scale to set the stored values of the "
"dimensions to range from [0, 2147483647]."
)
)
ap.add_argument(
"--verbose", "-v", action="store_true", help="turn on verbose logging"
)
Expand Down Expand Up @@ -327,6 +414,12 @@ def create_config(args: argparse.Namespace) -> CodemParameters:
ICP_RMSE_THRESHOLD=float(args.icp_rmse_threshold),
ICP_ROBUST=args.icp_robust,
ICP_SOLVE_SCALE=args.icp_solve_scale,
SCALE_X=args.scale_x,
SCALE_Y=args.scale_y,
SCALE_Z=args.scale_z,
OFFSET_X=args.offset_x,
OFFSET_Y=args.offset_y,
OFFSET_Z=args.offset_z,
VERBOSE=args.verbose,
ICP_SAVE_RESIDUALS=args.icp_save_residuals,
TIGHT_SEARCH=args.tight_search,
Expand Down
7 changes: 6 additions & 1 deletion src/codem/preprocessing/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import math
import os
import tempfile
from typing import Any
from typing import Dict
from typing import Optional
from typing import Tuple
Expand Down Expand Up @@ -70,6 +69,12 @@ class CodemParameters(TypedDict):
ICP_RMSE_THRESHOLD: float
ICP_ROBUST: bool
ICP_SOLVE_SCALE: bool
OFFSET_X: str
OFFSET_Y: str
OFFSET_Z: str
SCALE_X: str
SCALE_Y: str
SCALE_Z: str
VERBOSE: bool
ICP_SAVE_RESIDUALS: bool
OUTPUT_DIR: str
Expand Down
7 changes: 7 additions & 0 deletions src/codem/registration/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ def _apply_pointcloud(self) -> None:
writer_kwargs = {"filename": self.out_name}
if self.fnd_crs is not None:
writer_kwargs["a_srs"] = self.fnd_crs.to_wkt()
writer_kwargs["forward"] = "all"
writer_kwargs["offset_x"] = self.config["OFFSET_X"]
writer_kwargs["offset_y"] = self.config["OFFSET_Y"]
writer_kwargs['offset_z'] = self.config["OFFSET_Z"]
writer_kwargs["scale_x"] = self.config["SCALE_X"]
writer_kwargs["scale_y"] = self.config["SCALE_Y"]
writer_kwargs['scale_z'] = self.config["SCALE_Z"]
pipeline |= pdal.Writer.las(**writer_kwargs)

pipeline.execute()
Expand Down

0 comments on commit ceab1ae

Please sign in to comment.