Free Electron
SurfaceSearchable.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 __surface_SurfaceSearchable_h__
8 #define __surface_SurfaceSearchable_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief Tree-searchable Surface
17 
18  @ingroup surface
19 *//***************************************************************************/
20 class FE_DL_EXPORT SurfaceSearchable:
21  public SurfaceSphere,
22  public CastableAs<SurfaceSearchable>
23 {
24  public:
25 
26  //* optional arrays
27  typedef enum
28  {
29  e_arrayNull= 0x00,
30  e_arrayColor= 0x01,
31  e_arrayUV= 0x02,
32  e_arrayRadius= 0x04
33  } Arrays;
34 
35  class FE_DL_EXPORT Impact:
36  public SurfaceSphere::Impact,
37  public CastableAs<Impact>
38  {
39  public:
40  Impact(void)
41  {
42 #if FE_COUNTED_STORE_TRACKER
43  setName("SurfaceSearchable::Impact");
44 #endif
45  }
46  virtual ~Impact(void) {}
47 
48  virtual I32 triangleIndex(void)
49  { return m_triangleIndex; }
50  void setTriangleIndex(I32 a_triangleIndex)
51  { m_triangleIndex=a_triangleIndex; }
52 
53  virtual I32 primitiveIndex(void)
54  { return m_primitiveIndex; }
55  void setPrimitiveIndex(I32 a_primitiveIndex)
56  { m_primitiveIndex=a_primitiveIndex; }
57 
58  virtual I32 nearestSubIndex(void)
59  { return m_nearestSubIndex; }
60  void setNearestSubIndex(I32 a_nearestSubIndex)
61  { m_nearestSubIndex=a_nearestSubIndex; }
62 
63  virtual I32 partitionIndex(void)
64  { return m_partitionIndex; }
65  void setPartitionIndex(I32 a_partitionIndex)
66  { m_partitionIndex=a_partitionIndex; }
67 
68  virtual Vector2 uv(void)
69  { return m_uv; }
70  void setUV(Vector2 a_uv)
71  { m_uv=a_uv; }
72 
73  virtual SpatialVector du(void)
74  { return m_du; }
75  void setDu(SpatialVector a_du)
76  { m_du=a_du; }
77 
78  virtual SpatialVector dv(void)
79  { return m_dv; }
80  void setDv(SpatialVector a_dv)
81  { m_dv=a_dv; }
82 
83  virtual SpatialVector tangent(void)
84  { return m_tangent; }
85  void setTangent(SpatialVector a_tangent)
86  { m_tangent=a_tangent; }
87 
88  virtual SpatialBary barycenter(void)
89  { return m_barycenter; }
90  void setBarycenter(SpatialBary a_barycenter)
91  { m_barycenter=a_barycenter; }
92 
93  virtual I32 pointIndex0(void) const
94  { return m_pointIndex0; }
95  void setPointIndex0(I32 a_pointIndex0)
96  { m_pointIndex0=a_pointIndex0; }
97 
98  virtual I32 pointIndex1(void) const
99  { return m_pointIndex1; }
100  void setPointIndex1(I32 a_pointIndex1)
101  { m_pointIndex1=a_pointIndex1; }
102 
103  virtual SpatialVector vertex0(void) const
104  { return m_vertex0; }
105  void setVertex0(SpatialVector a_vertex0)
106  { m_vertex0=a_vertex0; }
107 
108  virtual SpatialVector vertex1(void) const
109  { return m_vertex1; }
110  void setVertex1(SpatialVector a_vertex1)
111  { m_vertex1=a_vertex1; }
112 
113  virtual SpatialVector normal0(void) const
114  { return m_normal0; }
115  void setNormal0(SpatialVector a_normal0)
116  { m_normal0=a_normal0; }
117 
118  virtual SpatialVector normal1(void) const
119  { return m_normal1; }
120  void setNormal1(SpatialVector a_normal1)
121  { m_normal1=a_normal1; }
122 
123  virtual void copy(sp<SpatialTreeI::Hit>& a_rspHit);
124 
125  //* TODO point indexes
126 
127  protected:
128  I32 m_triangleIndex;
129  I32 m_primitiveIndex;
130  I32 m_nearestSubIndex;
131  I32 m_partitionIndex;
132  Vector2 m_uv;
133  SpatialVector m_du;
134  SpatialVector m_dv;
135  SpatialVector m_tangent;
136  SpatialBary m_barycenter;
137  I32 m_pointIndex0;
138  I32 m_pointIndex1;
139  SpatialVector m_vertex0;
140  SpatialVector m_vertex1;
141  SpatialVector m_normal0;
142  SpatialVector m_normal1;
143  };
144 
145  //* TODO move to SurfaceBase
146  /// @brief match partition strings against patterns
147  class FE_DL_EXPORT PartitionSearchable: virtual public PartitionI
148  {
149  public:
150  PartitionSearchable(void):
151  m_matchCount(0),
152  m_tweaked(FALSE) {}
153 
154  virtual sp<PartitionI> clone(void) const;
155 
156  virtual U32 partitionCount(void) const
157  { return m_stringMap.size(); }
158 
159  virtual String partitionName(U32 a_index) const;
160 
161  //* NOTE lookup() and select() can
162  //* occur in any order
163 
164  virtual I32 lookup(String a_partitionString);
165  virtual I32 select(String a_filterString)
166  { return select(a_filterString,
167  PartitionI::e_matchRegex); }
168  virtual I32 select(String a_filterString,
169  PartitionI::FilterMethod a_filterMethod);
170  virtual BWORD add(String a_string);
171  virtual BWORD remove(String a_string);
172 
173  virtual BWORD match(I32 a_partitionIndex)
174  {
175  return a_partitionIndex>=0 &&
176  a_partitionIndex<
177  I32(m_filterArray.size()) &&
178  m_filterArray[a_partitionIndex];
179  }
180 
181  virtual BWORD matchable(void) const
182  { return m_matchCount>0; }
183 
184  private:
185 
186  std::map<String,I32> m_stringMap;
187  String m_filterString;
188  PartitionI::FilterMethod m_filterMethod;
189  Array<I32> m_filterArray;
190  I32 m_matchCount;
191  BWORD m_tweaked;
192  };
193 
194  SurfaceSearchable(void);
195 virtual ~SurfaceSearchable(void);
196 
197  //* As Protectable
198 virtual Protectable* clone(Protectable* pInstance=NULL);
199 
200  //* As SurfaceI
201 virtual void setRefinement(U32 a_refinement)
202  {
203  m_refinement=a_refinement;
204  if(m_spSpatialTree.isValid())
205  {
206  m_spSpatialTree->setRefinement(
207  m_refinement);
208  }
209  }
210 
211 virtual void setAccuracy(SurfaceI::Accuracy a_accuracy)
212  {
213  m_accuracy=a_accuracy;
214  if(m_spSpatialTree.isValid())
215  {
216  m_spSpatialTree->setAccuracy(
217  m_accuracy);
218  }
219  }
220 
221 virtual void setSearchable(BWORD a_searchable)
222  {
223  m_searchable=a_searchable;
224  }
225 
226 virtual void setSearch(String a_searchName)
227  {
228  m_searchName=a_searchName;
229  }
230 
231 virtual I32 triangleCount(void) { return m_elements; }
232 
233  using SurfaceSphere::sample;
234 
235 virtual SpatialTransform sample(Vector2 a_uv) const;
236 
237 virtual void prepareForSample(void);
238 virtual void prepareForSearch(void);
239 virtual void prepareForUVSearch(void);
240 
241  using SurfaceSphere::nearestPoints;
242  using SurfaceSphere::nearestPoint;
243 
245  nearestPoints(const Vector2& a_uv,
246  Real a_maxDistance,U32 a_hitLimit) const;
247 virtual sp<ImpactI> nearestPoint(const Vector2& a_uv) const;
248 
250  nearestPoints(const SpatialVector& a_origin,
251  Real a_maxDistance,U32 a_hitLimit,
252  sp<PartitionI> a_spPartition) const;
253 virtual sp<ImpactI> nearestPoint(const SpatialVector& a_origin,
254  Real a_maxDistance) const
255  { return nearestPoint(a_origin,
256  a_maxDistance,FALSE); }
257 virtual sp<ImpactI> nearestPoint(const SpatialVector& a_origin,
258  Real a_maxDistance,BWORD a_anyHit) const;
259 
260  using SurfaceSphere::rayImpacts;
261 
263  rayImpacts(const SpatialVector& a_origin,
264  const SpatialVector& a_direction,
265  Real a_maxDistance,U32 a_hitLimit) const;
266 
267  using SurfaceSphere::rayImpact;
268 
269 virtual sp<ImpactI> rayImpact(const SpatialVector& a_origin,
270  const SpatialVector& a_direction,
271  Real a_maxDistance,BWORD a_anyHit) const;
272 
273 virtual void partitionWith(String a_attributeName);
274 virtual U32 partitionCount(void) const
275  { return m_spPartition.isValid()?
276  m_spPartition->partitionCount(): 0; }
277 virtual String partitionName(U32 a_index) const
278  { return m_spPartition.isValid()?
279  m_spPartition->partitionName(a_index):
280  ""; }
281 virtual Vector4 partitionSphere(U32 a_index) const;
282 
283  using SurfaceSphere::setPartitionFilter;
284 
285  //* WARNING not thread-safe
286 virtual I32 setPartitionFilter(String a_filterString,
287  PartitionI::FilterMethod a_filterMethod)
288  { checkCache();
289  return m_spPartition.isValid()?
290  m_spPartition->select(
291  a_filterString,a_filterMethod): 0; }
292 virtual sp<PartitionI> createPartition(void);
293 
294  using SurfaceSphere::draw;
295 
296 virtual void draw(sp<DrawI> a_spDrawI,
297  const Color* a_pColor,
298  sp<DrawBufferI> a_spDrawBuffer) const
299  { drawInternal(FALSE,NULL,a_spDrawI,
300  a_pColor,sp<DrawBufferI>(NULL),
301  sp<PartitionI>(NULL)); }
302 virtual void draw(const SpatialTransform& a_rTransform,
303  sp<DrawI> a_spDrawI,
304  const fe::Color* a_pColor,
305  sp<DrawBufferI> a_spDrawBuffer,
306  sp<PartitionI> a_spPartition) const
307  { drawInternal(TRUE,&a_rTransform,
308  a_spDrawI,a_pColor,a_spDrawBuffer,
309  a_spPartition); }
310 
311  protected:
312 
313 virtual void drawInternal(BWORD a_transformed,
314  const SpatialTransform* a_pTransform,
315  sp<DrawI> a_spDrawI,
316  const fe::Color* a_pColor,
317  sp<DrawBufferI> a_spDrawBuffer,
318  sp<PartitionI> a_spPartition) const {}
319 
320  I32 lookupPartition(String a_partitionString)
321  { return m_spPartition.isValid()?
322  m_spPartition->lookup(
323  a_partitionString): -1; }
324 
325 virtual void cache(void);
326  void clear();
327 
328  void filterUV(void);
329  void calcTangents(void);
330  void calcBoundingSphere(void);
331 
332  void setOptionalArrays(Arrays a_arrays)
333  { m_optionalArrays=a_arrays; }
334  void resizeArrays(U32 a_elementCount,U32 a_verticeCount);
335  void resizeFor(U32 a_primitiveCount,U32 a_vertexCount,
336  U32& a_rElementAllocated,
337  U32& a_rVertexAllocated);
338 
339  U32 m_refinement;
340  SurfaceI::Accuracy m_accuracy;
341  BWORD m_searchable;
342  String m_searchName;
343 
344  U32 m_elements;
345  U32 m_vertices;
346 
347  Arrays m_optionalArrays;
348  Vector3i* m_pElementArray; //* <start, count, open>
349  SpatialVector* m_pVertexArray;
350  SpatialVector* m_pNormalArray;
351  SpatialVector* m_pTangentArray;
352  Vector2* m_pUVArray;
353  SpatialVector* m_pUV3Array;
354  Color* m_pColorArray;
355  Real* m_pRadiusArray;
356  I32* m_pTriangleIndexArray;
357  I32* m_pPartitionIndexArray;
358  I32* m_pPointIndexArray;
359  I32* m_pPrimitiveIndexArray;
360 
361  Array<I32> m_vertexMap;
362  Array<I32> m_hullPointMap;
363  Array<Vector4i> m_hullFacePointArray;
364 
365  sp<Component> m_spSearchComponent;
366  sp<SpatialTreeI> m_spSpatialTree;
367  sp<SpatialTreeI> m_spUVTree;
368 
369  String m_partitionAttr;
370  sp<PartitionI> m_spPartition;
371  Array<Vector4> m_partitionSphere;
372 
373  protected:
374 mutable CountedPoolCore* m_pImpactPool;
375 };
376 
377 } /* namespace ext */
378 } /* namespace fe */
379 
380 #endif /* __surface_SurfaceSearchable_h__ */
virtual void setSearchable(BWORD a_searchable)
Set whether this surface may be searched.
Definition: SurfaceSearchable.h:221
Base class providing protection counting for cp<>
Definition: Protectable.h:28
kernel
Definition: namespace.dox:3
Special vector for color (RGBA)
Definition: Color.h:21
matchable list of strings
Definition: PartitionI.h:20
virtual I32 triangleCount(void)
Number of barycentric elements.
Definition: SurfaceSearchable.h:231
virtual void setAccuracy(SurfaceI::Accuracy a_accuracy)
Set what primitive to search down to.
Definition: SurfaceSearchable.h:211
Spherical Surface.
Definition: SurfaceSphere.h:20
Automatically reference-counted string container.
Definition: String.h:128
Tree-searchable Surface.
Definition: SurfaceSearchable.h:20
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
virtual void setRefinement(U32 a_refinement)
Set limitation of surface improvement, such as subdivision.
Definition: SurfaceSearchable.h:201
match partition strings against patterns
Definition: SurfaceSearchable.h:147
virtual void setSearch(String a_searchName)
Set component to use for searching.
Definition: SurfaceSearchable.h:226
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192