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/simobject/SimObject.h>
14#include <memory>
15#include <optional>
16#include <string>
17
18namespace environment
19{
20class EnvironmentProvider;
21}
22
23#ifdef FH_VISUALIZATION
24# include "visual/BakedFieldTexture.h"
25
26# include <OgreMaterial.h>
27#endif
28
29namespace environmentmodels
30{
31
52class VisualField : public SimObject
53{
54public:
63 void FinalSetup(const double T, const double* const X, ISimObjectCreator* Creator) override;
64
66 void OdeFcn(const double T, const double* const X, double* const XDot) const override;
67
72 [[nodiscard]] util::Refresh RefreshMode() const;
73
74protected:
84 VisualField(std::string SimObjectName, ISimObjectCreator* Creator, int numAxes);
85
87 ~VisualField() override;
88
98 void ResolveCounts(const double extent[3], std::size_t budget, int counts[3]) const;
99
111 void ValidateGridCounts(ISimObjectCreator* Creator, const int counts[3], const std::string& extentParameterName) const;
112
116 [[nodiscard]] bool MaskInaccurate() const { return !m_showExtrapolated; }
117
124 [[nodiscard]] bool ExpectsToSampleOnce() const;
125
131 [[nodiscard]] bool MaySampleInTheBackground() const;
132
137 [[nodiscard]] environment::field::ScalarField& Field() const;
138
140 [[nodiscard]] double StartTime() const { return m_startTime; }
141
148 [[nodiscard]] bool RefreshDue(double T, bool moved) const;
149
153 void Refreshed(double T);
154
167
169 [[nodiscard]] double ValueMin() const { return m_valueMin; }
170
172 [[nodiscard]] double ValueMax() const { return m_valueMax; }
173
174#ifdef FH_VISUALIZATION
179 void Show(const util::BakedField& baked);
180
191 void SwapTextures(std::unique_ptr<visual::BakedFieldTexture> textures);
192
199 Ogre::MaterialPtr CloneMaterial(const Ogre::String& baseMaterialName);
200
206 void ApplyMaterialSettings() const;
207
211 [[nodiscard]] const Ogre::MaterialPtr& Material() const { return m_material; }
212#endif
213
214private:
216 void ReadQuantity(ISimObjectCreator* Creator);
217
219 void ReadRefresh(ISimObjectCreator* Creator);
220
222 void FixEncodingRange(double T, const util::SamplingBox& box);
223
225 [[nodiscard]] std::uint64_t Revision() const;
226
228 [[nodiscard]] bool UnchangedSinceLastSample() const;
229
231 [[nodiscard]] bool ChangesWithWakesOnly() const;
232
233 int m_numAxes;
234
235 util::FieldQuantity m_quantity;
237 double m_axis[3];
238 std::string m_fieldName;
239
240 util::Refresh m_requestedRefresh;
241 double m_refreshPeriod;
242 std::optional<util::RefreshSchedule> m_schedule;
243
244 bool m_hasSpacing;
245 bool m_hasResolution;
246 double m_spacing[3];
247 int m_resolution[3];
248
249 double m_colorRange[2];
250 double m_visibleRange[2];
251 double m_alphaRange[2];
252
253 bool m_hasColorRange;
254 bool m_hasVisibleRange;
255 bool m_showExtrapolated;
256
257 bool m_encodingFixed;
258 double m_valueMin;
259 double m_valueMax;
260
261 double m_startTime;
262
263 environment::EnvironmentProvider* m_pEnvironment;
264
265 std::shared_ptr<environment::field::ScalarField> m_field;
266
267#ifdef FH_VISUALIZATION
268 std::unique_ptr<visual::BakedFieldTexture> m_texture;
269 Ogre::MaterialPtr m_material;
270#endif
271};
272
273} // namespace environmentmodels
Definition VisualField.h:53
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:172
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:140
bool MaskInaccurate() const
Definition VisualField.h:116
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:169
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:25
FieldQuantity
The quantity a field visualiser shows, its Quantity parameter.
Definition EnvironmentQuantityField.h:22
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