Leaflet polygon object attributes - arrays

Within a leaflet polygon object, there are two arrays "_originalPoints" and "_parts", I was wondering if anyone knew what the purpose of these two arrays were.
Thanks,

I'm Leaflet author.
_originalPoints is an array of projected geographical points (screen coordinates of the polygon points), and _parts is an array of arrays of points that eventually gets rendered after clipping and simplifying points. In case of polygon different "parts" are needed to render holes in polygons, and in case of polylines you often get several paths out of one after clipping (cutting points off a certain rectangular area for performance).

Related

Dividing up a map into polygon regions based on a list of single point coordinates

I'm trying to divide up a city map into polygon regions based on a list of single point coordinates.
The idea is that a polygon region would extend outwards from a single point in all directions until it bordered with polygon regions extending out from nearby / adjacent points. I don't want to use a fixed radius because I want the end result to be complete coverage of the map. So the regions will be irregularly shapes and sized, extending their "territory" as far as possible before bumping up against other territories or the map boundary.
Does anyone know of an algorithm, library or program that can generate such a list of polygons given a list of single point coordinates and a map boundary?
Perhaps you want delaunay-triangulation or a voronoi diagram.
Example page from JSTS
delaunay triangulation
voronoi diagram

how do I do "reverse" texture mapping from texture image x,y to 3d space?

I am using WPF 3D, but I think this question should apply to any 3d texture mapping.
Suppose I have a model of a cow, and I want to draw a circular spot on the cow (and I want to do this dynamically -- supposed I don't know the location of the spot until run-time). I could do this by coloring the vertexes (vertexes are assigned a color based on their distance from the center of the spot), but if the model is fairly low-poly, that will give a pretty jagged-edged circle.
I could do it using a pixel shader, where the shader colors each pixel based on its distance from the center of the spot. But suppose I don't have access to pixel shaders (since I don't in WPF).
So, it seems that what I want to do is dynamically create a texture with the circle pattern on it, and texture the cow with it.
The question is: As I'm drawing that texture, how can I know what 3d coordinate in model space a given xy coordinate on the texture image corresponds to?
That is, suppose I have already textured my model with a plain white texture -- I've set up texture coordinates, done texture mapping, but don't have the texture image yet. So I have this 1000x1000 (or whatever) pixel image that gets draped nicely over the cow according to some nice texture coordinates that have been set up on the model beforehand. I understand that when the 3D hardware goes to draw a given triangle, it uses the texture coordinates of the vertexes of the triangle to find the corresponding triangular region of the image, and then interpolates across the surface of the triangle to fill displayed model pixels with colors from that triangular region of the image.
How do I go the other way? How do I say, for this given xy point on my texture image, and given the texture coordinates that have already been set up on the model, what's the 3d coordinate in model space that this image pixel is going to correspond to once texture mapping happens?
If I had such a function, I could color my texture map image such that all the points (in 3d space) within a certain distance of the circle center point on the cow would get one color, and all points outside that distance would get another color, and I'd end up with a nice, crisp circular spot on the cow, even with a relatively low-poly model. Does that sound right?
I do understand that given the texture coordinates for the vertexes of each triangle, I can step through the triangles in my model, find the corresponding triangle on the texture image, and do my own interpolation, across the texture pixels in that triangle, by interpolating across the 3d plane determined by the vertex points. And that doesn't sound too hard. But I'm just trying to understand if there is some standard 3d concept/function where I can just call a ready-made function to give me the model space coordinates for a given texture xy.
I did end up getting this working. I walk every point on the texture (1024 x 1024 points). Using the model's texture coordinates, I determine which polygon face, if any, the given u,v point is inside of. If it's inside of a face, I get the model coordinates for each point on that face. I then do a barycentric interpolation as described here: http://paulbourke.net/texture_colour/interpolation/
That is, for each u,v point on the texture, I use an inside-polygon check to determine which quad it's in on the 2D texture sheet and then I use an interpolation on that same 2D geometry as described in the link above, but instead of interpolating colors or normals I'm interpolating 3D coordinates.
I can then use the 3D coordinate to color the point on the texture (e.g., to color a circular spot on the cow based on how far in model space the given texture point is from the spot center point). And then I can apply the texture to the model, and it works.
Again, it seems like this must be a standard procedure with a name...
One issue is that the result is very sensitive to the quality of the the texturing as set up by the modeler. For instance, if a relatively large quad on the cow corresponds to a small quad on the texture image, there just aren't enough pixels to work with to get a smooth curve within that model quad once the texture is applied. You can of course use a higher-res texture, such as 2048x2048, but then your loop time is 4x.
It's actually a rasterization process if I didn't misunderstand your question. In lightmapping, one may also need to find the corresponding positions and normals in world space for each texel in the lightmap space and then baking irradiance. (which seems similar to your goal)
You can use standard Graphics API to do this task instead of writing your own implementation. Let:
Size of texture -> Size of G-buffers
UVs of each mesh triangle -> Vertex positions vec3(u, v, 0) of the input stage
Indices of each mesh triangle -> Indices of the input stage
Positions (and normals, etc.) of each mesh triangle -> Attributes of the input stage
After the rasterizer stage of the graphics pipeline, all fragments that lie within the UV triangle are generated, and the attributes that have been supplied are interpolated automatically. You can do whatever you want now in pixel shader!

"Determine velocity 2D of an object using Camera"- How to track the centroid of the object?

I'm trying to make a project "Determine velocity 2D of an object using Camera". That's just 2D velocity. I want to use Lucas Kanade algorithm in OpenCV. But I can't distinguish what coner belong to my object, and i can't find the centroid of my object to track ( This is white object place in Black background, this object have any shape, example: square, elip,.. ). How do I track the centroid of the object to determine the distance of the motion? Do I need use Lucas Kanade algorithm to make this project? Please help me.
To obtain the velocity of an object you need to do two things, firstly you need to detect the object in each image (and condense it to the centroid as you have suggested), secondly you need to associate detected objects across different images. Once you've done that the velocity can be easily calculated by the simple equation of motion velocity = distance/time.
Association is easy if you only detect one object in each image (just assume the detection is the object), although this approach is liable to break in the real world.
Detecting your object is where I believe you are having difficulty. If it really is as simple as a single white object against a solid black background then finding the centroid should be simple, simply average the coordinates of all white pixels. If you have a noisy image, then you will need to do some cleaning up first, for example morphological closing and opening operations to remove small specks of noise.

Convert 3D mesh to 2D and place it on WPF Canvas

Is it possible to convert 3D object from Viewport3D and show it on Canvas, but conversion MUST NOT be depended from a camera position and its view point.
By another words using WPF i would like to make 4 views like in 3Ds Max, such as: Perspective (for 3D objects) and Front, Top, Left views (for 2D ).
Perspective view is a Viewport3D, but how show all 3D objects from the Viewport to the other views - Top, Front and Left ?
Mathematically speaking, no, it's not possible.
However, you should be able to simulate that by specifying a Camera Position that is top, front, and left. Can't you calculate approximately where that is based on the bounds of the 3D object?
http://en.wikipedia.org/wiki/Homogeneous_coordinates#Use_in_computer_graphics

Rectangle matrix calculations in OpenCV

I had a generalized question to find out if it was possible or not to do matrix calculations on a rectangle. I have a CvRect that has information stored in it with coordinates and I have a cvMat that has transformational data. What I would like to know is if there was a way to get the Rect to use the matrix data to generate a rotated, skewed, and repositioned rectangle out of it. I've searched online, but I was only able to get information on image transforms.
Thanks in advance for the help.
No, this is not possible. cv::Rect is also not capable of that, as it only describes rectangles in a Manhattan world. There is cv::RotatedRect, but this also does not handle skewing.
You can, however, feed the corner points of your rectangle to cv::transform:
http://opencv.itseez.com/modules/core/doc/operations_on_arrays.html?highlight=transform#cv2.transform
You will then obtain four points that are transformed accordingly. Note that there are also more specialized versions of this function, e.g. warpPerspective() and warpAffine().

Resources