8 #ifndef META_OCEAN_CV_DETECTOR_HEMI_CUBE_H
9 #define META_OCEAN_CV_DETECTOR_HEMI_CUBE_H
55 typedef std::unordered_map<MapIndex, IndexSet32, MapIndexHash>
Map;
71 HemiCube(
const unsigned int bins,
const unsigned int imageWidth,
const unsigned int imageHeight,
const Scalar focalLength);
77 inline bool isValid()
const;
143 inline size_t size()
const;
149 inline size_t nonEmptyBins()
const;
167 const Map& map()
const;
175 inline const FiniteLine2& operator[](
const unsigned int index)
const;
183 inline FiniteLine2& operator[](
const unsigned int index);
210 template <
bool tScale>
234 unsigned int imageWidth_ = 0u;
237 unsigned int imageHeight_ = 0u;
249 unsigned int numberBins_ = 0u;
260 ocean_assert(newLine.
isValid());
265 const unsigned int newLineIndex = (
unsigned int)
linesInMap_.size();
266 ocean_assert(bin.find(newLineIndex) == bin.end());
268 bin.insert(newLineIndex);
308 ocean_assert(index < (
unsigned int)
linesInMap_.size());
314 ocean_assert(index < (
unsigned int)
linesInMap_.size());
325 template <
bool tScale>
337 if constexpr (tScale)
339 const Scalar maxValue = std::max(std::abs(lineEquation[0]), std::max(std::abs(lineEquation[1]), std::abs(lineEquation[2])));
341 return lineEquation * (
Scalar(1.0) / maxValue);
Data structure used for efficient grouping to 2D line segments This data structure is inspired by and...
Definition: HemiCube.h:35
Vector2 principalPoint_
Principal point of the image in which the lines have have been found; using the image center should w...
Definition: HemiCube.h:240
size_t size() const
Return the number of lines stored in the Hemi cube.
Definition: HemiCube.h:280
Vector3 rayFrom(const Vector2 &point) const
Compute the point on the ray at a specific depth (3D ray which points from the center of projection t...
Definition: HemiCube.h:347
unsigned int numberBins_
Number of bins along one dimension (cube)
Definition: HemiCube.h:249
const FiniteLine2 & operator[](const unsigned int index) const
Get a const reference to a line in the Hemi cube.
Definition: HemiCube.h:306
Map map_
The actual map data structure.
Definition: HemiCube.h:246
HemiCube()=default
Default constructor.
std::unordered_map< MapIndex, IndexSet32, MapIndexHash > Map
The actual cube map: maps a line to a bin (set of line indices)
Definition: HemiCube.h:55
bool isValid() const
Check if the Hemi cube is fully initialized.
Definition: HemiCube.h:252
size_t nonEmptyBins() const
Return the number of bins in the Hemi cube which actually contain data.
Definition: HemiCube.h:285
MapIndex mapIndexFrom(const FiniteLine2 &line) const
Given a 2D line segment, compute its location (map index) in the cube map.
FiniteLines2 linesInMap_
All lines which are represented by their indices in the map.
Definition: HemiCube.h:231
PixelPosition hemiCubeCoordinatesFrom(const MapIndex &mapIndex) const
Given the map index of a line, compute its pixel location in a image representation of the cube map.
Definition: HemiCube.h:318
VectorT3< unsigned int > MapIndex
The location of a line in the cube map is defined as the triple (binX, binY, faceIndex),...
Definition: HemiCube.h:39
Vector3 lineEquationFrom(const FiniteLine2 &line) const
For a given 2D line segment compute its representation as a line equation (3D vector) The line equati...
Definition: HemiCube.h:326
unsigned int imageWidth_
Width of the image in which the lines in the cube map have been found; used to convert 2D image point...
Definition: HemiCube.h:234
const FiniteLines2 & lines() const
Get a reference to the lines stored in the Hemi cube.
Definition: HemiCube.h:296
HemiCube(const unsigned int bins, const unsigned int imageWidth, const unsigned int imageHeight, const Scalar focalLength)
Constructor.
void insert(const FiniteLine2 &newLine)
Add a line to the Hemi cube The line will be added as-is, it will not be merged with similar lines in...
Definition: HemiCube.h:257
unsigned int imageHeight_
Height of the image in which the lines in the cube map have been found; used to convert 2D image poin...
Definition: HemiCube.h:237
void clear()
Clear this Hemi cube.
Definition: HemiCube.h:290
void merge(const FiniteLines2 &lines, const Scalar maxLineDistance, const Scalar maxLineGap, Indices32 *mapping=nullptr, const Scalar cosAngle=Numeric::cos(Numeric::weakEps()))
Merge a similar lines in set of line segments Lines will be added to a Hemi cube internally.
IndexSet32 find(const FiniteLine2 &line, const Scalar radius=Scalar(1)) const
Find similar lines in Hemi cube.
const Map & map() const
Returns a reference to the internal map of lines indices.
Definition: HemiCube.h:301
Scalar focalLength_
Focal length of the original camera; used convert 2D image points into 3D rays.
Definition: HemiCube.h:243
static FiniteLine2 fuse(const FiniteLine2 &line0, const FiniteLine2 &line1)
Compute line segment that minimizes the distances to the endpoints of the input line segments Compute...
void updateLine(unsigned int index, const FiniteLine2 &updatedLine)
Update a line segment stored in the Hemi cube Updates the line segment at index index and its map ind...
static FiniteLines2 mergeGreedyBruteForce(const FiniteLines2 &lines, const Scalar maxLineDistance, const Scalar maxLineGap, Indices32 *mapping=nullptr, const Scalar cosAngle=Numeric::cos(Numeric::weakEps()))
Merge a similar lines in set of line segments (brute-force search/no use of Hemi cubes,...
bool isValid() const
Returns whether this line has valid parameters.
Definition: FiniteLine2.h:622
const VectorT2< T > & point0() const
Returns the first end point of the line.
Definition: FiniteLine2.h:348
const VectorT2< T > & point1() const
Returns the second end point of the line.
Definition: FiniteLine2.h:354
static constexpr T weakEps()
Returns a weak epsilon.
static T cos(const T value)
Returns the cosine of a given value.
Definition: Numeric.h:1584
static constexpr bool isNotEqualEps(const T value)
Returns whether a value is not smaller than or equal to a small epsilon.
Definition: Numeric.h:2237
This class implements a vector with three elements.
Definition: Vector3.h:97
VectorT3< T > cross(const VectorT3< T > &vector) const
Returns the cross product of two vectors.
Definition: Vector3.h:597
T length() const
Returns the length of the vector.
Definition: Vector3.h:664
std::set< Index32 > IndexSet32
Definition of a set holding 32 bit indices.
Definition: Base.h:114
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
PixelPositionT< unsigned int > PixelPosition
Definition of the default PixelPosition object with a data type allowing only positive coordinate val...
Definition: PixelPosition.h:27
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< FiniteLine2 > FiniteLines2
Definition of a vector holding FiniteLine2 objects.
Definition: FiniteLine2.h:57
VectorT3< Scalar > Vector3
Definition of a 3D vector.
Definition: Vector3.h:22
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition: Vector2.h:21
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15
Helper to compute hash values for map indices.
Definition: HemiCube.h:45
size_t operator()(const MapIndex &mapIndex) const noexcept
Compute hash value for a map index.