Ejemplo n.º 1
0
void BoundingBox::Define(const Polyhedron& poly)
{
    Clear();
    Merge(poly);
}
Ejemplo n.º 2
0
    void reorderList(ListNode *head)
	{
        ListNode *pMid = findMidPos(head);
        pMid = reverseList(pMid);
        head = Merge(head, pMid);
    }
Ejemplo n.º 3
0
void Sphere::Merge(const Vector3* vertices, unsigned count)
{
    while (count--)
        Merge(*vertices++);
}
Ejemplo n.º 4
0
void			btDbvt::benchmark()
{
	static const btScalar	cfgVolumeCenterScale		=	100;
	static const btScalar	cfgVolumeExentsBase			=	1;
	static const btScalar	cfgVolumeExentsScale		=	4;
	static const int		cfgLeaves					=	8192;
	static const bool		cfgEnable					=	true;

	//[1] btDbvtVolume intersections
	bool					cfgBenchmark1_Enable		=	cfgEnable;
	static const int		cfgBenchmark1_Iterations	=	8;
	static const int		cfgBenchmark1_Reference		=	3499;
	//[2] btDbvtVolume merges
	bool					cfgBenchmark2_Enable		=	cfgEnable;
	static const int		cfgBenchmark2_Iterations	=	4;
	static const int		cfgBenchmark2_Reference		=	1945;
	//[3] btDbvt::collideTT
	bool					cfgBenchmark3_Enable		=	cfgEnable;
	static const int		cfgBenchmark3_Iterations	=	512;
	static const int		cfgBenchmark3_Reference		=	5485;
	//[4] btDbvt::collideTT self
	bool					cfgBenchmark4_Enable		=	cfgEnable;
	static const int		cfgBenchmark4_Iterations	=	512;
	static const int		cfgBenchmark4_Reference		=	2814;
	//[5] btDbvt::collideTT xform
	bool					cfgBenchmark5_Enable		=	cfgEnable;
	static const int		cfgBenchmark5_Iterations	=	512;
	static const btScalar	cfgBenchmark5_OffsetScale	=	2;
	static const int		cfgBenchmark5_Reference		=	7379;
	//[6] btDbvt::collideTT xform,self
	bool					cfgBenchmark6_Enable		=	cfgEnable;
	static const int		cfgBenchmark6_Iterations	=	512;
	static const btScalar	cfgBenchmark6_OffsetScale	=	2;
	static const int		cfgBenchmark6_Reference		=	7270;
	//[7] btDbvt::rayTest
	bool					cfgBenchmark7_Enable		=	cfgEnable;
	static const int		cfgBenchmark7_Passes		=	32;
	static const int		cfgBenchmark7_Iterations	=	65536;
	static const int		cfgBenchmark7_Reference		=	6307;
	//[8] insert/remove
	bool					cfgBenchmark8_Enable		=	cfgEnable;
	static const int		cfgBenchmark8_Passes		=	32;
	static const int		cfgBenchmark8_Iterations	=	65536;
	static const int		cfgBenchmark8_Reference		=	2105;
	//[9] updates (teleport)
	bool					cfgBenchmark9_Enable		=	cfgEnable;
	static const int		cfgBenchmark9_Passes		=	32;
	static const int		cfgBenchmark9_Iterations	=	65536;
	static const int		cfgBenchmark9_Reference		=	1879;
	//[10] updates (jitter)
	bool					cfgBenchmark10_Enable		=	cfgEnable;
	static const btScalar	cfgBenchmark10_Scale		=	cfgVolumeCenterScale/10000;
	static const int		cfgBenchmark10_Passes		=	32;
	static const int		cfgBenchmark10_Iterations	=	65536;
	static const int		cfgBenchmark10_Reference	=	1244;
	//[11] optimize (incremental)
	bool					cfgBenchmark11_Enable		=	cfgEnable;
	static const int		cfgBenchmark11_Passes		=	64;
	static const int		cfgBenchmark11_Iterations	=	65536;
	static const int		cfgBenchmark11_Reference	=	2510;
	//[12] btDbvtVolume notequal
	bool					cfgBenchmark12_Enable		=	cfgEnable;
	static const int		cfgBenchmark12_Iterations	=	32;
	static const int		cfgBenchmark12_Reference	=	3677;
	//[13] culling(OCL+fullsort)
	bool					cfgBenchmark13_Enable		=	cfgEnable;
	static const int		cfgBenchmark13_Iterations	=	1024;
	static const int		cfgBenchmark13_Reference	=	2231;
	//[14] culling(OCL+qsort)
	bool					cfgBenchmark14_Enable		=	cfgEnable;
	static const int		cfgBenchmark14_Iterations	=	8192;
	static const int		cfgBenchmark14_Reference	=	3500;
	//[15] culling(KDOP+qsort)
	bool					cfgBenchmark15_Enable		=	cfgEnable;
	static const int		cfgBenchmark15_Iterations	=	8192;
	static const int		cfgBenchmark15_Reference	=	1151;
	//[16] insert/remove batch
	bool					cfgBenchmark16_Enable		=	cfgEnable;
	static const int		cfgBenchmark16_BatchCount	=	256;
	static const int		cfgBenchmark16_Passes		=	16384;
	static const int		cfgBenchmark16_Reference	=	5138;
	//[17] select
	bool					cfgBenchmark17_Enable		=	cfgEnable;
	static const int		cfgBenchmark17_Iterations	=	4;
	static const int		cfgBenchmark17_Reference	=	3390;

	btClock					wallclock;
	printf("Benchmarking dbvt...\r\n");
	printf("\tWorld scale: %f\r\n",cfgVolumeCenterScale);
	printf("\tExtents base: %f\r\n",cfgVolumeExentsBase);
	printf("\tExtents range: %f\r\n",cfgVolumeExentsScale);
	printf("\tLeaves: %u\r\n",cfgLeaves);
	printf("\tsizeof(btDbvtVolume): %u bytes\r\n",sizeof(btDbvtVolume));
	printf("\tsizeof(btDbvtNode):   %u bytes\r\n",sizeof(btDbvtNode));
	if(cfgBenchmark1_Enable)
	{// Benchmark 1	
		srand(380843);
		btAlignedObjectArray<btDbvtVolume>	volumes;
		btAlignedObjectArray<bool>			results;
		volumes.resize(cfgLeaves);
		results.resize(cfgLeaves);
		for(int i=0;i<cfgLeaves;++i)
		{
			volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
		}
		printf("[1] btDbvtVolume intersections: ");
		wallclock.reset();
		for(int i=0;i<cfgBenchmark1_Iterations;++i)
		{
			for(int j=0;j<cfgLeaves;++j)
			{
				for(int k=0;k<cfgLeaves;++k)
				{
					results[k]=Intersect(volumes[j],volumes[k]);
				}
			}
		}
		const int time=(int)wallclock.getTimeMilliseconds();
		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark1_Reference)*100/time);
	}
	if(cfgBenchmark2_Enable)
	{// Benchmark 2	
		srand(380843);
		btAlignedObjectArray<btDbvtVolume>	volumes;
		btAlignedObjectArray<btDbvtVolume>	results;
		volumes.resize(cfgLeaves);
		results.resize(cfgLeaves);
		for(int i=0;i<cfgLeaves;++i)
		{
			volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
		}
		printf("[2] btDbvtVolume merges: ");
		wallclock.reset();
		for(int i=0;i<cfgBenchmark2_Iterations;++i)
		{
			for(int j=0;j<cfgLeaves;++j)
			{
				for(int k=0;k<cfgLeaves;++k)
				{
					Merge(volumes[j],volumes[k],results[k]);
				}
			}
		}
		const int time=(int)wallclock.getTimeMilliseconds();
		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark2_Reference)*100/time);
	}
	if(cfgBenchmark3_Enable)
	{// Benchmark 3	
		srand(380843);
		btDbvt						dbvt[2];
		btDbvtBenchmark::NilPolicy	policy;
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[0]);
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[1]);
		dbvt[0].optimizeTopDown();
		dbvt[1].optimizeTopDown();
		printf("[3] btDbvt::collideTT: ");
		wallclock.reset();
		for(int i=0;i<cfgBenchmark3_Iterations;++i)
		{
			btDbvt::collideTT(dbvt[0].m_root,dbvt[1].m_root,policy);
		}
		const int time=(int)wallclock.getTimeMilliseconds();
		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark3_Reference)*100/time);
	}
	if(cfgBenchmark4_Enable)
	{// Benchmark 4
		srand(380843);
		btDbvt						dbvt;
		btDbvtBenchmark::NilPolicy	policy;
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
		dbvt.optimizeTopDown();
		printf("[4] btDbvt::collideTT self: ");
		wallclock.reset();
		for(int i=0;i<cfgBenchmark4_Iterations;++i)
		{
			btDbvt::collideTT(dbvt.m_root,dbvt.m_root,policy);
		}
		const int time=(int)wallclock.getTimeMilliseconds();
		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark4_Reference)*100/time);
	}
	if(cfgBenchmark5_Enable)
	{// Benchmark 5	
		srand(380843);
		btDbvt								dbvt[2];
		btAlignedObjectArray<btTransform>	transforms;
		btDbvtBenchmark::NilPolicy			policy;
		transforms.resize(cfgBenchmark5_Iterations);
		for(int i=0;i<transforms.size();++i)
		{
			transforms[i]=btDbvtBenchmark::RandTransform(cfgVolumeCenterScale*cfgBenchmark5_OffsetScale);
		}
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[0]);
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt[1]);
		dbvt[0].optimizeTopDown();
		dbvt[1].optimizeTopDown();
		printf("[5] btDbvt::collideTT xform: ");
		wallclock.reset();
		for(int i=0;i<cfgBenchmark5_Iterations;++i)
		{
			btDbvt::collideTT(dbvt[0].m_root,dbvt[1].m_root,transforms[i],policy);
		}
		const int time=(int)wallclock.getTimeMilliseconds();
		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark5_Reference)*100/time);
	}
	if(cfgBenchmark6_Enable)
	{// Benchmark 6	
		srand(380843);
		btDbvt								dbvt;
		btAlignedObjectArray<btTransform>	transforms;
		btDbvtBenchmark::NilPolicy			policy;
		transforms.resize(cfgBenchmark6_Iterations);
		for(int i=0;i<transforms.size();++i)
		{
			transforms[i]=btDbvtBenchmark::RandTransform(cfgVolumeCenterScale*cfgBenchmark6_OffsetScale);
		}
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
		dbvt.optimizeTopDown();
		printf("[6] btDbvt::collideTT xform,self: ");
		wallclock.reset();
		for(int i=0;i<cfgBenchmark6_Iterations;++i)
		{
			btDbvt::collideTT(dbvt.m_root,dbvt.m_root,transforms[i],policy);		
		}
		const int time=(int)wallclock.getTimeMilliseconds();
		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark6_Reference)*100/time);
	}
	if(cfgBenchmark7_Enable)
	{// Benchmark 7	
		srand(380843);
		btDbvt								dbvt;
		btAlignedObjectArray<btVector3>		rayorg;
		btAlignedObjectArray<btVector3>		raydir;
		btDbvtBenchmark::NilPolicy			policy;
		rayorg.resize(cfgBenchmark7_Iterations);
		raydir.resize(cfgBenchmark7_Iterations);
		for(int i=0;i<rayorg.size();++i)
		{
			rayorg[i]=btDbvtBenchmark::RandVector3(cfgVolumeCenterScale*2);
			raydir[i]=btDbvtBenchmark::RandVector3(cfgVolumeCenterScale*2);
		}
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
		dbvt.optimizeTopDown();
		printf("[7] btDbvt::rayTest: ");
		wallclock.reset();
		for(int i=0;i<cfgBenchmark7_Passes;++i)
		{
			for(int j=0;j<cfgBenchmark7_Iterations;++j)
			{
				btDbvt::rayTest(dbvt.m_root,rayorg[j],rayorg[j]+raydir[j],policy);
			}
		}
		const int	time=(int)wallclock.getTimeMilliseconds();
		unsigned	rays=cfgBenchmark7_Passes*cfgBenchmark7_Iterations;
		printf("%u ms (%i%%),(%u r/s)\r\n",time,(time-cfgBenchmark7_Reference)*100/time,(rays*1000)/time);
	}
	if(cfgBenchmark8_Enable)
	{// Benchmark 8	
		srand(380843);
		btDbvt								dbvt;
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
		dbvt.optimizeTopDown();
		printf("[8] insert/remove: ");
		wallclock.reset();
		for(int i=0;i<cfgBenchmark8_Passes;++i)
		{
			for(int j=0;j<cfgBenchmark8_Iterations;++j)
			{
				dbvt.remove(dbvt.insert(btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale),0));
			}
		}
		const int	time=(int)wallclock.getTimeMilliseconds();
		const int	ir=cfgBenchmark8_Passes*cfgBenchmark8_Iterations;
		printf("%u ms (%i%%),(%u ir/s)\r\n",time,(time-cfgBenchmark8_Reference)*100/time,ir*1000/time);
	}
	if(cfgBenchmark9_Enable)
	{// Benchmark 9	
		srand(380843);
		btDbvt										dbvt;
		btAlignedObjectArray<const btDbvtNode*>	leaves;
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
		dbvt.optimizeTopDown();
		dbvt.extractLeaves(dbvt.m_root,leaves);
		printf("[9] updates (teleport): ");
		wallclock.reset();
		for(int i=0;i<cfgBenchmark9_Passes;++i)
		{
			for(int j=0;j<cfgBenchmark9_Iterations;++j)
			{
				dbvt.update(const_cast<btDbvtNode*>(leaves[rand()%cfgLeaves]),
					btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale));
			}
		}
		const int	time=(int)wallclock.getTimeMilliseconds();
		const int	up=cfgBenchmark9_Passes*cfgBenchmark9_Iterations;
		printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark9_Reference)*100/time,up*1000/time);
	}
	if(cfgBenchmark10_Enable)
	{// Benchmark 10	
		srand(380843);
		btDbvt										dbvt;
		btAlignedObjectArray<const btDbvtNode*>	leaves;
		btAlignedObjectArray<btVector3>				vectors;
		vectors.resize(cfgBenchmark10_Iterations);
		for(int i=0;i<vectors.size();++i)
		{
			vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1))*cfgBenchmark10_Scale;
		}
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
		dbvt.optimizeTopDown();
		dbvt.extractLeaves(dbvt.m_root,leaves);
		printf("[10] updates (jitter): ");
		wallclock.reset();

		for(int i=0;i<cfgBenchmark10_Passes;++i)
		{
			for(int j=0;j<cfgBenchmark10_Iterations;++j)
			{			
				const btVector3&	d=vectors[j];
				btDbvtNode*		l=const_cast<btDbvtNode*>(leaves[rand()%cfgLeaves]);
				btDbvtVolume		v=btDbvtVolume::FromMM(l->volume.Mins()+d,l->volume.Maxs()+d);
				dbvt.update(l,v);
			}
		}
		const int	time=(int)wallclock.getTimeMilliseconds();
		const int	up=cfgBenchmark10_Passes*cfgBenchmark10_Iterations;
		printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark10_Reference)*100/time,up*1000/time);
	}
	if(cfgBenchmark11_Enable)
	{// Benchmark 11	
		srand(380843);
		btDbvt										dbvt;
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
		dbvt.optimizeTopDown();
		printf("[11] optimize (incremental): ");
		wallclock.reset();	
		for(int i=0;i<cfgBenchmark11_Passes;++i)
		{
			dbvt.optimizeIncremental(cfgBenchmark11_Iterations);
		}
		const int	time=(int)wallclock.getTimeMilliseconds();
		const int	op=cfgBenchmark11_Passes*cfgBenchmark11_Iterations;
		printf("%u ms (%i%%),(%u o/s)\r\n",time,(time-cfgBenchmark11_Reference)*100/time,op/time*1000);
	}
	if(cfgBenchmark12_Enable)
	{// Benchmark 12	
		srand(380843);
		btAlignedObjectArray<btDbvtVolume>	volumes;
		btAlignedObjectArray<bool>				results;
		volumes.resize(cfgLeaves);
		results.resize(cfgLeaves);
		for(int i=0;i<cfgLeaves;++i)
		{
			volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
		}
		printf("[12] btDbvtVolume notequal: ");
		wallclock.reset();
		for(int i=0;i<cfgBenchmark12_Iterations;++i)
		{
			for(int j=0;j<cfgLeaves;++j)
			{
				for(int k=0;k<cfgLeaves;++k)
				{
					results[k]=NotEqual(volumes[j],volumes[k]);
				}
			}
		}
		const int time=(int)wallclock.getTimeMilliseconds();
		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark12_Reference)*100/time);
	}
	if(cfgBenchmark13_Enable)
	{// Benchmark 13	
		srand(380843);
		btDbvt								dbvt;
		btAlignedObjectArray<btVector3>		vectors;
		btDbvtBenchmark::NilPolicy			policy;
		vectors.resize(cfgBenchmark13_Iterations);
		for(int i=0;i<vectors.size();++i)
		{
			vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1)).normalized();
		}
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
		dbvt.optimizeTopDown();
		printf("[13] culling(OCL+fullsort): ");
		wallclock.reset();	
		for(int i=0;i<cfgBenchmark13_Iterations;++i)
		{
			static const btScalar	offset=0;
			policy.m_depth=-SIMD_INFINITY;
			dbvt.collideOCL(dbvt.m_root,&vectors[i],&offset,vectors[i],1,policy);
		}
		const int	time=(int)wallclock.getTimeMilliseconds();
		const int	t=cfgBenchmark13_Iterations;
		printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark13_Reference)*100/time,(t*1000)/time);
	}
	if(cfgBenchmark14_Enable)
	{// Benchmark 14	
		srand(380843);
		btDbvt								dbvt;
		btAlignedObjectArray<btVector3>		vectors;
		btDbvtBenchmark::P14				policy;
		vectors.resize(cfgBenchmark14_Iterations);
		for(int i=0;i<vectors.size();++i)
		{
			vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1)).normalized();
		}
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
		dbvt.optimizeTopDown();
		policy.m_nodes.reserve(cfgLeaves);
		printf("[14] culling(OCL+qsort): ");
		wallclock.reset();	
		for(int i=0;i<cfgBenchmark14_Iterations;++i)
		{
			static const btScalar	offset=0;
			policy.m_nodes.resize(0);
			dbvt.collideOCL(dbvt.m_root,&vectors[i],&offset,vectors[i],1,policy,false);
			policy.m_nodes.quickSort(btDbvtBenchmark::P14::sortfnc);
		}
		const int	time=(int)wallclock.getTimeMilliseconds();
		const int	t=cfgBenchmark14_Iterations;
		printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark14_Reference)*100/time,(t*1000)/time);
	}
	if(cfgBenchmark15_Enable)
	{// Benchmark 15	
		srand(380843);
		btDbvt								dbvt;
		btAlignedObjectArray<btVector3>		vectors;
		btDbvtBenchmark::P15				policy;
		vectors.resize(cfgBenchmark15_Iterations);
		for(int i=0;i<vectors.size();++i)
		{
			vectors[i]=(btDbvtBenchmark::RandVector3()*2-btVector3(1,1,1)).normalized();
		}
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
		dbvt.optimizeTopDown();
		policy.m_nodes.reserve(cfgLeaves);
		printf("[15] culling(KDOP+qsort): ");
		wallclock.reset();	
		for(int i=0;i<cfgBenchmark15_Iterations;++i)
		{
			static const btScalar	offset=0;
			policy.m_nodes.resize(0);
			policy.m_axis=vectors[i];
			dbvt.collideKDOP(dbvt.m_root,&vectors[i],&offset,1,policy);
			policy.m_nodes.quickSort(btDbvtBenchmark::P15::sortfnc);
		}
		const int	time=(int)wallclock.getTimeMilliseconds();
		const int	t=cfgBenchmark15_Iterations;
		printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark15_Reference)*100/time,(t*1000)/time);
	}
	if(cfgBenchmark16_Enable)
	{// Benchmark 16	
		srand(380843);
		btDbvt								dbvt;
		btAlignedObjectArray<btDbvtNode*>	batch;
		btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
		dbvt.optimizeTopDown();
		batch.reserve(cfgBenchmark16_BatchCount);
		printf("[16] insert/remove batch(%u): ",cfgBenchmark16_BatchCount);
		wallclock.reset();
		for(int i=0;i<cfgBenchmark16_Passes;++i)
		{
			for(int j=0;j<cfgBenchmark16_BatchCount;++j)
			{
				batch.push_back(dbvt.insert(btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale),0));
			}
			for(int j=0;j<cfgBenchmark16_BatchCount;++j)
			{
				dbvt.remove(batch[j]);
			}
			batch.resize(0);
		}
		const int	time=(int)wallclock.getTimeMilliseconds();
		const int	ir=cfgBenchmark16_Passes*cfgBenchmark16_BatchCount;
		printf("%u ms (%i%%),(%u bir/s)\r\n",time,(time-cfgBenchmark16_Reference)*100/time,int(ir*1000.0/time));
	}
	if(cfgBenchmark17_Enable)
	{// Benchmark 17
		srand(380843);
		btAlignedObjectArray<btDbvtVolume>	volumes;
		btAlignedObjectArray<int>			results;
		btAlignedObjectArray<int>			indices;
		volumes.resize(cfgLeaves);
		results.resize(cfgLeaves);
		indices.resize(cfgLeaves);
		for(int i=0;i<cfgLeaves;++i)
		{
			indices[i]=i;
			volumes[i]=btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale);
		}
		for(int i=0;i<cfgLeaves;++i)
		{
			btSwap(indices[i],indices[rand()%cfgLeaves]);
		}
		printf("[17] btDbvtVolume select: ");
		wallclock.reset();
		for(int i=0;i<cfgBenchmark17_Iterations;++i)
		{
			for(int j=0;j<cfgLeaves;++j)
			{
				for(int k=0;k<cfgLeaves;++k)
				{
					const int idx=indices[k];
					results[idx]=Select(volumes[idx],volumes[j],volumes[k]);
				}
			}
		}
		const int time=(int)wallclock.getTimeMilliseconds();
		printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark17_Reference)*100/time);
	}
	printf("\r\n\r\n");
}
Ejemplo n.º 5
0
/*main{{{*/
int main()
{
	/*ROOT Define{{{*/
	// Fill color
	gStyle->SetStatColor(0);
	gStyle->SetTitleFillColor(0);
	gStyle->SetCanvasColor(0);
	gStyle->SetPadColor(0);
	gStyle->SetFrameFillColor(0);

	// Border mode
	gStyle->SetCanvasBorderMode(0);
	gStyle->SetPadBorderMode(0);
	gStyle->SetFrameBorderMode(0);
	gStyle->SetPalette(1,0);

	// Font
	gStyle->SetTextFont(32);
	gStyle->SetLabelFont(32, "xyz");
	gStyle->SetTitleFont(22, "xyz");
	gStyle->SetStatFont(32);
	gStyle->SetTitleFillColor(0);

	// Opt
	//    gStyle->SetOptDate(0);
	//    gStyle->SetOptTitle(1);
	//    gStyle->SetOptStat(1);
	//    gStyle->SetOptFit(1);
	//    // Margin
	// //    gStyle->SetPadLeftMargin(0.1);
	// //    gStyle->SetPadRightMargin(0.1);
	// //    gStyle->SetPadTopMargin(0.1);
	// //    gStyle->SetPadBottomMargin(0.1);


	//void HallA_style() {
	gROOT->SetStyle("Plain");
	gStyle->SetPaperSize(TStyle::kUSLetter);
	gStyle->SetPaperSize(18,22);
	gStyle->SetOptFit(1111);
	gStyle->SetPalette(1);
	gStyle->SetNdivisions(505);

	gStyle->SetCanvasColor(0);
	gStyle->SetPadTopMargin(.05);
	gStyle->SetPadLeftMargin(.15);
	gStyle->SetPadRightMargin(.1);
	gStyle->SetPadBottomMargin(.15);
	gStyle->SetTitleYOffset(1.3);
	gStyle->SetLabelFont(32,"X");
	gStyle->SetLabelFont(32,"Y");

	// prepare gStyle to be useful
	//   1 = solid
	//   2 = long dash (30 10)
	gStyle->SetTitleFillColor(-1); 
	//   3 = dotted (4 8)
	//   4 = dash-dot (15 12 4 12)
	//   5 = short dash ( 15 15 )
	//   6 = dash-dot-dot 
	gStyle->SetLineStyleString(1,"[]");
	gStyle->SetLineStyleString(2,"[30 10]");
	gStyle->SetLineStyleString(3,"[4 8]");
	gStyle->SetLineStyleString(4,"[15 12 4 12]");
	gStyle->SetLineStyleString(5,"[15 15]");
	gStyle->SetLineStyleString(6,"[15 12 4 12 4 12]");
	gStyle->SetLabelSize(0.05,"X");
	gStyle->SetLabelSize(0.05,"Y");
	gStyle->SetNdivisions(505,"Y");
	gStyle->SetOptDate(0);
	gStyle->SetDateY(.98);
	gStyle->SetStripDecimals(kFALSE);

	gStyle->SetHistFillColor(0); 
	gStyle->SetFillColor(0); 
	gStyle->SetFillStyle(4000); 
	gStyle->SetStatStyle(0); 
	gStyle->SetTitleStyle(0); 
	gStyle->SetCanvasBorderSize(0); 
	gStyle->SetFrameBorderSize(0); 
	gStyle->SetLegendBorderSize(0); 
	gStyle->SetStatBorderSize(0); 
	gStyle->SetTitleBorderSize(0); 

	/*}}}*/

	TString Target; cerr<<" Which Target? (H2,He3,He4,C12,Ca40,Ca48) "; cin >> Target;
	ofstream outfile(Form("XS_%s.dat",Target.Data()));
	outfile << Form("%4s %7s %4s %7s %7s %7s %16s %16s %16s", 
			"Target",  "Angle","E0","Ep","Nu","xbj","XS","XS_Err","XS_MC")
		<< endl;
	
	cerr<<"--- Comment = "; cin>>Com;
	//bool bMC = kTRUE;
	//bool bMC = kFALSE;
	//double Theta =21;
	//double Zero[100] = {100*0.0};
    double E0 = 3.356;

	/*Merge{{{*/

	/*Degree 21 {{{*/
	double xbj_21[100], Ep_21[100], Nu_21[100], XS_EX_21[100], XS_EX_Err_21[100], XS_MC_21[100];
	int N_21 = 0;
	if(Target=="H2" ||Target=="He3" ||  Target=="He4" || Target=="C12"||Target=="Ca40"||Target=="Ca48"){
		Merge(Form("R21_%s.dat",Target.Data()), xbj_21, Ep_21, XS_EX_21, XS_EX_Err_21, XS_MC_21, &N_21);
		cerr<<"=== 21: Total Points = "<<N_21<<endl;
		for(int i=0;i<N_21;i++){
			Nu_21[i] = E0 - Ep_21[i];
			cerr    << Form("%4s %7.3f %7.3f %7.3f %7.3f %7.3f %16e %16e %16e",
				   	Target.Data(),21.00, E0, Ep_21[i], Nu_21[i], xbj_21[i],XS_EX_21[i],XS_EX_Err_21[i],XS_MC_21[i] )
				<< endl;
			outfile << Form("%4s %7.3f %7.3f %7.3f %7.3f %7.3f %16e %16e %16e", 
					Target.Data(),21.00, E0, Ep_21[i], Nu_21[i], xbj_21[i],XS_EX_21[i],XS_EX_Err_21[i],XS_MC_21[i] )
				<< endl;
		}
	}
	double Q2_21_D = 4.0*E0*Ep_Cut_21_1[0]*pow(TMath::Sin(21.*3.1415926/180.0*0.5),2);
	double Q2_21_U = 4.0*E0*Ep_Cut_21_2[3]*pow(TMath::Sin(21.*3.1415926/180.0*0.5),2);
	/*}}}*/

	/*Degree 23 {{{*/
	double xbj_23[100], Nu_23[100], Ep_23[100], XS_EX_23[100], XS_EX_Err_23[100], XS_MC_23[100];
	int N_23 = 0;
	if(Target=="He3" ||  Target=="He4" || Target=="C12"||Target=="Ca40"||Target=="Ca48"){
		Merge(Form("R23_%s.dat",Target.Data()), xbj_23, Ep_23, XS_EX_23, XS_EX_Err_23, XS_MC_23, &N_23);
		cerr<<"=== 23: Total Points = "<<N_23<<endl;
		for(int i=0;i<N_23;i++){
			Nu_23[i] = E0 - Ep_23[i];
			cerr    << Form("%4s %7.3f %7.3f %7.3f %7.3f %7.3f %16e %16e %16e", 
					Target.Data(),23.00, E0, Ep_23[i], Nu_23[i], xbj_23[i],XS_EX_23[i],XS_EX_Err_23[i],XS_MC_23[i] )
				<< endl;
			outfile << Form("%4s %7.3f %7.3f %7.3f %7.3f %7.3f %16e %16e %16e", 
					Target.Data(),23.00, E0, Ep_23[i], Nu_23[i], xbj_23[i],XS_EX_23[i],XS_EX_Err_23[i],XS_MC_23[i] )
				<< endl;
		}
	}
	double Q2_23_D = 4.0*E0*Ep_Cut_23_1[0]*pow(TMath::Sin(23.*3.1415926/180.0*0.5),2);
	double Q2_23_U = 4.0*E0*Ep_Cut_23_2[3]*pow(TMath::Sin(23.*3.1415926/180.0*0.5),2);
		/*}}}*/

	/*QE{{{*/
	double xbj_QE[100], Nu_QE[100], Ep_QE[100], XS_EX_QE[100], XS_EX_Err_QE[100], XS_MC_QE[100];
	int N_QE = 0;
	if(Target=="He3" ||  Target=="He4" || Target=="C12"||Target=="Ca40"||Target=="Ca48"){
		Merge(Form("RQE_%s.dat",Target.Data()), xbj_QE, Ep_QE, XS_EX_QE, XS_EX_Err_QE, XS_MC_QE, &N_QE);
		cerr<<"=== QE: Total Points = "<<N_QE<<endl;
		for(int i=0;i<N_QE;i++){
			Nu_QE[i] = E0 - Ep_QE[i];
			cerr    << Form("%4s %7.3f %7.3f %7.3f %7.3f %7.3f %16e %16e %16e", Target.Data(),25.00, E0, Ep_QE[i], Nu_QE[i], xbj_QE[i],XS_EX_QE[i],XS_EX_Err_QE[i],XS_MC_QE[i] )
				<< endl;

			outfile << Form("%4s %7.3f %7.3f %7.3f %7.3f %7.3f %16e %16e %16e", Target.Data(),25.00, E0, Ep_QE[i], Nu_QE[i], xbj_QE[i],XS_EX_QE[i],XS_EX_Err_QE[i],XS_MC_QE[i] )
				<< endl;
		}
	}
	double Q2_25_D = 4.0*E0*Ep_Cut_QE_1[0]*pow(TMath::Sin(25.*3.1415926/180.0*0.5),2);
	/*}}}*/

	/*Degree 25 {{{*/
	double xbj_25[100], Ep_25[100], Nu_25[100], XS_EX_25[100], XS_EX_Err_25[100], XS_MC_25[100];
	int N_25 = 0;
	if(Target=="H2" ||Target=="He3" ||  Target=="He4" || Target=="C12"||Target=="Ca40"||Target=="Ca48"){
		Merge(Form("R25_%s.dat",Target.Data()), xbj_25, Ep_25, XS_EX_25, XS_EX_Err_25, XS_MC_25, &N_25);
		cerr<<"=== 25: Total Points = "<<N_25<<endl;
		for(int i=0;i<N_25;i++){
			Nu_25[i] = E0 - Ep_25[i];
			cerr    << Form("%4s %7.3f %7.3f %7.3f %7.3f %7.3f %16e %16e %16e", 
					Target.Data(),25.00, E0, Ep_25[i], Nu_25[i], xbj_25[i],XS_EX_25[i],XS_EX_Err_25[i],XS_MC_25[i] )
				<< endl;
			outfile << Form("%4s %7.3f %7.3f %7.3f %7.3f %7.3f %16e %16e %16e", 
					Target.Data(),25.00, E0, Ep_25[i], Nu_25[i], xbj_25[i],XS_EX_25[i],XS_EX_Err_25[i],XS_MC_25[i] )
				<< endl;
		}
	}
	double Q2_25_U = 4.0*E0*Ep_Cut_25_2[3]*pow(TMath::Sin(25.*3.1415926/180.0*0.5),2);
	/*}}}*/

	/*Degree 28 {{{*/
	double xbj_28[100], Nu_28[100], Ep_28[100], XS_EX_28[100], XS_EX_Err_28[100], XS_MC_28[100];
	int N_28 = 0;
	if(Target=="He3" || Target=="C12"){
		Merge(Form("R28_%s.dat",Target.Data()), xbj_28, Ep_28, XS_EX_28, XS_EX_Err_28, XS_MC_28, &N_28);
		cerr<<"=== 28: Total Points = "<<N_28<<endl;
		for(int i=0;i<N_28;i++){
			Nu_28[i] = E0 - Ep_28[i];
			cerr    << Form("%4s %7.3f %7.3f %7.3f %7.3f %7.3f %16e %16e %16e", 
					Target.Data(),28.00, E0, Ep_28[i], Nu_28[i], xbj_28[i],XS_EX_28[i],XS_EX_Err_28[i],XS_MC_28[i] )
				<< endl;
			outfile << Form("%4s %7.3f %7.3f %7.3f %7.3f %7.3f %16e %16e %16e", 
					Target.Data(),28.00, E0, Ep_28[i], Nu_28[i], xbj_28[i],XS_EX_28[i],XS_EX_Err_28[i],XS_MC_28[i] )
				<< endl;
		}
	}
	double Q2_28_D = 4.0*E0*Ep_Cut_28_1[0]*pow(TMath::Sin(28.*3.1415926/180.0*0.5),2);
	double Q2_28_U = 4.0*E0*Ep_Cut_28_1[3]*pow(TMath::Sin(28.*3.1415926/180.0*0.5),2);
	/*}}}*/

	/*}}}*/

    /*Plot{{{*/
    /*Range{{{*/
	double Min = 1000, Max =-1000;
	for(int i=0; i<N_21;i++){
		Min = Min<XS_EX_21[i]?Min:XS_EX_21[i];
		Max = Max>XS_EX_21[i]?Max:XS_EX_21[i];
	}
	for(int i=0; i<N_23;i++){
		Min = Min<XS_EX_23[i]?Min:XS_EX_23[i];
		Max = Max>XS_EX_23[i]?Max:XS_EX_23[i];
	}
	for(int i=0; i<N_QE;i++){
		Min = Min<XS_EX_QE[i]?Min:XS_EX_QE[i];
		Max = Max>XS_EX_QE[i]?Max:XS_EX_QE[i];
	}
	for(int i=0; i<N_25;i++){
		Min = Min<XS_EX_25[i]?Min:XS_EX_25[i];
		Max = Max>XS_EX_25[i]?Max:XS_EX_25[i];
	}
	for(int i=0; i<N_28;i++){
		Min = Min<XS_EX_28[i]?Min:XS_EX_28[i];
		Max = Max>XS_EX_28[i]?Max:XS_EX_28[i];
	}
/*}}}*/

	/*Xbj{{{*/
	double xbj_err[200];
	for(int i=0;i<200;i++)
       xbj_err[200]=0;

	Double_t Xbj_Max = 2.2;
	Double_t Xbj_Min = 0.5;
	if(Target=="H2")
		Xbj_Max = 2.2;
	else if(Target=="He3"){
		Xbj_Max = 3.5;
		Max*=3.0;
	}
	else if(Target=="He4")
		Xbj_Max = 4.3;
	else
		Xbj_Max = 5.3;

	TCanvas *c1 = new TCanvas("c1","c1",1200,800);
	TH2F* xs = new TH2F("xs","",1000,Xbj_Min,Xbj_Max,1000,Min/2.1,Max*2.1);
	xs->SetStats(kFALSE);
	xs->SetXTitle("x_{bj}");
	xs->GetXaxis()->CenterTitle(1);
	xs->GetXaxis()->SetTitleFont(32);
	xs->GetXaxis()->SetTitleSize(0.06);
	xs->SetYTitle("#frac{d#sigma}{dE'd#Omega} (nb/MeV/sr)");
	xs->GetYaxis()->CenterTitle(1);
	xs->GetYaxis()->SetTitleFont(32);
	xs->GetYaxis()->SetTitleSize(0.04);
	xs->Draw(); 
	//gPad->SetLogy(1);
	gPad->SetLogy(1);

	TLegend *l1 = new TLegend(0.60,0.59,0.75, 0.94,Form("%s Target",Target.Data()));
	l1->SetBorderSize(0);
	l1->SetTextSize(0.03);
	l1->SetTextFont(32);

	TGraphErrors *pl_21 = new TGraphErrors(N_21,xbj_21,XS_EX_21,xbj_err,XS_EX_Err_21);
	pl_21-> SetMarkerSize(1.0);
	pl_21-> SetMarkerStyle(24);
	pl_21-> SetMarkerColor(2);
	pl_21-> GetXaxis()->SetTitle("x_{bj}");
	pl_21-> GetYaxis()->SetTitle("#sigma");
	pl_21->Draw("P");
	l1->AddEntry(pl_21, Form("21^{o}: %4.3f<Q^{2}<%4.3f (GeV/c^{2})",Q2_21_D,Q2_21_U),"p");

	TGraph *p1_21_mc = new TGraphErrors(N_21,xbj_21,XS_MC_21);
	p1_21_mc-> SetLineWidth(2);
	p1_21_mc-> SetLineStyle(2);
	//p1_21_mc-> SetLineColor(2);
	p1_21_mc-> SetLineColor(1);
	p1_21_mc-> GetXaxis()->SetTitle("x_{bj}");
	p1_21_mc-> GetYaxis()->SetTitle("#sigma");
	p1_21_mc->Draw("L");
	
	TGraphErrors *pl_23 = new TGraphErrors(N_23,xbj_23,XS_EX_23,xbj_err,XS_EX_Err_23);
	if(!(Target=="H2")){
		pl_23-> SetMarkerSize(1.0);
		pl_23-> SetMarkerStyle(25);
		pl_23-> SetMarkerColor(3);
		pl_23-> GetXaxis()->SetTitle("x_{bj}");
		pl_23-> GetYaxis()->SetTitle("#sigma");
		pl_23->Draw("P");
		l1->AddEntry(pl_23, Form("23^{o}: %4.3f<Q^{2}<%4.3f (GeV/c^{2})",Q2_23_D,Q2_23_U),"p");
		
		TGraph *p1_23_mc = new TGraphErrors(N_23,xbj_23,XS_MC_23);
		p1_23_mc-> SetLineWidth(2);
		p1_23_mc-> SetLineStyle(2);
		//p1_23_mc-> SetLineColor(3);
		p1_23_mc-> SetLineColor(1);
		p1_23_mc-> GetXaxis()->SetTitle("x_{bj}");
		p1_23_mc-> GetYaxis()->SetTitle("#sigma");
		p1_23_mc->Draw("L");
	}

	TGraphErrors *pl_QE = new TGraphErrors(N_QE,xbj_QE,XS_EX_QE,xbj_err,XS_EX_Err_QE);
	pl_QE-> SetMarkerSize(1.0);
	pl_QE-> SetMarkerStyle(26);
	pl_QE-> SetMarkerColor(4);
	pl_QE-> GetXaxis()->SetTitle("x_{bj}");
	pl_QE-> GetYaxis()->SetTitle("#sigma");
	pl_QE->Draw("P");

	TGraph *p1_QE_mc = new TGraphErrors(N_QE,xbj_QE,XS_MC_QE);
	p1_QE_mc-> SetLineWidth(2);
	p1_QE_mc-> SetLineStyle(2);
	//p1_QE_mc-> SetLineColor(4);
	p1_QE_mc-> SetLineColor(1);
	p1_QE_mc-> GetXaxis()->SetTitle("x_{bj}");
	p1_QE_mc-> GetYaxis()->SetTitle("#sigma");
	p1_QE_mc->Draw("L");

	TGraphErrors *pl_25 = new TGraphErrors(N_25,xbj_25,XS_EX_25,xbj_err,XS_EX_Err_25);
	pl_25-> SetMarkerSize(1.0);
	pl_25-> SetMarkerStyle(26);
	pl_25-> SetMarkerColor(4);
	pl_25-> GetXaxis()->SetTitle("x_{bj}");
	pl_25-> GetYaxis()->SetTitle("#sigma");
	pl_25->Draw("P");
	l1->AddEntry(pl_25, Form("25^{o}: %4.3f<Q^{2}<%4.3f (GeV/c^{2})",Q2_25_D,Q2_25_U),"p");

	TGraph *p1_25_mc = new TGraphErrors(N_25,xbj_25,XS_MC_25);
	p1_25_mc-> SetLineWidth(2);
	p1_25_mc-> SetLineStyle(2);
	//p1_25_mc-> SetLineColor(4);
	p1_25_mc-> SetLineColor(1);
	p1_25_mc-> GetXaxis()->SetTitle("x_{bj}");
	p1_25_mc-> GetYaxis()->SetTitle("#sigma");
	p1_25_mc->Draw("L");
	
	TGraphErrors *pl_28 = new TGraphErrors(N_28,xbj_28,XS_EX_28,xbj_err,XS_EX_Err_28);
	if(Target=="He3" || Target=="C12"){
		pl_28-> SetMarkerSize(1.0);
		pl_28-> SetMarkerStyle(28);
		pl_28-> SetMarkerColor(6);
		pl_28-> GetXaxis()->SetTitle("x_{bj}");
		pl_28-> GetYaxis()->SetTitle("#sigma");
		pl_28->Draw("P");
		l1->AddEntry(pl_28, Form("28^{o}: %4.3f<Q^{2}<%4.3f (GeV/c^{2})",Q2_28_D,Q2_28_U),"p");

		TGraph *p1_28_mc = new TGraphErrors(N_28,xbj_28,XS_MC_28);
		p1_28_mc-> SetLineWidth(2);
		p1_28_mc-> SetLineStyle(2);
		//p1_28_mc-> SetLineColor(6);
		p1_28_mc-> SetLineColor(1);
		p1_28_mc-> GetXaxis()->SetTitle("x_{bj}");
		p1_28_mc-> GetYaxis()->SetTitle("#sigma");
		p1_28_mc->Draw("L");
	}

	//l1->AddEntry(p1_21_mc, "Theory","l");
	l1->AddEntry(p1_21_mc, "Model","l");
	l1->Draw();
	c1->Print(Form("%s_XS_All_xbj.pdf",Target.Data()));
	c1->Print(Form("%s_XS_All_xbj.png",Target.Data()));
	/*}}}*/

	/*Ep{{{*/
	const double Ep_Min = 2.30;
	const double Ep_Max = 3.30;

	TCanvas *c2 = new TCanvas("c2","c2",1200,800);
	TH2F* ep = new TH2F("ep","",1000,E0-Ep_Max,E0-Ep_Min,1000,Min/2.1,Max*2.1);
	ep->SetStats(kFALSE);
	ep->SetXTitle("#nu");
	ep->GetXaxis()->CenterTitle(1);
	ep->GetXaxis()->SetTitleFont(32);
	ep->GetXaxis()->SetTitleSize(0.06);
	ep->SetYTitle("#frac{d#sigma}{dE'd#Omega} (nb/MeV/sr)");
	ep->GetYaxis()->CenterTitle(1);
	ep->GetYaxis()->SetTitleFont(32);
	ep->GetYaxis()->SetTitleSize(0.04);
	ep->Draw(); 
	//gPad->SetLogy(1);
	gPad->SetLogy(1);

	TLegend *l2 = new TLegend(0.60,0.19,0.75, 0.54,Form("%s Target",Target.Data()));
	l2->SetBorderSize(0);
	l2->SetTextSize(0.03);
	l2->SetTextFont(32);

	TGraphErrors *p2_21 = new TGraphErrors(N_21,Nu_21,XS_EX_21,xbj_err,XS_EX_Err_21);
	p2_21-> SetMarkerSize(1.0);
	p2_21-> SetMarkerStyle(24);
	p2_21-> SetMarkerColor(2);
	p2_21-> GetXaxis()->SetTitle("#nu");
	p2_21-> GetYaxis()->SetTitle("#sigma");
	p2_21->Draw("P");
	l2->AddEntry(p2_21, Form("21^{o}: %4.3f<Q^{2}<%4.3f (GeV/c^{2})",Q2_21_D,Q2_21_U),"p");

	TGraph *p2_21_mc = new TGraphErrors(N_21,Nu_21,XS_MC_21);
	p2_21_mc-> SetLineWidth(2);
	p2_21_mc-> SetLineStyle(2);
	//p2_21_mc-> SetLineColor(2);
	p2_21_mc-> SetLineColor(1);
	p2_21_mc-> GetXaxis()->SetTitle("#nu");
	p2_21_mc-> GetYaxis()->SetTitle("#sigma");
	p2_21_mc->Draw("L");
	
	TGraphErrors *p2_23 = new TGraphErrors(N_23,Nu_23,XS_EX_23,xbj_err,XS_EX_Err_23);
	if(!(Target=="H2")){
		p2_23-> SetMarkerSize(1.0);
		p2_23-> SetMarkerStyle(25);
		p2_23-> SetMarkerColor(3);
		p2_23-> GetXaxis()->SetTitle("#nu");
		p2_23-> GetYaxis()->SetTitle("#sigma");
		p2_23->Draw("P");
		l2->AddEntry(p2_23, Form("23^{o}: %4.3f<Q^{2}<%4.3f (GeV/c^{2})",Q2_23_D,Q2_23_U),"p");
	
		TGraph *p2_23_mc = new TGraphErrors(N_23,Nu_23,XS_MC_23);
		p2_23_mc-> SetLineWidth(2);
		p2_23_mc-> SetLineStyle(2);
		//p2_23_mc-> SetLineColor(3);
		p2_23_mc-> SetLineColor(1);
		p2_23_mc-> GetXaxis()->SetTitle("#nu");
		p2_23_mc-> GetYaxis()->SetTitle("#sigma");
		p2_23_mc->Draw("L");

}

	TGraphErrors *p2_QE = new TGraphErrors(N_QE,Nu_QE,XS_EX_QE,xbj_err,XS_EX_Err_QE);
	p2_QE-> SetMarkerSize(1.0);
	p2_QE-> SetMarkerStyle(26);
	p2_QE-> SetMarkerColor(4);
	p2_QE-> GetXaxis()->SetTitle("#nu");
	p2_QE-> GetYaxis()->SetTitle("#sigma");
	p2_QE->Draw("P");
	TGraphErrors *p2_25 = new TGraphErrors(N_25,Nu_25,XS_EX_25,xbj_err,XS_EX_Err_25);
	p2_25-> SetMarkerSize(1.0);
	p2_25-> SetMarkerStyle(26);
	p2_25-> SetMarkerColor(4);
	p2_25-> GetXaxis()->SetTitle("#nu}");
	p2_25-> GetYaxis()->SetTitle("#sigma");
	p2_25->Draw("P");
	l2->AddEntry(p2_25, Form("25^{o}: %4.3f<Q^{2}<%4.3f (GeV/c^{2})",Q2_25_D,Q2_25_U),"p");

	TGraph *p2_QE_mc = new TGraphErrors(N_QE,Nu_QE,XS_MC_QE);
	p2_QE_mc-> SetLineWidth(2);
	p2_QE_mc-> SetLineStyle(2);
	//p2_QE_mc-> SetLineColor(4);
	p2_QE_mc-> SetLineColor(1);
	p2_QE_mc-> GetXaxis()->SetTitle("#nu");
	p2_QE_mc-> GetYaxis()->SetTitle("#sigma");
	p2_QE_mc->Draw("L");

	TGraph *p2_25_mc = new TGraphErrors(N_25,Nu_25,XS_MC_25);
	p2_25_mc-> SetLineWidth(2);
	p2_25_mc-> SetLineStyle(2);
	p2_25_mc-> SetLineColor(1);
	//p2_25_mc-> SetLineColor(4);
	p2_25_mc-> GetXaxis()->SetTitle("#nu");
	p2_25_mc-> GetYaxis()->SetTitle("#sigma");
	p2_25_mc->Draw("L");

	TGraphErrors *p2_28 = new TGraphErrors(N_28,Nu_28,XS_EX_28,xbj_err,XS_EX_Err_28);
	if(Target=="He3" || Target=="C12"){
		p2_28-> SetMarkerSize(1.0);
		p2_28-> SetMarkerStyle(28);
		p2_28-> SetMarkerColor(6);
		p2_28-> GetXaxis()->SetTitle("#nu");
		p2_28-> GetYaxis()->SetTitle("#sigma");
		p2_28->Draw("P");
		l2->AddEntry(p2_28, Form("28^{o}: %4.3f<Q^{2}<%4.3f (GeV/c^{2})",Q2_28_D,Q2_28_U),"p");

		TGraph *p2_28_mc = new TGraphErrors(N_28,Nu_28,XS_MC_28);
		p2_28_mc-> SetLineWidth(2);
		p2_28_mc-> SetLineStyle(2);
		//p2_28_mc-> SetLineColor(6);
		p2_28_mc-> SetLineColor(1);
		p2_28_mc-> GetXaxis()->SetTitle("#nu");
		p2_28_mc-> GetYaxis()->SetTitle("#sigma");
		p2_28_mc->Draw("L");
	}

    //l2->AddEntry(p2_21_mc,"Theory","l");
    l2->AddEntry(p2_21_mc,"Model","l");

    l2->Draw();
    c2->Print(Form("%s_XS_All.png",Target.Data()));
	c2->Print(Form("%s_XS_All.pdf",Target.Data()));
 	/*}}}*/
	/*}}}*/

	outfile.close();

	return 0;
}
Ejemplo n.º 6
0
	void OnCombatStop(Unit* pTarget)
	{
		Merge();

        ParentClass::OnCombatStop( pTarget );
	}
Ejemplo n.º 7
0
	explicit SegmentTreeBase(const R& range, const T& defaultValue = T(), const Merge& merge = Merge()) :
			SegmentTreeBase(
					static_cast<std::size_t>(std::distance(std::begin(range), std::end(range))),
					defaultValue,
					merge
			) {
		std::copy(std::begin(range), std::end(range), values.begin() + shift);
		for (std::size_t index: downrange(shift, static_cast<std::size_t>(1))) {
			recalculate(index);
		}
	}
Ejemplo n.º 8
0
void KwayMergeSort::Sort() {
	DivideAndSort();
	Merge();
}
Ejemplo n.º 9
0
const TFile& TFileCollection::AddFile(const Stroka& name, const Stroka& alias1, const Stroka& alias2) {
    return Merge(TFile(name).AddAlias(alias1).AddAlias(alias2));
}
Ejemplo n.º 10
0
static char *
Merge(PyObject *args)
{
	PyObject *tmp = NULL;
	char *argvStore[ARGSZ];
	char **argv = NULL;
	int fvStore[ARGSZ];
	int *fv = NULL;
	int argc = 0, fvc = 0, i;
	char *res = NULL;

	if (!(tmp = PyList_New(0)))
	    return NULL;

	argv = argvStore;
	fv = fvStore;

	if (args == NULL)
		argc = 0;

	else if (!PyTuple_Check(args)) {
		argc = 1;
		fv[0] = 0;
		if (!(argv[0] = AsString(args, tmp)))
			goto finally;
	}
	else {
		argc = PyTuple_Size(args);

		if (argc > ARGSZ) {
			argv = (char **)ckalloc(argc * sizeof(char *));
			fv = (int *)ckalloc(argc * sizeof(int));
			if (argv == NULL || fv == NULL) {
				PyErr_NoMemory();
				goto finally;
			}
		}

		for (i = 0; i < argc; i++) {
			PyObject *v = PyTuple_GetItem(args, i);
			if (PyTuple_Check(v)) {
				fv[i] = 1;
				if (!(argv[i] = Merge(v)))
					goto finally;
				fvc++;
			}
			else if (v == Py_None) {
				argc = i;
				break;
			}
			else {
				fv[i] = 0;
				if (!(argv[i] = AsString(v, tmp)))
					goto finally;
				fvc++;
			}
		}
	}
	res = Tcl_Merge(argc, argv);
	if (res == NULL)
		PyErr_SetString(Tkinter_TclError, "merge failed");

  finally:
	for (i = 0; i < fvc; i++)
		if (fv[i]) {
			ckfree(argv[i]);
		}
	if (argv != argvStore)
		ckfree(FREECAST argv);
	if (fv != fvStore)
		ckfree(FREECAST fv);

	Py_DECREF(tmp);
	return res;
}
Ejemplo n.º 11
0
static PyObject *
Tkapp_Call(PyObject *self, PyObject *args)
{
	/* This is copied from Merge() */
	PyObject *tmp = NULL;
	char *argvStore[ARGSZ];
	char **argv = NULL;
	int fvStore[ARGSZ];
	int *fv = NULL;
	int argc = 0, fvc = 0, i;
	PyObject *res = NULL; /* except this has a different type */
	Tcl_CmdInfo info; /* and this is added */
	Tcl_Interp *interp = Tkapp_Interp(self); /* and this too */

	if (!(tmp = PyList_New(0)))
	    return NULL;

	argv = argvStore;
	fv = fvStore;

	if (args == NULL)
		argc = 0;

	else if (!PyTuple_Check(args)) {
		argc = 1;
		fv[0] = 0;
		if (!(argv[0] = AsString(args, tmp)))
			goto finally;
	}
	else {
		argc = PyTuple_Size(args);

		if (argc > ARGSZ) {
			argv = (char **)ckalloc(argc * sizeof(char *));
			fv = (int *)ckalloc(argc * sizeof(int));
			if (argv == NULL || fv == NULL) {
				PyErr_NoMemory();
				goto finally;
			}
		}

		for (i = 0; i < argc; i++) {
			PyObject *v = PyTuple_GetItem(args, i);
			if (PyTuple_Check(v)) {
				fv[i] = 1;
				if (!(argv[i] = Merge(v)))
					goto finally;
				fvc++;
			}
			else if (v == Py_None) {
				argc = i;
				break;
			}
			else {
				fv[i] = 0;
				if (!(argv[i] = AsString(v, tmp)))
					goto finally;
				fvc++;
			}
		}
	}
	/* End code copied from Merge() */

	/* All this to avoid a call to Tcl_Merge() and the corresponding call
	   to Tcl_SplitList() inside Tcl_Eval()...  It can save a bundle! */
	if (Py_VerboseFlag >= 2) {
		for (i = 0; i < argc; i++)
			PySys_WriteStderr("%s ", argv[i]);
	}
	ENTER_TCL
	info.proc = NULL;
	if (argc < 1 ||
	    !Tcl_GetCommandInfo(interp, argv[0], &info) ||
	    info.proc == NULL)
	{
		char *cmd;
		cmd = Tcl_Merge(argc, argv);
		i = Tcl_Eval(interp, cmd);
		ckfree(cmd);
	}
	else {
		Tcl_ResetResult(interp);
		i = (*info.proc)(info.clientData, interp, argc, argv);
	}
	ENTER_OVERLAP
	if (info.proc == NULL && Py_VerboseFlag >= 2)
		PySys_WriteStderr("... use TclEval ");
	if (i == TCL_ERROR) {
		if (Py_VerboseFlag >= 2)
			PySys_WriteStderr("... error: '%s'\n",
				Tcl_GetStringResult(interp));
		Tkinter_Error(self);
	}
	else {
		if (Py_VerboseFlag >= 2)
			PySys_WriteStderr("-> '%s'\n", Tcl_GetStringResult(interp));
		res = PyString_FromString(Tcl_GetStringResult(interp));
	}
	LEAVE_OVERLAP_TCL

	/* Copied from Merge() again */
  finally:
	for (i = 0; i < fvc; i++)
		if (fv[i]) {
			ckfree(argv[i]);
		}
	if (argv != argvStore)
		ckfree(FREECAST argv);
	if (fv != fvStore)
		ckfree(FREECAST fv);

	Py_DECREF(tmp);
	return res;
}
Ejemplo n.º 12
0
Word *SortWords(Word *Before,Word *After,Word Total)
{
	Word ChunkSize;		/* Number of elements to sort */
	Word LoopCount;		/* Number of times loop has executed */
    
	if (Total<2) {			/* Already sorted? */
		return Before;		/* Exit now */
	}
	ChunkSize = 1;		/* Size of each list (Start with 1) */
	LoopCount = 1;		/* Number of times executed */
		
	for (;;) {
		Word *List1Ptr;		/* First list pointer */
		Word *List2Ptr;		/* Second list pointer */
		Word *DestPtr;		/* Dest buffer pointer */
		{
		Word ChunkCount;	/* Number of large chunks to merge */
		ChunkCount = Total>>LoopCount;	/* Number of chunks */
				
		List1Ptr = Before;	/* First list */
		List2Ptr = Before + (ChunkCount <<  (LoopCount-1));	/* Second list */
		DestPtr = After;
		
		/* Merge sort the large blocks */
		
		if (ChunkCount) {		/* Any large blocks? */
			do {
				Merge(List1Ptr,ChunkSize,List2Ptr,ChunkSize,DestPtr);
				List1Ptr+=ChunkSize;	/* Inc the pointers */
				List2Ptr+=ChunkSize;
				DestPtr+=ChunkSize<<1;
			} while (--ChunkCount);	/* Any more? */
		}
		}
		
		/* Copy or merge the remaining chunk fragment */
		
		{
		Word Remainder;
		Remainder = Total&((ChunkSize<<1)-1);
		if (Remainder) {
			if (Remainder > ChunkSize) {	
				Merge(List2Ptr,ChunkSize,List2Ptr+ChunkSize,Remainder - ChunkSize,DestPtr);
			} else  {	/* Copy the rest then... */
				do {
					*DestPtr++ = *List2Ptr++;
				} while (--Remainder);
			}
		}
		}
		
		/* Am I done yet? */

		ChunkSize <<= 1;		/* Next block size */
		if (ChunkSize >= Total) {	/* All done? */
			return After;		/* Exit */
		}
		++LoopCount;		/* Next loop count */
		{
		Word *Temp;
		Temp = Before;		/* Swap the pointers to the buffers */
		Before = After;
		After = Temp;
		}
	}
}
Ejemplo n.º 13
0
static HashTable* Overlay(Pool *p, const HashTable *overlay, const HashTable *base)
{
    return Merge(p, overlay, base, NULL, NULL);
}
Ejemplo n.º 14
0
void BoundingBox::Merge(const Frustum& frustum)
{
    Merge(frustum.vertices_, NUM_FRUSTUM_VERTICES);
}
Ejemplo n.º 15
0
void GSRenderer::VSync(int field)
{
	GSPerfMonAutoTimer pmat(&m_perfmon);

	m_perfmon.Put(GSPerfMon::Frame);

	Flush();

	if(!m_dev->IsLost(true))
	{
		if(!Merge(field ? 1 : 0))
		{
			return;
		}
	}
	else
	{
		ResetDevice();
	}

	m_dev->AgePool();

	// osd

	if((m_perfmon.GetFrame() & 0x1f) == 0)
	{
		m_perfmon.Update();

		double fps = 1000.0f / m_perfmon.Get(GSPerfMon::Frame);

		string s;

#ifdef GSTITLEINFO_API_FORCE_VERBOSE
		if(1)//force verbose reply
#else
		if(m_wnd->IsManaged())
#endif
		{
			//GSdx owns the window's title, be verbose.

			string s2 = m_regs->SMODE2.INT ? (string("Interlaced ") + (m_regs->SMODE2.FFMD ? "(frame)" : "(field)")) : "Progressive";

			s = format(
				"%lld | %d x %d | %.2f fps (%d%%) | %s - %s | %s | %d S/%d P/%d D | %d%% CPU | %.2f | %.2f",
				m_perfmon.GetFrame(), GetInternalResolution().x, GetInternalResolution().y, fps, (int)(100.0 * fps / GetTvRefreshRate()),
				s2.c_str(),
				theApp.m_gs_interlace[m_interlace].name.c_str(),
				theApp.m_gs_aspectratio[m_aspectratio].name.c_str(),
				(int)m_perfmon.Get(GSPerfMon::SyncPoint),
				(int)m_perfmon.Get(GSPerfMon::Prim),
				(int)m_perfmon.Get(GSPerfMon::Draw),
				m_perfmon.CPU(),
				m_perfmon.Get(GSPerfMon::Swizzle) / 1024,
				m_perfmon.Get(GSPerfMon::Unswizzle) / 1024
			);

			double fillrate = m_perfmon.Get(GSPerfMon::Fillrate);

			if(fillrate > 0)
			{
				s += format(" | %.2f mpps", fps * fillrate / (1024 * 1024));

				int sum = 0;

				for(int i = 0; i < 16; i++)
				{
					sum += m_perfmon.CPU(GSPerfMon::WorkerDraw0 + i);
				}

				s += format(" | %d%% CPU", sum);
			}
		}
		else
		{
			// Satisfy PCSX2's request for title info: minimal verbosity due to more external title text

			s = format("%dx%d | %s", GetInternalResolution().x, GetInternalResolution().y, theApp.m_gs_interlace[m_interlace].name.c_str());
		}

		if(m_capture.IsCapturing())
		{
			s += " | Recording...";
		}

		if(m_wnd->IsManaged())
		{
			m_wnd->SetWindowText(s.c_str());
		}
		else
		{
			// note: do not use TryEnterCriticalSection.  It is unnecessary code complication in
			// an area that absolutely does not matter (even if it were 100 times slower, it wouldn't
			// be noticeable).  Besides, these locks are extremely short -- overhead of conditional
			// is way more expensive than just waiting for the CriticalSection in 1 of 10,000,000 tries. --air

			std::lock_guard<std::mutex> lock(m_pGSsetTitle_Crit);

			strncpy(m_GStitleInfoBuffer, s.c_str(), countof(m_GStitleInfoBuffer) - 1);

			m_GStitleInfoBuffer[sizeof(m_GStitleInfoBuffer) - 1] = 0; // make sure null terminated even if text overflows
		}
	}
	else
	{
		// [TODO]
		// We don't have window title rights, or the window has no title,
		// so let's use actual OSD!
	}

	if(m_frameskip)
	{
		return;
	}

	// present

	m_dev->Present(m_wnd->GetClientRect().fit(m_aspectratio), m_shader);

	// snapshot

	if(!m_snapshot.empty())
	{
		bool shift = false;

		#ifdef _WIN32

		shift = !!(::GetAsyncKeyState(VK_SHIFT) & 0x8000);

		#else

		shift = m_shift_key;

		#endif

		if(!m_dump && shift)
		{
			GSFreezeData fd;
			fd.size = 0;
			fd.data = NULL;
			Freeze(&fd, true);
			fd.data = new uint8[fd.size];
			Freeze(&fd, false);

			m_dump.Open(m_snapshot, m_crc, fd, m_regs);

			delete [] fd.data;
		}

		if(GSTexture* t = m_dev->GetCurrent())
		{
			t->Save(m_snapshot + ".bmp");
		}

		m_snapshot.clear();
	}
	else
	{
		if(m_dump)
		{
            bool control = false;

            #ifdef _WIN32

            control = !!(::GetAsyncKeyState(VK_CONTROL) & 0x8000);

			#else

			control = m_control_key;

            #endif

	    	m_dump.VSync(field, !control, m_regs);
		}
	}

	// capture

	if(m_capture.IsCapturing())
	{
		if(GSTexture* current = m_dev->GetCurrent())
		{
			GSVector2i size = m_capture.GetSize();

			if(GSTexture* offscreen = m_dev->CopyOffscreen(current, GSVector4(0, 0, 1, 1), size.x, size.y))
			{
				GSTexture::GSMap m;

				if(offscreen->Map(m))
				{
					m_capture.DeliverFrame(m.bits, m.pitch, !m_dev->IsRBSwapped());

					offscreen->Unmap();
				}

				m_dev->Recycle(offscreen);
			}
		}
	}
}
Ejemplo n.º 16
0
inline void
WifiListWidget::MergeList(const WifiConfiguredNetworkInfo *p, unsigned n)
{
  for (unsigned i = 0; i < unsigned(n); ++i)
    Merge(p[i]);
}
/* See header for function doc. */
void ComposeFrame( filter_t *p_filter,
                   picture_t *p_outpic,
                   picture_t *p_inpic_top, picture_t *p_inpic_bottom,
                   compose_chroma_t i_output_chroma, bool swapped_uv_conversion )
{
    assert( p_outpic != NULL );
    assert( p_inpic_top != NULL );
    assert( p_inpic_bottom != NULL );

    /* Valid 4:2:0 chroma handling modes. */
    assert( i_output_chroma == CC_ALTLINE       ||
            i_output_chroma == CC_UPCONVERT     ||
            i_output_chroma == CC_SOURCE_TOP    ||
            i_output_chroma == CC_SOURCE_BOTTOM ||
            i_output_chroma == CC_MERGE );

    const bool b_upconvert_chroma = i_output_chroma == CC_UPCONVERT;

    for( int i_plane = 0 ; i_plane < p_inpic_top->i_planes ; i_plane++ )
    {
        bool b_is_chroma_plane = ( i_plane == U_PLANE || i_plane == V_PLANE );

        int i_out_plane;
        if( b_is_chroma_plane  &&  b_upconvert_chroma  && swapped_uv_conversion )
        {
            if( i_plane == U_PLANE )
                i_out_plane = V_PLANE;
            else /* V_PLANE */
                i_out_plane = U_PLANE;
        }
        else
        {
            i_out_plane = i_plane;
        }

        /* Copy luma or chroma, alternating between input fields. */
        if( !b_is_chroma_plane  ||  i_output_chroma == CC_ALTLINE )
        {
            /* Do an alternating line copy. This is always done for luma,
               and for 4:2:2 chroma. It can be requested for 4:2:0 chroma
               using CC_ALTLINE (see function doc).

               Note that when we get here, the number of lines matches
               in input and output.
            */
            plane_t dst_top;
            plane_t dst_bottom;
            plane_t src_top;
            plane_t src_bottom;
            FieldFromPlane( &dst_top,    &p_outpic->p[i_out_plane],   0 );
            FieldFromPlane( &dst_bottom, &p_outpic->p[i_out_plane],   1 );
            FieldFromPlane( &src_top,    &p_inpic_top->p[i_plane],    0 );
            FieldFromPlane( &src_bottom, &p_inpic_bottom->p[i_plane], 1 );

            /* Copy each field from the corresponding source. */
            plane_CopyPixels( &dst_top,    &src_top    );
            plane_CopyPixels( &dst_bottom, &src_bottom );
        }
        else /* Input 4:2:0, on a chroma plane, and not in altline mode. */
        {
            if( i_output_chroma == CC_UPCONVERT )
            {
                /* Upconverting copy - use all data from both input fields.

                   This produces an output picture with independent chroma
                   for each field. It can be used for general input when
                   the two input frames are different.

                   The output is 4:2:2, but the input is 4:2:0. Thus the output
                   has twice the lines of the input, and each full chroma plane
                   in the input corresponds to a field chroma plane in the
                   output.
                */
                plane_t dst_top;
                plane_t dst_bottom;
                FieldFromPlane( &dst_top,    &p_outpic->p[i_out_plane], 0 );
                FieldFromPlane( &dst_bottom, &p_outpic->p[i_out_plane], 1 );

                /* Copy each field from the corresponding source. */
                plane_CopyPixels( &dst_top,    &p_inpic_top->p[i_plane]    );
                plane_CopyPixels( &dst_bottom, &p_inpic_bottom->p[i_plane] );
            }
            else if( i_output_chroma == CC_SOURCE_TOP )
            {
                /* Copy chroma of input top field. Ignore chroma of input
                   bottom field. Input and output are both 4:2:0, so we just
                   copy the whole plane. */
                plane_CopyPixels( &p_outpic->p[i_out_plane],
                                  &p_inpic_top->p[i_plane] );
            }
            else if( i_output_chroma == CC_SOURCE_BOTTOM )
            {
                /* Copy chroma of input bottom field. Ignore chroma of input
                   top field. Input and output are both 4:2:0, so we just
                   copy the whole plane. */
                plane_CopyPixels( &p_outpic->p[i_out_plane],
                                  &p_inpic_bottom->p[i_plane] );
            }
            else /* i_output_chroma == CC_MERGE */
            {
                /* Average the chroma of the input fields.
                   Input and output are both 4:2:0. */
                uint8_t *p_in_top, *p_in_bottom, *p_out_end, *p_out;
                p_in_top    = p_inpic_top->p[i_plane].p_pixels;
                p_in_bottom = p_inpic_bottom->p[i_plane].p_pixels;
                p_out = p_outpic->p[i_out_plane].p_pixels;
                p_out_end = p_out + p_outpic->p[i_out_plane].i_pitch
                                  * p_outpic->p[i_out_plane].i_visible_lines;

                int w = FFMIN3( p_inpic_top->p[i_plane].i_visible_pitch,
                                p_inpic_bottom->p[i_plane].i_visible_pitch,
                                p_outpic->p[i_plane].i_visible_pitch );

                for( ; p_out < p_out_end ; )
                {
                    Merge( p_out, p_in_top, p_in_bottom, w );
                    p_out       += p_outpic->p[i_out_plane].i_pitch;
                    p_in_top    += p_inpic_top->p[i_plane].i_pitch;
                    p_in_bottom += p_inpic_bottom->p[i_plane].i_pitch;
                }
                EndMerge();
            }
        }
    }
}
Ejemplo n.º 18
0
/* Given:   NumFiles    Number of sorted runs (files) to be merged.
            FileName    The name of the text file to contain the merged data.
            Indirectly this function is also given the sorted runs, which are assumed to be
            files named  ExtSortTemp.0, ExtSortTemp.1, etc.
   Task:    To merge the data from these sorted runs into one combined, sorted file with
            the name given by FileName.
   Return:  Nothing directly, but the file named by FileName is modified (by being sorted).
*/
void HandleMerges(int NumFiles, PathType FileName)
   {
   StringType Extension;
   PathType OutFileName, InFileName1, InFileName2;
   int k, NumPairs, Count;
   bool Odd;

   // Repeatedly merge 2 runs, writing data to a new temp file (but write last one to original file).
   if (NumFiles == 0)   // No data is present, so there is no work to do.
      return;
   else if (NumFiles == 1)
      {
      // Remove original file and rename the temp file using name of the original.
      remove(FileName);
      rename("ExtSortTemp.0", FileName);

      #ifdef DEBUG
         cout << "Renaming ExtSortTemp.0 as " << FileName << endl;
      #endif

      return;   // The sort is finished.
      }
   else if (NumFiles == 2)
      {
      // Merge the 2 sorted temp files into original file.
      Merge("ExtSortTemp.0", "ExtSortTemp.1", FileName);
      remove("ExtSortTemp.0");
      remove("ExtSortTemp.1");
      return;   // The sort is finished.
      }
   else   // We have 3 or more files.
      {
      // Merge temp files, 2 at a time, until only 2 remain, then proceed as in last case.
      while (NumFiles > 2)
         {
         // Merge ExtSortTemp.0 and ExtSortTemp.1 into ExtSortTempA.0,
         // merge ExtSortTemp.2 and ExtSortTemp.3 into ExtSortTempA.1, etc.
         NumPairs = NumFiles / 2;
         for (k = 0, Count = 0; k < NumPairs; k++)
            {
            strcpy(InFileName1 , "ExtSortTemp.");
            _itoa(Count++, Extension, 10);
            strcat(InFileName1, Extension);
            strcpy(InFileName2 , "ExtSortTemp.");
            _itoa(Count++, Extension, 10);
            strcat(InFileName2, Extension);
            strcpy(OutFileName , "ExtSortTempA.");
            _itoa(k, Extension, 10);
            strcat(OutFileName, Extension);
            Merge(InFileName1, InFileName2, OutFileName);
            }
         // If the number of files is odd, just rename the last one.
         if (2 * NumPairs < NumFiles)
            {
            Odd = true;
            strcpy(InFileName1 , "ExtSortTemp.");
            _itoa(Count, Extension, 10);
            strcat(InFileName1, Extension);
            strcpy(OutFileName , "ExtSortTempA.");
            _itoa(NumPairs, Extension, 10);
            strcat(OutFileName, Extension);
            rename(InFileName1, OutFileName);

            #ifdef DEBUG
               cout << "Renaming " << InFileName1 << " as " << OutFileName << endl;
            #endif
            }
         else
            Odd = false;

         // Remove the temp files from before the merge.
         for (k = 0; k < NumFiles; k++)
            {
            strcpy(InFileName1 , "ExtSortTemp.");
            _itoa(k, Extension, 10);
            strcat(InFileName1, Extension);
            remove(InFileName1);
            }

         // Get the new number of sorted files.
         NumFiles = NumPairs;
         if (Odd)
            NumFiles++;

         // If number of ExtSortTempA files is now 2, merge them with output to original file and return.
         if (NumFiles == 2)
            {
            Merge("ExtSortTempA.0", "ExtSortTempA.1", FileName);
            remove("ExtSortTempA.0");
            remove("ExtSortTempA.1");
            return;   // The sort is finished.
            }

         // Otherwise, merge pairs of files as above, but start at the top end so as to 
         // incorporate any small remainder file.  Note that we now merge from the
         // ExtSortTempA files into ExtSortTemp files.
         NumPairs = NumFiles / 2;
         for (k = 0, Count = NumFiles - 1; k < NumPairs; k++)
            {
            strcpy(InFileName1 , "ExtSortTempA.");
            _itoa(Count--, Extension, 10);
            strcat(InFileName1, Extension);
            strcpy(InFileName2 , "ExtSortTempA.");
            _itoa(Count--, Extension, 10);
            strcat(InFileName2, Extension);
            strcpy(OutFileName , "ExtSortTemp.");
            _itoa(k, Extension, 10);
            strcat(OutFileName, Extension);
            Merge(InFileName1, InFileName2, OutFileName);
            }
         // If the number of files is odd, just rename the last one.
         if (2 * NumPairs < NumFiles)
            {
            Odd = true;
            strcpy(InFileName1 , "ExtSortTempA.");
            _itoa(0, Extension, 10);
            strcat(InFileName1, Extension);
            strcpy(OutFileName , "ExtSortTemp.");
            _itoa(NumPairs, Extension, 10);
            strcat(OutFileName, Extension);
            rename(InFileName1, OutFileName);

            #ifdef DEBUG
               cout << "Renaming " << InFileName1 << " as " << OutFileName << endl;
            #endif
            }
         else
            Odd = false;

         // Remove the temp files from before the merge.
         for (k = 0; k < NumFiles; k++)
            {
            strcpy(InFileName1 , "ExtSortTempA.");
            _itoa(k, Extension, 10);
            strcat(InFileName1, Extension);
            remove(InFileName1);
            }

         // Get the new number of sorted files.
         NumFiles = NumPairs;
         if (Odd)
            NumFiles++;

         // If number of ExtSortTemp files is now 2, merge them with output to original file and return.
         if (NumFiles == 2)
            {
            Merge("ExtSortTemp.0", "ExtSortTemp.1", FileName);
            remove("ExtSortTemp.0");
            remove("ExtSortTemp.1");
            return;   // The sort is finished.
            }
         }
      }
   }
Ejemplo n.º 19
0
	explicit SegmentTreeBase(std::size_t n, const T& defaultValue = T(), const Merge& merge = Merge()):
			n(n),
			defaultValue(defaultValue),
			shift(calculateShift(n)),
			values(shift << 1, defaultValue),
			merge(merge) {

	}
Ejemplo n.º 20
0
void cBlockArea::Merge(const cBlockArea & a_Src, const Vector3i & a_RelMinCoords, eMergeStrategy a_Strategy)
{
	Merge(a_Src, a_RelMinCoords.x, a_RelMinCoords.y, a_RelMinCoords.z, a_Strategy);
}
Ejemplo n.º 21
0
    GenExpTLVec*
    CFGEnumeratorSingle::PopulateExpsOfGNCost(const GrammarNode* GN, uint32 Cost, bool Complete)
    {
        auto Retval = new GenExpTLVec();
        GNCostPair Key(GN, Cost);
        Done = false;
        auto Type = GN->GetType();
        PushExpansion(GN->ToString());
        auto const ExpansionTypeID = GetExpansionTypeID();

        auto FPVar = GN->As<GrammarFPVar>();
        // The base cases
        if (FPVar != nullptr) {
            return MakeBaseExpression<GenFPExpression>(Retval, FPVar->GetOp(), Type,
                                                       ExpansionTypeID, Cost, Key, Complete);
        }

        auto LetVar = GN->As<GrammarLetVar>();
        if (LetVar != nullptr) {
            return MakeBaseExpression<GenLetVarExpression>(Retval, LetVar->GetOp(), Type,
                                                           ExpansionTypeID, Cost, Key, Complete);
        }

        auto Const = GN->As<GrammarConst>();
        if (Const != nullptr) {
            return MakeBaseExpression<GenConstExpression>(Retval, Const->GetOp(), Type,
                                                          ExpansionTypeID, Cost, Key, Complete);
        }

        auto Func = GN->As<GrammarFunc>();

        if (Func != nullptr) {
            auto const& Args = Func->GetChildren();
            auto Op = Func->GetOp();
            const uint32 OpCost = Op->GetCost();
            const uint32 Arity = Op->GetArity();

            if (Cost < Arity + OpCost) {
                Retval->Freeze();
                ExpRepository[Key] = Retval;
                PopExpansion();
                return Retval;
            }
            PartitionGenerator* PG;
            if (Op->IsSymmetric() && Args[0] == Args[1]) {
                PG = new SymPartitionGenerator(Cost - OpCost);
            } else {
                PG = new PartitionGenerator(Cost - OpCost, Arity);
            }

            const uint32 NumPartitions = PG->Size();
            for (uint32 i = 0; i < NumPartitions; ++i) {

                auto Feasible = true;
                vector<const GenExpTLVec*> ArgExpVecs(Arity, nullptr);
                auto CurPartition = (*PG)[i];
                vector<GenExpTLVec::ConstIterator> Begins(Arity);
                vector<GenExpTLVec::ConstIterator> Ends(Arity);

                for (uint32 j = 0; j < Arity; ++j) {
                    auto CurVec = GetVecForGNCost(Args[j], CurPartition[j]);
                    if (CurVec == nullptr) {
                        CurVec = PopulateExpsOfGNCost(Args[j], CurPartition[j], false);
                    }
                    if (CurVec->Size() == 0) {
                        Feasible = false;
                        break;
                    } else {
                        ArgExpVecs[j] = CurVec;
                        Begins[j] = CurVec->Begin();
                        Ends[j] = CurVec->End();
                    }
                }

                if (!Feasible) {
                    continue;
                }

                // Iterate over the cross product
                auto CPGen = new CrossProductGenerator(Begins, Ends, GetPoolForSize(Arity));

                for (auto CurArgs = CPGen->GetNext();
                     CurArgs != nullptr;
                     CurArgs = CPGen->GetNext()) {

                    auto CurExp = new (FuncExpPool->malloc())
                        GenFuncExpression(static_cast<const InterpretedFuncOperator*>(Op), CurArgs);

                    auto Status =
                        (Complete ?
                         Solver->ExpressionCallBack(CurExp, Type, ExpansionTypeID, Index) :
                         Solver->SubExpressionCallBack(CurExp, Type, ExpansionTypeID));

                    if ((Status & DELETE_EXPRESSION) == 0) {
                        CPGen->RelinquishOwnerShip();
                        Retval->PushBack(CurExp);
                        NumExpsCached++;
                    } else {
                        FuncExpPool->free(CurExp);
                    }
                    if ((Status & STOP_ENUMERATION) != 0) {
                        Done = true;
                        break;
                    }
                }
                delete CPGen;
                if (Done) {
                    break;
                }
            }
            delete PG;

            Retval->Freeze();
            ExpRepository[Key] = Retval;
            PopExpansion();
            return Retval;
        }

        auto Let = GN->As<GrammarLet>();

        // We handle this in similar spirit as functions
        if (Let != nullptr) {
            auto const& Bindings = Let->GetBindings();
            const uint32 NumBindings = Bindings.size();
            const uint32 Arity = NumBindings + 1;
            auto BoundNode = Let->GetBoundExpression();
            const uint32 NumLetBoundVars = TheGrammar->GetNumLetBoundVars();

            if (Cost < Arity + 1) {
                Retval->Freeze();
                ExpRepository[Key] = Retval;
                PopExpansion();
                return Retval;
            }

            // Making a let binding incurs a cost of 1!
            auto PG = new PartitionGenerator(Cost - 1, Arity);
            const uint32 NumPartitions = PG->Size();
            for (uint32 i = 0; i < NumPartitions; ++i) {
                auto Feasible = true;
                vector<const GenExpTLVec*> ArgExpVecs(Arity, nullptr);
                auto CurPartition = (*PG)[i];
                vector<GenExpTLVec::ConstIterator> Begins(Arity);
                vector<GenExpTLVec::ConstIterator> Ends(Arity);

                uint32 j = 0;
                uint32* Positions = new uint32[NumBindings];

                for (auto it = Bindings.begin(); it != Bindings.end(); ++it) {
                    auto CurVec = GetVecForGNCost(it->second, CurPartition[j]);
                    if (CurVec == nullptr) {
                        CurVec = PopulateExpsOfGNCost(it->second, CurPartition[j], false);
                    }
                    if (CurVec->Size() == 0) {
                        Feasible = false;
                        break;
                    } else {
                        ArgExpVecs[j] = CurVec;
                        Begins[j] = CurVec->Begin();
                        Ends[j] = CurVec->End();
                    }
                    Positions[j] = it->first->GetOp()->GetPosition();
                    ++j;
                }

                if (!Feasible) {
                    delete[] Positions;
                    continue;
                }

                // Finally, the expression set for the bound expression
                auto BoundVec = GetVecForGNCost(BoundNode, CurPartition[j]);
                if (BoundVec == nullptr) {
                    BoundVec = PopulateExpsOfGNCost(BoundNode, CurPartition[j], false);
                }
                if (BoundVec->Size() == 0) {
                    // cross product is empty not feasible
                    delete[] Positions;
                    continue;
                } else {
                    ArgExpVecs[NumBindings] = BoundVec;
                    Begins[NumBindings] = BoundVec->Begin();
                    Ends[NumBindings] = BoundVec->End();
                }


                // Iterate over the cross product of expressions
                // The bindings object will be of size of the NUMBER
                // of let bound vars for the whole grammar
                auto CPGen = new CrossProductGenerator(Begins, Ends,
                                                       GetPoolForSize(Arity));
                GenExpressionBase const** BindVec = nullptr;
                auto BindVecPool = GetPoolForSize(NumLetBoundVars);

                for (auto CurArgs = CPGen->GetNext(); CurArgs != nullptr; CurArgs = CPGen->GetNext()) {
                    // We need to build the binding vector based on the position
                    if (BindVec == nullptr) {
                        BindVec = (GenExpressionBase const**)BindVecPool->malloc();
                        memset(BindVec, 0, sizeof(GenExpressionBase const*) * NumLetBoundVars);
                    }
                    for (uint32 k = 0; k < NumBindings; ++k) {
                        BindVec[Positions[k]] = CurArgs[k];
                    }

                    auto CurExp = new (LetExpPool->malloc())
                        GenLetExpression(BindVec, CurArgs[NumBindings], NumLetBoundVars);
                    auto Status =
                        (Complete ?
                         Solver->ExpressionCallBack(CurExp, Type, ExpansionTypeID, Index) :
                         Solver->SubExpressionCallBack(CurExp, Type, ExpansionTypeID));

                    if ((Status & DELETE_EXPRESSION) == 0) {
                        BindVec = nullptr;
                        Retval->PushBack(CurExp);
                        NumExpsCached++;
                    } else {
                        LetExpPool->free(CurExp);
                    }
                    if ((Status & STOP_ENUMERATION) != 0) {
                        Done = true;
                        break;
                    }
                }

                delete CPGen;
                delete[] Positions;

                if (Done) {
                    break;
                }
            }

            delete PG;

            Retval->Freeze();
            ExpRepository[Key] = Retval;
            PopExpansion();
            return Retval;
        }

        auto NT = GN->As<GrammarNonTerminal>();
        if (NT != nullptr) {
            const vector<GrammarNode*>& Expansions = TheGrammar->GetExpansions(NT);
            for (auto const& Expansion : Expansions) {
                auto CurVec = GetVecForGNCost(Expansion, Cost);
                if (CurVec == nullptr) {
                    CurVec = PopulateExpsOfGNCost(Expansion, Cost, Complete);
                }
                Retval->Merge(*CurVec);
                if (Done) {
                    break;
                }
            }
            Retval->Freeze();
            ExpRepository[Key] = Retval;
            PopExpansion();
            return Retval;
        }

        // Should NEVER get here
        throw InternalError((string)"You probably subclassed GrammarNode and forgot to change " +
                            "CFGEnumerator.cpp.\nAt: " + __FILE__ + ":" + to_string(__LINE__));
    }
Ejemplo n.º 22
0
void OBoundingBox::Init(const OPolyhedron& poly)
{
	m_isInit = false;
	Merge(poly);
}
Ejemplo n.º 23
0
RuntimeVariablesContainer::RuntimeVariablesContainer(
    const gd::VariablesContainer& container) {
  Merge(container);
}
Ejemplo n.º 24
0
void OBoundingBox::Merge(const OVector3* vertices, unsigned count)
{
	while (count--)
		Merge(*vertices++);
}
Ejemplo n.º 25
0
//---------------------------------------------------------------------------
bool File_DcpAm::FileHeader_Begin()
{
    XMLDocument document;
    if (!FileHeader_Begin_XML(document))
       return false;

    std::string NameSpace;
    XMLElement* AssetMap=document.FirstChildElement("AssetMap");
    if (AssetMap==NULL)
    {
        NameSpace="am:";
        AssetMap=document.FirstChildElement((NameSpace+"AssetMap").c_str());
    }
    if (!AssetMap)
    {
        Reject("DcpAm");
        return false;
    }

    const char* Attribute=AssetMap->Attribute(NameSpace.empty()?"xmlns":"xmlns:am");
    if (!Attribute)
    {
        Reject("DcpAm");
        return false;
    }

    if (strcmp(Attribute, "http://www.digicine.com/PROTO-ASDCP-AM-20040311#")
     && strcmp(Attribute, "http://www.smpte-ra.org/schemas/429-9/2007/AM"))
    {
        Reject("DcpAm");
        return false;
    }

    Accept("DcpAm");
    Fill(Stream_General, 0, General_Format, "DCP AM");
    Fill(Stream_General, 0, General_Format_Version, NameSpace=="am:"?"SMPTE":"Interop");
    Config->File_ID_OnlyRoot_Set(false);

    //Parsing main elements
    for (XMLElement* AssetMap_Item=AssetMap->FirstChildElement(); AssetMap_Item; AssetMap_Item=AssetMap_Item->NextSiblingElement())
    {
        //AssetList
        if (!strcmp(AssetMap_Item->Value(), (NameSpace+"AssetList").c_str()))
        {
            for (XMLElement* AssetList_Item=AssetMap_Item->FirstChildElement(); AssetList_Item; AssetList_Item=AssetList_Item->NextSiblingElement())
            {
                //Asset
                if (!strcmp(AssetList_Item->Value(), (NameSpace+"Asset").c_str()))
                {
                    File_DcpPkl::stream Stream;

                    for (XMLElement* Asset_Item=AssetList_Item->FirstChildElement(); Asset_Item; Asset_Item=Asset_Item->NextSiblingElement())
                    {
                        //ChunkList
                        if (!strcmp(Asset_Item->Value(), (NameSpace+"ChunkList").c_str()))
                        {
                            for (XMLElement* ChunkList_Item=Asset_Item->FirstChildElement(); ChunkList_Item; ChunkList_Item=ChunkList_Item->NextSiblingElement())
                            {
                                //Chunk
                                if (!strcmp(ChunkList_Item->Value(), (NameSpace+"Chunk").c_str()))
                                {
                                    File_DcpPkl::stream::chunk Chunk;

                                    for (XMLElement* Chunk_Item=ChunkList_Item->FirstChildElement(); Chunk_Item; Chunk_Item=Chunk_Item->NextSiblingElement())
                                    {
                                        //Path
                                        if (!strcmp(Chunk_Item->Value(), (NameSpace+"Path").c_str()))
                                            Chunk.Path=Chunk_Item->GetText();
                                    }

                                    Stream.ChunkList.push_back(Chunk);
                                }
                            }
                        }

                        //Id
                        if (!strcmp(Asset_Item->Value(), (NameSpace+"Id").c_str()))
                            Stream.Id=Asset_Item->GetText();

                        //PackingList
                        if (!strcmp(Asset_Item->Value(), (NameSpace+"PackingList").c_str()))
                        {
                            PKL_Pos=Streams.size();
                            Stream.StreamKind=(stream_t)(Stream_Max+2); // Means PKL
                        }
                    }

                    Streams.push_back(Stream);
                 }
            }
        }

        //Creator
        if (!strcmp(AssetMap_Item->Value(), (NameSpace+"Creator").c_str()))
            Fill(Stream_General, 0, General_Encoded_Library, AssetMap_Item->GetText());

        //IssueDate
        if (!strcmp(AssetMap_Item->Value(), (NameSpace+"IssueDate").c_str()))
            Fill(Stream_General, 0, General_Encoded_Date, AssetMap_Item->GetText());

        //Issuer
        if (!strcmp(AssetMap_Item->Value(), (NameSpace+"Issuer").c_str()))
            Fill(Stream_General, 0, General_EncodedBy, AssetMap_Item->GetText());
    }
    Element_Offset=File_Size;

    //Merging with PKL
    if (PKL_Pos<Streams.size() && Streams[PKL_Pos].ChunkList.size()==1)
    {
        FileName Directory(File_Name);
        Ztring PKL_FileName; PKL_FileName.From_UTF8(Streams[PKL_Pos].ChunkList[0].Path);
        if (PKL_FileName.find(__T("file://"))==0 && PKL_FileName.find(__T("file:///"))==string::npos)
            PKL_FileName.erase(0, 7); //TODO: better handling of relative and absolute file naes
        MediaInfo_Internal MI;
        MI.Option(__T("File_KeepInfo"), __T("1"));
        Ztring ParseSpeed_Save=MI.Option(__T("ParseSpeed_Get"), __T(""));
        Ztring Demux_Save=MI.Option(__T("Demux_Get"), __T(""));
        MI.Option(__T("ParseSpeed"), __T("0"));
        MI.Option(__T("Demux"), Ztring());
        MI.Option(__T("File_IsReferenced"), __T("1"));
        size_t MiOpenResult=MI.Open(Directory.Path_Get()+PathSeparator+PKL_FileName);
        MI.Option(__T("ParseSpeed"), ParseSpeed_Save); //This is a global value, need to reset it. TODO: local value
        MI.Option(__T("Demux"), Demux_Save); //This is a global value, need to reset it. TODO: local value
        if (MiOpenResult
            && (MI.Get(Stream_General, 0, General_Format)==__T("DCP PKL")
            ||  MI.Get(Stream_General, 0, General_Format)==__T("IMF PKL")))
        {
            MergeFromPkl(((File_DcpPkl*)MI.Info)->Streams);

            for (size_t Pos=0; Pos<MI.Count_Get(Stream_Other); ++Pos)
            {
                Stream_Prepare(Stream_Other);
                Merge(*MI.Info, Stream_Other, Pos, StreamPos_Last);
            }
        }
    }

    //Creating the playlist
    if (!Config->File_IsReferenced_Get())
    {
        ReferenceFiles=new File__ReferenceFilesHelper(this, Config);

        for (File_DcpPkl::streams::iterator Stream=Streams.begin(); Stream!=Streams.end(); ++Stream)
            if (Stream->StreamKind==(stream_t)(Stream_Max+1) && Stream->ChunkList.size()==1) // Means CPL
            {
                sequence* Sequence=new sequence;
                Sequence->FileNames.push_back(Ztring().From_UTF8(Stream->ChunkList[0].Path));

                ReferenceFiles->AddSequence(Sequence);
            }

        ReferenceFiles->FilesForStorage=true;
    }

    //All should be OK...
    return true;
}
Ejemplo n.º 26
0
void OBoundingBox::Merge(const OFrustum& frustum)
{
	Merge(frustum.vertices, ONLY_FRUSTUM_VERTICES_NUM);
}
Ejemplo n.º 27
0
void Sphere::Define(const Polyhedron& poly)
{
    defined_ = false;
    Merge(poly);
}
Ejemplo n.º 28
0
void getClosest(PointX X[], PointY Y[], PointY Z[], int left, int right, PointX &a, PointX &b, float &d)
{
	/*剩下两个点*/
	if(right -left ==1)
	{
		d = getDis(X[left], X[right]);
		a = X[left];
		b = X[right];
		return;
	}
	/*剩下三个点*/
	if(right - left ==2)
	{
		float d1, d2, d3;
		d1 = getDis(X[left], X[right-1]);
		d2 = getDis(X[left], X[right]);
		d3 = getDis(X[left+1], X[right]);

        if(d1<=d2 && d1<=d3)   
        {   
            a=X[left];  
            b=X[right -1];  
            d=d1;  
            return;  
        }   
  
        if(d2<=d3)  
        {   
            a=X[left];  
            b=X[right];  
            d=d2;  
        }   
        else {   
            a=X[left+1];   
            b=X[right];   
            d=d3;   
        } 
			
		return;
	}

	int center = (left + right)/2;

	int k = left;
	int g= center +1;
	/*将已经按Y排序的点,根据中线,分别放入中线左边和右边*/
	for(int i = left; i <=right; i++)
	{
		if(Y[i].xID <= center) 
			Z[k++] = Y[i];
		else
			Z[g++] = Y[i];
	}

	PointX atmp, btmp;
	float dtmp;

	getClosest(X, Z, Y, left, center, a, b, d);
	getClosest(X, Z, Y, center+1, right, atmp, btmp, dtmp);

	if(dtmp< d)
	{
		a = atmp;
		b = btmp;
		d = dtmp;
	}

	Merge(Z, Y, left, center+1, right);

	int f = left;
	/*距离中心线距离在d内的点放入Z中,并且这些点是按照y坐标从小到大排序的 */
	for(int i =left; i<=right; i++)
	{
		if(ABS(X[center].x - Y[i].x) <d)
			Z[f++] = Y[i];
	}

	/*搜索刚刚加入strip中的点, 如果y之间的距离大于d,就开始搜索*/
	for(int i=left; i<f; i++)
		for(int j = i+1; j< f && (Y[j].y-Y[i].y) < d; j++)
		{
			dtmp =getDis(Y[i], Y[j]);
			if(dtmp <d)
			{
				d = dtmp;
				a = X[Y[i].xID];
				b = X[Y[j].xID];
			}
		}
}
Ejemplo n.º 29
0
void Sphere::Merge(const Frustum& frustum)
{
    const Vector3* vertices = frustum.vertices_;
    Merge(vertices, NUM_FRUSTUM_VERTICES);
}
Ejemplo n.º 30
0
//-------------------------------------------------------------------------
CSeqMasker::TMaskList *
CSeqMasker::DoMask( 
    const CSeqVector& data, TSeqPos begin, TSeqPos stop ) const
{
    ustat->total_ = 0;
    auto_ptr<TMaskList> mask(new TMaskList);

    if( window_size > data.size() )
    {
        ERR_POST( Warning 
                  << "length of data is shorter than the window size" );
    }

    Uint4 cutoff_score = ustat->get_threshold();
    Uint4 textend = ustat->get_textend();
    Uint1 nbits = discontig ? CSeqMaskerUtil::BitCount( pattern ) : 0;
    Uint4 unit_size = ustat->UnitSize() + nbits;
    auto_ptr<CSeqMaskerWindow> window_ptr
        (discontig ? new CSeqMaskerWindowPattern( data, unit_size, 
                                                  window_size, window_step, 
                                                  pattern, unit_step )
         : new CSeqMaskerWindow( data, unit_size, 
                                 window_size, window_step, 
                                 unit_step, begin, stop ));
    CSeqMaskerWindow & window = *window_ptr;
    score->SetWindow( window );

    if( trigger == eTrigger_Min ) trigger_score->SetWindow( window );

    Uint4 start = 0, end = 0, cend = 0;
    Uint4 limit = textend;
    const CSeqMaskerIstat::optimization_data * od 
        = ustat->get_optimization_data();

    CSeqMaskerCacheBoost booster( window, od );

    while( window )
    {
        Uint4 ts = (*trigger_score)();
        Uint4 s = (*score)();
        Uint4 adv = window_step;

        if( s < limit )
        {
            if( end > start )
            {
                if( window.Start() > cend )
                {
                    mask->push_back( TMaskedInterval( start, end ) );
                    start = end = cend = 0;
                }
            }

            if( od != 0 && od->cba_ != 0 )
            {
                adv = window.Start();

                if( !booster.Check() )
                    break;

                adv = window_step*( 1 + window.Start() - adv );
            }
        }
        else if( ts < cutoff_score )
        {
            if( end  > start )
            {
                if( window.Start() > cend + 1 )
                {
                    mask->push_back( TMaskedInterval( start, end ) );
                    start = end = cend = 0;
                }
                else cend = window.End();
            }
        }
        else
        {
            if( end > start )
            {
                if( window.Start() > cend + 1 )
                {
                    mask->push_back( TMaskedInterval( start, end ) );
                    start = window.Start();
                }
            }
            else start = window.Start();
    
            cend = end = window.End();
        }

        
        if( adv == window_step )
            ++window;

        score->PostAdvance( adv );
    }

    if( end > start ) 
        mask->push_back( TMaskedInterval( start, end ) );

    window_ptr.reset();

    if( merge_pass )
    {
        Uint1 nbits = discontig ? CSeqMaskerUtil::BitCount( pattern ) : 0;
        Uint4 unit_size = ustat->UnitSize() + nbits;

        if( mask->size() < 2 ) return mask.release();

        TMList masked, unmasked;
        TMaskList::iterator jtmp = mask->end();

        {{
             for( TMaskList::iterator i = mask->begin(), j = --jtmp; 
                  i != j; )
             {
                 masked.push_back( mitem( i->first, i->second, unit_size, 
                                          data, *this ) );
                 Uint4 nstart = (i++)->second - unit_size + 2;
                 unmasked.push_back( mitem( nstart, i->first + unit_size - 2, 
                                            unit_size, data, *this ) );
             }

             masked.push_back( mitem( (mask->rbegin())->first,
                                      (mask->rbegin())->second, 
                                      unit_size, data, *this ) );
         }}

        Int4 count = 0;
        TMList::iterator ii = masked.begin();
        TMList::iterator j = unmasked.begin();
        TMList::iterator k = ii, l = ii;
        --k; ++l;

        for( ; ii != masked.end(); k = l = ii, --k, ++l )
        {
            Uint4 ldist = (ii != masked.begin())
                ? ii->start - k->end - 1 : 0;
            TMList::iterator tmpend = masked.end();
            --tmpend;
            Uint4 rdist = (ii != tmpend)
                ? l->start - ii->end - 1 : 0;
            double lavg = 0.0, ravg = 0.0;
            bool can_go_left =  count && ldist
                && ldist <= mean_merge_cutoff_dist;
            bool can_go_right =  rdist
                && rdist <= mean_merge_cutoff_dist;

            if( can_go_left )
            {
                TMList::iterator tmp = j; --tmp;
                lavg = MergeAvg( k, tmp, unit_size );
                can_go_left = can_go_left && (lavg >= merge_cutoff_score);
            }

            if( can_go_right )
            {
                ravg = MergeAvg( ii, j, unit_size );
                can_go_right = can_go_right && (ravg >= merge_cutoff_score);
            }

            if( can_go_right )
            {
                if( can_go_left )
                {
                    if( ravg >= lavg )
                    {
                        ++count;
                        ++ii;
                        ++j;
                    }
                    else // count must be greater than 0.
                    {
                        --count;
                        k->avg = MergeAvg( k, --j, unit_size );
                        _TRACE( "Merging " 
                                << k->start << " - " << k->end
                                << " and " 
                                << ii->start << " - " << ii->end );
                        Merge( masked, k, unmasked, j );

                        if( count )
                        {
                            ii = --k;
                            --j;
                            --count;
                        }
                        else ii = k;
                    }
                }
                else
                {
                    ++count;
                    ++ii;
                    ++j;
                }
            }
            else if( can_go_left )
            {
                --count;
                k->avg = MergeAvg( k, --j, unit_size );
                _TRACE( "Merging " 
                        << k->start << " - " << k->end
                        << " and " 
                        << ii->start << " - " << ii->end );
                Merge( masked, k, unmasked, j );

                if( count )
                {
                    ii = --k;
                    --j;
                    --count;
                }
                else ii = k;
            }
            else
            {
                ++ii;
                ++j;
                count = 0;
            }
        }

        for( ii = masked.begin(), j = unmasked.begin(), k = ii++; 
             ii != masked.end(); (k = ii++), j++ )
        {
            if( k->end + abs_merge_cutoff_dist >= ii->start )
            {
                _TRACE( "Unconditionally merging " 
                        << k->start << " - " << k->end
                        << " and " 
                        << ii->start << " - " << ii->end );
                k->avg = MergeAvg( k, j, unit_size );
                Merge( masked, k, unmasked, j );
                ii = k; 

                if( ++ii == masked.end() ) break;
            }
        }

        mask->clear();

        for( TMList::const_iterator iii = masked.begin(); iii != masked.end(); ++iii )
            mask->push_back( TMaskedInterval( iii->start, iii->end ) );
    }

    return mask.release();
}