DiscreteHausdorffDistance.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2009 Sandro Santilli <strk@kbt.io>
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: algorithm/distance/DiscreteHausdorffDistance.java 1.5 (JTS-1.10)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/algorithm/distance/PointPairDistance.h> // for composition
#include <geos/algorithm/distance/DistanceToPoint.h> // for composition
#include <geos/util/IllegalArgumentException.h> // for inlines
#include <geos/geom/Geometry.h> // for inlines
#include <geos/util/math.h> // for inlines
#include <geos/geom/CoordinateFilter.h> // for inheritance
#include <geos/geom/CoordinateSequenceFilter.h> // for inheritance
#include <cstddef>
#include <vector>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
#endif
namespace geos {
namespace geom {
class Geometry;
class Coordinate;
//class CoordinateSequence;
}
}
namespace geos {
namespace algorithm { // geos::algorithm
namespace distance { // geos::algorithm::distance
class GEOS_DLL DiscreteHausdorffDistance {
public:
static double distance(const geom::Geometry& g0,
const geom::Geometry& g1);
static double distance(const geom::Geometry& g0,
const geom::Geometry& g1, double densifyFrac);
DiscreteHausdorffDistance(const geom::Geometry& p_g0,
const geom::Geometry& p_g1)
:
g0(p_g0),
g1(p_g1),
ptDist(),
densifyFrac(0.0)
{}
void setDensifyFraction(double dFrac);
double
distance()
{
compute(g0, g1);
return ptDist.getDistance();
}
double
orientedDistance()
{
computeOrientedDistance(g0, g1, ptDist);
return ptDist.getDistance();
}
const std::array<geom::CoordinateXY, 2>
getCoordinates() const
{
return ptDist.getCoordinates();
}
class MaxPointDistanceFilter : public geom::CoordinateFilter {
public:
MaxPointDistanceFilter(const geom::Geometry& p_geom)
:
geom(p_geom)
{}
void
filter_ro(const geom::CoordinateXY* pt) override
{
minPtDist.initialize();
DistanceToPoint::computeDistance(geom, *pt,
minPtDist);
maxPtDist.setMaximum(minPtDist);
}
const PointPairDistance&
getMaxPointDistance() const
{
return maxPtDist;
}
private:
PointPairDistance maxPtDist;
PointPairDistance minPtDist;
DistanceToPoint euclideanDist;
const geom::Geometry& geom;
// Declare type as noncopyable
MaxPointDistanceFilter(const MaxPointDistanceFilter& other);
MaxPointDistanceFilter& operator=(const MaxPointDistanceFilter& rhs);
};
class MaxDensifiedByFractionDistanceFilter
: public geom::CoordinateSequenceFilter {
public:
MaxDensifiedByFractionDistanceFilter(
const geom::Geometry& p_geom, double fraction)
:
geom(p_geom),
// Validity of the cast to size_t has been verified in setDensifyFraction()
numSubSegs(std::size_t(util::round(1.0 / fraction)))
{
}
void filter_ro(const geom::CoordinateSequence& seq,
std::size_t index) override;
bool
isGeometryChanged() const override
{
return false;
}
bool
isDone() const override
{
return false;
}
const PointPairDistance&
getMaxPointDistance() const
{
return maxPtDist;
}
private:
PointPairDistance maxPtDist;
PointPairDistance minPtDist;
const geom::Geometry& geom;
std::size_t numSubSegs; // = 0;
// Declare type as noncopyable
MaxDensifiedByFractionDistanceFilter(const MaxDensifiedByFractionDistanceFilter& other);
MaxDensifiedByFractionDistanceFilter& operator=(const MaxDensifiedByFractionDistanceFilter& rhs);
};
private:
void
compute(const geom::Geometry& p_g0,
const geom::Geometry& p_g1)
{
computeOrientedDistance(p_g0, p_g1, ptDist);
computeOrientedDistance(p_g1, p_g0, ptDist);
}
void computeOrientedDistance(const geom::Geometry& discreteGeom,
const geom::Geometry& geom,
PointPairDistance& ptDist);
const geom::Geometry& g0;
const geom::Geometry& g1;
PointPairDistance ptDist;
double densifyFrac; // = 0.0;
// Declare type as noncopyable
DiscreteHausdorffDistance(const DiscreteHausdorffDistance& other) = delete;
DiscreteHausdorffDistance& operator=(const DiscreteHausdorffDistance& rhs) = delete;
};
} // geos::algorithm::distance
} // geos::algorithm
} // geos
#ifdef _MSC_VER
#pragma warning(pop)
#endif
geos::algorithm::distance::DiscreteHausdorffDistance::setDensifyFraction
void setDensifyFraction(double dFrac)
geos::geom::CoordinateFilter
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition CoordinateFilter.h:43
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::algorithm::distance
Classes to compute distance metrics between geometries.
Definition DiscreteFrechetDistance.h:40
geos::algorithm
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32
geos::geom
Definition Angle.h:26
geos::util::round
double round(double val)
Definition math.h:36
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38