OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGeoAnnotationEllipseObject.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: ossimGeoAnnotationEllipseObject.cpp 15766 2009-10-20 12:37:09Z gpotts $
9 
10 #include <sstream>
11 
18 
20  "ossimGeoAnnotationEllipseObject",
22 
24  const ossimGpt& center,
25  const ossimDpt& widthHeight,
26  bool enableFill,
27  ossim_uint8 r,
28  ossim_uint8 g,
29  ossim_uint8 b,
30  ossim_uint8 thickness)
31  :ossimGeoAnnotationObject(r, g, b, thickness),
32  theProjectedEllipse(0),
33  theCenter(center),
34  theWidthHeight(widthHeight),
35  theEllipseWidthHeightUnitType(OSSIM_PIXEL) // default to image space
36 {
38  ossimDpt(0,0),
39  enableFill,
40  r,
41  g,
42  b,
43  thickness);
44 }
45 
49  theProjectedEllipse(rhs.theProjectedEllipse.valid()?(ossimAnnotationEllipseObject*)rhs.theProjectedEllipse->dup():(ossimAnnotationEllipseObject*)0),
50  theCenter(rhs.theCenter),
51  theWidthHeight(rhs.theWidthHeight),
52  theEllipseWidthHeightUnitType(rhs.theEllipseWidthHeightUnitType)
53 {
54 }
55 
57 {
59  {
61  }
62 }
63 
65 {
66  return new ossimGeoAnnotationEllipseObject(*this);
67 }
68 
70  double y)
71 {
75  theWidthHeight .x *= x;
76  theWidthHeight .y *= y;
77 }
78 
80 {
81  out << "center ground: " << theCenter << endl
82  << "width height image space flag = " << theEllipseWidthHeightUnitType
83  << endl
85  return out;
86 }
87 
89 {
91  {
92  theProjectedEllipse->draw(anImage);
93  }
94 }
95 
97 {
99  {
101  }
102 
103  return false;
104 }
105 
107 {
108  if(intersects(rect))
109  {
111  {
113  }
114  }
115 
116  return (ossimAnnotationObject*)0;
117 }
118 
120 {
122  {
124  }
125  else
126  {
127  rect.makeNan();
128  }
129 }
130 
132 {
134  {
136  }
137 }
138 
140 {
141  if(!projection)
142  {
143  return;
144  }
145 
146  // Ellipse center, height and width in image space.
147  ossimDpt projectedCenter;
148  ossimDpt projectedWidthHeight;
149 
150  // first get the center projected
151  projection->worldToLocal(theCenter, projectedCenter);
152 
153  getWidthHeightInPixels(projectedWidthHeight, projection);
154 
155  theProjectedEllipse->setCenterWidthHeight(projectedCenter,
156  projectedWidthHeight);
157 }
158 
160  const char* prefix) const
161 {
162  kwl.add(prefix, "center", theCenter.toString().c_str());
163  kwl.add(prefix, "ellipse_width", theWidthHeight.x);
164  kwl.add(prefix, "ellipse_height", theWidthHeight.y);
165  kwl.add(prefix, "azimuth", getAzimuth());
166  kwl.add(prefix, "fill", ossimString::toString(getFillFlag()));
167  kwl.add(prefix, "draw_axes", ossimString::toString(getDrawAxesFlag()));
168  kwl.add(prefix, "units",
169  ossimUnitTypeLut::instance()->getEntryString(theEllipseWidthHeightUnitType).c_str());
170 
171  return ossimGeoAnnotationObject::saveState(kwl, prefix);
172 }
173 
175  const char* prefix)
176 {
177  if (!theProjectedEllipse)
178  {
179  return false;
180  }
181 
182  //---
183  // Base class state must be called first to pick up colors...
184  //---
185  bool status = ossimGeoAnnotationObject::loadState(kwl, prefix);
186  if (status == true)
187  {
190  }
191 
192  const char* center = kwl.find(prefix, "center");
193  const char* ellipse_width = kwl.find(prefix, "ellipse_width");
194  const char* ellipse_height = kwl.find(prefix, "ellipse_height");
195  const char* azimuth = kwl.find(prefix, "azimuth");
196  const char* fill = kwl.find(prefix, "fill");
197  const char* draw_axes = kwl.find(prefix, "draw_axes");
198  const char* units = kwl.find(prefix, "units");
199 
200  if(units)
201  {
205  {
207  }
208  }
209 
210  if (center)
211  {
212  std::istringstream is(center);
213  is >> theCenter;
214  }
215  if(ellipse_width)
216  {
217  theWidthHeight.x = ossimString(ellipse_width).toDouble();
218  }
219  if(ellipse_height)
220  {
221  theWidthHeight.y = ossimString(ellipse_height).toDouble();
222  }
223 
224  if (azimuth)
225  {
226  setAzimuth(ossimString(azimuth).toFloat64());
227  }
228 
229  if (fill)
230  {
231  setFillFlag(ossimString(fill).toBool());
232  }
233 
234  if (draw_axes)
235  {
236  setDrawAxesFlag(ossimString(draw_axes).toBool());
237  }
238 
239  return status;
240 }
241 
243  ossimUnitType type)
244 {
246 }
247 
249 {
250  theWidthHeight = pt;
251 }
252 
254 {
256  {
258  }
259 }
260 
262 {
264  {
266  }
267  return 0.0;
268 }
269 
271  ossimDpt& widthHeight, const ossimImageGeometry* projection) const
272 {
274  {
275  case OSSIM_PIXEL:
276  {
277  widthHeight = theWidthHeight;
278 
279  break;
280  }
281 
282  case OSSIM_DEGREES:
283  case OSSIM_MINUTES:
284  case OSSIM_SECONDS:
285  {
286  ossimGpt origin = projection->hasProjection()?projection->getProjection()->origin():ossimGpt();
287  ossimDpt gsd = projection->getMetersPerPixel();
288 
289  ossimUnitConversionTool uct(origin,
292 
293  double x = uct.getValue(OSSIM_METERS);
294 
296 
297  double y = uct.getValue(OSSIM_METERS);
298 
299  widthHeight.x = ceil(x/gsd.x);
300  widthHeight.y = ceil(y/gsd.y);
301 
302  break;
303  }
304 
305  case OSSIM_METERS:
306  {
307  ossimDpt gsd = projection->getMetersPerPixel();
308  widthHeight.x = static_cast<ossim_int32>(theWidthHeight.x/gsd.x+0.5);
309  widthHeight.y = static_cast<ossim_int32>(theWidthHeight.y/gsd.y+0.5);
310 
311  break;
312  }
313 
314  default:
315  {
316  ossimDpt gsd = projection->getMetersPerPixel();
317 
320 
321  double x = uct.getValue(OSSIM_METERS);
322 
324 
325  double y = uct.getValue(OSSIM_METERS);
326 
327  widthHeight.x = ceil(x/gsd.x);
328  widthHeight.y = ceil(y/gsd.y);
329 
330  break;
331  }
332  }
333 }
335  ossim_uint8 g,
336  ossim_uint8 b)
337 {
339  {
340  theProjectedEllipse->setColor(r, g, b);
341  }
343 }
344 
346 {
348  {
349  theProjectedEllipse->setThickness(thickness);
350  }
351 }
352 
354 {
356  {
358  }
359 }
360 
362 {
364  {
366  }
367  return false;
368 }
369 
371 {
373  {
375  }
376 }
377 
379 {
381  {
383  }
384  return false;
385 }
386 
388 {
389  theCenter = gpt;
390 }
391 
393 {
394  gpt = theCenter;
395 }
396 
virtual void setDrawAxesFlag(bool flag)
Turns on and off drawing of axes on the ellipse.
void makeNan()
Definition: ossimDrect.h:388
ossim_uint32 x
virtual ossim_float64 getAzimuth() const
Gets the azimuth.
virtual void setThickness(ossim_uint8 thickness)
Sets the pen thickness of theProjectedEllipse.
double getValue(ossimUnitType unitType=OSSIM_METERS) const
virtual void getBoundingRect(ossimDrect &rect) const
virtual void setWidthHeight(const ossimDpt &pt)
Sets the width and height of point.
virtual void setDrawAxesFlag(bool flag)
Turns on and off drawing of axes on the ellipse.
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
virtual void setThickness(ossim_uint8 thickness)
virtual void setEllipseWidthHeightUnitType(ossimUnitType type)
ossimUnitType
Represents serializable keyword/value map.
ossim_uint32 y
virtual void transform(ossimImageGeometry *projection)
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual void setAzimuth(ossim_float64 azimuth)
Sets the azimuth.
void setValue(double value, ossimUnitType unitType=OSSIM_METERS)
double y
Definition: ossimDpt.h:165
virtual ossimAnnotationObject * getNewClippedObject(const ossimDrect &rect) const
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 ossim_int32 getEntryNumber(const char *entry_string, bool case_insensitive=true) const
virtual std::ostream & print(std::ostream &out) const
Generic print method.
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
virtual void applyScale(double x, double y)
virtual bool intersects(const ossimDrect &rect) const
virtual void getCenter(ossimGpt &gpt) const
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void setColor(ossim_uint8 r, ossim_uint8 g, ossim_uint8 b)
Sets the color of theProjectedEllipse.
void getWidthHeightInPixels(ossimDpt &widthHeight, const ossimImageGeometry *projection) const
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.
virtual void setCenter(const ossimGpt &gpt)
Sets the center ground point.
ossimDpt getMetersPerPixel() const
Returns the GSD associated with this image in the active projection.
double toDouble() const
virtual void draw(ossimRgbImage &anImage) const
virtual void setCenterWidthHeight(const ossimDpt &center, const ossimDpt &widthHeight)
virtual void setColor(ossim_uint8 r, ossim_uint8 g, ossim_uint8 b)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Saves the current state of this object.
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
virtual ossimAnnotationObject * getNewClippedObject(const ossimDrect &rect) const
return status
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
virtual void applyScale(double x, double y)
virtual ossimGpt origin() const =0
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 setAzimuth(ossim_float64 azimuth)
Sets the azimuth.
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
bool hasProjection() const
Returns TRUE if valid projection defined.
bool worldToLocal(const ossimGpt &world_pt, ossimDpt &local_pt) const
Exposes the 3D world-to-local image coordinate reverse projection.
ossimString toString(ossim_uint32 precision=15) const
Definition: ossimGpt.cpp:78
virtual bool intersects(const ossimDrect &rect) const
ossimRefPtr< ossimAnnotationEllipseObject > theProjectedEllipse
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
virtual void draw(ossimRgbImage &anImage) const
ossimGeoAnnotationEllipseObject(const ossimGpt &center=ossimGpt(0, 0), const ossimDpt &widthHeight=ossimDpt(0, 0), bool enableFill=false, ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255, ossim_uint8 thickness=1)
virtual void setFillFlag(bool flag)
Sets the fill flag.
static ossimUnitTypeLut * instance()
Returns the static instance of an ossimUnitTypeLut object.
RTTI_DEF1(ossimGeoAnnotationEllipseObject, "ossimGeoAnnotationEllipseObject", ossimGeoAnnotationObject)
unsigned char ossim_uint8
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
int ossim_int32
virtual ossim_float64 getAzimuth() const
Gets the azimuth.