ClipPlaneSet.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
12 
14 
15 
17  {
21  };
22 
23 // An array of arrays of T, with the point arrays to be used like a stack.
24 // When the stack is popped, the top array is swapped to a holding area instead of
25 // going to destructor, and then reused on later push
26 template<typename T>
27 struct BVectorCache : bvector<bvector<T>>
28 {
30 // pope the top bvector<T>, and save it in the cache.
31 // return false if nothing to pop
32 bool PopToCache ()
33  {
34  if (size () > 0)
35  {
37  back ().swap (m_cache.back ()); // This preserves the heap allocation
38  m_cache.back ().clear ();
39  pop_back (); // This is an empty bvector, so destructor does not free anything.
40  return true;
41  }
42  return false;
43  }
44 // push an (empty) bvector.
45 // (If possible, it is taken from the cache, and will have pre-allocated heap memory)
47  {
49  if (m_cache.size () > 0)
50  {
51  back ().swap (m_cache.back ()); // This preserves the heap allocation
52  back ().clear();
53  }
54  }
55 
56 // push
57 // push data, using sequence that reuses capacity if possible
58 void PushCopy (bvector<T> const &data)
59  {
60  PushFromCache ();
61  back() = data;
62  }
63 // clear all bvectors to the cache. (preserving heap allocations)
64 void ClearToCache ()
65  {
66  while (PopToCache ())
67  {
68  }
69  }
70 
71 
73  {
74  data.clear ();
75  if (!empty ())
76  {
77  data.swap (back());
78  PopToCache ();
79  return true;
80  }
81  return false;
82  }
83 };
84 /*=================================================================================**/
87 
90  {
93 
95  ConvexClipPlaneSet (size_t n) : T_ClipPlanes (n) { }
96 
98  GEOMDLLIMPEXP ConvexClipPlaneSet (ClipPlaneCP planes, size_t nPlanes);
99 
101  GEOMDLLIMPEXP bool IsPointInside (DPoint3dCR point) const;
102 
104  GEOMDLLIMPEXP bool IsPointOnOrInside (DPoint3dCR point, double tolerance) const;
105 
107  GEOMDLLIMPEXP bool IsSphereInside (DPoint3dCR point, double tolerance) const;
108 
110  GEOMDLLIMPEXP bool ClipBoundedSegment (DPoint3dCR pointA, DPoint3dCR pointB, double &fraction0, double &fraction1, double planeSign) const;
111 
113  GEOMDLLIMPEXP bool ClipUnBoundedSegment (DPoint3dCR pointA, DPoint3dCR pointB, double &fraction0, double &fraction1, double planeSign) const;
114 
116  GEOMDLLIMPEXP static ConvexClipPlaneSet FromXYBox (double x0, double y0, double x1, double y1);
117 
119  // normals
120  GEOMDLLIMPEXP static ConvexClipPlaneSet FromXYPolyLine (bvector<DPoint3d> &points, bvector<bool> &hiddenEdge, bool leftIsInside);
121 
130  GEOMDLLIMPEXP ClipPlaneContainment ClassifyPointContainment (DPoint3dCP points, size_t nPoints, bool onIsOutside = false) const;
131 
133  GEOMDLLIMPEXP void TransformInPlace (TransformCR transform);
134 
136  GEOMDLLIMPEXP bool GetRange (DRange3dR range, TransformCP transform) const;
137 
143  GEOMDLLIMPEXP int ReloadSweptConvexPolygon
144  (
145  bvector<DPoint3d> const &points,
146  DVec3dCR sweepDirection,
147  int sideSelect
148  );
150  GEOMDLLIMPEXP void ConvexPolygonClip
151  (
152  bvector<DPoint3d> const &input,
153  bvector<DPoint3d> &output,
154  bvector<DPoint3d> &work
155  ) const;
156 
158  GEOMDLLIMPEXP void ConvexPolygonClipInsideOutside
159  (
160  bvector<DPoint3d> const &input,
161  bvector<DPoint3d> &inside,
162  BVectorCache<DPoint3d> &outside,
163  bvector<DPoint3d> &work1,
164  bvector<DPoint3d> &work2,
165  bool clearOutside = true,
166  double distanceTolerance = 0.0
167  ) const;
168  }; // ConvexClipPlaneSet
169 
170 
172 
173 /*=================================================================================**/
176 
179  {
182 
184  GEOMDLLIMPEXP ClipPlaneSet(ClipPlaneCP planes, size_t nPlanes);
185 
187  GEOMDLLIMPEXP ClipPlaneSet (ConvexClipPlaneSetCR convexSet);
188 
192  GEOMDLLIMPEXP static ClipPlaneSet FromSweptPolygon (DPoint3dCP points, size_t n, DVec3dCP direction = NULL);
193  GEOMDLLIMPEXP static ClipPlaneSet FromSweptPolygon (DPoint3dCP points, size_t n, DVec3dCP direction,
194  bvector<bvector<DPoint3d>> *shapes
195  );
196 
198  GEOMDLLIMPEXP bool IsPointInside (DPoint3dCR point) const;
199 
201  GEOMDLLIMPEXP bool IsPointOnOrInside (DPoint3dCR point, double tolerance) const;
202 
204  GEOMDLLIMPEXP bool IsSphereInside (DPoint3dCR point, double radius) const;
205 
207  GEOMDLLIMPEXP void TransformInPlace (TransformCR transform);
208 
210  GEOMDLLIMPEXP static ClipPlaneSet FromXYBox (double x0, double y0, double x1, double y1);
211 
213  GEOMDLLIMPEXP bool TestRayIntersect (DPoint3dCR point, DVec3dCR direction) const;
214 
216  GEOMDLLIMPEXP bool GetRayIntersection (double& tNear, DPoint3dCR point, DVec3dCR direction) const;
217 
226  GEOMDLLIMPEXP ClipPlaneContainment ClassifyPointContainment (DPoint3dCP points, size_t nPoints, bool onIsOutside = false) const;
227 
229  GEOMDLLIMPEXP bool GetRange (DRange3dR range, TransformCP transform) const;
230  };
231 
233 
struct DVec3d const * DVec3dCP
Definition: msgeomstructs_typedefs.h:89
bool GetRange(DRange3dR range, TransformCP transform) const
Get range of this ConvexClipPlaneSet.
bool SwapBackPop(bvector< T > &data)
Definition: ClipPlaneSet.h:72
void push_back(const_reference)
struct DPoint3d const * DPoint3dCP
Definition: msgeomstructs_typedefs.h:79
bool IsPointOnOrInside(DPoint3dCR point, double tolerance) const
Test if point is inside to supplied tolerance.
Definition: ClipPlaneSet.h:19
bool GetRange(DRange3dR range, TransformCP transform) const
Get range of this ClipPlaneSet.
static ClipPlaneSet FromSweptPolygon(DPoint3dCP points, size_t n, DVec3dCP direction=NULL)
Create a (chain of) convex clippers for an (unbounded) polygon sweep in given direction.
bool IsPointInside(DPoint3dCR point) const
Test if point is inside all planes.
#define END_BENTLEY_GEOMETRY_NAMESPACE
Definition: Bentley.r.h:30
ClipPlaneContainment ClassifyPointContainment(DPoint3dCP points, size_t nPoints, bool onIsOutside=false) const
return a summary classification
void clear()
bool PopToCache()
Definition: ClipPlaneSet.h:32
bool ClipUnBoundedSegment(DPoint3dCR pointA, DPoint3dCR pointB, double &fraction0, double &fraction1, double planeSign) const
Clip an unbounded line to this set of planes.
struct ConvexClipPlaneSet const & ConvexClipPlaneSetCR
Definition: msgeomstructs_typedefs.h:95
bool IsSphereInside(DPoint3dCR point, double tolerance) const
Test if sphere is inside all planes.
void TransformInPlace(TransformCR transform)
Transform plane set.
bool ClipBoundedSegment(DPoint3dCR pointA, DPoint3dCR pointB, double &fraction0, double &fraction1, double planeSign) const
Clip a (bounded) line segment to this set of planes.
ClipPlaneSet()
Create empty clip plane set.
Definition: ClipPlaneSet.h:181
#define NULL
Definition: Bentley.h:157
void ClearToCache()
Definition: ClipPlaneSet.h:64
static ClipPlaneSet FromXYBox(double x0, double y0, double x1, double y1)
Create clip plane set from XY box.
void swap(bvector &)
bool IsPointInside(DPoint3dCR point) const
Test if point is inside.
void TransformInPlace(TransformCR transform)
Transform each plane set.
bvector< ConvexClipPlaneSet > T_ConvexClipPlaneSets
Definition: ClipPlaneSet.h:171
struct DRange3d & DRange3dR
Definition: msgeomstructs_typedefs.h:108
void PushCopy(bvector< T > const &data)
Definition: ClipPlaneSet.h:58
void ConvexPolygonClipInsideOutside(bvector< DPoint3d > const &input, bvector< DPoint3d > &inside, BVectorCache< DPoint3d > &outside, bvector< DPoint3d > &work1, bvector< DPoint3d > &work2, bool clearOutside=true, double distanceTolerance=0.0) const
Return the (0 or 1) intersection polygon and (0 or to numClipPlane) outside pieces.
size_type size() const
Definition: stdcxx/bvector.h:283
struct Transform const * TransformCP
Definition: msgeomstructs_typedefs.h:134
static ConvexClipPlaneSet FromXYBox(double x0, double y0, double x1, double y1)
Create clip plane set from XY box.
void pop_back()
Definition: stdcxx/bvector.h:337
Definition: ClipPlaneSet.h:20
bool IsPointOnOrInside(DPoint3dCR point, double tolerance) const
Test if point is inside all planes to supplied tolerance.
bool empty() const
Definition: stdcxx/bvector.h:297
A Bentley supplied implementation std::vector.
Definition: stdcxx/bvector.h:77
ConvexClipPlaneSet()
Create emplty convex plane set.
Definition: ClipPlaneSet.h:92
bvector< bvector< T > > m_cache
Definition: ClipPlaneSet.h:29
int ReloadSweptConvexPolygon(bvector< DPoint3d > const &points, DVec3dCR sweepDirection, int sideSelect)
reinitialize to clip to a swept polygon.
ClipPlaneContainment
Definition: ClipPlaneSet.h:16
! A ClipPlaneSet is an array of ConvexClipPlaneSet representing the union of all of these sets...
Definition: ClipPlaneSet.h:178
struct Transform const & TransformCR
Definition: msgeomstructs_typedefs.h:134
bool TestRayIntersect(DPoint3dCR point, DVec3dCR direction) const
Test for intersection with ray.
bool IsSphereInside(DPoint3dCR point, double radius) const
Test if point is inside to supplied tolerance.
Definition: ClipPlaneSet.h:18
void PushFromCache()
Definition: ClipPlaneSet.h:46
! A ConvexClipPlaneSet is an array of planes oriented so the intersection of their inside halfspaces ...
Definition: ClipPlaneSet.h:89
pointer data()
Definition: stdcxx/bvector.h:322
#define BEGIN_BENTLEY_GEOMETRY_NAMESPACE
Definition: Bentley.r.h:29
struct DPoint3d const & DPoint3dCR
Definition: msgeomstructs_typedefs.h:79
static ConvexClipPlaneSet FromXYPolyLine(bvector< DPoint3d > &points, bvector< bool > &hiddenEdge, bool leftIsInside)
Create clip plane set from XY polygon.
BEGIN_BENTLEY_GEOMETRY_NAMESPACE typedef bvector< ClipPlane > T_ClipPlanes
Definition: ClipPlaneSet.h:13
bvector< ClipPlaneSet > T_ClipPlaneSets
Definition: ClipPlaneSet.h:232
reference back()
Definition: stdcxx/bvector.h:325
struct ClipPlane const * ClipPlaneCP
Definition: msgeomstructs_typedefs.h:93
struct DVec3d const & DVec3dCR
Definition: msgeomstructs_typedefs.h:89
Definition: ClipPlaneSet.h:27
ClipPlaneContainment ClassifyPointContainment(DPoint3dCP points, size_t nPoints, bool onIsOutside=false) const
return a summary classification
bool GetRayIntersection(double &tNear, DPoint3dCR point, DVec3dCR direction) const
Get nearest intersect distance along ray.
void ConvexPolygonClip(bvector< DPoint3d > const &input, bvector< DPoint3d > &output, bvector< DPoint3d > &work) const
Return the (polygon) of intersection.
ConvexClipPlaneSet(size_t n)
Create convex plane set of specified size.
Definition: ClipPlaneSet.h:95

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.