[Bf-blender-cvs] [198fa02] openvdb: Add possibility to draw voxels as boxes.

Kévin Dietrich noreply at git.blender.org
Thu Jun 18 07:01:06 CEST 2015


Commit: 198fa023c1261b6ae13064563dc6a482aea8aa6e
Author: Kévin Dietrich
Date:   Wed Jun 17 16:49:30 2015 +0200
Branches: openvdb
https://developer.blender.org/rB198fa023c1261b6ae13064563dc6a482aea8aa6e

Add possibility to draw voxels as boxes.

The colors are set to be the same as the VDB paper, just like for the
tree. They are drawn perfectly, but that'll for the moment.

===================================================================

M	intern/openvdb/intern/openvdb_render.cpp
M	intern/openvdb/intern/openvdb_render.h
M	intern/openvdb/openvdb_capi.cpp
M	intern/openvdb/openvdb_capi.h
M	source/blender/editors/space_view3d/drawobject.c

===================================================================

diff --git a/intern/openvdb/intern/openvdb_render.cpp b/intern/openvdb/intern/openvdb_render.cpp
index c0d55c7..2dcd8ed 100644
--- a/intern/openvdb/intern/openvdb_render.cpp
+++ b/intern/openvdb/intern/openvdb_render.cpp
@@ -171,7 +171,7 @@ void OpenVDBPrimitive_draw_tree(OpenVDBPrimitive *vdb_prim, const bool draw_root
 	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 }
 
-void OpenVDBPrimitive_draw_values(OpenVDBPrimitive *vdb_prim, float tolerance, float point_size)
+void OpenVDBPrimitive_draw_values(OpenVDBPrimitive *vdb_prim, float tolerance, float point_size, const bool draw_box)
 {
 	using namespace openvdb;
 	using namespace openvdb::math;
@@ -179,29 +179,69 @@ void OpenVDBPrimitive_draw_values(OpenVDBPrimitive *vdb_prim, float tolerance, f
 	FloatGrid::Ptr grid = gridPtrCast<FloatGrid>(vdb_prim->getGridPtr());
 	std::vector<vertex> vertices, colors;
 
-	for (FloatGrid::ValueOnCIter iter = grid->cbeginValueOn(); iter; ++iter) {
-		float value = iter.getValue();
+	if (draw_box) {
+		CoordBBox bbox;
+		Vec3f wmin, wmax;
 
-		if (value < tolerance) {
-			continue;
+		/* The following colors are meant to be the same as in the example images of
+		 * "VDB: High-Resolution Sparse Volumes With Dynamic Topology",
+		 * K. Museth, 2013 */
+		Vec3f voxel_color[2] = {
+		    Vec3f(0.523f, 0.0325175f, 0.0325175f), // positive values
+		    Vec3f(0.92f, 0.92f, 0.92f), // negative values
+		};
+
+		Vec3f color;
+
+		for (FloatGrid::ValueOnCIter iter = grid->cbeginValueOn(); iter; ++iter) {
+			float value = iter.getValue();
+
+			if (value < tolerance) {
+				continue;
+			}
+
+			iter.getBoundingBox(bbox);
+
+			const Vec3f min(bbox.min().x() - 0.5f, bbox.min().y() - 0.5f, bbox.min().z() - 0.5f);
+			const Vec3f max(bbox.max().x() + 0.5f, bbox.max().y() + 0.5f, bbox.max().z() + 0.5f);
+
+			wmin = grid->indexToWorld(min);
+			wmax = grid->indexToWorld(max);
+
+			color = isNegative(value) ? voxel_color[1] : voxel_color[0];
+			add_box(&vertices, &colors, wmin, wmax, color);
 		}
+	}
+	else {
+		for (FloatGrid::ValueOnCIter iter = grid->cbeginValueOn(); iter; ++iter) {
+			float value = iter.getValue();
 
-		Vec3f point = grid->indexToWorld(iter.getCoord());
-		Vec3f color(value);
-		add_point(&vertices, &colors, point, color);
+			if (value < tolerance) {
+				continue;
+			}
+
+			Vec3f point = grid->indexToWorld(iter.getCoord());
+			Vec3f color(value);
+			add_point(&vertices, &colors, point, color);
+		}
 	}
 
 	glPointSize(point_size);
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_COLOR_ARRAY);
-	glEnable(GL_BLEND);
+	glEnable(GL_LIGHTING);
+	glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
+	glEnable(GL_COLOR_MATERIAL);
+	glShadeModel(GL_SMOOTH);
 
 	glVertexPointer(3, GL_FLOAT, 0, &vertices[0]);
 	glColorPointer(3, GL_FLOAT, 0, &colors[0]);
-	glDrawArrays(GL_POINTS, 0, vertices.size());
+	glDrawArrays(draw_box ? GL_QUADS : GL_POINTS, 0, vertices.size());
 
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_COLOR_ARRAY);
+	glDisable(GL_COLOR_MATERIAL);
+	glDisable(GL_LIGHTING);
 }
 
 }
diff --git a/intern/openvdb/intern/openvdb_render.h b/intern/openvdb/intern/openvdb_render.h
index 03db84a..96b9a39 100644
--- a/intern/openvdb/intern/openvdb_render.h
+++ b/intern/openvdb/intern/openvdb_render.h
@@ -9,7 +9,7 @@ void OpenVDBPrimitive_draw_tree(OpenVDBPrimitive *vdb_prim, const bool draw_root
                                 const bool draw_level_1, const bool draw_level_2,
                                 const bool draw_leaves);
 
-void OpenVDBPrimitive_draw_values(OpenVDBPrimitive *vdb_prim, float tolerance, float point_size);
+void OpenVDBPrimitive_draw_values(OpenVDBPrimitive *vdb_prim, float tolerance, float point_size, const bool draw_box);
 
 }
 
diff --git a/intern/openvdb/openvdb_capi.cpp b/intern/openvdb/openvdb_capi.cpp
index d3241df..b81d698 100644
--- a/intern/openvdb/openvdb_capi.cpp
+++ b/intern/openvdb/openvdb_capi.cpp
@@ -247,7 +247,7 @@ void OpenVDB_draw_primitive(OpenVDBPrimitive *vdb_prim,
     internal::OpenVDBPrimitive_draw_tree(vdb_prim, draw_root, draw_level_1, draw_level_2, draw_leaves);
 }
 
-void OpenVDB_draw_primitive_values(struct OpenVDBPrimitive *vdb_prim, float tolerance, float point_size)
+void OpenVDB_draw_primitive_values(struct OpenVDBPrimitive *vdb_prim, float tolerance, float point_size, const bool draw_box)
 {
-	internal::OpenVDBPrimitive_draw_values(vdb_prim, tolerance, point_size);
+	internal::OpenVDBPrimitive_draw_values(vdb_prim, tolerance, point_size, draw_box);
 }
diff --git a/intern/openvdb/openvdb_capi.h b/intern/openvdb/openvdb_capi.h
index d15d616..cc28a21 100644
--- a/intern/openvdb/openvdb_capi.h
+++ b/intern/openvdb/openvdb_capi.h
@@ -124,7 +124,7 @@ void OpenVDB_draw_primitive(struct OpenVDBPrimitive *vdb_prim,
                             const bool draw_level_2,
                             const bool draw_leaves);
 
-void OpenVDB_draw_primitive_values(struct OpenVDBPrimitive *vdb_prim, float tolerance, float point_size);
+void OpenVDB_draw_primitive_values(struct OpenVDBPrimitive *vdb_prim, float tolerance, float point_size, const bool draw_box);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index a613a02..6d23c3a 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -8074,14 +8074,18 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
 					if (sds->density) {
 						OpenVDB_draw_primitive(sds->density, draw_root, draw_level_1, draw_level_2, draw_leaves);
 						if (draw_voxels && draw_data->voxel_drawing == DRAW_VOXELS_POINT)
-							OpenVDB_draw_primitive_values(sds->density, draw_data->tolerance, draw_data->point_size);
+							OpenVDB_draw_primitive_values(sds->density, draw_data->tolerance, draw_data->point_size, false);
+						if (draw_voxels && draw_data->voxel_drawing == DRAW_VOXELS_BOX)
+							OpenVDB_draw_primitive_values(sds->density, draw_data->tolerance, draw_data->point_size, true);
 						if (draw_voxels && draw_data->voxel_drawing == DRAW_VOXELS_VOLUME)
 							render_volume = true;
 					}
 					if (sds->density_high) {
 						OpenVDB_draw_primitive(sds->density_high, draw_root, draw_level_1, draw_level_2, draw_leaves);
 						if (draw_voxels && draw_data->voxel_drawing == DRAW_VOXELS_POINT)
-							OpenVDB_draw_primitive_values(sds->density_high, draw_data->tolerance, draw_data->point_size);
+							OpenVDB_draw_primitive_values(sds->density_high, draw_data->tolerance, draw_data->point_size, false);
+						if (draw_voxels && draw_data->voxel_drawing == DRAW_VOXELS_BOX)
+							OpenVDB_draw_primitive_values(sds->density_high, draw_data->tolerance, draw_data->point_size, true);
 						if (draw_voxels && draw_data->voxel_drawing == DRAW_VOXELS_VOLUME)
 							render_volume = true;
 					}




More information about the Bf-blender-cvs mailing list