CFastEdgesExtractorComp.h
Go to the documentation of this file.
1 #ifndef iedge_CFastEdgesExtractorComp_included
2 #define iedge_CFastEdgesExtractorComp_included
3 
4 
5 // ACF includes
6 #include "iimg/IBitmap.h"
7 #include "iimg/CScanlineMask.h"
9 
10 // ACF-Solutions includes
11 #include "imeas/INumericValue.h"
13 
14 #include "iedge/IEdgesExtractor.h"
15 
16 
17 namespace iedge
18 {
19 
20 
22  public iproc::TSyncProcessorCompBase<IEdgesExtractor>,
24 {
25 public:
27 
28  I_BEGIN_COMPONENT(CFastEdgesExtractorComp);
29  I_REGISTER_INTERFACE(imeas::INumericConstraints);
30  I_ASSIGN(m_defaultThresholdParamCompPtr, "DefaultThresholdParam", "Default threshold parameter, if not taken from parameters", false, "DefaultThresholdParam");
31  I_ASSIGN(m_thresholdParamIdAttrPtr, "ThresholdParamId", "Threshold parameter ID (imeas::INumericValue)", false, "EdgeThreshold");
32  I_ASSIGN(m_defaultAoiCompPtr, "DefaultAoi", "Area of interest used if not specified in parameters", false, "DefaultAoi");
33  I_ASSIGN(m_aoiParamIdAttrPtr, "AoiParamId", "ID of area of interest in parameter set", false, "AoiParams");
34  I_ASSIGN(m_maxNodesCountAttrPtr, "MaxNodesCount", "Maximal number of nodes in container", true, 100000);
35  I_ASSIGN(m_keepSingletonsAttrPtr, "KeepSingletons", "If enabled lines containing only single isolated edge point will be also created", true, false);
36  I_END_COMPONENT;
37 
38  // reimplemented (iedge::IEdgesExtractor)
39  virtual bool DoContourExtraction(
40  const iprm::IParamsSet* paramsPtr,
41  const iimg::IBitmap& bitmap,
42  CEdgeLineContainer& result) const;
43 
44  // reimplemented (iproc::IProcessor)
45  virtual int DoProcessing(
46  const iprm::IParamsSet* paramsPtr,
47  const istd::IPolymorphic* inputPtr,
48  istd::IChangeable* outputPtr,
49  ibase::IProgressManager* progressManagerPtr = NULL);
50 
51  // reimplemented (imeas::INumericConstraints)
52  virtual int GetNumericValuesCount() const;
53  virtual QString GetNumericValueName(int index) const;
54  virtual QString GetNumericValueDescription(int index) const;
55  virtual const imath::IUnitInfo& GetNumericValueUnitInfo(int index) const;
56 
57 private:
58  enum
59  {
60  THRESHOLD_FACTOR = 510 // Maximum value of derivative strenghtness
61  };
62 
63 
64  struct ExtNode
65  {
66  i2d::CVector2d position;
67  i2d::CVector2d derivative;
68  double rawWeight;
69  bool isHorizontal;
70 
71  ExtNode* prevPtr;
72  ExtNode* nextPtr;
73 
74  double prevWeight;
75  double nextWeight;
76 
77  mutable bool isExtracted;
78  };
79 
80  struct PixelDescriptor
81  {
82  qint16 brightness;
83  qint16 dx;
84  qint16 dy;
85  quint32 dirLength2;
86  ExtNode* listReference;
87  };
88 
89  class InternalContainer
90  {
91  public:
92  InternalContainer(int size);
93 
94  bool IsContainerFull() const;
95 
96  void ExtractLines(
97  double weightScale,
98  CEdgeLineContainer& result,
99  bool keepSingletons);
100 
101  ExtNode* AddElementToList();
102 
103  private:
104  QVector<ExtNode> m_buffer;
105  int m_freeIndex;
106 
107  bool m_isContainerFull;
108  };
109 
110  // static methods
111  static void TryConnectElements(
112  const PixelDescriptor& neightborPixel,
113  PixelDescriptor& pixel);
114  static void CalcDerivative(
115  const quint8* prevSourceLine,
116  const quint8* sourceLine,
117  int x,
118  PixelDescriptor& pixelDescriptor);
119  static void CalcDerivativeLine(
120  const quint8* prevSourceLine,
121  const quint8* sourceLine,
122  int inputBeginX,
123  int inputEndX,
124  PixelDescriptor* destLine);
125  static void CalcPoint(
126  int x,
127  int y,
128  quint32 threshold2Factor,
129  PixelDescriptor* prevPrevDestLine,
130  PixelDescriptor* prevDestLine,
131  PixelDescriptor* destLine,
132  InternalContainer& container);
133  static void CalcOutputLine(
134  int outputBeginX,
135  int outputEndX,
136  int y,
137  quint32 threshold2Factor,
138  PixelDescriptor* prevPrevDestLine,
139  PixelDescriptor* prevDestLine,
140  PixelDescriptor* destLine,
141  InternalContainer& container);
142 
143  I_REF(imeas::INumericValue, m_defaultThresholdParamCompPtr);
144  I_ATTR(QByteArray, m_thresholdParamIdAttrPtr);
145  I_REF(i2d::IObject2d, m_defaultAoiCompPtr);
146  I_ATTR(QByteArray, m_aoiParamIdAttrPtr);
147  I_ATTR(int, m_maxNodesCountAttrPtr);
148  I_ATTR(bool, m_keepSingletonsAttrPtr);
149 };
150 
151 
152 } // namespace iedge
153 
154 
155 #endif // !iedge_CFastEdgesExtractorComp_included
156 
157 
Simple definition macro for a synchronous processor.
virtual QString GetNumericValueName(int index) const
Get human readable name of numeric value for specified list index.
Describe additional meta information for set of numeric values.
virtual const imath::IUnitInfo & GetNumericValueUnitInfo(int index) const
Get range of possible numeric values for specified list index.
General parameter set containing list of numeric values.
Definition: INumericValue.h:19
virtual QString GetNumericValueDescription(int index) const
Get human readable description of numeric value for specified list index.
virtual int GetNumericValuesCount() const
Get number of expected numeric values.
iproc::TSyncProcessorCompBase< IEdgesExtractor > BaseClass
virtual int DoProcessing(const iprm::IParamsSet *paramsPtr, const istd::IPolymorphic *inputPtr, istd::IChangeable *outputPtr, ibase::IProgressManager *progressManagerPtr=NULL)
virtual bool DoContourExtraction(const iprm::IParamsSet *paramsPtr, const iimg::IBitmap &bitmap, CEdgeLineContainer &result) const

© 2007-2011 Witold Gantzke and Kirill Lepskiy