Ejemplo n.º 1
0
void setMatrices()
{
    // Set up the projection and model-view matrices
    GLfloat aspectRatio = (GLfloat)window.GetWidth()/window.GetHeight();
    GLfloat nearClip = 0.1f;
    GLfloat farClip = 500.0f;
    GLfloat fieldOfView = 45.0f; // Degrees

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fieldOfView, aspectRatio, nearClip, farClip);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0, 0.0, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);

    glPushMatrix(); // set the light in the scene correctly
    transNode(cathedralScene, cathedralScene->mRootNode);
    GLfloat light0_position[] = { 0, 30, 0, 0 };
    glLightfv( GL_LIGHT0, GL_POSITION, light0_position );
    GLfloat light1_position[] = { 0, 11, 0, 0.0 };
    glLightfv( GL_LIGHT1, GL_POSITION, light1_position );
    glPopMatrix();

    glRotatef(rad_to_deg(pitch), 1.0, 0.0, 0.0);
    glRotatef(rad_to_deg(yaw), 0.0, 1.0, 0.0);
    glTranslatef(position.x, position.y, position.z);

    // We store the modelview matrix here, but it's actually the view matrix because we haven't done any model transforms yet
//    static double viewMatrix[16];
    GLfloat *viewMatrix = new GLfloat[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix);
    GLint inverseViewMatrixUniform = glGetUniformLocation(envMapShader->programID(), "inverseViewMatrix");
    glUniformMatrix4fv(inverseViewMatrixUniform, 1, true, viewMatrix);
    delete [] viewMatrix;
}
Ejemplo n.º 2
0
// TODO: remove this?
void transNode(aiScene const *scene, aiNode const *node)
{
    if ( node == NULL ) return;
    aiMatrix4x4 m = node->mTransformation;

    float mat[16] = {m.a1,m.b1,m.c1,m.d1,m.a2,m.b2,m.c2,m.d2,m.a3,
                     m.b3,m.c3,m.d3,m.a4,m.b4,m.c4,m.d4
                    };

    glMultMatrixf(mat);

    for (int i = 0; i < (int)node->mNumChildren; i++)
    {
        transNode(scene, node->mChildren[i]);
    }
}
Ejemplo n.º 3
0
trans_local xFlowJoWorkspace::getTransformation(wsRootNode root,const compensation & comp, PARAM_VEC & transFlag,trans_global_vec * gTrans,biexpTrans * _globalBiExpTrans,linTrans * _globalLinTrans){

	trans_local res;

	/*
	 * get transformations node
	 */
	xmlXPathObjectPtr transParentNodeRes=root.xpathInNode("../Transformations");
	unsigned short nTransParentNodes=transParentNodeRes->nodesetval->nodeNr;
	if(nTransParentNodes<=0)
	{
		COUT<<"compensation not found!"<<endl;
		xmlXPathFreeObject(transParentNodeRes);
		return(res);
	}else if(nTransParentNodes>1){
		throw(domain_error("More than one 'Transformations' node found!"));
	}

	wsNode transParentNode(transParentNodeRes->nodesetval->nodeTab[0]);

	/*
	 * parse each individual transformation
	 */
	xmlXPathObjectPtr transRes=transParentNode.xpathInNode("child::*");

	trans_map curTp=res.getTransMap();

	for(int j=0;j<transRes->nodesetval->nodeNr;j++)
	{
		wsNode transNode(transRes->nodesetval->nodeTab[j]);

		//parse the parameter name
		string pname;
		xmlXPathObjectPtr paramRes=transNode.xpathInNode("*[local-name()='parameter']");
		if(paramRes->nodesetval->nodeNr!=1)
			pname="";
		else{
			wsNode paramNode(paramRes->nodesetval->nodeTab[0]);
			pname=paramNode.getProperty("name");
			}


		xmlXPathFreeObject(paramRes);
		/*
		 * when channel name is not specified
		 * try to parse it as the generic trans that is applied to channels
		 * that do not have channel-specific trans defined in workspace
		 * ,
		 */
		if(pname.empty())
			pname="*";

		string transType=(const char*)transNode.getNodePtr()->name;
		if(transType.compare("biex")==0)
		{

			if(g_loglevel>=GATING_SET_LEVEL)
				COUT<<"biex func:"<<pname<<endl;
			biexpTrans *curTran=new biexpTrans();
			curTran->setName("");
			curTran->setChannel(pname);
			curTran->pos=atof(transNode.getProperty("pos").c_str());
			curTran->neg=atof(transNode.getProperty("neg").c_str());
			curTran->widthBasis=atof(transNode.getProperty("width").c_str());
			curTran->maxValue=atof(transNode.getProperty("maxRange").c_str());
			unsigned short thisLen=atoi(transNode.getProperty("length").c_str());
			if(thisLen!=256)
				throw(domain_error("length is not 256 for biex transformation!"));
			/*
			 * do the lazy calibration table calculation and interpolation
			 * when it gets saved in gh
			 */
			curTp[curTran->getChannel()]=curTran;
		}else if(transType.compare("linear")==0){
//			if(g_loglevel>=GATING_SET_LEVEL)
//				COUT<<"flin func:"<<pname<<endl;
//			double minRange=atof(transNode.getProperty("minRange").c_str());
//			double maxRange=atof(transNode.getProperty("maxRange").c_str());
//			flinTrans *curTran=new flinTrans(minRange,maxRange);
//			curTran->setName("");
//			curTran->setChannel(pname);
//
//			curTp[curTran->getChannel()]=curTran;
			//do nothing for linear trans
		}else if(transType.compare("log")==0){
			if(g_loglevel>=GATING_SET_LEVEL)
				COUT<<"flog func:"<<pname<<endl;
			double offset=atof(transNode.getProperty("offset").c_str());
			double decade=atof(transNode.getProperty("decades").c_str());
			logTrans *curTran=new logTrans(offset,decade);
			curTran->setName("");
			curTran->setChannel(pname);

			curTp[curTran->getChannel()]=curTran;
		}else if(transType.compare("fasinh")==0){
			if(g_loglevel>=GATING_SET_LEVEL)
				COUT<<"fasinh func:"<<pname<<endl;
			double length=atof(transNode.getProperty("length").c_str());
			double maxRange=atof(transNode.getProperty("maxRange").c_str());
			double M=atof(transNode.getProperty("M").c_str());
			double T=atof(transNode.getProperty("T").c_str());
			double A=atof(transNode.getProperty("A").c_str());
			fasinhTrans *curTran=new fasinhTrans(maxRange,length, T,A,M);
			curTran->setName("");
			curTran->setChannel(pname);

			curTp[curTran->getChannel()]=curTran;
		}
		else
			throw(domain_error("unknown tranformation type!"));

	}
	xmlXPathFreeObject(transRes);
	xmlXPathFreeObject(transParentNodeRes);

	res.setTransMap(curTp);
	return res;
}
Ejemplo n.º 4
0
/*
 *parsing transformations from CompensationEditor node and
 *store in global container within gs
 *
 */
trans_global_vec winFlowJoWorkspace::getGlobalTrans(){


	trans_global_vec res;


	/*
	 * get CompensationEditor node
	 */

	string path="/Workspace/CompensationEditor";
	xmlXPathContextPtr context = xmlXPathNewContext(doc);
	xmlXPathObjectPtr CompEdres = xmlXPathEval((xmlChar *)path.c_str(), context);
	if(xmlXPathNodeSetIsEmpty(CompEdres->nodesetval))
	{
		COUT<<"no CompensationEditor found!"<<endl;
		xmlXPathFreeObject(CompEdres);
		xmlXPathFreeContext(context);
		return(res);
	}
	wsNode compEdNode(CompEdres->nodesetval->nodeTab[0]);

	/*
	 * parse all Compensation nodes and store them in global trans container
	 */
	path="/Workspace/CompensationEditor/Compensation";
	wsNode node(doc->children);
	xmlXPathObjectPtr compNodeRes =node.xpath(path);
	unsigned short nCompNodes=compNodeRes->nodesetval->nodeNr;
	if(nCompNodes<=0)
	{
		COUT<<"compensation not found!"<<endl;
		xmlXPathFreeObject(compNodeRes);
		return(res);
	}
	for(unsigned i =0;i<nCompNodes;i++)
	{
		wsNode compNode(compNodeRes->nodesetval->nodeTab[i]);
		string compName=compNode.getProperty("name");

		trans_global curTg;
		curTg.setGroupName(compName);

		if(g_loglevel>=GATING_SET_LEVEL)
			COUT<<"group:"<<compName<<endl;
		/*
		 * parse transformations for current compNode
		 */
		trans_map curTp=curTg.getTransMap();
		path=".//*[local-name()='logicle']";//get logicle(actually it is biexp)
		xmlXPathObjectPtr TransRes=compNode.xpathInNode(path);
		for(int j=0;j<TransRes->nodesetval->nodeNr;j++)
		{
			wsNode transNode(TransRes->nodesetval->nodeTab[j]);

			string pname=transNode.getProperty("parameter");
			/*
			 * when channel name is not specified
			 * try to parse it as the generic trans that is applied to channels
			 * that do not have channel-specific trans defined in workspace
			 * ,
			 */
			if(pname.empty())
				pname="*";

			string transType=(const char*)transNode.getNodePtr()->name;
			if(transType.compare("logicle")==0)
			{

				if(g_loglevel>=GATING_SET_LEVEL)
					COUT<<"logicle func:"<<pname<<endl;
				biexpTrans *curTran=new biexpTrans();
				curTran->setName(compName);


				curTran->setChannel(pname);
				curTran->pos=atof(transNode.getProperty("T").c_str());
				curTran->neg=atof(transNode.getProperty("w").c_str());
				curTran->widthBasis=atof(transNode.getProperty("m").c_str());
				/*
				 * do the lazy calibration table calculation and interpolation
				 * when it gets saved in gh
				 */
				curTp[curTran->getChannel()]=curTran;
			}
			else
			{
				xmlXPathFreeObject(TransRes);
				xmlXPathFreeObject(compNodeRes);
				throw(domain_error("unknown tranformation type!"));
			}


		}
		xmlXPathFreeObject(TransRes);
		/*
		 * parse sample list
		 */
		path="Samples/Sample";//get logicle(actually it is biexp)
		xmlXPathObjectPtr sampleRes=compNode.xpathInNode(path);
		unsigned nSample=sampleRes->nodesetval->nodeNr;
		vector<int> sampleIDs;
		for(unsigned j=0;j<nSample;j++)
		{
			wsNode curNode(sampleRes->nodesetval->nodeTab[j]);
			string curSampleID=curNode.getProperty("sampleID");
			sampleIDs.push_back(atoi(curSampleID.c_str()));
		}
		curTg.setSampleIDs(sampleIDs);
		xmlXPathFreeObject(sampleRes);
		curTg.setTransMap(curTp);
		/*
		 * push the tg object to global container
		 */
		res.push_back(curTg);
	}
	xmlXPathFreeObject(compNodeRes);


	return res;
}
Ejemplo n.º 5
0
void generateCubeMap()
{
    glViewport(0, 0, CUBE_MAP_SIZE, CUBE_MAP_SIZE);

    glUseProgram(phongShader->programID());
    GLint drawShadows = glGetUniformLocation(phongShader->programID(), "drawShadows");
    glUniform1i(drawShadows, 0);

    glGenTextures(1, &cubeMapTextureID);
    glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMapTextureID);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    for (uint face = 0; face < 6; face++) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Set up the projection and model-view matrices
        GLfloat aspectRatio = 1.0f;
        GLfloat nearClip = 0.1f;
        GLfloat farClip = 500.0f;
        GLfloat fieldOfView = 90.0f; // Degrees

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(fieldOfView, aspectRatio, nearClip, farClip);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        switch (face) {
        case 0:
            /// positive x
            gluLookAt(0.0f, 2.0f, 0.0f,
                      1.0f, 2.0f, 0.0f,
                      0.0f, 1.0f, 0.0f);
            break;
        case 1:
            // negative x
            gluLookAt(0.0f, 2.0f, 0.0f,
                      -1.0f, 2.0f, 0.0f,
                      0.0f, 1.0f, 0.0f);
            break;
        case 2:
            // positive y
            gluLookAt(0.0f, 2.0f, 0.0f,
                      0.0f, 3.0f, 0.0f,
                      0.0f, 0.0f, -1.0f);
            break;
        case 3:
            // negative y
            gluLookAt(0.0f, 2.0f, 0.0f,
                      0.0f, 1.0f, 0.0f,
                      0.0f, 0.0f, 1.0f);
            break;
        case 4:
            // positive z
            gluLookAt(0.0f, 2.0f, 0.0f,
                      0.0f, 2.0f, 1.0f,
                      0.0f, 1.0f, 0.0f);
            break;
        case 5:
            // negative z
            gluLookAt(0.0f, 2.0f, 0.0f,
                      0.0f, 2.0f, -1.0f,
                      0.0f, 1.0f, 0.0f);
            break;
        default:
            break;
        }



        // TODO: WHY SO DARK CUBEMAP
        glPushMatrix(); // set the light in the scene correctly

        transNode(cathedralScene, cathedralScene->mRootNode);  // TODO: STILL NEED TO FIGURE OUT WHY I DO THIS

        GLfloat light0_position[] = { 0, 30, 0, 0 };
        glLightfv( GL_LIGHT0, GL_POSITION, light0_position );

        GLfloat light1_position[] = { 0, 11, 0, 0.0 };
        glLightfv( GL_LIGHT1, GL_POSITION, light1_position );

        glPopMatrix();


        renderNode(phongShader, cathedralScene, cathedralScene->mRootNode, false);

        // Copy the back buffer into the current face of the cube map
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_RGBA,
                     CUBE_MAP_SIZE, CUBE_MAP_SIZE, 0, GL_RGBA, GL_FLOAT, NULL);
        glCopyTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, 0, 0, 0, 0, CUBE_MAP_SIZE, CUBE_MAP_SIZE);
    }

    glUniform1i(drawShadows, 1);
    glViewport(0, 0, window.GetWidth(), window.GetHeight());
}