Adding a new GUI component to MRView


since there is no method of adding a module to MRView right now I decided to follow @jdtournier 's approach and fork the project to accomplish my goal. I would like to add some type of indicator to mrview to indicate the position of a surgical tool relative to the brain model. For now it would be sufficient to have this indicator in the ortho view and I also thought about overriding the set_focus event for this which must be a very bad programming style.

Since mrview uses Qt for GUI components I would like to know how I would add a new GUI component (for example a red line or a small dot) to the ortho view and how I would register it to the update mechanism of the graphics library. Maybe I would also need a bit of introduction to how coordinates are handled - especially on how to translate mm coordinates in the patient’s system to internal coordinates for the graphic library (I found some methods like screen_to_model in the projections class).

I am of course familiar with object oriented programming but I would like to get a hint on where to add the data structures for this type of function and where the graphic update mechanics happen.

It would also be good to know if you have any advice on how to implement a listener for incoming network packages into this project. Can I register an EventHandler somewhere or would I use a seperate thread for this?

Every bit of help is appreciated!

Best regards,
Darius and @Lucius

Actually, I reckon that’s by far the simplest approach for now – and there’s nothing inherently bad programming-wise about this. It might impede usability though if you’re trying to interact with the viewer while the focus is jumping around in real time…

This is where is gets messy… Yes, MRView relies on the Qt library, but only for the UI widgets (i.e. buttons, menus, sliders, text entries, …). The main window is rendered using raw OpenGL 3.3 – and that’s an entirely different beast. If you’re not familiar with OpenGL already, it’s actually quite an undertaking to do even the most trivial change on that front. This site is a good place to start learning OpenGL. But if I’m honest, I reckon you might want to think about whether you really want to dive into this: there’s a lot to learn, and if this is the only thing you have in mind, it’s probably a lot of effort for not a lot of gain. On the other hand, if you reckon OpenGL would be a useful skill to list on your CV, then go for it!

Personally, I think the absolute simplest thing you could do on that front it to add an additional cross-hairs with a different colour. You could then simply invoke the Projection::render_crosshairs() call in your tool’s draw() call. The only thing to tweak here would be to add the ability to modify the colour of the cross-hairs, so you add yours in a different colour from the main ones (currently, that call is hard-coded to yellow). The most effective way to do this would be via setting uniform variables in the C++ code that will be available to the OpenGL shader, so you can set the colour without recompiling the shader. Relatively trivial when you know, probably a bit like black magic if you don’t…

If you really need to add your own event handling, the place to start digging is the Qt event loop. But since Qt already offers functionality for listening to the network, I reckon you’d be much better off using their classes if you can - you don’t want to dig around the guts of Qt too much, it’ll probably cause more problems than it solves…

But the alternative is to use a separate thread to listen to your events, and use Qt’s signal/slot mechanism to notify the main thread as needed (I have a feeling this is what you’ve actually already gone for?). This might actually be simpler and much more flexible in the long run…