14 auto iter = std::find(pi.
begin(), pi.
end(), index);
15 if (iter != pi.
end()) {
32 for (
Size i = 0; i < r.
size(); ++i) {
38 std::nth_element(x.begin(), x.begin() + mid, x.end());
41 return {
Vector(x[mid], y[mid], z[mid]) + offset,
Vector(0._f) };
56 void OrthoCamera::update() {
59 cached.v -=
dot(cached.v, cached.w) * cached.w;
60 cached.u =
cross(cached.v, cached.w);
63 float OrthoCamera::estimateFov(
const Storage& storage)
const {
78 for (
Size i = 0; i < r.
size(); ++i) {
86 for (
Size i = 0; i < r.
size(); ++i) {
87 const Vector dr = r[i] - r_com;
88 distances[i] =
getLength(dr - cached.w *
dot(cached.w, dr));
92 std::nth_element(distances.begin(), distances.begin() + mid, distances.end());
100 data.
ortho.
fov = this->estimateFov(storage);
111 const float x = float(
dot(r - data.
position, cached.u)) * fov;
112 const float y = float(
dot(r - data.
position, cached.v)) * fov;
114 return { { point, fov * float(r[
H]) } };
119 const float rx = (coords.
x - data.
imageSize.
x * 0.5f) / fov;
120 const float ry = (data.
imageSize.
y * 0.5f - coords.
y - 1) / fov;
126 ray.
origin -= cached.w * scale;
133 return unprojectImpl(coords,
true);
167 const Vector fixed1 = this->unprojectImpl(
Coords(fixedPoint),
false)->origin;
169 const Vector fixed2 = this->unprojectImpl(
Coords(fixedPoint),
false)->origin;
170 const Vector dp = fixed1 - fixed2;
194 cached.u = matrix * cached.u;
195 cached.v = matrix * cached.v;
196 cached.w =
cross(cached.u, cached.v);
204 const Vector dp = -offset.
x / fov * cached.u - offset.
y / fov * cached.v;
241 const Float proj =
dot(dr, cached.dir);
246 const Vector r0 = dr / proj;
254 const float leftRel = float(
dot(left0, r0) / leftLength);
255 const float upRel = float(
dot(up0, r0) / upLength);
256 const float x = 0.5f * (1.f + leftRel) * data.
imageSize.
x;
257 const float y = 0.5f * (1.f + upRel) * data.
imageSize.
y;
258 const float hAtUnitDist = float(r[
H] / proj);
259 const float h = hAtUnitDist / float(leftLength) * float(data.
imageSize.
x);
265 const float rx = 2.f * coords.
x / data.
imageSize.
x - 1.f;
266 const float ry = 2.f * coords.
y / data.
imageSize.
y - 1.f;
267 const Vector dir = cached.dir + cached.left * rx - cached.up * ry;
324 cached.dir = matrix * cached.dir;
325 cached.up = matrix * cached.up;
326 cached.left = matrix * cached.left;
334 data.
target -= worldOffset;
342 void PerspectiveCamera::update() {
353 cached.up = tgfov / aspect *
up;
454 const Coords p = (coords - cached.center) / cached.radius;
472 void FisheyeCamera::update() {
484 cached.radius =
min(cached.center.x, cached.center.y);
ArrayRef< T > makeArrayRef(Array< T > &data, const RefEnum type)
#define SPH_ASSERT(x,...)
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
Object representing a three-dimensional axis-aligned box.
Defines projection transforming 3D particles onto 2D screen.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
constexpr INLINE T max(const T &f1, const T &f2)
NAMESPACE_SPH_BEGIN constexpr INLINE T min(const T &f1, const T &f2)
Minimum & Maximum value.
INLINE T atan2(const T y, const T x)
INLINE auto abs(const T &f)
constexpr Float PI
Mathematical constants.
#define NAMESPACE_SPH_END
const NothingType NOTHING
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
@ MASS
Paricles masses, always a scalar quantity.
Holder of quantity values and their temporal derivatives.
Container for storing particle quantities and materials.
INLINE Tuple< TArgs &... > tieToTuple(TArgs &... args)
Creates a tuple of l-value references. Use IGNORE placeholder to omit one or more parameters.
INLINE Float getLength(const Vector &v)
Returns the length of the vector. Enabled only for vectors of floating-point precision.
INLINE Tuple< Vector, Float > getNormalizedWithLength(const Vector &v)
Returns normalized vector and length of the input vector as tuple.
INLINE BasicVector< float > cross(const BasicVector< float > &v1, const BasicVector< float > &v2)
Cross product between two vectors.
BasicVector< Float > Vector
INLINE float dot(const BasicVector< float > &v1, const BasicVector< float > &v2)
Make sure the vector is trivially constructible and destructible, needed for fast initialization of a...
INLINE Vector sphericalToCartesian(const Float r, const Float theta, const Float phi)
Constructs a vector from spherical coordinates.
INLINE Vector getNormalized(const Vector &v)
INLINE AffineMatrix & translate(const Vector &t)
AffineMatrix inverse() const
INLINE AffineMatrix & removeTranslation()
INLINE TCounter size() const
INLINE Iterator< StorageType > begin()
INLINE Iterator< StorageType > end()
INLINE Iterator< StorageType > end() noexcept
INLINE Iterator< StorageType > begin() noexcept
virtual Optional< CameraRay > unproject(const Coords &coords) const override
Returns a ray in particle coordinates corresponding to given coordinates in the image plane.
FisheyeCamera(const CameraParams &data)
INLINE Float lower() const
Returns lower bound of the interval.
INLINE Float size() const
Returns the size of the interval.
INLINE bool contains(const Float &value) const
Checks whether value is inside the interval.
Wrapper of type value of which may or may not be present.
virtual Optional< float > getCutoff() const override
Returns the clipping distance from plane passing through origin, perpendicular to camera direction.
virtual AffineMatrix getFrame() const override
Returns the transformation matrix converting camera space to world space.
virtual void transform(const AffineMatrix &matrix) override
Transforms the current view by given matrix.
virtual void resize(const Pixel newSize) override
Changes the image size.
virtual Optional< float > getWorldToPixel() const override
Returns the world-to-pixel ratio.
virtual void zoom(const Pixel fixedPoint, const float magnitude) override
virtual void setPosition(const Vector &newPosition) override
Moves the camera to new position in world space.
virtual Pixel getSize() const override
Returns the current resolution of the camera.
virtual Vector getUpVector() const override
Returns the reference "up" direction of the camera.
OrthoCamera(const CameraParams &data)
virtual void setCutoff(const Optional< float > newCutoff) override
Modifies the clipping distance of the camera.
virtual void autoSetup(const Storage &storage) override
Initializes the camera, using the provided particle storage.
virtual Vector getTarget() const override
Returns the current target point of the camera.
virtual void setTarget(const Vector &newTarget) override
virtual Optional< ProjectedPoint > project(const Vector &r) const override
Returns projected position of particle on the image.
virtual Optional< CameraRay > unproject(const Coords &coords) const override
Returns a ray in particle coordinates corresponding to given coordinates in the image plane.
virtual void pan(const Pixel offset) override
Moves the camera by relative offset in image space.
Common base for panoramic cameras.
virtual Vector getUpVector() const override
Returns the reference "up" direction of the camera.
virtual Optional< float > getCutoff() const override
Returns the clipping distance from plane passing through origin, perpendicular to camera direction.
virtual void setPosition(const Vector &newPosition) override
Moves the camera to new position in world space.
virtual void pan(const Pixel offset) override
Moves the camera by relative offset in image space.
virtual Optional< ProjectedPoint > project(const Vector &r) const override
Returns projected position of particle on the image.
virtual void setTarget(const Vector &newTarget) override
virtual Pixel getSize() const override
Returns the current resolution of the camera.
virtual void autoSetup(const Storage &storage) override
Initializes the camera, using the provided particle storage.
virtual Optional< float > getWorldToPixel() const override
Returns the world-to-pixel ratio.
virtual AffineMatrix getFrame() const override
Returns the transformation matrix converting camera space to world space.
virtual void setCutoff(const Optional< float > newCutoff) override
Modifies the clipping distance of the camera.
virtual void zoom(const Pixel UNUSED(fixedPoint), const float magnitude) override
virtual void transform(const AffineMatrix &matrix) override
Transforms the current view by given matrix.
PanoCameraBase(const CameraParams &data)
virtual Vector getTarget() const override
Returns the current target point of the camera.
virtual void resize(const Pixel newSize) override
Changes the image size.
virtual Pair< Vector > getTrackedPoint(const Storage &storage) const override
Vector dir
Unit direction of the camera.
virtual Pixel getSize() const override
Returns the current resolution of the camera.
virtual AffineMatrix getFrame() const override
Returns the transformation matrix converting camera space to world space.
virtual void setCutoff(const Optional< float > newCutoff) override
Modifies the clipping distance of the camera.
virtual Vector getUpVector() const override
Returns the reference "up" direction of the camera.
virtual Optional< ProjectedPoint > project(const Vector &r) const override
Returns projected position of particle on the image.
virtual void setTarget(const Vector &newTarget) override
virtual Optional< float > getWorldToPixel() const override
Returns the world-to-pixel ratio.
virtual void transform(const AffineMatrix &matrix) override
Transforms the current view by given matrix.
virtual void setPosition(const Vector &newPosition) override
Moves the camera to new position in world space.
virtual void autoSetup(const Storage &storage) override
Initializes the camera, using the provided particle storage.
virtual Vector getTarget() const override
Returns the current target point of the camera.
virtual void resize(const Pixel newSize) override
Changes the image size.
virtual void pan(const Pixel offset) override
Moves the camera by relative offset in image space.
virtual Optional< float > getCutoff() const override
Returns the clipping distance from plane passing through origin, perpendicular to camera direction.
Vector up
Up vector of the camera, size of which of represents the image size at unit distance.
virtual void zoom(const Pixel UNUSED(fixedPoint), const float magnitude) override
virtual Optional< CameraRay > unproject(const Coords &coords) const override
Returns a ray in particle coordinates corresponding to given coordinates in the image plane.
PerspectiveCamera(const CameraParams &data)
Generic container for storing scalar, vector or tensor quantity and its derivatives.
INLINE Array< TValue > & getValue()
Returns a reference to array of quantity values.
INLINE Array< TValue > & getDt()
Returns a reference to array of first derivatives of quantity.
SphericalCamera(const CameraParams &data)
virtual Optional< CameraRay > unproject(const Coords &coords) const override
Returns a ray in particle coordinates corresponding to given coordinates in the image plane.
Array with fixed number of allocated elements.
Container storing all quantities used within the simulations.
Quantity & getQuantity(const QuantityId key)
Retrieves quantity with given key from the storage.
Size getParticleCnt() const
Returns the number of particles.
bool has(const QuantityId key) const
Checks if the storage contains quantity with given key.
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
struct CameraParams::@20 perspective
Pixel imageSize
Size of the image.
struct CameraParams::@21 ortho
Float fov
Field of view (angle)
Vector position
Camera position in space.
Optional< float > cutoff
Cutoff distance of the camera.
Interval clipping
Defines the clipping planes of the camera.
Vector target
Look-at point in space.
Vector up
Up vector of the camera (direction)
Ray given by origin and target point.
Represents a particle projected onto image plane.