widget_settings_dialog* button::settings_dialog(int x, int y, int w, int h) { widget_settings_dialog* d = widget::settings_dialog(x,y,w,h); grid_ptr g(new grid(2)); g->add_col(new label("H Pad:", d->text_size(), d->font())); g->add_col(new slider(120, [&](double f){set_dim(0,0); this->set_hpadding(int(f*100.0));}, hpadding_/100.0, 1)); g->add_col(new label("V Pad:", d->text_size(), d->font())); g->add_col(new slider(120, [&](double f){set_dim(0,0); this->set_vpadding(int(f*100.0));}, vpadding_/100.0, 1)); std::vector<std::string> v; v.push_back("normal"); v.push_back("double"); dropdown_widget_ptr resolution(new dropdown_widget(v, 150, 28, dropdown_widget::DROPDOWN_LIST)); resolution->set_font_size(14); resolution->set_dropdown_height(h); resolution->set_selection(button_resolution_ == BUTTON_SIZE_NORMAL_RESOLUTION ? 0 : 1); resolution->set_on_select_handler([&](int n, const std::string& s){ this->button_resolution_ = s == "normal" ? BUTTON_SIZE_NORMAL_RESOLUTION : BUTTON_SIZE_DOUBLE_RESOLUTION; this->setup(); }); resolution->set_zorder(11); g->add_col(new label("Resolution:", d->text_size(), d->font())); g->add_col(resolution); v.clear(); v.push_back("default"); v.push_back("normal"); dropdown_widget_ptr style(new dropdown_widget(v, 150, 28, dropdown_widget::DROPDOWN_LIST)); style->set_font_size(14); style->set_dropdown_height(h); style->set_selection(button_style_ == BUTTON_STYLE_DEFAULT ? 0 : 1); style->set_on_select_handler([&](int n, const std::string& s){ this->button_style_ = s == "normal" ? BUTTON_STYLE_NORMAL : BUTTON_STYLE_DEFAULT; this->setup(); }); style->set_zorder(10); g->add_col(new label("Style:", d->text_size(), d->font())); g->add_col(style); // label: widget // on_click: function // *** resolution: string/dropdown (normal/double) // *** style: string/dropdown (default/formal) // *** hpad: int // *** vpad: int d->add_widget(g); return d; }
void selector_widget::init() { left_arrow_ = widget_ptr(new gui_section_widget(selector_left_arrow)); right_arrow_ = widget_ptr(new gui_section_widget(selector_right_arrow)); int width = 16; int height = 16; int n = 0; foreach(const selector_pair& p, list_) { if(p.second->width() > width) { width = p.second->width(); } if(p.second->height() > height) { height = p.second->height(); } if(n != current_selection_) { p.second->enable(false); } else { p.second->enable(); } ++n; } left_arrow_->set_loc(0, (abs(height-left_arrow_->height()))/2); //left_arrow_->set_dim(left_arrow_->width(), height); right_arrow_->set_loc(left_arrow_->width()+10+width, (abs(height-right_arrow_->height()))/2); //right_arrow_->set_dim(right_arrow_->width(), height); set_dim(width + left_arrow_->width() + right_arrow_->width() + 10, height); for(int n = 0; n != list_.size(); ++n) { widget_ptr& w = list_[n].second; w->set_loc((width - w->width())/2 + left_arrow_->width()+5, abs(height - w->height())/2); } }
void bar_widget::init() { left_cap_width_ = left_cap_.area.w() ? left_cap_.area.w()*scale_ : left_cap_.texture.width()*scale_; right_cap_width_ = right_cap_.area.w() ? right_cap_.area.w()*scale_ : right_cap_.texture.width()*scale_; total_bar_length_ = (segments_ * segment_length_ + (segments_-1) * tick_width_) * scale_; drained_bar_length_ = (drained_segments_ * segment_length_ + (drained_segments_-1) * tick_width_) * scale_; active_bar_length_ = ((segments_-drained_segments_) * segment_length_ + (segments_-(drained_segments_?drained_segments_:1)) * tick_width_) * scale_; int w = total_bar_length_ + left_cap_width_ + right_cap_width_; int h; if(bar_height_ == 0) { h = std::max(bar_.area.h(), std::max(left_cap_.area.h(), right_cap_.area.h()))*scale_; } else { h = bar_height_*scale_; } tick_distance_ = (segment_length_ + tick_width_) * scale_; if(bar_max_width_ != 0 && w > bar_max_width_) { double ratio = bar_max_width_ / double(w); left_cap_width_ = int(double(left_cap_width_) * ratio); right_cap_width_ = int(double(right_cap_width_) * ratio); total_bar_length_ = int(double(total_bar_length_) * ratio); drained_bar_length_ = int(double(drained_bar_length_) * ratio); active_bar_length_ = int(double(active_bar_length_) * ratio); tick_distance_ = int(double(tick_distance_) * ratio); w = bar_max_width_; } set_dim(w, h); }
void button::set_label(widget_ptr label) { label_ = label; if(width() == 0 && height() == 0) { set_dim(label_->width()+hpadding_*2,label_->height()+vpadding_*2); } }
dialog::dialog(int x, int y, int w, int h) : opened_(false), cancelled_(false), clear_bg_(196), padding_(10), add_x_(0), add_y_(0), bg_alpha_(1.0), last_draw_(-1) { set_environment(); set_loc(x,y); set_dim(w,h); forced_dimensions_ = rect(x, y, w, h); }
button::button(widget_ptr label, boost::function<void ()> onclick) : label_(label), onclick_(onclick), normal_texture_(graphics::texture::get("button.png")), focus_texture_(graphics::texture::get("button-active.png")), depressed_texture_(graphics::texture::get("button-pressed.png")), current_texture_(&normal_texture_) { set_dim(label_->width()+hpadding*2,label_->height()+vpadding*2); }
void checkbox::on_click() { checked_ = !checked_; const int w = width(); const int h = height(); set_label(create_checkbox_widget(label_, checked_)); set_dim(w, h); onclick_(checked_); }
void widget::set_value(const std::string& key, const variant& v) { if(key == "width") { w_ = v.as_int(); } else if(key == "height") { h_ = v.as_int(); } else if(key == "rect" || key == "draw_area") { std::vector<int> r = v.as_list_int(); ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute"); set_loc(r[0], r[1]); set_dim(r[2], r[3]); } else if(key == "xy" || key == "left_top") { std::vector<int> xy = v.as_list_int(); ASSERT_LOG(xy.size() == 2, "Two values must be supplied to the X, Y attribute"); set_loc(xy[0], xy[1]); } else if(key == "wh") { std::vector<int> wh = v.as_list_int(); ASSERT_LOG(wh.size() == 2, "Two values must be supplied to the W, H attribute"); set_dim(wh[0], wh[1]); } else if(key == "right_bottom") { std::vector<int> rb = v.as_list_int(); ASSERT_LOG(rb.size() == 2, "Two values must be supplied to the R, B attribute"); set_dim(rb[0] - x(), rb[1] - y()); } else if(key == "left") { x_ = v.as_int(); } else if(key == "top") { y_ = v.as_int(); } else if(key == "right") { w_ = v.as_int() - x(); } else if(key == "bottom") { h_ = v.as_int() - y(); } else if(key == "visible") { visible_ = v.as_bool(); } else if(key == "id") { id_ = v.as_string(); } else if(key == "disable") { disabled_ = v.as_bool(); } else if(key == "enable") { disabled_ = !v.as_bool(); } else if(key == "disabled_opacity") { int opa = v.as_int(); disabled_opacity_ = (opa > 255) ? 255 : (opa < 0) ? 0 : opa; } }
grid::grid(int ncols) : ncols_(ncols), col_widths_(ncols, 0), col_aligns_(ncols, grid::ALIGN_LEFT), row_height_(0), selected_row_(-1), allow_selection_(false), must_select_(false), swallow_clicks_(false), hpad_(0), show_background_(false), max_height_(-1), allow_highlight_(true), set_h_(0), set_w_(0) { set_environment(); set_dim(0,0); }
key_button::key_button(SDLKey key, BUTTON_RESOLUTION button_resolution) : label_(widget_ptr(new graphical_font_label(get_key_name(key), "door_label", 2))), key_(key), button_resolution_(button_resolution), normal_button_image_set_(framed_gui_element::get("regular_button")), depressed_button_image_set_(framed_gui_element::get("regular_button_pressed")), focus_button_image_set_(framed_gui_element::get("regular_button_focus")), current_button_image_set_(normal_button_image_set_), grab_keys_(false) { set_dim(label_->width()+hpadding*2,label_->height()+vpadding*2); }
void preview_tileset_widget::init() { foreach(const level_tile& t, tiles_) { const int w = t.x + t.object->width(); const int h = t.y + t.object->height(); width_ = std::max(width_, w); height_ = std::max(height_, h); } set_dim(width_, height_); }
key_button::key_button(const variant& v, game_logic::formula_callable* e) : widget(v,e), normal_button_image_set_(framed_gui_element::get("regular_button")), depressed_button_image_set_(framed_gui_element::get("regular_button_pressed")), focus_button_image_set_(framed_gui_element::get("regular_button_focus")), current_button_image_set_(normal_button_image_set_), grab_keys_(false) { std::string key = v["key"].as_string(); key_ = get_key_sym(key); label_ = v.has_key("label") ? widget_factory::create(v["label"], e) : widget_ptr(new graphical_font_label(key, "door_label", 2)); button_resolution_ = v["resolution"].as_string_default("normal") == "normal" ? BUTTON_SIZE_NORMAL_RESOLUTION : BUTTON_SIZE_DOUBLE_RESOLUTION; set_dim(label_->width()+hpadding*2,label_->height()+vpadding*2); }
text_editor_widget::text_editor_widget(int width, int height) : last_op_type_(NULL), font_size_(FontSize), char_width_(font::char_width(font_size_)), char_height_(font::char_height(font_size_)), select_(0,0), cursor_(0,0), nrows_((height - BorderSize*2)/char_height_), ncols_((width - 20 - BorderSize*2)/char_width_), scroll_pos_(0), begin_highlight_line_(-1), end_highlight_line_(-1), has_focus_(false), is_dragging_(false), last_click_at_(-1), consecutive_clicks_(0), text_color_(255, 255, 255, 255) { if(height == 0) { height = char_height_; nrows_ = 1; ncols_ = width/char_width_; } set_dim(BorderSize*2 + char_width_*ncols_, BorderSize*2 + char_height_*nrows_); text_.push_back(""); }
void convert_to_ijk(float *P, int n, SHORTIM im) { ///////////////////////////////////////////////////////// // convert P from (i,j,k) to (x,y,z) coordinates float T[16]; float dum[4]={0.0,0.0,0.0,1.0}; DIM dim; set_dim(dim,im); xyz2ijk(T, dim); for(int i=0; i<n; i++) { // note that P is (3 x n) dum[0]=P[0*n + i]; dum[1]=P[1*n + i]; dum[2]=P[2*n + i]; multi(T,4,4,dum,4,1,dum); P[0*n + i]=dum[0]; P[1*n + i]=dum[1]; P[2*n + i]=dum[2]; } }
// lmfile (landmarks file) - This is a text file with format: // i1 j1 k1 // i2 j2 k2 // i3 j3 k3 // where // (i1, j1, k1) are the coordinates of the AC // (i2, j2, k2) are the coordinates of the PC, and // (i3, j3, k3) are the coordinates of the RP. // subfile (subject file) - 3D T1W volume of type short in NIFTI format // TPIL - output 4x4 rigid-body transformation matrix that would transform // subfile into a standardized PIL orientation void new_PIL_transform(const char *subfile,const char *lmfile,char *orient,float *TPIL, int SAVE_MRX_FLAG) { float Qavg[3]; // average of rows of Q float Pavg[3]; // average of rows of P float TPIL0[16]; // transforms the original image to MSP/AC-PC aligned PIL orientation int n; // number of landmarks float *LM; // (3 x n) matrix of detected landmarks float *invT; char filename[1024]; SHORTIM subimPIL; nifti_1_header PILbraincloud_hdr; // subfile without the directory structure and extension char subfile_prefix[1024]; char imagedir[1024]; char modelfile[1024]=""; if( niftiFilename(subfile_prefix, subfile)==0 ) exit(0); getDirectoryName(subfile, imagedir); getARTHOME(); // initial TPIL0 using old PIL transformation char opt_CENTER_AC_old; opt_CENTER_AC_old = opt_CENTER_AC; // record opt_CENTER_AC opt_CENTER_AC = NO; // temporarily set opt_CENTER_AC to NO standard_PIL_transformation(subfile, lmfile, orient, 0, TPIL0); opt_CENTER_AC = opt_CENTER_AC_old; // restore opt_CENTER_AC ///////////////////////////////////////////////////////// // Read input volume from subfile SHORTIM subim; nifti_1_header subim_hdr; subim.v = (short *)read_nifti_image(subfile, &subim_hdr); if(subim.v==NULL) { printf("Error reading %s, aborting ...\n", subfile); exit(1); } set_dim(subim, subim_hdr); ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// // Reslice subim to PIL space sprintf(filename,"%s/PILbrain.nii",ARTHOME); PILbraincloud_hdr=read_NIFTI_hdr(filename); set_dim(subimPIL, PILbraincloud_hdr); invT = inv4(TPIL0); resliceImage(subim, subimPIL, invT, LIN); free(invT); // Detect 8 landmarks on the MSP on the subimPIL volume sprintf(modelfile,"%s/orion.mdl",ARTHOME); LM=detect_landmarks(subimPIL, modelfile, n); convert_to_xyz(LM, n, subimPIL); // This block outputs the locations of the detected landmarks // in (i,j,k) coordinates of the native space of the input volume if(opt_txt) { FILE *fp; float landmark[4]; invT = inv4(TPIL0); sprintf(filename,"%s/%s_orion.txt",imagedir,subfile_prefix); fp=fopen(filename,"w"); if(fp==NULL) file_open_error(filename); for(int i=0; i<n; i++) { landmark[0]=LM[0*n + i]; landmark[1]=LM[1*n + i]; landmark[2]=LM[2*n + i]; landmark[3]=1; multi(invT,4,4,landmark,4,1,landmark); convert_to_ijk(landmark, 1, subim); fprintf(fp,"%5.1f %5.1f %5.1f\n",landmark[0], landmark[1], landmark[2]); } fclose(fp); free(invT); } float *P; float *Q; // Image using Q insted of P' in Eq. (1) of Arun et al. 1987 float TLM[16]; Q = (float *)calloc(3*n,sizeof(float)); P = (float *)calloc(3*n,sizeof(float)); for(int i=0; i<3*n; i++) P[i]=LM[i]; delete subimPIL.v; ///////////////////////////////////////////////////////// // read Q { FILE *fp; int r, r2; int cm[3]; fp=fopen(modelfile, "r"); if(fp==NULL) file_open_error(modelfile); fread(&n, sizeof(int), 1, fp); fread(&r, sizeof(int), 1, fp); fread(&r2, sizeof(int), 1, fp); SPH refsph(r); for(int i=0; i<n; i++) { fread(cm, sizeof(int), 3, fp); fread(refsph.v, sizeof(float), refsph.n, fp); Q[0*n + i]=cm[0]; Q[1*n + i]=cm[1]; Q[2*n + i]=cm[2]; } fclose(fp); convert_to_xyz(Q, n, subimPIL); } Procrustes(Q, Qavg, n, P, Pavg, TLM); multi(TLM,4,4,TPIL0,4,4,TPIL); // create the *LM.ppm image if(opt_ppm || opt_png) { int *lmx, *lmy; float lm[4]; invT = inv4(TPIL); resliceImage(subim, subimPIL, invT, LIN); free(invT); lmx = (int *)calloc(n,sizeof(int)); lmy = (int *)calloc(n,sizeof(int)); for(int i=0; i<n; i++) { lm[0] = P[i] + Pavg[0]; lm[1] = P[n+i] + Pavg[1]; lm[2] = P[2*n+i] + Pavg[2]; lm[3] = 1.0; multi(TLM,4,4,lm,4,1,lm); convert_to_ijk(lm, 1, subimPIL); lmx[i]=(int)( lm[0] + 0.5 ); lmy[i]=(int)( lm[1] + 0.5 ); } sprintf(filename,"%s/%s_orion.ppm",imagedir, subfile_prefix); mspPPM(subimPIL, lmx, lmy, n, filename); delete lmx; delete lmy; delete subimPIL.v; } if(opt_CENTER_AC) { float ac[4]; float Ttmp[16]; ac[0] = P[1] + Pavg[0]; // landmark #1 is AC ac[1] = P[n+1] + Pavg[1]; ac[2] = P[2*n+1] + Pavg[2]; ac[3] = 1.0; multi(TLM,4,4,ac,4,1,ac); Ttmp[0]=1.0; Ttmp[1]=0.0; Ttmp[2]=0.0; Ttmp[3]=-ac[0]; // makes ac the center of the FOV Ttmp[4]=0.0; Ttmp[5]=1.0; Ttmp[6]=0.0; Ttmp[7]=-ac[1]; // ac[1] should be equal to pc[1] Ttmp[8]=0.0; Ttmp[9]=0.0; Ttmp[10]=1.0; Ttmp[11]=0; Ttmp[12]=0.0; Ttmp[13]=0.0; Ttmp[14]=0.0; Ttmp[15]=1.0; multi(Ttmp,4,4,TPIL,4,4,TPIL); } // save the PIL transformation in <subfile_prefix>_PIL.mrx if(SAVE_MRX_FLAG == 1) { FILE *fp; sprintf(filename,"%s/%s_PIL.mrx",imagedir, subfile_prefix); fp=fopen(filename,"w"); if(fp==NULL) file_open_error(filename); printMatrix(TPIL,4,4,"",fp); fclose(fp); } { float ssd1=0.0; float ssd3=0.0; float x[4], y[4]; x[3]=y[3]=1.0; for(int i=0; i<n; i++) { x[0] = Q[i] + Qavg[0]; x[1] = Q[i+n] + Qavg[1]; x[2] = Q[i+2*n] + Qavg[2]; y[0] = P[i]+Pavg[0]; y[1] = P[i+n]+Pavg[1]; y[2] = P[i+2*n]+Pavg[2]; ssd1 += (x[0]-y[0])*(x[0]-y[0]); ssd1 += (x[1]-y[1])*(x[1]-y[1]); ssd1 += (x[2]-y[2])*(x[2]-y[2]); multi(TLM,4,4,y,4,1,y); ssd3 += (x[0]-y[0])*(x[0]-y[0]); ssd3 += (x[1]-y[1])*(x[1]-y[1]); ssd3 += (x[2]-y[2])*(x[2]-y[2]); } //if(opt_v) printf("SSD (MSP + AC/PC transformation) = %f\n",ssd1); //if(opt_v) printf("SSD (MSP + AC/PC + LM transformation) = %f\n",ssd3); } delete subim.v; free(P); free(Q); }
widget::widget(const variant& v, game_logic::formula_callable* e) : environ_(e), w_(0), h_(0), x_(0), y_(0), zorder_(0), true_x_(0), true_y_(0), disabled_(false), disabled_opacity_(v["disabled_opacity"].as_int(127)), tooltip_displayed_(false), id_(v["id"].as_string_default()), align_h_(HALIGN_LEFT), align_v_(VALIGN_TOP) { if(v.has_key("width")) { w_ = v["width"].as_int(); } if(v.has_key("height")) { h_ = v["height"].as_int(); } if(v.has_key("wh")) { std::vector<int> iv = v["wh"].as_list_int(); ASSERT_LOG(iv.size() == 2, "WH attribute must be 2 integer elements."); w_ = iv[0]; h_ = iv[1]; } if(v.has_key("rect")) { std::vector<int> r = v["rect"].as_list_int(); ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute"); set_loc(r[0], r[1]); set_dim(r[2], r[3]); } if(v.has_key("draw_area")) { std::vector<int> r = v["draw_area"].as_list_int(); ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute"); set_loc(r[0], r[1]); set_dim(r[2], r[3]); } if(v.has_key("x")) { true_x_ = x_ = v["x"].as_int(); } if(v.has_key("y")) { true_y_ = y_ = v["y"].as_int(); } if(v.has_key("xy")) { std::vector<int> iv = v["xy"].as_list_int(); ASSERT_LOG(iv.size() == 2, "XY attribute must be 2 integer elements."); true_x_ = x_ = iv[0]; true_y_ = y_ = iv[1]; } zorder_ = v["zorder"].as_int(0); if(v.has_key("on_process")) { on_process_ = boost::bind(&widget::process_delegate, this); ffl_on_process_ = get_environment()->create_formula(v["on_process"]); } if(v.has_key("tooltip")) { if(v["tooltip"].is_string()) { set_tooltip(v["tooltip"].as_string(), v["tooltip_size"].as_int(18)); } else if(v["tooltip"].is_map()) { set_tooltip(v["tooltip"]["text"].as_string(), v["tooltip"]["size"].as_int(18)); } else { ASSERT_LOG(false, "Specify the tooltip as a string, e.g. \"tooltip\":\"Text to display on mouseover\", " "or a map, e.g. \"tooltip\":{\"text\":\"Text to display.\", \"size\":14}"); } } visible_ = v["visible"].as_bool(true); if(v.has_key("align_h")) { std::string align = v["align_h"].as_string(); if(align == "left") { align_h_ = HALIGN_LEFT; } else if(align == "middle" || align == "center" || align == "centre") { align_h_ = HALIGN_CENTER; } else if(align == "right") { align_h_ = HALIGN_RIGHT; } else { ASSERT_LOG(false, "Invalid align_h attribute given: " << align); } } if(v.has_key("align_v")) { std::string align = v["align_v"].as_string(); if(align == "top") { align_v_ = VALIGN_TOP; } else if(align == "middle" || align == "center" || align == "centre") { align_v_ = VALIGN_CENTER; } else if(align == "bottom") { align_v_ = VALIGN_BOTTOM; } else { ASSERT_LOG(false, "Invalid align_v attribute given: " << align); } } disabled_ = !v["enabled"].as_bool(true); recalc_loc(); }
widget::widget(const variant& v, game_logic::formula_callable* e) : environ_(e), w_(0), h_(0), x_(0), y_(0), zorder_(0), true_x_(0), true_y_(0), disabled_(false), disabled_opacity_(v["disabled_opacity"].as_int(127)), tooltip_displayed_(false), id_(v["id"].as_string_default()), align_h_(HALIGN_LEFT), align_v_(VALIGN_TOP), tooltip_display_delay_(v["tooltip_delay"].as_int(500)), tooltip_ticks_(INT_MAX), resolution_(v["frame_size"].as_int(0)), display_alpha_(v["alpha"].as_int(256)), pad_w_(0), pad_h_(0), claim_mouse_events_(v["claim_mouse_events"].as_bool(true)), draw_with_object_shader_(v["draw_with_object_shader"].as_bool(true)) { set_alpha(display_alpha_ < 0 ? 0 : (display_alpha_ > 256 ? 256 : display_alpha_)); if(v.has_key("width")) { w_ = v["width"].as_int(); } if(v.has_key("height")) { h_ = v["height"].as_int(); } if(v.has_key("wh")) { std::vector<int> iv = v["wh"].as_list_int(); ASSERT_LOG(iv.size() == 2, "WH attribute must be 2 integer elements."); w_ = iv[0]; h_ = iv[1]; } if(v.has_key("rect")) { std::vector<int> r = v["rect"].as_list_int(); ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute"); set_loc(r[0], r[1]); set_dim(r[2], r[3]); } if(v.has_key("draw_area")) { std::vector<int> r = v["draw_area"].as_list_int(); ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute"); set_loc(r[0], r[1]); set_dim(r[2], r[3]); } if(v.has_key("x")) { true_x_ = x_ = v["x"].as_int(); } if(v.has_key("y")) { true_y_ = y_ = v["y"].as_int(); } if(v.has_key("xy")) { std::vector<int> iv = v["xy"].as_list_int(); ASSERT_LOG(iv.size() == 2, "XY attribute must be 2 integer elements."); true_x_ = x_ = iv[0]; true_y_ = y_ = iv[1]; } zorder_ = v["zorder"].as_int(0); if(v.has_key("on_process")) { on_process_ = boost::bind(&widget::process_delegate, this); ffl_on_process_ = get_environment()->create_formula(v["on_process"]); } if(v.has_key("tooltip")) { if(v["tooltip"].is_string()) { SDL_Color color = v.has_key("tooltip_color") ? graphics::color(v["tooltip_color"]).as_sdl_color() : graphics::color_yellow(); set_tooltip(v["tooltip"].as_string(), v["tooltip_size"].as_int(18), color, v["tooltip_font"].as_string_default()); } else if(v["tooltip"].is_map()) { SDL_Color color = v["tooltip"].has_key("color") ? graphics::color(v["tooltip"]["color"]).as_sdl_color() : graphics::color_yellow(); set_tooltip(v["tooltip"]["text"].as_string(), v["tooltip"]["size"].as_int(18), color, v["tooltip"]["font"].as_string_default()); } else { ASSERT_LOG(false, "Specify the tooltip as a string, e.g. \"tooltip\":\"Text to display on mouseover\", " "or a map, e.g. \"tooltip\":{\"text\":\"Text to display.\", \"size\":14}"); } } visible_ = v["visible"].as_bool(true); if(v.has_key("align_h")) { std::string align = v["align_h"].as_string(); if(align == "left") { align_h_ = HALIGN_LEFT; } else if(align == "middle" || align == "center" || align == "centre") { align_h_ = HALIGN_CENTER; } else if(align == "right") { align_h_ = HALIGN_RIGHT; } else { ASSERT_LOG(false, "Invalid align_h attribute given: " << align); } } if(v.has_key("align_v")) { std::string align = v["align_v"].as_string(); if(align == "top") { align_v_ = VALIGN_TOP; } else if(align == "middle" || align == "center" || align == "centre") { align_v_ = VALIGN_CENTER; } else if(align == "bottom") { align_v_ = VALIGN_BOTTOM; } else { ASSERT_LOG(false, "Invalid align_v attribute given: " << align); } } disabled_ = !v["enabled"].as_bool(true); if(v.has_key("frame")) { set_frame_set(v["frame"].as_string()); } if(v.has_key("frame_padding")) { ASSERT_LOG(v["frame_padding"].is_list() && v["frame_padding"].num_elements() == 2, "'pad' must be two element list"); set_padding(v["frame_padding"][0].as_int(), v["frame_padding"][1].as_int()); } if(v.has_key("frame_pad_width")) { set_padding(v["frame_pad_width"].as_int(), get_pad_height()); } if(v.has_key("frame_pad_height")) { set_padding(get_pad_width(), v["frame_pad_height"].as_int()); } recalc_loc(); }
border_widget::border_widget(widget_ptr child, graphics::color col, int border_size) : child_(child), color_(col), border_size_(border_size) { set_dim(child->width() + border_size*2, child->height() + border_size*2); child_->set_loc(border_size, border_size); }
int invert_test(void) { QudaGaugeParam gaugeParam = newQudaGaugeParam(); QudaInvertParam inv_param = newQudaInvertParam(); double mass = 0.95; set_params(&gaugeParam, &inv_param, sdim, sdim, sdim, tdim, cpu_prec, prec, prec_sloppy, link_recon, link_recon_sloppy, mass, tol, 500, 1e-3, 0.8); // this must be before the FaceBuffer is created (this is because it allocates pinned memory - FIXME) initQuda(device); setDims(gaugeParam.X); setDimConstants(gaugeParam.X); size_t gSize = (gaugeParam.cpu_prec == QUDA_DOUBLE_PRECISION) ? sizeof(double) : sizeof(float); for (int dir = 0; dir < 4; dir++) { fatlink[dir] = malloc(V*gaugeSiteSize*gSize); longlink[dir] = malloc(V*gaugeSiteSize*gSize); } construct_fat_long_gauge_field(fatlink, longlink, 1, gaugeParam.cpu_prec, &gaugeParam); for (int dir = 0; dir < 4; dir++) { for(int i = 0;i < V*gaugeSiteSize;i++){ if (gaugeParam.cpu_prec == QUDA_DOUBLE_PRECISION){ ((double*)fatlink[dir])[i] = 0.5 *rand()/RAND_MAX; }else{ ((float*)fatlink[dir])[i] = 0.5* rand()/RAND_MAX; } } } #ifdef MULTI_GPU //exchange_init_dims(gaugeParam.X); int ghost_link_len[4] = { Vs_x*gaugeSiteSize*gSize, Vs_y*gaugeSiteSize*gSize, Vs_z*gaugeSiteSize*gSize, Vs_t*gaugeSiteSize*gSize }; for(int i=0;i < 4;i++){ ghost_fatlink[i] = malloc(ghost_link_len[i]); ghost_longlink[i] = malloc(3*ghost_link_len[i]); if (ghost_fatlink[i] == NULL || ghost_longlink[i] == NULL){ printf("ERROR: malloc failed for ghost fatlink or ghost longlink\n"); exit(1); } } //exchange_cpu_links4dir(fatlink, ghost_fatlink, longlink, ghost_longlink, gaugeParam.cpu_prec); void *fat_send[4], *long_send[4]; for(int i=0;i < 4;i++){ fat_send[i] = malloc(ghost_link_len[i]); long_send[i] = malloc(3*ghost_link_len[i]); } set_dim(Z); pack_ghost(fatlink, fat_send, 1, gaugeParam.cpu_prec); pack_ghost(longlink, long_send, 3, gaugeParam.cpu_prec); int dummyFace = 1; FaceBuffer faceBuf (Z, 4, 18, dummyFace, gaugeParam.cpu_prec); faceBuf.exchangeCpuLink((void**)ghost_fatlink, (void**)fat_send, 1); faceBuf.exchangeCpuLink((void**)ghost_longlink, (void**)long_send, 3); for (int i=0; i<4; i++) { free(fat_send[i]); free(long_send[i]); } #endif ColorSpinorParam csParam; csParam.fieldLocation = QUDA_CPU_FIELD_LOCATION; csParam.nColor=3; csParam.nSpin=1; csParam.nDim=4; for(int d = 0; d < 4; d++) { csParam.x[d] = gaugeParam.X[d]; } csParam.x[0] /= 2; csParam.precision = inv_param.cpu_prec; csParam.pad = 0; csParam.siteSubset = QUDA_PARITY_SITE_SUBSET; csParam.siteOrder = QUDA_EVEN_ODD_SITE_ORDER; csParam.fieldOrder = QUDA_SPACE_SPIN_COLOR_FIELD_ORDER; csParam.gammaBasis = QUDA_DEGRAND_ROSSI_GAMMA_BASIS; csParam.create = QUDA_ZERO_FIELD_CREATE; in = new cpuColorSpinorField(csParam); out = new cpuColorSpinorField(csParam); ref = new cpuColorSpinorField(csParam); tmp = new cpuColorSpinorField(csParam); if (inv_param.cpu_prec == QUDA_SINGLE_PRECISION){ constructSpinorField((float*)in->v); }else{ constructSpinorField((double*)in->v); } #ifdef MULTI_GPU if(testtype == 6){ record_gauge(fatlink, ghost_fatlink[3], Vsh_t, longlink, ghost_longlink[3], 3*Vsh_t, link_recon, link_recon_sloppy, &gaugeParam); }else{ gaugeParam.type = QUDA_ASQTAD_FAT_LINKS; gaugeParam.ga_pad = MAX(sdim*sdim*sdim/2, sdim*sdim*tdim/2); gaugeParam.reconstruct= gaugeParam.reconstruct_sloppy = QUDA_RECONSTRUCT_NO; loadGaugeQuda(fatlink, &gaugeParam); gaugeParam.type = QUDA_ASQTAD_LONG_LINKS; gaugeParam.ga_pad = 3*MAX(sdim*sdim*sdim/2, sdim*sdim*tdim/2); gaugeParam.reconstruct= link_recon; gaugeParam.reconstruct_sloppy = link_recon_sloppy; loadGaugeQuda(longlink, &gaugeParam); } #else gaugeParam.type = QUDA_ASQTAD_FAT_LINKS; gaugeParam.reconstruct = gaugeParam.reconstruct_sloppy = QUDA_RECONSTRUCT_NO; loadGaugeQuda(fatlink, &gaugeParam); gaugeParam.type = QUDA_ASQTAD_LONG_LINKS; gaugeParam.reconstruct = link_recon; gaugeParam.reconstruct_sloppy = link_recon_sloppy; loadGaugeQuda(longlink, &gaugeParam); #endif double time0 = -((double)clock()); // Start the timer unsigned long volume = Vh; unsigned long nflops=2*1187; //from MILC's CG routine double nrm2=0; double src2=0; int ret = 0; switch(testtype){ case 0: //even volume = Vh; inv_param.solution_type = QUDA_MATPCDAG_MATPC_SOLUTION; inv_param.matpc_type = QUDA_MATPC_EVEN_EVEN; invertQuda(out->v, in->v, &inv_param); time0 += clock(); time0 /= CLOCKS_PER_SEC; #ifdef MULTI_GPU matdagmat_mg4dir(ref, fatlink, ghost_fatlink, longlink, ghost_longlink, out, mass, 0, inv_param.cpu_prec, gaugeParam.cpu_prec, tmp, QUDA_EVEN_PARITY); #else matdagmat(ref->v, fatlink, longlink, out->v, mass, 0, inv_param.cpu_prec, gaugeParam.cpu_prec, tmp->v, QUDA_EVEN_PARITY); #endif mxpy(in->v, ref->v, Vh*mySpinorSiteSize, inv_param.cpu_prec); nrm2 = norm_2(ref->v, Vh*mySpinorSiteSize, inv_param.cpu_prec); src2 = norm_2(in->v, Vh*mySpinorSiteSize, inv_param.cpu_prec); break; case 1: //odd volume = Vh; inv_param.solution_type = QUDA_MATPCDAG_MATPC_SOLUTION; inv_param.matpc_type = QUDA_MATPC_ODD_ODD; invertQuda(out->v, in->v, &inv_param); time0 += clock(); // stop the timer time0 /= CLOCKS_PER_SEC; #ifdef MULTI_GPU matdagmat_mg4dir(ref, fatlink, ghost_fatlink, longlink, ghost_longlink, out, mass, 0, inv_param.cpu_prec, gaugeParam.cpu_prec, tmp, QUDA_ODD_PARITY); #else matdagmat(ref->v, fatlink, longlink, out->v, mass, 0, inv_param.cpu_prec, gaugeParam.cpu_prec, tmp->v, QUDA_ODD_PARITY); #endif mxpy(in->v, ref->v, Vh*mySpinorSiteSize, inv_param.cpu_prec); nrm2 = norm_2(ref->v, Vh*mySpinorSiteSize, inv_param.cpu_prec); src2 = norm_2(in->v, Vh*mySpinorSiteSize, inv_param.cpu_prec); break; case 2: //full spinor errorQuda("full spinor not supported\n"); break; case 3: //multi mass CG, even case 4: case 5: case 6: #define NUM_OFFSETS 4 nflops = 2*(1205 + 15* NUM_OFFSETS); //from MILC's multimass CG routine double masses[NUM_OFFSETS] ={5.05, 1.23, 2.64, 2.33}; double offsets[NUM_OFFSETS]; int num_offsets =NUM_OFFSETS; void* outArray[NUM_OFFSETS]; int len; cpuColorSpinorField* spinorOutArray[NUM_OFFSETS]; spinorOutArray[0] = out; for(int i=1;i < num_offsets; i++){ spinorOutArray[i] = new cpuColorSpinorField(csParam); } for(int i=0;i < num_offsets; i++){ outArray[i] = spinorOutArray[i]->v; } for (int i=0; i< num_offsets;i++){ offsets[i] = 4*masses[i]*masses[i]; } len=Vh; volume = Vh; inv_param.solution_type = QUDA_MATPCDAG_MATPC_SOLUTION; if (testtype == 3){ inv_param.matpc_type = QUDA_MATPC_EVEN_EVEN; } else if (testtype == 4||testtype == 6){ inv_param.matpc_type = QUDA_MATPC_ODD_ODD; }else { //testtype ==5 errorQuda("test 5 not supported\n"); } double residue_sq; if (testtype == 6){ //invertMultiShiftQudaMixed(spinorOutArray, in->v, &inv_param, offsets, num_offsets, &residue_sq); }else{ invertMultiShiftQuda(outArray, in->v, &inv_param, offsets, num_offsets, &residue_sq); } cudaThreadSynchronize(); printfQuda("Final residue squred =%g\n", residue_sq); time0 += clock(); // stop the timer time0 /= CLOCKS_PER_SEC; printfQuda("done: total time = %g secs, %i iter / %g secs = %g gflops, \n", time0, inv_param.iter, inv_param.secs, inv_param.gflops/inv_param.secs); printfQuda("checking the solution\n"); QudaParity parity; if (inv_param.solve_type == QUDA_NORMEQ_SOLVE){ //parity = QUDA_EVENODD_PARITY; errorQuda("full parity not supported\n"); }else if (inv_param.matpc_type == QUDA_MATPC_EVEN_EVEN){ parity = QUDA_EVEN_PARITY; }else if (inv_param.matpc_type == QUDA_MATPC_ODD_ODD){ parity = QUDA_ODD_PARITY; }else{ errorQuda("ERROR: invalid spinor parity \n"); exit(1); } for(int i=0;i < num_offsets;i++){ printfQuda("%dth solution: mass=%f, ", i, masses[i]); #ifdef MULTI_GPU matdagmat_mg4dir(ref, fatlink, ghost_fatlink, longlink, ghost_longlink, spinorOutArray[i], masses[i], 0, inv_param.cpu_prec, gaugeParam.cpu_prec, tmp, parity); #else matdagmat(ref->v, fatlink, longlink, outArray[i], masses[i], 0, inv_param.cpu_prec, gaugeParam.cpu_prec, tmp->v, parity); #endif mxpy(in->v, ref->v, len*mySpinorSiteSize, inv_param.cpu_prec); double nrm2 = norm_2(ref->v, len*mySpinorSiteSize, inv_param.cpu_prec); double src2 = norm_2(in->v, len*mySpinorSiteSize, inv_param.cpu_prec); printfQuda("relative residual, requested = %g, actual = %g\n", inv_param.tol, sqrt(nrm2/src2)); //emperical, if the cpu residue is more than 2 order the target accuracy, the it fails to converge if (sqrt(nrm2/src2) > 100*inv_param.tol){ ret |=1; errorQuda("Converge failed!\n"); } } for(int i=1; i < num_offsets;i++){ delete spinorOutArray[i]; } }//switch if (testtype <=2){ printfQuda("Relative residual, requested = %g, actual = %g\n", inv_param.tol, sqrt(nrm2/src2)); printfQuda("done: total time = %g secs, %i iter / %g secs = %g gflops, \n", time0, inv_param.iter, inv_param.secs, inv_param.gflops/inv_param.secs); //emperical, if the cpu residue is more than 2 order the target accuracy, the it fails to converge if (sqrt(nrm2/src2) > 100*inv_param.tol){ ret = 1; errorQuda("Convergence failed!\n"); } } end(); return ret; }
bool Engine::bufferModel() { // Input loader InputManager::init(GLFWwindowPtr, WIDTH, HEIGHT, camera); // Define objects auto back = std::make_shared<Object2D>(); back->set_loc(vec3(-1, 0., -0.2)); back->set_dim(vec3(2., 1., -1.)); back->set_texture_dir("Images/sky.jpg"); back->toggle_wrap(); back->buffer("Models/sphere.obj"); om.addObject("back", std::move(back)); /* auto floor = std::make_shared<Object2D>(); floor->set_loc(vec3(-1, -1., -0.2)); floor->set_dim(vec3(2., 1., -1.)); floor->set_texture_dir("Images/floor.jpg"); floor->toggle_wrap(); floor->buffer("Models/sphere.obj"); om.addObject("floor", std::move(floor)); auto thief = std::make_shared<Player2D>(); thief->set_loc(vec3(0.0, 0.0, 0)); thief->set_dim(vec3(0.4, 0.7, 1.0)); thief->set_texture_dir("Images/thief.png"); thief->set_behavior(Player2D::CONTROLLED); thief->set_label(Player2D::PLAYER); thief->set_bound(Player2D::SQUARE); thief->set_max_force(0.7f); thief->set_max_speed(0.7f); thief->set_max_acceleration(0.3f); thief->buffer(); om.addObject("thief", std::move(thief)); auto mes = std::make_shared<Object2D>(); mes->set_dim(vec3(0.5, 0.4, 1.0)); mes->set_texture_dir("Images/ouch.png"); mes->set_invisibility(true); mes->buffer(); om.addObject("ouch", std::move(mes)); auto lord1 = std::make_shared<Object2D>(); lord1->set_loc(vec3(-0.4, -0.4, 0)); lord1->set_dim(vec3(0.4, .6, 1.)); lord1->set_texture_dir("Images/lord.png"); lord1->set_target(om.objects.at("thief")); lord1->set_behavior(Object2D::SEEK); lord1->set_label(Player2D::ENEMY); lord1->set_bound(Player2D::SQUARE); lord1->set_max_force(0.3f); lord1->set_max_speed(0.2f); lord1->buffer(); om.addObject("lord1", std::move(lord1)); auto lord2 = std::make_shared<Object2D>(); lord2->set_loc(vec3(-0.7, -0.4, 0)); lord2->set_dim(vec3(0.6, 0.7, 1.)); lord2->set_texture_dir("Images/lord2.png"); lord2->set_target(om.objects.at("thief")); lord2->set_behavior(Object2D::SEEK); lord2->set_label(Player2D::ENEMY); lord2->set_bound(Player2D::SQUARE); lord2->set_max_force(0.4f); lord2->set_max_speed(0.3f); lord2->buffer(); om.addObject("lord2", std::move(lord2)); */ // Define view camera = FreeCamera(WIDTH, HEIGHT); camera.set_camera( vec3(0.0f, 0.0f, 2.f), vec3(0.0f, 0.0f, -1.0f), vec3(0.0f, 1.0f, 0.0f) ); camera.is_ortho(false); return true; }