Why is the imageIds array ordered from caudal to cranial in Cornerstone.js?

I have a question about the order of elements in the imageIds array in the ImageVolume and StreamingImageVolume classes. I had assumed that the imageIds array would be populated starting with the image id of the most cranial slice, but it seems to be the opposite. Upon checking, the imageIds array is populated starting with the image id of the most caudal slice.

As a result, the order of the one-dimensional array obtained via voxelManager.getCompleteScalarDataArray was also different from what I had intuitively expected. The value stored at index 0 corresponded to the value of column 0, row 0 of the most caudal slice image.

Is this ordering intentional in Cornerstone.js? My understanding is that, in general, smaller index numbers are assigned to more cranial slices. For instance, in Orthanc, I believe instance numbers are assigned in that way as well.

This is a good question.

We organize them using the function located at packages/core/src/utilities/sortImageIdsAndGetSpacing.ts.

I believe the order is arbitrary since the scalarDataArray lacks an index. However, the voxelManager includes methods like getAtIndex and getAtIJK, which should provide accurate results.