OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimAnnotationSource.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See LICENSE.txt file in the top level directory.
4 //
5 // Author: Garrett Potts
6 //
7 //*************************************************************************
8 // $Id: ossimAnnotationSource.cpp 15766 2009-10-20 12:37:09Z gpotts $
9 
15 
17  "ossimAnnotationSource",
19 
21  :
22  ossimImageSourceFilter(inputSource),
23  theRectangle(0, 0, 0, 0),
24  theNumberOfBands(1),
25  theImage(0),
26  theTile(0),
27  theAnnotationObjectList()
28 {
29  theRectangle.makeNan();
30 }
31 
33 {
34  deleteAll();
35  destroy();
36 }
37 
39 {
40  // theImage is an ossimRefPtr<ossimRgbImage> so this is not a leak.
41  theImage = 0;
42 
43  // theTile is an ossimRefPtr<ossimImageData> so this is not a leak.
44  theTile = 0;
45 }
46 
48 {
49  if (!theImage)
50  {
51  theImage = new ossimRgbImage();
52  }
53 
54  if (!theTile)
55  {
56  theTile = new ossimU8ImageData( this,
58  rect.width(),
59  rect.height() );
61  }
62 }
63 
65 {
67  {
69  }
70  return OSSIM_UINT8;
71 }
72 
74 {
76  {
78  }
79  return theNumberOfBands;
80 }
81 
82 
84 {
85  //---
86  // Call the base class initialize.
87  // Note: This will reset "theInputConnection" if it changed...
88  //---
90 
92  {
94 
95  // This will call destroy on band count change.
97  }
98  else
99  {
100  destroy();
101  }
102 }
103 
105 {
106  ossimIrect result;
107  result.makeNan();
108 
110  {
112  result = temp;
113  }
114 
115  if(result.hasNans())
116  {
117  result = theRectangle;
118  }
119  else if(!theRectangle.hasNans())
120  {
121  result.combine(theRectangle);
122  }
123 
124  return result;
125 }
126 
128 {
129  theNumberOfBands = bands;
130  if (theTile.get())
131  {
133  {
134  //---
135  // This will wide things slick and force an allocate()
136  // call on first getTile().
137  //---
138  destroy();
139  }
140  }
141 }
142 
144  const ossimIrect& tile_rect, ossim_uint32 resLevel)
145 {
146  ossimRefPtr<ossimImageData> inputTile = 0;
147 
148  //---
149  // NOTE:
150  // This source is written to be used with or without an input connection.
151  // So any call to inputTile should be preceeded by: if (inputTile.valid())"
152  //---
154  {
155  // Fetch tile from pointer from the input source.
156  inputTile = theInputConnection->getTile(tile_rect, resLevel);
157  }
158 
159  // Check for remap bypass:
160  if ( !theEnableFlag )
161  {
162  return inputTile;
163  }
164 
165  // Check for first time through or reallocation force by band change.
166  if ( !theTile )
167  {
168  allocate(tile_rect);
169  }
170 
171  // Allocation failed!
172  if(!theTile)
173  {
174  return inputTile;
175  }
176 
177  //---
178  // Set the image rectangle and bands. This will set the origin.
179  //
180  // NOTE: We do this before the "theTile->makeBlank()" call for efficiency
181  // since this will force a "ossimImageData::initialize()", which performs
182  // a "makeBlank" if a resize is needed due to tile rectangle or number
183  // of band changes.
184  //---
186 
187  //---
188  // Start with a blank tile.
189  //
190  // NOTE: This will not do anything if already blank.
191  //---
192  theTile->makeBlank();
193 
194  if(inputTile.valid() &&
195  inputTile->getBuf()&&
196  (inputTile->getDataObjectStatus()!=OSSIM_EMPTY))
197  {
198  //---
199  // Copy the input tile to the output tile performing scalar remap if
200  // needed.
201  //---
202  theTile->loadTile(inputTile.get());
203  }
204 
205  // Annotate the output tile.
207 
208  theTile->validate();
209 
210  return theTile;
211 }
212 
214 {
215  if(anObject)
216  {
217  theAnnotationObjectList.push_back(anObject);
218  return true;
219  }
220 
221  return false;
222 }
223 
225 {
226  if(anObject)
227  {
228  AnnotationObjectListType::iterator current =
229  theAnnotationObjectList.begin();
230  while(current != theAnnotationObjectList.end())
231  {
232  if(*current == anObject)
233  {
234  theAnnotationObjectList.erase(current);
235  return true;
236  }
237  ++current;
238  }
239  }
240 
241  return false;
242 }
243 
245  const char* prefix)const
246 {
247  // Save the state of all annotation objects we have.
248  AnnotationObjectListType::const_iterator obj =
249  theAnnotationObjectList.begin();
250  ossim_uint32 objIdx = 0;
251  while (obj < theAnnotationObjectList.end())
252  {
253  ossimString newPrefix = prefix;
254 
255  newPrefix += (ossimString("object") +
256  ossimString::toString(objIdx) +
257  ossimString("."));
258  (*obj)->saveState(kwl, newPrefix.c_str());
259  ++objIdx;
260  ++obj;
261  }
262 
263  return ossimImageSourceFilter::saveState(kwl, prefix);
264 }
265 
267  const char* prefix)
268 {
269  ossim_uint32 index = 0;
270  ossimString copyPrefix = prefix;
271  ossim_uint32 result = kwl.getNumberOfSubstringKeys(copyPrefix +
272  "object[0-9]+\\.");
273 
274  ossim_uint32 numberOfMatches = 0;
275  const ossim_uint32 MAX_INDEX = result + 100;
276 
277  while(numberOfMatches < result)
278  {
279  ossimString newPrefix = copyPrefix;
280  newPrefix += ossimString("object");
281  newPrefix += ossimString::toString(index);
282  newPrefix += ossimString(".");
283 
284  const char* lookup = kwl.find(newPrefix.c_str(), "type");
285  if (lookup)
286  {
287  ++numberOfMatches;
288 
291  create(kwl, newPrefix.c_str());
292  if (obj.valid())
293  {
294  if(!addObject(obj.get()))
295  {
297  << "ossimGeoAnnotationSource::loadState\n"
298  << "Object " << obj->getClassName()
299  << " is not a geographic object" << endl;
300  obj = 0;
301  }
302  }
303  }
304 
305  ++index;
306 
307  if (index > MAX_INDEX) // Avoid infinite loop...
308  {
309  break;
310  }
311  }
312 
313  return ossimImageSourceFilter::loadState(kwl, prefix);
314 }
315 
317 {
319 
320  if(theAnnotationObjectList.size()>0)
321  {
322  ossimDrect rect;
323  theAnnotationObjectList[0]->computeBoundingRect();
324 
325  theAnnotationObjectList[0]->getBoundingRect(theRectangle);
326 
327  AnnotationObjectListType::iterator object =
328  (theAnnotationObjectList.begin()+1);
329  while(object != theAnnotationObjectList.end())
330  {
331  (*object)->computeBoundingRect();
332  (*object)->getBoundingRect(rect);
333  if(theRectangle.hasNans())
334  {
335  theRectangle = rect;
336  }
337  else if(!rect.hasNans())
338  {
340  }
341  ++object;
342  }
343  }
344 }
345 
347  const ossimDpt& imagePoint)
348 {
350  AnnotationObjectListType::iterator currentObject;
351 
352  currentObject = theAnnotationObjectList.begin();
353 
354  while(currentObject != theAnnotationObjectList.end())
355  {
356  if((*currentObject)->isPointWithin(imagePoint))
357  {
358  result.push_back(*currentObject);
359  }
360 
361  ++currentObject;
362  }
363  return result;
364 }
365 
367  const ossimDrect& imageRect)
368 {
370  AnnotationObjectListType::iterator currentObject;
371 
372  currentObject = theAnnotationObjectList.begin();
373 
374  while(currentObject != theAnnotationObjectList.end())
375  {
376  ossimRefPtr<ossimAnnotationObject> current = (*currentObject);
377  if(current->isPointWithin(imageRect.ul()))
378  {
379  result.push_back(*currentObject);
380  }
381  else if(current->isPointWithin(imageRect.ll()))
382  {
383  result.push_back(*currentObject);
384  }
385  else if(current->isPointWithin(imageRect.lr()))
386  {
387  result.push_back(*currentObject);
388  }
389  else if(current->isPointWithin(imageRect.ur()))
390  {
391  result.push_back(*currentObject);
392  }
393 
394  ++currentObject;
395  }
396  return result;
397 }
398 
400 {
401  AnnotationObjectListType::iterator obj;
402 
403  theAnnotationObjectList.clear();
404 }
405 
407 {
409 
410  if(theImage->getImageData().valid())
411  {
412  AnnotationObjectListType::iterator object =
413  theAnnotationObjectList.begin();
414  while(object != theAnnotationObjectList.end())
415  {
416  if((*object).valid())
417  {
418  (*object)->draw(*theImage);
419  }
420  ++object;
421  }
422  }
423 }
424 
427 {
429 }
430 
432 {
434 }
void makeNan()
Definition: ossimDrect.h:388
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
virtual ossim_uint32 getNumberOfBands() const
ossim_uint32 getNumberOfSubstringKeys(const ossimString &regularExpression) const
AnnotationObjectListType pickObjects(const ossimDpt &imagePoint)
Represents serializable keyword/value map.
bool theEnableFlag
Definition: ossimSource.h:62
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
virtual bool deleteObject(ossimAnnotationObject *anObject)
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)
const ossimDpt & ul() const
Definition: ossimDrect.h:339
ossimAnnotationSource(ossimImageSource *inputSource=0)
ossim_uint32 height() const
Definition: ossimIrect.h:487
static ossimString toString(bool aValue)
Numeric to string methods.
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
ossimDrect combine(const ossimDrect &rect) const
Definition: ossimDrect.h:826
std::vector< ossimRefPtr< ossimAnnotationObject > > AnnotationObjectListType
const AnnotationObjectListType & getObjectList() const
static ossimAnnotationObjectFactory * instance()
virtual void setNumberOfBands(ossim_uint32 bands)
virtual void initialize()
Initialize the data buffer.
virtual bool addObject(ossimAnnotationObject *anObject)
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
ossimRefPtr< ossimImageData > getImageData()
Will return the image data.
virtual ossimDataObjectStatus validate() const
virtual void setImageRectangleAndBands(const ossimIrect &rect, ossim_uint32 numberOfBands)
virtual void drawAnnotations(ossimRefPtr< ossimImageData > tile)
ossimImageSource * theInputConnection
unsigned int ossim_uint32
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
bool hasNans() const
Definition: ossimDrect.h:396
ossim_uint32 width() const
Definition: ossimIrect.h:500
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimScalarType
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
virtual void makeBlank()
Initializes data to null pixel values.
RTTI_DEF1(ossimAnnotationSource, "ossimAnnotationSource", ossimImageSourceFilter) ossimAnnotationSource
AnnotationObjectListType theAnnotationObjectList
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
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
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
const ossimDpt & ur() const
Definition: ossimDrect.h:340
ossimRefPtr< ossimRgbImage > theImage
virtual bool isPointWithin(const ossimDpt &imagePoint) 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
bool hasNans() const
Definition: ossimIrect.h:337
void allocate(const ossimIrect &rect)
const ossimDpt & ll() const
Definition: ossimDrect.h:342
8 bit unsigned integer
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
void setCurrentImageData(ossimRefPtr< ossimImageData > &imageData)
Allows you to change the image data that this RgbImage object operates on.
ossimRefPtr< ossimImageData > theTile
const ossimDpt & lr() const
Definition: ossimDrect.h:341
ossimIrect combine(const ossimIrect &rect) const
Definition: ossimIrect.cpp:543
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)