10 #include "../AtpCommon.h" 30 using namespace ossim;
36 std::shared_ptr<AutoTiePoint> AtpGenerator::s_referenceATP;
110 static const char* MODULE=
" AtpGenerator::initialize() ";
118 vector<ossimDpt> refVertices, cmpVertices;
123 CFATAL<<MODULE<<
"Null input chain(s)."<<endl;
129 CINFO<<
"\n"<<MODULE<<
"Initializing image pair with:" 131 <<
"\n CMP_ID: "<<
m_cmpImage->getImageId()<<endl;
140 vector<ossimPolygon> intersectPolys;
142 if (intersectPolys.empty())
144 CINFO<<MODULE<<
"No intersect polygon found."<<endl;
170 CFATAL<<MODULE<<
"Null ref image geometry."<<endl;
194 CFATAL<<MODULE<<
"Unhandled algorithm type."<<endl;
214 static const char *MODULE =
"AtpGenerator::constructChain() ";
229 imageId = image->getFilename();
232 image->setImageId(imageId);
238 CINFO << MODULE <<
"m_aoiView: " << vuRect << endl;;
242 chain->
add(handler.
get());
246 if (doHistogramStretch)
249 chain->
add(histo_remapper.
get());
263 unsigned int band = image->getActiveBand();
264 if ((band > numBands) || (band <= 0))
266 CINFO << MODULE <<
"Specified band (" << band <<
") is outside allowed range (1 to " 268 <<
"). Using default band 1 which may not be ideal." << endl;
273 chain->
add(band_selector.
get());
274 vector<ossim_uint32> bandList;
275 bandList.push_back(band);
284 chain->
add(remapper.
get());
323 if (cmpGsd.x > cmpGsd.y)
328 if (cmpGsd.x > refGsd.x)
342 chain->
add(renderer);
347 if (filterType.
empty())
348 filterType =
"bilinear";
362 CINFO<<MODULE<<
"\n imagePt: "<<imagePt<<
363 "\n viewPt: "<<viewPt<<
"\n rtIpt: "<<rtIpt<<endl;
372 std::vector<ossimDpt>& validVertices)
374 validVertices.clear();
387 vector<ossimIpt> iverts;
389 for (
const auto &vert : iverts)
390 validVertices.emplace_back(vert);
393 if (validVertices.empty())
403 validVertices.emplace_back(rect.ul());
404 validVertices.emplace_back(rect.ur());
405 validVertices.emplace_back(rect.lr());
406 validVertices.emplace_back(rect.ll());
410 if (validVertices.empty())
414 ve->setOutputName(verticesFile);
417 const vector<ossimIpt> &iverts = ve->getVertices();
418 for (
const auto &vert : iverts)
419 validVertices.emplace_back(vert);
426 for (
auto &vertex : validVertices)
439 out<<
"\nTiepoint list is empty.\n"<<endl;
443 for (
size_t i=0; i<tpList.size(); ++i)
445 out<<
"\ntiepoint["<<i<<
"]: "<<tpList[i]<<endl;
452 const char* MODULE =
"AtpGenerator::generateTiePointList() ";
471 CINFO <<
"\n" << MODULE <<
"No TPs found in tile." << endl;
477 if (!tileATPs.empty())
478 atpList.insert(atpList.end(), tileATPs.begin(), tileATPs.end());
484 CINFO<<
"\n"<<MODULE<<
"Total number of TPs found in pair = "<<atpList.size()<<endl;
497 const char* MODULE =
"AtpGenerator::layoutSearchTiles() ";
507 double min_area = numTpsPerTile*featureSideSize*featureSideSize/2.0;
513 CINFO<<MODULE<<
"Intersect polygon num vertices is less than 3! This should never happen."<<endl;
516 if (intersectPoly[0] == intersectPoly[lastVertex])
521 CWARN<<MODULE<<
"Intersect polygon num vertices is less than 3! This should never happen."<<endl;
526 double intersectArea = fabs(intersectPoly.
area());
527 if (intersectArea < min_area)
529 CINFO<<MODULE<<
"Intersect area too small"<<endl;
541 int aoiWidth = aoiRect.
width();
542 int aoiHeight = aoiRect.
height();
553 dx = side_length-marginSize;
554 dy = side_length-marginSize;
558 for (
int nx=gridSize; nx>1; nx--)
560 dx = (int) floor(aoiWidth/nx);
561 if (dx >= side_length)
564 for (
int ny=gridSize; ny>1; ny--)
566 dy = (int) floor(aoiHeight/ny);
567 if (dy >= side_length)
573 for (
int y=aoiRect.
ul().
y;
y<=aoiRect.
lr().
y-side_length;
y+=dy)
575 for (
int x=aoiRect.
ul().
x;
x<=aoiRect.
lr().
x-side_length;
x+=dx)
JsonParam & getParameter(const char *paramName)
Returns a parameter (might be a null parameter if paramName not found in the configuration.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
void getBoundingRect(ossimDrect &rect)
bool getValidVertices(ossimRefPtr< ossimImageChain > chain, ossimRefPtr< ossimImageViewProjectionTransform > &ivt, std::vector< ossimDpt > &validVertices)
Establishes valid image vertices in view space for later computing overlap.
Base class for all automatic tiepoints.
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
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)
const ossimMapProjection * getAsMapProjection() const
This code was derived from https://gist.github.com/mshockwave.
void getBoundingRect(ossimIrect &bounding_rect) const
Get the bounding rect of (0, 0) to (imageSize.x-1, imageSize.y-1).
std::shared_ptr< ossim::Image > m_cmpImage
Finds auto-tie-points using the descriptor-based matching algorithm.
ossim_uint32 height() const
std::string getCmpFilename()
virtual void initialize()
Needs to be called after ref and cmp images are set.
virtual void setOrigin(const ossimGpt &origin)
This will set the utm zone and utm origin base on origin passed in.
unsigned int asUint() const
const ossimIpt & ul() const
Finds auto-tie-points using the corss-correlation-based matching algorithm.
std::shared_ptr< ossim::Image > m_refImage
bool isRectWithin(const ossimIrect &rect) const
METHOD: isRectWithin() Returns true if all the corner points of the given rect fit within...
std::vector< std::shared_ptr< AutoTiePoint > > AtpList
static ossimElevManager * instance()
METHOD: instance() Implements singelton pattern.
ossimRefPtr< ossimImageViewProjectionTransform > m_refIVT
ossimRefPtr< ossimImageChain > m_refChain
void removeVertex(int vertex)
METHOD: remove() Removes the vertex from the polygon.
virtual bool generateTiePointList(ossim::TiePointList &tpList)
This is the main workhorse method.
virtual ossimImageSource * getLastSource()
Return the last source which is the one that last receives the getTile request.
void setImageSize(const ossimIpt &size)
virtual bool openValidVertices(const ossimFilename &vertices_file)
Opens the valid image vertices file and sets theValidImageVerticesFile variable.
void setImageViewTransform(ossimImageViewTransform *transform)
ossimRefPtr< ossimMultiResLevelHistogram > getImageHistogram() const
Fetches the current entry image's histogram.
virtual void setMetersPerPixel(const ossimDpt &gsd)
virtual ossimScalarType getOutputScalarType() const
This call is passed to the head of the list.
void set_ul(const ossimIpt &pt)
virtual void accept(ossimVisitor &visitor)
We will add a visitor interface for all connectable objects.
void setStretchMode(StretchMode mode, bool rebuildTableFlag=false)
Sets remap mode to mode.
std::string asString() const
std::string getRefFilename()
ossimImageHandlerRegistry supports the new state cache.
virtual ossimFilename createDefaultValidVerticesFilename() const
ossimRefPtr< ossimImageChain > m_cmpChain
ossimRefPtr< AtpAnnotatedImage > m_annotatedCmpImage
std::vector< std::shared_ptr< TiePoint > > TiePointList
virtual void setOutputScalarType(ossimScalarType scalarType)
Sets the output scalar type.
std::string getRefImageID()
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if non defined...
virtual const ossimFilename & getFilename() const
Returns the filename.
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
unsigned int ossim_uint32
ossimDpt getMetersPerPixel() const
Returns the GSD associated with this image in the active projection.
const ossimIpt & lr() const
virtual bool add(ossimConnectableObject *source)
Will return true or false if an image source was added to the chain.
ossim_uint32 width() const
THESE FUNCTIONS REQUIRE OPENCV.
bool diagnosticLevel(unsigned int level) const
Convenience method returns TRUE if the currently set diagnostic level is <= level.
void getBoundingRect(ossimIrect &rect) const
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
ossim_uint32 getNumberOfVertices() const
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
T * getObjectAs(ossim_uint32 idx=0)
void set_lr(const ossimIpt &pt)
void getTiePoint(ossimGpt &tie, bool edge) const
Get the latitude, longitude of the tie point.
void layoutSearchTileRects(ossimPolygon &overlapPoly)
Finds optimum layout of patches within the intersect area for feature search.
This class defines an abstract Handler which all image handlers(loaders) should derive from...
ossimRefPtr< AtpAnnotatedImage > m_annotatedRefImage
ossimRefPtr< ossimImageGeometry > m_viewGeom
virtual void getValidImageVertices(vector< ossimIpt > &validVertices, ossimVertexOrdering ordering=OSSIM_CLOCKWISE_ORDER, ossim_uint32 resLevel=0) const
ordering specifies how the vertices should be arranged.
static std::shared_ptr< AutoTiePoint > s_referenceATP
void setDefaultHeightAboveEllipsoid(double meters)
double area() const
Returns polygon area. Negative indicates CW ordering of vertices (in right-handed coordinates) ...
virtual void setOutputBandList(const vector< ossim_uint32 > &outputBandList, bool disablePassThru=false)
Sets the output band list.
ossimImageHandler * getImageHandler(ossimRefPtr< ossimImageChain > &chain)
static AtpConfig & instance()
Singleton implementation.
void setImageID(const ossimString &id)
Sets the image ID in case it is externally generated.
virtual void setUlTiePoints(const ossimGpt &gpt)
static ossimImageHandlerRegistry * instance()
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
Returns zero-based bounding rectangle of the image.
For engineering use in ATP.
virtual bool setCurrentEntry(ossim_uint32 entryIdx)
void setHistogram(ossimRefPtr< ossimMultiResLevelHistogram > histogram)
Sets the histogram.
std::string getCmpImageID()
bool getVisiblePolygons(vector< ossimPolygon > &polyList) const
void setRefImage(std::shared_ptr< ossim::Image > ref_image)
const ossimString & getImageID() const
Fetches the image ID.
std::vector< ossimIrect > m_searchTileRects
ossimRefPtr< ossimImageViewProjectionTransform > m_cmpIVT
void getCenter(ossimDpt ¢er_point) const
std::basic_ostream< char > ostream
Base class for char output streams.
void setCmpImage(std::shared_ptr< ossim::Image > cmp_image)
Singleton class maintaining parameters affecting the automatic tie point generation.
static void writeTiePointList(ostream &out, const AtpList &tpList)
For engineering use.
const std::string & string() const
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
virtual bool buildHistogram(int numberOfRLevels=0, ossimHistogramMode mode=OSSIM_HISTO_MODE_NORMAL)
Build a histogram for image file.