OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimActiveEdgeTable.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // AUTHOR: Garrett Potts (gpotts@imagelinks.com)
6 //
7 //*****************************************************************************
8 // $Id: ossimActiveEdgeTable.cpp 11347 2007-07-23 13:01:59Z gpotts $
11 #include <ossim/base/ossimLine.h>
12 #include <ossim/base/ossimString.h>
14 #include <iterator>
15 using namespace std;
16 
17 
19 {
20 
21 }
22 
24 {
25  createTable(polygon);
26  if(theTable.size())
27  {
28  ossim_int32 iNextY, iY;
30  ossim_uint32 numPts = polygon.getVertexCount();
31  theLastScanLine = 0;
32 
33  for (ossim_uint32 i=0; i<numPts; ++i)
34  {
35  // CURRENT EDGE IS FROM polygon[i] to polygon[(i+1)%numPts]
36  int iNext = (i+1)%numPts; // INDEX FOR SECOND EDGE VERTEX
37  iNextY = ossim::round<ossim_int32>(polygon[iNext].y-theRectOrigin.y);
38  iY = ossim::round<ossim_int32>(polygon[i].y-theRectOrigin.y);
39  int dy = (iNextY - iY);
40  if (dy != 0) // ADD ONLY IF EDGE NOT HORIZONTAL
41  {
42  if (dy> 0) // local max
43  {
44  double m = (polygon[iNext].x-polygon[i].x)/
45  (polygon[iNext].y-polygon[i].y);
46 
47  edge = ossimActiveEdgeTableNode(iNextY+1,
48  m,
49  polygon[i].x);
50 
51  addEdgeToTable(edge, iY);
52 
53  }
54  else // local min so
55  {
56  double m = (polygon[i].x-polygon[iNext].x)/
57  (polygon[i].y-polygon[iNext].y);
58 
59  edge = ossimActiveEdgeTableNode(iY,
60  m,
61  polygon[iNext].x);
62 
63  addEdgeToTable(edge, iNextY);
64  }
65 
66  }
67  }
68  }
69 }
70 
72 {
73  theBoundingRect.makeNan();
74  theRectOrigin.makeNan();
75  if(polygon.getVertexCount() >2)
76  {
77  theTable.clear();
78  polygon.getBoundingRect(theBoundingRect);
79  if(!theBoundingRect.hasNans())
80  {
81  theTable.resize(theBoundingRect.height()+1);
82  theRectOrigin = theBoundingRect.ul();
83  }
84  }
85 }
86 
88  ossim_int32 scanLine)
89 {
90  theTable[scanLine].push_back(edge);
91 }
92 
94 {
95  int i = 0;
96  for(i=0;i<(int)theTable.size();++i)
97  {
98  if(theTable[i].size())
99  {
100  theActiveList = theTable[i];
101  theTable[i].clear();
102  theCurrentScanLine = i;
103  theActiveList.sort();
104  return;
105  }
106  }
107 }
108 
110 {
111  std::list<ossimActiveEdgeTableNode>::iterator current = theActiveList.begin();
112 
113  while(current != theActiveList.end())
114  {
115  (*current).theCurrentX += (*current).theSlope;
116 
117  if((*current).theMaxY == theCurrentScanLine)
118  {
119  current = theActiveList.erase(current);
120  }
121  else
122  {
123  ++current;
124  }
125  }
126 };
127 
129 {
130  if((theCurrentScanLine < (int)theTable.size())&&
131  theTable[theCurrentScanLine].size())
132  {
133  theTable[theCurrentScanLine].sort();
134  theActiveList.merge(theTable[theCurrentScanLine]);
135  theActiveList.sort();
136 
137  theTable[theCurrentScanLine].clear();
138  }
139 }
140 
142 {
143  copy(theActiveList.begin(),
144  theActiveList.end(),
145  ostream_iterator<ossimActiveEdgeTableNode>(ossimNotify(ossimNotifyLevel_INFO) << "->"));
146  ossimNotify(ossimNotifyLevel_INFO) << "NULL\n";
147 }
148 
150  :theEdgeTable(edgeTable),
151  theTableInitializedFlag(false)
152 {
153 }
154 
156 {
157  if(!theEdgeTable) return false;
158 
160  {
163  }
164  else
165  {
169  }
170 
172 
173  return (theEdgeTable->theActiveList.size());
174 }
175 
177  ossimIpt& end)
178 {
179  if(!theEdgeTable) return false;
181 
183  {
184  return false;
185  }
186  else
187  {
189 
190  start = ossimIpt(ossim::round<int>((*theIterator).theCurrentX),
191  y);
192  ++theIterator;
194  {
195  end = start;
196  }
197  else
198  {
199  end = ossimIpt( ossim::round<int>((*theIterator).theCurrentX),
200  y);
201 
202  ++theIterator;
203  }
204  }
205 
206  if(start.x > end.x)
207  {
208  swap(start.x, end.x);
209  }
210  return true;
211 }
ossim_uint32 x
ossim_uint32 y
void addEdgeToTable(const ossimActiveEdgeTableNode &edge, ossim_int32 scanLine)
void addPolygon(const ossimPolygon &polygon)
ossimActiveEdgeTableHelper(ossimActiveEdgeTable *edgeTable)
yy_size_t size
ossim_uint32 getVertexCount() const
unsigned int ossim_uint32
ossim_int32 getCurrentScanLine() const
void getBoundingRect(ossimIrect &rect) const
std::list< ossimActiveEdgeTableNode > theActiveList
std::list< ossimActiveEdgeTableNode >::const_iterator theIterator
ossim_int32 x
Definition: ossimIpt.h:141
void createTable(const ossimPolygon &polygon)
bool getNextLineSegment(ossimIpt &start, ossimIpt &end)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
ossimActiveEdgeTable * theEdgeTable
int ossim_int32