Ejemplo n.º 1
0
void test_bezier()
{
	size_t width = 400;
	size_t height = 400;
	int centerx = width / 2;
	int centery = height / 2;
	int xsize = (int)(centerx*0.9);
	int ysize = (int)(centery*0.9);

	pb_rgba pb;
	pb_rgba_init(&pb, width, height);

	// background color
	raster_rgba_rect_fill(&pb, 0, 0, width, height, cornsilk);

	// needed for all curves
	int m = 100;
	Pt3 curve[200];

	// One loop
	int nctrls = 5;
	Pt3 ctrls1[5] = { { centerx - xsize, centery, 0 }, { centerx, centery - ysize, 0 }, { centerx + xsize, centery, 0 }, { centerx, centery + ysize, 0 }, { centerx - xsize, centery, 0 } };
	bez3_curve(ctrls1, nctrls, m, curve);
	polyline(&pb, curve, m, pBlack);


	// one double peak through the middle
	Pt3 ctrls3[5] = { { centerx - xsize, centery, 0 }, { centerx - (xsize*0.3f), centery + ysize, 0 }, { centerx, centery - ysize, 0 }, { centerx + (xsize*0.3f), centery + ysize, 0 }, { centerx + xsize, centery, 0 } };
	bez3_curve(ctrls3, nctrls, m, curve);
	polyline(&pb, curve, m, pRed);

	// Now we have a simple image, so write it to a file
	int err = write_PPM_binary("test_bezier.ppm", &pb);
}
Ejemplo n.º 2
0
/*!
  \brief Draw step function
  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted
  \sa QwtCurve::draw, QwtCurve::drawCurve, QwtCurve::drawDots, 
      QwtCurve::drawLines, QwtCurve::drawSpline, QwtCurve::drawSticks
*/
void QwtCurve::drawSteps(QPainter *painter,
    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
{
    QPointArray polyline(2 * (to - from) + 1);

    bool inverted = d_options & Yfx;
    if ( d_options & Inverted )
        inverted = !inverted;

    int i,ip;
    for (i = from, ip = 0; i <= to; i++, ip += 2)
    {
        int xi = xMap.transform(x(i));
        int yi = yMap.transform(y(i));

        if ( ip > 0 )
        {
            if (inverted)
                polyline.setPoint(ip - 1, polyline[ip-2].x(), yi);
            else
                polyline.setPoint(ip - 1, xi, polyline[ip-2].y());
        }

        polyline.setPoint(ip, xi, yi);
    }

    QwtPainter::drawPolyline(painter, polyline);

    if ( painter->brush().style() != Qt::NoBrush )
    {
        closePolyline(xMap, yMap, polyline);
        painter->setPen(QPen(Qt::NoPen));
        QwtPainter::drawPolygon(painter, polyline);
    }
}
Ejemplo n.º 3
0
static inline Polygon qwtToPolylineFiltered( 
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QwtSeriesData<QPointF> *series, 
    int from, int to, Round round )
{
    // in curves with many points consecutive points
    // are often mapped to the same position. As this might
    // result in empty lines ( or symbols hidden by others )
    // we try to filter them out

    Polygon polyline( to - from + 1 );
    Point *points = polyline.data();

    const QPointF sample0 = series->sample( from );

    points[0].rx() = round( xMap.transform( sample0.x() ) );
    points[0].ry() = round( yMap.transform( sample0.y() ) );

    int pos = 0;
    for ( int i = from + 1; i <= to; i++ )
    {
        const QPointF sample = series->sample( i );

        const Point p( round( xMap.transform( sample.x() ) ),
            round( yMap.transform( sample.y() ) ) );

        if ( points[pos] != p )
            points[++pos] = p;
    }

    polyline.resize( pos + 1 );
    return polyline;
}
Ejemplo n.º 4
0
/*!
  Draw step function

  The direction of the steps depends on Inverted attribute. 

  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted

  \sa CurveAttribute, setCurveAttribute(),
      draw(), drawCurve(), drawDots(), drawLines(), drawSticks()
*/
void QwtPlotCurve::drawSteps(QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap, 
    int from, int to) const
{
    QwtPolygon polyline(2 * (to - from) + 1);

    bool inverted = d_data->curveType == Yfx;
    if ( d_data->attributes & Inverted )
        inverted = !inverted;

    int i,ip;
    for (i = from, ip = 0; i <= to; i++, ip += 2)
    {
        const int xi = xMap.transform(x(i));
        const int yi = yMap.transform(y(i));

        if ( ip > 0 )
        {
            if (inverted)
                polyline.setPoint(ip - 1, polyline[ip-2].x(), yi);
            else
                polyline.setPoint(ip - 1, xi, polyline[ip-2].y());
        }

        polyline.setPoint(ip, xi, yi);
    }

    if ( d_data->paintAttributes & ClipPolygons )
        polyline = QwtClipper::clipPolygon(painter->window(), polyline);

    QwtPainter::drawPolyline(painter, polyline);

    if ( d_data->brush.style() != Qt::NoBrush )
        fillCurve(painter, xMap, yMap, polyline);
}
Ejemplo n.º 5
0
void Plotter::loopDrawCurves(QPainter *painter)
{

    PlotSettings settings = zoomStack[curZoom];
    QRect rect(Margin,Margin,width()-(2*Margin),height()-(2*Margin));
    painter->setClipRect(rect.adjusted(+1,+1,-1,-1));
     QVector<QPointF> data = loopMap;
    QPolygonF polyline(data.count());
    //qDebug() << "Data Count:"<<data.count();
    double y =0.0,x=0.0;
    int l_nCounter =0;
    m_nOffset =0.0;
    double dx=0.0,dy=0.0;
    for(int j=0; j< data.count();++j)
    {
         dx = data[j].x();
         dy = data[j].y();
         if(m_bUniPolar == true)
         {
             float l_nDiv = (dy/2.0);
//             printf("UniPolar %f->%f\n",l_nDiv,dy - l_nDiv);
         }
         if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX))
         {
             //printf("X:%f Y:%f\n",dx,dy);
         }
        y =0.0,x=0.0;
        if(m_bVIMode == true)
            x = ((rect.width()/2)+5.0  + ((dx)*(((rect.width()-1)))/(settings.spanX())));
        else
            x = (rect.left()+ ((dx)*(((rect.width()-1)))/(settings.spanX())));

        if( m_bUniPolar == true){
            y = ((Margin+rect.bottom()) - (((dy/2.0)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
            //y+=10;
//            printf(" Coord-Y %f\n",dy/2.0);
        }
        else
            y = ((Margin+rect.height()/2) - ((dy+m_nOffset)*((rect.height()-1))/(settings.spanY())));
       // printf(" Coord- X & Y %f %f\n",x,y);
        if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX)&&(( data[j].y()>=settings.minY && data[j].y()<=settings.maxY)))
        {
            polyline[j] = QPointF(x,y);
            l_nCounter++;
        }
    }
    y =0.0,x=0.0;
//    for(int l_nIndex=0;l_nIndex< data.count();l_nIndex++)
//    {
//        QPointF(x,y);
//        x = polyline.at(l_nIndex).x();
//        y = polyline.at(l_nIndex).y();
//    }

    painter->setPen(Qt::red);
     painter->drawPolyline(polyline);
     loopMap.clear();
    // qDebug() << "Inside Loop Draw Curves";

}
Ejemplo n.º 6
0
void plotter::drawCurves(QPainter *painter)
{
    static const QColor colorForIds[6] = {
        Qt::blue, Qt::green, Qt::red, Qt::cyan, Qt::magenta, Qt::yellow
    };
    PlotSettings settings = zoomStack[curZoom];
    QRect rect(Margin, Margin,
               width() - 2 * Margin, height() - 2 * Margin);
    if (!rect.isValid())
        return;

    painter->setClipRect(rect.adjusted(+1, +1, -1, -1));

    //Esto lo deje asi porque en teoria serviria para graficar varias funciones en un mismo plot
    QMapIterator<int, QVector<QPointF> > i(curveMap);
    while (i.hasNext()) {
        i.next();

        int id = i.key();
        QVector<QPointF> data = i.value();
        QPolygonF polyline(data.count());
        for (int j = 0; j < data.count(); ++j) {
            double dx = data[j].x() - settings.minX;
            double dy = data[j].y() - settings.minY;
            double x = rect.left() + (dx * (rect.width() - 1)
                                         / settings.spanX());
            double y = rect.bottom() - (dy * (rect.height() - 1)
                                           / settings.spanY());
            polyline[j] = QPointF(x, y);
        }
        painter->setPen(colorForIds[uint(id) % 6]);
        painter->drawPolyline(polyline);
    }
}
Ejemplo n.º 7
0
/*!
  Draw step function

  The direction of the steps depends on Inverted attribute.

  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted

  \sa CurveAttribute, setCurveAttribute(),
      draw(), drawCurve(), drawDots(), drawLines(), drawSticks()
*/
void QwtPlotCurve::drawSteps(QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    int from, int to) const
{
    QwtPolygonF polyline(2 * (to - from) + 1);

    bool inverted = d_data->curveType == Yfx;
    if ( d_data->attributes & Inverted )
        inverted = !inverted;

    int i,ip;
    for (i = from, ip = 0; i <= to; i++, ip += 2)
    {
        const double xi = xMap.xTransform(x(i));
        const double yi = yMap.xTransform(y(i));

        if ( ip > 0 )
        {
            if (inverted)
                polyline[ip - 1] = QPointF(polyline[ip-2].x(), yi);
            else
                polyline[ip - 1] = QPointF(xi, polyline[ip-2].y());
        }

        polyline[ip] = QPointF(xi, yi);
    }

	if ( d_data->canvasRect.isValid() && (d_data->paintAttributes & ClipPolygons) )
		polyline = QwtClipper::clipPolygonF(d_data->canvasRect, polyline);

    QwtPainter::drawPolyline(painter, polyline);

    if ( d_data->brush.style() != Qt::NoBrush )
        fillCurve(painter, xMap, yMap, polyline);
}
Ejemplo n.º 8
0
void
Canvas::autoclip_polyline(const POINT* lppt, unsigned cPoints, const RECT rc)
{
  if (need_clipping())
    clipped_polyline(lppt, cPoints, rc);
  else
    polyline(lppt, cPoints);
}
Ejemplo n.º 9
0
Adesk::Boolean 
myWorldGeometry::polyPolyline (Adesk::UInt32 nbPolylines,
                               const AcGiPolyline * pPolylines) const
{
    _print(_T("\t\tmyWorldGeometry::polylines\n"));
    for (Adesk::UInt32 i = 0; i < nbPolylines; ++i)
        polyline (pPolylines[i]);
    return Adesk::kFalse;
}
Ejemplo n.º 10
0
static inline Polygon qwtToPoints( 
    const QRectF &boundingRect,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QwtSeriesData<QPointF> *series, 
    int from, int to, Round round )
{
    Polygon polyline( to - from + 1 );
    Point *points = polyline.data();

    int numPoints = 0;

    if ( boundingRect.isValid() )
    {
        // iterating over all values
        // filtering out all points outside of
        // the bounding rectangle

        for ( int i = from; i <= to; i++ )
        {
            const QPointF sample = series->sample( i );

            const double x = xMap.transform( sample.x() );
            const double y = yMap.transform( sample.y() );

            if ( boundingRect.contains( x, y ) )
            {
                points[ numPoints ].rx() = round( x );
                points[ numPoints ].ry() = round( y );

                numPoints++;
            }
        }

        polyline.resize( numPoints );
    }
    else
    {
        // simply iterating over all values
        // without any filtering

        for ( int i = from; i <= to; i++ )
        {
            const QPointF sample = series->sample( i );

            const double x = xMap.transform( sample.x() );
            const double y = yMap.transform( sample.y() );

            points[ numPoints ].rx() = round( x );
            points[ numPoints ].ry() = round( y );

            numPoints++;
        }
    }

    return polyline;
}
Ejemplo n.º 11
0
Adesk::Boolean 
myWorldGeometry::polyline  (const AcGiPolyline& polylineObj) const
{
    _print(_T("\t\tmyWorldGeometry::polyline2\n"));
    polyline (polylineObj.points(), 
              polylineObj.vertexList(), 
              polylineObj.normal(), 
              polylineObj.baseSubEntMarker());
    return Adesk::kFalse;
}
Ejemplo n.º 12
0
static void line(FILE *pt,WORD x1,WORD y1,WORD x2,WORD y2)
{
    WORD points[4];
    points[0]=x1;
    points[1]=y1;
    points[2]=x2;
    points[3]=y2;
    polyline(pt,points,4);
    return;
}
Ejemplo n.º 13
0
entities::entities(std::vector< std::vector< dxfpair > > sections) {
    // Read the main information about the entities section and then put it in the enetites class
    int value;
    char string[10000];
    std::vector< dxfpair > single_line;
    std::vector< std::vector< dxfpair > > pline;
    pline.clear();
    single_line.clear();

    for(int i = 0; i < sections.size(); i++) {
        sections[i][0].value_char(string);
        value = detmine_entity(string);
        switch( value ) {
        case 0:
            // Get everything from the start of the polyline designation to an SEQEND value
            pline.clear();  // First clear out the pline information
            do {
                pline.push_back( sections[i] );
                sections[++i][0].value_char(string);
            } while( strncmp(string,"SEQEND",6) != 0 );
            ents_polyline.push_back( polyline( pline ) );
            break;

        case 1:
            // ARC
            ents_arc.push_back( arc( sections[i] ) );
            break;

        case 2:
            // CIRCLE
            ents_circle.push_back( circle( sections[i] ) );
            break;

        case 3:
            // LINE
            ents_line.push_back( line( sections[i] ) );
            break;
        case 11:
            // TEXT
            ents_text.push_back( text( sections[i] ) );
            break;
        case 21:
            // LWPOLYLINE
            ents_lwpolyline.push_back( lwpolyline( sections[i] ) );
        case 9:
            // INSERT
            ents_insert.push_back( insert( sections[i] ) );

            //default:
            // Nothing here
        }

    }

}
Ejemplo n.º 14
0
void
Canvas::line(int ax, int ay, int bx, int by)
{
#ifndef NOLINETO
  ::MoveToEx(dc, ax, ay, NULL);
  ::LineTo(dc, bx, by);
#else
  POINT p[2] = {{ax, ay}, {bx, by}};
  polyline(p, 2);
#endif
}
Ejemplo n.º 15
0
void
Canvas::two_lines(int ax, int ay, int bx, int by, int cx, int cy)
{
#ifndef NOLINETO
  ::MoveToEx(dc, ax, ay, NULL);
  ::LineTo(dc, bx, by);
  ::LineTo(dc, cx, cy);
#else
  POINT p[2];

  p[0].x = ax;
  p[0].y = ay;
  p[1].x = bx;
  p[1].y = by;
  polyline(p, 2);

  p[0].x = cx;
  p[0].y = cy;
  polyline(p, 2);
#endif
}
Ejemplo n.º 16
0
/*!
  \brief Draw lines

  If the CurveAttribute Fitted is enabled a QwtCurveFitter tries
  to interpolate/smooth the curve, before it is painted.

  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param canvasRect Contents rect of the canvas
  \param from index of the first point to be painted
  \param to index of the last point to be painted

  \sa setCurveAttribute(), setCurveFitter(), draw(),
      drawLines(), drawDots(), drawSteps(), drawSticks()
*/
void QwtPlotCurve::drawLines( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    int size = to - from + 1;
    if ( size <= 0 )
        return;

    const bool doAlign = QwtPainter::roundingAlignment( painter );

    QPolygonF polyline( size );

    QPointF *points = polyline.data();
    for ( int i = from; i <= to; i++ )
    {
        const QPointF sample = d_series->sample( i );

        double x = xMap.transform( sample.x() );
        double y = yMap.transform( sample.y() );
        if ( doAlign )
        {
            x = qRound( x );
            y = qRound( y );
        }

        points[i - from].rx() = x;
        points[i - from].ry() = y;
    }

    if ( ( d_data->attributes & Fitted ) && d_data->curveFitter )
        polyline = d_data->curveFitter->fitCurve( polyline );

    if ( d_data->paintAttributes & ClipPolygons )
    {
        qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF());
        const QPolygonF clipped = QwtClipper::clipPolygonF( 
            canvasRect.adjusted(-pw, -pw, pw, pw), polyline, false );

        QwtPainter::drawPolyline( painter, clipped );
    }
    else
    {
        QwtPainter::drawPolyline( painter, polyline );
    }

    if ( d_data->brush.style() != Qt::NoBrush )
        fillCurve( painter, xMap, yMap, canvasRect, polyline );
}
Ejemplo n.º 17
0
void QgsDxfPaintEngine::drawPolygon( const QPointF* points, int pointCount, PolygonDrawMode mode )
{
  Q_UNUSED( mode );
  if ( !mDxf || !mPaintDevice )
  {
    return;
  }

  QgsPolyline polyline( pointCount );
  for ( int i = 0; i < pointCount; ++i )
  {
    polyline[i] = toDxfCoordinates( points[i] );
  }

  bool closed = ( pointCount > 3 && points[0] == points[pointCount - 1] );
  mDxf->writePolyline( polyline, mLayer, "CONTINUOUS", currentColor(), currentWidth(), closed );
}
Ejemplo n.º 18
0
int plane::cross(const polyline &pll, point *crpt, int& qcrpt, 
		 polyline *crpll, int& qcrpll, vfloat prec) const 
{
  pvecerror("int plane::cross(polyline &pll, ...");

  int n;
  qcrpt=0;
  qcrpll=0;
  for(n=0; n<pll.qsl; n++)
  {
    point cpt=cross(pll.sl[n]);
    if(vecerror == 3) // the line is in the plane
      crpll[qcrpll++]=polyline(&(pll.pt[n]), 2);
    else if(vecerror != 0)
      vecerror=0;
    else
    {
      vec v1=cpt-pll.pt[n];
      if(length(v1) < prec)
      {
	if(n == 0) // otherwise it is probably included on the previous step
	{
	  crpt[qcrpt++]=cpt;
	}
      }
      else
      {
	vec v2=cpt-pll.pt[n+1];
	if(length(v2) < prec)
	  crpt[qcrpt++]=cpt;
	else if(check_par( v1 , v2, prec ) == -1 ) 
	        // anti-parallel vectors, point inside borders
	  crpt[qcrpt++]=cpt;
      }
    }
  }
  if(qcrpt>0 || qcrpll>0)
    return 1;
  else
    return 0;
}
Ejemplo n.º 19
0
/*!
  \brief Draw lines
  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted
  \sa QwtCurve::draw, QwtCurve::drawLines, QwtCurve::drawDots, 
      QwtCurve::drawSpline, QwtCurve::drawSteps, QwtCurve::drawSticks
*/
void QwtCurve::drawLines(QPainter *painter,
    const QwtDiMap &xMap, const QwtDiMap &yMap, int from, int to)
{
    QPointArray polyline(to - from + 1);
    for (int i = from; i <= to; i++)
    {
        int xi = xMap.transform(x(i));
        int yi = yMap.transform(y(i));

        polyline.setPoint(i - from, xi, yi);
    }

    QwtPainter::drawPolyline(painter, polyline);

    if ( painter->brush().style() != Qt::NoBrush )
    {
        closePolyline(xMap, yMap, polyline);
        painter->setPen(QPen(Qt::NoPen));
        QwtPainter::drawPolygon(painter, polyline);
    }
}
Ejemplo n.º 20
0
void Plotter::drawCurves(QPainter *painter)
{
    //设置为静态变量,可以使得函数调用时不用每次都进行初始化。
    static const QColor colorForIds[6] =
    {
        Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta, Qt::yellow
    };

    PlotSettings settings = zoomStack[curZoom];
    QRect rect(Margin, Margin, width() - 2 * Margin, height() - 2 * Margin);
    if (!rect.isValid())
        return;

    /*We start by calling setClipRect() to set the QPainter's clip region to the
      rectangle that contains the curves (excluding the margins and the frame around the graph).
      QPainter will then ignore drawing operations on pixels outside the area.
     */
    painter->setClipRect(rect.adjusted(+1, +1, -1, -1));
    QMapIterator<int, QVector<QPointF> > i(curveMap);
    while (i.hasNext())
    {
        i.next();
        int id = i.key();
        const QVector<QPointF> &data = i.value();
        QPolygonF polyline(data.count());
        for (int j = 0; j < data.count(); ++j)
        {
            double dx = data[j].x() - settings.minX;
            double dy = data[j].y() - settings.minY;
            double x = rect.left() + (dx * (rect.width() - 1)
                                         / settings.spanX());
            double y = rect.bottom() - (dy * (rect.height() - 1)
                                           / settings.spanY());
            polyline[j] = QPointF(x, y);
        }
        painter->setPen(colorForIds[uint(id) % 6]);
        painter->drawPolyline(polyline);
    }
}
Ejemplo n.º 21
0
Archivo: plot.c Proyecto: rhdunn/sptk
static void hatching(int type)
{
   int n;
   int frame;
   int d, angle;

   scanf("%d %d", &d, &angle);

   for (n = 0; _getcord(&pb); n++) {
      points[n].x = normx(pb.x);
      points[n].y = normy(pb.y);
   }
   points[n].x = points[0].x;
   points[n].y = points[0].y;

   switch (type -= 20) {
   case 1:
      frame = 1;
      type = -1;
      break;
   case 2:
      frame = 0;
      type = -1;
      break;
   case 3:
      frame = 1;
      type = -1;
      break;
   default:
      if (type < 0) {
         frame = 0;
         type = -type;
      } else
         frame = 1;
      break;
   }
   polyline(points, frame, type, n);
}
Ejemplo n.º 22
0
static void update_window(handle_t hwnd, hsi_window_t *wnd)
  {
  rect_t wnd_rect;
  get_window_rect(hwnd, &wnd_rect);

  extent_t ex;
  rect_extents(&wnd_rect, &ex);

  point_t pt;
  rect_t rect;
  // fill without a border
  rectangle(hwnd, &wnd_rect, 0, wnd->background_color, &wnd_rect);

  if (wnd->draw_border)
    round_rect(hwnd, &wnd_rect, &gray_pen, color_hollow, &wnd_rect, 12);

  /////////////////////////////////////////////////////////////////////////////
  //
  // Draw the HSI Indicator

  const gdi_dim_t mark_start = 12;
  const gdi_dim_t center_x = ex.dx >> 1;
  const gdi_dim_t center_y = ex.dy >> 1;
  const gdi_dim_t window_x = ex.dx;
  const gdi_dim_t window_y = ex.dy;
  const gdi_dim_t border = 10;
  const gdi_dim_t pixels_per_nm_cdi = 6;
  const point_t median = { center_x, center_y };
  const gdi_dim_t major_mark = mark_start + 16;
  const gdi_dim_t minor_mark = mark_start + 8;
  const gdi_dim_t font_x_y = 19;
  const gdi_dim_t font_center = (font_x_y >> 1) + 1;
  const gdi_dim_t font_ordinal = major_mark + font_center;

  // start at 0
  gdi_dim_t i = 0;
  gdi_dim_t index;
  for (index = -wnd->direction; i < 12; index += 30, i++)
    {
    while (index > 359)
      index -= 360;

    while (index < 0)
      index += 360;

    // draw the marker
    point_t pts[2];

    pts[0].x = center_x; pts[0].y = mark_start;
    pts[1].x = center_x; pts[1].y = major_mark;
    rotate_point(&median, &pts[0], index);
    rotate_point(&median, &pts[1], index);

    polyline(hwnd, &wnd_rect, &white_pen, 2, pts);

    bool do_minor_mark = false;
    int16_t minor_index;
    for (minor_index = 0; minor_index < 30; minor_index += 5)
      {
      pts[0].x = center_x; pts[0].y = mark_start;
      pts[1].x = center_x; pts[1].y = do_minor_mark ? minor_mark : major_mark;

      rotate_point(&median, &pts[0], index + minor_index);
      rotate_point(&median, &pts[1], index + minor_index);

      polyline(hwnd, &wnd_rect, &white_pen, 2, pts);

      do_minor_mark = !do_minor_mark;
      }

    // we now draw the text onto the canvas.  The text has a 23x23 pixel
    // block so the center is 12, 12.
    pts[0].x = center_x; pts[0].y = font_ordinal;
    int16_t rotn = (index < 0) ? index + 360 : index;
    rotate_point(&median, &pts[0], rotn);

    draw_text(hwnd, &wnd_rect, wnd->font, color_white, color_black,
      (char *)&i, 1,
      make_point(pts[0].x - font_center, pts[0].y - font_center, &pt),
      0, 0, 0);
    }

  ///////////////////////////////////////////////////////////////////////////
  // Draw the Track

  int rotation = wnd->track - wnd->direction;

  // the marker is a dashed line
  point_t track_marker[4] = {
    { center_x, center_y - 88 },
    { center_x - 7, center_y - 95 },
    { center_x + 7, center_y - 95 },
    { center_x, center_y - 88 }
    };

  for (i = 0; i < 4; i++)
    rotate_point(&median, &track_marker[i], rotation);

  polygon(hwnd, &wnd_rect, &gray_pen, color_hollow, 4, track_marker);

  point_t track_line[2] = {
    { center_x, center_y - 88 },
    { median.x, median.y }
    };

  rotate_point(&median, &track_line[0], rotation);

  polyline(hwnd, &wnd_rect, &track_pen, 2, track_line);

  ///////////////////////////////////////////////////////////////////////////
  // Draw the CDI

  rotation = wnd->course - wnd->direction;

  gdi_dim_t dist;
  for (dist = -10; dist < 11; dist += 2)
    {
    if (dist == 0)
      continue;

    point_t pts[2] = {
      { center_x + (pixels_per_nm_cdi * dist), center_y - 5 },
      { center_x + (pixels_per_nm_cdi * dist), center_y + 5 }
      };

    rotate_point(&median, &pts[0], rotation);
    rotate_point(&median, &pts[1], rotation);

    polyline(hwnd, &wnd_rect, &green_pen_3, 2, pts);
    }

  // draw the CDI Marker head next
  point_t cdi_pts[4] = {
    { center_x, center_y - 97 },
    { center_x - 6, center_y - 88 },
    { center_x + 6, center_y - 88 },
    { center_x, center_y - 97 }
    };

  for (i = 0; i < 4; i++)
    rotate_point(&median, &cdi_pts[i], rotation);

  polygon(hwnd, &wnd_rect, 0, color_green, 4, cdi_pts);

  // we now convert the deviation to pixels.
  // 1 degree = 24 pixels
  double cdi_var = pixels_per_nm_cdi *((double)wnd->deviation / 10);

  gdi_dim_t cdi = (gdi_dim_t) max(-66, min(66, roundf(cdi_var)));

  point_t pts[4];
  pts[0].x = center_x; pts[0].y = center_y - 98;
  pts[1].x = center_x; pts[1].y = center_y - 50;

  rotate_point(&median, &pts[0], rotation);
  rotate_point(&median, &pts[1], rotation);

  polyline(hwnd, &wnd_rect, &green_pen_3, 2, pts);

  pts[0].x = center_x; pts[0].y = center_y + 50;
  pts[1].x = center_x; pts[1].y = center_y + 98;

  rotate_point(&median, &pts[0], rotation);
  rotate_point(&median, &pts[1], rotation);

  polyline(hwnd, &wnd_rect, &green_pen_3, 2, pts);

  pts[0].x = center_x + cdi; pts[0].y = center_y - 48;
  pts[1].x = pts[0].x; pts[1].y = center_y + 48;

  rotate_point(&median, &pts[0], rotation);
  rotate_point(&median, &pts[1], rotation);

  polyline(hwnd, &wnd_rect, &green_pen_3, 2, pts);

  /////////////////////////////////////////////////////////////////////////////
  //	Draw the heading bug.

  int hdg = wnd->heading - wnd->direction;

  point_t heading_points[8] = {
    { center_x - 15, 3 },
    { center_x - 5, 3 },
    { center_x, 10 },
    { center_x + 5, 3 },
    { center_x + 15, 3 },
    { center_x + 15, 12 },
    { center_x - 15, 12 },
    { center_x - 15, 3 }
    };

  for (i = 0; i < 8; i++)
    rotate_point(&median, &heading_points[i], hdg);

  polyline(hwnd, &wnd_rect, &magenta_pen, 8, heading_points);

  heading_points[0].x = center_x - 5; heading_points[0].y = 0;
  heading_points[1].x = center_x + 5; heading_points[1].y = 0;
  heading_points[2].x = center_x; heading_points[2].y = 10;
  heading_points[3].x = center_x - 5; heading_points[3].y = 0;

  polygon(hwnd, &wnd_rect, &white_pen, color_white, 4, heading_points);

  /////////////////////////////////////////////////////////////////////////////
  // Draw the wind direction indicator.
  // it is in the top left of the HSI and has an arrow that is
  // relative to the magnetic heading of the aircraft and the
  // speed/magnetic heading in the form deg/speed so
  // so for a wind of 15 knots at 50 degrees magnetic we would
  // show 050/15.  If the aircraft heading is 240 degrees magnetic we
  // would see a wind vector on the tail of 40 degrees toward the aircraft
  // the wind direction is shown as a yellow triangle around the HSI indicator
  // the text allows for 3 characters with an maximum width of 23 pixels each
  // so the allowance is 69 by 64 pixels

  int16_t relative_wind = wnd->direction + wnd->magnetic_variation - wnd->direction;
  while (relative_wind < 0)
    relative_wind += 360;

  // draw the wind first
  point_t wind_bug[4] =
    {
    { center_x - 15, 2 },
    { center_x + 15, 2 },
    { center_x, 12 },
    { center_x - 15, 2 }
    };

  for (i = 0; i < 4; i++)
    rotate_point(&median, &wind_bug[i], relative_wind);

  polyline(hwnd, &wnd_rect, &yellow_pen, 4, wind_bug);

  // now the text in upper left

  char msg[32];
  sprintf(msg, "%03.3d", wnd->direction + wnd->magnetic_variation);
  size_t length = strlen(msg);

  extent_t pixels;
  text_extent(wnd, wnd->font, msg, length, &pixels);
  draw_text(hwnd, &wnd_rect, wnd->font, color_yellow, color_hollow,
    msg, length, make_point(25 - (pixels.dx >> 1), 2, &pt), 0, 0, 0);

  sprintf(msg, "%d", wnd->wind_speed);
  length = strlen(msg);
  text_extent(wnd, wnd->font, msg, length, &pixels);
  draw_text(hwnd, &wnd_rect, wnd->font, color_yellow, color_hollow,
    msg, length, make_point(25 - (pixels.dx >> 1), 13, &pt), 0, 0, 0);

  /////////////////////////////////////////////////////////////////////////////
  // Draw the estimated time to waypoint.
  // drawn in top right as distance/time
  sprintf(msg, "%d", wnd->distance_to_waypoint);
  length = strlen(msg);
  text_extent(wnd, wnd->font, msg, length, &pixels);
  draw_text(hwnd, &wnd_rect, wnd->font, color_yellow, color_hollow,
    msg, length, make_point(window_x - 25 - (pixels.dx >> 1), 2, &pt), 0, 0, 0);

  sprintf(msg, "%02.2d:%02.2d", wnd->time_to_waypoint / 60, wnd->time_to_waypoint % 60);
  length = strlen(msg);
  text_extent(wnd, wnd->font, msg, length, &pixels);
  draw_text(hwnd, &wnd_rect, wnd->font, color_yellow, color_hollow,
    msg, length, make_point(window_x - 25 - (pixels.dx >> 1), 13, &pt), 0, 0, 0);

  sprintf(msg, "%s", wnd->waypoint_name);
  length = strlen(msg);
  text_extent(wnd, wnd->font, msg, length, &pixels);
  draw_text(hwnd, &wnd_rect, wnd->font, color_yellow, color_hollow,
    msg, length, make_point(window_x - 25 - (pixels.dx >> 1), 24, &pt), 0, 0, 0);
  }
Ejemplo n.º 23
0
Archivo: box.c Proyecto: drafnel/Vis5d
void draw_tick_marks( Display_Context dtx )
{
    float verts[2][3];
    /* base and up vectors for text drawn along x,y,z axes. */
    static float bx[3] = { 0.05, 0.0, 0.0 },      ux[3] = { 0.0, 0.05, 0.05 };
    /*
    static float by[3] = { -0.035, 0.0, -0.035 },  uy[3] = { 0.0, 0.07, 0.0 };
    static float bz[3] = { -0.035, -0.035, 0.0 }, uz[3] = { 0.0, 0.0, 0.07 };
    */
    float tick_inc, i, row, col, lev;
    char str[100];

    /* set depth cueing & line color */
    /* MJK 3.29.99 */
    if (dtx->Reversed) {
        set_color( PACK_COLOR(0,0,0,255) );
    }
    else {
        set_color( dtx->BoxColor );
    }


    set_depthcue( dtx->DepthCue );

    /* go in the order.. low south side, low east side,
       go counter-clock-wise, then high south side, couterclockwise,
       then southeast side, and work coutner-clockwise, so there are
       12 sides to loop through */

    dtx->tick_do[0] = 1;
    dtx->tick_type[0] = 1;
    dtx->tick_num[0] = 10;
    if (dtx->tick_do[0]) {
        tick_inc = (float)(dtx->Nc)/(float)(dtx->tick_num[0]-1);
        row = dtx->Nr-1;
        lev = 0;
        for (i = tick_inc; i < dtx->Nc; i += tick_inc) {
            col = i;
            vis5d_gridPRIME_to_xyzPRIME(dtx->dpy_context_index, 0, 0,
                                        row, col, lev, &verts[0][0], &verts[0][1], &verts[0][2]);
            verts[1][0] = verts[0][0];
            verts[1][1] = verts[0][1] - 0.05;
            verts[1][2] = verts[0][2] - 0.062;
            polyline( verts, 2);
            if (dtx->tick_type[0] == 0) {
                float lat, lon, hgt;
                vis5d_gridPRIME_to_geo(dtx->dpy_context_index, 0, 0,
                                       row, col, lev, &lat, &lon, &hgt);
                /*float2string(lon, str); */
                if (strlen(str) <2) {
                    plot_string( str, verts[1][0]-.009, verts[1][1]-.05, verts[1][2]-0.062, bx, ux, 0);
                }
                else if (strlen(str) <4) {
                    plot_string( str, verts[1][0]-.02, verts[1][1]-.05, verts[1][2]-0.062, bx, ux, 0);
                }
                else {
                    plot_string( str, verts[1][0]-.05, verts[1][1]-.05, verts[1][2]-0.062, bx, ux, 0);
                }
            }
            else if (dtx->tick_type[0] == 1) {
                /* float2string(col, str); */
                if (strlen(str) <2) {
                    plot_string( str, verts[1][0]-.009, verts[1][1]-.05, verts[1][2]-0.062, bx, ux, 0);
                }
                else if (strlen(str) <4) {
                    plot_string( str, verts[1][0]-.02, verts[1][1]-.05, verts[1][2]-0.062, bx, ux, 0);
                }
                else {
                    plot_string( str, verts[1][0]-.05, verts[1][1]-.05, verts[1][2]-0.062, bx, ux, 0);
                }
            }
        }
    }
}
Ejemplo n.º 24
0
void gks_drv_mac(
  int fctid, int dx, int dy, int dimx, int *ia,
  int lr1, double *r1, int lr2, double *r2, int lc, char *chars,
  void **ptr)
{
  p = (ws_state_list *) *ptr;

  switch (fctid)
    {
/* open workstation */
    case 2:
      gkss = (gks_state_list_t *) *ptr;

      p = (ws_state_list *) calloc(1, sizeof(ws_state_list));

      if (pthread_mutex_init(&p->mutex, NULL))
	{
	  perror("pthread_mutex_init");
	  exit(-1);
	}
      p->run = 0;
      if (pthread_create(&p->thread, NULL, exec, (void *) p))
	{
	  perror("pthread_create");
	  exit(-1);
	}

      while (!p->run)
	usleep(10000);

      p->port = GetWindowPort(p->win);
      SetPort(p->port);

      *ptr = p;
      break;

/* close workstation */
    case 3:
      p->run = 0;
      pthread_join(p->thread, NULL);
      pthread_mutex_destroy(&p->mutex);

      free(p);
      break;

/* activate workstation */
    case 4:
      p->state = GKS_K_WS_ACTIVE;
      break;

/* deactivate workstation */
    case 5:
      p->state = GKS_K_WS_INACTIVE;
      break;

/* clear workstation */
    case 6:
      clear_ws();
      break;

/* update workstation */
    case 8:
      pthread_mutex_lock(&p->mutex);
      QDFlushPortBuffer(p->port, NULL);
      pthread_mutex_unlock(&p->mutex);
      break;

/* polyline */
    case 12:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  polyline(ia[0], r1, r2);
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* polymarker */
    case 13:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  polymarker(ia[0], r1, r2);
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* text */
    case 14:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  text(r1[0], r2[0], strlen(chars), chars);
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* fill area */
    case 15:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  fillarea(ia[0], r1, r2);
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* cell array */
    case 16:
    case DRAW_IMAGE:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  int true_color = fctid == DRAW_IMAGE;

	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  cellarray(r1[0], r1[1], r2[0], r2[1], dx, dy, dimx, ia, true_color);
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* set color representation */
    case 48:
      set_color_rep(ia[1], r1[0], r1[1], r1[2]);
      break;

    case 49:
/* set window */
      set_norm_xform(*ia, gkss->window[*ia], gkss->viewport[*ia]);
      break;

    case 50:
/* set viewport */
      set_norm_xform(*ia, gkss->window[*ia], gkss->viewport[*ia]);
      if (*ia == gkss->cntnr)
        set_clip_rect(*ia);
      break;

    case 52:
/* select normalization transformation */
    case 53:
/* set clipping inidicator */
      set_clip_rect(gkss->cntnr);
      break;

/* set workstation window */
    case 54:
      p->window[0] = r1[0];
      p->window[1] = r1[1];
      p->window[2] = r2[0];
      p->window[3] = r2[1];

      set_xform();
      init_norm_xform();
      break;

/* set workstation viewport */
    case 55:
      p->viewport[0] = r1[0];
      p->viewport[1] = r1[1];
      p->viewport[2] = r2[0];
      p->viewport[3] = r2[1];

      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  LockPortBits(p->port);
	  resize_window();
	  set_xform();
	  init_norm_xform();
	  UnlockPortBits(p->port);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

/* request locator */
    case 81:
      if (p->state == GKS_K_WS_ACTIVE)
	{
	  pthread_mutex_lock(&p->mutex);
	  QDFlushPortBuffer(p->port, NULL);
	  get_pointer(r1, r2, &ia[0]);
	  pthread_mutex_unlock(&p->mutex);
	}
      break;

    default:
      ;
    }
}
Ejemplo n.º 25
0
Archivo: plotter.cpp Proyecto: Qmax/PT6
void Plotter::drawCurves(QPainter *painter)
{
	//printf("Inside DrawCurves\n");


    static const QColor colorForIds[7] = {Qt::red,Qt::green,Qt::cyan,Qt::magenta,Qt::yellow,Qt::blue,Qt::white};
    PlotSettings settings = zoomStack[curZoom];
    if( m_moveFlag == true)
    {
        settings.maxX = m_ZoomSettings->maxX;
        settings.maxY = m_ZoomSettings->maxY;
        settings.minX = m_ZoomSettings->minX;
        settings.minY = m_ZoomSettings->minY;
        settings.m_nOffset = m_ZoomSettings->m_nOffset;
        settings.numXTicks = m_ZoomSettings->numXTicks;
        settings.numYTicks = m_ZoomSettings->numYTicks;
    }
    QRect rect(Margin,Margin,width()-(2*Margin),height()-(2*Margin));
    //qDebug()<<"Draw Curves:"<< settings.m_nOffset;
    if(m_bshowZoomRect == true)
    {
        painter->setPen(colorForIds[6]);
        painter->drawRect(rubberBandRect);
    }

    if(!rect.isValid())
        return;
    painter->setClipRect(rect.adjusted(+1,+1,-1,-1));
    QMapIterator<int, QVector<QPointF> > i(curveMap);
//    printf("Rect Left: %d\n",rect.left());
//    printf("Rect Height: %d\n",rect.height());
//    printf("Rect width: %d\n",rect.width());
//    printf("Rect Bottom: %d\n",rect.bottomLeft().y());
//    printf("Rect Top: %d\n",rect.top());
    double dx,dy;
    while(i.hasNext()){

        i.next();
        int id = i.key();
        QVector<QPointF> data = i.value();
        QPolygonF polyline(data.count());
        double y =0.0,x=0.0;
        int l_nCounter =0;
        //printf("MinY:%f\n",settings.minY);
        //printf("Offset:%f\n",m_nOffset);
        for(int j=0; j< data.count();++j)
        {
             dx = data[j].x();
             dy = data[j].y();
             if(m_bUniPolar == true)
             {
                 float l_nDiv = (dy/2.0);
                 printf("UniPolar %f->%f\n",l_nDiv,dy - l_nDiv);
             }
             if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX))
             {
                 //printf("X:%f Y:%f\n",dx,dy);
             }
            y =0.0,x=0.0;
            if(m_ZoomFlag == false)
            {
                if(m_bVIMode == true)
                    x = (rect.width()/2+ (dx*(((rect.width()-1)))/(settings.spanX())));
                else
                    x = (rect.left()+ (dx*(((rect.width()-1)))/(settings.spanX())));

                if( m_bUniPolar == true){
                    y = ((Margin+rect.bottom()) - (((dy/2.0)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
                    printf(" Coord-Y %f\n",dy/2.0);
                }
                else
                    y = ((Margin+rect.height()) - (((dy-settings.minY)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
                	//y = ((Margin+rect.height()/2) - ((dy*rect.height()-1)/4.096));/*((rect.height()-1))));*/
                	//y = (Margin+rect.height()/2) - (dy);
               // printf(" Coord- X & Y %f %f\n",x,y);
               // qDebug() << dy;
            }
            else if(m_ZoomFlag == true)
            {
                x = (rect.left() + ((dx-settings.minX)*(((rect.width()-1)))/(settings.spanX())));
                y = ((Margin+rect.height()) - (((dy-settings.minY)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
            }
            if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX)&&(( data[j].y()>=settings.minY && data[j].y()<=settings.maxY)))
            {
                polyline[j] = QPointF(x,y);
                l_nCounter++;
            }
        }
        QPolygonF zoomPolyline(l_nCounter);
        y =0.0,x=0.0;
        int l_nIndex1 =0;
        for(int l_nIndex=0;l_nIndex< data.count();l_nIndex++)
        {
            QPointF(x,y);
            x = polyline.at(l_nIndex).x();
            y = polyline.at(l_nIndex).y();
            if(x!=0.0 || y!=0.0 )
            {
                zoomPolyline[l_nIndex1] = QPointF(x,y);
                l_nIndex1++;
            }
        }
        painter->setPen(colorForIds[uint(id) %6]);
        if(m_ZoomFlag == false)
            painter->drawPolyline(polyline);
        else
            painter->drawPolyline(zoomPolyline);
        }
    }
Ejemplo n.º 26
0
void dialogAnalog::fillPixmap(CData *data, QPen *dataPen)
{
    mainwindow->analogMutex.lock();
	TAnalog_Data plot,next_plot;
	QPainter painter;
    int heightPerField = lastPixmap.height() / NbBits;
	
	painter.begin(&lastPixmap);
	painter.setPen(*dataPen);

    QVector< QVector<QPoint> > polyline(64);

    Qt::CheckState csMarker = chkBShowMarker->checkState();

    for (int j=1;j<data->size();j++)
	{
		plot = data->Read(j-1);
		next_plot = data->Read(j);

		int current = heightPerField;
		int X1,Y1,X2,Y2;
		
		X1=StateToX(plot.state);
		X2=StateToX(next_plot.state);

        // Crop to the visible area
        if (!( (j>1) && ( (X2<0) || ( X1>frame_dataview->width())))) {

            for (int jj=0;jj<NbBits;jj++)
            {
                //#define READ_BIT(b,p)	( ((b)>>(p)) & 0x01 ? 1 :0 )
                Y1= current - READ_BIT(plot.values,jj)* 3 * heightPerField / 5;
                Y2= current - READ_BIT(next_plot.values,jj)* 3 * heightPerField / 5;
                //painter.drawLine(X1,Y1,X2,Y1);
                //painter.drawLine(X2,Y1,X2,Y2);
                polyline[jj].append( QPoint(X1,Y1) );
                polyline[jj].append( QPoint(X2,Y1) );
                current += heightPerField;
            }

            // plot the Markers
            // Need to optimize
            if ( plot.marker && (csMarker == Qt::Checked) ) {
                QPen pen((Qt::white));
                pen.setStyle(Qt::DotLine);
                painter.setPen(pen);
                painter.drawLine(X1,12,X1,height());
                // set font ------------------------------------------------------------------------------------
                QFont textFont;
                textFont.setPixelSize(10);
                painter.setFont(textFont);
                painter.drawText(X1, 11, QString::number(plot.marker,10));
                painter.setPen(*dataPen);
            }
        }
	}
    if (polyline.size()) {
        for (int jj=0;jj<NbBits;jj++)
        {
            if (polyline[jj].size())
                painter.drawPolyline(polyline[jj].data(),polyline[jj].size());
        }
    }
	painter.end();
    mainwindow->analogMutex.unlock();
}
Ejemplo n.º 27
0
void Plotter::drawCurves(QPainter *painter)
{
	//~~~~~~~~Adjust X-y Axis ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    QStringList stringList;
    bool ok=true;
    QFile textFile("AdjustXYaxisVI.txt");
    if (textFile.open(QIODevice::ReadOnly))
    {
        QTextStream textStream(&textFile);
        while (!textStream.atEnd())
        {
            stringList.append(textStream.readLine());
        }
        adjustXaxis=stringList.value(0).toDouble(&ok) * m_nXZoomFactor;
        adjustYaxis=stringList.value(1).toDouble(&ok) * m_nYZoomFactor;
    }else{
        adjustXaxis=5.5;
        adjustYaxis=0;
    }
//    qDebug() << "Zoom Factor:" << m_nXZoomFactor << m_nYZoomFactor;
//    qDebug() << "Adjust Axis:" << adjustXaxis << adjustYaxis;
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    static const QColor colorForIds[8] = {Qt::red,Qt::green,Qt::cyan,Qt::magenta,Qt::yellow,Qt::white,Qt::gray,Qt::black};
    PlotSettings settings = zoomStack[curZoom];
    if( m_moveFlag == true)
    {
        settings.maxX = m_ZoomSettings->maxX;
        settings.maxY = m_ZoomSettings->maxY;
        settings.minX = m_ZoomSettings->minX;
        settings.minY = m_ZoomSettings->minY;
        settings.m_nOffset = m_ZoomSettings->m_nOffset;
        settings.numXTicks = m_ZoomSettings->numXTicks;
        settings.numYTicks = m_ZoomSettings->numYTicks;
    }
    QRect rect(Margin,Margin,width()-(2*Margin),height()-(2*Margin));
    if(m_bshowZoomRect == true)
    {
        painter->setPen(colorForIds[6]);
        painter->drawRect(rubberBandRect);
    }

    if(!rect.isValid())
        return;
    painter->setClipRect(rect.adjusted(+1,+1,-1,-1));
    QMapIterator<int, QVector<QPointF> > i(curveMap);
//    printf("Rect Left: %d\n",rect.left());
//    printf("Rect Height: %d\n",rect.height());
//    printf("Rect width: %d\n",rect.width());
//    printf("Rect Bottom: %d\n",rect.bottomLeft().y());
//    printf("Rect Top: %d\n",rect.top());
    double dx,dy;
    while(i.hasNext()){

        i.next();
        int id = i.key();
      //  qDebug() << "Curve ID" << id;
        QVector<QPointF> data = i.value();
        QPolygonF polyline(data.count());
        double y =0.0,x=0.0;
        int l_nCounter =0;
        //printf("MinY:%f\n",settings.minY);
        //printf("Offset:%f\n",m_nOffset);
        m_nOffset =0.0;
        for(int j=0; j< data.count();++j)
        {
             dx = data[j].x();
             dy = data[j].y();
             if(m_bUniPolar == true)
             {
                 float l_nDiv = (dy/2.0);
//                 printf("UniPolar %f->%f\n",l_nDiv,dy - l_nDiv);
             }
             if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX))
             {
                 //printf("X:%f Y:%f\n",dx,dy);
             }
            y =0.0,x=0.0;
            if(m_ZoomFlag == false)
            {
                if(m_bVIMode == true)
                    x = ((rect.width()/2)+adjustXaxis  + ((dx)*(((rect.width()-1)))/(settings.spanX())));
                else
                    x = (rect.left()+ ((dx)*(((rect.width()-1)))/(settings.spanX())));

                if( m_bUniPolar == true){
                    y = ((Margin+rect.bottom()) - (((dy/2.0)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
                    //y+=10;
//                    printf(" Coord-Y %f\n",dy/2.0);
                }
                else
                    y = (((Margin+rect.height()/2)+adjustYaxis) - ((dy+m_nOffset)*((rect.height()-1))/(settings.spanY())));//TO CHANGE THE Y AXIS IN THE GRAPH
               // printf(" Coord- X & Y %f %f\n",x,y);
            }
            else if(m_ZoomFlag == true)
            {
                x = (rect.left() + ((dx-settings.minX)*(((rect.width()-1)))/(settings.spanX())));
                y = ((Margin+rect.height()) - (((dy-settings.minY)+settings.m_nOffset)*((rect.height()-1))/(settings.spanY())));
            }
            if(( data[j].x()>=settings.minX && data[j].x()<=settings.maxX)&&(( data[j].y()>=settings.minY && data[j].y()<=settings.maxY)))
            {

            	polyline[j] = QPointF(x,y);
                l_nCounter++;
            }
        }
        QPolygonF zoomPolyline(l_nCounter);
        y =0.0,x=0.0;
        int l_nIndex1 =0;
        for(int l_nIndex=0;l_nIndex< data.count();l_nIndex++)
        {
            QPointF(x,y);
            x = polyline.at(l_nIndex).x();
            y = polyline.at(l_nIndex).y();
            //qDebug()<<x<<y;
            if(x!=0.0 || y!=0.0 )
            {
                zoomPolyline[l_nIndex1] = QPointF(x,y);
                l_nIndex1++;
            }
        }
//        if( m_nClearID == id)
//        	painter->setPen(Qt::black);
        //else
        	QPen pen;
        	painter->setPen(colorForIds[uint(id) %6]);
//        	pen.setColor(colorForIds[uint(id) %6]);
//            pen.setWidth(20);
//            painter->setPen(pen);


        if(m_ZoomFlag == false)
        {
        	painter->setPen(colorForIds[uint(id) %6]);
                painter->drawPolyline(polyline);
//            qDebug()<<"Band:"<<m_objPlotData->m_nEnvelopBand;
            //compareCurvePoints(polyline1);
        }
        else
            painter->drawPolyline(zoomPolyline);
        }
   // qDebug() << "Exit Draw Cruves.";
}
Ejemplo n.º 28
0
 void ide_device::polyline(int n, double *x, double *y, const pGEcontext gc) {
     auto dev = get_or_create_file_device();
     if (dev->polyline != nullptr) {
         dev->polyline(n, x, y, gc, dev);
     }
 }
Ejemplo n.º 29
0
/*!
  \brief Draw a spline
  \param painter Painter
  \param xMap x map
  \param yMap y map
  \sa QwtCurve::draw, QwtCurve::drawCurve, QwtCurve::drawDots,
      QwtCurve::drawLines, QwtCurve::drawSteps, QwtCurve::drawSticks
*/
void QwtCurve::drawSpline(QPainter *painter,
    const QwtDiMap &xMap, const QwtDiMap &yMap)
{
    register int i;

    int size = dataSize();
    double *txval = new double[size];
    double *tyval = new double[size];


    if ( !txval || !tyval )
    {
        if (txval) delete[] txval;
        if (tyval) delete[] tyval;
        return;
    }

    QPointArray polyline(d_splineSize);

    //
    // Transform x and y values to window coordinates
    // to avoid a distinction between linear and
    // logarithmic scales.
    //
    for (i=0;i<size;i++)
    {
        txval[i] = xMap.xTransform(x(i));
        tyval[i] = yMap.xTransform(y(i));
    }

    int stype;
    if (! (d_options & (Yfx|Xfy|Parametric)))
    {
        if (qwtChkMono(txval, size))
        {
            stype = Yfx;
        }
        else
        {
            if(qwtChkMono(tyval, size))
            {
                stype = Xfy;
            }
            else
            {
                stype = Parametric;
                if ( (d_options & Periodic) ||
                    ( (x(0) == x(size-1))
                    && (y(0) == y(size-1))))
                {
                    stype |= Periodic;
                }
            }
        }
    }
    else
    {
        stype = d_options;
    }

    if (stype & Parametric)
    {
        double *param = new double[size];
        if (param)
        {
            //
            // setup parameter vector
            //
            param[0] = 0.0;
            for (i=1; i<size; i++)
            {
                double delta = sqrt( qwtSqr(txval[i] - txval[i-1])
                              + qwtSqr( tyval[i] - tyval[i-1]));
                param[i] = param[i-1] + qwtMax(delta, 1.0);
            }

            //
            // setup splines
            int rc = d_spx.recalc(param, txval, size, stype & Periodic);
            if (!rc)
                rc = d_spy.recalc(param, tyval, size, stype & Periodic);

            if (rc)
            {
                drawLines(painter, xMap, yMap, 0, size - 1);
            }
            else
            {
                // fill point array
                double delta = param[size - 1] / double(d_splineSize-1);
                for (i=0;i<d_splineSize;i++)
                {
                    double dtmp = delta * double(i);
                    polyline.setPoint(i, int(floor (d_spx.value(dtmp) + 0.5)),
                                  int(floor (d_spy.value(dtmp) + 0.5)));
                }
            }

            delete[] param;
        }
    }
    else if (stype & Xfy)
    {
        if (tyval[size-1] < tyval[0])
        {
            qwtTwistArray(txval, size);
            qwtTwistArray(tyval, size);
        }

        // 1. Calculate spline coefficients
        int rc = d_spx.recalc(tyval, txval, size, stype & Periodic);
        if (rc)                         // an error occurred
        {
            drawLines(painter, xMap, yMap, 0, size - 1);
        }
        else                            // Spline OK
        {
            double ymin = qwtGetMin(tyval, size);
            double ymax = qwtGetMax(tyval, size);
            double delta = (ymax - ymin) / double(d_splineSize - 1);

            for (i=0;i<d_splineSize;i++)
            {
                double dtmp = ymin + delta * double(i);
                polyline.setPoint(i, int(floor(d_spx.value(dtmp) + 0.5)),
                              int(floor(dtmp + 0.5)));
            }
        }
    }
    else
    {
        if (txval[size-1] < txval[0])
        {
            qwtTwistArray(tyval, size);
            qwtTwistArray(txval, size);
        }


        // 1. Calculate spline coefficients
        int rc = d_spy.recalc(txval, tyval, size, stype & Periodic);
        if (rc)                         // error
        {
            drawLines(painter, xMap, yMap, 0, size - 1);
        }
        else                            // Spline OK
        {
            double xmin = qwtGetMin(txval, size);
            double xmax = qwtGetMax(txval, size);
            double delta = (xmax - xmin) / double(d_splineSize - 1);

            for (i=0;i<d_splineSize;i++)
            {
                double dtmp = xmin + delta * double(i);
                polyline.setPoint(i, int(floor (dtmp + 0.5)),
                              int(floor(d_spy.value(dtmp) + 0.5)));
            }
        }
    }

    delete[] txval;
    delete[] tyval;

    QwtPainter::drawPolyline(painter, polyline);

    if ( painter->brush().style() != Qt::NoBrush )
    {
        closePolyline(xMap, yMap, polyline);
        painter->setPen(QPen(Qt::NoPen));
        QwtPainter::drawPolygon(painter, polyline);
    }
}
Ejemplo n.º 30
0
void GLWidget3D::drawScene(int drawMode) {
	///////////////////////////////////
	// GEN MODE
	if(G::global().getInt("3d_render_mode")==0){
		//vboRenderManager.renderStaticGeometry(QString("sky"));

		glDisable(GL_CULL_FACE);
		mainWin->urbanGeometry->render(vboRenderManager);
		glEnable(GL_CULL_FACE);
		
		vboRenderManager.vboTerrain.render(vboRenderManager);
		if(mainWin->controlWidget->ui.terrain_2DShader->isChecked()==false)
			vboRenderManager.vboWater.render(vboRenderManager);

		// draw the selected vertex and edge
		if (vertexSelected) {
			RendererHelper::renderPoint(vboRenderManager, "selected_vertex", selectedVertex->pt, QColor(0, 0, 255), selectedVertex->pt3D.z() + 2.0f);
		}
		if (edgeSelected) {
			Polyline3D polyline(selectedEdge->polyline3D);
			for (int i = 0; i < polyline.size(); ++i) polyline[i].setZ(polyline[i].z() + 10.0f);
			RendererHelper::renderPolyline(vboRenderManager, "selected_edge_lines", "selected_edge_points", polyline, QColor(0, 0, 255));
		}

	}
	///////////////////////////////////
	// LC MODE
	if(G::global().getInt("3d_render_mode")==1||G::global().getInt("3d_render_mode")==2){//LC HATCH

		// NORMAL
		if(drawMode==0){
			glUniform1i(glGetUniformLocation(vboRenderManager.program,"shadowState"), 0);//SHADOW: Disable

			// RENDER SKY WATER

			vboRenderManager.renderStaticGeometry(QString("sky"));
			vboRenderManager.vboWater.render(vboRenderManager);

			

			if(shadowEnabled)
				glUniform1i(glGetUniformLocation(vboRenderManager.program,"shadowState"), 1);//SHADOW: Render Normal with Shadows

			vboRenderManager.vboTerrain.render(vboRenderManager);

			vboRenderManager.renderStaticGeometry(QString("3d_sidewalk"));
			vboRenderManager.renderStaticGeometry(QString("3d_roads"));

			
			vboRenderManager.renderStaticGeometry(QString("3d_roads_inter"));//
			vboRenderManager.renderStaticGeometry(QString("3d_roads_interCom"));//
			

			vboRenderManager.renderStaticGeometry(QString("3d_building"));
			vboRenderManager.renderStaticGeometry(QString("3d_building_fac"));

			if(mainWin->controlWidget->ui.render_3DtreesCheckBox->isChecked()){
				vboRenderManager.renderStaticGeometry(QString("3d_trees"));//hatch
				vboRenderManager.renderAllStreetElementName("tree");//LC
				vboRenderManager.renderAllStreetElementName("streetLamp");//LC
			}

		}
		// SHADOWS
		if(drawMode==1){
			glUniform1i(glGetUniformLocation(vboRenderManager.program,"shadowState"), 2);// SHADOW: From light

			vboRenderManager.vboTerrain.render(vboRenderManager);

			//vboRenderManager.renderStaticGeometry(QString("3d_sidewalk"));
			//vboRenderManager.renderStaticGeometry(QString("3d_roads"));
			vboRenderManager.renderStaticGeometry(QString("3d_building"));
			vboRenderManager.renderStaticGeometry(QString("3d_building_fac"));

			if(mainWin->controlWidget->ui.render_3DtreesCheckBox->isChecked()){
				vboRenderManager.renderStaticGeometry(QString("3d_trees"));//hatch
				vboRenderManager.renderAllStreetElementName("tree");//LC
				vboRenderManager.renderAllStreetElementName("streetLamp");//LC
			}
		}
	}

	///////////////////////////////////
	// 2D WITH BLOCKS MODE
	if(G::global().getInt("3d_render_mode")==3){

		glDisable(GL_CULL_FACE);
		mainWin->urbanGeometry->render(vboRenderManager);
		glEnable(GL_CULL_FACE);
		
		vboRenderManager.vboTerrain.render(vboRenderManager);

		vboRenderManager.renderStaticGeometry(QString("2d_blocks"));
		vboRenderManager.renderStaticGeometry(QString("2d_parks"));

		// draw the selected vertex and edge
		if (vertexSelected) {
			RendererHelper::renderPoint(vboRenderManager, "selected_vertex", selectedVertex->pt, QColor(0, 0, 255), selectedVertex->pt3D.z() + 2.0f);
		}
		if (edgeSelected) {
			Polyline3D polyline(selectedEdge->polyline3D);
			for (int i = 0; i < polyline.size(); ++i) polyline[i].setZ(polyline[i].z() + 10.0f);
			RendererHelper::renderPolyline(vboRenderManager, "selected_edge_lines", "selected_edge_points", polyline, QColor(0, 0, 255));
		}

	}
}