Esempio n. 1
0
//creates a collage of all the customers who registered the coffee shop
void FaceDetection::CreateCollage(const Customers& customers)
{
	cv::Mat finalImage;
	cv::Mat temp;
	cv::Size *min= FindSmallest(customers);//we creates the collage with the measure, of the smallest image height
	for (int i= 0; i < customers.GetSize(); i++){
		Customer *curCust= customers.GetCustomerAt(i);
		std::string custName= curCust->getName();
		std::string imagePath= "faces/" + custName + "/" + custName + ".tiff";
		cv::Mat curImage= cv::imread(imagePath);
		if (0 == i){//the first image added to the collage
			finalImage= curImage;
			cv::resize(finalImage, finalImage, *min);
		}
		else {//one or more images are already in the collage
			cv::resize(curImage, curImage, *min);
			temp= cv::Mat((*min).height, ((*min).width)*(i+1), CV_8UC3);//creates a blank image with the size of the current collage and the added image
			MergeImage(finalImage, temp, 0);//insert the current collage to the blank image, starting at the leftmostmost area
			MergeImage(curImage, temp, (temp.size().width-curImage.size().width));//added the image to the collage
			finalImage= temp;
		}
	}
	cv::imwrite( "collage.tiff", finalImage);
	delete min;
}
Esempio n. 2
0
//Selection Sort
void Sort(Card deck[], uint size)
{
  for(uint i = 0; i < size; ++i)
  {
    uint s = FindSmallest(deck,i,size);
    SwapCards(deck,i,s);
  }
}
Esempio n. 3
0
File: main.cpp Progetto: Junch/debug
int main()
{
	int arr[] = {4, 2, -5, 3};

	printf("Smallest is %d\n", FindSmallest(arr, _countof(arr)));

	getchar();

	return 0;
}
Esempio n. 4
0
nextstep Step6(gsl_matrix * const M,
               gsl_vector_uint * const rowCov,
               gsl_vector_uint * const colCov)
{
	unsigned int i, j;
	float minval;
	bool hasRowCov;

	minval = FindSmallest(M, rowCov, colCov);
	for(i = 0; i < M->size1; i++)
	{
		hasRowCov = (gsl_vector_uint_get(rowCov, i) == COVERED);
		for(j = 0; j < M->size2; j++)
		{
			if(hasRowCov == true)
				gsl_matrix_set(M, i, j, gsl_matrix_get(M, i, j)+minval);
		
			if(gsl_vector_uint_get(colCov, j) == UNCOVERED)
				gsl_matrix_set(M, i, j, gsl_matrix_get(M, i, j)-minval);
		}
	}

	return STEP4;
}
Esempio n. 5
0
/*
================
sdIK_Walker::Evaluate
================
*/
bool sdIK_Walker::Evaluate( void ) {
	trace_t results;

	// clear joint mods
	ClearJointMods();
	animator->CreateFrame( gameLocal.time, true );

	const renderEntity_t* renderEnt = self->GetRenderEntity();

	idVec3 normal					= -self->GetPhysics()->GetGravityNormal();
	const idVec3& modelOrigin		= renderEnt->origin;
	const idMat3& modelAxis			= renderEnt->axis;
	float modelHeight				= modelOrigin * normal;

	isStable = true;

	// get the joint positions for the feet
	for ( int i = 0; i < legs.Num(); i++ ) {
		leg_t& leg = legs[ i ];

		idVec3 footOrigin;
		animator->GetJointTransform( leg.footJoint, gameLocal.time, footOrigin );
		
		leg.current.jointWorldOrigin = modelOrigin + footOrigin * modelAxis;

		idVec3 start	= leg.current.jointWorldOrigin + ( normal * footUpTrace );
		idVec3 end		= leg.current.jointWorldOrigin - ( normal * footDownTrace );

//		gameLocal.clip.Translation( results, start, end, footModel, modelAxis, CONTENTS_SOLID, self );
		if ( !gameLocal.clip.TracePoint( CLIP_DEBUG_PARMS results, start, end, MASK_VEHICLESOLID | CONTENTS_MONSTER, self ) ) {
			isStable = false;
		}

		leg.current.floorHeight = results.endpos * normal;

		idMat3 newAxes;

		if ( results.fraction != 1.f ) {
			idVec3 normal = results.c.normal * modelAxis.Transpose();

			idVec3 vec3_forward( 1.f, 0.f, 0.f );

			newAxes[ 0 ] = vec3_forward - ( normal * ( vec3_forward * normal ) );
			newAxes[ 0 ].Normalize();

			newAxes[ 2 ] = normal;

			newAxes[ 1 ] = newAxes[ 2 ].Cross( newAxes[ 0 ] );
		} else {
			newAxes.Identity();
		}

		idQuat newQuat;
		newQuat.Slerp( leg.lastAnkleAxes.ToQuat(), newAxes.ToQuat(), 0.1f );
		leg.lastAnkleAxes = newQuat.ToMat3();
		leg.lastAnkleAxes.FixDenormals();

		if ( ik_debug.GetBool() && footModel ) {
			idFixedWinding w;
			for ( int j = 0; j < footModel->GetTraceModel()->numVerts; j++ ) {
				w += footModel->GetTraceModel()->verts[j];
			}
			gameRenderWorld->DebugWinding( colorRed, w, results.endpos, results.endAxis );
		}
	}

	// adjust heights of the ankles
	float smallestShift = idMath::INFINITY;
	float largestAnkleHeight = -idMath::INFINITY;
	for ( int i = 0; i < legs.Num(); i++ ) {
		leg_t& leg = legs[ i ];

		idVec3 ankleOrigin;
		idVec3 footOrigin;

		animator->GetJointTransform( leg.ankleJoint, gameLocal.time, ankleOrigin, leg.current.ankleAxis );
		animator->GetJointTransform( leg.footJoint, gameLocal.time, footOrigin );

		float shift = leg.current.floorHeight - modelHeight + footShift;

		if ( shift < smallestShift ) {
			smallestShift = shift;
		}

		leg.current.jointWorldOrigin = modelOrigin + ankleOrigin * modelAxis;

		float height = leg.current.jointWorldOrigin * normal;

		if ( oldHeightsValid ) {
			float step = height + shift - leg.oldAnkleHeight;
			if ( step < 0 ) {
				shift -= smoothing * step;
			} else {
				shift -= downsmoothing * step;
			}
		}

		float newHeight = height + shift;
		if ( newHeight > largestAnkleHeight ) {
			largestAnkleHeight = newHeight;
		}

		leg.oldAnkleHeight = newHeight;

		leg.current.jointWorldOrigin += shift * normal;
	}

	idVec3 waistOrigin;
	animator->GetJointTransform( waistJoint, gameLocal.time, waistOrigin );
	waistOrigin = modelOrigin + waistOrigin * modelAxis;

	// adjust position of the waist
	waistOffset = ( smallestShift + waistShift ) * normal;

	// if the waist should be at least a certain distance above the floor
	if ( minWaistFloorDist > 0.0f && waistOffset * normal < 0.0f ) {
		idVec3 start	= waistOrigin;
		idVec3 end		= waistOrigin + waistOffset - normal * minWaistFloorDist;
		gameLocal.clip.Translation( CLIP_DEBUG_PARMS results, start, end, footModel, modelAxis, CONTENTS_SOLID, self );
		float height = ( waistOrigin + waistOffset - results.endpos ) * normal;
		if ( height < minWaistFloorDist ) {
			waistOffset += ( minWaistFloorDist - height ) * normal;
		}
	}

	// if the waist should be at least a certain distance above the ankles
	if ( minWaistAnkleDist > 0.0f ) {
		float height = ( waistOrigin + waistOffset ) * normal;
		if ( height - largestAnkleHeight < minWaistAnkleDist ) {
			waistOffset += ( minWaistAnkleDist - ( height - largestAnkleHeight ) ) * normal;
		}
	}

	if ( oldHeightsValid ) {
		// smoothly adjust height of waist
		float newHeight = ( waistOrigin + waistOffset ) * normal;
		float step = newHeight - oldWaistHeight;
		waistOffset -= waistSmoothing * step * normal;
	}

	// save height of waist for smoothing
	oldWaistHeight = ( waistOrigin + waistOffset ) * normal;

	if ( !oldHeightsValid ) {
		oldHeightsValid = true;
		return false;
	}

	// solve IK
	for ( int i = 0; i < legs.Num(); i++ ) {
		leg_t& leg = legs[ i ];

		idVec3 hipOrigin;

		idMat3 axis;
		// get the position of the hip in world space
		animator->GetJointTransform( leg.hipJoint, gameLocal.time, hipOrigin, axis );

		hipOrigin = modelOrigin + waistOffset + hipOrigin * modelAxis;

//		DebugAxis( hipOrigin, axis * modelAxis );

		idVec3 hipDir = leg.hipForward * axis * modelAxis;

		idVec3 midOrigin;

		// get the IK bend direction
		animator->GetJointTransform( leg.midJoint, gameLocal.time, midOrigin, axis );

		midOrigin = modelOrigin + waistOffset + midOrigin * modelAxis;

//		DebugAxis( midOrigin, axis * modelAxis );

		idVec3 midDir		= leg.midForward * axis * modelAxis;
		idVec3 midSideDir	= leg.midSide * axis * modelAxis;

		idVec3 kneeOrigin;

		// get the IK bend direction
		animator->GetJointTransform( leg.kneeJoint, gameLocal.time, kneeOrigin, axis );

		kneeOrigin = modelOrigin + waistOffset + kneeOrigin * modelAxis;
		
//		DebugAxis( kneeOrigin, axis * modelAxis );

		idVec3 kneeDir = leg.kneeForward * axis * modelAxis;

		idVec3 ankleOrigin;
		
		animator->GetJointTransform( leg.ankleJoint, gameLocal.time, ankleOrigin, axis );

		ankleOrigin = modelOrigin + waistOffset + ankleOrigin * modelAxis;




		float len1 = leg.upperLegLength;
		float minLen2 = fabs( leg.midLegLength - leg.lowerLegLength );
		float maxLen2 = leg.midLegLength + leg.lowerLegLength;
		float wantLen = ( hipOrigin - leg.current.jointWorldOrigin ).Length();
		float constrainedMaxLen2, constrainedMinLen2;

		float lenTotal	= 0;
		if( minLen2 < fabs( wantLen - len1 ) ) {
			minLen2 = fabs( wantLen - len1 );
		}
		float minTotal	= FindSmallest( len1, minLen2, maxLen2, constrainedMaxLen2, constrainedMinLen2 );
		float maxTotal	= len1 + maxLen2;

		if ( maxTotal < wantLen ) {
			lenTotal = maxTotal;
		} else if ( minTotal > wantLen ) {
			lenTotal = constrainedMaxLen2;
		} else {
			float scale = compressionInterpolate.GetCurrentValue( MS2SEC( gameLocal.time ) );
			lenTotal = Lerp( minLen2, maxLen2, scale );
		}

		// solve IK and calculate upper knee position
		SolveTwoBones( hipOrigin, leg.current.jointWorldOrigin, midDir, leg.upperLegLength, lenTotal, midOrigin );

		float d1 = ( hipOrigin - midOrigin ).Length();

		idVec3 kneeDirTest = kneeDir;
		kneeDirTest.z += invertedLegDirOffset;
		kneeDirTest.NormalizeFast();

		// solve IK and calculate lower knee position, using -kneeDir, as lower leg is inverted
		SolveTwoBones( midOrigin, leg.current.jointWorldOrigin, -kneeDirTest, leg.midLegLength, leg.lowerLegLength, kneeOrigin );

		float d2 = ( midOrigin - kneeOrigin ).Length();

		if ( ik_debug.GetBool() ) {
			gameRenderWorld->DebugLine( colorCyan, hipOrigin, midOrigin );
			gameRenderWorld->DebugLine( colorRed, midOrigin, kneeOrigin );
			gameRenderWorld->DebugLine( colorBlue, kneeOrigin, leg.current.jointWorldOrigin );

			gameRenderWorld->DebugLine( colorYellow, midOrigin, midOrigin + ( midSideDir * 32 ) );

			gameRenderWorld->DebugLine( colorGreen, hipOrigin, hipOrigin + ( hipDir * 32 ) );
			gameRenderWorld->DebugLine( colorGreen, midOrigin, midOrigin + ( midDir * 32 ) );
			gameRenderWorld->DebugLine( colorGreen, kneeOrigin, kneeOrigin + ( -kneeDirTest * 32 ) );
		}

		// get the axis for the hip joint
		GetBoneAxis( hipOrigin, midOrigin, hipDir, axis );
		leg.current.hipAxis = leg.upperLegToHipJoint * ( axis * modelAxis.Transpose() );

		// get the axis for the knee joint
		GetBoneAxis( midOrigin, kneeOrigin, midSideDir, axis );
		leg.current.midAxis = leg.midToUpperLegJoint * ( axis * modelAxis.Transpose() );

		// get the axis for the knee joint
		GetBoneAxis( kneeOrigin, leg.current.jointWorldOrigin, kneeDir, axis );
		leg.current.kneeAxis = leg.lowerLegToKneeJoint * ( axis * modelAxis.Transpose() );
	}

	// set the joint mods
	animator->SetJointPos( waistJoint, JOINTMOD_WORLD_OVERRIDE, ( waistOrigin + waistOffset - modelOrigin ) * modelAxis.Transpose() );
	for ( int i = 0; i < legs.Num(); i++ ) {
		leg_t& leg = legs[ i ];

		animator->SetJointAxis( leg.hipJoint, JOINTMOD_WORLD_OVERRIDE, leg.current.hipAxis );
		animator->SetJointAxis( leg.midJoint, JOINTMOD_WORLD_OVERRIDE, leg.current.midAxis );
		animator->SetJointAxis( leg.kneeJoint, JOINTMOD_WORLD_OVERRIDE, leg.current.kneeAxis );
		animator->SetJointAxis( leg.ankleJoint, JOINTMOD_WORLD_OVERRIDE, leg.current.ankleAxis * leg.lastAnkleAxes );
	}

	return true;
}