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