Esempio n. 1
0
// This function Poisson samples the inverse Fourier transformed power and populates the volume
// with galaxies.
void Gendr(std::string file, double variance, fftw_real *deltar3d) {
    // Create Mersenne twister random number generators for the Poisson sampling, and
    // to distribute galaxies in a uniform random manner within the cells.
    std::mt19937_64 generator;
    
    // Seed the generator
    generator.seed(time(0));
    
    std::ofstream fout; // Output filestream
    
    double n = nbar*dL*dL*dL;
    int count = 0;
    
    fout.open(file.c_str(),std::ios::out); // Open output file
    fout.precision(15); // Set the number of digits to output
    
    // Loop through all the grid points, assign galaxies uniform random positions within
    // each cell.
    for (int i = 0; i < N; ++i) {
        double xmin = i*dL;
        double xmax = (i+1)*dL;
        
        // Uniform random distribution for the x coordinate
        std::uniform_real_distribution<double> xpos(xmin, xmax);
        for (int j = 0; j < N; ++j) {
            double ymin = j*dL;
            double ymax = (j+1)*dL;
            
            // Uniform random distribution for the y coordinate
            std::uniform_real_distribution<double> ypos(ymin, ymax);
            for (int k = 0; k < N; ++k) {
                double zmin = k*dL;
                double zmax = (k+1)*dL;
                
                // Uniform random distribution for the z coordinate
                std::uniform_real_distribution<double> zpos(zmin, zmax);
                
                int index = k + N*(j+N*i); // Calculate grid index
                
                // Check that the matter density field is positive. Set to zero if not.
                //if (deltar3d[index] < 0.0) continue;
                
                // Initialize the Poisson distribution with the value of the matter field
                double density = n*exp(deltar3d[index]-variance/2);
                std::poisson_distribution<int> distribution(density);
                int numGal = distribution(generator); // Randomly Poisson sample
                count += numGal;
                
                // Randomly generate positions for numGal galaxies within the cell
                for (int gal = 0; gal < numGal; ++gal) {
                    fout << xpos(generator) << " " << ypos(generator) << " " << zpos(generator) << "\n";
                }
            }
        }
    }
    fout.close(); // Close file
    fout.open("GalaxyNum.dat",std::ios::app);
    fout << count << " " << file << "\n";
    fout.close();
}
Esempio n. 2
0
        void Cube::initCubeTexture()
        {
            QImage xpos("./bin/textures/room/xpos.png");
            QImage xneg("./bin/textures/room/xneg.png");
            QImage ypos("./bin/textures/room/ypos.png");
            QImage yneg("./bin/textures/room/yneg.png");
            QImage zpos("./bin/textures/room/zpos.png");
            QImage zneg("./bin/textures/room/zneg.png");
            int width = xpos.width();
            int height = xpos.height();
            glGenTextures(1, &m_texture);
            glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture);
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

            glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, xpos.bits()); 
            glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, xneg.bits()); 
            glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, ypos.bits()); 
            glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, yneg.bits()); 
            glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, zpos.bits()); 
            glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, zneg.bits()); 
            glBindTexture(GL_TEXTURE_CUBE_MAP, 0);

        }
/**
* \brief Default constructor
*/
SpecificWorker::SpecificWorker(MapPrx& mprx) : GenericWorker(mprx)
{
	connect(ci, SIGNAL(clicked()), this, SLOT(moverpataci()));
	connect(cd, SIGNAL(clicked()), this, SLOT(moverpatacd()));
	
	connect(Xpos, SIGNAL(clicked()), this, SLOT(xpos()));
	connect(Xneg, SIGNAL(clicked()), this, SLOT(xneg()));
	connect(Ypos, SIGNAL(clicked()), this, SLOT(ypos()));
	connect(Yneg, SIGNAL(clicked()), this, SLOT(yneg()));
	connect(Zpos, SIGNAL(clicked()), this, SLOT(zpos()));
	connect(Zneg, SIGNAL(clicked()), this, SLOT(zneg()));
	
	connect(Actualizar, SIGNAL(clicked()), this, SLOT(actualizar()));
	
	
	inner = new InnerModel("/home/ivan/robocomp/files/innermodel/hexapod1pata.xml");
	Posini=inner->transform("base","axisA1T");
	Posfin=Posini;
	
	QVec aux=inner->transform("arm1motor2","arm1motor3");
	qDebug()<<aux;
	angle1=atan(aux.y()/aux.z());
	Femur=aux.norm2();
	
	aux=inner->transform("arm1motor3","axisA1T");
	angle2=atan(aux.y()/aux.z());
	Tibia=aux.norm2();
	qDebug()<<aux;
	
	Coxa=52;
	
	qDebug()<<"-----------------------------";
	qDebug()<<"    Coxa   = "<<Coxa;
	qDebug()<<"    Femur  = "<<Femur;
	qDebug()<<"    Tibia  = "<<Tibia;
	qDebug()<<"    angle1 = "<<angle1;
	qDebug()<<"    angle2 = "<<angle2;
	qDebug()<<"-----------------------------";

	
	
// 	Femur=sqrt(14.5*14.5+64.5*64.5);
// 	Tibia=sqrt(123.714*123.714+ 23.6179 *23.6179);
	H=18.5;
// 	Posini=QVec::zeros(3);
// 	RoboCompJointMotor::MotorParamsList mp = jointmotor_proxy->getAllMotorParams();
// 	RoboCompJointMotor::MotorGoalPositionList mg;
// 	for(auto m:mp){
// 		cout<<m.name<<endl;
// 		RoboCompJointMotor::MotorGoalPosition p;
// 		p.name=m.name;
// 		p.maxSpeed=0.1;
// 		p.position=0;
// 		mg.push_back(p);
// // 		mg.insert(p);
// 	}
// 	jointmotor_proxy->setSyncPosition(mg);
	
	m1="arm1motor1";
	m2="arm1motor2";
	m3="arm1motor3";
}