I want to customize the TH1:SetShowProjection method for TH3 histograms and write a more complex GUI. I found DynamicSlice.C and it’s a good starting point for me, essentially what I want to do is to extend it to the 3D case.
Coming to my question, I was wondering if there’s already an easy way to get the respective 3D point from a (px, py) mouse cursor position.
Well, I thought that I could have a look to the current implementation of the 3D -> 2D projection (via SetShowProjection) in ROOT, there should be the piece of code I’m looking for… but I could not find it.
I don’t have any working example, but this is what I want to achieve:
I have a TH3D and I want to write a GUI that displays the histogram along with two interactive 2D orthogonal slices (xy and xz, for example), all in the same canvas. The slices are taken from the position of the mouse cursor and I want to display the two current slicing planes onto the TH3D, just as it happens with one projection when enabling SetShowProjection.
It’s pretty clear in my mind how the implementation should be, having seen DynamicSlice.C, but the missing starting point is finding a way to obtain the position of the two slices (the x and the z, staying with the same example) from the mouse position.
You can do something like in the gl example glbox.C.
When you move the mouse on the back plaine it highlights then you can move the plane
using the shift+mouse
Looks really nice, but frankly I don’t know where to start, the code in glbox.C is unexpectedly simple… How do I retrieve the current positions of the planes?
It was just an example showing what can be done. But that’s done with OpenGL. I do not think you want that. You want to use the normal LEGo and SURF plots ? To draw in that space you can look at: Plot mean and max values of TGraphs in a TMultiGraph
What I did in the end is mainly stealing code from TH3::Project3D, find the script and a test ROOT file attached here.
As you can see there are problems in visualizing the polylines (but I find them as well with TH1::SetShowProjection, so it might be a more general bug): the horizontal plane vanishes after the respective 2D slice is drawn and the vertical one stays on screen until the next mouse click.
I cannot do that because the histograms I normally visualize are quite big (not like the test I sent you) and it takes a while to render them… redrawing the 3D scene every time would kill the performance.
I will try to play around with different implementations and see if I can fix the problem, I wanted in any case to switch to filled shapes instead of polylines, maybe the problem will vanish…
Do you know how or the point in DynamicSlice.C where the old line gets erased? I just see a double DrawLine but I don’t think it is responsible for that…
TVirtualX::kXor or TVirtualX::kInvert? Does the following work for you?
auto c = new TCanvas;
c->FeedbackMode(true); // hides a call to gVirtualX->SetDrawMode(TVirtualX::kInvert)
// gVirtualX->SetDrawMode(TVirtualX::KXor)
gVirtualX->DrawLine(0, 0, 100, 100);
gVirtualX->DrawLine(0, 0, 100, 100); // does the line stay on screen?
But the tricky thing is that in DynamicSlice.C it works… I have no clue why.
In particular, at line 47 I do canvas->FeedbackMode(true), at lines 136 and 138 I declare the static structures holding the drawn coordinates, so I can delete them with DrawPolyLine at lines 170 and 232 and finally I draw the new rectangles at lines 367 and 368.
But as you can see it does not work. Also, the simple code I quoted in one of my previous comment in an interactive ROOT session does not work for me…