gmsh-TingyuanDoc
0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
discreteFrechetDistance.cpp
Go to the documentation of this file.
1
// Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2
//
3
// See the LICENSE.txt file in the Gmsh root directory for license information.
4
// Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5
6
#include <algorithm>
7
#include "
discreteFrechetDistance.h
"
8
#include "
fullMatrix.h
"
9
10
static
double
distance
(
const
SPoint3
&p1,
const
SPoint3
&p2)
11
{
12
return
p1.
distance
(p2);
13
}
14
15
static
double
c
(
int
i,
int
j,
fullMatrix<double>
&CA,
16
const
std::vector<SPoint3> &
P
,
const
std::vector<SPoint3> &Q)
17
{
18
double
CAij;
19
if
(CA(i, j) > -1) { CAij = CA(i, j); }
20
else
if
(i == 0 && j == 0) {
21
CA(i, j) =
distance
(
P
[0], Q[0]);
// update the CA permanent
22
CAij = CA(i, j);
// set the current relevant value
23
}
24
else
if
(i > 0 && j == 0) {
25
CA(i, j) = std::max(
c
(i - 1, 0, CA,
P
, Q),
distance
(
P
[i], Q[1]));
26
CAij = CA(i, j);
27
}
28
else
if
(i == 0 && j > 0) {
29
CA(i, j) = std::max(
c
(0, j - 1, CA,
P
, Q),
distance
(
P
[0], Q[j]));
30
CAij = CA(i, j);
31
}
32
else
if
(i > 0 && j > 0) {
33
double
temp =
34
std::min(std::min(
c
(i - 1, j, CA,
P
, Q),
c
(i - 1, j - 1, CA,
P
, Q)),
35
c
(i, j - 1, CA,
P
, Q));
36
CA(i, j) = std::max(temp,
distance
(
P
[i], Q[j]));
37
CAij = CA(i, j);
38
}
39
else
{
40
CA(i, j) = 1.e22;
41
CAij = CA(i, j);
42
}
43
return
CAij;
44
}
45
46
double
discreteFrechetDistance
(
const
std::vector<SPoint3> &
P
,
47
const
std::vector<SPoint3> &Q)
48
{
49
const
int
sP =
P
.size();
50
const
int
sQ = Q.size();
51
fullMatrix<double>
CA(sP, sQ);
52
CA.
setAll
(-1.0);
53
double
cm =
c
(sP - 1, sQ - 1, CA,
P
, Q);
54
return
cm;
55
}
distance
static double distance(const SPoint3 &p1, const SPoint3 &p2)
Definition:
discreteFrechetDistance.cpp:10
c
static double c(int i, int j, fullMatrix< double > &CA, const std::vector< SPoint3 > &P, const std::vector< SPoint3 > &Q)
Definition:
discreteFrechetDistance.cpp:15
fullMatrix::setAll
void setAll(const scalar &m)
Definition:
fullMatrix.h:422
SPoint3
Definition:
SPoint3.h:14
fullMatrix< double >
SPoint3::P
double P[3]
Definition:
SPoint3.h:16
SPoint3::distance
double distance(const SPoint3 &p) const
Definition:
SPoint3.h:176
discreteFrechetDistance.h
discreteFrechetDistance
double discreteFrechetDistance(const std::vector< SPoint3 > &P, const std::vector< SPoint3 > &Q)
Definition:
discreteFrechetDistance.cpp:46
fullMatrix.h
src
numeric
discreteFrechetDistance.cpp
Generated by
1.8.18