# Child tool functionality

Instances of tools registered with `supportChildTools=true` (see Tool Registration Arguments) can be parents to other tool instances. Parent instances can pass a `Transform` or `Image` to child tools.

The parent/child relationship is useful for image filter- and locator tools. For accessing arbitrary results, result references should be used instead.

## Changing the image (filter tools)

To pass a modified image to child-tools, add an `Image` crown instance to `output` with the name “Image” inside the execute function.

This example adds an inverted copy of the image:

    output:add("Image", input:getImage():invert())

A child to a tool with an “Image”-result will get the modified image from `input:getImage()`. This can be used to implement tools that act as image filters.

When a tool that sets the “Image”-result or one of its children is selected in the user interface, the resulting image will be shown in the Image view.

Note

The Image result does not need to be declared in the call to `Tool.register`.

## Specifying a transform (locator tools)

To pass a transform to child tools, call `output:setTransform2D()` or `output:setTransform3D()` with a `Transform` crown instance as argument inside the execute function.

This example adds a transform that shifts regions a bit:

    local transform = Transform.createFromMatrix2D(Matrix.createFromVector(
        {1, 0, 10,
         0, 1, 20,
         0, 0,  1}, 3, 3))

    output:setTransform2D(transform)

A child to a tool that sets the “Transform”-result will get its source regions transformed by that transform from `input:getTransformedRegion()`. This can be used to create “locator”-tools that locate a feature in the image for relative placement of regions for child tools.