Example #1
0
void initTrial()
{
	// --- initializing all variables
	// pick up[ the current size
	if(training)
		sizeNow = trial[round].getCurrent()["Size"];
	else
		sizeNow = round;

	diameter = depthCyl[sizeNow];
	
	if(training)
		condition = "training";
	else
		condition = "catch";

	// pick up the next size
	// if it's training...
	if(training)
	{
		// if there is another trial after the current...
		if(trial[round].hasNext())
			sizeNext = trial[round].getFullExtractions().at(trialNumber+1)["Size"];
		else 		// else if the next trial is a catch trial
			sizeNext = round;
	} 
	// else if it's catch...
	else
	{
		// if there is another catch trial...
		if(trialNumber+1 < str2num<int>(parameters.find("numCatchTrials")))
			sizeNext = round;
		else if(round<ROUNDS-1) // else if there is another round after the current...
			sizeNext = trial[round+1].getFullExtractions().at(0)["Size"];
		else 		// else the next trial is 99 (exp will be over)
			sizeNext = 99;
	}

	pickedUp=false; // has the obj been lifted?
	noVisibleFingers=0;
	frameN=0;
	handAtStart=true;
	fingersOccluded = 0;

	// turn the screen black
	isStimulusDrawn=false;

	// rebuffer the openGL scene
	drawGLScene();

	// move the platform
	// if it's the first trial of the first round (of the training)...
	if(trialNumber==0 && training && round==0)
	{
		// calibrate the platform
		platformPos = markers[4].p.transpose();
		// move it first up
		Vector3d pos0(0,-175,0); // desired location
		moveObjectAbsolute(pos0, platformPos, 6000);
	}
	// move object to middle position
	Vector3d pos1(0,-175,middlePos); // desired location
	moveObjectAbsolute(pos1, platformPos, 6000);

	// object's exact location depends on the current test condition
	// if it's a training trial[round]...
	if(training)
		objLocation = str2num<double>(parameters.find("TrainingDist"));
	else // else if it's a catch trial[round]...
		objLocation = str2num<double>(parameters.find("CatchDist"));

	// move object to location
	Vector3d pos2(0,-175,objLocation); // desired location
	moveObjectAbsolute(pos2, platformPos, 6000);
	
	// update markers
	optotrak->updateMarkers();
	// put new values into markers
	markers = optotrak->getAllMarkers();
	
	// initialize the pagnet's position to magnetPos
	magnetPos = markers[3].p.transpose()[1];

	// move the screen to middle position
	initProjectionScreen(middlePos);
	// move the screen to location
	initProjectionScreen(objLocation);

	// open the trial file, where we record online movements
	// setting file's name
	if(training)
		trialFileName = "C:/Users/visionlab/Google Drive/DATA/SizeWeightIllusion/" + parameters.find("SubjectName") + "/" + parameters.find("SubjectName") + "_round_" + stringify<double>(round) + "trial_" + stringify<double>(trialNumber) + "training.txt";
	else
		trialFileName = "C:/Users/visionlab/Google Drive/DATA/SizeWeightIllusion/" + parameters.find("SubjectName") + "/" + parameters.find("SubjectName") + "_round_" + stringify<double>(round) + "trial_" + stringify<double>(trialNumber) + "catch.txt";

	// creating-opening the file
	trialFile.open(trialFileName.c_str());
	// writing the first line of the file (headers)
	trialFile << fixed << "subjName" << "\t" <<
						  "trialN" << "\t" <<
						  "time" << "\t" <<
						  "frameN" << "\t" <<
						  "indexXraw" << "\t" <<
						  "indexYraw" << "\t" <<
						  "indexZraw" << "\t" <<
						  "thumbXraw" << "\t" <<
						  "thumbYraw" << "\t" <<
						  "thumbZraw" << "\t" <<
						  "eyeRXraw" << "\t" <<
						  "eyeRYraw" << "\t" <<
						  "eyeRZraw" << "\t" <<
						  "eyeLXraw" << "\t" <<
						  "eyeLYraw" << "\t" <<
						  "eyeLZraw" << "\t" <<
						  "fingersOccluded" << "\t" <<
						  "objectPosX" << "\t" <<
						  "objectPosY" << "\t" <<
						  "objectPosZ" << "\t" <<
						  "isStimulusDrawn" << "\t" <<
						  "noVisibleFingers" << "\t" <<
						  "round" << "\t" <<
						  "AbsDepth" << "\t" <<
						  "size" << "\t" <<
						  "diameter" << "\t" <<
						  "condition" << "\t" <<
						  "IOD" << "\t" <<
						  "allTrials" <<
						  endl;

	// release the cylinder!!
	isStimulusDrawn=true;
	
	// trial can start
	beepOk(0);
	timer.start();

}
Example #2
0
void advanceTrial()
{
	double timeElapsed = timer.getElapsedTimeInMilliSec();
	responseFile.precision(3);
    responseFile << 
					parameters.find("SubjectName") << "\t" <<
					interoculardistance << "\t" <<
					trialNumber << "\t" <<
					objLocation <<"\t" <<
                    sizeNow <<"\t" <<
					diameter <<"\t" <<
                    timer.getElapsedTimeInMilliSec() << "\t" <<
					training << "\t" <<
					round << "\t" <<
					endl;
	
	trialFile.close();

	trialNumber++;
	allTrials++;

	// if fingers were invisible for more than 20% of the trial
	double noVisibleFingersD = noVisibleFingers;
	double frameND = frameN;

	if(noVisibleFingersD/frameND > .2)
		trial[round].reinsert(trial[round].getCurrent()); // repeat this trial at the end
	
	if(training)
	{
		if( !trial[round].isEmpty() )
		{
			trial[round].next();
			initTrial();
		}
		else
		{
			trialNumber = 0;
			training=false;
			initTrial();
		}
	}else
	{
		if(trialNumber < str2num<int>(parameters.find("numCatchTrials")))
		{
			trial[round].next();
			initTrial();
		}else if(round+1<ROUNDS) // if there is another round after the current
		{
			trialNumber = 0;
			round++;
			trial[round].next();
			training=true;
			initTrial();
		}else
		{
			cleanup();
			exit(0);
		}
	}
}
Example #3
0
void drawInfo()
{
	if ( visibleInfo )
	{
		glDisable(GL_COLOR_MATERIAL);
		glDisable(GL_BLEND);
		glDisable(GL_LIGHTING);

		GLText text;

		if ( gameMode )
			text.init(SCREEN_WIDTH,SCREEN_HEIGHT,glWhite,GLUT_BITMAP_HELVETICA_18);
		else
			text.init(640,480,glWhite,GLUT_BITMAP_HELVETICA_12);
		text.enterTextInputMode();

		switch ( headCalibrationDone )
			{
		case 0:
			{
			if ( allVisibleHead )
				text.draw("==== Head Calibration OK ==== Press Spacebar to continue");
			else
				text.draw("Be visible with the head and glasses");
			}
			break;
		case 1:
		case 2:
			{
			if ( allVisiblePatch )
				text.draw("Move the head in the center");
			else
				text.draw("Be visible with the patch");
			}
			break;
		case 3:	// When the head calibration is done then calibrate the fingers
			{
			switch ( fingerCalibrationDone )
				{
			case 0:
				text.draw("Press F to record platform markers");
				break;
			case 1:
				text.draw("Move index and thumb on platform markers to record ghost finger tips, then press F");
				break;
			case 2:
				text.draw("Move index and thumb to rigidbody tip to define starting position, then press F");
				break;
			case 3:
				text.draw("Finger calibration successfull!");
				break;
				}
			}
			break;
			}

	if ((GetKeyState(VK_CAPITAL) & 0x0001)!=0)
	{
	  text.draw("#");
	  text.draw("#");
	  text.draw("# ----------------------------> Caps Lock ON!");
	  text.draw("#");
	  text.draw("#");
	}

	text.draw("####### SUBJECT #######");
	text.draw("#");
	text.draw("# Name: " +parameters.find("SubjectName"));
	text.draw("# IOD: " +stringify<double>(interoculardistance));
	text.draw("#");
	if ( abs(mirrorAlignment - 45.0) < 0.2 )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("# Mirror Alignment = " + stringify<double>(mirrorAlignment));
	glColor3fv(glWhite);
	text.draw("#");
	text.draw("#######################");
	text.draw("HeadCalibration= " + stringify<int>(headCalibrationDone) );
	text.draw("FingerCalibration= " + stringify<int>(fingerCalibrationDone) );

	glColor3fv(glWhite);
	text.draw("Calibration Platform" );

	if ( isVisible(markers[1].p) && isVisible(markers[2].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Marker "+ stringify<int>(1)+stringify< Eigen::Matrix<double,1,3> > (markers[1].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(2)+stringify< Eigen::Matrix<double,1,3> > (markers[2].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(4)+stringify< Eigen::Matrix<double,1,3> > (markers[4].p.transpose())+ " [mm]" );
	
	glColor3fv(glWhite);
	text.draw("Marker "+ stringify<int>(3)+stringify< Eigen::Matrix<double,1,3> > (markers[3].p.transpose())+ " [mm]" );

	glColor3fv(glWhite);
	text.draw(" " );
	text.draw("Mirror" );

	if ( isVisible(markers[5].p) && isVisible(markers[6].p) && isVisible(markers[7].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Marker "+ stringify<int>(5)+stringify< Eigen::Matrix<double,1,3> > (markers[5].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(6)+stringify< Eigen::Matrix<double,1,3> > (markers[6].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(7)+stringify< Eigen::Matrix<double,1,3> > (markers[7].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(8)+stringify< Eigen::Matrix<double,1,3> > (markers[8].p.transpose())+ " [mm]" );

	glColor3fv(glWhite);
	text.draw(" " );
	text.draw("Index" );

	if ( isVisible(markers[13].p) && isVisible(markers[14].p) && isVisible(markers[16].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Marker "+ stringify<int>(13)+stringify< Eigen::Matrix<double,1,3> > (markers[13].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(14)+stringify< Eigen::Matrix<double,1,3> > (markers[14].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(16)+stringify< Eigen::Matrix<double,1,3> > (markers[16].p.transpose())+ " [mm]" );

	glColor3fv(glWhite);
	text.draw(" " );
	text.draw("Thumb" );

	if ( isVisible(markers[15].p) && isVisible(markers[17].p) && isVisible(markers[18].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Marker "+ stringify<int>(15)+stringify< Eigen::Matrix<double,1,3> > (markers[15].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(17)+stringify< Eigen::Matrix<double,1,3> > (markers[17].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(18)+stringify< Eigen::Matrix<double,1,3> > (markers[18].p.transpose())+ " [mm]" );

	glColor3fv(glWhite);

	text.draw("Alignment(X,Y)= " +stringify<double>(alignmentX)+","+stringify<double>(alignmentY));
	text.draw("Index= " +stringify< Eigen::Matrix<double,1,3> >(index.transpose()));
	text.draw("Thumb= " +stringify< Eigen::Matrix<double,1,3> >(thumb.transpose()));
	text.draw("Timer= " + stringify<int>(timer.getElapsedTimeInMilliSec()) );
	text.draw("Frame= " + stringify<int>(frameN));
	text.draw("Training= " + stringify<int>(training));
	glColor3fv(glRed);
	text.draw("CurSize= " + stringify<int>(trial[round].getCurrent()["Size"]));	
	text.leaveTextInputMode();
	}else
	{

	glDisable(GL_COLOR_MATERIAL);
	glDisable(GL_BLEND);
	glDisable(GL_LIGHTING);
	GLText text1;

	if ( gameMode )
		text1.init(SCREEN_WIDTH,SCREEN_HEIGHT,glBlue,GLUT_BITMAP_HELVETICA_18);
	else
		text1.init(640,480,glBlue,GLUT_BITMAP_HELVETICA_12);
	text1.enterTextInputMode();

	text1.draw("                                                                                                                                                                                   Round= " + stringify<int>(round));
	text1.draw("  ");
	text1.draw("                                                                                                                                                                                   #-NOW-#");

	if(training)
		text1.draw("                                                                                                                                                                                   Training");
	else
		text1.draw("                                                                                                                                                                                   Catch");
	text1.draw("                                                                                                                                                                                   Trial= " + stringify<int>(trialNumber));

	text1.draw("                                                                                                                                                                                   SizeNow= " + stringify<int>(sizeNow));
	text1.draw("  ");
	text1.draw("                                                                                                                                                                                   #-NEXT-#");
	glColor3fv(glRed);
	text1.draw("                                                                                                                                                                                   SizeNext= " + stringify<int>(sizeNext));


	text1.leaveTextInputMode();
	}
}
Example #4
0
void drawStimulus()
{
	if (fingerCalibrationDone==3 && isStimulusDrawn && !pickedUp)
	{

		if(markers[3].p.transpose()[1]-magnetPos > 2.5)
			pickedUp = true;
		else
			pickedUp = pickedUp;

		glLoadIdentity();

		// check for fingers' visibility
		if(fingersOccluded==0)
			drawFingers();
		else
			drawNoFingers();

		// location of the object depends on the condition
		if(training)
		{
			// and on the visibility of the magnet
			if(!objectOccluded)
			{
				// place object at training pos
				glTranslated(0.0,markers[3].p.transpose()[1]-magnetPos,str2num<double>(parameters.find("TrainingDist")));
				// rotation available for debugging purposes (vertical by default)
				glRotated(theta,1,0,0);
				// black square in the middle to present only half of the cylinder
				if(half)
					drawBlackSquare();
				// draw the object
				drawEllipsoid(sizeNow);
			}else
			{
				glTranslated(0.0,0.0,-400.0);
				glRotated(M_PI*90.0,0,0,1);
				drawEllipsoid(sizeNow);
			}
		}else
		{
			if(!objectOccluded)
			{
				// place object at training pos
				glTranslated(0.0,markers[3].p.transpose()[1]-magnetPos,str2num<double>(parameters.find("CatchDist")));
				// rotation available for debugging purposes (vertical by default)
				glRotated(theta,1,0,0);
				// black square in the middle to present only half of the cylinder
				if(half)
					drawBlackSquare();
				// draw the object
				drawEllipsoid(sizeNow);
			}else
			{
				glTranslated(0.0,0.0,-400.0);
				glRotated(M_PI,0,0,1);
				drawEllipsoid(sizeNow);
			}
		}
	}
}
Example #5
0
void drawInfo()
{
	if ( visibleInfo )
	{
		glDisable(GL_COLOR_MATERIAL);
		glDisable(GL_BLEND);
		glDisable(GL_LIGHTING);

		GLText text;

		if ( gameMode )
			text.init(SCREEN_WIDTH,SCREEN_HEIGHT,glWhite,GLUT_BITMAP_HELVETICA_18);
		else
			text.init(640,480,glWhite,GLUT_BITMAP_HELVETICA_12);
		text.enterTextInputMode();

		switch (fingerCalibrationDone)
		{
			case 0:
				text.draw("Calibration object and index marker are not visible.");		
				break;

			case 1:
				{
					glColor3fv(glGreen);
					text.draw("Index marker has been detected and calibrated. Waiting for Thumb marker to be visible...");	
				} break;

			case 2:
				{
					glColor3fv(glGreen);
					text.draw("Index marker has been detected and calibrated.");	
					text.draw("Thumb marker has been detected and calibrated.");	
					glColor3fv(glWhite);
					text.draw("Touch the two outer markers with the fingerpads then press F (fingers and calibration object visible)");
				} break;

			case 3:
				text.draw("Set home position then press F to start the demo");		
				break;
		}

	if(interoculardistance>0.0)
	{
		glColor3fv(glWhite);
		text.draw(" ");
		text.draw("####### SUBJECT #######");
		text.draw("#");
		text.draw("# Name: " +parameters.find("SubjectName"));
	} else {
		text.draw(" ");
		text.draw(" ");
		text.draw(" ");
	}
	text.draw("# IOD: " +stringify<double>(interoculardistance));
	if ( abs(mirrorAlignment - 45.0) < 0.2 )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("# Mirror Alignment = " +stringify<double>(mirrorAlignment));

	if(interoculardistance>0.0)
	{
		glColor3fv(glWhite);
		text.draw("#");
		text.draw("# trial: " +stringify<double>(trialNumber));
		text.draw("#");
		text.draw("#######################");
		text.draw("HeadCalibration= " + stringify<int>(headCalibrationDone) );
		text.draw("FingerCalibration= " + stringify<int>(fingerCalibrationDone) );
		
		glColor3fv(glWhite);
		text.draw("Calibration Platform" );
		
		if ( isVisible(markers[1].p) && isVisible(markers[2].p) )
			glColor3fv(glGreen);
		else
			glColor3fv(glRed);
		
		text.draw("Marker "+ stringify<int>(1)+stringify< Eigen::Matrix<double,1,3> > (markers[1].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(2)+stringify< Eigen::Matrix<double,1,3> > (markers[2].p.transpose())+ " [mm]" );
	
		glColor3fv(glWhite);
		text.draw("Marker "+ stringify<int>(3)+stringify< Eigen::Matrix<double,1,3> > (markers[3].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(4)+stringify< Eigen::Matrix<double,1,3> > (markers[4].p.transpose())+ " [mm]" );

		glColor3fv(glWhite);
		text.draw(" " );
		text.draw("Mirror" );

		if ( isVisible(markers[5].p) && isVisible(markers[6].p) && isVisible(markers[7].p) )
			glColor3fv(glGreen);
		else
			glColor3fv(glRed);
		text.draw("Marker "+ stringify<int>(5)+stringify< Eigen::Matrix<double,1,3> > (markers[5].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(6)+stringify< Eigen::Matrix<double,1,3> > (markers[6].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(7)+stringify< Eigen::Matrix<double,1,3> > (markers[7].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(8)+stringify< Eigen::Matrix<double,1,3> > (markers[8].p.transpose())+ " [mm]" );

		glColor3fv(glWhite);
		text.draw(" " );
		text.draw("Index" );

		if ( isVisible(markers[13].p) && isVisible(markers[14].p) && isVisible(markers[16].p) )
			glColor3fv(glGreen);
		else
			glColor3fv(glRed);
		text.draw("Marker "+ stringify<int>(13)+stringify< Eigen::Matrix<double,1,3> > (markers[13].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(14)+stringify< Eigen::Matrix<double,1,3> > (markers[14].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(16)+stringify< Eigen::Matrix<double,1,3> > (markers[16].p.transpose())+ " [mm]" );

		glColor3fv(glWhite); 
		text.draw(" " );
		text.draw("Thumb" );

		if ( isVisible(markers[15].p) && isVisible(markers[17].p) && isVisible(markers[18].p) )
			glColor3fv(glGreen);
		else
			glColor3fv(glRed);
		text.draw("Marker "+ stringify<int>(15)+stringify< Eigen::Matrix<double,1,3> > (markers[15].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(17)+stringify< Eigen::Matrix<double,1,3> > (markers[17].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(18)+stringify< Eigen::Matrix<double,1,3> > (markers[18].p.transpose())+ " [mm]" );

		glColor3fv(glWhite);

		text.draw("EyeRight= "+stringify< Eigen::Matrix<double,1,3> > (eyeRight.transpose())+ " [mm]" );
		text.draw("EyeLeft= "+stringify< Eigen::Matrix<double,1,3> > (eyeLeft.transpose())+ " [mm]" );
		text.draw("Index= " +stringify< Eigen::Matrix<double,1,3> >(index.transpose()));
		text.draw("Thumb= " +stringify< Eigen::Matrix<double,1,3> >(thumb.transpose()));
		text.draw("Timer= " + stringify<int>(timer.getElapsedTimeInMilliSec()) );
		text.draw("Trial= " + stringify<int>(trialNumber));
		text.draw(stringify<double>(abs(mirrorAlignment - 45.0)));
		text.leaveTextInputMode();
	}
	}
}
void initTrial()
{
	// reset counters
	frameN = 0;
	stimulus = 1;
	isTrialDone = false;
	motion = 0.0;

	cerr << "\n--------- TRIAL #" << trialNumber << " ----------" << endl;

	// set the width of the object to 20mm
	objwidth = 20.0;

	// retrieve the depth cue
	if(trial.getCurrent().first["DepthCue"] == 1)
	{
		depth_cue_pedestal = "stereo";
		depth_cue_stimulus = "motion_mono";
	}
	else
	{
		depth_cue_pedestal = "motion_mono";
		depth_cue_stimulus = "stereo";
	}
	// draw an empty screen
	isStimulusDrawn=false;

	// assign the stimuli
	if(unifRand(-1.0, 1.0) > 0.0)
	{
		first_stimulus = "pedestal";
		second_stimulus = "stimulus";
	} else 
	{
		first_stimulus = "stimulus";
		second_stimulus = "pedestal";
	}
#ifdef TEST
		double PSE = str2num<double>(parameters.find("PSE"));
		double JND = unifRand(-str2num<double>(parameters.find("JND")), str2num<double>(parameters.find("JND")));

		cerr << "PSE = " << PSE << endl;
		cerr << "JND = " << JND << endl;

		// set the depth of the pedestal
		depth_pedestal = trial.getCurrent().first["RelDepthObj"];

		// set the depth of the stimulus
		depth_stimulus = depth_pedestal + trial.getCurrent().second->getCurrentStaircase()->getState();

		objdistance = trial.getCurrent().first["AbsDepth"];

//		bool decision = ((depth_stimulus + JND) > (depth_pedestal + PSE) && first_stimulus == "stimulus") || (depth_stimulus + JND) > (depth_pedestal + PSE) && second_stimulus == "stimulus";

		bool decision = ((depth_stimulus + JND) > (depth_pedestal + PSE) || (depth_stimulus + JND) > (depth_pedestal + PSE));

		advanceTrial(decision);
#else
	if(training)
	{	
		// set the depth of the pedestal
		depth_pedestal = 40.0;

		// set the depth of the stimulus to be either clearly smaller or clearly larger than the pedestal
		if(unifRand(-1.0, 1.0) > 0.0)
			depth_stimulus = 20.0;
		else
			depth_stimulus = 60.0;

		objdistance = -360;
	}

	if(experiment)
	{
		// set the depth of the pedestal
		depth_pedestal = trial.getCurrent().first["RelDepthObj"];

		// set the depth of the stimulus
		depth_stimulus = depth_pedestal + trial.getCurrent().second->getCurrentStaircase()->getState();

		objdistance = trial.getCurrent().first["AbsDepth"];
	}

	// build the three rods
	build_three_rods();

	// refresh the scene
	drawGLScene();

	// set the monitor at the right ditance
	initProjectionScreen(objdistance);

	// draw the stimulus	
	beepOk(0);
	isStimulusDrawn=true;

	timer.start();
#endif
}
Example #7
0
void initTrial()
{
	// initializing all variables
	frameN=0;
	started = false;
	handAtStart=true;
	reachedObject = false;
	fingersOccluded = 0;
	num_lost_frames = 0;
	isStimulusDrawn=false;
	stimPosn = trial.getCurrent()["StimPosn"];
	cout << "initTrial: " + trialNumber << endl;
	cout << "initTrial: " + stimPosn << endl;

	// roll on
	drawGLScene();
	
	// move the screen
	initProjectionScreen(trial.getCurrent()["AbsDepth"]); //evces 031414

	if (!debug_no_motion) {
	if(trialNumber==0){
			Vector3d pos1(0,-35,trial.getCurrent()["AbsDepth"]-25);
			moveObjectAbsolute(pos1, centercal, 7500);
	}
	}

	string trialFileName = "C:/Users/visionlab/Google Drive/DATA/Evan-haptic/spatial2/" + parameters.find("SubjectName") + "/" + parameters.find("SubjectName") + "trial_" + stringify<double>(trialNumber) + "_" + stringify<double>(attempt) + ".txt";
	trialFile.open(trialFileName.c_str());
	trialFile << fixed << "subjName\ttrialN\ttime\tframeN\tindexXYZraw\tthumbXYZraw\tfingersOccluded\tattempt\treachedObject\tnum_lost_frames" << endl;

	isStimulusDrawn=true;
	beepOk(0);
	timer.start();
}
void drawFixation()
{
	switch ( headCalibrationDone )
	{   
	case 1:
		// Fixed stimulus
		glColor3fv(glWhite);
		glDisable(GL_BLEND);
		glPointSize(5);
		glBegin(GL_POINTS);
		glVertex3d(0,0,focalDistance);
		glEnd();
		glPointSize(1);
		break;
	case 2:
		// Fixed stimulus + projected points
		glColor3fv(glWhite);
		glDisable(GL_BLEND);
		glPointSize(5);
		glBegin(GL_POINTS);
		glVertex3d(0,0,focalDistance);
		glColor3fv(glRed);
		glVertex3dv(projPointEyeRight.data());
		glColor3fv(glBlue);
		glVertex3d(eyeRight.x(),eyeRight.y(),focalDistance);
		glEnd();
		glPointSize(1);
	
		// Draw the calibration circle
		glColor3fv(glWhite);
		break;
	
	case 3:
	{
	// DRAW THE FIXATION POINT 
	double eyeToCenterAngleX= toDegrees(atan(eyeRight.x()/(-focalDistance-eyeRight.z()) ));
	double eyeToCenterAngleY= toDegrees(atan(eyeRight.y()/(-focalDistance-eyeRight.z()) ));
	double projPointAngleX = toDegrees( atan( (projPointEyeRight.x()-eyeRight.x())/abs(projPointEyeRight.z())));
	double maxAllowedTranslationYaw = str2num<double>(parameters.find("MaxAllowedTranslationYaw"));


	Vector3d stimulusCenter(0,0,0);
	Matrix3d objrotation = Matrix3d::Identity();
	// IMPORTANT Reset the previous status of transformation
	objectActiveTransformation.setIdentity();

	switch ( (int) factors["Rotation"] )
	{
	case 2:
	{
		objrotation = (AngleAxis<double>(eulerAngles.getYaw()*factors["FollowingSpeed"], Vector3d::UnitY())
		*AngleAxis<double>(eulerAngles.getPitch(), Vector3d::UnitX())).toRotationMatrix();
		instantPlaneSlant = toDegrees(eulerAngles.getYaw())*factors["RotationSpeed"]+factors["Slant"];
		stimulusCenter = objrotation*Vector3d(0,0,focalDistance)+headEyeCoords.getRigidStart().getFullTransformation().translation();
		objectActiveTransformation.linear()=objrotation;
	}
	break;
	case 1:
	{
		objrotation = (AngleAxis<double>(eulerAngles.getYaw(), Vector3d::UnitY())
		*AngleAxis<double>(eulerAngles.getPitch()*factors["FollowingSpeed"], Vector3d::UnitX())).toRotationMatrix();
		instantPlaneSlant = toDegrees(eulerAngles.getPitch())*factors["RotationSpeed"]+factors["Slant"];
		stimulusCenter = objrotation*Vector3d(0,0,focalDistance)+headEyeCoords.getRigidStart().getFullTransformation().translation();
		objectActiveTransformation.linear()=objrotation;
	}
	break;
	case 0:
	{
		objrotation = (AngleAxis<double>(eulerAngles.getYaw(), Vector3d::UnitY())
		*AngleAxis<double>(eulerAngles.getPitch(), Vector3d::UnitX())).toRotationMatrix();
		//instantPlaneSlant = eyeRight.x()*factors["RotationSpeed"]/10+factors["Slant"];
		instantPlaneSlant = toDegrees( atan(eyeRight.x()/abs(focalDistance+eyeRight.z()) ) )*factors["RotationSpeed"]+factors["Slant"];
		stimulusCenter  = headEyeCoords.getRigidStart().getFullTransformation().linear()*Vector3d(eyeRight.x()*factors["FollowingSpeed"],eyeRight.y(),eyeRight.z()+focalDistance);
		objectActiveTransformation.linear() = objrotation;
	}
	break;
	}
	objectActiveTransformation.translation() = stimulusCenter;
	Vector3d fixationPointTmp = objectActiveTransformation.translation();

	glPushMatrix();
	glTranslated(fixationPointTmp.x(),fixationPointTmp.y(),fixationPointTmp.z());
	glutSolidSphere(1,10,10);
	glPopMatrix();
	break;	
	}
}
}
void drawInfo()
{
	if ( visibleInfo )
	{
	GLText text;	
	text.init(SCREEN_WIDTH,SCREEN_HEIGHT,glWhite,GLUT_BITMAP_HELVETICA_12);
	text.enterTextInputMode();
	text.draw("####### SUBJECT #######");
	text.draw("#");
	text.draw("# Name: " +parameters.find("SubjectName"));
	text.draw("# IOD: " +stringify<double>(interoculardistance));
	text.draw("#");
		if(visibleSpecs)
		{
	text.draw("# trial: " +stringify<double>(trialNumber));
	text.draw("#");
	text.draw("# obj depth: " +stringify<double>(trial.getCurrent().first["RelDepthObj"]));
	text.draw("# simulated depth: " +stringify<double>(trial.getCurrent().second->getCurrentStaircase()->getState()));
	text.draw("# stairID: " +stringify<double>(trial.getCurrent().second->getCurrentStaircase()->getID()));
	text.draw("#");
    text.draw("# stairState: " +stringify<double>(trial.getCurrent().second->getCurrentStaircase()->getState() - trial.getCurrent().first["RelDepthObj"]));
	text.draw("#");
    text.draw("# stairInversions: " +stringify<double>(trial.getCurrent().second->getCurrentStaircase()->getInversions()));
    text.draw("# stairAscending: " +stringify<double>(trial.getCurrent().second->getCurrentStaircase()->getAscending()));
	text.draw("#");
   text.draw("# stepsDone: " +stringify<double>(trial.getCurrent().second->getCurrentStaircase()->getStepsDone()));
		}
//	text.draw("#");
   /*
	for ( std::map<string,double>::iterator iter = trial.getCurrent().begin(); iter!=trial.getCurrent().end();++iter)
	{
		text.draw(iter->first + ": " + stringify<double>(iter->second));
	}
	*/
	text.draw("#######################");
/*	text.draw("HeadCalibration= " + stringify<int>(headCalibrationDone) );
	if ( isVisible(markers[1].p) && isVisible(markers[2].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Marker "+ stringify<int>(1)+stringify< Eigen::Matrix<double,1,3> > (markers[1].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(2)+stringify< Eigen::Matrix<double,1,3> > (markers[2].p.transpose())+ " [mm]" );
	
	glColor3fv(glWhite);
	text.draw("Marker "+ stringify<int>(3)+stringify< Eigen::Matrix<double,1,3> > (markers[3].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(4)+stringify< Eigen::Matrix<double,1,3> > (markers[4].p.transpose())+ " [mm]" );
	
	if ( isVisible(markers[5].p) && isVisible(markers[6].p) && isVisible(markers[7].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Marker "+ stringify<int>(5)+stringify< Eigen::Matrix<double,1,3> > (markers[5].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(6)+stringify< Eigen::Matrix<double,1,3> > (markers[6].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(7)+stringify< Eigen::Matrix<double,1,3> > (markers[7].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(9)+stringify< Eigen::Matrix<double,1,3> > (markers[9].p.transpose())+ " [mm]" );
	
	glColor3fv(glWhite);

	text.draw("EyeRight= "+stringify< Eigen::Matrix<double,1,3> > (eyeRight.transpose())+ " [mm]" );
	text.draw("EyeLeft= "+stringify< Eigen::Matrix<double,1,3> > (eyeLeft.transpose())+ " [mm]" );
	text.draw("Alignment(X,Y)= " +stringify<double>(alignmentX)+","+stringify<double>(alignmentY));
	text.draw(" ");
	text.draw("jitter = " +stringify<double>(jitter));
	text.draw(" ");
	text.draw("size = " +stringify<double>((xedge + jitter)));
	text.draw("xedge = " +stringify<double>(xedge));
	text.draw(" ");
	text.draw("depth = " +stringify<double>(zedge + (jitter/2)));
	text.draw("zedge = " +stringify<double>(zedge));
*/	text.leaveTextInputMode();
	}
}
Example #10
0
void drawInfo()
{
	if ( visibleInfo )
	{
		glDisable(GL_COLOR_MATERIAL);
		glDisable(GL_BLEND);
		glDisable(GL_LIGHTING);

		GLText text;

		if ( gameMode )
			text.init(SCREEN_WIDTH,SCREEN_HEIGHT,glWhite,GLUT_BITMAP_HELVETICA_18);
		else
			text.init(1280,1024,glWhite,GLUT_BITMAP_HELVETICA_12);
		text.enterTextInputMode();

		switch ( headCalibrationDone )
			{
		case 0:
			{
			if ( allVisibleHead )
				text.draw("==== Head Calibration OK ==== Press Spacebar to continue");
			else
				text.draw("Be visible with the head and glasses");
			}
			break;
		case 1:
		case 2:
			{
			if ( allVisiblePatch )
				text.draw("Move the head in the center");
			else
				text.draw("Be visible with the patch");
			}
			break;
		case 3:	// When the head calibration is done then calibrate the fingers
			{
			switch ( fingerCalibrationDone )
				{
			case 0:
				text.draw("Press F to record platform markers");
				break;
			case 1:
				text.draw("Move index and thumb on platform markers to record ghost finger tips, then press F");
				break;
			case 2:
				text.draw("Move index and thumb to rigidbody tip to define starting position, then press F");
				break;
			case 3:
				text.draw("Finger calibration successfull!");
				break;
				}
			}
			break;
			}

	text.draw("####### SUBJECT #######");
	text.draw("#");
	text.draw("# Name: " +parameters.find("SubjectName"));
	text.draw("# IOD: " +stringify<double>(interoculardistance));
	text.draw("#");
	text.draw("# trial: " +stringify<double>(trialNumber));
	text.draw("#");
//	text.draw("# obj depth: " +stringify<double>(trial.getCurrent()["RelDepthObj"] + dz));
//	text.draw("#");
	/*
	for ( std::map<string,double>::iterator iter = trial.getCurrent().begin(); iter!=trial.getCurrent().end();++iter)
	{
		text.draw(iter->first + ": " + stringify<double>(iter->second));
	}
	*/
	text.draw("#######################");
	text.draw("HeadCalibration= " + stringify<int>(headCalibrationDone) );
	text.draw("FingerCalibration= " + stringify<int>(fingerCalibrationDone) );

	glColor3fv(glWhite);
	text.draw("Calibration Platform" );

	if ( isVisible(markers[1].p) && isVisible(markers[2].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Marker "+ stringify<int>(1)+stringify< Eigen::Matrix<double,1,3> > (markers[1].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(2)+stringify< Eigen::Matrix<double,1,3> > (markers[2].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(4)+stringify< Eigen::Matrix<double,1,3> > (markers[4].p.transpose())+ " [mm]" );
	
	glColor3fv(glWhite);
	text.draw("Marker "+ stringify<int>(3)+stringify< Eigen::Matrix<double,1,3> > (markers[3].p.transpose())+ " [mm]" );

	glColor3fv(glWhite);
	text.draw(" " );
	text.draw("Mirror" );

	if ( isVisible(markers[5].p) && isVisible(markers[6].p) && isVisible(markers[7].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Marker "+ stringify<int>(5)+stringify< Eigen::Matrix<double,1,3> > (markers[5].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(6)+stringify< Eigen::Matrix<double,1,3> > (markers[6].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(7)+stringify< Eigen::Matrix<double,1,3> > (markers[7].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(8)+stringify< Eigen::Matrix<double,1,3> > (markers[8].p.transpose())+ " [mm]" );

	glColor3fv(glWhite);
	text.draw(" " );
	text.draw("Index" );

	if ( isVisible(markers[13].p) && isVisible(markers[14].p) && isVisible(markers[16].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Marker "+ stringify<int>(13)+stringify< Eigen::Matrix<double,1,3> > (markers[13].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(14)+stringify< Eigen::Matrix<double,1,3> > (markers[14].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(16)+stringify< Eigen::Matrix<double,1,3> > (markers[16].p.transpose())+ " [mm]" );

	glColor3fv(glWhite);
	text.draw(" " );
	text.draw("Thumb" );

	if ( isVisible(markers[15].p) && isVisible(markers[17].p) && isVisible(markers[18].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Marker "+ stringify<int>(15)+stringify< Eigen::Matrix<double,1,3> > (markers[15].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(17)+stringify< Eigen::Matrix<double,1,3> > (markers[17].p.transpose())+ " [mm]" );
	text.draw("Marker "+ stringify<int>(18)+stringify< Eigen::Matrix<double,1,3> > (markers[18].p.transpose())+ " [mm]" );

	glColor3fv(glWhite);

	text.draw("Alignment(X,Y)= " +stringify<double>(alignmentX)+","+stringify<double>(alignmentY));
	if ( abs(mirrorAlignment - 45.0) < 0.2 )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Mirror Alignment = " +stringify<double>(mirrorAlignment));
	text.draw("Index= " +stringify< Eigen::Matrix<double,1,3> >(index.transpose()));
	text.draw("Thumb= " +stringify< Eigen::Matrix<double,1,3> >(thumb.transpose()));
	text.draw("Timer= " + stringify<int>(timer.getElapsedTimeInMilliSec()) );
	text.draw("Trial= " + stringify<int>(trialNumber));
	text.draw("Frame= " + stringify<int>(frameN));
	text.draw("theta= " + stringify<int>(theta));
	text.leaveTextInputMode();
	}
}
void initVariables()
{
	trial.init(parameters);
	interoculardistance = str2num<double>(parameters.find("IOD"));
}
void idle()
{

	updateTheMarkers();

	// Visibility check
	allVisiblePlatform = isVisible(markers[1].p) && isVisible(markers[2].p);
	allVisibleIndex = isVisible(markers[13].p) && isVisible(markers[14].p) && isVisible(markers[16].p);
	allVisibleThumb = isVisible(markers[15].p) && isVisible(markers[17].p) && isVisible(markers[18].p);
	allVisibleFingers = allVisibleIndex && allVisibleThumb;

	allVisibleObject = isVisible(markers[8].p) && isVisible(markers[11].p) && isVisible(markers[12].p);

	allVisiblePatch = isVisible(markers[10].p) && isVisible(markers[11].p) && isVisible(markers[12].p);
	allVisibleHead = allVisiblePatch && isVisible(markers[9].p);

	// mirror alignment check
	mirrorAlignment = asin(
			abs((markers[6].p.z()-markers[7].p.z()))/
			sqrt(
			pow(markers[6].p.x()-markers[7].p.x(), 2) +
			pow(markers[6].p.z()-markers[7].p.z(), 2)
			)
			)*180/M_PI;

	// screen Y alignment check
	screenAlignmentY = asin(
			abs((markers[19].p.y()-markers[21].p.y()))/
			sqrt(
			pow(markers[19].p.x()-markers[21].p.x(), 2) +
			pow(markers[19].p.y()-markers[21].p.y(), 2)
			)
			)*180/M_PI;

	// screen Z alignment check
	screenAlignmentZ = asin(
			abs(markers[19].p.z()-markers[20].p.z())/
			sqrt(
			pow(markers[19].p.x()-markers[20].p.x(), 2) +
			pow(markers[19].p.z()-markers[20].p.z(), 2)
			)
			)*180/M_PI*
			abs(markers[19].p.x()-markers[20].p.x())/
			(markers[19].p.x()-markers[20].p.x());

	// eye coordinates
	eyeRight = Vector3d(interoculardistance/2,0,0);
	eyeLeft = Vector3d(-interoculardistance/2,0,0);

	// fingers coordinates, fingersOccluded and framesOccluded
	if ( allVisibleFingers )
	{
		indexCoords.update(markers[13].p, markers[14].p, markers[16].p );
		thumbCoords.update(markers[15].p, markers[17].p, markers[18].p );
	}

	// Record the calibration platform's position and home position
	if ( isVisible(markers[1].p) && allVisibleObject && fingerCalibrationDone==0 )
	{
		fingerCalibrationDone=1;
		calibration_fingers(fingerCalibrationDone);
	}

	// Record the calibration platform's position and home position
	if ( isVisible(markers[2].p) && allVisibleObject && fingerCalibrationDone==1 )
	{
		fingerCalibrationDone=2;
		calibration_fingers(fingerCalibrationDone);
		beepOk(2);
	}

	if ( allVisibleObject && fingerCalibrationDone==2 )
	{
		upperPin.update(markers[8].p, markers[11].p, markers[12].p );
		lowerPin.update(markers[8].p, markers[11].p, markers[12].p );
	}

	#ifndef SIMULATION
	// index coordinates
	if(allVisibleIndex)
		ind = indexCoords.getP1();

	// thumb coordinates
	if(allVisibleThumb)
		thu = thumbCoords.getP1();
	#endif

	// what the program checks online during the grasp
	if (fingerCalibrationDone==4 )
	{
		// frames counting
		frameN++;

		// fingersOccluded
		if ( allVisibleFingers )
			fingersOccluded = 0;
		else
		{
			fingersOccluded=1;
		}
		
		if(timer.getElapsedTimeInMilliSec() > 1500)
			iGrasped = true;

		if(isHandHome && !iGrasped)
		{
			timer.start();
			frames_at_start++;
		}

		if(iGrasped)
			frames_post_grasp++;

		// middle point between index and thumb (center of grasp)
		grip_position = (ind + thu)/2;

		// euclidean distance to home
		dist_to_home = sqrt( pow((grip_position.x() - home_position.x()),2) + pow((grip_position.y() - home_position.y()),2) + pow((grip_position.z() - home_position.z()),2) );

		// is the hand at start?
		if( dist_to_home < 50.0 )
			isHandHome = true;
		else
			isHandHome = false;

		// euclidean distance to target
		dist_to_target = sqrt( pow((grip_position.x() - 0.0),2) + pow((grip_position.y() - 0.0),2) + pow((grip_position.z() - trial.getCurrent()["AbsDepth"]),2) );

		if(!isHandHome && !allVisibleFingers && !iGrasped)
			framesOccluded++;

		// Write to responseFile
		markersFile << fixed <<
			parameters.find("SubjectName") << "\t" <<
			interoculardistance << "\t" <<
			trialNumber << "\t" <<
			timer.getElapsedTimeInMilliSec() << "\t" <<		//time
			frameN << "\t" <<								//frameN
			ind.transpose() << "\t" <<					//indexXraw, indexYraw, indexZraw
			thu.transpose() << "\t" <<					//thumbXraw, thumbYraw, thumbZraw
			eyeRight.transpose() << "\t" <<					//eyeRXraw, eyeRYraw, eyeRZraw
			eyeLeft.transpose() << "\t" <<					//eyeLXraw, eyeLYraw, eyeLZraw
			fingersOccluded	<< "\t" <<						//fingersOccluded
			framesOccluded	<< "\t" <<						//framesOccluded
			trial.getCurrent()["AbsDepth"]	<< "\t" <<
			trial.getCurrent()["RelDepthObj"] << "\t" <<
			frameToGrasp <<
			endl;
	}
}
void drawInfo()
{
	if ( visibleInfo )
	{
		GLText text;	
		text.init(SCREEN_WIDTH,SCREEN_HEIGHT,glWhite,GLUT_BITMAP_HELVETICA_12);
		text.enterTextInputMode();

		switch (fingerCalibrationDone)
		{
			case 0:
				text.draw("Calibration object and index marker are not visible.");		
				break;

			case 1:
				{
					glColor3fv(glGreen);
					text.draw("Index marker has been detected and calibrated. Waiting for Thumb marker to be visible...");	
				} break;

			case 2:
				{
					glColor3fv(glGreen);
					text.draw("Index marker has been detected and calibrated.");	
					text.draw("Thumb marker has been detected and calibrated.");	
					glColor3fv(glWhite);
					text.draw("Touch the two outer markers with the fingerpads then press F (fingers and calibration object visible)");
				} break;

			case 3:
				text.draw("Set home position then press F to start the demo");		
				break;
		}
		glColor3fv(glWhite);
		text.draw("FingerCalibration= " + stringify<int>(fingerCalibrationDone) );
		text.draw(" ");
		text.draw("####### SUBJECT #######");
		text.draw("#");
		text.draw("# Name: " +parameters.find("SubjectName"));
		text.draw("# IOD: " +stringify<double>(interoculardistance));
		text.draw("#");
		text.draw("# trial: " +stringify<double>(trialNumber));
		text.draw("#");
		text.draw("#######################\n\n");
		text.draw(" ");

		// check if mirror is calibrated
		if ( abs(mirrorAlignment - 45.0) < 0.2 )
			glColor3fv(glGreen);
		else
			glColor3fv(glRed);
		text.draw("# Mirror Alignment = " +stringify<double>(mirrorAlignment));

		// check if monitor is calibrated
		if ( screenAlignmentY < 89.0 )
			glColor3fv(glRed);
		else
			glColor3fv(glGreen);
		text.draw("# Screen Alignment Y = " +stringify<double>(screenAlignmentY));
		if ( abs(screenAlignmentZ) < 89.0 )
			glColor3fv(glRed);
		else
			glColor3fv(glGreen);
		text.draw("# Screen Alignment Z = " +stringify<double>(screenAlignmentZ));
		glColor3fv(glWhite);
		// X and Z coords of simulated fixation
		text.draw("# Fixation Z = " +stringify<double>(markers[19].p.x()-120.0)+ " [mm]");
		text.draw("# Fixation X = " +stringify<double>(markers[19].p.z()+363.0)+ " [mm]");
		text.draw(" ");

		glColor3fv(glWhite);
		text.draw("Calibration Platform" );
		
		if ( isVisible(markers[1].p) && isVisible(markers[2].p) )
			glColor3fv(glGreen);
		else
			glColor3fv(glRed);
		
		text.draw("Marker "+ stringify<int>(1)+stringify< Eigen::Matrix<double,1,3> > (markers[1].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(2)+stringify< Eigen::Matrix<double,1,3> > (markers[2].p.transpose())+ " [mm]" );

		if ( isVisible(markers[3].p) )
			glColor3fv(glGreen);
		else
			glColor3fv(glRed);
		text.draw("Marker "+ stringify<int>(3)+stringify< Eigen::Matrix<double,1,3> > (markers[3].p.transpose())+ " [mm]" );

		glColor3fv(glWhite);
		text.draw(" " );
		text.draw("Index" );

		if ( isVisible(markers[13].p) && isVisible(markers[14].p) && isVisible(markers[16].p) )
			glColor3fv(glGreen);
		else
			glColor3fv(glRed);
		text.draw("Marker "+ stringify<int>(13)+stringify< Eigen::Matrix<double,1,3> > (markers[13].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(14)+stringify< Eigen::Matrix<double,1,3> > (markers[14].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(16)+stringify< Eigen::Matrix<double,1,3> > (markers[16].p.transpose())+ " [mm]" );

		glColor3fv(glWhite); 
		text.draw(" " );
		text.draw("Thumb" );

		if ( isVisible(markers[15].p) && isVisible(markers[17].p) && isVisible(markers[18].p) )
			glColor3fv(glGreen);
		else
			glColor3fv(glRed);
		text.draw("Marker "+ stringify<int>(15)+stringify< Eigen::Matrix<double,1,3> > (markers[15].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(17)+stringify< Eigen::Matrix<double,1,3> > (markers[17].p.transpose())+ " [mm]" );
		text.draw("Marker "+ stringify<int>(18)+stringify< Eigen::Matrix<double,1,3> > (markers[18].p.transpose())+ " [mm]" );
		
		glColor3fv(glWhite); 
		text.draw(" " );
		text.draw("time: " +stringify<int>(timer.getElapsedTimeInMilliSec()));
		text.draw("Index = " +stringify< Eigen::Matrix<double,1,3> > (ind.transpose()));
		text.draw("Thumb = " +stringify< Eigen::Matrix<double,1,3> > (thu.transpose()));
		text.draw("Home = " +stringify< Eigen::Matrix<double,1,3> > (home_position.transpose()));
		text.draw("Dist To Home = " +stringify<double> (dist_to_home));
		text.draw("framesOccluded = " +stringify<int> (framesOccluded));
		text.draw("frameN = " +stringify<int> (frameN));
		text.draw("frames_at_start = " +stringify<int> (frames_at_start));
		text.draw("frames_post_grasp = " +stringify<int> (frames_post_grasp));
		text.draw("framesOccluded/frameN = " +stringify<double> ((double)framesOccluded/(frameN-frames_at_start-frames_post_grasp+1)));

		text.leaveTextInputMode();
	}

	if ( expFinished )
	{
		GLText text2;	
		text2.init(SCREEN_WIDTH,SCREEN_HEIGHT,glWhite,GLUT_BITMAP_HELVETICA_12);
		text2.enterTextInputMode();
		text2.draw("The experiment is finished.");
		text2.leaveTextInputMode();
	}

}
Example #14
0
void idle()
{
	// update optotrak
	optotrak->updateMarkers();
	// fill markers with updated coords
	markers = optotrak->getAllMarkers();

	// Coordinates picker
	allVisiblePlatform = isVisible(markers[1].p);
	allVisibleIndex = isVisible(markers[13].p) && isVisible(markers[14].p) && isVisible(markers[16].p);
	allVisibleThumb = isVisible(markers[15].p) && isVisible(markers[17].p) && isVisible(markers[18].p);
	allVisibleFingers = allVisibleIndex && allVisibleThumb;

	// mirror visible
	allVisiblePatch = isVisible(markers[5].p) && isVisible(markers[6].p) && isVisible(markers[7].p);
	allVisibleHead = allVisiblePatch && isVisible(markers[1].p);

	if ( allVisiblePatch )
		headEyeCoords.update(markers[5].p,markers[6].p,markers[7].p);

	if ( allVisibleFingers )
	{
		indexCoords.update(markers[13].p, markers[14].p, markers[16].p );
		thumbCoords.update(markers[15].p, markers[17].p, markers[18].p );
		fingersOccluded = 0;
	}
	
	// during the trial (after the calibratioon)
	if (fingerCalibrationDone==3 )
	{
		
		// check for visibility of the fingers
		if ( !allVisibleFingers )
		{
			fingersOccluded=1;
			noVisibleFingers++;
		}
		
		// check for the visibility of the object
		if(!isVisible(markers[3].p))
			objectOccluded=1;
		else
			objectOccluded=0;
		
		// start the flow of the frames
		frameN++;
	
		// eye coords depend on whether the head calibration took place or not
		if(headCalibration)
		{
			// real time coords
			eyeLeft = headEyeCoords.getLeftEye();	
			eyeRight = headEyeCoords.getRightEye();
		} else	{
			// fixed coords
			eyeRight = Vector3d(interoculardistance/2,0,0);
			eyeLeft = -eyeRight;
		}
	
		// online position of fingers updated
		index = indexCoords.getP1();
		thumb = thumbCoords.getP1();
	
		// online posotion of the mirror updated
		mirrorAlignment = asin(
			abs((markers[6].p.z()-markers[7].p.z()))/
			sqrt(
			pow(markers[6].p.x()-markers[7].p.x(), 2) +
			pow(markers[6].p.z()-markers[7].p.z(), 2)
			)
			)*180/M_PI;
		
		// online info written in the trialFile
		trialFile << fixed <<
			parameters.find("SubjectName") << "\t" <<		//subjName
			trialNumber << "\t" <<							//trialN
			timer.getElapsedTimeInMilliSec() << "\t" <<		//time
			frameN << "\t" <<								//frameN
			index.transpose() << "\t" <<					//indexXraw, indexYraw, indexZraw
			thumb.transpose() << "\t" <<					//thumbXraw, thumbYraw, thumbZraw
			eyeRight.transpose() << "\t" <<					//eyeRXraw, eyeRYraw, eyeRZraw
			eyeLeft.transpose() << "\t" <<					//eyeLXraw, eyeLYraw, eyeLZraw
			fingersOccluded << "\t" <<						//fingersOccluded
			markers[3].p.transpose() << "\t" <<				//objectPos
			isStimulusDrawn << "\t" <<
			noVisibleFingers << "\t" <<
			round << "\t" <<
			objLocation <<"\t" <<
            sizeNow <<"\t" <<
			diameter <<"\t" <<
			condition << "\t" <<
			interoculardistance << "\t" <<
			allTrials
			;
		trialFile << endl;
		
	}

}
Example #15
0
// Questa funzione e' quella che in background fa tutti i conti matematici, quindi qui devi inserire 
// 1) Scrittura su file continua delle coordinate che vuoi salvare
// 2) Estrazione delle coordinate a partire dai corpi rigidi precedentemente definiti vedi ad esempio
// come e' fatto per eyeLeft e eyeRight oppure per thumb ed index
void idle()
{
	optotrak->updateMarkers();
	
	/*cerr << trial.getCurrent()["AbsDepth"] << "\t" << 
		trial.getCurrent()["ObjHeight"] << "\t" <<
		trial.getCurrent()["HapticFB"] << endl;
	*/
	//cerr << parameters.find("fObjHeight",1) << endl;

	markers = optotrak->getAllMarkers();
	// Coordinates picker
	allVisiblePlatform = isVisible(markers[1].p);
	allVisibleIndex = isVisible(markers[13].p) && isVisible(markers[14].p) && isVisible(markers[16].p);
	allVisibleThumb = isVisible(markers[15].p) && isVisible(markers[17].p) && isVisible(markers[18].p);
	allVisibleFingers = allVisibleIndex && allVisibleThumb;

	allVisiblePatch = isVisible(markers[5].p) && isVisible(markers[6].p) && isVisible(markers[7].p);
	allVisibleHead = allVisiblePatch && isVisible(markers[1].p);

	mirrorAlignment = asin(
			abs((markers[6].p.z()-markers[7].p.z()))/
			sqrt(
			pow(markers[6].p.x()-markers[7].p.x(), 2) +
			pow(markers[6].p.z()-markers[7].p.z(), 2)
			)
			)*180/M_PI;

	if ( allVisiblePatch )
		headEyeCoords.update(markers[5].p,markers[6].p,markers[7].p);

	if ( allVisibleFingers )
	{
		indexCoords.update(markers[13].p, markers[14].p, markers[16].p );
		thumbCoords.update(markers[15].p, markers[17].p, markers[18].p );
		fingersOccluded = 0;
	}

	if (fingerCalibrationDone==3 )
	{
		// check for finger occlusion
		if ( !allVisibleFingers )
		{
			fingersOccluded=1;
			num_lost_frames += 1;
		}
		
		// advance frame number
		frameN++;

		// check that we're at the start
		// if so, keep resetting timer
		if(((-500) < index.y()) && (index.y() < (-315)) && ((-500) < thumb.y()) && (thumb.y() < (-315)))
		{
			handAtStart = true;
			timer.start();
		} else // we've moved from the start, begin counting
		{
			handAtStart = false;
		}
		
		// if we're in the reaching area
		if(!handAtStart && ((-315) <= index.y()) && (index.y() < 200) && ((-315) <= thumb.y()) && (thumb.y() < 100))
		{
			started=true; // we've started
		}else{
			started=started;
		}

		// find y_dist and z_dist
		y_dist = (abs(index.y() - (-25)) + abs(thumb.y() - (-25)));
		z_dist = (abs(index.z() - (trial.getCurrent()["AbsDepth"])) + abs(thumb.z() - (trial.getCurrent()["AbsDepth"])));
		within_time_limit = (timer.getElapsedTimeInMilliSec() <= str2num<double>(parameters.find("TimeLimit")));

		if(!reachedObject && (stimPosn==LEFT) && started) {
			x_dist = (abs(index.x() - (-26)) + abs(thumb.x() - (-26)));
			if ( (x_dist <= 25) && (y_dist <= 70) && (z_dist <= 25) && within_time_limit) {
				reachedObject = true;
				TGA_frame = frameN;
			}
		}else if(!reachedObject && (stimPosn==RIGHT) && started) {
			x_dist = (abs(index.x() - (74)) + abs(thumb.x() - (74)));
			if ( (x_dist <= 25) && (y_dist <= 70) && (z_dist <= 25) && within_time_limit) {
				reachedObject = true;
				TGA_frame = frameN;
			}
		}

	}

	if(headCalibration)
	{
	eyeLeft = headEyeCoords.getLeftEye();
	eyeRight = headEyeCoords.getRightEye();
	} else	{
	eyeRight = Vector3d(interoculardistance/2,0,0);
	eyeLeft = -eyeRight;
	}

	index = indexCoords.getP1();
	thumb = thumbCoords.getP1();

	// Write to trialFile
	if (fingerCalibrationDone==3 )
		{

		trialFile << fixed <<
			parameters.find("SubjectName") << "\t" <<		//subjName
			trialNumber << "\t" <<							//trialN
			timer.getElapsedTimeInMilliSec() << "\t" <<		//time
			frameN << "\t" <<								//frameN
			index.transpose() << "\t" <<					//indexXraw, indexYraw, indexZraw
			thumb.transpose() << "\t" <<					//thumbXraw, thumbYraw, thumbZraw
			//eyeRight.transpose() << "\t" <<					//eyeRXraw, eyeRYraw, eyeRZraw
			//eyeLeft.transpose() << "\t" <<					//eyeLXraw, eyeLYraw, eyeLZraw
			fingersOccluded << "\t" <<						//fingersOccluded
			attempt << "\t" <<	
			reachedObject << "\t" <<	
			num_lost_frames
			;

		trialFile << endl;
		
		}

}
void drawInfo()
{
	if ( visibleInfo )
	{
		glDisable(GL_COLOR_MATERIAL);
		glDisable(GL_BLEND);
		glDisable(GL_LIGHTING);

		GLText text;

		if ( gameMode )
			text.init(SCREEN_WIDTH,SCREEN_HEIGHT,glWhite,GLUT_BITMAP_HELVETICA_18);
		else
			text.init(640,480,glWhite,GLUT_BITMAP_HELVETICA_12);
		text.enterTextInputMode();

		switch ( headCalibrationDone )
			{
		case 0:
			{
			if ( allVisibleHead )
				text.draw("==== Head Calibration OK ==== Press Spacebar to continue");
			else
				text.draw("Be visible with the head and glasses");
			}
			break;
		case 1:
		case 2:
			{
			if ( allVisiblePatch )
				text.draw("Move the head in the center");
			else
				text.draw("Be visible with the patch");
			}
			break;
		case 3:	// When the head calibration is done then calibrate the fingers
			{
			switch ( fingerCalibrationDone )
				{
			case 0:
				text.draw("Press F to record platform markers");
				break;
			case 1:
				text.draw("Move index on platform markers to record ghost finger tips, then press F");
				break;
			case 2:
				text.draw("Move index to rigidbody tip to define starting position, then press F");
				break;
			case 3:
				text.draw("Finger calibration successfull!");
				break;
				}
			}
			break;
			}

	text.draw("####### SUBJECT #######");
	text.draw("#");
	text.draw("# Name: " +parameters.find("SubjectName"));
	text.draw("# IOD: " +stringify<double>(interoculardistance));
	text.draw("#");
	text.draw("# trial: " +stringify<double>(trialNumber));
	text.draw("#");
//	text.draw("# obj depth: " +stringify<double>(trial.getCurrent()["RelDepthObj"] + dz));
//	text.draw("#");
	/*
	for ( std::map<string,double>::iterator iter = trial.getCurrent().begin(); iter!=trial.getCurrent().end();++iter)
	{
		text.draw(iter->first + ": " + stringify<double>(iter->second));
	}
	*/
	text.draw("#######################");
	text.draw("HeadCalibration= " + stringify<int>(headCalibrationDone) );
	text.draw("FingerCalibration= " + stringify<int>(fingerCalibrationDone) );

	// platform calibration
	if ( isVisible(markers[15].p) && isVisible(markers[16].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Platform front "+ stringify<int>(1)+stringify< Eigen::Matrix<double,1,3> > (markers[15].p.transpose())+ " [mm]" );
	text.draw("Platform side "+ stringify<int>(2)+stringify< Eigen::Matrix<double,1,3> > (markers[16].p.transpose())+ " [mm]" );
	
	//head
	if ( isVisible(markers[1].p) && isVisible(markers[2].p) && isVisible(markers[3].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Head 1 "+ stringify<int>(5)+stringify< Eigen::Matrix<double,1,3> > (markers[1].p.transpose())+ " [mm]" );
	text.draw("Head 2 "+ stringify<int>(6)+stringify< Eigen::Matrix<double,1,3> > (markers[2].p.transpose())+ " [mm]" );
	text.draw("Head 3 "+ stringify<int>(7)+stringify< Eigen::Matrix<double,1,3> > (markers[3].p.transpose())+ " [mm]" );
	text.draw("Head 4 "+ stringify<int>(8)+stringify< Eigen::Matrix<double,1,3> > (markers[4].p.transpose())+ " [mm]" );

	//index
	if ( isVisible(markers[7].p) && isVisible(markers[8].p) && isVisible(markers[9].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Index 1 "+ stringify<int>(13)+stringify< Eigen::Matrix<double,1,3> > (markers[7].p.transpose())+ " [mm]" );
	text.draw("Index 2 "+ stringify<int>(14)+stringify< Eigen::Matrix<double,1,3> > (markers[8].p.transpose())+ " [mm]" );
	text.draw("Index 3 "+ stringify<int>(16)+stringify< Eigen::Matrix<double,1,3> > (markers[9].p.transpose())+ " [mm]" );
	
	//thumb
	if ( isVisible(markers[11].p) && isVisible(markers[12].p) && isVisible(markers[13].p) )
		glColor3fv(glGreen);
	else
		glColor3fv(glRed);
	text.draw("Thumb 1 "+ stringify<int>(13)+stringify< Eigen::Matrix<double,1,3> > (markers[11].p.transpose())+ " [mm]" );
	text.draw("Thumb 2 "+ stringify<int>(14)+stringify< Eigen::Matrix<double,1,3> > (markers[12].p.transpose())+ " [mm]" );
	text.draw("Thumb 3 "+ stringify<int>(16)+stringify< Eigen::Matrix<double,1,3> > (markers[13].p.transpose())+ " [mm]" );

	//other specs
	glColor3fv(glWhite);

	text.draw("EyeRight= "+stringify< Eigen::Matrix<double,1,3> > (eyeRight.transpose())+ " [mm]" );
	text.draw("EyeLeft= "+stringify< Eigen::Matrix<double,1,3> > (eyeLeft.transpose())+ " [mm]" );
	text.draw("Alignment(X,Y)= " +stringify<double>(alignmentX)+","+stringify<double>(alignmentY));
	text.draw("Index= " +stringify< Eigen::Matrix<double,1,3> >(index.transpose()));
	text.draw("Timer= " + stringify<int>(timer.getElapsedTimeInMilliSec()) );
	text.draw("Trial= " + stringify<int>(trialNumber));
	text.draw("Index Speed= " + stringify<double>(markers[14].v.norm()));
	text.draw("Condition= " + stringify<int>(condition));
	text.draw("StairState= " + stringify<double>(trial.getCurrent().second->getCurrentStaircase()->getState()));
	text.draw("StairID= " + stringify<double>(trial.getCurrent().second->getCurrentStaircase()->getID()));
	text.leaveTextInputMode();
	}
}
/*** INFO ***/
void drawInfo()
{
	if ( visibleInfo )
	{
		GLText text;	
		text.init(SCREEN_WIDTH,SCREEN_HEIGHT,glWhite,GLUT_BITMAP_HELVETICA_12);
		text.enterTextInputMode();

		glColor3fv(glWhite);
		if(experiment)
			text.draw("####### SUBJECT #######");
		if(training)
			text.draw("####### THIS IS JUST A TRAINING #######");
		text.draw("#");
		text.draw("# Name: " +parameters.find("SubjectName"));
		text.draw("# IOD: " +stringify<double>(interoculardistance));
		text.draw("#");
		text.draw("# trial: " +stringify<double>(trialNumber));
		text.draw("#");
		text.draw("#######################\n\n");
		text.draw(" ");

		// check if mirror is calibrated
		if ( abs(mirrorAlignment - 45.0) < 0.2 )
			glColor3fv(glGreen);
		else
			glColor3fv(glRed);
		text.draw("# Mirror Alignment = " +stringify<double>(mirrorAlignment));

		// check if monitor is calibrated
		if ( screenAlignmentY < 89.0 )
			glColor3fv(glRed);
		else
			glColor3fv(glGreen);
		text.draw("# Screen Alignment Y = " +stringify<double>(screenAlignmentY));

		if ( abs(screenAlignmentZ) < 89.4 )
			glColor3fv(glRed);
		else
			glColor3fv(glGreen);
		text.draw("# Screen Alignment Z = " +stringify<double>(screenAlignmentZ));

		glColor3fv(glWhite);
		// X and Z coords of simulated fixation
		text.draw("# Fixation Z = " +stringify<double>(markers.at(screen1).p.x()-120.0)+ " [mm]");
		text.draw("# Fixation X = " +stringify<double>(markers.at(screen1).p.z()+363.0)+ " [mm]");
		text.draw(" ");

		glColor3fv(glWhite); 
		text.draw(" " );
		text.draw("time: " +stringify<int>(timer.getElapsedTimeInMilliSec()));
		text.draw(" " );
		if(depth_cue_pedestal == "stereo")
		{
			text.draw("Moving: = " +stringify<double> (depth_stimulus));
			text.draw("Stereo: = " +stringify<double> (depth_pedestal));
		} else
		{
			text.draw("Moving: = " +stringify<double> (depth_pedestal));
			text.draw("Stereo: = " +stringify<double> (depth_stimulus));
		}

		text.leaveTextInputMode();
	}

	if ( expFinished )
	{
		GLText text2;	
		text2.init(SCREEN_WIDTH,SCREEN_HEIGHT,glWhite,GLUT_BITMAP_HELVETICA_12);
		text2.enterTextInputMode();
		text2.draw("The experiment is finished.");
		text2.leaveTextInputMode();
	}

	if ( inPause )
	{
		GLText text3;	
		text3.init(SCREEN_WIDTH,SCREEN_HEIGHT,glWhite,GLUT_BITMAP_HELVETICA_18);
		text3.enterTextInputMode();
		text3.draw("P A U S E");
		text3.leaveTextInputMode();
	}
}
void update(int value)
{   // Read the experiment from file, if the file is finished exit suddenly
    if ( inputStream.eof() )
    {   cleanup();
        exit(0);
    }

    if ( isReading )
    {   // This reads a line (frame) in inputStream
        readline(inputStream, trialNumber,  headCalibration,  trialMode, pointMatrix );

        headEyeCoords.update(pointMatrix.col(0),pointMatrix.col(1),pointMatrix.col(2));
        Affine3d active = headEyeCoords.getRigidStart().getFullTransformation();
        eulerAngles.init( headEyeCoords.getRigidStart().getFullTransformation().rotation() );

        eyeLeft = headEyeCoords.getLeftEye();
        eyeRight= headEyeCoords.getRightEye();

        cyclopeanEye = (eyeLeft+eyeRight)/2.0;

		if ( trialMode == STIMULUSMODE )
			stimulusFrames++;
		if ( trialMode == FIXATIONMODE )
			stimulusFrames=0;

        // Projection of view normal on the focal plane
	Vector3d directionOfSight = (active.rotation()*Vector3d(0,0,-1)).normalized();
	Eigen::ParametrizedLine<double,3> lineOfSightRight = Eigen::ParametrizedLine<double,3>::Through( eyeRight , eyeRight+directionOfSight );
	Eigen::ParametrizedLine<double,3> lineOfSightLeft  = Eigen::ParametrizedLine<double,3>::Through( eyeLeft, eyeLeft+directionOfSight );
	
	double lineOfSightRightDistanceToFocalPlane = lineOfSightRight.intersection(focalPlane);
	double lineOfSightLeftDistanceToFocalPlane = lineOfSightLeft.intersection(focalPlane);
	
	//double lenghtOnZ = (active*(center-eyeCalibration )+eyeRight).z();
	projPointEyeRight = lineOfSightRightDistanceToFocalPlane *(directionOfSight)+ (eyeRight);
	projPointEyeLeft= lineOfSightLeftDistanceToFocalPlane * (directionOfSight) + (eyeLeft);
	// second projection the fixation point computed with z non constant but perfectly parallel to projPointEyeRight
	lineOfSightRightDistanceToFocalPlane= (( active.rotation()*(center)) - eyeRight).norm();
	Vector3d secondProjection = lineOfSightRightDistanceToFocalPlane *(directionOfSight)+ (eyeRight);
	
	if ( !zOnFocalPlane )
	projPointEyeRight=secondProjection ;

	// Compute the translation to move the eye in order to avoid share components
	Vector3d posAlongLineOfSight = (headEyeCoords.getRigidStart().getFullTransformation().rotation())*(eyeRight -eyeCalibration);
	// GENERATION OF PASSIVE MODE.
        // HERE WE MOVE THE SCREEN TO FACE THE OBSERVER's EYE
        if ( passiveMode )
        {
            initProjectionScreen(0, headEyeCoords.getRigidStart().getFullTransformation()*Translation3d(center));
        }
        else
            initProjectionScreen(focalDistance, Affine3d::Identity());
        
	objectPassiveTransformation = ( cam.getModelViewMatrix()*objectActiveTransformation );
    
	ofstream outputfile;
	outputfile.open("data.dat");
	outputfile << "Subject Name: " << parameters.find("SubjectName") << endl;
	outputfile << "Passive matrix:" << endl << objectPassiveTransformation.matrix() << endl;
	outputfile << "Yaw: " << toDegrees(eulerAngles.getYaw()) << endl <<"Pitch: " << toDegrees(eulerAngles.getPitch()) << endl;
	outputfile << "EyeLeft: " <<  headEyeCoords.getLeftEye().transpose() << endl;
	outputfile << "EyeRight: " << headEyeCoords.getRightEye().transpose() << endl << endl;
	outputfile << "Slant: " << instantPlaneSlant << endl;
	outputfile << "Factors:" << endl;
	for (map<string,double>::iterator iter=factors.begin(); iter!=factors.end(); ++iter)
	{
		outputfile << "\t\t" << iter->first << "= " << iter->second << endl;
	}
	
	}

    if ( trialMode == PROBEMODE )
        isReading=false;

    glutPostRedisplay();
    glutTimerFunc(TIMER_MS, update, 0);
}
void initTrial()
{
	// reset counters
	frameN = 0;
	stimulus = 1;
	isTrialDone = false;
	motion = 0.0;

	if(checkglasses)
		build_stereocheck();

	cerr << "\n--------- TRIAL #" << trialNumber << " ----------" << endl;

	// set the width of the object to 20mm
	objwidth = 20.0;

	// retrieve the depth cue
	if(trial.getCurrent().first["DepthCue"] == 1)
	{
		depth_cue_pedestal = "stereo";
		depth_cue_stimulus = "motion_mono";
	}
	else
	{
		depth_cue_pedestal = "motion_mono";
		depth_cue_stimulus = "stereo";
	}
	// draw an empty screen
	isStimulusDrawn=false;

	// assign the stimuli
	if(unifRand(-1.0, 1.0) > 0.0)
	{
		first_stimulus = "pedestal";
		second_stimulus = "stimulus";
	} else 
	{
		first_stimulus = "stimulus";
		second_stimulus = "pedestal";
	}
#ifdef TEST
		double PSE = str2num<double>(parameters.find("PSE"));
		double JND = unifRand(-str2num<double>(parameters.find("JND")), str2num<double>(parameters.find("JND")));

		cerr << "PSE = " << PSE << endl;
		cerr << "JND = " << JND << endl;

		// set the depth of the pedestal
		depth_pedestal = trial.getCurrent().first["RelDepthObj"];

		// set the depth of the stimulus
		depth_stimulus = depth_pedestal + trial.getCurrent().second->getCurrentStaircase()->getState();

		objdistance = trial.getCurrent().first["AbsDepth"];

//		bool decision = ((depth_stimulus + JND) > (depth_pedestal + PSE) && first_stimulus == "stimulus") || (depth_stimulus + JND) > (depth_pedestal + PSE) && second_stimulus == "stimulus";

		bool decision = ((depth_stimulus + JND) > (depth_pedestal + PSE) || (depth_stimulus + JND) > (depth_pedestal + PSE));

		advanceTrial(decision);
#else
	if(training)
	{	
		trial_time = 2500;

		// set the depth of the pedestal
		depth_pedestal = 40.0;

		// set the depth of the stimulus to be either clearly smaller or clearly larger than the pedestal
		if(unifRand(-1.0, 1.0) > 0.0)
			depth_stimulus = 20.0;
		else
			depth_stimulus = 60.0;

		objdistance = -360;
	}

	if(experiment)
	{
		trial_time = trial_duration;

		// set the depth of the pedestal
		depth_pedestal = trial.getCurrent().first["RelDepthObj"];

		// set the depth of the stimulus
		depth_stimulus = depth_pedestal + trial.getCurrent().second->getCurrentStaircase()->getState();

		objdistance = trial.getCurrent().first["AbsDepth"];
	}

	// build fixation cross
	build_fixation_cross();

	// build the two planes
	build_two_planes();

	// calculate the length of the oblique plane
	oblPlane_pedestal_length = sqrt( pow(depth_pedestal, 2) + pow(obl_length, 2) );
	oblPlane_stimulus_length = sqrt( pow(depth_stimulus, 2) + pow(obl_length, 2) );
	build_oblique_plane(oblPlane_pedestal_length, oblPlane_stimulus_length);

	// calculate the angle of the oblique plane
	oblTheta_pedestal = atan( depth_pedestal/obl_length ) * 180/M_PI;
	oblTheta_stimulus = atan( depth_stimulus/obl_length ) * 180/M_PI;

	// refresh the scene
	drawGLScene();

	// set the monitor at the right ditance
	initProjectionScreen(objdistance);

	// draw the stimulus	
	beepOk(0);
	isStimulusDrawn=true;

	timer.start();
#endif
}
// Inizializza gli stream, apre il file per poi scriverci
void initStreams()
{
	// Initializza il file parametri partendo dal file parameters.txt, se il file non esiste te lo dice
	ifstream parametersFile;
	parametersFile.open(parametersFile_directory.c_str());
	parameters.loadParameterFile(parametersFile);

	// Subject name
	string subjectName = parameters.find("SubjectName");

	initVariables();

	// Principal streams files

	// response file (if haptic)
	if(condition == 1)
	{
		string responseFileName = experiment_directory + responseFile_name + subjectName + "_" + stringify<int>(condition) + "_" + stringify<int>(stimulus_noise) + ".txt";

		// Check for output file existence
		if (util::fileExists(responseFileName))
		{
			string error_on_file_io = responseFileName + string(" already exists");
			cerr << error_on_file_io << endl;
#ifndef SIMULATION
			MessageBox(NULL, (LPCSTR)"FILE ALREADY EXISTS\n Please check the parameters file.",NULL, NULL);
#endif
			exit(0);
		}
		else
		{
			responseFile.open(responseFileName.c_str());
			cerr << "File " << responseFileName << " loaded successfully" << endl;
		}

		responseFile << fixed << responseFile_headers << endl;
	}

	// summary file
	string summaryFileName = experiment_directory + responseFile_name + subjectName + "_" + stringify<int>(condition) + "_" + stringify<int>(stimulus_noise) + "_summary.txt";
/*
	/// Summary file
	if ( !util::fileExists(summaryFileName) )
	        summaryFile.open(summaryFileName.c_str());
*/
	// Check for output file existence
    if (util::fileExists(summaryFileName))
    {
        string error_on_file_io = summaryFileName + string(" already exists");
        cerr << error_on_file_io << endl;
#ifndef SIMULATION
	MessageBox(NULL, (LPCSTR)"FILE ALREADY EXISTS\n Please check the parameters file.",NULL, NULL);
#endif
        exit(0);
    }
    else
    {
        summaryFile.open(summaryFileName.c_str());
        cerr << "File " << summaryFileName << " loaded successfully" << endl;
    }

	summaryFile << fixed << summaryFile_headers << endl;
}
Example #21
0
/*** TRIAL ***/
void initVariables()
{
	// student directory
	student_directory = parameters.find("student");
	total_trials = str2num<int>(parameters.find("total_trials"));
}