11 : scheduler(scheduler) {
20 cached.values.resize(cached.positions.size());
22 parallelFor(*scheduler, 0, cached.positions.size(), [
this, &colorizer](
const Size i) {
23 cached.values[i] = colorizer.evalScalar(i).value();
27 finder->
build(*scheduler, cached.positions);
31 return !cached.values.empty();
37 { 0b0000, { -1, -1 } },
38 { 0b1111, { -1, -1 } },
55 { 0b1010, { -1, -1 } },
56 { 0b0101, { -1, -1 } },
67 for (
auto& isoAndCoord : map) {
68 if (
getLength(p - isoAndCoord.value) < 100) {
81 const Vector pos1(ray1->origin[
X], ray1->origin[
Y], 0._f);
82 const Vector pos2(ray2->origin[
X], ray2->origin[
Y], 0._f);
84 const Size resY =
Size(resX *
float(size.
y) /
float(size.
x));
85 const Vector dxdp =
Vector(1._f / resX, 1._f / resY, 0._f) * (pos2 - pos1);
90 for (
Size y = 0; y < resY; ++y) {
91 for (
Size x = 0; x < resX; ++x) {
94 finder->
findAll(pos, 2._f * h, neighs);
99 const float w = float(kernel.
value(pos - cached.positions[n.index], h));
100 sum += cached.values[n.index] * w;
129 for (
Size x = 0; x < resX - 1; ++x) {
130 for (
Size y = 0; y < resY - 1; ++y) {
132 const float v1 = grid[p +
Pixel(0, 0)];
133 const float v2 = grid[p +
Pixel(1, 0)];
134 const float v3 = grid[p +
Pixel(1, 1)];
135 const float v4 = grid[p +
Pixel(0, 1)];
137 const float vmin =
min(v1, v2, v3, v4);
138 const float vmax =
max(v1, v2, v3, v4);
144 for (
float iso = isoMin; iso <= isoMax; iso += step) {
145 if (cached.palette) {
149 const int f1 = int(v1 > iso);
150 const int f2 = int(v2 > iso);
151 const int f3 = int(v3 > iso);
152 const int f4 = int(v4 > iso);
154 const Size flag = f1 << 3 | f2 << 2 | f3 << 1 | f4;
155 const Pixel edge = MS_TABLE[flag];
156 if (edge !=
Pixel(-1, -1)) {
157 const std::pair<Pixel, Pixel>& ps1 = MS_EDGE_TO_VTX[edge.
x];
158 const std::pair<Pixel, Pixel>& ps2 = MS_EDGE_TO_VTX[edge.
y];
159 const Pixel p11 = p + ps1.first;
160 const Pixel p12 = p + ps1.second;
161 const Pixel p21 = p + ps2.first;
162 const Pixel p22 = p + ps2.second;
164 SPH_ASSERT((grid[p11] > iso) != (grid[p12] > iso));
165 SPH_ASSERT((grid[p21] > iso) != (grid[p22] > iso));
167 const float rati1 = (grid[p11] - iso) / (grid[p11] - grid[p12]);
168 SPH_ASSERT(rati1 >= 0.f && rati1 <= 1.f, rati1);
171 const float rati2 = (grid[p21] - iso) / (grid[p21] - grid[p22]);
172 SPH_ASSERT(rati2 >= 0.f && rati2 <= 1.f, rati2);
176 const Coords labelCoord = (c1 + c2) * 0.5f;
178 if (labelCoord.
y < topmostCoord->y && isCoordValid(labelMap, labelCoord)) {
179 topmostCoord.value() = labelCoord;
182 labelMap.
insert(iso, labelCoord);
190 for (
const auto& isoAndCoord : labelMap) {
192 if (cached.palette) {
201 if (cached.palette) {
202 const Pixel origin(size.
x - 50, 231);
206 cached.palette->transform([](
const Rgba& color) {
return Rgba(color.
intensity()); });
208 palette = cached.palette.value();
#define SPH_ASSERT(x,...)
Defines projection transforming 3D particles onto 2D screen.
Object converting quantity values of particles into colors.
Renderer drawing iso-contours of specified quantity.
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.
INLINE Float weight(const Vector &r1, const Vector &r2)
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 lerp(const T v1, const T v2, const TAmount amount)
#define NAMESPACE_SPH_END
void drawPalette(IRenderContext &context, const Pixel origin, const Pixel size, const Rgba &lineColor, const Palette &palette)
Renderer drawing individual particles as dots.
@ POSITION
Positions (velocities, accelerations) of particles, always a vector quantity,.
INLINE void parallelFor(IScheduler &scheduler, const Size from, const Size to, TFunctor &&functor)
Executes a functor concurrently from all available threads.
Key-value associative container.
INLINE Float getLength(const Vector &v)
Returns the length of the vector. Enabled only for vectors of floating-point precision.
BasicVector< Float > Vector
void fill(const Type &value)
virtual bool isInitialized() const override
Checks if the renderer has been initialized.
virtual void render(const RenderParams ¶ms, Statistics &stats, IRenderOutput &output) const override
Draws particles into the bitmap, given the data provided in initialize.
Optional< Palette > palette
virtual void initialize(const Storage &storage, const IColorizer &colorizer, const ICamera &camera) override
Prepares the objects for rendering and updates its data.
ContourRenderer(SharedPtr< IScheduler > scheduler, const GuiSettings &settings)
Cubic spline (M4) kernel.
Container of key-value pairs.
void build(IScheduler &scheduler, ArrayView< const Vector > points)
Constructs the struct with an array of vectors.
virtual Size findAll(const Size index, const Float radius, Array< NeighbourRecord > &neighbours) const =0
Finds all neighbours within given radius from the point given by index.
Interface defining a camera or view, used by a renderer.
virtual Pixel getSize() const =0
Returns the current resolution of the camera.
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 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.
INLINE Float value(const Vector &r, const Float h) const noexcept
Wrapper of type value of which may or may not be present.
Represents a color palette, used for mapping arbitrary number to a color.
virtual Array< IRenderOutput::Label > getLabels() const override
virtual void setColor(const Rgba &color, const Flags< ColorFlag > flags) override
Selects the color for one or more drawing modes.
virtual void drawText(const Coords p, const Flags< TextAlign > align, const std::string &s) override
virtual void setFontSize(const int newFontSize) override
virtual void drawLine(const Coords p1, const Coords p2) override
Draws a line connecting two points.
Rgba inverse() const
Returns an inverse color.
float intensity() const
Returns the average intensity of the color.
static const Settings & getDefaults()
\brief Returns a reference to object containing default values of all settings.
Object holding various statistics about current run.
Container storing all quantities used within the simulations.
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.
INLINE Optional< TValue & > tryGet(const TKey &key)
Returns a reference to the value matching the given key, or NOTHING if no such value exists.
AutoPtr< ISymmetricFinder > getFinder(const RunSettings &settings)
Holds information about a neighbour particles.
Parameters of the rendered image.
bool showLabels
Show numerical values of iso-lines.
Rgba background
Background color of the rendered image.
struct RenderParams::@33 particles
Parameters of the particle renderer.
AutoPtr< ICamera > camera
Camera used for rendering.
bool showKey
If true, a color palette and a distance scale is included in the image.
float isoStep
Step between subsequent iso-lines.
Size gridSize
Horizontal resolution of the grid.
struct RenderParams::@37 contours
bool grayScale
If true, the palette is converted to grayscale.