Creating a PCL point cloud using a container of Eigen Vector3d - eigen

I am trying to generate a PCL point cloud. All my points are in the following container type:
std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d> >
I would like to create a pointer to a PCL point cloud:
pcl::PointCloud<pcl::PointXYZ>::Ptr pc
What would be the most efficient way to create this point cloud?

Since PCL seems to use a float[4] to store the points, when you specify pcl:PointXYZ, you will have to copy each element individually (not tested):
pc->points.resize( v.size() );
for(size_t i=0; i<v.size(); ++i)
pc->points[i].getVector3fMap() = v[i].cast<float>();
if you used a vector4d instead and ensured that the last coefficient of each element is 0, you could do a memcpy or even a swap (with a bit of trickery).

Point Cloud:
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
Vector:
std::vector<pcl::PointCloud<pcl::PointXYZ>, Eigen::aligned_allocator<pcl::PointXYZ> > vectorOfPointCloud;
Push-back to add point clouds into a vector:
vectorOfPointCloud.push_back(*cloud);

Related

GameMaker studio 2. Player Knockback

trying to create a player damage indication when a collision with an enemy occurs.
I used this code within a collision event of the player object:
direction = point_direction(other.x,other.y,x,y);
hsp = lengthdir_x(6,direction);
vsp = lengthdir_y(4,direction)-2;
if (sign(hsp) !=0) image_xscale = sign(hsp);
However, the player object is simply pushed upward vertically rather than backwards in a parabola.
Any, ideas on how to implement a basic knockback system?
If you want a parabola, you can add an upward force afterward, like so:
direction = point_direction(other.x, other.y, x , y);
speed = 6
motion_add(90, 3)
If you don't and you'd rather a more "repeatable" parabola that always look the same, maybe you should use another method, something like
if other.x>x {hdirection=1}else{hdirection=-1}
hspeed = hdirection*6
vspeed = -2
I believe this would work better for what you're trying to achieve, unless you want to implement knockback variable depending on the angle of collision.
So I would need to see all the rest of your player physics to be sure, but I can tell you right now that direction = point_direction(other.x,other.y,x,y); is probable not what you mean, and same goes for lengthdir(). The exact origins of the colliding objects at the moment of collision have a huge effect on what that direction is, which can cause a lot of screwiness. For example: if the line is perfectly horizontal (because other.y == y) then lengthdir_y() will always be equal to zero for any input value no matter how huge.
But more importantly direction is a built-in variable of GameMaker, so using it with a custom physics system can also cause some screwiness. Fox's answer might help if you are using built-ins, but based on the fact that you have an "hsp" and "vsp" instead of hspeed and vspeed, my guess is you want to avoid built-ins.
If you just want to get the horizontal direction of the collision, you should use sign(x - other.x). Then, instead of using lengthdir(), you can just use a constant. Here it is all together:
var dir = sign(x - other.x)
hsp = 6*dir; //I'm assuming that 6 is how much horizontal you wanted
vsp = -4;
if (sign(hsp) !=0) image_xscale = sign(hsp); //This line could just go in your step event
Hope that helps! Feel free to comment if you have more questions.

How can I access ProjectionMatrix in three.js directly?

How can I access the perspective camera's projection matrix directly and change one or more of the 16 values?
I tried the code bellow with and without .updateProjectionMatrix() and it doesn't work, probably it is overiden by an internal function:
cameraPersp.projectionMatrix.elements.set =
(a,b,c,d,
e,f,g,h,
i,j,k,l,
m,n,o,p);
cameraPersp.updateProjectionMatrix();
Also, I have no idea if it can be multiplied, added etc using .set (lack of documentation) -it doesn't raise an error though.
So, to set a given matrix to custom float values, directly:
cameraPersp.projectionMatrix.set
(a,b,c,d,
e,f,g,h,
i,j,k,l,
m,n,o,p);
To change a single matrix value directly:
cameraPersp.projectionMatrix.elements[n] = yourfloatvalue;
In both cases, updateProjectionMatrix() should NOT be called.

Paraview rotate fields

I am using Paraview 5.0.1. If any solution requires updating, I can try.
I want to programmatically obtain field plots (and corresponding PlotOverLine) of displacements and stresses in rotated coordinate systems.
What are appropriate/convenient/possible ways of doing this?
So far, I have created one Calculator filter for each component of displacements and stresses.
For instance, I used Calculators in 2D with results
(displacement.iHat)*cos(0.7853981625)+(displacement.jHat)*sin(0.7853981625)
(stress_3-stress_0)*sin(45.0*3.14159265/180)*cos(45.0*3.14159265/180)+stress_1*((cos(45.0*3.14159265/180))^2-(sin(45.0*3.14159265/180))^2)
It works fine, but it is quite cumbersome, in several aspects:
Creating them (one filter per component).
Plotting several of them in a single XY plot
Exporting them (one export per component).
Is there a simple way to do this?
PS: The Transform filter does not accomplish this. It rotates the view, not the fields.
Two solutions:
Ugly, inneficient solution
Use Transform and check "Transform All Input vectors"
Add a calculator and add a dummy array
Use transform the other way around, without checking "Transform All Input vectors"
Correct solution :
Compute the transformation yourself in a programmable filter
input = self.GetUnstructuredGridInput();
output = self.GetUnstructuredGridOutput();
output.ShallowCopy(input)
data = input.GetPointData().GetArray("YourArray")
vec = vtk.vtkDoubleArray();
vec.SetNumberOfComponents(3);
vec.SetName("TransformedVectors");
numPoints = input.GetNumberOfPoints()
for i in xrange(0, numPoints):
tuple = data.GetTuple(i)
transform(tuple) # implement the transform in python
vec.InsertNextTuple(tuple)
output.GetPointData().AddArray(vec)

OpenACCArray swap function

while trying to create an object oriented OpenACC implementation I stumbled upon this question.
From there I took the code provided by #mat-colgrove at the GTC15 (code available at http://www.pgroup.com/lit/samples/gtc15_S5233.tar).
Since I am interested how to use objects to manage data on with OpenACC I posted another question.
I was quite impressed by the ease of the OpenACCArray::swap function, so I created a small example to test it (see gist).
First I tried to just swap and hope that it is sufficient to swap the pointers on the host, but this ends in a fatal memory error. (presumably because the size and capacity members are not updated on the device)
A safer approach, that I assumed to work is to update the host, swap arrays and update device. This runs but creates wrong results.
I am compiling for nvidia accelerators.
Looks like this is my fault since I didn't test the swap routine.
The problem here is while the code is swapping the data on the host, the device copy of the objects still point to the old array. The fix is to re-attach (i.e. set the object's device pointers to the correct arrays) the lists.
void swap(OpenACCArray<type>& x)
{
type* tmp_list = list;
int tmp_size = _size;
int tmp_capacity = _capacity;
list = x.list;
_size = x._size;
_capacity = x._capacity;
x.list = tmp_list;
x._size = tmp_size;
x._capacity = tmp_capacity;
#ifdef _OPENACC
#pragma acc update device(_size,_capacity,x._size,x._capacity)
acc_attach((void**)&list);
acc_attach((void**)&x.list);
#endif
}
"acc_attach" is a PGI extension that hopefully will be adopted in the OpenACC 3.0 standard.
Thanks for trying things out and let me know if you encounter other issues.
- Mat

Find crossing lines in drawing engine

i am working on a little multimedia - project in which the user, amongst other things, can draw shapes on a canvas (2d) by connecting points with a line.
but i need to prohibit the user from crossing lines.
what i am looking for would be a small algorithm that can find intersecting lines.
the project is done in AS3/Flash but i guess the answer would be universal.
anyone can give me a clue?
thanks
Here is an example in Java but I think you can easily adapt to AS3 :
public static boolean intersects(double ax, double ay, double bx, double by,
double cx, double cy, double dx, double dy) {
double denum = ((bx-ax)*(dy-cy)-(by-ay)*(dx-cx));
if (denum == 0) return false; // parallel segments
double r = ((ay-cy)*(dx-cx)-(ax-cx)*(dy-cy)) / denum;
double s =
((ay-cy)*(bx-ax)-(ax-cx)*(by-ay)) / denum;
return 0<=r && r<=1 && 0<=s && s<=1;
}
It should return true if the segments [AB] and [CD] intersect.
You can find reference here
You can use the methods Point, hitTest, hitTestObject or hitTestPoint. I don't know if Super Chafouin's answer is helpful, but I believe that the code looks quite different in AS3 though.
To explain what they mean, I'll quote Aaron Beall from actionscript.org, giving a nice explanation:
hitTestObject checks the bounding box rectangle of two display
objects. It always checks rectangle-vs-rectangle.
hitTestPoint checks a point (x,y) against a display object:
- With shapeFlag true it checks point-vs-shape
- With shapeFlag false it checks point-vs-rectangle
BitmapData/hitTest checks a bitmap against a point, rectangle, or
other bitmapdata. Using a check of bitmapdata-vs-bitmapdata means you
can perform alpha channel based shape-vs-shape checks. See here:
http://www.mikechambers.com/blog/200...ion-detection/
(Also, not to nitpick but just to make sure you understand, neither
hitTestObject or hitTestPoint are "triggered" -- you must manually
call them when you want to check something.)
Asking for a whole algorithm is quite something, it depends on your app too.
See for more examples and documentation here, here
I hope this will help!

Resources