81 VL_DEBUG_SET_OBJECT_NAME()
85 mGeometry->setObjectName(
"vl::SlicedVolume");
89 fvec3(0,0,0),
fvec3(1,0,0),
fvec3(1,1,0),
fvec3(0,1,0),
90 fvec3(0,0,1),
fvec3(1,0,1),
fvec3(1,1,1),
fvec3(0,1,1)
113 int light_enable[4] = { 0,0,0,0 };
114 fvec3 light_position[4];
116 for(
int i=0; i<4; ++i)
119 light_enable[i] = light !=
NULL;
160 int v0, v1, intersection, flags;
161 bool operator<(
const Edge& other)
const 163 return intersection > other.intersection;
204 fvec3((
float)
box().minCorner().x(), (
float)
box().minCorner().y(), (
float)
box().minCorner().z()),
205 fvec3((
float)
box().maxCorner().x(), (
float)
box().minCorner().y(), (
float)
box().minCorner().z()),
206 fvec3((
float)
box().maxCorner().x(), (
float)
box().maxCorner().y(), (
float)
box().minCorner().z()),
207 fvec3((
float)
box().minCorner().x(), (
float)
box().maxCorner().y(), (
float)
box().minCorner().z()),
208 fvec3((
float)
box().minCorner().x(), (
float)
box().minCorner().y(), (
float)
box().maxCorner().z()),
209 fvec3((
float)
box().maxCorner().x(), (
float)
box().minCorner().y(), (
float)
box().maxCorner().z()),
210 fvec3((
float)
box().maxCorner().x(), (
float)
box().maxCorner().y(), (
float)
box().maxCorner().z()),
211 fvec3((
float)
box().minCorner().x(), (
float)
box().maxCorner().y(), (
float)
box().maxCorner().z())
216 for(
int i=0; i<8; ++i)
218 cube_verts[i] = mat * cube_verts[i];
219 if (fabs(cube_verts[i].z()) < fabs(cube_verts[min_idx].z())) min_idx = i;
220 if (fabs(cube_verts[i].z()) > fabs(cube_verts[max_idx].z())) max_idx = i;
223 if (cube_verts[min_idx].z() > 0)
231 const int BOTTOM = 2;
234 const int FRONT = 16;
239 {0,1,-1,FRONT |BOTTOM}, {1,2,-1,FRONT|RIGHT}, {2,3,-1,FRONT|TOP}, {3,0,-1,FRONT |LEFT},
240 {4,5,-1,BACK |BOTTOM}, {5,6,-1,BACK |RIGHT}, {6,7,-1,BACK |TOP}, {7,4,-1,BACK |LEFT},
241 {1,5,-1,BOTTOM|RIGHT}, {2,6,-1,TOP |RIGHT}, {3,7,-1,TOP |LEFT}, {0,4,-1,BOTTOM|LEFT}
244 std::vector<fvec3> points;
245 std::vector<fvec3> points_t;
246 std::vector<fvec3> polygons;
247 std::vector<fvec3> polygons_t;
251 polygons.reserve(slice_count*5);
252 polygons_t.reserve(slice_count*5);
253 float zrange = cube_verts[max_idx].
z() - cube_verts[min_idx].
z();
254 float zstep = zrange/(slice_count+1);
256 for(
int islice=0; islice<slice_count; ++islice)
258 float z = cube_verts[max_idx].
z() - zstep*(islice+1);
259 fvec3 plane_o(0,0,z);
260 fvec3 plane_n(0,0,1.0f);
263 for(
int iedge=0; iedge<12; ++iedge)
265 edges[iedge].intersection = -1;
266 fvec3 vi = cube_verts[ edges[iedge].v0 ];
267 fvec3 eij = cube_verts[ edges[iedge].v1 ] - cube_verts[ edges[iedge].v0 ];
268 float denom =
dot(plane_n,eij);
271 float lambda = (z -
dot(plane_n,vi))/denom;
272 if (lambda<0 || lambda>1)
274 fvec3 v = vi + eij*lambda;
275 edges[iedge].intersection = (int)points.size();
279 fvec3 vt = a + b*lambda;
280 points_t.push_back(vt);
282 std::sort(edges, edges+12);
284 for(
int ie0=0; ie0<12-1; ++ie0)
286 if (edges[ie0].intersection == -1)
288 vert_idx[vert_idx_c++] = edges[ie0].intersection;
289 for(
int ie1=ie0+1; ie1<12; ++ie1)
291 if (edges[ie1].intersection == -1)
293 if( (edges[ie0].flags & edges[ie1].flags) )
295 Edge t = edges[ie0+1];
296 edges[ie0+1] = edges[ie1];
302 for(
int vc=0; vc<vert_idx_c-2; ++vc)
304 polygons.push_back(imat*points [vert_idx[0]]);
305 polygons.push_back(imat*points [vert_idx[vc+1]]);
306 polygons.push_back(imat*points [vert_idx[vc+2]]);
307 polygons_t.push_back(points_t[vert_idx[0]]);
308 polygons_t.push_back(points_t[vert_idx[vc+1]]);
309 polygons_t.push_back(points_t[vert_idx[vc+2]]);
312 for(
int ie0=0; ie0<12-1; ++ie0)
314 if (edges[ie0].intersection == -1)
316 if (edges[ie0+1].intersection == -1)
318 VL_CHECK(edges[ie0].flags & edges[ie0+1].flags)
328 vertex_array->
resize(polygons.size());
329 texcoo_array->
resize(polygons_t.size());
347 if (!img_size.
x() || !img_size.
y() || !img_size.
z())
349 Log::error(
"SlicedVolume::generateTextureCoordinates(): failed! The img_size passed does not represent a 3D image.\n");
353 float dx = 0.5f/img_size.
x();
354 float dy = 0.5f/img_size.
y();
355 float dz = 0.5f/img_size.
z();
357 float x0 = 0.0f + dx;
358 float x1 = 1.0f - dx;
359 float y0 = 0.0f + dy;
360 float y1 = 1.0f - dy;
361 float z0 = 0.0f + dz;
362 float z1 = 1.0f - dz;
366 fvec3(x0,y0,z0),
fvec3(x1,y0,z0),
fvec3(x1,y1,z0),
fvec3(x0,y1,z0),
367 fvec3(x0,y0,z1),
fvec3(x1,y0,z1),
fvec3(x1,y1,z1),
fvec3(x0,y1,z1),
374 if (!img_size.
x() || !img_size.
y() || !img_size.
z())
376 Log::error(
"SlicedVolume::setDisplayRegion(): failed! The size passed does not represent a 3D image.\n");
380 float dx = 0.5f/img_size.
x();
381 float dy = 0.5f/img_size.
y();
382 float dz = 0.5f/img_size.
z();
384 float x0 = min_corner.
x()/(float)img_size.
x() + dx;
385 float x1 = max_corner.
x()/(float)img_size.
x() - dx;
386 float y0 = min_corner.
y()/(float)img_size.
y() + dy;
387 float y1 = max_corner.
y()/(float)img_size.
y() - dy;
388 float z0 = min_corner.
z()/(float)img_size.
z() + dz;
389 float z1 = max_corner.
z()/(float)img_size.
z() - dz;
393 fvec3(x0,y0,z0),
fvec3(x1,y0,z0),
fvec3(x1,y1,z0),
fvec3(x0,y1,z0),
394 fvec3(x0,y0,z1),
fvec3(x1,y0,z1),
fvec3(x1,y1,z1),
fvec3(x0,y1,z1)
Associates a Renderable object to an Effect and Transform.
const mat4 & viewMatrix() const
Returns the Camera's view matrix (inverse of the modeling matrix).
Vector3< float > fvec3
A 3 components vector with float precision.
Transform * transform()
Returns the Transform bound tho an Actor.
int getUniformLocation(const char *name) const
Returns the binding index of the given uniform.
const T_Scalar & z() const
ref< Geometry > mGeometry
int sliceCount() const
Returns the number of slices used to render the volume.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
Vector3< T_Scalar > xyz() const
void generateTextureCoordinates(const ivec3 &size)
Generates a default set of texture coordinates for the 8 box corners of the volume based on the given...
Wraps a GLSL program to which you can bind vertex, fragment and geometry shaders. ...
const Collection< ActorEventCallback > * actorEventCallbacks() const
Returns the list of ActorEventCallback bound to an Actor.
SlicedVolume()
Constructor.
const Light * getLight(int light_index) const
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
Viewport * viewport()
The viewport bound to a camera.
Visualization Library main namespace.
const BufferObject * bufferObject() const
const fvec3 * texCoords() const
Returns the texture coordinates assigned to each of the 8 box corners of the volume.
float dot(float a, float b)
const unsigned char * ptr() const
Returns the pointer to the first element of the local buffer. Equivalent to bufferObject()->ptr() ...
T_Scalar getInverse(Matrix4 &dest) const
The AABB class implements an axis-aligned bounding box using vl::real precision.
float max(float a, float b)
void bindActor(Actor *)
Binds a SlicedVolume to an Actor so that the SlicedVolume can generate the viewport aligned slices' g...
An abstract class that represents all the objects that can be rendered.
Matrix4 & fill(T_Scalar val)
const mat4 & modelingMatrix() const
Returns the Camera's modelingMatrix() (inverse of the view matrix).
Transform * boundTransform()
const T_Scalar & y() const
void setBox(const AABB &box)
Defines the dimensions of the box enclosing the volume.
Manages most of the OpenGL rendering states responsible of the final aspect of the rendered objects...
Uniform * gocUniform(const char *name)
Equivalent to getUniformSet()->getUniform(name, get_mode)
const GLSLProgram * getGLSLProgram() const
Returns a GLSLProgram if it exists or NULL otherwise.
Vector3< T_Scalar > getT() const
const fvec4 & position() const
The position or direction of a light.
void setLod(int lod_index, Renderable *renderable)
Sets the Renderable object representing the LOD level specifed by lod_index.
Wraps the OpenGL function glLight().
const T_Scalar & x() const
The ref<> class is used to reference-count an Object.
Matrix4< float > fmat4
A 4x4 matrix using float precision.
Represents a virtual camera defining, among other things, the point of view from which scenes can be ...
void onActorRenderStarted(Actor *actor, real frame_clock, const Camera *cam, Renderable *renderable, const Shader *shader, int pass)
Event generated just before an Actor is rendered but after the render states are ready and setup...
const AABB & box() const
The dimensions of the box enclosing the volume.
Wraps the OpenGL function glDrawArrays().
const Actor * actor() const
Returns the currently bound actor.
virtual void updateUniforms(Actor *actor, real clock, const Camera *camera, Renderable *rend, const Shader *shader)
Updates the uniforms used by the GLSLProgram to render the volume each time the onActorRenderStarted(...