CFastEdgesExtractorComp.h
Go to the documentation of this file.
1 #ifndef iedge_CFastEdgesExtractorComp_included
2 #define iedge_CFastEdgesExtractorComp_included
3 
4 
5 // Qt includes
6 #include <QtCore/QMutex>
7 
8 // ACF includes
9 #include <iimg/IBitmap.h>
10 #include <iimg/CScanlineMask.h>
12 
13 // ACF-Solutions includes
14 #include <imeas/INumericValue.h>
16 
17 #include <iedge/IEdgesExtractor.h>
18 
19 
20 namespace iedge
21 {
22 
23 
25  public iproc::TSyncProcessorCompBase<IEdgesExtractor>,
26  virtual public imeas::INumericConstraints,
27  virtual protected iprm::IOptionsList
28 {
29 public:
31 
32  I_BEGIN_COMPONENT(CFastEdgesExtractorComp);
33  I_REGISTER_INTERFACE(imeas::INumericConstraints);
34  I_ASSIGN(m_defaultThresholdParamCompPtr, "DefaultThresholdParam", "Default threshold parameter, if not taken from parameters", false, "DefaultThresholdParam");
35  I_ASSIGN(m_thresholdParamIdAttrPtr, "ThresholdParamId", "Threshold parameter ID (imeas::INumericValue)", false, "EdgeThreshold");
36  I_ASSIGN(m_defaultAoiCompPtr, "DefaultAoi", "Area of interest used if not specified in parameters", false, "DefaultAoi");
37  I_ASSIGN(m_aoiParamIdAttrPtr, "AoiParamId", "ID of area of interest in parameter set", false, "AoiParams");
38  I_ASSIGN(m_maxNodesCountAttrPtr, "MaxNodesCount", "Maximal number of nodes in container", true, 100000);
39  I_ASSIGN(m_keepSingletonsAttrPtr, "KeepSingletons", "If enabled lines containing only single isolated edge point will be also created", true, false);
40  I_END_COMPONENT;
41 
42  // reimplemented (iedge::IEdgesExtractor)
43  virtual bool DoContourExtraction(
44  const iprm::IParamsSet* paramsPtr,
45  const iimg::IBitmap& bitmap,
46  CEdgeLineContainer& result) const;
47 
48  // reimplemented (iproc::IProcessor)
49  virtual int DoProcessing(
50  const iprm::IParamsSet* paramsPtr,
51  const istd::IPolymorphic* inputPtr,
52  istd::IChangeable* outputPtr,
53  ibase::IProgressManager* progressManagerPtr = NULL);
54 
55  // reimplemented (imeas::INumericConstraints)
56  virtual const iprm::IOptionsList& GetValueListInfo() const;
57  virtual const imath::IUnitInfo* GetNumericValueUnitInfo(int index) const;
58 
59 protected:
60  // reimplemented (iprm::IOptionsList)
61  virtual int GetOptionsFlags() const;
62  virtual int GetOptionsCount() const;
63  virtual QString GetOptionName(int index) const;
64  virtual QString GetOptionDescription(int index) const;
65  virtual QByteArray GetOptionId(int index) const;
66  virtual bool IsOptionEnabled(int index) const;
67 
68  // reimplemented (icomp::CComponentBase)
69  virtual void OnComponentCreated();
70 
71 private:
72  enum
73  {
74  THRESHOLD_FACTOR = 510 // Maximum value of derivative strenghtness
75  };
76 
77 
78  struct ExtNode
79  {
80  i2d::CVector2d position;
81  i2d::CVector2d derivative;
82 
83  ExtNode* prevPtr;
84  ExtNode* nextPtr;
85 
86  double rawWeight;
87  double prevWeight;
88  double nextWeight;
89 
90  bool isHorizontal;
91  mutable bool isExtracted;
92  };
93 
94 
95  struct PixelDescriptor
96  {
97  quint32 dirLength2;
98  qint16 dx, dy;
99  qint16 brightness;
100 
101  ExtNode* listReference;
102  };
103 
104 
105  class MemoryPoolManager
106  {
107  public:
108  ~MemoryPoolManager();
109 
110  void* GetMemory(int bytes);
111  bool ReleaseMemory(void* ptr);
112 
113  private:
114  void Dispose();
115 
116  struct ChunkInfo
117  {
118  int bytes;
119  void* ptr;
120  };
121 
122  typedef QList<ChunkInfo> ChunkList;
123  ChunkList m_freeList;
124  ChunkList m_usedList;
125 
126  QMutex m_lock;
127  };
128 
129  class InternalContainer
130  {
131  public:
132  InternalContainer(int size);
133  ~InternalContainer();
134 
135  bool IsContainerFull() const;
136 
137  void ExtractLines(
138  double weightScale,
139  CEdgeLineContainer& result,
140  bool keepSingletons);
141 
142  ExtNode* AddElementToList();
143 
144  private:
145  ExtNode* m_buffer;
146  int m_bufferSize;
147  int m_freeIndex;
148 
149  bool m_isContainerFull;
150 
151  static MemoryPoolManager s_memoryManager;
152  };
153 
154  // static methods
155  static void TryConnectElements(
156  const PixelDescriptor& neightborPixel,
157  PixelDescriptor& pixel);
158  static void CalcDerivative(
159  const quint8* prevSourceLine,
160  const quint8* sourceLine,
161  int x,
162  PixelDescriptor& pixelDescriptor);
163  static void CalcDerivativeLine(
164  const quint8* prevSourceLine,
165  const quint8* sourceLine,
166  int inputBeginX,
167  int inputEndX,
168  PixelDescriptor* destLine);
169  static void CalcPoint(
170  int x,
171  int y,
172  quint32 threshold2Factor,
173  PixelDescriptor* prevPrevDestLine,
174  PixelDescriptor* prevDestLine,
175  PixelDescriptor* destLine,
176  InternalContainer& container);
177  static void CalcOutputLine(
178  int outputBeginX,
179  int outputEndX,
180  int y,
181  quint32 threshold2Factor,
182  PixelDescriptor* prevPrevDestLine,
183  PixelDescriptor* prevDestLine,
184  PixelDescriptor* destLine,
185  InternalContainer& container);
186 
187  I_REF(imeas::INumericValue, m_defaultThresholdParamCompPtr);
188  I_ATTR(QByteArray, m_thresholdParamIdAttrPtr);
189  I_REF(i2d::IObject2d, m_defaultAoiCompPtr);
190  I_ATTR(QByteArray, m_aoiParamIdAttrPtr);
191  I_ATTR(int, m_maxNodesCountAttrPtr);
192  I_ATTR(bool, m_keepSingletonsAttrPtr);
193 };
194 
195 
196 } // namespace iedge
197 
198 
199 #endif // !iedge_CFastEdgesExtractorComp_included
200 
201 
Simple definition macro for a synchronous processor.
virtual QString GetOptionName(int index) const
Describe additional meta information for set of numeric values.
General parameter set containing list of numeric values.
Definition: INumericValue.h:20
iproc::TSyncProcessorCompBase< IEdgesExtractor > BaseClass
virtual bool IsOptionEnabled(int index) const
virtual int DoProcessing(const iprm::IParamsSet *paramsPtr, const istd::IPolymorphic *inputPtr, istd::IChangeable *outputPtr, ibase::IProgressManager *progressManagerPtr=NULL)
virtual QByteArray GetOptionId(int index) const
virtual int GetOptionsFlags() const
virtual int GetOptionsCount() const
virtual bool DoContourExtraction(const iprm::IParamsSet *paramsPtr, const iimg::IBitmap &bitmap, CEdgeLineContainer &result) const
virtual const iprm::IOptionsList & GetValueListInfo() const
Get general information about the "content" of the numeric value.
virtual const imath::IUnitInfo * GetNumericValueUnitInfo(int index) const
Get range of possible numeric values for specified list index.
virtual QString GetOptionDescription(int index) const

© 2007-2017 Witold Gantzke and Kirill Lepskiy