[Bf-blender-cvs] [ae8327d] master: Mask: add option to detect self intersections
Campbell Barton
noreply at git.blender.org
Thu Feb 13 09:16:16 CET 2014
Commit: ae8327dbf3afcdb6a6a0335aceeaa58600d7f1d3
Author: Campbell Barton
Date: Thu Feb 13 19:09:28 2014 +1100
https://developer.blender.org/rBae8327dbf3afcdb6a6a0335aceeaa58600d7f1d3
Mask: add option to detect self intersections
===================================================================
M release/scripts/startup/bl_ui/properties_mask_common.py
M source/blender/blenkernel/intern/displist.c
M source/blender/blenkernel/intern/mask_rasterize.c
M source/blender/blenlib/BLI_scanfill.h
M source/blender/blenlib/CMakeLists.txt
M source/blender/blenlib/intern/scanfill.c
A source/blender/blenlib/intern/scanfill_utils.c
M source/blender/bmesh/operators/bmo_triangulate.c
M source/blender/makesdna/DNA_mask_types.h
M source/blender/makesrna/intern/rna_mask.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_mask_common.py b/release/scripts/startup/bl_ui/properties_mask_common.py
index 7e8873e..a19f425 100644
--- a/release/scripts/startup/bl_ui/properties_mask_common.py
+++ b/release/scripts/startup/bl_ui/properties_mask_common.py
@@ -108,6 +108,7 @@ class MASK_PT_layers:
layout.prop(active_layer, "falloff")
row = layout.row(align=True)
+ layout.prop(active_layer, "use_fill_overlap")
layout.prop(active_layer, "use_fill_holes")
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index 517c832..07890e8 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -459,6 +459,7 @@ void BKE_displist_fill(ListBase *dispbase, ListBase *to, const float normal_proj
float *f1;
int colnr = 0, charidx = 0, cont = 1, tot, a, *index, nextcol = 0;
int totvert;
+ const int scanfill_flag = BLI_SCANFILL_CALC_REMOVE_DOUBLES | BLI_SCANFILL_CALC_POLYS | BLI_SCANFILL_CALC_HOLES;
if (dispbase == NULL)
return;
@@ -519,7 +520,7 @@ void BKE_displist_fill(ListBase *dispbase, ListBase *to, const float normal_proj
/* XXX (obedit && obedit->actcol) ? (obedit->actcol-1) : 0)) { */
if (totvert && (tot = BLI_scanfill_calc_ex(&sf_ctx,
- BLI_SCANFILL_CALC_REMOVE_DOUBLES | BLI_SCANFILL_CALC_HOLES,
+ scanfill_flag,
normal_proj)))
{
if (tot) {
diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c
index 694f892..2c60f52 100644
--- a/source/blender/blenkernel/intern/mask_rasterize.c
+++ b/source/blender/blenkernel/intern/mask_rasterize.c
@@ -918,6 +918,10 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mas
unsigned int face_index;
int scanfill_flag = 0;
+ bool is_isect = false;
+ ListBase isect_remvertbase = {NULL, NULL};
+ ListBase isect_remedgebase = {NULL, NULL};
+
/* now we have all the splines */
face_coords = MEM_mallocN((sizeof(float) * 3) * sf_vert_tot, "maskrast_face_coords");
@@ -941,12 +945,50 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mas
cos += 3;
}
+
+ /* --- inefficient self-intersect case --- */
+ /* if self intersections are found, its too trickty to attempt to map vertices
+ * so just realloc and add entirely new vertices - the result of the self-intersect check
+ */
+ if ((masklay->flag & MASK_LAYERFLAG_FILL_OVERLAP) &&
+ (is_isect = BLI_scanfill_calc_self_isect(&sf_ctx,
+ &isect_remvertbase,
+ &isect_remedgebase)))
+ {
+ unsigned int sf_vert_tot_isect = (unsigned int)BLI_countlist(&sf_ctx.fillvertbase);
+ unsigned int i = sf_vert_tot;
+
+ face_coords = MEM_reallocN(face_coords, sizeof(float[3]) * (sf_vert_tot + sf_vert_tot_isect));
+
+ cos = (float *)&face_coords[sf_vert_tot][0];
+
+ for (sf_vert = sf_ctx.fillvertbase.first; sf_vert; sf_vert = sf_vert->next) {
+ copy_v3_v3(cos, sf_vert->co);
+ sf_vert->tmp.u = i++;
+ cos += 3;
+ }
+
+ sf_vert_tot += sf_vert_tot_isect;
+
+ /* we need to calc polys after self intersect */
+ scanfill_flag |= BLI_SCANFILL_CALC_POLYS;
+ }
+ /* --- end inefficient code --- */
+
+
/* main scan-fill */
if ((masklay->flag & MASK_LAYERFLAG_FILL_DISCRETE) == 0)
scanfill_flag |= BLI_SCANFILL_CALC_HOLES;
sf_tri_tot = (unsigned int)BLI_scanfill_calc_ex(&sf_ctx, scanfill_flag, zvec);
+ if (is_isect) {
+ /* add removed data back, we only need edges for feather,
+ * but add verts back so they get freed along with others */
+ BLI_movelisttolist(&sf_ctx.fillvertbase, &isect_remvertbase);
+ BLI_movelisttolist(&sf_ctx.filledgebase, &isect_remedgebase);
+ }
+
face_array = MEM_mallocN(sizeof(*face_array) * ((size_t)sf_tri_tot + (size_t)tot_feather_quads), "maskrast_face_index");
face_index = 0;
diff --git a/source/blender/blenlib/BLI_scanfill.h b/source/blender/blenlib/BLI_scanfill.h
index c564fce..4fca3fb 100644
--- a/source/blender/blenlib/BLI_scanfill.h
+++ b/source/blender/blenlib/BLI_scanfill.h
@@ -56,6 +56,13 @@ typedef struct ScanFillContext {
#define BLI_SCANFILL_ARENA_SIZE MEM_SIZE_OPTIMAL(1 << 14)
+/**
+ * \note this is USHRT_MAX so incrementing will set to zero
+ * which happens if callers choose to increment #ScanFillContext.poly_nr before adding each curve.
+ * Nowhere else in scanfill do we make use of intentional overflow like this.
+ */
+#define SF_POLY_UNSET ((unsigned short)-1)
+
typedef struct ScanFillVert {
struct ScanFillVert *next, *prev;
union {
@@ -101,12 +108,15 @@ enum {
* removing double verts. - campbell */
BLI_SCANFILL_CALC_REMOVE_DOUBLES = (1 << 1),
+ /* calculate isolated polygons */
+ BLI_SCANFILL_CALC_POLYS = (1 << 2),
+
/* note: This flag removes checks for overlapping polygons.
* when this flag is set, we'll never get back more faces then (totvert - 2) */
- BLI_SCANFILL_CALC_HOLES = (1 << 2),
+ BLI_SCANFILL_CALC_HOLES = (1 << 3),
/* checks valid edge users - can skip for simple loops */
- BLI_SCANFILL_CALC_LOOSE = (1 << 3),
+ BLI_SCANFILL_CALC_LOOSE = (1 << 4),
};
void BLI_scanfill_begin(ScanFillContext *sf_ctx);
unsigned int BLI_scanfill_calc(ScanFillContext *sf_ctx, const int flag);
@@ -117,6 +127,13 @@ void BLI_scanfill_end(ScanFillContext *sf_ctx);
void BLI_scanfill_begin_arena(ScanFillContext *sf_ctx, struct MemArena *arena);
void BLI_scanfill_end_arena(ScanFillContext *sf_ctx, struct MemArena *arena);
+
+/* scanfill_utils.c */
+bool BLI_scanfill_calc_self_isect(
+ ScanFillContext *sf_ctx,
+ ListBase *fillvertbase,
+ ListBase *filledgebase);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 80e6292..9194bb5 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -87,6 +87,7 @@ set(SRC
intern/rand.c
intern/rct.c
intern/scanfill.c
+ intern/scanfill_utils.c
intern/smallhash.c
intern/sort.c
intern/sort_utils.c
diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c
index c01a4a5..0610414 100644
--- a/source/blender/blenlib/intern/scanfill.c
+++ b/source/blender/blenlib/intern/scanfill.c
@@ -38,7 +38,6 @@
#include "MEM_guardedalloc.h"
-#include "BLI_callbacks.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_memarena.h"
@@ -85,16 +84,6 @@ typedef struct ScanFillVertLink {
#define SF_POLY_NEW 0 /* all polys initialized to this */
#define SF_POLY_VALID 1 /* has at least 3 verts */
-
-/**
- * \note this is USHRT_MAX so incrementing will set to zero
- * which happens if callers choose to increment #ScanFillContext.poly_nr before adding each curve.
- * Nowhere else in scanfill do we make use of intentional overflow like this.
- */
-#define SF_POLY_UNSET USHRT_MAX
-
-
-
/* **** FUNCTIONS FOR QSORT *************************** */
@@ -903,7 +892,7 @@ unsigned int BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const
sf_ctx->poly_nr = SF_POLY_UNSET;
}
- if (flag & BLI_SCANFILL_CALC_HOLES && (poly == 0)) {
+ if (flag & BLI_SCANFILL_CALC_POLYS && (poly == 0)) {
for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) {
mul_v2_m3v3(eve->xy, mat_2d, eve->co);
diff --git a/source/blender/blenlib/intern/scanfill_utils.c b/source/blender/blenlib/intern/scanfill_utils.c
new file mode 100644
index 0000000..a6477d4
--- /dev/null
+++ b/source/blender/blenlib/intern/scanfill_utils.c
@@ -0,0 +1,509 @@
+/*
+ * ***** 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): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenlib/intern/scanfill_utils.c
+ * \ingroup bli
+ */
+
+#include <stdio.h>
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+#include "BLI_strict_flags.h"
+#include "BLI_ghash.h"
+
+#include "BLI_scanfill.h" /* own include */
+
+
+typedef struct PolyInfo {
+ ScanFillEdge *edge_first, *edge_last;
+ ScanFillVert *vert_outer;
+} PolyInfo;
+
+typedef struct PolySort {
+ float area;
+ unsigned short poly_nr;
+} PolySort;
+
+typedef struct ScanFillIsect {
+ struct ScanFillIsect *next, *prev;
+ float co[3];
+
+ /* newly created vertex */
+ ScanFillVert *v;
+} ScanFillIsect;
+
+
+#define V_ISISECT 1
+#define E_ISISECT 1
+#define E_ISDELETE 2
+
+
+#define EFLAG_SET(eed, val) { CHECK_TYPE(eed, ScanFillEdge *); \
+ (eed)->user_flag = (eed)->user_flag | (unsigned int)val; } (void)0
+#if 0
+#define EFLAG_CLEAR(eed, val) { CHECK_TYPE(eed, ScanFillEdge *); \
+ (eed)->user_flag = (eed)->user_flag & ~(unsigned int)val; } (void)0
+#endif
+
+#define VFLAG_SET(eve, val) { CHECK_TYPE(eve, ScanFillVert *); \
+ (eve)->user_flag = (eve)->user_flag | (unsigned int)val; } (void)0
+#if 0
+#define VFLAG_CLEAR(eve, val) { CHECK_TYPE(eve, ScanFillVert *); \
+ (eve)->user_flags = (eve)->user_flag & ~(unsigned int)val; } (void)0
+#endif
+
+
+#if 0
+void BKE_scanfill_obj_dump(S
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list