[Paraview] Finite-size voxels and Point vs. Cell Centered Image Data

Eric Nodwell enodwell at ucalgary.ca
Wed Jun 2 09:58:39 EDT 2010


Burlen,

I think that's the way to go.  However, it is still necessary to use scalars on CellData to get correct rendering.  Actually, for most filters, CellData scalars vtkImageData does work correctly.  However, it is easy to convert from PointData scalars data to CellData scalars, and since the underlying array of data is the same, there is no loss of efficiency (just some loss of programming clarity) .  This is the approach I've gone with.  Here's an example (single pixel, just to be as simple as possible).

// Create point-centered vtkImageData (single-pixel)
vtkImageData* imageAsPointCentered = vtkImageData::New();
imageAsPointCentered->SetScalarTypeToInt();
imageAsPointCentered->SetSpacing (1, 1, 1);
imageAsPointCentered->SetOrigin (0, 0, 0);
imageAsPointCentered->SetDimensions (1, 1, 1);  // SetExtent would be better
imageAsPointCentered->SetScalarComponentFromFloat (0,0,0,0,10);

// Do something with the point-centered vtkImageData here.

// Time to render, make a cell-centered vtkImageData of the same data.
vtkImageData* imageAsCellCentered = vtkImageData::New();
imageAsCellCentered->SetSpacing (1, 1, 1);
imageAsCellCentered->SetOrigin (-0.5,-0.5, -0.5);
imageAsCellCentered->SetDimensions (2, 2, 2);
imageAsCellCentered->GetCellData()->SetScalars (imageAsPointCentered->GetPointData()->GetScalars());

// Now render imageAsCellCentered / save to open in ParaView, etc...

cheers,
Eric


On 2010-06-01, at 5:30 PM, burlen wrote:

> Hi Eric,
>> I assume by dual grid you mean creating two vtkImageData objects
> No. I mean to suggest place the nodes of the vis grid (your vtkImageData) at the cell centers of the computation grid (what you have on disk). When you do this, you no longer have cell data, instead you have point data, which is what vtk needs.
> 
> I am attaching an illustration from an 2d cell centered AMR grid, but the idea is the same for 3D cell centered data on a uniform grid. See figs a and d.
> 
> Burlen
> 
> 
> Eric Nodwell wrote:
>> Burlen,
>> 
>> I assume by dual grid you mean creating two vtkImageData objects, which both contain pointers (properly registered and reference counted) to the same vtkDataArray object, but in one case, as the Scalars for the CellData, and in the other case as the Scalars for the PointsData.  This might work, although it does seem unnecessarily complicated for "storing voxels as volume elements" which would seem to be a common usage.  And I'm not sure it answers all the questions such as, how would you write the data to a file?  If you want it accurately rendered in ParaView, it needs to be stored with CellData Scalars, but that could be problematic if you (or someone else) wants to read it and process it with VTK again.
>> 
>> Also there seems to be no guarantee that vtkImageData won't clobber your CellData Scalars when you're not looking.  Consider the following method copied from vtkImageData.cxx .  I have no idea when this might be called, but notice that PointData Scalars will survive it, while CellData Scalars won't.
>> 
>> //----------------------------------------------------------------------------
>> // Graphics filters reallocate every execute.  Image filters try to reuse
>> // the scalars.
>> void vtkImageData::PrepareForNewData()
>> {
>>  // free everything but the scalars
>>  vtkDataArray *scalars = this->GetPointData()->GetScalars();
>>  if (scalars)
>>    {
>>    scalars->Register(this);
>>    }
>>  this->Initialize();
>>  if (scalars)
>>    {
>>    this->GetPointData()->SetScalars(scalars);
>>    scalars->UnRegister(this);
>>    }
>> }
>> 
>> 
>> 
>> On 2010-06-01, at 2:04 PM, burlen wrote:
>> 
>>  
>>> Hi Eric,
>>>    
>>>> Because now of course our scalar image data needs to be associated with cells, not to points.  But vtkImageData in many cases only deals with the scalar data attached to the PointData.
>>>>      
>>> Could you use the concept of a dual grid? In other words make your vis grid node centered with the nodes located on the cell centers of your computational grid? Your arrays end up in PointData that way with no interpolations required.
>>> 
>>> Burlen
>>> 
>>> Eric Nodwell wrote:
>>>    
>>>> Francois,
>>>> 
>>>> Thank you for the reply.
>>>> 
>>>> Using 2x2x2 points for one voxel is fine in principle.  The difficulty is, you can't really conveniently (as far as I can tell) use a vtkImageData object for this purpose.  Because now of course our scalar image data needs to be associated with cells, not to points.  But vtkImageData in many cases only deals with the scalar data attached to the PointData.  For example, this is from vtkImageData.cxx :
>>>> 
>>>> //----------------------------------------------------------------------------
>>>> // This method returns a pointer to the origin of the vtkImageData.
>>>> void *vtkImageData::GetScalarPointer()
>>>> {
>>>> if (this->PointData->GetScalars() == NULL)
>>>>   {
>>>>   vtkDebugMacro("Allocating scalars in ImageData");
>>>>   this->AllocateScalars();
>>>>   }
>>>> return this->PointData->GetScalars()->GetVoidPointer(0);
>>>> }
>>>> 
>>>> Notice that is method just grabs the Scalars from PointData, and other methods of vtkImageData are similar, so if you want to store the scalars in CellData, which is necessary represent voxels, it is quite difficult.
>>>> 
>>>> Eric
>>>> 
>>>> 
>>>>       
>>>>> Date: Tue, 1 Jun 2010 13:26:15 -0400
>>>>> From: Francois Bertel <francois.bertel at kitware.com>
>>>>> Subject: Re: [Paraview] Finite-size voxels and Point vs. Cell Centered
>>>>> 	Image	Data
>>>>> To: paraview at paraview.org
>>>>> Message-ID:
>>>>> 	<AANLkTikZ6uW4TOfEUdMDu0XOCwc_1b4_0rs9N_z9SGtr at mail.gmail.com>
>>>>> Content-Type: text/plain; charset=ISO-8859-1
>>>>> 
>>>>> Hello,
>>>>> 
>>>>> in vtkImageData, "Dimension" is the number of points along each axis,
>>>>> not the number of cells along each axis. If you want one voxel, then
>>>>> you need 2x2x2 points.
>>>>> Note that using GetDimension() is OK but SetDimension() is only here
>>>>> for backward compatibility, use SetExtent() instead:
>>>>> 
>>>>> image->SetExtent(0,1,0,1,0,1);
>>>>>           
>>>> _______________________________________________
>>>> 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 ParaView Wiki at: http://paraview.org/Wiki/ParaView
>>>> 
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.paraview.org/mailman/listinfo/paraview
>>>>       
>>>    
>> 
>>  
> 
> <dualgrid.png>



More information about the ParaView mailing list