src/container.cc
branchpyrit
changeset 95 ca7d4c665531
parent 92 9af5c039b678
equal deleted inserted replaced
94:4c8abb8977dc 95:ca7d4c665531
    26 
    26 
    27 #include "common.h"
    27 #include "common.h"
    28 #include "container.h"
    28 #include "container.h"
    29 #include "serialize.h"
    29 #include "serialize.h"
    30 
    30 
    31 void Container::addShape(Shape* aShape)
    31 void Container::addShape(const Shape* aShape)
    32 {
    32 {
    33 	const Float e = Eps;
    33 	const Float e = Eps;
    34 	if (shapes.size() == 0) {
    34 	if (shapes.size() == 0) {
    35 		/* initialize bounding box */
    35 		/* initialize bounding box */
    36 		bbox = aShape->get_bbox();
    36 		bbox = aShape->get_bbox();
    47 		if (shapebb.H.z + e > bbox.H.z)  bbox.H.z = shapebb.H.z + e;
    47 		if (shapebb.H.z + e > bbox.H.z)  bbox.H.z = shapebb.H.z + e;
    48 	}
    48 	}
    49 	shapes.push_back(aShape);
    49 	shapes.push_back(aShape);
    50 };
    50 };
    51 
    51 
    52 Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray,
    52 const Shape *Container::nearest_intersection(const Shape *origin_shape, const Ray &ray,
    53         Float &nearest_distance)
    53         Float &nearest_distance)
    54 {
    54 {
    55 	Shape *nearest_shape = NULL;
    55 	const Shape *nearest_shape = NULL;
    56 	ShapeList::iterator shape;
    56 	ShapeList::iterator shape;
    57 	for (shape = shapes.begin(); shape != shapes.end(); shape++)
    57 	for (shape = shapes.begin(); shape != shapes.end(); shape++)
    58 		if (*shape != origin_shape && (*shape)->intersect(ray, nearest_distance))
    58 		if (*shape != origin_shape && (*shape)->intersect(ray, nearest_distance))
    59 			nearest_shape = *shape;
    59 			nearest_shape = *shape;
    60 	return nearest_shape;
    60 	return nearest_shape;
    61 }
    61 }
    62 
    62 
    63 #ifndef NO_SIMD
    63 #ifndef NO_SIMD
    64 void Container::packet_intersection(const Shape* const* origin_shapes, const RayPacket &rays,
    64 void Container::packet_intersection(const Shape* const* origin_shapes, const RayPacket &rays,
    65 	Float *nearest_distances, Shape **nearest_shapes)
    65 	Float *nearest_distances, const Shape **nearest_shapes)
    66 {
    66 {
    67 	for (int i = 0; i < 4; i++)
    67 	for (int i = 0; i < 4; i++)
    68 		nearest_shapes[i] = nearest_intersection(origin_shapes[i], rays[i],
    68 		nearest_shapes[i] = nearest_intersection(origin_shapes[i], rays[i],
    69 			nearest_distances[i]);
    69 			nearest_distances[i]);
    70 }
    70 }
    71 #endif
    71 #endif
    72 
    72 
    73 ostream & Container::dump(ostream &st)
    73 ostream & Container::dump(ostream &st) const
    74 {
    74 {
    75 	st << "(container," << shapes.size();
    75 	st << "(container," << shapes.size();
    76 	ShapeList::iterator shape;
    76 	ShapeList::const_iterator shape;
    77 	for (shape = shapes.begin(); shape != shapes.end(); shape++)
    77 	for (shape = shapes.begin(); shape != shapes.end(); shape++)
    78 	{
    78 	{
    79 		int idx;
    79 		int idx;
    80 		if (!shape_index.get(*shape, idx))
    80 		if (!shape_index.get(*shape, idx))
    81 			st << "," << **shape;
    81 			st << "," << **shape;