OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGeoAnnotationMultiPolyLineObject.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 //
7 //*************************************************************************
8 // $Id: ossimGeoAnnotationMultiPolyLineObject.cpp 17206 2010-04-25 23:20:40Z dburken $
9 
10 #include <sstream>
11 
17 
18 
20  "ossimGeoAnnotationMultiPolyLineObject",
22 
24  :
26  theMultiPolyLine(),
27  theBoundingRect(),
28  theDatum(ossimDatumFactory::instance()->wgs84()),
29  theProjectedPolyLineObject(0)
30 {
33 }
34 
36  const vector<ossimPolyLine>& multiPoly,
37  ossim_uint8 r,
38  ossim_uint8 g,
39  ossim_uint8 b,
40  ossim_uint8 thickness)
41  :
42  ossimGeoAnnotationObject(r, g, b, thickness),
43  theMultiPolyLine(multiPoly),
44  theBoundingRect(),
45  theDatum(ossimDatumFactory::instance()->wgs84()),
46  theProjectedPolyLineObject(0)
47 {
50 }
51 
55  theMultiPolyLine(rhs.theMultiPolyLine),
56  theBoundingRect(rhs.theBoundingRect),
57  theDatum(rhs.theDatum),
58  theProjectedPolyLineObject(rhs.theProjectedPolyLineObject.valid()?(ossimAnnotationMultiPolyLineObject*)rhs.theProjectedPolyLineObject->dup():0)
59 {
60 }
61 
63 {
64  return new ossimGeoAnnotationMultiPolyLineObject(*this);
65 }
66 
68 {
70 }
71 
72 void ossimGeoAnnotationMultiPolyLineObject::applyScale(double /* x */, double /* y */)
73 {
75  << "ossimGeoAnnotationPolyLineObject::applyScale NOT IMPLEMENTED!!!!"
76  << endl;
77 }
78 
80 {
81  if(!projection)
82  {
83  return;
84  }
85 
87 
88  //---
89  // NOTE:
90  // allocateProjectedPolygon() will set theProjectedPolyLineObject to 0 if
91  // theMultiPolyLine is empty (theMultiPolyLine.size() == 0). So check
92  // before accessing pointer to avoid a core dump.
93  //---
95  {
96  return;
97  }
98 
99  std::vector<ossimPolyLine>& multiPolyLine =
101  ossimGpt tempPoint(0,0, ossim::nan(), theDatum);
102 
103  for(std::vector<ossimPolyLine>::size_type polyI = 0;
104  polyI < theMultiPolyLine.size();
105  ++polyI)
106  {
107  ossimPolyLine polyLine;
108 
109  ossim_uint32 numberOfVertices =
110  theMultiPolyLine[polyI].getNumberOfVertices();
111  for(ossim_uint32 pointI = 0; pointI < numberOfVertices; ++pointI)
112  {
113  tempPoint.latd(theMultiPolyLine[polyI][pointI].lat);
114  tempPoint.lond(theMultiPolyLine[polyI][pointI].lon);
115  ossimDpt temp;
116  projection->worldToLocal(tempPoint, temp);
117  if(!temp.hasNans())
118  {
119  multiPolyLine[polyI].addPoint(temp);
120  }
121  }
122  multiPolyLine[polyI].roundToIntegerBounds(true);
123  }
124 }
125 
127 {
129  << "ossimGeoAnnotationMultiPolyLineObject::print\n"
130  << "Poly line size: " << theMultiPolyLine.size() << endl;
131  return out;
132 }
133 
135 {
137  << "ossimGeoAnnotationMultiPolyObject::intersects NOT IMPLEMENTED"
138  << endl;
139  return false;
140 }
141 
143  const ossimDrect& /* rect */)const
144 {
146  << "ossimGeoAnnotationMultiPolyObject::getNewClippedObject "
147  << "NOT IMPLEMENTED" << endl;
148 
149  return (ossimAnnotationObject*)(dup());
150 }
151 
153 {
155  {
157  }
158 }
159 
161 {
162  rect = theBoundingRect;
163 }
164 
166  const ossimGpt& pt)
167 {
168  if(polygonIndex < theMultiPolyLine.size())
169  {
170  theMultiPolyLine[polygonIndex].addPoint(pt);
171 
172  // we will have to reset the projected polygon
174  }
175 }
176 
178  const vector<ossimPolyLine>& multiPoly)
179 {
180  theMultiPolyLine = multiPoly;
182 }
183 
185 {
188  {
191  }
192 
193 }
194 
196 {
198  {
199  return theProjectedPolyLineObject->isPointWithin(imagePoint);
200  }
201 
202  return false;
203 }
204 
206  ossim_uint8 g,
207  ossim_uint8 b)
208 {
211  {
213  }
214 }
215 
217 {
220  {
222  }
223 }
224 
226 {
227  theDatum = datum;
228 }
229 
231 {
232  return theDatum;
233 }
234 
235 const std::vector<ossimPolyLine>&
237 {
238  return theMultiPolyLine;
239 }
240 
241 std::vector<ossimPolyLine>&
243 {
244  return theMultiPolyLine;
245 }
246 
248  const char* prefix) const
249 {
250  ossim_uint32 vIdx = 0;
251 
252  for(ossim_uint32 i = 0; i < theMultiPolyLine.size(); ++i)
253  {
255  for(ossim_uint32 j = 0; j < pl.getNumberOfVertices(); ++j)
256  {
257  ossimDpt dpt = pl[j];
259  os << setprecision(15) << dpt.x << " " << dpt.y << endl;
260 
261  ossimString key = "v";
262  key += ossimString::toString(vIdx);
263  kwl.add(prefix, key.c_str(), os.str().c_str());
264  ++vIdx;
265  }
266  }
267 
268  return ossimGeoAnnotationObject::saveState(kwl, prefix);
269 }
270 
272  const ossimKeywordlist& kwl, const char* prefix)
273 {
274  //---
275  // Base class state must be called first to pick up colors...
276  //---
277  bool status = ossimGeoAnnotationObject::loadState(kwl, prefix);
278 
279  ossim_uint32 index = 0;
280  ossimString copyPrefix = prefix;
281  ossim_uint32 count = kwl.getNumberOfSubstringKeys(copyPrefix+
282  "v[0-9]");
283 
284  ossim_uint32 numberOfMatches = 0;
285  const ossim_uint32 MAX_INDEX = count + 100;
286  ossimPolyLine pl;
287 
288  while(numberOfMatches < count)
289  {
290  ossimString key = "v";
291  key += ossimString::toString(index);
292 
293  const char* lookup = kwl.find(prefix, key.c_str());
294  if (lookup)
295  {
296  ++numberOfMatches;
297  ossimDpt dpt;
298  ossimString x,y;
299  std::istringstream is(lookup);
300  is >> x >> y;
301  pl.addPoint(ossimDpt(x.toDouble(), y.toDouble()));
302  }
303 
304  if (pl.size() == 2)
305  {
306  theMultiPolyLine.push_back(pl);
307  pl.clear();
308  }
309 
310  ++index;
311 
312  if (index > MAX_INDEX) // Avoid infinite loop...
313  {
314  break;
315  }
316  }
317 
318  return status;
319 }
320 
322 {
324 
325  if(theMultiPolyLine.size())
326  {
327  vector<ossimPolyLine> polyList(theMultiPolyLine.size());
330  theRed,
331  theGreen,
332  theBlue,
333  theThickness);
334  }
335 }
void makeNan()
Definition: ossimDrect.h:388
ossim_uint32 x
virtual void draw(ossimRgbImage &anImage) const
virtual bool intersects(const ossimDrect &rect) const
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
ossim_uint32 getNumberOfSubstringKeys(const ossimString &regularExpression) const
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
virtual void setThickness(ossim_uint8 thickness)
Represents serializable keyword/value map.
ossim_uint32 y
virtual void setColor(ossim_uint8 r, ossim_uint8 g, ossim_uint8 b)
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Saves the current state of this object.
double y
Definition: ossimDpt.h:165
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.
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
ossim_uint32 getNumberOfVertices() const
Definition: ossimPolyLine.h:70
RTTI_DEF1(ossimGeoAnnotationMultiPolyLineObject, "ossimGeoAnnotationMultiPolyLineObject", ossimGeoAnnotationObject)
virtual void getBoundingRect(ossimDrect &rect) const
virtual bool isPointWithin(const ossimDpt &imagePoint) const
ossimRefPtr< ossimAnnotationMultiPolyLineObject > theProjectedPolyLineObject
const std::vector< ossimPolyLine > & getMultiPolyLine() const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual ossimDrect getBoundingRect() 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.
ossim_uint32 size()
const std::vector< ossimPolyLine > & getMultiPolyLine() const
virtual ossimAnnotationObject * getNewClippedObject(const ossimDrect &rect) const
unsigned int ossim_uint32
virtual void setColor(ossim_uint8 r, ossim_uint8 g, ossim_uint8 b)
virtual void setMultiPolyLine(const vector< ossimPolyLine > &multiPoly)
bool hasNans() const
Definition: ossimDpt.h:67
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
void addPoint(const ossimDpt &pt)
return status
virtual void addPoint(ossim_uint32 polygonIndex, const ossimGpt &pt)
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 draw(ossimRgbImage &anImage) const
double x
Definition: ossimDpt.h:164
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 bool isPointWithin(const ossimDpt &imagePoint) const
bool worldToLocal(const ossimGpt &world_pt, ossimDpt &local_pt) const
Exposes the 3D world-to-local image coordinate reverse projection.
virtual std::ostream & print(std::ostream &out) const
Generic print method.
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
unsigned char ossim_uint8
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
virtual void transform(ossimImageGeometry *projection)