Esempio n. 1
0
glm::vec3 indirect(const Ray &rOrigine, const Ray &rReflect, const glm::vec3 &p, const glm::vec3 & n, int countdown, const Diffuse &diffuse) {
    float pdf;
    glm::vec3 w = glm::normalize(sample_sphere(1, random_u(), random_u(), pdf, n));
    Ray rIndirect{p+0.1f*w, w};
    return radiance(rIndirect, countdown);
    //return glm::vec3(0,0,0);
}
Esempio n. 2
0
glm::vec3 radiance (const Ray & r, int iterations = 3)
{
    float t = 1.0f;
    glm::vec3 normale, normale2;
    Object* o = intersect(r, t, normale);
    if (t == noIntersect)
        return glm::vec3(0,0,0);
    glm::vec3 pointIntersection = r.origin + t*r.direction;

    // Calcul pour les ombres douces, point aléatoire de lumière autour de scene::light
    float pdf = 0;
    glm::vec3 normaleSphereLumiere = glm::normalize(pointIntersection - scene::light);
    glm::vec3 vecLumiere = sample_sphere(10, random_u(), random_u(), pdf, normaleSphereLumiere);
    glm::vec3 light = scene::light + vecLumiere;

    glm::vec3 directionLum = light - pointIntersection;
    glm::vec3 directionLumNormalize = glm::normalize(directionLum);
    Ray rayLum{pointIntersection+directionLumNormalize*0.1f, directionLumNormalize};
    intersect(rayLum, t, normale2);

    glm::vec3 direct(0,0,0);

    if (t*t > longueurCarree(directionLum))
    {
        direct = o->direct(normale, directionLumNormalize) / (pdf*longueurCarree(directionLum));
    }

    glm::vec3 indirect(0,0,0);

    if (iterations > 0)
         indirect = o->indirect(r.direction, pointIntersection, normale, iterations);

    return direct + indirect;
}
Esempio n. 3
0
glm::vec3 indirect(const glm::vec3 &c, const glm::vec3 &p, const glm::vec3 &n, const Diffuse &diffuse, int iterations)
{
    float pdf;
    glm::vec3 directionRay = sample_sphere(1, random_u(), random_u(), pdf, n);
    Ray ray{p+directionRay*0.1f, directionRay};
    return radiance(ray, iterations-1) * diffuse.color;
}
Esempio n. 4
0
void exoSamplingMonteCarlo() {
    float xuni = 0;
    float xboxmuller = 0;
    int it = 100;
    float ecartType = 0.7;
    for(int i = 0; i < it; ++i){

        xuni += cos(pi*random_u()-(pi/2))*pi;
        float val = sqrt(-2*log(random_u()))*cos(2*pi*random_u())*ecartType;
        if(val >= -pi/2 && val <= pi/2)
            xboxmuller += (cos(val))/((1/(ecartType*sqrt(2*pi)))*exp(-(val*val)/(2*ecartType*ecartType)));
    }
    std::cout << (xuni/it) << ", " << (xboxmuller/it) << std::endl;
}
Esempio n. 5
0
void monteCarloGaussien()
{
    float value = 0;
    int echantillons = 100;
    float ecartType = 0.7;
    for (int i = 0; i < echantillons; i++)
    {
        float xi = sqrt(-2*log(random_u()))*cos(2*pi*random_u())*ecartType;
        if (xi <= pi/2 && xi >= -pi/2)
        {
            float pdfi = 1/(ecartType*sqrt(2*pi))*exp(-xi*xi/(2*ecartType*ecartType));
            value += cos(xi)/pdfi;
        }
    }
    std::cout << value/echantillons << std::endl;
}
Esempio n. 6
0
glm::vec3 indirect(const glm::vec3 &c, const glm::vec3 &p, const glm::vec3 &n, const Glass &glass, int iterations)
{
    float ior = 1.5f;

    // Calcul du rayon réfléchi
    glm::vec3 direction = reflect(c,n);
    glm::vec3 directionNorm = glm::normalize(direction);
    Ray rayReflexion{p+directionNorm*0.1f, directionNorm};

    // Calcul du rayon réfracté
    glm::vec3 vecRefract;
    refract(-c, n, ior, vecRefract);
    Ray rayRefraction{p+vecRefract*0.1f, vecRefract};

    // Calcul du coefficient reflechi/refracte

    float coeff = fresnelR(-c, n, ior);

    float rand = random_u();

    if (rand < coeff)
    {
        return radiance(rayReflexion, iterations-1);
    }
    return radiance(rayRefraction, iterations-1) * glass.color;

    //return radiance(rayReflexion, iterations-1) * coeff + radiance(rayRefraction, iterations-1) * (1- coeff);
}
Esempio n. 7
0
void monteCarloGaussienXYZ()
{
    float value = 0;
    int echantillons = 100;
    float ecartType = 0.7;
    for (int i = 0; i < echantillons; i++)
    {
        float xi = sqrt(-2*log(random_u()))*cos(2*pi*random_u())*ecartType;
        float yi = sqrt(-2*log(random_u()))*cos(2*pi*random_u())*ecartType;
        float zi = random_u()*pi-pi/2;
        if (xi <= pi/2 && xi >= -pi/2 && yi <= pi/2 && yi >= -pi/2)
        {
            float pdfiX = 1/(ecartType*sqrt(2*pi))*exp(-xi*xi/(2*ecartType*ecartType));
            float pdfiY = 1/(ecartType*sqrt(2*pi))*exp(-yi*yi/(2*ecartType*ecartType));
            float pdfiZ = 1/pi;
            value += cos(xi*yi)*zi/(pdfiX*pdfiY*pdfiZ);
        }
    }
    std::cout << value/echantillons << std::endl;
}
Esempio n. 8
0
void monteCarloUniforme()
{
    float value = 0;
    int echantillons = 100;
    for (int i = 0; i < echantillons; i++)
    {
        float xi = pi*random_u()-pi/2;
        value += cos(xi)*pi; // pdf(xi) = 1/pi
    }
    std::cout << value/echantillons << std::endl;
}
Esempio n. 9
0
glm::vec3 indirect(const Ray &rOrigine, const Ray &rReflect, const glm::vec3 &p,  const glm::vec3 & n, int countdown, const Glass &glass) {

    float fresnel = fresnelR(-rOrigine.direction,n, 1.5);
    glm::vec3 refracted;
    bool canRefract = refract(-rOrigine.direction, n, 1.5, refracted);
    Ray rRefracted{p+refracted*0.1f, refracted};
    if(canRefract) {
        float u = random_u();
        if(u < fresnel)
            return radiance(rReflect, countdown);
        else
            return radiance(rRefracted, countdown);
    }
        //return fresnel*radiance(rReflect, countdown)+(1-fresnel)*radiance(rRefracted, countdown);
    else
        return fresnel*radiance(rReflect, countdown);
}
Esempio n. 10
0
int main (int, char **)
{
    QTime timer;
    timer.start();
    int w = 768, h = 768;
    int samplesLight = 1;
    int samplesAliasing = 1;
    std::vector<glm::vec3> colors(w * h, glm::vec3{0.f, 0.f, 0.f});

    Ray cam {{50, 52, 295.6}, glm::normalize(glm::vec3{0, -0.042612, -1})};	// cam pos, dir
    float near = 1.f;
    float far = 10000.f;

    glm::mat4 camera =
        glm::scale(glm::mat4(1.f), glm::vec3(float(w), float(h), 1.f))
        * glm::translate(glm::mat4(1.f), glm::vec3(0.5, 0.5, 0.f))
        * glm::perspective(float(54.5f * pi / 180.f), float(w) / float(h), near, far)
        * glm::lookAt(cam.origin, cam.origin + cam.direction, glm::vec3(0, 1, 0))
        ;

    glm::mat4 screenToRay = glm::inverse(camera);

    #pragma omp parallel for schedule(dynamic)
    for (int y = 0; y < h; y++)
    {
        std::cerr << "\rRendering: " << 100 * y / (h - 1) << "%";

        for (unsigned short x = 0; x < w; x++)
        {
            glm::vec3 r(0,0,0);

            for (int samplesA = 0; samplesA < samplesAliasing; ++samplesA)
            {
                   float aleaX = random_u()-0.5;
                   float aleaY = random_u()-0.5;

                   glm::vec4 p0 = screenToRay * glm::vec4{float(x + aleaX), float(h - y + aleaY), 0.f, 1.f};
                   glm::vec4 p1 = screenToRay * glm::vec4{float(x + aleaX), float(h - y + aleaY), 1.f, 1.f};

                   glm::vec3 pp0 = glm::vec3(p0 / p0.w);
                   glm::vec3 pp1 = glm::vec3(p1 / p1.w);

                   glm::vec3 d = glm::normalize(pp1 - pp0);

                   for (int samplesL = 0; samplesL < samplesLight; ++samplesL) {
                       r += radiance (Ray{pp0, d});
                   }
            }

            r = r/float(samplesLight*samplesAliasing);

            colors[y * w + x] += glm::clamp(r, glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.f, 1.f, 1.f));// * 0.25f;
        }
    }

    std::cout << "\n" << timer.elapsed()/1000.0 << "s" << std::endl;

    {
        std::fstream f("image.ppm", std::fstream::out);
        f << "P3\n" << w << " " << h << std::endl << "255" << std::endl;

        for (auto c : colors)
            f << toInt(c.x) << " " << toInt(c.y) << " " << toInt(c.z) << " ";
    }

}
void random_config( void ) {

    int i, m, j, k, ind = 0 ;
    int tmp_dr[Dim];


    for ( k=0 ; k<nD ; k++ ) {
        for ( j=0 ; j<Dim ; j++ )
            x[ind][j] = ran2() * L[j] ;

        x[ind][2] = ran2()*(L[2]-2*wall_thick)*(1-phiHA-phiHB-phiP-phiHC-phisol) + wall_thick;

        tp[ ind ] = ( Nda > 0 ? 0 : 1 ) ;

        ind += 1 ;

        for ( m=1 ; m<Nda + Ndb ; m++ ) {

            for ( j=0 ; j<Dim ; j++ ) {
                x[ind][j] = x[ ind-1 ][ j ] + gasdev2() ;

                if ( x[ind][j] > L[j] )
                    x[ind][j] -= L[j] ;
                else if ( x[ind][j] < 0.0 )
                    x[ind][j] += L[j] ;
            }
            x[ind][2] = x[ind-1][2];

            tp[ ind ] = ( m < Nda ? 0 : 1 ) ;

            ind++ ;

        }
    }

    // Random A homopolymers //
    for ( k=0 ; k<nA ; k++ ) {
        for ( j=0 ; j<Dim ; j++ )
            x[ind][j] = ran2() * L[j] ;

        tp[ ind ] = 0 ;

        ind += 1 ;

        for ( m=1 ; m<Nha ; m++ ) {

            for ( j=0 ; j<Dim ; j++ ) {
                x[ind][j] = x[ ind-1 ][ j ] + gasdev2() ;

                if ( x[ind][j] > L[j] )
                    x[ind][j] -= L[j] ;
                else if ( x[ind][j] < 0.0 )
                    x[ind][j] += L[j] ;
            }

            tp[ ind ] = 0 ;

            ind++ ;

        }
    }

    // Random B homopolymers //
    for ( k=0 ; k<nB ; k++ ) {
        for ( j=0 ; j<Dim ; j++ )
            x[ind][j] = ran2() * L[j] ;

        tp[ ind ] = 1 ;

        ind += 1 ;

        for ( m=1 ; m<Nhb ; m++ ) {

            for ( j=0 ; j<Dim ; j++ ) {
                x[ind][j] = x[ ind-1 ][ j ] + gasdev2() ;

                if ( x[ind][j] > L[j] )
                    x[ind][j] -= L[j] ;
                else if ( x[ind][j] < 0.0 )
                    x[ind][j] += L[j] ;
            }

            tp[ ind ] = 1 ;

            ind++ ;

        }
    }

    // Random particle centers, graft locations //
    for ( k=0 ; k<nP ; k++ ) {
        int center_ind , gind,prev_graft ;
        double u[Dim] ;


        for ( j=0 ; j<Dim ; j++ )
            x[ind][j] = ran2() * L[j] ;

        x[ind][2] = ran2()*((L[2]-2*wall_thick)*(1-phiHA-phiHB-phiP-phiHC-phisol) - 2*Rp) + wall_thick+Rp;
        for(j=0 ; j<3 ; j++) {

            euler_ang[k][j] = 0;
            euler_q[k][j+1] = 0;
        }

        euler_q[k][0] = 1;
        // euler_ang[k][0] = PI/2.0;

        tp[ ind ] = 2 ;

        center_ind = ind ;

        ind += 1 ;


        for ( m=0 ; m<ng_per_partic ; m++ ) {

            // Place the grafting site //
            if(uni_sig ==1) { //fibonacci grafting sites
                fibonacci_u ( u , m );
                gind = k*ng_per_partic + m;
                if(k==0 and m==0)cout<<"fibonacci grafting is used"<<endl;
            }
            else if(uni_sig ==2) { //uniform grafting
                unif_sig ( u , m );
                gind = k*ng_per_partic + m;
                if(k==0  and m==0)cout<<"uniform grafting is used"<<endl;
            }
            else { //random grafting sites
                random_u( u ) ;
                gind = k*ng_per_partic + m;
                if(k==0 and m==0)cout<<"random grafting is used"<<endl;
            }


            for ( j=0 ; j<Dim ; j++ ) {
                x[ind][j] = x[center_ind][j] + Rp * u[j] ;
                grf_bf_x[gind][j] = Rp * u[j];

                if ( x[ind][j] > L[j] )
                    x[ind][j] -= L[j] ;
                else if ( x[ind][j] < 0.0 )
                    x[ind][j] += L[j] ;
            }
            //  cout<<" ng "<<m<<" "<<x[ind][0]<<" "<<x[ind][1]<<" "<<x[ind][2]<<endl;

            tp[ ind ] = -1 ;

            if ( m > 0 ) {
                double mdr2, dr[Dim], mdr ;
                mdr2 = pbc_mdr2( x[ prev_graft ] , x[ ind ] , dr ) ;
                mdr = sqrt( mdr2 ) ;

                graft_req[k][m-1] = mdr ;
            }

            prev_graft = ind ;

            ind++ ;

            // Place the chain grafted to this site
            for ( i=0 ; i<Ng ; i++ ) {

                for ( j=0 ; j<Dim ; j++ ) {
                    x[ind][j] = x[ind-1][j] + 0.5 * u[j] ;

                    if ( x[ind][j] > L[j] )
                        x[ind][j] -= L[j] ;
                    else if ( x[ind][j] < 0.0 )
                        x[ind][j] += L[j] ;
                }

                tp[ ind ] = 0 ;
                ind++ ;
            }
        }
    }

    // Random C homopolymers //
    for ( k=0 ; k<nC ; k++ ) {
        for ( j=0 ; j<Dim ; j++ )
            x[ind][j] = ran2() * L[j] ;

        x[ind][2] = -ran2()*(L[2]-2*wall_thick)*(phiHC+phisol) +L[2] -  wall_thick;

        tp[ ind ] = 3 ;

        ind += 1 ;

        for ( m=1 ; m<Nhc ; m++ ) {

            for ( j=0 ; j<Dim ; j++ ) {
                x[ind][j] = x[ ind-1 ][ j ] + gasdev2() ;

                if ( x[ind][j] > L[j] )
                    x[ind][j] -= L[j] ;
                else if ( x[ind][j] < 0.0 )
                    x[ind][j] += L[j] ;
            }

            x[ind][2] = x[ind-1][2];

            tp[ ind ] = 3 ;

            ind++ ;

        }
    }

    ind = nD*(Nda+Ndb) + nA*Nha +nB*Nhb + nP * ( 1 + ng_per_partic * ( Ng + 1 ) ) + max_nC*Nhc ;
// Random sol  //
    for ( k=0 ; k<nsol ; k++ ) {
        for ( j=0 ; j<Dim ; j++ )
            x[ind][j] = ran2() * L[j] ;

        x[ind][2] = -ran2()*(L[2]-2*wall_thick)*(phiHC+phisol) +L[2] -  wall_thick;

        tp[ ind ] = 4 ;

        ind += 1 ;


    }






    // Assign the labels //
    for ( i=0 ; i<nstot ; i++ ) {
        if ( tp[i] == 0 )
            xc[i] = "H" ;
        else if ( tp[i] == 1 )
            xc[i] = "He" ;
        else if ( tp[i] == 2 )
            xc[i] = "O" ;
        else if ( tp[i] == 3 )
            xc[i] = "S" ;
        else if ( tp[i] == 4 )
            xc[i] = "N" ;
        else if ( tp[i] == 5 )
            xc[i] = "Br" ;
        else if ( tp[i] == 6 )
            xc[i] = "C" ;
        else if ( tp[i] == 7 )
            xc[i] = "Na" ;
        else if ( tp[i] == 8 )
            xc[i] = "P" ;
        else if ( tp[i] == 9 )
            xc[i] = "Ca" ;
        else if ( tp[i] == -1 )
            xc[i] = "X" ;
    }

    calc_A();

    printf("config generated!\n") ;
    fflush( stdout ) ;
}
void cyl_config( void ) {



    //the period in cyl phase is adjusted along x and y dim. Z dim is a slave dim!//

    int i, m, j, k, ind = 0 ;

    int num_prd = int(double(nD/2.0));

    double tmp_r,dx_adjsn = pow(L[0]*L[0] +L[1]*L[1],0.5)/4.0/double(Nda+Ndb-1), center_crd[2], tmp_center[2];
    center_crd[0] = L[0]/2.0;
    center_crd[1] = L[1]/2.0;

    double tmp_vct[2];
    x[ind][L_dim] = L[L_dim]/2.0 ;

    for(i = 0; i<nD ; i++) {


        if(ran2()<0.5) {

            x[ind][0] = center_crd[0];
            x[ind][1] = center_crd[1];
            x[ind][2] = ran2()*(L[2]-2*wall_thick)*nsD/nstot + wall_thick;

            tmp_vct[1] = ran2()*2*PI;
            tmp_vct[0] = cos(tmp_vct[1]);
            tmp_vct[1] = sin(tmp_vct[1]);

            tp[ ind ] = ( Nda > 0 ? 0 : 1 ) ;

            ind +=1;


            for(j=1 ; j<(Nda +Ndb); j++ ) {
                x[ind][2] = x[ind-1][2];
                x[ind][0] = x[ind-1][0] +dx_adjsn*tmp_vct[0];
                x[ind][1] = x[ind-1][1] +dx_adjsn*tmp_vct[1];
                tp[ ind ] = ( j< Nda ? 0 : 1 ) ;
                ind +=1 ;

            }

        }
        else {
            x[ind][0] = 0;
            x[ind][1] = 0;
            x[ind][2] = ran2()*(L[2]-2*wall_thick)*nsD/nstot + wall_thick;
            tmp_vct[1] = ran2()*2*PI;
            tmp_vct[0] = cos(tmp_vct[1]);
            tmp_vct[1] = sin(tmp_vct[1]);

            tp[ ind ] = ( Nda > 0 ? 0 : 1 ) ;
            ind +=1;

            for(j=1 ; j<(Nda +Ndb); j++ ) {
                x[ind][2] = x[ind-1][2];
                x[ind][0] = x[ind-1][0] +dx_adjsn*tmp_vct[0];
                x[ind][1] = x[ind-1][1] +dx_adjsn*tmp_vct[1];
                tp[ ind ] = ( j< Nda ? 0 : 1 ) ;

                for(m = 0 ; m<Dim-1; m++) {
                    if(x[ind][m]<0)
                        x[ind][m] += L[m];
                    else if(x[ind][m]>L[m])
                        x[ind][m] -= L[m];
                    else {}
                }
                ind +=1 ;
            }

        }





    }//nD

    // Random A homopolymers //
    for ( k=0 ; k<nA ; k++ ) {
        for ( j=0 ; j<Dim ; j++ )
            x[ind][j] = ran2() * L[j] ;

        tp[ ind ] = 0 ;

        ind += 1 ;

        for ( m=1 ; m<Nha ; m++ ) {

            for ( j=0 ; j<Dim ; j++ ) {
                x[ind][j] = x[ ind-1 ][ j ] + gasdev2() ;

                if ( x[ind][j] > L[j] )
                    x[ind][j] -= L[j] ;
                else if ( x[ind][j] < 0.0 )
                    x[ind][j] += L[j] ;
            }

            tp[ ind ] = 0 ;

            ind++ ;

        }
    }

    // Random B homopolymers //
    for ( k=0 ; k<nB ; k++ ) {
        for ( j=0 ; j<Dim ; j++ )
            x[ind][j] = ran2() * L[j] ;

        tp[ ind ] = 1 ;

        ind += 1 ;

        for ( m=1 ; m<Nhb ; m++ ) {

            for ( j=0 ; j<Dim ; j++ ) {
                x[ind][j] = x[ ind-1 ][ j ] + gasdev2() ;

                if ( x[ind][j] > L[j] )
                    x[ind][j] -= L[j] ;
                else if ( x[ind][j] < 0.0 )
                    x[ind][j] += L[j] ;
            }

            tp[ ind ] = 1 ;

            ind++ ;

        }
    }

    // Random C homopolymers //
    for ( k=0 ; k<nC ; k++ ) {
        for ( j=0 ; j<(Dim-1) ; j++ )
            x[ind][j] = ran2() * L[j] ;

        tmp_r =  -ran2()*(L[2]-2*wall_thick)*nsC/nstot +L[2] -  wall_thick;
        x[ind][2]  = tmp_r ;
        tp[ ind ] = 3 ;

        ind += 1 ;

        for ( m=1 ; m<Nhc ; m++ ) {

            for ( j=0 ; j<Dim-1 ; j++ ) {
                x[ind][j] = x[ ind-1 ][ j ] + gasdev2() ;
                x[ind][2]  = tmp_r ;

                if ( x[ind][j] > L[j] )
                    x[ind][j] -= L[j] ;
                else if ( x[ind][j] < 0.0 )
                    x[ind][j] += L[j] ;
            }

            tp[ ind ] = 3 ;

            ind++ ;

        }
    }//nC


    //  Random NPs //
    for ( k=0 ; k<nP ; k++ ) {
        int center_ind , tmp_flg ,gind,prev_graft ;
        double u[Dim] ;

        x[ind][2] = ran2() * L[2] ;

        if(A_partics>=0) {

            tmp_vct[1] = ran2()*2*PI;
            tmp_vct[0] = cos(tmp_vct[1]);
            tmp_vct[1] = sin(tmp_vct[1]);
            tmp_r  = ran2()*(dx_adjsn*Nda);

            if(k<int(nP/2.0)) {
                tmp_flg = 1 ;

            }
            else {
                tmp_flg = 0;
            }
            x[ind][0] = (tmp_flg >0 ? tmp_r*tmp_vct[0] : L[0]/2.0 + tmp_r*tmp_vct[0] );
            x[ind][1] = (tmp_flg >0 ? tmp_r*tmp_vct[1] : L[1]/2.0 + tmp_r*tmp_vct[1] );

            for(m=0; m<Dim-1; m++) {
                if(x[ind][m]<0)
                    x[ind][m] += L[m];
                else if(x[ind][m] >=L[m] )
                    x[ind][m] -= L[m];
                else {}
            }
        }
        else {
            for(m=0; m<Dim; m++) {
                x[ind][m] = ran2() * L[m] ;

            }

        }

        for(j=0 ; j<3 ; j++) {

            euler_ang[k][j] = 0;
            euler_q[k][j+1] = 0;
        }

        euler_q[k][0] = 1;
        // euler_ang[k][0] = PI/2.0;

        tp[ ind ] = 2 ;

        center_ind = ind ;

        ind += 1 ;


        for ( m=0 ; m<ng_per_partic ; m++ ) {

            // Place the grafting site //
            if(uni_sig ==1) { //fibonacci grafting sites
                fibonacci_u ( u , m );
                gind = k*ng_per_partic + m;
                if(k==0 and m==0)cout<<"fibonacci grafting is used"<<endl;
            }
            else if(uni_sig ==2) { //uniform grafting
                unif_sig ( u , m );
                gind = k*ng_per_partic + m;
                if(k==0  and m==0)cout<<"uniform grafting is used"<<endl;
            }
            else { //random grafting sites
                random_u( u ) ;
                gind = k*ng_per_partic + m;
                if(k==0 and m==0)cout<<"random grafting is used"<<endl;
            }


            for ( j=0 ; j<Dim ; j++ ) {
                x[ind][j] = x[center_ind][j] + Rp * u[j] ;
                grf_bf_x[gind][j] = Rp * u[j];

                if ( x[ind][j] > L[j] )
                    x[ind][j] -= L[j] ;
                else if ( x[ind][j] < 0.0 )
                    x[ind][j] += L[j] ;
            }
            //  cout<<" ng "<<m<<" "<<x[ind][0]<<" "<<x[ind][1]<<" "<<x[ind][2]<<endl;

            tp[ ind ] = -1 ;

            if ( m > 0 ) {
                double mdr2, dr[Dim], mdr ;
                mdr2 = pbc_mdr2( x[ prev_graft ] , x[ ind ] , dr ) ;
                mdr = sqrt( mdr2 ) ;

                graft_req[k][m-1] = mdr ;
            }

            prev_graft = ind ;

            ind++ ;

            // Place the chain grafted to this site
            for ( i=0 ; i<Ng ; i++ ) {

                for ( j=0 ; j<Dim ; j++ ) {
                    x[ind][j] = x[ind-1][j] + 0.5 * u[j] ;

                    if ( x[ind][j] > L[j] )
                        x[ind][j] -= L[j] ;
                    else if ( x[ind][j] < 0.0 )
                        x[ind][j] += L[j] ;
                }

                tp[ ind ] = 0 ;
                ind++ ;
            }
        }//np_grdt
    } //nP

    // Assign the labels //
    for ( i=0 ; i<nstot ; i++ ) {
        if ( tp[i] == 0 )
            xc[i] = "H" ;
        else if ( tp[i] == 1 )
            xc[i] = "He" ;
        else if ( tp[i] == 2 )
            xc[i] = "O" ;
        else if ( tp[i] == 3 )
            xc[i] = "S" ;
        else if ( tp[i] == 4 )
            xc[i] = "N" ;
        else if ( tp[i] == 5 )
            xc[i] = "Br" ;
        else if ( tp[i] == 6 )
            xc[i] = "C" ;
        else if ( tp[i] == 7 )
            xc[i] = "Na" ;
        else if ( tp[i] == 8 )
            xc[i] = "P" ;
        else if ( tp[i] == 9 )
            xc[i] = "Ca" ;
        else if ( tp[i] == -1 )
            xc[i] = "X" ;
    }
    printf("config generated!\n") ;
    fflush( stdout ) ;
}
void lamm_config( void ) {

    int i, m, j, k, ind = 0 ;

    int num_prd = int(double(nD/2.0));
    double dx_adjsn = -L[L_dim]/2.0/double(Nda+Ndb-1);

    for(i=0; i<2; i++) {
        for(k = 0 ; k< (i !=1 ? num_prd :(nD-num_prd)); k++) {
            for ( j=0 ; j<(Dim) ; j++ )
                if(j!= L_dim)x[ind][j] = ran2() * L[j] ;

            x[ind][L_dim] = L[L_dim]/2.0 ;

            tp[ ind ] = ( Nda > 0 ? 0 : 1 ) ;

            ind += 1 ;

            for ( m=1 ; m<Nda + Ndb ; m++ ) {



                for ( j=0 ; j<Dim ; j++ ) {
                    if(j!= L_dim)
                        x[ind][j] = x[ ind-1 ][ j ];

                }
                x[ind][L_dim] = x[ ind-1 ][ L_dim ]  +dx_adjsn;

                tp[ ind ] = ( m < Nda ? 0 : 1 ) ;

                ind++ ;

            }
        }//num_prd
        dx_adjsn *=-1;
    }//i<4



    // Random A homopolymers //
    for ( k=0 ; k<nP ; k++ ) {
        int center_ind , gind,prev_graft ;
        double u[Dim] ;

        for ( j=0 ; j<Dim ; j++ )
            if(j != L_dim)x[ind][j] = ran2() * L[j] ;

        if(A_partics>=0) {
            x[ind][L_dim] = L[L_dim]/2 + (ran2() -0.5) * (L[L_dim]/2.0-Rp);
        }
        else {

            x[ind][L_dim] = L[L_dim]/4 + L[L_dim]/2*(ran2()> 0.5 ? 1:0) + (ran2() -0.5) *Rp;

        }

        for(j=0 ; j<3 ; j++) {

            euler_ang[k][j] = 0;
            euler_q[k][j+1] = 0;
        }

        euler_q[k][0] = 1;
        // euler_ang[k][0] = PI/2.0;

        tp[ ind ] = 2 ;

        center_ind = ind ;

        ind += 1 ;


        for ( m=0 ; m<ng_per_partic ; m++ ) {

            // Place the grafting site //
            if(uni_sig ==1) { //fibonacci grafting sites
                fibonacci_u ( u , m );
                gind = k*ng_per_partic + m;
                if(k==0 and m==0)cout<<"fibonacci grafting is used"<<endl;
            }
            else if(uni_sig ==2) { //uniform grafting
                unif_sig ( u , m );
                gind = k*ng_per_partic + m;
                if(k==0  and m==0)cout<<"uniform grafting is used"<<endl;
            }
            else { //random grafting sites
                random_u( u ) ;
                gind = k*ng_per_partic + m;
                if(k==0 and m==0)cout<<"random grafting is used"<<endl;
            }


            for ( j=0 ; j<Dim ; j++ ) {
                x[ind][j] = x[center_ind][j] + Rp * u[j] ;
                grf_bf_x[gind][j] = Rp * u[j];

                if ( x[ind][j] > L[j] )
                    x[ind][j] -= L[j] ;
                else if ( x[ind][j] < 0.0 )
                    x[ind][j] += L[j] ;
            }
            //  cout<<" ng "<<m<<" "<<x[ind][0]<<" "<<x[ind][1]<<" "<<x[ind][2]<<endl;

            tp[ ind ] = -1 ;

            if ( m > 0 ) {
                double mdr2, dr[Dim], mdr ;
                mdr2 = pbc_mdr2( x[ prev_graft ] , x[ ind ] , dr ) ;
                mdr = sqrt( mdr2 ) ;

                graft_req[k][m-1] = mdr ;
            }

            prev_graft = ind ;

            ind++ ;

            // Place the chain grafted to this site
            for ( i=0 ; i<Ng ; i++ ) {

                for ( j=0 ; j<Dim ; j++ ) {
                    x[ind][j] = x[ind-1][j] + 0.5 * u[j] ;

                    if ( x[ind][j] > L[j] )
                        x[ind][j] -= L[j] ;
                    else if ( x[ind][j] < 0.0 )
                        x[ind][j] += L[j] ;
                }

                tp[ ind ] = 0 ;
                ind++ ;
            }
        }//np_grdt
    } //nP

    // Assign the labels //
    for ( i=0 ; i<nstot ; i++ ) {
        if ( tp[i] == 0 )
            xc[i] = "H" ;
        else if ( tp[i] == 1 )
            xc[i] = "He" ;
        else if ( tp[i] == 2 )
            xc[i] = "O" ;
        else if ( tp[i] == 3 )
            xc[i] = "S" ;
        else if ( tp[i] == 4 )
            xc[i] = "N" ;
        else if ( tp[i] == 5 )
            xc[i] = "Br" ;
        else if ( tp[i] == 6 )
            xc[i] = "C" ;
        else if ( tp[i] == 7 )
            xc[i] = "Na" ;
        else if ( tp[i] == 8 )
            xc[i] = "P" ;
        else if ( tp[i] == 9 )
            xc[i] = "Ca" ;
    }
    printf("config generated!\n") ;
    fflush( stdout ) ;
}
Esempio n. 14
0
int main (int, char **)
{
    int w = 768, h = 768, iterations = 0;
    std::vector<glm::vec3> colors(w * h, glm::vec3{0.f, 0.f, 0.f});

    Ray cam {{50, 52, 295.6}, glm::normalize(glm::vec3{0, -0.042612, -1})};	// cam pos, dir
    float near = 1.f;
    float far = 10000.f;

    glm::mat4 camera =
        glm::scale(glm::mat4(1.f), glm::vec3(float(w), float(h), 1.f))
        * glm::translate(glm::mat4(1.f), glm::vec3(0.5, 0.5, 0.f))
        * glm::perspective(float(54.5f * pi / 180.f), float(w) / float(h), near, far)
        * glm::lookAt(cam.origin, cam.origin + cam.direction, glm::vec3(0, 1, 0))
        ;

    glm::mat4 screenToRay = glm::inverse(camera);
    QTime t;
    t.start();
    #pragma omp parallel for
    for (int y = 0; y < h; y++)
    {
        std::cerr << "\rRendering: " << 100 * iterations / ((w-1)*(h-1)) << "%";

        for (unsigned short x = 0; x < w; x++)
        {
            glm::vec3 r;
            float smoothies = 5.f;
            for(int smooths = 0; smooths < smoothies; ++smooths)
            {
                float u = random_u();
                //float v = random_u();
                float R = sqrt(-2*log(u));
                //float R2 = sqrt(-2*log(v));
                float xDecal = R * cos(2*pi*u)*.5;
                float yDecal = R * sin(2*pi*u)*.5;
                glm::vec4 p0 = screenToRay * glm::vec4{float(x)+xDecal-.5, float(h - y )+ yDecal-.5, 0.f, 1.f};
                glm::vec4 p1 = screenToRay * glm::vec4{float(x)+xDecal-.5, float(h - y )+ yDecal-.5, 1.f, 1.f};

                glm::vec3 pp0 = glm::vec3(p0 / p0.w);
                glm::vec3 pp1 = glm::vec3(p1 / p1.w);

                glm::vec3 d = glm::normalize(pp1 - pp0);

                r += radiance (Ray{pp0, d});

            }
            r/=smoothies;
            colors[y * w + x] = colors[y * w + x]*0.25f + glm::clamp(r, glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.f, 1.f, 1.f));// * 0.25f;
            ++iterations;
        }
    }

    {
        std::fstream f("C:\\Users\\etu\\Desktop\\image6.ppm", std::fstream::out);
        f << "P3\n" << w << " " << h << std::endl << "255" << std::endl;

        for (auto c : colors)
            f << toInt(c.x) << " " << toInt(c.y) << " " << toInt(c.z) << " ";
    }

    std::cout << std::endl << "Rendered in " << t.elapsed()/1000. << "s." << std::endl;
}
Esempio n. 15
0
// dirLux normalisé
glm::vec3 random_light(const glm::vec3 dirLux, float &pdf) {
    float u = random_u();
    float v = random_u();
    return sample_sphere(10.f, u, v, pdf, -dirLux);
}