Free Electron
SurfaceVDB.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __vdb_SurfaceVDB_h__
8 #define __vdb_SurfaceVDB_h__
9 namespace fe
10 {
11 namespace ext
12 {
13 
14 /**************************************************************************//**
15  @brief VDB Surface
16 
17  @ingroup vdb
18 *//***************************************************************************/
19 class FE_DL_EXPORT SurfaceVDB:
20  public SurfaceSphere,
21  public CastableAs<SurfaceVDB>
22 {
23  public:
24  class Impact:
25  public SurfaceSphere::Impact,
26  public CastableAs<Impact>
27  {
28  public:
29  Impact(void)
30  {
31 #if FE_COUNTED_STORE_TRACKER
32  setName("SurfaceVDB::Impact");
33 #endif
34  }
35  virtual ~Impact(void) {}
36 
37  virtual I32 pointIndex0(void) const
38  { return m_pointIndex0; }
39  void setPointIndex0(I32 a_pointIndex0)
40  { m_pointIndex0=a_pointIndex0; }
41 
42  virtual SpatialVector vertex0(void) const
43  { return m_vertex0; }
44  void setVertex0(SpatialVector a_vertex0)
45  { m_vertex0=a_vertex0; }
46 
47  virtual Vector2 uv(void)
48  { return m_uv; }
49  void setUV(Vector2 a_uv)
50  { m_uv=a_uv; }
51 
52  using SurfaceSphere::Impact::draw;
53 
54  virtual void draw(const SpatialTransform& a_rTransform,
55  sp<DrawI> a_spDrawI,
56  const fe::Color* a_pColor,
57  sp<DrawBufferI> a_spDrawBuffer,
58  sp<PartitionI> a_spPartition) const;
59 
60  protected:
61  Vector2 m_uv;
62  I32 m_pointIndex0;
63  SpatialVector m_vertex0;
64 
65  };
66  SurfaceVDB(void);
67 virtual ~SurfaceVDB(void);
68 
69  //* As Protectable
70 virtual Protectable* clone(Protectable* pInstance=NULL);
71 
72  //* As SurfaceI
73 
74  using SurfaceSphere::bind;
75 
76 virtual void bind(Instance a_instance);
77 
78  using SurfaceSphere::containment;
79 
80 virtual Containment containment(
81  const SpatialVector& a_origin) const;
82 
83  using SurfaceSphere::nearestPoint;
84 
85 virtual sp<SurfaceI::ImpactI> nearestPoint(
86  const SpatialVector& a_origin) const;
87 
88  using SurfaceSphere::rayImpact;
89 
90 virtual sp<SurfaceI::ImpactI> rayImpact(const SpatialVector& a_origin,
91  const SpatialVector& a_direction,
92  Real a_maxDistance,
93  BWORD a_anyHit) const;
94 
95  using SurfaceSphere::draw;
96 
97 virtual void draw(const SpatialTransform&,
98  sp<DrawI> a_spDrawI,
99  const fe::Color* a_color,
100  sp<DrawBufferI> a_spDrawBuffer,
101  sp<PartitionI> a_spPartition) const;
102 
103  I32 vertexCount(void) const
104  { return m_vertexCount; }
105 
106  BWORD getVertexPoint(I32 a_index,
107  SpatialVector& a_rPoint)
108  {
109  if(a_index<0 || a_index>=m_vertexCount)
110  {
111  return FALSE;
112  }
113  a_rPoint=m_pVertexArray[a_index];
114  return TRUE;
115  }
116  BWORD getVertexNormal(I32 a_index,
117  SpatialVector& a_rNormal)
118  {
119  if(a_index<0 || a_index>=m_vertexCount)
120  {
121  return FALSE;
122  }
123  a_rNormal=m_pNormalArray[a_index];
124  return TRUE;
125  }
126  BWORD getVertexCpt(I32 a_index,
127  SpatialVector& a_rCpt)
128  {
129  if(a_index<0 || a_index>=m_vertexCount)
130  {
131  return FALSE;
132  }
133  a_rCpt=m_pCptArray[a_index];
134  return TRUE;
135  }
136  BWORD getVertexValue(I32 a_index,
137  Real& a_rValue)
138  {
139  if(a_index<0 || a_index>=m_vertexCount)
140  {
141  return FALSE;
142  }
143  a_rValue=m_pValueArray[a_index];
144  return TRUE;
145  }
146 
147  protected:
148 virtual void cache(void);
149 
150 virtual void resolveImpact(sp<ImpactI> a_spImpactI) const {}
151 
152  sp<SurfaceI::ImpactI> computeImpact(const SpatialVector& a_origin,
153  const SpatialVector&
154  a_intersection,
155  I32 a_vertexIndex) const;
156 
157  openvdb::Vec3d spatialToIndex(
158  const SpatialVector& a_point) const;
159  SpatialVector indexToSpatial(
160  const openvdb::Vec3d& a_coord) const;
161  private:
162 
163  class PointList: public std::vector<openvdb::Vec3R>
164  {
165  public:
166  using PosType = openvdb::Vec3R;
167 
168  PointList(void) {}
169 
170  void getPos(size_t n, openvdb::Vec3R& xyz) const
171  { xyz = operator[](n); }
172  };
173 
174  I32 nearestIndex(const SpatialVector& a_origin,
175  Real a_maxDistance) const;
176 
177  void bindGridBase(openvdb::GridBase::ConstPtr& a_gridPtr);
178 
179  String m_vdbClass;
180 
181  openvdb::FloatGrid::ConstPtr m_floatGridPtr;
182  openvdb::Vec3SGrid::ConstPtr m_cptGridPtr;
183  openvdb::Vec3SGrid::ConstPtr m_normalGridPtr;
184  openvdb::Vec3SGrid::ConstPtr m_uvGridPtr;
185 
186  openvdb::tools::PointIndexGrid::Ptr m_pointGridPtr;
187 
188  PointList m_pointList;
189 
190  SpatialVector* m_pVertexArray;
191  SpatialVector* m_pNormalArray;
192  Color* m_pColorArray;
193  SpatialVector* m_pCptArray;
194  Real* m_pValueArray;
195  I32 m_vertexCount;
196 
197 mutable CountedPool<Impact> m_vdbImpactPool;
198 };
199 
200 } /* namespace ext */
201 } /* namespace fe */
202 
203 #endif /* __vdb_SurfaceVDB_h__ */
Base class providing protection counting for cp<>
Definition: Protectable.h:28
Smart pointer used with types represented by BaseType.
Definition: Instance.h:28
kernel
Definition: namespace.dox:3
Special vector for color (RGBA)
Definition: Color.h:21
VDB Surface.
Definition: SurfaceVDB.h:19
Spherical Surface.
Definition: SurfaceSphere.h:20
Automatically reference-counted string container.
Definition: String.h:128
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192