14 : scheduler(scheduler) {
24 kernel = Factory::getKernel<3>(settings);
30 cached.colors.clear();
44 finder->
build(*scheduler, r);
47 for (
Triangle& t : cached.triangles) {
52 float weightSum = 0.f;
53 for (
auto& n : neighs) {
54 const Size i = n.index;
57 const float w = float(
max(kernel.
value(r[i] - pos, r[i][
H]),
EPS));
58 colorSum += color * w;
62 if (weightSum == 0._f) {
67 const float gray = ambient + sunIntensity *
max(0.f,
float(
dot(sunPosition, t.
normal())));
68 cached.colors.push(colorSum / weightSum * gray);
74 return !cached.triangles.empty();
86 Order triangleOrder(cached.triangles.size());
88 triangleOrder.
shuffle([
this, &cameraDir](
const Size i1,
const Size i2) {
89 const Vector v1 = cached.triangles[i1].center();
90 const Vector v2 = cached.triangles[i2].center();
91 return dot(cameraDir, v1) >
dot(cameraDir, v2);
95 for (
Size i = 0; i < cached.triangles.size(); ++i) {
96 const Size idx = triangleOrder[i];
102 if (!p1 || !p2 || !p3) {
105 context.
drawTriangle(p1->coords, p2->coords, p3->coords);
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.
INLINE Float maxElement(const T &value)
Returns maximum element, simply the value iself by default.
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.
Array< Triangle > getSurfaceMesh(IScheduler &scheduler, const Storage &storage, const McConfig &config)
Returns the triangle mesh of the body surface (or surfaces of bodies).
constexpr INLINE T max(const T &f1, const T &f2)
constexpr INLINE T clamp(const T &f, const T &f1, const T &f2)
Renderer visualizing the surface as triangle mesh.
#define NAMESPACE_SPH_END
Helper object defining permutation.
Tool to measure time spent in functions and profile the code.
@ 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.
Box getBoundingBox(const Storage &storage, const Float radius)
Convenience function to get the bounding box of all particles.
String getFormattedTime(const String &format)
Utility functions.
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 row(const Size idx) const
Object providing safe access to continuous memory of data.
Helper object defining three-dimensional interval (box).
INLINE Vector size() const
Returns box dimensions.
INLINE TValue get(const GuiSettingsId id) const
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 AffineMatrix getFrame() const =0
Returns the transformation matrix converting camera space to world space.
virtual Optional< ProjectedPoint > project(const Vector &r) const =0
Returns projected position of particle on the image.
Interface for objects assigning colors to particles.
virtual Rgba evalColor(const Size idx) const =0
Returns the color of idx-th particle.
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
virtual bool isInitialized() const override
Checks if the renderer has been initialized.
MeshRenderer(SharedPtr< IScheduler > scheduler, const GuiSettings &settings)
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
Can only be called from main thread.
Wrapper of type value of which may or may not be present.
Permutation, i.e. (discrete) invertible function int->int.
void shuffle(TBinaryPredicate &&predicate)
Shuffles the order using a binary predicate.
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 drawTriangle(const Coords p1, const Coords p2, const Coords p3) override
Draws a triangle given three points.
virtual void drawText(const Coords p, const Flags< TextAlign > align, const std::string &s) override
static Rgba transparent()
Settings & set(const TEnum idx, TValue &&value, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0)
Saves a value into the settings.
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.
Array< TValue > & getValue(const QuantityId key)
Retrieves a quantity values from the storage, given its key and value type.
INLINE Vector normal() const
INLINE Vector center() const
@ SPH_FINDER
Structure for searching nearest neighbours of particles.
@ SURFACE_RESOLUTION
Size of the grid used in MarchingCubes (in code units, not h).
@ SURFACE_LEVEL
Value of iso-surface being constructed; lower value means larget bodies.
@ SURFACE_SUN_INTENSITY
Intentity of the sun.
@ SURFACE_SUN_POSITION
Direction to the sun used for shading.
@ SURFACE_AMBIENT
Ambient color for surface renderer.
AutoPtr< ISymmetricFinder > getFinder(const RunSettings &settings)
Float gridResolution
Absolute size of each produced triangle.
Parameters of the rendered image.
AutoPtr< ICamera > camera
Camera used for rendering.