Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PointCulling as trait #273

Closed
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ error-chain = "0.11.0"
fnv = "1.0.6"
num = "0.1.36"
num-traits = "0.1.36"
objekt = "0.1.2"
pbr = "1.0.0-alpha.1"
protobuf = "2.0.0"
scoped-pool = "^0.1"
Expand All @@ -41,6 +42,7 @@ tempdir = "0.3.7"

[workspace]
members = [
"point_cloud_client",
"point_viewer_grpc",
"point_viewer_grpc_proto_rust",
"point_viewer_proto_rust",
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DEFAULT_GOAL := all

.PHONY: all
all:
yarn build_all
cargo build --release --all
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"private": true,
"workspaces": [
"octree_web_viewer/client",
"xray/client"
],
"scripts": {
"build_all": "yarn install --silent --ignore-engines && yarn wsrun build",
"test": "yarn wsrun --exclude-missing test"
},
"devDependencies": {
"typescript": "^3.3.3",
"wsrun": "^3.3.3"
}
}
17 changes: 17 additions & 0 deletions point_cloud_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "point_cloud_client"
version = "0.1.0"
edition = "2018"

[[bin]]
name = "point_cloud_client_test"
path = "src/bin/test.rs"

[dependencies]
cgmath = "0.16.0"
collision = "0.18.0"
fnv = "1.0.6"
point_viewer = { path = ".." }
point_viewer_grpc = { path = "../point_viewer_grpc" }
protobuf = "2.0.0"
structopt = "0.2"
89 changes: 89 additions & 0 deletions point_cloud_client/src/bin/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// This removes clippy warnings regarding redundant StructOpt.
#![allow(clippy::redundant_closure)]

use cgmath::Point3;
use collision::Aabb3;
use point_cloud_client::PointCloudClient;
use point_viewer::errors::{ErrorKind, Result};
use point_viewer::octree::{OctreeFactory, PointLocation};
use point_viewer::PointData;
use std::sync::Arc;
use structopt::StructOpt;

fn point3f64_from_str(s: &str) -> std::result::Result<Point3<f64>, &'static str> {
let coords: std::result::Result<Vec<f64>, &'static str> = s
.split(|c| c == ' ' || c == ',' || c == ';')
.map(|s| s.parse::<f64>().map_err(|_| "Could not parse point."))
.collect();
let coords = coords?;
if coords.len() != 3 {
return Err("Wrong number of coordinates.");
}
Ok(Point3::new(coords[0], coords[1], coords[2]))
}

#[derive(StructOpt)]
#[structopt(about = "Simple point_cloud_client test.")]
struct CommandlineArguments {
/// The locations containing the octree data.
#[structopt(parse(from_str), raw(required = "true"))]
locations: Vec<String>,

/// The minimum value of the bounding box to be queried.
#[structopt(
long = "min",
default_value = "-500.0 -500.0 -500.0",
parse(try_from_str = "point3f64_from_str")
)]
min: Point3<f64>,

/// The maximum value of the bounding box to be queried.
#[structopt(
long = "max",
default_value = "500.0 500.0 500.0",
parse(try_from_str = "point3f64_from_str")
)]
max: Point3<f64>,

/// The maximum number of points to return.
#[structopt(long = "num-points", default_value = "50000000")]
num_points: usize,
}

fn main() {
let args = CommandlineArguments::from_args();
let num_points = args.num_points;
let point_cloud_client = PointCloudClient::new(&args.locations, OctreeFactory::new())
.expect("Couldn't create octree client.");
let point_location = PointLocation {
culling: Arc::new(Box::new(Aabb3::new(args.min, args.max))),
global_from_local: None,
};
let mut point_count: usize = 0;
let mut print_count: usize = 1;
let callback_func = |point_data: PointData| -> Result<()> {
point_count += point_data.position.len();
if point_count >= print_count * 1_000_000 {
print_count += 1;
println!("Streamed {}M points", point_count / 1_000_000);
}
if point_count >= num_points {
return Err(std::io::Error::new(
std::io::ErrorKind::Interrupted,
format!("Maximum number of {} points reached.", num_points),
)
.into());
}
Ok(())
};
match point_cloud_client.for_each_point_data(&point_location, callback_func) {
Ok(_) => (),
Err(e) => match e.kind() {
ErrorKind::Io(ref e) if e.kind() == std::io::ErrorKind::Interrupted => (),
_ => {
println!("Encountered error:\n{}", e);
std::process::exit(1);
}
},
}
}
39 changes: 39 additions & 0 deletions point_cloud_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use point_viewer::errors::*;
use point_viewer::octree::{
BatchIterator, Octree, OctreeFactory, PointLocation, NUM_POINTS_PER_BATCH,
};
use point_viewer::PointData;

pub struct PointCloudClient {
octrees: Vec<Octree>,
pub num_points_per_batch: usize,
}

impl PointCloudClient {
pub fn new(locations: &[String], octree_factory: OctreeFactory) -> Result<Self> {
let octrees: Result<Vec<Octree>> = locations
.iter()
.map(|location| {
octree_factory
.generate_octree(location)
.map(|octree| *octree)
})
.collect();
octrees.map(|octrees| PointCloudClient {
octrees,
num_points_per_batch: NUM_POINTS_PER_BATCH,
})
}

pub fn for_each_point_data<F>(&self, point_location: &PointLocation, mut func: F) -> Result<()>
where
F: FnMut(PointData) -> Result<()>,
{
for octree in &self.octrees {
let mut batch_iterator =
BatchIterator::new(octree, point_location, self.num_points_per_batch);
batch_iterator.try_for_each_batch(&mut func)?;
}
Ok(())
}
}
22 changes: 14 additions & 8 deletions point_viewer_grpc/src/bin/octree_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;

use point_viewer::octree::{octree_from_directory, OctreeFactory};
use point_viewer::Point;
use point_viewer::math::AllPoints;
use point_viewer::octree::{octree_from_directory, BatchIterator, OctreeFactory, PointLocation};
use point_viewer_grpc::proto_grpc::OctreeClient;
use point_viewer_grpc::service::start_grpc_server;
use point_viewer_grpc_proto_rust::proto;
Expand Down Expand Up @@ -71,14 +71,20 @@ fn server_benchmark(octree_directory: &Path, num_points: u64) {
)
});
let mut counter: u64 = 0;
octree.all_points().for_each(|_p: Point| {
if counter % 1_000_000 == 0 {
println!("Streamed {}M points", counter / 1_000_000);
}
counter += 1;
if counter == num_points {
let all_points = PointLocation {
culling: Arc::new(Box::new(AllPoints {})),
global_from_local: None,
};
let mut batch_iterator = BatchIterator::new(&octree, &all_points, 1_000_000);
let mut num_batches = 0;
let _result = batch_iterator.try_for_each_batch(move |_| {
num_batches += 1;
counter = num_batches * 1_000_000;
if counter >= num_points {
std::process::exit(0)
}
println!("Streamed {}M points", num_batches);
Ok(())
});
}

Expand Down
Loading