OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGeographicAnnotationGrid.cpp
Go to the documentation of this file.
7 #include <ossim/base/ossimDms.h>
9 
10 
11 static ossimTrace traceDebug("ossimGeographicAnnotationGrid:debug");
12 
15  theViewProjection(NULL),
16  theGroundRect(0,0,0,0),
17  theDeltaLatSpacing(1.0/60.0), // every minute
18  theDeltaLonSpacing(1.0/60.0)
19 {
20 }
21 
23 
24 {
25  if(!anImage.getImageData())
26  {
27  return;
28  }
30 
31  if((fabs(theDeltaLatSpacing) <= DBL_EPSILON)||
33  {
34  return;
35  }
36 
37 // ossimDrect imageRect = anImage.getImageData()->getImageRectangle();
38  // If the view projection exists we will use it to
39  // compute the bounding ground rect and find all lines
40  // that overlap that area in the lat and lon direction
41  // and draw them.
42  //
43  // I the projection doesn't exist we will assume that
44  // the geographic grid to generate will be 0,0 is origin
45  // -180lon and 90lat.
46  //
48  {
51 
52  line = new ossimAnnotationLineObject();
53  font = new ossimAnnotationGdBitmapFont();
54 
55  ossimDpt start;
56  ossimDpt end;
57  ossimGpt groundUpper(0,0,0,theGroundRect.ul().datum());
58  ossimGpt groundLower(0,0,0,theGroundRect.ul().datum());
59  double height = theGroundRect.height();
60  double width = theGroundRect.width();
61  double lat = theGroundRect.ul().latd();
62 // ossimDrect imageRect = anImage.getImageData()->getImageRectangle();
63  double lon;
64 
65  // used for the font spacing
66  ossimDrect boundingRect;
67 
68  // we will go across the longitudinal direction first
70  lon <= theGroundRect.ur().lond();
71  lon += theDeltaLonSpacing)
72  {
73  groundUpper.lond(lon);
74  groundUpper.latd(lat);
75  groundLower.lond(lon);
76  groundLower.latd(lat-height);
77 
78  theViewProjection->worldToLineSample(groundUpper, start);
79  theViewProjection->worldToLineSample(groundLower, end);
80 
81  line->setLine(start, end);
82  line->draw(anImage);
83  }
84  lon = theGroundRect.ul().lond();
85 
86  // now go accross longitude and place the
87  // text in.
89  lon <= theGroundRect.ur().lond();
90  lon += theDeltaLonSpacing)
91  {
92  groundUpper.lond(lon);
93  groundUpper.latd(lat);
94  groundLower.lond(lon);
95  groundLower.latd(lat-height);
96 
97  theViewProjection->worldToLineSample(groundUpper, start);
98  theViewProjection->worldToLineSample(groundLower, end);
99  font->setText(ossimDms(groundUpper.lond(), false).toString("ddd@mm'ss.ssss\"C"));
100  font->getBoundingRect(boundingRect);
101  start.y -= boundingRect.height();
102  font->setCenterTextPosition(start);
103  font->draw(anImage);
104 
105  end.y += boundingRect.height();
106  font->setCenterText(end,
107  ossimDms(groundLower.lond(), false).toString("ddd@mm'ss.ssssC"));
108  font->draw(anImage);
109  }
110  lon = theGroundRect.ul().lond();
111 
112  ossimGpt groundLeft;
113  ossimGpt groundRight;
114 
115  // Now go down lat direction
116  for(lat = theGroundRect.ul().latd()-theDeltaLatSpacing;
117  lat >= theGroundRect.lr().latd();
118  lat -= theDeltaLatSpacing)
119  {
120  groundLeft.lond(lon);
121  groundLeft.latd(lat);
122  groundRight.lond(lon+width);
123  groundRight.latd(lat);
124 
125  theViewProjection->worldToLineSample(groundLeft, start);
126  theViewProjection->worldToLineSample(groundRight, end);
127 
128  line->setLine(start, end);
129  line->draw(anImage);
130  }
131 
132  // now go down lat direction font
133  for(lat = theGroundRect.ul().latd()-theDeltaLatSpacing;
134  lat >= theGroundRect.lr().latd();
135  lat -= theDeltaLatSpacing)
136  {
137  groundLeft.lond(lon);
138  groundLeft.latd(lat);
139  groundRight.lond(lon+width);
140  groundRight.latd(lat);
141 
142  theViewProjection->worldToLineSample(groundLeft, start);
143  theViewProjection->worldToLineSample(groundRight, end);
144 
145 
146  font->setText(ossimDms(groundLeft.latd()).toString("ddd@mm'ss.ssss\"C"));
147  font->getBoundingRect(boundingRect);
148  start.x -= boundingRect.width()/2.0-1;
149  font->setCenterTextPosition(start);
150  font->draw(anImage);
151 
152  end.x += boundingRect.width()/2.0+1;
153  font->setCenterText(end,
154  ossimDms(groundRight.latd()).toString("ddd@mm'ss.ssssC"));
155  font->draw(anImage);
156  }
157 
158  line = 0;
159  font = 0;
160  }
161 }
162 
163 
165  const ossimGrect& boundingGroundRect)
166 {
167  static const char* MODULE = "ossimGeographicAnnotationGrid::setViewProjectionInformation";
168  theViewProjection = projection;
169 
170  // set the ground and then stretch it
171  // to cover which even degree grid we are currently
172  // in.
173  theGroundRect = boundingGroundRect;
174 
175  // find the even degree grid.
176  ossimGrect rect(ossimGpt(90, -180),
177  ossimGpt(-90, 180));
178 
179  // make sure that it is within the range of the
180  // geographic grid.
181  ossimGrect clipRect = rect.clipToRect(boundingGroundRect);
182 
183  // for easier math we will shift the points so they
184  // are between 0..360Lon and 0..180Lat. This way
185  // we are working with just positive numbers
186  double upperLeftLonShift = clipRect.ul().lond() + 180;
187  double upperLeftLatShift = clipRect.ul().latd() + 90;
188  double lowerRightLonShift = clipRect.lr().lond() + 180;
189  double lowerRightLatShift = clipRect.lr().latd() + 90;
190 
191  // now find the even boundaries
192  double upperLeftLonCell = floor(upperLeftLonShift/theDeltaLonSpacing)*
194  double upperLeftLatCell = floor(upperLeftLatShift/theDeltaLatSpacing)*
196  double lowerRightLonCell = floor(lowerRightLonShift/theDeltaLonSpacing)*
198  double lowerRightLatCell = floor(lowerRightLatShift/theDeltaLatSpacing)*
200 
201  // now adjust them by 1 boundary distance.
202  upperLeftLonCell -= theDeltaLonSpacing;
203  upperLeftLatCell += theDeltaLatSpacing;
204  lowerRightLonCell += theDeltaLonSpacing;
205  lowerRightLatCell -= theDeltaLatSpacing;
206 
207  // now clamp to the range of the lat and lon
208  upperLeftLonCell = (upperLeftLonCell<0?0:upperLeftLonCell);
209  upperLeftLatCell = (upperLeftLatCell>180?180:upperLeftLatCell);
210  lowerRightLonCell = (lowerRightLonCell>360?360:lowerRightLonCell);
211  lowerRightLatCell = (lowerRightLatCell<0?0:lowerRightLatCell);
212 
213  // now shift them back into range
214  upperLeftLonCell -= 180;
215  upperLeftLatCell -= 90;
216  lowerRightLonCell -= 180;
217  lowerRightLatCell -= 90;
218 
219  const ossimDatum* datum = theGroundRect.ul().datum();
220  theGroundRect = ossimGrect(upperLeftLatCell, upperLeftLonCell,
221  lowerRightLatCell, lowerRightLonCell,
222  datum);
223 
224  if(traceDebug())
225  {
226  CLOG << "Ground Rect: " << theGroundRect << endl;
227  }
229 }
230 
232 {
233  rect = theBoundingRect;
234 }
235 
237 {
238  static const char* MODULE = "ossimGeographicAnnotationGrid::computeBoundingRect";
239 
241  {
242  vector<ossimDpt> points(4);
243 
248 
249  // now solve the bounding rect in view space.
250  theBoundingRect = ossimDrect(points);
251 
252  // for now we will add a border for the labelling
253  // of lat lon readouts. We need a better border
254  // computation that checks exactly what we need
255  // based on font sizes.
256  //
257  ossimDpt ul = theBoundingRect.ul();
258  ossimDpt lr = theBoundingRect.lr();
259 
260 
262  font->setCenterText(ossimDpt(0,0),"ddd@mm'ss.ssssC");
263  ossimDrect boundingRect;
264  font->getBoundingRect(boundingRect);
265  font = 0;
266 
267  theBoundingRect = ossimDrect(ul.x - boundingRect.width(),
268  ul.y - boundingRect.height(),
269  lr.x + boundingRect.width(),
270  lr.y + boundingRect.height());
271 
272  if(traceDebug())
273  {
274  CLOG << " bounding rect: " << theBoundingRect << endl;
275  }
276  }
277 }
278 
280 {
281  return out;
282 }
ossimRefPtr< ossimMapProjection > theViewProjection
#define CLOG
Definition: ossimTrace.h:23
ossim_float64 width() const
Definition: ossimDrect.h:522
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
bool valid() const
Definition: ossimRefPtr.h:75
virtual void draw(ossimRgbImage &anImage) const
virtual ossimDpt worldToLineSample(const ossimGpt &worldPoint) const
const ossimDpt & ul() const
Definition: ossimDrect.h:339
ossim_float64 width() const
Returns the width of a rectangle in deg.
Definition: ossimGrect.h:247
double y
Definition: ossimDpt.h:165
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
const ossimDatum * datum() const
datum().
Definition: ossimGpt.h:196
virtual void draw(ossimRgbImage &anImage) const
virtual ossimDrect getBoundingRect() const
virtual void draw(ossimRgbImage &anImage) const
ossimRefPtr< ossimImageData > getImageData()
Will return the image data.
virtual void setCenterTextPosition(const ossimDpt &position)
void setLine(const ossimDpt &start, const ossimDpt &end)
ossimGrect clipToRect(const ossimGrect &rect) const
Definition: ossimGrect.h:190
const ossimGpt & ul() const
Definition: ossimGrect.h:252
ossimGpt ur() const
Definition: ossimGrect.h:257
#define DBL_EPSILON
ossim_float64 height() const
Definition: ossimDrect.h:517
virtual void setCenterText(const ossimDpt &center, const ossimString &text)
virtual void getBoundingRect(ossimDrect &rect) const
void setDrawColor(ossim_uint8 r=255, ossim_uint8 g=255, ossim_uint8 b=255)
virtual void setText(const ossimString &text)
virtual void setViewProjectionInformation(ossimMapProjection *projection, const ossimGrect &boundingGroundRect)
double x
Definition: ossimDpt.h:164
ossim_float64 height() const
Returns the height of a rectangle in deg.
Definition: ossimGrect.h:242
const ossimDpt & lr() const
Definition: ossimDrect.h:341
const ossimGpt & lr() const
Definition: ossimGrect.h:269
ossimGpt ll() const
Definition: ossimGrect.h:263
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23