ParticleSystemData2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: ParticleSystemData2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D particle system data.
6 > Created Time: 2017/04/28
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_PARTICLE_SYSTEM_DATA2_H
10 #define CUBBYFLOW_PARTICLE_SYSTEM_DATA2_H
11 
12 #include <Core/Array/Array1.h>
15 #include <Core/Vector/Vector2.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 ParticleSystemData2;
33  }
34 }
35 
36 #endif
37 
38 namespace CubbyFlow
39 {
48  {
49  public:
52 
55 
58 
60  explicit ParticleSystemData2(size_t numberOfParticles);
61 
64 
66  virtual ~ParticleSystemData2();
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 Vector2D& initialVal = Vector2D());
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 Vector2D& newPosition,
162  const Vector2D& newVelocity = Vector2D(),
163  const Vector2D& newForce = Vector2D());
164 
178  void AddParticles(
179  const ConstArrayAccessor1<Vector2D>& newPositions,
182 
192 
194  void SetNeighborSearcher(const PointNeighborSearcher2Ptr& 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 ParticleSystemData2& other);
221 
224 
225  protected:
227  flatbuffers::FlatBufferBuilder* builder,
228  flatbuffers::Offset<fbs::ParticleSystemData2>* fbsParticleSystemData)
229  const;
230 
232  const fbs::ParticleSystemData2* 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  PointNeighborSearcher2Ptr m_neighborSearcher;
246  std::vector<std::vector<size_t>> m_neighborLists;
247  };
248 
250  using ParticleSystemData2Ptr = std::shared_ptr<ParticleSystemData2>;
251 }
252 
253 #endif
ConstArrayAccessor1< Vector2D > GetVelocities() const
Returns the velocity array (immutable).
double GetRadius() const
Returns the radius of the particles.
Abstract base class for any serializable class.
Definition: Serialization.h:20
ParticleSystemData2()
Default constructor.
void Resize(size_t newNumberOfParticles)
Resizes the number of particles of the container.
ParticleSystemData2 & operator=(const ParticleSystemData2 &other)
Copies from other particle system data.
void SetNeighborSearcher(const PointNeighborSearcher2Ptr &newNeighborSearcher)
Sets neighbor searcher.
void Set(const ParticleSystemData2 &other)
Copies from other particle system data.
2-D particle system data.
Definition: ParticleSystemData2.h:47
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes this particle system data from the buffer.
ConstArrayAccessor1< Vector2D > GetForces() const
Returns the force array (immutable).
size_t AddVectorData(const Vector2D &initialVal=Vector2D())
Adds a vector data layer and returns its index.
virtual void SetRadius(double newRadius)
Sets the radius of the particles.
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
void BuildNeighborLists(double maxSearchRadius)
Builds neighbor lists with given search radius.
std::shared_ptr< ParticleSystemData2 > ParticleSystemData2Ptr
Shared pointer type of ParticleSystemData2.
Definition: ParticleSystemData2.h:250
void AddParticles(const ConstArrayAccessor1< Vector2D > &newPositions, const ConstArrayAccessor1< Vector2D > &newVelocities=ConstArrayAccessor1< Vector2D >(), const ConstArrayAccessor1< Vector2D > &newForces=ConstArrayAccessor1< Vector2D >())
Adds particles to the data structure.
double GetMass() const
Returns the mass of the particles.
1-D array class.
Definition: Array1.h:29
void AddParticle(const Vector2D &newPosition, const Vector2D &newVelocity=Vector2D(), const Vector2D &newForce=Vector2D())
Adds a particle to the data structure.
Definition: pybind11Utils.h:24
size_t AddScalarData(double initialVal=0.0)
Adds a scalar data layer and returns its index.
Vector2< double > Vector2D
Double-type 2D vector.
Definition: Vector2.h:341
ConstArrayAccessor1< Vector2D > GetPositions() const
Returns the position array (immutable).
const std::vector< std::vector< size_t > > & GetNeighborLists() const
Returns neighbor lists.
size_t GetNumberOfParticles() const
Returns the number of particles.
virtual void SetMass(double newMass)
Sets the mass of the particles.
1-D array accessor class.
Definition: ArrayAccessor1.h:28
ConstArrayAccessor1< double > ScalarDataAt(size_t idx) const
Returns custom scalar data layer at given index (immutable).
2-D vector class.
Definition: Vector2.h:26
std::shared_ptr< PointNeighborSearcher2 > PointNeighborSearcher2Ptr
Shared pointer for the PointNeighborSearcher2 type.
Definition: PointNeighborSearcher2.h:79
void SerializeParticleSystemData(flatbuffers::FlatBufferBuilder *builder, flatbuffers::Offset< fbs::ParticleSystemData2 > *fbsParticleSystemData) const
void BuildNeighborSearcher(double maxSearchRadius)
Builds neighbor searcher with given search radius.
void DeserializeParticleSystemData(const fbs::ParticleSystemData2 *fbsParticleSystemData)
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes this particle system data to the buffer.
const PointNeighborSearcher2Ptr & GetNeighborSearcher() const
Returns neighbor searcher.
virtual ~ParticleSystemData2()
Destructor.
ConstArrayAccessor1< Vector2D > VectorDataAt(size_t idx) const
Returns custom vector data layer at given index (immutable).