About created a pdf file by Core-Plot - core-plot

Core plot is quite powerful, I use it to create ecg graph.
When I create pdf file, I encounter some problems.
Each small grid is square on my App.
But when I use -dataForPDFRepresentationOfLayer() to write to the pdf file, small grid is not square.
The pdf file's "minorGridLine" on wrong position.
I set up the pixel dimensions of the plot area and number of grid lines.
Each small grid is square on my app, but small grid isn't square on the pdf file.
How to solve this problem?
Thanks,
Midas

You're seeing the effect of aligning the grid lines to pixel boundaries to get crisper edges on the lines. The upper image (the screenshot) looks like a 1x render with blurred minor grid lines and anti-aliasing on the data line. The bottom image (the PDF) has crisp line edges implying a higher resolution (2x or 3x) drawing canvas. When the resolution is high enough to render the line width with an integer number of pixels, Core Plot moves the lines to fall on the nearest pixel boundaries to eliminate the fuzzy edges caused by anti-aliasing.
Possible solutions are to ensure that the pixel dimensions of the plot area are an even multiple of the number of minor tick locations (accounting for the contentsScale of the graph) or adjusting the line width of the minor grid lines so it's not possible to render them with an integer number of pixels. For example, use a line width of 0.4 instead of 0.5.

Related

How to do texture edge padding for tiling correctly?

My aim is to draw a set of texures (128x128 pixels) as (gap-less) tiles without filtering artifacts in XNA.
Currently, I use for example 25 x 15 fully opaque tiles (alpha is always 255) in x-y to create a background image in a game, or a similar number of semi-transparent tiles to create the game "terrain" (foreground). In both cases, the tiles are scaled and drawn using floating-point positions. As it is known, to avoid filtering artifacts (like small but visible gaps, or unwanted color overlaps at the tile borders) one has to do "edge padding" which is described as adding an additional fringe of a width of one pixel and using the color of adjacent pixels for the added pixels. Discussions about this issue can be found for example here. An example image of this issue from our game can be found below.
However, I do not really understand how to do this - technically, and specifically in XNA.
(1) When adding a fringe of one pixel width, my tiles would then be 129 x 129 and the overlapping fringes would create quite visible artifacts of their own.
(2) Alternatively, once could add the padding pixels but then not draw the full 129x129 pixel texture but only its "center" (without the fringe) e.g. by choosing the source rectangle of this texture to be (1,1,128,128). But are then the padding pixels not simply ignored or is the filtering hardware really using this information?
So basically, I wonder how this is done properly? :-)
Example image of filtering issue from game: Unwanted vertical gap in brown foreground tiles.

OpenCV warp perspective to align and equalize rectangle size

I'm trying to align two rectangles using the perspectiveTransform. In the image below there are the two orange rectangles (I know their dimensions and locations) and I want to warp the perspective so that they are of approximately the same size and in line (the green ones in the image). A perspectiveTransform that e.g. makes the small one equal in size with the big one doesn't really do the trick, as the size of the big one changes too. Any help much appreciated!

A 2D grid of 100 x 100 squares in OpenGL ES 2.0

I'd like to display a 2D grid of 100 x 100 squares. The size of each square is 10 pixels wide and filled with color. The color of any square may be updated at any time.
I'm new to OpenGL and wondered if I need to define the vertices for every square in the grid or is there another way? I want to use OpenGL directly rather than a framework like Cocos2D for this simple task.
You can probably get away with just rendering the positions of your squares as points with a size of 10. GL_POINT's always are a set number of pixels wide and high, so that will keep your squares 10 pixels always. If you render the squares as a quad you will have to make sure they are the right distance from the camera to be 10 pixels wide and high (also the aspect may affect it).

Computer vision for a length ratio

Let's say I take a picture of two hammers side-by-side (although they may be aligned differently, but always one on the right and one on the left), wherein each might look like this, and I want to calculate the ratio of the lengths of the handles of the hammers.
For example, the output from an input image would be the length of the red part of the one on the left (its handle) divided by the length of the handle of the one on the right.
How would I go about doing this?
If you know the handle color it doesn't sound hard. Just select those pixels and take the longer side of a minimum oriented bounding box.
Here are a couple of hints:
Make sure that the bounding boxes of the hammers don't overlap. If you can guarantee this, try this approach:
Scale the image to width=10%, height=10px. Find the largest amount of pixels in background color near the middle of the image. That allows you to separate the two hammers into individual images. Multiply the positions by 10 to transform them back into coordinates of the original image.
Create two images (one for each hammer)
Crop the border
Scale the image to width = 10px, height = 10%. Count all reddish pixels (save the image and examine the pixel values for red and non-red parts to get an idea what to look for)

Calculating the cells contained inside a rectangle on an Isometric Grid

Consider that we are given an isometric grid (consider something like Diablo) of tiles. We have some measures for the grid, like grid height, grid width and tile height/width. Consider this image:
The center cell of the grid is 0,0 extending iso-north (+y), iso-south(-y), iso-east(+x), iso-west(-x).
Let's say we to draw a rectangle at an arbitrary location on the grid. We do NOT have the isometric positions for the rectangle, but rather have the normal draw coordinates for the grid where the top left hand corner is 0,0 and south is y+, right is x+.
If we had the top, left, height, width of the rectangle in question - how could we calculate an array of iso-cells that crossed by the bottom edge of the rectangle.
Any language you choose to demonstrate this will suffice.
In some papers and books about isometric programming (Isometric programming with Direct X7, yes its old but gives an overview about the problems and techniques) they use mousemaps.
Also there is the technique to render the area of the map covered by the rectangle into an image, each tile gets a unique color (and it is just the color rendered). Afterwards they check which colors are in the image and so extract the list of tiles.
Since you are using a classic isometric tile width half height there could be a mathematical solution too. Unfortunatly an suggested algorithm would depend heavily on your map layout.
The code for a Java based TileSystem can be found here

Resources