 
 	CheckCUDAError("pass data back to CPU");
 	
-	for (int i = 0; i < points_nb; ++i)
-	{
-		if (fabs(host_seedsInfo[i * 4 + 3]) >= 1e-12){
-			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];
-		}
-	}
-	std::ofstream fileout("eight_2.txt");
-	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]);
-		fileout << "Line " << i << ':' << setprecision(16) << host_seedsInfo[i * 4 + 0] << ' ' << host_seedsInfo[i * 4 + 1] << ' ' << host_seedsInfo[i * 4 + 2] << ' ' << host_seedsInfo[i * 4 + 3] << endl;
-		//fileout << "Points " << i << ':' << host_seedsInfo[i] << endl;
-		//seeds_polygon_nb[i] = host_seedsInfo[i];
-	}
+	cudaEventRecord(stop, 0);
+	cudaEventSynchronize(stop);
+	cudaEventElapsedTime(&elapsed_time, start, stop);
+	printf("Compute RVD time: %lfms\n", elapsed_time);
+	getchar();
+	//for (int i = 0; i < points_nb; ++i)
+	//{
+	//	if (fabs(host_seedsInfo[i * 4 + 3]) >= 1e-12){
+	//		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];
+	//	}
+	//}
+	//std::ofstream fileout("S2new.txt");
+	//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]);
+	//	fileout << "Line " << i << ':' << setprecision(16) << host_seedsInfo[i * 4 + 0] << ' ' << host_seedsInfo[i * 4 + 1] << ' ' << host_seedsInfo[i * 4 + 2] << ' ' << host_seedsInfo[i * 4 + 3] << endl;
+	//	//fileout << "Points " << i << ':' << host_seedsInfo[i] << endl;
+	//	//seeds_polygon_nb[i] = host_seedsInfo[i];
+	//}
 	
 	free(host_seedsInfo);
 	cudaFree(dev_seeds_pointer);

	return ret;
}

/*
	device function
	find nearest n seeds in device

	input:
	centriod : the physical position of the seed
	seeds_pointer : pointer which store the position of the seeds
	seeds_nb : the number of seeds

	output:
	nearest_points : the result of the function which store the index of the nearest seeds
*/
__device__
void findNearestPoints(double3 centriod, double* seeds_pointer, int seeds_nb, int* nearest_points, int nearest_points_nb)
{
	seeds_nb = 115;
	double* distance_from_centroid = (double*)malloc(sizeof(double) * seeds_nb);

	//find the nearest points
	for (int i = 0; i < seeds_nb; ++i)
	{
		double3 seeds_pos = { seeds_pointer[i * 3 + 0], seeds_pointer[i * 3 + 1], seeds_pointer[i * 3 + 2] };
		distance_from_centroid[i] = computeDistance(centriod, seeds_pos);
		
	}
	double* test = (double*)malloc(sizeof(double) * 100);
	test[0] = 0.01;
	free(test);
	free(distance_from_centroid);
	return;
	//һ洢±
	int* index = (int*)malloc(sizeof(int) * seeds_nb);
	for (int i = 0; i < seeds_nb; ++i)
	{
		index[i] = i;
	}

	for (int i = 1; i < seeds_nb; ++i)
	{
		double key = distance_from_centroid[i];
		int store_index = index[i];
		for (int j = i - 1; j >= 0; --j)
		{
			if (distance_from_centroid[j] >= key)
			{
				distance_from_centroid[j + 1] = distance_from_centroid[j];
				index[j + 1] = index[j];
				if (j == 0)
				{
					distance_from_centroid[j] = key;
					index[j] = store_index;
				}
			}
			else
			{
				distance_from_centroid[j + 1] = key;
				index[j + 1] = store_index;
				break;
			}
		}
	}
	for (int i = 0; i < nearest_points_nb; ++i)
	{
		nearest_points[i] = index[i];
	}

	free(distance_from_centroid);
	free(index);
}


/*
device function

output: polygon pong and its number
*/
__device__
void clip_by_plane(Cuda_Polygon& ping, Cuda_Polygon& pong, int seed_i, int seed_j, double* seeds_pointer, int seeds_nb)
{
	//reset the pong
	pong.vertex_nb = 0;

	if (ping.vertex_nb == 0)
		return;

	//get the position of seed i and seed j
