HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_NeighbourList.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: Geometry library (C++)
7  *
8  * COMMENTS: For a set of geometric points with a fixed interatction
9  * radius, build a list of neighbours for each point.
10  * This is useful for things like particle-based fluid
11  * simulations.
12  *
13  */
14 
15 #ifndef __GU_NEIGHBOUR_LIST_H__
16 #define __GU_NEIGHBOUR_LIST_H__
17 
18 #include "GU_API.h"
19 
20 #include "GU_Detail.h"
21 
22 #include <GA/GA_Types.h>
23 
24 #include <UT/UT_HashGrid.h>
25 #include <UT/UT_Array.h>
26 #include <UT/UT_String.h>
28 
29 class UT_SmallAlloc;
30 class GEO_PointTree;
31 
32 ///
33 /// GU_NeighbourListParms
34 /// Parameters necessary for building the neighbour list data structure
35 ///
37 {
38 public:
40  virtual ~GU_NeighbourListParms();
41 
42  // We can support either fixed radii, or varying radii amongst
43  // the provided point set, though varying radii is more expensive
45  {
47  NONUNIFORM
48  };
49 
50  void setMode( InteractionMode mode );
51  InteractionMode getMode() const;
52 
53  void setOverrideRadius( bool overrideRadius );
54  bool getOverrideRadius() const;
55 
56  void setRadius( fpreal radius );
57  fpreal getRadius() const;
58 
59  void setRadiusScale( fpreal radiusScale );
60  fpreal getRadiusScale() const;
61 
62  void setRadiusAttribute( const char *name );
63  const char *getRadiusAttribute() const;
64 
65 private:
66  InteractionMode myMode;
67 
68  /// Whether or not to override provided radii with a
69  /// fixed radius, and the desired fixed radius.
70  bool myOverrideRadius;
71  fpreal myRadius;
72 
73  /// Scaling factor for the desired radius (either from the
74  /// given override radius, or obtained from point attributes).
75  fpreal myRadiusScale;
76 
77  /// String storing the attribute name used to store
78  /// per-point interaction radii.
79  UT_String myRadiusAttributeName;
80 
81 };
82 
83 ///
84 /// GU_NeighbourList
85 /// This class associates with each point in the provided geometry
86 /// a fixed interaction radius. Based on this interaction radius, a
87 /// list of neighbour points can be efficiently determined for each
88 /// point in the geometry.
89 ///
91 {
92 public:
93  typedef GA_Index IdxType;
95 
97  virtual ~GU_NeighbourList();
98 
99  /// Build the neighbour list structure from the given gdp
100  void build(const GU_Detail *gdp,
101  const GU_NeighbourListParms &parms);
102 
103  /// Erases our storage.
104  void clearLists();
105 
106  /// Fills the giving point array with the list of neighbours of the
107  /// given point index.
108  /// Out of range point indices will be return empty lists.
109  /// If the gdp has too few points, the out of range neighbours are
110  /// ignored.
111  void getNeighbours(int pointidx, const GU_Detail *gdp,
112  UT_Array<GA_Offset> &ptlist) const;
113 
114  int64 getMemoryUsage() const;
115 
116 private:
117  /// Determine what fixed radius to do when using fixed neighbour
118  /// interaction radii. This works by finding the largest radius
119  /// amongst all particles in the input.
120  bool setNeighbourRadius(
121  const GU_Detail *gdp,
122  const GU_NeighbourListParms &parms);
123 
124  /// Helper function which creates a hash grid data structure
125  /// for the particle field.
126  void buildPointGrid(
127  const GU_Detail *gdp,
128  const GU_NeighbourListParms &parms);
129  void destroyPointGrid();
130 
131  /// Threaded method to look up in the point grid the neighbour
132  /// list for each element.
133  THREADED_METHOD1(GU_NeighbourList, gdp->getNumPoints() > 1000,
134  buildListFromPointGrid,
135  const GU_Detail *, gdp)
136  void buildListFromPointGridPartial(const GU_Detail *gdp,
137  const UT_JobInfo &info);
138 
139  /// Threaded method to look up in the point tree the neighbour
140  /// list for each element.
141  THREADED_METHOD3(GU_NeighbourList, gdp->getNumPoints() > 1000,
142  buildListFromPointTree,
143  const GU_Detail *, gdp,
144  fpreal, radscale,
145  const char *, radname)
146  void buildListFromPointTreePartial(const GU_Detail *gdp,
147  fpreal radscale,
148  const char *radname,
149  const UT_JobInfo &info);
150 
151  /// Helper function which constructs a KD-tree when using
152  /// non-uniform radii.
153  void buildPointTree(
154  const GU_Detail *gdp,
155  const GU_NeighbourListParms &parms);
156  void destroyPointTree();
157 
158 private:
160  myMode;
161 
162  /// Per-point neighbour information.
163  UT_Array<IdxType *> myNeighbourIdx;
164  UT_IntArray myNeighbourLen;
165 
166  /// Our storage tables where we keep our actual data
167  /// We have one per thread.
168  UT_Array<UT_SmallAlloc *> myAllocTables;
169 
170  /// Fixed neighbour radius used for the uniform data structure
171  fpreal myFixedRadius;
172 
173  /// Data structure used to efficiently initialize the neighbour
174  /// lists.
175  UT_HashGrid<GA_Offset> *myPointGrid;
176 
177  /// Data structure used to initialize the neighbour lists
178  /// when using non-uniform radii.
179  GEO_PointTree *myPointTree;
180 
181 };
182 
183 #endif
#define THREADED_METHOD1(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1)
#define THREADED_METHOD3(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3)
long long int64
Definition: SYS_Types.h:116
#define GU_API
Definition: GU_API.h:14
GLuint const GLchar * name
Definition: glcorearb.h:786
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
GLenum mode
Definition: glcorearb.h:99
UT_ValArray< IdxType > IdxArrayType
fpreal64 fpreal
Definition: SYS_Types.h:277