OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimOrthoImageMosaic.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: ossimOrthoImageMosaic.cpp 21631 2012-09-06 18:10:55Z dburken $
11 #include <ossim/base/ossimTrace.h>
16 
17 static ossimTrace traceDebug ("ossimOrthoImageMosaic:debug");
18 
19 RTTI_DEF1(ossimOrthoImageMosaic, "ossimOrthoImageMosaic", ossimImageMosaic);
20 
21 //**************************************************************************************************
22 //
23 //**************************************************************************************************
26 {
27  m_Delta.makeNan();
29 }
30 
31 //**************************************************************************************************
32 //
33 //**************************************************************************************************
35  :ossimImageMosaic(inputSources)
36 {
37  m_Delta.makeNan();
39 }
40 
41 //**************************************************************************************************
42 //
43 //**************************************************************************************************
45 {
46 }
47 
48 //**************************************************************************************************
49 //
50 //**************************************************************************************************
52  ossim_uint32 resLevel)const
53 {
54  ossim_uint32 result = 0;
55  for(ossim_uint32 i = 0; i < m_InputTiePoints.size(); ++i)
56  {
58  getInput(i));
59  if(interface&&
60  !m_InputTiePoints[i].hasNans())
61  {
62  ossimIrect tempRect = getRelativeRect(i, resLevel);
63 
64  if(!tempRect.hasNans())
65  {
66  if(tempRect.intersects(rect))
67  {
68  ++result;
69  }
70  }
71  }
72  }
73 
74  return 0;
75 }
76 
77 //**************************************************************************************************
78 //
79 //**************************************************************************************************
80 void ossimOrthoImageMosaic::getOverlappingImages(std::vector<ossim_uint32>& result,
81  const ossimIrect& rect,
82  ossim_uint32 resLevel)const
83 {
84  result.clear();
85  for(ossim_uint32 i = 0; i < m_InputTiePoints.size(); ++i)
86  {
88  getInput(i));
89  if(interface&&
90  !m_InputTiePoints[i].hasNans())
91  {
92  ossimIrect tempRect = getRelativeRect(i, resLevel);
93 
94  if(!tempRect.hasNans())
95  {
96  if(tempRect.intersects(rect))
97  {
98  result.push_back(i);
99  }
100  }
101  }
102  }
103 }
104 
105 //**************************************************************************************************
106 // Returns the image geometry for the complete mosaic
107 //**************************************************************************************************
109 {
110  if ( !m_Geometry.valid() )
111  {
112  // The geometry (projection) associated with this mosaic is necessarily the same for all
113  // single-image objects feeding into this combiner, So we will copy the first image source's
114  // geometry, and modify our copy to reflect the mosaic-specific items.
116  if(interface)
117  {
118  ossimRefPtr<ossimImageGeometry> inputGeom = interface->getImageGeometry();
119  if ( inputGeom.valid() )
120  {
121  m_Geometry = new ossimImageGeometry(*inputGeom);
122  updateGeometry();
123  }
124  }
125  }
126  return m_Geometry;
127 }
128 
129 //**************************************************************************************************
132 //**************************************************************************************************
134 {
135  if (!m_Geometry.valid())
136  return;
137 
139  if (mapProj)
140  {
141  if(m_Units == "degrees")
142  {
145  mapProj->origin().datum()));
146  }
147  else if(m_Units == "meters")
148  {
149  mapProj->setMetersPerPixel(m_Delta);
151  }
152  }
153 }
154 
155 //**************************************************************************************************
156 //
157 //**************************************************************************************************
159 {
160  ossimDpt decimation;
161 
162  decimation.makeNan();
163 
165  getInput(0));
166  if(interface)
167  {
168  interface->getDecimationFactor(resLevel,
169  decimation);
170  }
171  if(decimation.hasNans())
172  {
173  return m_BoundingRect;
174  }
175  return m_BoundingRect*decimation;
176 }
177 
178 //**************************************************************************************************
179 //
180 //**************************************************************************************************
182 {
183  m_InputTiePoints.clear();
184  m_Delta.makeNan();
186 
187  if(traceDebug())
188  {
190  << "ossimOrthoImageMosaic::initialize() DEBUG: Entered..."
191  << "Number of inputs = " << getNumberOfInputs()
192  << std::endl;
193  }
194  if(getNumberOfInputs())
195  {
197  for(ossim_uint32 i = 0; i < getNumberOfInputs(); ++i)
198  {
200  m_InputTiePoints[i].makeNan();
201  if(interface)
202  {
203  ossimRefPtr<ossimImageGeometry> geom = interface->getImageGeometry();
204  if( geom.valid() )
205  {
207  if(mapPrj)
208  {
209  if(!mapPrj->isGeographic())
210  {
211  m_Units = "meters";
212  m_Delta = mapPrj->getMetersPerPixel();
213  }
214  else
215  {
216  m_Units = "degrees";
218  }
219  if(m_Units == "degrees")
220  {
221  m_InputTiePoints[i].x = mapPrj->getUlGpt().lond();
222  m_InputTiePoints[i].y = mapPrj->getUlGpt().latd();
223  }
224  else if(m_Units == "meters")
225  {
226  m_InputTiePoints[i].x = mapPrj->getUlEastingNorthing().x;;
227  m_InputTiePoints[i].y = mapPrj->getUlEastingNorthing().y;
228  }
229 
230  if(traceDebug())
231  {
233  << "tie points for input " << i << " = "
234  << m_InputTiePoints[i] << std::endl;
235  }
236 
237  }
238  }
239  if(!m_InputTiePoints[i].hasNans())
240  {
241  if(m_UpperLeftTie.hasNans())
242  {
244  }
245  else if(!m_InputTiePoints[i].hasNans())
246  {
247  if(m_Units == "meters")
248  {
251  }
252  else
253  {
256  }
257  }
258  }
259  }
260  else
261  {
262  m_InputTiePoints[i].makeNan();
263 // CLOG << "Input " << i << " will not be used since no ortho information exists" << endl;
264  }
265  }
266  }
267 
269  if(traceDebug())
270  {
272  << "m_UpperLeftTie = " << m_UpperLeftTie << std::endl
273  << "delta per pixel = " << m_Delta << std::endl
274  << "bounding rect = " << m_BoundingRect << std::endl;
275  }
277 
278  // Finally, update the geometry (if there was one already defined), to reflect the change in input
279  updateGeometry();
280 
281  if(traceDebug())
282  {
283  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimOrthoImageMosaic::initialize() DEBUG: Leaving..." << std::endl;
284  }
285 }
286 
287 //**************************************************************************************************
288 //
289 //**************************************************************************************************
291  const ossimIrect& origin,
292  ossim_uint32 resLevel)
293 {
294  const char *MODULE="ossimOrthoImageMosaic::getNextTile";
295 
297 
298  if(theCurrentIndex >= size)
299  {
301  }
302 
303  ossimImageSource* temp = NULL;
306 
307  do
308  {
310  if(temp)
311  {
312  ossimIrect relRect = getRelativeRect(theCurrentIndex, resLevel);
313 
314  if(traceDebug())
315  {
316  CLOG << "Rel rect for input " << theCurrentIndex
317  << " = " << relRect
318  << "\nRes level: " << resLevel
319  << endl;
320  }
321 
322  if(origin.intersects(relRect))
323  {
324  // get the rect relative to the input rect
325  //
326  ossimIrect shiftedRect = origin + (ossimIpt(-relRect.ul().x,
327  -relRect.ul().y));
328 
329  // request that tile from the input space.
330  result = temp->getTile(shiftedRect, resLevel);
331 
332  // now change the origin to the output origin.
333  if (result.valid())
334  {
335  result->setOrigin(origin.ul());
336 
337  status = result->getDataObjectStatus();
338 
339  if((status == OSSIM_NULL)||(status == OSSIM_EMPTY))
340  {
341  result = NULL;
342  }
343  }
344  }
345  else
346  {
347  result = NULL;
348  }
349  }
350 
351  // Go to next source.
352  ++theCurrentIndex;
353 
354  } while(!result.valid() && (theCurrentIndex<size));
355 
356  returnedIdx = theCurrentIndex;
357  if(result.valid())
358  {
359  --returnedIdx;
360  }
361  return result;
362 }
363 
364 //**************************************************************************************************
365 //
366 //**************************************************************************************************
368 {
369  const char* MODULE = "ossimOrthoImageMosaic::computeBoundingRect";
370 
372 
373  for(ossim_uint32 i = 0; i < m_InputTiePoints.size(); ++ i)
374  {
375  ossimIrect shiftedRect = getRelativeRect(i, resLevel);
376 
377  if(traceDebug())
378  {
379  CLOG << "bounding rect for input " << (i+1)
380  << ":" << shiftedRect << endl;
381  }
382  if(!shiftedRect.hasNans())
383  {
384  if(m_BoundingRect.hasNans())
385  {
386  m_BoundingRect = shiftedRect;
387  }
388  else
389  {
390  m_BoundingRect = m_BoundingRect.combine(shiftedRect);
391  }
392  }
393  }
394 }
395 
396 //**************************************************************************************************
397 //
398 //**************************************************************************************************
400  ossim_uint32 resLevel)const
401 {
402  ossimIrect result;
404  getInput(index));
405  result.makeNan();
406  if(interface&&
407  !m_InputTiePoints[index].hasNans())
408  {
409  ossimIrect inputRect = interface->getBoundingRect();
410  result = inputRect;
411 
412  if(!inputRect.hasNans())
413  {
414  ossimDpt shift = (m_InputTiePoints[index] - m_UpperLeftTie);
415 
416  shift.x/= m_Delta.x;
417  shift.y/=-m_Delta.y;
418 
419  result = result + shift;
420  if(!resLevel)
421  {
422  return result;
423  }
424  ossimDpt decimation;
425  interface->getDecimationFactor(resLevel, decimation);
426  if(!decimation.hasNans())
427  {
428  result = result * decimation;
429  }
430  }
431  }
432 
433  return result;
434 }
virtual const ossimDpt & getDecimalDegreesPerPixel() const
Returns decimal degrees per pixel as an ossimDpt with "x" representing longitude and "y" representing...
std::vector< ossimDpt > m_InputTiePoints
#define CLOG
Definition: ossimTrace.h:23
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
virtual void getOverlappingImages(std::vector< ossim_uint32 > &result, const ossimIrect &rect, ossim_uint32 resLevel=0) const
Used to populate the result with the index of the overlapping images.
bool valid() const
Definition: ossimRefPtr.h:75
void computeBoundingRect(ossim_uint32 resLevel=0)
double y
Definition: ossimDpt.h:165
ossimDpt m_Delta
Holds R0 delta and will be scaled for different r-level requests.
virtual bool isGeographic() const
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossimDataObjectStatus getDataObjectStatus() const
virtual void setDecimalDegreesPerPixel(const ossimDpt &gsd)
ossim_uint32 theCurrentIndex
bool intersects(const ossimIrect &rect) const
Definition: ossimIrect.cpp:183
An image mosaic is a simple combiner that will just do a simple mosaic.
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the geometry associated with the full mosaic.
virtual void setUlGpt(const ossimGpt &ulGpt)
virtual void setMetersPerPixel(const ossimDpt &gsd)
const ossimDatum * datum() const
datum().
Definition: ossimGpt.h:196
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
RTTI_DEF1(ossimOrthoImageMosaic, "ossimOrthoImageMosaic", ossimImageMosaic)
virtual void initialize()
std::vector< ossimRefPtr< ossimConnectableObject > > ConnectableObjectList
double lat
Definition: ossimDpt.h:165
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
yy_size_t size
virtual void setUlEastingNorthing(const ossimDpt &ulEastingNorthing)
ossimIrect getRelativeRect(ossim_uint32 index, ossim_uint32 resLevel=0) const
virtual ossimGpt origin() const
unsigned int ossim_uint32
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
bool hasNans() const
Definition: ossimDpt.h:67
double lon
Definition: ossimDpt.h:164
virtual const ossimGpt & getUlGpt() const
virtual ossim_uint32 getNumberOfOverlappingImages(const ossimIrect &rect, ossim_uint32 resLevel=0) const
Used to retrieve the number of overlapping images withint the given rect.
void updateGeometry()
If this object is maintaining an ossimImageGeometry, this method needs to be called after each time t...
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
virtual void setOrigin(const ossimIpt &origin)
return status
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
ossimDpt m_UpperLeftTie
Will hold the upper left tie of the mosaic.
#define max(a, b)
Definition: auxiliary.h:76
ossim_int32 y
Definition: ossimIpt.h:142
void makeNan()
Definition: ossimIrect.h:329
virtual ossim_uint32 getNumberOfInputs() const
Returns the number of input objects.
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 &returnedIdx, const ossimIrect &origin, ossim_uint32 resLevel=0)
double x
Definition: ossimDpt.h:164
bool hasNans() const
Definition: ossimIrect.h:337
ossim_int32 x
Definition: ossimIpt.h:141
virtual const ossimDpt & getUlEastingNorthing() const
ossimDataObjectStatus
Definitions for data object status.
ossimRefPtr< ossimImageGeometry > m_Geometry
The input image geometry, altered by the map tiepoint.
virtual ossimDpt getMetersPerPixel() const
ossimIrect combine(const ossimIrect &rect) const
Definition: ossimIrect.cpp:543
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void makeNan()
Definition: ossimDpt.h:65
#define min(a, b)
Definition: auxiliary.h:75
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)