CHoughSpace2d.h
Go to the documentation of this file.
1 #ifndef ialgo_CHoughSpace2d_included
2 #define ialgo_CHoughSpace2d_included
3 
4 
5 // STL includes
6 #include <cmath>
7 
8 // Qt includes
9 #include <QtCore/QMultiMap>
10 
11 // ACF includes
12 #include <i2d/CVector2d.h>
13 #include <iimg/CGeneralBitmap.h>
14 
15 // ACF-Solutions includes
16 #include <ialgo/TIHoughSpace.h>
18 
19 
20 namespace ialgo
21 {
22 
23 
28  public iimg::CGeneralBitmap,
29  virtual public TIHoughSpace<2>
30 {
31 public:
33 
35 
36  CHoughSpace2d();
37  CHoughSpace2d(const istd::CIndex2d& size, bool isWrappedX = false, bool isWrappedY = false);
38 
39  bool CreateHoughSpace(
40  const istd::CIndex2d& size,
41  bool isWrappedX,
42  bool isWrappedY,
43  bool isFloatSpace);
44 
49  void SetDimensionWrapped(int dimensionIndex, bool state);
50 
54  template <typename Operation>
55  void ApplyOperation(Operation operation);
56 
60  template <typename Operation>
61  void CombineWithSpace(const CHoughSpace2d& space, Operation operation);
62 
63  // reimplemented (ialgo::TIHoughSpace<2>)
64  virtual istd::TIndex<2> GetSpaceSize() const;
65  virtual bool CreateHoughSpace(const istd::TIndex<2>& size, const double& initValue = 0);
66  virtual bool IsDimensionWrapped(int dimensionIndex) const;
67  virtual ExtensionMode GetExtensionMode(int dimensionIndex) const;
68  virtual void IncreaseValueAt(const imath::TVector<2>& position, double value);
69  virtual void SmoothHoughSpace(const istd::TIndex<2>& iterations);
70  virtual bool AnalyseHoughSpace(
71  const double& minValue,
72  ResultsConsumer& resultProcessor) const;
73  virtual bool ExtractToBitmap(iimg::IBitmap& bitmap) const;
74  virtual bool GetSpacePosition(const imath::TVector<2>& position, imath::TVector<2>& result) const;
75  virtual double GetSpaceDistance(const imath::TVector<2>& position1, const imath::TVector<2>& position2) const;
76  virtual double GetSpaceDistance2(const imath::TVector<2>& position1, const imath::TVector<2>& position2) const;
77 
78  // reimplemented (iimg::CGeneralBitmap)
79  virtual bool CreateBitmap(PixelFormat pixelFormat, const istd::CIndex2d& size, int pixelBitsCount = 0, int componentsCount = 0);
80  virtual bool CreateBitmap(PixelFormat pixelFormat, const istd::CIndex2d& size, void* dataPtr, bool releaseFlag, int linesDifference = 0);
81 
82 private:
83  bool m_isWrapped[2];
84 };
85 
86 
87 // inline methods
88 
89 inline double CHoughSpace2d::GetSpaceDistance(const imath::TVector<2>& position1, const imath::TVector<2>& position2) const
90 {
91  return qSqrt(GetSpaceDistance2(position1, position2));
92 }
93 
94 
95 inline double CHoughSpace2d::GetSpaceDistance2(const imath::TVector<2>& position1, const imath::TVector<2>& position2) const
96 {
98 
99  i2d::CVector2d diff = position2 - position1;
100  if (m_isWrapped[0]){
101  double offset = spaceSize.GetX() * 0.5;
102  diff.SetX(std::fmod(diff.GetX() + offset + spaceSize.GetX(), spaceSize.GetX()) - offset);
103  }
104 
105  if (m_isWrapped[1]){
106  double offset = spaceSize.GetY() * 0.5;
107  diff.SetY(std::fmod(diff.GetY() + offset + spaceSize.GetY(), spaceSize.GetY()) - offset);
108  }
109 
110  return diff.GetLength2();
111 }
112 
113 
114 // template methods
115 
116 template <typename Operation>
117 void CHoughSpace2d::ApplyOperation(Operation operation)
118 {
119 
121 
122  for (int y = 0; y < size.GetY(); ++y){
123  if (BaseClass::GetPixelFormat() == PF_FLOAT32){
124  float* linePtr = (float*)BaseClass::GetLinePtr(y);
125  for (int x = 0; x < size.GetX(); ++x){
126  linePtr[x] = operation(linePtr[x]);
127  }
128  }
129  else{
130  Q_ASSERT(GetPixelFormat() == PF_GRAY32);
131 
132  quint32* linePtr = (quint32*)BaseClass::GetLinePtr(y);
133  for (int x = 0; x < size.GetX(); ++x){
134  linePtr[x] = operation(linePtr[x]);
135  }
136  }
137  }
138 }
139 
140 
141 template <typename Operation>
142 void CHoughSpace2d::CombineWithSpace(const CHoughSpace2d& space, Operation operation)
143 {
145  istd::CIndex2d spaceSize = space.GetImageSize();
146 
147  istd::CIndex2d commonSize(qMin(size.GetX(), spaceSize.GetX()), qMin(size.GetY(), spaceSize.GetY()));
148  for (int y = 0; y < commonSize.GetY(); ++y){
149  if (BaseClass::GetPixelFormat() == PF_FLOAT32){
150  float* linePtr = (float*)BaseClass::GetLinePtr(y);
151  const float* spaceLinePtr = (const float*)space.GetLinePtr(y);
152  for (int x = 0; x < commonSize.GetX(); ++x){
153  linePtr[x] = operation(linePtr[x], spaceLinePtr[x]);
154  }
155  }
156  else{
157  Q_ASSERT(GetPixelFormat() == PF_GRAY32);
158 
159  quint32* linePtr = (quint32*)BaseClass::GetLinePtr(y);
160  const quint32* spaceLinePtr = (const quint32*)space.GetLinePtr(y);
161  for (int x = 0; x < commonSize.GetX(); ++x){
162  linePtr[x] = operation(linePtr[x], spaceLinePtr[x]);
163  }
164  }
165  }
166 }
167 
168 
169 } // namespace ialgo
170 
171 
172 #endif // !ialgo_CHoughSpace2d_included
173 
174 
virtual bool CreateBitmap(PixelFormat pixelFormat, const istd::CIndex2d &size, int pixelBitsCount=0, int componentsCount=0)
ExtensionMode
Describe how the space is extended, it means how the area outside of space should be interpreted...
Definition: TIHoughSpace.h:65
double GetLength2() const
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...
bool CreateHoughSpace(const istd::CIndex2d &size, bool isWrappedX, bool isWrappedY, bool isFloatSpace)
void CombineWithSpace(const CHoughSpace2d &space, Operation operation)
Combine this space with some other space.
virtual void IncreaseValueAt(const imath::TVector< 2 > &position, double value)
virtual PixelFormat GetPixelFormat() const
iimg::CGeneralBitmap BaseClass
Definition: CHoughSpace2d.h:32
double GetY() const
virtual bool ExtractToBitmap(iimg::IBitmap &bitmap) const
Extract this Hough space to some gray scale bitmap.
void SetDimensionWrapped(int dimensionIndex, bool state)
Set if this space to be wrapped horizontaly or not.
virtual bool GetSpacePosition(const imath::TVector< 2 > &position, imath::TVector< 2 > &result) const
void SetX(double x)
virtual double GetSpaceDistance2(const imath::TVector< 2 > &position1, const imath::TVector< 2 > &position2) const
Definition: CHoughSpace2d.h:95
Consumer of results generated for some multidimensional space (typically Hough space).
void SetY(double y)
void ApplyOperation(Operation operation)
Apply some operation to each element.
virtual istd::TIndex< 2 > GetSpaceSize() const
Get size of this Hough space.
virtual ExtensionMode GetExtensionMode(int dimensionIndex) const
Get extension mode for single dimension.
virtual void SmoothHoughSpace(const istd::TIndex< 2 > &iterations)
virtual double GetSpaceDistance(const imath::TVector< 2 > &position1, const imath::TVector< 2 > &position2) const
Definition: CHoughSpace2d.h:89
virtual const void * GetLinePtr(int positionY) const
virtual istd::CIndex2d GetImageSize() const
TSimpleSpaceResultConsumer< 2 > StdConsumer
Definition: CHoughSpace2d.h:34
Template interface for Hough space.
Definition: TIHoughSpace.h:21
double GetX() const
virtual bool AnalyseHoughSpace(const double &minValue, ResultsConsumer &resultProcessor) const
Analyse this Hough space to find set of local maximums.
Hough space used for 2d Hough transformations.
Definition: CHoughSpace2d.h:27

© 2007-2017 Witold Gantzke and Kirill Lepskiy