[vtkusers] Get IDs within vtkImageStencilData

Richard Brown richard.j.brown at live.co.uk
Mon Mar 14 06:26:17 EDT 2016


David, 

Sorry for the belated reply; it took me a while to get round to testing the new classes.
I can confirm that they respond perfectly to my needs, thanks a million!

Regards,
Richard

> On 25 Jan 2016, at 14:40, David Gobbi <david.gobbi at gmail.com> wrote:
> 
> Hi Richard,
> 
> I've put my code up on gitlab, three classes in total:
> https://gitlab.kitware.com/vtk/vtk/merge_requests/1118 <https://gitlab.kitware.com/vtk/vtk/merge_requests/1118>
> 
> Two of these classes are iterators, meaning that they allow you to
> write your own loop.  The third class is a filter that extracts all of
> the point data that lies within the stencil.  Here are some examples
> (the examples are python, C++ code would be similar):
> 
> # Example for iterating over all point Ids in an image
> iter = vtkImagePointDataIterator(image, image.GetExtent(), stencil)
> scalars = image.GetPointData().GetScalars()
> while (not iter.IsAtEnd()):
>     # loop over a contiguous span of Ids
>     for i in range(iter.GetId(), iter.GetId() + iter.GetSpanSize()):
>         value = scalars.GetTuple(i)
>     # advance to the next span
>     iter.NextSpan()
> 
> # Example for iterating over all points in an image
> iter = vtkImagePointIterator(image, image.GetExtent(), stencil)
> scalars = image.GetPointData().GetScalars()
> while (not iter.IsAtEnd()):
>     point = iter.GetPosition()
>     idx = iter.GetIndex()
>     value = scalars.GetTuple(iter.GetId())
>     iter.Next()
> 
> # Example for using the vtkImageToPoints filter
> filter = vtkImageToPoints()
> filter.SetInputConnection(reader.GetOutputPort())
> filter.SetStencilConnection(polyToStencil.GetOutputPort())
> filter.Update()
> # Get a polydata object with points and attributes
> polyData = filter.GetOutput()
> points = polyData.GetPoints()
> scalars = polyData.GetPointData().GetScalars()
> 
> I'm not sure if these were quite what you were looking for, I was
> aiming to create general-purpose classes.
> 
> Cheers,
>  - David
> 
> 
> 
> 
> On Wed, Jan 20, 2016 at 9:31 AM, David Gobbi <david.gobbi at gmail.com <mailto:david.gobbi at gmail.com>> wrote:
> Proposed patches for VTK are at this page:
> https://gitlab.kitware.com/vtk/vtk/merge_requests <https://gitlab.kitware.com/vtk/vtk/merge_requests>
> And a log of accepted patches is at this page:
> https://gitlab.kitware.com/groups/vtk <https://gitlab.kitware.com/groups/vtk>
> 
> When my patch is ready, I'll send you a link.
> 
>  - David
> 
> 
> On Wed, Jan 20, 2016 at 9:10 AM, Richard Brown <richard.j.brown at live.co.uk <mailto:richard.j.brown at live.co.uk>> wrote:
> Great thanks David.
> 
> Silly question, but where is gitlab?
> 
> Regards,
> Richard
> 
>> On 19 Jan 2016, at 23:09, David Gobbi <david.gobbi at gmail.com <mailto:david.gobbi at gmail.com>> wrote:
>> 
>> Hi Rich,
>> 
>> The quick answer is no, there are no classes in VTK to do this.
>> 
>> However, I have a class of my own called vtkImageExtractVoxels that
>> almost does what you need: it creates a vtkDataArray that contains the
>> the values of all of the voxels in the stencil.  It would be trivial to modify
>> this class so it so that it gives all the IDs.
>> 
>> Coincidentally, just 5 minutes before I saw your email, I started editing
>> this class because I need it to give the (x,y,z) of all in-stencil voxels.
>> So I'll get it to produce the IDs as well, and then put it on gitlab if you
>> want to try it out.
>> 
>>  - David
>> 
>> On Tue, Jan 19, 2016 at 2:59 PM, mbcx9rb9 <richard.j.brown at live.co.uk <mailto:richard.j.brown at live.co.uk>> wrote:
>> Hi all,
>> 
>> Is there any way to get a list containing the IDs of all voxels within a
>> vtkImageStencilData?
>> 
>> My method at the moment for getting all the voxels in the stencil is to
>> create a vtkOBBTree and check if the centre of each voxel is inside the
>> vtkPolyData related to the stencil, but this is very slow.
>> 
>> Thanks in advance for any pointers,
>> Rich
> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160314/3de41353/attachment.html>


More information about the vtkusers mailing list