[Bf-blender-cvs] [b0a9c01] temp-curve-draw: Initial cubic fitting, curve freehand drawing
Campbell Barton
noreply at git.blender.org
Wed Apr 13 16:34:47 CEST 2016
Commit: b0a9c014e732e0e3b911f2b81c3e02a29ca2e41c
Author: Campbell Barton
Date: Fri Apr 8 15:39:19 2016 +1000
Branches: temp-curve-draw
https://developer.blender.org/rBb0a9c014e732e0e3b911f2b81c3e02a29ca2e41c
Initial cubic fitting, curve freehand drawing
===================================================================
M build_files/cmake/macros.cmake
M extern/CMakeLists.txt
A extern/curve_fit_nd/CMakeLists.txt
A extern/curve_fit_nd/curve_fit_nd.h
A extern/curve_fit_nd/intern/curve_fit_corners_detect.c
A extern/curve_fit_nd/intern/curve_fit_cubic.c
A extern/curve_fit_nd/intern/curve_fit_inline.h
M release/scripts/startup/bl_ui/space_view3d_toolbar.py
M source/blender/editors/curve/CMakeLists.txt
M source/blender/editors/curve/curve_intern.h
M source/blender/editors/curve/curve_ops.c
A source/blender/editors/curve/editcurve_paint.c
M source/blender/makesdna/DNA_scene_types.h
M source/blender/makesrna/intern/rna_scene.c
===================================================================
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 2b7a43b..85bc400 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -578,6 +578,7 @@ function(SETUP_BLENDER_SORTED_LIBS)
ge_phys_bullet
bf_intern_smoke
extern_lzma
+ extern_curve_fit_nd
ge_logic_ketsji
extern_recastnavigation
ge_logic
diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt
index 1cce7dc..58e0c68 100644
--- a/extern/CMakeLists.txt
+++ b/extern/CMakeLists.txt
@@ -23,6 +23,9 @@
#
# ***** END GPL LICENSE BLOCK *****
+# Libs that adhere to strict flags
+add_subdirectory(curve_fit_nd)
+
# Otherwise we get warnings here that we cant fix in external projects
remove_strict_flags()
diff --git a/source/blender/editors/curve/CMakeLists.txt b/extern/curve_fit_nd/CMakeLists.txt
similarity index 66%
copy from source/blender/editors/curve/CMakeLists.txt
copy to extern/curve_fit_nd/CMakeLists.txt
index 83346e9..202071c 100644
--- a/source/blender/editors/curve/CMakeLists.txt
+++ b/extern/curve_fit_nd/CMakeLists.txt
@@ -14,19 +14,17 @@
# 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): Jacques Beaurain.
+# The Original Code is Copyright (C) 2013, Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): none yet.
#
# ***** END GPL LICENSE BLOCK *****
set(INC
- ../include
- ../../blenkernel
- ../../blenlib
- ../../blentranslation
- ../../makesdna
- ../../makesrna
- ../../windowmanager
- ../../../../intern/guardedalloc
+ .
)
set(INC_SYS
@@ -34,17 +32,11 @@ set(INC_SYS
)
set(SRC
- curve_ops.c
- editcurve.c
- editcurve_add.c
- editcurve_select.c
- editfont.c
+ intern/curve_fit_cubic.c
+ intern/curve_fit_corners_detect.c
- curve_intern.h
+ intern/curve_fit_inline.h
+ curve_fit_nd.h
)
-if(WITH_INTERNATIONAL)
- add_definitions(-DWITH_INTERNATIONAL)
-endif()
-
-blender_add_lib(bf_editor_curve "${SRC}" "${INC}" "${INC_SYS}")
+blender_add_lib(extern_curve_fit_nd "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/extern/curve_fit_nd/curve_fit_nd.h b/extern/curve_fit_nd/curve_fit_nd.h
new file mode 100644
index 0000000..a036311
--- /dev/null
+++ b/extern/curve_fit_nd/curve_fit_nd.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2016, DWANGO Co., Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __SPLINE_FIT__
+#define __SPLINE_FIT__
+
+
+/* spline_fit_cubic.c */
+
+/**
+ * Takes a flat array of points:
+ * `points[dims]`
+ *
+ * And calculates cubic (bezier) splines:
+ * `r_cubic_array[r_cubic_array_len][4][dims]`.
+ *
+ * Where each cubic has 0 and 3 for the points and indices 1 and 2 for the handles.
+ */
+
+int spline_fit_cubic_to_points_db(
+ const double *points,
+ const unsigned int points_len,
+ const unsigned int dims,
+ const double error,
+ const unsigned int *corners,
+ const unsigned int corners_len,
+
+ double **r_cubic_array, unsigned int *r_cubic_array_len);
+
+int spline_fit_cubic_to_points_fl(
+ const float *points,
+ const unsigned int points_len,
+ const unsigned int dims,
+ const float error,
+ const unsigned int *corners,
+ const unsigned int corners_len,
+
+ float **r_cubic_array, unsigned int *r_cubic_array_len);
+
+
+/* spline_fit_corners_detect.c */
+int spline_fit_corners_detect_db(
+ const double *points,
+ const unsigned int points_len,
+ const unsigned int dims,
+ const double radius_min,
+ const double radius_max,
+ const unsigned int samples_max,
+ const double angle_limit,
+
+ unsigned int **r_corners,
+ unsigned int *r_corners_len);
+
+int spline_fit_corners_detect_fl(
+ const float *points,
+ const unsigned int points_len,
+ const unsigned int dims,
+ const float radius_min,
+ const float radius_max,
+ const unsigned int samples_max,
+ const float angle_limit,
+
+ unsigned int **r_corners,
+ unsigned int *r_corners_len);
+
+#endif /* __SPLINE_FIT__ */
+
diff --git a/extern/curve_fit_nd/intern/curve_fit_corners_detect.c b/extern/curve_fit_nd/intern/curve_fit_corners_detect.c
new file mode 100644
index 0000000..48492f1
--- /dev/null
+++ b/extern/curve_fit_nd/intern/curve_fit_corners_detect.c
@@ -0,0 +1,447 @@
+/*
+ * Copyright (c) 2016, Blender Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <math.h>
+#include <float.h>
+#include <stdbool.h>
+#include <assert.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "../curve_fit_nd.h"
+
+typedef unsigned int uint;
+
+#include "curve_fit_inline.h"
+
+#if !defined(_MSC_VER)
+# define USE_VLA
+#endif
+
+#ifdef USE_VLA
+# ifdef __GNUC__
+# pragma GCC diagnostic ignored "-Wvla"
+# endif
+#else
+# ifdef __GNUC__
+# pragma GCC diagnostic error "-Wvla"
+# endif
+#endif
+
+/* -------------------------------------------------------------------- */
+
+/** \name Simple Vector Math Lib
+ * \{ */
+
+static double angle_vnvnvn_cos(
+ const double v0[], const double v1[], const double v2[],
+ const uint dims)
+{
+#ifdef USE_VLA
+ double dvec0[dims];
+ double dvec1[dims];
+#else
+ double *dvec0 = alloca(sizeof(double) * dims);
+ double *dvec1 = alloca(sizeof(double) * dims);
+#endif
+ normalize_vn_vnvn(dvec0, v0, v1, dims);
+ normalize_vn_vnvn(dvec1, v1, v2, dims);
+ double d = dot_vnvn(dvec0, dvec1, dims);
+ /* sanity check */
+ d = max(-1.0, min(1.0, d));
+ return d;
+}
+
+static double angle_vnvnvn(
+ const double v0[], const double v1[], const double v2[],
+ const uint dims)
+{
+ return acos(angle_vnvnvn_cos(v0, v1, v2, dims));
+}
+
+
+static bool isect_line_sphere_vn(
+ const double l1[],
+ const double l2[],
+ const double sp[],
+ const double r,
+ uint dims,
+
+ double r_p1[]
+#if 0 /* UNUSED */
+ double r_p2[]
+#endif
+ )
+{
+#ifdef USE_VLA
+ double ldir[dims];
+ double tvec[dims];
+#else
+ double *ldir = alloca(sizeof(double) * dims);
+ double *tvec = alloca(sizeof(double) * dims);
+#endif
+
+ sub_vn_vnvn(ldir, l2, l1, dims);
+
+ sub_vn_vnvn(tvec, l1, sp, dims);
+ const double a = len_squared_vn(ldir, dims);
+ const double b = 2.0 * dot_vnvn(ldir, tvec, dims);
+ const double c = len_squared_vn(sp, dims) + len_squared_vn(l1, dims) - (2.0 * dot_vnvn(sp, l1, dims)) - sq(r);
+
+ const double i = b * b - 4.0 * a * c;
+
+ if ((i < 0.0) || (a == 0.0)) {
+ return false;
+ }
+ else if (i == 0.0) {
+ /* one intersection */
+ const double mu = -b / (2.0 * a);
+ mul_vnvn_fl(r_p1, ldir, mu, dims);
+ iadd_vnvn(r_p1, l1, dims);
+ return true;
+ }
+ else if (i > 0.0) {
+ /* # avoid calc twice */
+ const double i_sqrt = sqrt(i);
+ double mu;
+
+ /* Note: when l1 is inside the sphere and l2 is outside.
+ * the first intersection point will always be between the pair. */
+
+ /* first intersection */
+ mu = (-b + i_sqrt) / (2.0 * a);
+ mul_vnvn_fl(r_p1, ldir, mu, dims);
+ iadd_vn
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list