OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimPolyCutter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Garrett Potts
9 //
10 //*************************************************************************
11 // $Id: ossimPolyCutter.cpp 21518 2012-08-22 21:15:56Z dburken $
16 #include <ossim/base/ossimCommon.h>
19 static const char* NUMBER_POLYGONS_KW = "number_polygons";
20 
22 
25  theTile(NULL),
26  theCutType(OSSIM_POLY_NULL_OUTSIDE),
27  m_boundingOverwrite(false)
28 {
29  thePolygonList.push_back(ossimPolygon());
30  theBoundingRect.makeNan();
31 }
32 
33 // ossimPolyCutter::ossimPolyCutter(ossimImageSource* inputSource,
34 // ossimPolyArea2d* polygon)
36  const ossimPolygon& polygon)
37  : ossimImageSourceFilter(inputSource),
38  theTile(NULL),
39  theCutType(OSSIM_POLY_NULL_INSIDE),
40  m_boundingOverwrite(false)
41 {
42  thePolygonList.push_back(polygon);
44  initialize();
45 }
46 
48 {
49 }
50 
52  ossim_uint32 resLevel)
53 {
55  {
56  return theTile;
57  }
59  resLevel);
60 
61  if(!isSourceEnabled() || theBoundingRect.hasNans() || !input.valid())
62  {
63  return input;
64  }
65 
66  if((input->getDataObjectStatus() == OSSIM_EMPTY) ||
67  (input->getDataObjectStatus() == OSSIM_NULL))
68  {
69  return input;
70  }
71 
72  if(!theTile.valid())
73  {
74  allocate(); // First time through...
75  }
76 
77  if(!theTile.valid())
78  {
79  return input;
80  }
81 
82  theTile->setImageRectangle(tileRect);
83 
84  theTile->loadTile(input.get());
86  vector<ossimPolygon>* polyList = &thePolygonList;
87  vector<ossimPolygon> scaledPoly;
88 
89  ossimIrect boundingRect = getBoundingRect(resLevel);
90  if(resLevel)
91  {
92  ossimDpt decimation;
93  getDecimationFactor(resLevel, decimation);
94 
95  if(!decimation.hasNans())
96  {
97  for(int polyIndex = 0;
98  polyIndex < (int)thePolygonList.size();
99  ++polyIndex)
100  {
101  scaledPoly.push_back(thePolygonList[polyIndex]*decimation);
102  }
103  polyList = &scaledPoly;
104  }
105  }
106 
107  if(polyList->size()&&
109  {
110 // ossimActiveEdgeTable aet;
111 
112 
114  {
115  if(boundingRect.intersects(tileRect))
116  {
117  theTile->makeBlank();
119  for(int polyIndex = 0; polyIndex < (int)polyList->size(); ++polyIndex)
120  {
122  (*polyList)[polyIndex]);
123  }
124  theTile->validate();
125  }
126  else
127  {
128  theTile->makeBlank();
129  }
130  }
132  {
133  if(boundingRect.intersects(tileRect))
134  {
136  for(int polyIndex = 0;
137  polyIndex < (int)polyList->size();
138  ++polyIndex)
139  {
141  (*polyList)[polyIndex]);
142  }
143  }
144  theTile->validate();
145  }
146 
147  }
148  return theTile;
149 }
150 
152 {
153  ossimIrect result;
154 
155  result.makeNan();
156  if(!theInputConnection)
157  {
158  return result;
159  }
160  if(!isSourceEnabled())
161  {
163  }
164 
165  result = theInputConnection->getBoundingRect(resLevel);
166 
168  {
170  {
171  ossimDpt decimation;
172  getDecimationFactor(resLevel, decimation);
173  if(decimation.hasNans())
174  {
175  result = theBoundingRect;
176  }
177  else
178  {
179  result = theBoundingRect*decimation;
180  }
181  }
182  }
183  else if(isSourceEnabled())
184  {
185  return theBoundingRect;
186  }
187 
188  return result;
189 }
190 
192 {
193  // Capture the input connection.
195 
196  // Force an allocate on next getTile.
197  theTile = NULL;
198 }
199 
201 {
202  theTile=NULL;
204  {
207  theTile->initialize();
208 
209  }
210 }
211 
213  const char* prefix)const
214 {
215  ossimString newPrefix = prefix;
216 
217  for(int i = 0; i < (int)thePolygonList.size();++i)
218  {
219  newPrefix = ossimString(prefix) + "polygon" + ossimString::toString(i)+".";
220 
221  thePolygonList[i].saveState(kwl, newPrefix.c_str());
222  }
223  kwl.add(prefix,
224  NUMBER_POLYGONS_KW,
225  (int)thePolygonList.size(),
226  true);
227 
228  ossimString fillType = "null_inside";
230  {
231  fillType = "null_outside";
232  }
233  kwl.add(prefix,
234  "cut_type",
235  fillType.c_str(),
236  true);
237 
238  return ossimImageSourceFilter::saveState(kwl, prefix);;
239 }
240 
242  const char* prefix)
243 {
244  const char* numberPolygons = kwl.find(prefix, NUMBER_POLYGONS_KW);
245 
246  ossimString newPrefix;
247  if(numberPolygons)
248  {
249  thePolygonList.clear();
250  int npolys = ossimString(numberPolygons).toLong();
251  for(int i = 0; i < npolys;++i)
252  {
253  thePolygonList.push_back(ossimPolygon());
254 
255  newPrefix = ossimString(prefix) + "polygon" + ossimString::toString(i)+".";
256 
257  thePolygonList[i].loadState(kwl, newPrefix.c_str());
258  }
259  }
260 
261  const char* lookup = kwl.find(prefix,
262  "cut_type");
263  if(lookup)
264  {
266  ossimString test = lookup;
267  if(test == "null_outside")
268  {
270  }
271  }
272  else
273  {
275  }
276 
278 
279 
280  return ossimImageSourceFilter::loadState(kwl, prefix);
281 }
282 
283 void ossimPolyCutter::setPolygon(const vector<ossimDpt>& polygon,
284  ossim_uint32 index)
285 {
286  if(index < polygon.size())
287  {
288  thePolygonList[index] = polygon;
289 
291  }
292 
293 }
294 
295 void ossimPolyCutter::setPolygon(const vector<ossimIpt>& polygon,
296  ossim_uint32 index)
297 {
298  if(polygon.size())
299  {
300  thePolygonList[index] = polygon;
302  }
303 }
304 
305 void ossimPolyCutter::addPolygon(const vector<ossimIpt>& polygon)
306 {
307  thePolygonList.push_back(ossimPolygon(polygon));
309 }
310 
311 void ossimPolyCutter::addPolygon(const vector<ossimDpt>& polygon)
312 {
313  thePolygonList.push_back(ossimPolygon(polygon));
315 }
316 
318 {
319  thePolygonList.push_back(ossimPolygon(polygon));
321 }
322 
323 
325 {
326  theCutType = cutType;
327 }
328 
330 {
331  return theCutType;
332 }
333 
335 {
337 }
338 
340 {
342 }
343 
345 {
346 
348 }
349 
350 void ossimPolyCutter::getPropertyNames(std::vector<ossimString>& propertyNames)const
351 {
353 }
354 
356 {
357  ossimIrect bounds;
359 
360  for(int i = 0; i < (int)thePolygonList.size(); ++i)
361  {
362  thePolygonList[i].getBoundingRect(bounds);
363 
364  if(!bounds.hasNans())
365  {
367  {
368  theBoundingRect = bounds;
369  }
370  else
371  {
373  }
374  }
375  }
376 }
377 
379 {
380  return theBoundingRect;
381 }
382 
384 {
385  theBoundingRect = rect;
386  m_boundingOverwrite = true;
387 }
388 
390 {
391  if(!count)
392  {
393  thePolygonList.clear();
394  thePolygonList.clear();
395  }
396  else
397  {
398  thePolygonList.resize(count);
399  }
400 }
401 
402 std::vector<ossimPolygon>& ossimPolyCutter::getPolygonList()
403 {
404  return thePolygonList;
405 }
406 
407 const std::vector<ossimPolygon>& ossimPolyCutter::getPolygonList()const
408 {
409  return thePolygonList;
410 }
411 
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
ossimRefPtr< ossimImageData > theTile
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
void setImageData(ossimImageData *imageData)
virtual void setImageRectangle(const ossimIrect &rect)
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tileRect, ossim_uint32 resLevel=0)
void allocate()
Called on first getTile, will initialize all data needed.
static ossimString toString(bool aValue)
Numeric to string methods.
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual void addPolygon(const vector< ossimIpt > &polygon)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
bool intersects(const ossimIrect &rect) const
Definition: ossimIrect.cpp:183
ossimPolyCutterCutType getCutType() const
virtual void initialize()
Initialize the data buffer.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
void copyInputToThis(const void *input, const ossimPolygon &region, bool clipPoly=true)
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
static ossimImageDataFactory * instance()
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual ossimDataObjectStatus validate() const
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
void fill(const double *values, const ossimIrect &rect, bool clipPoly=true)
virtual void setPolygon(const vector< ossimDpt > &polygon, ossim_uint32 i=0)
ossimImageSource * theInputConnection
virtual std::vector< ossimPolygon > & getPolygonList()
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
const ossimIrect & getRectangle() const
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
bool hasNans() const
Definition: ossimDpt.h:67
virtual void initialize()
virtual void makeBlank()
Initializes data to null pixel values.
ossimImageDataHelper theHelper
long toLong() const
toLong&#39;s deprecated, please use the toInts...
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
void makeNan()
Definition: ossimIrect.h:329
virtual const void * getBuf() const
ossimIrect theBoundingRect
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
virtual void setNumberOfPolygons(ossim_uint32 count)
virtual void setDataObjectStatus(ossimDataObjectStatus status) const
Full list found in ossimConstants.h.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
bool hasNans() const
Definition: ossimIrect.h:337
virtual void setProperty(ossimRefPtr< ossimProperty > property)
void setRectangle(const ossimIrect &rect)
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
virtual void getDecimationFactor(ossim_uint32 resLevel, ossimDpt &result) const
Will return the decimation factor for the given resolution level.
std::vector< ossimPolygon > thePolygonList
ossimPolyCutterCutType theCutType
ossimIrect combine(const ossimIrect &rect) const
Definition: ossimIrect.cpp:543
virtual ~ossimPolyCutter()
void setCutType(ossimPolyCutterCutType cutType)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)