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 Trait and Iterator cleanup #278

Merged
merged 1 commit into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Binary file removed .DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 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 Down
8 changes: 4 additions & 4 deletions octree_web_viewer/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class App {

const result = window
.fetch(request)
.then((response) => { return response.text(); }) // todo error handling?
.then((response) => { return response.text(); }) // TODO(catevita, negin-z): error handling?

return result;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ class App {
}

private cleanup() {
// TODO(negin-z) block requests from the viewer that is going to be replaced
// TODO(negin-z): block requests from the viewer that is going to be replaced
this.removeControls();
if (this.renderer) {
this.renderArea.removeChild(this.renderer.domElement);
Expand Down Expand Up @@ -171,7 +171,7 @@ class App {
.name('Point Cloud ID')
.onFinishChange(this.run);

// TODO(negin-z) error handling
// TODO(negin-z): error handling
this.fetchDefaultOctreeId()
.then(this.setOctreeId)
.then(this.run);
Expand All @@ -180,7 +180,7 @@ class App {
}

private onWindowResize() {
// TODO(cvitadello) why is the window size used here?
// TODO(cvitadello): why is the window size used here?
this.camera.aspect = window.innerWidth / window.innerHeight;
this.camera.updateProjectionMatrix();
this.renderer.setSize(window.innerWidth, window.innerHeight);
Expand Down
15 changes: 9 additions & 6 deletions point_cloud_client/src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
use cgmath::Point3;
use collision::Aabb3;
use point_cloud_client::PointCloudClient;
use point_viewer::errors::*;
use point_viewer::octree::{OctreeFactory, PointCulling, PointLocation};
use point_viewer::errors::{ErrorKind, Result};
use point_viewer::octree::{OctreeFactory, PointLocation, PointQuery};
use point_viewer::PointData;
use structopt::StructOpt;

// size for batch
const BATCH_SIZE: usize = 1_000_000;

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 == ';')
Expand Down Expand Up @@ -54,17 +57,17 @@ fn main() {
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: PointCulling::Aabb(Aabb3::new(args.min, args.max)),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason to remove the min/max restriction?
Then the whole point of having min/max arguments goes away...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it also was a copy-paste error

let point_location = PointQuery {
location: PointLocation::Aabb(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 {
if point_count >= print_count * BATCH_SIZE {
print_count += 1;
println!("Streamed {}M points", point_count / 1_000_000);
println!("Streamed {}M points", point_count / BATCH_SIZE);
}
if point_count >= num_points {
return Err(std::io::Error::new(
Expand Down
4 changes: 2 additions & 2 deletions point_cloud_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use collision::{Aabb, Aabb3, Union};
use point_viewer::errors::*;
use point_viewer::octree::{
BatchIterator, Octree, OctreeFactory, PointLocation, NUM_POINTS_PER_BATCH,
BatchIterator, Octree, OctreeFactory, PointQuery, NUM_POINTS_PER_BATCH,
};
use point_viewer::PointData;

Expand Down Expand Up @@ -39,7 +39,7 @@ impl PointCloudClient {
&self.aabb
}

pub fn for_each_point_data<F>(&self, point_location: &PointLocation, mut func: F) -> Result<()>
pub fn for_each_point_data<F>(&self, point_location: &PointQuery, mut func: F) -> Result<()>
where
F: FnMut(PointData) -> Result<()>,
{
Expand Down
38 changes: 23 additions & 15 deletions point_viewer_grpc/src/bin/octree_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ 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::octree::{
octree_from_directory, BatchIterator, OctreeFactory, PointLocation, PointQuery,
};
use point_viewer_grpc::proto_grpc::OctreeClient;
use point_viewer_grpc::service::start_grpc_server;
use point_viewer_grpc_proto_rust::proto;

// size for batch
const BATCH_SIZE: usize = 1_000_000;
fn main() {
let matches = clap::App::new("octree_benchmark")
.args(&[
Expand Down Expand Up @@ -53,7 +56,7 @@ fn main() {
.value_of("octree_directory")
.expect("octree_directory not given"),
);
let num_points = u64::from_str(matches.value_of("num-points").unwrap_or("50000000"))
let num_points = usize::from_str(matches.value_of("num-points").unwrap_or("50000000"))
.expect("num-points needs to be a number");
if matches.is_present("no-client") {
server_benchmark(&octree_directory, num_points)
Expand All @@ -63,26 +66,31 @@ fn main() {
}
}

fn server_benchmark(octree_directory: &Path, num_points: u64) {
fn server_benchmark(octree_directory: &Path, num_points: usize) {
let octree = octree_from_directory(octree_directory).unwrap_or_else(|_| {
panic!(
"Could not create octree from '{}'",
octree_directory.display()
)
});
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 mut counter: usize = 0;
let all_points = PointQuery {
location: PointLocation::AllPoints(),
global_from_local: None,
};
let mut batch_iterator = BatchIterator::new(&octree, &all_points, BATCH_SIZE);

let _result = batch_iterator.try_for_each_batch(move |point_data| {
counter += point_data.position.len();
if counter >= num_points {
std::process::exit(0)
}
println!("Streamed {}M points", counter / BATCH_SIZE);
Ok(())
});
}

fn full_benchmark(octree_directory: &Path, num_points: u64, port: u16) {
fn full_benchmark(octree_directory: &Path, num_points: usize, port: u16) {
let octree_factory = OctreeFactory::new();
let mut server = start_grpc_server("0.0.0.0", port, octree_directory, octree_factory);
server.start();
Expand All @@ -94,12 +102,12 @@ fn full_benchmark(octree_directory: &Path, num_points: u64, port: u16) {
let req = proto::GetAllPointsRequest::new();
let receiver = client.get_all_points(&req).unwrap();

let mut counter: u64 = 0;
let mut counter: usize = 0;

'outer: for rep in receiver.wait() {
for _pos in rep.expect("Stream error").get_positions().iter() {
if counter % 1_000_000 == 0 {
println!("Streamed {}M points", counter / 1_000_000);
if counter % BATCH_SIZE == 0 {
println!("Streamed {}M points", counter / BATCH_SIZE);
}
counter += 1;
if counter == num_points {
Expand Down
Loading