 /*
 */
 __device__
-void intersection_clip_facet_with_knn(double* polygon_pointer, int& vertex_nb, int current_seed, double* seeds_pointer, int seeds_nb, int *seeds_neighbor_index, int k)
+void intersection_clip_facet_with_knn(double* polygon_pointer, int& vertex_nb, int current_seed, double* seeds_pointer, int seeds_nb, int *seeds_neighbor_index, int k
+, int tid, int pass)
 {
 	
 	//set a buffer pointer to store the polygon
-	double* polygon_buffer = (double*)malloc(sizeof(double) * 10 * 4);
+	double polygon_buffer[40];
 	int polygon_buffer_nb = 0;
-
+	
 	for (int i = 0; i < k; ++i)
 	{
 		int j = seeds_neighbor_index[current_seed * k + i];


	CheckCUDAError("pass data back to CPU");

	/*for (int i = 0; i < points_nb; ++i)
	{
		if (host_seedsInfo[i * 4 + 3] != 0){
			host_seedsInfo[i * 4 + 0] /= host_seedsInfo[i * 4 + 3];
			host_seedsInfo[i * 4 + 1] /= host_seedsInfo[i * 4 + 3];
			host_seedsInfo[i * 4 + 2] /= host_seedsInfo[i * 4 + 3];
		}
	}*/

	for (int i = 0; i < points_nb; ++i)
	{
		printf("Line %d : x : %.17lf, y : %.17lf, z : %.17lf, w : %.17lf\n", i, host_seedsInfo[i * 4 + 0], host_seedsInfo[i * 4 + 1], host_seedsInfo[i * 4 + 2], host_seedsInfo[i * 4 + 3]);
	}

	free(host_seedsInfo);

		polygon[0] = v1.x; polygon[1] = v1.y; polygon[2] = v1.z; polygon[3] = 1.0;
		polygon[4] = v2.x; polygon[5] = v2.y; polygon[6] = v2.z; polygon[7] = 1.0;
		polygon[8] = v3.x; polygon[9] = v3.y; polygon[10] = v3.z; polygon[11] = 1.0;
		
		intersection_clip_facet_with_knn(polygon, vertex_nb, current_seed, seeds_pointer, seeds_nb, seeds_neighbor_index, k, tid, i);

		/*if (tid == 0 & i == 2)
		{
			for (int m = 0; m < seeds_nb * 4; ++m)
				ret_seeds[m] = m;
			ret_seeds[0] = v1.x;
			ret_seeds[1] = v1.y;
			ret_seeds[2] = v1.z;

			for (int m = 0; m < vertex_nb * 4; ++m)
			{
				ret_seeds[4 + m] = polygon[m];
			}
			ret_seeds[21] = vertex_nb;
		}
		if (i == 5)
			return;*/
		//now we get the clipped polygon stored in "polygon"
		//take care of the sychonize
		//change the polygon data into "weight" and "position"
