void HamiltonMatrix::computeMatrixElements() { cout << "Computing the Hamilton matrix " << endl; int s; int nStates = SLBit.size(); // int newState; bitset<BITS> newState; int i, j, k, l; double interactionElement; H = zeros(nStates, nStates); for (int st = 0; st < SLBit.size(); st++) { for (int b = 0; b < interactions.n_rows; b++) { newState = SLBit[st]; i = interactions(b, 0); j = interactions(b, 1); k = interactions(b, 2); l = interactions(b, 3); interactionElement = interactions(b, 4); // Using the two body operator. Mathematics: a+(i)a+(j)a-(l)a-(k)|psi> s = 1; newState = removeParticle(k, newState); s *= sign(k, newState); newState = removeParticle(l, newState); s *= sign(l, newState); newState = addParticle(j, newState); s *= sign(j, newState); newState = addParticle(i, newState); s *= sign(i, newState); if (newState != 0) { // Searching for the new state to compute the matrix elements. for (int st2 = 0; st2 < SLBit.size(); st2++) { if (newState == SLBit[st2]) { H(st, st2) += interactionElement * s; } } } } // One body energies H(st, st) += oneBodyEnergy(st); } // Symmetrizing the Hamilton matrix for (int i = 0; i < H.n_rows; i++) { for (int j = 0; j < i; j++) { H(j, i) = H(i, j); } } cout << "Completed generating the Hamilton matrix" << endl; }
// The grid gets divided into segments (of dimensions LPG.XSS * LPG.YSS * // LPG.ZSS cells) each of which is assigned to a separate thread for particle // interaction scan. Each slot of vector SEGMENT_INTERACTIONS contains a vector // with the interactions scanned in a segment. This vector is then flattened and // returned. std::vector<interaction> collect_interactions(lp_grid lpg) { long xs_count = 1+lpg.x/lpg.xss; long ys_count = 1+lpg.y/lpg.yss; long zs_count = 1+lpg.z/lpg.zss; long thread_count = xs_count*ys_count*zs_count; std::vector< std::thread > threads (thread_count); std::vector< std::vector<interaction> > segment_interactions (thread_count); long sii=0; // sii = segment interactions index for (long xsi=0; xsi<xs_count; xsi++) for (long ysi=0; ysi<ys_count; ysi++) for (long zsi=0; zsi<zs_count; zsi++, sii++) threads[sii] = std::thread (collect_segment_interactions, lpg, xsi, ysi, zsi, sii, std::ref(segment_interactions)); for (long ti=0; ti<thread_count; ti++) threads[ti].join(); // flatten interaction vector long ic=0; // interaction count for(sii=0; sii<segment_interactions.size(); sii++) ic += segment_interactions[sii].size(); std::vector<interaction> interactions (ic); long fii=0; // flat interactions index for(sii=0; sii<segment_interactions.size(); sii++) for(long ii=0; ii<segment_interactions[sii].size(); ii++, fii++) interactions[fii] = segment_interactions[sii][ii]; return interactions; }
/* #if 1 #include "mex.h" // matlab: function pairs = interactions(pos, L, boxdim, cutoff) // assumes pos is in [0,L]^3 // assumes boxdim >= 4 // pairs is an int array, may need to convert to double for matlab use void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int npos; const double *pos; double L; int boxdim; double cutoff; npos = mxGetN(prhs[0]); pos = mxGetPr(prhs[0]); L = mxGetScalar(prhs[1]); boxdim = (int) mxGetScalar(prhs[2]); cutoff = mxGetScalar(prhs[3]); // estimate max number of pairs, assuming somewhat uniform distribution double ave_per_box = npos / (double)(boxdim*boxdim*boxdim) + 1.; int maxnumpairs = (int) (0.7*npos*ave_per_box*(NUM_BOX_NEIGHBORS+1) + 1.); printf("interactions: maxnumpairs: %d\n", maxnumpairs); // allocate storage for output int *pairs = (int *) malloc(2*maxnumpairs*sizeof(int)); double *distances2 = (double *) malloc(maxnumpairs*sizeof(double)); if (pairs == NULL || distances2 == NULL) { printf("interactions: could not allocate storage\n"); return; } int numpairs; // actual number of pairs int ret; ret = interactions(npos, pos, L, boxdim, cutoff*cutoff, distances2, pairs, maxnumpairs, &numpairs); if (ret != 0) { printf("interactions: error occured\n"); if (ret == -1) printf("interactions: estimate of required storage was too low\n"); return; } printf("interactions: numpairs: %d\n", numpairs); // allocate matlab output matrix plhs[0] = mxCreateDoubleMatrix(numpairs, 3, mxREAL); double *data = (double *) mxGetPr(plhs[0]); // first col of data array is row indices // second col of data array is col indices // third col of data array is distance2 int i; for (i=0; i<numpairs; i++) { data[i] = pairs[2*i]; data[i+numpairs] = pairs[2*i+1]; data[i+numpairs*2] = distances2[i]; } free(pairs); free(distances2); } #else*/ int main() { int npos = 3; double pos[] = {0., 0., 0., 0., 0., 3.5, 0., 3.5, 0.}; double L = 8; int pairs[1000*2]; int numpairs; double distances2[1000]; //int interactions(int npos, const double *pos, double L, int boxdim, // double cutoff2, double *distances2, // int *pairs, int maxnumpairs, int *numpairs_p) //interactions(npos, pos, L, 8, 99., pairs, 1000, &numpairs); interactions(npos, pos, L, 8, 4,distances2, pairs, 1000, &numpairs); printf("numpairs %d\n", numpairs); return 0; }
// -------------------------------------------------------------------------- // // void Test_Interactions::testConstruction() { std::vector<Process> processes; processes.push_back(Process()); processes.push_back(Process()); const bool implicit_wildcards = false; Interactions interactions(processes, implicit_wildcards); CPPUNIT_ASSERT( !interactions.useCustomRates() ); // Construct with a rate calculator. const RateCalculator rc; std::vector<CustomRateProcess> processes2; processes2.push_back(CustomRateProcess()); processes2.push_back(CustomRateProcess()); Interactions interactions2(processes2, implicit_wildcards, rc); CPPUNIT_ASSERT( interactions2.useCustomRates() ); // DONE }
int main() { int i, j, tstep; time_t t; srand((unsigned) time(&t)); struct timeval startTime, endTime; long long time1, time2, totaltime; getBasic(); printf("No. of Particles : %d\nNo. of Particles on shell : %d\nShell Radius : %d \n", npos, nsphere, shell_radius); /////START TOTAL_TIME //gettimeofday(&startTime, NULL); double *pos, *shell, *rad; pos = (double *)malloc(sizeof(double)*(npos+nsphere)*3); rad = (double *)malloc(sizeof(double)*npos); shell = pos + 3*npos; setPosRad(pos, rad); savePos(pos, rad, 0); getShell(shell); //printf("here\n"); //check pos & shell //printVectors(pos, npos+nsphere, 3); double L = 2*shell_radius; int boxdim = shell_radius; double cutoff2 = (2 * shell_particle_radius) * (2 * shell_particle_radius); int maxnumpairs = 5000000; int *pairs = (int *)malloc(sizeof(int)*2*maxnumpairs); int *finalPairs = (int *)malloc(sizeof(int)*2*maxnumpairs); double *distances2 = (double *)malloc(sizeof(double)*maxnumpairs); int numpairs_p; double *f; f = (double *)malloc(sizeof(double)*3*npos); complex *f1, *f2, *f3, *rpy, *lanczos_out; f1 = (complex *)malloc(sizeof(complex)*npos); f2 = (complex *)malloc(sizeof(complex)*npos); f3 = (complex *)malloc(sizeof(complex)*npos); rpy = (complex *)malloc(sizeof(complex)*(npos*3)); lanczos_out = (complex *)malloc(sizeof(complex)*(npos*3)); double *f_serial; f_serial = (double *)malloc(sizeof(double)*3*npos); double error1, error2; double *standardNormalZ1, *standardNormalZ; standardNormalZ = (double *)malloc(sizeof(double)*npos*3); standardNormalZ1 = (double *)malloc(sizeof(double)*npos*3); lanczos_t *lanczos, *lanczos1; lanczos = malloc(sizeof(lanczos)); int maxiters = 200; double *A; lanczos1 = malloc(sizeof(lanczos)); A = (double *)malloc(sizeof(double)*3*3*npos*npos); char dir[100] = "outputs/"; //double *Mf; //Mf = (double *)malloc(sizeof(double)*3*npos); for(tstep = 0; tstep<tmax; tstep++) { printf("time step %d started\n", tstep+1); //gettimeofday(&startTime, NULL); interactions(npos+nsphere, pos, L, boxdim, cutoff2, distances2, pairs, maxnumpairs, &numpairs_p); interactionsFilter(&numpairs_p, pairs, finalPairs, rad, pos); printf("beyond interactions\n"); //printf("Final number of pairs (after filtering) : %d\n", numpairs_p); computeForce(f, f1, f2, f3, pos, rad, finalPairs, numpairs_p); //gettimeofday(&endTime, NULL); //time1 = (endTime.tv_sec-startTime.tv_sec)*1000000 + endTime.tv_usec-startTime.tv_usec; //printf("For INTERACTIVE : %ld msec\n", time1/1000); if(CHECKCODE) { //gettimeofday(&startTime, NULL); computeForceSerial(f_serial, pos, rad, shell); //gettimeofday(&endTime, NULL); //time2 = (endTime.tv_sec-startTime.tv_sec)*1000000 + endTime.tv_usec-startTime.tv_usec; //printf("For SERIAL : %ld msec\n", time2/1000); //printVectors(f_serial, npos, 3); //error1 = relError(f_serial, f, npos, 3); //printf("Relative Error in computeForce %lf\n", error1); //error2 = maxError(f_serial, f, npos, 3); //printf("Max Error in computeForce %lf\n", error2); } //char dir[100] = "outputs/"; //printf("Calling computeRPY : \n"); //gettimeofday(&startTime, NULL); computerpy_(&npos, pos, rad, f1, f2, f3, rpy, dir); //gettimeofday(&endTime, NULL); //time2 = (endTime.tv_sec-startTime.tv_sec)*1000000 + endTime.tv_usec-startTime.tv_usec; //printf("For 5 call FMM: %ld \n", time2/1000); //gettimeofday(&endTime, NULL); //time1 = (endTime.tv_sec-startTime.tv_sec)*1000000 + endTime.tv_usec-startTime.tv_usec; //printf("Total Time taken for RPY with FMM: %ld \n", time1/1000); //printf("Calling postCorrection : \n"); //gettimeofday(&startTime, NULL); //postCorrection(npos, pos, rad, numpairs_p, finalPairs, f1, f2, f3, rpy); getNorm((100000000+(rand()%99999999)), standardNormalZ); //getNorm((100000000+(rand()%99999999)), standardNormalZ1); //printVectors(standardNormalZ, 3*npos, 1); /* if(CHECKCODE){ for(i=0;i<npos*3;i++) standardNormalZ1[i] = standardNormalZ[i]; } */ // if(CHECKCODE) { //create_lanczos (&lanczos1, 1, maxiters, npos*3); //double *Az; //Az = (double *)malloc(sizeof(double)*3*npos); //gettimeofday(&startTime, NULL); createDiag(A, rad); //sqrtMatrix(A, standardNormalZ1); //printVectors(A, 3*npos, 3*npos); //printVectorsToFile(A, 3*npos); mobilityMatrix(A, pos, rad); //printVectorsToFile(A, 3*npos); //printVectorsToFile(A, npos*3); //compute_lanczos(lanczos1, 1e-4, 1, standardNormalZ1, 3*npos, // SERIAL, f1, f2, f3, lanczos_out, pos, rad, numpairs_p, finalPairs, A); //printf("Z: \n"); //printVectors(standardNormalZ1, npos, 3); //printVectorsToFile(A, 3*npos); multiplyMatrix(A, f_serial); //gettimeofday(&endTime, NULL); //time1 = (endTime.tv_sec-startTime.tv_sec)*1000000 + endTime.tv_usec-startTime.tv_usec; //printf("For SERIAL : %ld msec\n", time1/1000); //printf("Mf: \n"); //printf("M*f : \n"); //printVectors(A, npos, 3); //printf("\n"); //printf("RPY : \n"); //printVectorsComplex(rpy, 10, 3); //printf("\n"); //printf("Relative error in RPy and M*f : %lf\n", relErrorRealComplex(A, rpy, npos, 3)); //printf("Maximum error in Rpy and M*f : %lf\n", maxErrorRealComplex(A, rpy, npos, 3)); } //printf("Adding Random Brownian motion ... \n"); create_lanczos (&lanczos, 1, maxiters, npos*3); compute_lanczos(lanczos, 1e-4, 1, standardNormalZ, 3*npos, FMM, f1, f2, f3, lanczos_out, pos, rad, numpairs_p, finalPairs, A); /////////END TOTAL_TIME //gettimeofday(&endTime, NULL); //totaltime = (endTime.tv_sec-startTime.tv_sec)*1000000 + endTime.tv_usec-startTime.tv_usec; //printf("Total time computing 1 time step (%d particles) : %ld msec\n", npos, totaltime/1000); //if(CHECKCODE){ // printf("Relative Error in brownian : %lf\n", relError(standardNormalZ, standardNormalZ1, npos, 3)); //} updatePos(pos, rpy, standardNormalZ); //updatePosSerial(pos, A, standardNormalZ1); //printf("new pos: \n"); //printVectors(pos, npos, 3); savePos(pos, rad, tstep+1); printf("%d time steps done\n\n", tstep+1); } //gettimeofday(&endTime, NULL); //totaltime = (endTime.tv_sec-startTime.tv_sec)*1000000 + endTime.tv_usec-startTime.tv_usec; //printf("Total time computing %d time steps (%d particles) : %ld msec\n", tmax, npos, totaltime/1000); return 0; }
int main(int argc, char **argv) { int option, steps = 365, delta = 1, body_count; char *input = "init.dat", *output = "result.dat"; bool parallel = false, mpi = false, global_newton = false; long double start; long double px, py; imggen_info img_info; body *bodies = NULL; /* PBM default values */ img_info.gen_img = false; img_info.img_steps = 1000; img_info.img_prefix = "PBM"; img_info.offset = 2; img_info.width = 600; img_info.heigth = 600; /* Read cmdline params */ while ((option = getopt(argc,argv,"phs:d:f:o:i:x:gmn")) != -1) { switch(option) { case 'p': parallel = true; break; case 's': steps = atoi(optarg); break; case 'd': delta = atoi(optarg); break; case 'f': input = optarg; break; case 'o': output = optarg; break; case 'i': img_info.img_prefix = optarg; break; case 'x': img_info.img_steps = atoi(optarg); break; case 'g': img_info.gen_img = true; break; case 'm': mpi = true; break; case 'n': global_newton = true; break; default: printhelp(); return 1; } } /* Init MPI */ MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &mpi_processors); MPI_Comm_rank(MPI_COMM_WORLD, &mpi_self); /* Validate params */ if (steps < 0 || delta < 1 || img_info.img_steps < 1) { m_printf("Wrong parameter value! Will exit!\n Steps: %i | Delta: %i | Input Filepath: %s", steps, delta, input); } bodies = readBodies(fopen(input,"r"), &body_count); if (bodies == NULL) { m_printf("Error while reading input file %s. Will exit now!\n", input); MPI_Finalize(); return 1; } /* Assert that all masses > 0 and any two particles do not share the same position */ if (!examineBodies(bodies, body_count, &img_info.max_x, &img_info.max_y)) { m_printf("Error while reading input file %s. Some value are not permitted!\n", input); printBodies(bodies, body_count); MPI_Finalize(); return 1; } totalImpulse(bodies, body_count, &px, &py); m_printf("Initial total impulse: px = %Le , py = %Le\n", px, py); MPI_Barrier(MPI_COMM_WORLD); start = seconds(); if (parallel) { m_printf("PARALLEL\n"); if (mpi) { m_printf("MPI+OMP\n"); if (global_newton) { m_printf("GLOBAL NEWTON\n"); solve_parallel_mpi_global_newton(bodies, body_count, steps, delta, img_info); } else { solve_parallel_mpi(bodies, body_count, steps, delta, img_info); } } else { m_printf("OMP\n"); solve_parallel(bodies, body_count, steps, delta, img_info); } } else { m_printf("SEQUENTIAL\n"); solve_sequential(bodies, body_count, steps, delta, img_info); } MPI_Barrier(MPI_COMM_WORLD); long double elapsed = seconds() - start; m_printf("Rate of interactions: %Lf\n", interactions(body_count, steps, elapsed)); m_printf("Elapsed time: %Lf\n", elapsed); totalImpulse(bodies, body_count, &px, &py); m_printf("Resulting total impulse: px = %Le , py = %Le\n", px, py); /* Write result to file */ FILE *f = fopen(output,"w"); if (f == NULL) { m_printf("Error while opening output file %s.\n", output); MPI_Finalize(); return 1; } writeBodies(f, bodies, body_count); MPI_Finalize(); return 0; }
// -------------------------------------------------------------------------- // // void Test_Interactions::testUpdateProcessIDMoves() { // Setup two valid processes. std::vector<Process> processes; std::vector<std::string> process_elements1(3); process_elements1[0] = "A"; process_elements1[1] = "B"; process_elements1[2] = "V"; std::vector<std::string> process_elements2(3); process_elements2[0] = "B"; process_elements2[1] = "A"; process_elements2[2] = "A"; std::vector<std::vector<double> > process_coordinates1(3, std::vector<double>(3, 0.0)); process_coordinates1[1][0] = -1.0; process_coordinates1[1][1] = 0.0; process_coordinates1[1][2] = 0.0; process_coordinates1[2][0] = 0.3; process_coordinates1[2][1] = 0.3; process_coordinates1[2][2] = 0.3; std::vector<int> move_origins; move_origins.push_back(0); move_origins.push_back(1); std::vector<Coordinate> move_vectors; move_vectors.push_back( Coordinate(-1.0, 0.0, 0.0) ); move_vectors.push_back( Coordinate( 1.0, 0.0, 0.0) ); // Possible types. std::map<std::string, int> possible_types; possible_types["*"] = 0; possible_types["A"] = 1; possible_types["B"] = 2; possible_types["V"] = 3; const double rate = 13.7; const Configuration c1(process_coordinates1, process_elements1, possible_types); const Configuration c2(process_coordinates1, process_elements2, possible_types); // Let this process be valid at site 0. processes.push_back(Process(c1,c2,rate,std::vector<int>(1,0), move_origins, move_vectors)); // Let this process be valid at sites 0 and 2. std::vector<int> sites_vector(2,0); sites_vector[1] = 2; processes.push_back(Process(c1,c2,rate,sites_vector, move_origins, move_vectors)); std::vector<std::vector<double> > process_coordinates2(3, std::vector<double>(3, 0.0)); process_coordinates2[1][0] = 0.7; process_coordinates2[1][1] = 0.7; process_coordinates2[1][2] = -0.3; process_coordinates2[2][0] = 1.0; process_coordinates2[2][1] = 1.0; process_coordinates2[2][2] = 1.0; move_vectors[0] = Coordinate( 0.7, 0.7, -0.3); move_vectors[1] = Coordinate(-0.7,-0.7, 0.3); const Configuration c3(process_coordinates2, process_elements1, possible_types); const Configuration c4(process_coordinates2, process_elements2, possible_types); // Let the process be valid at site 1. processes.push_back(Process(c3,c4,rate,std::vector<int>(1,1), move_origins, move_vectors)); Interactions interactions(processes, true); // Generate a corresponding configuration. std::vector<std::vector<double> > config_coordinates; std::vector<std::string> elements; for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) { for (int k = 0; k < 5; ++k) { std::vector<double> coord(3); coord[0] = 0.0 + i*1.0; coord[1] = 0.0 + j*1.0; coord[2] = 0.0 + k*1.0; config_coordinates.push_back(coord); elements.push_back("V"); coord[0] = 0.3 + i*1.0; coord[1] = 0.3 + j*1.0; coord[2] = 0.3 + k*1.0; elements.push_back("B"); config_coordinates.push_back(coord); } } } // Get the config and lattice map. Configuration config(config_coordinates, elements, possible_types); const LatticeMap lattice_map(2, std::vector<int>(3,5), std::vector<bool>(3,true)); // Now, setup the matchlists in the configuration. config.initMatchLists(lattice_map, interactions.maxRange()); // Check the process match lists before we start. CPPUNIT_ASSERT_EQUAL(static_cast<int>(interactions.processes()[0]->minimalMatchList().size()), 3); CPPUNIT_ASSERT_EQUAL(static_cast<int>(interactions.processes()[1]->minimalMatchList().size()), 3); CPPUNIT_ASSERT_EQUAL(static_cast<int>(interactions.processes()[2]->minimalMatchList().size()), 3); // Check the id moves before update. { const std::vector< std::pair<int, int> > & id_moves = interactions.processes()[0]->idMoves(); CPPUNIT_ASSERT_EQUAL( static_cast<int>(id_moves.size()), 2 ); CPPUNIT_ASSERT_EQUAL( id_moves[0].first, 0 ); CPPUNIT_ASSERT_EQUAL( id_moves[0].second, 2 ); CPPUNIT_ASSERT_EQUAL( id_moves[1].first, 2 ); CPPUNIT_ASSERT_EQUAL( id_moves[1].second, 0 ); } // Update the interactions according to the configuration match lists. // This also updates the id moves on the processes. interactions.updateProcessMatchLists(config, lattice_map); // Check the id moves after update. { const std::vector<MinimalMatchListEntry> & match = interactions.processes()[0]->minimalMatchList(); CPPUNIT_ASSERT_EQUAL( static_cast<int>(match.size()), 6 ); const std::vector< std::pair<int, int> > & id_moves = interactions.processes()[0]->idMoves(); CPPUNIT_ASSERT_EQUAL( static_cast<int>(id_moves.size()), 2 ); CPPUNIT_ASSERT_EQUAL( id_moves[0].first, 0 ); CPPUNIT_ASSERT_EQUAL( id_moves[0].second, 5 ); CPPUNIT_ASSERT_EQUAL( id_moves[1].first, 5 ); CPPUNIT_ASSERT_EQUAL( id_moves[1].second, 0 ); // Wildcards are now added. CPPUNIT_ASSERT_EQUAL( match[0].match_type, 1 ); CPPUNIT_ASSERT_EQUAL( match[1].match_type, 3 ); CPPUNIT_ASSERT_EQUAL( match[2].match_type, 0 ); CPPUNIT_ASSERT_EQUAL( match[3].match_type, 0 ); CPPUNIT_ASSERT_EQUAL( match[4].match_type, 0 ); CPPUNIT_ASSERT_EQUAL( match[5].match_type, 2 ); } }
// -------------------------------------------------------------------------- // // void Test_Interactions::testUpdateProcessMatchLists() { // Setup two valid processes. std::vector<Process> processes; std::vector<std::string> process_elements1(3); process_elements1[0] = "A"; process_elements1[1] = "B"; process_elements1[2] = "V"; std::vector<std::string> process_elements2(3); process_elements2[0] = "B"; process_elements2[1] = "A"; process_elements2[2] = "A"; std::vector<std::vector<double> > process_coordinates1(3, std::vector<double>(3, 0.0)); process_coordinates1[1][0] = -1.0; process_coordinates1[1][1] = 0.0; process_coordinates1[1][2] = 0.0; process_coordinates1[2][0] = 0.3; process_coordinates1[2][1] = 0.3; process_coordinates1[2][2] = 0.3; // Possible types. std::map<std::string, int> possible_types; possible_types["*"] = 0; possible_types["A"] = 1; possible_types["B"] = 2; possible_types["V"] = 3; const double rate = 13.7; const Configuration c1(process_coordinates1, process_elements1, possible_types); const Configuration c2(process_coordinates1, process_elements2, possible_types); // Let this process be valid at site 0. processes.push_back(Process(c1,c2,rate,std::vector<int>(1,0))); // Let this process be valid at sites 0 and 2. std::vector<int> sites_vector(2,0); sites_vector[1] = 2; processes.push_back(Process(c1,c2,rate,sites_vector)); std::vector<std::vector<double> > process_coordinates2(3, std::vector<double>(3, 0.0)); process_coordinates2[1][0] = 0.7; process_coordinates2[1][1] = 0.7; process_coordinates2[1][2] = -0.3; process_coordinates2[2][0] = 1.0; process_coordinates2[2][1] = 1.0; process_coordinates2[2][2] = 1.0; const Configuration c3(process_coordinates2, process_elements1, possible_types); const Configuration c4(process_coordinates2, process_elements2, possible_types); // Let the process be valid at site 1. processes.push_back(Process(c3,c4,rate,std::vector<int>(1,1))); Interactions interactions(processes, true); // Generate a corresponding configuration. std::vector<std::vector<double> > config_coordinates; std::vector<std::string> elements; for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) { for (int k = 0; k < 5; ++k) { std::vector<double> coord(3); coord[0] = 0.0 + i*1.0; coord[1] = 0.0 + j*1.0; coord[2] = 0.0 + k*1.0; config_coordinates.push_back(coord); elements.push_back("V"); coord[0] = 0.3 + i*1.0; coord[1] = 0.3 + j*1.0; coord[2] = 0.3 + k*1.0; elements.push_back("B"); config_coordinates.push_back(coord); } } } // Get the config and lattice map. Configuration config(config_coordinates, elements, possible_types); // Make sure we do this on a non-periodic lattice map, to make sure // the most central cell is choosen for determining wildcard positions. const LatticeMap lattice_map(2, std::vector<int>(3,5), std::vector<bool>(3,false)); // Now, setup the matchlists in the configuration. config.initMatchLists(lattice_map, interactions.maxRange()); // Check the process match lists before we start. CPPUNIT_ASSERT_EQUAL(static_cast<int>(interactions.processes()[0]->minimalMatchList().size()), 3); CPPUNIT_ASSERT_EQUAL(static_cast<int>(interactions.processes()[1]->minimalMatchList().size()), 3); CPPUNIT_ASSERT_EQUAL(static_cast<int>(interactions.processes()[2]->minimalMatchList().size()), 3); // Update the interactions according to the configuration match lists. interactions.updateProcessMatchLists(config, lattice_map); // Check a few coordinates and match types. { const std::vector<MinimalMatchListEntry> & match = interactions.processes()[0]->minimalMatchList(); CPPUNIT_ASSERT_EQUAL( static_cast<int>(match.size()), 6 ); // Wildcards are now added. CPPUNIT_ASSERT_EQUAL( match[0].match_type, 1 ); CPPUNIT_ASSERT_EQUAL( match[1].match_type, 3 ); CPPUNIT_ASSERT_EQUAL( match[2].match_type, 0 ); CPPUNIT_ASSERT_EQUAL( match[3].match_type, 0 ); CPPUNIT_ASSERT_EQUAL( match[4].match_type, 0 ); CPPUNIT_ASSERT_EQUAL( match[5].match_type, 2 ); // These are not changed - but sorted. CPPUNIT_ASSERT_DOUBLES_EQUAL( match[0].coordinate.x(), process_coordinates1[0][0], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[0].coordinate.y(), process_coordinates1[0][1], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[0].coordinate.z(), process_coordinates1[0][2], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[1].coordinate.x(), process_coordinates1[2][0], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[1].coordinate.y(), process_coordinates1[2][1], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[1].coordinate.z(), process_coordinates1[2][2], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[5].coordinate.x(), process_coordinates1[1][0], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[5].coordinate.y(), process_coordinates1[1][1], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[5].coordinate.z(), process_coordinates1[1][2], 1.0e-10 ); // Here are the added wildcards. CPPUNIT_ASSERT_DOUBLES_EQUAL( match[2].coordinate.x(), -0.7, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[2].coordinate.y(), 0.3, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[2].coordinate.z(), 0.3, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[3].coordinate.x(), 0.3, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[3].coordinate.y(), -0.7, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[3].coordinate.z(), 0.3, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[4].coordinate.x(), 0.3, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[4].coordinate.y(), 0.3, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[4].coordinate.z(), -0.7, 1.0e-10 ); } { // This one is not changed, since it was applicable to more than one basis site. const std::vector<MinimalMatchListEntry> & match = interactions.processes()[1]->minimalMatchList(); CPPUNIT_ASSERT_EQUAL( static_cast<int>(match.size()), 3 ); // Not changed - but sorted. CPPUNIT_ASSERT_DOUBLES_EQUAL( match[0].coordinate.x(), process_coordinates1[0][0], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[0].coordinate.y(), process_coordinates1[0][1], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[0].coordinate.z(), process_coordinates1[0][2], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[1].coordinate.x(), process_coordinates1[2][0], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[1].coordinate.y(), process_coordinates1[2][1], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[1].coordinate.z(), process_coordinates1[2][2], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[2].coordinate.x(), process_coordinates1[1][0], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[2].coordinate.y(), process_coordinates1[1][1], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[2].coordinate.z(), process_coordinates1[1][2], 1.0e-10 ); } { const std::vector<MinimalMatchListEntry> & match = interactions.processes()[2]->minimalMatchList(); CPPUNIT_ASSERT_EQUAL( static_cast<int>(match.size()), 47 ); // Not changed. CPPUNIT_ASSERT_DOUBLES_EQUAL( match[0].coordinate.x(), process_coordinates2[0][0], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[0].coordinate.y(), process_coordinates2[0][1], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[0].coordinate.z(), process_coordinates2[0][2], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[13].coordinate.x(), process_coordinates2[1][0], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[13].coordinate.y(), process_coordinates2[1][1], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[13].coordinate.z(), process_coordinates2[1][2], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[46].coordinate.x(), process_coordinates2[2][0], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[46].coordinate.y(), process_coordinates2[2][1], 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[46].coordinate.z(), process_coordinates2[2][2], 1.0e-10 ); // These are the added wildcards. for (int i = 0; i < 47; ++i) { if (i != 0 && i != 13 && i != 46) { CPPUNIT_ASSERT_EQUAL( match[i].match_type, 0 ); } } // Check one coordinate. CPPUNIT_ASSERT_DOUBLES_EQUAL( match[17].coordinate.x(),-0.3, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[17].coordinate.y(),-0.3, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[17].coordinate.z(),-1.3, 1.0e-10 ); // Check another one. CPPUNIT_ASSERT_DOUBLES_EQUAL( match[18].coordinate.x(),-1.0, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[18].coordinate.y(),-1.0, 1.0e-10 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( match[18].coordinate.z(), 0.0, 1.0e-10 ); } }
// -------------------------------------------------------------------------- // // void Test_Interactions::testQuery() { // Setup two valid processes. std::vector<Process> processes; // Possible types. std::map<std::string, int> possible_types; possible_types["A"] = 0; possible_types["B"] = 1; possible_types["V"] = 2; // A process that independent of local environment swaps a "B" to "V" { const std::vector<std::string> process_elements1(1,"B"); const std::vector<std::string> process_elements2(1,"V"); const std::vector<std::vector<double> > process_coordinates(1, std::vector<double>(3, 0.0)); const double rate = 1.234; Configuration c1(process_coordinates, process_elements1, possible_types); Configuration c2(process_coordinates, process_elements2, possible_types); Process p(c1, c2, rate, std::vector<int>(1,0)); // Store twize. processes.push_back(p); processes.push_back(p); } // A process that finds an A between two B's in the 1,1,1 direction // and swap the A and the first B. { std::vector<std::string> process_elements1(3); process_elements1[0] = "A"; process_elements1[1] = "B"; process_elements1[2] = "B"; std::vector<std::string> process_elements2(3); process_elements2[0] = "B"; process_elements2[1] = "A"; process_elements2[2] = "B"; std::vector<std::vector<double> > process_coordinates(3, std::vector<double>(3, 0.0)); process_coordinates[1][0] = -0.25; process_coordinates[1][1] = -0.25; process_coordinates[1][2] = -0.25; process_coordinates[2][0] = 0.25; process_coordinates[2][1] = 0.25; process_coordinates[2][2] = 0.25; const double rate = 13.7; Configuration c1(process_coordinates, process_elements1, possible_types); Configuration c2(process_coordinates, process_elements2, possible_types); Process p(c1, c2, rate, std::vector<int>(1,0)); processes.push_back(p); } // Setup the interactions object. Interactions interactions(processes, false); // Query for the processes. const std::vector<Process*> & queried_processes = interactions.processes(); // Check the length of the list of processes. CPPUNIT_ASSERT_EQUAL( static_cast<int>(queried_processes.size()), 3 ); // Get the types in the queried processes and check. CPPUNIT_ASSERT_EQUAL( queried_processes[0]->minimalMatchList()[0].match_type, 1 ); CPPUNIT_ASSERT_EQUAL( queried_processes[0]->minimalMatchList()[0].update_type, 2 ); CPPUNIT_ASSERT_EQUAL( queried_processes[2]->minimalMatchList()[2].match_type, 1 ); CPPUNIT_ASSERT_EQUAL( queried_processes[2]->minimalMatchList()[2].update_type, 1 ); // Query for the total number of available sites. This is zero since no sites are added to // the processes. CPPUNIT_ASSERT_EQUAL( interactions.totalAvailableSites(), 0 ); // Add sites to the processes and see that we get the correct number out. interactions.processes()[0]->addSite(12); interactions.processes()[0]->addSite(143); interactions.processes()[0]->addSite(1654); interactions.processes()[0]->addSite(177777); interactions.processes()[1]->addSite(12); interactions.processes()[1]->addSite(143); interactions.processes()[2]->addSite(1654); interactions.processes()[2]->addSite(177777); interactions.processes()[2]->addSite(177777); CPPUNIT_ASSERT_EQUAL( interactions.totalAvailableSites(), 9 ); // Query for the rate calculator. const RateCalculator & rc = interactions.rateCalculator(); CPPUNIT_ASSERT( &rc != NULL ); }
// -------------------------------------------------------------------------- // // void Test_Interactions::testUpdateAndPickCustom() { // Setup a list of custom rate processes. std::vector<CustomRateProcess> processes; // Setup a vector of dummy processes. std::vector<std::string> process_elements1(1); process_elements1[0] = "A"; std::vector<std::string> process_elements2(1); process_elements2[0] = "B"; std::vector<std::vector<double> > process_coordinates(1, std::vector<double>(3, 0.0)); // Possible types. std::map<std::string, int> possible_types; possible_types["A"] = 0; possible_types["B"] = 1; possible_types["V"] = 2; const double rate = 1.0/13.7; Configuration c1(process_coordinates, process_elements1, possible_types); Configuration c2(process_coordinates, process_elements2, possible_types); std::vector<int> sites_vector(1,0); processes.push_back(CustomRateProcess(c1,c2,rate,sites_vector, 1.0)); processes.push_back(CustomRateProcess(c1,c2,rate,sites_vector, 1.0)); processes.push_back(CustomRateProcess(c1,c2,rate/2.0,sites_vector, 1.0)); processes.push_back(CustomRateProcess(c1,c2,rate,sites_vector, 1.0)); processes.push_back(CustomRateProcess(c1,c2,rate,sites_vector, 1.0)); processes.push_back(CustomRateProcess(c1,c2,rate,sites_vector, 1.0)); // Fake a matching by adding sites to the processes. // First process, 3 sites, total rate 12 processes[0].addSite(12, 4.0); processes[0].addSite(123, 7.0); processes[0].addSite(332, 1.0); // Second process, 2 sites, total rate 4 processes[1].addSite(19, 1.0); processes[1].addSite(12, 3.0); // Third process, 4 sites, total rate 3 processes[2].addSite(19, 1.0/4.0); processes[2].addSite(12, 5.0/4.0); processes[2].addSite(234, 2.0/4.0); processes[2].addSite(991, 4.0/4.0); // The sixth process, one site, total rate 12. processes[5].addSite(992, 12.0); // Setup the interactions object. RateCalculator rc; Interactions interactions(processes, true, rc); // Update the probability table. interactions.updateProbabilityTable(); // Check the values of the probability table. const std::vector<std::pair<double, int> > & probability_table = \ interactions.probabilityTable(); CPPUNIT_ASSERT_EQUAL( static_cast<int>(probability_table.size()), static_cast<int>(processes.size()) ); CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[0].first, 12.0, 1.0e-14 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[1].first, 16.0, 1.0e-14 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[2].first, 19.0, 1.0e-14 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[3].first, 19.0, 1.0e-14 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[4].first, 19.0, 1.0e-14 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( probability_table[5].first, 31.0, 1.0e-14 ); CPPUNIT_ASSERT_EQUAL( probability_table[0].second, 3 ); CPPUNIT_ASSERT_EQUAL( probability_table[1].second, 2 ); CPPUNIT_ASSERT_EQUAL( probability_table[2].second, 4 ); CPPUNIT_ASSERT_EQUAL( probability_table[3].second, 0 ); CPPUNIT_ASSERT_EQUAL( probability_table[4].second, 0 ); CPPUNIT_ASSERT_EQUAL( probability_table[5].second, 1 ); // Make sure to seed the random number generator before we test any // random dependent stuff. seedRandom(false, 131); // Pick processes from this table with enough statistics should give // the distribution proportional to the number of available sites, // but with the double rate for the third process should halve // this entry. std::vector<int> picked(6,0); const int n_loop = 1000000; for (int i = 0; i < n_loop; ++i) { const int p = interactions.pickProcessIndex(); // Make sure the picked process is not negative or too large. CPPUNIT_ASSERT( p >= 0 ); CPPUNIT_ASSERT( p < static_cast<int>(probability_table.size()) ); ++picked[p]; } CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[0]/n_loop, 12.0/31.0, 1.0e-2 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[1]/n_loop, 4.0/31.0, 1.0e-2 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[2]/n_loop, 3.0/31.0, 1.0e-2 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[3]/n_loop, 0.0/31.0, 1.0e-2 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[4]/n_loop, 0.0/31.0, 1.0e-2 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked[5]/n_loop, 12.0/31.0, 1.0e-2 ); // Check that picking the process twice with two different access methods and // a seed reset inbetween gives a reference to the same object. seedRandom(false, 87); const int p = interactions.pickProcessIndex(); const Process & proc1 = (*interactions.processes()[p]); seedRandom(false, 87); const Process & proc2 = (*interactions.pickProcess()); CPPUNIT_ASSERT_EQUAL( &proc1, &proc2 ); // Alter the total rate in one of the processes and re-run the picking. interactions.processes()[5]->removeSite(992); interactions.processes()[5]->addSite(992, 24.0); // Update the probability table. interactions.updateProbabilityTable(); std::vector<int> picked2(6,0); for (int i = 0; i < n_loop; ++i) { const int p = interactions.pickProcessIndex(); // Make sure the picked process is not negative or too large. CPPUNIT_ASSERT( p >= 0 ); CPPUNIT_ASSERT( p < static_cast<int>(probability_table.size()) ); ++picked2[p]; } CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[0]/n_loop, 12.0/43.0, 1.0e-2 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[1]/n_loop, 4.0/43.0, 1.0e-2 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[2]/n_loop, 3.0/43.0, 1.0e-2 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[3]/n_loop, 0.0/43.0, 1.0e-2 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[4]/n_loop, 0.0/43.0, 1.0e-2 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0*picked2[5]/n_loop, 24.0/43.0, 1.0e-2 ); // DONE }
//------------------------------------------------------------------------------ void HamiltonMatrix::computeMatrixElements() { cout << "Setting up the Hamilton matrix " << endl; int phase; int nStates = slaterDeterminants.size(); bitset<BITS> newState; int i, j, k, l; double interactionElement; H = zeros(nStates, nStates); Ht = zeros(nStates, nStates); for (int st = 0; st < nStates; st++) { for (int b = 0; b < (int)interactions.n_rows; b++) { newState = slaterDeterminants[st]; i = interactions(b, 0); j = interactions(b, 1); k = interactions(b, 2); l = interactions(b, 3); // Using the two body operator. Mathematics: a+(i)a+(j)a-(l)a-(k)|psi> phase = 1; newState = removeParticle(k, newState); phase *= sign(k, newState); newState = removeParticle(l, newState); phase *= sign(l, newState); newState = addParticle(j, newState); phase *= sign(j, newState); newState = addParticle(i, newState); phase *= sign(i, newState); if (newState[BITS - 1] != 1) { interactionElement = interactions(b, 4); // Searching for the new state to compute the matrix elements. for (int st2 = 0; st2 < (int)slaterDeterminants.size(); st2++) { if (newState == slaterDeterminants[st2]) { H(st, st2) += interactionElement * phase; break; } } } } // One body energies H(st, st) += spsEnergy(st); } #if DEBUG cout << H << endl; // // Symmetrizing the Hamilton matrix // for (int i = 0; i < H.n_rows; i++) { // for (int j = 0; j < i; j++) { // H(j, i) = H(i, j); // } // } cout << "Completed generating the Hamilton matrix" << endl; #endif }
void mainLoop() { ARMarkerInfo *marker_info; ARUint8 *dataPtr; int marker_num; if(!calib)//special paycay florian cvReleaseImage(&image); if(!calib) detectColision(); // Recuperation du flux video if ( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) { arUtilSleep(2); return; } // Passage en mode 2D pour analyse de l'image capturee argDrawMode2D(); // Récupération de l'image openCV puis conversion en ARImage //IplImage* imgTest; image = cvCreateImage(cvSize(xsize, ysize), IPL_DEPTH_8U, 4); image->imageData = (char *)dataPtr; //sinon l'image est à l'envers cvFlip(image, image, 1); //test si les couleurs ont déjà été calibrée // si oui on teste si y a collision, sinon on calibre interactionBoutton(); if(calib) calibrage(); else { updateColor(); interactions(); } // affichage image à l'ecran argDispImage( (unsigned char *)image->imageData, 0,0 ); // Recuperation d'une autre image car on a fini avec la precedente arVideoCapNext(); if (arDetectMarker(dataPtr, thresh, &marker_info, &marker_num) < 0) { printf("impossible de detecter le marqueur\n"); cleanup(); } if(visible == false && !calib) //element IHM : procedure qui permet de savoir si on recherche ou pas + réinit mouvemment des objets précédement affiché { glEnable(GL_LIGHT0); objet1_x =0;objet1_y =0;objet2_x =0;objet2_y =0; if(scan.isVisible(0)==true) scan.setVisible(false,0); if(scan.isVisible(1)==false) scan.setVisible(true,1); glColor3ub(255,0,0); texte(GLUT_BITMAP_HELVETICA_18,(char*)"Searching",cparam.xsize-100,cparam.ysize-30); if(alterne1==0 && alterne2 > 20) { glColor3ub(255,0,0); texte(GLUT_BITMAP_HELVETICA_18,(char*)"Searching .",cparam.xsize-100,cparam.ysize-30); if(alterne2 > 30){alterne2=0;alterne1=(alterne1+1)%3;} } if(alterne1==1 && alterne2 > 20 ) { glColor3ub(255,0,0); texte(GLUT_BITMAP_HELVETICA_18,(char*)"Searching ..",cparam.xsize-100,cparam.ysize-30); if(alterne2 > 30){alterne2=0;alterne1=(alterne1+1)%3;} } if(alterne1==2 && alterne2 > 20) { glColor3ub(255,0,0); texte(GLUT_BITMAP_HELVETICA_18,(char*)"Searching ...",cparam.xsize-100,cparam.ysize-30); if(alterne2 > 30){alterne2=0;alterne1=(alterne1+1)%3;} } alterne2+=1; glDisable(GL_LIGHT0); } else if(calib) { if(couleur == 0) { glColor3ub(0,0,255); texte(GLUT_BITMAP_HELVETICA_18,(char*)"Choose thumb's color",cparam.xsize-220,cparam.ysize-30); texte(GLUT_BITMAP_HELVETICA_18,(char*)"then press enter",cparam.xsize-220,cparam.ysize-(30+18)); } else if(couleur == 1) { glColor3ub(0,255,0); texte(GLUT_BITMAP_HELVETICA_18,(char*)"Choose forefinger's color",cparam.xsize-220,cparam.ysize-30); texte(GLUT_BITMAP_HELVETICA_18,(char*)"then press enter",cparam.xsize-220,cparam.ysize-(30+18)); texte(GLUT_BITMAP_HELVETICA_18,(char*)"Press return for thumb",cparam.xsize-220,cparam.ysize-(30+18*2)); } else { glColor3ub(255,0,0); texte(GLUT_BITMAP_HELVETICA_18,(char*)"Choose middle's color",cparam.xsize-220,cparam.ysize-(30)); texte(GLUT_BITMAP_HELVETICA_18,(char*)"then press enter",cparam.xsize-220,cparam.ysize-(30+18)); texte(GLUT_BITMAP_HELVETICA_18,(char*)"Press return for forefinger",cparam.xsize-220,cparam.ysize-(30+18*2)); } } else //passage mode 3d + init profondeur { argDrawMode3D(); argDraw3dCamera(0, 0); glClearDepth(1.0); glClear(GL_DEPTH_BUFFER_BIT); } /// Visibilite de l'objet if(visible == false ) //si on a jms vu de patron ou qu'on a demandé une recapture des patrons faire { //recherche objet visible for (int i=0; i<2; i++) //pour chaque patron initialisé faire { k = -1; //k renseigne sur la visibilité du marker et son id for (int j=0; j<marker_num; j++) // pour chaque marqueur trouver avec arDetectMarker { if (object[i].patt_id == marker_info[j].id) { if (k == -1) { k = j; } else if (marker_info[k].cf < marker_info[j].cf) { k = j; } } } object[i].visible = k; if (k >= 0) { visible = true; arGetTransMat(&marker_info[k], object[i].center, object[i].width,object[i].trans); printf("object[%d] center[%f, %f]\n", i, marker_info->pos[0], marker_info->pos[1]); printf("object[%d] hg[%f, %f]\n", i, marker_info->vertex[0][0], marker_info->vertex[0][1]); printf("object[%d] hd[%f, %f]\n", i, marker_info->vertex[1][0], marker_info->vertex[1][1]); printf("object[%d] bg[%f, %f]\n", i, marker_info->vertex[2][0], marker_info->vertex[2][1]); printf("object[%d] bd[%f, %f]\n", i, marker_info->vertex[3][0], marker_info->vertex[3][1]); //changement etat boutton if(scan.isVisible(0)==false) scan.setVisible(true,0); if(scan.isVisible(1)==true) scan.setVisible(false,1); //si on a vu un patron, on créé une nouvelle instance de l'objet créé par le patron, qu'on stocke dans les objets à l'écran. onscreen_object.push_back(Object3D(mesh.at(object[i].model_id), object[i].center, object[i].trans, object[i].width)); } } } //vu qu'on ne gère plus à partir de la variable "visible" d'un patron, on display, dans tout les cas, soit le vecteur est vide, soit //on a un ou plusieurs objets à afficher display(true); if(menuShow==true) menu.show(); if(!calib) scan.show(); help.show(); quit.show(); argSwapBuffers(); /// Affichage de l'image sur l'interface graphique }