/* ----------------------------------------------------------------------- Main Window -------------------------------------------------------------------------*/ #include "MyFrame.h" //Icones #include "UDG.xpm" #include #include #include #include #include #include #include "glew.h" #include "vcObscuranceMap.h" #include "CMesh.h" BEGIN_EVENT_TABLE(MyFrame,wxFrame) EVT_BUTTON(MyFrame::MAIN_MODEL, MyFrame::OnSelectModel) EVT_BUTTON(MyFrame::MAIN_IMAGE, MyFrame::OnSelectImage) EVT_BUTTON(MyFrame::MAIN_START, MyFrame::OnStart) EVT_COMBOBOX(MyFrame::MAIN_RES, MyFrame::OnSelectResolution) END_EVENT_TABLE() // My frame constructor MyFrame::MyFrame (const wxChar * title, int xpos, int ypos, int width, int height) : wxFrame ( (wxFrame *) NULL, -1, title, wxPoint(xpos, ypos), wxSize(width,height), wxCLOSE_BOX|wxCAPTION|wxSYSTEM_MENU ) { //Init Parameters modelString = new wxString(""); imageString = new wxString(""); res = 0; wxString choices_res_text[3]; choices_res_text[0] = " 256 x 256"; choices_res_text[1] = " 512 x 512"; choices_res_text[2] = "1024 x 1024"; choices_res[0] = 256; choices_res[1] = 512; choices_res[2] = 1024; //Create Fonts wxFont * font10 = new wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); wxFont * font10bold = new wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD); //Set Frame Icon SetIcon(wxIcon(UDG_xpm)); //Set BackGround SetBackgroundColour(wxColour(200,200,200)); //Create Main Sizer wxBoxSizer * mainSizer = new wxBoxSizer(wxVERTICAL); //Create GridSizer wxGridSizer * gridSizer = new wxGridSizer(3,1,5,5); mainSizer->Add(gridSizer,1,wxALL|wxEXPAND,10); //Model wxStaticBoxSizer * modelBoxSizer = new wxStaticBoxSizer(wxVERTICAL,this); gridSizer->Add(modelBoxSizer,2,wxALL|wxEXPAND,5); wxButton * modelButton = new wxButton( this, MAIN_MODEL, "Select Model"); modelButton->SetFont(*font10bold); modelBoxSizer->Add(modelButton,1,wxALL|wxEXPAND,5); modelText = new wxStaticText(this, wxID_ANY, "Load a Model..."); modelText->SetFont(*font10); modelBoxSizer->Add(modelText,1,wxALL|wxEXPAND,5); //Image wxStaticBoxSizer * imageBoxSizer = new wxStaticBoxSizer(wxVERTICAL,this); gridSizer->Add(imageBoxSizer,2,wxALL|wxEXPAND,5); wxButton * imageButton = new wxButton( this, MAIN_IMAGE, "Select Image"); imageButton->SetFont(*font10bold); imageBoxSizer->Add(imageButton,1,wxALL|wxEXPAND,5); imageText = new wxStaticText(this, wxID_ANY, "Save to..."); imageText->SetFont(*font10); imageBoxSizer->Add(imageText,1,wxALL|wxEXPAND,5); //Group wxGridSizer * groupSizer = new wxGridSizer(1,2,5,5); gridSizer->Add(groupSizer,1,wxALL|wxEXPAND,2); //Resolution wxStaticBoxSizer * resBoxSizer = new wxStaticBoxSizer(wxVERTICAL,this); groupSizer->Add(resBoxSizer,1,wxALL|wxEXPAND); wxStaticText * resLabel = new wxStaticText(this, wxID_ANY, "Resolution"); resLabel->SetFont(*font10bold); resBoxSizer->Add(resLabel,1,wxALL|wxEXPAND,2); wxComboBox * combo_res = new wxComboBox(this, MAIN_RES, "", wxDefaultPosition, wxDefaultSize, 3, choices_res_text, wxCB_READONLY); combo_res->Select(0); res = choices_res[0]; resBoxSizer->Add(combo_res,1,wxALL|wxEXPAND,2); //Start startButton = new wxButton( this, MAIN_START, "Start",wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); startButton->SetFont(*font10bold); startButton->Enable(false); mainSizer->Add(startButton,0,wxALL|wxCENTER,5); //mainSizer SetSizer(mainSizer); mainSizer->SetSizeHints(this); } //Destructor MyFrame::~MyFrame() { } void MyFrame::CheckStart() { if ( ( *modelString != "" ) && ( *imageString != "" ) && ( res != 0)) { //Toggle Button startButton->Enable(true); } else startButton->Enable(false); } void MyFrame::OnSelectModel(wxCommandEvent & event) { const wxChar * FILETYPES = wxT ( //"Ogre Mesh files|*.mesh|" "Ogre XML files|*.xml|" "All files|*.*" ); wxFileDialog * openFileDialog = new wxFileDialog(this,"Select Mesh", /*Default folder*/"",/*Default Filename*/"", FILETYPES,wxOPEN|wxFILE_MUST_EXIST,wxDefaultPosition); if (openFileDialog->ShowModal() == wxID_OK ) { modelString = new wxString(""); modelString->Append(openFileDialog->GetPath()); modelText->SetLabel(openFileDialog->GetFilename()); } CheckStart(); } //Image saving location void MyFrame::OnSelectImage(wxCommandEvent & event) { const wxChar * FILETYPES = wxT ( "Bitmap|*.bmp|" "All files|*.*" ); wxFileDialog * saveFileDialog = new wxFileDialog(this,"Select where to Save Image", /*Default folder*/"",/*Default Filename*/"", FILETYPES,wxSAVE,wxDefaultPosition); if (saveFileDialog->ShowModal() == wxID_OK ) { imageString = new wxString(""); imageString->Append(saveFileDialog->GetPath()); imageText->SetLabel(saveFileDialog->GetFilename()); } CheckStart(); } void MyFrame::OnStart(wxCommandEvent & event) { float *ObscuranceMap; int i, j; CMesh g_pMesh; //if image.bmp exists... if ( wxFile::Exists(imageString->GetData()) ) { int response = ::wxMessageBox("Image already exists?\nOverwrite?", "Attention!", wxYES_NO); if ( response == wxNO ) return; } ObscuranceMap = new float[res * res * 4]; char *name = new char[modelString->Length() + 100], character; for (i = 0, j = 0; i < modelString->Length(); i++, j++) { character = modelString->GetChar(i); if (character == '\\') { name[j] = modelString->GetChar(i); name[j + 1] = modelString->GetChar(i); j++; } else name[j] = modelString->GetChar(i); } name[j] = '\0'; //start Obscurances generation vcObscurerGenerateImage(g_pMesh, name, int(res/256), &res, &res, &ObscuranceMap); typedef unsigned char uchar; uchar *bmp = new unsigned char[res * res * 3]; float r_float; i = 0; j = 0; while (i < (res * res * 4)) { r_float = ObscuranceMap[i] * 255; bmp[j] = uchar(r_float); r_float = ObscuranceMap[i+1] * 255; bmp[j + 1] = uchar(r_float); r_float = ObscuranceMap[i+2] * 255; bmp[j + 2] = uchar(r_float); j += 3; i += 4; } wxImage img(res,res); img.SetData(bmp,res,res); img.SaveFile(*imageString, wxBITMAP_TYPE_BMP); //freeing memory g_pMesh.FreeMem(); delete name; } //Seleccionar Resolucio void MyFrame::OnSelectResolution(wxCommandEvent & event) { int id = event.GetSelection(); res = choices_res[id]; CheckStart(); } //Seleccionar Qualitat /*->void MyFrame::OnSelectQuality(wxCommandEvent & event) { int id = event.GetSelection(); qua = choices_qua[id]; ComprovaStart(); }*/