void FFreeFormBoardData::DrawMarkers(float marker_size_cm, uint32_t dpi, float margin_cm, cv::Size2f page_size_cm) { float pixels_per_cm = float(dpi) / INCH; cv::Size page_size_pix( (int)std::round(pixels_per_cm*(page_size_cm.width - margin_cm)), (int)std::round(pixels_per_cm*(page_size_cm.height - margin_cm)) ); uint32_t marker_pixels = (uint32_t)std::round(pixels_per_cm*marker_size_cm); uint32_t margin_pixels = (uint32_t)std::round(pixels_per_cm*margin_cm); //cv::Mat img_out(page_size_pix, CV_8UC1); //img_out.setTo(255); //int marker_side = std::min(page_size_pix.width, page_size_pix.height) - 2*margin_pixels; //cv::Mat img_marker; //dictionary.drawMarker(ids[0], marker_side, img_marker, 1); //cv::putText(img_marker, "1", cv::Point(10, 10), cv::FONT_HERSHEY_SCRIPT_SIMPLEX, 10.0, cv::Scalar::all(125)); //img_marker.copyTo(img_out.rowRange(margin_pixels, margin_pixels+marker_side).colRange(margin_pixels, margin_pixels+marker_side)); //cv::putText(img_out, "1", cv::Point(margin_pixels, margin_pixels + marker_side + 10), // cv::FONT_HERSHEY_SCRIPT_SIMPLEX, 4.0, cv::Scalar(125), 3); //Pages.resize(1); //Pages[0] = img_marker; //putText(_image, s.str(), cent, FONT_HERSHEY_SIMPLEX, 0.5, textColor, 2); Pages.clear(); for (int id = 0; id < 10; id++) { Pages.push_back(RenderMarker(id, marker_pixels, margin_pixels)); } }
void Gmeter::Render() { Gauge::Render(); char buf[10]; double value = globals->m_DataSource->GetAirframe()->GetAirframeData_D(m_DataSource); if (value > m_Max) { value = m_Max; } else if (value < m_Min) { value = m_Min; } // draw the gauge label glColor3ub(255, 255, 255); globals->m_FontManager->SetSize(m_Font, 4, 4); globals->m_FontManager->Print(10, 40, m_Label.c_str(), m_Font); // draw the "reset" button label glColor3ub(255, 0, 0); globals->m_FontManager->SetSize(m_Font, 3.0, 3.0); globals->m_FontManager->Print(34, 4, "R", m_Font); glMatrixMode(GL_MODELVIEW); glEnableClientState(GL_VERTEX_ARRAY); glPushMatrix(); glLineWidth(2.0); glEnable(GL_LINE_SMOOTH); glTranslatef(18, 18, 0); // draw gauge circle outside glColor3ub(255, 255, 255); CircleEvaluator *aCircle = globals->m_CircleEvaluator; aCircle->SetDegreesPerPoint(10.0); aCircle->SetRadius(R); aCircle->SetOrigin(0.0, 0.0); aCircle->SetArcStartEnd(startDegree - rangeDegree, startDegree + rangeDegree); aCircle->ResetVertices(); aCircle->Evaluate(); aCircle->Render(GL_LINE_STRIP); // draw gauge "reset" button glColor3ub(255, 255, 255); aCircle->SetDegreesPerPoint(10.0); aCircle->SetRadius(5); aCircle->SetOrigin(16.0, -12.0); aCircle->SetArcStartEnd(8, 242); aCircle->ResetVertices(); aCircle->Evaluate(); aCircle->Render(GL_LINE_STRIP); // draw gauge arrow double percentage = value / m_Max ; double degree = startDegree + ((rangeDegree - 15.0) * percentage); double radians = degree * DEG_TO_RAD; glColor3ub(255, 255, 255); const float vertices[] = {0,0, R * sin(radians),R * cos(radians)}; glVertexPointer(2, GL_FLOAT, 0, &vertices); glDrawArrays(GL_LINE_STRIP, 0, 2); // draw gauge max positive arrow if (value > m_maxValue) { m_maxValue = value; } percentage = m_maxValue / m_Max ; degree = startDegree + ((rangeDegree - 15.0) * percentage); double maxRadians = degree * DEG_TO_RAD; // draw gauge min negative arrow if (value < m_minValue) { m_minValue = value; } percentage = m_minValue / m_Max ; degree = startDegree + ((rangeDegree - 15.0) * percentage); double minRadians = degree * DEG_TO_RAD; glColor3ub(255, 0, 0); const float arrVertices[] = {R * sin(minRadians), R * cos(minRadians), 0, 0, R * sin(maxRadians), R * cos(maxRadians)}; glVertexPointer(2, GL_FLOAT, 0, &arrVertices); glDrawArrays(GL_LINE_STRIP, 0, 3); // draw gauge rectangle containing the current value glLineWidth(1.0); glColor3ub(120, 120, 120); const float rectVertices[] = {44.0,-5.0, 13.0, -5.0, 13.0, 5.0, 44.0, 5.0}; glVertexPointer(2, GL_FLOAT, 0, &rectVertices); glDrawArrays(GL_LINE_STRIP, 0, 4); // round current value value = round(10 * value) / 10; if (value == 0.0) value = fabs(value); // draw current value in gauge display if (fabs(value) < m_MinYellow) { glColor3ub(255, 255, 255); } else if (fabs(value) < m_MinRed) { glColor3ub(247, 231, 8); } else { glColor3ub(255, 20, 20); } sprintf(buf, "%.1f", value); globals->m_FontManager->SetSize(m_Font, 4.0, 3.5); globals->m_FontManager->Print(15.0, -1.5, buf, m_Font); // render gauge markers for(double xs = m_Min; xs <= m_Max; xs += m_TickSpacing) { if (fabs(xs) <= m_MinYellow) { glColor3ub(255, 255, 255); } else if (fabs(xs) <= m_MinRed) { glColor3ub(247, 231, 8); } else { glColor3ub(255, 20, 20); } RenderMarker(xs); } glPopMatrix(); glDisableClientState(GL_VERTEX_ARRAY); }