예제 #1
0
void initVariables()
{
    interoculardistance = str2num<double>(parameters.find("IOD"));
    // Create the factors-staircase object TrialGenerator
    trial.init(parameters);
    maxTotalTrials = trial.getRemainingTrials();
    cerr << "There are " << maxTotalTrials << " total trials to do..." << endl;
    factors = trial.getNext();

    redDotsPlane.setNpoints(300);
    redDotsPlane.setDimensions(50,50,0.1);

    redDotsPlane.compute();
    //stimDrawer.drawSpecialPoints();
    stimDrawer.setStimulus(&redDotsPlane);
    stimDrawer.setSpheres(false);
    stimDrawer.initList(&redDotsPlane,glRed,3);


    // Set the maximum x displacement of head
    maxXOscillation = util::str2num<double>(parameters.find("MaxXOscillation"));
    nOscillationsFixation = util::str2num<int>(parameters.find("NOscillationsFixation"));
    minOscTime = util::str2num<double>(parameters.find("MinOscillationTime"));
    maxOscTime = util::str2num<double>(parameters.find("MaxOscillationTime"));

	centerTolerance = util::str2num<double>(parameters.find("CenterTolerance"));

    totalTimer.start();
}
예제 #2
0
void initVariables()
{
    totalTimer.start();
    interoculardistance = str2num<double>(parameters.find("IOD"));
    trial.init(parameters);
    factors = trial.getNext(); // Initialize the factors in order to start from trial 1

    useCircularMask = util::str2num<int>( parameters.find("CircularMask")) == 1 ;
    circularMaskRadius = util::str2num<int>(parameters.find("CircularMaskRadius"));
    if (useCircularMask)
        glEnable(GL_STENCIL_TEST);
    else
        glDisable(GL_STENCIL_TEST);

    fixationDurationInSeconds = util::str2num<double>(parameters.find("AdaptationDurationInSeconds"));
    // Imposta stimolo e drawer
    redDotsPlane.setNpoints(util::str2num<int>(parameters.find("NumStimulusPoints")));
    redDotsPlane.setDimensions(
        util::str2num<int>(parameters.find("StimulusEdgeLength")),
        util::str2num<int>(parameters.find("StimulusEdgeLength")),0.1);
    redDotsPlane.compute();
    stimDrawer.initList(&redDotsPlane,glRed);

    resetPointStrip();

    stimulusDurationInMilliSeconds = util::str2num<double>(parameters.find("StimulusDuration"));
    initialAdaptationTimeInSeconds = util::str2num<double>(parameters.find("InitialAdaptationTime"));
    initialAdaptationFlowIncrement = util::str2num<double>(parameters.find("InitialAdaptationFlowIncrement"));
    stimMotion=SINUSOIDAL_MOTION;
    trialMode = INITIALADAPTATION;

    headEyeCoords.init(Vector3d(interoculardistance/2,0,0),Vector3d(interoculardistance/2,0,0), Vector3d(0,0,0),Vector3d(0,10,0),Vector3d(0,0,10),interoculardistance );
    eyeCalibration=headEyeCoords.getRightEye();
}
예제 #3
0
void initVariables()
{
    interoculardistance = str2num<double>(parameters.find("IOD"));
    stimulusEmiCycles= atoi(parameters.find("StimulusEmiCycles").c_str());
    trial.init(parameters);
    factors = trial.getNext(); // Initialize the factors in order to start from trial 1

    if ( atoi(parameters.find("DrawOccluder").c_str()) ==1 )
    {
        redDotsPlane.setNpoints(500);  //XXX controllare densita di distribuzione dei punti
        redDotsPlane.setDimensions(200,200,0.1);
    }
    else
    {
        redDotsPlane.setNpoints(75);  //XXX controllare densita di distribuzione dei punti
        redDotsPlane.setDimensions(50,50,0.1);
    }
    //redDotsPlane.setSlantTilt( factors["Slant"], (int) factors["Tilt"] );
    redDotsPlane.compute();
    stimDrawer.setStimulus(&redDotsPlane);
    stimDrawer.initList(&redDotsPlane);

    /** Bound check things **/
    signsX.push_back(false);
    signsX.push_back(false);

    signsY.push_back(false);
    signsY.push_back(false);

    headEyeCoords.init(Vector3d(-32.5,0,0),Vector3d(32.5,0,0), Vector3d(0,0,0),Vector3d(0,10,0),Vector3d(0,0,10),interoculardistance );
    eyeCalibration=headEyeCoords.getRightEye();
    model.load("../data/objmodels/occluder.obj");
}
예제 #4
0
void mouseFunc(int button, int state, int _x , int _y)
{
    if ( trialMode!=PROBEMODE || !canCalibrate )
        return;
    if ( button== GLUT_LEFT_BUTTON && canCalibrate )
    {
        response=true;
    }

    if (button == GLUT_RIGHT_BUTTON && canCalibrate )
    {
        response=false;
    }

    responseFile <<
                 trialNumber << "\t" <<
                 factors.at("Tilt") << "\t" <<
                 factors.at("Slant") << "\t" <<
                 factors.at("Binocular") << "\t" <<
                 factors.at("OmegaY") << "\t" <<
                 responseTimer.getElapsedTimeInMilliSec() << "\t" <<
                 response << endl;
    beepOk();
    factors = trial.getNext();

    trialMode=FIXATIONMODE;
    translationTimer.start();
    responseTimer.start();
    trialNumber++;
    glutPostRedisplay();
}
예제 #5
0
/*** FUNCTIONS FOR TRIAL MODE DRAWING ***/
void advanceTrial()
{
    switch (trialMode)
    {
    case FIXATIONMODE:
    {
        stimulusTimer.start();
        clearAndWait(2);
        trialMode=STIMULUSMODE;
    }
        break;
    case STIMULUSMODE:
    {
        trialMode=PROBEMODE;
        stimulusTimer.start();
    }
        break;
    case PROBEMODE:
    {
        responseTimer.start();
        trialMode=FIXATIONMODE;
    }
    }
    factors = trial.getNext();
}
예제 #6
0
void initTrial()
{
	factors = trial.getNext();
	isStimulusDrawn=false;
	letStimTimer=false;
	endTrial=false;
	drawGLScene();
	initProjectionScreen(factors["AbsDepth"]);
	#ifdef OBJMOVE
	Vector3d pos(0,-41,factors["AbsDepth"]);
	moveObjectAbsolute(pos, centercal, 5000);
	#endif
	beepOk(0);
	occludedFrames=0;
	xedge = 0;
	zedge = 0;
	jitter = unifRand(str2num<double>(parameters.find("SideLowBound")),
		str2num<double>(parameters.find("SideUpBound")));

	if(factors["AbsDepth"]==-270)
	{
		if(factors["RelDepth"]==30)
		{
			estsize = str2num<double>(subjParams.find("s30@270"));
			estdepth = str2num<double>(subjParams.find("d30@270"));
		}else if(factors["RelDepth"]==40)
		{
			estsize = str2num<double>(subjParams.find("s40@270"));
			estdepth = str2num<double>(subjParams.find("d40@270"));
		}
		else if(factors["RelDepth"]==50)
		{
			estsize = str2num<double>(subjParams.find("s50@270"));
			estdepth = str2num<double>(subjParams.find("d50@270"));
		}
	} else if(factors["AbsDepth"]==-450)
	{
		if(factors["RelDepth"]==30)
		{
			estsize = str2num<double>(subjParams.find("s30@450"));
			estdepth = str2num<double>(subjParams.find("d30@450"));
		}
		else if(factors["RelDepth"]==40)
		{
			estsize = str2num<double>(subjParams.find("s40@450"));
			estdepth = str2num<double>(subjParams.find("d40@450"));
		}
		else if(factors["RelDepth"]==50)
		{
			estsize = str2num<double>(subjParams.find("s50@450"));
			estdepth = str2num<double>(subjParams.find("d50@450"));
		}
	}

	timer.start();
	isStimulusDrawn=true;
}
예제 #7
0
void mouseFunc(int button, int state, int _x , int _y)
{
    if ( trialMode == PROBEMODE )
    {
        glutWarpPointer(SCREEN_WIDTH/2,SCREEN_HEIGHT/2);

        if ( button == GLUT_LEFT_BUTTON && (state==GLUT_DOWN) )
            probeAngle+=90;
        if ( button == GLUT_RIGHT_BUTTON && (state==GLUT_DOWN) )
            probeAngle-=90;

        if( button== GLUT_MIDDLE_BUTTON  )
        {
            double responseTime=responseTimer.getElapsedTimeInMilliSec();
            double clickDelay=100;	//milliseconds before the click is valid
            if ( responseTime > clickDelay )
            {
                timeFrame=0.0; //this put the stimulus in the center each central time mouse is clicked in
                bool contraction = ( factors["Tilt"]==90 ) || (factors["Tilt"]==0);
                double angleResponse = (mod(probeAngle+probeStartingAngle,360));
                if ( trial.getRemainingTrials()==0 )
                {
                    responseFile << setw(6) << left <<  trialNumber << " " << factors["Def"] <<" " << factors["Tilt"] <<" " << factors["Slant"] << " " << factors["Anchored"] <<  " " << factors["FollowingSpeed"] << " " << factors["Onset"] << " " << (focalDistance - eyeCalibration.z()) << " " << angleResponse << " " << responseTime << " " << contraction << endl;
                    cleanup();
                    exit(0);
                }
                else
                {
                    responseFile << setw(6) << left <<  trialNumber << " " << factors["Def"] <<" " << factors["Tilt"] <<" " << factors["Slant"] << " " << factors["Anchored"] << " " << factors["FollowingSpeed"] << " " << factors["Onset"] << " " << (focalDistance - eyeCalibration.z()) << " " << angleResponse << " " << responseTime << " " << contraction << endl;
                    factors = trial.getNext();
                    trialNumber++;
                }
                advanceTrial();

                double possibleAngles[]= {0,90,180,270};
                probeStartingAngle=possibleAngles[rand()%4];
                probeAngle=0;
                if ( atoi(parameters.find("DrawOccluder").c_str()) ==1 )
                {
                    redDotsPlane.setNpoints(500);  //XXX controllare densita di distribuzione dei punti
                    redDotsPlane.setDimensions(200,200,0.1);
                }
                else
                {
                    redDotsPlane.setNpoints(75);  //XXX controllare densita di distribuzione dei punti
                    redDotsPlane.setDimensions(50,50,0.1);
                }
                //redDotsPlane.setSlantTilt( factors["Slant"], (int) factors["Tilt"] );
                redDotsPlane.compute();
                stimDrawer.initList(&redDotsPlane);
                mouseButton=0;
            }
        }
    }
    glutPostRedisplay();
}
예제 #8
0
void advanceTrial()
{
	double timeElapsed = timer.getElapsedTimeInMilliSec();
	responseFile.precision(3);
    responseFile << 
					parameters.find("SubjectName") << "\t" <<
					//interoculardistance << "\t" <<
					trialNumber << "\t" <<
					stimPosn << "\t" <<
					trial.getCurrent()["RodVisibleTime"] << "\t" <<
					trial.getCurrent()["AbsDepth"] <<"\t" <<
                    //"50" << "\t" <<//trial.getCurrent()["ObjHeight"] <<"\t" <<
                    timer.getElapsedTimeInMilliSec() << "\t" <<
					//trial.getCurrent()["HapticFB"] << "\t" <<
					//randCond << "\t" <<
					//randIncrement << "\t" <<
					stimCond << "\t" <<
					BG_WHITE << "\t" <<
					endl;
	
	trialFile.close();

	double percent_occluded_frames = num_lost_frames/TGA_frame;
	bool not_enough_frames = percent_occluded_frames > 0.20;
	cout << num_lost_frames << "_" << frameN << "_" << percent_occluded_frames << endl;
	int overwrite = 0;

	if (training || !reachedObject || not_enough_frames ) {
		cout << training << "_" << !reachedObject << "_" << not_enough_frames << endl;
		map<std::string,double> currentFactorsList = trial.getCurrent();
		trial.reinsert(currentFactorsList);
		beepOk(1);
		overwrite = 1;
	}

	if( !trial.isEmpty() )
	{
		if (!overwrite)
			trialNumber++;
		cout << trialNumber << endl;
		factors = trial.getNext();
		initTrial();
	}
	else
	{
		exit(0);
	}

}
예제 #9
0
void initTrial()
{
	factors = trial.getNext();
	fingersAtStart=true;
	endTrial=false;
	
	if (factors["ViewingCondition"]==1)			// all binocular
	{
		viewTransportLeft = 1.0;
		viewTransportRight = 1.0;
		viewPointingLeft = 1.0;
		viewPointingRight = 1.0;
	}
	if (factors["ViewingCondition"]==2)	// all monocular
	{
		viewTransportLeft = 0.0;
		viewTransportRight = 1.0;
		viewPointingLeft = 0.0;
		viewPointingRight = 1.0;
	}
	if (factors["ViewingCondition"]==3)	// binocular then dark
	{
		viewTransportLeft = 1.0;
		viewTransportRight = 1.0;
		viewPointingLeft = 0.0;
		viewPointingRight = 0.0;
	} 
	
	if (factors["ViewingCondition"]==4)	// monocular then dark
	{
		viewTransportLeft = 0.0;
		viewTransportRight = 1.0;
		viewPointingLeft = 0.0;
		viewPointingRight = 0.0;
	}

	initProjectionScreen(-400);
	Vector3d pos(0,-250,factors["AbsDepth"]);
	moveObjectAbsolute(pos, centercal, 5000);

	drawGLScene();

	beepOk(0);
	timer.start();

}
void initVariables()
{   trial.init(parameters);
// module factor: 0 -> 1 -> 2
    module.init(1,false);

    module.addFactor("Phase",str2num<int>(parameters.find("Phase"),","));
    block = module.getNext();

    if ( parameters.exists("StimulusDensity") )
        stimulusDensity = str2num<double>(parameters.find("StimulusDensity"));
    else
        cerr << "Stimulus density parameters not found, set to 0.025..." << endl;

    adaptStimHeight = str2num<double>(parameters.find("AdaptStimulusHeight"));
    adaptStimRadius = str2num<double>(parameters.find("AdaptStimulusRadius"));

// crea la lista degli offset in adaptation dati start, end e numero steps
    int nTrials = str2num<int>(parameters.find("AdaptTrials"));
    double adaptOffsetStart = str2num<double>(parameters.find("AdaptOffsetStart"));
    double adaptOffsetEnd = str2num<double>(parameters.find("AdaptOffsetEnd"));
    int adaptOffsetNSteps = str2num<int>(parameters.find("AdaptOffsetSteps"));
    if ( adaptOffsetNSteps > nTrials )
    {   cerr << "too much steps, they must be at max " << nTrials << endl;
        cin.ignore(1e6,'\n');
        exit(0);
    }

    double adaptOffsetDelta = (adaptOffsetEnd - adaptOffsetStart)/adaptOffsetNSteps;
    for (int i=0; i<= adaptOffsetNSteps ; i++)
        adaptOffsets.push_back(i*adaptOffsetDelta+adaptOffsetStart);
    while ( adaptOffsets.size() != nTrials+2 ) //+2 così non rogna nel markersFile
        adaptOffsets.push_back(adaptOffsetEnd );

    testStimHeight = str2num<double>(parameters.find("TestStimulusHeight"));

    ballRadius = str2num<double>(parameters.find("BallRadius"));
    initStimulus(adaptStimHeight,adaptStimRadius*2,adaptStimRadius*2);

    hapticRodCenter = Vector3d(0,0,focalDistance);

    indexInside[0]=indexInside[1]=false;
    globalTimer.start();
    frameTimer.start();

    //trial.print(cerr);
}
예제 #11
0
void initVariables()
{
    interoculardistance = str2num<double>(parameters.find("IOD"));
    trial.init(parameters);
    factors = trial.getNext(); // Initialize the factors in order to start from trial 1

    redDotsPlane.setNpoints(75);  //XXX controllare densita di distribuzione dei punti
    redDotsPlane.setDimensions(50,50,0.1);

    redDotsPlane.compute();
    //stimDrawer.drawSpecialPoints();
    stimDrawer.setSpheres(true);
    stimDrawer.setStimulus(&redDotsPlane);
    stimDrawer.initList(&redDotsPlane);
    /** Bound check things **/
    signs.push_back(false);
    signs.push_back(false);
    rythmMaker.start();
}
예제 #12
0
void mouseFunc(int button, int state, int _x , int _y)
{
    if ( trialMode == PROBEMODE )
    {
        glutWarpPointer(SCREEN_WIDTH/2,SCREEN_HEIGHT/2);

        if ( button == GLUT_LEFT_BUTTON && (state==GLUT_DOWN) )
            mouseButton=1;
        if ( button == GLUT_RIGHT_BUTTON && (state==GLUT_DOWN) )
            mouseButton=-1;

        if( (button== GLUT_LEFT_BUTTON || button==GLUT_RIGHT_BUTTON) && (state==GLUT_UP) && (mouseButton!=0) )
        {
            double responseTime=responseTimer.getElapsedTimeInMilliSec();
            double clickDelay=100;	//milliseconds before the click is valid
            if ( responseTime > clickDelay )
            {
                timeFrame=0.0; //this put the stimulus in the center each central time mouse is clicked in
                if ( trial.isEmpty() )
                {
                    responseFile << setw(6) << left <<  trialNumber << " " << factors["Def"] <<" " << factors["Tilt"] <<" " << factors["Slant"] << " " << factors["Anchored"] << " " << factors["RotationSpeed"] << " " << factors["FollowingSpeed"] << " " << factors["Onset"] << " " << (focalDistance - eyeCalibration.z()) << " " << mouseButton << " " << responseTime << endl;
                    cleanup();
                    exit(0);
                }
                else
                {
                    responseFile << setw(6) << left <<  trialNumber << " " << factors["Def"] <<" " << factors["Tilt"] <<" " << factors["Slant"] << " " << factors["Anchored"] << " " << factors["RotationSpeed"] << " " << factors["FollowingSpeed"] << " " << factors["Onset"] << " " << (focalDistance - eyeCalibration.z()) << " " << mouseButton << " " << responseTime << endl;
                    factors = trial.getNext();
                    trialNumber++;

                }
                advanceTrial();
                redDotsPlane.setDimensions(50,50,0.1);
                redDotsPlane.setSlantTilt(factors["Slant"], factors["Tilt"] );
                redDotsPlane.compute();
                stimDrawer.initList(&redDotsPlane);
                mouseButton=0;
            }
        }
    }
    glutPostRedisplay();
}
예제 #13
0
void initTrial()
{
	factors = trial.getNext();
	isStimulusDrawn=false;
	drawGLScene();
	initProjectionScreen(factors["AbsDepth"]);
	//Vector3d pos(0, -44, (str2num<double>(parameters.find("StartPosObj"))+factors["RelDepthObj"]));
	//moveObjectAbsolute(pos, centercal, 5000);
	//positionObj(pos);
	if(trialNumber%24==0)
		beepOk(1);
	else
		beepOk(0);
	xedge = 0;
	zedge = 0;
	jitter = unifRand(str2num<double>(parameters.find("VirtualObjRelDepthLowBound")),
		str2num<double>(parameters.find("VirtualObjRelDepthUpBound")));
	timer.start();
	isStimulusDrawn=true;
}
예제 #14
0
void initTrial()
{
	factors = trial.getNext();
	screenAtDistance=false;
	isStimulusDrawn=false;
	initProjectionScreen(factors["AbsDepth"]);
	if(	screenAtDistance )
		endTrial=false;
		timer.start();
		drawGLScene();
	#ifdef OBJMOVE
	Vector3d pos(0,-41,factors["AbsDepth"]);
	moveObjectAbsolute(pos, centercal, 5000);
	#endif
	//beepOk(1);
	beepOk(2);
	occludedFrames=0;
	xedge = 0;
	zedge = 0;
	jitter = unifRand(str2num<double>(parameters.find("SideLowBound")),
		str2num<double>(parameters.find("SideUpBound")));

}
예제 #15
0
void keyPressed()
{
    if ( trialMode == PROBEMODE )
    {
        if ( trialNumber==0)
        {   responseFile << setw(6) << left <<
                         "TrialNumber Tilt Slant Translation Onset TranslationConstant EyeCalx EyeCaly EyeCalz StimFrames ProbeAngle" << endl;
        }
        stimulusDuration.stop();
        responseFile << setw(6) << left <<
                     trialNumber << " " <<
                     factors["Tilt"] << " "  <<
                     factors["Slant"] << " " <<
                     factors["Translation"] << " " <<
                     factors["Onset"] << " " <<
                     factors["TranslationConstant"] << " " <<
                     eyeCalibration.transpose() << " " <<
                     stimulusFrames << " " <<
                     probeAngle << endl;
        if ( trial.getRemainingTrials()==0 )
        {
            cleanup();
            exit(0);
        }
        else
        {
            factors = trial.getNext();
            trialNumber++;
        }
        trialMode++;
        trialMode=trialMode%4;
        double possibleAngles[]= {0,90,180,270};
        probeStartingAngle=possibleAngles[rand()%4];
        redDotsPlane.compute();
        stimDrawer.initList(&redDotsPlane);
    }
}
예제 #16
0
void initVariables()
{
    totalTimer.start();
    interoculardistance = str2num<double>(parameters.find("IOD"));
    trial.init(parameters);
    factors = trial.getNext(); // Initialize the factors in order to start from trial 1

    // Imposta stimolo e drawer
    redDotsPlane.setNpoints(75);
    redDotsPlane.setDimensions(50,50,0.1);
    redDotsPlane.compute();
    stimDrawer.initList(&redDotsPlane,glRed);

    // Imposta striscia del fixation e drawer
    stripPlane.setNpoints(N_STRIP_POINTS);
    stripPlane.setDimensions(STRIP_WIDTH,STRIP_HEIGHT,0.01);
    stripPlane.compute();
    stripDrawer.initList(&stripPlane,glRed);

    stimMotion=SINUSOIDAL_MOTION;

    headEyeCoords.init(Vector3d(-32.5,0,0),Vector3d(32.5,0,0), Vector3d(0,0,0),Vector3d(0,10,0),Vector3d(0,0,10),interoculardistance );
    eyeCalibration=headEyeCoords.getRightEye();
}
예제 #17
0
// Funzione di callback per gestire pressioni dei tasti
void handleKeypress(unsigned char key, int x, int y)
{   switch (key)
    {   //Quit program
	case 'x':
		// Facendo cosi si cancella lo stimolo durante il movimento (SINCRONO) del monitor.
		// Si imposta il isStimulusDrawn a FALSE e si riaggiorna la schermata con una drawGLScene()
		// infine si muove il monitor, la chiamata blocca il programma per x secondi, si 
		// simula lo spostamento dello schermo di proiezione ed infine si reimposta isStimulusDrawn a TRUE
		// cosi' la prossima chiamata di drawStimulus() lo disegna correttamente a schermo. Provare per credere...
		factors = trial.getNext();
		isStimulusDrawn=false;
		drawGLScene();
		initProjectionScreen(factors["AbsDepth"]);
		isStimulusDrawn=true;
		break;
	case 'i':
		visibleInfo=!visibleInfo;
		break;
	case 'm':
		interoculardistance += 0.5;
	break;
	case 'n':
		interoculardistance -= 0.5;
	break;
	case '+':
	{
		// Il trucco per avanzare alla modalita' trial successiva: incrementi di uno e poi tieni il resto della 
		// divisione per due, in questo caso ad esempio sara' sempre:
		// 0,1,0,1,0,1
		// se metti il resto della divisione per 3 invece la variabile trialMode sar'
		// 0,1,2,0,1,2
		// ogni ciclo della variabile trialMode normalmente e' un trial (1)
		// puoi anche definire una funzione void advanceTrial() che si occupa di andare al trial successivo,
		// deve contenere una chiamata alla BalanceFactor::getNext() cosi' passi alla nuova lista di fattori
		// Ad esempio
		// trialMode++;
		// trialMode=trialMode%3;
	}
	break;
	case 'Q':
	case 'q':
    case 27:	//corrisponde al tasto ESC
    {   
		// Ricorda quando chiami una funzione exit() di chiamare prima cleanup cosi
		// spegni l'Optotrak ed i markers (altrimenti loro restano accesi e li rovini) 
		cleanup();
        exit(0);
    }
    break;
    case ' ':
    {
        // Here we record the head shape - coordinates of eyes and markers, but centered in (0,0,0)
        if ( headCalibrationDone==0 && allVisiblePatch )
        {
            headEyeCoords.init(markers[1].p-Vector3d(230,0,0),markers[1].p, markers[5].p,markers[6].p,markers[7].p,interoculardistance );
            headCalibrationDone=1;
			beepOk(0);
            break;
        }
        // Second calibration, you must look a fixed fixation point
        if ( headCalibrationDone==1 && allVisiblePatch )
        {
            headEyeCoords.init( headEyeCoords.getP1(),headEyeCoords.getP2(), markers[5].p, markers[6].p,markers[7].p,interoculardistance );
            headCalibrationDone=2;
            break;
        }
    }
    break;
    // Enter key: press to make the final calibration
    case 13:
    {
        if ( headCalibrationDone == 2 && allVisiblePatch )
        {
            headEyeCoords.init( headEyeCoords.getP1(),headEyeCoords.getP2(), markers[1].p, markers[2].p,markers[3].p,interoculardistance );
            headCalibrationDone=3;
			visibleInfo=false;
        }
    }
    break;
      case '5':
      {  
		  zedge -= .25;
	  }
      break;
      case '8':
      {  
		  zedge += .25;
      }
      break;
      case '4':
      {  
		  xedge += .25;
      }
      break;
      case '6':
      {  
		  xedge -= .25;
	  }
      break;
	  case '0':
	  {
		  advanceTrial();
	  }
	  break;
	  // In genere a me piace attaccare al tasto p una funzione che stampi 
	  // le tue variabili di interesse su standard output ad esempio la lista dei fattori attuali con nome
    case 'p':
	{
		for (map<string,double>::iterator iter = factors.begin(); iter!=factors.end(); ++iter )
		{
			cout << iter->first << " " << iter->second << endl;
		}
	}
	break;
	}
}
예제 #18
0
// Funzione di callback per gestire pressioni dei tasti
void handleKeypress(unsigned char key, int x, int y)
{   switch (key)
    {   //Quit program
	case 'x':
		// Facendo cosi si cancella lo stimolo durante il movimento (SINCRONO) del monitor.
		// Si imposta il isStimulusDrawn a FALSE e si riaggiorna la schermata con una drawGLScene()
		// infine si muove il monitor, la chiamata blocca il programma per x secondi, si 
		// simula lo spostamento dello schermo di proiezione ed infine si reimposta isStimulusDrawn a TRUE
		// cosi' la prossima chiamata di drawStimulus() lo disegna correttamente a schermo. Provare per credere...
		//factors = trial.getNext();
	//	trial.next();
		drawGLScene();
//		initProjectionScreen(trial.getCurrent()["AbsDepth"]);
		break;
	case 'i':
		visibleInfo=!visibleInfo;
		break;
	case 'm':
		interoculardistance += 0.5;
	break;
	case 'n':
		interoculardistance -= 0.5;
	break;
	case '+':
	{
		// Il trucco per avanzare alla modalita' trial successiva: incrementi di uno e poi tieni il resto della 
		// divisione per due, in questo caso ad esempio sara' sempre:
		// 0,1,0,1,0,1
		// se metti il resto della divisione per 3 invece la variabile trialMode sar'
		// 0,1,2,0,1,2
		// ogni ciclo della variabile trialMode normalmente e' un trial (1)
		// puoi anche definire una funzione void advanceTrial() che si occupa di andare al trial successivo,
		// deve contenere una chiamata alla BalanceFactor::getNext() cosi' passi alla nuova lista di fattori
		// Ad esempio
		 trialMode++;
		 trialMode=trialMode%4;
	}
	break;
	case 'Q':
	case 'q':
    case 27:	//corrisponde al tasto ESC
    {   
		// Ricorda quando chiami una funzione exit() di chiamare prima cleanup cosi
		// spegni l'Optotrak ed i markers (altrimenti loro restano accesi e li rovini) 
		cleanup();
        exit(0);
    }
    break;
	case 'd':
		{
		fingersShown = !fingersShown;
		}
	break;
    case ' ':
    {
        // Here we record the head shape - coordinates of eyes and markers, but centered in (0,0,0)
        if ( headCalibrationDone==0 && allVisiblePatch )
        {
            headEyeCoords.init(markers[1].p-Vector3d(230,0,0),markers[1].p, markers[5].p,markers[6].p,markers[7].p,interoculardistance );
            headCalibrationDone=1;
			beepOk(0);
            break;
        }
        // Second calibration, you must look a fixed fixation point
        if ( headCalibrationDone==1 && allVisiblePatch )
        {
            headEyeCoords.init( headEyeCoords.getP1(),headEyeCoords.getP2(), markers[5].p, markers[6].p,markers[7].p,interoculardistance );
            headCalibrationDone=2;
            break;
        }
    }
    break;
	case 'f':
	case 'F':
		{
		// Here we record the finger tip physical markers
		if ( allVisiblePlatform && (fingerCalibrationDone==0) )
			{
			//platformFingers=markers[1].p;
			platformIndex=markers[1].p;
			platformThumb=markers[2].p;
			//centercal = markers[4].p;
			fingerCalibrationDone=1;
			beepOk(0);
			break;
			}
		if ( (fingerCalibrationDone==1) && allVisibleFingers )
			{
			indexCoords.init(platformIndex, markers.at(13).p, markers.at(14).p, markers.at(16).p );
			thumbCoords.init(platformThumb, markers.at(15).p, markers.at(17).p, markers.at(18).p );
			fingerCalibrationDone=2;
			beepOk(0);
			break;
			}
		if ( fingerCalibrationDone==2  && allVisibleFingers )
			{
			beepOk(0);
			fingerCalibrationDone=3;
			visibleInfo=!visibleInfo;
			factors = trial.getNext();
			initTrial();
			break;
			}
		}
		break;
    // Enter key: press to make the final calibration
    case 13:
    {
        if ( headCalibrationDone == 2 && allVisiblePatch )
        {
            headEyeCoords.init( headEyeCoords.getP1(),headEyeCoords.getP2(), markers[5].p, markers[6].p,markers[7].p,interoculardistance );
            headCalibrationDone=3;
			visibleInfo=false;
        }
    }
    break;
      case '5':
      {  
		  alignmentY -= .5;
	  }
      break;
      case '8':
      {  
		alignmentY += .5;
      }
      break;
	  case '4':
      {  
		  alignmentX -= .5;
	  }
      break;
      case '6':
      {  
		alignmentX += .5;
      }
	  break;
	  case '1':
      {  
		  stim_translation_z -= 1;
	  }
      break;
      case '3':
      {  
		stim_translation_z += 1;
      }
	  break;
      case 's':
      {  
		  advanceTrial();
	  }
      break;
	  case '0':
	  {
		 training=!training;
	  }
	  break;
	  case 'c':
	  {
		 pulsingColors=!pulsingColors;
	  }
	  break;
	  case 'l':
	  {
		 cout << left_height << "\t" << right_height << endl;
	  }
	  break;
	  case 'v':
	  {
		  stim_vanish_when_reached=!stim_vanish_when_reached;
	  }
	  break;
	  case 'w':
	  {
		 BG_WHITE=(BG_WHITE+1)%2;
	  }
	}
}
예제 #19
0
void handleKeypress(unsigned char key, int x, int y)
{   switch (key)
    {   //Quit program
    case 'q':
    case 27:
    {   cleanup();
        exit(0);
    }
    break;
    case ' ':
    {   // Here we record the head shape - coordinates of eyes and markers, but centered in (0,0,0)
        if ( headCalibrationDone==0 && allVisibleHead )
        {   headEyeCoords.init(markers.at(17).p,markers.at(18).p, markers.at(1).p,markers.at(2).p,markers.at(3).p,interoculardistance );
            headCalibrationDone=1;
            beepOk();
            break;
        }
        if ( headCalibrationDone==1 && allVisiblePatch )
        {
            headCalibrationDone=3;
            beepOk();
        }
    }
    break;
    case 'i':
        infoDraw=!infoDraw;
        break;
    case 'f':
    case 'F':
    {   // Here we record the finger tip physical markers
        if ( allVisiblePlatform && (fingerCalibrationDone==0) )
        {   platformIndex=markers.at(16).p;
            platformThumb=markers.at(15).p;
            fingerCalibrationDone=1;
            beepOk();
            break;
        }
        if ( (fingerCalibrationDone==1) && allVisibleFingers )
        {   thumbCoords.init(platformThumb, markers.at(11).p, markers.at(12).p, markers.at(13).p);
            indexCoords.init(platformIndex, markers.at(7).p, markers.at(8).p, markers.at(9).p );
            fingerCalibrationDone=2;
            beepOk();
            break;
        }
        if ( fingerCalibrationDone==2  && allVisibleFingers )
        {   infoDraw=false;
            drawGLScene();
            physicalRigidBodyTip = indexCoords.getP1().p;
            fingerCalibrationDone=3;

            switch ( block.at("Phase") )
            {
            case 0:
            case 2:
            {   factors = trial.getNext();
                initStimulus(testStimHeight,testStimRadius);
                moveScreenAbsolute(factors.at("Distances"),homeFocalDistance,SCREENSPEED);
                initProjectionScreen(factors.at("Distances"));
                visualRodCenter = Vector3d(0,0,factors.at("Distances"));
                hapticRodCenter = rodAway;	// keep it away
                moveRod(rodAway,RODSPEED);
            }
            break;
            case 1:
            {   double zadaptmin = str2num<double>(parameters.find("AdaptZMin"));
                double zadaptmax = str2num<double>(parameters.find("AdaptZMax"));

                if (str2num<int>(parameters.find("AdaptMoveMonitor"))==1)
                    visualRodCenter = Vector3d(0,0,mathcommon::unifRand(zadaptmin,zadaptmax));
                else
                    visualRodCenter = Vector3d(0,0,(zadaptmax+zadaptmin)/2);

                if ( str2num<int>(parameters.find("AdaptHapticFeedback"))==1 )
                    hapticRodCenter = visualRodCenter - Vector3d(0,0,adaptOffsets.at(block1TrialNumber));
                else
                    hapticRodCenter = rodAway;

                initProjectionScreen( visualRodCenter.z() );
                initStimulus(str2num<double>(parameters.find("AdaptStimulusHeight")),str2num<double>(parameters.find("AdaptStimulusRadius")));
                moveScreenAbsoluteAsynchronous(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                moveRod(hapticRodCenter,RODSPEED);
            }
            break;
            }
            trialMode = HANDONSTARTMODE;
            fingerDistance = (indexCoords.getP1().p-thumbCoords.getP1().p).norm();
            beepTrial();
            trialFrame=0;
            globalTimer.start();
            totalTime.start();
            break;
        }
    }
    break;
    }
}
예제 #20
0
void advanceTrial()
{   if ( trialMode == STIMULUSMODE )
    {   bool pretrialMode=trialMode;
        trialMode++;
        trialMode=trialMode%2;
        totalTrialNumber++;

        if (block.at("Phase") != 1 )
        {
            double percentOccludedFrames = ((double)occludedFrames/(double)drawingTrialFrame )*100.0;
            if ( percentOccludedFrames > str2num<double>(parameters.find("TestPercentOccludedFrames")) )
            {
                cerr << "Percent occluded frames is" << percentOccludedFrames << " " << occludedFrames << " over " << drawingTrialFrame << endl;
                trial.reinsert(factors);

            }
            drawingTrialFrame=0;
            occludedFrames=0;
        }
        trialFrame=0;
        switch( block.at("Phase") )
        {
        case 0:  //pre-test
        {
            if ( !trial.isEmpty() )	// ci son ancora trial
            {   beepTrial();
                initStimulus(testStimHeight,testStimRadius);
                factors = trial.getNext();
                deltaXRods = mathcommon::unifRand(str2num<double>(parameters.find("DeltaXMin")),str2num<double>(parameters.find("DeltaXMax")));
                visualRodCenter = Vector3d(0,0,factors.at("Distances"));
                hapticRodCenter  = rodAway;
                initProjectionScreen(visualRodCenter.z());
                moveScreenAbsolute(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                beepTrial();
            }
            else // si prepara per la modalità 1 (adaptation)
            {   trialMode = HANDONSTARTMODE;
                block = module.getNext();
                initStimulus(testStimHeight,testStimRadius );
                double zadaptmin = str2num<double>(parameters.find("AdaptZMin"));
                double zadaptmax = str2num<double>(parameters.find("AdaptZMax"));

                if (str2num<int>(parameters.find("AdaptMoveMonitor"))==1)
                    visualRodCenter=Vector3d(0,0,mathcommon::unifRand(zadaptmin,zadaptmax));
                else
                    visualRodCenter=Vector3d(0,0, (zadaptmin+zadaptmax)/2);
                initProjectionScreen( visualRodCenter.z());

                if ( str2num<int>(parameters.find("AdaptHapticFeedback"))==1 )
                    hapticRodCenter = visualRodCenter - Vector3d(0,0,adaptOffsets.at(block1TrialNumber));
                else
                    hapticRodCenter = rodAway;

                moveRod(Vector3d(0,0,hapticRodCenter.z() ),RODSPEED);

                checkBounds();
                beepLong();
            }
            block0TrialNumber++;
        }
        break;
        case 1:  // adaptation
        {
            block1TrialNumber++;
            if ( block1TrialNumber < str2num<int>(parameters.find("AdaptTrials")) )
            {   beepTrial();
                initStimulus(adaptStimHeight,adaptStimRadius);
                double zadaptmin = str2num<double>(parameters.find("AdaptZMin"));
                double zadaptmax = str2num<double>(parameters.find("AdaptZMax"));

                if (str2num<int>(parameters.find("AdaptMoveMonitor"))==1)
                    visualRodCenter = Vector3d(0,0,mathcommon::unifRand(zadaptmin,zadaptmax));
                else
                    visualRodCenter=Vector3d(0,0, (zadaptmin+zadaptmax)/2);

                if ( str2num<int>(parameters.find("AdaptHapticFeedback"))==1 )
                {
                    hapticRodCenter = visualRodCenter - Vector3d(0,0,adaptOffsets.at(block1TrialNumber));
                    moveScreenAbsoluteAsynchronous(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                    moveRod(hapticRodCenter,RODSPEED);
                }
                else
                {
                    hapticRodCenter = rodAway;
                    moveScreenAbsolute(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                }

                initProjectionScreen( visualRodCenter.z());
                beepTrial();
            }
            else
            {   beepLong();
                trialMode = HANDONSTARTMODE;
                block  = module.getNext();
                // reset the factors in order to prepare the next test phase
                trial.init(parameters);
                factors.clear();
                factors  = trial.getNext();
                deltaXRods = mathcommon::unifRand(str2num<double>(parameters.find("DeltaXMin")),str2num<double>(parameters.find("DeltaXMax")));
                //cerr << "DISTANCE= " << factors.at("Distances") << endl;
                initStimulus(testStimHeight,testStimRadius);
                visualRodCenter = Vector3d(0,0,factors.at("Distances"));
                hapticRodCenter = rodAway;

                moveScreenAbsolute(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                moveRod(rodAway,RODSPEED);
                initProjectionScreen(visualRodCenter.z());

                beepTrial();
            }
        }
        break;
        case 2:  /// post-test
        {   if ( trial.isEmpty() )
            {   beepLong();
                cleanup();
                exit(0);
            }
            else
            {   beepTrial();
                initStimulus(testStimHeight,testStimRadius);
                factors = trial.getNext();
                deltaXRods = mathcommon::unifRand(str2num<double>(parameters.find("DeltaXMin")),str2num<double>(parameters.find("DeltaXMax")));
                cerr << "DISTANCE= " << factors.at("Distances") << endl;
                visualRodCenter =  Vector3d(0,0,factors.at("Distances"));
                hapticRodCenter  = rodAway;
                initProjectionScreen(visualRodCenter.z());
                moveScreenAbsolute(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                beepTrial();
            }
            block2TrialNumber++;
        }
        break;
        }
        globalTimer.start();
    }
    // Mettere una idle così non perde il primo trial
    idle();
}
예제 #21
0
/*** FUNCTIONS FOR TRIAL MODE DRAWING ***/
void advanceTrial()
{
    if ( trial.isEmpty() )
    {
#ifdef WIN32
        for (int i=0; i<3; i++)
        {
            Beep(220,440);
            totalTimer.sleep(20);
        }
#endif
        exit(0);
    }

    switch (trialMode)
    {
    case FIXATIONMODE:
    {
#ifdef WIN32
        Beep(440,440);
#endif
        totalTimer.start();
        stimulusTimer.start();
        //clearAndWait(2);
        trialMode=STIMULUSMODE;
    }
    break;
    case STIMULUSMODE:
    {
#ifdef WIN32
        Beep(440,440);
#endif
        trialMode=PROBEMODE;
        totalTimer.start();
        stimulusTimer.start();
    }
    break;
    case PROBEMODE:
    {
#ifdef WIN32
        Beep(880,440);
#endif
        resetPointStrip();
        responseTimer.start();
        totalTimer.start();
        trialMode=FIXATIONMODE;
    }
    }
    resetPointStrip();
    factors = trial.getNext();
    trialNumber++;
    responseFile << setw(6) << left <<
                 trialNumber << "\t" <<
                 factors["Tilt"] << "\t"  <<
                 factors["Slant"] << "\t" <<
                 factors["Def"] << "\t" <<
                 factors["FlowDirection"] << "\t" <<
                 factors["FlowIncrement"] << "\t" << endl;

    double responseTime=responseTimer.getElapsedTimeInMilliSec();
    timeFrame=0.0; //this put the stimulus in the center each central time mouse is clicked in
}
예제 #22
0
void handleKeypress(unsigned char key, int x, int y)
{   switch (key)
    {   //Quit program
    case 'q':
    case 27:
    {   exit(0);
    }
    break;
    case ' ':
    {   // Here we record the head shape - coordinates of eyes and markers, but centered in (0,0,0)
        if ( headCalibrationDone==0 && allVisibleHead )
        {
            headEyeCoords.init(markers.at(18).p-Vector3d(ChinRestWidth,0,0),markers.at(18).p, markers.at(1).p,markers.at(2).p,markers.at(3).p,interoculardistance );
            headCalibrationDone=1;
            beepOk();
            break;
        }
        if ( headCalibrationDone==1 && allVisiblePatch )
        {
            headCalibrationDone=3;
            beepOk();
        }
    }
    break;

    case 'i':
        infoDraw=!infoDraw;
        break;
    case 'f':
    case 'F':
    {   // Here we record the finger tip physical markers
        if ( allVisiblePlatform && (fingerCalibrationDone==0) )
        {
            platformIndex=markers.at(16).p;
            platformThumb=markers.at(15).p;
            fingerCalibrationDone=1;
            beepOk();
            break;
        }
        if ( (fingerCalibrationDone==1) && allVisibleFingers )
        {
            thumbCoords.init(platformThumb, markers.at(11).p, markers.at(12).p, markers.at(13).p);
            indexCoords.init(platformIndex, markers.at(7).p, markers.at(8).p, markers.at(9).p );
            fingerCalibrationDone=2;
            // XXX sposto l'oggetto a home per permettere le dita di calibrarsi
            // TriesteMotorFunctions::homeObject(3500); //// XXX commentato: A TS no servi
            beepOk();
            break;
        }
        if ( fingerCalibrationDone==2  && allVisibleFingers )
        {   infoDraw=false;
            drawGLScene();
            physicalRigidBodyTip = indexCoords.getP1().p;
            fingerCalibrationDone=3;

            switch ( block.at("Phase") )
            {
            case 0:
            {
                cerr << "Key 721 case 0" << endl;
                factors = trial.getNext();
                deltaXRods = mathcommon::unifRand(str2num<double>(parameters.find("DeltaXMin")),str2num<double>(parameters.find("DeltaXMax")));
                initStimulus(factors.at("StimulusHeight"),deltaXRods,factors.at("RelDepth"));
                // moveMonitorAbsolute(factors.at("Distances"),homeFocalDistance,SCREENSPEED);
                initProjectionScreen(factors.at("Distances"));
                visualRodCenter = Vector3d(0,0,factors.at("Distances"));
                hapticRodCenter = rodAway;	// keep it away
                // moveRod(rodAway,RODSPEED);
                cerr << "Key 730 case 0" << endl;
            }
            beepOk();
            break;
            case 2:
            {   factors = trial.getNext();
                deltaXRods = mathcommon::unifRand(str2num<double>(parameters.find("DeltaXMin")),str2num<double>(parameters.find("DeltaXMax")));
                initStimulus(factors.at("StimulusHeight"),deltaXRods,factors.at("RelDepth"));
                // moveMonitorAbsolute(factors.at("Distances"),homeFocalDistance,SCREENSPEED);
                initProjectionScreen(factors.at("Distances"));
                visualRodCenter = Vector3d(0,0,factors.at("Distances"));
                hapticRodCenter = rodAway;	// keep it away
                // moveRod(rodAway,RODSPEED);
            }
            break;
            case 1:
            {
                cerr << "Key 735 case 1" << endl;
                double zadaptmin = str2num<double>(parameters.find("AdaptZMin"));
                double zadaptmax = str2num<double>(parameters.find("AdaptZMax"));

                if (str2num<int>(parameters.find("AdaptMoveMonitor"))==1)
                    visualRodCenter = Vector3d(0,0,mathcommon::unifRand(zadaptmin,zadaptmax));
                else
                    visualRodCenter = Vector3d(0,0,(zadaptmax+zadaptmin)/2);

                if ( str2num<int>(parameters.find("AdaptHapticFeedback"))==1 )
                    hapticRodCenter = visualRodCenter - Vector3d(0,0,adaptOffsets.at(block1TrialNumber));
                else
                    hapticRodCenter = rodAway;

                initProjectionScreen( visualRodCenter.z() );
                initStimulus(str2num<double>(parameters.find("AdaptStimulusHeight")),adaptStimRadius*2,adaptStimRadius*2);
                moveMonitorAbsoluteAsynchronous(visualRodCenter.z(),homeFocalDistance,SCREENSPEED);
                moveRod(hapticRodCenter,RODSPEED);
            }
            break;
            }
            cerr << "Key 756 " << endl;
            trialMode = HANDONSTARTMODE;
            cerr << "Key 758 " << endl;
            fingerDistance = (indexCoords.getP1().p-thumbCoords.getP1().p).norm();
            cerr << "Key 760 " << endl;
            beepTrial();
            cerr << "Key 762 " << endl;
            trialFrame=0;
            globalTimer.start();
            totalTime.start();
            break;
        }
    }
    break;
    }
}
void advanceTrial()
{
	// Determine if previous trial was a good trial
	double percentOccludedFrames = numLostFrames/TGA_frame;
	bool notEnoughFrames = percentOccludedFrames > 0.10 ;
	int overwrite = 0;

	// If any of these things are true when advanceTrial is called, reinsert!
	if (training || !reachedObject || notEnoughFrames ) {
        beepOk(3); // 1000hz, 50ms
		if (training)
			cout << "Training Mode!" << endl;
		if (!reachedObject)
			cout << "I don't think you reached the object..." << endl;
		if (notEnoughFrames)
			cout << "Be visible!" << endl;

		if (!controlCondition) {
			map<std::string,double> currentFactorsList = trial.getCurrent();
			trial.reinsert(currentFactorsList);
		}

		overwrite = 1;
	}

	// Write previous trial to response file
	if (!overwrite && !controlCondition)
	{
		responseFile.precision(3);
		responseFile << 
						parameters.find("SubjectName") << "\t" <<
						trialNumber << "\t" <<
						TGA_time << "\t" <<
						trial.getCurrent()["ObjPosn"] << "\t" <<
                        sm_lg << "\t" <<
						con_inc << "\t" <<
						endl;
	} else if (!overwrite && controlCondition) {
		controlResponseFile.precision(3);
		controlResponseFile << 
						parameters.find("SubjectName") << "\t" <<
						controlTrial << "\t" <<
						TGA_time << "\t" <<
						currentObj << "\t" <<
                        sm_lg << "\t" <<
						con_inc << "\t" <<
						endl;
	}

	// Close previous trial file
	trialFile.close();

	// If we're done with control block
	if (controlCondition && controlTrial==16) {
		if (!overwrite) { // and not overwriting, change over
			plato_stop();
			exit(0);
			//controlCondition=false;
			//endControl=true;
		}
		else // if we ARE overwriting, initTrial again until we get it
			initTrial();
	}
	// If we're still in the control block
	if (controlCondition && controlTrial<16 ){
		if (!overwrite) //and not overwriting
			controlTrial++; //increment
		initTrial(); //initTrial will handle a repeat or the next trial
	}
	// If we're in the main block
	if( !trial.isEmpty() && !controlCondition)
	{
		if (!endControl) { // If it's NOT the v. first main block trial
			if (!overwrite) // and we're not overwriting due to a bad trial
				trialNumber++; // increment
			factors = trial.getNext(); // get the next trial and initialize it!
			initTrial();
		} else { // It IS the v. first main block trial (endControl)
			endControl=false; // turn this switch off so we know next time around that it's trial 1
			initTrial(); // initTrial WITHOUT getNext because we already gotNext at the end of calibration
		}
	}
	// Finally, if we're out of trials, finish the experiment.
	else if (trial.isEmpty() && !controlCondition)
	{
		controlCondition=true;
		initTrial();
	}
}
예제 #24
0
int main(void)
{  randomizeSeed();
   /*
   BalanceFactor<int> balance;
   map<string,int> factors;
   balance.init(1,true);
   vector<int> f;
   for (int i=0; i<10; i++)
   f.push_back(i);

   balance.addFactor( "Slant",  f );
   while ( !balance.isEmpty() )
   {
       factors = balance.getNext();
       cout << factors["Slant"] << endl;
   }
   balance.init(1,true);
   cerr << "==========" << endl;
   f.clear();
   for (int i=0; i<10; i++)
   f.push_back(i);

   balance.addFactor( "Slant",  f );
   while ( !balance.isEmpty() )
   {
       factors = balance.getNext();
       cout << factors["Slant"] << endl;
   }
   */
   /*
   balance.addFactor( "Tilt", vlist_of<int>(90) );
   balance.addFactor( "Anchored", vlist_of<int>(0)(1)(2)(3));

   //balance.print();

   while ( !balance.isEmpty() )
   {
         map<string, int> tmp2 = balance.getNext() ;
         for ( map<string, int>::iterator iter = tmp2.begin(); iter!=tmp2.end(); ++iter)
         cout << iter->first << " " << iter->second << " ";
         cout << endl;
   }

   cerr << isnan(1.0/0.0) << " " << isinf(1.0/0.0) << endl;
    return 0;
    */
   map<string,int> factors;
   ifstream paramFile;
   paramFile.open("prova.exp");

   ParametersLoader params;
   params.loadParameterFile(paramFile);
   BalanceFactor<int> bfact;
   bfact.init(params);
   while (!bfact.isEmpty())
   {  factors = bfact.getNext();
      cout << factors["StimSpeed"] << endl;
   }
   //bfact.print();

   bfact.init(params);

   while (!bfact.isEmpty())
   {  factors = bfact.getNext();
      cout << factors["StimSpeed"] << endl;
   }
   /*
   BalanceFactor<int> balance;
   balance.init(params);
   balance.print();

   while ( !balance.isEmpty() )
   {
        map<string,int> vals = balance.getNext();
        for ( map<string,int>::iterator iter = vals.begin(); iter!=vals.end(); ++iter )
        {
        cout << iter->first << " " << iter->second << endl;
        }
        cout << endl << endl;

   }
   */

   return 0;
}
// Funzione di callback per gestire pressioni dei tasti
void handleKeypress(unsigned char key, int x, int y)
{
    switch (key)
    {
            
        case 'x':
        {
            
        }
            break;
            
        case 'i':
        {
            visibleInfo=!visibleInfo;
        }
            break;
            
        case 't':
        {
            training = !training;
        }
            break;
            
        case '*':
        {
            
        }
            break;
            
        case 'q':
        {
            
        }
            break;
            
        case 27: //ESC
        {
            exit(0);
        }
            break;
            
        case 'f':
        {
			if (!objectsForward)
			{
				beepOk(2);
				objectsForward = true;
				RoveretoMotorFunctions::moveObjectAbsolute(mountDisplayPosn, motorHomePosn, 3000);
				break;
			}
            if ( objectsForward && (startPosCalibration==0) && (fingerCalibrationDone==0) && allVisiblePlatform)
            {
                platformIndex=markers[16].p;
                platformThumb=markers[15].p;
                fingerCalibrationDone=1;
                beepOk(2);
                break;
            }
            if ( (startPosCalibration==0) && (fingerCalibrationDone==1) && allVisibleFingers )
            {
                indexCoords.init(platformIndex, markers.at(19).p, markers.at(23).p, markers.at(24).p );
                thumbCoords.init(platformThumb, markers.at(20).p, markers.at(21).p, markers.at(22).p );
                fingerCalibrationDone=2;
                beepOk(2);
				break;
            }
			if ( (startPosCalibration==0) && (fingerCalibrationDone==2) && allVisibleFingers) 
            {
                startPos_front = index.z()-20;
                startPos_right = index.x()+20;
                startPos_top = index.y()+20;
				startPos_rear = thumb.z()+20;
                startPos_left = thumb.x()-20;
                startPos_bottom = thumb.y()-20;
                startPosCalibration=1;
                beepOk(2);
                break;
            }
			if (  (startPosCalibration==1) && (fingerCalibrationDone==2)) 
			{
				startPosCalibration = 2;
				beepOk(2);
				RoveretoMotorFunctions::moveObjectAbsolute(showTopMidBoard,motorHomePosn,4000);
				break;
			}
            if ( (startPosCalibration==2) && (fingerCalibrationDone==2) ) 
            {
				objL_X = markers[10].p.x();
				objL_Y = markers[10].p.y();
				objL_Z = markers[10].p.z();
				startPosCalibration=3;
                beepOk(2);
				break;
			}
			if ( (startPosCalibration==3) && (fingerCalibrationDone==2) ) 
            {
				objR_X = markers[10].p.x();
				objR_Y = markers[10].p.y();
				objR_Z = markers[10].p.z();
                startPosCalibration=4;
				beepOk(2);
				break;
			}
			if ( (startPosCalibration==4) && (fingerCalibrationDone==2) && allVisibleFingers) 
            {
                fingerCalibrationDone=3;
                visibleInfo=false;
                training=false;
                factors = trial.getNext();
                initTrial();
                break;
            }
        }
            break;
            
        case 's':
        {
            advanceTrial();
        }
            break;
            
        case '0':
        {
            
        }
            break;
            
        case 'e':
        {
            cout << "Hand at start: " << handAtStart << endl;
            cout << "Started: " << started << endl;
            cout << "Reached Object: " << reachedObject << endl;
        }
            break;
            
        case 'j':
        {
            cout << "Distance to Object: sqrt(" << x_dist << "^2 + " << y_dist << "^2 + " << z_dist << "^2) = " << grip_distanceToTarget << endl;
            cout << "Start Pos Corner: " << startPos_right << "\t" << startPos_top << "\t" << startPos_front << endl;
        }
            break;
            
        case '5': //down
        {
            
        }
            break;
            
        case '8': //up
        {
            
        }
            break;
            
        case '4': //left
        {
            
        }
            break;
            
        case '6': //right
        {
           
        }
            break;
            
        case '1': //left 2
        {  
           
        }
            break;
            
        case '3': //right 2
        {  
            
        }
            break;
            
	}
}