bool FibpProcess::initConnectionServer(const ProcessOptions& po)
{
    const BrokerAgentConfig& baConfig = FibpConfig::get()->getBrokerAgentConfig();
    std::size_t threadPoolSize = baConfig.threadNum_;
    bool enableTest = baConfig.enableTest_;
    unsigned int port = baConfig.port_;

    boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(),port);

    // init Router
    driverRouter_.reset(new ::izenelib::driver::Router);

    initializeDriverRouter(*driverRouter_, enableTest);

    boost::shared_ptr<FiberDriverConnectionFactory> factory(
        new FiberDriverConnectionFactory(driverRouter_)
    );

    driverServer_.reset(
        new FiberDriverServerV2(endpoint, factory, threadPoolSize)
    );

    boost::asio::ip::tcp::endpoint http_endpoint(boost::asio::ip::tcp::v4(), port + 1);
    boost::shared_ptr<HttpConnectionFactory> http_factory(
        new HttpConnectionFactory(driverRouter_));
    httpServer_.reset(new FiberHttpServerV2(http_endpoint, http_factory, threadPoolSize));

    std::string dns_servers;
    dns_servers = po.getRegistryAddr();
    if (dns_servers.empty())
    {
        dns_servers = FibpConfig::get()->distributedUtilConfig_.dns_config_.servers_;
    }
    std::string report_addr = po.getReportAddr();
    std::size_t port_pos = report_addr.find(":");
    if (port_pos == std::string::npos)
    {
        LOG(ERROR) << "The report address is wrong, should be ip:port. " << report_addr;
        return false;
    }
    std::string report_ip = report_addr.substr(0, port_pos);
    std::string report_port = report_addr.substr(port_pos + 1);
    FibpForwardManager::get()->init(dns_servers,
        FibpConfig::get()->distributedCommonConfig_.localHost_,
        port, report_ip, report_port, threadPoolSize);

    rpcServer_.reset(new FibpRpcServer(
            port + 2, threadPoolSize));
    addExitHook(boost::bind(&FibpProcess::stopConnectionServer, this));

    return true;
}
Example #2
0
void GpsimProcessor::compileMicrobe( const QString &filename, QObject *receiver, const char * successMember, const char * failMember )
{
	ProcessOptions o;
	o.b_addToProject = false;
	o.setTargetFile( QString(filename).replace(".microbe",".hex") );
	o.setInputFiles(filename);
	o.setMethod( ProcessOptions::Method::Forget );
	o.setProcessPath( ProcessOptions::ProcessPath::Microbe_Program );
	ProcessChain * pc = new ProcessChain(o);
	if (receiver)
	{
		if (successMember)
			connect( pc, SIGNAL(successful()), receiver, successMember );
		if (failMember)
			connect( pc, SIGNAL(failed()), receiver, failMember );
	}
}
Example #3
0
void FlowCode::processInput( ProcessOptions options )
{
	m_processOptions = options;
	
	if ( !options.p_flowCodeDocument )
	{
		options.p_flowCodeDocument = new FlowCodeDocument( QString::null, 0l );
		options.p_flowCodeDocument->openURL( options.inputFiles().first() );
		
		connect( this, SIGNAL(processSucceeded( Language *)), options.p_flowCodeDocument, SLOT(deleteLater()) );
		connect( this, SIGNAL(processFailed( Language *)), options.p_flowCodeDocument, SLOT(deleteLater()) );
	}
Example #4
0
void Gplib::processInput( ProcessOptions options )
{
	resetLanguageProcess();
	m_processOptions = options;
	
	*m_languageProcess << ("gplib");
	*m_languageProcess << ("--create");
	
	*m_languageProcess << ( options.intermediaryOutput() );
	
	const QStringList inputFiles = options.inputFiles();
	QStringList::const_iterator end = inputFiles.end();
	for ( QStringList::const_iterator it = inputFiles.begin(); it != end; ++it )
		*m_languageProcess << ( *it );

	if ( !start() )
	{
		KMessageBox::sorry( LanguageManager::self()->logView(), i18n("Linking failed. Please check you have gputils installed.") );
		processInitFailed();
		return;
	}
}
Example #5
0
void Microbe::processInput( ProcessOptions options )
{
    resetLanguageProcess();
    m_processOptions = options;

    *m_languageProcess << ("microbe");

    // Input Asm file
    *m_languageProcess << ( options.inputFiles().first() );

    // Output filename
    *m_languageProcess << ( options.intermediaryOutput() );

    *m_languageProcess << ("--show-source");

    if ( !start() )
    {
//		QMessageBox::critical( LanguageManager::self()->logView(), tr("Assembly failed. Please check you have KTechlab installed properly (\"microbe\" could not be started).") );
        qCritical() << "assembly failed";
        processInitFailed();
        return;
    }
}
Example #6
0
//BEGIN class ProcessChain
ProcessChain::ProcessChain( ProcessOptions options, const char *name )
	: QObject( KTechlab::self() /*, name */ )
{
    setObjectName( name );
	m_pFlowCode = 0l;
	m_pGpasm = 0l;
	m_pGpdasm = 0l;
	m_pGplib = 0l;
	m_pGplink = 0l;
	m_pMicrobe = 0l;
	m_pPicProgrammer = 0l;
	m_pSDCC = 0l;
	m_processOptions = options;
	
	QString target;
	if ( ProcessOptions::ProcessPath::to( options.processPath() ) == ProcessOptions::ProcessPath::Pic )
		target = options.m_picID;
	else
		target = options.targetFile();
	
	LanguageManager::self()->logView()->addOutput( i18n("Building: %1", target ), LogView::ot_important );
	QTimer::singleShot( 0, this, SLOT(compile()) );
}
int main(int argc, char* argv[])
{
    setupDefaultSignalHandlers();
    bool caughtException = false;

    try
    {
        ProcessOptions po;
        std::vector<std::string> args(argv + 1, argv + argc);

        if (po.setLogServerProcessArgs(argv[0], args))
        {
            __pid_t pid = getPid();
            LOG(INFO) << "\tLog Server Process : pid=" << pid;

            LogServerProcess logServerProcess;

            if (logServerProcess.init(po.getConfigFile()))
            {
                logServerProcess.start();
                logServerProcess.join();
            }
            else
            {
                logServerProcess.stop();
            }
        }
    }
    catch (const std::exception& e)
    {
        caughtException = true;
        std::cerr << e.what() << std::endl;
    }

    return caughtException ? 1 : 0;
}
Example #8
0
void Gpdasm::processInput( ProcessOptions options )
{
	resetLanguageProcess();
	m_asmOutput = "";
	m_processOptions = options;;

	*m_languageProcess << ("gpdasm");

	*m_languageProcess << ("--processor");
 	*m_languageProcess << ( options.m_picID );
	*m_languageProcess << ( options.inputFiles().first() );

	if ( !start() )
	{
		// QMessageBox::critical( LanguageManager::self()->logView(), tr("Disassembly failed. Please check you have gputils installed.") );
        qDebug() << "disassembly failed";
		processInitFailed();
		return;
	}
}
int main(int argc, char* argv[])
{
	// Only 1 argument: xml filename
	if (argc < 2)
	{
		cout << "\nTo few arguments.";
		return 0;
	}

	// Path is a structure from Boost file system
	path ConfigFile(argv[1]);
	if (!exists(ConfigFile))
	{
		cout << ConfigFile.filename().string() << " not exists " << '\n';
		return 0;
	}
	// ProcessOptions is a class that contains all necessary parameters
	ProcessOptions ProcOptions;
	// Read parameters from the XML file
	ProcOptions.LoadParams(ConfigFile.string());
	string ProcOptionsStr = ProcOptions.ShowParams();
	cout << ProcOptionsStr;

	path PathToProcess(ProcOptions.InFolderName1);
	if (!exists(PathToProcess))
	{
		cout << PathToProcess << " not exists " << '\n';
		return 0;
	}
	if (!is_directory(PathToProcess))
	{
		cout << PathToProcess << " This is not a directory path " << '\n';
		//return 0;
	}

	if (ProcOptions.displayResult)
	{
		namedWindow("Image", WINDOW_AUTOSIZE);
	}

	if (ProcOptions.displaySmallImage)
	{
		namedWindow("ImageSmall", WINDOW_AUTOSIZE);
	}

	regex FilePattern(ProcOptions.InFilePattern1);

	// Create ROI. The ROI could be the whole image or a tile of specific size and shape
	Mat Roi;
	int roiMaxX, roiMaxY; // Bounding box sizes for ROI 
	switch (ProcOptions.tileShape) // Different tile shapes
	{
	case 1: // Rectangle
		roiMaxX = ProcOptions.maxTileX;
		roiMaxY = ProcOptions.maxTileY;
		Roi = Mat::ones(roiMaxY, roiMaxX, CV_16U);
		break;
	case 2: // Ellipse
		roiMaxX = ProcOptions.maxTileX;
		roiMaxY = ProcOptions.maxTileY;
		Roi = Mat::zeros(roiMaxY, roiMaxX, CV_16U);
		ellipse(Roi, Point(roiMaxX / 2, roiMaxY / 2),
			Size(roiMaxX / 2, roiMaxY / 2), 0.0, 0.0, 360.0,
			1, -1);
		break;
	case 3: // Hexagon
	{
		int edgeLength = ProcOptions.maxTileX;
		roiMaxX = edgeLength * 2;
		roiMaxY = (int)((float)edgeLength * 0.8660254 * 2.0);
		Roi = Mat::zeros(roiMaxY, roiMaxX, CV_16U);

		Point vertice0(edgeLength / 2, 0);
		Point vertice1(edgeLength / 2 + edgeLength - 1, 0);
		Point vertice2(roiMaxX - 1, roiMaxY / 2);
		Point vertice3(edgeLength / 2 + edgeLength - 1, roiMaxY - 1);
		Point vertice4(edgeLength / 2, roiMaxY - 1);
		Point vertice5(0, roiMaxY / 2);

		line(Roi, vertice0, vertice1, 1, 1);
		line(Roi, vertice1, vertice2, 1, 1);
		line(Roi, vertice2, vertice3, 1, 1);
		line(Roi, vertice3, vertice4, 1, 1);
		line(Roi, vertice4, vertice5, 1, 1);
		line(Roi, vertice5, vertice0, 1, 1);
		unsigned short *wRoi;

		for (int y = 1; y < roiMaxY - 1; y++)
		{
			wRoi = (unsigned short *)Roi.data + roiMaxX * y;
			int x = 0;
			for (x; x < roiMaxX; x++)
			{
				if (*wRoi)
					break;
				wRoi++;
			}
			x++;
			wRoi++;
			for (x; x < roiMaxX; x++)
			{
				if (*wRoi)
					break;
				*wRoi = 1;
				wRoi++;
			}
		}

	}
	break;
	default:
		break;
	}

	int stepNr = (int)(180.0 / ProcOptions.angleStep); // angle step for computations (number of steps)

	// data vector
	float *Energy = new float[stepNr];
	float *Contrast = new float[stepNr];
	float *Correlation = new float[stepNr];
	float *Homogenity = new float[stepNr];

	int *Angles = new int[stepNr]; // vector for best angles histogtam

	// check how many features to compute
	float featCount = 0;
	if (ProcOptions.useContrast)
		featCount++;
	if (ProcOptions.useEnergy)
		featCount++;
	if (ProcOptions.useHomogeneity)
		featCount++;
	if (ProcOptions.useCorrelation)
		featCount++;
	//Matrix declarations
	Mat ImIn, ImInF, ImToShow, SmallIm, COM, SmallImToShow;

	steady_clock::time_point timePointOld = steady_clock::now();
	// loop through all files in the inpur directory
	for (directory_entry& FileToProcess : directory_iterator(PathToProcess))
	{

		steady_clock::time_point timePointPresent = steady_clock::now();
		duration<double> time_span = duration_cast<duration<double>>(timePointPresent - timePointOld);
		cout << "file time: " << time_span.count() << "\n";
		timePointOld = timePointPresent;

		path InPath = FileToProcess.path();

		string OutString = ProcOptionsStr;

		// check if the filename follows the input regular expression
		if (!regex_match(InPath.filename().string().c_str(), FilePattern))
			continue;

		if (!exists(InPath))
		{
			cout << InPath.filename().string() << " File does not exist" << "\n";
			continue;
		}

		OutString += "In file - " + InPath.filename().string() + "\n";
		cout << "In file  - " << InPath.filename().string() << "\n";

		//Mat ImIn = imread(InPath.string(), CV_LOAD_IMAGE_ANYDEPTH);
		ImIn.release();
		ImIn = imread(InPath.string(), CV_LOAD_IMAGE_ANYDEPTH);
		// check if it is an image file
		if (!ImIn.size)
		{
			cout << "this is not a valid image file";
			continue;
		}

		int maxX, maxY, maxXY;
		maxX = ImIn.cols;
		maxY = ImIn.rows;
		maxXY = maxX * maxY;

		// conversion to float
		//Mat ImInF;						// ,ImInFTemp;
		ImInF.release();
		ImIn.convertTo(ImInF, CV_32F);
		// Filtering

		//
		switch (ProcOptions.preprocessType)
		{
		case 1:
			blur(ImInF, ImInF, Size(3, 3));
			break;
		case 2:
			medianBlur(ImInF, ImInF, 3);
			break;
		default:
			break;
		}


		float maxNormGlobal = ProcOptions.maxNormGlobal;
		float minNormGlobal = ProcOptions.minNormGlobal;

		switch (ProcOptions.normalisation)
		{
		case 1:
			NormParamsMinMax(ImInF, &maxNormGlobal, &minNormGlobal);
			break;
		case 2:
			NormParamsMinMax(ImInF, &maxNormGlobal, &minNormGlobal);
			break;
		case 3:
			NormParamsMeanP3Std(ImInF, &maxNormGlobal, &minNormGlobal);
			break;
		case 4:
			NormParamsMeanP3Std(ImInF, &maxNormGlobal, &minNormGlobal);
			break;
		case 5:
			NormParams1to99perc(ImInF, &maxNormGlobal, &minNormGlobal);
			break;
		case 6:
			NormParams1to99perc(ImInF, &maxNormGlobal, &minNormGlobal);
			break;
		default:
			break;
		}

		OutString += "Min Norm Global: \t" + to_string(minNormGlobal) + "\n";
		OutString += "Max Norm Global: \t" + to_string(maxNormGlobal) + "\n";

		float displayMax = ProcOptions.displayMax;
		float displayMin = ProcOptions.displayMin;

		if (!ProcOptions.useFixtDispNorm)
		{
			displayMax = maxNormGlobal;
			displayMin = minNormGlobal;
		}

		//Mat ImToShow;
		ImToShow.release();
		ImToShow = ShowImageF32PseudoColor(ImInF, displayMin, displayMax);

		if (ProcOptions.showTiles)
		{
			switch (ProcOptions.tileShape)
			{
			case 1:
				for (int y = ProcOptions.offsetTileY; y <= (maxY - ProcOptions.offsetTileY); y += ProcOptions.shiftTileY)
				{
					for (int x = ProcOptions.offsetTileX; x <= (maxX - ProcOptions.offsetTileX); x += ProcOptions.shiftTileX)
					{
						rectangle(ImToShow, Point(x - roiMaxX / 2, y - roiMaxY / 2),
							Point(x - roiMaxX / 2 + roiMaxX - 1, y - roiMaxY / 2 + roiMaxY - 1),
							Scalar(0.0, 0.0, 0.0, 0.0), ProcOptions.tileLineThickness);
					}
				}
				break;
			case 2:
				for (int y = ProcOptions.offsetTileY; y <= (maxY - ProcOptions.offsetTileY); y += ProcOptions.shiftTileY)
				{
					for (int x = ProcOptions.offsetTileX; x <= (maxX - ProcOptions.offsetTileX); x += ProcOptions.shiftTileX)
					{
						ellipse(ImToShow, Point(x, y),
							Size(roiMaxX / 2, roiMaxY / 2), 0.0, 0.0, 360.0,
							Scalar(0.0, 0.0, 0.0, 0.0), ProcOptions.tileLineThickness);
					}
				}
				break;
			case 3:
				for (int y = ProcOptions.offsetTileY; y <= (maxY - ProcOptions.offsetTileY); y += ProcOptions.shiftTileY)
				{
					for (int x = ProcOptions.offsetTileX; x <= (maxX - ProcOptions.offsetTileX); x += ProcOptions.shiftTileX)
					{
						int edgeLength = ProcOptions.maxTileX;
						Point vertice0(x - edgeLength / 2, y - (int)((float)edgeLength * 0.8660254));
						Point vertice1(x + edgeLength - edgeLength / 2, y - (int)((float)edgeLength * 0.8660254));
						Point vertice2(x + edgeLength, y);
						Point vertice3(x + edgeLength - edgeLength / 2, y + (int)((float)edgeLength * 0.8660254));
						Point vertice4(x - edgeLength / 2, y + (int)((float)edgeLength * 0.8660254));
						Point vertice5(x - edgeLength, y);

						line(ImToShow, vertice0, vertice1, Scalar(0.0, 0.0, 0.0, 0.0), ProcOptions.tileLineThickness);
						line(ImToShow, vertice1, vertice2, Scalar(0.0, 0.0, 0.0, 0.0), ProcOptions.tileLineThickness);
						line(ImToShow, vertice2, vertice3, Scalar(0.0, 0.0, 0.0, 0.0), ProcOptions.tileLineThickness);
						line(ImToShow, vertice3, vertice4, Scalar(0.0, 0.0, 0.0, 0.0), ProcOptions.tileLineThickness);
						line(ImToShow, vertice4, vertice5, Scalar(0.0, 0.0, 0.0, 0.0), ProcOptions.tileLineThickness);
						line(ImToShow, vertice5, vertice0, Scalar(0.0, 0.0, 0.0, 0.0), ProcOptions.tileLineThickness);

					}
				}
				break;
			default:
				break;
			}
		}

		if (ProcOptions.displayResult)
		{
			imshow("Image", ImToShow);
			waitKey(50);
		}

		//Mat SmallIm;
		SmallIm.release();
		int xTileNr = 0;
		int yTileNr = 0;

		OutString += "Tile Y\tTile X\tAngle Contrast\tAngle Energy\tAngle Hogeneity\tAngle Corelation\tMean Intensity\tTile min norm\tTile max norm\n";
		for (int y = ProcOptions.offsetTileY; y <= (maxY - ProcOptions.offsetTileY); y += ProcOptions.shiftTileY)
		{
			for (int x = ProcOptions.offsetTileX; x <= (maxX - ProcOptions.offsetTileX); x += ProcOptions.shiftTileX)
			{
				ImInF(Rect(x - roiMaxX / 2, y - roiMaxY / 2, roiMaxX, roiMaxY)).copyTo(SmallIm);
				float meanSmallIm = -10.0;
				//if (ProcOptions.useMinMean)
				meanSmallIm = MatFMeanRoi(SmallIm, Roi, 1);
				bool meanCondition = 0;
				if (ProcOptions.useMinMean)
				{
					if (meanSmallIm >= ProcOptions.minMean)
						meanCondition = true;
					else
						meanCondition = false;
				}
				else
					meanCondition = true;

				float maxNorm, minNorm;

				switch (ProcOptions.normalisation)
				{
				case 1:
					NormParamsMinMax(SmallIm, Roi, 1, &maxNorm, &minNorm);
					break;
				case 2:
					maxNorm = maxNormGlobal;
					minNorm = minNormGlobal;
					break;
				case 3:
					NormParamsMeanP3Std(SmallIm, Roi, 1, &maxNorm, &minNorm);
					break;
				case 4:
					maxNorm = maxNormGlobal;
					minNorm = minNormGlobal;
					break;
				case 5:
					NormParams1to99perc(SmallIm, Roi, 1, &maxNorm, &minNorm);
					break;
				case 6:
					maxNorm = maxNormGlobal;
					minNorm = minNormGlobal;
					break;
				default:
					maxNorm = 65535.0;
					minNorm = 0.0;
					break;
				}

				for (int i = 0; i < stepNr; i++)
				{
					Angles[i] = 0;
					Contrast[i] = 0.0;
					Energy[i] = 0.0;
					Homogenity[i] = 0.0;
					Correlation[i] = 0.0;

				}

				// ofset loop
				if (meanCondition)
				{
					for (int offset = ProcOptions.minOfset; offset <= ProcOptions.maxOfset; offset += 1)
					{
						for (int angleIndex = 0; angleIndex < stepNr; angleIndex++)
						{
							float angle = ProcOptions.angleStep * angleIndex;
							//Mat COM; // co-occurrence matrix definition
							COM.release();
							if (ProcOptions.tileShape < 2)
								COM = COMCardone4(SmallIm, offset, angle, ProcOptions.binCount, maxNorm, minNorm, ProcOptions.interpolation);
							else
								COM = COMCardoneRoi(SmallIm, Roi, offset, angle, ProcOptions.binCount, maxNorm, minNorm, ProcOptions.interpolation, 1);
							float tmpContrast, tmpEnergy, tmpHomogenity, tmpCorrelation;
							COMParams(COM, &tmpContrast, &tmpEnergy, &tmpHomogenity, &tmpCorrelation);

							Contrast[angleIndex] += tmpContrast;
							Energy[angleIndex] += tmpEnergy;
							Homogenity[angleIndex] += tmpHomogenity;
							Correlation[angleIndex] = +tmpCorrelation;
						}

					}
				}
				// best angle for ofset
				int bestAngle = 0;
				int bestAngleContrast, bestAngleEnergy, bestAngleHomogenity, bestAngleCorrelation;
				bestAngleContrast = FindBestAngleMin(Contrast, stepNr);
				bestAngleEnergy = FindBestAngleMax(Energy, stepNr);
				bestAngleHomogenity = FindBestAngleMax(Homogenity, stepNr);
				bestAngleCorrelation = FindBestAngleMax(Correlation, stepNr);

				if (ProcOptions.useContrast)
					bestAngle = bestAngleContrast;
				if (ProcOptions.useEnergy)
					bestAngle = bestAngleEnergy;
				if (ProcOptions.useHomogeneity)
					bestAngle = bestAngleHomogenity;
				if (ProcOptions.useCorrelation)
					bestAngle = bestAngleCorrelation;

				/*
				int bestAngle = 0;
				if (ProcOptions.useContrast)
					Angles[bestAngleContrast]++;
				if (ProcOptions.useEnergy)
					Angles[bestAngleEnergy]++;
				if (ProcOptions.useHomogeneity)
					Angles[bestAngleHomogenity]++;
				if (ProcOptions.useCorrelation)
					Angles[bestAngleCorrelation]++;

				int bestAngle = 0;
				int maxAngle = Angles[0];
				for (int i = 1; i < stepNr; i++)
				{
					if (maxAngle < Angles[i])
					{
						maxAngle = Angles[i];
						bestAngle = i;
					}
				}
				*/


				// show line on image
				//int barCenterX = ProcOptions.maxTileX / 2 + x;
				//int barCenterY = ProcOptions.maxTileY / 2 + y;

				double lineLength;
//				if (ProcOptions.lineLengthPropToConfidence)
//					lineLength = (double)(ProcOptions.lineHalfLength) / (ProcOptions.maxOfset - ProcOptions.minOfset + 1) / featCount * maxAngle;
//				else
//					lineLength = (double)(ProcOptions.lineHalfLength);

				lineLength = (double)(ProcOptions.lineHalfLength);

				int lineOffsetX = (int)round(lineLength *  sin((double)(bestAngle)*ProcOptions.angleStep* PI / 180.0));
				int lineOffsetY = (int)round(lineLength * cos((double)(bestAngle)*ProcOptions.angleStep* PI / 180.0));

				//


				if ( meanCondition)
				{
					//line(ImToShow, Point(barCenterX - lineOffsetX, barCenterY - lineOffsetY), Point(barCenterX + lineOffsetX, barCenterY + lineOffsetY), Scalar(0, 0.0, 0.0, 0.0), ProcOptions.imposedLineThickness);
					line(ImToShow, Point(x - lineOffsetX, y - lineOffsetY), Point(x + lineOffsetX, y + lineOffsetY), Scalar(0, 0.0, 0.0, 0.0), ProcOptions.imposedLineThickness);
				}
				if (ProcOptions.displayResult)
				{
					imshow("Image", ImToShow);
				}

				cout << yTileNr << "\t" << xTileNr << "\t";
				cout << "A Cont = " << to_string(bestAngleContrast*ProcOptions.angleStep);
				cout << "A Ener = " << to_string(bestAngleEnergy*ProcOptions.angleStep);
				cout << "A Homg = " << to_string(bestAngleHomogenity*ProcOptions.angleStep);
				cout << "A Corr = " << to_string(bestAngleCorrelation*ProcOptions.angleStep);

				//cout << "  c = " << ItoStrLS(maxAngle, 2) << " mean =  " << to_string(meanSmallIm);
				cout << " min norm = " << to_string(minNorm) << " max norm = " << to_string(maxNorm) << "\n";
				OutString += ItoStrLS(yTileNr, 2) + "\t" + ItoStrLS(xTileNr, 2) + "\t";
				if ( meanCondition)
				{
					OutString += to_string((float)bestAngleContrast * ProcOptions.angleStep) + "\t";
					OutString += to_string((float)bestAngleEnergy * ProcOptions.angleStep) + "\t";
					OutString += to_string((float)bestAngleHomogenity * ProcOptions.angleStep) + "\t";
					OutString += to_string((float)bestAngleCorrelation * ProcOptions.angleStep) + "\t";

					//OutString += to_string((float)(maxAngle) / (float)(ProcOptions.maxOfset - ProcOptions.minOfset + 1) / (float)featCount) + "\t";
				}
				else
				{
					OutString += "NAN\t";
					OutString += "NAN\t";
					OutString += "NAN\t";
					OutString += "NAN\t";
				}
				OutString += to_string(meanSmallIm) + "\t" + to_string(minNorm) + "\t" + to_string(maxNorm) + "\n";

				if (ProcOptions.displaySmallImage)
				{
					//Mat SmallImToShow = ShowImageF32PseudoColor(SmallIm, minNorm, maxNorm);
					SmallImToShow.release();
					SmallImToShow = ShowImageF32PseudoColor(SmallIm, minNorm, maxNorm);
					line(SmallImToShow, Point(SmallImToShow.cols / 2 - lineOffsetX, SmallImToShow.rows / 2 - lineOffsetY), Point(SmallImToShow.cols / 2 + lineOffsetX, SmallImToShow.rows / 2 + lineOffsetY), Scalar(0, 0.0, 0.0, 0.0), ProcOptions.imposedLineThickness);
					imshow("ImageSmall", ShowSolidRegionOnImage(GetContour5(Roi), SmallImToShow));
				}

				if (ProcOptions.displayResult || ProcOptions.displaySmallImage)
				{
					if (ProcOptions.goThru)
						waitKey(50);
					else
						waitKey(0);
				}
				xTileNr++;

			}
			yTileNr++;
			xTileNr = 0;
		}
		
		if (ProcOptions.imgOut)
		{
			imwrite(ProcOptions.OutFolderName1 + InPath.filename().stem().string() + ".bmp", ImToShow);
		}

		if (ProcOptions.textOut)
		{
			string TextFileName = ProcOptions.OutFolderName1 + InPath.filename().stem().string() + ".txt";
			std::ofstream out(TextFileName);
			out << OutString;
			out.close();
		}
	}
	//end
	//for debug only
	//string TempStr;
	//cin >> TempStr;
	return 0;
}
Example #10
0
void SDCC::processInput( ProcessOptions options )
{
    resetLanguageProcess();

    MicroInfo * info = MicroLibrary::self()->microInfoWithID( options.m_picID );
    if (!info)
    {
        outputError( i18n("Could not find PIC with ID \"%1\".").arg(options.m_picID) );
        return;
    }

    m_processOptions = options;

    *m_languageProcess << ("sdcc");


    //BEGIN Pass custom sdcc options
#define ARG(text,option) if ( KTLConfig::text() ) *m_languageProcess << ( QString("--%1").arg(option) );
    // General
    ARG( sDCC_nostdlib,			"nostdlib" )
    ARG( sDCC_nostdinc,			"nostdinc" )
    ARG( sDCC_less_pedantic,		"less-pedantic" )
    ARG( sDCC_std_c89,			"std-c89" )
    ARG( sDCC_std_c99,			"std-c99" )

    // Code generation
    ARG( sDCC_stack_auto,			"stack-auto" )
    ARG( sDCC_int_long_reent,		"int-long-reent" )
    ARG( sDCC_float_reent,			"float-reent" )
    ARG( sDCC_fommit_frame_pointer,	"fommit-frame-pointer" )
    ARG( sDCC_no_xinit_opt,			"no-xinit-opt" )
    ARG( sDCC_all_callee_saves,		"all-callee-saves" )

    // Optimization
    ARG( sDCC_nooverlay,			"nooverlay" )
    ARG( sDCC_nogcse,			"nogcse" )
    ARG( sDCC_nolabelopt,			"nolabelopt" )
    ARG( sDCC_noinvariant,			"noinvariant" )
    ARG( sDCC_noinduction,			"noinduction" )
    ARG( sDCC_no_peep,			"no-peep" )
    ARG( sDCC_noloopreverse,		"noloopreverse" )
    ARG( sDCC_opt_code_size,		"opt-code-size" )
    ARG( sDCC_opt_code_speed,		"opt-code-speed" )
    ARG( sDCC_peep_asm,			"peep-asm" )
    ARG( sDCC_nojtbound,			"nojtbound" )

    // PIC16 Specific
    if ( info->instructionSet()->set() == AsmInfo::PIC16 )
    {
        ARG( sDCC_nodefaultlibs,		"nodefaultlibs" )
        ARG( sDCC_pno_banksel,			"pno-banksel" )
        ARG( sDCC_pstack_model_large,	"pstack-model=large" )
        ARG( sDCC_debug_xtra,			"debug-xtra" )
        ARG( sDCC_denable_peeps,		"denable-peeps" )
        ARG( sDCC_calltree,			"calltree" )
        ARG( sDCC_fstack,			"fstack" )
        ARG( sDCC_optimize_goto,		"optimize-goto" )
        ARG( sDCC_optimize_cmp,			"optimize-cmp" )
        ARG( sDCC_optimize_df,			"optimize-df" )
    }
#undef ARG

    if ( !KTLConfig::miscSDCCOptions().isEmpty() )
        *m_languageProcess << ( KTLConfig::miscSDCCOptions() );
    //END Pass custom sdcc options


    *m_languageProcess << ("--debug"); // Enable debugging symbol output
    *m_languageProcess << ("-S"); // Compile only; do not assemble or link

    QString asmSwitch;
    switch ( info->instructionSet()->set() )
    {
    case AsmInfo::PIC12:
        // Last time I checked, SDCC doesn't support Pic12, and probably never will, but whatever...
        asmSwitch = "-mpic12";
        break;
    case AsmInfo::PIC14:
        asmSwitch = "-mpic14";
        break;
    case AsmInfo::PIC16:
        asmSwitch = "-mpic16";
        break;
    }

    *m_languageProcess << (asmSwitch);

    *m_languageProcess << ( "-"+options.m_picID.lower() );

    *m_languageProcess << ( options.inputFiles().first() );

    *m_languageProcess << ("-o");
    *m_languageProcess << ( options.intermediaryOutput() );

    if ( !start() )
    {
        KMessageBox::sorry( LanguageManager::self()->logView(), i18n("Compilation failed. Please check you have sdcc installed.") );
        processInitFailed();
        return;
    }
}
Example #11
0
void Gplink::processInput( ProcessOptions options )
{
	resetLanguageProcess();
	m_processOptions = options;
	
	*m_languageProcess << ("gplink");
	
	if ( !options.m_hexFormat.isEmpty() )
	{
		*m_languageProcess << ("--hex-format");
		*m_languageProcess << (options.m_hexFormat);
	}
	
	if ( options.m_bOutputMapFile )
		*m_languageProcess << ("--map");
	
	if ( !options.m_libraryDir.isEmpty() )
	{
		*m_languageProcess << ("--include");
		*m_languageProcess << ( options.m_libraryDir );
	}
	
	if ( !options.m_linkerScript.isEmpty() )
	{
		*m_languageProcess << ("--script");
		*m_languageProcess << ( options.m_linkerScript );
	}
	
	if ( !options.m_linkOther.isEmpty() )
		*m_languageProcess << (options.m_linkOther);
	
	// Output hex file
	*m_languageProcess << ("--output");
	*m_languageProcess << ( options.intermediaryOutput() );
	
	// Input object file
	const QStringList inputFiles = options.inputFiles();
	QStringList::const_iterator end = inputFiles.end();
	for ( QStringList::const_iterator it = inputFiles.begin(); it != end; ++it )
		*m_languageProcess << ( *it );
	
	// Other libraries
	end = options.m_linkLibraries.end();
	for ( QStringList::const_iterator it = options.m_linkLibraries.begin(); it != end; ++it )
		*m_languageProcess << ( *it );
	
	// if selected to automatically link to SDCC libraries, add some options.
	if( KTLConfig::gplink_link_shared() ) 
	{	
		// set up the include directory
		MicroInfo * info = MicroLibrary::self()->microInfoWithID( options.m_picID );
		if ( ! info )
		{
			// be program won't link anyway, but the user can't say that the program didn't try
			kError() << k_funcinfo << "Couldn't find the requested PIC" << options.m_picID << endl;
			kWarning() << k_funcinfo << "Supposing that the pic is pic12 or pic14" << endl;
			*m_languageProcess << "-I" << m_sdccLibDir + "/pic" ;
		}
		else
		{
			if ( info->instructionSet()->set() == AsmInfo::PIC16 )
				*m_languageProcess << "-I" << m_sdccLibDir + "/pic16" ;
			else
				*m_languageProcess << "-I" << m_sdccLibDir + "/pic" ;
		
			// to pic to link against
			*m_languageProcess << options.m_picID.lower().replace ( "p","pic" ) + ".lib";
		}
		*m_languageProcess << "libsdcc.lib";
	}
	
	if ( !start() )
	{
		KMessageBox::sorry( LanguageManager::self()->logView(), i18n("Linking failed. Please check you have gputils installed.") );
		processInitFailed();
		return;
	}
}
Example #12
0
QString GpsimProcessor::generateSymbolFile( const QString &fileName, QObject *receiver, const char *successMember, const char * failMember )
{
	if ( !isValidProgramFile(fileName) )
		return QString::null;

	QString extension = fileName.right(
        fileName.length() - fileName.lastIndexOf('.') - 1
        ).toLower();

	if ( extension == "cod" )
	{
		QTimer::singleShot( 0, receiver, successMember );
		return fileName;
	}
	if ( extension == "hex" )
	{
		QTimer::singleShot( 0, receiver, successMember );
		// We've already checked for the existance of the ".cod" file in GpsimProcessor::isValidProgramFile
		return QString(fileName).replace(".hex",".cod");
	}

	else if ( extension == "basic" || extension == "microbe" )
	{
		compileMicrobe( fileName, receiver, successMember, failMember );
		return QString(fileName).replace( "."+extension, ".cod" );
	}
	else if ( extension == "flowcode" )
	{
		const QString hexFile = QTemporaryFile( "tmpXXXXXX.hex" ).fileName();

		ProcessOptions o;
		o.b_addToProject = false;
		o.setTargetFile( hexFile );
		o.setInputFiles( QStringList(fileName) );
		o.setMethod( ProcessOptions::Method::Forget );
		o.setProcessPath( ProcessOptions::ProcessPath::FlowCode_Program );

		ProcessChain * pc = new ProcessChain(o);
		if (receiver)
		{
			if (successMember)
				connect( pc, SIGNAL(successful()), receiver, successMember );
			if (failMember)
				connect( pc, SIGNAL(failed()), receiver, failMember );
		}

		return QString(hexFile).replace( ".hex", ".cod" );
	}
	else if ( extension == "asm" )
	{
		ProcessOptions o;
		o.b_addToProject = false;
		o.setTargetFile( QString(fileName).replace(".asm",".hex"));
		o.setInputFiles(QStringList(fileName));
		o.setMethod( ProcessOptions::Method::Forget );
		o.setProcessPath( ProcessOptions::ProcessPath::path( ProcessOptions::guessMediaType(fileName), ProcessOptions::ProcessPath::Program ) );

		ProcessChain *pc = new ProcessChain(o);
		if (receiver)
		{
			if (successMember)
				connect( pc, SIGNAL(successful()), receiver, successMember );
			if (failMember)
				connect( pc, SIGNAL(failed()), receiver, failMember );
		}

		return QString(fileName).replace(".asm",".cod");
	}
	else if ( extension == "c" )
	{
		ProcessOptions o;
		o.b_addToProject = false;
		o.setTargetFile( QString(fileName).replace(".c",".hex"));
		o.setInputFiles(QStringList(fileName));
		o.setMethod( ProcessOptions::Method::Forget );
		o.setProcessPath( ProcessOptions::ProcessPath::C_Program );

		ProcessChain *pc = new ProcessChain(o);
		if (receiver)
		{
			if (successMember)
				connect( pc, SIGNAL(successful()), receiver, successMember );
			if (failMember)
				connect( pc, SIGNAL(failed()), receiver, failMember );
		}

		return QString(fileName).replace(".c",".cod");
	}

	if ( failMember )
		QTimer::singleShot( 0, receiver, failMember );
	return QString::null;
}
Example #13
0
void Gpasm::processInput( ProcessOptions options )
{
	resetLanguageProcess();
	m_processOptions = options;

	AsmParser p( options.inputFiles().first() );
	p.parse();

	*m_languageProcess << ("gpasm");

	if ( ProcessOptions::ProcessPath::from( options.processPath() ) == ProcessOptions::ProcessPath::AssemblyRelocatable )
		*m_languageProcess << ("--object");

// 	*m_languageProcess << ("--debug-info"); // Debug info

	// Output filename
	*m_languageProcess << ("--output");
	*m_languageProcess << ( options.intermediaryOutput() );

	if ( !options.m_hexFormat.isEmpty() )
	{
		*m_languageProcess << ("--hex-format");
		*m_languageProcess << (options.m_hexFormat);
	}

	// Radix
	if ( !p.containsRadix() )
	{
		*m_languageProcess << ("--radix");
		switch( KtlConfig::self()->radix() )
		{
            case KtlConfig::Binary:
				*m_languageProcess << ("BIN");
				break;
			case KtlConfig::Octal:
				*m_languageProcess << ("OCT");
				break;
			case KtlConfig::Hexadecimal:
				*m_languageProcess << ("HEX");
				break;
			case KtlConfig::Decimal:
			default:
				*m_languageProcess << ("DEC");
				break;
		}
		*m_languageProcess << ("DEC"); // choose the default
	}

	// Warning Level
	*m_languageProcess << ("--warning");
	switch( KtlConfig::self()->gpasmWarningLevel() )
	{
		case KtlConfig::Warnings:
			*m_languageProcess << ("1");
			break;
		case KtlConfig::Errors:
			*m_languageProcess << ("2");
			break;
		default:
		case KtlConfig::All:
			*m_languageProcess << ("0");
			break;
	}

	// Ignore case
	if ( KtlConfig::self()->ignoreCase() )
		*m_languageProcess << ("--ignore-case");
	// Dos formatting
	if ( KtlConfig::self()->dosFormat() )
		*m_languageProcess << ("--dos");

	// Force list
	if ( options.b_forceList )
		*m_languageProcess << ("--force-list");

	// Other options
	if ( !KtlConfig::self()->miscGpasmOptions().isEmpty() )
		*m_languageProcess << ( KtlConfig::self()->miscGpasmOptions() );
	// Input Asm file
	*m_languageProcess << ( options.inputFiles().first() );

	if ( !start() )
	{
		// KMessageBox::sorry( LanguageManager::self()->logView(), tr("Assembly failed. Please check you have gputils installed.") );
        qCritical() << "assembly failed";
		processInitFailed();
		return;
	}
}
Example #14
0
void ProcessChain::slotFinishedCompile(Language *language)
{
	ProcessOptions options = language->processOptions();
	
	if ( options.b_addToProject && ProjectManager::self()->currentProject() )
		ProjectManager::self()->currentProject()->addFile( KUrl(options.targetFile()) );
	
	ProcessOptions::ProcessPath::MediaType typeTo = ProcessOptions::ProcessPath::to( m_processOptions.processPath() );
	
	TextDocument * editor = 0l;
	if ( KTLConfig::reuseSameViewForOutput() )
	{
		editor = options.textOutputTarget();
		if ( editor && (!editor->url().isEmpty() || editor->isModified()) )
			editor = 0l;
	}
	
	switch (typeTo)
	{
		case ProcessOptions::ProcessPath::AssemblyAbsolute:
		case ProcessOptions::ProcessPath::AssemblyRelocatable:
		case ProcessOptions::ProcessPath::C:
		case ProcessOptions::ProcessPath::Disassembly:
		case ProcessOptions::ProcessPath::Library:
		case ProcessOptions::ProcessPath::Microbe:
		case ProcessOptions::ProcessPath::Object:
		case ProcessOptions::ProcessPath::Program:
		{
			switch ( options.method() )
			{
				case ProcessOptions::Method::LoadAsNew:
				{
					if ( !editor )
						editor = DocManager::self()->createTextDocument();
					
					if ( !editor )
						break;
				
					QString text;
					QFile f( options.targetFile() );
					if ( !f.open( QIODevice::ReadOnly ) )
					{
						editor->deleteLater();
						editor = 0l;
						break;
					}
				
					QTextStream stream(&f);
				
					while ( !stream.atEnd() )
						text += stream.readLine()+'\n';
				
					f.close();
	
					editor->setText( text, true );
					break;
				}
			
				case ProcessOptions::Method::Load:
				{
					editor = dynamic_cast<TextDocument*>( DocManager::self()->openURL(options.targetFile()) );
					break;
				}
			
				case ProcessOptions::Method::Forget:
					break;
			}
		}
			
		case ProcessOptions::ProcessPath::FlowCode:
		case ProcessOptions::ProcessPath::Pic:
		case ProcessOptions::ProcessPath::Unknown:
			break;
	}
	
	
	if (editor)
	{
		switch (typeTo)
		{
			case ProcessOptions::ProcessPath::AssemblyAbsolute:
			case ProcessOptions::ProcessPath::AssemblyRelocatable:
			{
				if ( KTLConfig::autoFormatMBOutput() )
					editor->formatAssembly();
				editor->slotInitLanguage( TextDocument::ct_asm );
				break;
			}
		
			case ProcessOptions::ProcessPath::C:
				editor->slotInitLanguage( TextDocument::ct_c );
				break;
			
			case ProcessOptions::ProcessPath::Disassembly:
				break;
			
			case ProcessOptions::ProcessPath::Library:
			case ProcessOptions::ProcessPath::Object:
			case ProcessOptions::ProcessPath::Program:
				editor->slotInitLanguage( TextDocument::ct_hex );
				break;
			
			case ProcessOptions::ProcessPath::Microbe:
				editor->slotInitLanguage( TextDocument::ct_microbe );
				break;
			
			case ProcessOptions::ProcessPath::FlowCode:
			case ProcessOptions::ProcessPath::Pic:
			case ProcessOptions::ProcessPath::Unknown:
				break;
		}
		
		DocManager::self()->giveDocumentFocus( editor );
	}
	
	options.setTextOutputtedTo( editor );

	emit successful(options);
	emit successful();
}