Getting wrong coordinate from Cesium-DrawHelper shape created event - terrain

i am using cesium with drawHelper plugin on GWT (Cesium Terrain Server for terrain). i am drawing shapes(marker , polyline , polygon..) to my 3d map.
I can draw shapes to the map with exact coordinates where my mouse is pointing but when i change the angle of camera look , i cannot draw shapes where my mouse pointing because i am getting wrong coordinates and this leads to draw my shapes on wrong coordinates.
(i get coordinates from DrawHelpers shape create event for instance 'markerCreated' returns position)

I solved my problem with editing DrawHelper.js ,
it was getting position with scene.camera.pickEllipsoid function , i changed it with creating a ray and picking position via globe.pick. Code :
var cartesian = scene.camera.pickEllipsoid(movement.position,ellipsoid)
Replaced it with
var ray = scene.camera.getPickRay(movement.position);
var pickedPosition = scene.globe.pick(ray,scene);
if(pickedPosition){
markers.addBillBoard(pickedPosition);
_self.stopDrawing();
options.callback(pickedPosition);
Adding marker on terrain to the coordinates which pointing from mouse fixed like this...

Related

Get face coordinates using affdex sdk

It's possible to get face coordinates in image source file or frame? Some thing like:
face.Height = Affdex.Face[0].PositionHeight;
face.Left = Affdex.Face[0].PositionLeft;
face.Top = Affdex.Face[0].PositionTop;
face.Width = Affdex.Face[0].PositionWidth;
http://developer.affectiva.com/fpi/
The bounding box for each face is not provided directly via the Affdex SDKs, but they do provide coordinates for all the face points, so to determine a face's bounding box, all you need to do is iterate through its face points and track the max/min values in each dimension.
As an example, see the drawFacePoints method in the DrawingView class of the AffdexMe sample app: https://github.com/Affectiva/affdexme-android/blob/master/app/src/main/java/com/affectiva/affdexme/DrawingView.java

Openlayer distors vector shapes

I have a problem with drawing my vector shapes - when I zoom enough, it looks like some coordinates are skipped and the shape gets distorted - see the attached picture:
The shape is loaded from geojson file, where it's defined like:
"coordinates":[[[18.58235,49.81784],[18.58545,49.81738],[18.59252,49.81296]
,[18.59279,49.80395],[18.59986,49.79953],[18.60013,49.79051]
,[18.60719,49.78609],[18.61425,49.78168],[18.61093,49.7663]
,[18.07565,49.432],[18.07509,49.43198],[18.06119,49.43289]
,[18.04734,49.43411],[18.03356,49.43564],[18.01987,49.43747]
,[18.00628,49.4396],[17.99281,49.44204],[17.98218,49.44422]]]
Any idea, what's wrong?
Marek
Your polygon geometry is invalid. You have to add another coordinate pair at the end, with the same values as the first coordinate pair:
"coordinates":[[[18.58235,49.81784],[18.58545,49.81738],[18.59252,49.81296]
,[18.59279,49.80395],[18.59986,49.79953],[18.60013,49.79051]
,[18.60719,49.78609],[18.61425,49.78168],[18.61093,49.7663]
,[18.07565,49.432],[18.07509,49.43198],[18.06119,49.43289]
,[18.04734,49.43411],[18.03356,49.43564],[18.01987,49.43747]
,[18.00628,49.4396],[17.99281,49.44204],[17.98218,49.44422]
,[18.58235,49.81784]]]

depth image based rendering

I have to implement a depth image base rendering. Given a 2D image and a depth map, the algorithm will generate a virtual view - what the scene would look like if a camera was placed in a different position. I wrote this function, V is the matrix with the pixel of 2d view, D the pixels from depth map and camera shift a parameter.
Z=1.1-D./255; is a normalization. I try to follow this instruction:
For each pixel in the depth map, compute the disparity that results from the depth, For each pixel in the source 2D image, find a new location for it in the virtual view: old location + disparity of that specific pixel.
The function doesnt work very well, what's wrong?
function[virtualView]=renderViews(V,D,camerashift)
Z=1.1-D./255;
[M,N]=size(Z);
for m=1:M
for n=1:N
d=camerashift/Z(m,n);
shift=round(abs(d));
V2(m,n)=V(m+shift,n);
end
end
imshow(V2)

Obtaining 3D location of an object being looked at by a camera with known position and orientation

I am building an augmented reality application and I have the yaw, pitch, and roll for the camera. I want to start placing objects in the 3D environment. I want to make it so that when the user clicks, a 3D point pops up right where the camera is pointed (center of the 2D screen) and when the user moves, the point moves accordingly in 3D space. The camera does not change position, only orientation. Is there a proper way to recover the 3D location of this point? We can assume that all points are equidistant from the camera location.
I am able to accomplish this independently for two axes (OpenGL default orientation). This works for changes in the vertical axis:
x = -sin(pitch)
y = cos(pitch)
z = 0
This also works for changes in the horizontal axis:
x = 0
y = -sin(yaw)
z = cos(yaw)
I was thinking that I should just make combine into:
x = -sin(pitch)
y = sin(yaw) * cos(pitch)
z = cos(yaw)
and that seems to be close, but not exactly correct. Any suggestions would be greatly appreciated!
It sounds like you just want to convert from a rotation vector (pitch,yaw,roll) to a rotation matrix. The conversion can bee seen on the Wikipedia article on rotation matrices. The idea is that once you have constructed your matrix, to transform any point simply.
final_pos = rot_mat*initial_pose
where final and initial pose are 3x1 vectors and rot_mat is a 3x3 matrix.

Drawing an angle/angular/"Conical"/"Arcing" gradient in Objective-C (IOS) using Core Graphics

I'm trying to draw a "conical"/"arcing" gradient (I don't know what would be the correct term for this) (Photoshop calls it an "angle" gradient —your friendly neighborhood stackoverflow editor) using Objective-C (IOS), pretty much exactly like the image shown in the following thread.
After days of googling and searching the internet to no avail, I've decided to ask for help here.
A little background on what I'm trying to do. My objective is to create a custom UIView, which is circular progress bar, a ring basicly, somewhat similar to the activity indicator as seen in the TweetBot iPhone app (displays when you drag to refresh, which can be seen in action here, around 17-18 seconds into the video, on top of the iphone screen). I want the progress indicator (the fill of the ring) to be a simple two color gradient, which can be set programmatically, and the view to be resizable.
Filling the ring shape with a gradient that "follows" the arc of the ring is where I'm stuck. The answers that I get from googling, reading Apple's Core Graphics documentation on gradients and searching on SO are either about radial gradients or linear/axial gradients, which is not what I'm trying to achieve.
The thread linked above suggests using pre-made images, but this isn't an option because the colors of the gradient should be settable, the view should be resizable and the fill of the progress bar isn't always 100% full obviously (which would be the state of the gradient as shown in the picture in the thread above).
The only solution that I've come up with is to draw the gradient "manually", so without using a CGGradientRef, clipping small slices of the gradient with single solid color fills within a circular path. I don't know exactly how well this will perform when the bar is being animated though, it shouldn't be that bad, but it might be a problem.
So my first question:
Is there an easier/different solution to draw a conical/arcing gradient in Objective-C (IOS) than the solution I've come up with?
Second question:
If I have to draw the gradient manually in my view using the solution I came up with, how can I determine or calculate (if this is even possible) the value (HEX or RGBA) of each color "slice" of the gradient that I'm trying to draw, as illustrated in the image below.
(Can't link image) gradient slice illustration
Looks to me like a job for a pixel shader. I remember seeing a Quartz Composer example that simulated a radar sweep, and that used a pixel shader to produce an effect like you're describing.
Edit:
Found it. This shader was written by Peter Graffignino:
kernel vec4 radarSweep(sampler image, __color color1,__color color2, float angle, vec4 rect)
{
vec4 val = sample(image, samplerCoord(image));
vec2 locCart = destCoord();
float theta, r, frac, angleDist;
locCart.x = (locCart.x - rect.z/2.0) / (rect.z/2.0);
locCart.y = (locCart.y - rect.w/2.0) / (rect.w/2.0);
// locCart is now normalized
theta = degrees(atan(locCart.y, locCart.x));
theta = (theta < 0.0) ? theta + 360.0 : theta;
r = length(locCart);
angleDist = theta - angle;
angleDist = (angleDist < 0.0) ? angleDist + 360.0 : angleDist;
frac = 1.0 - angleDist/360.0;
// sum up 3 decaying phosphors with different time constants
val = val*exp2(-frac/.005) + (val+.1)*exp2(-frac/.25)*color1 + val*exp2(-frac/.021)*color2;
val = r > 1.0 ? vec4(0.0, 0.0,0.0,0.0) : val; // constrain to circle
return val;
}
The thread linked above suggests using pre-made images, but this isn't an option because the colors of the gradient should be settable, the view should be resizable and the fill of the progress bar isn't always 100% full obviously (which would be the state of the gradient as shown in the picture in the thread above).
Not a problem!
Use the very black-to-white image from the other question (or a bigger version if you need one), in the following fashion:
Clip to whatever shape you want to draw the gradient in.
Fill with the color at the end of the gradient.
Use the black-to-white gradient image as a mask.
Fill with the color at the start of the gradient.
You can rotate the gradient by rotating the mask image.
This only supports the simplest case of a gradient with a color at each extreme end; it doesn't scale to three or more colors and doesn't support unusual gradient stop positioning.
FYI: here's also a good tutorial for creating a circular progress bar using Quartz drawing.
http://www.turnedondigital.com/blog/quartz-tutorial-how-to-draw-in-quartz/