[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43010] trunk/blender: Add remesh modifier (dual contouring).

Nicholas Bishop nicholasbishop at gmail.com
Fri Dec 30 22:11:43 CET 2011


Revision: 43010
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43010
Author:   nicholasbishop
Date:     2011-12-30 21:11:40 +0000 (Fri, 30 Dec 2011)
Log Message:
-----------
Add remesh modifier (dual contouring).

This patch adds a new remeshing modifier. The algorithm is based on
the paper "Dual Contouring of Hermite Data", and the implementation
was contributed to Blender by Dr. Tao Ju.

The contributed code is in intern/dualcon, and was modified to compile
under gcc and work on 64-bit systems. Files not needed for Blender
were removed and a small C wrapper was added in order to interface it
with Blender. The rest of the patch is just standard modifier stuff.

Reviewed by Sergey, code review link:
http://codereview.appspot.com/5491053/

The remesh icon was contributed by Zafio:
http://blenderartists.org/forum/showthread.php?240751-Request-for-modifier-icon/page2.
Thanks to everyone in that thread for the icon proposals and
discussion.

Documentation and examples on the Blender wiki:
http://wiki.blender.org/index.php/User:Nicholasbishop/RemeshModifier

In case the history is needed for anything, check the remesh-modifier
branch of this git repository:
https://gitorious.org/~nicholasbishop/blenderprojects/nicholasbishop-blender

Modified Paths:
--------------
    trunk/blender/intern/CMakeLists.txt
    trunk/blender/intern/SConscript
    trunk/blender/release/datafiles/blender_icons.png
    trunk/blender/release/scripts/startup/bl_ui/properties_data_modifier.py
    trunk/blender/source/blender/blenkernel/BKE_mesh.h
    trunk/blender/source/blender/editors/datafiles/blender_icons.png.c
    trunk/blender/source/blender/editors/include/UI_icons.h
    trunk/blender/source/blender/makesdna/DNA_modifier_types.h
    trunk/blender/source/blender/makesrna/intern/rna_modifier.c
    trunk/blender/source/blender/modifiers/CMakeLists.txt
    trunk/blender/source/blender/modifiers/MOD_modifiertypes.h
    trunk/blender/source/blender/modifiers/SConscript
    trunk/blender/source/blender/modifiers/intern/MOD_util.c
    trunk/blender/source/blenderplayer/bad_level_call_stubs/stubs.c
    trunk/blender/source/creator/CMakeLists.txt

Added Paths:
-----------
    trunk/blender/intern/dualcon/
    trunk/blender/intern/dualcon/CMakeLists.txt
    trunk/blender/intern/dualcon/SConscript
    trunk/blender/intern/dualcon/dualcon.h
    trunk/blender/intern/dualcon/intern/
    trunk/blender/intern/dualcon/intern/GeoCommon.h
    trunk/blender/intern/dualcon/intern/MemoryAllocator.h
    trunk/blender/intern/dualcon/intern/ModelReader.h
    trunk/blender/intern/dualcon/intern/Projections.cpp
    trunk/blender/intern/dualcon/intern/Projections.h
    trunk/blender/intern/dualcon/intern/Queue.h
    trunk/blender/intern/dualcon/intern/cubes.h
    trunk/blender/intern/dualcon/intern/dualcon_c_api.cpp
    trunk/blender/intern/dualcon/intern/manifold_table.cpp
    trunk/blender/intern/dualcon/intern/manifold_table.h
    trunk/blender/intern/dualcon/intern/marching_cubes_table.cpp
    trunk/blender/intern/dualcon/intern/marching_cubes_table.h
    trunk/blender/intern/dualcon/intern/octree.cpp
    trunk/blender/intern/dualcon/intern/octree.h
    trunk/blender/intern/dualcon/intern/readme.txt
    trunk/blender/source/blender/modifiers/intern/MOD_remesh.c

Modified: trunk/blender/intern/CMakeLists.txt
===================================================================
--- trunk/blender/intern/CMakeLists.txt	2011-12-30 21:10:21 UTC (rev 43009)
+++ trunk/blender/intern/CMakeLists.txt	2011-12-30 21:11:40 UTC (rev 43010)
@@ -31,6 +31,7 @@
 add_subdirectory(iksolver)
 add_subdirectory(opennl)
 add_subdirectory(mikktspace)
+add_subdirectory(dualcon)
 
 if(WITH_AUDASPACE)
 	add_subdirectory(audaspace)

Modified: trunk/blender/intern/SConscript
===================================================================
--- trunk/blender/intern/SConscript	2011-12-30 21:10:21 UTC (rev 43009)
+++ trunk/blender/intern/SConscript	2011-12-30 21:11:40 UTC (rev 43010)
@@ -9,6 +9,7 @@
             'container/SConscript',
             'memutil/SConscript/',
             'decimation/SConscript',
+            'dualcon/SConscript',
             'iksolver/SConscript',
             'itasc/SConscript',
             'boolop/SConscript',

Added: trunk/blender/intern/dualcon/CMakeLists.txt
===================================================================
--- trunk/blender/intern/dualcon/CMakeLists.txt	                        (rev 0)
+++ trunk/blender/intern/dualcon/CMakeLists.txt	2011-12-30 21:11:40 UTC (rev 43010)
@@ -0,0 +1,46 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+	.
+	intern
+	../../extern/Eigen3
+)
+
+set(SRC
+	intern/manifold_table.cpp
+	intern/marching_cubes_table.cpp
+	intern/octree.cpp
+	intern/Projections.cpp
+	
+	intern/cubes.h
+	intern/GeoCommon.h
+	intern/manifold_table.h
+	intern/marching_cubes_table.h
+	intern/MemoryAllocator.h
+	intern/ModelReader.h
+	intern/octree.h
+	intern/Projections.h
+	intern/Queue.h
+
+	intern/dualcon_c_api.cpp
+	dualcon.h
+)
+
+blender_add_lib(bf_intern_dualcon "${SRC}" "${INC}" "")
+

Added: trunk/blender/intern/dualcon/SConscript
===================================================================
--- trunk/blender/intern/dualcon/SConscript	                        (rev 0)
+++ trunk/blender/intern/dualcon/SConscript	2011-12-30 21:11:40 UTC (rev 43010)
@@ -0,0 +1,9 @@
+#!/usr/bin/python
+Import ('env')
+
+sources = env.Glob('intern/*.cpp')
+
+incs = '. ../../extern/Eigen3'
+defs = ''
+
+env.BlenderLib ('bf_intern_dualcon', sources, Split(incs), Split(defs), libtype=['intern'], priority=[100] )

Added: trunk/blender/intern/dualcon/dualcon.h
===================================================================
--- trunk/blender/intern/dualcon/dualcon.h	                        (rev 0)
+++ trunk/blender/intern/dualcon/dualcon.h	2011-12-30 21:11:40 UTC (rev 43010)
@@ -0,0 +1,95 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Nicholas Bishop
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef DUALCON_H
+#define DUALCON_H
+
+#ifdef __cplusplus
+extern "C" { 
+#endif
+
+typedef float (*DualConCo)[3];
+typedef unsigned int (*DualConFaces)[4];
+struct DerivedMesh;
+
+typedef struct DualConInput {
+	DualConCo co;
+	int co_stride;
+	int totco;
+	
+	DualConFaces faces;
+	int face_stride;
+	int totface;
+	
+	float min[3], max[3];
+} DualConInput;
+
+/* callback for allocating memory for output */
+typedef void *(*DualConAllocOutput)(int totvert, int totquad);
+/* callback for adding a new vertex to the output */
+typedef void (*DualConAddVert)(void *output, const float co[3]);
+/* callback for adding a new quad to the output */
+typedef void (*DualConAddQuad)(void *output, const int vert_indices[4]);
+
+typedef enum {
+	DUALCON_FLOOD_FILL = 1,
+} DualConFlags;
+
+typedef enum {
+	/* blocky */
+	DUALCON_CENTROID,
+	/* smooth */
+	DUALCON_MASS_POINT,
+	/* keeps sharp edges */
+	DUALCON_SHARP_FEATURES,
+} DualConMode;
+
+/* Usage:
+   
+   The three callback arguments are used for creating the output
+   mesh. The alloc_output callback takes the total number of vertices
+   and faces (quads) that will be in the output. It should allocate
+   and return a structure to hold the output mesh. The add_vert and
+   add_quad callbacks will then be called for each new vertex and
+   quad, and the callback should add the new mesh elements to the
+   structure.
+*/
+void *dualcon(const DualConInput *input_mesh,
+			  /* callbacks for output */
+			  DualConAllocOutput alloc_output,
+			  DualConAddVert add_vert,
+			  DualConAddQuad add_quad,
+
+			  /* flags and settings to control the remeshing
+				 algorithm */
+			  DualConFlags flags,
+			  DualConMode mode,
+			  float threshold,
+			  float hermite_num,
+			  float scale,
+			  int depth);
+
+#ifdef __cplusplus
+} 
+#endif
+
+#endif

Added: trunk/blender/intern/dualcon/intern/GeoCommon.h
===================================================================
--- trunk/blender/intern/dualcon/intern/GeoCommon.h	                        (rev 0)
+++ trunk/blender/intern/dualcon/intern/GeoCommon.h	2011-12-30 21:11:40 UTC (rev 43010)
@@ -0,0 +1,69 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Tao Ju
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef GEOCOMMON_H
+#define GEOCOMMON_H
+
+#define UCHAR unsigned char
+#define USHORT unsigned short
+
+#define USE_MINIMIZER
+
+/**
+ * Structure definitions for points and triangles.
+ *
+ * @author Tao Ju
+ */
+
+
+// 3d point with integer coordinates
+typedef struct
+{
+	int x, y, z;
+} Point3i;
+
+typedef struct
+{
+	Point3i begin;
+	Point3i end;
+} BoundingBox;
+
+// triangle that points to three vertices
+typedef struct 
+{
+	float vt[3][3] ;
+} Triangle;
+
+// 3d point with float coordinates
+typedef struct
+{
+	float x, y, z;
+} Point3f;
+
+typedef struct
+{
+	Point3f begin;
+	Point3f end;
+} BoundingBoxf;
+
+
+#endif

Added: trunk/blender/intern/dualcon/intern/MemoryAllocator.h
===================================================================
--- trunk/blender/intern/dualcon/intern/MemoryAllocator.h	                        (rev 0)
+++ trunk/blender/intern/dualcon/intern/MemoryAllocator.h	2011-12-30 21:11:40 UTC (rev 43010)
@@ -0,0 +1,219 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Tao Ju
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef MEMORYALLOCATOR_H
+#define MEMORYALLOCATOR_H
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define HEAP_BASE 16
+#define UCHAR unsigned char
+
+/**
+ * Customized memory allocators that allocates/deallocates memory in chunks
+ *
+ * @author Tao Ju
+ */
+
+
+
+/**
+ * Base class of memory allocators
+ */
+class VirtualMemoryAllocator
+{
+public:
+	virtual UCHAR * allocate( ) = 0 ;
+	virtual void deallocate( UCHAR * obj ) = 0 ;
+	virtual void destroy( ) = 0 ;
+	virtual void printInfo( ) = 0 ;
+
+	virtual int getAllocated( ) = 0 ;
+	virtual int getAll( ) = 0 ;
+	virtual int getBytes( ) = 0 ;
+};
+
+/**
+ * Dynamic memory allocator - allows allocation/deallocation
+ * 
+ * Note: there are 4 bytes overhead for each allocated yet unused object.
+ */
+template < int N >
+class MemoryAllocator : public VirtualMemoryAllocator
+{
+private:
+
+	/// Constants
+	int HEAP_UNIT, HEAP_MASK ;
+
+	/// Data array
+	UCHAR ** data ;
+
+	/// Allocation stack
+	UCHAR *** stack ;
+
+	/// Number of data blocks
+	int datablocknum ;
+
+	/// Number of stack blocks
+	int stackblocknum ;
+
+	/// Size of stack
+	int stacksize ;
+
+	/// Number of available objects on stack
+	int available ;
+
+	/**
+	 * Allocate a memory block
+	 */
+	void allocateDataBlock ( )
+	{
+		// Allocate a data block
+		datablocknum += 1 ;
+		data = ( UCHAR ** )realloc( data, sizeof ( UCHAR * ) * datablocknum ) ;
+		data[ datablocknum - 1 ] = ( UCHAR * )malloc( HEAP_UNIT * N ) ;
+
+		// Update allocation stack
+		for ( int i = 0 ; i < HEAP_UNIT ; i ++ )
+		{

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list