 	{
 		fout << i << ':' << host_test_polygon[i] << endl;
 	}*/
+}
+
+extern "C" void runRVD(double* host_seeds_pointer, double* host_mesh_vertex_pointer,
+	int* host_facet_index, int points_nb, int mesh_vertex_nb, int mesh_facet_nb,
+	std::vector<int> facet_center_neigbors, std::vector<int> seeds_neighbors)
+{
+	//GPU data
+	double* dev_seeds_pointer;
+	double* dev_mesh_vertex_pointer;
+	int* dev_mesh_facet_index;
+	double* dev_seedsInformation;
+	int* dev_seedsPolygonNumber;
+	double* ret_seeds;
+
+	int *dev_facet_center_neighbors, *dev_seeds_neighbors;
+
+	//CPU data
+	double* host_seedsInfo = (double*)malloc(sizeof(double) * points_nb * 4);
+
+	//allocate the memory
+	checkCudaErrors(cudaMalloc((void**)&dev_seeds_pointer, sizeof(double) * points_nb * 3));
+	checkCudaErrors(cudaMalloc((void**)&dev_mesh_vertex_pointer, sizeof(double) * mesh_vertex_nb * 3));
+	checkCudaErrors(cudaMalloc((void**)&dev_mesh_facet_index, sizeof(int) * mesh_facet_nb * 3));
+	checkCudaErrors(cudaMalloc((void**)&dev_seedsInformation, sizeof(double) * points_nb * 4));
+	checkCudaErrors(cudaMalloc((void**)&ret_seeds, sizeof(double) * points_nb * 4));
+
+	checkCudaErrors(cudaMalloc((void**)&dev_facet_center_neighbors, sizeof(int) * facet_center_neigbors.size()));
+	checkCudaErrors(cudaMalloc((void**)&dev_seeds_neighbors, sizeof(int) * seeds_neighbors.size()));
+
+	checkCudaErrors(cudaMemcpyToSymbol(SeedsInformation, &dev_seedsInformation, sizeof(double*), size_t(0), cudaMemcpyHostToDevice));
+
+	//pass the data from CPU to GPU
+	cudaMemcpy(dev_seeds_pointer, host_seeds_pointer, sizeof(double) * points_nb * 3, cudaMemcpyHostToDevice);
+	cudaMemcpy(dev_mesh_vertex_pointer, host_mesh_vertex_pointer, sizeof(double) * mesh_vertex_nb * 3, cudaMemcpyHostToDevice);
+	cudaMemcpy(dev_mesh_facet_index, host_facet_index, sizeof(int) * mesh_facet_nb * 3, cudaMemcpyHostToDevice);
+	cudaMemcpy(dev_facet_center_neighbors, &facet_center_neigbors[0], sizeof(int) * facet_center_neigbors.size(), cudaMemcpyHostToDevice);
+	cudaMemcpy(dev_seeds_neighbors, &seeds_neighbors[0], sizeof(int) * seeds_neighbors.size(), cudaMemcpyHostToDevice);
+
+	CheckCUDAError("cudaMemcpyHostToDevice");
+
+	int threads = 512;
+	int blocks = mesh_facet_nb / threads + ((mesh_facet_nb % threads) ? 1 : 0);
+
+	compute_RVD_with_knn << <threads, blocks >> >(dev_seeds_pointer, points_nb, dev_mesh_vertex_pointer, mesh_vertex_nb, dev_mesh_facet_index, mesh_facet_nb, dev_facet_center_neighbors,
+		dev_seeds_neighbors, 10, ret_seeds);
+
+	CheckCUDAError("kenerl function");
+	
+	cudaMemcpy(host_seedsInfo, ret_seeds, sizeof(double) * points_nb * 4, cudaMemcpyDeviceToHost);
+
+	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);
+	cudaFree(dev_seeds_pointer);
+	cudaFree(dev_mesh_vertex_pointer);
+	cudaFree(dev_mesh_facet_index);
+	cudaFree(dev_seedsInformation);
+	cudaFree(ret_seeds);
+	cudaFree(dev_facet_center_neighbors);
+	cudaFree(dev_seeds_neighbors);
+
+	return;
 }
	free(seeds_neighbors);
	free(polygon_buffer);
}

/*
	a thread to compute the RVD in parallel way

	}
}

/*
*/
__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)
{
	
	//set a buffer pointer to store the polygon
	double* polygon_buffer = (double*)malloc(sizeof(double) * 10 * 4);
	int polygon_buffer_nb = 0;

	for (int i = 0; i < k; ++i)
	{
		int j = seeds_neighbor_index[current_seed * k + i];
		if (current_seed != j)
		{
			clip_by_plane(polygon_pointer, vertex_nb, polygon_buffer, polygon_buffer_nb, current_seed, j, seeds_pointer, seeds_nb);
			swap_polygons(polygon_pointer, vertex_nb, polygon_buffer, polygon_buffer_nb);
		}
	}

	free(polygon_buffer);
}

/*
	device function
