void TrajectoryClassifier::run()
{
	SampleSet& set = SampleSet::get_instance();
	if (set.empty())
	{
		Logger<< " End Clustering(Warning: Empty Set).\n";
		return;
	}
	//Step 1: compute rotate feature
	DeformableRegistration nonrigid;

	vector<PCloudTraj> totalTraj;

	vector<IndexType> sampleCenterVtxId;

	totalTraj.clear();

	sampleCenterVtxId.clear();
	if (isEqual)
	{

		Logger<<"Using Equal Length Traj"<<endl;

		nonrigid.calculateFixedLengthTrajWithTracingAlong(totalTraj,centerFrame,sampleCenterVtxId,trajLen,octreeRes);

	}else
	{
		Logger<<"Using Unequal Length Traj"<<endl;
		nonrigid.calculateDownSmpLifeSpanTrajCenter(totalTraj,centerFrame,sampleCenterVtxId,trajLen,octreeRes,threshold,lifeT); 
	}


	//calculate motion models

	IndexType modeNum = (IndexType)(modelT * sampleCenterVtxId.size());
	vector<IndexType> labels;
	labels.resize(totalTraj.size(),0);

	if (totalTraj.size() < 50)
	{
		Logger<<"Traj size is small!.\n";
		Logger<< " End Clustering.\n";
		return;
	}

	//rigid or affine motion model

	if (isRigid)
	{
		Logger<<"Using Rigid motion  model"<<endl;

		vector<PCloudModel> totalModel;

		totalModel.clear();

		nonrigid.sampleModel(totalTraj,totalModel,modeNum);

		J_LinkageAdapter_Matlab<PCloudTraj, PCloudModel, Traj2ModDistanceFunc>	algo_adaptor(totalTraj, totalModel, labels, Traj2ModDistanceFunc(threshold),perC);

		algo_adaptor.compute();

	}else
	{
		Logger<<"Using Affine motion  model"<<endl;

		vector<PCloudAffModel> totalModel;

		totalModel.clear();

		nonrigid.sampleAffineModel(totalTraj,totalModel,modeNum);

		J_LinkageAdapter_Matlab<PCloudTraj, PCloudAffModel, Traj2AffModelDistFunc>	algo_adaptor(totalTraj, totalModel, labels, Traj2AffModelDistFunc(threshold),perC);

		algo_adaptor.compute();

	}

	Logger<<"centerFrame = "<<centerFrame<<endl;


	Sample& sample0 = set[centerFrame];

	vector<bool> isSelector(sample0.num_vertices(),false);

	//in order to visual sample vertexes 

	for (int i = 0; i < sampleCenterVtxId.size(); i++)
	{
		isSelector[sampleCenterVtxId[i]] = true;
	}

	if (isEqual)
	{
#ifdef SAVE_CORRESPONDENCE

		IndexType smp_range[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,
			51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,
			101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,
			141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173};

		char corr_file_name[1024];


		if(_access(".\\tmp",0) == -1){
			CreateDirectory(_T(".\\tmp"), NULL);
		}
		if(_access(".\\tmp\\corr",0) == -1){
			CreateDirectory(_T(".\\tmp\\corr"), NULL);
		}
		sprintf(corr_file_name,".\\tmp\\corr\\hksingle_corr%.2d_%.2f.txt",centerFrame,perC);

		FILE *in_correspond = fopen(corr_file_name,"w");

		for ( int i=0; i<sampleCenterVtxId.size();i++ )
		{
			for (int j=0; j<(sizeof(smp_range)/sizeof(IndexType));j++)
			{
				if(centerFrame==smp_range[j] || totalTraj[i].trajLifeSpan.start > smp_range[j] )continue;
				if(totalTraj[i].trajLifeSpan.end < smp_range[j])break;
				IndexType v = sampleCenterVtxId[i];

				fprintf(in_correspond,"%d %d %d %d\n", centerFrame, v, smp_range[j], totalTraj[i].trajNode[smp_range[j] - totalTraj[i].trajLifeSpan.start]);

			}
		}


		fclose(in_correspond);

#endif

		bubleSort(sampleCenterVtxId,labels,(IndexType)labels.size());

		vector<IndexType> label_smooth(labels.size(),0);

		diff_using_bfs(labels,sampleCenterVtxId,centerFrame);

		nonrigid.smoothSmapleLabel_KDTree(sample0,sampleCenterVtxId,labels,label_smooth);

		IndexType nLabels = 1;

		// in order to set the label system continuous and the 0 as the first label
		nLabels = orderLabels(label_smooth);

		Logger<<"seg size = "<<nLabels; 

		vector<IndexType> result_label(sample0.num_vertices(),0);

		// propagate the sample vertexes to original point cloud.
		nonrigid.propagateLabel2Orignal(sample0,sampleCenterVtxId,label_smooth,result_label); 

#ifdef SAVE_LABELS

		char label_labsmooth[1024];

		if(_access(".\\tmp",0) == -1){
			CreateDirectory(_T(".\\tmp"), NULL);
		}
		if(_access(".\\tmp\\results",0) == -1){
			CreateDirectory(_T(".\\tmp\\label"), NULL);
		}
		sprintf(label_labsmooth,".\\tmp\\label\\orilabels%.2d_%.2f.txt",centerFrame,perC);

		FILE *in_label_smooth = fopen(label_labsmooth, "w");

		IndexType tpd = 0;

		for ( int i=0; i<set[centerFrame].num_vertices(); i++ )
		{
			if (isSelector[i])  //to output sampled vtx
			{
				fprintf( in_label_smooth, "%d %d %d\n", centerFrame, result_label[i], i );
			}
		}

		fclose(in_label_smooth);

#endif

#ifdef SAVE_CORRESPONDENCE

		//visualize the segmentation results in point cloud.
		IndexType i = 0;
		IndexType k = 0;
		for (Sample::vtx_iterator v_iter = sample0.begin();
			v_iter != sample0.end();
			v_iter++,i++ )
		{
			if (isSelector[i])
			{
				(*v_iter)->set_visble(true);

				(*v_iter)->set_label( label_smooth[k] );//smooth label
				k++;
			}else
			{
				(*v_iter)->set_visble(false);
			}
		}
#endif 

	}




	//IndexType frames[] = {1,2,3,4,5,6,7,8,9,10/*,11,12,13,14,15,16,17,18,19,20*/};
	if ( !isEqual)
	{
		for ( IndexType i= (centerFrame - trajLen/2 ); i<= (centerFrame + trajLen/2 ); i++ )
		{
			for (IndexType j=0; j<set[i].num_vertices(); j++)
			{
				set[i][j].set_visble(false);
			}
		}

		map<IndexType, IndexType> inter_labels;
		IndexType trajSize = (IndexType)totalTraj.size();
		for (IndexType tId = 0; tId < trajSize; tId ++) 
		{
			IndexType nodeId = 0;

			for (IndexType stF = totalTraj[tId].trajLifeSpan.start; stF <= totalTraj[tId].trajLifeSpan.end; stF ++, nodeId ++)
			{
				if ( centerFrame == stF)
				{

					inter_labels[totalTraj[tId].trajNode[nodeId] ] = labels[tId];

				}

			}
		}

		vector<IndexType> order_labels;
		order_labels.resize(sampleCenterVtxId.size(),0);

		for (IndexType i= 0; i < sampleCenterVtxId.size(); i ++)
		{
			if (inter_labels.find(sampleCenterVtxId[i]) != inter_labels.end() )
			{
				order_labels[i] = inter_labels[sampleCenterVtxId[i] ];

			}else
			{
				Logger<<"Unmark point.\n";
			}

		}

		bubleSort(sampleCenterVtxId,order_labels,(IndexType)order_labels.size());
		vector<IndexType> label_smooth(order_labels.size(),0);

		diff_using_bfs(order_labels,sampleCenterVtxId,centerFrame); 
		nonrigid.smoothSmapleLabel_KDTree(sample0,sampleCenterVtxId,order_labels,label_smooth);

		IndexType nLabels = 0;

		nLabels = orderLabels(label_smooth);

		Logger<<"seg size = "<<nLabels; 

		IndexType i = 0;
		IndexType k = 0;
		for (Sample::vtx_iterator v_iter = sample0.begin();
			v_iter != sample0.end();
			v_iter++,i++ )
		{
			if (isSelector[i])
			{
				(*v_iter)->set_visble(true);
				(*v_iter)->set_label( label_smooth[k] );//smooth label
				k++;
			}else
			{
				(*v_iter)->set_visble(false);
			}
		}

	}
	Logger<< " End Clustering.\n";
}
Ejemplo n.º 2
0
void TrajectoryClassifier::run()
{

	Loggger << "Begin Clustering.\n";

	SampleSet& set = SampleSet::get_instance();

	if (set.empty())
	{
		Loggger<< " End Clustering(Warning: Empty Set).\n";
		emit finish_compute();
		return;
	}


	//Step 1: compute rotate feature


 	DeformableRegistration nonrigid;

	//Loggger<<"Neighbor Number = "<<neigborNum<<endl;
 	//MatrixXX featureMat;
    //nonrigid.calculateTrajFrature(featureMat);

	// test life spans traj
  	vector<PCloudTraj> totalTraj;

	vector<IndexType> sampleCenterVtxId;

	totalTraj.clear();

	sampleCenterVtxId.clear();

	//calculate trajectories with either equal or unequal.

	if (isEqual)
	{
		
		Loggger<<"Using Equal Length Traj"<<endl;

		nonrigid.calculateFixedLengthTrajWithTracingAlong(totalTraj,centerFrame,sampleCenterVtxId,trajLen,octreeRes);

		//nonrigid.calculateFixedLengthTraj(totalTraj,centerFrame,sampleCenterVtxId,trajLen,octreeRes);//ÏȲÉÑùÔÙÅä×¼--¼ä¸ôÅä×¼--always

	}else
	{
		Loggger<<"Using Unequal Length Traj"<<endl;
		//nonrigid.calculateDownSmpLifeSpanTraj(totalTraj,centerFrame,sampleCenterVtxId,trajLen,octreeRes,threshold,lifeT);
		nonrigid.calculateDownSmpLifeSpanTrajCenter(totalTraj,centerFrame,sampleCenterVtxId,trajLen,octreeRes,threshold,lifeT); 
	}


	//calculate motion models

	IndexType modeNum = modelT * sampleCenterVtxId.size();
	vector<IndexType> labels;
	labels.resize(totalTraj.size(),0);
    
	if (totalTraj.size() < 50)
	{
		Loggger<<"Traj size is small!.\n";
		Loggger<< " End Clustering.\n";
		emit finish_compute();
		return;
	}

	//rigid or affine motion model

	if (isRigid)
	{
		Loggger<<"Using Rigid motion  model"<<endl;

		vector<PCloudModel> totalModel;

		totalModel.clear();

		nonrigid.sampleModel(totalTraj,totalModel,modeNum);

		J_LinkageAdapter_Matlab<PCloudTraj, PCloudModel, Traj2ModDistanceFunc>	algo_adaptor(totalTraj, totalModel, labels, Traj2ModDistanceFunc(threshold),perC);

		algo_adaptor.compute();

	}else
	{
		Loggger<<"Using Affine motion  model"<<endl;

		vector<PCloudAffModel> totalModel;

		totalModel.clear();

		nonrigid.sampleAffineModel(totalTraj,totalModel,modeNum);

		J_LinkageAdapter_Matlab<PCloudTraj, PCloudAffModel, Traj2AffModelDistFunc>	algo_adaptor(totalTraj, totalModel, labels, Traj2AffModelDistFunc(threshold),perC);

		algo_adaptor.compute();

	}


    //Êä³ö²ÎÊý
	Loggger<<"centerFrame = "<<centerFrame<<endl;

	LOCK( set[centerFrame] );

	Sample& sample0 = set[centerFrame];

	vector<bool> isSelector(sample0.num_vertices(),false);

	//in order to visual sample vertexes 

	for (int i = 0; i < sampleCenterVtxId.size(); i++)
	{
		isSelector[sampleCenterVtxId[i]] = true;
	}

	if (isEqual)
	{
		#ifdef SAVE_CORRESPONDENCE

			IndexType smp_range[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,
			                         51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,
			                         101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,
			                         141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173};

 			char corr_file_name[1024];

  			//sprintf(corr_file_name,"F:\\EG2015\\rebuttal1127\\hanger\\hanger_corr%.2d_%.2f.txt",centerFrame,perC);

			//sprintf(corr_file_name,"G:\\Projects\\EG2015\\rebuttal1127\\15_26\\hksingle_corr%.2d_%.2f.txt",centerFrame,perC);

			//sprintf(corr_file_name,"G:\\Projects\\EG2015\\rebuttal1127\\hanger\\hangerAll\\hangerAll_corr%.2d_%.2f.txt",centerFrame,perC);

			//horse eva 12-15

			sprintf(corr_file_name,"G:\\Data\\horse\\quaEva1215\\J-linkage threshold test\\hksingle_corr%.2d_%.2f.txt",centerFrame,perC);

  			FILE *in_correspond = fopen(corr_file_name,"w");
  
  			for ( int i=0; i<sampleCenterVtxId.size();i++ )
  			{
  				for (int j=0; j<(sizeof(smp_range)/sizeof(IndexType));j++)
  				{
  					if(centerFrame==smp_range[j] || totalTraj[i].trajLifeSpan.start > smp_range[j] )continue;
  					if(totalTraj[i].trajLifeSpan.end < smp_range[j])break;
  					IndexType v = sampleCenterVtxId[i];
  
  					fprintf(in_correspond,"%d %d %d %d\n", centerFrame, v, smp_range[j], totalTraj[i].trajNode[smp_range[j] - totalTraj[i].trajLifeSpan.start]);
  
  				}
  			}
 
 
  			fclose(in_correspond);

		#endif

          	bubleSort(sampleCenterVtxId,labels,labels.size());

       		vector<IndexType> label_smooth(labels.size(),0);
       
			//separate the same motion at nonadjacent region.
       		//diff_using_bfs(labels,sampleCenterVtxId,centerFrame);
       
			//smooth the segmentation results.
       		nonrigid.smoothSmapleLabel_KDTree(sample0,sampleCenterVtxId,labels,label_smooth);
   
			IndexType nLabels = 1;

			// in order to set the label system continuous and the 0 as the first label
			nLabels = orderLabels(label_smooth);
      
       		Loggger<<"seg size = "<<nLabels; 

			vector<IndexType> result_label(sample0.num_vertices(),0);

			// propagate the sample vertexes to original point cloud.
			nonrigid.propagateLabel2Orignal(sample0,sampleCenterVtxId,label_smooth,result_label); 

		 #ifdef SAVE_LABELS

  		    char label_labsmooth[1024];
  		   	//sprintf(label_labsmooth,"F:\\EG2015\\rebuttal1127\\hanger\\hanger_labels%.2d_%.2f.txt",centerFrame,perC);

			//sprintf(label_labsmooth,"G:\\Projects\\EG2015\\rebuttal1127\\15_26\\hklabels%.2d_%.2f.txt",centerFrame,perC);

			//sprintf(label_labsmooth,"G:\\Projects\\EG2015\\rebuttal1127\\hanger\\hangerAll\\hangerAll_labels%.2d_%.2f.txt",centerFrame,perC);
			//horse eva 12-15

			sprintf(label_labsmooth,"G:\\Data\\born\\one_chair\\downsample\\orilabels%.2d_%.2f.txt",centerFrame,perC);

  		   	FILE *in_label_smooth = fopen(label_labsmooth, "w");

  		   	IndexType tpd = 0;
  		 		 
			for ( int i=0; i<set[centerFrame].num_vertices(); i++ )
			{
				fprintf( in_label_smooth, "%d %d %d\n", centerFrame, result_label[i], i );
			}
  		   
  		   	fclose(in_label_smooth);
		 	 
		 #endif

		#ifdef SAVE_CORRESPONDENCE

			//visualize the segmentation results in point cloud.
       			IndexType i = 0;
     				IndexType k = 0;
       			for (Sample::vtx_iterator v_iter = sample0.begin();
       				v_iter != sample0.end();
       				v_iter++,i++ )
       			{
     					if (isSelector[i])
     					{
     						(*v_iter)->set_visble(true);
     						//(*v_iter)->set_label( labels[k] );//orignal label
     						(*v_iter)->set_label( label_smooth[k] );//smooth label
     						k++;
     					}else
     					{
     						(*v_iter)->set_visble(false);
     					}
       			}
		#endif 

	}

	

//     
// 	//IndexType frames[] = {1,2,3,4,5,6,7,8,9,10/*,11,12,13,14,15,16,17,18,19,20*/};
//     if ( !isEqual)
//     {
// 		for ( IndexType i= (centerFrame - trajLen/2 ); i<= (centerFrame + trajLen/2 ); i++ )
// 		{
// 			for (IndexType j=0; j<set[i].num_vertices(); j++)
// 			{
// 				set[i][j].set_visble(false);
// 			}
// 		}
// 
// 		//ÉèÖÃÖÐÐÄ֡ŤÇúÁ¿´óµÄµãlabelΪ0
// // 		IndexType i = 0;
// // 		for (Sample::vtx_iterator v_iter = sample0.begin();
// // 			v_iter != sample0.end();
// // 			v_iter++,i++ )
// // 		{
// // 			if (isSelector[i])
// // 			{
// // 				(*v_iter)->set_visble(true);
// // 				(*v_iter)->set_label( 0 );//smooth label
// // 			}/*else
// // 			 {
// // 			 (*v_iter)->set_visble(false);
// // 			 }*/
// // 		}
// 
// 
// 		//¼Ç¼ÖÐÐÄÖ¡¶¥µã±êÇ©Çé¿ö
// 		map<IndexType, IndexType> inter_labels;
// 
// 		//¿ÉÊÓ»¯¹ì¼£µÄlabel
// 		IndexType trajSize = totalTraj.size();
// 
// 		//for (IndexType tId = 0; tId < trajSize; tId ++) //¹ì¼£
// 		//{
// 		//	IndexType nodeId = 0;
// 		//	for (IndexType stF = totalTraj[tId].trajLifeSpan.start; stF <= totalTraj[tId].trajLifeSpan.end; stF ++, nodeId ++) //Ö¡
// 		//	{
// 		//		set[stF][totalTraj[tId].trajNode[nodeId] ].set_visble(true);
// 
// 		//		set[stF][totalTraj[tId].trajNode[nodeId] ].set_label(labels[tId]);
// 
// 		//		
// 		//	}
// 		//}
// 
// 
// 		//Ö»¿ÉÊÓ»¯ÖÐÐÄÖ¡----0816
// 		for (IndexType tId = 0; tId < trajSize; tId ++) //¹ì¼£
// 		{
// 			IndexType nodeId = 0;
// 
// 			for (IndexType stF = totalTraj[tId].trajLifeSpan.start; stF <= totalTraj[tId].trajLifeSpan.end; stF ++, nodeId ++) //Ö¡
// 			{
// 				if ( centerFrame == stF)
// 				{
// 
// 					inter_labels[totalTraj[tId].trajNode[nodeId] ] = labels[tId];
// 
// 				}
// 
// 			}
// 		}
// 
// 		//»ñÈ¡Õë¶Ô²ÉÑùµãµÄ±êÇ©
// 		vector<IndexType> order_labels;
// 		order_labels.resize(sampleCenterVtxId.size(),0);
// 
// 		for (IndexType i= 0; i < sampleCenterVtxId.size(); i ++)
// 		{
// 			if (inter_labels.find(sampleCenterVtxId[i]) != inter_labels.end() )
// 			{
//                 order_labels[i] = inter_labels[sampleCenterVtxId[i] ];
// 
// 			}else
// 			{
// 				Loggger<<"Unmark point.\n";
// 			}
// 			
// 		}
// 
// 		bubleSort(sampleCenterVtxId,order_labels,order_labels.size());//ΪÁËÅäºÏ¶¥µãºÅÂëË÷Òý-
// 
// 		vector<IndexType> label_smooth(order_labels.size(),0);
// 
// 		//nonrigid.smoothSmapleLabel_KDTree(sample0,sampleCenterVtxId,labels,label_smooth);
// 
// 		diff_using_bfs(order_labels,sampleCenterVtxId,centerFrame);//ÏàͬÑÕÉ«²»Í¬Á¬Í¬¿é±ê¼Ç²»Í¬ÑÕÉ«
// 
// 		nonrigid.smoothSmapleLabel_KDTree(sample0,sampleCenterVtxId,order_labels,label_smooth);
// 
// 		IndexType nLabels = 0;
// 
// 		nLabels = orderLabels(label_smooth);
// 
// 		Loggger<<"seg size = "<<nLabels; //ÊǵÄlabel±êºÅ´Ó0¿ªÊ¼¼ÆËã
// 
// 		//¿ÉÊÓ»¯ÖÐÐÄÖ¡
// 
// 		IndexType i = 0;
// 		IndexType k = 0;
// 		for (Sample::vtx_iterator v_iter = sample0.begin();
// 			v_iter != sample0.end();
// 			v_iter++,i++ )
// 		{
// 			if (isSelector[i])
// 			{
// 				(*v_iter)->set_visble(true);
// 				(*v_iter)->set_label( label_smooth[k] );//smooth label
// 				k++;
// 			}else
// 			{
// 				(*v_iter)->set_visble(false);
// 			}
// 		}
// 
//     }
	UNLOCK(set[centerFrame]);
 	Loggger<< " End Clustering.\n";
	emit finish_compute();
}
Ejemplo n.º 3
0
void TrajectoryClassifier::visDistor()
{
	Loggger << "Begin Visual distortion.\n";

	SampleSet& set = SampleSet::get_instance();

	if (set.empty())
	{
		Loggger<< " End Clustering(Warning: Empty Set).\n";
		emit finish_compute();
		return;
	}

 	DeformableRegistration nonrigid;
	vector<PCloudTraj> totalTraj;

	IndexType trajLen = 1;
	IndexType octreeRes = 32;
	vector<IndexType> sampleCenterVtxId;

	LOCK( set[centerFrame] );

	//nonrigid.calculateFixedLengthTraj(totalTraj,centerFrame,sampleCenterVtxId,trajLen,octreeRes);//ÏȲÉÑùÔÙÅä×¼--¼ä¸ôÅä×¼
	//nonrigid.produceDreamTraj(totalTraj,sampleCenterVtxId);
	nonrigid.calculateFixedLengthTrajWithTracingAlong(totalTraj,centerFrame,sampleCenterVtxId,trajLen,octreeRes);//Á¬ÐøÅä×¼
	///20150122 -¼ÆË㶥µãµÄŤÇúÁ¿
    vector<ScalarType> disVal;
	nonrigid.calculateVtxDistor(totalTraj,disVal,centerFrame);


// 	for (int i = 0; i < 20; i++)
// 	{
// 		Loggger<<"distor"<<disVal[i]<<endl;
// 	}



	Sample& sample0 = set[centerFrame];
	vector<bool> isSelector(sample0.num_vertices(),false);

	bubleSort(sampleCenterVtxId,disVal,disVal.size());//ordered by vertex id


	///////////////////////////////////// in order to visual sample vertex
	for (int i = 0; i < sampleCenterVtxId.size(); i++)
	{
		isSelector[sampleCenterVtxId[i]] = true;
	}
	//  

	auto minId = std::minmax_element(disVal.begin(),disVal.end());
	ScalarType minV = *minId.first;
    ScalarType maxV = *minId.second;

	IndexType i = 0;
	IndexType k = 0;
	for (Sample::vtx_iterator v_iter = sample0.begin();
		v_iter != sample0.end();
		v_iter++,i++ )
	{
		if (isSelector[i])
		{
			(*v_iter)->set_visble(true);
			ScalarType ratio = (disVal[k] - minV) / maxV;
			//(*v_iter)->set_value( disVal[k] );//orignal label

			(*v_iter)->set_value( ratio );//orignal label
			k++;
		}else
		{
			(*v_iter)->set_visble(false);

		}

	}

	UNLOCK(set[centerFrame]);

	Loggger<< " End VISUAL DISTORSION.\n";
	emit finish_compute();
}
Ejemplo n.º 4
0
void TrajectoryClassifier::run(){

	Logger << "Begin Clustering.\n";

	SampleSet& set = SampleSet::get_instance();

	if (set.empty())
	{
		Logger<< " End Clustering(Warning: Empty Set).\n";
		emit finish_compute();
		return;
	}


	//Step 1: compute rotate feature


	// calculate feature
 	DeformableRegistration nonrigid;

 	//MatrixXX featureMat;
    //nonrigid.calculateTrajFrature(featureMat);

	// test life spans traj
  	vector<PCloudTraj> totalTraj;
     //nonrigid.calculateLifeSpansTraj(totalTraj,2);
 	////nonrigid.produceDreamTraj(totalTraj);


	////2014-11-1
	//IndexType centerFrame = 0;
	//IndexType trajLen = 1;
	//IndexType modeNum = 6500;
	//IndexType octreeRes = 64;
	//vector<IndexType> sampleCenterVtxId;
	////nonrigid.calculateFixedLengthTraj(totalTraj,5,5);
	////nonrigid.calculateFixedLengthTrajWithTracingAlong(totalTraj,centerFrame,sampleCenterVtxId,trajLen,octreeRes);//连续配准
	//nonrigid.calculateFixedLengthTraj(totalTraj,centerFrame,sampleCenterVtxId,trajLen,octreeRes);//先采样再配准--间隔配准
	////nonrigid.calculateFixedLengthTrajBySampleTraj(totalTraj,centerFrame,trajLen,sampleCenterVtxId);//先配准再采样



	//2014-12-16
	//vector<PCloudModel> totalModel;
	//nonrigid.sampleModel(totalTraj,totalModel,modeNum);

	////nonrigid.sampleModelByNeig(totalTraj,totalModel,3000);

	//static distance--output.txt
	//nonrigid.staticDistance(totalTraj,totalModel);


	///J-linkage-clustering
	//ScalarType threshold = 0.012;//horse -
	//ScalarType threshold = 5.00;//horse -dancing girl
	//ScalarType threshold = 6.0; //scanned hand myself
	//ScalarType threshold = 2.3; //hand2
	//11-2
	//ScalarType threshold = .0280; // walk man--1105WalkMan
	//ScalarType threshold = 0.5280; // walk man--1105WalkMan-T-linkage
	//ScalarType threshold = 4.5; //pink
	//ScalarType threshold = 15.0;//lab  walk --手向上伸展,脚向前踢--1105human pose
	//ScalarType threshold = 2.95;//hand_dis
	//ScalarType threshold = 50.0;//background--

	//ScalarType threshold = 1.8;//hao li test
	//2014-12-11
	//ScalarType threshold = 0.03500;//animation  dance
	//ScalarType threshold = 0.0091100;//hip_hop man(0_9)

// 	vector<IndexType> labels;//12-25
// 	labels.resize(totalTraj.size());
// 	//J_LinkageAdapter_II<PCloudTraj, PCloudModel, Traj2ModDistanceFunc>	algo_adaptor(totalTraj, totalModel, labels, Traj2ModDistanceFunc(0.3));
// 	//J_LinkageAdapter<PCloudTraj, PCloudModel, Traj2ModDistanceFunc>	algo_adaptor(totalTraj, totalModel, labels, Traj2ModDistanceFunc(threshold));
// 	J_LinkageAdapter_Matlab<PCloudTraj, PCloudModel, Traj2ModDistanceFunc>	algo_adaptor(totalTraj, totalModel, labels, Traj2ModDistanceFunc(threshold));
// 	algo_adaptor.compute();


	//using t-linkage-2014-12-11
	//T_LinkageAdapter<PCloudTraj, PCloudModel, Traj2ModDistanceFunc>algo_adaptor(totalTraj, totalModel, labels, Traj2ModDistanceFunc(threshold));
	//algo_adaptor.compute();


	///
// 	Logger<<"octree resolution = "<<octreeRes<<endl;
// 	Logger<<"centerFrame = "<<centerFrame<<endl;
// 	Logger<<"Traj len = "<<trajLen<<endl;
// 	Logger<<"j_linkage's threshold  = "<<threshold<<endl;


	/// test sample 9-30
	///nonrigid.testingcalPmodel();
	///Logger<<"cluster end !.\n";





	///2014-10-21-text TPS using data:same radius_but_rotate//
	//nonrigid.testingcalPmodel();//变形后的坐标不对



	////2014-10-22 test kmeans
	//nonrigid.calculateTrajFeature(totalTraj,5,featureMat);

// 	using namespace cv;
 	//cv::Mat	cluster_data;
 	//cv::Mat labels;
 	//cv::Mat centers;
 	//cv::eigen2cv(featureMat, cluster_data );
 	//cv::kmeans( cluster_data, 2, labels,  
 	//	cv::TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 100, 0.0001),
 	//	5, cv::KMEANS_PP_CENTERS, centers);



 	//Step 2: Begin Clustering, use opencv 's k-means clustering
//  	using namespace cv;
//  	Mat	cluster_data;
//  	Mat labels;
//  	Mat centers;
//  	cv::eigen2cv( rot_feature_mat, cluster_data );
//  	cv::kmeans( cluster_data, 10, labels,  
//  		TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 200, 0.00001),
//  		5, KMEANS_PP_CENTERS, centers);
 
 





 	//Step 3: Store the results

	////12-26-read file to visual 
    vector<IndexType> labels;
	vector<IndexType> label_smooth;
	vector<IndexType> sampleCenterVtxId;
	IndexType centerFrame;
	nonrigid.readSampleLabelFile("label_smp000_0.01200.txt",labels,label_smooth,sampleCenterVtxId,centerFrame); 
	////


  	LOCK( set[centerFrame] );
	Sample& sample0 = set[centerFrame];
	vector<bool> isSelector(sample0.num_vertices(),false);

	//bubleSort(sampleCenterVtxId,labels,labels.size());//ordered by vertex id
    //vector<IndexType> label_smooth(labels.size(),0);
	//nonrigid.smoothSampleLabel(sample0,sampleCenterVtxId,labels,label_smooth);


	//////////////////////////////////////////////////////////////////////////
	///save labels and label-smooth
	//IndexType smp_range[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
	//char label_labsmooth[256];
	//sprintf(label_labsmooth,"label_smp%.3d_%.5f.txt",centerFrame,threshold);
	//FILE *in_label_smmoth = fopen(label_labsmooth, "w");
	//for (IndexType s_vtx = 0; s_vtx < labels.size(); s_vtx++)
	//{
	//	fprintf( in_label_smmoth, "%d %d %d %d\n", centerFrame, labels[s_vtx], label_smooth[s_vtx],sampleCenterVtxId[s_vtx]);
	//}
	//fclose(in_label_smmoth);

	/////////////




	for (int i = 0; i < sampleCenterVtxId.size(); i++)
	{
		isSelector[sampleCenterVtxId[i]] = true;
	}

  	IndexType i = 0;
	IndexType k = 0;
  	for (Sample::vtx_iterator v_iter = sample0.begin();
  		v_iter != sample0.end();
  		v_iter++,i++ )
  	{
		if (isSelector[i])
		{
			(*v_iter)->set_visble(true);
			(*v_iter)->set_label( labels[k] );//orignal label
			//(*v_iter)->set_label( label_smooth[k] );//smooth label
			k++;
		}else
		{
			(*v_iter)->set_visble(false);
			/*smp0[ i ].set_visble(false);*/
		}
  		//(*v_iter)->set_label( labels.at<IndexType>(i) );
		//(*v_iter)->set_label( labels[i]);
  	}


	///2014-12-5--visulization-to orignal point cloud

	//vector<IndexType> result_label(sample0.num_vertices(),0);
	//nonrigid.propagateLabel2Orignal(sample0,sampleCenterVtxId,label_smooth,result_label); 



   ////save file 2014-12-18
	///IndexType smp_range[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
// 	char label_file_name[256];
// 	char corr_file_name[256];
// 	sprintf(label_file_name,"labels%.3d_%.5f.txt",centerFrame,threshold);
// 	sprintf(corr_file_name,"corr%.3d_%.5f.txt",centerFrame,threshold);
// 	FILE *in_label = fopen(label_file_name, "w");
// 	FILE *in_correspond = fopen(corr_file_name,"w");
// 	vector<PCloudTraj> trajs;
// 	
// 	for ( int i=0; i<set[centerFrame].num_vertices(); i++ )
// 	{
// 		fprintf( in_label, "%d %d %d\n", centerFrame, result_label[i], i );
// 	}
// 
// 	for ( int i=0; i<sampleCenterVtxId.size();i++ )
// 	{
// 		for (int j=0; j<(sizeof(smp_range)/sizeof(IndexType));j++)
// 		{
// 			if(centerFrame==smp_range[j] || totalTraj[i].trajLifeSpan.start > smp_range[j] )continue;
// 			if(totalTraj[i].trajLifeSpan.end < smp_range[j])break;
// 			IndexType v = sampleCenterVtxId[i];
// 			fprintf(in_correspond,"%d %d %d %d\n", centerFrame, v, smp_range[j], totalTraj[i].trajNode[smp_range[j] - totalTraj[i].trajLifeSpan.start]);
// 		}
// 	}
// 
// 	fclose(in_label);
// 	fclose(in_correspond);


  ///save file 2014-12-18--[12-25]

// 	IndexType i = 0;
// 	for (Sample::vtx_iterator v_iter = sample0.begin();
//   	v_iter != sample0.end();
//   	v_iter++,i++ )
// 	{
// 		(*v_iter)->set_label( result_label[i] );
// 	}

	Logger<<"ori data vertex size = "<<sample0.num_vertices()<<endl;
	UNLOCK(set[centerFrame]);




//2014-10-27-
	//Visualize bool vertex----Mesh
	//Sample& smp0 = SampleSet::get_instance()[7];
	//int k=0;
	//for ( int i=0; i<smp0.num_vertices();i++ )
	//{
	//	if ( k<labels.size() && totalTraj[k].trajNode[5]== i )
	//	{
	//		smp0[ i ].set_visble(true);
	//		smp0[ i ].set_label( labels[k] );
	//		++k;
	//	}
	//	else
	//	{
	//		smp0[ i ].set_visble(false);
	//	}
	//}


// test non-rigid
 	Logger<< " End Clustering.\n";
	emit finish_compute();
}