Cleanup: manually remove header text not handled by automation
[blender.git] / source / blender / gpencil_modifiers / intern / MOD_gpencilsimplify.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software  Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2017, Blender Foundation
17  * This is a new part of Blender
18  */
19
20 /** \file blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c
21  *  \ingroup modifiers
22  */
23
24 #include <stdio.h>
25
26 #include "DNA_scene_types.h"
27 #include "DNA_object_types.h"
28 #include "DNA_gpencil_types.h"
29 #include "DNA_gpencil_modifier_types.h"
30 #include "DNA_vec_types.h"
31
32 #include "BLI_utildefines.h"
33
34 #include "BKE_gpencil.h"
35 #include "BKE_gpencil_modifier.h"
36
37 #include "DEG_depsgraph.h"
38
39 #include "MOD_gpencil_util.h"
40 #include "MOD_gpencil_modifiertypes.h"
41
42 static void initData(GpencilModifierData *md)
43 {
44         SimplifyGpencilModifierData *gpmd = (SimplifyGpencilModifierData *)md;
45         gpmd->pass_index = 0;
46         gpmd->step = 1;
47         gpmd->factor = 0.0f;
48         gpmd->layername[0] = '\0';
49 }
50
51 static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
52 {
53         BKE_gpencil_modifier_copyData_generic(md, target);
54 }
55
56 static void deformStroke(
57         GpencilModifierData *md, Depsgraph *UNUSED(depsgraph),
58         Object *ob, bGPDlayer *gpl, bGPDstroke *gps)
59 {
60         SimplifyGpencilModifierData *mmd = (SimplifyGpencilModifierData *)md;
61
62         if (!is_stroke_affected_by_modifier(
63                     ob,
64                     mmd->layername, mmd->pass_index, mmd->layer_pass, 4, gpl, gps,
65                     mmd->flag & GP_SIMPLIFY_INVERT_LAYER, mmd->flag & GP_SIMPLIFY_INVERT_PASS,
66                     mmd->flag & GP_SIMPLIFY_INVERT_LAYERPASS))
67         {
68                 return;
69         }
70
71         if (mmd->mode == GP_SIMPLIFY_FIXED) {
72                 for (int i = 0; i < mmd->step; i++) {
73                         BKE_gpencil_simplify_fixed(gps);
74                 }
75         }
76         else {
77                 /* simplify stroke using Ramer-Douglas-Peucker algorithm */
78                 BKE_gpencil_simplify_stroke(gps, mmd->factor);
79         }
80 }
81
82 static void bakeModifier(
83         struct Main *UNUSED(bmain), Depsgraph *depsgraph,
84         GpencilModifierData *md, Object *ob)
85 {
86         bGPdata *gpd = ob->data;
87
88         for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
89                 for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
90                         for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
91                                 deformStroke(md, depsgraph, ob, gpl, gps);
92                         }
93                 }
94         }
95 }
96
97 GpencilModifierTypeInfo modifierType_Gpencil_Simplify = {
98         /* name */              "Simplify",
99         /* structName */        "SimplifyGpencilModifierData",
100         /* structSize */        sizeof(SimplifyGpencilModifierData),
101         /* type */              eGpencilModifierTypeType_Gpencil,
102         /* flags */             eGpencilModifierTypeFlag_SupportsEditmode,
103
104         /* copyData */          copyData,
105
106         /* deformStroke */      deformStroke,
107         /* generateStrokes */   NULL,
108         /* bakeModifier */      bakeModifier,
109         /* remapTime */         NULL,
110
111         /* initData */          initData,
112         /* freeData */          NULL,
113         /* isDisabled */        NULL,
114         /* updateDepsgraph */   NULL,
115         /* dependsOnTime */     NULL,
116         /* foreachObjectLink */ NULL,
117         /* foreachIDLink */     NULL,
118         /* foreachTexLink */    NULL,
119         /* getDuplicationFactor */ NULL,
120 };