ICF 3.1.1.10
Technical documentation of ICF Libraries
CHoughSpace2d.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// STL includes
10#include <cmath>
11
12// Qt includes
13#include <QtCore/QMultiMap>
14
15// ICF includes
16#include <i2d/CVector2d.h>
17#include <iimg/CGeneralBitmap.h>
18#include <ialgo/TIHoughSpace.h>
20
21
22namespace ialgo
23{
24
25
31 virtual public TIHoughSpace<2>
32{
33public:
35
37
39 CHoughSpace2d(const istd::CIndex2d& size, bool isWrappedX = false, bool isWrappedY = false);
40
42 const istd::CIndex2d& size,
43 bool isWrappedX,
44 bool isWrappedY,
45 bool isFloatSpace);
46
51 void SetDimensionWrapped(int dimensionIndex, bool state);
52
56 template <typename Operation>
57 void ApplyOperation(Operation operation);
58
62 template <typename Operation>
63 void CombineWithSpace(const CHoughSpace2d& space, Operation operation);
64
65 // reimplemented (ialgo::TIHoughSpace<2>)
67 virtual bool CreateHoughSpace(const istd::TIndex<2>& size, const double& initValue = 0);
68 virtual bool IsDimensionWrapped(int dimensionIndex) const;
69 virtual ExtensionMode GetExtensionMode(int dimensionIndex) const;
70 virtual void IncreaseValueAt(const imath::TVector<2>& position, double value);
71 virtual void SmoothHoughSpace(const istd::TIndex<2>& iterations);
72 virtual bool AnalyseHoughSpace(
73 const double& minValue,
74 ResultsConsumer& resultProcessor) const;
75 virtual bool ExtractToBitmap(iimg::IBitmap& bitmap) const;
76 virtual bool GetSpacePosition(const imath::TVector<2>& position, imath::TVector<2>& result) const;
77 virtual double GetSpaceDistance(const imath::TVector<2>& position1, const imath::TVector<2>& position2) const;
78 virtual double GetSpaceDistance2(const imath::TVector<2>& position1, const imath::TVector<2>& position2) const;
79
80 // reimplemented (iimg::CGeneralBitmap)
81 virtual bool CreateBitmap(PixelFormat pixelFormat, const istd::CIndex2d& size, int pixelBitsCount = 0, int componentsCount = 0);
82 virtual bool CreateBitmap(PixelFormat pixelFormat, const istd::CIndex2d& size, istd::COptMemory&& data, int linesDifference = 0);
83
84private:
85 bool m_isWrapped[2];
86};
87
88
89// inline methods
90
91inline double CHoughSpace2d::GetSpaceDistance(const imath::TVector<2>& position1, const imath::TVector<2>& position2) const
92{
93 return qSqrt(GetSpaceDistance2(position1, position2));
94}
95
96
97inline double CHoughSpace2d::GetSpaceDistance2(const imath::TVector<2>& position1, const imath::TVector<2>& position2) const
98{
100
101 i2d::CVector2d diff = position2 - position1;
102 if (m_isWrapped[0]){
103 double offset = spaceSize.GetX() * 0.5;
104 diff.SetX(std::fmod(diff.GetX() + offset + spaceSize.GetX(), spaceSize.GetX()) - offset);
105 }
106
107 if (m_isWrapped[1]){
108 double offset = spaceSize.GetY() * 0.5;
109 diff.SetY(std::fmod(diff.GetY() + offset + spaceSize.GetY(), spaceSize.GetY()) - offset);
110 }
111
112 return diff.GetLength2();
113}
114
115
116// template methods
117
118template <typename Operation>
119void CHoughSpace2d::ApplyOperation(Operation operation)
120{
121
123
124 for (int y = 0; y < size.GetY(); ++y){
126 float* linePtr = (float*)BaseClass::GetLinePtr(y);
127 for (int x = 0; x < size.GetX(); ++x){
128 linePtr[x] = operation(linePtr[x]);
129 }
130 }
131 else{
132 Q_ASSERT(GetPixelFormat() == PF_GRAY32);
133
134 quint32* linePtr = (quint32*)BaseClass::GetLinePtr(y);
135 for (int x = 0; x < size.GetX(); ++x){
136 linePtr[x] = operation(linePtr[x]);
137 }
138 }
139 }
140}
141
142
143template <typename Operation>
144void CHoughSpace2d::CombineWithSpace(const CHoughSpace2d& space, Operation operation)
145{
147 istd::CIndex2d spaceSize = space.GetImageSize();
148
149 istd::CIndex2d commonSize(qMin(size.GetX(), spaceSize.GetX()), qMin(size.GetY(), spaceSize.GetY()));
150 for (int y = 0; y < commonSize.GetY(); ++y){
152 float* linePtr = (float*)BaseClass::GetLinePtr(y);
153 const float* spaceLinePtr = (const float*)space.GetLinePtr(y);
154 for (int x = 0; x < commonSize.GetX(); ++x){
155 linePtr[x] = operation(linePtr[x], spaceLinePtr[x]);
156 }
157 }
158 else{
159 Q_ASSERT(GetPixelFormat() == PF_GRAY32);
160
161 quint32* linePtr = (quint32*)BaseClass::GetLinePtr(y);
162 const quint32* spaceLinePtr = (const quint32*)space.GetLinePtr(y);
163 for (int x = 0; x < commonSize.GetX(); ++x){
164 linePtr[x] = operation(linePtr[x], spaceLinePtr[x]);
165 }
166 }
167 }
168}
169
170
171} // namespace ialgo
172
173
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
double GetY() const
Get Y position of this vector.
Definition CVector2d.h:184
double GetX() const
Get X position of this vector.
Definition CVector2d.h:172
void SetY(double y)
Set Y position of this vector.
Definition CVector2d.h:190
void SetX(double x)
Set X position of this vector.
Definition CVector2d.h:178
Hough space used for 2d Hough transformations.
virtual bool CreateBitmap(PixelFormat pixelFormat, const istd::CIndex2d &size, istd::COptMemory &&data, int linesDifference=0)
Create bitmap with specified size and format using external image data buffer.
CHoughSpace2d(const istd::CIndex2d &size, bool isWrappedX=false, bool isWrappedY=false)
void ApplyOperation(Operation operation)
Apply some operation to each element.
iimg::CGeneralBitmap BaseClass
virtual bool CreateHoughSpace(const istd::TIndex< 2 > &size, const double &initValue=0)
virtual ExtensionMode GetExtensionMode(int dimensionIndex) const
Get extension mode for single dimension.
virtual double GetSpaceDistance2(const imath::TVector< 2 > &position1, const imath::TVector< 2 > &position2) const
virtual void SmoothHoughSpace(const istd::TIndex< 2 > &iterations)
void CombineWithSpace(const CHoughSpace2d &space, Operation operation)
Combine this space with some other space.
void SetDimensionWrapped(int dimensionIndex, bool state)
Set if this space to be wrapped horizontaly or not.
virtual double GetSpaceDistance(const imath::TVector< 2 > &position1, const imath::TVector< 2 > &position2) const
TSimpleSpaceResultConsumer< 2 > StdConsumer
virtual void IncreaseValueAt(const imath::TVector< 2 > &position, double value)
virtual bool IsDimensionWrapped(int dimensionIndex) const
Check if this space is wrapped horizontaly, it means the the left pixel is neighbour of the right one...
virtual bool ExtractToBitmap(iimg::IBitmap &bitmap) const
Extract this Hough space to some gray scale bitmap.
virtual bool AnalyseHoughSpace(const double &minValue, ResultsConsumer &resultProcessor) const
Analyse this Hough space to find set of local maximums.
bool CreateHoughSpace(const istd::CIndex2d &size, bool isWrappedX, bool isWrappedY, bool isFloatSpace)
virtual istd::TIndex< 2 > GetSpaceSize() const
Get size of this Hough space.
virtual bool GetSpacePosition(const imath::TVector< 2 > &position, imath::TVector< 2 > &result) const
virtual bool CreateBitmap(PixelFormat pixelFormat, const istd::CIndex2d &size, int pixelBitsCount=0, int componentsCount=0)
Create bitmap with specified size and format.
Template interface for Hough space.
Consumer of results generated for some multidimensional space (typically Hough space).
Standard device- and platform-independent bitmap definition.
PixelFormat GetPixelFormat() const override
Get the bitmap's pixel format.
const void * GetLinePtr(int positionY) const override
Get pointer to buffer for single line.
istd::CIndex2d GetImageSize() const override
Get size of this raster image.
Definition of single plane bitmap.
Definition IBitmap.h:24
PixelFormat
Bitmap pixel format description.
Definition IBitmap.h:30
@ PF_GRAY32
32-bit grayscale bitmap.
Definition IBitmap.h:69
@ PF_FLOAT32
32-bit floating point coded bitmap (type float).
Definition IBitmap.h:74
Implementation of fixed-size mathematical vector with specified type of elements.
Definition TVector.h:32
Element GetLength2() const
Return euclidian length square.
Definition TVector.h:366
Index implementation for addressing elements in 2D-space.
Definition CIndex2d.h:25
int GetX() const
Definition CIndex2d.h:105
int GetY() const
Definition CIndex2d.h:117
Memory block with optional deleting function used during destruction.
Definition COptMemory.h:21
Multidimensional index used to addressing fixed-size array.
Definition TIndex.h:22
Contains implementations of interfaces and components of common algorithms with no association to ano...

© Witold Gantzke and Kirill Lepskiy