 	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

ping store the result;
*/
__device__
void swap_polygons(double* ping, int& ping_nb, double* pong, int& pong_nb)
{
	//!!! can be accerate
	//ȷǷʹmemset memcpy
	double temp;
	int temp_nb = ping_nb;

	ping_nb = pong_nb;
	pong_nb = temp_nb;

	for (int i = 0; i < 40; ++i)
	{
		temp = ping[i];
		ping[i] = pong[i];
		pong[i] = temp;
	}
}

/*
*/
__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
, int tid, int pass)
{
	
	//set a buffer pointer to store the polygon
	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];
		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);
		}
	}
	return;
}

/*
	device function
	compute the intersection of a facet and a seed(a cell)

	input:

*/
__device__
void intersection_clip_facet(double* polygon_pointer, int& vertex_nb, int current_seed, double* seeds_pointer, int seeds_nb)
{
	double3 current_seed_pos = { seeds_pointer[current_seed * 3 + 0],
		seeds_pointer[current_seed * 3 + 1],
		seeds_pointer[current_seed * 3 + 2] };

	int* seeds_neighbors = (int*)malloc(sizeof(int) * 20);
	findNearestPoints(current_seed_pos, seeds_pointer, seeds_nb, seeds_neighbors, 20);

	////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 < 20; ++i)
	{
		int j = seeds_neighbors[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(seeds_neighbors);
	free(polygon_buffer);
}

__global__

		SeedsInformation[tid * 4 + 3] = 0.0;
	}

	int f_idx1 = mesh_facet[tid * 3 + 0];
	int f_idx2 = mesh_facet[tid * 3 + 1];
	int f_idx3 = mesh_facet[tid * 3 + 2];
