public override SimpleDatum GetData(bool bNormalize, out int nDataLen) { int nScale = 4; nDataLen = 4; Valuemap data = new Valuemap(1, 6, 1); data.SetPixel(0, 0, getValue(m_dfX, -MAX_X, MAX_X, bNormalize)); data.SetPixel(0, 1, getValue(m_dfXDot, -MAX_X * nScale, MAX_X * nScale, bNormalize)); data.SetPixel(0, 2, getValue(m_dfTheta, -MAX_THETA, MAX_THETA, bNormalize)); data.SetPixel(0, 3, getValue(m_dfThetaDot, -MAX_THETA * nScale * 2, MAX_THETA * nScale * 2, bNormalize)); data.SetPixel(0, 4, getValue(m_dfForceMag, -100, 100, bNormalize)); data.SetPixel(0, 5, m_nSteps); return(new SimpleDatum(data)); }
/// <summary> /// Query the next data in the streaming database. /// </summary> /// <param name="nWait">Specfies the maximum amount of time (in ms.) to wait for data.</param> /// <returns>A simple datum containing the data is returned.</returns> public SimpleDatum Query(int nWait) { if (!m_colData.WaitForCount(nWait)) { return(null); } int nCount = m_nQueryCount * m_nFieldCount; Valuemap vals = new Valuemap(1, m_nFieldCount, m_nQueryCount); double[] rgLast = null; for (int i = 0; i < m_nQueryCount; i++) { DataItem di = m_colData.GetData(nWait); if (di == null) { throw new Exception("The data item should not be null!"); } double[] rgItem = di.GetData(); for (int j = 0; j < rgItem.Length; j++) { vals.SetPixel(i, j, rgItem[j]); } rgLast = rgItem; } SimpleDatum sd = new SimpleDatum(vals); sd.TimeStamp = Utility.ConvertTimeFromMinutes(rgLast[0]); return(sd); }
private Tuple <DirectBitmap, SimpleDatum> getData(COLORTYPE ct, int nWid, int nHt, int nOffset, int nDownsample, byte[] rg, bool bPreprocess, bool bGetAction, bool bForceGray) { int nChannels = (bPreprocess || bForceGray) ? 1 : 3; int nSize = Math.Min(nWid, nHt); int nDsSize = nSize / nDownsample; int nX = 0; int nY = 0; bool bY = false; bool bX = false; if (m_bmpRaw != null && (m_bmpRaw.Width != nWid || m_bmpRaw.Height != nHt)) { m_bmpRaw.Dispose(); m_bmpRaw = null; } if (m_bmpActionRaw != null && (m_bmpActionRaw.Width != nDsSize || m_bmpActionRaw.Height != nDsSize)) { m_bmpActionRaw.Dispose(); m_bmpActionRaw = null; } if (m_bmpRaw == null) { m_bmpRaw = new DirectBitmap(nWid, nHt); } if (m_bmpActionRaw == null) { m_bmpActionRaw = new DirectBitmap(nDsSize, nDsSize); } DirectBitmap bmp = m_bmpRaw; Valuemap dataV = null; Bytemap dataB = null; if (bGetAction) { if (m_bPreprocess) { dataV = new Valuemap(nChannels, nDsSize, nDsSize); } else { dataB = new Bytemap(nChannels, nDsSize, nDsSize); } } for (int y = 0; y < nHt; y++) { if (y % nDownsample == 0 && y > nOffset && y < nOffset + nSize) { bY = true; } else { bY = false; } for (int x = 0; x < nWid; x++) { int nIdx = (y * nWid) + x; int nR = rg[nIdx]; int nG = nR; int nB = nR; if (x % nDownsample == 0) { bX = true; } else { bX = false; } if (ct == COLORTYPE.CT_COLOR) { nG = rg[nIdx + (nWid * nHt * 1)]; nB = rg[nIdx + (nWid * nHt * 2)]; } Color clr = Color.FromArgb(nR, nG, nB); bmp.SetPixel(x, y, clr); if (bForceGray) { int nClr = (nR + nG + nB) / 3; clr = Color.FromArgb(nClr, nClr, nClr); } if (bY && bX && (dataB != null || dataV != null)) { if (bPreprocess) { if (nR != 144 && nR != 109 && nR != 0) { dataV.SetPixel(nX, nY, 1.0); } } else { dataB.SetPixel(nX, nY, clr); } nX++; } } if (bY) { nX = 0; nY++; } } SimpleDatum sd = null; if (m_bPreprocess) { if (dataV != null) { sd = new SimpleDatum(dataV); } } else { if (dataB != null) { sd = new SimpleDatum(dataB); } } return(new Tuple <DirectBitmap, SimpleDatum>(bmp, sd)); }