Repository navigation
Add File::readGrids() - #2356
Conversation
5cb2416 to
69410f9
Compare
Signed-off-by: Dan Bailey <danbailey@ilm.com>
69410f9 to
29dbb01
Compare
Signed-off-by: Dan Bailey <danbailey@ilm.com>
There was a problem hiding this comment.
Looks good with a few exceptions:
See in-lined comment about missing "this->"
It seem to me that similarly named grids with shared trees are duplicated when calling readGrids. That is readGrids() loses instance sharing when converting streamed files. In File.cc (lines 548–551), each cached grid is resolved independently. For two same-name grids sharing a tree, conversion creates two separate trees.
- getGrids(options) preserves tree sharing.
- readGrids("density", options) breaks sharing for files written through io::Stream.
- Files containing grid offsets preserve sharing correctly.
This contradicts the new API’s documented behavior and can multiply conversion work and memory consumption. Reusing the source-tree cache already implemented in getGrids() would address it.
| @@ -519,7 +519,6 @@ File::readGrid(const Name& name, const io::ReadOptions& readOptions) | |||
| // (along with the entire contents of the file, because the file | |||
| // doesn't support random access), retrieve and return it. | |||
| GridBase::Ptr cachedGrid = retrieveCachedGrid(name); | |||
There was a problem hiding this comment.
Please add this-> here and to the new calls to member functions. I prefer this style because it makes calls on the current object immediately distinguishable from calls to free functions.
|
|
||
| // Seek to and read in the grid from the file. | ||
| const GridDescriptor& gd = it->second; | ||
| return readGridFromDescriptor(it->second, readOptions); |
There was a problem hiding this comment.
Please add this-> here and to the new calls to member functions. I prefer this style because it makes calls on the current object immediately distinguishable from calls to free functions.
| } else if (readOptions.clipBBox.isSorted()) { | ||
| // A clip depends on each grid's own transform, so instances do not share trees. | ||
| for (NameMapCIter it = range.first; it != range.second; ++it) { | ||
| ret->push_back(readGridFromDescriptor(it->second, readOptions)); |
There was a problem hiding this comment.
Please add this-> here and to the new calls to member functions. I prefer this style because it makes calls on the current object immediately distinguishable from calls to free functions.
|
|
||
| const std::pair<NameMapCIter, NameMapCIter> range = mGridDescriptors.equal_range(name); | ||
|
|
||
| if (!inputHasGridOffsets()) { |
There was a problem hiding this comment.
Please add this-> here and to the new calls to member functions. I prefer this style because it makes calls on the current object immediately distinguishable from calls to free functions.
| for (NameMapCIter it = range.first; it != range.second; ++it) { | ||
| const auto cachedIt = mNamedGrids.find(it->second.uniqueName()); | ||
| if (cachedIt == mNamedGrids.end()) continue; | ||
| ret->push_back(resolveCachedGrid(cachedIt->second, readOptions, mReadDiagnostics)); |
There was a problem hiding this comment.
Please add this-> here and to the new calls to member functions. I prefer this style because it makes calls on the current object immediately distinguishable from calls to free functions.
|
|
||
| for (NameMapCIter it = range.first; it != range.second; ++it) { | ||
| const GridDescriptor& gd = it->second; | ||
| gd.seekToGrid(inputStream()); |
There was a problem hiding this comment.
Please add this-> here and to the new calls to member functions. I prefer this style because it makes calls on the current object immediately distinguishable from calls to free functions.
| for (NameMapCIter it = range.first; it != range.second; ++it) { | ||
| const GridDescriptor& gd = it->second; | ||
| gd.seekToGrid(inputStream()); | ||
| GridBase::Ptr grid = Archive::readGrid(gd, inputStream(), readOptions, mReadDiagnostics); |
There was a problem hiding this comment.
Please add this-> here and to the new calls to member functions. I prefer this style because it makes calls on the current object immediately distinguishable from calls to free functions.
| << "\" for grid " << GridDescriptor::nameAsString(gd.uniqueName()) | ||
| << " in file " << mFilename); | ||
| } | ||
| parentIt->second.seekToGrid(inputStream()); |
There was a problem hiding this comment.
Please add this-> here and to the new calls to member functions. I prefer this style because it makes calls on the current object immediately distinguishable from calls to free functions.
| } | ||
| parentIt->second.seekToGrid(inputStream()); | ||
| namedGrids[gd.instanceParentName()] = | ||
| Archive::readGrid(parentIt->second, inputStream(), readOptions, mReadDiagnostics); |
There was a problem hiding this comment.
Please add this-> here and to the new calls to member functions. I prefer this style because it makes calls on the current object immediately distinguishable from calls to free functions.
| // Seek to and read in the grid from the file. | ||
| gd.seekToGrid(inputStream()); | ||
| grid = Archive::readGrid(gd, inputStream(), readOptions, mReadDiagnostics); | ||
| GridBase::Ptr grid = Archive::readGrid(gd, inputStream(), readOptions, mReadDiagnostics); |
There was a problem hiding this comment.
Please add this-> here and to the new calls to member functions. I prefer this style because it makes calls on the current object immediately distinguishable from calls to free functions.
Signed-off-by: Dan Bailey <danbailey@ilm.com>
Signed-off-by: Dan Bailey <danbailey@ilm.com>
Signed-off-by: Dan Bailey <danbailey@ilm.com>
I think you're right. I thought I'd go over the other instance cases to confirm there was nothing missing and I also found a bug in One more thing to highlight - for all clipping methods used with files with grid offsets, the grids get de-instanced. This has always been the case, for example Files with and without grid offsets adds so much complexity, I am glad we are moving away from this in the new file format. :) Finally, I made the changes you requested to add |
kmuseth
left a comment
There was a problem hiding this comment.
Thanks for addressing my comments - I'll approve
Signed-off-by: Dan Bailey <danbailey@ilm.com>
802689a
into
AcademySoftwareFoundation:master
I believe this was functionality that was always intended to be added. In fact, there was a "@todo GridPtrVec readAllGrids(const Name&)" in the code which matches the method I am adding.
The problem is that when you have multiple grids with the same name - for example two grids called "density", the names get changed to "density[0]" and "density[1]" to disambiguate them, which requires the user to extract the names from the metadata and to parse these names and then iterate over all grids to which this applies and read them one-by-one. This is complicated workflow.
This new method
File::readGrids(const Name&, ...)allows the user to callreadGrids("density", ...)and it will read all grids with that name and return a populated GridPtrVecPtr. The grids are stored in the vector in the same order in which they appear in the file. I also added this to the Python bindings.