void  TrackingKymoView::DeleteDiffTData(std::set<unsigned int> difft_selection)
{
	std::set<unsigned int>::iterator sel_iter;
	for(sel_iter = difft_selection.begin(); sel_iter!= difft_selection.end(); ++sel_iter)
	{
		unsigned int vtk_cell_id = *sel_iter;
		
		TraceLine *tline = reinterpret_cast<TraceLine*>(m_tobj->hashc[vtk_cell_id]);
		std::cout<<"deleting cell:"<<vtk_cell_id<<" with id: "<<tline->GetId()<<std::endl;
		TraceBit tb1 = tline->subtrace_hash[vtk_cell_id].at(0);
		TraceBit tb2 = tline->subtrace_hash[vtk_cell_id].at(1);
		int maxtime = MAX(tb1.time,tb2.time);

		std::vector<TraceLine*>* trace_lines  = m_tobj->GetTraceLinesPointer();
		std::vector<TraceLine*>::iterator trace_lines_iter;
		for(trace_lines_iter = trace_lines->begin() ;trace_lines_iter!= trace_lines->end(); ++trace_lines_iter)
		{
			if(tline->GetId() == (*trace_lines_iter)->GetId())
			{
				int new_id = this->GetMaxId()+1;
				trace_lines->erase(trace_lines_iter);
				TraceLine::TraceBitsType::iterator tbit_iter = tline->GetTraceBitIteratorBegin();
				TraceLine * new_tline1 = new TraceLine();
				TraceLine * new_tline2 = new TraceLine();
				ObjectSelection::Point point;
				
				while(tbit_iter != tline->GetTraceBitIteratorEnd())
				{
					if((*tbit_iter).time < maxtime)
					{
						new_tline1->AddTraceBit(*tbit_iter);
					}
					else 
					{
						point.id = tbit_iter->id;
						point.time = tbit_iter->time;
						(*tbit_iter).id = new_id;
						point.new_id = new_id;
						points_from_delete.push_back(point);
						new_tline2->AddTraceBit(*tbit_iter);
					}
					++tbit_iter;
				}
				trace_lines->push_back(new_tline1);
				new_tline2->SetId(new_id);
				trace_lines->push_back(new_tline2);
				break;
			}
		}
	}

}
void TrackingKymoView::DeleteAndRelabelData(void)
{
	if(TSelection.empty()) return;
	
	std::vector<unsigned int> tmp_selection;
	std::set<unsigned int> samet_selection;	// list of sub-tracks selected within the same track
	//std::set<unsigned int> difft_selection;
	std::map<int, std::set<unsigned int> > selection_map;

	std::set<unsigned int>::iterator sel_iter;

	for(sel_iter = TSelection.begin(); sel_iter!= TSelection.end(); ++sel_iter)
		tmp_selection.push_back(*sel_iter);

	// figure out the number of different selected tracks:
	std::set<int> selected_ids;
	for(int i = 0; i< tmp_selection.size(); ++i)
	{
		TraceLine *tline1 = reinterpret_cast<TraceLine*>(m_tobj->hashc[tmp_selection.at(i)]);
		selected_ids.insert(tline1->GetId());
	}
	std::set<int>::iterator sel_ids_iter;
	for(sel_ids_iter = selected_ids.begin(); sel_ids_iter!= selected_ids.end(); ++sel_ids_iter)
	{
		std::set<unsigned int> samet_selection;
		for(int i = 0; i< tmp_selection.size(); ++i)
		{
			TraceLine *tline = reinterpret_cast<TraceLine*>(m_tobj->hashc[tmp_selection.at(i)]);
			int id = tline->GetId();
			if(tline->GetId() == *sel_ids_iter)
				samet_selection.insert(tmp_selection.at(i));
		}
		selection_map[*sel_ids_iter] = samet_selection;
	}
	std::map<int, std::set<unsigned int> >::iterator select_map_iter;
	for(select_map_iter = selection_map.begin(); select_map_iter!= selection_map.end(); ++select_map_iter)
	{
		if(!(*select_map_iter).second.empty()&& (*select_map_iter).second.size()>1)
			this->DeleteSameTData((*select_map_iter).second);
		else if(!(*select_map_iter).second.empty()&& (*select_map_iter).second.size()==1)
			this->DeleteDiffTData((*select_map_iter).second);
	}
	if(!points_from_delete.empty())
	{
		Selection->SelectPoints(points_from_delete);
		points_from_delete.clear();
	}

	
}
void  TrackingKymoView::DeleteSameTData(std::set<unsigned int> samet_selection)
{
	std::set<unsigned int>::iterator sel_iter = samet_selection.begin();
	TraceLine *tline = reinterpret_cast<TraceLine*>(m_tobj->hashc[*sel_iter]);
	int new_id = this->GetMaxId()+1;

	// first find the trace line in the data to erase it:
	std::vector<TraceLine*>* trace_lines  = m_tobj->GetTraceLinesPointer();
	std::vector<TraceLine*>::iterator trace_lines_iter;
	for(trace_lines_iter = trace_lines->begin() ;trace_lines_iter!= trace_lines->end(); ++trace_lines_iter)
	{
		if(tline->GetId() == (*trace_lines_iter)->GetId())
		{
			trace_lines->erase(trace_lines_iter);
			break;
		}
	}

	printf("I am here\n");

	TraceLine * tline_tmp = new TraceLine();
	tline_tmp = tline;
	sel_iter = samet_selection.begin();
	while(sel_iter != samet_selection.end())
	{
		TraceBit tb1 = tline->subtrace_hash[*sel_iter].at(0);
		TraceBit tb2 = tline->subtrace_hash[*sel_iter].at(1);
		int maxtime = MAX(tb1.time,tb2.time);
		tline_tmp = this->DeleteTlineRecursive(tline_tmp,*sel_iter,new_id,maxtime);
		++new_id;
		++sel_iter;
	}
	trace_lines->push_back(tline_tmp);

}