glvis icon indicating copy to clipboard operation
glvis copied to clipboard

Calling VisualizationSceneSolution3d from own application

Open altineller opened this issue 1 year ago • 4 comments

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 avatar Feb 19 '24 20:02 altineller

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

altineller avatar Feb 23 '24 00:02 altineller

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.

v-dobrev avatar Feb 23 '24 06:02 v-dobrev

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.

altineller avatar Feb 25 '24 19:02 altineller

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.

v-dobrev avatar Feb 27 '24 01:02 v-dobrev