gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
closestVertex.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 "closestVertex.h"
7 #include "GEntity.h"
8 #include "GEdge.h"
9 #include "GFace.h"
10 #include <vector>
11 
12 closestVertexFinder::closestVertexFinder(GEntity *ge, bool closure) : nbVtcs(0)
13 {
14 #if defined(HAVE_ANN)
15  std::set<MVertex *> vtcs;
16  ge->addVerticesInSet(vtcs, closure);
17  nbVtcs = vtcs.size();
18  if(nbVtcs) {
19  vertex = new MVertex *[nbVtcs];
20  index = new ANNidx[1];
21  dist = new ANNdist[1];
22  vCoord = annAllocPts(nbVtcs, 3);
23  int k = 0;
24  auto vIter = vtcs.begin();
25  for(; vIter != vtcs.end(); ++vIter, ++k) {
26  MVertex *mv = *vIter;
27  vCoord[k][0] = mv->x();
28  vCoord[k][1] = mv->y();
29  vCoord[k][2] = mv->z();
30  vertex[k] = mv;
31  }
32  kdtree = new ANNkd_tree(vCoord, nbVtcs, 3);
33  }
34 #else
36  "Gmsh must be compiled with ANN support for finding closest nodes");
37 #endif
38 }
39 
41 {
42 #if defined(HAVE_ANN)
43  if(nbVtcs) {
44  delete kdtree;
45  annDeallocPts(vCoord);
46  delete[] vertex;
47  delete[] index;
48  delete[] dist;
49  }
50 #endif
51 }
52 
54 {
55 #if defined(HAVE_ANN)
56  if(nbVtcs == 0) return nullptr;
57  double xyz[3] = {p.x(), p.y(), p.z()};
58  kdtree->annkSearch(xyz, 1, index, dist);
59  return vertex[index[0]];
60 #else
61  return nullptr;
62 #endif
63 }
64 
66  const std::vector<double> &tfo)
67 {
68 #if defined(HAVE_ANN)
69  if(nbVtcs == 0) return nullptr;
70  double ori[4] = {p.x(), p.y(), p.z(), 1};
71  double xyz[4] = {0, 0, 0, 0};
72  if(tfo.size() == 16) {
73  int idx = 0;
74  for(int i = 0; i < 4; i++)
75  for(int j = 0; j < 4; j++) xyz[i] += tfo[idx++] * ori[j];
76  }
77  else
78  std::memcpy(xyz, ori, 3 * sizeof(double));
79  kdtree->annkSearch(xyz, 1, index, dist);
80  return vertex[index[0]];
81 #else
82  return nullptr;
83 #endif
84 }
closestVertexFinder::nbVtcs
unsigned int nbVtcs
Definition: closestVertex.h:35
GFace.h
GEntity.h
MVertex
Definition: MVertex.h:24
Msg::Warning
static void Warning(const char *fmt,...)
Definition: GmshMessage.cpp:543
MVertex::z
double z() const
Definition: MVertex.h:62
SPoint3
Definition: SPoint3.h:14
GEntity
Definition: GEntity.h:31
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
GEdge.h
closestVertexFinder::closestVertexFinder
closestVertexFinder(GEntity *ge, bool includeClosure)
Definition: closestVertex.cpp:12
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
GEntity::addVerticesInSet
void addVerticesInSet(std::set< MVertex * > &, bool closure) const
Definition: GEntity.cpp:166
closestVertexFinder::~closestVertexFinder
~closestVertexFinder()
Definition: closestVertex.cpp:40
closestVertexFinder::operator()
MVertex * operator()(const SPoint3 &p)
Definition: closestVertex.cpp:53
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
MVertex::y
double y() const
Definition: MVertex.h:61
closestVertex.h
MVertex::x
double x() const
Definition: MVertex.h:60