Exemplo n.º 1
0
void CCropDialog::ProcessError(QProcess::ProcessError Error)
{
	if(Error == QProcess::FailedToStart)
	{
		PrintToOutput(tr("Conversion program not found"));
		//ui.convertButton->setEnabled(true);
	}
	m_bStartCropping = false;
	m_bProcessFinished = true;
}
Exemplo n.º 2
0
void CCropDialog::ProcessFinished(int nExitCode, QProcess::ExitStatus ExitStatus)
{
	if(ExitStatus == QProcess::CrashExit)
	{
		PrintToOutput(tr("Conversion program crashed."));
		m_bStartCropping = false;
	}
	else if(nExitCode != 0)
	{
		PrintToOutput(tr("Conversion failed."));
		m_bStartCropping = false;
	}
	else
	{
		// success to create
		PrintToOutput(tr("OK..."));
	}
	//ui.convertButton->setEnabled(true);
	m_bProcessFinished = true;
}
Exemplo n.º 3
0
void CCropDialog::on_pushButtonCrop_clicked()
{
	/* *************************
	m_pCropThread = new CCropThread(this);
	m_pCropThread->start();
	**************************** */

	QString strTemplateFilename(tr("%1/%2")
								.arg(ui.lineEditSourceFolder->text())
								.arg(sTEMPLATE_IMAGE_FILENAME));
	if(QFile::exists(strTemplateFilename) != true)
	{
		QMessageBox::critical(this, tr("Missing the template image file"), 
							tr("%1 is necessary to crop the image stacks.")
							.arg(sTEMPLATE_IMAGE_FILENAME));
		return;
	}
	
	// make sub folders for cropped data
	QString strZoomOutFolder, strColumnFolder;
	QDir Dir;
	
	m_bStartCropping = true;
	ui.pushButtonCrop->setEnabled(false);
	ui.pushButtonPauseResume->setEnabled(true);
	ui.listWidgetOutput->clear();
	m_bProcessFinished = true;
	m_bPause = false;
	
	////////////////////////////////
	// ZO_1 is not a part of ZoomOutLevel, but needs to be made.
	for(quint32 i = 0, nZoomOutLevel = 1; 
		i < m_TissueBlock.m_nNumZoomLevel+1; i++, nZoomOutLevel *= 2)
	{
		strZoomOutFolder = ui.lineEditDestFolder->text() 
							+ "/" 
							+ QString(sZOOM_OUT_DIR_PREFIX"%1")
								.arg(nZoomOutLevel); 
		Dir.mkdir(strZoomOutFolder);
		PrintToOutput(strZoomOutFolder + " folder created.");

		for(quint32 j = 0; j < m_TissueBlock.m_nNumCol; j++)
		{
			strColumnFolder = strZoomOutFolder + "/" + QString("%1").arg(j);
			Dir.mkdir(strColumnFolder);
			PrintToOutput("\t" + strColumnFolder + " folder created.");
		}
	}

	// open list for source image files
	qint32 nOffset = (m_TissueBlock.m_nStartCol > m_TissueBlock.m_nEndCol) ?
					-1 : 1;
	//QString strSrcFile;
	QString strLine;
	quint32 nSrcStartCol = m_TissueBlock.m_nStartCol;
	
	/////////////////////
	// specify a task that processes only one column
	quint32 nColsToCrop = m_TissueBlock.m_nNumCol;
	quint32 iCol = 0;
	
	//if(m_nSrcCropCol != -1) // an image stack number is specified
	if(ui.comboBoxColumn->currentText() != "All")
	{
		int nSrcCropCol = ui.comboBoxColumn->currentText().toInt();
		iCol = qAbs((int)nSrcStartCol - nSrcCropCol);//(int)m_nSrcCropCol);
		nColsToCrop = iCol+1; // only one column
		nSrcStartCol = nSrcCropCol;//m_nSrcCropCol;
	}

	//for( i = 0; i < m_TissueBlock.m_nNumCol; i++, nSrcStartCol+=nOffset)
	for(; iCol < nColsToCrop; iCol++, nSrcStartCol+=nOffset)
	{
#if 0
		//////////////////////////////////////////////////////////////////////
		// src image crop area
		QString strCropFile(tr("%1/%2_crop_point.txt")
								.arg(ui.lineEditSourceFolder->text()) 
								.arg(nSrcStartCol));

		QFile fileCrop(strCropFile);
		if(!(fileCrop.open(QFile::ReadOnly | QFile::Text)))
		{
			PrintToOutput(tr("No %1 exists.").arg(strCropFile));
			continue; // ignore no folder exists
			//QMessageBox::critical(this, tr("File open error"), 
			//							tr("No %1 exists.").arg(strCropFile));
			//return;
		}
		QTextStream txtstrmCrop(&fileCrop);
		while(!txtstrmCrop.atEnd())
		{
			strLine = txtstrmCrop.readLine();
			if(strLine.isNull())
				break;
			m_TissueBlock.m_vCropStartX.append(strLine.toInt());
		};

		//////////////////////////////////////////////////////////////////////
		// src image crop area index
		QString strChunkPosFile(tr("%1/%2_chunk_pos.txt")
									.arg(ui.lineEditSourceFolder->text())
									.arg(nSrcStartCol));

		QFile fileChunkPos(strChunkPosFile);
		if(!fileChunkPos.open(QFile::ReadOnly | QFile::Text))
		{
			PrintToOutput(tr("No %1 exists.").arg(strChunkPosFile));
			continue; // ignore no folder exists
			//QMessageBox::critical(this, tr("File open error"), 
			//							tr("No %1 exists.").arg(strChunkPosFile));
			//return;
		}
		QTextStream txtstrmChunkPos(&fileChunkPos);
		while(!txtstrmChunkPos.atEnd())
		{
			strLine = txtstrmChunkPos.readLine();
			if(strLine.isNull())
				break;
			m_TissueBlock.m_vChunkPos.append(strLine.toDouble());
		}
#endif		

		QString strSubFolder(tr("%1/%2")
									.arg(ui.lineEditSourceFolder->text())
									.arg(nSrcStartCol));
		QDir dirDataFolder(strSubFolder);
	    
		QStringList slstFilters;
	    slstFilters << QString(tr("*%1").arg(m_Settings.m_strDestFileFormat));
	    dirDataFolder.setNameFilters(slstFilters);
		QStringList slstEntry = dirDataFolder.entryList();
		
		PrintToOutput(tr("Files: %1").arg(slstEntry.count()));
		
		if(slstEntry.count() > 0)
			ui.progressBarImage->setRange(0, slstEntry.count()-1);

		QString strDestImage, strOptions, strSrcImage, strArgs;
		//QStrinList strlstLine;
		qreal rZ;
		quint32 nImage;//, nStartImage;//, nIndexChunk = 0;
		//bool bFirst = true;
		
		//while(!txtstrmSrc.atEnd())
		for(int iImage = 0; iImage < slstEntry.count(); iImage++)
		{
			//QStringList slstImageFile = slstEntry.at(nImage).split(".");
			QString strImageFile = slstEntry.at(iImage);

			// src image filename
			//strLine = txtstrmSrc.readLine();
			//if(strLine.isNull())
			//	break;
			
			// get z coordinate value
			int nPosZ = strImageFile.indexOf('z', 0);//strLine.indexOf('z', 0);
			if(nPosZ == -1)
			{
				QMessageBox::critical(this, tr("Invalid src image filename"), 
									tr("%1 is an invalid src image filename.")
									.arg(strImageFile)); //.arg(strLine));
				m_bStartCropping = false;
				ui.pushButtonCrop->setEnabled(true);
				ui.pushButtonPauseResume->setEnabled(false);
				return;
			}
			rZ = strImageFile.mid(nPosZ+1, 6).toDouble();//strLine.mid(nPosZ+1, 6).toDouble();

			nImage = qRound((rZ - m_TissueBlock.m_rMinStartZ)\
							/m_TissueBlock.m_rThickness);
			//if(bFirst)
			//{
			//	bFirst = false;
			//	nStartImage = nImage;
			//}
#if 0			
			//if((nImage - nStartImage) == m_TissueBlock.m_vChunkPos[nIndexChunk])
			if(rZ == m_TissueBlock.m_vChunkPos[nIndexChunk])
				nIndexChunk++;
#endif
			// make src filename
			strSrcImage = QString(tr("%1/%2/%3")
									.arg(ui.lineEditSourceFolder->text())
									.arg(nSrcStartCol)
									.arg(strImageFile));//.arg(strLine));
			// make dest filename
			QString strZoomOutDir = m_Settings.m_strZoomOutDirPrefix + "1";
			//strDestImage = QString(tr("%1/%2/%3/%4%5")
			//							.arg(ui.lineEditDestFolder->text()) 
			//							.arg(strZoomOutDir)
			//							.arg(i)
			//							.arg(nImage)
			//							.arg(m_Settings.m_strDestFileFormat));
			strDestImage.sprintf("%s/%s/%d/%05d%s", 
										ui.lineEditDestFolder->text().toStdString().c_str(),
										strZoomOutDir.toStdString().c_str(),
										iCol, // jrkwon: %05d
										nImage,
										m_Settings.m_strDestFileFormat.toStdString().c_str());
#if 0			
			strOptions = QString(tr("%1x%2+%3+%4")
							.arg(m_TissueBlock.m_nWidth)
							.arg(m_TissueBlock.m_nLength)
							.arg(m_TissueBlock.m_vCropStartX[nIndexChunk])
							.arg(0));
			strArgs = QString(tr("%1 -crop %2 %3")
							.arg(strSrcImage)
							.arg(strOptions)
							.arg(strDestImage));
			PrintToOutput(strArgs);

			QStringList strlstArgs;
			strlstArgs << strSrcImage << tr("-crop") << strOptions << strDestImage;

			QString strImageMagickConvert;
			strImageMagickConvert = QString(tr("%1%2%3%4")
										 .arg(m_Settings.m_strProjectDir)
										 .arg(m_Settings.m_strToolkit)
										 .arg(m_Settings.m_strImageMagick)
										 .arg("/convert"));
#endif
			ui.progressBarColumn->setValue(iCol);
			ui.progressBarImage->setValue(iImage);
#if 0
			while(m_bProcessFinished == false || m_bPause)
			{
				QCoreApplication::processEvents();				
			}
			m_Process.start(strImageMagickConvert, strlstArgs);
			m_bProcessFinished = false;
			//PrintToOutput(strImageMagickConvert);

			QCoreApplication::processEvents();
#endif			
			// see if there already is a dest file, and do this only no dest file exists
			if(QFile::exists(strDestImage) == false)
			{
				quint32 nStartX;
				if(GetCropX(strSrcImage, nStartX))
				{
					//DoCrop(m_TissueBlock.m_vCropStartX[nIndexChunk], 0, 
					DoCrop(nStartX, 0, 
							m_TissueBlock.m_nWidth, m_TissueBlock.m_nLength,
							strSrcImage, strDestImage);
					QString strMsg(tr("CropX: %1, Src: %2, Dest: %3")
									.arg(nStartX).arg(strSrcImage).arg(strDestImage));
					PrintToOutput(strMsg);
				}
			}
			
			if(m_bStartCropping != true)
			{
				ui.pushButtonCrop->setEnabled(true);
				ui.pushButtonPauseResume->setEnabled(false);
				ui.progressBarColumn->setValue(0);
				ui.progressBarImage->setValue(0);
				return;
			}
		}
	}
	ui.pushButtonCrop->setEnabled(true);
	ui.pushButtonPauseResume->setEnabled(false);
}
Exemplo n.º 4
0
void CCropDialog::UpdateOutput()
{
	QByteArray baNewData = m_Process.readAllStandardError();
	PrintToOutput(QString::fromLocal8Bit(baNewData));
}
Exemplo n.º 5
0
/*************************************************************************
 * Parallel Arrays
 * -----------------------------------------------------------------------
 * This program will receive as input the nam of an input file and an
 * output file. It will the rean in a list of names, id #'s, and balances
 * form the input file.This program then will prompt the user for a name
 * to search for, when it finds the name it will output to a file the
 * person's id #, name, and balance.The program will prompt for another
 * name until the word "done" is entered.
 *
 * Inputs :
 * 	inFileName   -	It will store the name of the file the program will
 * 					read from
 * 	outFileName  -  It will store the name of the file the program will
 * 					output to
 * 	searchItem	 -	It will store the item name the user wants to search
 * Outputs :
 * 	It will output all the information the user wants to know from the
 * 	file read
 ************************************************************************/
int main()
{
	//Declare the Input file in console
	ifstream inFile;
	ofstream outFile;

	string inFileName;	 //Variable used to store the User's input file
	string outFileName;  //Variable used to store the user's output file

	const int ARR_SIZE = 10;   // CALC      - The number of items in an
							   //			   array
	string namesAr[ARR_SIZE];  // CALC & OUT - Store names in the array
	int idsAr[ARR_SIZE];	   // CALC & OUT - Store id #'s
	float balanceAr[ARR_SIZE]; // CALC & OUT - Store the balance of the
							   //	           student
	string searchItem;		   // IN & CALC  - Stores the name the user
							   // 			   wants to search
 	int foundAt;			   // CALC       - Store the index of the item
 							   //              found

	//Declare the Input file in console
	cout << left << setw(42);
	cout << "What input file would you like to use?: ";
	getline(cin, inFileName);
	inFile.open(inFileName.c_str());

	//Declare the Output File in console
	cout << setw(42);
	cout << "What output file would you like to use?:";
	getline(cin, outFileName);
	outFile.open(outFileName.c_str());

	PrintHeader(outFile);

	ReadInputs ( namesAr, idsAr, balanceAr, ARR_SIZE, inFile);

	//The heading of the output File
		outFile << left;
		outFile << setw(9)  << "ID #";
		outFile << setw(25) <<"NAME"  << "BALANCE DUE";
		outFile << setw(10) << "\n----"  ;
		outFile << setw(25) << "--------------------";
		outFile << "-----------";

	//Asking user to search for a name until "done" is entered
	cout << setw(52) << "\nWho do you want to search for(enter done to exit):";
	getline(cin, searchItem);

	//While-loop will stop when user enters "done"
	while(searchItem != "done")
	{
		 foundAt= SearchName(namesAr, ARR_SIZE, searchItem);

		 PrintToOutput( namesAr, idsAr, balanceAr, ARR_SIZE, foundAt,
				 	 	outFile);

		 cout << setw(52) << "\nWho do you want to search for(enter "
				             "done to exit):";
		 getline(cin, searchItem);
	}

	cout <<"\nThank you for using my program.";

	// Close files when the program is done
	inFile.close();
	outFile.close();
	return 0;
}