How to get the cursor position in Windows? - c++

I need to check a pixel color and I let the user tag the position on the screen.
I've tried both GetCursorPos() and GetPhysicalCursorPosition() but neither returns the correct value.
(I noticed that getting my screen resolution via GetSystemMetrics returns a wrong resolution as well. It reports to be 2560x1440, but it really is 3840x2160.)
So, when multiplying the result of GetCursorPos() by 1.5, I do get the correct cursor position for my monitor. However, the positions on my other two 1080p monitors are still wrong. They were not correct before.

Related

Way to set the value of Image Position (patient) tag of DICOM slice

Is there any way to set the value of Image Position (patient) tag of DICOM slice using DCMTK.
Detailed Explanation
I have this
In this window, the user needs to enter the x,y and z values of the ImagePosition(patient) tag in the DICOM slice which the user need to find.
I will take those x,y,z values in some variable say, xval,yval,zval.
And now I need to set these values in the DICOMImageReader reader or using any VTK variable (like vtkMarchingSquares or vtkClipper or vtkPlane ..etc) so that I can either show or clip where the corresponding slice is, in the 3D rendered output.
Is my question clear? Is there any possible way?
What I tried
1.To clip the corresponding slice in 3D rendered output
I tried using vtkClipPolyData1 clipper like below
plane->SetOrigin(0,0,0);//vtkPlane//
plane->SetNormal(xval,yval,zval);
clipper->SetClipFunction(plane);
But this is not working.
I also tried[don't know whether this is right or wrong]
double a=(double)(xval)/100;
double b=(double)(yval)/100;
double c =(double)(zval)/100;
clipper->SetNormal(a,b,c);
but this code is not clipping the exact position,it is clipped at somewhere else.
2.To show the corresponding slice in 3d rendered output
vtkSmartPointer<vtkLookupTable> bwLut =vtkSmartPointer<vtkLookupTable>::New();
bwLut->SetTableRange (0, 2000);
bwLut->SetSaturationRange (0, 0);
bwLut->SetHueRange (0, 0);
bwLut->SetValueRange (0, 1);
bwLut->Build();
vtkSmartPointer<vtkImageMapToColors> sagittalColors =
vtkSmartPointer<vtkImageMapToColors>::New();
sagittalColors->SetInputConnection(reader->GetOutputPort());
sagittalColors->SetLookupTable(bwLut);
sagittalColors->Update();
vtkSmartPointer<vtkImageActor> sagittal =vtkSmartPointer<vtkImageActor>::New();
sagittal->GetMapper()>SetInputConnection(sagittalColors->GetOutputPort());
sagittal->SetPosition(xval,yval,zval);//this is where i put the values//
Anybody could help pleaseee?

How can I move the screen using SDL2, C++?

I have a window with a width of 260 pixels. By using the DrawSurface function I can put an image on the position which is not visible on the screen, for example (500, 10). Now I want to move the screen (by pressing the button) to the point where is the image. Is it possible?
I'm not sure how accurate or up-to-date this article is but it gives a lot of starting code for implementing a makeshift camera using an SDL_Rect variable. In your case, you would modify the x and y variables of the camera object and use the apply_surface() method to show textures relative to the camera's position.

Pyplot rotated labels offset by one

Just getting into matplot lib and running into odd problem - I'm trying to plot 10 items, and use their names on the x-axis. I followed this suggestion and it worked great, except that my label names are long and they were all scrunched up. So I found that you can rotate labels, and got the following:
plt.plot([x for x in range(len(df.columns))], df[df.columns[0]], 'ro',)
plt.xticks(range(10), df.columns, rotation=45)
The labels all seem to be off by a tick ("Arthrobacter" should be aligned with 0). So I thought my indexing was wrong, and tried a bunch of other crap to fix it, but it turns out it's just odd (at least to me) behavior of the rotation. If I do rotation='vertical', I get what I want:
I see now that the center of the labels are clearly aligned with the ticks, but I expected that they'd terminate on the ticks. Like this (done in photoshop):
Is there a way to get this done automatically?
The labels are not "off", labels are actually placed via their "center". In your second image, the corresponding tick is above the center of the label, not above its endpoint. You can change that by adding ha='right' which modifies the horizontal alignement of the label.
plt.plot([x for x in range(len(df.columns))], df[df.columns[0]], 'ro',)
plt.xticks(range(10), df.columns, rotation=45, ha='right')
See the comparison below :
1)
plt.plot(np.arange(4), np.arange(4))
plt.xticks(np.arange(4), ['veryverylongname']*4, rotation=45)
plt.tight_layout()
2)
plt.plot(np.arange(4), np.arange(4))
plt.xticks(np.arange(4), ['veryverylongname']*4, rotation=45, ha='right')
plt.tight_layout()

Clips are not linking up end to end

it has been a big while since I have last used After Effects.
Currently I am getting into a problem in which I have a few footages, tried changing the frame rate etc but it does not seems to help.
You can see in the image, the the lower bar clip is not starting right off at the end of the first clip, since the first clip ends off slightly more than the 07f mark.
As such, if I try to add in another clip, it can only be at the 07f or the 08f mark.
Is there anyways that I can make it 'linked' up end to end?
Just hold Shift button while dragging the second footage.
And to easily change the frame-rate you can use video copilot frame rate converter

OpenGL: Current raster position stays invalid (freaky error, makes no sense)

I am getting a rather odd error while displaying bitmap texts on screen and using glRasterPos3f function to position them. When I start the application, all my texts fit inside the view and everything works fine and dandy. However, things start to get really messed up as soon as one of them gets outside the view - all my texts disappear and won't reappear ever again not even if I set the view back to its original position.
I did some investigation and made an explicit check of the raster position validity flag, like this:
glRasterPos3f(xPos, yPos, zPos);
// check raster position validity
GLboolean valid;
pin_ptr<GLboolean> p_valid = &valid;
glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, p_valid);
if (!valid)
return;
Well now this is when things start to really boggle my mind - the condition at the end of this code gets triggered not just when a text position gets outside the view, but from then on ever since! It drives me into despair. Even if I restore the view to its usual working state, the validity bit appears to stay cleared forever. Any ideas on what might be the possible cause for this or maybe how to restore raster position manually somehow?
EDIT: Some pics...
Initial state, all is well:
http://i.imgur.com/SFGU4QI.png
I zoom in, some raster position gets invalid, texts disappear:
http://i.imgur.com/cj2xVAs.png
When I zoom back out again, there still aren't any texts...
All OpenGL raster operations are discarded if the glRasterPos transforms to outside the clip space to NDC space volume. So if your text starts out at a position outside the visible viewport it won't show up. And if the text extends to beyond the visible viewport, everything after the last character visible will get messed up.
Which means, glRasterPos is rather useless. It's use is strongly discouraged, as are all OpenGL raster operations. In fact those have been removed entirely from modern OpenGL versions.