[930] | 1 | /* -----------------------------------------------------------------------
|
---|
| 2 | Main Window
|
---|
| 3 | -------------------------------------------------------------------------*/
|
---|
| 4 | #include "MyFrame.h"
|
---|
| 5 |
|
---|
| 6 | //Icones
|
---|
| 7 | #include "UDG.xpm"
|
---|
| 8 |
|
---|
| 9 | #include <wx/progdlg.h>
|
---|
| 10 | #include <wx/file.h>
|
---|
| 11 | #include <wx/string.h>
|
---|
| 12 | #include <wx/strconv.h>
|
---|
| 13 | #include <wx/bitmap.h>
|
---|
| 14 | #include <wx/image.h>
|
---|
| 15 |
|
---|
| 16 | #include "glew.h"
|
---|
| 17 | #include "vcObscuranceMap.h"
|
---|
| 18 | #include "CMesh.h"
|
---|
| 19 |
|
---|
| 20 | BEGIN_EVENT_TABLE(MyFrame,wxFrame)
|
---|
| 21 | EVT_BUTTON(MyFrame::MAIN_MODEL, MyFrame::OnSelectModel)
|
---|
| 22 | EVT_BUTTON(MyFrame::MAIN_IMAGE, MyFrame::OnSelectImage)
|
---|
| 23 | EVT_BUTTON(MyFrame::MAIN_START, MyFrame::OnStart)
|
---|
| 24 | EVT_COMBOBOX(MyFrame::MAIN_RES, MyFrame::OnSelectResolution)
|
---|
| 25 | END_EVENT_TABLE()
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | // My frame constructor
|
---|
| 29 | MyFrame::MyFrame (const wxChar * title, int xpos, int ypos, int width, int height)
|
---|
| 30 | : wxFrame ( (wxFrame *) NULL, -1, title, wxPoint(xpos, ypos), wxSize(width,height), wxCLOSE_BOX|wxCAPTION|wxSYSTEM_MENU )
|
---|
| 31 | {
|
---|
| 32 | //Init Parameters
|
---|
| 33 | modelString = new wxString("");
|
---|
| 34 | imageString = new wxString("");
|
---|
| 35 | res = 0;
|
---|
| 36 |
|
---|
| 37 | wxString choices_res_text[3];
|
---|
| 38 | choices_res_text[0] = " 256 x 256";
|
---|
| 39 | choices_res_text[1] = " 512 x 512";
|
---|
| 40 | choices_res_text[2] = "1024 x 1024";
|
---|
| 41 |
|
---|
| 42 | choices_res[0] = 256;
|
---|
| 43 | choices_res[1] = 512;
|
---|
| 44 | choices_res[2] = 1024;
|
---|
| 45 |
|
---|
| 46 | //Create Fonts
|
---|
| 47 | wxFont * font10 = new wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
---|
| 48 | wxFont * font10bold = new wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
|
---|
| 49 |
|
---|
| 50 | //Set Frame Icon
|
---|
| 51 | SetIcon(wxIcon(UDG_xpm));
|
---|
| 52 |
|
---|
| 53 | //Set BackGround
|
---|
| 54 | SetBackgroundColour(wxColour(200,200,200));
|
---|
| 55 |
|
---|
| 56 | //Create Main Sizer
|
---|
| 57 | wxBoxSizer * mainSizer = new wxBoxSizer(wxVERTICAL);
|
---|
| 58 |
|
---|
| 59 | //Create GridSizer
|
---|
| 60 | wxGridSizer * gridSizer = new wxGridSizer(3,1,5,5);
|
---|
| 61 | mainSizer->Add(gridSizer,1,wxALL|wxEXPAND,10);
|
---|
| 62 |
|
---|
| 63 | //Model
|
---|
| 64 | wxStaticBoxSizer * modelBoxSizer = new wxStaticBoxSizer(wxVERTICAL,this);
|
---|
| 65 | gridSizer->Add(modelBoxSizer,2,wxALL|wxEXPAND,5);
|
---|
| 66 |
|
---|
| 67 | wxButton * modelButton = new wxButton( this, MAIN_MODEL, "Select Model");
|
---|
| 68 | modelButton->SetFont(*font10bold);
|
---|
| 69 | modelBoxSizer->Add(modelButton,1,wxALL|wxEXPAND,5);
|
---|
| 70 |
|
---|
| 71 | modelText = new wxStaticText(this, wxID_ANY, "Load a Model...");
|
---|
| 72 | modelText->SetFont(*font10);
|
---|
| 73 | modelBoxSizer->Add(modelText,1,wxALL|wxEXPAND,5);
|
---|
| 74 |
|
---|
| 75 | //Image
|
---|
| 76 | wxStaticBoxSizer * imageBoxSizer = new wxStaticBoxSizer(wxVERTICAL,this);
|
---|
| 77 | gridSizer->Add(imageBoxSizer,2,wxALL|wxEXPAND,5);
|
---|
| 78 |
|
---|
| 79 | wxButton * imageButton = new wxButton( this, MAIN_IMAGE, "Select Image");
|
---|
| 80 | imageButton->SetFont(*font10bold);
|
---|
| 81 | imageBoxSizer->Add(imageButton,1,wxALL|wxEXPAND,5);
|
---|
| 82 |
|
---|
| 83 | imageText = new wxStaticText(this, wxID_ANY, "Save to...");
|
---|
| 84 | imageText->SetFont(*font10);
|
---|
| 85 | imageBoxSizer->Add(imageText,1,wxALL|wxEXPAND,5);
|
---|
| 86 |
|
---|
| 87 | //Group
|
---|
| 88 | wxGridSizer * groupSizer = new wxGridSizer(1,2,5,5);
|
---|
| 89 | gridSizer->Add(groupSizer,1,wxALL|wxEXPAND,2);
|
---|
| 90 |
|
---|
| 91 | //Resolution
|
---|
| 92 | wxStaticBoxSizer * resBoxSizer = new wxStaticBoxSizer(wxVERTICAL,this);
|
---|
| 93 | groupSizer->Add(resBoxSizer,1,wxALL|wxEXPAND);
|
---|
| 94 |
|
---|
| 95 | wxStaticText * resLabel = new wxStaticText(this, wxID_ANY, "Resolution");
|
---|
| 96 | resLabel->SetFont(*font10bold);
|
---|
| 97 | resBoxSizer->Add(resLabel,1,wxALL|wxEXPAND,2);
|
---|
| 98 |
|
---|
| 99 | wxComboBox * combo_res = new wxComboBox(this, MAIN_RES, "", wxDefaultPosition, wxDefaultSize, 3, choices_res_text, wxCB_READONLY);
|
---|
| 100 | combo_res->Select(0);
|
---|
| 101 | res = choices_res[0];
|
---|
| 102 | resBoxSizer->Add(combo_res,1,wxALL|wxEXPAND,2);
|
---|
| 103 |
|
---|
| 104 | //Start
|
---|
| 105 | startButton = new wxButton( this, MAIN_START, "Start",wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
---|
| 106 | startButton->SetFont(*font10bold);
|
---|
| 107 | startButton->Enable(false);
|
---|
| 108 | mainSizer->Add(startButton,0,wxALL|wxCENTER,5);
|
---|
| 109 |
|
---|
| 110 | //mainSizer
|
---|
| 111 | SetSizer(mainSizer);
|
---|
| 112 | mainSizer->SetSizeHints(this);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | //Destructor
|
---|
| 116 | MyFrame::~MyFrame()
|
---|
| 117 | {
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | void MyFrame::CheckStart()
|
---|
| 121 | {
|
---|
| 122 |
|
---|
| 123 | if ( ( *modelString != "" )
|
---|
| 124 | && ( *imageString != "" )
|
---|
| 125 | && ( res != 0))
|
---|
| 126 | {
|
---|
| 127 | //Toggle Button
|
---|
| 128 | startButton->Enable(true);
|
---|
| 129 | }
|
---|
| 130 | else
|
---|
| 131 | startButton->Enable(false);
|
---|
| 132 |
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | void MyFrame::OnSelectModel(wxCommandEvent & event)
|
---|
| 137 | {
|
---|
| 138 | const wxChar * FILETYPES = wxT
|
---|
| 139 | (
|
---|
| 140 | //"Ogre Mesh files|*.mesh|"
|
---|
| 141 | "Ogre XML files|*.xml|"
|
---|
| 142 | "All files|*.*"
|
---|
| 143 | );
|
---|
| 144 |
|
---|
| 145 | wxFileDialog * openFileDialog = new wxFileDialog(this,"Select Mesh",
|
---|
| 146 | /*Default folder*/"",/*Default Filename*/"",
|
---|
| 147 | FILETYPES,wxOPEN|wxFILE_MUST_EXIST,wxDefaultPosition);
|
---|
| 148 |
|
---|
| 149 | if (openFileDialog->ShowModal() == wxID_OK )
|
---|
| 150 | {
|
---|
| 151 | modelString = new wxString("");
|
---|
| 152 | modelString->Append(openFileDialog->GetPath());
|
---|
| 153 | modelText->SetLabel(openFileDialog->GetFilename());
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | CheckStart();
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | //Image saving location
|
---|
| 160 | void MyFrame::OnSelectImage(wxCommandEvent & event)
|
---|
| 161 | {
|
---|
| 162 | const wxChar * FILETYPES = wxT
|
---|
| 163 | (
|
---|
| 164 | "Bitmap|*.bmp|"
|
---|
| 165 | "All files|*.*"
|
---|
| 166 | );
|
---|
| 167 |
|
---|
| 168 | wxFileDialog * saveFileDialog = new wxFileDialog(this,"Select where to Save Image",
|
---|
| 169 | /*Default folder*/"",/*Default Filename*/"",
|
---|
| 170 | FILETYPES,wxSAVE,wxDefaultPosition);
|
---|
| 171 |
|
---|
| 172 | if (saveFileDialog->ShowModal() == wxID_OK )
|
---|
| 173 | {
|
---|
| 174 | imageString = new wxString("");
|
---|
| 175 | imageString->Append(saveFileDialog->GetPath());
|
---|
| 176 | imageText->SetLabel(saveFileDialog->GetFilename());
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | CheckStart();
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | void MyFrame::OnStart(wxCommandEvent & event)
|
---|
| 183 | {
|
---|
| 184 | float *ObscuranceMap;
|
---|
| 185 | int i, j;
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 | CMesh g_pMesh;
|
---|
| 189 |
|
---|
| 190 | //if image.bmp exists...
|
---|
| 191 | if ( wxFile::Exists(imageString->GetData()) )
|
---|
| 192 | {
|
---|
| 193 | int response = ::wxMessageBox("Image already exists?\nOverwrite?", "Attention!", wxYES_NO);
|
---|
| 194 |
|
---|
| 195 | if ( response == wxNO )
|
---|
| 196 | return;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 | ObscuranceMap = new float[res * res * 4];
|
---|
| 201 |
|
---|
| 202 | char *name = new char[modelString->Length() + 100], character;
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | for (i = 0, j = 0; i < modelString->Length(); i++, j++)
|
---|
| 206 | {
|
---|
| 207 | character = modelString->GetChar(i);
|
---|
| 208 |
|
---|
| 209 | if (character == '\\')
|
---|
| 210 | {
|
---|
| 211 | name[j] = modelString->GetChar(i);
|
---|
| 212 | name[j + 1] = modelString->GetChar(i);
|
---|
| 213 | j++;
|
---|
| 214 | }
|
---|
| 215 | else
|
---|
| 216 | name[j] = modelString->GetChar(i);
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | name[j] = '\0';
|
---|
| 220 |
|
---|
| 221 | //start Obscurances generation
|
---|
| 222 | vcObscurerGenerateImage(g_pMesh, name, int(res/256), &res, &res, &ObscuranceMap);
|
---|
| 223 |
|
---|
| 224 | typedef unsigned char uchar;
|
---|
| 225 | uchar *bmp = new unsigned char[res * res * 3];
|
---|
| 226 | float r_float;
|
---|
| 227 |
|
---|
[953] | 228 | for (i = 0, j = 0; i < (res * res * 4); i += 4, j += 3)
|
---|
[930] | 229 | {
|
---|
| 230 | r_float = ObscuranceMap[i] * 255;
|
---|
| 231 | bmp[j] = uchar(r_float);
|
---|
| 232 | r_float = ObscuranceMap[i+1] * 255;
|
---|
| 233 | bmp[j + 1] = uchar(r_float);
|
---|
| 234 | r_float = ObscuranceMap[i+2] * 255;
|
---|
| 235 | bmp[j + 2] = uchar(r_float);
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 | wxImage img(res,res);
|
---|
| 240 |
|
---|
| 241 | img.SetData(bmp,res,res);
|
---|
| 242 |
|
---|
| 243 | img.SaveFile(*imageString, wxBITMAP_TYPE_BMP);
|
---|
| 244 |
|
---|
| 245 | //freeing memory
|
---|
| 246 | g_pMesh.FreeMem();
|
---|
| 247 | delete name;
|
---|
| 248 |
|
---|
| 249 |
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | //Seleccionar Resolucio
|
---|
| 253 | void MyFrame::OnSelectResolution(wxCommandEvent & event)
|
---|
| 254 | {
|
---|
| 255 | int id = event.GetSelection();
|
---|
| 256 | res = choices_res[id];
|
---|
| 257 | CheckStart();
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | //Seleccionar Qualitat
|
---|
| 261 | /*->void MyFrame::OnSelectQuality(wxCommandEvent & event)
|
---|
| 262 | {
|
---|
| 263 | int id = event.GetSelection();
|
---|
| 264 | qua = choices_qua[id];
|
---|
| 265 | ComprovaStart();
|
---|
| 266 | }*/
|
---|
| 267 |
|
---|
| 268 |
|
---|