OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGeoAnnotationPolyObject.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 //*************************************************************************
9 // $Id: ossimGeoAnnotationPolyObject.cpp 19734 2011-06-06 23:45:36Z dburken $
10 
11 #include <sstream>
12 
17 #include <ossim/base/ossimTrace.h>
18 
19 static const ossimTrace
20 traceDebug(ossimString("ossimGeoAnnotationPolyObject:debug"));
21 
23  "ossimGeoAnnotationPolyObject",
25 
27  ossim_uint8 r,
28  ossim_uint8 g,
29  ossim_uint8 b,
30  ossim_uint8 thickness)
31  :ossimGeoAnnotationObject(r, g, b, thickness),
32  thePolygon(),
33  theProjectedPolyObject(0),
34  m_PolyType(OSSIM_POLY_EXTERIOR_RING)
35 {
36  theProjectedPolyObject = new ossimAnnotationPolyObject(enableFill,
37  r,
38  g,
39  b,
40  thickness);
41 }
42 
44  const std::vector<ossimGpt>& groundPts,
45  bool enableFill,
46  ossim_uint8 r,
47  ossim_uint8 g,
48  ossim_uint8 b,
49  ossim_uint8 thickness)
50  :ossimGeoAnnotationObject(r, g, b, thickness),
51  thePolygon(),
52  theProjectedPolyObject(0),
53  m_PolyType(OSSIM_POLY_EXTERIOR_RING)
54 {
55 
56  thePolygon = groundPts;
57 
58  // we will initialize the projected polygon's size
59  // so we don't have to reset it every time we do a
60  // projection
61  //
62  std::vector<ossimDpt> projectedPoints(thePolygon.size());
63 
65  enableFill,
66  r,
67  g,
68  b,
69  thickness);
70 }
71 
75  thePolygon(rhs.thePolygon),
76  theProjectedPolyObject(rhs.theProjectedPolyObject.valid()?(ossimAnnotationPolyObject*)rhs.theProjectedPolyObject->dup():(ossimAnnotationPolyObject*)0),
77  m_PolyType(rhs.m_PolyType)
78 {
79 }
80 
82 {
84 }
85 
87 {
88  return new ossimGeoAnnotationPolyObject(*this);
89 }
90 
92  double y)
93 {
94  for(int i = 0; i < (int)thePolygon.size(); ++i)
95  {
96  thePolygon[i].lond(thePolygon[i].lond()*x);
97  thePolygon[i].latd(thePolygon[i].latd()*y);
98  }
100  {
102  }
103 
104 }
105 
107 {
108  // make sure it's not null
109  if(!projection)
110  {
111  return;
112  }
114  const std::vector<ossimGpt>::size_type BOUNDS = thePolygon.size();
115 
116  for(std::vector<ossimGpt>::size_type index=0; index < BOUNDS; ++index)
117  {
118  projection->worldToLocal(thePolygon[(int)index], poly[(int)index]);
119  }
120 
121  // update the bounding rect
122  //
124 }
125 
127 {
128  out << "number_of_points: " << thePolygon.size() << std::endl;
129  if(thePolygon.size() > 0)
130  {
131  for(long index =0; index < (long)(thePolygon.size()-1); ++index)
132  {
133  out << thePolygon[index] << std::endl;
134  }
135  out << thePolygon[thePolygon.size()-1] << std::endl;
136  }
137  out << "Projected Polygon" << std::endl;
139  return out;
140 }
141 
143 {
145  {
146  theProjectedPolyObject->draw(anImage);
147  }
148 }
149 
151  const ossimDrect& rect)const
152 {
154  {
156  }
157 
158  return (ossimAnnotationObject*)0;
159 }
160 
162 {
164  {
165  return theProjectedPolyObject->intersects(rect);
166  }
167 
168  return false;
169 }
170 
172 {
173  rect.makeNan();
175  {
177  }
178 }
179 
181 {
183  {
185  }
186 }
187 
188 const std::vector<ossimGpt>& ossimGeoAnnotationPolyObject::getPolygon()const
189 {
190  return thePolygon;
191 }
192 
193 void ossimGeoAnnotationPolyObject::setPolygon(const std::vector<ossimGpt>& poly)
194 {
195  thePolygon = poly;
196  std::vector<ossimDpt> projectedPoints(thePolygon.size());
198  {
199  theProjectedPolyObject->setPolygon(projectedPoints);
200  }
201 
202 }
203 
204 
206 {
208  {
210  }
211 }
212 
214  ossim_uint8 g,
215  ossim_uint8 b)
216 {
219  {
221  }
222 }
223 
225 {
228  {
230  }
231 }
232 
234  const char* prefix) const
235 {
236  ossim_uint32 vIdx = 0;
237 
238  for(ossim_uint32 i = 0; i < thePolygon.size(); ++i)
239  {
240  ossimString key = "v";
241  key += ossimString::toString(vIdx);
242 
243  kwl.add(prefix, key.c_str(), thePolygon[i].toString().c_str());
244 
245  ++vIdx;
246  }
247 
248  return ossimGeoAnnotationObject::saveState(kwl, prefix);
249 }
250 
252  const char* prefix)
253 {
255  {
256  return false;
257  }
258 
259  //---
260  // Base class state must be called first to pick up colors...
261  //---
262  bool status = ossimGeoAnnotationObject::loadState(kwl, prefix);
263 
264  ossim_uint32 index = 0;
265  ossimString copyPrefix = prefix;
266  ossim_uint32 count = kwl.getNumberOfSubstringKeys(copyPrefix+"v[0-9]*");
267 
268  ossim_uint32 numberOfMatches = 0;
269  const ossim_uint32 MAX_INDEX = count + 100;
270 
271  while(numberOfMatches < count)
272  {
273  ossimString key = "v";
274  key += ossimString::toString(index);
275 
276  const char* lookup = kwl.find(prefix, key.c_str());
277  if (lookup)
278  {
279  ++numberOfMatches;
280  ossimGpt gpt;
281 
282  std::istringstream is(lookup);
283  is >> gpt;
284  thePolygon.push_back(gpt);
285  }
286 
287  ++index;
288 
289  if (index > MAX_INDEX) // Avoid infinite loop...
290  {
291  break;
292  }
293  }
294 
295  // Set up the annotator.
298 
299  std::vector<ossimDpt> projectedPoints(thePolygon.size());
300  theProjectedPolyObject->setPolygon(projectedPoints);
301 
302  if (traceDebug())
303  {
305  << "ossimGeoAnnotationPolyObject::loadState DEBUG:" << std::endl;
306  for (ossim_uint32 i=0; i<thePolygon.size(); ++i)
307  {
309  << "thePolygon[" << i << "]: " << thePolygon[i] << std::endl;
310  }
311  }
312 
313  return status;
314 }
void makeNan()
Definition: ossimDrect.h:388
virtual void getBoundingRect(ossimDrect &rect) const
ossim_uint32 x
virtual void draw(ossimRgbImage &anImage) const
ossim_uint32 getNumberOfSubstringKeys(const ossimString &regularExpression) const
virtual void setThickness(ossim_uint8 thickness)
virtual void draw(ossimRgbImage &anImage) const
Represents serializable keyword/value map.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Saves the current state of this object.
ossim_uint32 y
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual void transform(ossimImageGeometry *projection)
static ossimString toString(bool aValue)
Numeric to string methods.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Saves the current state of this object.
virtual ossimAnnotationObject * getNewClippedObject(const ossimDrect &rect) const
virtual void setColor(ossim_uint8 r, ossim_uint8 g, ossim_uint8 b)
virtual ossimAnnotationObject * getNewClippedObject(const ossimDrect &rect) 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.
ossimRefPtr< ossimAnnotationPolyObject > theProjectedPolyObject
const ossimPolygon & getPolygon() const
virtual std::ostream & print(std::ostream &out) const
Generic print method.
ossimGeoAnnotationPolyObject(bool enableFill=false, ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)
virtual std::ostream & print(std::ostream &out) const
Generic print method.
virtual void applyScale(double x, double y)
RTTI_DEF1(ossimGeoAnnotationPolyObject, "ossimGeoAnnotationPolyObject", ossimGeoAnnotationObject) ossimGeoAnnotationPolyObject
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual ossimDrect getBoundingRect() const
virtual const std::vector< ossimGpt > & getPolygon() const
unsigned int ossim_uint32
virtual void setColor(ossim_uint8 r, ossim_uint8 g, ossim_uint8 b)
virtual void applyScale(double x, double y)
virtual bool intersects(const ossimDrect &rect) const
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
return status
virtual bool intersects(const ossimDrect &rect) const
virtual void setThickness(ossim_uint8 thickness)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual void setPolygon(const std::vector< ossimGpt > &poly)
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 worldToLocal(const ossimGpt &world_pt, ossimDpt &local_pt) const
Exposes the 3D world-to-local image coordinate reverse projection.
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
unsigned char ossim_uint8
virtual void setPolygon(const vector< ossimDpt > &imagePoints)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23