Skip to content
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

Closed
wants to merge 9 commits into from

Conversation

arjo129
Copy link
Contributor

@arjo129 arjo129 commented Apr 8, 2022

🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸🔸

🎉 New feature

Closes #

Summary

The following PR adds a datastructure that represents a sparse volumetric grid. It allows for storing data in 3D.

TODO

  • Write unit tests
  • docs

Test it

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

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.

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]>
@github-actions github-actions bot added the 🌱 garden Ignition Garden label Apr 8, 2022
@chapulina chapulina added the MBARI-LRAUV Sponsored by MBARI-LRAUV project: https://github.com/osrf/lrauv label Apr 8, 2022
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
@arjo129 arjo129 mentioned this pull request Apr 12, 2022
Signed-off-by: Arjo Chakravarty <[email protected]>
Signed-off-by: Arjo Chakravarty <[email protected]>
@codecov
Copy link

codecov bot commented Apr 12, 2022

Codecov Report

Merging #406 (1038807) into main (120806b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 1038807 differs from pull request most recent head ca1fc75. Consider uploading reports for the commit ca1fc75 to get more accurate results

@@           Coverage Diff            @@
##             main     #406    +/-   ##
========================================
  Coverage   99.73%   99.73%            
========================================
  Files          69       72     +3     
  Lines        6353     6474   +121     
========================================
+ Hits         6336     6457   +121     
  Misses         17       17            
Impacted Files Coverage Δ
include/ignition/math/Helpers.hh 100.00% <100.00%> (ø)
include/ignition/math/PiecewiseScalarField3.hh 100.00% <100.00%> (ø)
include/ignition/math/VolumetricGridLookupField.hh 100.00% <100.00%> (ø)
include/ignition/math/detail/AxisIndex.hh 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 120806b...ca1fc75. Read the comment docs.

Signed-off-by: Arjo Chakravarty <[email protected]>
@arjo129 arjo129 marked this pull request as ready for review April 12, 2022 08:14
@arjo129 arjo129 requested a review from scpeters as a code owner April 12, 2022 08:14
Copy link
Contributor

@hidmic hidmic left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arjo129 nit:

Suggested change
/// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arjo129 nit:

Suggested change
/// 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.
Copy link
Contributor

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)
Copy link
Contributor

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];
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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>>
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arjo129 nit:

Suggested change
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());
}
Copy link
Contributor

@hidmic hidmic Apr 12, 2022

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;
Copy link
Contributor

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?

@arjo129
Copy link
Contributor Author

arjo129 commented Apr 21, 2022

Superseded by #412

@arjo129 arjo129 closed this Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌱 garden Ignition Garden MBARI-LRAUV Sponsored by MBARI-LRAUV project: https://github.com/osrf/lrauv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants