Beispiel #1
0
void halg::AnimPloter::paintEvent( QPaintEvent * event )
{
    if ( m_animPlots.empty( ) ) return;

    bool hasNewFrames = false;
    for (auto plotAnim : m_animPlots)
    {
        Plot * plot;
        if ( m_frameCount < plotAnim.size( ) )
        {
            plot = plotAnim[ m_frameCount ];
            hasNewFrames = true;
        }
        else
        {
            plot = plotAnim[ plotAnim.size( ) - 1 ];
        }
        DrawPlot( plot );
    }
    if ( hasNewFrames )
    {
        ++m_frameCount;
    }
    else
    {
        m_timer.stop( );
    }
    Ploter::paintEvent( event );
}
Beispiel #2
0
void FreqWindow::OnAxisChoice(wxCommandEvent & event)
{
   mLogAxis = (mAxisChoice->GetSelection())?true:false;

   DrawPlot();
   mFreqPlot->Refresh(true);
}
Beispiel #3
0
void halg::Ploter::paintEvent( QPaintEvent * )
{
    for(auto plot: m_plots)
    {
        DrawPlot( plot );
    }
}
Beispiel #4
0
void Widget::on_keyErr_clicked()
{
    DWORD keyBlobLen, blockLen = 0;
    BYTE *keyBlob, *srcData, *newData, *blockData1, *blockData2;
    HCRYPTPROV hCryptProv;
    HCRYPTKEY hKey, dhKey;
    QVector<int> values;
    QFile myFile(fName);

    plot->clear();
    if (myFile.exists())
        myFile.open(QIODevice::ReadOnly);
    else
    {
        QMessageBox::critical(0, "Ошибка", "Файл не выбран", QMessageBox::Ok);
        return;
    }
    CryptAcquireContext(&hCryptProv, NULL, MS_DEF_RSA_SCHANNEL_PROV, PROV_RSA_SCHANNEL, CRYPT_VERIFYCONTEXT);
    CryptGenKey(hCryptProv, CALG_AES_256, 0, &hKey);
    CryptEncrypt(hKey, 0, true, 0, NULL, &blockLen, myFile.size());
    srcData = new BYTE[block * blockLen];
    newData = new BYTE[block * blockLen];
    blockData1  = new BYTE[blockLen];
    blockData2  = new BYTE[blockLen];
    myFile.read((char*)srcData, block * blockLen);
    myFile.close();
    memcpy((char*)newData, (char*)srcData, block * blockLen);
    newData[0] = -newData[0];
    CryptDuplicateKey(hKey, NULL, 0, &dhKey);
    CryptExportKey(dhKey, 0, SIMPLEBLOB, 0, NULL, &keyBlobLen);
    keyBlob = new BYTE[keyBlobLen];
    CryptExportKey(dhKey, 0, SIMPLEBLOB, 0, keyBlob, &keyBlobLen);
    keyBlob[0] = -keyBlob[0];
    CryptImportKey(hCryptProv, keyBlob, keyBlobLen, 0, 0, &dhKey);
    for (uint i = 0; i < (block * blockLen); i++)
    {
        CryptEncrypt(hKey, 0, i < 2, 0, srcData + i, &blockLen, block * blockLen);
        CryptEncrypt(dhKey, 0, i < 2, 0, newData + i, &blockLen, block * blockLen);
    }
    for(uint i = 0; i < (block * blockLen); i += blockLen)
    {
        int k = 0;
        memcpy(blockData1, srcData + i, blockLen);
        memcpy(blockData2, newData + i, blockLen);
        for (uint j = i; j < (i + blockLen); j++)
            k += trueBitsCount(srcData[j] ^ newData[j]);
        values.push_back(k);
    }
    delete[] newData;
    delete[] srcData;
    delete[] blockData1;
    delete[] blockData2;
    delete[] keyBlob;
    CryptReleaseContext(hCryptProv, 0);
    CryptDestroyKey(hKey);
    CryptDestroyKey(dhKey);
    DrawPlot(plot, values);
    plot->show();
}
void FreqWindow::OnSize(wxSizeEvent & WXUNUSED(event))
{
   Layout();

   DrawPlot();

   Refresh(true);
}
Beispiel #6
0
//*******************************************************************************************************/
//* FileName:		clPlot.cpp
//*
//* Contents:		Implementation of clPlot, axis, legend, serie and timeaxis
//*
//* NOTE 1:			Only a minimum of parameter validation is implemented to save time since this plot is 
//*					time critical.
//*
//* NOTE 2:			All functionality is not fully implemented.
//*
//* Author:			Jan Vidar Berger
//*******************************************************************************************************/
//* 12.feb.98	Jan Vidar Berger	Implemented flicker free drawing. Thanks to John Kim for providing 
//*									the CGridMemDC and to Keith Rule, the author of CMemDC.
//*******************************************************************************************************/

#include "stdafx.h"
#include "clPlot.h"
#include "GridMemDC.h"

#include "malloc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

long	clPlot::m_lMaxDataPrSerie;	// max allowed data pr. serie.
long	clPlot::m_lMaxDataTotal;	// max allowed data total.

//*******************************************************************************************************/
//* time axis threshold. contains grid and label intervals to be used within specified
//* seconds pr. pixels thresholds. The array is terminated by a 'bIAmInUse'=FALSE.
//*******************************************************************************************************/
struct{
	BOOL	bIAmInUse;					// indicate valid entry, last=FALSE
	long	lgridinterval;				// grid line interval in seconds
	long	llabelinterval;				// time label interval in seconds
	long	lmodethreshold;				// mode threshold in seconds pr. pixel
}gridsetting[]={
	TRUE, 1, 4,	0,						// 0: pr. second

	FALSE, 1, 1,0,						// last entry in table
};

//*******************************************************************************************************/
//* Function:		serie::serie
//*******************************************************************************************************/
serie::serie()
{
	m_bIAmInUse		= FALSE;
	m_color			= RGB(0,0,0);
	m_iLineStyle	= PS_SOLID;
	m_bRightAxisAlign	= FALSE;
	m_lNoValues		= 0;
	m_lbegin		= 0;
	m_lend			= 0;
	m_pvalues		= NULL;

}

//*******************************************************************************************************/
//* Function:		serie::~serie
//*******************************************************************************************************/
serie::~serie()
{
	if(m_pvalues !=NULL)
		free(m_pvalues);
}

//*******************************************************************************************************/
//* Function:		serie::AddPoint
//*
//* Description:	AddPoint add new data to the end of a data serie. It will simply append the data,
//*					update the list index and get out. 
//*
//*					This function will also call realloc or malloc to re-size or create the plot array as
//*					needed.
//*
//*					The nice thing about circular lists is that they are multi thread enabled as is. You
//*					must however implement a syncronization mechanism if more than one thread is supposed
//*					to enter data into the plot.
//*
//* Parameters:		valuetime		Time (x value).
//*					y				y value
//*
//* Return Value:	-none-
//*
//* Author:			Jan Vidar Berger
//*******************************************************************************************************/
void serie::AddPoint(CTime &valuetime , double &y)
{
	if(m_lNoValues > 0)
		m_pvalues = (value*)realloc(m_pvalues, (m_lNoValues+1)*sizeof(value));
	else
		m_pvalues = (value*)malloc((m_lNoValues+1)*sizeof(value));

	m_pvalues[m_lend].ValueTime = valuetime;
	m_pvalues[m_lend].dValue	= y;
	m_lNoValues++;
	m_lend++;
	if(m_lend >= clPlot::m_lMaxDataPrSerie)
		m_lend=0;
	if(m_lbegin == m_lend){
		m_lbegin++;
		if(m_lbegin >= clPlot::m_lMaxDataPrSerie)
			m_lbegin=0;
	}
}

//*******************************************************************************************************/
//* Function:		serie::Reset
//*
//* Description:	Reset the serie. Remove data and reset indexes and pointers.
//*
//* Parameters:		-none-
//*
//* Return Value:	-none-
//*
//* Author:			Jan Vidar Berger
//*******************************************************************************************************/
void serie::Reset()
{
	m_lNoValues=0;

	if(m_pvalues !=NULL)
		free(m_pvalues);

	m_pvalues = NULL;

	m_lbegin		= 0;
	m_lend			= 0;
}

//*******************************************************************************************************/
//*******************************************************************************************************/
clPlot::clPlot()
{
	m_ctlBkColor		= RGB(255,255,255);
	m_plotBkColor		= RGB(255,255,255);
	m_legendBkColor		= RGB(255,255,255);
	m_gridColor			= RGB(127,127,127);
	m_bctlBorder		= TRUE;
	m_bplotBorder		= TRUE;
	m_blegendBorder		= TRUE;
	m_bPrimaryLegend	= FALSE;
	m_bSecondaryLegend	= FALSE;
	m_bAxisLY			= TRUE;
	m_bAxisRY			= TRUE;
	m_bAxisBX			= TRUE;
	m_bAutoScrollX		= FALSE;
	m_bSimMode			= FALSE;

	m_lMaxDataPrSerie	= 10000;
	m_lMaxDataTotal		= 100000;
	m_dNoData			= 0.0;

	m_dzoom				= 1.0;
	
	lArraySize			= 1000;			// only points with differebt x,y will be put into the array

	pLineArray			= new CPoint[lArraySize];
	SetBXRange(CTime::GetCurrentTime()-CTimeSpan(60),CTime::GetCurrentTime());

	m_logFont.lfHeight			= -13;
	m_logFont.lfWidth			= 0;
	m_logFont.lfEscapement		= 0;
	m_logFont.lfOrientation		= 0;
	m_logFont.lfWeight			= 400;
	m_logFont.lfItalic			= FALSE;
	m_logFont.lfUnderline		= FALSE;
	m_logFont.lfStrikeOut		= FALSE;
	m_logFont.lfCharSet			= ANSI_CHARSET;
	m_logFont.lfOutPrecision	= OUT_DEFAULT_PRECIS;
	m_logFont.lfClipPrecision	= CLIP_DEFAULT_PRECIS;
	m_logFont.lfQuality			= PROOF_QUALITY;
	m_logFont.lfPitchAndFamily	= DEFAULT_PITCH;
	wcscpy(m_logFont.lfFaceName,_T("Ariel"));

	m_zoomFont.lfHeight			= -13;
	m_zoomFont.lfWidth			= 0;
	m_zoomFont.lfEscapement		= 0;
	m_zoomFont.lfOrientation		= 0;
	m_zoomFont.lfWeight			= 400;
	m_zoomFont.lfItalic			= FALSE;
	m_zoomFont.lfUnderline		= FALSE;
	m_zoomFont.lfStrikeOut		= FALSE;
	m_zoomFont.lfCharSet			= ANSI_CHARSET;
	m_zoomFont.lfOutPrecision	= OUT_DEFAULT_PRECIS;
	m_zoomFont.lfClipPrecision	= CLIP_DEFAULT_PRECIS;
	m_zoomFont.lfQuality			= PROOF_QUALITY;
	m_zoomFont.lfPitchAndFamily	= DEFAULT_PITCH;
	wcscpy(m_zoomFont.lfFaceName,_T("Ariel"));

	m_font.CreateFontIndirect(&m_zoomFont);
}

//*******************************************************************************************************/
//*******************************************************************************************************/
clPlot::~clPlot()
{
	delete [] pLineArray;
}


//*******************************************************************************************************/
//*******************************************************************************************************/
BEGIN_MESSAGE_MAP(clPlot, CWnd)
	//{{AFX_MSG_MAP(clPlot)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//*******************************************************************************************************/
//*******************************************************************************************************/
BOOL clPlot::Create(DWORD dwstyle, CRect &rect, CWnd *pParent, UINT id)
{
	DWORD style = dwstyle & (~WS_BORDER);
	if(dwstyle & WS_BORDER)
		m_bctlBorder=TRUE;
	else
		m_bctlBorder=FALSE;

	if(!CWnd::Create(NULL, _T(""), style, rect, pParent, id, NULL))
		return FALSE;

	
	m_ctlRect = rect;
	pParent->ClientToScreen(m_ctlRect);
	ScreenToClient(m_ctlRect);

	ComputeRects(TRUE);
	return TRUE;
}

//*******************************************************************************************************/
//* Function        : clPlot::ComputeRects
//*
//* Description	    : Compute rects used for internal possitioning of different objects. This function is 
//*					  called when the plot is created or sized.
//*
//* Return type	    : void 
//*
//* Parameter(s)    : bInitialization		indicate wherever parameters that can be changed abu the user
//*											also should be computed.
//*
//* Author          : Jan Vidar Berger
//*******************************************************************************************************/
void clPlot::ComputeRects(BOOL bInitialization)
{
	// adjust the client rect for borders

	//GetClientRect(m_ctlRect);
	CClientDC dc(this);
	int w = 0;
	int n=0;
	CSize z=dc.GetTextExtent(CString("A"));
//	m_TextHeight = z.cy;

	m_dzoom = ((double)m_ctlRect.Height()/(double)z.cy) / 25.0;

	m_zoomFont.lfWidth = (int)(m_logFont.lfWidth * m_dzoom);
	m_zoomFont.lfHeight = (int)(m_logFont.lfHeight * m_dzoom);
	m_font.Detach();
	m_font.CreateFontIndirect(&m_zoomFont);
	CFont *oFont = dc.SelectObject(&m_font);
//	SetFont(&m_font);
	z=dc.GetTextExtent(CString("A"));
	m_TextHeight = z.cy;
	if(m_bctlBorder){
		m_clientRect.left = m_ctlRect.left+2;
		m_clientRect.right = m_ctlRect.right-2;
		m_clientRect.top = m_ctlRect.top+2;
		m_clientRect.bottom = m_ctlRect.bottom-2;
	}else{
		m_clientRect = m_ctlRect;
	}

	if(bInitialization)
	{
		m_iMtop = m_iMbottom = m_clientRect.Height()/10;
		m_iMleft = m_iMright = m_clientRect.Width()/10;
	}

	// compute plot rect.
	m_plotRect.left = m_clientRect.left + m_iMleft;
	m_plotRect.right = m_clientRect.right - m_iMright;
	m_plotRect.top = m_clientRect.top + m_iMtop;
	m_plotRect.bottom = m_clientRect.bottom - m_iMbottom;

	// compute default legend possition

	if(bInitialization)
	{
		m_legendRect.left = m_plotRect.left + (m_iMleft/5);
		m_legendRect.right = m_plotRect.left + (m_plotRect.Width()/5);
		m_legendRect.top = m_plotRect.top - (m_iMtop/2);
		m_legendRect.bottom = m_plotRect.top + (m_iMtop);
		int w = 0;
		int n=0;
		for(int x = 0; x< MAXLEGENDS;x++){
			if(m_primarylegends[x].m_bIAmInUse){
				n++;
				z=dc.GetTextExtent(CString(m_primarylegends[x].m_szTitle));
				if(z.cx > w )
					w=z.cx;
//				m_TextHeight = z.cy;
			}
		}

		m_legendRect.right = m_legendRect.left + 40 + w;
		m_legendRect.bottom = m_legendRect.top + 10 + (m_TextHeight*n);
	}

	// compute left axis area
	m_axisLYRect.left = m_clientRect.left + (m_iMleft/5);
	m_axisLYRect.right = m_plotRect.left;
	m_axisLYRect.top = m_plotRect.top;
	m_axisLYRect.bottom = m_plotRect.bottom;

	// compute right axis area
	m_axisRYRect.left =  m_plotRect.left;
	m_axisRYRect.right = m_clientRect.right - (m_iMright/5);
	m_axisRYRect.top = m_plotRect.top;
	m_axisRYRect.bottom = m_plotRect.bottom;

	// compute bottom axis area
	m_axisBXRect.left = m_plotRect.left;
	m_axisBXRect.right = m_plotRect.right;
	m_axisBXRect.top = m_plotRect.bottom;
	m_axisBXRect.bottom = m_clientRect.bottom - (m_iMbottom/5);

//	if(bInitialization)
//	{
		m_timeaxis.m_dSecondsPrPixel = ((double)(m_timeaxis.m_maxtime.GetTime() - m_timeaxis.m_mintime.GetTime())) / (double)m_plotRect.Width();
		m_leftaxis.m_dValuePrPixel   = ((double)(m_leftaxis.maxrange- m_leftaxis.minrange) / (double)m_plotRect.Height());
		m_rightaxis.m_dValuePrPixel   = ((double)(m_rightaxis.maxrange- m_rightaxis.minrange) / (double)m_plotRect.Height());
//	}
	dc.SelectObject(oFont);
}

//*******************************************************************************************************/
//* Function:		clPlot::OnPaint
//*
//* Description:	This function will create a memory image, call Draw to draw the plot on it, and when
//*					copy the image into memory.
//*
//*					This is fast and provides flicker free plot update.
//*
//* Author:			Jan Vidar Berger
//*******************************************************************************************************/
void clPlot::OnPaint() 
{
        CPaintDC dc(this); // device context for painting
        CGridMemDC  pdc(&dc);  // non flickering painting

        Draw(&pdc);
		
		// Do not call CWnd::OnPaint() for painting messages
}

BOOL clPlot::OnEraseBkgnd(CDC* pDC) 
{
		return FALSE;
}

//*******************************************************************************************************/
//*******************************************************************************************************/
void clPlot::Draw(CDC * dc)
{
	CFont *oFont = dc->SelectObject(&m_font);
	DrawBasic(dc);
	DrawGrid(dc);
	DrawPlot(dc);
	DrawLegend(dc);
	dc->SelectObject(oFont);
}
void FreqWindow::Recalc()
{
   if (!mData || mDataLen < mWindowSize) {
      DrawPlot();
      return;
   }

   SpectrumAnalyst::Algorithm alg =
      SpectrumAnalyst::Algorithm(mAlgChoice->GetSelection());
   int windowFunc = mFuncChoice->GetSelection();

   wxWindow *hadFocus = FindFocus();
   // In wxMac, the skipped window MUST be a top level window.  I'd originally made it
   // just the mProgress window with the idea of preventing user interaction with the
   // controls while the plot was being recalculated.  This doesn't appear to be necessary
   // so just use the the top level window instead.
   {
      Maybe<wxWindowDisabler> blocker;
      if (IsShown())
         blocker.create(this);
      wxYieldIfNeeded();

      mAnalyst->Calculate(alg, windowFunc, mWindowSize, mRate,
         mData.get(), mDataLen,
         &mYMin, &mYMax, mProgress);
   }
   if (hadFocus) {
      hadFocus->SetFocus();
   }

   if (alg == SpectrumAnalyst::Spectrum) {
      if(mYMin < -dBRange)
         mYMin = -dBRange;
      if(mYMax <= -dBRange)
         mYMax = -dBRange + 10.; // it's all out of range, but show a scale.
      else
         mYMax += .5;
   }

   // Prime the scrollbar
   mPanScroller->SetScrollbar(0, (mYMax - mYMin) * 100, (mYMax - mYMin) * 100, 1);

   DrawPlot();
}
Beispiel #8
0
// CDlgPathMOE message handlers
void CDlgPathMOE::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	CRect PlotRect;
	GetClientRect(PlotRect);

	CRect PlotRectOrg = PlotRect;

	if(m_TimeLeft<0)
		m_TimeLeft = 0;

	if(m_TimeRight< m_TimeLeft+30)
		m_TimeRight= m_TimeLeft+30;


	if(Cur_MOE_type1>=0)
	{
	if(Cur_MOE_type2==-1 )
	{
		PlotRect.top += 200;
		PlotRect.bottom -= 35;
		PlotRect.left += 60;
		PlotRect.right -= 100;

		DrawPlot(&dc,Cur_MOE_type1, PlotRect);
	}else
	{
		PlotRect.top += 200;
		PlotRect.bottom = 200+ (PlotRect.bottom-200-35)/2;
		PlotRect.left += 60;
		PlotRect.right -= 100;

		DrawPlot(&dc, Cur_MOE_type1, PlotRect);

		PlotRect.top = PlotRect.bottom+45;
		PlotRect.bottom = PlotRectOrg.bottom -20;
		PlotRect.left = PlotRectOrg.left+60;
		PlotRect.right = PlotRectOrg.right-100;

		DrawPlot(&dc,Cur_MOE_type2, PlotRect);

	}
	}
}
Beispiel #9
0
void FreqWindow::OnSize(wxSizeEvent & event)
{
   Layout();

   mUpdateRect.x = 0;
   mUpdateRect.y = 0;
   mUpdateRect.SetSize( mFreqPlot->GetSize() );
   mPlotRect = mUpdateRect;

   DrawPlot();

   Refresh(true);
}
Beispiel #10
0
void Widget::on_srcTextErr_clicked()
{
    DWORD blockLen = 32; // Хотя должно быть 16ж
    DWORD dataSize;
    HCRYPTPROV hCryptProv;
    HCRYPTKEY hKey;
    uchar srcData[blockLen];
    uchar newData[blockLen];
    QVector<int> values;
    QFile myFile(fName);

    plot->clear();
    if (myFile.exists())
        myFile.open(QIODevice::ReadOnly);
    else
    {
        QMessageBox::critical(0, "Ошибка", "Файл не выбран", QMessageBox::Ok);
        return;
    }
    CryptAcquireContext(&hCryptProv, NULL, MS_DEF_RSA_SCHANNEL_PROV, PROV_RSA_SCHANNEL, CRYPT_VERIFYCONTEXT);
    CryptGenKey(hCryptProv, CALG_AES_256, 0, &hKey);
    //CryptEncrypt(hKey, 0, true, 0, NULL, &blockLen, myFile.size());
    //srcData = new uchar[blockLen];
    //newData = new uchar[blockLen];
    dataSize = myFile.read((char *)(&srcData[0]), blockLen);
    memcpy(&newData[0], &srcData[0], blockLen);
    newData[0] = -newData[0];
    for (uint i = 0; i < block; i++)
    {
        int k = 0;
        CryptEncrypt(hKey, 0, i < 2, 0, &srcData[0], &dataSize, block*blockLen);
        CryptEncrypt(hKey, 0, i < 2, 0, &newData[0], &dataSize, block*blockLen);
        for (uint j = 0; j < blockLen; j++)
            k += trueBitsCount((uint)(srcData[j] ^ newData[j]));
        values.push_back(k);
        memset(&srcData[0], 0, blockLen);
        dataSize = myFile.read((char *)(&srcData[0]), blockLen);
        memcpy(&newData[0], &srcData[0], blockLen);
    }
    myFile.close();
    CryptReleaseContext(hCryptProv, 0);
    CryptDestroyKey(hKey);
    //delete[] srcData;
    //srcData = 0;
    //delete[] newData;
    //newData = 0;
    DrawPlot(plot, values);
    plot->show();
}
Beispiel #11
0
void FreqWindow::Recalc()
{
   wxLogMessage(wxT("Starting FreqWindow::Recalc()"));
   if (mProcessed)
      delete[] mProcessed;
   mProcessed = NULL;

   if (!mData) {
      mFreqPlot->Refresh(true);
      return;
   }

   int alg = mAlgChoice->GetSelection();
   int windowFunc = mFuncChoice->GetSelection();
   long windowSize = 0;
   (mSizeChoice->GetStringSelection()).ToLong(&windowSize);

   int f = NumWindowFuncs();

   if (!(windowSize >= 32 && windowSize <= 65536 &&
         alg >= 0 && alg <= 4 && windowFunc >= 0 && windowFunc < f)) {
      mFreqPlot->Refresh(true);
      return;
   }

   mWindowSize = windowSize;

   if (mDataLen < mWindowSize) {
      mFreqPlot->Refresh(true);
      return;
   }

   mProcessed = new float[mWindowSize];

   int i;
   for (i = 0; i < mWindowSize; i++)
      mProcessed[i] = float(0.0);
   int half = mWindowSize / 2;

   float *in = new float[mWindowSize];
   float *in2 = new float[mWindowSize];
   float *out = new float[mWindowSize];
   float *out2 = new float[mWindowSize];
   float *win = new float[mWindowSize];

   // initialize the window
   for(int i=0; i<mWindowSize; i++)
      win[i] = 1.0;
   WindowFunc(windowFunc, mWindowSize, win);
   // Scale window such that an amplitude of 1.0 in the time domain
   // shows an amplitude of 0dB in the frequency domain
   double wss = 0;
   for(int i=0; i<mWindowSize; i++)
      wss += win[i];
   if(wss > 0)
      wss = 4.0 / (wss*wss);
   else
      wss = 1.0;

   //Progress dialog over FFT operation
   wxLogMessage(wxT("Starting progress dialogue in FreqWindow::Recalc()"));
   ProgressDialog *mProgress = new ProgressDialog(_("FreqWindow"),_("Drawing Spectrum"));

   int start = 0;
   int windows = 0;
   while (start + mWindowSize <= mDataLen) {
      for (i = 0; i < mWindowSize; i++)
         in[i] = win[i] * mData[start + i];

      switch (alg) {
      case 0:                  // Spectrum
         PowerSpectrum(mWindowSize, in, out);

         for (i = 0; i < half; i++)
            mProcessed[i] += out[i];
         break;

      case 1:
      case 2:
      case 3:   // Autocorrelation, Cuberoot AC or Enhanced AC

         // Take FFT
#ifdef EXPERIMENTAL_USE_REALFFTF
         RealFFT(mWindowSize, in, out, out2);
#else
         FFT(mWindowSize, false, in, NULL, out, out2);
#endif
         // Compute power
         for (i = 0; i < mWindowSize; i++)
            in[i] = (out[i] * out[i]) + (out2[i] * out2[i]);

         if (alg == 1) {
            for (i = 0; i < mWindowSize; i++)
               in[i] = sqrt(in[i]);
         }
         if (alg == 2 || alg == 3) {
            // Tolonen and Karjalainen recommend taking the cube root
            // of the power, instead of the square root

            for (i = 0; i < mWindowSize; i++)
               in[i] = pow(in[i], 1.0f / 3.0f);
         }
         // Take FFT
#ifdef EXPERIMENTAL_USE_REALFFTF
         RealFFT(mWindowSize, in, out, out2);
#else
         FFT(mWindowSize, false, in, NULL, out, out2);
#endif

         // Take real part of result
         for (i = 0; i < half; i++)
            mProcessed[i] += out[i];
         break;

      case 4:                  // Cepstrum
#ifdef EXPERIMENTAL_USE_REALFFTF
         RealFFT(mWindowSize, in, out, out2);
#else
         FFT(mWindowSize, false, in, NULL, out, out2);
#endif

         // Compute log power
         // Set a sane lower limit assuming maximum time amplitude of 1.0
         float power;
         float minpower = 1e-20*mWindowSize*mWindowSize;
         for (i = 0; i < mWindowSize; i++)
         {
            power = (out[i] * out[i]) + (out2[i] * out2[i]);
            if(power < minpower)
               in[i] = log(minpower);
            else
               in[i] = log(power);
         }
         // Take IFFT
#ifdef EXPERIMENTAL_USE_REALFFTF
         InverseRealFFT(mWindowSize, in, NULL, out);
#else
         FFT(mWindowSize, true, in, NULL, out, out2);
#endif

         // Take real part of result
         for (i = 0; i < half; i++)
            mProcessed[i] += out[i];

         break;
      }                         //switch

      start += half;
      windows++;
      // only update the progress dialogue infrequently to reduce it's overhead
      // If we do it every time, it spends as much time updating X11 as doing
      // the calculations. 10 seems a reasonable compromise on Linux that
      // doesn't make it unresponsive, but avoids the slowdown.
      if ((windows % 10) == 0)
         mProgress->Update(1 - static_cast<float>(mDataLen - start) / mDataLen);
   }

   wxLogMessage(wxT("Finished updating progress dialogue in FreqWindow::Recalc()"));
   switch (alg) {
   double scale;
   case 0:                     // Spectrum
      // Convert to decibels
      mYMin = 1000000.;
      mYMax = -1000000.;
      scale = wss / (double)windows;
      for (i = 0; i < half; i++)
      {
         mProcessed[i] = 10 * log10(mProcessed[i] * scale);
         if(mProcessed[i] > mYMax)
            mYMax = mProcessed[i];
         else if(mProcessed[i] < mYMin)
            mYMin = mProcessed[i];
      }
      if(mYMin < -dBRange)
         mYMin = -dBRange;
      if(mYMax <= -dBRange)
         mYMax = -dBRange + 10.; // it's all out of range, but show a scale.
      else
         mYMax += .5;

      mProcessedSize = half;
      mYStep = 10;
      break;

   case 1:                     // Standard Autocorrelation
   case 2:                     // Cuberoot Autocorrelation
      for (i = 0; i < half; i++)
         mProcessed[i] = mProcessed[i] / windows;

      // Find min/max
      mYMin = mProcessed[0];
      mYMax = mProcessed[0];
      for (i = 1; i < half; i++)
         if (mProcessed[i] > mYMax)
            mYMax = mProcessed[i];
         else if (mProcessed[i] < mYMin)
            mYMin = mProcessed[i];

      mYStep = 1;

      mProcessedSize = half;
      break;

   case 3:                     // Enhanced Autocorrelation
      for (i = 0; i < half; i++)
         mProcessed[i] = mProcessed[i] / windows;

      // Peak Pruning as described by Tolonen and Karjalainen, 2000

      // Clip at zero, copy to temp array
      for (i = 0; i < half; i++) {
         if (mProcessed[i] < 0.0)
            mProcessed[i] = float(0.0);
         out[i] = mProcessed[i];
      }

      // Subtract a time-doubled signal (linearly interp.) from the original
      // (clipped) signal
      for (i = 0; i < half; i++)
         if ((i % 2) == 0)
            mProcessed[i] -= out[i / 2];
         else
            mProcessed[i] -= ((out[i / 2] + out[i / 2 + 1]) / 2);

      // Clip at zero again
      for (i = 0; i < half; i++)
         if (mProcessed[i] < 0.0)
            mProcessed[i] = float(0.0);

      // Find new min/max
      mYMin = mProcessed[0];
      mYMax = mProcessed[0];
      for (i = 1; i < half; i++)
         if (mProcessed[i] > mYMax)
            mYMax = mProcessed[i];
         else if (mProcessed[i] < mYMin)
            mYMin = mProcessed[i];

      mYStep = 1;

      mProcessedSize = half;
      break;

   case 4:                     // Cepstrum
      for (i = 0; i < half; i++)
         mProcessed[i] = mProcessed[i] / windows;

      // Find min/max, ignoring first and last few values
      int ignore = 4;
      mYMin = mProcessed[ignore];
      mYMax = mProcessed[ignore];
      for (i = ignore + 1; i < half - ignore; i++)
         if (mProcessed[i] > mYMax)
            mYMax = mProcessed[i];
         else if (mProcessed[i] < mYMin)
            mYMin = mProcessed[i];

      mYStep = 1;

      mProcessedSize = half;
      break;
   }

   delete[]in;
   delete[]in2;
   delete[]out;
   delete[]out2;
   delete[]win;

   wxLogMessage(wxT("About to draw plot in FreqWindow::Recalc()"));
   DrawPlot();
   mFreqPlot->Refresh(true);
   delete mProgress;
}
Beispiel #12
0
void FreqWindow::OnAxisChoice(wxCommandEvent & WXUNUSED(event))
{
   mLogAxis = mAxisChoice->GetSelection() ? true : false;
   DrawPlot();
}
Beispiel #13
0
void FreqWindow::OnZoomSlider(wxCommandEvent & WXUNUSED(event))
{
   DrawPlot();
}
Beispiel #14
0
void FreqWindow::OnPanScroller(wxScrollEvent & WXUNUSED(event))
{
   DrawPlot();
}
Beispiel #15
0
void FreqWindow::OnGridOnOff(wxCommandEvent & WXUNUSED(event))
{
   mDrawGrid = mGridOnOff->IsChecked();

   DrawPlot();
}
Beispiel #16
0
void CCube::RenderCube(const GLfloat* asize)
{
    static double dOff[3] = {-1.0f, -1.0f, -.5f};
    static const double dMin[3] = {-1.0f, -1.0f, -.5f};
    static const double dMax[3] = {2.0f, 1.5f, 1.0f};
    static const double dFactor[3] = {.01f, .01f, .01f};
    static bool bDec[3] = { false, false, false};

    InitCamera();

    glLineWidth(3);

    diffuse[0] = diffuse[1] = diffuse[2] = 0.8 + scaleAll;
    specular[0] = specular[1] = specular[2] = 1.0;

    glPushMatrix();   // light matrix
    OrthographicMatrix();

    // get an appropriate lOffset if available - we want at least 100 points + 2 for "padding"
    long lOffset = 0;
    if (sm && sm->bSensorFound) {
        if (sm->lOffset > MAX_PLOT_POINTS+2) { // note the two point "padding" so we are reading the latest value that isn't in use by the sensor (i.e. writing)
            lOffset = sm->lOffset-2;
        }
    }

    if (bIsQCNLive) {
        glTranslatef(asize[E_DX], asize[E_DZ], 0.0);//Jesse Lawrence Changed - X & Z MOTIONS (Y IS SIZE)
    } else {
        glTranslatef(-.50 + dOff[0], dOff[1], dOff[2]);
    }

    for (int i = 0; i < 3; i++)  {
        if (dOff[i]>dMax[i]) {
            bDec[i] = true;
        }
        else if (dOff[i]<dMin[i]) {
            bDec[i] = false;
        }
        dOff[i] += (dFactor[i] * (bDec[i] ? -1.0 : 1.0));
    }

    glRotatef(rot.x, rot.y, rot.y/3.0f, 0.0);
    rot.x += rotationSpeed * 1.9134f;
    rot.y += rotationSpeed * 2.1234f;

    glPushMatrix();

    //glTranslatef(0.0f, 0.0f,-7.0f);	// Translate Into The Screen 7.0 Units
    //glRotatef(rotqube,0.0f,1.0f,0.0f);	// Rotate The cube around the Y axis
    //glRotatef(rotqube,1.0f,1.0f,1.0f);

    if (bIsQCNLive) {
        float asize_all = asize[E_DY];//Jesse Lawrence Added - Constant size for all dimensions
        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(blue);          // Color Green
        glVertex3f( asize_all, asize_all, -asize_all);      // Top Right Of The Quad (Top)
        glVertex3f(-asize_all, asize_all,-asize_all);      // Top Left Of The Quad (Top)
        glVertex3f(-asize_all, asize_all, asize_all);      // Bottom Left Of The Quad (Top)
        glVertex3f( asize_all, asize_all, asize_all);      // Bottom Right Of The Quad (Top)
        glEnd();
        // note the asize in DrawPlot below should be the "y-axis" for whichever face we're looking at
//  DrawPlot(lOffset ? (const GLfloat*) &(sm->x0[lOffset]) : NULL, asize, CUBE_TOP);  // x-axis is green

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(blue);         // Color Yellow
        glVertex3f( asize_all,-asize_all, asize_all);      // Top Right Of The Quad (Bottom)
        glVertex3f(-asize_all,-asize_all, asize_all);      // Top Left Of The Quad (Bottom)
        glVertex3f(-asize_all,-asize_all,-asize_all);      // Bottom Left Of The Quad (Bottom)
        glVertex3f( asize_all,-asize_all,-asize_all);      // Bottom Right Of The Quad (Bottom)
        glEnd();
//  DrawPlot(lOffset ? (const float*) &(sm->y0[lOffset]) : NULL, asize, CUBE_BOTTOM);   // y-axis is yellow

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(orange);           // Color Blue
        glVertex3f( asize_all, asize_all, asize_all);      // Top Right Of The Quad (Front)
        glVertex3f(-asize_all, asize_all, asize_all);      // Top Left Of The Quad (Front)
        glVertex3f(-asize_all,-asize_all, asize_all);      // Bottom Left Of The Quad (Front)
        glVertex3f( asize_all,-asize_all, asize_all);      // Bottom Right Of The Quad (Front)
        glEnd();
//  DrawPlot(lOffset ? (const float*) &(sm->z0[lOffset]) : NULL, asize, CUBE_FRONT);  // z-axis is blue

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(green);            // Color Red
        glVertex3f( asize_all,-asize_all,-asize_all);      // Top Right Of The Quad (Back)
        glVertex3f(-asize_all,-asize_all,-asize_all);      // Top Left Of The Quad (Back)
        glVertex3f(-asize_all, asize_all,-asize_all);      // Bottom Left Of The Quad (Back)
        glVertex3f( asize_all, asize_all,-asize_all);      // Bottom Right Of The Quad (Back)
        glEnd();
//  DrawPlot(lOffset ? (const float*) &(sm->fsig[lOffset]) : NULL, asize, CUBE_BACK);   // fsig/significance is red

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(green);           // Color Cyan
        glVertex3f(-asize_all, asize_all, asize_all);      // Top Right Of The Quad (Left)
        glVertex3f(-asize_all, asize_all,-asize_all);      // Top Left Of The Quad (Left)
        glVertex3f(-asize_all,-asize_all,-asize_all);      // Bottom Left Of The Quad (Left)
        glVertex3f(-asize_all,-asize_all, asize_all);      // Bottom Right Of The Quad (Left)
        glEnd();
//  DrawPlot(lOffset ? (const float*) &(sm->fmag[lOffset]) : NULL, asize, CUBE_LEFT);   // magnitude

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(orange);        // Color Magenta
        glVertex3f( asize_all, asize_all,-asize_all);      // Top Right Of The Quad (Right)
        glVertex3f( asize_all, asize_all, asize_all);      // Top Left Of The Quad (Right)
        glVertex3f( asize_all,-asize_all, asize_all);      // Bottom Left Of The Quad (Right)
        glVertex3f( asize_all,-asize_all,-asize_all);      // Bottom Right Of The Quad (Right)
        glEnd();
//  DrawPlot(lOffset ? (const float*) &(sm->vari[lOffset]) : NULL, asize, CUBE_RIGHT);   // variance
    } else {  // screensaver mode
        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(green);          // Color Green
        glVertex3f( asize[E_DX], asize[E_DY], -asize[E_DZ]);      // Top Right Of The Quad (Top)
        glVertex3f(-asize[E_DX], asize[E_DY],-asize[E_DZ]);      // Top Left Of The Quad (Top)
        glVertex3f(-asize[E_DX], asize[E_DY], asize[E_DZ]);      // Bottom Left Of The Quad (Top)
        glVertex3f( asize[E_DX], asize[E_DY], asize[E_DZ]);      // Bottom Right Of The Quad (Top)
        glEnd();
        // note the asize in DrawPlot below should be the "y-axis" for whichever face we're looking at
        DrawPlot(lOffset ? (const GLfloat*) &(sm->x0[lOffset]) : NULL, asize, CUBE_TOP);  // x-axis is green

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(yellow);         // Color Yellow
        glVertex3f( asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Top Right Of The Quad (Bottom)
        glVertex3f(-asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Top Left Of The Quad (Bottom)
        glVertex3f(-asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Bottom Left Of The Quad (Bottom)
        glVertex3f( asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Bottom Right Of The Quad (Bottom)
        glEnd();
        DrawPlot(lOffset ? (const float*) &(sm->y0[lOffset]) : NULL, asize, CUBE_BOTTOM);   // y-axis is yellow

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(blue);           // Color Blue
        glVertex3f( asize[E_DX], asize[E_DY], asize[E_DZ]);      // Top Right Of The Quad (Front)
        glVertex3f(-asize[E_DX], asize[E_DY], asize[E_DZ]);      // Top Left Of The Quad (Front)
        glVertex3f(-asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Bottom Left Of The Quad (Front)
        glVertex3f( asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Bottom Right Of The Quad (Front)
        glEnd();
        DrawPlot(lOffset ? (const float*) &(sm->z0[lOffset]) : NULL, asize, CUBE_FRONT);  // z-axis is blue

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(red);            // Color Red
        glVertex3f( asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Top Right Of The Quad (Back)
        glVertex3f(-asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Top Left Of The Quad (Back)
        glVertex3f(-asize[E_DX], asize[E_DY],-asize[E_DZ]);      // Bottom Left Of The Quad (Back)
        glVertex3f( asize[E_DX], asize[E_DY],-asize[E_DZ]);      // Bottom Right Of The Quad (Back)
        glEnd();
        DrawPlot(lOffset ? (const float*) &(sm->fsig[lOffset]) : NULL, asize, CUBE_BACK);   // fsig/significance is red

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(cyan);           // Color Cyan
        glVertex3f(-asize[E_DX], asize[E_DY], asize[E_DZ]);      // Top Right Of The Quad (Left)
        glVertex3f(-asize[E_DX], asize[E_DY],-asize[E_DZ]);      // Top Left Of The Quad (Left)
        glVertex3f(-asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Bottom Left Of The Quad (Left)
        glVertex3f(-asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Bottom Right Of The Quad (Left)
        glEnd();
        DrawPlot(lOffset ? (const float*) &(sm->fmag[lOffset]) : NULL, asize, CUBE_LEFT);   // magnitude

        glBegin(GL_QUADS);            // Draw The Cube Using quads
        glColor4fv(magenta);        // Color Magenta
        glVertex3f( asize[E_DX], asize[E_DY],-asize[E_DZ]);      // Top Right Of The Quad (Right)
        glVertex3f( asize[E_DX], asize[E_DY], asize[E_DZ]);      // Top Left Of The Quad (Right)
        glVertex3f( asize[E_DX],-asize[E_DY], asize[E_DZ]);      // Bottom Left Of The Quad (Right)
        glVertex3f( asize[E_DX],-asize[E_DY],-asize[E_DZ]);      // Bottom Right Of The Quad (Right)
        glEnd();
        DrawPlot(lOffset ? (const float*) &(sm->vari[lOffset]) : NULL, asize, CUBE_RIGHT);   // variance
    }

    glPopMatrix();
    glPopMatrix(); // rotation matrix

    glFlush();
}