示例#1
0
returnValue PlotWindow::getAutoScaleYLimits(	const VariablesGrid& dataGridY,
												PlotFormat plotFormat,
												double& lowerLimit,
												double& upperLimit
												) const
{
	double maxValue  = dataGridY.getMax( );
	double minValue  = dataGridY.getMin( );
	double meanValue = dataGridY.getMean( );

	if ( ( acadoIsZero( maxValue ) == BT_TRUE ) && ( acadoIsZero( minValue ) == BT_TRUE ) )
		meanValue = 0.1 / 0.025;

	lowerLimit = minValue - 0.1*( maxValue-minValue ) - 0.025*meanValue - 1.0e-8;
	upperLimit = maxValue + 0.1*( maxValue-minValue ) + 0.025*meanValue + 1.0e-8;

	
	if ( ( plotFormat == PF_LOG ) || ( plotFormat == PF_LOG_LOG ) )
	{
		if ( ( acadoIsStrictlyGreater( minValue,0.0, ZERO ) == BT_TRUE ) && ( acadoIsGreater( lowerLimit,0.0, ZERO ) == BT_FALSE ) )
		{
			lowerLimit = ( minValue + acadoMin( minValue,EPS ) ) / sqrt(10.0);
			upperLimit = upperLimit * sqrt(10.0);
		}
	}
	else
	{
		if ( ( acadoIsStrictlyGreater( minValue,0.0, ZERO ) == BT_TRUE ) && ( acadoIsGreater( lowerLimit,0.0, ZERO ) == BT_FALSE ) )
			lowerLimit = 0.0;

		if ( ( acadoIsStrictlySmaller( maxValue,0.0 ) == BT_TRUE ) && ( acadoIsSmaller( upperLimit,0.0 ) == BT_FALSE ) )
			upperLimit = 0.0;
	}
	
	return SUCCESSFUL_RETURN;
}
示例#2
0
// uses a simple O(n^2) algorithm for sorting
returnValue VariablesGrid::merge(	const VariablesGrid& arg,
									MergeMethod _mergeMethod,
									BooleanType keepOverlap
									)
{
	if ( ( keepOverlap == BT_FALSE ) && ( _mergeMethod == MM_DUPLICATE ) )
		return ACADOERROR( RET_INVALID_ARGUMENTS );

	// nothing to do if arg or object itself is empty
	if ( arg.getNumPoints( ) == 0 )
		return SUCCESSFUL_RETURN;

	if ( getNumPoints( ) == 0 )
	{
		*this = arg;
		return SUCCESSFUL_RETURN;
	}

	// use append if grids do not overlap
	if ( acadoIsSmaller( getLastTime( ),arg.getFirstTime( ) ) == BT_TRUE )
		return appendTimes( arg,_mergeMethod );


	// construct merged grid
	VariablesGrid mergedGrid;
	uint j = 0;
	BooleanType overlapping = BT_FALSE;

	for( uint i=0; i<getNumPoints( ); ++i )
	{
		if ( keepOverlap == BT_FALSE )
			overlapping = arg.isInInterval( getTime(i) );

		// add all grid points of argument grid that are smaller 
		// then current one of original grid
		while ( ( j < arg.getNumPoints( ) ) && 
				( acadoIsStrictlySmaller( arg.getTime( j ),getTime( i ) ) == BT_TRUE ) )
		{
			if ( ( overlapping == BT_FALSE ) ||
				 ( ( overlapping == BT_TRUE ) && ( _mergeMethod == MM_REPLACE ) ) )
			{
				mergedGrid.addMatrix( *(arg.values[j]),arg.getTime( j ) );
			}

			++j;
		}

		// merge current grid points if they are at equal times
		if ( acadoIsEqual( arg.getTime( j ),getTime( i ) ) == BT_TRUE )
		{
			switch ( _mergeMethod )
			{
				case MM_KEEP:
					mergedGrid.addMatrix( *(values[i]),getTime( i ) );
					break;
	
				case MM_REPLACE:
					mergedGrid.addMatrix( *(arg.values[j]),arg.getTime( j ) );
					break;
	
				case MM_DUPLICATE:
					mergedGrid.addMatrix( *(values[i]),getTime( i ) );
					mergedGrid.addMatrix( *(arg.values[j]),arg.getTime( j ) );
					break;
			}
			++j;
		}
		else
		{
			// add current grid point of original grid
			if ( ( overlapping == BT_FALSE ) ||
				 ( ( overlapping == BT_TRUE ) && ( _mergeMethod == MM_KEEP ) ) )
			{
				mergedGrid.addMatrix( *(values[i]),getTime( i ) );//arg.
			}
		}
	}

	// add all remaining grid points of argument grid
	while ( j < arg.getNumPoints( ) )
	{
		if ( acadoIsStrictlyGreater( arg.getTime(j),getLastTime() ) == BT_TRUE )
			mergedGrid.addMatrix( *(arg.values[j]),arg.getTime( j ) );

		++j;
	}

	// merged grid becomes current grid
	*this = mergedGrid;

	return SUCCESSFUL_RETURN;
}