[vtkusers] vtkImageData point extraction

David Gobbi david.gobbi at gmail.com
Tue Dec 28 12:53:58 EST 2010


Hi Karoush,

You, it looks like I did have the Source and Input switched in my last email.
The "outside the whole extent" error is a bit surprising to me, because the
vtkProbeFilter is supposed to automatically set the UpdateExtent to be
exactly the same as the WholeExtent.  So this error might be coming from
some earlier filter in the pipeline.

One thing you can check is that GetBounds() on your image data returns a
bounds that is at least as large as GetBounds() on your structured grid.
I'm just making a guess here, but the Spacing and Origin of your image
data might not be correct.  You should print them out (after calling Update,
of course) just to be sure.

  David


On Tue, Dec 28, 2010 at 9:31 AM, Jafari, Kourosh <kjafari at rad.hfh.edu> wrote:
> Thanks David,
>
> I had actually set up the points of the structured grid. I had replaced it with "..." in the e-mail to make it brief. I applied your suggestions but still it crashes. Following is the actual code (the structured grid here is just an example to test the code). Are you sure SetInput is for points in which we want to resample and SetSource is the volume? Actually, when I exchange their inputs the program does not crash but give the error message:
>
> ERROR: In ..\..\vtk-5.6.0\Filtering\vtkStreamingDemandDrivenPipeline.cxx, line 879
> vtkStreamingDemandDrivenPipeline (03CF52C8): The update extent specified in the information for output port 0 on algorithm vtkTrivialProducer(0259FD08) is 0 249 0 249 0 249, which is outside the whole extent 0 99 0 99 0 99.
>
> Thanks  a lot,
> Kourosh
>
> ----------------------------------------------------------
> The actual code that causes the program to crash:
>
>  vtkProbeFilter* probe = vtkProbeFilter::New();
>  // Create the structured grid
>  int i, j, k, kOffset, jOffset, offset;
>  float x[3], v[3], rMin=0, rMax=3.0, deltaRad, deltaZ;
>  float radius, theta;
>  static int dims[3]={100,100,100};
>  vtkStructuredGrid *sgrid = vtkStructuredGrid::New();
>  sgrid->SetDimensions(dims);
>  vtkFloatArray *vectors = vtkFloatArray::New();
>    vectors->SetNumberOfComponents(3);
>    vectors->SetNumberOfTuples(dims[0]*dims[1]*dims[2]);
>    vtkPoints *points = vtkPoints::New();
>  points->Allocate(dims[0]*dims[1]*dims[2]);
>  deltaZ = 2.0 / (dims[2]-1);
>  deltaRad = (rMax-rMin) / (dims[1]-1);
>  v[2]=0.0;
>  for ( k=0; k<dims[2]; k++)
>  {
>  x[2] = (-1.0 + k*deltaZ)*10;
>  kOffset = k * dims[0] * dims[1];
>  for (j=0; j<dims[1]; j++)
>  {
>   radius = rMin + j*deltaRad;
>   jOffset = j * dims[0];
>   for (i=0; i<dims[0]; i++)
>   {
>    v[0] = -x[1];
>    v[1] = x[0];
>    v[2] = 2;
>    x[0]=i;x[1]=j;x[2]=k;
>    offset = i + jOffset + kOffset;
>    points->InsertPoint(offset,x);
>    vectors->InsertTuple(offset,v);
>   }
>  }
>  }
>  sgrid->SetPoints(points);
>    points->Delete();
>  sgrid->GetPointData()->SetVectors(vectors);
>    vectors->Delete();
>
>  probe->SetInput(sgrid);
>  probe->SetSource(connector->GetOutput());
>  probe->SpatialMatchOff();
>  probe->Update();
>  vtkImageData *imageP = vtkImageData::New();
>  imageP->DeepCopy(probe->GetImageDataOutput());
>
>
>
>
>
>
>
>
>
>
>
>
>
> ________________________________________
> From: David Gobbi [david.gobbi at gmail.com]
> Sent: Tuesday, December 28, 2010 2:45 AM
> To: Jafari, Kourosh
> Cc: vtkusers at vtk.org
> Subject: Re: [vtkusers] vtkImageData point extraction
>
> Hi Kourosh,
>
> Don't use SpatialMatchOn() until you first have it working properly
> with SpatialMatchOff().  Also, don't forget to do probe->Update()
> before you use the probe filter's output.
>
> If sgrid->SetDimensions(dims) the only thing that you did to set up
> the structured grid, then that isn't enough.  The structured grid
> needs you to set the points (I've never used vtkStructuredGrid,
> myself, so I can't provide an example, but I'm sure that it takes a
> few more steps to create the data).
>
>  David
>
>
> On Sat, Dec 25, 2010 at 8:38 PM, Jafari, Kourosh <kjafari at rad.hfh.edu> wrote:
>> Hi David,
>>
>> I have similar a question. I have a 3D image volume and would like to sample it on a structured grid. Here is how I use it:
>>
>>  static int dims[3]={100,100,100};
>>  vtkStructuredGrid *sgrid = vtkStructuredGrid::New();
>>  sgrid->SetDimensions(dims);
>>
>> ....
>>
>>  probe->SetInput(sgrid);
>>  probe->SetSource(connector->GetOutput());
>>  probe->SpatialMatchOn();
>>
>>  vtkImageData *imageP = vtkImageData::New();
>>  imageP->DeepCopy(probe->GetImageDataOutput());
>>
>>
>> The type of connector->GetOutput() is vtkImageData which is the volume I'd like to sample. I later display imageP. There is no compilation error but it crashes when I run it. If I exchange the inputs of SetInput and SetSource, it does not crash but it does not do anything either. What am I missing?
>>
>> Thanks!!
>> Kourosh
>>
>>
>> ________________________________________
>> From: vtkusers-bounces at vtk.org [vtkusers-bounces at vtk.org] On Behalf Of David Gobbi [david.gobbi at gmail.com]
>> Sent: Friday, December 24, 2010 4:51 PM
>> To: Maxwell, Thomas P. (GSFC-606.2)[SCIENCE APPLICATIONS INTL CORP]
>> Cc: vtkusers at vtk.org
>> Subject: Re: [vtkusers] vtkImageData point extraction
>>
>> Hi Tom,
>>
>> I think you want vtkProbeFilter.  It takes two inputs, one input for
>> volumetric data and another input for a set of points whose scalars
>> will be interpolated from the first input.
>>
>> probeFilter->SetSourceConnection(<data-to-be-interpolated goes here>)
>> probeFilter->SetInputConnection(<point input goes here>)
>>
>> Is this what you were looking for?
>>
>>   David
>>
>>
>> On Thu, Dec 23, 2010 at 9:43 AM, Maxwell, Thomas P.
>> (GSFC-606.2)[SCIENCE APPLICATIONS INTL CORP] <thomas.maxwell at nasa.gov>
>> wrote:
>>>
>>> Is there a VTK filter that will take as input a vtkImageData and a list of
>>> (unstructured) points and then compute (as output) the image values at the
>>> specified point locations?
>>>
>>> Thanks,
>>> Tom
>> _______________________________________________
>> 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