OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
ATP::AtpGenerator Class Reference

Base class for OSSIM-based ATP generators. More...

#include <AtpGenerator.h>

Inheritance diagram for ATP::AtpGenerator:

Public Types

enum  Algorithm { ALGO_UNASSIGNED =0, CROSSCORR, DESCRIPTOR, NASA }
 

Public Member Functions

 AtpGenerator (Algorithm algo)
 
virtual ~AtpGenerator ()
 
void setRefImage (std::shared_ptr< ossim::Image > ref_image)
 
void setCmpImage (std::shared_ptr< ossim::Image > cmp_image)
 
virtual void initialize ()
 Needs to be called after ref and cmp images are set. More...
 
void setBandWeights (const std::vector< double > weights)
 When the input images are multiband, the bands must be combined into a single-band image. More...
 
virtual bool generateTiePointList (ossim::TiePointList &tpList)
 This is the main workhorse method. More...
 
ossimRefPtr< ossimImageViewProjectionTransformgetRefIVT ()
 
ossimRefPtr< ossimImageViewProjectionTransformgetCmpIVT ()
 
ossimRefPtr< ossimImageChaingetRefChain ()
 
ossimRefPtr< ossimImageChaingetCmpChain ()
 
std::string getRefImageID ()
 
std::string getCmpImageID ()
 
std::string getRefFilename ()
 
std::string getCmpFilename ()
 
ossimRefPtr< AtpTileSourcegetAtpTileSource ()
 

Static Public Member Functions

static void writeTiePointList (ostream &out, const AtpList &tpList)
 For engineering use. More...
 

Public Attributes

ossimRefPtr< AtpAnnotatedImagem_annotatedRefImage
 
ossimRefPtr< AtpAnnotatedImagem_annotatedCmpImage
 

Protected Member Functions

 AtpGenerator ()
 
virtual ossimRefPtr< ossimImageChainconstructChain (std::shared_ptr< ossim::Image > image, ossimRefPtr< ossimImageViewProjectionTransform > &ivt)
 Constructs the processing chain for the input image according to the needs of the generator. More...
 
bool getValidVertices (ossimRefPtr< ossimImageChain > chain, ossimRefPtr< ossimImageViewProjectionTransform > &ivt, std::vector< ossimDpt > &validVertices)
 Establishes valid image vertices in view space for later computing overlap. More...
 
void layoutSearchTileRects (ossimPolygon &overlapPoly)
 Finds optimum layout of patches within the intersect area for feature search. More...
 
ossimImageHandlergetImageHandler (ossimRefPtr< ossimImageChain > &chain)
 

Protected Attributes

Algorithm m_algorithm
 
std::shared_ptr< ossim::Imagem_refImage
 
std::shared_ptr< ossim::Imagem_cmpImage
 
ossimRefPtr< AtpTileSourcem_atpTileSource
 
ossimRefPtr< ossimImageChainm_refChain
 
ossimRefPtr< ossimImageChainm_cmpChain
 
ossimRefPtr< ossimImageViewProjectionTransformm_refIVT
 
ossimRefPtr< ossimImageViewProjectionTransformm_cmpIVT
 
ossimRefPtr< ossimImageGeometrym_viewGeom
 
ossimIrect m_aoiView
 
std::vector< double > m_bandWeights
 
double m_refEllipHgt
 
std::vector< ossimIrectm_searchTileRects
 

Static Protected Attributes

static std::shared_ptr< AutoTiePoints_referenceATP
 

Friends

class AtpTileSource
 

Detailed Description

Base class for OSSIM-based ATP generators.

TODO: Currently, ATP generation only works with pair-wise matching. Eventually it should support N-way matching with an arbitrary number of input images. The multiple image case is presently handled by the AutoTiePointService.

Definition at line 33 of file AtpGenerator.h.

Member Enumeration Documentation

◆ Algorithm

Enumerator
ALGO_UNASSIGNED 
CROSSCORR 
DESCRIPTOR 
NASA 

Definition at line 38 of file AtpGenerator.h.

Constructor & Destructor Documentation

◆ AtpGenerator() [1/2]

ATP::AtpGenerator::AtpGenerator ( Algorithm  algo)

Definition at line 39 of file AtpGenerator.cpp.

40 : m_algorithm (algo),
41  m_refEllipHgt(0)
42 {
43 }
Algorithm m_algorithm
Definition: AtpGenerator.h:116

◆ ~AtpGenerator()

ATP::AtpGenerator::~AtpGenerator ( )
virtual

Definition at line 46 of file AtpGenerator.cpp.

47 {
48 }

◆ AtpGenerator() [2/2]

ATP::AtpGenerator::AtpGenerator ( )
inlineprotected

Member Function Documentation

◆ constructChain()

ossimRefPtr< ossimImageChain > ATP::AtpGenerator::constructChain ( std::shared_ptr< ossim::Image image,
ossimRefPtr< ossimImageViewProjectionTransform > &  ivt 
)
protectedvirtual

Constructs the processing chain for the input image according to the needs of the generator.

As a convenience, the image-to-common view IVT is initialized

Definition at line 211 of file AtpGenerator.cpp.

References ossimImageChain::add(), ossim::JsonParam::asBool(), ossim::JsonParam::asFloat(), ossim::JsonParam::asString(), ossimImageHandler::buildHistogram(), CINFO, CROSSCORR, ossim::JsonConfig::diagnosticLevel(), ossimString::empty(), ossimRefPtr< T >::get(), ossimImageGeometry::getAsMapProjection(), ossimImageGeometry::getBoundingRect(), ossimImageHandler::getImageGeometry(), ossimImageHandler::getImageHistogram(), ossimImageHandler::getImageID(), ossimImageGeometry::getMetersPerPixel(), ossimImageSource::getNumberOfOutputBands(), ossimImageChain::getOutputScalarType(), ossim::JsonConfig::getParameter(), ossimImageGeometry::getTiePoint(), ossimImageViewProjectionTransform::imageToView(), ATP::AtpConfig::instance(), ossimImageHandlerRegistry::instance(), ossim::isnan(), ossimHistogramRemapper::LINEAR_AUTO_MIN_MAX, m_algorithm, m_viewGeom, ossimImageHandlerRegistry::open(), OSSIM_UINT8, ossimImageHandler::setCurrentEntry(), ossimHistogramRemapper::setHistogram(), ossimImageHandler::setImageID(), ossimImageRenderer::setImageViewTransform(), ossimMapProjection::setMetersPerPixel(), ossimUtmProjection::setOrigin(), ossimBandSelector::setOutputBandList(), ossimScalarRemapper::setOutputScalarType(), ossimImageRenderer::setProperty(), ossimHistogramRemapper::setStretchMode(), ossimMapProjection::setUlTiePoints(), ossimImageViewProjectionTransform::viewToImage(), ossimDpt::x, and ossimDpt::y.

Referenced by initialize().

213 {
214  static const char *MODULE = "AtpGenerator::constructChain() ";
215  AtpConfig &config = AtpConfig::instance();
216 
218  ossimRefPtr<ossimImageHandler> handler = factory->open(image->getFilename());
219  if (!handler)
220  return NULL;
221  handler->setCurrentEntry(image->getEntryIndex());
222 
223  // Check if an imageID was provided in job JSON. otherwise, check if image handler can get it:
224  ossimString imageId = image->getImageId();
225  if (imageId.empty())
226  {
227  imageId = handler->getImageID();
228  if (imageId.empty())
229  imageId = image->getFilename();
230  }
231  handler->setImageID(imageId);
232  image->setImageId(imageId);
233 
234  if (config.diagnosticLevel(5))
235  {
236  ossimIrect vuRect;
237  handler->getImageGeometry()->getBoundingRect(vuRect);
238  CINFO << MODULE << "m_aoiView: " << vuRect << endl;;
239  }
240 
242  chain->add(handler.get());
243 
244  // Add histogram (experimental)
245  bool doHistogramStretch = config.getParameter("doHistogramStretch").asBool();
246  if (doHistogramStretch)
247  {
249  chain->add(histo_remapper.get());
252  if (!histogram)
253  {
254  handler->buildHistogram();
255  histogram = handler->getImageHistogram();
256  }
257  histo_remapper->setHistogram(histogram);
258 
259  // Need to select a band if multispectral:
260  unsigned int numBands = handler->getNumberOfOutputBands();
261  if (numBands > 1)
262  {
263  unsigned int band = image->getActiveBand();
264  if ((band > numBands) || (band <= 0))
265  {
266  CINFO << MODULE << "Specified band (" << band << ") is outside allowed range (1 to "
267  << numBands
268  << "). Using default band 1 which may not be ideal." << endl;
269  band = 1;
270  }
271  band--; // shift to zero-based
273  chain->add(band_selector.get());
274  vector<ossim_uint32> bandList;
275  bandList.push_back(band);
276  band_selector->setOutputBandList(bandList);
277  }
278  }
279 
280  // Can only work in 8-bit radiometry:
281  if (chain->getOutputScalarType() != OSSIM_UINT8)
282  {
284  chain->add(remapper.get());
285  remapper->setOutputScalarType(OSSIM_UINT8);
286  }
287 
288  // Finally, add a cache to the input chain:
290  chain->add(cache.get());
291 
292  // Check for specified GSD in config parameters (experimental):
293  double viewGsd = config.getParameter("viewGSD").asFloat();
294 
295  // Set up a common view geometry, even if derived class works exclusively in image space.
296  ossimRefPtr<ossimImageGeometry> image_geom = handler->getImageGeometry();
297  if (!m_viewGeom)
298  {
299  ossimDpt gsd;
300  if (!ossim::isnan(viewGsd) && (viewGsd != 0.0))
301  gsd = ossimDpt(viewGsd, viewGsd);
302  else
303  {
304  gsd = image_geom->getMetersPerPixel();
305  if (gsd.x > gsd.y)
306  gsd.y = gsd.x;
307  else
308  gsd.x = gsd.y;
309  }
310  ossimGpt proj_origin;
311  image_geom->getTiePoint(proj_origin, false);
313  proj->setOrigin(proj_origin);
314  proj->setMetersPerPixel(gsd);
315  proj->setUlTiePoints(proj_origin);
316  m_viewGeom = new ossimImageGeometry(NULL, proj);
317  }
318  else
319  {
320  // View geometry was already set up by first image of the pair (REF). Only need to check the
321  // GSD of the CMP image and adjust the view GSD to match if larger:
322  ossimDpt cmpGsd(image_geom->getMetersPerPixel());
323  if (cmpGsd.x > cmpGsd.y)
324  cmpGsd.y = cmpGsd.x;
325  else
326  cmpGsd.x = cmpGsd.y;
328  if (cmpGsd.x > refGsd.x)
329  {
330  refGsd.x = cmpGsd.x;
331  refGsd.y = cmpGsd.y;
333  }
334  }
335 
336  ivt = new ossimImageViewProjectionTransform(image_geom.get(), m_viewGeom.get());
337 
338  if (m_algorithm == CROSSCORR)
339  {
340  // Need to add a renderer since correlations are done in view-space:
341  ossimImageRenderer* renderer = new ossimImageRenderer;
342  chain->add(renderer);
343  renderer->setImageViewTransform(ivt.get());
344 
345  // Set the appropriate resampling filter for ATP. TODO: Need experimentation.
346  ossimString filterType = AtpConfig::instance().getParameter("resamplingMethod").asString();
347  if (filterType.empty())
348  filterType = "bilinear";
349  ossimRefPtr<ossimProperty> p = new ossimStringProperty("filter_type", filterType);
350  renderer->setProperty(p);
351 
352  // Add cache after resampler:
354  chain->add(cache.get());
355 
357  {
358  ossimDpt imagePt(1,1);
359  ossimDpt viewPt, rtIpt;
360  ivt->imageToView(imagePt, viewPt);
361  ivt->viewToImage(viewPt, rtIpt);
362  CINFO<<MODULE<<"\n imagePt: "<<imagePt<<
363  "\n viewPt: "<<viewPt<<"\n rtIpt: "<<rtIpt<<endl;
364  }
365 
366  }
367  return chain;
368 }
JsonParam & getParameter(const char *paramName)
Returns a parameter (might be a null parameter if paramName not found in the configuration.
Definition: JsonConfig.cpp:377
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual void imageToView(const ossimDpt &imagePoint, ossimDpt &viewPoint) const
Workhorse of the object. Converts image-space to view-space.
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
const ossimMapProjection * getAsMapProjection() const
void getBoundingRect(ossimIrect &bounding_rect) const
Get the bounding rect of (0, 0) to (imageSize.x-1, imageSize.y-1).
double y
Definition: ossimDpt.h:165
virtual void setOrigin(const ossimGpt &origin)
This will set the utm zone and utm origin base on origin passed in.
virtual void viewToImage(const ossimDpt &viewPoint, ossimDpt &imagePoint) const
Other workhorse of the object. Converts view-space to image-space.
void setImageViewTransform(ossimImageViewTransform *transform)
ossimRefPtr< ossimMultiResLevelHistogram > getImageHistogram() const
Fetches the current entry image&#39;s histogram.
virtual void setMetersPerPixel(const ossimDpt &gsd)
virtual ossimScalarType getOutputScalarType() const
This call is passed to the head of the list.
void setStretchMode(StretchMode mode, bool rebuildTableFlag=false)
Sets remap mode to mode.
std::string asString() const
Definition: JsonConfig.cpp:285
ossimImageHandlerRegistry supports the new state cache.
virtual void setOutputScalarType(ossimScalarType scalarType)
Sets the output scalar type.
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if non defined...
ossimDpt getMetersPerPixel() const
Returns the GSD associated with this image in the active projection.
Cache Tile Source.
virtual bool add(ossimConnectableObject *source)
Will return true or false if an image source was added to the chain.
bool diagnosticLevel(unsigned int level) const
Convenience method returns TRUE if the currently set diagnostic level is <= level.
Definition: JsonConfig.cpp:461
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
void getTiePoint(ossimGpt &tie, bool edge) const
Get the latitude, longitude of the tie point.
ossimRefPtr< ossimImageGeometry > m_viewGeom
Definition: AtpGenerator.h:124
virtual void setOutputBandList(const vector< ossim_uint32 > &outputBandList, bool disablePassThru=false)
Sets the output band list.
double x
Definition: ossimDpt.h:164
bool empty() const
Definition: ossimString.h:411
static AtpConfig & instance()
Singleton implementation.
Definition: AtpConfig.cpp:20
void setImageID(const ossimString &id)
Sets the image ID in case it is externally generated.
virtual void setUlTiePoints(const ossimGpt &gpt)
static ossimImageHandlerRegistry * instance()
8 bit unsigned integer
Algorithm m_algorithm
Definition: AtpGenerator.h:116
virtual bool setCurrentEntry(ossim_uint32 entryIdx)
void setHistogram(ossimRefPtr< ossimMultiResLevelHistogram > histogram)
Sets the histogram.
#define CINFO
const ossimString & getImageID() const
Fetches the image ID.
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91
virtual bool buildHistogram(int numberOfRLevels=0, ossimHistogramMode mode=OSSIM_HISTO_MODE_NORMAL)
Build a histogram for image file.

◆ generateTiePointList()

bool ATP::AtpGenerator::generateTiePointList ( ossim::TiePointList tpList)
virtual

This is the main workhorse method.

It launches the auto-tie-point generation process given the REF and CMP images. TODO: Currently, ATP generation only works with pair-wise matching. Eventually it should support N-way matching with an arbitrary number of input images.

Definition at line 450 of file AtpGenerator.cpp.

References CINFO, ossim::JsonConfig::diagnosticLevel(), initialize(), ATP::AtpConfig::instance(), m_annotatedCmpImage, m_annotatedRefImage, m_atpTileSource, m_cmpChain, m_refChain, and m_searchTileRects.

451 {
452  const char* MODULE = "AtpGenerator::generateTiePointList() ";
453  initialize();
454 
456  return false;
457 
458  AtpConfig& config = AtpConfig::instance();
459 
460  // Need to search for features in the REF tile first, then consider only those locations
461  // for correlating. The search tiles were previously established in the base class initialization
462  ossimRefPtr<ossimImageData> ref_tile = 0;
463  ossim_uint32 tileId = 0;
464  for (auto &searchTileRect : m_searchTileRects)
465  {
466  ref_tile = m_atpTileSource->getTile(searchTileRect);
467 
468  AtpList &tileATPs = m_atpTileSource->getTiePoints();
469  if (tileATPs.empty() && config.diagnosticLevel(1))
470  {
471  CINFO << "\n" << MODULE << "No TPs found in tile." << endl;
472  ++tileId;
473  continue;
474  }
475 
476  // Add remaining tile ATPs to master ATP list:
477  if (!tileATPs.empty())
478  atpList.insert(atpList.end(), tileATPs.begin(), tileATPs.end());
479 
480  ++tileId;
481  }
482 
483  if (config.diagnosticLevel(1))
484  CINFO<<"\n"<<MODULE<<"Total number of TPs found in pair = "<<atpList.size()<<endl;
485 
486  if (config.diagnosticLevel(3))
487  {
488  m_annotatedRefImage->write();
489  if (config.diagnosticLevel(4))
490  m_annotatedCmpImage->write();
491  }
492  return true;
493 }
virtual void initialize()
Needs to be called after ref and cmp images are set.
std::vector< std::shared_ptr< AutoTiePoint > > AtpList
Definition: AutoTiePoint.h:137
ossimRefPtr< ossimImageChain > m_refChain
Definition: AtpGenerator.h:120
ossimRefPtr< ossimImageChain > m_cmpChain
Definition: AtpGenerator.h:121
ossimRefPtr< AtpAnnotatedImage > m_annotatedCmpImage
Definition: AtpGenerator.h:92
ossimRefPtr< AtpTileSource > m_atpTileSource
Definition: AtpGenerator.h:119
unsigned int ossim_uint32
ossimRefPtr< AtpAnnotatedImage > m_annotatedRefImage
Definition: AtpGenerator.h:91
static AtpConfig & instance()
Singleton implementation.
Definition: AtpConfig.cpp:20
#define CINFO
std::vector< ossimIrect > m_searchTileRects
Definition: AtpGenerator.h:128

◆ getAtpTileSource()

ossimRefPtr<AtpTileSource> ATP::AtpGenerator::getAtpTileSource ( )
inline

Definition at line 90 of file AtpGenerator.h.

References m_atpTileSource.

90 { return m_atpTileSource; } // For engineering use
ossimRefPtr< AtpTileSource > m_atpTileSource
Definition: AtpGenerator.h:119

◆ getCmpChain()

ossimRefPtr<ossimImageChain> ATP::AtpGenerator::getCmpChain ( )
inline

Definition at line 83 of file AtpGenerator.h.

References m_cmpChain.

83 { return m_cmpChain; }
ossimRefPtr< ossimImageChain > m_cmpChain
Definition: AtpGenerator.h:121

◆ getCmpFilename()

string ATP::AtpGenerator::getCmpFilename ( )

Definition at line 87 of file AtpGenerator.cpp.

References ossimImageHandler::getFilename(), getImageHandler(), m_cmpChain, and ossimString::string().

88 {
90  if (!handler)
91  return "";
92  return handler->getFilename().string();
93 }
ossimRefPtr< ossimImageChain > m_cmpChain
Definition: AtpGenerator.h:121
virtual const ossimFilename & getFilename() const
Returns the filename.
This class defines an abstract Handler which all image handlers(loaders) should derive from...
ossimImageHandler * getImageHandler(ossimRefPtr< ossimImageChain > &chain)
const std::string & string() const
Definition: ossimString.h:414

◆ getCmpImageID()

string ATP::AtpGenerator::getCmpImageID ( )

Definition at line 71 of file AtpGenerator.cpp.

References getImageHandler(), ossimImageHandler::getImageID(), m_cmpChain, and ossimString::string().

72 {
74  if (!handler)
75  return "";
76  return handler->getImageID().string();
77 }
ossimRefPtr< ossimImageChain > m_cmpChain
Definition: AtpGenerator.h:121
This class defines an abstract Handler which all image handlers(loaders) should derive from...
ossimImageHandler * getImageHandler(ossimRefPtr< ossimImageChain > &chain)
const ossimString & getImageID() const
Fetches the image ID.
const std::string & string() const
Definition: ossimString.h:414

◆ getCmpIVT()

ossimRefPtr<ossimImageViewProjectionTransform> ATP::AtpGenerator::getCmpIVT ( )
inline

Definition at line 81 of file AtpGenerator.h.

References m_cmpIVT.

81 { return m_cmpIVT; }
ossimRefPtr< ossimImageViewProjectionTransform > m_cmpIVT
Definition: AtpGenerator.h:123

◆ getImageHandler()

ossimImageHandler * ATP::AtpGenerator::getImageHandler ( ossimRefPtr< ossimImageChain > &  chain)
protected

Definition at line 95 of file AtpGenerator.cpp.

References ossimImageChain::accept(), and ossimCollectionVisitor::getObjectAs().

Referenced by getCmpFilename(), getCmpImageID(), getRefFilename(), and getRefImageID().

96 {
97  if (!chain)
98  return 0;
99 
100  ossimTypeNameVisitor visitor ("ossimImageHandler");
101  chain->accept(visitor);
102  ossimImageHandler* handler = (ossimImageHandler*) visitor.getObjectAs<ossimImageHandler>();
103 
104  return handler;
105 }
virtual void accept(ossimVisitor &visitor)
We will add a visitor interface for all connectable objects.
This class defines an abstract Handler which all image handlers(loaders) should derive from...

◆ getRefChain()

ossimRefPtr<ossimImageChain> ATP::AtpGenerator::getRefChain ( )
inline

Definition at line 82 of file AtpGenerator.h.

References m_refChain.

82 { return m_refChain; }
ossimRefPtr< ossimImageChain > m_refChain
Definition: AtpGenerator.h:120

◆ getRefFilename()

string ATP::AtpGenerator::getRefFilename ( )

Definition at line 79 of file AtpGenerator.cpp.

References ossimImageHandler::getFilename(), getImageHandler(), m_refChain, and ossimString::string().

80 {
82  if (!handler)
83  return "";
84  return handler->getFilename().string();
85 }
ossimRefPtr< ossimImageChain > m_refChain
Definition: AtpGenerator.h:120
virtual const ossimFilename & getFilename() const
Returns the filename.
This class defines an abstract Handler which all image handlers(loaders) should derive from...
ossimImageHandler * getImageHandler(ossimRefPtr< ossimImageChain > &chain)
const std::string & string() const
Definition: ossimString.h:414

◆ getRefImageID()

string ATP::AtpGenerator::getRefImageID ( )

Definition at line 63 of file AtpGenerator.cpp.

References getImageHandler(), ossimImageHandler::getImageID(), m_refChain, and ossimString::string().

64 {
66  if (!handler)
67  return "";
68  return handler->getImageID().string();
69 }
ossimRefPtr< ossimImageChain > m_refChain
Definition: AtpGenerator.h:120
This class defines an abstract Handler which all image handlers(loaders) should derive from...
ossimImageHandler * getImageHandler(ossimRefPtr< ossimImageChain > &chain)
const ossimString & getImageID() const
Fetches the image ID.
const std::string & string() const
Definition: ossimString.h:414

◆ getRefIVT()

ossimRefPtr<ossimImageViewProjectionTransform> ATP::AtpGenerator::getRefIVT ( )
inline

Definition at line 80 of file AtpGenerator.h.

References m_refIVT.

80 { return m_refIVT; }
ossimRefPtr< ossimImageViewProjectionTransform > m_refIVT
Definition: AtpGenerator.h:122

◆ getValidVertices()

bool ATP::AtpGenerator::getValidVertices ( ossimRefPtr< ossimImageChain chain,
ossimRefPtr< ossimImageViewProjectionTransform > &  ivt,
std::vector< ossimDpt > &  validVertices 
)
protected

Establishes valid image vertices in view space for later computing overlap.

Definition at line 370 of file AtpGenerator.cpp.

References ossimImageHandler::createDefaultValidVerticesFilename(), ossimImageHandler::getBoundingRect(), ossimImageHandler::getImageGeometry(), ossimImageChain::getLastSource(), ossimImageGeometry::getProjection(), ossimImageHandler::getValidImageVertices(), ossimImageViewProjectionTransform::imageToView(), and ossimImageHandler::openValidVertices().

Referenced by initialize().

373 {
374  validVertices.clear();
375 
376  // Need to establish the valid image vertices for establishing overlap polygon. Compute in
377  // image space then transform the vertices to view space:
378  if (!chain)
379  return false;
380  ossimImageHandler *handler = dynamic_cast<ossimImageHandler *>(chain->getLastSource());
381  if (!handler)
382  return false;
383 
384  // Check if there is already a vertices file alongside the image:
385  if (handler->openValidVertices())
386  {
387  vector<ossimIpt> iverts;
388  handler->getValidImageVertices(iverts);
389  for (const auto &vert : iverts)
390  validVertices.emplace_back(vert);
391  }
392 
393  if (validVertices.empty())
394  {
395  // If the projection is a sensor model, then assume that the four image-space coordinates are
396  // valid image coordinates.
398  if (geom)
399  {
400  if (dynamic_cast<ossimSensorModel*>(geom->getProjection()))
401  {
402  ossimIrect rect (handler->getBoundingRect());
403  validVertices.emplace_back(rect.ul());
404  validVertices.emplace_back(rect.ur());
405  validVertices.emplace_back(rect.lr());
406  validVertices.emplace_back(rect.ll());
407  }
408  }
409 
410  if (validVertices.empty())
411  {
412  ossimFilename verticesFile(handler->createDefaultValidVerticesFilename());
414  ve->setOutputName(verticesFile);
415  ve->setAreaOfInterest(handler->getBoundingRect(0));
416  ve->execute();
417  const vector<ossimIpt> &iverts = ve->getVertices();
418  for (const auto &vert : iverts)
419  validVertices.emplace_back(vert);
420  }
421  }
422 
423  // The image vertices are necessarily in image space coordinates. Need to transform to a common
424  // "view" space before determining the overlap polygon:
425  ossimDpt vpt;
426  for (auto &vertex : validVertices)
427  {
428  ivt->imageToView(vertex, vpt);
429  vertex = vpt;
430  }
431 
432  return true;
433 }
Class ossimVertexExtractor.
virtual void imageToView(const ossimDpt &imagePoint, ossimDpt &viewPoint) const
Workhorse of the object. Converts image-space to view-space.
virtual ossimImageSource * getLastSource()
Return the last source which is the one that last receives the getTile request.
virtual bool openValidVertices(const ossimFilename &vertices_file)
Opens the valid image vertices file and sets theValidImageVerticesFile variable.
virtual ossimFilename createDefaultValidVerticesFilename() const
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if non defined...
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
This class defines an abstract Handler which all image handlers(loaders) should derive from...
virtual void getValidImageVertices(vector< ossimIpt > &validVertices, ossimVertexOrdering ordering=OSSIM_CLOCKWISE_ORDER, ossim_uint32 resLevel=0) const
ordering specifies how the vertices should be arranged.
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
Returns zero-based bounding rectangle of the image.

◆ initialize()

void ATP::AtpGenerator::initialize ( )
virtual

Needs to be called after ref and cmp images are set.

Definition at line 108 of file AtpGenerator.cpp.

References ALGO_UNASSIGNED, ossim::JsonParam::asString(), ossim::JsonParam::asUint(), CFATAL, CINFO, constructChain(), CROSSCORR, DESCRIPTOR, ossim::JsonConfig::diagnosticLevel(), ossimPolyArea2d::getBoundingRect(), ossimIrect::getCenter(), ossimElevManager::getHeightAboveEllipsoid(), ossimImageChain::getImageGeometry(), ossim::JsonConfig::getParameter(), getValidVertices(), ossimPolyArea2d::getVisiblePolygons(), ossimGpt::height(), ATP::AtpConfig::instance(), ossimElevManager::instance(), layoutSearchTileRects(), ossimImageGeometry::localToWorld(), ossimIrect::lr(), m_algorithm, m_annotatedCmpImage, m_annotatedRefImage, m_aoiView, m_atpTileSource, m_cmpChain, m_cmpImage, m_cmpIVT, m_refChain, m_refEllipHgt, m_refImage, m_refIVT, m_viewGeom, NASA, s_referenceATP, ossimIrect::set_lr(), ossimIrect::set_ul(), ossimElevManager::setDefaultHeightAboveEllipsoid(), ossimImageGeometry::setImageSize(), ossimElevManager::setUseGeoidIfNullFlag(), ossimIrect::size(), ossimIrect::ul(), ossimIpt::x, and ossimIpt::y.

Referenced by generateTiePointList().

109 {
110  static const char* MODULE=" AtpGenerator::initialize() ";
111  AtpConfig &config = AtpConfig::instance();
112 
113  // Initialize the reference ATP containing the static data members used by all ATPs:
114  s_referenceATP.reset(new AutoTiePoint());
115  m_viewGeom = 0;
116 
117  // Establish image processing chains:
118  vector<ossimDpt> refVertices, cmpVertices;
121  if (!m_refChain || !m_cmpChain)
122  {
123  CFATAL<<MODULE<<"Null input chain(s)."<<endl;
124  return;
125  }
126 
127  if (config.diagnosticLevel(1))
128  {
129  CINFO<<"\n"<<MODULE<<"Initializing image pair with:"
130  <<"\n REF_ID: "<<m_refImage->getImageId()
131  <<"\n CMP_ID: "<<m_cmpImage->getImageId()<<endl;
132  }
133 
134  // Establish the actual overlap polygon and set AOI as its bounding rect:
135  getValidVertices(m_refChain, m_refIVT, refVertices);
136  getValidVertices(m_cmpChain, m_cmpIVT, cmpVertices);
137  ossimPolyArea2d refPoly (refVertices);
138  ossimPolyArea2d cmpPoly (cmpVertices);
139  ossimPolyArea2d overlapPoly (refPoly & cmpPoly);
140  vector<ossimPolygon> intersectPolys;
141  overlapPoly.getVisiblePolygons(intersectPolys);
142  if (intersectPolys.empty())
143  {
144  CINFO<<MODULE<<"No intersect polygon found."<<endl;
145  return;
146  }
147  ossimPolygon intersectPoly (intersectPolys[0]);
148 
149  ossimDrect viewDrect;
150  overlapPoly.getBoundingRect(viewDrect);
151  m_aoiView = viewDrect;
153 
154  if (config.diagnosticLevel(3))
155  {
156  ossimString basename (config.getParameter("annotatedImageBaseName").asString());
157  m_annotatedRefImage = new AtpAnnotatedImage(m_refChain, m_refIVT, m_aoiView);
158  m_annotatedRefImage->setImageName(basename+"Ref.tif");
159  m_annotatedCmpImage = new AtpAnnotatedImage(m_cmpChain, m_cmpIVT, m_aoiView);
160  m_annotatedCmpImage->setImageName(basename+"Cmp.tif");
161  }
162 
163  // Establish the feature search tile locations:
164  layoutSearchTileRects(intersectPoly);
165 
166  // Establish the nominal height above ellipsoid for MSL at this location:
168  if (!refGeom)
169  {
170  CFATAL<<MODULE<<"Null ref image geometry."<<endl;
171  return;
172  }
173  ossimDpt viewCenter;
174  ossimGpt geoCenter;
175  m_aoiView.getCenter(viewCenter);
176  refGeom->localToWorld(viewCenter, geoCenter);
178  geoCenter.height(m_refEllipHgt); // Sea level
181 
182  // Now need the algorithm-specific tile source that does the pixel pulling:
183  switch (m_algorithm)
184  {
185  case CROSSCORR:
186  m_atpTileSource = new ossimCorrelationSource(this);
187  break;
188  case DESCRIPTOR:
189  m_atpTileSource = new ossimDescriptorSource(this);
190  break;
191  case NASA:
192  case ALGO_UNASSIGNED:
193  default:
194  CFATAL<<MODULE<<"Unhandled algorithm type."<<endl;
195  return;
196  }
197 
198  // Adjust AOI for half-width of correlation window -- this really should only apply to crosscorr,
199  // but descriptors also have a sampling window (just not readily known):
200  int patch_center = (config.getParameter("corrWindowSize").asUint() + 1) / 2;
201  ossimIpt first_pos(m_aoiView.ul().x + patch_center, m_aoiView.ul().y + patch_center);
202  ossimIpt last_pos(m_aoiView.lr().x - patch_center, m_aoiView.lr().y - patch_center);
203  m_aoiView.set_ul(first_pos);
204  m_aoiView.set_lr(last_pos);
205 
206  m_atpTileSource->initialize();
207 }
bool getValidVertices(ossimRefPtr< ossimImageChain > chain, ossimRefPtr< ossimImageViewProjectionTransform > &ivt, std::vector< ossimDpt > &validVertices)
Establishes valid image vertices in view space for later computing overlap.
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
ossimIrect m_aoiView
Definition: AtpGenerator.h:125
virtual ossimRefPtr< ossimImageChain > constructChain(std::shared_ptr< ossim::Image > image, ossimRefPtr< ossimImageViewProjectionTransform > &ivt)
Constructs the processing chain for the input image according to the needs of the generator...
void setUseGeoidIfNullFlag(bool flag)
std::shared_ptr< ossim::Image > m_cmpImage
Definition: AtpGenerator.h:118
const ossimIpt & ul() const
Definition: ossimIrect.h:274
std::shared_ptr< ossim::Image > m_refImage
Definition: AtpGenerator.h:117
static ossimElevManager * instance()
METHOD: instance() Implements singelton pattern.
ossimRefPtr< ossimImageViewProjectionTransform > m_refIVT
Definition: AtpGenerator.h:122
ossimRefPtr< ossimImageChain > m_refChain
Definition: AtpGenerator.h:120
void setImageSize(const ossimIpt &size)
ossimIpt size() const
Definition: ossimIrect.h:510
void set_ul(const ossimIpt &pt)
Definition: ossimIrect.h:589
ossimRefPtr< ossimImageChain > m_cmpChain
Definition: AtpGenerator.h:121
ossimRefPtr< AtpAnnotatedImage > m_annotatedCmpImage
Definition: AtpGenerator.h:92
bool localToWorld(const ossimDpt &local_pt, ossimGpt &world_pt) const
Exposes the 3D projection from image to world coordinates.
virtual double getHeightAboveEllipsoid(const ossimGpt &gpt)
ossimRefPtr< AtpTileSource > m_atpTileSource
Definition: AtpGenerator.h:119
double height() const
Definition: ossimGpt.h:107
const ossimIpt & lr() const
Definition: ossimIrect.h:276
void set_lr(const ossimIpt &pt)
Definition: ossimIrect.h:623
void layoutSearchTileRects(ossimPolygon &overlapPoly)
Finds optimum layout of patches within the intersect area for feature search.
ossimRefPtr< AtpAnnotatedImage > m_annotatedRefImage
Definition: AtpGenerator.h:91
ossimRefPtr< ossimImageGeometry > m_viewGeom
Definition: AtpGenerator.h:124
ossim_int32 y
Definition: ossimIpt.h:142
static std::shared_ptr< AutoTiePoint > s_referenceATP
Definition: AtpGenerator.h:129
void setDefaultHeightAboveEllipsoid(double meters)
#define CFATAL
static AtpConfig & instance()
Singleton implementation.
Definition: AtpConfig.cpp:20
ossim_int32 x
Definition: ossimIpt.h:141
Algorithm m_algorithm
Definition: AtpGenerator.h:116
#define CINFO
ossimRefPtr< ossimImageViewProjectionTransform > m_cmpIVT
Definition: AtpGenerator.h:123
void getCenter(ossimDpt &center_point) const
Definition: ossimIrect.cpp:672

◆ layoutSearchTileRects()

void ATP::AtpGenerator::layoutSearchTileRects ( ossimPolygon overlapPoly)
protected

Finds optimum layout of patches within the intersect area for feature search.

Definition at line 495 of file AtpGenerator.cpp.

References ossimPolygon::area(), ossim::JsonParam::asUint(), CINFO, CWARN, ossim::JsonConfig::diagnosticLevel(), ossimPolygon::getBoundingRect(), ossimPolygon::getNumberOfVertices(), ossim::JsonConfig::getParameter(), ossimIrect::height(), ATP::AtpConfig::instance(), ossimPolygon::isRectWithin(), ossimIrect::lr(), m_annotatedRefImage, m_aoiView, m_searchTileRects, ossimPolygon::removeVertex(), ossimIrect::ul(), ossimIrect::width(), ossimIpt::x, x, ossimIpt::y, and y.

Referenced by initialize().

496 {
497  const char* MODULE = "AtpGenerator::layoutSearchTiles() ";
498  AtpConfig& config = AtpConfig::instance();
499 
500  m_searchTileRects.clear();
501 
502  // Note this seems to be specific to correlation-based matching, but should be generalized:
503  unsigned int featureSideSize = config.getParameter("corrWindowSize").asUint();
504 
505  // ### Critical value set here such that we can fit at least 1/2 the number of desired TPs:
506  unsigned int numTpsPerTile = config.getParameter("numFeaturesPerTile").asUint();
507  double min_area = numTpsPerTile*featureSideSize*featureSideSize/2.0;
508 
509  // Found issue with last vertex = first vertex. Remove last if so:
510  int lastVertex = intersectPoly.getNumberOfVertices() - 1;
511  if (lastVertex < 2)
512  {
513  CINFO<<MODULE<<"Intersect polygon num vertices is less than 3! This should never happen."<<endl;
514  return;
515  }
516  if (intersectPoly[0] == intersectPoly[lastVertex])
517  {
518  intersectPoly.removeVertex(lastVertex);
519  if (lastVertex < 3)
520  {
521  CWARN<<MODULE<<"Intersect polygon num vertices is less than 3! This should never happen."<<endl;
522  return;
523  }
524  }
525 
526  double intersectArea = fabs(intersectPoly.area());
527  if (intersectArea < min_area)
528  {
529  CINFO<<MODULE<<"Intersect area too small"<<endl;
530  return;
531  }
532 
533  if (config.diagnosticLevel(3) && m_annotatedRefImage)
534  m_annotatedRefImage->annotateOverlap(intersectPoly);
535 
536  // Prepare to layout evenly-spaced search tiles across overlap bounding rect:
537  ossimIrect aoiRect;
538  intersectPoly.getBoundingRect(aoiRect);
539  int side_length = (int) config.getParameter("featureSearchTileSize").asUint();
540  int dx, dy; // tile width and height
541  int aoiWidth = aoiRect.width();
542  int aoiHeight = aoiRect.height();
543 
544  // Determine optimal X and Y-direction space between tiles (actually between corresponding
545  // UL corners)
546  int gridSize = (int) config.getParameter("searchGridSize").asUint();
547  if (gridSize == 0)
548  {
549  // Check for overlap requirement to account for sampling kernel width:
550  int marginSize = (int) config.getParameter("featureSearchTileMargin").asUint();
551 
552  // No gridsize indicates contiguous tiles (full coverage, usually for DEM generation ATPs:
553  dx = side_length-marginSize;
554  dy = side_length-marginSize;
555  }
556  else
557  {
558  for (int nx=gridSize; nx>1; nx--)
559  {
560  dx = (int) floor(aoiWidth/nx);
561  if (dx >= side_length)
562  break;
563  }
564  for (int ny=gridSize; ny>1; ny--)
565  {
566  dy = (int) floor(aoiHeight/ny);
567  if (dy >= side_length)
568  break;
569  }
570  }
571 
572  // Create tile rects now that the intervals are known:
573  for (int y=aoiRect.ul().y; y<=aoiRect.lr().y-side_length; y+=dy)
574  {
575  for (int x=aoiRect.ul().x; x<=aoiRect.lr().x-side_length; x+=dx)
576  {
577  m_searchTileRects.push_back(ossimIrect (x, y, x+side_length-1, y+side_length-1));
578  }
579  }
580 
581  // Keep only those rects that are inside the overlap polygon. The layout was done over the
582  // overlap's bounding rect, so some may spill outside the overlap:
583  vector<ossimIrect>::iterator b = m_searchTileRects.begin();
584  while (b != m_searchTileRects.end())
585  {
586  if(!intersectPoly.isRectWithin(*b))
587  b = m_searchTileRects.erase(b);
588  else
589  b++;
590  }
591 
592  // Don't bother with less than N boxes, just make the entire intersection a search patch:
593  if (gridSize && (m_searchTileRects.size() < 4))
594  {
595  m_searchTileRects.clear();
596  m_searchTileRects.push_back(m_aoiView);
597  }
598 
599  if (config.diagnosticLevel(2))
600  {
601  for (int tileIdx=0; tileIdx<m_searchTileRects.size(); ++tileIdx)
602  CINFO<<MODULE<<"m_searchTileRects["<<tileIdx<<"] = "<<m_searchTileRects[tileIdx]<<endl;
603 
604  if (config.diagnosticLevel(3) && m_annotatedRefImage)
605  m_annotatedRefImage->annotateFeatureSearchTiles(m_searchTileRects);
606  }
607 }
ossim_uint32 x
ossimIrect m_aoiView
Definition: AtpGenerator.h:125
ossim_uint32 y
ossim_uint32 height() const
Definition: ossimIrect.h:487
const ossimIpt & ul() const
Definition: ossimIrect.h:274
const ossimIpt & lr() const
Definition: ossimIrect.h:276
ossim_uint32 width() const
Definition: ossimIrect.h:500
ossimRefPtr< AtpAnnotatedImage > m_annotatedRefImage
Definition: AtpGenerator.h:91
ossim_int32 y
Definition: ossimIpt.h:142
static AtpConfig & instance()
Singleton implementation.
Definition: AtpConfig.cpp:20
ossim_int32 x
Definition: ossimIpt.h:141
#define CWARN
#define CINFO
std::vector< ossimIrect > m_searchTileRects
Definition: AtpGenerator.h:128

◆ setBandWeights()

void ATP::AtpGenerator::setBandWeights ( const std::vector< double >  weights)
inline

When the input images are multiband, the bands must be combined into a single-band image.

Parameters
weightsVector of normalized weights (0-1) applied to the input bands for combining.

Definition at line 54 of file AtpGenerator.h.

References m_bandWeights.

54 { m_bandWeights = weights; }
std::vector< double > m_bandWeights
Definition: AtpGenerator.h:126

◆ setCmpImage()

void ATP::AtpGenerator::setCmpImage ( std::shared_ptr< ossim::Image cmp_image)

Definition at line 57 of file AtpGenerator.cpp.

References m_cmpImage.

58 {
59  m_cmpImage = cmp_image;
60 }
std::shared_ptr< ossim::Image > m_cmpImage
Definition: AtpGenerator.h:118

◆ setRefImage()

void ATP::AtpGenerator::setRefImage ( std::shared_ptr< ossim::Image ref_image)

Definition at line 51 of file AtpGenerator.cpp.

References m_refImage.

52 {
53  m_refImage = ref_image;
54 }
std::shared_ptr< ossim::Image > m_refImage
Definition: AtpGenerator.h:117

◆ writeTiePointList()

void ATP::AtpGenerator::writeTiePointList ( ostream out,
const AtpList tpList 
)
static

For engineering use.

Renders relevant tiepoint data to disk file(s). Optionally accepts an LUT file for raster-based remapping.

Parameters
outBaseNameThis is the base name of possible multiple outputs, as needed by derived generator.
lutFileOptional LUT file formatted as specified in ossimIndexToRgbLutFilter.
Returns
True if successful. For engineering use. Convenience method for outputting tiepoint list to output stream.

Definition at line 435 of file AtpGenerator.cpp.

436 {
437  if (tpList.empty())
438  {
439  out<<"\nTiepoint list is empty.\n"<<endl;
440  }
441  else
442  {
443  for (size_t i=0; i<tpList.size(); ++i)
444  {
445  out<<"\ntiepoint["<<i<<"]: "<<tpList[i]<<endl;
446  }
447  }
448 }

Friends And Related Function Documentation

◆ AtpTileSource

friend class AtpTileSource
friend

Definition at line 35 of file AtpGenerator.h.

Member Data Documentation

◆ m_algorithm

Algorithm ATP::AtpGenerator::m_algorithm
protected

Definition at line 116 of file AtpGenerator.h.

Referenced by constructChain(), and initialize().

◆ m_annotatedCmpImage

ossimRefPtr<AtpAnnotatedImage> ATP::AtpGenerator::m_annotatedCmpImage

Definition at line 92 of file AtpGenerator.h.

Referenced by generateTiePointList(), and initialize().

◆ m_annotatedRefImage

ossimRefPtr<AtpAnnotatedImage> ATP::AtpGenerator::m_annotatedRefImage

Definition at line 91 of file AtpGenerator.h.

Referenced by generateTiePointList(), initialize(), and layoutSearchTileRects().

◆ m_aoiView

ossimIrect ATP::AtpGenerator::m_aoiView
protected

Definition at line 125 of file AtpGenerator.h.

Referenced by initialize(), and layoutSearchTileRects().

◆ m_atpTileSource

ossimRefPtr<AtpTileSource> ATP::AtpGenerator::m_atpTileSource
protected

Definition at line 119 of file AtpGenerator.h.

Referenced by generateTiePointList(), getAtpTileSource(), and initialize().

◆ m_bandWeights

std::vector<double> ATP::AtpGenerator::m_bandWeights
protected

Definition at line 126 of file AtpGenerator.h.

Referenced by setBandWeights().

◆ m_cmpChain

ossimRefPtr<ossimImageChain> ATP::AtpGenerator::m_cmpChain
protected

◆ m_cmpImage

std::shared_ptr<ossim::Image> ATP::AtpGenerator::m_cmpImage
protected

Definition at line 118 of file AtpGenerator.h.

Referenced by initialize(), and setCmpImage().

◆ m_cmpIVT

ossimRefPtr<ossimImageViewProjectionTransform> ATP::AtpGenerator::m_cmpIVT
protected

Definition at line 123 of file AtpGenerator.h.

Referenced by getCmpIVT(), and initialize().

◆ m_refChain

ossimRefPtr<ossimImageChain> ATP::AtpGenerator::m_refChain
protected

◆ m_refEllipHgt

double ATP::AtpGenerator::m_refEllipHgt
protected

Definition at line 127 of file AtpGenerator.h.

Referenced by initialize().

◆ m_refImage

std::shared_ptr<ossim::Image> ATP::AtpGenerator::m_refImage
protected

Definition at line 117 of file AtpGenerator.h.

Referenced by initialize(), and setRefImage().

◆ m_refIVT

ossimRefPtr<ossimImageViewProjectionTransform> ATP::AtpGenerator::m_refIVT
protected

Definition at line 122 of file AtpGenerator.h.

Referenced by getRefIVT(), and initialize().

◆ m_searchTileRects

std::vector<ossimIrect> ATP::AtpGenerator::m_searchTileRects
protected

Definition at line 128 of file AtpGenerator.h.

Referenced by generateTiePointList(), and layoutSearchTileRects().

◆ m_viewGeom

ossimRefPtr<ossimImageGeometry> ATP::AtpGenerator::m_viewGeom
protected

Definition at line 124 of file AtpGenerator.h.

Referenced by constructChain(), and initialize().

◆ s_referenceATP

std::shared_ptr< AutoTiePoint > ATP::AtpGenerator::s_referenceATP
staticprotected

Definition at line 129 of file AtpGenerator.h.

Referenced by initialize().


The documentation for this class was generated from the following files: