Merging r48238 through r48240 from trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 24 Jun 2012 15:31:40 +0000 (15:31 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 24 Jun 2012 15:31:40 +0000 (15:31 +0000)
source/blender/compositor/operations/COM_KeyingScreenOperation.cpp
source/blender/compositor/operations/COM_KeyingScreenOperation.h
source/blender/makesrna/intern/rna_nodetree_types.h

index 9f7b69636ab739852d1c500bdbf210cb7346016f..20b293bef34bc6a3dcdc27482f17a4c538082f44 100644 (file)
@@ -65,6 +65,9 @@ void KeyingScreenOperation::deinitExecution()
                if (triangulation->triangles)
                        MEM_freeN(triangulation->triangles);
 
+               if (triangulation->triangles_AABB)
+                       MEM_freeN(triangulation->triangles_AABB);
+
                MEM_freeN(this->cachedTriangulation);
 
                this->cachedTriangulation = NULL;
@@ -155,6 +158,33 @@ KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTri
        MEM_freeN(sites);
        BLI_freelistN(&edges);
 
+       if (triangulation->triangles_total) {
+               rctf *rect;
+               rect = triangulation->triangles_AABB =
+                       (rctf *) MEM_callocN(sizeof(rctf) * triangulation->triangles_total, "voronoi triangulation AABB");
+
+               for (i = 0; i < triangulation->triangles_total; i++, rect++) {
+                       int *triangle = triangulation->triangles[i];
+                       VoronoiTriangulationPoint *a = &triangulation->triangulated_points[triangle[0]],
+                                                 *b = &triangulation->triangulated_points[triangle[1]],
+                                                 *c = &triangulation->triangulated_points[triangle[2]];
+
+                       float min[2], max[2];
+
+                       INIT_MINMAX2(min, max);
+
+                       DO_MINMAX2(a->co, min, max);
+                       DO_MINMAX2(b->co, min, max);
+                       DO_MINMAX2(c->co, min, max);
+
+                       rect->xmin = min[0];
+                       rect->ymin = min[1];
+
+                       rect->xmax = max[0];
+                       rect->ymax = max[1];
+               }
+       }
+
        return triangulation;
 }
 
@@ -203,18 +233,24 @@ void KeyingScreenOperation::executePixel(float *color, int x, int y, MemoryBuffe
        if (this->movieClip && data) {
                TriangulationData *triangulation = (TriangulationData *) data;
                int i;
+               float co[2] = {(float) x, (float) y};
+
                for (i = 0; i < triangulation->triangles_total; i++) {
-                       int *triangle = triangulation->triangles[i];
-                       VoronoiTriangulationPoint *a = &triangulation->triangulated_points[triangle[0]],
-                       *b = &triangulation->triangulated_points[triangle[1]],
-                       *c = &triangulation->triangulated_points[triangle[2]];
-                       float co[2] = {(float) x, (float) y}, w[3];
-
-                       if (barycentric_coords_v2(a->co, b->co, c->co, co, w)) {
-                               if (barycentric_inside_triangle_v2(w)) {
-                                       color[0] += a->color[0] * w[0] + b->color[0] * w[1] + c->color[0] * w[2];
-                                       color[1] += a->color[1] * w[0] + b->color[1] * w[1] + c->color[1] * w[2];
-                                       color[2] += a->color[2] * w[0] + b->color[2] * w[1] + c->color[2] * w[2];
+                       rctf *rect = &triangulation->triangles_AABB[i];
+
+                       if (IN_RANGE_INCL(x, rect->xmin, rect->xmax) && IN_RANGE_INCL(y, rect->ymin, rect->ymax)) {
+                               int *triangle = triangulation->triangles[i];
+                               VoronoiTriangulationPoint *a = &triangulation->triangulated_points[triangle[0]],
+                                                         *b = &triangulation->triangulated_points[triangle[1]],
+                                                         *c = &triangulation->triangulated_points[triangle[2]];
+                               float w[3];
+
+                               if (barycentric_coords_v2(a->co, b->co, c->co, co, w)) {
+                                       if (barycentric_inside_triangle_v2(w)) {
+                                               color[0] += a->color[0] * w[0] + b->color[0] * w[1] + c->color[0] * w[2];
+                                               color[1] += a->color[1] * w[0] + b->color[1] * w[1] + c->color[1] * w[2];
+                                               color[2] += a->color[2] * w[0] + b->color[2] * w[1] + c->color[2] * w[2];
+                                       }
                                }
                        }
                }
index 9d3f44f6be20c6827b3ffdd71458e40469919b8e..a539ecf696e13d1888f07493ac742493fc0a3b78 100644 (file)
@@ -47,6 +47,7 @@ protected:
                VoronoiTriangulationPoint *triangulated_points;
                int (*triangles)[3];
                int triangulated_points_total, triangles_total;
+               rctf *triangles_AABB;
        } TriangulationData;
 
        MovieClip *movieClip;
index dd604e8735776af3c3500aced73987c32eb87691..a4837a88b1722a4562b306061f7c0dcf54e912a4 100644 (file)
@@ -37,7 +37,7 @@ DefNode( ShaderNode,     SH_NODE_MATERIAL,        def_sh_material,        "MATER
 DefNode( ShaderNode,     SH_NODE_RGB,             0,                      "RGB",            RGB,              "RGB",               ""              )
 DefNode( ShaderNode,     SH_NODE_VALUE,           0,                      "VALUE",          Value,            "Value",             ""              )
 DefNode( ShaderNode,     SH_NODE_MIX_RGB,         def_mix_rgb,            "MIX_RGB",        MixRGB,           "MixRGB",            ""              )
-DefNode( ShaderNode,     SH_NODE_VALTORGB,        def_colorramp,          "VALTORGB",       ValToRGB,         "ColorRamp",      ""              )
+DefNode( ShaderNode,     SH_NODE_VALTORGB,        def_colorramp,          "VALTORGB",       ValToRGB,         "ColorRamp",         ""              )
 DefNode( ShaderNode,     SH_NODE_RGBTOBW,         0,                      "RGBTOBW",        RGBToBW,          "RGB to BW",         ""              )
 DefNode( ShaderNode,     SH_NODE_TEXTURE,         def_texture,            "TEXTURE",        Texture,          "Texture",           ""              )
 DefNode( ShaderNode,     SH_NODE_NORMAL,          0,                      "NORMAL",         Normal,           "Normal",            ""              )
@@ -91,13 +91,13 @@ DefNode( ShaderNode,     SH_NODE_TEX_WAVE,           def_sh_tex_wave,        "TE
 DefNode( ShaderNode,     SH_NODE_TEX_MUSGRAVE,       def_sh_tex_musgrave,    "TEX_MUSGRAVE",       TexMusgrave,      "Musgrave Texture",  ""       )
 DefNode( ShaderNode,     SH_NODE_TEX_VORONOI,        def_sh_tex_voronoi,     "TEX_VORONOI",        TexVoronoi,       "Voronoi Texture",   ""       )
 DefNode( ShaderNode,     SH_NODE_TEX_CHECKER,        def_sh_tex_checker,     "TEX_CHECKER",        TexChecker,       "Checker Texture",   ""       )
-DefNode( ShaderNode,     SH_NODE_TEX_COORD,          0,                      "TEX_COORD",          TexCoord,         "Texture Coordinate","")
+DefNode( ShaderNode,     SH_NODE_TEX_COORD,          0,                      "TEX_COORD",          TexCoord,         "Texture Coordinate",""       )
 
 DefNode( CompositorNode, CMP_NODE_VIEWER,         def_cmp_viewer,         "VIEWER",         Viewer,           "Viewer",            ""              )
 DefNode( CompositorNode, CMP_NODE_RGB,            0,                      "RGB",            RGB,              "RGB",               ""              )
 DefNode( CompositorNode, CMP_NODE_VALUE,          0,                      "VALUE",          Value,            "Value",             ""              )
 DefNode( CompositorNode, CMP_NODE_MIX_RGB,        def_mix_rgb,            "MIX_RGB",        MixRGB,           "Mix RGB",           ""              )
-DefNode( CompositorNode, CMP_NODE_VALTORGB,       def_colorramp,          "VALTORGB",       ValToRGB,         "ColorRamp",      ""              )
+DefNode( CompositorNode, CMP_NODE_VALTORGB,       def_colorramp,          "VALTORGB",       ValToRGB,         "ColorRamp",         ""              )
 DefNode( CompositorNode, CMP_NODE_RGBTOBW,        0,                      "RGBTOBW",        RGBToBW,          "RGB to BW",         ""              )
 DefNode( CompositorNode, CMP_NODE_NORMAL,         0,                      "NORMAL",         Normal,           "Normal",            ""              )
 DefNode( CompositorNode, CMP_NODE_CURVE_VEC,      def_vector_curve,       "CURVE_VEC",      CurveVec,         "Vector Curve",      ""              )
@@ -118,7 +118,7 @@ DefNode( CompositorNode, CMP_NODE_COMPOSITE,      0,                      "COMPO
 DefNode( CompositorNode, CMP_NODE_OUTPUT_FILE,    def_cmp_output_file,    "OUTPUT_FILE",    OutputFile,       "Output File",       ""              )
 DefNode( CompositorNode, CMP_NODE_TEXTURE,        def_texture,            "TEXTURE",        Texture,          "Texture",           ""              )
 DefNode( CompositorNode, CMP_NODE_TRANSLATE,      0,                      "TRANSLATE",      Translate,        "Translate",         ""              )
-DefNode( CompositorNode, CMP_NODE_ZCOMBINE,       def_cmp_zcombine,              "ZCOMBINE",       Zcombine,         "Z Combine",         ""              )
+DefNode( CompositorNode, CMP_NODE_ZCOMBINE,       def_cmp_zcombine,       "ZCOMBINE",       Zcombine,         "Z Combine",         ""              )
 DefNode( CompositorNode, CMP_NODE_COMBRGBA,       0,                      "COMBRGBA",       CombRGBA,         "Combine RGBA",      ""              )
 DefNode( CompositorNode, CMP_NODE_DILATEERODE,    def_cmp_dilate_erode,   "DILATEERODE",    DilateErode,      "Dilate/Erode",      ""              )
 DefNode( CompositorNode, CMP_NODE_ROTATE,         def_cmp_rotate,         "ROTATE",         Rotate,           "Rotate",            ""              )
@@ -179,7 +179,7 @@ DefNode( TextureNode,    TEX_NODE_BRICKS,         def_tex_bricks,         "BRICK
 DefNode( TextureNode,    TEX_NODE_MATH,           def_math,               "MATH",           Math,             "Math",              ""              )
 DefNode( TextureNode,    TEX_NODE_MIX_RGB,        def_mix_rgb,            "MIX_RGB",        MixRGB,           "Mix RGB",           ""              )
 DefNode( TextureNode,    TEX_NODE_RGBTOBW,        0,                      "RGBTOBW",        RGBToBW,          "RGB to BW",         ""              )
-DefNode( TextureNode,    TEX_NODE_VALTORGB,       def_colorramp,          "VALTORGB",       ValToRGB,         "ColorRamp",      ""              )
+DefNode( TextureNode,    TEX_NODE_VALTORGB,       def_colorramp,          "VALTORGB",       ValToRGB,         "ColorRamp",         ""              )
 DefNode( TextureNode,    TEX_NODE_IMAGE,          def_tex_image,          "IMAGE",          Image,            "Image",             ""              )
 DefNode( TextureNode,    TEX_NODE_CURVE_RGB,      def_rgb_curve,          "CURVE_RGB",      CurveRGB,         "RGB Curve",         ""              )
 DefNode( TextureNode,    TEX_NODE_INVERT,         0,                      "INVERT",         Invert,           "Invert",            ""              )