float CImageColourCombo2::GetValue(EChannel eChannel) { float f; f = cImageColours[0]->GetValue(eChannel); if (!IsNotANumber(&f)) { return f; } f = cImageColours[1]->GetValue(eChannel); if (!IsNotANumber(&f)) { return f; } return gfNaN; }
BOOL CImageAccessor::MakeColour(SImageColour* psDest, CImageColour* pcColour) { int i; float fValue; SImageColour sTemp; BOOL bValid; void* pvData; CChannelAccessor* pcAccessor; int iSize; CArrayChannelAccessor* pacAccessors; if (GetBufferSize() > sizeof(SImageColour)) { //The colour representation is too big to fit. psDest->Zero(); return FALSE; } bValid = TRUE; pvData = psDest; if (mpcAccessor->GetByteSize() == -1) { return FALSE; } pacAccessors = mpcAccessor->GetAccessors(); for (i = 0; i < pacAccessors->NumElements(); i++) { pcAccessor = pacAccessors->Get(i); fValue = pcColour->GetValue(pcAccessor->miChannel); iSize = pcAccessor->miAccessByteSize; if (iSize < 0) { iSize = 1; } if (!IsNotANumber(&fValue)) { gcTypeConverter.Do(pcAccessor->meAccessType, &sTemp, PT_float, &fValue); ga_memcpy_fast[pcAccessor->miAccessByteSize](pvData, &sTemp); } else { //There are more channels in the accessor than are provided by the colour. //The destination will not be usable. bValid = FALSE; } pvData = (void*)(size_t)(((int)(size_t)pvData) + iSize); } return bValid; }
STD_ERROR DLLEXPORT GRAPH_Plot( void *Data , int iYAxisPrecision ) { STD_ERROR StdError = {0}; int panel = 0; int numberOfPoints = 0, numberOfTraces = 0, maxNumberOfPoints = 0; int index = 0, tempIndex = 0, totalIndex = 0, PlotIndex = 0; int *pPointCounter = NULL; double *pSinglePlot = NULL; double lfCurrentX = 0.0, lfStepX = 0.0; double lfY_axis_min = 0.0, lfY_axis_max = 0.0; tsPlotGraphData *pData = NULL; IF ( (Data == NULL) , "Pointer passed NULL"); pData = (tsPlotGraphData*)Data; IF( ( pData->TraceList == NULL ) , "No traces added."); IF( ( pData->numberOfTraces == 0 ) , "No traces added."); panel = pData->panel; numberOfTraces = pData->numberOfTraces; lfCurrentX = pData->start_x; if ( pData->numberOfPoints ) lfStepX = ( pData->stop_x - pData->start_x ) / (double)(pData->numberOfPoints-1); else lfStepX = pData->stop_x - pData->start_x; ProcessDrawEvents(); numberOfPoints = pData->numberOfPoints; if ( numberOfPoints == 0 ) { for ( index = 0 ; index < numberOfTraces ; index++ ) if ( pData->TraceList[index].numberOfPoints > numberOfPoints ) numberOfPoints = pData->TraceList[index].numberOfPoints; } maxNumberOfPoints = numberOfPoints * numberOfTraces; CALLOC_ERR( pSinglePlot , maxNumberOfPoints+128 , sizeof(double)); CALLOC_ERR( pPointCounter , numberOfTraces+1 , sizeof(int)); IF (( pSinglePlot == NULL ), "Can't allocate Memory."); IF (( pPointCounter == NULL ), "Can't allocate Memory."); SetCtrlAttribute ( panel , pData->control , ATTR_NUM_TRACES , numberOfTraces ); SetCtrlAttribute ( panel , pData->control , ATTR_SCROLL_MODE , VAL_CONTINUOUS ); SetCtrlAttribute (panel, pData->control, ATTR_GRID_COLOR, VAL_BLACK); SetCtrlAttribute ( panel , pData->control , ATTR_POINTS_PER_SCREEN , numberOfPoints ); lfY_axis_min = pData->y_axis_min; lfY_axis_max = pData->y_axis_max; if (( IsNotANumber (lfY_axis_min) == 0 ) && ( IsNotANumber (lfY_axis_max) == 0 ) && ( fabs( lfY_axis_min ) > 1E-20 ) && ( fabs( lfY_axis_max ) > 1E-20 )) { SetAxisScalingMode (panel, pData->control, VAL_LEFT_YAXIS,VAL_MANUAL, lfY_axis_min , lfY_axis_max); } SetAxisScalingMode (panel, pData->control, VAL_BOTTOM_XAXIS ,VAL_MANUAL, pData->start_x , lfStepX ); SetCtrlAttribute (panel, pData->control, ATTR_YPRECISION , iYAxisPrecision ); if ( pData->szY_AxisName ) SetCtrlAttribute ( panel , pData->control , ATTR_YNAME , pData->szY_AxisName ); if ( pData->szX_AxisName ) SetCtrlAttribute (panel, pData->control , ATTR_XNAME , pData->szX_AxisName ); SetCtrlAttribute ( panel , pData->control , ATTR_LEGEND_NUM_VISIBLE_ITEMS , numberOfTraces ); for ( index = 0 ; index < numberOfTraces ; index++ ) { SetTraceAttribute ( panel , pData->control , index+1 , ATTR_TRACE_COLOR , pData->TraceList[index].trace_color ); SetTraceAttributeEx ( panel , pData->control , index+1 , ATTR_TRACE_LG_TEXT , pData->TraceList[index].szTraceName ); SetTraceAttribute ( panel , pData->control , index+1 , ATTR_TRACE_LG_TEXT_COLOR , VAL_BLACK ); SetTraceAttribute ( panel , pData->control , index+1 , ATTR_TRACE_LG_VISIBLE , 1 ); if ( pData->TraceList[index].iThickness > 0 ) SetTraceAttribute (panel, pData->control, index+1 ,ATTR_TRACE_THICKNESS, pData->TraceList[index].iThickness ); SetTraceAttribute ( panel , pData->control , index+1 , ATTR_TRACE_VISIBLE , 1 ); } for ( PlotIndex = 0 ; PlotIndex < numberOfPoints ; PlotIndex++ ) { for ( index = 0 ; index < numberOfTraces ; index++ ) { if ( ( lfCurrentX >= pData->TraceList[index].start_x ) && ( pPointCounter[index] < pData->TraceList[index].numberOfPoints ) && ( pPointCounter[index] < numberOfPoints )) { tempIndex = pPointCounter[index] + pData->TraceList[index].startTraceFromIndex; pSinglePlot[totalIndex++] = pData->TraceList[index].Trace[tempIndex]; pPointCounter[index]++; } else { tempIndex = pData->TraceList[index].startTraceFromIndex; pSinglePlot[totalIndex++] = pData->TraceList[index].Trace[tempIndex]; pPointCounter[index]++; } } lfCurrentX += lfStepX; } PlotStripChart ( panel , pData->control , pSinglePlot , totalIndex , 0 , 0 , VAL_DOUBLE ); Error: if ( pSinglePlot ) free(pSinglePlot); if ( pPointCounter ) free( pPointCounter ); ProcessDrawEvents(); return StdError; }