NvBlastExtAuthoringAccelerator.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27 
28 
29 #ifndef NVBLASTEXTAUTHORINGACCELERATOR_H
30 #define NVBLASTEXTAUTHORINGACCELERATOR_H
31 
32 #include <set>
33 #include <vector>
35 
36 
37 namespace Nv
38 {
39  namespace Blast
40  {
41 
42  class Mesh;
43 
48  {
49  public:
50 
57  virtual void setState(const NvcBounds3* bounds) = 0;
58 
65  virtual void setState(const Vertex* pos, const Edge* ed, const Facet& fc) = 0;
70  virtual void setState(const NvcVec3& point) = 0;
75  virtual int32_t getNextFacet() = 0;
76 
77 
78  virtual void setPointCmpDirection(int32_t dir) = 0;
79 
80 
81  virtual ~SpatialAccelerator() {};
82  };
83 
84 
89  {
90  public:
94  DummyAccelerator(int32_t count);
95  virtual void setState(const NvcBounds3* bounds) override;
96  virtual void setState(const Vertex* pos, const Edge* ed, const Facet& fc) override;
97  virtual void setState(const NvcVec3& point) override;
98  virtual int32_t getNextFacet() override;
99 
100  virtual void setPointCmpDirection(int32_t dir) override {};
101  private:
102  int32_t m_count;
103  int32_t m_current;
104  };
105 
107  {
108  float coord;
109  uint32_t index;
110  bool end;
111 
112  SegmentToIndex(float c, uint32_t i, bool end) : coord(c), index(i), end(end) {};
113 
114  bool operator<(const SegmentToIndex& in) const
115  {
116  if (coord < in.coord) return true;
117  if (coord > in.coord) return false;
118  return end < in.end;
119  }
120  };
121 
122 
123 
124  class Grid
125  {
126 
127  public:
128 
129  friend class GridWalker;
130 
131  Grid(int32_t resolution);
132  void setMesh(const Nv::Blast::Mesh* m);
133 
134  private:
135  int32_t m_resolution;
136  int32_t m_r3;
137  int32_t m_mappedFacetCount;
138  NvcVec3 m_spos;
139  NvcVec3 m_deltas;
140  std::vector< std::vector<int32_t> > m_spatialMap;
141  };
142 
143  class GridWalker : public SpatialAccelerator // Iterator to traverse the grid
144  {
145  public:
146  GridWalker(Grid* grd);
147 
148  virtual void setState(const NvcBounds3* bounds) override;
149  virtual void setState(const Vertex* pos, const Edge* ed, const Facet& fc) override;
150  virtual void setState(const NvcVec3& point) override;
151  virtual int32_t getNextFacet() override;
152  virtual void setPointCmpDirection(int32_t dir) override;
153  private:
154  Grid* m_grid;
155 
156  // Iterator data
157  std::vector<uint32_t> m_alreadyGotFlag;
158  uint32_t m_alreadyGotValue;
159  std::vector<int32_t> m_cellList;
160  int32_t m_gotCells;
161  int32_t m_iteratorCell;
162  int32_t m_iteratorFacet;
163  int32_t m_pointCmdDir;
164  };
165 
166 
168  {
169  public:
174  virtual void setState(const Vertex* pos, const Edge* ed, const Facet& fc) override;
175  virtual void setState(const NvcBounds3* bounds) override;
176  virtual void setState(const NvcVec3& point) override;
177  virtual int32_t getNextFacet() override;
178  virtual void setPointCmpDirection(int32_t dir) override {};
179  private:
180 
181 
182  /*
183  For fast point test.
184  */
185  std::vector<std::vector<uint32_t> > m_xSegm;
186  std::vector<std::vector<uint32_t> > m_ySegm;
187  std::vector<std::vector<uint32_t> > m_zSegm;
188  std::vector<uint32_t> m_indices;
189  std::vector<uint32_t> m_foundx;
190  std::vector<uint32_t> m_foundy;
191 
192  uint32_t m_iterId;
193  int32_t m_current;
194  uint32_t m_facetCount;
195 
196  NvcVec3 m_minimal;
197  NvcVec3 m_maximal;
198 
199  NvcVec3 m_rescale;
200 
201 
202  };
203 
204 
211  {
212  public:
217  BBoxBasedAccelerator(const Mesh* mesh, int32_t resolution);
218  virtual ~BBoxBasedAccelerator();
219  int32_t getNextFacet() override;
220  void setState(const Vertex* pos, const Edge* ed, const Facet& fc) override;
221  void setState(const NvcBounds3* bounds) override;
222  void setState(const NvcVec3& p) override;
223  void setPointCmpDirection(int32_t dir) override {};
224  private:
225 
226  void buildAccelStructure(const Vertex* pos, const Edge* edges, const Facet* fc, int32_t facetCount);
227 
228  int32_t m_resolution;
229  NvcBounds3 m_bounds;
230  std::vector< std::vector<int32_t> > m_spatialMap;
231  std::vector<NvcBounds3> m_cells;
232 
233 
234  // Iterator data
235  std::vector<uint32_t> m_alreadyGotFlag;
236  uint32_t m_alreadyGotValue;
237  std::vector<int32_t> m_cellList;
238  int32_t m_gotCells;
239  int32_t m_iteratorCell;
240  int32_t m_iteratorFacet;
241  };
242 
243  } // namespace Blast
244 } // namsepace Nv
245 
246 
247 #endif // ifndef NVBLASTEXTAUTHORINGACCELERATOR_H
virtual void setPointCmpDirection(int32_t dir) override
Definition: NvBlastExtAuthoringAccelerator.h:178
Definition: NvBlastExtAuthoringAccelerator.h:210
Definition: NvBlastExtAuthoringAccelerator.h:47
virtual void setState(const NvcBounds3 *bounds)=0
Definition: NvBlastExtAuthoringMesh.h:42
Definition: NvBlastExtAuthoringTypes.h:106
bool operator<(const SegmentToIndex &in) const
Definition: NvBlastExtAuthoringAccelerator.h:114
virtual void setPointCmpDirection(int32_t dir) override
Definition: NvBlastExtAuthoringAccelerator.h:100
float coord
Definition: NvBlastExtAuthoringAccelerator.h:108
bool end
Definition: NvBlastExtAuthoringAccelerator.h:110
Definition: NvBlastExtAuthoringAccelerator.h:106
virtual ~SpatialAccelerator()
Definition: NvBlastExtAuthoringAccelerator.h:81
void setPointCmpDirection(int32_t dir) override
Definition: NvBlastExtAuthoringAccelerator.h:223
SegmentToIndex(float c, uint32_t i, bool end)
Definition: NvBlastExtAuthoringAccelerator.h:112
virtual void setPointCmpDirection(int32_t dir)=0
Definition: NvBlastExtAuthoringAccelerator.h:124
Definition: NvBlastExtAuthoringAccelerator.h:88
Definition: NvCTypes.h:92
uint32_t index
Definition: NvBlastExtAuthoringAccelerator.h:109
virtual int32_t getNextFacet()=0
Definition: NvBlastExtAuthoringAccelerator.h:167
Definition: NvBlastExtAuthoringTypes.h:57
Definition: NvBlastExtAuthoringAccelerator.h:143
Definition: NvBlastExtAuthoringTypes.h:67
Definition: NvBlastExtAuthoring.h:34
Definition: NvCTypes.h:49