ParticleSystemData3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: ParticleSystemData3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-D particle system data.
6 > Created Time: 2017/05/08
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_PARTICLE_SYSTEM_DATA3_H
10 #define CUBBYFLOW_PARTICLE_SYSTEM_DATA3_H
11 
12 #include <Core/Array/Array1.h>
15 #include <Core/Vector/Vector3.h>
16 
17 #include <memory>
18 #include <vector>
19 
20 #ifndef CUBBYFLOW_DOXYGEN
21 
22 namespace flatbuffers
23 {
24  class FlatBufferBuilder;
25  template <typename T> struct Offset;
26 }
27 
28 namespace CubbyFlow
29 {
30  namespace fbs
31  {
32  struct ParticleSystemData3;
33  }
34 }
35 
36 #endif
37 
38 namespace CubbyFlow
39 {
48  {
49  public:
52 
55 
58 
60  explicit ParticleSystemData3(size_t numberOfParticles);
61 
64 
66  virtual ~ParticleSystemData3();
67 
79  void Resize(size_t newNumberOfParticles);
80 
82  size_t GetNumberOfParticles() const;
83 
92  size_t AddScalarData(double initialVal = 0.0);
93 
102  size_t AddVectorData(const Vector3D& initialVal = Vector3D());
103 
105  double GetRadius() const;
106 
108  virtual void SetRadius(double newRadius);
109 
111  double GetMass() const;
112 
114  virtual void SetMass(double newMass);
115 
118 
121 
124 
127 
130 
133 
135  ConstArrayAccessor1<double> ScalarDataAt(size_t idx) const;
136 
139 
142 
145 
160  void AddParticle(
161  const Vector3D& newPosition,
162  const Vector3D& newVelocity = Vector3D(),
163  const Vector3D& newForce = Vector3D());
164 
178  void AddParticles(
179  const ConstArrayAccessor1<Vector3D>& newPositions,
182 
192 
194  void SetNeighborSearcher(const PointNeighborSearcher3Ptr& newNeighborSearcher);
195 
205  const std::vector<std::vector<size_t>>& GetNeighborLists() const;
206 
208  void BuildNeighborSearcher(double maxSearchRadius);
209 
211  void BuildNeighborLists(double maxSearchRadius);
212 
214  void Serialize(std::vector<uint8_t>* buffer) const override;
215 
217  void Deserialize(const std::vector<uint8_t>& buffer) override;
218 
220  void Set(const ParticleSystemData3& other);
221 
224 
225  protected:
227  flatbuffers::FlatBufferBuilder* builder,
228  flatbuffers::Offset<fbs::ParticleSystemData3>* fbsParticleSystemData)
229  const;
230 
232  const fbs::ParticleSystemData3* fbsParticleSystemData);
233 
234  private:
235  double m_radius = 1e-3;
236  double m_mass = 1e-3;
237  size_t m_numberOfParticles = 0;
238  size_t m_positionIdx;
239  size_t m_velocityIdx;
240  size_t m_forceIdx;
241 
242  std::vector<ScalarData> m_scalarDataList;
243  std::vector<VectorData> m_vectorDataList;
244 
245  PointNeighborSearcher3Ptr m_neighborSearcher;
246  std::vector<std::vector<size_t>> m_neighborLists;
247  };
248 
250  using ParticleSystemData3Ptr = std::shared_ptr<ParticleSystemData3>;
251 }
252 
253 #endif
3-D vector class.
Definition: Vector3.h:26
Abstract base class for any serializable class.
Definition: Serialization.h:20
double GetRadius() const
Returns the radius of the particles.
std::shared_ptr< PointNeighborSearcher3 > PointNeighborSearcher3Ptr
Shared pointer for the PointNeighborSearcher3 type.
Definition: PointNeighborSearcher3.h:79
const std::vector< std::vector< size_t > > & GetNeighborLists() const
Returns neighbor lists.
void SetNeighborSearcher(const PointNeighborSearcher3Ptr &newNeighborSearcher)
Sets neighbor searcher.
size_t AddScalarData(double initialVal=0.0)
Adds a scalar data layer and returns its index.
double GetMass() const
Returns the mass of the particles.
ConstArrayAccessor1< double > ScalarDataAt(size_t idx) const
Returns custom scalar data layer at given index (immutable).
ConstArrayAccessor1< Vector3D > GetVelocities() const
Returns the velocity array (immutable).
void BuildNeighborSearcher(double maxSearchRadius)
Builds neighbor searcher with given search radius.
size_t AddVectorData(const Vector3D &initialVal=Vector3D())
Adds a vector data layer and returns its index.
std::shared_ptr< ParticleSystemData3 > ParticleSystemData3Ptr
Shared pointer type of ParticleSystemData3.
Definition: ParticleSystemData3.h:250
const PointNeighborSearcher3Ptr & GetNeighborSearcher() const
Returns neighbor searcher.
void DeserializeParticleSystemData(const fbs::ParticleSystemData3 *fbsParticleSystemData)
size_t GetNumberOfParticles() const
Returns the number of particles.
virtual void SetMass(double newMass)
Sets the mass of the particles.
ConstArrayAccessor1< Vector3D > GetForces() const
Returns the force array (immutable).
ConstArrayAccessor1< Vector3D > VectorDataAt(size_t idx) const
Returns custom vector data layer at given index (immutable).
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
ParticleSystemData3 & operator=(const ParticleSystemData3 &other)
Copies from other particle system data.
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes this particle system data to the buffer.
1-D array class.
Definition: Array1.h:29
virtual void SetRadius(double newRadius)
Sets the radius of the particles.
Definition: pybind11Utils.h:24
ConstArrayAccessor1< Vector3D > GetPositions() const
Returns the position array (immutable).
void AddParticle(const Vector3D &newPosition, const Vector3D &newVelocity=Vector3D(), const Vector3D &newForce=Vector3D())
Adds a particle to the data structure.
ParticleSystemData3()
Default constructor.
void Set(const ParticleSystemData3 &other)
Copies from other particle system data.
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes this particle system data from the buffer.
1-D array accessor class.
Definition: ArrayAccessor1.h:28
void SerializeParticleSystemData(flatbuffers::FlatBufferBuilder *builder, flatbuffers::Offset< fbs::ParticleSystemData3 > *fbsParticleSystemData) const
3-D particle system data.
Definition: ParticleSystemData3.h:47
void Resize(size_t newNumberOfParticles)
Resizes the number of particles of the container.
virtual ~ParticleSystemData3()
Destructor.
void BuildNeighborLists(double maxSearchRadius)
Builds neighbor lists with given search radius.
void AddParticles(const ConstArrayAccessor1< Vector3D > &newPositions, const ConstArrayAccessor1< Vector3D > &newVelocities=ConstArrayAccessor1< Vector3D >(), const ConstArrayAccessor1< Vector3D > &newForces=ConstArrayAccessor1< Vector3D >())
Adds particles to the data structure.
Vector3< double > Vector3D
Double-type 3D vector.
Definition: Vector3.h:353