mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 04:50:34 +05:00
Move Redraw() function from NGSolve to Netgen
- used in Snapshot
This commit is contained in:
parent
64b1331c23
commit
245da0ee87
@ -3536,6 +3536,7 @@ namespace netgen
|
||||
|
||||
#ifdef NG_PYTHON
|
||||
#include <../general/ngpython.hpp>
|
||||
#include "../include/nginterface.h"
|
||||
|
||||
DLL_HEADER void ExportMeshVis(py::module &m)
|
||||
{
|
||||
@ -3577,6 +3578,32 @@ DLL_HEADER void ExportMeshVis(py::module &m)
|
||||
([] () {
|
||||
return vsmesh.GetMesh();
|
||||
}));
|
||||
m.def ("_Redraw",
|
||||
([](bool blocking, double fr)
|
||||
{
|
||||
static auto last_time = std::chrono::system_clock::now()-std::chrono::seconds(10);
|
||||
auto now = std::chrono::system_clock::now();
|
||||
double elapsed = std::chrono::duration<double>(now-last_time).count();
|
||||
if (elapsed * fr > 1)
|
||||
{
|
||||
Ng_Redraw(blocking);
|
||||
last_time = std::chrono::system_clock::now();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}),
|
||||
py::arg("blocking")=false, py::arg("fr") = 25, R"raw_string(
|
||||
Redraw all
|
||||
|
||||
Parameters:
|
||||
|
||||
blocking : bool
|
||||
input blocking
|
||||
|
||||
fr : double
|
||||
input framerate
|
||||
|
||||
)raw_string");
|
||||
}
|
||||
// BOOST_PYTHON_MODULE(libvisual)
|
||||
// {
|
||||
|
@ -11,3 +11,14 @@ del sys
|
||||
del os
|
||||
|
||||
from . import libngpy
|
||||
|
||||
def Redraw(*args, **kwargs):
|
||||
if libngpy.meshvis._Redraw(*args, **kwargs):
|
||||
try:
|
||||
import netgen
|
||||
import tkinter
|
||||
cnt = 0
|
||||
while(netgen.gui.win.tk.dooneevent(tkinter._tkinter.DONT_WAIT) and cnt < 100):
|
||||
cnt += 1
|
||||
except:
|
||||
pass
|
||||
|
@ -26,8 +26,7 @@ if not netgen.libngpy._meshing._netgen_executable_started:
|
||||
pass
|
||||
|
||||
def Snapshot(w,h, filename=None):
|
||||
import ngsolve
|
||||
ngsolve.Redraw(blocking=True)
|
||||
netgen.Redraw(blocking=True)
|
||||
import numpy
|
||||
image = netgen.libngpy.Snapshot(w, h)
|
||||
image = numpy.array(image, dtype=numpy.uint8).reshape(h, w, 3)
|
||||
|
Loading…
Reference in New Issue
Block a user