trueeyes.h 12.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
#ifndef TRUEEYES_H
#define TRUEEYES_H

#include <GL/glew.h>

#include <QtGui/QMainWindow>
#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; v<volumes; v++)
			ui.lstVolumes->insertItem(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; s<shaders; s++)
			ui.lstShaders->insertItem(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; t<textures; t++)
			ui.lstTextures->insertItem(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; s<sources; s++)
			ui.lstSources->insertItem(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; f<num_selected; f++)
			{
				rtsFilename filename = string(files.value(f).toAscii());
				newVolume.Filenames.push_back(filename);
			}
			newVolume.Name = newVolume.Filenames[0].getPrefix();
			LoadImages(newVolume);
			refreshView();
		}

	}
	void on_mnuLoadShader_activated()
	{
		//load a file dialog and grab the selected file name
		QString filename =QFileDialog::getOpenFileName(this,tr("Load Shader"), QString(), tr("(*.glsl)"));
		//if a file was selected, load the shader
		if(!filename.isEmpty())
			CreateShader(string(filename.toAscii()));
		refreshView();
		gpRenderWindow->updateGL();
	}
	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; t<TextureList.size(); t++){
			TextureList[t].Texture.Clean();
			LoadTexture(TextureList[t]);
			
		}
		gpRenderWindow->updateGL();
		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