예제 #1
0
// The equivalent to glRotate applied to the model matrix
void rotate(float angle, float x, float y, float z) {

	float aux[16];

	setRotationMatrix(aux,angle,x,y,z);
	multMatrix(modelMatrix,aux);
	setModelMatrix();
}
예제 #2
0
TEST_F(MotionEventTest, Transform) {
    // Generate some points on a circle.
    // Each point 'i' is a point on a circle of radius ROTATION centered at (3,2) at an angle
    // of ARC * i degrees clockwise relative to the Y axis.
    // The geometrical representation is irrelevant to the test, it's just easy to generate
    // and check rotation.  We set the orientation to the same angle.
    // Coordinate system: down is increasing Y, right is increasing X.
    const float PI_180 = float(M_PI / 180);
    const float RADIUS = 10;
    const float ARC = 36;
    const float ROTATION = ARC * 2;

    const size_t pointerCount = 11;
    PointerProperties pointerProperties[pointerCount];
    PointerCoords pointerCoords[pointerCount];
    for (size_t i = 0; i < pointerCount; i++) {
        float angle = float(i * ARC * PI_180);
        pointerProperties[i].clear();
        pointerProperties[i].id = i;
        pointerCoords[i].clear();
        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, sinf(angle) * RADIUS + 3);
        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, -cosf(angle) * RADIUS + 2);
        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, angle);
    }
    MotionEvent event;
    event.initialize(0, 0, AMOTION_EVENT_ACTION_MOVE, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, pointerCount, pointerProperties, pointerCoords);
    float originalRawX = 0 + 3;
    float originalRawY = -RADIUS + 2;

    // Check original raw X and Y assumption.
    ASSERT_NEAR(originalRawX, event.getRawX(0), 0.001);
    ASSERT_NEAR(originalRawY, event.getRawY(0), 0.001);

    // Now translate the motion event so the circle's origin is at (0,0).
    event.offsetLocation(-3, -2);

    // Offsetting the location should preserve the raw X and Y of the first point.
    ASSERT_NEAR(originalRawX, event.getRawX(0), 0.001);
    ASSERT_NEAR(originalRawY, event.getRawY(0), 0.001);

    // Apply a rotation about the origin by ROTATION degrees clockwise.
    float matrix[9];
    setRotationMatrix(matrix, ROTATION * PI_180);
    event.transform(matrix);

    // Check the points.
    for (size_t i = 0; i < pointerCount; i++) {
        float angle = float((i * ARC + ROTATION) * PI_180);
        ASSERT_NEAR(sinf(angle) * RADIUS, event.getX(i), 0.001);
        ASSERT_NEAR(-cosf(angle) * RADIUS, event.getY(i), 0.001);
        ASSERT_NEAR(tanf(angle), tanf(event.getOrientation(i)), 0.1);
    }

    // Applying the transformation should preserve the raw X and Y of the first point.
    ASSERT_NEAR(originalRawX, event.getRawX(0), 0.001);
    ASSERT_NEAR(originalRawY, event.getRawY(0), 0.001);
}
예제 #3
0
void SeedGLWidget::paintGL()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	int viewportWidth = _viewportHeight*(_widgetWidth-_planeWidth)*1.0/_widgetHeight;

	int anchorWidth = 200, anchorHeight = 200;

	glViewport(0,0,_widgetWidth-_planeWidth, _widgetHeight);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, viewportWidth, 0, _viewportHeight, -2000, 2000);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glEnable(GL_DEPTH_TEST);
	glPushMatrix();
	glTranslatef(_translateX, _translateY, 0);
	glTranslatef(viewportWidth/2.0, _viewportHeight/2.0, 0);
	setRotationMatrix();

	glColor3f(1, 1, 1);
	if (_volumeData)
	{
		switch (_viewpoint)
		{
		case VP_AXIAL:
			_volumeData->drawAxialSlice();
			break;
		case VP_CORONAL:
			_volumeData->drawCoronalSlice();
			break;
		case VP_SAGITTAL:
			_volumeData->drawSagittalSlice();
			break;
		}
	}

	drawSeedRegion();

	glPopMatrix();

	if (_bDrawing)
	{
		drawPenTrack();
	}

	glViewport(_widgetWidth-_planeWidth-anchorWidth, 0, anchorWidth, anchorHeight);
	drawAnchor();

	drawImageInfo();
	drawPlanes(_widgetWidth-_planeWidth, _planeWidth, _widgetHeight);
}
예제 #4
0
 // Apply a rotation
 void
 rotatePoseMatrix(float angle, float x, float y, float z,
                               float* matrix)
 {
     if (matrix) {
         float rotate_matrix[16];
         setRotationMatrix(angle, x, y, z, rotate_matrix);
         
         // matrix * scale_matrix
         multiplyMatrix(matrix, rotate_matrix, matrix);
     }
 }
예제 #5
0
    // Constructor(s) ################################################
    //################################################################
    Object3D(char* objName, char* fileName, UINT32 vertexCount, float modelSize, bool active = true,
             glm::mat4 scaleMatrix       = glm::mat4(),
             glm::mat4 translationMatrix = glm::mat4(),
             glm::mat4 rotationalMatrix  = glm::mat4()){

        setObjName(objName);
        setFileName(fileName);
        setVertexCount(vertexCount);
        setModelSize(modelSize);
        setActive(active);

        //Unless default function parameters are overwritten,
        //we will write identity matrices to the matrices
        setRotationMatrix(rotationalMatrix);
        setScaleMatrix(scaleMatrix);
        setTranslationMatrix(translationMatrix);

    }
예제 #6
0
void SeedGLWidget::selectRegion()
{
	/*if (_seedRegions.empty())
	{
		return;
	}*/

	glViewport (0, 0, 1024, 1024);

	glBindTexture(GL_TEXTURE_2D, 0);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fboId);
	glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);

	glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
	glClear (GL_COLOR_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0, _widgetWidth-_planeWidth, _widgetHeight, 0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glColor3f(1, 1, 1);

	gluTessBeginPolygon(tessObj, NULL);
	gluTessBeginContour(tessObj);
	for (int i=0; i<_penTrack.size(); ++i)
	{
		gluTessVertex(tessObj, _penTrack[i], _penTrack[i]);
	}
	gluTessEndContour(tessObj);
	gluTessEndPolygon(tessObj);
	
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	GLubyte * tempBuffer = new GLubyte [1024*1024];
	glBindTexture(GL_TEXTURE_2D, _texId);
	glGetTexImage(GL_TEXTURE_2D, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, tempBuffer);

	GLdouble modelMatrix[16];
	GLdouble projMatrix[16];
	int viewport[4];

	int viewportWidth = _viewportHeight*(_widgetWidth-_planeWidth)*1.0/_widgetHeight;
	glViewport (0, 0, 1024, 1024);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, viewportWidth, 0, _viewportHeight, -2000, 2000);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(_translateX, _translateY, 0);
	glTranslatef(viewportWidth/2.0, _viewportHeight/2.0, 0);
	setRotationMatrix();
	_volumeData->setTransformMatrix();

	glGetIntegerv(GL_VIEWPORT, viewport);
	glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
	glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);

	int minX = floor(_minDrawX*1023.0/(_widgetWidth-_planeWidth-1));
	int maxX = ceil(_maxDrawX*1023.0/(_widgetWidth-_planeWidth-1));
	int minY = floor((_widgetHeight-_maxDrawY)*1023.0/(_widgetHeight-1));
	int maxY = ceil((_widgetHeight-_minDrawY)*1023.0/(_widgetHeight-1));

	for (int i=minX; i<=maxX; ++i)
	{
		for (int j=minY; j<maxY; ++j)
		{
			if (tempBuffer[j*1024+i]>0)
			{
				double x, y, z;
				gluUnProject(i, j, 0, modelMatrix, projMatrix, viewport, &x, &y, &z);
				//add to seed region list

				switch (_viewpoint)
				{
				case 1: //AXIAL
					z = _seedData->_aSliceIdx;
					break;
				case 2: //CORONAL
					y = _seedData->_cSliceIdx;
					break;
				case 3: //SAGITTAL
					x = _seedData->_pSliceIdx;
					break;
				}
				if (_bAddRegion)
				{
					_seedData->addSeedPoint(x,y,z, _currentSeedIndex);
				} else
				{
					_seedData->removeSeedPoint(x,y,z,_currentSeedIndex);
				}
			}
		}
	}

	delete tempBuffer;

	_seedData->setASlice(_aSlicePos);
	_seedData->setPSlice(_pSlicePos);
	_seedData->setCSlice(_cSlicePos);

}
예제 #7
0
파일: fpose.cpp 프로젝트: DrItanium/scummvm
FPose::FPose(Axis axis, float amount) {
	setRotationMatrix(axis, amount);
}
예제 #8
0
void CompositionDBG::initialize(const ChangeType rT, const ComDBGFuncID rF,double const rChangingRatio,const bool rFlagDimChange, const bool rFlagNumPeakChange,
	const int peakNumChangeMode,const bool flagNoise, const bool flagTimelinkage){

    RealDBG::initialize(rT,rFlagDimChange,rFlagNumPeakChange,peakNumChangeMode,flagNoise,flagTimelinkage);
    setOptType(MIN_OPT);
    setNumberofChanges(rChangingRatio);
	if(!ms_funID.get()) ms_funID.reset(new ComDBGFuncID());
    *CompositionDBG::ms_funID=rF;
	setAccuracy(1.0);
	setDisAccuracy(0.1);
	m_globalOpt.setFlagLocTrue();
    ProblemTag *basic_fun=new ProblemTag[m_numPeaks];

	switch(*CompositionDBG::ms_funID){
		case COMDBG_SPHERE:
			for(int i=0;i<m_numPeaks;i++) basic_fun[i]=Sphere;
			break;
		case COMDBG_RASTRIGIN:
			for(int i=0;i<m_numPeaks;i++) basic_fun[i]=Rastrigin;
			break;
		case COMDBG_GRIEWANK:
			for(int i=0;i<m_numPeaks;i++) basic_fun[i]=Griewank;
			break;
		case COMDBG_ACKLEY:
			for(int i=0;i<m_numPeaks;i++) basic_fun[i]=Ackley;
			break;
		case COMDBG_HYBRID:
			basic_fun[0]=Sphere;		basic_fun[5]=Sphere;
			basic_fun[1]=Rastrigin;		basic_fun[6]=Rastrigin;
			basic_fun[2]=Weierstrass;	basic_fun[7]=Weierstrass;
			basic_fun[3]=Griewank;		basic_fun[8]=Griewank;
			basic_fun[4]=Ackley;		basic_fun[9]=Ackley;
			for(int i=10;i<m_numPeaks;i++) basic_fun[i]=Sphere;
			break;
	}
	setBasicFunction(basic_fun);
    delete []basic_fun;
	basic_fun=0;

	double *t=new double[m_numPeaks];
	for(int i=0;i<m_numPeaks;i++)t[i]=1.;
	setCovergeSevrity(t);
	setStretchSeverity();
	setRotationMatrix();
	
	Matrix m(m_numDim,1);
	double *gene=new double[m_numDim];
	for(int i=0;i<m_numPeaks;i++){
		for(int j=0;j<m_numDim;j++){ // calculate the estimate max value of funciton i
			gene[j]=m_searchRange[j].m_upper;
			gene[j]/=mp_stretchSeverity[i];
		}
		m.setDataRow(gene,m_numDim);
		m*=mp_rotationMatrix[i];
		copy(m[0].begin(),m[0].end(),gene);
		correctSolution(mp_comFunction[i],gene);
		mp_fmax[i]=selectFun(mp_comFunction[i],gene);
		if(mp_fmax[i]==0)   throw myException("the estimation max value must be greater not equal to 0@CompositionDBG::initialize");

	}
	
	calculateGlobalOptima();
	updateTimeLinkage();

	delete [] t;
	delete [] gene;
	t=0;
	gene=0;

 }