Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed Jul 9, 2024
1 parent 45de7ff commit 2f3b1bf
Show file tree
Hide file tree
Showing 34 changed files with 894 additions and 190 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches:
- main
- develop
pull_request: {}


jobs:

build:
name: cargo build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo build

test:
name: cargo test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt clippy
- name: rustfmt
run: cargo fmt --all -- --check
- name: clippy
run: cargo clippy
- name: test
run: cargo test --verbose
50 changes: 48 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
### JetBrains template
# Created by https://www.toptal.com/developers/gitignore/api/rust,macos,jetbrains+all
# Edit at https://www.toptal.com/developers/gitignore?templates=rust,macos,jetbrains+all

### JetBrains+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

Expand Down Expand Up @@ -77,7 +80,49 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Rust template
### JetBrains+all Patch ###
# Ignore everything but code style settings and run configurations
# that are supposed to be shared within teams.

.idea/*

!.idea/codeStyles
!.idea/runConfigurations

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Rust ###
# Generated by Cargo
# will have compiled files and executables
debug/
Expand All @@ -93,3 +138,4 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# End of https://www.toptal.com/developers/gitignore/api/rust,macos,jetbrains+all
29 changes: 16 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ members = [
"crates/*"
]

resolver = "2"

[workspace.package]
version = "0.0.1-alpha.1"
authors = ["Benedikt Schwab"]
version = "0.0.1-alpha.3"
authors = ["Benedikt Schwab <benedikt.schwab@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/tum-gis/evoxel"

[workspace.dependencies]
ecoord = { version = "0.0.1-alpha", registry = "custom" }
ecoord = { version = "0.0.1-alpha.3" }

thiserror = "1.0.34"
tracing = "0.1.30"
tracing-subscriber = "0.3.8"
polars = "0.26.1"
ndarray = "0.15"
serde = "1.0"
serde_json = "1.0"
rayon = "1.5"
nalgebra = "0.31.1"
chrono = "0.4.22"
clap = "4.5.9"
thiserror = "1.0.61"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
polars = "0.41.3"
ndarray = "0.15.6"
serde = "1.0.204"
serde_json = "1.0.120"
rayon = "1.10.0"
nalgebra = "0.33.0"
chrono = "0.4.38"
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# evoxel

A Rust library for processing 3D voxel grids.

> [!WARNING]
> The library is at an early stage of development.
## Contributing

The library is developed at the [TUM Chair of Geoinformatics](https://github.com/tum-gis) and contributions are highly welcome.
4 changes: 3 additions & 1 deletion crates/evoxel-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ description = "CLI tool for evoxel operations"


[dependencies]
evoxel = { version = "0.0.1-alpha.1", path = "../evoxel", registry = "custom" }
evoxel = { version = "0.0.1-alpha.3", path = "../evoxel" }

clap = { workspace = true, features = ["derive"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
nalgebra = { workspace = true }
10 changes: 10 additions & 0 deletions crates/evoxel-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# evoxel-cli

CLI tool for processing 3D voxel grids.

> [!WARNING]
> The library is at an early stage of development.
## Contributing

The library is developed at the [TUM Chair of Geoinformatics](https://github.com/tum-gis) and contributions are highly welcome.
22 changes: 22 additions & 0 deletions crates/evoxel-cli/src/arguments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use clap::{Parser, Subcommand};

#[derive(Parser)]
#[clap(author, version, about, long_about = None, propagate_version = true)]
pub struct Arguments {
#[clap(subcommand)]
pub command: Commands,
}

#[derive(Subcommand)]
pub enum Commands {
/// Run some tests
Test {
/// Input directory
#[clap(long)]
input_directory_path: String,

/// Output directory
#[clap(long)]
output_directory_path: String,
},
}
1 change: 1 addition & 0 deletions crates/evoxel-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod test;
44 changes: 44 additions & 0 deletions crates/evoxel-cli/src/commands/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use evoxel::io::{EvoxelReader, EvoxelWriter};
use nalgebra::Point3;
use std::path::Path;
use std::time::Instant;
use tracing::info;

pub fn run(input_directory_path: impl AsRef<Path>, output_directory_path: impl AsRef<Path>) {
// let path = PathBuf::from("/submap_0");
let start = Instant::now();
let voxel_grid = EvoxelReader::new(input_directory_path).finish().unwrap();
let duration = start.elapsed();
info!(
"Read voxel grid with {} cells in {:?}.",
voxel_grid.size(),
duration
);

let voxel_grid = evoxel::transform::aggregate_by_index(&voxel_grid).unwrap();
let voxel_grid = evoxel::transform::filter_by_count(&voxel_grid, 3).unwrap();
let voxel_grid = evoxel::transform::explode(&voxel_grid).unwrap();
let voxel_grid = evoxel::transform::filter_by_index_bounds(
&voxel_grid,
Point3::new(676, 95, 0),
Point3::new(1271, 135, 86),
)
.unwrap();

info!("Start");
let start = Instant::now();
let c = voxel_grid.get_all_cell_indices_in_local_frame();
let duration = start.elapsed();
info!("Calculated {} points in {:?}.", c.len(), duration);
//let all = voxel_grid.get_all_center_points();

info!(
"Start writing voxel grid with {} cells to {}",
voxel_grid.size(),
output_directory_path.as_ref().display()
);
EvoxelWriter::new(output_directory_path)
.with_compressed(false)
.finish(&voxel_grid)
.expect("should work");
}
37 changes: 17 additions & 20 deletions crates/evoxel-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
use evoxel::io::EvoxelReader;
use std::path::PathBuf;
use std::time::Instant;
use tracing::info;
mod arguments;
mod commands;

use crate::arguments::{Arguments, Commands};
use clap::Parser;
use std::path::{Path, PathBuf};

fn main() {
tracing_subscriber::fmt::init();
info!("Hello, world!");
let arguments = Arguments::parse();

let path = PathBuf::from("/submap_0");
let start = Instant::now();
let voxel_grid = EvoxelReader::new(path).finish().unwrap();
let duration = start.elapsed();
info!(
"Read voxel grid with {} cells in {:?}.",
voxel_grid.size(),
duration
);
match &arguments.command {
Commands::Test {
input_directory_path,
output_directory_path,
} => {
let input_directory_path = Path::new(input_directory_path).canonicalize().unwrap();
let output_directory_path = PathBuf::from(output_directory_path);

info!("Start");
let start = Instant::now();
let c = voxel_grid.get_all_cell_indices_in_local_frame();
let duration = start.elapsed();
info!("Calculated {} points in {:?}.", c.len(), duration);
//let all = voxel_grid.get_all_center_points();
commands::test::run(input_directory_path, output_directory_path);
}
};
}
5 changes: 3 additions & 2 deletions crates/evoxel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
description = "Core of the evoxel library"
description = "Core primitives and operations for processing 3D voxel grids."


[dependencies]
ecoord = { workspace = true }

polars = { workspace = true, features = ["lazy", "csv-file", "parquet", "ndarray", "rows"] }
thiserror = { workspace = true }
polars = { workspace = true, features = ["lazy", "parquet", "ndarray", "rows"] }
ndarray = { workspace = true }
rayon = { workspace = true }
nalgebra = { workspace = true }
Expand Down
10 changes: 10 additions & 0 deletions crates/evoxel-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# evoxel-core

Core primitives and operations for processing 3D voxel grids.

> [!WARNING]
> The library is at an early stage of development.
## Contributing

The library is developed at the [TUM Chair of Geoinformatics](https://github.com/tum-gis) and contributions are highly welcome.
39 changes: 39 additions & 0 deletions crates/evoxel-core/src/data_frame_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::Error::{ColumnNameMisMatch, NoData, TypeMisMatch};
use crate::{Error, VoxelDataColumnNames, VoxelGridInfo};
use ecoord::ReferenceFrames;
use polars::datatypes::DataType;
use polars::frame::DataFrame;

pub fn check_data_integrity(
voxel_data: &DataFrame,
_info: &VoxelGridInfo,
_reference_frames: &ReferenceFrames,
) -> Result<(), Error> {
if voxel_data.is_empty() {
return Err(NoData("voxel_data"));
}

let column_names = voxel_data.get_column_names();
if column_names[0] != VoxelDataColumnNames::X.as_str() {
return Err(ColumnNameMisMatch);
}
if column_names[1] != VoxelDataColumnNames::Y.as_str() {
return Err(ColumnNameMisMatch);
}
if column_names[2] != VoxelDataColumnNames::Z.as_str() {
return Err(ColumnNameMisMatch);
}

let data_types = voxel_data.dtypes();
if data_types[0] != DataType::Int64 {
return Err(TypeMisMatch("x"));
}
if data_types[1] != DataType::Int64 {
return Err(TypeMisMatch("y"));
}
if data_types[2] != DataType::Int64 {
return Err(TypeMisMatch("z"));
}

Ok(())
}
19 changes: 19 additions & 0 deletions crates/evoxel-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
EcoordError(#[from] ecoord::Error),
#[error(transparent)]
Polars(#[from] polars::error::PolarsError),

#[error("No data: {0}")]
NoData(&'static str),
#[error("Lengths don't match: {0}")]
ShapeMisMatch(&'static str),

#[error("Field {0} does not match type")]
TypeMisMatch(&'static str),
#[error("unknown data store error")]
ColumnNameMisMatch,
}
Loading

0 comments on commit 2f3b1bf

Please sign in to comment.