Trait vox_geometry_rust::intersection_query_engine3::IntersectionQueryEngine3[][src]

pub trait IntersectionQueryEngine3<T> {
    fn intersects_aabb<Callback>(
        &self,
        aabb: &BoundingBox3D,
        test_func: &mut Callback
    ) -> bool
    where
        Callback: BoxIntersectionTestFunc3<T>
;
fn intersects_ray<Callback>(
        &self,
        ray: &Ray3D,
        test_func: &mut Callback
    ) -> bool
    where
        Callback: RayIntersectionTestFunc3<T>
;
fn for_each_intersecting_item_aabb<Callback, Visitor>(
        &self,
        aabb: &BoundingBox3D,
        test_func: &mut Callback,
        visitor_func: &mut Visitor
    )
    where
        Callback: BoxIntersectionTestFunc3<T>,
        Visitor: IntersectionVisitorFunc3<T>
;
fn for_each_intersecting_item_ray<Callback, Visitor>(
        &self,
        ray: &Ray3D,
        test_func: &mut Callback,
        visitor_func: &mut Visitor
    )
    where
        Callback: RayIntersectionTestFunc3<T>,
        Visitor: IntersectionVisitorFunc3<T>
;
fn closest_intersection<Callback>(
        &self,
        ray: &Ray3D,
        test_func: &mut Callback
    ) -> ClosestIntersectionQueryResult3<T>
    where
        Callback: GetRayIntersectionFunc3<T>
; }
Expand description

Abstract base class for 3-D intersection test query engine.

Required methods

fn intersects_aabb<Callback>(
    &self,
    aabb: &BoundingBox3D,
    test_func: &mut Callback
) -> bool where
    Callback: BoxIntersectionTestFunc3<T>, 
[src]

Returns true if given \p box intersects with any of the stored items.

fn intersects_ray<Callback>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback
) -> bool where
    Callback: RayIntersectionTestFunc3<T>, 
[src]

Returns true if given \p ray intersects with any of the stored items.

fn for_each_intersecting_item_aabb<Callback, Visitor>(
    &self,
    aabb: &BoundingBox3D,
    test_func: &mut Callback,
    visitor_func: &mut Visitor
) where
    Callback: BoxIntersectionTestFunc3<T>,
    Visitor: IntersectionVisitorFunc3<T>, 
[src]

Invokes \p visitor_func for every intersecting items.

fn for_each_intersecting_item_ray<Callback, Visitor>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback,
    visitor_func: &mut Visitor
) where
    Callback: RayIntersectionTestFunc3<T>,
    Visitor: IntersectionVisitorFunc3<T>, 
[src]

Invokes \p visitor_func for every intersecting items.

fn closest_intersection<Callback>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback
) -> ClosestIntersectionQueryResult3<T> where
    Callback: GetRayIntersectionFunc3<T>, 
[src]

Returns the closest intersection for given \p ray.

Implementors

impl<T: Clone> IntersectionQueryEngine3<T> for Bvh3<T>[src]

fn intersects_aabb<Callback>(
    &self,
    aabb: &BoundingBox3D,
    test_func: &mut Callback
) -> bool where
    Callback: BoxIntersectionTestFunc3<T>, 
[src]

use vox_geometry_rust::bvh3::Bvh3;
use vox_geometry_rust::vector3::Vector3D;
use vox_geometry_rust::bounding_box3::BoundingBox3D;
use vox_geometry_rust::unit_tests_utils::*;
use vox_geometry_rust::nearest_neighbor_query_engine3::*;
use vox_geometry_rust::intersection_query_engine3::IntersectionQueryEngine3;
let mut bvh:Bvh3<Vector3D> = Bvh3::new();

let mut overlaps_func = |pt:&Vector3D, bbox:&BoundingBox3D| {
    let mut aabb = BoundingBox3D::new(*pt, *pt);
    aabb.expand(0.1);
    return bbox.overlaps(&aabb);
};

let num_samples = get_number_of_sample_points3();
let points = (0..num_samples).map(|index| Vector3D::new_lst(get_sample_points3()[index])).collect();

let bounds = (0..num_samples).map(|index| {
    let c = Vector3D::new_lst(get_sample_points3()[index]);
    let mut aabb = BoundingBox3D::new(c, c);
    aabb.expand(0.1);
    aabb
}).collect();

bvh.build(&points, &bounds);

let test_box = BoundingBox3D::new(Vector3D::new(0.25, 0.15, 0.3), Vector3D::new(0.5, 0.6, 0.4));
let mut has_overlaps = false;
for i in 0..num_samples {
    has_overlaps |= overlaps_func(&Vector3D::new_lst(get_sample_points3()[i]), &test_box);
}

assert_eq!(has_overlaps, bvh.intersects_aabb(&test_box, &mut overlaps_func));

let test_box3 = BoundingBox3D::new(Vector3D::new(0.3, 0.2, 0.1), Vector3D::new(0.6, 0.5, 0.4));
has_overlaps = false;
for i in 0..num_samples {
    has_overlaps |= overlaps_func(&Vector3D::new_lst(get_sample_points3()[i]), &test_box3);
}

assert_eq!(has_overlaps, bvh.intersects_aabb(&test_box3, &mut overlaps_func));

fn intersects_ray<Callback>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback
) -> bool where
    Callback: RayIntersectionTestFunc3<T>, 
[src]

use vox_geometry_rust::bvh3::Bvh3;
use vox_geometry_rust::vector3::Vector3D;
use vox_geometry_rust::bounding_box3::BoundingBox3D;
use vox_geometry_rust::ray3::Ray3D;
use vox_geometry_rust::unit_tests_utils::*;
use vox_geometry_rust::nearest_neighbor_query_engine3::*;
use vox_geometry_rust::intersection_query_engine3::IntersectionQueryEngine3;
let mut bvh:Bvh3<BoundingBox3D> = Bvh3::new();

let mut intersects_func = |a:&BoundingBox3D, ray:&Ray3D| {
        return a.intersects(ray);
};

let num_samples = get_number_of_sample_points3();
let items = (0..num_samples / 2).map(|index| {
    let c = Vector3D::new_lst(get_sample_points3()[index]);
    let mut aabb = BoundingBox3D::new(c, c);
    aabb.expand(0.1);
    aabb
}).collect();

bvh.build(&items, &items);

for i in 0..num_samples / 2 {
    let ray = Ray3D::new(Vector3D::new_lst(get_sample_dirs3()[i + num_samples / 2]),
                         Vector3D::new_lst(get_sample_dirs3()[i + num_samples / 2]));
    // ad-hoc search
    let mut ans_ints = false;
    for j in 0..num_samples / 2 {
        if intersects_func(&items[j], &ray) {
            ans_ints = true;
            break;
        }
    }

    // bvh search
    let oct_ints = bvh.intersects_ray(&ray, &mut intersects_func);

    assert_eq!(ans_ints, oct_ints);
}

fn for_each_intersecting_item_aabb<Callback, Visitor>(
    &self,
    aabb: &BoundingBox3D,
    test_func: &mut Callback,
    visitor_func: &mut Visitor
) where
    Callback: BoxIntersectionTestFunc3<T>,
    Visitor: IntersectionVisitorFunc3<T>, 
[src]

use vox_geometry_rust::bvh3::Bvh3;
use vox_geometry_rust::vector3::Vector3D;
use vox_geometry_rust::bounding_box3::BoundingBox3D;
use vox_geometry_rust::unit_tests_utils::*;
use vox_geometry_rust::nearest_neighbor_query_engine3::*;
use vox_geometry_rust::intersection_query_engine3::IntersectionQueryEngine3;
let mut bvh:Bvh3<Vector3D> = Bvh3::new();

let mut overlaps_func = |pt:&Vector3D, bbox:&BoundingBox3D| {
        return bbox.contains(pt);
};

let overlaps_func3 = |pt:&Vector3D, bbox:&BoundingBox3D| {
        return bbox.contains(pt);
};

let num_samples = get_number_of_sample_points3();
let points = (0..num_samples).map(|index| Vector3D::new_lst(get_sample_points3()[index])).collect();

let bounds = (0..num_samples).map(|index| {
    let c = Vector3D::new_lst(get_sample_points3()[index]);
    let mut aabb = BoundingBox3D::new(c, c);
    aabb.expand(0.1);
    aabb
}).collect();

bvh.build(&points, &bounds);

let test_box = BoundingBox3D::new(Vector3D::new(0.3, 0.2, 0.1), Vector3D::new(0.6, 0.5, 0.4));
let mut num_overlaps = 0;
for i in 0..num_samples {
    num_overlaps += overlaps_func(&Vector3D::new_lst(get_sample_points3()[i]), &test_box) as usize;
}

let mut measured = 0;
bvh.for_each_intersecting_item_aabb(&test_box, &mut overlaps_func, &mut |pt:&Vector3D| {
    assert_eq!(overlaps_func3(pt, &test_box), true);
    measured += 1;
});

assert_eq!(num_overlaps, measured);

fn closest_intersection<Callback>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback
) -> ClosestIntersectionQueryResult3<T> where
    Callback: GetRayIntersectionFunc3<T>, 
[src]

use vox_geometry_rust::bvh3::Bvh3;
use vox_geometry_rust::vector3::Vector3D;
use vox_geometry_rust::bounding_box3::BoundingBox3D;
use vox_geometry_rust::ray3::Ray3D;
use vox_geometry_rust::unit_tests_utils::*;
use vox_geometry_rust::nearest_neighbor_query_engine3::*;
use vox_geometry_rust::intersection_query_engine3::*;
let mut bvh:Bvh3<BoundingBox3D> = Bvh3::new();

let mut intersects_func = |a:&BoundingBox3D, ray:&Ray3D| {
    let bbox_result = a.closest_intersection(ray);
    return if bbox_result.is_intersecting {
         bbox_result.t_near
    } else {
         f64::MAX
    };
};

let num_samples = get_number_of_sample_points3();
let items = (0..num_samples / 2).map(|index| {
    let c = Vector3D::new_lst(get_sample_points3()[index]);
    let mut aabb = BoundingBox3D::new(c, c);
    aabb.expand(0.1);
    aabb
}).collect();

bvh.build(&items, &items);

for i in 0..num_samples / 2 {
    let ray = Ray3D::new(Vector3D::new_lst(get_sample_points3()[i + num_samples / 2]),
                         Vector3D::new_lst(get_sample_dirs3()[i + num_samples / 2]));
        // ad-hoc search
    let mut ans_ints:ClosestIntersectionQueryResult3<BoundingBox3D> = ClosestIntersectionQueryResult3::new();
    for j in 0..num_samples / 2 {
        let dist = intersects_func(&items[j], &ray);
        if dist < ans_ints.distance {
            ans_ints.distance = dist;
            ans_ints.item = Some(bvh.item(j).clone());
        }
    }

    // bvh search
    let bvh_ints = bvh.closest_intersection(&ray, &mut intersects_func);

    assert_eq!(ans_ints.distance, bvh_ints.distance);
    let ans_aabb = ans_ints.item.unwrap_or(BoundingBox3D::new_default());
    let oct_aabb = bvh_ints.item.unwrap_or(BoundingBox3D::new_default());
    assert_eq!(ans_aabb.upper_corner, oct_aabb.upper_corner);
    assert_eq!(ans_aabb.lower_corner, oct_aabb.lower_corner);
}

fn for_each_intersecting_item_ray<Callback, Visitor>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback,
    visitor_func: &mut Visitor
) where
    Callback: RayIntersectionTestFunc3<T>,
    Visitor: IntersectionVisitorFunc3<T>, 
[src]

impl<T: Clone> IntersectionQueryEngine3<T> for ListQueryEngine3<T>[src]

fn intersects_aabb<Callback>(
    &self,
    aabb: &BoundingBox3D,
    test_func: &mut Callback
) -> bool where
    Callback: BoxIntersectionTestFunc3<T>, 
[src]

fn intersects_ray<Callback>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback
) -> bool where
    Callback: RayIntersectionTestFunc3<T>, 
[src]

fn for_each_intersecting_item_aabb<Callback, Visitor>(
    &self,
    aabb: &BoundingBox3D,
    test_func: &mut Callback,
    visitor_func: &mut Visitor
) where
    Callback: BoxIntersectionTestFunc3<T>,
    Visitor: IntersectionVisitorFunc3<T>, 
[src]

fn for_each_intersecting_item_ray<Callback, Visitor>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback,
    visitor_func: &mut Visitor
) where
    Callback: RayIntersectionTestFunc3<T>,
    Visitor: IntersectionVisitorFunc3<T>, 
[src]

fn closest_intersection<Callback>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback
) -> ClosestIntersectionQueryResult3<T> where
    Callback: GetRayIntersectionFunc3<T>, 
[src]

impl<T: Clone> IntersectionQueryEngine3<T> for Octree<T>[src]

fn intersects_aabb<Callback>(
    &self,
    aabb: &BoundingBox3D,
    test_func: &mut Callback
) -> bool where
    Callback: BoxIntersectionTestFunc3<T>, 
[src]

use vox_geometry_rust::vector3::Vector3D;
use vox_geometry_rust::bounding_box3::BoundingBox3D;
use vox_geometry_rust::octree::Octree;
use vox_geometry_rust::unit_tests_utils::*;
use vox_geometry_rust::nearest_neighbor_query_engine3::NearestNeighborQueryEngine3;
use vox_geometry_rust::intersection_query_engine3::IntersectionQueryEngine3;
let mut octree:Octree<Vector3D> = Octree::new();

let mut overlaps_func = |pt:&Vector3D, bbox:&BoundingBox3D| {
        return bbox.contains(pt);
    };

let num_samples = get_number_of_sample_points3();
let points = (0..100).map(|index| Vector3D::new_lst(get_sample_points3()[index])).collect();

octree.build(&points, &BoundingBox3D::new(Vector3D::new_default(), Vector3D::new(1.0, 1.0, 1.0)), &mut overlaps_func, 5);

let test_box = BoundingBox3D::new(Vector3D::new(0.25, 0.15, 0.3), Vector3D::new(0.5, 0.6, 0.4));
let mut has_overlaps = false;
for i in 0..num_samples {
    has_overlaps |= overlaps_func(&Vector3D::new_lst(get_sample_points3()[i]), &test_box);
}

assert_eq!(has_overlaps, octree.intersects_aabb(&test_box, &mut overlaps_func));

let test_box3 = BoundingBox3D::new(Vector3D::new(0.3, 0.2, 0.1), Vector3D::new(0.6, 0.5, 0.4));
has_overlaps = false;
for i in 0..num_samples {
    has_overlaps |= overlaps_func(&Vector3D::new_lst(get_sample_points3()[i]), &test_box3);
}

assert_eq!(has_overlaps, octree.intersects_aabb(&test_box3, &mut overlaps_func));

fn intersects_ray<Callback>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback
) -> bool where
    Callback: RayIntersectionTestFunc3<T>, 
[src]

use vox_geometry_rust::vector3::Vector3D;
use vox_geometry_rust::bounding_box3::BoundingBox3D;
use vox_geometry_rust::ray3::Ray3D;
use vox_geometry_rust::octree::Octree;
use vox_geometry_rust::unit_tests_utils::*;
use vox_geometry_rust::nearest_neighbor_query_engine3::NearestNeighborQueryEngine3;
use vox_geometry_rust::intersection_query_engine3::IntersectionQueryEngine3;
let mut octree:Octree<BoundingBox3D> = Octree::new();

let mut overlaps_func = |a:&BoundingBox3D, bbox:&BoundingBox3D| {
    return bbox.overlaps(a);
};

let mut intersects_func = |a:&BoundingBox3D, ray:&Ray3D| {
    return a.intersects(ray);
};

let num_samples = get_number_of_sample_points3();
let items = (0..num_samples / 2).map(|index| {
    let c = Vector3D::new_lst(get_sample_points3()[index]);
    let mut aabb = BoundingBox3D::new(c, c);
    aabb.expand(0.1);
    aabb
}).collect();

octree.build(&items, &BoundingBox3D::new(Vector3D::new_default(), Vector3D::new(1.0, 1.0, 1.0)), &mut overlaps_func, 5);
for i in 0..num_samples / 2 {
    let ray = Ray3D::new(Vector3D::new_lst(get_sample_points3()[i + num_samples / 2]),
              Vector3D::new_lst(get_sample_dirs3()[i + num_samples / 2]));
    // ad-hoc search
    let mut ans_ints = false;
    for j in 0..num_samples / 2 {
        if intersects_func(&items[j], &ray) {
            ans_ints = true;
            break;
        }
    }

    // Octree search
    let oct_ints = octree.intersects_ray(&ray, &mut intersects_func);

    assert_eq!(ans_ints, oct_ints);
}

fn for_each_intersecting_item_aabb<Callback, Visitor>(
    &self,
    aabb: &BoundingBox3D,
    test_func: &mut Callback,
    visitor_func: &mut Visitor
) where
    Callback: BoxIntersectionTestFunc3<T>,
    Visitor: IntersectionVisitorFunc3<T>, 
[src]

use vox_geometry_rust::vector3::Vector3D;
use vox_geometry_rust::bounding_box3::BoundingBox3D;
use vox_geometry_rust::octree::Octree;
use vox_geometry_rust::unit_tests_utils::*;
use vox_geometry_rust::nearest_neighbor_query_engine3::NearestNeighborQueryEngine3;
use vox_geometry_rust::intersection_query_engine3::IntersectionQueryEngine3;
let mut octree:Octree<Vector3D> = Octree::new();

let mut overlaps_func = |pt:&Vector3D, bbox:&BoundingBox3D| {
        return bbox.contains(pt);
};

let overlaps_func3 = |pt:&Vector3D, bbox:&BoundingBox3D| {
        return bbox.contains(pt);
};

let num_samples = get_number_of_sample_points3();
let points = (0..100).map(|index| Vector3D::new_lst(get_sample_points3()[index])).collect();

octree.build(&points, &BoundingBox3D::new(Vector3D::new_default(), Vector3D::new(1.0, 1.0, 1.0)), &mut overlaps_func, 5);

let test_box = BoundingBox3D::new(Vector3D::new(0.3, 0.2, 0.1), Vector3D::new(0.6, 0.5, 0.4));
let mut num_overlaps = 0;
for i in 0..num_samples {
    num_overlaps += overlaps_func(&Vector3D::new_lst(get_sample_points3()[i]), &test_box) as usize;
}

let mut measured = 0;
octree.for_each_intersecting_item_aabb(&test_box, &mut overlaps_func,
                             &mut |pt:&Vector3D| {
                                 assert_eq!(overlaps_func3(pt, &test_box), true);
                                 measured += 1;
                             });

assert_eq!(num_overlaps, measured);

fn closest_intersection<Callback>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback
) -> ClosestIntersectionQueryResult3<T> where
    Callback: GetRayIntersectionFunc3<T>, 
[src]

use vox_geometry_rust::vector3::Vector3D;
use vox_geometry_rust::bounding_box3::{BoundingBox3D, BoundingBox3};
use vox_geometry_rust::ray3::Ray3D;
use vox_geometry_rust::octree::Octree;
use vox_geometry_rust::unit_tests_utils::*;
use vox_geometry_rust::nearest_neighbor_query_engine3::NearestNeighborQueryEngine3;
use vox_geometry_rust::intersection_query_engine3::*;
let mut octree:Octree<BoundingBox3D> = Octree::new();

let mut overlaps_func = |a:&BoundingBox3D, bbox:&BoundingBox3D| {
    return bbox.overlaps(a);
};

let mut intersects_func = |a:&BoundingBox3D, ray:&Ray3D| {
    let bbox_result = a.closest_intersection(ray);
    return if bbox_result.is_intersecting {
         bbox_result.t_near
    } else {
         f64::MAX
    };
};

let num_samples = get_number_of_sample_points3();
let items = (0..num_samples / 2).map(|index| {
    let c = Vector3D::new_lst(get_sample_points3()[index]);
    let mut aabb = BoundingBox3D::new(c, c);
    aabb.expand(0.1);
    aabb
}).collect();

octree.build(&items, &BoundingBox3D::new(Vector3D::new_default(), Vector3D::new(1.0, 1.0, 1.0)), &mut overlaps_func, 5);

for i in 0..num_samples / 2 {
    let ray = Ray3D::new(Vector3D::new_lst(get_sample_points3()[i + num_samples / 2]),
              Vector3D::new_lst(get_sample_dirs3()[i + num_samples / 2]));
    // ad-hoc search
    let mut ans_ints:ClosestIntersectionQueryResult3<BoundingBox3D> = ClosestIntersectionQueryResult3::new();
    for j in 0..num_samples / 2 {
        let dist = intersects_func(&items[j], &ray);
        if dist < ans_ints.distance {
            ans_ints.distance = dist;
            ans_ints.item = Some(octree.item(j));
        }
    }

    // Octree search
    let oct_ints = octree.closest_intersection(&ray, &mut intersects_func);

    assert_eq!(ans_ints.distance, oct_ints.distance);
    let ans_aabb = ans_ints.item.unwrap_or(BoundingBox3D::new_default());
    let oct_aabb = oct_ints.item.unwrap_or(BoundingBox3D::new_default());
    assert_eq!(ans_aabb.upper_corner, oct_aabb.upper_corner);
    assert_eq!(ans_aabb.lower_corner, oct_aabb.lower_corner);
}

fn for_each_intersecting_item_ray<Callback, Visitor>(
    &self,
    ray: &Ray3D,
    test_func: &mut Callback,
    visitor_func: &mut Visitor
) where
    Callback: RayIntersectionTestFunc3<T>,
    Visitor: IntersectionVisitorFunc3<T>, 
[src]