Exemplo n.º 1
0
// If the inputs change state, this will affect the output state.  If any inputs are InvalidState, then the output is InvalidState.  If any of the inputs are in ProcessingState, then the output is ProcessingState. Otherwise, it's ReadyState.
void AM1DExpressionAB::onInputSourceStateChanged() {
	combinedInputState_ = 0;
	for(int i=0; i<inputDataSourceCount(); i++)
		combinedInputState_ |= inputDataSourceAt(i)->state();

	// anything that could trigger a change in the output validity must call this
	reviewState();
}
Exemplo n.º 2
0
// X-values (or axis values)
///////////////////////////////
// Set the expression used for the independent variable (aka x-axis... the one returned by axisValue()).   If \c xExpression is an empty string, the expression is set back to default, ie: the independent variable of the first input data source.
bool AM1DExpressionAB::setXExpression(const QString& xExpressionIn) {

	QString xExpression = xExpressionIn;

	xExpressionValid_ = true;
	xUsedVariables_.clear();
	xDirect_ = false;

	if(xExpression.isEmpty() && !sources_.isEmpty())
		xExpression = sources_.at(0)->name() + ".x";

	try {
		xParser_.SetExpr(xExpression.toStdString());
		xParser_.Eval();

		// determine usedVariables_:
		mu::varmap_type usedvar = xParser_.GetUsedVar();
		mu::varmap_type::const_iterator item = usedvar.begin();
		// Query the used variables.  item->second is a pointer to the variable storage location. (With a better design, we might not need the inner loop.)
		for (; item!=usedvar.end(); ++item)
		{
			// search to find out if a variable is used. It is used if the pointer to the storage location matches item->second.
			for(int i=0; i<allVariables_.count(); i++)
				if( &(allVariables_.at(i).value) == item->second)
					xUsedVariables_ << &(allVariables_[i]);
		}

		// Optimization: is the whole expression merely a single input source name? Can we operate in direct mode?
		if(xExpressionValid_ && xUsedVariables_.count() == 1) {	// precondition: only one input variable
			xDirectVar_ = *(xUsedVariables_.at(0));	// storing it here won't matter if xDirect_ is not set.
			if(xDirectVar_.useAxisValue) {	// is this an axisValue name?
				if(xExpression.trimmed() == sources_.at(xDirectVar_.sourceIndex)->name() + ".x")	// the whole expression matches just the name. We can go direct.
					xDirect_ = true;
			}
			else {
				if(xExpression.trimmed() == sources_.at(xDirectVar_.sourceIndex)->name())	// whole expression matches justthe name. Can go direct
					xDirect_ = true;
			}
		}

	}
	catch(mu::Parser::exception_type& e) {
		// QString explanation = QString("AM1DExpressionAB Analysis Block: error setting X expression: %1: '%2'.  We found '%3' at position %4.").arg(QString::fromStdString(e.GetMsg())).arg(QString::fromStdString(e.GetExpr())).arg(QString::fromStdString(e.GetToken())).arg(e.GetPos());
		// AMErrorMon::report(AMErrorReport(this, AMErrorReport::Debug, e.GetCode(), explanation));
		xExpressionValid_ = false;
	}

	// anything that could trigger a change in the output validity must call this
	reviewState();
	emitValuesChanged();	/// \todo: actually, we mean that the axis values changed. How to signal that?

	if(!currentlySettingInputSources_)
		setModified(true);

	return xExpressionValid_;
}
Exemplo n.º 3
0
// If the inputs change size, this will affect the output state. All the inputs need to be the same size for now, otherwise the result is invalid.
void AM1DExpressionAB::onInputSourceSizeChanged() {
	size_ = inputDataSourceAt(0)->size(0);
	sizesMatch_ = true;
	for(int i=1; i<inputDataSourceCount(); i++)
		if(inputDataSourceAt(i)->size(0) != size_)
			sizesMatch_ = false;

	// anything that could trigger a change in the output validity must call this
	reviewState();
}
Exemplo n.º 4
0
void AMNormalizationAB::setInputDataSourcesImplementation(const QList<AMDataSource *> &dataSources)
{
	// disconnect connections from old sources, if they exist.
	if(!sources_.isEmpty()) {

		for (int i = 0; i < sources_.size(); i++){

			disconnect(sources_.at(i)->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
			disconnect(sources_.at(i)->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
			disconnect(sources_.at(i)->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
		}
	}

	if(dataSources.isEmpty()) {

		sources_.clear();
		axes_.clear();
		setDescription("-- No input data --");
	}

	// we know that this will only be called with valid input source
	/*
	else {

		sources_ = dataSources;
		axes_.clear();

		for (int i = 0, size = sources_.at(0)->rank(); i < size; i++)
			axes_.append(sources_.at(0)->axisInfoAt(i));

		cacheUpdateRequired_ = true;
		cachedData_ = QVector<double>(size().product());

		setDescription(QString("Sum of spectra from %1 maps").arg(sources_.size()));

		for (int i = 0; i < sources_.size(); i++){

			connect(sources_.at(i)->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
			connect(sources_.at(i)->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
			connect(sources_.at(i)->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
		}
	}
	*/
	else {
		sources_ = dataSources;
		setInputSources();
	}

	reviewState();

	emitSizeChanged();
	emitValuesChanged(AMnDIndex(0), size()-1);
	emitAxisInfoChanged();
	emitInfoChanged();
}
void REIXSXESImageInterpolationAB::setInputDataSourcesImplementation(const QList<AMDataSource *> &dataSources)
{
	// disconnect connections from old source, if it exists.
	if(inputSource_) {
		disconnect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
		disconnect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
		disconnect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
		inputSource_ = 0;
	}

	if(dataSources.isEmpty()) {
		inputSource_ = 0;
		sources_.clear();

		axes_[0] = AMAxisInfo("invalid", 0, "No input data");
	}

	// we know that this will only be called with one valid input source
	else {
		inputSource_ = dataSources.at(0);
		sources_ = dataSources;

		axes_[0] = inputSource_->axisInfoAt(0);	// take the X axis info from the data source.
		axes_[0].description = "Emission Energy";
		axes_[0].units = "eV";
		axes_[0].size /= binningLevel_;

		cacheUpdateRequired_ = true;
		axisValueCacheInvalid_ = true;
		cachedData_ = QVector<double>(axes_.at(0).size);
		cachedAxisValues_ = QVector<double>(axes_.at(0).size);

		if(shiftValues1_.isEmpty()) {
			for(int i=0,cc=inputSource_->size(1); i<cc; i++)
				shiftValues1_ << 0;	// make a null shift list, matching the size of the input data. Don't do this if we already have a shift list.
		}
		if(shiftValues2_.isEmpty()) {
			for(int i=0,cc=inputSource_->size(1); i<cc; i++)
				shiftValues2_ << 0;	// make a null shift list, matching the size of the input data. Don't do this if we already have a shift list.
		}


		connect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
		connect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
		connect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));

	}

	reviewState();

	emitSizeChanged();
	emitValuesChanged();
	emitAxisInfoChanged();
	emitInfoChanged();
}
void REIXSXESImageInterpolationAB::setShiftValues2(const AMIntList &shiftValues2)
{
	if(shiftValues2 == shiftValues2_)
		return;
	shiftValues2_ = shiftValues2;

	cacheUpdateRequired_ = true;	// could change all our cached values
	reviewState();	// might change the state to valid, if we didn't have proper number of shift values before.

	emitValuesChanged();
	emit shiftValuesChanged();
	setModified(true);
}
Exemplo n.º 7
0
// Set the data source inputs.
void AM2DAdditionAB::setInputDataSourcesImplementation(const QList<AMDataSource*>& dataSources)
{
	// disconnect connections from old sources, if they exist.
	if(!sources_.isEmpty()) {

		for (int i = 0; i < sources_.size(); i++){

			disconnect(sources_.at(i)->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
			disconnect(sources_.at(i)->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
			disconnect(sources_.at(i)->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
		}
	}

	if(dataSources.isEmpty()) {

		sources_.clear();
		axes_[0] = AMAxisInfo("invalid", 0, "No input data");
		axes_[1] = AMAxisInfo("invalid", 0, "No input data");

		setDescription("-- No input data --");
	}

	// we know that this will only be called with valid input source
	else {

		sources_ = dataSources;

		axes_[0] = sources_.at(0)->axisInfoAt(0);
		axes_[1] = sources_.at(0)->axisInfoAt(1);

		setDescription(QString("Sum of %1").arg(sources_.at(0)->description()));

		for (int i = 0; i < sources_.size(); i++){

			connect(sources_.at(i)->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
			connect(sources_.at(i)->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
			connect(sources_.at(i)->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
		}
	}

	reviewState();

	emitSizeChanged(0);
	emitSizeChanged(1);
	emitValuesChanged();
	emitAxisInfoChanged(0);
	emitAxisInfoChanged(1);
	emitInfoChanged();
}
void REIXSXESImageInterpolationAB::setRangeRound(double rangeRound)
{
	if(rangeRound == rangeRound_)
		return;

	rangeRound_ = rangeRound;
	if(liveCorrelation())
	{
		callCorrelation_.schedule();
	}

	cacheUpdateRequired_ = true;
	reviewState();

	emitValuesChanged();
	setModified(true);
}
void REIXSXESImageInterpolationAB::setSumRangeMaxX(int sumRangeMaxX)
{
	if(sumRangeMaxX == sumRangeMaxX_)
		return;

	sumRangeMaxX_ = sumRangeMaxX;
	if(liveCorrelation())
	{
		callCorrelation_.schedule();
	}

	cacheUpdateRequired_ = true;
	reviewState();

	emitValuesChanged();
	setModified(true);
}
Exemplo n.º 10
0
// Set the data source inputs.
void AM1DRunningAverageFilterAB::setInputDataSourcesImplementation(const QList<AMDataSource*>& dataSources) {

	// disconnect connections from old source, if it exists.
	if(inputSource_) {
		disconnect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
		disconnect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
		disconnect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));
	}

	if(dataSources.isEmpty()) {
		inputSource_ = 0;
		sources_.clear();

		axes_[0] = AMAxisInfo("invalid", 0, "No input data");
		setDescription("-- No input data --");
	}

	// we know that this will only be called with valid input source
	else {
		inputSource_ = dataSources.at(0);
		sources_ = dataSources;

		axes_[0] = inputSource_->axisInfoAt(0);

		setDescription(QString("Running Average of %1")
					   .arg(inputSource_->name()));

		connect(inputSource_->signalSource(), SIGNAL(valuesChanged(AMnDIndex,AMnDIndex)), this, SLOT(onInputSourceValuesChanged(AMnDIndex,AMnDIndex)));
		connect(inputSource_->signalSource(), SIGNAL(sizeChanged(int)), this, SLOT(onInputSourceSizeChanged()));
		connect(inputSource_->signalSource(), SIGNAL(stateChanged(int)), this, SLOT(onInputSourceStateChanged()));

	}

	reviewState();

	emitSizeChanged(0);
	emitValuesChanged();
	emitAxisInfoChanged(0);
	emitInfoChanged();
}
Exemplo n.º 11
0
/// Connected to be called when the state() flags of any input source change
void AM1DRunningAverageFilterAB::onInputSourceStateChanged() {

	// just in case the size has changed while the input source was invalid, and now it's going valid.  Do we need this? probably not, if the input source is well behaved. But it's pretty inexpensive to do it twice... and we know we'll get the size right everytime it goes valid.
	onInputSourceSizeChanged();
	reviewState();
}