Lib GDX Font rendering issues - graphics

I use an OrthographicCamera set to 720 by 1280 and then set it's combined matrix as the projection matrix in my SpriteBatch. I then generate a BitmapFont using the FreeTypeFontGenerator and use it to render text.
OrthographicCamera camera = new OrthographicCamera();
camera.setToOrtho(false, 720, 1280);
SpriteBatch batch = new SpriteBatch();
batch.setProjectionMatrix(camera.combined);
This is the output:
As you can see the fonts look very distorted and the only way I found to fix it is by removing the line where I set the projection matrix in my SpriteBatch.
batch.setProjectionMatrix(camera.combined);
I put this as an issue on the lib GDX github page, but I was told this is not because of Lib GDX. I need to use this projection matrix so that I can develop my application in one resolution and have it scale to fit any screen. Is there a way to render text without encountering this problems?

Use a pixel perfect projection, by using ScreenViewport. Then use Table to layout your GUI, including its labels. This way you can also support multiple aspect ratio or even use a different layout depending on the aspect ratio.
If you want to support a wide range of resolution then you will need to provide different assets depending on the resolution. Depending on the file size you might want to use different build flavors or use ResolutionFileHandleResolver. Alternatively you can use the freetype extension to generate the correct font for the device, but be aware that that might result in additional render calls which can affect performance.
Note that all of this only applies for your GUI. For you game logic you obviously use the coordinate system that makes most sense for that (e.g. meters), with a separate camera.

Related

Custom (manual) implementation of MSAA in Vulkan

Im using Vulkan to render simple textured meshes. To achieve a smooth result, I tried to use the built-in multisampling, but the maximum available number of samples for the render target (image) is only x4. This is not enough for my purposes, I need x8/x16.
How to efficiently implement antialiasing manually?
Multisample antialiasing is a technique that requires cooperation from the rasterizer, render targets, and other portions of the per-fragment processing hardware. It's a technique that rasterizes at a higher resolution, but only executes the fragment shader at a lower resolution, broadcasting the results across multiple samples within the same pixel area.
That's not something you can do manually.
You can always resort to super-sampling (render at a high resolution and then downsample). Or you can use faux antialiasing techniques like FXAA and the like. But you can't emulate MSAA manually.

Is there any code for an interactive plotting application for a two dimensional curves

Plotting packages offer a variety of methods for displaying data. Write an interactive plotting application for two dimensionsional curves. Your application should be able to allow the user to choose the mode (line strip or polyline display of the data, bar chart or pie charts), colours, and line styles.
You should start with the GUI editation like this:
Does anyone know of a low level (no frameworks) example of a drag & drop, re-order-able list?
and change it to your primitives (more points per primitive instead of one ... handle each point as (sub)object so you can change its position later).
Then just add tools like add object,del object,... For hand drawing tool use piece wise interpolation cubics
The grid can be done like this:
How to draw dynamic 2D grid that adjusts according to camera zoom: OpenGL
Mouse zooming/panning is also important
Zooming graphics based on current mouse position
Putting all above together into simple editor looks like this:
Using GPU for curve rendering might give you some nice speed and functionality boost:
Is it possible to express "t" variable from Cubic Bezier Curve equation?
Mouse selection of objects might be a speed problem if your scene contains too many objects so in such case its best to use index buffers where you can mouse select with pixel perfect precision for almost free in O(1):
OpenGL 3D-raypicking with high poly meshes
The example is for 3D , in 2D is much simpler ...
Also do not forget to implement save/load functionality to some vector file format. I recommend using SVG it might be complicated to start with it but you can quickly check it contents in any SVG viewer or browser also in notepad as its just a text file. If you use just basic path elements and ignore the rest of SVG features you will see the parsing and creating SVG is not that hard for example See these:
Get Vertices/Edges From BMP or SVG (C#)
Discrete probability distribution plot with given values
For really big datasets you might want to use spatial subdivision techniques (Bounding (Volume)Area Hierarchy, or Quad tree) to ease up the operations...
More in depth implementation details about 2D vector gfx editors depends on language, OS, gfx api and GUI api you using and task you are aiming for ...

How to make image fit screen in Godot

I am new in godot engine and I am trying to make mobile game (portrait mode only). I would like to make background image fit screen size. How do I do that? Do i have to import images with specific sizes and implement them all for various screens? If I import image to big, it will just cut out parts that don't fit screen.
Also, while developing, which width and height values should I use for these purposes?
With Godot 3, I am able to set size and position of sprite / other UI elements using script. I am not using the stretch mode for display window.
Here is how you can easily make the sprite to match viewport size -
var viewportWidth = get_viewport().size.x
var viewportHeight = get_viewport().size.y
var scale = viewportWidth / $Sprite.texture.get_size().x
# Optional: Center the sprite, required only if the sprite's Offset>Centered checkbox is set
$Sprite.set_position(Vector2(viewportWidth/2, viewportHeight/2))
# Set same scale value horizontally/vertically to maintain aspect ratio
# If however you don't want to maintain aspect ratio, simply set different
# scale along x and y
$Sprite.set_scale(Vector2(scale, scale))
Also for targeting mobile devices I would suggest importing a PNG of size 1080x1920 (you said portrait).
Working with different screen sizes is always a bit complicated. Especially for mobile games due to the different screen sizes, resolutions and aspect ratios.
The easiest way I can think of, is scaling of the viewport. Keep in mind that your root node is always a viewport. In Godot you can stretch the viewport in the project settings (you have to enable the stretch mode option). You can find a nice little tutorial here.
However, viewport stretching might result in an image distortion or black bars at the edges.
Another elegant approach would be to create an image that is larger than you viewport and just define an area that has to be shown on every device no matter whats the resolution. Here is someone showing what I am meaning.
I can't really answer your second question about the optimal width and height but I would look for the most typical mobile phone resolutions and ratios and go with that settings. In the end you probably should start with using the width and height ratio of the phone you want to use for testing and debugging.
Hope that helps.

Geogebra resizing shapes without copying

How do I resize a shape without making a copy and using dilate from point?
How my shape with vectors looks like
How do I limit the axes range for exporting?
How do I define a size, say 3 cm for cropping a portion of the graphics view for export?
Also, is there any software for making simulated graphs without any real data? I'm doing image processing and need to make mock-ups such as temporal segments and histograms.
I guess this question is out of scope of stackoverflow and should be asked in https://help.geogebra.org , but I'll try anyway.
1) You can right-click the graphics view and set the dimensions in there. The export will take the current graphics view. Or you can select part of Graphics using the mouse before export. Or use points Export_1, Export_2 as described here
2) You define cropping of graphics view in one of the ways described above to eg. 6 units, then set the export scale to 0.5cm per unit
3) You can do random functions in GeoGebra directly, eg.
Function[Join[{0,5},Sequence[3*sin(k)+RandomUniform[0, 1],k,0,5,0.1]]]

DICOM Image is too dark with ITK

i am trying to read an image with ITK and display with VTK.
But there is a problem that has been haunting me for quite some time.
I read the images using the classes itkGDCMImageIO and itkImageSeriesReader.
After reading, i can do two different things:
1.
I can convert the ITK image to vtkImageData using itkImageToVTKImageFilter and the use vtkImageReslicer to get all three axes. Then, i use the classes vtkImageMapper, vtkActor2D, vtkRenderer and QVTKWidget to display the image.
In this case, when i display the images, there are several problems with colors. Some of them are shown very bright, others are so dark you can barely see them.
2.
The second scenario is the registration pipeline. Here, i read the image as before, then use the classes shown in the ITK Software Guide chapter about registration. Then i resample the image and use the itkImageSeriesWriter.
And that's when the problem appears. After writing the image to a file, i compare this new image with the image i used as input in the XMedcon software. If the image i wrote ahs been shown too bright in my software, there no changes when i compare both of them in XMedcon. Otherwise, if the image was too dark in my software, it appears all messed up in XMedcon.
I noticed, when comparing both images (the original and the new one) that, in both cases, there are changes in modality, pixel dimensions and glmax.
I suppose the problem is with the glmax, as the major changes occur with the darker images.
I really don't know what to do. Does this have something to do with color level/window? The most strange thing is that all the images are very similar, with identical tags and only some of them display errors when shown/written.
I'm not familiar with the particulars of VTK/ITK specifically, but it sounds to me like the problem is more general than that. Medical images have a high dynamic range and often the images will appear very dark or very bright if the window isn't set to some appropriate range. The DICOM tags Window Center (0028, 1050) and Window Width (0028, 1051) will include some default window settings that were selected by the modality. Usually these values are reasonable, but not always. See part 3 of the DICOM standard (11_03pu.pdf is the filename) section C.11.2.1.2 for details on how raw image pixels are scaled for display. The general idea is that you'll need to apply a linear scaling to the images to get appropriate pixel values for display.
What pixel types do you use? In most cases, it's simpler to use a floating point type while using ITK, but raw medical images are often in short, so that could be your problem.
You should also write the image to the disk after each step (in MHD format, for example), and inspect it with a viewer that's known to work properly, such as vv (http://www.creatis.insa-lyon.fr/rio/vv). You could also post them here as well as your code for further review.
Good luck!
For what you describe as your first issue:
I can convert the ITK image to vtkImageData using itkImageToVTKImageFilter and the use vtkImageReslicer to get all three axes. Then, i use the classes vtkImageMapper, vtkActor2D, vtkRenderer and QVTKWidget to display the image.
In this case, when i display the images, there are several problems with colors. Some of them are shown very bright, others are so dark you can barely see them.
I suggest the following: Check your window/level in VTK, they probably aren't adequate to your images. If they are abdominal tomographies window = 350 level 50 should be a nice color level.

Resources