1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/*
* $Revision: 2523 $
*
* last checkin:
* $Author: gutwenger $
* $Date: 2012-07-02 20:59:27 +0200 (Mon, 02 Jul 2012) $
***************************************************************/
/** \file
* \brief Declaration of class NearestRectangleFinder
*
* \author Carsten Gutwenger
*
* \par License:
* This file is part of the Open Graph Drawing Framework (OGDF).
*
* \par
* Copyright (C)<br>
* See README.txt in the root directory of the OGDF installation for details.
*
* \par
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* Version 2 or 3 as published by the Free Software Foundation;
* see the file LICENSE.txt included in the packaging of this file
* for details.
*
* \par
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* \par
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* \see http://www.gnu.org/copyleft/gpl.html
***************************************************************/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef OGDF_NEAREST_RECTANGLE_FINDER_H
#define OGDF_NEAREST_RECTANGLE_FINDER_H
#include <ogdf/basic/Array.h>
#include <ogdf/basic/geometry.h>
namespace ogdf {
//---------------------------------------------------------
// NearestRectangleFinder
// finds in a given set of rectangles for each point in a given
// set of points the nearest rectangle
//---------------------------------------------------------
class OGDF_EXPORT NearestRectangleFinder
{
public:
struct RectRegion;
struct PairRectDist;
struct PairCoordId;
NearestRectangleFinder(double mad = 20, double td = 5) {
m_maxAllowedDistance = mad;
m_toleranceDistance = td;
}
// the maximal allowed distance between a rectangle and a point
// rectangles with a greater distance are not considered
void maxAllowedDistance(double mad) { m_maxAllowedDistance = mad; }
double maxAllowedDistance() const { return m_maxAllowedDistance; }
// the tolerance in which rectangles are considered to be ambigous, i.e.
// if the rectangle with the minimum distance to point p has distance mindist
// and there is another rectangle with distance dist such that
// dist <= minDist + toleranceDistance, we say that the closest rectangle is not unique.
void toleranceDistance(double td) { m_toleranceDistance = td; }
double toleranceDistance() const { return m_toleranceDistance; }
// finds the nearest rectangles for a given set of points
// The nearest rectangles are passed in a list. If the list is empty, there
// is no rectangle within the ,aximal allowed distance. If the list contains
// more than one element, the nearest rectangle is not unique for the
// given tolerance.
void find(
const Array<RectRegion> ®ion, // given rectangles
const Array<DPoint> &point, // given points
Array<List<PairRectDist> > &nearest); // nearest rectangles
// trivial implementation of find(). Can be used in order to check
// correctness. Computes only rectangle with minimum distance without
// considering maxAllowedDistance and toleranceDistance.
void findSimple(
const Array<RectRegion> ®ion,
const Array<DPoint> &point,
Array<List<PairRectDist> > &nearest);
private:
class CoordComparer;
class YCoordComparer;
double m_maxAllowedDistance;
double m_toleranceDistance;
};
//---------------------------------------------------------
// RectRegion
// represents a rectangle given by center point, width and height
//---------------------------------------------------------
struct NearestRectangleFinder::RectRegion
{
friend ostream &operator<<(ostream &os, const RectRegion &rect) {
os << "(" << rect.m_x << "," << rect.m_y << ":" <<
rect.m_width << "," << rect.m_height << ")";
return os;
}
double m_x, m_y, m_width, m_height;
};
//---------------------------------------------------------
// PairRectDist
// represents a rectangle (given by its index) and a
// distance value
//---------------------------------------------------------
struct OGDF_EXPORT NearestRectangleFinder::PairRectDist
{
PairRectDist() { }
PairRectDist(int index, double distance) {
m_index = index;
m_distance = distance;
}
friend ostream &operator<<(ostream &os, const PairRectDist &p) {
os << "(" << p.m_index << "," << p.m_distance << ")";
return os;
}
int m_index;
double m_distance;
};
} // end namespace ogdf
#endif
|