[Paraview] netCDF reader

Moreland, Kenneth kmorel at sandia.gov
Mon Jan 18 14:56:53 EST 2010


>> I'm not sure vtkImageData (and everything that uses it) really supports
>> negative spacing.  See, for example, this email thread:
>> http://www.vtk.org/pipermail/vtkusers/2009-May/100989.html.
>>  
> I agree. And that's why I have added the function fabs to make positive the
> tolerance variable.
> 
>  From ParaView3/VTK/IO/vtkNetCDFCOARDSReader.cxx (line 105...)
>     this->Spacing
>       = (this->Coordinates->GetValue(dimLen-1) - this->Origin)/(dimLen-1);
>     this->HasRegularSpacing = true;     // Then check to see if it is false.
>     double tolerance = 0.01*this->Spacing;
>     for (size_t i = 1; i < dimLen; i++)
>       {
>       double expectedValue = this->Origin + i*this->Spacing;
>       double actualValue = this->Coordinates->GetValue(i);
>       if (   (actualValue < expectedValue-tolerance)
>           || (actualValue > expectedValue+tolerance) )
>         {
>         this->HasRegularSpacing = false;
>         fprintf(stderr,"HasRegularSpacing = false");
>         break;
>         }
>       }
> 
> As I have written, if a coordinate variable goes from 90 to -90
> (decreasing) with dimLen=7
> (-90, -60, -30, 0, 30, 60, 90)
> then Spacing variable is (-90 -90)/6 = -30 so negative, as tolerance
> value equals to -0.3
> expectedValue for i equals  90 +30 = 120 instead of 60 !
> Consequence you get a "HasRegularSpacing = false"  whereas the grid is
> regular.
> Put a simple fabs solves the problem
> double tolerance = fabs(0.01*this->Spacing);
> Is it clearer ?

No.  I already understand that if the tolerance gets a negative value, the
HasRegularSpacing check will fail even if the spacing really is regular.
And I understand how using abs will fix that.

My point is that if the spacing is negative, then you cannot use a
vtkImageData because vtkImageData does not support negative spacing.  And
the only reason for the HasRegularSpacing check is there in the first place
is to decide whether to use a vtkImageData.

So, the code would be clearer if there was a statement like
if(this->Spacing<=0.0) { skip HasRegularSpacing check and use
vtkRectilinearGrid instead of vtkImagedata }.  But regardless, the code ends
up doing the right thing even if technically HasRegularSpacing is set to
false instead of true.

>>  
>>> - Test on units should be case independant
>>> line 133, units.find(" since ")
>>> I have netCDF files where "since" is typed with uppercase (generated by
>>> ferret software from the NOAA/PMEL).
>>>    
>> 
>> That is easy enough to change.
>>  
> Do you mean that the user have to change it by himself using ncrename
> (netcdf operators).
> I hope not and I consider that it should be treated within the reader. A
> user does not care
> about a typology of an attribut.
> Having said that, I don't know how to lowercase a vtkStdString.

I mean it is an easy fix in the code.  I checked in a fix this morning.

-Ken

   ****      Kenneth Moreland
    ***      Sandia National Laboratories
***********  
*** *** ***  email: kmorel at sandia.gov
**  ***  **  phone: (505) 844-8919
    ***      web:   http://www.cs.unm.edu/~kmorel





More information about the ParaView mailing list