FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
VisualField.h
1#pragma once
2
8#include <EnvironmentQuantityField.h>
9#include <RefreshSchedule.h>
10#include <ScalarFieldBake.h>
11#include <cstddef>
12#include <cstdint>
13#include <fhsim/PrintDuringExec.h>
14#include <fhsim/simobject/SimObject.h>
15#include <memory>
16#include <optional>
17#include <string>
18
19namespace environment
20{
21class EnvironmentProvider;
22}
23
24#ifdef FH_VISUALIZATION
25# include "visual/BakedFieldTexture.h"
26
27# include <OgreMaterial.h>
28#endif
29
30namespace environmentmodels
31{
32
53class VisualField : public SimObject
54{
55public:
64 void FinalSetup(const double T, const double* const X, ISimObjectCreator* Creator) override;
65
67 void OdeFcn(const double T, const double* const X, double* const XDot) const override;
68
73 [[nodiscard]] util::Refresh RefreshMode() const;
74
75protected:
85 VisualField(std::string SimObjectName, ISimObjectCreator* Creator, int numAxes);
86
88 ~VisualField() override;
89
99 void ResolveCounts(const double extent[3], std::size_t budget, int counts[3]) const;
100
112 void ValidateGridCounts(ISimObjectCreator* Creator, const int counts[3], const std::string& extentParameterName) const;
113
117 [[nodiscard]] bool MaskInaccurate() const { return !m_showExtrapolated; }
118
125 [[nodiscard]] bool ExpectsToSampleOnce() const;
126
132 [[nodiscard]] bool MaySampleInTheBackground() const;
133
138 [[nodiscard]] environment::field::ScalarField& Field() const;
139
141 [[nodiscard]] double StartTime() const { return m_startTime; }
142
149 [[nodiscard]] bool RefreshDue(double T, bool moved) const;
150
154 void Refreshed(double T);
155
168
170 [[nodiscard]] double ValueMin() const { return m_valueMin; }
171
173 [[nodiscard]] double ValueMax() const { return m_valueMax; }
174
175#ifdef FH_VISUALIZATION
180 void Show(const util::BakedField& baked);
181
192 void SwapTextures(std::unique_ptr<visual::BakedFieldTexture> textures);
193
200 Ogre::MaterialPtr CloneMaterial(const Ogre::String& baseMaterialName);
201
207 void ApplyMaterialSettings() const;
208
212 [[nodiscard]] const Ogre::MaterialPtr& Material() const { return m_material; }
213#endif
214
222 void Log(const std::string& message, fhsim::ELogLevel level) const;
223
224private:
226 void ReadQuantity(ISimObjectCreator* Creator);
227
229 void ReadRefresh(ISimObjectCreator* Creator);
230
232 void FixEncodingRange(double T, const util::SamplingBox& box);
233
235 [[nodiscard]] std::uint64_t Revision() const;
236
238 [[nodiscard]] bool UnchangedSinceLastSample() const;
239
241 [[nodiscard]] bool ChangesWithWakesOnly() const;
242
243 int m_numAxes;
244
245 util::FieldQuantity m_quantity;
247 double m_axis[3];
248 std::string m_fieldName;
249
250 util::Refresh m_requestedRefresh;
251 double m_refreshPeriod;
252 std::optional<util::RefreshSchedule> m_schedule;
253
254 bool m_hasSpacing;
255 bool m_hasResolution;
256 double m_spacing[3];
257 int m_resolution[3];
258
259 double m_colorRange[2];
260 double m_visibleRange[2];
261 double m_alphaRange[2];
262
263 bool m_hasColorRange;
264 bool m_hasVisibleRange;
265 bool m_showExtrapolated;
266
267 bool m_encodingFixed;
268 double m_valueMin;
269 double m_valueMax;
270
271 double m_startTime;
272
273 environment::EnvironmentProvider* m_pEnvironment;
274 PrintDuringExec* m_print = nullptr;
275
276 std::shared_ptr<environment::field::ScalarField> m_field;
277
278#ifdef FH_VISUALIZATION
279 std::unique_ptr<visual::BakedFieldTexture> m_texture;
280 Ogre::MaterialPtr m_material;
281#endif
282};
283
284} // namespace environmentmodels
Definition VisualField.h:54
void Log(const std::string &message, fhsim::ELogLevel level) const
bool RefreshDue(double T, bool moved) const
~VisualField() override
Releases the cloned material and the textures.
environment::field::ScalarField & Field() const
void OdeFcn(const double T, const double *const X, double *const XDot) const override
No state; the ODE function is a no-op.
double ValueMax() const
Field value encoded as code 65535, fixed at the first SampleOver().
Definition VisualField.h:173
void ValidateGridCounts(ISimObjectCreator *Creator, const int counts[3], const std::string &extentParameterName) const
double StartTime() const
Simulation time of FinalSetup [s], the time of the first sample.
Definition VisualField.h:141
bool MaskInaccurate() const
Definition VisualField.h:117
util::Refresh RefreshMode() const
void FinalSetup(const double T, const double *const X, ISimObjectCreator *Creator) override
double ValueMin() const
Field value encoded as code 1, fixed at the first SampleOver().
Definition VisualField.h:170
util::BakedField SampleOver(double T, const util::SamplingBox &box)
void ResolveCounts(const double extent[3], std::size_t budget, int counts[3]) const
VisualField(std::string SimObjectName, ISimObjectCreator *Creator, int numAxes)
Environment SimObjects.
Definition Environment.h:30
FieldQuantity
The quantity a field visualiser shows, its Quantity parameter.
Definition EnvironmentQuantityField.h:23
Refresh
When a field visualiser samples again, its Refresh parameter.
Definition RefreshSchedule.h:15
Definition WaterVelocity.h:33
A scalar field evaluated over a SamplingBox and encoded to 16-bit codes.
Definition ScalarFieldBake.h:52
Definition ScalarFieldBake.h:44