GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmSpatialIndex.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2015 by Erwan Yann Renaut
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_SPATIAL_INDEX_H_
25#define _GEMA_SPATIAL_INDEX_H_
26
27#include "gmPluginObject.h"
28#include "gmPluginCategory.h"
29
30#include "gmVector.h"
31#include <functional>
32
33class GmMesh;
34class GmCell;
35class GmValueAccessor;
36
37
38#define GMP_MAX_INDEX_DIM 3
39
41 int cellId; //Cell Id
42 int ip; //Integration point Id
43 double ccoord[GMP_MAX_INDEX_DIM]; // Cartesian coordinates of the point
44
45 GmpMmGaussData() : cellId(-1), ip(-1)
46 {
47 memset(ccoord, 0, sizeof(double) * GMP_MAX_INDEX_DIM);
48 }
49
50 bool operator==(const GmpMmGaussData& other) const {
51 bool eq = cellId == other.cellId && ip == other.ip;
52 //If cell/ip are equal the cached coord should also be, but we dont check it
53 assert(!eq || !memcmp(ccoord, other.ccoord, sizeof(double) * GMP_MAX_INDEX_DIM));
54 return eq;
55 }
56};
57
58template<typename T>
59struct GmpRefDist {
60 T value;
61 double distance;
62};
63
66{
67public:
68 GmSpatialIndex(GmSimulationData* simulation, QString id, QString description, const GmLogCategory& logger);
69 virtual ~GmSpatialIndex();
70
71 /*
72 Extends GmSpatialIndex point search with a 'point validator',
73 which can be passed as argument to the methods.
74 It takes the coordinates of the search and query points, and
75 only include the search point if 'validator' returns true.
76 It is not assumed to be symetric!!!
77 Point are always passed in the order
78 'validator(src, dst)'
79 with 'src' being the query coordinate and 'dst' a point belonging to the spatial index.
80 */
81 using PointValidator = std::function<bool(const double*, const double*)>;
82 static bool defaultPointValidator(const double*, const double*) { return true; }
83
84 // Comments on the base class
85 virtual const char* pluginCategory() const { return GM_PLUGIN_SPATIALINDEX; }
86
97 virtual bool hasCapability(QString capabilityName) const = 0;
98
100 virtual GmMesh* mesh() const = 0;
101
102 virtual int ndim() const = 0;
103
108 virtual const GmValueAccessor* coordAccessor() const = 0;
109
111 virtual bool activeOnly() const = 0;
112
114 virtual int ruleSet() const = 0;
115
117 virtual bool isOutsideOfDomain(const GmVector& crd) const = 0;
118
120 virtual int numReferences() const = 0;
121
126 virtual bool getClosestNode(const GmVector& crd, double& sqrDist, int& outNodeId, const PointValidator& pv = defaultPointValidator) const = 0;
127
129 virtual void getClosestNodes(const GmVector& crd, int n, QVector <GmpRefDist<int>>& nodeList, bool ordered, const PointValidator& pv = defaultPointValidator) const = 0;
130
132 virtual void getClosestNodes(const GmVector& crd, double r, QVector <GmpRefDist<int>>& nodeList, bool ordered, const PointValidator& pv = defaultPointValidator) const = 0;
133
135 virtual void getClosestNodes(const GmVector& crd, int n, QVector<int>& nodeList, bool ordered, const PointValidator& pv = defaultPointValidator) const = 0;
136
138 virtual void getClosestNodes(const GmVector& crd, double r, QVector<int>& nodeList, bool ordered, const PointValidator& pv = defaultPointValidator) const = 0;
139
143 virtual GmCell* getContainingCell(const GmVector& crd) const = 0;
144
148 virtual bool getClosestGaussPoint(const GmVector& crd, double& sqrDist, GmpMmGaussData& outRef, const PointValidator& pv = defaultPointValidator) const = 0;
149
151 virtual void getClosestGaussPoints(const GmVector& crd, int n, QVector<GmpRefDist<GmpMmGaussData> >& gpList, bool ordered, const PointValidator& pv = defaultPointValidator) const = 0;
152
154 virtual void getClosestGaussPoints(const GmVector& crd, double r, QVector<GmpRefDist<GmpMmGaussData> >& gpList, bool ordered, const PointValidator& pv = defaultPointValidator) const = 0;
155
157 virtual void getClosestGaussPoints(const GmVector& crd, int n, QVector<GmpMmGaussData>& gpList, bool ordered, const PointValidator& pv = defaultPointValidator) const = 0;
158
160 virtual void getClosestGaussPoints(const GmVector& crd, double r, QVector<GmpMmGaussData>& gpList, bool ordered, const PointValidator& pv = defaultPointValidator) const = 0;
161
162 virtual void printParameters(const GmLogCategory& logger);
163};
164
165
166#endif // _GEMA_SPATIAL_INDEX_H_
Base interface for mesh cells.
Definition gmCell.h:88
Class representing a category with multiple logging levels.
Definition gmLog.h:58
Base interface class for Mesh type plugins.
Definition gmMesh.h:48
Base interface class for all object plugins.
Definition gmPluginObject.h:37
virtual void printParameters(const GmLogCategory &logger)=0
Asks the object to print all of its parameters using the provided logger.
Definition gmPluginObject.cpp:62
Auxiliar class used to store the complete set of simulation data.
Definition gmSimulationData.h:55
Base interface class for Spatial Index type plugins.
Definition gmSpatialIndex.h:66
virtual void getClosestGaussPoints(const GmVector &crd, double r, QVector< GmpMmGaussData > &gpList, bool ordered, const PointValidator &pv=defaultPointValidator) const =0
Returns the ids of the gauss points whose distance to crd are less than radius, unordered.
virtual int ruleSet() const =0
For the nearestGauss capability, returns the rule set of the indexed Gauss points....
virtual bool hasCapability(QString capabilityName) const =0
This function should return true or false to indicate whether the spatial index supports the requeste...
virtual void getClosestGaussPoints(const GmVector &crd, int n, QVector< GmpRefDist< GmpMmGaussData > > &gpList, bool ordered, const PointValidator &pv=defaultPointValidator) const =0
Returns the ids of the n closest gauss points, together with their squared distances,...
virtual bool getClosestGaussPoint(const GmVector &crd, double &sqrDist, GmpMmGaussData &outRef, const PointValidator &pv=defaultPointValidator) const =0
Returns the ids of the closest gauss point, together with its squared distance. MUST be implemented i...
virtual bool activeOnly() const =0
For the nearestGauss and containingCell capabilities, does this index considers only active cells or ...
virtual void getClosestNodes(const GmVector &crd, double r, QVector< int > &nodeList, bool ordered, const PointValidator &pv=defaultPointValidator) const =0
Returns the ids of the nodes whose distances to crd are less than radius, unordered.
virtual void getClosestNodes(const GmVector &crd, int n, QVector< int > &nodeList, bool ordered, const PointValidator &pv=defaultPointValidator) const =0
Returns the ids of the n closest nodes, unordered.
virtual GmMesh * mesh() const =0
Returns the mesh that this index is tied to.
virtual const GmValueAccessor * coordAccessor() const =0
Returns the coordinate accessor stored by the spatial index. Using this accessor ensures that queries...
virtual void getClosestGaussPoints(const GmVector &crd, double r, QVector< GmpRefDist< GmpMmGaussData > > &gpList, bool ordered, const PointValidator &pv=defaultPointValidator) const =0
Returns the ids of the gauss points whose distance to crd are less than radius, together with their s...
virtual int numReferences() const =0
Returns the number of nodes, cells or gauss points stored at the index.
virtual void getClosestGaussPoints(const GmVector &crd, int n, QVector< GmpMmGaussData > &gpList, bool ordered, const PointValidator &pv=defaultPointValidator) const =0
Returns the ids of the n closest gauss points, unordered.
virtual const char * pluginCategory() const
Returns the plugin category.
Definition gmSpatialIndex.h:85
virtual GmCell * getContainingCell(const GmVector &crd) const =0
Returns a pointer to the cell in which the given point falls in. MUST be implemented if the 'containi...
virtual bool getClosestNode(const GmVector &crd, double &sqrDist, int &outNodeId, const PointValidator &pv=defaultPointValidator) const =0
Returns the id of the closest node to the given coordinate, also filling sqrDist with the square of t...
virtual void getClosestNodes(const GmVector &crd, int n, QVector< GmpRefDist< int > > &nodeList, bool ordered, const PointValidator &pv=defaultPointValidator) const =0
Returns the ids of the n closest nodes, together with their squared distances, in distance order.
virtual void getClosestNodes(const GmVector &crd, double r, QVector< GmpRefDist< int > > &nodeList, bool ordered, const PointValidator &pv=defaultPointValidator) const =0
Returns the ids of the nodes whose distances to crd are less than radius, together with their squared...
virtual bool isOutsideOfDomain(const GmVector &crd) const =0
Returns true if the given point is outside of the spatial index domain.
Interface class for accessing and setting values from an "indexable" collection of values.
Definition gmValueAccessor.h:60
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
Declaration of macros for standard plugin categories.
#define GM_PLUGIN_SPATIALINDEX
Plugin implements spatial indices.
Definition gmPluginCategory.h:32
Declaration of the GmPluginObject base class.
Declaration of the GmVector class.
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition gmVector.h:34
Definition gmSpatialIndex.h:40
Definition gmSpatialIndex.h:59