Dynamic Neural Field Composer 0.0.0
A C++20 library and interactive application for building and simulating Dynamic Neural Field (DNF) architectures.
Loading...
Searching...
No Matches
resize.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <map>
5#include <sstream>
6#include <iomanip>
7
8#include "tools/math.h"
9#include "element.h"
10
12{
15 enum class InterpolationMethod : int
16 {
17 LINEAR,
18 NEAREST,
19 CUBIC
20 };
21
23 inline const std::map<InterpolationMethod, std::string> InterpolationMethodToString = {
27 };
28
32 {
35
43
44 bool operator==(const ResizeParameters& other) const
45 {
46 return method == other.method &&
48 }
49
50 [[nodiscard]] std::string toString() const override
51 {
52 std::ostringstream result;
53 result << "Parameters: ["
54 << "Interpolation method: " << InterpolationMethodToString.at(method) << ", "
55 << "Input field dimensions: " << inputDimensions.toString()
56 << "]";
57 return result.str();
58 }
59 };
60
71 class Resize final : public Element
72 {
73 private:
74 ResizeParameters parameters;
75 public:
79 Resize(const ElementCommonParameters& elementCommonParameters,
80 const ResizeParameters& parameters);
81
82 void init() override;
83 void step(double t, double deltaT) override;
84 void addInput(const std::shared_ptr<Element>& inputElement,
85 const std::string& inputComponent = "output") override;
86 std::string toString() const override;
87 std::shared_ptr<Element> clone() const override;
88
92 void changeInputDimensions(const ElementDimensions& newInputDimensions);
93
94 void setParameters(const ResizeParameters& parameters);
95 [[nodiscard]] ResizeParameters getParameters() const;
96 };
97}
Abstract base class for all simulation elements.
Definition element.h:28
Resamples a 1D input field of size N to this element's output size M.
Definition resize.h:72
std::string toString() const override
Definition resize.cpp:71
void changeInputDimensions(const ElementDimensions &newInputDimensions)
Resize the input field dimensions and rebuild the input buffer. Connections are not removed automatic...
Definition resize.cpp:84
void init() override
Initialize the element (called once before the simulation loop).
Definition resize.cpp:16
void step(double t, double deltaT) override
Advance the element by one time step.
Definition resize.cpp:22
ResizeParameters getParameters() const
Definition resize.cpp:97
void setParameters(const ResizeParameters &parameters)
Definition resize.cpp:91
void addInput(const std::shared_ptr< Element > &inputElement, const std::string &inputComponent="output") override
Register inputElement as an upstream source for this element.
Definition resize.cpp:43
std::shared_ptr< Element > clone() const override
Definition resize.cpp:79
InterpolationMethod
Interpolation method used when resampling an input field to a new size.
Definition resize.h:16
@ LINEAR
Piecewise linear interpolation.
@ NEAREST
Nearest-neighbour sampling.
@ CUBIC
Catmull-Rom cubic spline interpolation.
Definition element_parameters.h:10
const std::map< InterpolationMethod, std::string > InterpolationMethodToString
Maps InterpolationMethod values to human-readable strings.
Definition resize.h:23
Definition element_parameters.h:188
Definition element_parameters.h:159
std::string toString() const
Definition element_parameters.cpp:55
Definition element_parameters.h:206
Parameters for a 1D Resize element.
Definition resize.h:32
bool operator==(const ResizeParameters &other) const
Definition resize.h:44
InterpolationMethod method
Interpolation method used for resampling.
Definition resize.h:33
ElementDimensions inputDimensions
Spatial dimensions of the source (input) field.
Definition resize.h:34
std::string toString() const override
Definition resize.h:50
ResizeParameters(const InterpolationMethod method=InterpolationMethod::LINEAR, const ElementDimensions &inputDimensions=ElementDimensions{})
Construct Resize parameters.
Definition resize.h:39