SPH
src
core
sph
initial
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
6
NAMESPACE_SPH_BEGIN
7
8
class
IUvMapping
:
public
Polymorphic
{
9
public
:
10
virtual
Array<Vector>
generate
(
const
Storage
& storage)
const
= 0;
11
};
12
13
class
SphericalUvMapping
:
public
IUvMapping
{
14
public
:
15
virtual
Array<Vector>
generate
(
const
Storage
& storage)
const override
{
16
SPH_ASSERT
(storage.
getMaterialCnt
() == 1);
17
18
ArrayView<const Vector>
r = storage.
getValue
<
Vector
>(
QuantityId::POSITION
);
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
39
ArrayView<const Vector>
r = storage.
getValue
<
Vector
>(
QuantityId::POSITION
);
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
54
NAMESPACE_SPH_END
SPH_ASSERT
#define SPH_ASSERT(x,...)
Definition:
Assert.h:94
NAMESPACE_SPH_BEGIN
NAMESPACE_SPH_BEGIN
Definition:
BarnesHut.cpp:13
Box.h
Object representing a three-dimensional axis-aligned box.
Size
uint32_t Size
Integral type used to index arrays (by default).
Definition:
Globals.h:16
PI
constexpr Float PI
Mathematical constants.
Definition:
MathUtils.h:361
NAMESPACE_SPH_END
#define NAMESPACE_SPH_END
Definition:
Object.h:12
QuantityId::POSITION
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
getBoundingBox
Box getBoundingBox(const Storage &storage, const Float radius)
Convenience function to get the bounding box of all particles.
Definition:
Storage.cpp:832
Storage.h
Container for storing particle quantities and materials.
cartensianToSpherical
INLINE SphericalCoords cartensianToSpherical(const Vector &v)
Converts vector in cartesian coordinates to spherical coordinates.
Definition:
Vector.h:806
Vector
BasicVector< Float > Vector
Definition:
Vector.h:539
Y
@ Y
Definition:
Vector.h:23
X
@ X
Definition:
Vector.h:22
Z
@ Z
Definition:
Vector.h:24
ArrayView
Object providing safe access to continuous memory of data.
Definition:
ArrayView.h:17
ArrayView::size
INLINE TCounter size() const
Definition:
ArrayView.h:101
Array
Generic dynamically allocated resizable storage.
Definition:
Array.h:43
BasicVector< Float >
Box
Helper object defining three-dimensional interval (box).
Definition:
Box.h:17
IUvMapping
Definition:
UvMapping.h:8
IUvMapping::generate
virtual Array< Vector > generate(const Storage &storage) const =0
PlanarUvMapping
Definition:
UvMapping.h:34
PlanarUvMapping::generate
virtual Array< Vector > generate(const Storage &storage) const override
Definition:
UvMapping.h:36
SphericalUvMapping
Definition:
UvMapping.h:13
SphericalUvMapping::generate
virtual Array< Vector > generate(const Storage &storage) const override
Definition:
UvMapping.h:15
Storage
Container storing all quantities used within the simulations.
Definition:
Storage.h:230
Storage::getMaterialCnt
Size getMaterialCnt() const
Return the number of materials in the storage.
Definition:
Storage.cpp:437
Storage::getValue
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
Definition:
Storage.cpp:191
Post::getCenterOfMass
Vector getCenterOfMass(ArrayView< const Float > m, ArrayView< const Vector > r, ArrayView< const Size > idxs=nullptr)
Computes the center of mass.
Definition:
Analysis.cpp:461
Polymorphic
Base class for all polymorphic objects.
Definition:
Object.h:88
SphericalCoords
Definition:
Vector.h:799
SphericalCoords::phi
Float phi
longitude
Definition:
Vector.h:802
SphericalCoords::theta
Float theta
latitude
Definition:
Vector.h:801
Generated by
1.9.1