Fix vtk mrml double array storage node reader writer
Created by: jcfr
The reader in vtkMRMLDoubleArrayStorage
was always setting the
first line of values in the .mcsv
file as labels. If the stored
vtkMRMLDoubleArray
had not labels set, then the retrieved double
array labels would be set to the first line of numerical values,
associated with the first data point. This resulted in a missing
data point as well as shifted indices for all remaining points,
and incorrect labels.
The correction this commit offers is to write the line '# nolabels' in the file if labels exist. If the reader finds this line, it will set the first line of values as the first data point, instead of setting it as label values.
Examples :
Here are four examples with (u,v,w) as labels, (12.1,425.577,-454) for the first data point, and (8.79633e+09,0,-1) for the second one:
(1) New writer: vtkMRMLDoubleArrayNode with labels
# measurement file filename.mcsv
u,v,w
12.1,425.577,-454
8.79633e+09,0,-1
(2) New writer: vtkMRMLDoubleArrayNode with no labels set
# measurement file filename.mcsv
# nolabels
12.1,425.577,-454
8.79633e+09,0,-1
(3) Old writer: vtkMRMLDoubleArrayNode with labels
# measurement file filename.mcsv
# columns = x,y,yerr
u,v,w
12.1,425.577,-454
8.79633e+09,0,-1
(4) Old writer: vtkMRMLDoubleArrayNode with no labels set
# measurement file filename.mcsv
# columns = x,y,yerr
12.1,425.577,-454
8.79633e+09,0,-1
Observations :
The line '# columns = x,y,yerr' was hardcoded [1] in the former writer and had no meaning related to the actual double array node labels. The inspiration problably came from .mcsv or .acsv writers/readers [2][3] but had no effect here.
[1] https://github.com/Slicer/Slicer/blob/6e63b4bf5dbc65a9973160de7397dfc47882e038/Libs/MRML/Core/vtkMRMLDoubleArrayStorageNode.cxx#L244 [2] https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Markups/MRML/vtkMRMLMarkupsFiducialStorageNode.cxx#L159-L185 [3] https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Annotations/MRML/vtkMRMLAnnotationFiducialsStorageNode.cxx#L245-L268