[vtkusers] remove vtkImageBlend item

Mauro Maiorca mauromaiorca at gmail.com
Thu Feb 3 10:18:04 EST 2011


Hi David,

thank you very much for your quick reply and your clarification! It
makes all sense now, and it works!
But, how can I keep track of a particular object, then?
I don't mind redrawing all the canvas, but I'm concerned about a
reasonably big image (i.e. up to 4096x4096 pixel): I assume each call
to blend->AddInputConnection(0,color->GetOutputPort()) will re-load
the whole image, unless AddInputConnection has a really smart
buffering policy (is it the case?).

cheers,
Mauro


On Fri, Feb 4, 2011 at 1:08 AM, David Gobbi <david.gobbi at gmail.com> wrote:
> Hi Mauro,
> I don't think that converting the image to a vtkImageStencilData is the
> correct approach.
> When you call blend->AddInputConnection(0, color->GetOutputPort())
> the first argument should always be 0.  All of the image inputs for
> vtkImageBlend go into port zero.  It is what VTK calls a "multiple
> input port," meaning that it is a port that can take multiple input
> connections.
> If you call blend->AddInputConnection(1, ...) then you are adding
> a connection to the second port, which is not an image port (as
> you have seen, it is a vtkImageStencilData port).  This is not what
> you want to do.
> Take a look at the documentation for vtkAlgorithm for more info on
> how ports/connections work.  The main idea is that VTK inputs are
> identified by two numbers: (port number, connection number), i.e.
> there is really a 2D array of inputs.
>  - David
>
> On Thu, Feb 3, 2011 at 6:46 AM, Mauro Maiorca <mauromaiorca at gmail.com>
> wrote:
>>
>> Hi David,
>>
>> thank you very much for your quick reply.
>> The function RemoveInputConnection was what I was actually looking
>> for, and works fine with the canvas objects.
>> I'll also take into account your clever suggestion to don't mess up
>> with the indexes!!
>> The "only" problem left is with AddInputConnection and the grayscale
>> 2D image (to which I have to attach/detach the canvas objects).
>> Before your input, I was using "blend->SetInput(color->GetOutput());"
>> where color is an instance of vtkImageMapToColors, that gets as input
>> a casted image (vtkImageCast) and a lookup table (vtkLookupTable).
>> Unfortunately, AddInputConnection wants vtkImageStencilData (while
>> SetInput is happy with vtkImageData), so I had to convert vtkImageData
>> into vtkImageStencilData. You actually helped a lot on that (you
>> replied few years ago to a similar help request), recommending the
>> good old Rube Goldberg machine and few handy tricks! However I'm still
>> far from the solution, what I've got till now (and still not quite
>> there) is:
>>
>> //convert poly to image data
>> vtkSmartPointer<vtkPolyDataToImageStencil> dataToStencil =
>> vtkSmartPointer<vtkPolyDataToImageStencil>::New();
>> dataToStencil->SetInputConnection (color->GetOutputPort());
>> dataToStencil -> Update();
>>
>> // Create an empty image
>> vtkSmartPointer<vtkImageGridSource> source =
>> vtkSmartPointer<vtkImageGridSource>::New();
>> source->SetFillValue(0);
>> source->SetLineValue (0);
>> source -> SetDataExtent ((imageCast->GetOutput())->GetExtent());
>> source->Update();
>>
>> //apply the stencil to the image
>> vtkSmartPointer<vtkImageStencil> stencil =
>> vtkSmartPointer<vtkImageStencil>::New();
>> stencil->SetInputConnection (source->GetOutputPort());
>> stencil -> SetStencil (dataToStencil->GetOutput() );
>> stencil -> ReverseStencilOn();
>> stencil -> Update();
>>
>> //blend
>> blend->AddInputConnection(0, stencil->GetOutputPort());
>>
>>
>> but nothing, it compiles but I get segmentation fault in runtime. The
>> segmentation fault goes away if I comment out the line:
>> blend->AddInputConnection(0, stencil->GetOutputPort());
>> I'm definitely forgetting something, but not sure what exactly! Any
>> suggestion would be appreciated!!!
>>
>> thanks a lot for your help!
>>
>> cheers,
>> Mauro
>>
>>
>>
>> On Mon, Jan 31, 2011 at 4:12 PM, David Gobbi <david.gobbi at gmail.com>
>> wrote:
>> > Hi Mauro,
>> >
>> > The inputs can be added/removed with these vtkAlgorithm methods:
>> >   blend->AddInputConnection(0, canvas->GetOutputPort());
>> >   blend->RemoveInputConnection(0, canvas->GetOutputPort());
>> >
>> > In all honesty, though, I find it easiest to call this:
>> >   blend->RemoveAllInputs();
>> > Then I can start over again by adding all the inputs. Otherwise,
>> > it can be difficult to keep the inputs in the correct order.
>> >
>> >  - David
>> >
>> > On Sun, Jan 30, 2011 at 9:11 PM, Mauro Maiorca <mauromaiorca at gmail.com>
>> > wrote:
>> >>
>> >> Hello vtk users,
>> >>
>> >> I'm struggling to understand how to remove an item from a vtkImageBlend
>> >> object.
>> >>
>> >> To be more specific, I have a (grayscale) 2D image and few
>> >> vtkImageCanvasSource2D objects to interactively attach/detach to the
>> >> greyscale image.
>> >> In order to attach the objects to the grayscale image I'm using
>> >> vtkImageBlend, and it's working fine.
>> >> The problem is to detach the vtkImageCanvasSource2D objects from
>> >> vtkImageBlend: I don't see any "remove" function in vtkImageBlend.
>> >> Do you know whether it is possible? If vtkImageBlend is not the best
>> >> approach to solve my problem, do you know a better (VTK) approach to
>> >> it?
>> >> As a quick and dirty solution, I create a new vtkImageBlend and I
>> >> attach to it the grayscale image plus all the
>> >> vtkImageCanvasSource2Dobjects except the one I want to "remove", it's
>> >> working but it's (obviously) slow with a big image and a big number of
>> >> objects.
>> >>
>> >> cheers,
>> >> Mauro
>> >> _______________________________________________
>> >> Powered by www.kitware.com
>> >>
>> >> Visit other Kitware open-source projects at
>> >> http://www.kitware.com/opensource/opensource.html
>> >>
>> >> Please keep messages on-topic and check the VTK FAQ at:
>> >> http://www.vtk.org/Wiki/VTK_FAQ
>> >>
>> >> Follow this link to subscribe/unsubscribe:
>> >> http://www.vtk.org/mailman/listinfo/vtkusers
>> >
>
>



More information about the vtkusers mailing list