GLVis / glvis

Lightweight OpenGL tool for accurate and flexible finite element visualization
http://glvis.org
BSD 3-Clause "New" or "Revised" License
253 stars 52 forks source link

Calling VisualizationSceneSolution3d from own application #274

Open altineller opened 8 months ago

altineller commented 8 months ago

Hello,

I would like to use glVis for my own magnetometer calibration software. For this I am trying to use glVis as a library within QTCreator. I have solved all the dependency issues. And I have attempted to create a new VisualizationSceneSolution3d with a mesh and solution, and then callint SDLMainLoop(true), but it crashes.

   int         geom_ref_type = Quadrature1D::ClosedUniform;
   const char *mesh_file = "/home/can/gl/mfem/data/ref-cube.mesh";

   Mesh *mesh = new Mesh(mesh_file, 1, 1);
   int dim = mesh->Dimension();

   GLVisGeometryRefiner.SetType(geom_ref_type);

   H1_FECollection fec(1, 3);
   FiniteElementSpace fespace(mesh, &fec);
   GridFunction x(&fespace);
   x = 0;

   VisualizationSceneSolution3d * vss;
   vs = vss = new VisualizationSceneSolution3d(*mesh, x);
   SDLMainLoop(true);
   return 0;

And when I debugged it I got:

Screenshot from 2024-02-19 23-14-33

Indicating a problem with renderer.

How can I programmatically visualize a mesh, using glVis library within my own application?

Best Regards, Can

altineller commented 7 months ago

I have succeeded to recreate a GLVis scene:

`
stream_state.mesh.reset(meshRead); stream_state.SetMeshSolution(); stream_state.Extrude1DMeshAndSolution();

// 0: use_soln, 1: use_vector_soln, 2: mesh Session single_session(2, std::move(stream_state)); single_session.StartSession();

SDLMainLoop(); `

I would like to encapsulate the SDLoutput from GLVis in a QT Window. I need more information about this SDLMainLoop(). How can I for example call required functions from a render() subfunction?

Any ideas / recomendations / help greatly appreciated.

Best Regards, -C

v-dobrev commented 7 months ago

I'm not really sure if it is possible to use an SDL2 application (GLVis) inside a Qt application (your application). Maybe you can check the SDL2 forums and issues, see https://www.libsdl.org.

altineller commented 7 months ago

I'm not really sure if it is possible to use an SDL2 application (GLVis) inside a Qt application (your application). Maybe you can check the SDL2 forums and issues, see https://www.libsdl.org.

Yes, I studied SDL a bit and quickly realized that it would not be the smartest thing to do.

I have mounted the core glvis code into a sdl imgui application, and I was able to run glvis frame within the imgui example application, with few minor problems, such as SDL already being open, etc.

Like many visualization applications GLVis consists of multiple threads / workers that does different things, is that correct? What points should I handle when running it as an SDL app inside an sdl application?

Best Regards, C.

v-dobrev commented 7 months ago

Like many visualization applications GLVis consists of multiple threads / workers that does different things, is that correct?

Yes, GLVis uses C++ threads.

What points should I handle when running it as an SDL app inside an sdl application?

I think you are the first to explore that. I suspect that as long as the events in the GLVis window are handled, things should work mostly fine.