[Bf-blender-cvs] [5c22e28d81c] greasepencil-object: GPencil: Add turnpolicy parameter to trace

Antonio Vazquez noreply at git.blender.org
Mon Apr 13 12:37:38 CEST 2020


Commit: 5c22e28d81c4399a1949f4b7d202aa674894f2e8
Author: Antonio Vazquez
Date:   Mon Apr 13 12:37:29 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB5c22e28d81c4399a1949f4b7d202aa674894f2e8

GPencil: Add turnpolicy parameter to trace

This determines how turn in the trace process. (It uses Potracle lib values)

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

M	release/scripts/startup/bl_operators/gpencil_trace_image.py
M	source/blender/editors/gpencil/gpencil_trace_ops.c

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

diff --git a/release/scripts/startup/bl_operators/gpencil_trace_image.py b/release/scripts/startup/bl_operators/gpencil_trace_image.py
index ecb370db802..85fb776e2de 100644
--- a/release/scripts/startup/bl_operators/gpencil_trace_image.py
+++ b/release/scripts/startup/bl_operators/gpencil_trace_image.py
@@ -95,6 +95,20 @@ class GPENCIL_OT_trace(Operator):
         precision=3,
         step=1,
     )
+    turnpolicy: EnumProperty(
+        name="Turn Policy",
+        description="Determines how to resolve ambiguities during decomposition of bitmaps into paths",
+        items=(
+            ("BLACK", "Black",  "prefers to connect black (foreground) components"),
+            ("WHITE", "White", "Prefers to connect white (background) components"),
+            ("LEFT", "Left", "Always take a left turn"),
+            ("RIGHT", "Right", "Always take a right turn"),
+            ("MINORITY", "Minority", "Prefers to connect the color (black or white) that occurs least frequently"),
+            ("MAJORITY", "Majority", "Prefers to connect the color (black or white) that occurs most frequently"),
+            ("RANDOM", "Random", "Choose pseudo-randomly.")
+        ),
+        default="MINORITY"
+    )
 
     @classmethod
     def poll(self, context):
@@ -108,7 +122,8 @@ class GPENCIL_OT_trace(Operator):
             resolution=self.resolution,
             scale=self.scale,
             sample=self.sample,
-            threshold=self.threshold
+            threshold=self.threshold,
+            turnpolicy=self.turnpolicy
         )
 
         return {'FINISHED'}
diff --git a/source/blender/editors/gpencil/gpencil_trace_ops.c b/source/blender/editors/gpencil/gpencil_trace_ops.c
index b77f19445fb..30f51c4c83c 100644
--- a/source/blender/editors/gpencil/gpencil_trace_ops.c
+++ b/source/blender/editors/gpencil/gpencil_trace_ops.c
@@ -92,6 +92,7 @@ static int gp_trace_image_exec(bContext *C, wmOperator *op)
   const float sample = RNA_float_get(op->ptr, "sample");
   const int resolution = RNA_int_get(op->ptr, "resolution");
   const int thickness = RNA_int_get(op->ptr, "thickness");
+  const int turnpolicy = RNA_enum_get(op->ptr, "turnpolicy");
 
   ImBuf *ibuf;
   void *lock;
@@ -109,6 +110,7 @@ static int gp_trace_image_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
   param->turdsize = 0;
+  param->turnpolicy = turnpolicy;
 
   /* Create a new grease pencil object in origin. */
   bool newob = false;
@@ -197,6 +199,35 @@ static int gp_trace_image_exec(bContext *C, wmOperator *op)
 
 void GPENCIL_OT_trace_image(wmOperatorType *ot)
 {
+  static const EnumPropertyItem turnpolicy_type[] = {
+      {POTRACE_TURNPOLICY_BLACK,
+       "BLACK",
+       0,
+       "Black",
+       "prefers to connect black (foreground) components"},
+      {POTRACE_TURNPOLICY_WHITE,
+       "WHITE",
+       0,
+       "White",
+       "Prefers to connect white (background) components"},
+      {POTRACE_TURNPOLICY_LEFT, "LEFT", 0, "Left", "Always take a left turn"},
+      {POTRACE_TURNPOLICY_RIGHT, "RIGHT", 0, "Right", "Always take a right turn"},
+      {POTRACE_TURNPOLICY_MINORITY,
+       "MINORITY",
+       0,
+       "Minority",
+       "Prefers to connect the color (black or white) that occurs least frequently in a local "
+       "neighborhood of the current position"},
+      {POTRACE_TURNPOLICY_MAJORITY,
+       "MAJORITY",
+       0,
+       "Majority",
+       "Prefers to connect the color (black or white) that occurs most frequently in a local "
+       "neighborhood of the current position"},
+      {POTRACE_TURNPOLICY_RANDOM, "RANDOM", 0, "Random", "Choose pseudo-randomly"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   /* identifiers */
   ot->name = "Trace Image to Grease Pencil";
   ot->idname = "GPENCIL_OT_trace_image";
@@ -248,4 +279,10 @@ void GPENCIL_OT_trace_image(wmOperatorType *ot)
                        "Determine what is considered white and what black",
                        0.0f,
                        1.0f);
+  RNA_def_enum(ot->srna,
+               "turnpolicy",
+               turnpolicy_type,
+               POTRACE_TURNPOLICY_MINORITY,
+               "Turn Policy",
+               "Determines how to resolve ambiguities during decomposition of bitmaps into paths");
 }



More information about the Bf-blender-cvs mailing list