⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ebm_gui.cpp

📁 Gaussian Mixture Algorithm
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		for(int i = 0; i < dim0; i++){			int pointvalue;			double value_double;			float value_float;			intg value_intg;			int value_ubyte;			// here we calculate the position of the point			switch((int)type){				case 0:					value_double = static_cast<Idx<double>*>(matrix)->get(i);					if(value_double >= 0) pointvalue = (int)floor(30 - (vmax - value_double)/(vmax-vmin)*30);					else pointvalue = (int) floor((value_double - vmin)/(vmax-vmin)*30);					if(value_double > vmax) pointvalue = 30;					if(value_double < vmin) pointvalue = 0;					break;				case 1:					value_float = static_cast<Idx<float>*>(matrix)->get(i);					if(value_float >= 0) pointvalue = (int)floor(30 - (vmax - value_float)/(vmax-vmin)*30);					else pointvalue = (int) floor((value_float - vmin)/(vmax-vmin)*30);					if(value_float > vmax) pointvalue = 30;					if(value_float < vmin) pointvalue = 0;					break;				case 2:					value_intg = static_cast<Idx<intg>*>(matrix)->get(i);					if(value_intg >= 0) pointvalue = (int)floor(30 - (vmax - value_intg)/(vmax-vmin)*30);					else pointvalue = (int) floor((value_intg - vmin)/(vmax-vmin)*30);					if(value_intg > vmax) pointvalue = 30;					if(value_intg < vmin) pointvalue = 0;					break;				case 3:					value_ubyte = (int)static_cast<Idx<ubyte>*>(matrix)->get(i);					if(value_ubyte >= 0) pointvalue = (int)floor(30 - (vmax - value_ubyte)/(vmax-vmin)*30);					else pointvalue = (int) floor((value_intg - vmin)/(vmax-vmin)*30);					if(value_ubyte > vmax) pointvalue = 30;					if(value_ubyte < vmin) pointvalue = 0;					break;			}			// If the zoom is higher than 2, we make bigger pixels...			for(int j= -floor(zoom/2); j <= floor(zoom/2); j++){				for(int k= -floor(zoom/2); k <= floor(zoom/2); k++){					if((i*zoom+j >= 0) && ((i*zoom+j) <= dim0*zoom -1) && ((pointvalue*zoom+k) >= 0) && ((pointvalue*zoom+k) <= 30*zoom - 1)){						painter.drawPoint(i*zoom+j, pointvalue*zoom+k);					}				}			}		}		// then we put it into the container and resize everything accordingly		container->setPixmap(displaymap);		container->adjustSize();		container->setMinimumSize(dim0*zoom+5, 30*zoom +2);		QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);		container->setSizePolicy(policy);		container->setFrameShape(QFrame::Box);	}	// else, if idx3_as_rgb is false,  we display the layer as a grayscale matrix	else if(( idx1_as_array) || (order == 2) || ((order >= 3) && !idx3_as_rgb)){		if(idx1_as_array) dim1 = 1;		// the dimensions x and y in the picture are swapped to match the i and j dimensions in Idxs		Idx<ubyte>* mycopy = (order < 3)? new Idx<ubyte>(dim0, dim1) : new Idx<ubyte>(dim1, dim2);		if(type == DOUBLE){			Idx<double> test1(mycopy->dim(0), mycopy->dim(1));			if(order==2) idx_copy(*(static_cast<Idx<double>*>(matrix)), test1);			else {				Idx<double> bla = static_cast<Idx<double>*>(matrix)->select(0,indexofLayer);				idx_copy( bla, test1);			}			idx_dotc( test1, (double)(255/(vmax-vmin)), test1);			idx_addc( test1, (double)(-vmin*255/(vmax-vmin)), test1);			idx_copy( test1, *mycopy);		}		if(type == FLOAT){			Idx<float> test2(mycopy->dim(0), mycopy->dim(1));			if(order==2) idx_copy(*(static_cast<Idx<float>*>(matrix)), test2);			else {				Idx<float> bla = static_cast<Idx<float>*>(matrix)->select(0,indexofLayer);				idx_copy( bla, test2);			}			idx_dotc( test2, (float)(255/(vmax-vmin)), test2);			idx_addc( test2, (float)(-vmin*255/(vmax-vmin)), test2);			idx_copy( test2, *mycopy);		}		if(type == INTG){			if(order==2) idx_copy(*(static_cast<Idx<intg>*>(matrix)), *mycopy);			else {				Idx<intg> test3 = static_cast<Idx<intg>*>(matrix)->select(0,indexofLayer);				idx_copy(test3, *mycopy);			}			idx_dotc(*mycopy, (ubyte)(255/(vmax-vmin)), *mycopy);			idx_addc(*mycopy, (ubyte)(-vmin*255/(vmax-vmin)), *mycopy);		}		if(type == UBYTE){			if(order==2) idx_copy(*(static_cast<Idx<ubyte>*>(matrix)), *mycopy);			else {				Idx<ubyte> test4 = static_cast<Idx<ubyte>*>(matrix)->select(2,indexofLayer);				idx_copy(test4, *mycopy);			}			idx_dotc(*mycopy, (ubyte)(255/(vmax-vmin)), *mycopy);			idx_addc(*mycopy, (ubyte)(-vmin*255/(vmax-vmin)), *mycopy);		}	    QPixmap* mydisplay = new QPixmap(mycopy->dim(1), mycopy->dim(0));	    QPainter* painter = new QPainter(mydisplay);		QImage* image;		QVector<QRgb> table(256);		for (int i = 0; i < 256; i++){		    table[i] = qRgb(i, i, i);		}		image = new QImage((uchar*)mycopy->idx_ptr(), mycopy->dim(1), mycopy->dim(0), mycopy->dim(1) * sizeof(unsigned char), QImage::Format_Indexed8);		image->setColorTable(table);		//image = new QImage(image->scaled(dim1*zoom, dim0*zoom));		painter->drawImage(0, 0, *image);	    //container->setGeometry(QRect(0,0, dim1*zoom, dim0*zoom));	    container->setPixmap(*mydisplay);		container->setMinimumSize(mycopy->dim(1)*zoom + 2, mycopy->dim(0)*zoom + 2);		QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);		container->setSizePolicy(policy);		container->setFrameShape(QFrame::Box);	}	// if the order of the Idx is equal or more than 3 and the Idx3_as_rgb is true, we group the layers 3 by 3 and make it RGB matrices	else{		Idx<ubyte>myimage(dim1, dim2, 4);		Idx<ubyte> mypartimage = myimage.narrow(2,3,0);		if(type == DOUBLE){			Idx<double> test1 = static_cast<Idx<double>*>(matrix)->narrow(0,3,indexofLayer);			{ idx_aloop2(i, test1, double, o, mypartimage, ubyte){				*o = (ubyte)((*i - vmin)/(vmax-vmin) * 255);				if(*o >= 255) *o = 255;				if(*o <= 0) *o = 0;				}			}		}		if(type == FLOAT){			Idx<float> test2 = static_cast<Idx<float>*>(matrix)->narrow(0,3,indexofLayer);			{ idx_aloop2(i, test2, float, o, mypartimage, ubyte){				*o = (ubyte)((*i - vmin)/(vmax-vmin) * 255);				if(*o >= 255) *o = 255;				if(*o <= 0) *o = 0;				}			}		}		if(type == INTG){			Idx<intg> test3 = static_cast<Idx<intg>*>(matrix)->narrow(2,3,indexofLayer);			idx_copy(test3, mypartimage);			idx_dotc(myimage, (ubyte)(255/(vmax-vmin)), myimage);			idx_addc(myimage, (ubyte)(-vmin*255/(vmax-vmin)), myimage);		}		if(type == UBYTE){			Idx<ubyte> test4 = static_cast<Idx<ubyte>*>(matrix)->narrow(2,2,indexofLayer);			idx_copy(test4, mypartimage);			idx_dotc(myimage, (ubyte)(255/(vmax-vmin)), myimage);			idx_addc(myimage, (ubyte)(-vmin*255/(vmax-vmin)), myimage);		}	    QPixmap* mydisplay = new QPixmap(dim2, dim1);	    QPainter* painter = new QPainter(mydisplay);		QImage* image;		image = new QImage((uchar*)myimage.idx_ptr(), dim2, dim1, dim2 * sizeof(unsigned char), QImage::Format_RGB32);		image = new QImage(image->rgbSwapped());		painter->drawImage( 0, 0, *image);	    container->setGeometry(QRect(0,0, dim2*zoom, dim1*zoom));	    container->setPixmap(*mydisplay);		container->setMinimumSize(dim2*zoom + 2, dim1*zoom + 2);		QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);		container->setSizePolicy(policy);		container->setFrameShape(QFrame::Box);	}}void idx_displayGui::displayAll(void* idx, idx_type type, idx_plotdata* plotdata){	// if idx3_as_RGB is false, one container will display a unique layer	if(!(plotdata->idx3_as_RGB)){		int Noflayer = display.size();		displayer->setMinimumWidth(30);		// create the images for each layer of the idx		for(int i =0; i < Noflayer; i++){			displaymatrixlayer(display[i], idx, type, i, plotdata->norm ? plotdata->min_norm : plotdata->min, plotdata->norm ? plotdata->max_norm : plotdata->max, plotdata->zoom, plotdata->idx1_as_array, false);			displayer->setMinimumWidth(displayer->minimumWidth() + display[i]->minimumWidth() + 2*(plotdata->zoom+1));			display[i]->setVisible(true);		}		// sets the size of the various containers for X		displayer->setMinimumHeight(display[0]->minimumHeight()+10);		displayer->setMaximumSize(displayer->minimumSize());		scroll->setMinimumHeight( displayer->minimumHeight() + 25);		scroll->setMinimumWidth(min(displayer->minimumWidth() + 25, 450));		if(Noflayer == 1) scroll->setFixedWidth(min(displayer->minimumWidth() + 25, 800));		scroll->setVisible(plotdata->visible);		adjustSize();	}	else {		// if idx3_as_RGB is true, only 1/3 of the containers will be used : we have to check that there still are 3 layers to display as RGB or display the 1 or 2 remaining in grayscale, then		// disable the remaining containers		int Noflayer = display.size();		displayer->setMinimumWidth(30);		int currentplot = 0, i=0;		while(i < Noflayer){			// if enough layers in X to make a RGB matrix			if( i + 2 < Noflayer){				displaymatrixlayer(display[currentplot], idx, type, i, plotdata->norm ? plotdata->min_norm : plotdata->min, plotdata->norm ? plotdata->max_norm : plotdata->max, plotdata->zoom, false, true);				displayer->setMinimumWidth(displayer->minimumWidth() + display[currentplot]->minimumWidth()+ 2*(plotdata->zoom+1));				currentplot++;				i = i+3;			}			else{				// if not enough layers in X, make grayscale matrix				displaymatrixlayer(display[currentplot], idx, type, i, plotdata->norm ? plotdata->min_norm : plotdata->min, plotdata->norm ? plotdata->max_norm : plotdata->max, plotdata->zoom, false, false);				displayer->setMinimumWidth(displayer->minimumWidth() + display[currentplot]->minimumWidth()+ 2*(plotdata->zoom+1));				currentplot++;				i++;			}		}		// then disable the remaining containers for X		for(int j = currentplot; j < Noflayer; j++) {			display[j]->setVisible(false);		}		// finally, resize the various containers		displayer->setMinimumHeight(display[0]->minimumHeight()+10);		displayer->setMaximumSize(displayer->minimumSize());		scroll->setMinimumHeight(displayer->minimumHeight() + 25);		//scroll->setMaximumWidth(displayer->minimumWidth() + 25);		scroll->setVisible(plotdata->visible);	}}////////////////////////////////////////////////////////////////////////////// idx gui related function///////////////////////////////////////////////////////////////////////////Idx_Gui::Idx_Gui(void* idxarg, idx_type argtype, const char* title, QWidget *parent, QMutex* mutex):	ebbox(parent, title, NULL, NULL, mutex){	idx = idxarg;	type = argtype;	if(idx == NULL) {		ylerror("Idx Null");		return;	}	if(static_cast<Idx<double>*>(idx)->order() == 0) {		ylerror("Not defined for Idx0");		return;	}	initialize_data(&plotdata, &printdata, idx, type);	fromproperties = false;	properties = new idx_propgui(0, static_cast<Idx<double>*>(idx)->order());	visible = new idx_displayGui(0, ((static_cast<Idx<double>*>(idx)->order() > 2) && (static_cast<Idx<double>*>(idx)->dim(0) >1)) ? static_cast<Idx<double>*>(idx)->dim(0) : 1, title);	ui.vboxLayoutcont->addWidget(visible);	dynamic_cast<idx_displayGui*>(visible)->displayAll(idx, type, &plotdata);	connect(dynamic_cast<idx_propgui*>(properties)->okbutton, SIGNAL( clicked() ), this, SLOT(refreshdisplay() ) );}void Idx_Gui::openProperties(){	dynamic_cast<idx_propgui*>(properties)->set_data(&plotdata, &printdata);	fromproperties = true;	properties->setModal(true);	properties->show();}void Idx_Gui::refreshdisplay(){	refreshform();	if(fromproperties){		// if the display settings are sets from the properties dialog, we have to update it (contrary to the case where it is sets by keyboard shortcuts)		dynamic_cast<idx_propgui*>(properties)->get_data(&plotdata, &printdata);		fromproperties = false;	}	if(mutex != NULL) mutex->lock();	QString errors;	errors = checkproperties(errors);	int validate;	if(errors != NULL){		errors = "We have detected the following problems : \n" + errors + "\n";		errors = errors + "Do you still want to validate these properties ?";		validate = QMessageBox::warning(this, "Properties checking", errors, QMessageBox::Yes | QMessageBox::No);	} else validate = QMessageBox::Yes;	if(validate == QMessageBox::Yes){		dynamic_cast<idx_displayGui*>(visible)->displayAll(idx, type, &plotdata);		properties->close();		setFocus();		adjustSize();	}	if(mutex != NULL) mutex->unlock();}QString Idx_Gui::checkproperties(QString s){	// checks various possibilities for wrong or strange display settings	if((plotdata.max <= plotdata.min) && !(plotdata.norm) && plotdata.visible) s = s + "the max is inferior or equal to the min; ";	if((plotdata.min > plotdata.min_norm) && !(plotdata.norm) && plotdata.visible) s = s +  "the min is superior to the minimum of the idx; ";	if((plotdata.max < plotdata.max_norm) && !(plotdata.norm) && plotdata.visible) s = s +  "the max is inferior to the maximum of the idx; ";	return s;}void Idx_Gui::print(){	if(mutex != NULL) mutex->lock();	if(!(printdata.onfile)){		switch(type){			case 0:				if(printdata.pretty) { printf(" Idx : \n"); static_cast<Idx<double>*>(idx)->pretty(stdout);}				if(printdata.elems) { printf("elements : \n"); static_cast<Idx<double>*>(idx)->printElems();}				break;			case 1:				if(printdata.pretty) { printf(" Idx : \n"); static_cast<Idx<float>*>(idx)->pretty(stdout);}				if(printdata.elems) { printf("elements : \n"); static_cast<Idx<float>*>(idx)->printElems();}				break;			case 2:				if(printdata.pretty) { printf(" Idx : \n"); static_cast<Idx<intg>*>(idx)->pretty(stdout);}				if(printdata.elems) { printf("elements : \n"); static_cast<Idx<intg>*>(idx)->printElems();}				break;			case 3:				if(printdata.pretty) { printf(" Idx : \n"); static_cast<Idx<ubyte>*>(idx)->pretty(stdout);}				if(printdata.elems) { printf("elements : \n"); static_cast<Idx<ubyte>*>(idx)->printElems();}				break;		}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -