DSC
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
query.h
1 //
2 // Created by Morten Nobel-Jørgensen on 19/11/14.
3 // Copyright (c) 2014 ___FULLUSERNAME___. All rights reserved.
4 //
5 
6 #pragma once
7 
8 #include "DSC.h"
9 #include "CGLA/Ray.h"
10 #include "attribute_vector.h"
11 #include <vector>
12 #include <set>
13 
19 namespace is_mesh {
20  enum class QueryType {
21  All,
22  Interface,
23  Boundary
24  };
25 
27  double dist;
28  CGLA::Ray ray;
29  QueryType query_type;
30  SimplexSet<TetrahedronKey> tetrahedron_key;
31  FaceKey face_key;
32  ISMesh *mesh;
33  void next();
34  bool tetWalking(SimplexSet < FaceKey > &faces);
35  public:
36 
38  QueryResultIterator(FaceKey const &first_boundary_intersection, double dist, CGLA::Ray const &ray, QueryType const &query_type, ISMesh *mesh);
40  CGLA::Vec3d collision_point();
41  FaceKey operator*();
42  QueryResultIterator &operator++();
43  bool operator!=(const QueryResultIterator & other);
44  bool operator==(const QueryResultIterator & other);
45  };
46 
47  class QueryResult {
48  FaceKey first_intersection;
49  double dist;
50  CGLA::Ray ray;
51  QueryType query_type;
52  ISMesh *mesh;
53  public:
54  QueryResult():mesh(nullptr){}
55  QueryResult(FaceKey const &first_intersection, double dist, CGLA::Ray const &ray, QueryType const &query_type, ISMesh *mesh);
56 
57  QueryResultIterator begin();
58  QueryResultIterator end();
59  };
60 
61  class Query {
62  ISMesh *mesh;
63  std::vector<FaceKey> *boundary_faces = nullptr;
64 
65  public:
66  Query(ISMesh *mesh);
67  ~Query();
68 
69  const ISMesh * get_is_mesh();
70 
71  QueryResult raycast_faces(CGLA::Ray ray, QueryType queryType = QueryType::All);
72 
73  // Must be called explicit prior to raycasting if the boundary triangles of the ISMesh has changed
74  void rebuild_boundary_cache();
75 
76  // returns the nodes within max distance to a given from_node
77  // includes the from_node in the result
78  std::set<NodeKey> neighborhood(NodeKey from_node, double max_distance);
79 
80  // returns the nodes within max distance to a given point
81  std::set<NodeKey> neighborhood(vec3 from, double max_distance);
82 
83  // return the list of edges where both nodes are contained in the nodeKeys
84  std::set<EdgeKey> edges(const std::set<NodeKey> nodeKeys);
85 
86  // return the list of faces where both nodes are contained in the edgeKeys
87  std::set<FaceKey> faces(const std::set<EdgeKey> edgeKeys);
88 
89  // return the list of tets where both nodes are contained in the faceKeys
90  std::set<TetrahedronKey> tetrahedra(const std::set<FaceKey> faceKeys);
91 
92  // exclude 'hanging' nodes, edges and faces. (such as nodes with only one edge etc)
93  // or in other words only include structures from tets
94  void filter_subset(std::set<NodeKey> &nodes, std::set<EdgeKey> &edges, std::set<FaceKey> &faces, std::set<TetrahedronKey> &tets);
95 
96  // Performs graph search
97  // Valid for TetrahedronKey, FaceKey, EdgeKey but _not_ NodeKey
98  template <typename K>
99  SimplexSet<K> connected(K initialKey, std::function<bool(K k)> includeKey);
100 
101  std::set<NodeKey> nodes(is_mesh::Geometry *geometry);
102  };
103 
104  template <typename K>
105  inline SimplexSet<K> Query::connected(K initialKey, std::function<bool(K k)> includeKey) {
106  AttributeVector<K, char> explored;
107  SimplexSet<K> res;
108  std::vector<K> q{initialKey};
109  while (!q.empty()){
110  K qKey = q.back();
111  q.pop_back();
112 
113  if (explored[qKey]){
114  continue;
115  }
116  explored[qKey] = true;
117 
118  if (includeKey(qKey)){
119  res.push_back(qKey);
120 
121  const auto & simplex = mesh->get(qKey);
122  auto boundary = simplex.get_boundary();
123  for (auto b : boundary){
124  for (auto bb : mesh->get(b).get_co_boundary()){
125  if (explored[bb]){
126  continue;
127  }
128  q.push_back(bb);
129  }
130  }
131  }
132  }
133 
134  return res;
135  }
136 
137 }
138 
139 
140 
Definition: geometry.h:24
Definition: query.h:47
A 3D double vector.
Definition: Vec3d.h:26
Definition: query.h:26
Definition: Ray.h:12
Definition: attribute_vector.h:17
Definition: query.h:61
Definition: key.h:68
Definition: is_mesh.h:40
Definition: key.h:82