Commit: 34afceb924553643d4dc56641d7d039f8da3d208
Author: Antonio Vazquez
Date:   Mon Aug 7 16:58:13 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB34afceb924553643d4dc56641d7d039f8da3d208

New Simplify stroke operator

Internally runs the same function used in Simplify modifier, but as operator.

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

M       release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M       source/blender/blenkernel/BKE_gpencil.h
M       source/blender/blenkernel/intern/gpencil_modifier.c
M       source/blender/editors/gpencil/gpencil_edit.c
M       source/blender/editors/gpencil/gpencil_intern.h
M       source/blender/editors/gpencil/gpencil_ops.c

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

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py 
b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 2ad008ccd7f..5077cb43f44 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -220,6 +220,7 @@ class GreasePencilStrokeEditPanel:
         layout.separator()
         col = layout.column(align=True)
         col.operator("gpencil.stroke_subdivide", text="Subdivide")
+        col.operator("gpencil.stroke_simplify", text="Simplify")
         col.operator("gpencil.stroke_join", text="Join").type = 'JOIN'
         col.operator("gpencil.stroke_join", text="Join & Copy").type = 
'JOINCOPY'
         col.operator("gpencil.stroke_flip", text="Flip Direction")
@@ -811,6 +812,7 @@ class GPENCIL_MT_gpencil_edit_specials(Menu):
         layout.operator_context = 'INVOKE_REGION_WIN'
 
         layout.operator("gpencil.stroke_subdivide", text="Subdivide")
+        layout.operator("gpencil.stroke_simplify", text="Simplify")
 
         layout.separator()
 
diff --git a/source/blender/blenkernel/BKE_gpencil.h 
b/source/blender/blenkernel/BKE_gpencil.h
index 09e12fde229..e7d5b57e28d 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -173,6 +173,9 @@ void BKE_gpencil_array_modifier(int id, struct 
GpencilArrayModifierData *mmd, st
 void BKE_gpencil_dupli_modifier(int id, struct GpencilDupliModifierData *mmd, 
struct Object *ob, struct bGPDlayer *gpl, struct bGPDframe *gpf);
 void BKE_gpencil_opacity_modifier(int id, struct GpencilOpacityModifierData 
*mmd, struct Object *ob, struct bGPDlayer *gpl, struct bGPDstroke *gps);
 
+/* (wrapper api) simplify stroke using Ramer-Douglas-Peucker algorithm */
+void BKE_gpencil_simplify_stroke(struct bGPDlayer *gpl, struct bGPDstroke 
*gps, float factor);
+
 bool BKE_gpencil_use_this_lattice(struct Object *ob, struct Object *lattice);
 void BKE_gpencil_lattice_init(struct Object *ob);
 void BKE_gpencil_lattice_modifier(int id, struct GpencilLatticeModifierData 
*mmd, struct Object *ob, struct bGPDlayer *gpl, struct bGPDstroke *gps);
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c 
b/source/blender/blenkernel/intern/gpencil_modifier.c
index b44774ea988..6b67b895bac 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -848,6 +848,20 @@ void gpencil_rdp_stroke(bGPDstroke *gps, tbGPDspoint 
*points2d, float epsilon)
        MEM_SAFE_FREE(marked);
 }
 
+/* (wrapper api) simplify stroke using Ramer-Douglas-Peucker algorithm */
+void BKE_gpencil_simplify_stroke(bGPDlayer *gpl, bGPDstroke *gps, float factor)
+{
+       /* first create temp data and convert points to 2D */
+       tbGPDspoint *points2d = MEM_mallocN(sizeof(tbGPDspoint) * 
gps->totpoints, "GP Stroke temp 2d points");
+
+       gpencil_stroke_project_2d(gps->points, gps->totpoints, points2d);
+
+       gpencil_rdp_stroke(gps, points2d, factor);
+
+       MEM_SAFE_FREE(points2d);
+}
+
+
 /* simplify stroke using Ramer-Douglas-Peucker algorithm */
 void BKE_gpencil_simplify_modifier(int UNUSED(id), GpencilSimplifyModifierData 
*mmd, Object *UNUSED(ob), bGPDlayer *gpl, bGPDstroke *gps)
 {
diff --git a/source/blender/editors/gpencil/gpencil_edit.c 
b/source/blender/editors/gpencil/gpencil_edit.c
index 437f4126af0..570eb1b3441 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -2724,3 +2724,53 @@ void GPENCIL_OT_stroke_subdivide(wmOperatorType *ot)
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 
 }
+
+/* ** simplify stroke *** */
+static int gp_stroke_simplify_exec(bContext *C, wmOperator *op)
+{
+       bGPdata *gpd = ED_gpencil_data_get_active(C);
+       float factor = RNA_float_get(op->ptr, "factor");
+
+       /* sanity checks */
+       if (ELEM(NULL, gpd))
+               return OPERATOR_CANCELLED;
+
+       /* Go through each editable + selected stroke */
+       GP_EDITABLE_STROKES_BEGIN(C, gpl, gps)
+       {
+               if (gps->flag & GP_STROKE_SELECT) {
+                       /* simplify stroke using Ramer-Douglas-Peucker 
algorithm */
+                       BKE_gpencil_simplify_stroke(gpl, gps, factor);
+               }
+       }
+       GP_EDITABLE_STROKES_END;
+
+       /* notifiers */
+       BKE_gpencil_batch_cache_dirty(gpd);
+       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+
+       return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_stroke_simplify(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+
+       /* identifiers */
+       ot->name = "Simplify Stroke";
+       ot->idname = "GPENCIL_OT_stroke_simplify";
+       ot->description = "Simplify selected stroked reducing number of points";
+
+       /* api callbacks */
+       ot->exec = gp_stroke_simplify_exec;
+       ot->poll = gp_active_layer_poll;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
+
+       /* properties */
+       prop = RNA_def_float(ot->srna, "factor", 0.0f, 0.0f, 100.0f, "Factor", 
"", 0.0f, 100.0f);
+       /* avoid re-using last var */
+       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+
+}
diff --git a/source/blender/editors/gpencil/gpencil_intern.h 
b/source/blender/editors/gpencil/gpencil_intern.h
index 13a051cd427..a639b804c5b 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -244,6 +244,7 @@ void GPENCIL_OT_stroke_cyclical_set(struct wmOperatorType 
*ot);
 void GPENCIL_OT_stroke_join(struct wmOperatorType *ot);
 void GPENCIL_OT_stroke_flip(struct wmOperatorType *ot);
 void GPENCIL_OT_stroke_subdivide(struct wmOperatorType *ot);
+void GPENCIL_OT_stroke_simplify(struct wmOperatorType *ot);
 
 void GPENCIL_OT_brush_add(struct wmOperatorType *ot);
 void GPENCIL_OT_brush_remove(struct wmOperatorType *ot);
diff --git a/source/blender/editors/gpencil/gpencil_ops.c 
b/source/blender/editors/gpencil/gpencil_ops.c
index 71813bb18c4..ba283eabd8b 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -652,6 +652,7 @@ void ED_operatortypes_gpencil(void)
        WM_operatortype_append(GPENCIL_OT_stroke_join);
        WM_operatortype_append(GPENCIL_OT_stroke_flip);
        WM_operatortype_append(GPENCIL_OT_stroke_subdivide);
+       WM_operatortype_append(GPENCIL_OT_stroke_simplify);
 
        WM_operatortype_append(GPENCIL_OT_brush_add);
        WM_operatortype_append(GPENCIL_OT_brush_remove);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to