www.cemf.ir
collisionCheck.cpp
Go to the documentation of this file.
1 #include "collisionCheck.hpp"
2 
3 bool
5 {
6  fill(head_, static_cast<uint32>(-1));
7  fill(next_, static_cast<uint32>(-1));
8 
9  for (auto i = 0uL; i < position_.size(); i++)
10  {
12  {
14  "Point "<< position_[i]<< "is not in search box"<<endl;
15  }
16 
17  const auto ind = pointIndex(position_[i]);
18  next_[i] = head_(ind.x(), ind.y(), ind.z());
19  head_(ind.x(), ind.y(), ind.z()) = static_cast<uint32>(i);
20  }
21 
22  return true;
23 }
24 
26  box sBox,
27  real dx,
28  const realx3Vector& pos,
29  const realVector& diam
30 )
31  : searchBox_(sBox),
32  dx_(dx),
33  nCells_((sBox.maxPoint() - sBox.minPoint()) / dx + realx3(1.0)),
34  position_(pos),
35  diameters_(diam),
36  next_("next", pos.size()),
37  head_("head", nCells_.x(), nCells_.y(), nCells_.z())
38 {
39  if(!build())
40  {
41  fatalExit;
42  }
43 }
44 
45 bool
47 {
48 
49  if(!searchBox_.isInside(p)) return false;
50 
51  const auto ind = pointIndex(p);
52  const auto startInd = max(ind - 1 ,int32x3(0));
53  const auto endInd = min( ind+1 ,nCells_-1);
54 
55  for(int32 i=startInd.x(); i<=endInd.x(); i++)
56  {
57  for(int32 j=startInd.y(); j<=endInd.y(); j++)
58  {
59  for(int32 k=startInd.z(); k<=endInd.z(); k++)
60  {
61  uint32 n = head_(i, j, k);
62 
63  while( n != static_cast<uint32>(-1))
64  {
65  if( ((position_[n]-p).length() - 0.5*(diameters_[n]+d )) <= 0.0 )
66  {
67  return false;
68  }
69  n = next_[n];
70  }
71  }
72  }
73  }
74 
75  return true;
76 }
77 
78 bool
80 {
81  size_t n = position_.size()-1;
82  if( next_.size() != n )
83  {
85  "size mismatch of next and position"<<endl;
86  return false;
87  }
88  next_.push_back(static_cast<uint32>(-1));
89  const auto& p = position_[n];
90 
91  if(!searchBox_.isInside(p))
92  {
94  "Point "<< p <<" is not inside the search box"<<endl;
95  return false;
96  }
97 
98  const auto ind = pointIndex(p);
99 
100  next_[n] = head_(ind.x(), ind.y(), ind.z());
101  head_(ind.x(), ind.y(), ind.z()) = static_cast<uint32>(n);
102 
103  return true;
104 }
pFlow::collisionCheck::build
bool build()
Definition: collisionCheck.cpp:4
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::fill
void fill(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:44
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::collisionCheck::collisionCheck
collisionCheck(box sBox, real dx, const realx3Vector &pos, const realVector &diam)
Definition: collisionCheck.cpp:25
pFlow::collisionCheck::head_
ViewType3D< uint32, HostSpace > head_
Definition: collisionCheck.hpp:29
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::Vector::size
auto size() const
Size of the vector.
Definition: Vector.hpp:265
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::collisionCheck::pointIndex
int32x3 pointIndex(const realx3 &p) const
Definition: collisionCheck.hpp:31
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::collisionCheck::mapLastAddedParticle
bool mapLastAddedParticle()
Definition: collisionCheck.cpp:79
pFlow::collisionCheck::searchBox_
box searchBox_
Definition: collisionCheck.hpp:17
collisionCheck.hpp
pFlow::collisionCheck::position_
const realx3Vector & position_
Definition: collisionCheck.hpp:23
pFlow::collisionCheck::checkPoint
bool checkPoint(const realx3 &p, const real d) const
Definition: collisionCheck.cpp:46
pFlow::collisionCheck::next_
uint32Vector next_
Definition: collisionCheck.hpp:27
pFlow::int32x3
triple< int32 > int32x3
Definition: types.hpp:38
pFlow::min
T min(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:28
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::box
Definition: box.hpp:32
pFlow::triple< real >
pFlow::box::isInside
INLINE_FUNCTION_HD bool isInside(const realx3 &point) const
Definition: box.hpp:84
pFlow::Vector< realx3 >