Ejemplo n.º 1
0
void idle()
{
    if (trialNumber >= maxTotalTrials )
        exit(0);
	double elapsedFrameTime = totalTimer.getTimeIntervalInMilliSec();
    optotrak.updateMarkers(elapsedFrameTime);
    markers = optotrak.getAllMarkers();
    headEyeCoords.update(markers[1],markers[2],markers[3],TIMER_MS);

    allVisiblePatch =  markers[1].isVisible() && markers[2].isVisible()
                       && markers[3].isVisible();
    allVisibleHead = markers[17].isVisible() && markers[18].isVisible() && allVisibleHead;

    eyeLeft = headEyeCoords.getLeftEye().p;
    eyeRight = headEyeCoords.getRightEye().p;
    cyclopeanEye = (eyeLeft+eyeRight)/2.0;

    projPointEyeRight = getEyeProjectionPoint();

    checkBounds(nOscillationsFixation,
                eyeRight.x(),
                trialMode,
                headCalibrationDone,
                minOscTime,
                maxOscTime,
                maxXOscillation,
                translationTimer,
                beepOk,
                tweeter,
                woofer,tweeter);

    if ( trialMode == STIMULUSMODE )
        deltaT+=TIMER_MS;
    else
        deltaT=0;

    if (headCalibrationDone == 3 && trialMode != PROBEMODE )
    {
        // Questo rende conto del fatto che lo stimolo appare solo quando l'occhio è quasi in centro
		int actualTrialMode = trialMode;
		if ( trialMode == STIMULUSMODE && ( eyeRight.x()) > centerTolerance )
			actualTrialMode=FIXATIONMODE;

	markersFile << fixed <<   trialNumber << " " << actualTrialMode << " " ;
        markersFile << fixed << setprecision(3) << eyeRight.transpose() << " " << eyeLeft.transpose() << " " << toDegrees(headEyeCoords.getPitch()) << " " << toDegrees(headEyeCoords.getYaw()) << " " << toDegrees(headEyeCoords.getRoll()) << " " ;
        markersFile <<	fixed << setprecision(0)<<
                    factors["OmegaY"] << " " <<
                    factors["Binocular"] << " " <<
                    factors["Tilt"] << " " <<
                    factors["Slant"] << " " <<
                    totalTimer.getElapsedTimeInMilliSec() << endl;

        //objectPassiveTransformation.setIdentity();
		if ( actualTrialMode == STIMULUSMODE )
		{
        objectPassiveTransformation = getPassiveMatrix();
        matrixFile << setw(6) << left <<
                   trialNumber << " "  ;
        for ( int i=0; i<3; i++)
            matrixFile << objectPassiveTransformation.matrix().row(i) << " " ;
        matrixFile << endl;
		}

		if ( actualTrialMode == STIMULUSMODE )
		{
				vector< Vector3d> projPoints = stimDrawer.projectStimulusPoints(objectActiveTransformation,headEyeCoords.getRigidStart().getFullTransformation(),cam,focalDistance,screen,Vector3d(0,0,0),false,false);

				MatrixXd a1toa6 = stimDrawer.computeOpticFlow(projPoints, focalDistance, elapsedFrameTime/1000);
				flowsFile << trialNumber << " " << a1toa6.transpose() << endl;
		}
		}

    writeContinuosDataFile();

}
Ejemplo n.º 2
0
/**
 * @brief drawStimulus
 */
void drawStimulus()
{
    //////////////////////////////
    // Update stimuli
    double oscillationAmplitude=50.0;
    double oscillationPeriod=100.0;
    static double timeFrame=0.0;
    timeFrame+=1.0;
	
    if ( !trial.getCurrent().at("StimulusAnchored") )
    {
        // FISSO
        glPushMatrix();
        glLoadIdentity();
        Vector3d translationFactor(0,0,focalDistance);
        double instantPlaneSlant = trial.getCurrent().at("Slant");

        switch ( (int) trial.getCurrent().at("Tilt") )
        {
        case 0:
        {
            glTranslated( translationFactor.x(), translationFactor.y(), translationFactor.z());
            glRotated( -instantPlaneSlant ,0,1,0);
            glScaled(1/sin(toRadians( -90-trial.getCurrent().at("Slant"))),1,1);	//backprojection phase
            break;
        }
        case 90:
        {
            glTranslated( translationFactor.x(), translationFactor.y(), translationFactor.z());
            glRotated( -instantPlaneSlant ,1,0,0);
            glScaled(1,1/sin(toRadians( -90-trial.getCurrent().at("Slant") )),1); //backprojection phase
            break;
        }
        case 180:
        {
            glTranslated( translationFactor.x(), translationFactor.y(), translationFactor.z());
            glRotated( -instantPlaneSlant ,0,1,0);
            glScaled(1/sin(toRadians( -90-trial.getCurrent().at("Slant") )),1,1); //backprojection phase
            break;
        }
        case 270:
        {
            glTranslated( translationFactor.x(), translationFactor.y(), translationFactor.z());
            glRotated( -instantPlaneSlant ,1,0,0);
            glScaled(1,1/sin(toRadians( -90-trial.getCurrent().at("Slant") )),1); //backprojection phase
            break;
        }
        }
		glGetDoublev(GL_MODELVIEW_MATRIX,objectActiveTransformation.data());
        stimDrawer.draw();
        glPopMatrix();
    }
    else
    {
        // ANCORATO
        glPushMatrix();
        glLoadMatrixd( (headEyeCoords.getRigidStart().getFullTransformation()*Translation3d(Vector3d(0,0,focalDistance))).data() );
        glGetDoublev(GL_MODELVIEW_MATRIX,objectActiveTransformation.data());
		stimDrawer.draw();
        glPopMatrix();
    }

	// Draw the occlusor
    if ( useCircularOcclusor )
    {
		double maskRadius=parameters.get("CircularOcclusorRadius");
        glPushMatrix();
        glLoadIdentity();
		Vector3d projCoords;
		if ( trial.getCurrent().at("StimulusAnchored") )
			projCoords << project( (headEyeCoords.getRigidStart().getFullTransformation()*Translation3d(Vector3d(0,0,focalDistance))).translation() );
		else
			projCoords << project( Vector3d(0,0,focalDistance) );
		circleMask( projCoords.x(), projCoords.y(), maskRadius );
        glPopMatrix();
    }
	bool passiveMode=false;
	stimDrawer.projectStimulusPoints( objectActiveTransformation, headEyeCoords.getRigidStart().getFullTransformation(), cam, focalDistance, screen, eyeCalibration, passiveMode, true);
}