Hello all,
I have a question about the applicability of the thrust into c++ classes.
I am trying to implement a class object that receives (x,y,z) coordinates of vertices as ver1, ver2, and ver3. Then, assigns to a triangle and calculates area and normal vector.
However, I didn’t quite understand how to create a class of thrust vectors.
Here are the coordinates of the vertices I read it from a file and I would like to send them to a class that will assign them into triangles.
thrust::host_vector<double> dum(start, end); //dum has coordinates and I create
vertices from it.
thrust::host_vector<double> ver1(dum.begin(),dum.begin()+3); //initilizing elements in CPU.
thrust::host_vector<double> ver2(dum.begin()+3,dum.begin()+6);
thrust::host_vector<double> ver3(dum.begin()+6,dum.end());
thrust::device_vector<double> ver1_gpu = ver1; //copying CPU vectors to GPU vectors.
thrust::device_vector<double> ver2_gpu = ver2;
thrust::device_vector<double> ver3_gpu = ver3;
triangle(ver1_gpu, ver2_gpu, ver3_gpu);
In the triangle class, I tried to initialize 3 vertices that have all zeros for their first 3 elements. Since each vertices have 3 coordinates.(x, y, and z).
and I also initialize area and normal variables.
class triangle
{
thrust::device_vector<double>v1(3,0);
thrust::device_vector<double>v2(3,0);
thrust::device_vector<double>v3(3,0);
thrust::device_vector<double>E1(3,0);
thrust::device_vector<double>E2(3,0);
thrust::device_vector<double>E3(3,0);
double normal;
double area;
public:
__device__ __host__ triangle(device_vector<double>vert1, device_vector<double>vert2, device_vector<double>vert3)
{
triangle.v1 = vert1;
triangle.v2 = vert2;
triangle.v3 = vert3;
triangle.E1 = vert2 - vert1;
triangle.E2 = vert3 - vert1;
dummy = cross(obj.E2, obj.E1);%% Cross product
triangle.Area = norm(dummy) / 2;
triangle.Normal = dummy / norm(dummy);
}
};
I’d like to do all of my calculations in the device.
I am new to cuda and its libraries and I know I am wrong in many places but I seek your help.
Thanks.