black_hole/preprocess/definitions.h

This file defines the types used in the preprocessing functions that generate the precomputed textures of our black hole model. A GLSL equivalent of this file is used in the GLSL functions that implement this model.

To increase the code readability we introduce different types for dimensionless quantities and for angles, as well as for the two precomputed textures of our model:

#ifndef BLACK_HOLE_PREPROCESS_DEFINITIONS_H_
#define BLACK_HOLE_PREPROCESS_DEFINITIONS_H_

#include "math/angle.h"
#include "math/binary_function.h"
#include "math/scalar.h"

namespace black_hole {
namespace preprocess {

// Provides the C++ equivalent of 'definitions.glsl', used to compile the main
// functions of our black hole shader with a C++ compiler (both to reuse them in
// order to precompute the textures they need, and for testing them).

constexpr int RAY_DEFLECTION_TEXTURE_WIDTH = 512;
constexpr int RAY_DEFLECTION_TEXTURE_HEIGHT = 512;

constexpr int RAY_INVERSE_RADIUS_TEXTURE_WIDTH = 64;
constexpr int RAY_INVERSE_RADIUS_TEXTURE_HEIGHT = 32;

template <typename T1, typename T2>
struct Tuple2 {
  T1 x;
  T2 y;
  inline constexpr Tuple2() {}
  inline constexpr Tuple2(const T1 x, const T2 y) : x(x), y(y) {}

  inline Tuple2 operator+(const Tuple2& rhs) const {
    return Tuple2(x + rhs.x, y + rhs.y);
  }
  inline Tuple2& operator+=(const Tuple2& rhs) {
    x += rhs.x;
    y += rhs.y;
    return *this;
  }
  inline Tuple2 operator*(const double rhs) const {
    return Tuple2(x * rhs, y * rhs);
  }
};

typedef dimensional::Scalar<0, 0, 0, 0, 0> Real;

typedef Tuple2<dimensional::Angle, Real> TimedAngle;

typedef Tuple2<Real, Real> TimedInverseDistance;

typedef dimensional::BinaryFunction<RAY_DEFLECTION_TEXTURE_WIDTH,
                                    RAY_DEFLECTION_TEXTURE_HEIGHT, TimedAngle>
    RayDeflectionTexture;

typedef dimensional::BinaryFunction<RAY_INVERSE_RADIUS_TEXTURE_WIDTH,
                                    RAY_INVERSE_RADIUS_TEXTURE_HEIGHT,
                                    TimedInverseDistance>
    RayInverseRadiusTexture;

}  // namespace preprocess
}  // namespace black_hole

#endif  // BLACK_HOLE_PREPROCESS_DEFINITIONS_H_