All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SegmenterRegionGrowingSegment.cpp
Go to the documentation of this file.
2 
3 #include <cstdlib>
4 #include <string.h>
5 
6 namespace te
7 {
8  namespace rp
9  {
11  const SegmenterRegionGrowingSegment& other )
12  {
13  m_id = other.m_id;
14  m_status = other.m_status;
15  m_size = other.m_size;
16  m_xStart = other.m_xStart;
17  m_xBound = other.m_xBound;
18  m_yStart = other.m_yStart;
19  m_yBound = other.m_yBound;
20 
21  free( m_neighborSegments );
22  if( other.m_neighborSegmentsSize )
23  {
26  other.m_neighborSegmentsSize );
27  memcpy( m_neighborSegments, other.m_neighborSegments,
29  other.m_neighborSegmentsSize );
31  }
32  else
33  {
36  }
37 
38  if( other.m_featuresSize )
39  {
40  memcpy( m_features, other.m_features,
41  sizeof( FeatureType ) * other.m_featuresSize );
42  }
44 
45  return *this;
46  }
47 
49  SegmenterRegionGrowingSegment * const nSegPtr )
50  {
51  if( nSegPtr )
52  {
53  unsigned int idx = 0;
54 
55  for( idx = 0 ; idx < m_neighborSegmentsSize ; ++idx )
56  {
57  if( m_neighborSegments[ idx ] == nSegPtr )
58  {
59  return;
60  }
61  }
62 
63  for( idx = 0 ; idx < m_neighborSegmentsSize ; ++idx )
64  {
65  if( m_neighborSegments[ idx ] == 0 )
66  {
67  m_neighborSegments[ idx ] = nSegPtr;
68  return;
69  }
70  }
71 
73  m_neighborSegments, ( m_neighborSegmentsSize + 1 ) * sizeof(
75 
77 
79  }
80  }
81 
83  SegmenterRegionGrowingSegment * const nSegPtr )
84  {
85  unsigned int numberOfZeroes = 0;
86  unsigned int idx = 0;
87  for( ; idx < m_neighborSegmentsSize ; ++idx )
88  {
89  if( m_neighborSegments[ idx ] == nSegPtr )
90  {
91  m_neighborSegments[ idx ] = 0;
92  ++numberOfZeroes;
93  }
94  else if( m_neighborSegments[ idx ] == 0 )
95  {
96  ++numberOfZeroes;
97  }
98  }
99 
100  unsigned int numberOfNonZeroes = m_neighborSegmentsSize - numberOfZeroes;
101 
102  if( ( m_neighborSegmentsSize > 4 ) && ( numberOfNonZeroes < numberOfZeroes ) )
103  {
105  malloc( numberOfNonZeroes * sizeof( SegmenterRegionGrowingSegment* ) );
106 
107  unsigned int idx2 = 0;
108 
109  for( idx = 0 ; idx < m_neighborSegmentsSize ; ++idx )
110  {
111  if( m_neighborSegments[ idx ] )
112  {
113  auxVecPtr[ idx2++ ] = m_neighborSegments[ idx ];
114  }
115  }
116 
117  free( m_neighborSegments );
118  m_neighborSegments = auxVecPtr;
119  m_neighborSegmentsSize = numberOfNonZeroes;
120  }
121  }
122 
124  {
125  free( m_neighborSegments );
126  m_neighborSegments = 0;
128  }
129  } // namespace rp
130 } // namespace te
unsigned int m_neighborSegmentsSize
The current size of m_neighborSegments.
unsigned int m_yBound
Segment lower bound Y coordinate box over the label image.
unsigned int m_xStart
Segment left X coordinate box over the label image.
unsigned int m_xBound
Segment lower bound X coordinate box over the label image.
void addNeighborSegment(SegmenterRegionGrowingSegment *const nSegPtr)
Add a pointer of a neighbor segment (if it is not already there).
Region Growing segment.
FeatureType * m_features
A pionter to a fixed size vector of segment features.
SegmenterRegionGrowingSegment ** m_neighborSegments
Neighborhood segments pointers (some pointers can be null) or a null pointer if there is no neighborh...
SegmenterRegionGrowingSegment & operator=(const SegmenterRegionGrowingSegment &other)
unsigned int m_size
Segment area (pixels number).
unsigned int m_featuresSize
The current size of m_features.
unsigned int m_yStart
Segment upper Y coordinate box over the label image.
void removeNeighborSegment(SegmenterRegionGrowingSegment *const nSegPtr)
Remove all occurrences of a neighbor segment.
bool m_status
Segment status (active=true).
void clearNeighborSegments()
Remove all neighbor segments.
SegmenterSegmentsBlock::SegmentIdDataType m_id
Segment ID.