 					dev_facets_, facet_nb_,
 					dev_points_nn_, k_,
 					dev_facets_nn_, dimension_,
-					dev_ret_, dev_retidx
+					dev_ret_, f_k_
 					);
 				CheckCUDAError("kernel function");
 				copy_back();
-
+				//printf("--------------passsed kernel----------------");
 				//result_print("facetnn.txt", facets_nn_, facet_nb_, 4);
 				//result_print("retdata.txt", host_ret_, points_nb_ * 4, 4);
 				//result_print("retidx.txt", host_retidx, facet_nb_ * 100, 10);
-			
-				for (index_t t = 0; t < points_nb_ * 4; ++t){
-					update_data[t] += host_ret_[t];
-				}
-				
-				for (index_t t = 0; t < facet_nb_; ++t){
-					has_visited[t].insert(facets_nn_[t]);
-					for (index_t s = 0; s < data_size; ++s){
-						int cur_seed = host_retidx[t * data_size + s];
-						if (cur_seed < -1) break;
-						if (cur_seed >= 0 && cur_seed < points_nb_){
-							if (has_visited[t].find(cur_seed) == has_visited[t].end()){
-								has_visited[t].insert(cur_seed);
-								to_visited[t].push(cur_seed);
-							}
-						}
-					}
-				}
-
-				while (!check_task_finished(to_visited)){
-					
-					//put the data into a special array.
-					go_next(next, data_size + 1);
-					cudaMemcpy(dev_next, next, sizeof(int) * facet_nb_ * (data_size + 1), cudaMemcpyHostToDevice);
-					cudaMemset(dev_retidx, -2, sizeof(int) * facet_nb_ * 100);
-					//result_print("next.txt", next, facet_nb_ * (data_size+1), data_size + 1);
-					//go
-					threads = 128;
-					blocks = (facet_nb_ * data_size) / threads + (((facet_nb_ * data_size) % threads) ? 1 : 0);
-					go_rvd << < blocks, threads >> >(
-						dev_vertex_, vertex_nb_,
-						dev_points_, points_nb_,
-						dev_facets_, facet_nb_,
-						dev_points_nn_, k_,
-						dev_next, dimension_, data_size,
-						dev_ret_, dev_retidx
-						);
-
-					cudaMemcpy(host_ret_, dev_ret_, sizeof(double) * points_nb_ * 4, cudaMemcpyDeviceToHost);
-					cudaMemcpy(host_retidx, dev_retidx, sizeof(int) * facet_nb_ * data_size * 10, cudaMemcpyDeviceToHost);
-					CheckCUDAError("copy back");
-					//result_print("go_rvd.txt", host_retidx, facet_nb_ * 100, 10);
-					for (index_t t = 0; t < points_nb_ * 4; ++t){
-						update_data[t] += host_ret_[t];
-					}
-					insert_to_visited(host_retidx, data_size);
-				}
-
-
+		
 				//result_print("retdata.txt", host_ret_, facet_nb_ * 400, 4);
 				//result_print("C:\\Users\\JWhan\\Desktop\\DATA\\retdata.txt", host_ret_, points_nb_ * 4, 4);
 				is_store_ = false;
-				for (int i = 0; i < points_nb_; ++i){
-					double d = update_data[i * 4 + 3];
-					if (fabs(update_data[i * 4 + 3]) > 1e-30){
-						update_data[i * 4 + 0] /= update_data[i * 4 + 3];
-						update_data[i * 4 + 1] /= update_data[i * 4 + 3];
-						update_data[i * 4 + 2] /= update_data[i * 4 + 3];
-
-						x_->set_vertex(&update_data[i * 4], dimension_, i);
-					}
-					else
-					{
-						//std::cout << "point  " << i << " hsa no RVD." << std::endl;
-
-					}
-					//x_->add_vertexd(&host_ret_[i * 4], dimension_);
-				}
-
-				if (is_store_){
-					std::vector<int> sample_facet(points_nb_);
-					std::string name = "C:\\Users\\JWhan\\Desktop\\DATA\\RVD_" + String::to_string(store_filename_counter_) + ".xyz";
-					points_save_xyz(name, *x_, sample_facet);
-					store_filename_counter_++;
-				}
-				//update_points();
+				
+				update_points();
 				iter_watcher.stop();
 				iter_watcher.synchronize();
 				iter_watcher.print_elaspsed_time(std::cout);

			prev_l = l;
			prev_k = k;
		}
		//reset the pong
		//pong.vertex_nb = 0;

		//if (ping.vertex_nb == 0)
		//	return;
		//
		//// Compute d = n . (2m), where n is the
		//// normal vector of the bisector [i, j]
		//// and m the middle point of the bisector.
		//double d = 0.0;
		//double3 temp = sub(position_i, position_j);
		//d = dot(add(position_i, position_j), temp);

		////The predecessor of the first vertex is the last vertex
		//int prev_k = ping.vertex_nb - 1;

		////get the position data
		////CudaVertex* prev_vk = &ping.vertex[prev_k];

		////then we compute prev_vertex_position "cross" n 
		////prev_l = prev_vertex_position . n
		//
		//double prev_l = ping.vertex[prev_k].x * temp.x + ping.vertex[prev_k].y * temp.y + ping.vertex[prev_k].z * temp.z;

		//int prev_status = sgn(2.0 * prev_l - d);
		//
		////traverse the Vertex in this Polygon
		//for (int k = 0; k < ping.vertex_nb; ++k){

		//	//CudaVertex* vk = &ping.vertex[k];
		//	
		//	double l = ping.vertex[k].x * temp.x + ping.vertex[k].y * temp.y + ping.vertex[k].z + temp.z;
		//	
		//	int status = sgn(2.0 * l - d);

		//	//If status of edge extremities differ,
		//	//then there is an intersection.
		//	if (status != prev_status && (prev_status) != 0){
		//		// create the intersection and update the Polyon
		//		CudaVertex I;

		//		//compute the position and weight
		//		double denom = 2.0 * (prev_l - l);
		//		double lambda1, lambda2;

		//		// Shit happens!
		//		if (m_fabs(denom) < 1e-20)
		//		{
		//			lambda1 = 0.5;
		//			lambda2 = 0.5;
		//		}
		//		else
		//		{
		//			lambda1 = (d - 2.0 * l) / denom;
		//			// Note: lambda2 is also given
		//			// by (2.0*l2-d)/denom
		//			// (but 1.0 - lambda1 is a bit
		//			//  faster to compute...)
		//			lambda2 = 1.0 - lambda1;
		//		}

		//		//Set the Position of Vertex
		//		I.x = lambda1 * ping.vertex[prev_k].x + lambda2 * ping.vertex[k].x;
		//		I.y = lambda1 * ping.vertex[prev_k].y + lambda2 * ping.vertex[k].y;
		//		I.z = lambda1 * ping.vertex[prev_k].z + lambda2 * ping.vertex[k].z;

		//		//Set the Weight of Vertex
		//		I.w = (lambda1 * ping.vertex[prev_k].w + lambda2 * ping.vertex[k].w);

		//		if (status > 0)
		//		{
		//			I.neigh_s = (j);
		//		}
		//		else {
		//			I.neigh_s = (ping.vertex[k].neigh_s);
		//		}

		//		//add I to pong
		//		pong.vertex[pong.vertex_nb] = I;
		//		pong.vertex_nb++;
		//	}
		//	if (status > 0)
		//	{
		//		//add vertex to pong
		//		pong.vertex[pong.vertex_nb] = ping.vertex[k];
		//		pong.vertex_nb++;
		//	}

		//	//prev_vk = vk;
		//	//prev_vertex_position = vertex_position;
		//	prev_status = status;
		//	prev_l = l;
		//	prev_k = k;
		//}
		
	}

	/*

		current_polygon.vertex[2].y = vertex[facet_index.z * dim + 1];
		current_polygon.vertex[2].z = vertex[facet_index.z * dim + 2];
		current_polygon.vertex[2].w = 1.0;
		
		index_t current_seed = facets_nn[tid];
		
		intersection_clip_facet_SR(
			current_polygon,
			current_seed,
