void CloudParticle::adapt(const CloudPFControl &controlBack, const CloudPFControl &controlNew, const bool noValidCandidates) { gsl_rng_env_setup(); QVec noiseT = QVec::vec3(getRandom(varianceT(0)), getRandom(varianceT(1)), getRandom(varianceT(2))); // QVec noiseT = QVec::vec3(0,0,0); QVec T2 = T + noiseT; velT = T2 - T; T = T2; QVec noiseR = QVec::vec3(getRandom(varianceR(0)), getRandom(varianceR(1)), getRandom(varianceR(2)/10)); QVec R2 = R + noiseR; velR = R2 - R; R = R2; transformation = RTMat(R(0), R(1), R(2), T); }
void Gui::SetArm(const char* text) { //Initialize a surface used to hide a part of the screen wich is used later SDL_Surface* hide = NULL; hide=LoadImage("Images/hide.png"); //The variables that the window is going to get double mean =0;//the mean of the arm double variance =0;//its variance char armType ='A';//its type //Initializing the texts Texts arm(0,150,_font,text,_textColor); Texts instructions(0,250,_font2,"Choose a type of arm then click in the boxes and type the parameters",_textColor); //Initializing the buttons //Ok button to skip to the next window Buttons ok(361,500, "Images/ok1.png", "Images/ok2.png","Images/ok3.png"); //Type zones for the mean and the variance TypeZone meanT(300,400,_font2,"Mean",_textColor); TypeZone varianceT(600,400,_font2,"Variance",_textColor); //Radiobuttons to choose the type of arm (exponential, uniform real, uniform int, poisson, logNormal) RadioButtons exp(100,300,"Exponential",_font2,_textColor); RadioButtons unifr(exp.GetBox().x+exp.GetBox().w+20,300,"Uniform real",_font2,_textColor); RadioButtons unifi(unifr.GetBox().x+unifr.GetBox().w+20,300,"Uniform int",_font2,_textColor); RadioButtons poisson(unifi.GetBox().x+unifi.GetBox().w+20,300,"Poisson",_font2,_textColor); RadioButtons logNormal(poisson.GetBox().x+poisson.GetBox().w+20,300,"Log-normal",_font2,_textColor); //Calculate the x for centering them (width of the screen minus the sum the width of the buttons) int xCentered = ((*(_screen.GetScreen())).clip_rect.w-exp.GetBox().w-unifr.GetBox().w-unifi.GetBox().w-poisson.GetBox().w-logNormal.GetBox().w-80)/2; //Relocate the buttons exp.SetPosition(xCentered,exp.GetBox().y); unifr.SetPosition(exp.GetBox().x+exp.GetBox().w+20,unifr.GetBox().y); unifi.SetPosition(unifr.GetBox().x+unifr.GetBox().w+20,unifi.GetBox().y); poisson.SetPosition(unifi.GetBox().x+unifi.GetBox().w+20,poisson.GetBox().y); logNormal.SetPosition(poisson.GetBox().x+poisson.GetBox().w+20,logNormal.GetBox().y); //Display them all arm.DisplayCentered(_screen); instructions.DisplayCentered(_screen); //meanT.Display(_screen); ok.Show(_screen); exp.Show(_screen); unifr.Show(_screen); unifi.Show(_screen); poisson.Show(_screen); logNormal.Show(_screen); meanT.DisplayLeft(_screen,mean,_font2,_textColor); varianceT.DisplayRight(_screen,mean,_font2,_textColor); //Initialize the event structure SDL_Event event; //Initialization of the loop bool isChoiceCorrect= false; bool skip=false; while((skip==false)&&(_quit==false)) { //While there's an event to handle while( SDL_PollEvent( &event ) ) { //the buttons react to the user's actions ok.HandleEvents(event); exp.HandleEvents(event); unifr.HandleEvents(event); unifi.HandleEvents(event); poisson.HandleEvents(event); logNormal.HandleEvents(event); meanT.HandleEvents(event,mean); //For some button we just need the mean to set the distribution so in this case we hide the variance if((exp.IsActive()==false)&&(poisson.IsActive()==false)) { varianceT.HandleEvents(event,variance); } //we check if one option was chosen isChoiceCorrect = (exp.IsActive()|| unifr.IsActive()||unifi.IsActive()||poisson.IsActive()||logNormal.IsActive()); //If the user clicks on ok and made a choice if((ok.HandleEvents(event)==false)&&(isChoiceCorrect)) { //skip to the next window skip=true; } //If he clicks on ok and hasn't made a choice then change color of the text if((ok.HandleEvents(event)==false)&&(isChoiceCorrect==false)) { SDL_Color red={240,0,0}; exp.SetColor(red); unifr.SetColor(red); unifi.SetColor(red); poisson.SetColor(red); logNormal.SetColor(red); } //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program _quit = true; } } //Display all ok.Show(_screen); exp.Show(_screen); unifr.Show(_screen); unifi.Show(_screen); poisson.Show(_screen); logNormal.Show(_screen); meanT.DisplayLeft(_screen,mean, _font2,_textColor); //For some button we just need the mean to set the distribution so in this case we hide the variance if((exp.IsActive()==false)&&(poisson.IsActive()==false)) { varianceT.DisplayRight(_screen,variance, _font2,_textColor); } else { ApplySurface(400,398,hide,_screen.GetScreen()); } _screen.Display(); } _screen.Clean("Images/background.png"); //Then we save the parameters in the Gui's attributes //First we get the type of arm: if(exp.IsActive()){armType='A';} if(unifr.IsActive()){armType='B';} if(unifi.IsActive()){armType='C';} if(poisson.IsActive()){armType='D';} if(logNormal.IsActive()){armType='E';} std::vector<double> parameter; //Then acoording to the type of arms we calculate the parameters required switch(armType) { case 'A'://Exponential: we need the lambda _choices.push_back('A');//we save the type in _choices parameter.push_back(1.0/(mean*1.0)); _parameters.push_back(parameter);//and the parameters calculated using the mean and the variance in _parameters break; case 'B'://uniform real on [a,b] we need a and b _choices.push_back('B'); parameter.push_back((2.0*mean-sqrt(12.0*variance))/2.0); parameter.push_back((2.0*mean+sqrt(12.0*variance))/2.0); _parameters.push_back(parameter); break; case 'C': _choices.push_back('C');//uniform integer on [a,b] we need a and b parameter.push_back((2.0*mean -sqrt(12.0*variance+1.0)+1)/2.0); parameter.push_back((2.0*mean+sqrt(12.0*variance+1)-1)/2.0); _parameters.push_back(parameter); break; case 'D': //poisson we just need the mu wich equal to the mean _choices.push_back('D'); parameter.push_back(mean); _parameters.push_back(parameter); break; default: _choices.push_back('E'); //log-normal we need mu and sigma square parameter.push_back(log(mean*1.0)-0.5*log(1.0+((variance*1.0)/(mean*mean*1.0)))); parameter.push_back((2.0*mean+sqrt(12.0*variance+1.0)-1.0)/2.0); _parameters.push_back(parameter); break; } }