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

Support setting horizontal and vertical resolution for GpuRays #229

Merged
merged 7 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions include/ignition/rendering/GpuRays.hh
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,38 @@ namespace ignition
/// \brief Get the number of channels used to store the ray data.
/// \return Channel count.
public: virtual unsigned int Channels() const = 0;

/// \brief Set the horizontal resolution. This number is multiplied by
/// RayCount to calculate RangeCount, which is the the number range data
/// points.
/// \sa RayCount()
/// \param[in] _resolution The new horizontal resolution. The
/// absolute value of this parameter is used to prevent a
/// negative resolution value.
public: virtual void SetHorizontalResolution(double _resolution) = 0;

/// \brief Get the horizontal resolution. This number is multiplied by
/// RayCount to calculate RangeCount, which is the the number range data
/// points.
/// \sa RayCount()
/// \return The horizontal resolution
public: virtual double HorizontalResolution() const = 0;

/// \brief Set the vertical resolution. This number is multiplied by
/// VerticalRayCount to calculate VerticalRangeCount, which is the the
/// number vertical range data points.
/// \param[in] _resolution The new vertical resolution. The
/// absolute value of this parameter is used to prevent a
/// negative resolution value.
/// \sa VerticalRayCount()
public: virtual void SetVerticalResolution(double _resolution) = 0;

/// \brief Get the vertical resolution. This number is multiplied by
/// VerticalRayCount to calculate VerticalRangeCount, which is the the
/// number vertical range data points.
/// \return The vertical resolution.
/// \sa VerticalRayCount()
public: virtual double VerticalResolution() const = 0;
};
}
}
Expand Down
48 changes: 44 additions & 4 deletions include/ignition/rendering/base/BaseGpuRays.hh
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ namespace ignition
// Documentation inherited.
public: virtual unsigned int Channels() const override;

// Documentation inherited.
public: virtual void SetHorizontalResolution(double _resolution) override;

// Documentation inherited.
public: virtual double HorizontalResolution() const override;

// Documentation inherited.
public: virtual void SetVerticalResolution(double resolution) override;

// Documentation inherited.
public: virtual double VerticalResolution() const override;

/// \brief maximum value used for data outside sensor range
public: float dataMaxVal = ignition::math::INF_D;

Expand Down Expand Up @@ -180,10 +192,10 @@ namespace ignition
protected: int vSamples = 0;

/// \brief Resolution of horizontal rays
protected: int hResolution = 1;
protected: double hResolution = 1;

/// \brief Resolution of vertical rays
protected: int vResolution = 1;
protected: double vResolution = 1;

/// \brief Number of channels used to store the data
protected: unsigned int channels = 1u;
Expand Down Expand Up @@ -348,7 +360,7 @@ namespace ignition
//////////////////////////////////////////////////
int BaseGpuRays<T>::RangeCount() const
{
return this->RayCount() * this->hResolution;
return static_cast<int>(this->RayCount() * this->hResolution);
}

template <class T>
Expand All @@ -369,7 +381,7 @@ namespace ignition
//////////////////////////////////////////////////
int BaseGpuRays<T>::VerticalRangeCount() const
{
return this->VerticalRayCount() * this->vResolution;
return static_cast<int>(this->VerticalRayCount() * this->vResolution);
}

template <class T>
Expand Down Expand Up @@ -406,6 +418,34 @@ namespace ignition
{
return this->channels;
}

template <class T>
//////////////////////////////////////////////////
void BaseGpuRays<T>::SetHorizontalResolution(double _resolution)
{
this->hResolution = std::abs(_resolution);
}

template <class T>
//////////////////////////////////////////////////
double BaseGpuRays<T>::HorizontalResolution() const
{
return this->hResolution;
}

template <class T>
//////////////////////////////////////////////////
void BaseGpuRays<T>::SetVerticalResolution(double _resolution)
{
this->vResolution = std::abs(_resolution);
}

template <class T>
//////////////////////////////////////////////////
double BaseGpuRays<T>::VerticalResolution() const
{
return this->vResolution;
}
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/integration/gpu_rays.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ void GpuRaysTest::Configure(const std::string &_renderEngine)

gpuRays->SetVerticalRayCount(67);
EXPECT_NEAR(gpuRays->VerticalRayCount(), 67, 1e-6);

EXPECT_DOUBLE_EQ(1.0, gpuRays->HorizontalResolution());
EXPECT_DOUBLE_EQ(1.0, gpuRays->VerticalResolution());

gpuRays->SetHorizontalResolution(0.1);
gpuRays->SetVerticalResolution(10.5);
EXPECT_DOUBLE_EQ(0.1, gpuRays->HorizontalResolution());
EXPECT_DOUBLE_EQ(10.5, gpuRays->VerticalResolution());

gpuRays->SetHorizontalResolution(-2.4);
gpuRays->SetVerticalResolution(-0.8);
EXPECT_DOUBLE_EQ(2.4, gpuRays->HorizontalResolution());
EXPECT_DOUBLE_EQ(0.8, gpuRays->VerticalResolution());
}

// Clean up
Expand Down