32 Coords dir = p2->coords - p1->coords;
37 dir *= float(length / l);
38 const Coords c1 = p1->coords;
39 const Coords c2 = p1->coords + dir;
58 const Rgba& lineColor,
62 for (
int i = 0; i < size.
y; ++i) {
81 const Size ticsCnt = 5;
83 for (
Size i = 0; i < ticsCnt; ++i) {
92 for (
Float tic : tics) {
94 const int i = int(value * size.
y);
110 if (dir ==
Vector(0._f, 0._f, 1._f)) {
111 perpDir =
Vector(1._f, 0._f, 0._f);
117 const Coords shifted = camera.
project(originRay->origin + grid * perpDir)->coords;
124 for (
float x = origin.
x; x < size.
x; x += dx) {
127 for (
float x = origin.
x - dx; x >= 0; x -= dx) {
130 for (
float y = origin.
y; y < size.
y; y += dy) {
133 for (
float y = origin.
y - dy; y >= 0; y -= dy) {
142 const Rgba& background) {
143 const Coords keyStart(5, 2);
153 const float dFov_dPx = 1.f / wtp;
154 const float minimalScaleFov = dFov_dPx * 16;
155 float actScaleFov =
pow(10.f,
ceil(
log10(minimalScaleFov)));
156 const float scaleSize = actScaleFov / dFov_dPx;
159 context.
drawLine(lineStart +
Coords(-scaleSize / 2, -4), lineStart +
Coords(-scaleSize / 2, 4));
160 context.
drawLine(lineStart +
Coords(scaleSize / 2 + 1, -4), lineStart +
Coords(scaleSize / 2 + 1, 4));
164 std::wstring units = L
" m";
168 }
else if (actScaleFov > 1.e3f) {
169 actScaleFov /= 1.e3f;
173 if (scaleText.find(L
'\u00D7') != std::wstring::npos) {
175 scaleText = scaleText.substr(3);
177 context.
drawText(lineStart +
Coords(0, 6), flags, scaleText + units);
181 const float length = 40;
185 context.
drawLine(origin, origin + dir);
192 shouldContinue =
true;
196 return cutoff &&
abs(
dot(direction, r)) > cutoff.
value();
204 cached.positions.clear();
205 cached.colors.clear();
206 cached.vectors.clear();
210 bool hasVectorData = bool(colorizer.
evalVector(0));
212 for (
Size i = 0; i < r.
size(); ++i) {
214 if (p && !isCutOff(r[i], cutoff, direction)) {
216 cached.positions.push(r[i]);
219 cached.colors.push(color);
224 cached.vectors.push(v.
value());
231 for (
Size i = 0; i < ghosts->size(); ++i) {
232 const Vector pos = ghosts->getGhost(i).position;
234 if (p && !isCutOff(pos, cutoff, direction)) {
235 cached.idxs.push(
Size(-1));
236 cached.positions.push(pos);
240 cached.vectors.push(
Vector(0._f));
247 Order order(cached.positions.size());
249 const Vector r1 = cached.positions[i];
250 const Vector r2 = cached.positions[j];
251 return dot(direction, r1) >
dot(direction, r2);
254 cached.positions = order.
apply(cached.positions);
255 cached.idxs = order.
apply(cached.idxs);
256 cached.colors = order.
apply(cached.colors);
258 cached.cameraDir = direction;
261 cached.vectors = order.
apply(cached.vectors);
263 cached.vectors.clear();
270 return !cached.positions.empty();
277 return makeAuto<SmoothedRenderContext>(bitmap, kernel);
279 return makeAuto<AntiAliasedRenderContext>(bitmap);
283 return makeAuto<PreviewRenderContext<OverridePixelOp>>(bitmap);
285 return makeAuto<PreviewRenderContext<OverPixelOp>>(bitmap);
300 drawGrid(*context, *params.
camera, grid);
311 shouldContinue =
true;
314 for (
Size k = 0; k < cached.positions.size(); ++k) {
315 const Size i = reverseOrder ? cached.positions.size() - k - 1 : k;
324 if (!cached.vectors.empty()) {
326 dir.v = cached.vectors[i];
327 dir.r = cached.positions[i];
330 Rgba color = cached.colors[i];
335 if (cached.idxs[i] ==
Size(-1)) {
352 if (cached.palette) {
353 const Pixel origin(context->
size().
x - 50, 231);
357 cached.palette->transform([](
const Rgba& color) {
return Rgba(color.
intensity()); });
359 palette = cached.palette.value();
367 drawKey(*context, stats, wtp.value(), fps, params.
background);
388 shouldContinue =
false;
#define SPH_ASSERT(x,...)
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
Defines projection transforming 3D particles onto 2D screen.
Helper functions to check the internal consistency of the code.
Object converting quantity values of particles into colors.
Wraps a functor and executes it once the wrapper goes out of scope.
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 Float pow(const Float v)
Power for floats.
constexpr Float DEG_TO_RAD
INLINE T log10(const T f)
INLINE auto ceil(const T &f)
INLINE auto abs(const T &f)
#define NAMESPACE_SPH_END
Helper object defining permutation.
@ HYBRID
Logarithic scale for values > 1 and < -1, linear scale on interval <-1, 1>
@ LINEAR
Control points are interpolated on linear scale.
@ LOGARITHMIC
Control points are interpolated on logarithmic scale. All points must be positive!
void drawAxis(IRenderContext &context, const Rgba &color, const Vector &axis, const std::string &label)
void drawPalette(IRenderContext &context, const Pixel origin, const Pixel size, const Rgba &lineColor, const Palette &palette)
Renderer drawing individual particles as dots.
Array< Float > getLinearTics(const Interval &interval, const Size minCount)
Returns the tics to be drawn on a linear axis of a plot.
Array< Float > getLogTics(const Interval &interval, const Size minCount)
Returns the tics to be drawn on a logarithmic axis of a plot.
Drawing quantity values as functions of time or spatial coordinates.
Tool to measure time spent in functions and profile the code.
#define MEASURE_SCOPE(name)
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
Statistics gathered and periodically displayed during the run.
@ RUN_TIME
Current time of the simulation in code units. Does not necessarily have to be 0 when run starts.
String getFormattedTime(const String &format)
Utility functions.
std::wstring toPrintableString(const Float value, const Size precision, const Float decimalThreshold)
Converts the value to a printable string.
Random utility functions for drawing stuff to DC.
INLINE Float getLength(const Vector &v)
Returns the length of the vector. Enabled only for vectors of floating-point precision.
INLINE Float getSqrLength(const Vector &v)
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 getNormalized(const Vector &v)
PlotPoint transformPoint(const PlotPoint &p) const
Applies the affine transform on given point.
static AffineMatrix2 rotate(const Float phi)
Create a rotation matrix.
AffineMatrix2 transpose() const
Returns the transposed matrix.
INLINE Vector row(const Size idx) const
AffineMatrix inverse() const
Object providing safe access to continuous memory of data.
INLINE TCounter size() const
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
Cubic spline (M4) kernel.
INLINE TValue get(const GuiSettingsId id) const
Interface defining a camera or view, used by a renderer.
virtual Optional< float > getCutoff() const =0
Returns the clipping distance from plane passing through origin, perpendicular to camera direction.
virtual Pixel getSize() const =0
Returns the current resolution of the camera.
virtual AffineMatrix getFrame() const =0
Returns the transformation matrix converting camera space to world space.
virtual Optional< float > getWorldToPixel() const =0
Returns the world-to-pixel ratio.
virtual Optional< ProjectedPoint > project(const Vector &r) const =0
Returns projected position of particle on the image.
virtual Optional< CameraRay > unproject(const Coords &coords) const =0
Returns a ray in particle coordinates corresponding to given coordinates in the image plane.
Interface for objects assigning colors to particles.
virtual Optional< Palette > getPalette() const =0
Returns recommended palette for drawing this colorizer.
virtual Optional< Vector > evalVector(const Size UNUSED(idx)) const
Returns the vector representation of the colorized quantity for idx-th particle.
virtual Rgba evalColor(const Size idx) const =0
Returns the color of idx-th particle.
Abstraction of a device used for rendering.
virtual void drawCircle(const Coords center, const float radius)=0
Draws a circle, given its center and a radius.
virtual void drawLine(const Coords p1, const Coords p2)=0
Draws a line connecting two points.
virtual void drawText(const Coords p, const Flags< TextAlign > align, const std::string &s)=0
virtual void setColor(const Rgba &color, const Flags< ColorFlag > flags)=0
Selects the color for one or more drawing modes.
virtual Array< IRenderOutput::Label > getLabels() const
virtual void setThickness(const float thickness)=0
Modifies the thickness of the lines.
virtual void fill(const Rgba &color)=0
Fills the whole canvas with given color.
virtual Pixel size() const =0
Returns the size of the canvas associated with the context.
virtual void update(const Bitmap< Rgba > &bitmap, Array< Label > &&labels, const bool isFinal)=0
May be called once after render finishes or multiple times for progressive renderers.
Object representing a 1D interval of real numbers.
Wrapper of type value of which may or may not be present.
INLINE Type & value()
Returns the reference to the stored value.
Permutation, i.e. (discrete) invertible function int->int.
Array< T > apply(const Array< T > &input)
Shuffles given array using this order.
void shuffle(TBinaryPredicate &&predicate)
Shuffles the order using a binary predicate.
Represents a color palette, used for mapping arbitrary number to a color.
float relativeToPalette(const float value) const
Converts a relative position to an absolute position on a palette.
PaletteScale getScale() const
Returns the scale of the palette.
float paletteToRelative(const float value) const
Inverse transform to relativeToPalette.
Interval getInterval() const
Returns the interval for which the palette is defined.
ParticleRenderer(const GuiSettings &settings)
Optional< Palette > palette
Color palette or NOTHING if no palette is drawn.
virtual bool isInitialized() const override
Checks if the renderer has been initialized.
virtual void initialize(const Storage &storage, const IColorizer &colorizer, const ICamera &camera) override
Prepares the objects for rendering and updates its data.
virtual void render(const RenderParams ¶ms, Statistics &stats, IRenderOutput &output) const override
Draws particles into the bitmap, given the data provided in initialize.
virtual void cancelRender() override
Stops the rendering if it is currently in progress.
Non-owning wrapper of pointer.
Rgba brighten(const float amount) const
Returns a color brighter by given factor.
static Rgba gray(const float value=0.5f)
Rgba inverse() const
Returns an inverse color.
float intensity() const
Returns the average intensity of the color.
static Rgba transparent()
INLINE RawPtr< T > get() const
Object holding various statistics about current run.
TValue get(const StatisticsId idx) const
Returns value of a statistic.
bool has(const StatisticsId idx) const
Checks if the object contains a statistic with given ID.
Container storing all quantities used within the simulations.
SharedPtr< IStorageUserData > getUserData() const
Returns the stored user data.
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
int64_t elapsed(const TimerUnit unit) const
Returns elapsed time in timer units. Does not reset the timer.
void restart()
Reset elapsed duration to zero.
2D point and other primitives for 2D geometry
@ VIEW_GRID_SIZE
Size of the grid cell in simulation units (not window units); if zero, no grid is drawn.
constexpr Float au
Astronomical unit (exactly)
Parameters of the rendered image.
Optional< Size > selected
Highlighted particle (only for interactive view).
Rgba background
Background color of the rendered image.
struct RenderParams::@33 particles
Parameters of the particle renderer.
float length
Length of the drawn vectors in pixels;.
AutoPtr< ICamera > camera
Camera used for rendering.
bool showKey
If true, a color palette and a distance scale is included in the image.
bool doAntialiasing
If true, the particles will be drawn with antialiasing.
bool renderGhosts
If true, ghost particles (if present) will be rendered as empty circles.
struct RenderParams::@34 vectors
Parameters of rendered vectors.
bool grayScale
If true, the palette is converted to grayscale.
bool smoothed
If true, particles will be smoothed using cubic spline.
float scale
Scaling factor of drawn particles relative to 1.