[Bf-blender-cvs] [6a91edb] openvdb: Add a level of detail scheme to reduce the number of voxels to be drawn.

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


Commit: 6a91edb8e0cf80c58239fa2480b7ce02473c0f34
Author: Kévin Dietrich
Date:   Wed Jun 17 17:50:39 2015 +0200
Branches: openvdb
https://developer.blender.org/rB6a91edb8e0cf80c58239fa2480b7ce02473c0f34

Add a level of detail scheme to reduce the number of voxels to be drawn.

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

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	release/scripts/startup/bl_ui/properties_physics_smoke.py
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/makesdna/DNA_smoke_types.h
M	source/blender/makesrna/intern/rna_smoke.c

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

diff --git a/intern/openvdb/intern/openvdb_render.cpp b/intern/openvdb/intern/openvdb_render.cpp
index 2dcd8ed..8851079 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, const bool draw_box)
+void OpenVDBPrimitive_draw_values(OpenVDBPrimitive *vdb_prim, float tolerance, float point_size, const bool draw_box, const int lod)
 {
 	using namespace openvdb;
 	using namespace openvdb::math;
@@ -179,6 +179,12 @@ void OpenVDBPrimitive_draw_values(OpenVDBPrimitive *vdb_prim, float tolerance, f
 	FloatGrid::Ptr grid = gridPtrCast<FloatGrid>(vdb_prim->getGridPtr());
 	std::vector<vertex> vertices, colors;
 
+	size_t i = 0;
+	float fac = static_cast<float>(lod) * 0.01f;
+	size_t num_voxels = grid->activeVoxelCount();
+	float num_points = std::max(1.0f, floorf(num_voxels * fac));
+	float lod_fl = floorf(num_voxels / num_points);
+
 	if (draw_box) {
 		CoordBBox bbox;
 		Vec3f wmin, wmax;
@@ -200,16 +206,20 @@ void OpenVDBPrimitive_draw_values(OpenVDBPrimitive *vdb_prim, float tolerance, f
 				continue;
 			}
 
-			iter.getBoundingBox(bbox);
+			if (fmod((float)i, lod_fl) == 0.0f) {
+				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);
 
-			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);
 
-			wmin = grid->indexToWorld(min);
-			wmax = grid->indexToWorld(max);
+				color = isNegative(value) ? voxel_color[1] : voxel_color[0];
+				add_box(&vertices, &colors, wmin, wmax, color);
+			}
 
-			color = isNegative(value) ? voxel_color[1] : voxel_color[0];
-			add_box(&vertices, &colors, wmin, wmax, color);
+			i++;
 		}
 	}
 	else {
@@ -220,9 +230,13 @@ void OpenVDBPrimitive_draw_values(OpenVDBPrimitive *vdb_prim, float tolerance, f
 				continue;
 			}
 
-			Vec3f point = grid->indexToWorld(iter.getCoord());
-			Vec3f color(value);
-			add_point(&vertices, &colors, point, color);
+			if (fmod((float)i, lod_fl) == 0.0f) {
+				Vec3f point = grid->indexToWorld(iter.getCoord());
+				Vec3f color(value);
+				add_point(&vertices, &colors, point, color);
+			}
+
+			i++;
 		}
 	}
 
diff --git a/intern/openvdb/intern/openvdb_render.h b/intern/openvdb/intern/openvdb_render.h
index 96b9a39..5fbabaa 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, const bool draw_box);
+void OpenVDBPrimitive_draw_values(OpenVDBPrimitive *vdb_prim, float tolerance, float point_size, const bool draw_box, const int lod);
 
 }
 
diff --git a/intern/openvdb/openvdb_capi.cpp b/intern/openvdb/openvdb_capi.cpp
index b81d698..4b506fb 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, const bool draw_box)
+void OpenVDB_draw_primitive_values(struct OpenVDBPrimitive *vdb_prim, float tolerance, float point_size, const bool draw_box, const int lod)
 {
-	internal::OpenVDBPrimitive_draw_values(vdb_prim, tolerance, point_size, draw_box);
+	internal::OpenVDBPrimitive_draw_values(vdb_prim, tolerance, point_size, draw_box, lod);
 }
diff --git a/intern/openvdb/openvdb_capi.h b/intern/openvdb/openvdb_capi.h
index cc28a21..45e0572 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, const bool draw_box);
+void OpenVDB_draw_primitive_values(struct OpenVDBPrimitive *vdb_prim, float tolerance, float point_size, const bool draw_box, const int lod);
 
 #ifdef __cplusplus
 }
diff --git a/release/scripts/startup/bl_ui/properties_physics_smoke.py b/release/scripts/startup/bl_ui/properties_physics_smoke.py
index ff103b1..3b9dd89 100644
--- a/release/scripts/startup/bl_ui/properties_physics_smoke.py
+++ b/release/scripts/startup/bl_ui/properties_physics_smoke.py
@@ -376,11 +376,13 @@ class PHYSICS_PT_smoke_openvdb(PhysicButtonsPanel, Panel):
         layout.label(text="Draw OpenVDB Data:")
         layout.prop_menu_enum(draw_data, "show_tree")
         layout.prop(draw_data, "voxel_drawing")
-        
+
         if draw_data.voxel_drawing in { 'POINT' }:
             row = layout.row()
             row.prop(draw_data, "tolerance")
             row.prop(draw_data, "point_size")
+            row = layout.row()
+            row.prop(draw_data, "lod")
 
 
 class PHYSICS_PT_smoke_field_weights(PhysicButtonsPanel, Panel):
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 6d23c3a..3dc36d0 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -8074,18 +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, false);
+							OpenVDB_draw_primitive_values(sds->density, draw_data->tolerance, draw_data->point_size, false, draw_data->lod);
 						if (draw_voxels && draw_data->voxel_drawing == DRAW_VOXELS_BOX)
-							OpenVDB_draw_primitive_values(sds->density, draw_data->tolerance, draw_data->point_size, true);
+							OpenVDB_draw_primitive_values(sds->density, draw_data->tolerance, draw_data->point_size, true, draw_data->lod);
 						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, false);
+							OpenVDB_draw_primitive_values(sds->density_high, draw_data->tolerance, draw_data->point_size, false, draw_data->lod);
 						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);
+							OpenVDB_draw_primitive_values(sds->density_high, draw_data->tolerance, draw_data->point_size, true, draw_data->lod);
 						if (draw_voxels && draw_data->voxel_drawing == DRAW_VOXELS_VOLUME)
 							render_volume = true;
 					}
diff --git a/source/blender/makesdna/DNA_smoke_types.h b/source/blender/makesdna/DNA_smoke_types.h
index 07c3eca..c7a5a24 100644
--- a/source/blender/makesdna/DNA_smoke_types.h
+++ b/source/blender/makesdna/DNA_smoke_types.h
@@ -173,6 +173,7 @@ typedef struct OpenVDBDrawData {
 	float point_size;     /* size of the voxels */
 	short flags;          /* which level of the tree to draw */
 	short voxel_drawing;  /* how to draw the voxels */
+	int lod;              /* level of detail */
 } OpenVDBDrawData;
 
 enum {
diff --git a/source/blender/makesrna/intern/rna_smoke.c b/source/blender/makesrna/intern/rna_smoke.c
index 05573f5..bfbfbda 100644
--- a/source/blender/makesrna/intern/rna_smoke.c
+++ b/source/blender/makesrna/intern/rna_smoke.c
@@ -406,6 +406,14 @@ static void rna_def_openvdb_draw_data(BlenderRNA *brna)
 	                         "Minimun value a voxel should have to be drawn");
 	RNA_def_property_update(prop, NC_GEOM | ND_DATA, NULL);
 
+	prop = RNA_def_property(srna, "lod", PROP_INT, PROP_NONE);
+	RNA_def_property_int_sdna(prop, NULL, "lod");
+	RNA_def_property_range(prop, 0, 100);
+	RNA_def_property_ui_range(prop, 0, 100, 1, -1);
+	RNA_def_property_ui_text(prop, "Level of Detail",
+	                         "Percentage of the number of voxels to draw");
+	RNA_def_property_update(prop, NC_GEOM | ND_DATA, NULL);
+
 	prop = RNA_def_property(srna, "point_size", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "point_size");
 	RNA_def_property_range(prop, 0.0, 10.0);




More information about the Bf-blender-cvs mailing list