SPH
UvMapping.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "objects/geometry/Box.h"
4 #include "quantities/Storage.h"
5 
7 
8 class IUvMapping : public Polymorphic {
9 public:
10  virtual Array<Vector> generate(const Storage& storage) const = 0;
11 };
12 
14 public:
15  virtual Array<Vector> generate(const Storage& storage) const override {
16  SPH_ASSERT(storage.getMaterialCnt() == 1);
17 
19  const Vector center = getCenterOfMass(storage);
20  Array<Vector> uvws(r.size());
21 
22  for (Size i = 0; i < r.size(); ++i) {
23  const Vector xyz = r[i] - center;
24  SphericalCoords spherical = cartensianToSpherical(Vector(xyz[X], xyz[Z], xyz[Y]));
25  uvws[i] = Vector(spherical.phi / (2._f * PI) + 0.5_f, spherical.theta / PI, 0._f);
26  SPH_ASSERT(uvws[i][X] >= 0._f && uvws[i][X] <= 1._f, uvws[i][X]);
27  SPH_ASSERT(uvws[i][Y] >= 0._f && uvws[i][Y] <= 1._f, uvws[i][Y]);
28  }
29 
30  return uvws;
31  }
32 };
33 
34 class PlanarUvMapping : public IUvMapping {
35 public:
36  virtual Array<Vector> generate(const Storage& storage) const override {
37  SPH_ASSERT(storage.getMaterialCnt() == 1);
38 
40  const Box bbox = getBoundingBox(storage);
41  Array<Vector> uvws(r.size());
42 
43  for (Size i = 0; i < r.size(); ++i) {
44  const Vector xyz = (r[i] - bbox.lower()) / bbox.size();
45  uvws[i] = Vector(xyz[0], xyz[1], 0._f);
46  SPH_ASSERT(uvws[i][X] >= 0._f && uvws[i][X] <= 1._f, uvws[i][X]);
47  SPH_ASSERT(uvws[i][Y] >= 0._f && uvws[i][Y] <= 1._f, uvws[i][Y]);
48  }
49 
50  return uvws;
51  }
52 };
53 
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Object representing a three-dimensional axis-aligned box.
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
constexpr Float PI
Mathematical constants.
Definition: MathUtils.h:361
#define NAMESPACE_SPH_END
Definition: Object.h:12
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
Box getBoundingBox(const Storage &storage, const Float radius)
Convenience function to get the bounding box of all particles.
Definition: Storage.cpp:832
Container for storing particle quantities and materials.
INLINE SphericalCoords cartensianToSpherical(const Vector &v)
Converts vector in cartesian coordinates to spherical coordinates.
Definition: Vector.h:806
BasicVector< Float > Vector
Definition: Vector.h:539
@ Y
Definition: Vector.h:23
@ X
Definition: Vector.h:22
@ Z
Definition: Vector.h:24
Object providing safe access to continuous memory of data.
Definition: ArrayView.h:17
INLINE TCounter size() const
Definition: ArrayView.h:101
Generic dynamically allocated resizable storage.
Definition: Array.h:43
Helper object defining three-dimensional interval (box).
Definition: Box.h:17
virtual Array< Vector > generate(const Storage &storage) const =0
virtual Array< Vector > generate(const Storage &storage) const override
Definition: UvMapping.h:36
virtual Array< Vector > generate(const Storage &storage) const override
Definition: UvMapping.h:15
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Size getMaterialCnt() const
Return the number of materials in the storage.
Definition: Storage.cpp:437
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Definition: Storage.cpp:191
Vector getCenterOfMass(ArrayView< const Float > m, ArrayView< const Vector > r, ArrayView< const Size > idxs=nullptr)
Computes the center of mass.
Definition: Analysis.cpp:461
Base class for all polymorphic objects.
Definition: Object.h:88
Float phi
longitude
Definition: Vector.h:802
Float theta
latitude
Definition: Vector.h:801