falloff options for dilate/erode feather compo node.
authorCampbell Barton <ideasman42@gmail.com>
Thu, 21 Jun 2012 07:45:41 +0000 (07:45 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 21 Jun 2012 07:45:41 +0000 (07:45 +0000)
15 files changed:
source/blender/blenkernel/BKE_blender.h
source/blender/blenloader/intern/readfile.c
source/blender/compositor/nodes/COM_DilateErodeNode.cpp
source/blender/compositor/operations/COM_BlurBaseOperation.cpp
source/blender/compositor/operations/COM_BlurBaseOperation.h
source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp
source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h
source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp
source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h
source/blender/editors/space_node/drawnode.c
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/intern/rna_nodetree.c
source/blender/makesrna/intern/rna_scene.c
source/blender/nodes/composite/nodes/node_composite_dilate.c

index 144cbe2..5fe28d2 100644 (file)
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         263
-#define BLENDER_SUBVERSION      12
+#define BLENDER_SUBVERSION      13
 
 #define BLENDER_MINVERSION      250
 #define BLENDER_MINSUBVERSION   0
index b481fd4..47dab0d 100644 (file)
@@ -6982,6 +6982,21 @@ static void do_version_ntree_image_user_264(void *UNUSED(data), ID *UNUSED(id),
        }
 }
 
+static void do_version_ntree_dilateerode_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
+{
+       bNode *node;
+
+       for (node = ntree->nodes.first; node; node = node->next) {
+               if (node->type == CMP_NODE_DILATEERODE) {
+                       if (node->storage == NULL) {
+                               NodeDilateErode *data = MEM_callocN(sizeof(NodeDilateErode), __func__);
+                               data->falloff = PROP_SMOOTH;
+                               node->storage = data;
+                       }
+               }
+       }
+}
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
        /* WATCH IT!!!: pointers from libdata have not been converted */
@@ -7789,6 +7804,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                ma->strand_widthfade = 0.0f;
        }
 
+       if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 13)) {
+               bNodeTreeType *ntreetype = ntreeGetType(NTREE_COMPOSIT);
+
+               if (ntreetype && ntreetype->foreach_nodetree)
+                       ntreetype->foreach_nodetree(main, NULL, do_version_ntree_dilateerode_264);
+       }
+
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
 
index fbec152..285bfa0 100644 (file)
@@ -117,6 +117,12 @@ void DilateErodeNode::convertToOperations(ExecutionSystem *graph, CompositorCont
 #endif
                operationx->setSubtract(editorNode->custom2 < 0);
                operationy->setSubtract(editorNode->custom2 < 0);
+
+               if (editorNode->storage) {
+                       NodeDilateErode *data = (NodeDilateErode *)editorNode->storage;
+                       operationx->setFalloff(data->falloff);
+                       operationy->setFalloff(data->falloff);
+               }
        }
        else {
                if (editorNode->custom2 > 0) {
index a233c7a..df64b7c 100644 (file)
@@ -91,7 +91,7 @@ float *BlurBaseOperation::make_gausstab(int rad)
 
 /* normalized distance from the current (inverted so 1.0 is close and 0.0 is far)
  * 'ease' is applied after, looks nicer */
-float *BlurBaseOperation::make_dist_fac_inverse(int rad)
+float *BlurBaseOperation::make_dist_fac_inverse(int rad, int falloff)
 {
        float *dist_fac_invert, val;
        int i, n;
@@ -103,9 +103,26 @@ float *BlurBaseOperation::make_dist_fac_inverse(int rad)
        for (i = -rad; i <= rad; i++) {
                val = 1.0f - fabsf(((float)i / (float)rad));
 
-               /* ease - gives less hard lines for dilate/erode feather */
-               val = (3.0f * val * val - 2.0f * val * val * val);
-
+               /* keep in sync with proportional_falloff_curve_only_items */
+               switch (falloff) {
+                       case PROP_SMOOTH:
+                               /* ease - gives less hard lines for dilate/erode feather */
+                               val = (3.0f * val * val - 2.0f * val * val * val);
+                               break;
+                       case PROP_SPHERE:
+                               val = sqrtf(2.0f * val - val * val);
+                               break;
+                       case PROP_ROOT:
+                               val = sqrtf(val);
+                               break;
+                       case PROP_SHARP:
+                               val = val * val;
+                               break;
+                       case PROP_LIN:
+                       default:
+                               /* nothing */
+                               break;
+               }
                dist_fac_invert[i + rad] = val;
        }
 
index 33c07ab..8f72082 100644 (file)
@@ -37,7 +37,7 @@ protected:
        NodeBlurData *data;
        BlurBaseOperation(DataType data_type);
        float *make_gausstab(int rad);
-       float *make_dist_fac_inverse(int rad);
+       float *make_dist_fac_inverse(int rad, int falloff);
        float size;
        bool deleteData;
        bool sizeavailable;
index 1283ac4..954aef7 100644 (file)
@@ -54,7 +54,7 @@ void GaussianAlphaXBlurOperation::initExecution()
 
                this->rad = rad;
                this->gausstab = BlurBaseOperation::make_gausstab(rad);
-               this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad);
+               this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad, this->falloff);
        }
 }
 
@@ -77,7 +77,7 @@ void GaussianAlphaXBlurOperation::updateGauss(MemoryBuffer **memoryBuffers)
                        rad = 1;
 
                this->rad = rad;
-               this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad);
+               this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad, this->falloff);
        }
 }
 
index 3268e51..38817eb 100644 (file)
@@ -30,6 +30,7 @@ class GaussianAlphaXBlurOperation : public BlurBaseOperation {
 private:
        float *gausstab;
        float *distbuf_inv;
+       int falloff;  /* falloff for distbuf_inv */
        bool do_subtract;
        int rad;
        void updateGauss(MemoryBuffer **memoryBuffers);
@@ -58,5 +59,6 @@ public:
         * Set subtract for Dilate/Erode functionality
         */
        void setSubtract(bool subtract) { this->do_subtract = subtract; }
+       void setFalloff(int falloff) { this->falloff = falloff; }
 };
 #endif
index 1d67c23..e1105cf 100644 (file)
@@ -54,7 +54,7 @@ void GaussianAlphaYBlurOperation::initExecution()
 
                this->rad = rad;
                this->gausstab = BlurBaseOperation::make_gausstab(rad);
-               this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad);
+               this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad, this->falloff);
        }
 }
 
@@ -77,7 +77,7 @@ void GaussianAlphaYBlurOperation::updateGauss(MemoryBuffer **memoryBuffers)
                        rad = 1;
 
                this->rad = rad;
-               this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad);
+               this->distbuf_inv = BlurBaseOperation::make_dist_fac_inverse(rad, this->falloff);
        }
 }
 
index 0ffc264..67166be 100644 (file)
@@ -31,6 +31,7 @@ private:
        float *gausstab;
        float *distbuf_inv;
        bool do_subtract;
+       int falloff;
        int rad;
        void updateGauss(MemoryBuffer **memoryBuffers);
 public:
@@ -58,5 +59,6 @@ public:
         * Set subtract for Dilate/Erode functionality
         */
        void setSubtract(bool subtract) { this->do_subtract = subtract; }
+       void setFalloff(int falloff) { this->falloff = falloff; }
 };
 #endif
index b02e20b..90cbdcd 100644 (file)
@@ -1768,8 +1768,13 @@ static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C)
 {
        uiItemR(layout, ptr, "type", 0, NULL, ICON_NONE);
        uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE);
-       if (RNA_enum_get(ptr, "type") == CMP_NODE_DILATEERODE_DISTANCE_THRESH) {
-               uiItemR(layout, ptr, "edge", 0, NULL, ICON_NONE);
+       switch (RNA_enum_get(ptr, "type")) {
+               case CMP_NODE_DILATEERODE_DISTANCE_THRESH:
+                       uiItemR(layout, ptr, "edge", 0, NULL, ICON_NONE);
+                       break;
+               case CMP_NODE_DILATEERODE_DISTANCE_FEATHER:
+                       uiItemR(layout, ptr, "falloff", 0, NULL, ICON_NONE);
+                       break;
        }
 }
 
index 9bc002b..8de9a29 100644 (file)
@@ -559,6 +559,11 @@ typedef struct NodeColorspill {
        float uspillr, uspillg, uspillb;
 } NodeColorspill;
 
+typedef struct NodeDilateErode {
+       char falloff;
+       char pad[7];
+} NodeDilateErode;
+
 typedef struct NodeTexBase {
        TexMapping tex_mapping;
        ColorMapping color_mapping;
index 473ab74..a8d176d 100644 (file)
@@ -41,6 +41,7 @@ extern EnumPropertyItem object_mode_items[];
 extern EnumPropertyItem metaelem_type_items[];
 
 extern EnumPropertyItem proportional_falloff_items[];
+extern EnumPropertyItem proportional_falloff_curve_only_items[];
 extern EnumPropertyItem proportional_editing_items[];
 extern EnumPropertyItem snap_target_items[];
 extern EnumPropertyItem snap_element_items[];
index ef3dac5..51bd778 100644 (file)
@@ -2068,11 +2068,21 @@ static void def_cmp_dilate_erode(StructRNA *srna)
        RNA_def_property_ui_text(prop, "Distance", "Distance to grow/shrink (number of iterations)");
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 
+       /* CMP_NODE_DILATEERODE_DISTANCE_THRESH only */
        prop = RNA_def_property(srna, "edge", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "custom3");
        RNA_def_property_range(prop, -100, 100);
        RNA_def_property_ui_text(prop, "Edge", "Edge to inset");
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+       RNA_def_struct_sdna_from(srna, "NodeDilateErode", "storage");
+
+       /* CMP_NODE_DILATEERODE_DISTANCE_FEATHER only */
+       prop = RNA_def_property(srna, "falloff", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "falloff");
+       RNA_def_property_enum_items(prop, proportional_falloff_curve_only_items);
+       RNA_def_property_ui_text(prop, "Falloff", "Falloff type the feather");
+       RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
 static void def_cmp_scale(StructRNA *srna)
index 85c7b56..072df09 100644 (file)
@@ -101,6 +101,16 @@ EnumPropertyItem proportional_falloff_items[] = {
        {0, NULL, 0, NULL, NULL}
 };
 
+/* subset of the enum - only curves, missing random and const */
+EnumPropertyItem proportional_falloff_curve_only_items[] = {
+       {PROP_SMOOTH, "SMOOTH", ICON_SMOOTHCURVE, "Smooth", "Smooth falloff"},
+       {PROP_SPHERE, "SPHERE", ICON_SPHERECURVE, "Sphere", "Spherical falloff"},
+       {PROP_ROOT, "ROOT", ICON_ROOTCURVE, "Root", "Root falloff"},
+       {PROP_SHARP, "SHARP", ICON_SHARPCURVE, "Sharp", "Sharp falloff"},
+       {PROP_LIN, "LINEAR", ICON_LINCURVE, "Linear", "Linear falloff"},
+       {0, NULL, 0, NULL, NULL}
+};
+
 
 EnumPropertyItem proportional_editing_items[] = {
        {PROP_EDIT_OFF, "DISABLED", ICON_PROP_OFF, "Disable", "Proportional Editing disabled"},
index 2f13983..5977d29 100644 (file)
@@ -146,6 +146,13 @@ static void node_composit_exec_dilateerode(void *UNUSED(data), bNode *node, bNod
        }
 }
 
+static void node_composit_init_dilateerode(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
+{
+       NodeDilateErode *data = MEM_callocN(sizeof(NodeDilateErode), "NodeDilateErode");
+       data->falloff = PROP_SMOOTH;
+       node->storage = data;
+}
+
 void register_node_type_cmp_dilateerode(bNodeTreeType *ttype)
 {
        static bNodeType ntype;
@@ -153,7 +160,10 @@ void register_node_type_cmp_dilateerode(bNodeTreeType *ttype)
        node_type_base(ttype, &ntype, CMP_NODE_DILATEERODE, "Dilate/Erode", NODE_CLASS_OP_FILTER, NODE_OPTIONS);
        node_type_socket_templates(&ntype, cmp_node_dilateerode_in, cmp_node_dilateerode_out);
        node_type_size(&ntype, 130, 100, 320);
+       node_type_init(&ntype, node_composit_init_dilateerode);
        node_type_exec(&ntype, node_composit_exec_dilateerode);
        
+       node_type_storage(&ntype, "NodeDilateErode", node_free_standard_storage, node_copy_standard_storage);
+
        nodeRegisterType(ttype, &ntype);
 }