Refactoring and evolution of the Cage tool


A quick post to let you know that i started a refactoring of the Gimp cage tool. It’s a mandatory step to achieve a good quality and a solid basis to implement new things. It happens here by rewriting the frontend code as a state machine (as described here a few days ago), change on the data structure, documentation, and a lot of small fixes and simplifications.

In the future, a multi-points selection should come in a few days in the soc-2010-cage-2 branch. This editing mode will work in a similar way as in the path tool.

A proportional editing mode, similar to what you can find in Blender should come too.

Maybe i’ll start to getting satisfied of my work someday… =)

11 Responses to “Refactoring and evolution of the Cage tool”

  • Silvio Grosso:

    > Maybe i’ll start to getting satisfied of my work someday… =)

    We all hope so.
    This because your “satisfaction” means that your implementation of the Cage tool will prove useful for Gimp’s end-users ;-)

    Joking aside, THANKS a lot for your work on Gimp.
    It is really nice to see that a student who has worked on a Google summer of code continues working on his project ;-)

    Best regards and HAPPY NEW YEAR 2011

  • shtitusque:

    Rappelons que la machine à étatS permet de s’abstenir de commenter son code, ce qui est plutôt pratique :)
    Pour ceux-ce qui veulent voir de leur propres yeux, le commit en question dans l’article est (rapidement suivi de ).
    Bon courage pour la suite, le C n’est pas forcément le langage de mon (peut-être ?) futur SoC ;)

  • Thanks! it’s already a useful tool (one that I have often wanted in gimp), and almost ideal (speed and some ‘doubles’ where there is both a deformed and undeformed bit of the original left over- I should probably file (or check the tracker) for a bug on the doubling. It’s a great thing you continue to work on it till perfection.

  • Mic:

    Hi, Thanks for developing cage… but the transform you employ makes this tool useless in many applications.

    When you select a square and transform to a rectangle, you end up with strange non-linear mapping. Could you fix this (or at least provide a simple linear alternative)? For 4 control points, it should work like the “perspective” tool, and for more points, it should work in a similar manner.

    The goal is: when you surround any shape with control points and then move the control points to transform, NO AREA of the surrounded source image should go BEYOND the cage.

    This would make the tool useful in various transformations – so far it cannot be used for many (basic and popular) purposes. Also note that changing the transformation the way I described would not change much for existing users who are satisfied with the way it currently works. It is just adding an important and basic property to the current transform, and probably simplifying it.

    • Michael:

      Weee, my first bug report ! :)

      What you are describing is a complete different kind of transformation. The cage tool provide a conformal 2D mapping, aimed to preserve the detail of the area deformed. A 90 degree angle in an image will still be a 90 degree angle after the transformation. To do that, the area need to go outside the cage.

      They are other kind of cage deformation that provide what you describe, but they also came with rather ugly deformation. The Gimp developper and I choosed to not do that. Also, the algorithm behind the cage tool cannot be changed by some tweak to enable this behavior.

      The usecase I see are like this:
      – complex deformation, with more than 4 handles needs to respect the area, to avoid ugly and unusable deformation.
      – simple deformation are already well covered with tool like scale, perspective and others.

    • if you just leave the cage door open he will come out on his own just be sure the room door is closed so when you need to put him away you are not cinahsg him around the house.if you can’t catch me to put him away put a treat in his food dish he will go in and get it.

  • Mic:

    Not a bug report :-) I found some bugs as well, but this is something different :-)

    Now if you think about the rectangle-to-square scenario, the mapping I described also preserves angles. The problem with the current mapping is that it is pretty useless because it cannot be used in a predictable way to correct shapes (other than for fun).

    Imagine (I think this is a typical scenario) the user wants to correct the shape of the image by creating an envelope around it and dragging some vertices. This is sometimes called image warping, and various software toolkits display a grid with handles you can move. With your current tool, each movement of a vertex causes an unintuitive (and sometimes serious) deformation of the rest, so if one wants to straighten a photograph or fix some other transformation of an image, this is (almost) impossible to do well, or you end up in endless corrections of all the other vertices.

    An example of a very simple alternative I talked about would be to triangularize the cage and perform linear deformation only in triangles affected by moved vertices. A better alternative would be to propagate deformation into nearby triangles. Both are much simpler, much faster (easily realtime) and much more predictable than current solution, and both are a generalization of the current “perspective” tool to more than 4 vertices.

    As to other gimp tools: unfortunately, gimp does not have anything that would be suitable for the “straighten photo” case. The perspective tool works perfectly but can only handle 4 vertices. The IWarp tool works pixel-based and in a small separate window. There is also a bend upper/lower curve tool, which is some kind of generalization of the perspective tool, but it is still limited (only two envelope curves) and inconvenient (works in a separate window).

    Your assumption of “complex deformation, with more than 4 handles needs to respect the area” is not concise and in general not correct; most of the deformations that one would want to correct with Cage did not respect the area. Hope the alternatives I described look attractive enough for you to be implemented, they are crucial…

    • Michael:


      Sorry for the long delay. I’d say that what you describe is indeed not the goal of the cage tool and represent a different use case. But I hope that the cage tool adress some usecases also. Maybe one day someone will take care of these usecase, but be aware that even if the cage tool implement most of the code needed for that, it’s still something big.

      Also, be aware that i’m currently working on implementing the iWarp filter as a real tool for Gimp, so there won’t be a small preview windows anymore.

      If you have found some bugs in the cage tool or somewhere else, I would be pleased if you could fill a bug report:

      Thank you =)

      • Mic:

        Thanks for your response :-) I noticed your IWarp tool as well, unfortunately this is interactive and pixel-based, not a vector/envelope-based tool.

        I can only feel sorry that such a mature toolkit as Gimp is, still does not have a simple grid transform tool or envelope transform tool that would allow one to linearly reshape a geometry more complex than a 4-vertex one.

        I think this is exactly the use case for Cage, just the transformation is much simpler than you used – so that transformation of the inside of the cage is proportional to changes of the envelope (as one would expect).

    • Back-in-the-day it was mostly just a few drkins after work…although THAT crowd was right there with us…but in the part of town I grew up in, it was the norm and not just for the restaurant ‘clique’.I think maybe Tony should have dated his opinion to go with his ‘time period’…when I moved on to work restaurant jobs that were a little more ‘dignified’ or ‘cultured’ that was not the norm at all…and I don’t find or hear of it much today. Although it still goes on, I don’t think it would be found as the majority.As for the other article…what do you have your google alerts set for that you find these stories?!?!?! LOL