11 #include <wx/dcclient.h>
12 #include <wx/weakref.h>
26 this->
update(bitmap.
clone(), std::move(labels), isFinal);
31 std::unique_lock<std::mutex> lock(mutex);
32 render = std::move(bitmap);
38 std::unique_lock<std::mutex> lock(mutex);
61 camera = std::move(data->
camera);
65 return camera->
clone();
69 Outcome InteractiveRenderer::Status::isValid()
const {
70 if (!otherReason.empty()) {
72 }
else if (notInitialized) {
74 }
else if (particlesMissing) {
76 }
else if (cameraMissing) {
78 }
else if (colorizerMissing) {
94 job = dynamicCast<AnimationJob, IJob>(node->
getJob());
97 this->setRendererAccessor(globals);
102 this->setCameraAccessor(globals, slot.
provider);
104 status.cameraMissing =
true;
108 this->setNodeAccessor(slot.
provider);
110 status.particlesMissing =
true;
118 thread = std::thread([
this, globals] { this->renderLoop(globals); });
126 resolution = newResolution;
127 changed.resolution =
true;
135 cameraNode->
run(globals, callbacks);
139 void InteractiveRenderer::setCameraAccessor(
const RunSettings& globals,
150 changed.camera = this->getNewCamera(cameraNode, globals);
157 void InteractiveRenderer::setRendererAccessor(
const RunSettings& globals) {
166 const std::string key = anyCast<std::string>(value).value();
169 if (key ==
"quantities" || key ==
"surface_gravity") {
171 status.colorizerMissing = !changed.colorizer;
189 if (key ==
"transparent" || SOFT_PARAMS.
contains(
id)) {
199 this->setNodeAccessor(provider);
204 this->setCameraAccessor(globals, provider);
205 changed.camera = this->getNewCamera(provider, globals);
214 status.cameraMissing =
true;
216 status.particlesMissing =
true;
250 void InteractiveRenderer::renderLoop(
const RunSettings& globals) {
258 std::cout <<
"Updating ALL" << std::endl;
260 evaluated->
prepare(globals, callbacks);
265 status.otherReason = e.
what();
270 if (changed.node == evaluated) {
271 changed.node =
nullptr;
274 }
else if (preview) {
275 if (changed.camera) {
276 std::cout <<
"Updating camera" << std::endl;
277 status.cameraMissing =
false;
278 preview->
update(std::move(changed.camera));
280 if (changed.parameters) {
281 std::cout <<
"Updating parameters" << std::endl;
282 preview->
update(std::move(changed.parameters.value()));
285 if (changed.colorizer) {
286 std::cout <<
"Updating colorizer" << std::endl;
287 status.colorizerMissing =
false;
288 preview->
update(std::move(changed.colorizer));
290 if (changed.renderer) {
291 std::cout <<
"Updating renderer" << std::endl;
292 preview->
update(std::move(changed.renderer));
294 if (changed.resolution) {
295 std::cout <<
"Updating resolution" << std::endl;
297 changed.resolution =
false;
302 if (preview && !quitting && !changed.pending() && status.isValid()) {
303 std::cout <<
"Re-render" << std::endl;
304 preview->
render(resolution, output);
307 if (!quitting && !changed.pending()) {
308 std::unique_lock<std::mutex> lock(mutex);
314 void InteractiveRenderer::update() {
320 std::unique_lock<std::mutex> lock(mutex);
324 void InteractiveRenderer::stop() {
329 std::unique_lock<std::mutex> lock(mutex);
333 if (thread.joinable()) {
343 : wxPanel(parent, wxID_ANY, wxDefaultPosition, size) {
344 renderer = makeShared<InteractiveRenderer>(node,
this);
345 renderer->
start(globals);
347 this->Connect(wxEVT_PAINT, wxPaintEventHandler(RenderPane::onPaint));
348 this->Bind(wxEVT_SIZE, [
this](wxSizeEvent&
UNUSED(evt)) {
349 const wxSize size = this->GetClientSize();
354 void RenderPane::onPaint(wxPaintEvent&
UNUSED(evt)) {
358 const wxSize size = dc.GetSize();
364 bitmap = bitmap.ConvertToDisabled();
366 const wxSize offset = size - bitmap.GetSize();
367 dc.DrawBitmap(bitmap, wxPoint(offset.x / 2, offset.y / 2));
371 const wxString text = valid.
error() +
" ...";
372 const wxSize textSize = dc.GetTextExtent(text);
373 dc.DrawText(text, size.x / 2 - textSize.x / 2, size.y / 2 - textSize.y / 2);
#define SPH_ASSERT(x,...)
NAMESPACE_SPH_BEGIN void toWxBitmap(const Bitmap< Rgba > &bitmap, wxBitmap &wx)
Helper functions to check the internal consistency of the code.
@ NO_THROW
Function cannot throw exceptions.
@ MAIN_THREAD
Function can only be executed from main thread.
#define CHECK_FUNCTION(flags)
Object converting quantity values of particles into colors.
Container storing sorted unique values.
uint32_t Size
Integral type used to index arrays (by default).
@ PARTICLES
Job providing particles.
NAMESPACE_SPH_BEGIN void executeOnMainThread(const Function< void()> &function)
Posts a callback to be executed on main thread.
Posting events to be executed on main thread.
SharedPtr< JobNode > cloneHierarchy(JobNode &node, const Optional< std::string > &prefix)
Clones all nodes in the hierarchy.
#define NAMESPACE_SPH_END
const NothingType NOTHING
const SuccessTag SUCCESS
Global constant for successful outcome.
INLINE Outcome makeFailed(TArgs &&... args)
Constructs failed object with error message.
INLINE RawPtr< T > addressOf(T &ref)
NAMESPACE_SPH_BEGIN void safeRefresh(wxPanel *panel)
Calls Refresh on given main in main thread if the panel still exists.
Container for storing particle quantities and materials.
Measuring time intervals and executing periodic events.
AutoPtr< IRenderPreview > getRenderPreview(const RunSettings &global) const
AutoPtr< IRenderer > getRenderer(const RunSettings &global) const
AutoPtr< IColorizer > getColorizer(const RunSettings &global) const
RenderParams getRenderParams() const
Type-safe object that can store value of any type, similar to std::any.
Generic dynamically allocated resizable storage.
INLINE const TError & error() const
Returns the error message.
virtual void update(const Bitmap< Rgba > &bitmap, Array< Label > &&labels, const bool isFinal) override
May be called once after render finishes or multiple times for progressive renderers.
wxPanel * getPanel() const
virtual const char * what() const noexcept
bool contains(const T &value)
virtual AutoPtr< ICamera > clone() const =0
Base class for all object performing an operation in a simulation hierarchy.
virtual JobContext getResult() const =0
Returns the result of the job.
virtual void update(RenderParams &¶ms)=0
virtual void render(const Pixel resolution, IRenderOutput &output)=0
void resize(const Pixel newResolution)
void start(const RunSettings &globals)
InteractiveRenderer(const SharedPtr< JobNode > &node, wxPanel *panel)
Thrown when components of the run are mutually incompatible.
SharedPtr< TValue > getValue() const
Returns the stored value.
Size getSlotCnt() const
Returns the number of provider slots of this node.
virtual void run(const RunSettings &global, IJobCallbacks &callbacks) override
Evaluates the node and all its providers.
void addAccessor(const SharedToken &owner, const Accessor &accessor)
Adds an accessor for entries returned by the getSettings function.
std::string instanceName() const
Returns the instance name of the job.
Optional< ExtJobType > provides() const
Returns the type of the job.
RawPtr< IJob > getJob() const
Returns the underlying job.
SlotData getSlot(const Size index) const
Returns the information about given slot.
virtual void prepare(const RunSettings &global, IJobCallbacks &callbacks)
Evaluates all provides, without executing the node itself.
void enumerate(Function< void(const SharedPtr< JobNode > &job)> func)
Enumerates all nodes in the hierarchy.
RenderPane(wxWindow *parent, const wxSize size, const SharedPtr< JobNode > &node, const RunSettings &globals)
static Optional< GuiSettingsId > getEntryId(const std::string &name)
Returns an ID for given entry name.
SharedPtr< InteractiveRenderer > sharedFromThis() const
Object holding various statistics about current run.
Container storing all quantities used within the simulations.
virtual void onEnd(const Storage &UNUSED(storage), const Statistics &UNUSED(stats)) override
virtual void onStart(const IJob &job) override
Notifies the caller that a new job started running.
AutoPtr< ICamera > getCamera() const
@ COLORMAP_LOGARITHMIC_FACTOR
@ SURFACE_LEVEL
Value of iso-surface being constructed; lower value means larget bodies.
@ SURFACE_SUN_INTENSITY
Intentity of the sun.
@ SURFACE_AMBIENT
Ambient color for surface renderer.
AutoPtr< ICamera > camera
ExtJobType type
Specifies the type of the slot, or the type of the node connecting to it.
SharedPtr< JobNode > provider
Node currently connected to the slot.