#ifndef TRUEEYES_H #define TRUEEYES_H #include #include #include "ui_trueeyes.h" #include "ui_LoadRawDialog.h" #include "ui_HistogramToolDialog.h" #include "GlobalValues.h" //dialog boxes #include "LoadRawDialog.h" #include "HistogramToolDialog.h" //rendering variables #include "GLWidget.h" extern GLWidget* gpRenderWindow; #define SLIDER_RESOLUTION 100000 class TrueEyes : public QMainWindow { Q_OBJECT public: TrueEyes(QWidget *parent = 0, Qt::WFlags flags = 0); ~TrueEyes(); void closeEvent(QCloseEvent *event); private: Ui::TrueEyesClass ui; bool refresh; void refreshCropSliders() { float disp_range = gpCropMax[0] - gpCropMin[0]; if(disp_range > 0) ui.sldX->setValue(gpCropMin[0]/(1.0 - disp_range)*SLIDER_RESOLUTION); disp_range = gpCropMax[1] - gpCropMin[1]; if(disp_range > 0) ui.sldY->setValue(gpCropMin[1]/(1.0 - disp_range)*SLIDER_RESOLUTION); disp_range = gpCropMax[2] - gpCropMin[2]; if(disp_range > 0) ui.sldZ->setValue(gpCropMin[2]/(1.0 - disp_range)*SLIDER_RESOLUTION); } void refreshCropSpinners() { ui.spinCropMinX->setValue((double)gpCropMin[0]); ui.spinCropMinY->setValue((double)gpCropMin[1]); ui.spinCropMinZ->setValue((double)gpCropMin[2]); ui.spinCropMaxX->setValue((double)gpCropMax[0]); ui.spinCropMaxY->setValue((double)gpCropMax[1]); ui.spinCropMaxZ->setValue((double)gpCropMax[2]); } void refreshView() { refresh = true; //refresh global controls ui.spinStepSize->setValue((double)StepSize); ui.spinVolSizeX->setValue((double)gpVolSize[0]); ui.spinVolSizeY->setValue((double)gpVolSize[1]); ui.spinVolSizeZ->setValue((double)gpVolSize[2]); refreshCropSliders(); refreshCropSpinners(); //refresh the volume list int volumes = VolumeList.size(); ui.lstVolumes->clear(); ui.txtVolumeName->clear(); for(int v=0; vinsertItem(v, QString(VolumeList[v].Name.c_str())); //refresh the shader list int shaders = ShaderList.size(); ui.lstShaders->clear(); ui.txtShaderName->clear(); for(int s=0; sinsertItem(s, QString(ShaderList[s].Name.c_str())); //refresh the texture list int textures = TextureList.size(); ui.lstTextures->clear(); ui.txtTextureName->clear(); for(int t=0; tinsertItem(t, QString(TextureList[t].Name.c_str())); //refresh the source list int sources = SourceList.size(); ui.lstSources->clear(); ui.txtSourceName->clear(); for(int s=0; sinsertItem(s, QString(SourceList[s].Name.c_str())); refresh = false; } public slots: /******MENU ITEMS***********/ void on_mnuLoadRawFile_activated() { //create and open a dialog box Ui::LoadRawDialogClass dialog_ui; LoadRawDialog dialog; //dialog_ui.setupUi(&dialog); dialog.exec(); refreshView(); } void on_mnuLoadImages_activated() { //create a multi-selection file dialog box QStringList files = QFileDialog::getOpenFileNames(this,tr("Load Shader"), QString(), tr("(*.jpg; *.bmp)")); if(!files.empty()) { int num_selected = files.count(); VolumeData newVolume; newVolume.FileType = VOLUME_FILE_IMAGES; for(int f=0; fupdateGL(); } void on_mnuLoadTexture_activated() { //create a file dialog box QString file =QFileDialog::getOpenFileName(this,tr("Load Shader"), QString(), tr("(*.*)")); if(!file.isEmpty()) { rtsFilename filename = string(file.toAscii()); TextureData newTexture; newTexture.Name = filename.getPrefix(); newTexture.Filename = filename; LoadTexture(newTexture); TextureList.push_back(newTexture); refreshView(); } } void on_mnuSaveProject_activated() { //load a file dialog and grab the selected file name QString filename =QFileDialog::getSaveFileName(this,tr("Load Shader"), QString(), tr("(*.tep)")); SaveProject(string(filename.toAscii())); } void on_mnuLoadProject_activated() { //load a file dialog and grab the selected file name QString filename =QFileDialog::getOpenFileName(this,tr("Load Shader"), QString(), tr("(*.tep)")); if(!filename.isEmpty()) LoadProject(string(filename.toAscii())); //select the latest shader SelectedShader = ShaderList.size()-1; AttachShaderVariables(); refreshView(); gpRenderWindow->updateGL(); } void on_mnuHistogramTool_activated() { //create and open a dialog box Ui::HistogramToolDialogClass dialog_ui; HistogramToolDialog dialog; //dialog_ui.setupUi(&dialog); dialog.exec(); } /******BUTTONS*************/ void on_btnReloadShader_clicked() { ReloadShaders(); gpRenderWindow->updateGL(); refreshView(); } void on_btnReloadTextures_clicked() { //reload all textures for(int t=0; tupdateGL(); refreshView(); } void on_btnAddSource_clicked() { //create a new source VolumeSource newSource; //use the provided source name newSource.Name = string(ui.txtSourceName->text().toAscii()); //set the source position to the current source position newSource.S = SourceList[SelectedSource].S; //add the source to the global list SourceList.push_back(newSource); refreshView(); } void on_btnRemoveVolume_clicked() { int toRemove = ui.lstVolumes->currentRow(); if(toRemove < 0 || toRemove >= VolumeList.size()) return; //clean the texture from the GPU VolumeList[toRemove].Texture.Clean(); //erase the texture structure VolumeList.erase(VolumeList.begin() + toRemove); refreshView(); gpRenderWindow->updateGL(); } void on_btnRemoveShader_clicked() { int toRemove = ui.lstShaders->currentRow(); if(toRemove < 0 || toRemove >= ShaderList.size()) return; //clean the texture from the GPU ShaderList[toRemove].glProgram.Clean(); //erase the texture structure ShaderList.erase(ShaderList.begin() + toRemove); SelectedShader = ShaderList.size() - 1; refreshView(); gpRenderWindow->updateGL(); } void on_btnRemoveSource_clicked() { int toRemove = ui.lstSources->currentRow(); if(toRemove < 0 || toRemove >= ShaderList.size()) return; //erase the texture structure SourceList.erase(SourceList.begin() + toRemove); SelectedSource = 0; refreshView(); gpRenderWindow->updateGL(); } /*******LIST ITEMS SELECTED******/ void on_lstVolumes_currentRowChanged(int s) { if(refresh) return; //add the volume name to the editable text box ui.txtVolumeName->setText(tr(VolumeList[s].Name.c_str())); AttachShaderVariables(); gpRenderWindow->updateGL(); } void on_txtVolumeName_returnPressed() { int i = ui.lstVolumes->currentRow(); //ui.lstVolumes->clear(); VolumeList[i].Name = string(ui.txtVolumeName->text().toAscii()); refreshView(); AttachShaderVariables(); gpRenderWindow->updateGL(); } void on_lstShaders_currentRowChanged(int s) { if(refresh) return; SelectedShader = s; AttachShaderVariables(); gpRenderWindow->updateGL(); } void on_lstTextures_currentRowChanged(int s) { if(refresh) return; //add the volume name to the editable text box ui.txtTextureName->setText(tr(TextureList[s].Name.c_str())); AttachShaderVariables(); gpRenderWindow->updateGL(); } void on_txtTextureName_returnPressed() { int i = ui.lstTextures->currentRow(); //ui.lstVolumes->clear(); TextureList[i].Name = string(ui.txtTextureName->text().toAscii()); refreshView(); AttachShaderVariables(); gpRenderWindow->updateGL(); } void on_lstSources_currentRowChanged(int s) { if(refresh) return; SelectedSource = s; if(ui.chkRenderFromSelected->isChecked()) RenderSource = SelectedSource; SetRenderSource(); gpRenderWindow->updateGL(); } /*******OTHER WIDGETS***********/ void on_spinStepSize_valueChanged(double d) { StepSize = (float)d; gpRenderWindow->updateGL(); } void on_spinVolSizeX_valueChanged(double d) { if(refresh) return; gpVolSize[0] = (float)d; gpRenderWindow->updateGL(); } void on_spinVolSizeY_valueChanged(double d) { if(refresh) return; gpVolSize[1] = (float)d; gpRenderWindow->updateGL(); } void on_spinVolSizeZ_valueChanged(double d) { if(refresh) return; gpVolSize[2] = (float)d; gpRenderWindow->updateGL(); } void on_spinCropMinX_valueChanged(double d) { if(refresh) return; gpCropMin[0] = (float)d; refreshCropSliders(); gpRenderWindow->updateGL(); } void on_spinCropMaxX_valueChanged(double d) { if(refresh) return; gpCropMax[0] = (float)d; refresh=true; refreshCropSliders(); refresh=false; gpRenderWindow->updateGL(); } void on_spinCropMinY_valueChanged(double d) { if(refresh) return; gpCropMin[1] = (float)d; refresh=true; refreshCropSliders(); refresh=false; gpRenderWindow->updateGL(); } void on_spinCropMaxY_valueChanged(double d) { if(refresh) return; gpCropMax[1] = (float)d; refresh=true; refreshCropSliders(); refresh=false; gpRenderWindow->updateGL(); } void on_spinCropMinZ_valueChanged(double d) { if(refresh) return; gpCropMin[2] = (float)d; refresh=true; refreshCropSliders(); refresh=false; gpRenderWindow->updateGL(); } void on_spinCropMaxZ_valueChanged(double d) { if(refresh) return; gpCropMax[2] = (float)d; refresh=true; refreshCropSliders(); refresh=false; gpRenderWindow->updateGL(); } void on_sldX_sliderMoved(int i) { if(refresh) return; float frac = (float)i/(float)SLIDER_RESOLUTION; float disp_range = gpCropMax[0] - gpCropMin[0]; float newMin = frac*(1.0 - disp_range); float newMax = newMin + disp_range; gpCropMin[0] = newMin; gpCropMax[0] = newMax; refresh = true; refreshCropSpinners(); refresh = false; gpRenderWindow->updateGL(); } void on_sldY_sliderMoved(int i) { if(refresh) return; float frac = (float)i/(float)SLIDER_RESOLUTION; float disp_range = gpCropMax[1] - gpCropMin[1]; float newMin = frac*(1.0 - disp_range); float newMax = newMin + disp_range; gpCropMin[1] = newMin; gpCropMax[1] = newMax; refresh = true; refreshCropSpinners(); refresh = false; gpRenderWindow->updateGL(); } void on_sldZ_sliderMoved(int i) { if(refresh) return; float frac = (float)i/(float)SLIDER_RESOLUTION; float disp_range = gpCropMax[2] - gpCropMin[2]; float newMin = frac*(1.0 - disp_range); float newMax = newMin + disp_range; gpCropMin[2] = newMin; gpCropMax[2] = newMax; refresh = true; refreshCropSpinners(); refresh = false; gpRenderWindow->updateGL(); } void on_chkRenderFromSelected_stateChanged(int s) { if(s) RenderSource = SelectedSource; else RenderSource = 0; SetRenderSource(); gpRenderWindow->updateGL(); } void on_chkRenderSources_stateChanged(int s) { if(s) RenderSources = true; else RenderSources = false; } void on_sldLightTheta_sliderMoved(int i) { double theta = (double)i/(double)SLIDER_RESOLUTION; double phi = (double)ui.sldLightPhi->value()/(double)SLIDER_RESOLUTION; //convert from [0 1] to radians theta = theta * 3.14159; phi = phi * 2 * 3.14159; //convert to the light position float Lx = cos(phi) * sin(theta); float Ly = sin(phi) * sin(theta); float Lz = cos(theta); //move the light SourceList[SelectedSource].S.setPosition(Lx, Ly, Lz); SourceList[SelectedSource].S.LookAt(0.0, 0.0, 0.0); gpRenderWindow->updateGL(); } void on_sldLightPhi_sliderMoved(int i) { double theta = (double)ui.sldLightTheta->value()/(double)SLIDER_RESOLUTION; double phi = (double)i/(double)SLIDER_RESOLUTION; //convert from [0 1] to radians theta = theta * 3.14159; phi = phi * 2 * 3.14159; //convert to the light position float Lx = cos(phi) * sin(theta); float Ly = sin(phi) * sin(theta); float Lz = cos(theta); //move the light SourceList[SelectedSource].S.setPosition(Lx, Ly, Lz); SourceList[SelectedSource].S.LookAt(0.0, 0.0, 0.0); gpRenderWindow->updateGL(); } }; #endif // TRUEEYES_H