Skip to content

Commit

Permalink
Waves: add accessor to the tile size and cell count in triangulated g…
Browse files Browse the repository at this point in the history
…rid. (#119)

- Add accessors to TriangulatedGrid.
- Use array instead of tuple for dimensions (are homogenous and also support structured binding).

Signed-off-by: Rhys Mainwaring <[email protected]>
  • Loading branch information
srmainwaring authored Jan 20, 2023
1 parent bbd0f15 commit 2d1191f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 45 deletions.
6 changes: 3 additions & 3 deletions gz-waves/include/gz/waves/OceanTile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#ifndef GZ_WAVES_OCEANTILE_HH_
#define GZ_WAVES_OCEANTILE_HH_

#include <array>
#include <memory>
#include <tuple>
#include <vector>

#include <gz/math.hh>
Expand Down Expand Up @@ -47,11 +47,11 @@ class OceanTileT
explicit OceanTileT(WaveParametersPtr params, bool has_visuals = true);

/// \brief The size of the wave tile (m).
std::tuple<double, double> TileSize() const;
std::array<double, 2> TileSize() const;

/// \brief The number of cells in the wave tile in each direction.
/// The tile contains (nx + 1) * (ny + 1) vertices.
std::tuple<Index, Index> CellCount() const;
std::array<Index, 2> CellCount() const;

void SetWindVelocity(double ux, double uy);

Expand Down
4 changes: 4 additions & 0 deletions gz-waves/include/gz/waves/TriangulatedGrid.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef GZ_WAVES_TRIANGULATEDGRID_HH_
#define GZ_WAVES_TRIANGULATEDGRID_HH_

#include <array>
#include <memory>
#include <vector>

Expand Down Expand Up @@ -64,6 +65,9 @@ class TriangulatedGrid
void UpdatePoints(const std::vector<math::Vector3d>& from);
void UpdatePoints(const cgal::Mesh& from);

std::array<double, 2> TileSize() const;
std::array<Index, 2> CellCount() const;

private:
class Private;
std::unique_ptr<Private> impl_;
Expand Down
6 changes: 3 additions & 3 deletions gz-waves/include/gz/waves/WaveParameters.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#ifndef GZ_WAVES_WAVEPARAMETERS_HH_
#define GZ_WAVES_WAVEPARAMETERS_HH_

#include <array>
#include <memory>
#include <string>
#include <tuple>
#include <vector>

#include <gz/math/Vector2.hh>
Expand Down Expand Up @@ -67,10 +67,10 @@ class WaveParameters
std::string Algorithm() const;

/// \brief The size of the wave tile (m).
std::tuple<double, double> TileSize() const;
std::array<double, 2> TileSize() const;

/// \brief The number of cells in the wave tile in each direction.
std::tuple<Index, Index> CellCount() const;
std::array<Index, 2> CellCount() const;

/// \brief The number of wave components.
Index Number() const;
Expand Down
17 changes: 9 additions & 8 deletions gz-waves/src/OceanTile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <Eigen/Dense>

#include <array>
#include <cmath>
#include <iostream>
#include <vector>
Expand Down Expand Up @@ -1013,16 +1014,16 @@ void OceanTileT<gz::math::Vector3d>::SetWindVelocity(double ux, double uy)

//////////////////////////////////////////////////
template <>
std::tuple<double, double> OceanTileT<gz::math::Vector3d>::TileSize() const
std::array<double, 2> OceanTileT<gz::math::Vector3d>::TileSize() const
{
return std::make_tuple(impl_->lx_, impl_->ly_);
return {impl_->lx_, impl_->ly_};
}

//////////////////////////////////////////////////
template <>
std::tuple<Index, Index> OceanTileT<gz::math::Vector3d>::CellCount() const
std::array<Index, 2> OceanTileT<gz::math::Vector3d>::CellCount() const
{
return std::make_tuple(impl_->nx_, impl_->ny_);
return {impl_->nx_, impl_->ny_};
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -1135,16 +1136,16 @@ void OceanTileT<cgal::Point3>::SetWindVelocity(double ux, double uy)

//////////////////////////////////////////////////
template <>
std::tuple<double, double> OceanTileT<cgal::Point3>::TileSize() const
std::array<double, 2> OceanTileT<cgal::Point3>::TileSize() const
{
return std::make_tuple(impl_->lx_, impl_->ly_);
return {impl_->lx_, impl_->ly_};
}

//////////////////////////////////////////////////
template <>
std::tuple<Index, Index> OceanTileT<cgal::Point3>::CellCount() const
std::array<Index, 2> OceanTileT<cgal::Point3>::CellCount() const
{
return std::make_tuple(impl_->nx_, impl_->ny_);
return {impl_->nx_, impl_->ny_};
}

//////////////////////////////////////////////////
Expand Down
66 changes: 48 additions & 18 deletions gz-waves/src/TriangulatedGrid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ void TriangulatedGrid::Private::UpdatePoints(const cgal::Mesh& from) {

//////////////////////////////////////////////////
//////////////////////////////////////////////////
TriangulatedGrid::~TriangulatedGrid() {
TriangulatedGrid::~TriangulatedGrid()
{
}

//////////////////////////////////////////////////
Expand All @@ -578,18 +579,21 @@ TriangulatedGrid::TriangulatedGrid(Index nx, Index ny, double lx, double ly) :
}

//////////////////////////////////////////////////
void TriangulatedGrid::CreateMesh() {
void TriangulatedGrid::CreateMesh()
{
impl_->CreateMesh();
}

//////////////////////////////////////////////////
void TriangulatedGrid::CreateTriangulation() {
void TriangulatedGrid::CreateTriangulation()
{
impl_->CreateTriangulation();
}

//////////////////////////////////////////////////
std::unique_ptr<TriangulatedGrid> TriangulatedGrid::Create(
Index nx, Index ny, double lx, double ly) {
Index nx, Index ny, double lx, double ly)
{
std::unique_ptr<TriangulatedGrid> instance =
std::make_unique<TriangulatedGrid>(nx, ny, lx, ly);
instance->CreateMesh();
Expand All @@ -599,77 +603,103 @@ std::unique_ptr<TriangulatedGrid> TriangulatedGrid::Create(

//////////////////////////////////////////////////
bool TriangulatedGrid::Locate(const cgal::Point3& query,
int64_t& faceIndex) const {
int64_t& faceIndex) const
{
return impl_->Locate(query, faceIndex);
}

//////////////////////////////////////////////////
bool TriangulatedGrid::Height(const cgal::Point3& query,
double& height) const {
double& height) const
{
return impl_->Height(query, height);
}

//////////////////////////////////////////////////
bool TriangulatedGrid::Height(const std::vector<cgal::Point3>& queries,
std::vector<double>& heights) const {
std::vector<double>& heights) const
{
return impl_->Height(queries, heights);
}

//////////////////////////////////////////////////
bool TriangulatedGrid::Interpolate(TriangulatedGrid& patch) const {
bool TriangulatedGrid::Interpolate(TriangulatedGrid& patch) const
{
return impl_->Interpolate(patch);
}

//////////////////////////////////////////////////
const Point3Range& TriangulatedGrid::Points() const {
const Point3Range& TriangulatedGrid::Points() const
{
return impl_->Points();
}

//////////////////////////////////////////////////
const Index3Range& TriangulatedGrid::Indices() const {
const Index3Range& TriangulatedGrid::Indices() const
{
return impl_->Indices();
}

//////////////////////////////////////////////////
const cgal::Point3& TriangulatedGrid::Origin() const {
const cgal::Point3& TriangulatedGrid::Origin() const
{
return impl_->Origin();
}

//////////////////////////////////////////////////
void TriangulatedGrid::ApplyPose(const gz::math::Pose3d& pose) {
void TriangulatedGrid::ApplyPose(const gz::math::Pose3d& pose)
{
impl_->ApplyPose(pose);
}

//////////////////////////////////////////////////
bool TriangulatedGrid::IsValid(bool verbose) const {
bool TriangulatedGrid::IsValid(bool verbose) const
{
return impl_->IsValid(verbose);
}

//////////////////////////////////////////////////
void TriangulatedGrid::DebugPrintMesh() const {
void TriangulatedGrid::DebugPrintMesh() const
{
impl_->DebugPrintMesh();
}

//////////////////////////////////////////////////
void TriangulatedGrid::DebugPrintTriangulation() const {
void TriangulatedGrid::DebugPrintTriangulation() const
{
impl_->DebugPrintTriangulation();
}

//////////////////////////////////////////////////
void TriangulatedGrid::UpdatePoints(const std::vector<cgal::Point3>& from) {
void TriangulatedGrid::UpdatePoints(const std::vector<cgal::Point3>& from)
{
impl_->UpdatePoints(from);
}

//////////////////////////////////////////////////
void TriangulatedGrid::UpdatePoints(
const std::vector<gz::math::Vector3d>& from) {
const std::vector<gz::math::Vector3d>& from)
{
impl_->UpdatePoints(from);
}

//////////////////////////////////////////////////
void TriangulatedGrid::UpdatePoints(const cgal::Mesh& from) {
void TriangulatedGrid::UpdatePoints(const cgal::Mesh& from)
{
impl_->UpdatePoints(from);
}

//////////////////////////////////////////////////
std::array<double, 2> TriangulatedGrid::TileSize() const
{
return {impl_->lx_, impl_->ly_};
}

//////////////////////////////////////////////////
std::array<Index, 2> TriangulatedGrid::CellCount() const
{
return {impl_->nx_, impl_->ny_};
}

} // namespace waves
} // namespace gz
26 changes: 13 additions & 13 deletions gz-waves/src/WaveParameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

#include "gz/waves/WaveParameters.hh"

#include <array>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>

#include <gz/common.hh>
#include <gz/msgs.hh>
Expand Down Expand Up @@ -58,10 +58,10 @@ class WaveParametersPrivate
std::string algorithm_{"fft"};

/// \brief The size of the wave tile.
std::tuple<double, double> tile_size_{256.0, 256.0};
std::array<double, 2> tile_size_{256.0, 256.0};

/// \brief The size of the wave tile.
std::tuple<Index, Index> cell_count_{128, 128};
std::array<Index, 2> cell_count_{128, 128};

/// \brief The number of component waves.
Index number_{1};
Expand Down Expand Up @@ -292,7 +292,7 @@ void WaveParameters::SetFromSDF(sdf::Element& sdf)
sdf::Errors errors;
if (param->Get(value, errors))
{
impl_->tile_size_ = std::make_tuple(value[0], value[1]);
impl_->tile_size_ = {value[0], value[1]};
found = true;
}
}
Expand All @@ -302,7 +302,7 @@ void WaveParameters::SetFromSDF(sdf::Element& sdf)
sdf::Errors errors;
if (param->Get(value, errors))
{
impl_->tile_size_ = std::make_tuple(value, value);
impl_->tile_size_ = {value, value};
found = true;
}
}
Expand All @@ -323,7 +323,7 @@ void WaveParameters::SetFromSDF(sdf::Element& sdf)
sdf::Errors errors;
if (param->Get(value, errors))
{
impl_->cell_count_ = std::make_tuple(value[0], value[1]);
impl_->cell_count_ = {value[0], value[1]};
found = true;
}
}
Expand All @@ -334,7 +334,7 @@ void WaveParameters::SetFromSDF(sdf::Element& sdf)
if (param->Get(value, errors))
{
Index index = value;
impl_->cell_count_ = std::make_tuple(index, index);
impl_->cell_count_ = {index, index};
found = true;
}
}
Expand Down Expand Up @@ -393,13 +393,13 @@ std::string WaveParameters::Algorithm() const
}

//////////////////////////////////////////////////
std::tuple<double, double> WaveParameters::TileSize() const
std::array<double, 2> WaveParameters::TileSize() const
{
return impl_->tile_size_;
}

//////////////////////////////////////////////////
std::tuple<Index, Index> WaveParameters::CellCount() const
std::array<Index, 2> WaveParameters::CellCount() const
{
return impl_->cell_count_;
}
Expand Down Expand Up @@ -504,27 +504,27 @@ void WaveParameters::SetAlgorithm(const std::string& value)
//////////////////////////////////////////////////
void WaveParameters::SetTileSize(double value)
{
impl_->tile_size_ = std::make_tuple(value, value);
impl_->tile_size_ = {value, value};
impl_->Recalculate();
}

void WaveParameters::SetTileSize(double lx, double ly)
{
impl_->tile_size_ = std::make_tuple(lx, ly);
impl_->tile_size_ = {lx, ly};
impl_->Recalculate();
}

//////////////////////////////////////////////////
void WaveParameters::SetCellCount(Index value)
{
impl_->cell_count_ = std::make_tuple(value, value);
impl_->cell_count_ = {value, value};
impl_->Recalculate();
}

//////////////////////////////////////////////////
void WaveParameters::SetCellCount(Index nx, Index ny)
{
impl_->cell_count_ = std::make_tuple(nx, ny);
impl_->cell_count_ = {nx, ny};
impl_->Recalculate();
}

Expand Down

0 comments on commit 2d1191f

Please sign in to comment.