Cloth::Cloth(FXMVECTOR topLeftPostition, float height, float width, int numRows, int numColumns, float totalMass, float structuralStiffness, float structuralDamping, float shearStiffness, float shearDamping, float flexionStiffness, float flexionDamping) : timeSpentCalculatingInternalForce(0.0), timeSpentCalculatingExternalForce(0.0) { createParticles(topLeftPostition, height, width, totalMass); createStructuralLinks(structuralStiffness, structuralDamping); createShearLinks(shearStiffness, shearDamping); createFlexionLinks(flexionStiffness, flexionDamping); }
void Filtro_Particulas::spin() { ros::Rate loopRate(freq_); while(n_.ok()) { ros::spinOnce(); loopRate.sleep(); //cout<<free_ok_<<occ_ok_<<odom_ok_<<laser_ok_<<endl; if (free_ok_ == true && occ_ok_ == true){ createParticles(); if(create_particle_ok_ == 0 && odom_ok_ == true && laser_ok_ == true && zerar_deltas_ == false){ pose_anterior_.x = pose_x_; pose_anterior_.y = pose_y_; pose_anterior_.theta = pose_theta_; zerar_deltas_ = true; moveParticles(); //cout<<"moveParticles()"<<endl; }else if(create_particle_ok_ == 0 && odom_ok_ == true && laser_ok_ == true && zerar_deltas_ == true){ moveParticles(); } } } }
/** * Create Water Generic Emiter */ void createWaterEmiter(vec2 pos) { Emiter temp = createGenericEmiter(2, pos); temp.ttlMax = ((float)rand()/(float)(RAND_MAX)) * (MAX_TTL_WATER - MIN_TTL_WATER) + MIN_TTL_WATER; temp.nbParticle = rand() % (MAX_PARTICLE_WATER - MIN_PARTICLE_WATER) + MIN_PARTICLE_WATER; createParticles(temp); temp.ttlCurr = temp.ttlMax; temp.ttlPrev = temp.ttlMax; ParticleEmiters.push_back(temp); }
/** * Create FireWork Emiter */ void createFireWorkEmiter(vec2 pos) { Emiter temp = createGenericEmiter(1, pos); temp.ttlMax = ((float)rand()/(float)(RAND_MAX)) * (MAX_TTL_FW - MIN_TTL_FW) + MIN_TTL_FW; temp.nbParticle = rand() % (MAX_PARTICLE_FW - MIN_PARTICLE_FW) + MIN_PARTICLE_FW; createParticles(temp); temp.ttlCurr = temp.ttlMax; temp.ttlPrev = temp.ttlMax; ParticleEmiters.push_back(temp); }
void GvParticle::update(float dt) { updateParticles(dt); createParticles(dt*rate); if (getNumParticles() > maxCount) { deleteParticles(getNumParticles() - maxCount); } }
//-------------------------------------------------------------- void AnimationParticlesMega2::VM_draw(float w, float h) { drawBackground(0); m_resolution.set(w,h); createParticles(); if (!m_isParticlesInit) return; particleSystem.setTimeStep(timeStep); m_particlesVbo.updateVertexData(m_particlesPos, kParticles*1024); m_particlesVbo.updateColorData(m_particlesColor, kParticles*1024); ofEnableAlphaBlending(); // ofSetColor(255, 255, 255, lineOpacity); particleSystem.setupForces(); // apply per-particle forces // glBegin(GL_LINES); for(int i = 0; i < particleSystem.size(); i++) { Particle& cur = particleSystem[i]; // global force on other particles //particleSystem.addRepulsionForce(cur, particleNeighborhood, particleRepulsion/100); // forces on this particle cur.bounceOffWalls(0, 0, w, h); cur.addDampingForce(); } // glEnd(); // single global forces map<string,ParticleForce*>::iterator it = m_mapParticleForce.begin(); ParticleForce* pParticleForce=0; for ( ; it != m_mapParticleForce.end() ; ++it) { pParticleForce = it->second; particleSystem.m_color = m_isColorFromDevice ? pParticleForce->m_color : ofColor(255); particleSystem.addAttractionForce(pParticleForce->m_anchor.x, pParticleForce->m_anchor.y, w, centerAttraction*m_ampAttraction); particleSystem.addRepulsionForce(pParticleForce->m_anchor.x, pParticleForce->m_anchor.y, pParticleForce->m_volume*m_repulsionRadius, pParticleForce->m_volume*m_ampRepulsion, false); particleSystem.addRepulsionForce(pParticleForce->m_anchor.x, pParticleForce->m_anchor.y, pParticleForce->m_volume*m_repulsionRadius*m_colorRadiusFactor, 0, true); } particleSystem.update(); ofSetColor(255, 255, 255, pointOpacity); glPointSize(particleSystem.getParticleSize()); m_particlesVbo.draw(GL_POINTS,0,kParticles*1024); // ofDisableAlphaBlending(); }
void ParticleGenerator::getFileInput(char* fileName, ParticleContainer* pc, Simulation *sim) { double m = 1; int num_cuboids = 0; std::ifstream input_file(fileName); string tmp_string; if (input_file.is_open()) { getline(input_file, tmp_string); LOG4CXX_DEBUG(iolog, "Read line: " << tmp_string); while (tmp_string.size() == 0 || tmp_string[0] == '#') { getline(input_file, tmp_string); LOG4CXX_DEBUG(iolog, "Read line: " << tmp_string); } istringstream numstream(tmp_string); numstream >> num_cuboids; LOG4CXX_DEBUG(iolog, "Reading " << num_cuboids << "."); getline(input_file, tmp_string); LOG4CXX_DEBUG(iolog, "Read line: " << tmp_string); for (int i = 0; i < num_cuboids; i++) { istringstream datastream(tmp_string); for (int j = 0; j < 3; j++) { datastream >> X[j]; } for (int j = 0; j < 3; j++) { datastream >> V[j]; } for (int j = 0; j < 3; j++) { datastream >> num[j]; } if (datastream.eof()) { LOG4CXX_ERROR(iolog, "Error reading file: eof reached unexpectedly reading from line " << i); exit(-1); } datastream >> meanV; datastream >> M; datastream >> H; // create particles from cuboid data LOG4CXX_ERROR(particlelog, "Generating Cuboid..."); createParticles(pc); getline(input_file, tmp_string); } } else {
cloth::cloth(float width, float height, int num_particles_x, int num_particles_y) : num_particles_width(num_particles_x), num_particles_height(num_particles_y) { faces.clear(); fixedParticles.clear(); particles.clear(); constraints.clear(); createParticles( width, height, num_particles_x, num_particles_y); createSprings(); collisionFlag = false; draw_wire = false; clothThick = 0.1; collisionChecker = new collisionDetector(); intersectQ=vec3(0,0,0); iterativeTimes = 15; }
//! read particles matching a specific PDG name and run id from supplied // file. Must supply particle mass ourselves... EventArray* readParticles(const std::string& file, const std::string& particle, const double mass, const std::string& runId) { int resultCode(0); size_t numberOf(0); resultCode = countParticles(file, particle, runId, numberOf); if (resultCode) { std::cerr << "[pp6day3_muonanalysis:error] Failed to count particles in file " << file << std::endl; return 0; } // With number of particles known, create the appropriately sized // EventArray and fill it return createParticles(file, numberOf, particle, mass, runId); }
bool init(int argc, char *argv[]){ setDataDir(argc, argv); initGLFW(); ogle::initGLEW(); bool found_extensions = checkExtensions(); if (!found_extensions) return false; ogle::Debug::init(); initGLSettings(); createParticles(); createBufferObject(); return true; }
Cloth::Cloth(xml_node<>* clothParams) : timeSpentCalculatingInternalForce(0.0), timeSpentCalculatingExternalForce(0.0) { float x, y, z, height, width, mass, stiffness, damping; height = convertStringToNumber<float>(clothParams->first_attribute("height")->value()); width = convertStringToNumber<float>(clothParams->first_attribute("width")->value()); mass = convertStringToNumber<float>(clothParams->first_attribute("mass")->value()); windConstant = convertStringToNumber<float>(clothParams->first_attribute("wind_constant")->value()); xml_node<>* currentNode = clothParams->first_node("top_left_position"); x = convertStringToNumber<float>(currentNode->first_attribute("x")->value()); y = convertStringToNumber<float>(currentNode->first_attribute("y")->value()); z = convertStringToNumber<float>(currentNode->first_attribute("z")->value()); currentNode = clothParams->first_node("mesh_size"); rows = convertStringToNumber<int>(currentNode->first_attribute("rows")->value()); columns = convertStringToNumber<int>(currentNode->first_attribute("columns")->value()); XMVECTOR topLeft = XMVectorSet(x, y, z, 0.0f); createParticles(topLeft, height, width, mass); currentNode = clothParams->first_node("structural"); stiffness = convertStringToNumber<float>(currentNode->first_attribute("spring_coefficient")->value()); damping = convertStringToNumber<float>(currentNode->first_attribute("damping_coefficient")->value()); createStructuralLinks(stiffness, damping); currentNode = clothParams->first_node("shear"); stiffness = convertStringToNumber<float>(currentNode->first_attribute("spring_coefficient")->value()); damping = convertStringToNumber<float>(currentNode->first_attribute("damping_coefficient")->value()); createShearLinks(stiffness, damping); currentNode = clothParams->first_node("flexion"); stiffness = convertStringToNumber<float>(currentNode->first_attribute("spring_coefficient")->value()); damping = convertStringToNumber<float>(currentNode->first_attribute("damping_coefficient")->value()); createFlexionLinks(stiffness, damping); currentNode = clothParams->first_node("wind_direction"); x = convertStringToNumber<float>(currentNode->first_attribute("x")->value()); y = convertStringToNumber<float>(currentNode->first_attribute("y")->value()); z = convertStringToNumber<float>(currentNode->first_attribute("z")->value()); windDirection = XMVectorSet(x, y, z, 0.0f); }
int main(int argc, char** argv){ int i,j,k,l; int timeStep=0; int worldRank; int worldSize; double elapseTime; clock_t start; clock_t end; float seconds1=0.00; float seconds3=0.00; int numParticle; int dispParticle; double distance; double initialEnergy; double energy; double totalEnergy=0.00; double localEnergy=0.00; double globalEnergy; double previousEnergy=0.00; double fabGlobal; double fabPrev; particle p[N]; particle oldP[N]; int newX,newY,newZ; //496 is derived from 32P2/2 int index1Pair[496]; int index2Pair[496]; MPI_Datatype particleType; MPI_Datatype type[3]={MPI_DOUBLE,MPI_DOUBLE,MPI_DOUBLE}; int blocklen[3]={1,1,1}; MPI_Aint disp[3]; MPI_Aint extent; //Initialize MPI MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&worldRank); MPI_Comm_size(MPI_COMM_WORLD,&worldSize); MPI_Type_extent(MPI_DOUBLE,&extent); disp[0]=0; disp[1]=1*extent; disp[2]=2*extent; MPI_Type_struct(3,blocklen,disp,type,&particleType); MPI_Type_commit(&particleType); if(worldRank==0){ createParticles(p); for(i=0;i<N;i++) { printf("Particle %d: X:%f,Y:%f,Z:%f\n",i,p[i].x,p[i].y,p[i].z); } } while(1){ totalEnergy=0.00; localEnergy=0.00; globalEnergy=0.00; //broadcast particle coordinates to all processors MPI_Bcast(p,N,particleType, 0, MPI_COMM_WORLD); /*assign number of particle to compute particle decomposition technique is used */ numParticle =31; dispParticle = worldRank*(numParticle); //calculate total energy //form array 1 that contains the index of first particle of a pair l=0; k=N-1;//-1 to exclude same index pair for(i=0;i<N-1;i++){ for(j=0;j<k;j++){ index1Pair[l]=(N-1)-k+1; l++; } k--; } //form array 2 that contains the index of second particle of a pair l=0; k=N-1; for(i=0;i<N-1;i++){ for(j=0;j<k;j++){ index2Pair[l]=(N-1)-k+2+j; l++; } k--; } for(i=0;i<numParticle;i++){ k=i+dispParticle; distance = sqrt(pow(p[index1Pair[k]].x-p[index2Pair[k]].x,2.0)+pow(p[index1Pair[k]].y-p[index2Pair[k]].y,2.0)+pow(p[index1Pair[k]].z-p[index2Pair[k]].z,2.0)); if(distance == 0){ energy=0.00; } else energy = 1/pow(distance,12.0)-1/pow(distance,6.0); totalEnergy = totalEnergy + energy; } localEnergy = totalEnergy; //sum of all energy MPI_Allreduce(&localEnergy,&globalEnergy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); if(timeStep ==0){ initialEnergy=globalEnergy; } if(timeStep ==0 && worldRank==0) printf("Initial Energy= %f\n",initialEnergy); if(timeStep ==0){ initialEnergy=fabs(globalEnergy); } //accept new coordinate if new state energy less than previous state fabGlobal = fabs(globalEnergy); fabPrev = fabs(previousEnergy); if( fabGlobal < fabPrev || timeStep==50000){ if(fabGlobal <= (initialEnergy/4.00) && timeStep!=0 || timeStep ==50000){ if(worldRank==0){ printf("Solution is found after %d\n",timeStep); printf("New Energy = %f\n",globalEnergy); } break; } } else if(timeStep!=0){ //if(worldRank==0) //printf("greater"); for(i=0;i<N;i++){ p[i].x=oldP[i].x; p[i].y=oldP[i].y; p[i].z=oldP[i].z; } } previousEnergy = globalEnergy; //save old coordinates before moving particles for(i=0;i<N;i++){ oldP[i].x=p[i].x; oldP[i].y=p[i].y; oldP[i].z=p[i].z; } /* MOVING PARTICLES */ if(worldRank==0){ srand (time(NULL)); for(i=0;i<N;i++){ int randX=rand() % 19 + (-9); int randY=rand() % 19 + (-9); int randZ=rand() % 19 + (-9); newX = p[i].x*100 + randX*1; newY = p[i].y*100 + randY*1; newZ = p[i].z*100 + randZ*1; if(newX<=900 && newX>=100) p[i].x = (double)newX/100; if(newY<=900 && newY>=100) p[i].y = (double)newY/100; if(newZ<=900 && newZ>=100) p[i].z = (double)newZ/100; } } timeStep++; } MPI_Finalize(); return 0; }
void GvParticle::init() { clearParticles(); createParticles(startCount); }
//-------------------------------------------------------------- void ofApp::update(){ //openCV update///////////////////////////////////////////////////////////////////////////////////////////////////////// grabber.update(); //pull our next frame of video image.setFromPixels(grabber.getPixelsRef()); //set our CV Color Image to have the same data as the current frame greyImage = image; //convert our color image to grayscale greyDiff.absDiff(greyBackground, greyImage);//compare the difference of the background to a greyed version greyProcessed = greyDiff;//set our greyProcessed to the greyDiff greyProcessed.threshold(250);//threshold for finding light this is set high so that it can find fine light points contourFinder.findContours(greyProcessed, 40, (grabber.width*grabber.height)/2, maxBlobs, true);//using the graber find the contours of the blob if(contourFinder.nBlobs == 1) // if the number of detected blobs is 1 { drawPoint = true;//set draw point to be true to allow drawing createAlphaTrail(); if(particles.size()<maxParticles)//if the size of the vector of particles is less than the max allowed particles { createParticles();//create particles checkParticles();//check the size of the vector } } else { drawPoint = false;//if none of the above is true then remain false to avoid drawing when nothing is detected } for(int i = 0; i < contourFinder.nBlobs; i++)//go throught the blobs and send the information to a location point { blobCenters[i] = contourFinder.blobs[i].centroid; } //openCV end//////////////////////////////////////////////////////////////////////////////////////////////////////////// //audio update////////////////////////////////////////////////////////////////////////////////////////////////////////// scaledVol = ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true);//map the smoothed volume to a sensible set of integers volHistory.push_back( scaledVol );//push the oldest volume recording in the vector if( volHistory.size() >= 400 )//if the volume history hits the cap of 400 erase the oldest volume recording { checkFreq();//check the recorded amount of frequencies } //audio end//////////////////////////////////////////////////////////////////////////////////////////////////////////// //visuals update/////////////////////////////////////////////////////////////////////////////////////////////////////// for(int i = 0; i < particles.size(); i++) { particles[i].applyForce(wind);//apply the wind force to the big circle particles particles[i].applyForce(gravity);//apply the gravity force to the big circle particles particles[i].changeAlpha();//change the particle alpha particles[i].particleFlow();//run the particle flow function on every particle particles[i].particleMass = scaledVolInt;//set the current particles mass to be the current volume for variation particles[i].update();//update particles } particleLoc = blobLocation;//particle location is equal to the location of the blob found using the camera (must update) if(drawPoint) { screenFbo.begin();//start the FBO if(fboTimer == 0)//if the timer is 0 clear the FBO to give it a delayed alpha trail effect { ofClear(255, 255, 255);//clear the screen of the old particles fboTimer = 4;//after clearing reset the timer } screenFbo.end();//end the fbo screenFbo.begin(); ofEnableAlphaBlending(); for(int i = 0; i < particles.size(); i++)//loop through and draw the particles { particles[i].draw();//draw the particles particles[i].particleFlow();//call the flow function on the particles } screenFbo.end(); } //VISUALS end///////////////////////////////////////////////////////////////////////////////////////////////////////// }