void THISCLASS::DrawTicks(wxPaintDC &dc, const SwisTrackCoreEventRecorder::Timeline *timeline) { wxSize dcsize = dc.GetSize(); int dw = dcsize.GetWidth(); //int dh=dcsize.GetHeight(); // Not needed dc.SetFont(GetFont()); dc.SetPen(wxPen(wxColour(0xcc, 0xcc, 0xcc))); dc.SetTextForeground(wxColour(0xcc, 0xcc, 0xcc)); // Calculate how many ticks to display double mintickdistance = 5; double mintickdistancetime = mintickdistance / mViewScale; double tickdistancetime = pow(10, ceil(log(mintickdistancetime) / log((double)10))); // Draw ticks double endtime = mSwisTrack->mSwisTrackCore->mEventRecorder->CalculateDuration(&(timeline->mBegin), &(timeline->mEnd)); int ticknumber = (int)ceil(-mViewOffset / mViewScale / tickdistancetime); while (true) { double xtime = ticknumber * tickdistancetime; if (xtime >= endtime) { break; } int x = (int)floor(xtime * mViewScale + mViewOffset); if (x > dw) { break; } if (ticknumber % 10 == 0) { dc.DrawLine(x, 0, x, 4); wxString label = wxString::Format(wxT("%d"), (int)(xtime * 1000)); int textwidth, textheight; GetTextExtent(label, &textwidth, &textheight) ; textwidth >>= 1; dc.DrawText(label, x - textwidth, 2); } else {
void THISCLASS::DrawTrigger(wxPaintDC &dc, const SwisTrackCoreEventRecorder::Timeline *timeline) { // Prepare wxSize dcsize = dc.GetSize(); int dw = dcsize.GetWidth(); int dh = dcsize.GetHeight(); dc.SetBrush(wxBrush(wxColour(0xee, 0xee, 0xee))); dc.SetPen(wxPen(wxColour(0xee, 0xee, 0xee))); // Draw double starttime = -1; bool active = timeline->mBeginState.mTriggerActive; SwisTrackCoreEventRecorder::Timeline::tEventList::const_iterator it = timeline->mEvents.begin(); while (it != timeline->mEvents.end()) { if (it->mType == SwisTrackCoreEventRecorder::sType_BeforeTriggerStart) { starttime = mSwisTrack->mSwisTrackCore->mEventRecorder->CalculateDuration(&(timeline->mBegin), &(*it));; active = true; } else if (it->mType == SwisTrackCoreEventRecorder::sType_AfterTriggerStop) { double time = mSwisTrack->mSwisTrackCore->mEventRecorder->CalculateDuration(&(timeline->mBegin), &(*it)); DrawTrigger(dc, dw, dh, starttime, time); starttime = time; active = false; } it++; } // Draw last event if (active) { DrawTrigger(dc, dw, dh, starttime, -1); } }
//----------------------------------------------------------------------------- void LineProfileCanvas::OnPaintCustom( wxPaintDC& dc ) //----------------------------------------------------------------------------- { wxCoord yOffset( 1 ), w( 0 ), h( 0 ); dc.GetSize( &w, &h ); const double scaleX = static_cast<double>( w - 2 * GetBorderWidth() ) / static_cast<double>( ( GetDataCount() == 0 ) ? 1 : GetDataCount() - 1 ); const double scaleY = GetScaleY( h ); DrawMarkerLines( dc, w, h, scaleX ); unsigned int from, to; GetDrawRange( &from, &to ); const int borderWidth = GetBorderWidth(); const wxString YMarkerString( wxString::Format( wxT( "Draw Range(absolute): %d / %d, " ), from, to ) ); wxCoord xOffset; dc.GetTextExtent( YMarkerString, &xOffset, 0 ); xOffset += borderWidth / 2; dc.DrawText( YMarkerString, borderWidth / 2, yOffset ); if( m_boUnsupportedPixelFormat ) { dc.SetTextForeground( *wxRED ); dc.DrawText( wxString( wxT( "Unsupported pixel format" ) ), xOffset, yOffset ); dc.SetTextForeground( *wxBLACK ); } else if( m_ppData ) { for( int channel = 0; channel < m_ChannelCount; channel++ ) { DrawProfileLine( dc, h, borderWidth + 1, scaleX, scaleY, from, to, m_ppData[channel], GetDataCount(), *m_Pens[channel].pColour_ ); DrawInfoString( dc, wxString::Format( wxT( "%s%s: " ), ( channel != 0 ) ? wxT( ", " ) : wxT( "" ), m_Pens[channel].description_.c_str() ), xOffset, yOffset, *( m_Pens[channel].pColour_ ) ); } } }
void CMyGLCanvas_DisplayWindow3D::OnPostRenderSwapBuffers(double At, wxPaintDC &dc) { if (m_win3D) m_win3D->internal_setRenderingFPS(At>0 ? 1.0/At : 1e9); // If we are requested to do so, grab images to disk as they are rendered: string grabFile = m_win3D->grabImageGetNextFile(); if (m_win3D && (!grabFile.empty() || m_win3D->isCapturingImgs()) ) { int w,h; dc.GetSize(&w, &h); // create a memory DC and bitmap to capture the DC wxMemoryDC memDC; wxBitmap memBmp(w, h); memDC.SelectObject(memBmp); memDC.Blit(0,0, w,h, &dc, 0,0); if (!grabFile.empty()) { memBmp.SaveFile( _U(grabFile.c_str()) , wxBITMAP_TYPE_PNG ); m_win3D->internal_emitGrabImageEvent(grabFile); } if (m_win3D->isCapturingImgs()) { wxImage img = memBmp.ConvertToImage(); CImagePtr pimg = mrpt::gui::wxImage2MRPTImagePtr(img); { mrpt::synch::CCriticalSectionLocker lock(& m_win3D->m_last_captured_img_cs ); m_win3D->m_last_captured_img = pimg; pimg.clear_unique(); } } } }
//----------------------------------------------------------------------------- void PlotCanvasInfoBase::OnPaintCustom( wxPaintDC& dc ) //----------------------------------------------------------------------------- { wxCoord xOffset( 1 ), w( 0 ), h( 0 ); dc.GetSize( &w, &h ); const double scaleX = GetScaleX( w ); const double scaleY = GetScaleY( h ); DrawMarkerLines( dc, w, h, scaleX ); const plot_data_type offset = GetOffset(); for( unsigned int i = 0; i < m_PlotCount; i++ ) { const unsigned int valCount = static_cast<unsigned int>( m_ppPlotValues[i]->size() ); if( valCount > 1 ) { int lowerStart = h - GetBorderWidth(); dc.SetPen( m_pens[i % COLOUR_COUNT] ); for( unsigned int j = 0; j < valCount - 1; j++ ) { dc.DrawLine( static_cast<int>( GetBorderWidth() + ( j * scaleX ) + 1 ), static_cast<int>( lowerStart - ( ( ( *m_ppPlotValues[i] )[j] - offset ) * scaleY ) ), static_cast<int>( GetBorderWidth() + ( ( j + 1 ) * scaleX ) + 1 ), static_cast<int>( lowerStart - ( ( ( *m_ppPlotValues[i] )[j + 1] - offset ) * scaleY ) ) ); } dc.SetPen( wxNullPen ); } // info in the top left corner if( m_dataType == ctPropFloat ) { DrawInfoString( dc, wxString::Format( wxT( "Range: %.3f - %.3f, %s: %s " ), m_CurrentMinPlotValues[i], m_CurrentMaxPlotValues[i], GetPlotIdentifierPrefix().c_str(), m_PlotIdentifiers[i].c_str() ), xOffset, 1, m_pens[i] ); } else { DrawInfoString( dc, wxString::Format( wxT( "Range: %lld - %lld, %s: %s " ), static_cast<int64_type>( m_CurrentMinPlotValues[i] ), static_cast<int64_type>( m_CurrentMaxPlotValues[i] ), GetPlotIdentifierPrefix().c_str(), m_PlotIdentifiers[i].c_str() ), xOffset, 1, m_pens[i] ); } } }
void CMyGLCanvas_DisplayWindow3D::OnPostRenderSwapBuffers( double At, wxPaintDC& dc) { if (m_win3D) m_win3D->internal_setRenderingFPS(At > 0 ? 1.0 / At : 1e9); // If we are requested to do so, grab images to disk as they are rendered: string grabFile; if (m_win3D) grabFile = m_win3D->grabImageGetNextFile(); if (m_win3D && (!grabFile.empty() || m_win3D->isCapturingImgs())) { int w, h; dc.GetSize(&w, &h); // Save image directly from OpenGL - It could also use 4 channels and // save with GL_BGRA_EXT CImage::Ptr frame(new CImage(w, h, 3, false)); glReadBuffer(GL_FRONT); glReadPixels(0, 0, w, h, GL_BGR_EXT, GL_UNSIGNED_BYTE, (*frame)(0, 0)); if (!grabFile.empty()) { frame->saveToFile(grabFile); m_win3D->internal_emitGrabImageEvent(grabFile); } if (m_win3D->isCapturingImgs()) { { std::lock_guard<std::mutex> lock( m_win3D->m_last_captured_img_cs); m_win3D->m_last_captured_img = frame; frame.reset(); } } } }