-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds a volumetric grid field to help with lookup in 3D. #406
Conversation
The following PR adds a datastructure that represents a sparse volumetric grid. It allows for storing data in 3D. # TODO - [ ] Write unit tests - [ ] docs Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #406 +/- ##
========================================
Coverage 99.73% 99.73%
========================================
Files 69 72 +3
Lines 6353 6474 +121
========================================
+ Hits 6336 6457 +121
Misses 17 17
Continue to review full report at Codecov.
|
Signed-off-by: Arjo Chakravarty <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A humble first pass until @scpeters gets to this.
inline namespace IGNITION_MATH_VERSION_NAMESPACE { | ||
template<typename T> | ||
/// \brief Lookup table for a volumetric dataset. This class is used to | ||
/// lookup indices for a large dataset thats organized in a grid. This |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjo129 nit:
/// lookup indices for a large dataset thats organized in a grid. This | |
/// lookup indices for a large dataset that's organized in a grid. This |
template<typename T> | ||
/// \brief Lookup table for a volumetric dataset. This class is used to | ||
/// lookup indices for a large dataset thats organized in a grid. This | ||
/// class is not meant to be used by non-grid like data sets. The grid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjo129 nit:
/// class is not meant to be used by non-grid like data sets. The grid | |
/// class is not meant to be used with non-grid like datasets. The grid |
// NOTE: This part of the code assumes an exact grid of points. | ||
// The grid may be distorted or the stride between different points | ||
// may not be the same, but fundamentally the data is structured in | ||
// may It keeps track of the axis indices for each point in the grid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjo129 nit: note got caught in between two trains of thoughts :)
// The grid may be distorted or the stride between different points | ||
// may not be the same, but fundamentally the data is structured in | ||
// may It keeps track of the axis indices for each point in the grid. | ||
for(auto pt : _cloud) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjo129 nit: use const references here.
|
||
for(std::size_t i = 0; i < _cloud.size(); ++i) | ||
{ | ||
auto pt = _cloud[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjo129 nit: use a const reference here
} | ||
else if (fabs(it->first - _value) < _tol) | ||
{ | ||
// Exact match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjo129 meta: why introduce a tolerance to check for almost exact matches when we can return all points and defer to the interpolation algorithm to judge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if you see how the GetInterpolators
works it returns a variable number of points. By doing this this way it makes for cleaner interpolation code as we can separate the kind of interpolation we want to use (none, linear, bilinear, trilinear) just based on the length of the return vector. If we were to go with the other alternative we would spend a lot more time debugging the corner cases of the interpolation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjo129 hmm, why special casing? Isn't linear (resp. bilinear) interpolation just trilinear interpolation for a point that is on an edge (resp. face) of the 3D volumes that make up its grid? I guess I'm missing some numerical nuances here. Anywho, so long as the tolerance can be adjusted I'm OK with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #412 for my original plan.
/// four corners, if along an edge two points and if coincident with a | ||
/// corner one point. If the data is sparse and missing indices then a | ||
/// nullopt will be returned. | ||
public: std::vector<std::optional<std::size_t>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjo129 meta: why return a sequence of optional values instead of just a plain sequence of values that may just be empty?
/// corner one point. If the data is sparse and missing indices then a | ||
/// nullopt will be returned. | ||
public: std::vector<std::optional<std::size_t>> | ||
GetInterpolators(Vector3<T> &_pt) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjo129 nit:
GetInterpolators(Vector3<T> &_pt) const | |
GetInterpolators(const Vector3<T> &_pt) const |
x_indices_by_lat.AddIndexIfNotFound(pt.X()); | ||
y_indices_by_lon.AddIndexIfNotFound(pt.Y()); | ||
z_indices_by_depth.AddIndexIfNotFound(pt.Z()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjo129 meta meta: if AxisIndex::AddIndexIfNotFound()
returned the corresponding index, neither AxisIndex::GetNumUniqueIndices()
nor AxisIndex::GetIndex()
would be necessary (and the same goes for the floating point equality comparison that AxisIndex::GetIndex()
is forced to do).
std::size_t x_index = x_indices_by_lat.GetIndex(pt.X()).value(); | ||
std::size_t y_index = y_indices_by_lon.GetIndex(pt.Y()).value(); | ||
std::size_t z_index = z_indices_by_depth.GetIndex(pt.Z()).value(); | ||
index_table[z_index][y_index][x_index] = i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjo129 meta: should we be checking for duplicates?
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
Superseded by #412 |
🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸
🎉 New feature
Closes #
Summary
The following PR adds a datastructure that represents a sparse volumetric grid. It allows for storing data in 3D.
TODO
Test it
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.