示例#1
0
std::string DPSketch::getSketchStats() const
{
    std::stringstream ss;
    ss << "[DPSketch:";
    ss << " #layers: " << getNumLayers();
    ss << " #traces: " << getNumTraces();
    ss << " #points: " << getNumPoints();
    ss << "]";
    ss << std::endl;
    return ss.str();
}
示例#2
0
// ind start from zero
float *SpecData::getTrace(int ind, int npts) {

   float *data = specStruct->data;
   if(!data) {
	Winfoprintf("%s: No data!", key.c_str());
	return NULL;
   }

   int ntraces = getNumTraces();
   int np = specStruct->matrix[0];

   if(ind > ntraces) {
	Winfoprintf("Index %d out of range (1-%d)!", ind, ntraces);
	return NULL; 
   }
   if(np != npts) {
	Winfoprintf("Data size %d does not match %d!", npts, np);
	return NULL; 
   }

   return &(data[(ind)*np]);

}
/******************************************************************************
* AUTHOR		: Bharath A.
* DATE			: 03-SEP-2007
* NAME			: scale
* DESCRIPTION	: scales the tracegroup according to the x and y scale factors.
*				  After scaling, the tracegroup is translated in order to
*				  preserve the "cornerToPreserve".
* ARGUMENTS		: xScaleFactor - factor by which x dimension has to be scaled
*				  yScaleFactor - factor by which y dimension has to be scaled
*				  cornerToPreserve - corner to be retained after scaling
* RETURNS		: SUCCESS on successful scale operation
* NOTES			:
* CHANGE HISTROY
* Author			Date				Description of change
******************************************************************************/
int LTKTraceGroup::scale(float xScaleFactor, float yScaleFactor,
                          TGCORNER cornerToPreserve)
{

	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
		"Enter: LTKTraceGroup::scale()"<<endl;



	LTKTrace trace;
	vector<LTKTrace> scaledTracesVec;	// holds the scaled traces

	floatVector scaledXVec;				//	scaled x channel values of a trace
	floatVector scaledYVec;				//	scaled y channel values of a trace

	float x=0.0f;
    float y=0.0f;
	float xToPreserve=0.0f;
    float yToPreserve=0.0f;
	float xMin=0.0f;
	float yMin=0.0f;
	float xMax=0.0f;
	float yMax=0.0f;

	int numTraces=0;
	int traceIndex=0;
    int index=0;
	int numPoints=0;
	int errorCode=0;

	if(xScaleFactor <= 0)
	{
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) <<
        "Error: "<<EINVALID_X_SCALE_FACTOR <<": "<<
		getErrorMessage(EINVALID_X_SCALE_FACTOR) <<
		"LTKTraceGroup::scale()"<<endl;

		LTKReturnError(EINVALID_X_SCALE_FACTOR);
	}

	if(yScaleFactor <= 0)
	{
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) <<
        "Error: "<<EINVALID_Y_SCALE_FACTOR <<": "<<
		getErrorMessage(EINVALID_Y_SCALE_FACTOR) <<
		"LTKTraceGroup::scale()"<<endl;

		LTKReturnError(EINVALID_Y_SCALE_FACTOR);
	}

    errorCode = getBoundingBox(xMin, yMin, xMax, yMax);

	if( errorCode != SUCCESS )
	{
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) <<
        "Error: LTKTraceGroup::scale()"<<endl;

		LTKReturnError(errorCode);
	}

	switch ( cornerToPreserve )
	{

		case XMIN_YMIN:

			xToPreserve = xMin;
			yToPreserve = yMin;

			break;

		case XMIN_YMAX:

			xToPreserve=xMin;
			yToPreserve=yMax;

			break;


		case XMAX_YMIN:

			xToPreserve=xMax;
			yToPreserve=yMin;

			break;


		case XMAX_YMAX:
			xToPreserve=xMax;
			yToPreserve=yMax;

			break;


		default: break;//define an exception enum input validation

	}

    numTraces = getNumTraces();
    for(traceIndex=0; traceIndex < numTraces; ++traceIndex)
    {

		getTraceAt(traceIndex, trace);

		floatVector xVec;
		
		//no error handling required as the bounding box is found
        trace.getChannelValues(X_CHANNEL_NAME, xVec);

       
		floatVector yVec;
		
        trace.getChannelValues(Y_CHANNEL_NAME, yVec);

        
		numPoints = xVec.size();

		for(index=0; index < numPoints; ++index)
		{
			//the additive term is to translate back the scaled tracegroup
			//so that the corner asked for is preserved
			x= ( (xVec.at(index)*xScaleFactor)/m_xScaleFactor) +
        		 (xToPreserve*(1-(xScaleFactor/m_xScaleFactor)) );

			scaledXVec.push_back(x);

			//the additive term is to translate back the scaled tracegroup
			//so that the corner asked for is preserved
			y= ( (yVec.at(index)*yScaleFactor)/m_yScaleFactor) +
			     (yToPreserve*(1-(yScaleFactor/m_yScaleFactor)) );

            scaledYVec.push_back(y);
		}
		
		
		trace.reassignChannelValues(X_CHANNEL_NAME, scaledXVec);

		trace.reassignChannelValues(Y_CHANNEL_NAME, scaledYVec);

		scaledXVec.clear();

		scaledYVec.clear();

		scaledTracesVec.push_back(trace);

    }

	m_traceVector = scaledTracesVec;

	m_xScaleFactor = xScaleFactor;
	m_yScaleFactor = yScaleFactor;


	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
		"Exit: LTKTraceGroup::scale()"<<endl;

	return SUCCESS;
}
/******************************************************************************
* AUTHOR		: Bharath A.
* DATE			: 03-SEP-2007
* NAME			: translateTo
* DESCRIPTION	: translates the tracegroup so that the "referenceCorner" is
				  moved to (x,y)
* ARGUMENTS		: x: x value of point to which referenceCorner has to be moved
*				  y: y value of point to which referenceCorner has to be moved
*				  referenceCorner - the reference corner in the tracegroup that
				  has to be moved to (x,y)
* RETURNS		: SUCCESS on successful translation operation
* NOTES			:
* CHANGE HISTROY
* Author			Date				Description of change
*******************************************************************************/
int LTKTraceGroup::translateTo(float x,float y,TGCORNER referenceCorner)
{

	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
		"Enter: LTKTraceGroup::translateTo()"<<endl;

	LTKTrace trace;

	vector<LTKTrace> translatedTracesVec;	// holds the translated traces

	floatVector translatedXVec;				//	translated x channel values of a trace
	floatVector translatedYVec;				//	translated y channel values of a trace

	float xValue, yValue;
	float xReference, yReference;
	float xMin=0.0f;
	float yMin=0.0f;
	float xMax=0.0f;
	float yMax=0.0f;

	int errorCode;
	int traceIndex, index;
	int numPoints;


	if((errorCode = getBoundingBox(xMin,yMin,xMax,yMax))!=SUCCESS)
	{
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) <<
           "Error: LTKTraceGroup::translateTo()"<<endl;

		LTKReturnError(errorCode);
	}

	switch(referenceCorner)
	{

		case XMIN_YMIN:

			xReference=xMin;
			yReference=yMin;
			break;

		case XMIN_YMAX:

			xReference=xMin;
			yReference=yMax;

			break;


		case XMAX_YMIN:

			xReference=xMax;
			yReference=yMin;

			break;


		case XMAX_YMAX:
			xReference=xMax;
			yReference=yMax;

			break;


		default: break;//define an exception

	}

    int numTraces = getNumTraces();
    for(traceIndex=0; traceIndex < numTraces; ++traceIndex)
    {
        getTraceAt(traceIndex, trace);
		
		floatVector xVec;
		
		//no error handling required as the bounding box is found
        trace.getChannelValues(X_CHANNEL_NAME, xVec);

        
		floatVector yVec;
		
        trace.getChannelValues(Y_CHANNEL_NAME, yVec);

        
		numPoints = xVec.size();

		for(index=0; index < numPoints; index++)
		{

			xValue=xVec.at(index)+(x-xReference);
			translatedXVec.push_back(xValue);

			yValue=yVec.at(index)+(y-yReference);
			translatedYVec.push_back(yValue);

		}

		trace.reassignChannelValues(X_CHANNEL_NAME,translatedXVec);

		trace.reassignChannelValues(Y_CHANNEL_NAME,translatedYVec);

		translatedXVec.clear();

		translatedYVec.clear();

		translatedTracesVec.push_back(trace);

    }

	m_traceVector=translatedTracesVec;

	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
		"Exit: LTKTraceGroup::translateTo()"<<endl;

	return SUCCESS;

}
/******************************************************************************
* AUTHOR		: Balaji R.
* DATE			: 23-DEC-2004
* NAME			: getBoundingBox
* DESCRIPTION	: gets the bounding box of the incoming trace group
* ARGUMENTS		: inTraceGroup - incoming trace group
* RETURNS		: SUCCESS on successful get operation
* NOTES			:
* CHANGE HISTROY
* Author			Date				Description of change
*******************************************************************************/
int LTKTraceGroup::getBoundingBox(float& outXMin,float& outYMin,
                    float& outXMax,float& outYMax) const
{
	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
		"Enter: LTKTraceGroup::getBoundingBox()"<<endl;

	int numTraces = getNumTraces();	//	number of traces in the trace group

	int numPoints = -1;				//	number of points in a trace

	int pointIndex = -1;			//	variable to loop over points of a trace

	int errorCode;

	if ( numTraces == 0 )
	{
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) <<
        "Error: "<<EEMPTY_TRACE_GROUP <<": "<<
		getErrorMessage(EEMPTY_TRACE_GROUP) <<
		"LTKTraceGroup::getBoundingBox()"<<endl;

		LTKReturnError(EEMPTY_TRACE_GROUP);
	}


	outXMin = outYMin = FLT_MAX;
	outXMax = outYMax = -FLT_MAX;


	for(int traceIndex = 0 ; traceIndex < numTraces; ++traceIndex)
	{
		const LTKTrace& tempTrace = m_traceVector[traceIndex];
		
       	floatVector xVec;
		
        errorCode = tempTrace.getChannelValues(X_CHANNEL_NAME, xVec);
        
        if ( errorCode != SUCCESS )
        {
			LOG( LTKLogger::LTK_LOGLEVEL_ERR) <<
	        "Error: LTKTraceGroup::getBoundingBox()"<<endl;

            LTKReturnError(errorCode);
        }

		floatVector yVec;
        errorCode= tempTrace.getChannelValues(Y_CHANNEL_NAME, yVec);
        if ( errorCode != SUCCESS )
        {
			LOG( LTKLogger::LTK_LOGLEVEL_ERR) <<
	        "Error: LTKTraceGroup::getBoundingBox()"<<endl;

            LTKReturnError(errorCode);
        }

		numPoints = xVec.size();

		for(pointIndex =0 ; pointIndex < numPoints; pointIndex++)
		{
			float x,y;

			x = xVec[pointIndex];
			y = yVec[pointIndex];


			if ( x < outXMin )
			{
				outXMin = x;
			}

			if ( x > outXMax )
			{
				outXMax = x;
			}

			if ( y < outYMin )
			{
				outYMin = y;
			}

			if ( y > outYMax )
			{
				outYMax = y;
			}
		}

	}

	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) <<
		"Exit: LTKTraceGroup::getBoundingBox()"<<endl;


	return SUCCESS;

}