wx_BGI_Graphics
Classic BGI-compatible graphics API with modern OpenGL extension API
Loading...
Searching...
No Matches
wx_bgi_openlb.h
Go to the documentation of this file.
1#pragma once
2
3#include "wx_bgi.h"
4#include "wx_bgi_ext.h"
5
6#ifdef __cplusplus
7#include <utility>
8
9namespace olb
10{
11template <typename T, unsigned D>
12class SuperGeometry;
13}
14#endif
15
70static inline void wxbgi_openlb_begin_session(int width, int height, const char* title)
71{
73 wxbgi_wx_frame_create(width, height, title);
75}
76
87static inline void wxbgi_openlb_begin_canvas_session(int width, int height)
88{
89 wxbgi_wx_init_for_canvas(width, height);
90}
91
107static inline int wxbgi_openlb_pump(void)
108{
109 if (wxbgi_should_close() != 0)
110 return 0;
112 return wxbgi_should_close() == 0 ? 1 : 0;
113}
114
134static inline int wxbgi_openlb_present(void)
135{
137 return wxbgi_openlb_pump();
138}
139
186 int defaultFluidMaterial,
187 int defaultSolidMaterial,
188 int *outMatched);
189
237BGI_API int BGI_CALL wxbgi_openlb_sample_materials_2d(float minX, float minY, float z,
238 int cols, int rows,
239 float stepX, float stepY,
240 int defaultFluidMaterial,
241 int defaultSolidMaterial,
242 int *outMaterials,
243 int materialCount);
244
245#ifdef __cplusplus
246
263struct WxbgiOpenLbMaterializeStats
264{
266 int visited{0};
267
272 int matched{0};
273
279 int updated{0};
280};
281
350template <typename T, typename Mapper>
351inline WxbgiOpenLbMaterializeStats wxbgi_openlb_materialize_super_geometry_2d(
352 olb::SuperGeometry<T, 2> &superGeometry,
353 T z,
354 Mapper &&mapMaterial,
355 int defaultFluidMaterial = 1,
356 int defaultSolidMaterial = 2,
357 bool overwriteUnmatched = false)
358{
359 WxbgiOpenLbMaterializeStats stats;
360
361 superGeometry.forCoreSpatialLocations([&](auto latticeR) {
362 ++stats.visited;
363
364 const auto physR = superGeometry.getPhysR(latticeR);
365
366 int matched = 0;
367 const int bridgeMaterial = wxbgi_openlb_classify_point_material(
368 static_cast<float>(physR[0]),
369 static_cast<float>(physR[1]),
370 static_cast<float>(z),
371 defaultFluidMaterial,
372 defaultSolidMaterial,
373 &matched);
374
375 if (matched != 0)
376 ++stats.matched;
377 else if (!overwriteUnmatched)
378 return;
379
380 auto &blockGeometry = superGeometry.getBlockGeometry(latticeR[0]);
381 const int localR[2] = {latticeR[1], latticeR[2]};
382 const int currentMaterial = blockGeometry.get(localR);
383 const int nextMaterial = mapMaterial(physR, currentMaterial, bridgeMaterial, matched != 0);
384 if (nextMaterial == currentMaterial)
385 return;
386
387 blockGeometry.set(localR, nextMaterial);
388 ++stats.updated;
389 });
390
391 superGeometry.communicate();
392 superGeometry.getStatisticsStatus() = true;
393 superGeometry.updateStatistics(false);
394 return stats;
395}
396
425template <typename T>
426inline WxbgiOpenLbMaterializeStats wxbgi_openlb_materialize_super_geometry_2d(
427 olb::SuperGeometry<T, 2> &superGeometry,
428 T z,
429 int defaultFluidMaterial = 1,
430 int defaultSolidMaterial = 2,
431 bool overwriteUnmatched = false)
432{
433 return wxbgi_openlb_materialize_super_geometry_2d(
434 superGeometry,
435 z,
436 [defaultFluidMaterial](const auto &, int, int bridgeMaterial, bool matched) {
437 return matched ? bridgeMaterial : defaultFluidMaterial;
438 },
439 defaultFluidMaterial,
440 defaultSolidMaterial,
441 overwriteUnmatched);
442}
443
487template <typename T, typename Mapper>
488inline WxbgiOpenLbMaterializeStats wxbgi_openlb_materialize_super_geometry_3d(
489 olb::SuperGeometry<T, 3> &superGeometry,
490 Mapper &&mapMaterial,
491 int defaultFluidMaterial = 1,
492 int defaultSolidMaterial = 2,
493 bool overwriteUnmatched = false)
494{
495 WxbgiOpenLbMaterializeStats stats;
496
497 superGeometry.forCoreSpatialLocations([&](auto latticeR) {
498 ++stats.visited;
499
500 const auto physR = superGeometry.getPhysR(latticeR);
501
502 int matched = 0;
503 const int bridgeMaterial = wxbgi_openlb_classify_point_material(
504 static_cast<float>(physR[0]),
505 static_cast<float>(physR[1]),
506 static_cast<float>(physR[2]),
507 defaultFluidMaterial,
508 defaultSolidMaterial,
509 &matched);
510
511 if (matched != 0)
512 ++stats.matched;
513 else if (!overwriteUnmatched)
514 return;
515
516 auto &blockGeometry = superGeometry.getBlockGeometry(latticeR[0]);
517 const int localR[3] = {latticeR[1], latticeR[2], latticeR[3]};
518 const int currentMaterial = blockGeometry.get(localR);
519 const int nextMaterial = mapMaterial(physR, currentMaterial, bridgeMaterial, matched != 0);
520 if (nextMaterial == currentMaterial)
521 return;
522
523 blockGeometry.set(localR, nextMaterial);
524 ++stats.updated;
525 });
526
527 superGeometry.communicate();
528 superGeometry.getStatisticsStatus() = true;
529 superGeometry.updateStatistics(false);
530 return stats;
531}
532
557template <typename T>
558inline WxbgiOpenLbMaterializeStats wxbgi_openlb_materialize_super_geometry_3d(
559 olb::SuperGeometry<T, 3> &superGeometry,
560 int defaultFluidMaterial = 1,
561 int defaultSolidMaterial = 2,
562 bool overwriteUnmatched = false)
563{
564 return wxbgi_openlb_materialize_super_geometry_3d(
565 superGeometry,
566 [defaultFluidMaterial](const auto &, int, int bridgeMaterial, bool matched) {
567 return matched ? bridgeMaterial : defaultFluidMaterial;
568 },
569 defaultFluidMaterial,
570 defaultSolidMaterial,
571 overwriteUnmatched);
572}
573
574#endif
#define BGI_CALL
Definition bgi_types.h:20
#define BGI_API
Definition bgi_types.h:14
BGI_API int BGI_CALL wxbgi_poll_events(void)
Pumps pending OS/window events.
BGI_API int BGI_CALL wxbgi_should_close(void)
Reports whether the window received a close request.
BGI_API void BGI_CALL wxbgi_wx_refresh(void)
Request an immediate canvas repaint.
BGI_API void BGI_CALL wxbgi_wx_app_create(void)
Create the wx application instance.
BGI_API void BGI_CALL wxbgi_wx_set_frame_rate(int fps)
Set the auto-refresh rate in frames per second (default 0 = no auto-refresh).
BGI_API void BGI_CALL wxbgi_wx_frame_create(int width, int height, const char *title)
Create a top-level wxFrame with an embedded WxBgiCanvas.
BGI_API void BGI_CALL wxbgi_wx_init_for_canvas(int width, int height)
Initialise BGI state for wxWidgets-embedded mode (no GLFW).
Public classic BGI-compatible C API exported by the library.
Advanced non-BGI extension API for modern OpenGL workflows.
BGI_API int BGI_CALL wxbgi_openlb_classify_point_material(float x, float y, float z, int defaultFluidMaterial, int defaultSolidMaterial, int *outMatched)
Classify a single physical-space point against the active DDS scene and return the associated OpenLB ...
BGI_API int BGI_CALL wxbgi_openlb_sample_materials_2d(float minX, float minY, float z, int cols, int rows, float stepX, float stepY, int defaultFluidMaterial, int defaultSolidMaterial, int *outMaterials, int materialCount)
Sample a 2-D axis-aligned grid of physical points against the active DDS scene and write per-cell mat...