Пример #1
0
void XYChartCore::paintAxis(QPainter* painter)
{
    const qreal minKey = xAxis()->minimumValue();
    const qreal maxKey = xAxis()->maximumValue();
    const qreal minValue = yAxis()->minimumValue();
    const qreal maxValue = yAxis()->maximumValue();

    const QPointF origo = translatePoint(QPointF(0.0, 0.0));
    const QPointF p1 = translatePoint(QPointF(minKey, 0.0));
    const QPointF p2 = translatePoint(QPointF(maxKey, 0.0));
    const QPointF p3 = translatePoint(QPointF(0.0, minValue));
    const QPointF p4 = translatePoint(QPointF(0.0, maxValue));

    if (origo != p1)
        painter->drawLine(origo, p1);

    if (origo != p2)
        painter->drawLine(origo, p2);

    if (origo != p3)
        painter->drawLine(origo, p3);

    if (origo != p4)
        painter->drawLine(origo, p4);
}
Пример #2
0
void QwtPlotZoomer::rescale()
{
    QwtPlot *plt = plot();
    if ( !plt )
        return;

    const QRectF &rect = d_data->zoomStack[d_data->zoomRectIndex];
    if ( rect != scaleRect() )
    {
        const bool doReplot = plt->autoReplot();
        plt->setAutoReplot( false );

        double x1 = rect.left();
        double x2 = rect.right();
        if ( !plt->axisScaleDiv( xAxis() ).isIncreasing() )
            qSwap( x1, x2 );

        plt->setAxisScale( xAxis(), x1, x2 );

        double y1 = rect.top();
        double y2 = rect.bottom();
        if ( !plt->axisScaleDiv( yAxis() ).isIncreasing() )
            qSwap( y1, y2 );

        plt->setAxisScale( yAxis(), y1, y2 );

        plt->setAutoReplot( doReplot );

        plt->replot();
    }
}
Пример #3
0
void ImageMarker::updateBoundingRect() {
  if (!plot()) return;

  setXValue(plot()->invTransform(xAxis(), d_pos.x()));
  d_x_right = plot()->invTransform(xAxis(), d_pos.x() + d_size.width());

  setYValue(plot()->invTransform(yAxis(), d_pos.y()));
  d_y_bottom = plot()->invTransform(yAxis(), d_pos.y() + d_size.height());
}
/*!
  Return normalized bounding rect of the axes

  \warning Calling QwtPlot::setAxisScale() while QwtPlot::autoReplot() is FALSE
           leaves the axis in an 'intermediate' state.
           In this case, to prevent buggy behaviour, you must call
           QwtPlot::replot() before calling QwtPlotPicker::scaleRect().
           This quirk will be removed in a future release.

  \sa QwtPlot::autoReplot(), QwtPlot::replot().
*/
QwtDoubleRect QwtPlotPicker::scaleRect() const
{
    const QwtPlot *plt = plot();

    const QwtDoubleRect rect(
        plt->axisScale(xAxis())->lBound(),
        plt->axisScale(xAxis())->hBound(),
        plt->axisScale(yAxis())->lBound(),
        plt->axisScale(yAxis())->hBound()
    );

    return rect.normalize();
}
Пример #5
0
void Spectrogram::createLabels()
{
	clearLabels();

	QwtValueList levels = contourLevels();
	const int numLevels = levels.size();
    for (int l = 0; l < numLevels; l++){
		PlotMarker *m = new PlotMarker(l, d_labels_angle);

		QwtText t = QwtText(QString::number(levels[l]));
		t.setColor(d_labels_color);
		t.setFont(d_labels_font);

		if (d_white_out_labels)
			t.setBackgroundBrush(QBrush(Qt::white));
        else
            t.setBackgroundBrush(QBrush(Qt::transparent));
		m->setLabel(t);

        int x_axis = xAxis();
        int y_axis = yAxis();
		m->setAxis(x_axis, y_axis);

        if (d_graph && d_show_labels)
			m->attach(d_graph);
		d_labels_list << m;
	}
}
Пример #6
0
void COLLADA_Viewer::SixAxis(float flX, float flY, float flZ, float flG)
{
	(void) flG;
	if (_CrtRender.UsingPhysics())
	{
		static float dampedX = 0.0f;
		static float dampedY = 0.0f;
		static float dampedZ = 0.0f;

		dampedX=(flX + 10.f*dampedX)/11.f;
		dampedY=(flY + 10.f*dampedY)/11.f;
		dampedZ=(flZ + 10.f*dampedZ)/11.f;
		
		btTransform floorTrans;
		floorTrans.setIdentity();
		
		btVector3 xAxis(1,0,0);
		btVector3 zAxis(0,0,1);
		btQuaternion rotX(zAxis,dampedX*10.f);
		btQuaternion rotZ(xAxis,-dampedZ*10.f);
		
		btQuaternion combinedRot = rotZ*rotX;
		
		btMatrix3x3 orn;
		orn.setRotation(combinedRot);
		btVector3 up = orn.getColumn(1);

		CrtVec3f newG = CrtVec3f(up.getX(),up.getY(),up.getZ());
		_CrtRender.SetGravity(newG);
//	    printf("new gravity (%f, %f, %f)\n", newG.getX(), newG.getY(), newG.getZ());
	}
}
Пример #7
0
QwtDoubleRect PlotCurve::boundingRect() const
{
    QwtDoubleRect r = QwtPlotCurve::boundingRect();

    double percent = 0.01;

    double dw = percent*fabs(r.right() - r.left());
    double left = r.left() - dw;
    if (left <= 0.0) {
        ScaleEngine *sc_engine = (ScaleEngine *)this->plot()->axisScaleEngine(xAxis());
        if (sc_engine && (sc_engine->type() == ScaleTransformation::Log10 ||
                          sc_engine->type() == ScaleTransformation::Log2 ||
                          sc_engine->type() == ScaleTransformation::Ln))
            left = r.left();
    }

    r.setLeft(left);
    r.setRight(r.right() + dw);

    double dh = percent*fabs(r.top() - r.bottom());
    r.setBottom(r.bottom() + dh);

    double top = r.top() - dh;
    if (top <= 0.0) {
        ScaleEngine *sc_engine = (ScaleEngine *)this->plot()->axisScaleEngine(yAxis());
        if (sc_engine && (sc_engine->type() == ScaleTransformation::Log10 ||
                          sc_engine->type() == ScaleTransformation::Log2 ||
                          sc_engine->type() == ScaleTransformation::Ln))
            top = r.top();
    }
    r.setTop(top);

    return r;
}
Пример #8
0
BaseIF* makeChamber(const Real& radius,
                    const Real& thick,
                    const Real& offset,
                    const Real& height)
{
  RealVect zero(D_DECL(0.0,0.0,0.0));
  RealVect xAxis(D_DECL(1.0,0.0,0.0));
  bool inside = true;

  Vector<BaseIF*> pieces;

  // Create a chamber
  TiltedCylinderIF chamberOut(radius + thick/2.0,xAxis,zero, inside);
  TiltedCylinderIF chamberIn (radius - thick/2.0,xAxis,zero,!inside);

  IntersectionIF infiniteChamber(chamberIn,chamberOut);

  pieces.push_back(&infiniteChamber);

  RealVect normal1(D_DECL(1.0,0.0,0.0));
  RealVect point1(D_DECL(offset,0.0,0.0));
  PlaneIF plane1(normal1,point1,inside);

  pieces.push_back(&plane1);

  RealVect normal2(D_DECL(-1.0,0.0,0.0));
  RealVect point2(D_DECL(offset+height,0.0,0.0));
  PlaneIF plane2(normal2,point2,inside);

  pieces.push_back(&plane2);

  IntersectionIF* chamber = new IntersectionIF(pieces);

  return chamber;
}
Пример #9
0
/*!
  Expand the selected rectangle to minZoomSize() and zoom in
  if accepted.

  \param ok If true, complete the selection and emit selected signals
            otherwise discard the selection.

  \sa accept(), minZoomSize()
  \return True if the selection has been accepted, false otherwise
*/
bool QwtPlotZoomer::end( bool ok )
{
    ok = QwtPlotPicker::end( ok );
    if ( !ok )
        return false;

    QwtPlot *plot = QwtPlotZoomer::plot();
    if ( !plot )
        return false;

    const QPolygon &pa = selection();
    if ( pa.count() < 2 )
        return false;

    QRect rect = QRect( pa.first(), pa.last() );
    rect = rect.normalized();

    const QwtScaleMap xMap = plot->canvasMap( xAxis() );
    const QwtScaleMap yMap = plot->canvasMap( yAxis() );

    QRectF zoomRect = QwtScaleMap::invTransform( xMap, yMap, rect ).normalized();

    zoomRect = qwtExpandedZoomRect( zoomRect, minZoomSize(),
        xMap.transformation(), yMap.transformation() );

    zoom( zoomRect );

    return true;
}
Пример #10
0
Matrix RendererD3D::GetBillboardMatrix(Vector cameraPos, Vector upVector)
{
	Vector xAxis(0.0f,0.0f,0.0f);
	Vector yAxis(0.0f,0.0f,0.0f);
	Vector zAxis(0.0f,0.0f,0.0f);
	Vector upVect(0.0f,1.0f,0.0f);

	Vector cameraVector = cameraPos;

	zAxis = cameraVector;
	zAxis.normalize();

	xAxis = zAxis.Cross(upVect);
	xAxis.normalize();

	yAxis = xAxis.Cross(zAxis);
	yAxis.normalize();

	Matrix transform = { xAxis.x, xAxis.y, xAxis.z, 0.0f,
					yAxis.x, yAxis.y, yAxis.z, 0.0f,
					zAxis.x, zAxis.y, zAxis.z, 0.0f,
					0.0f, 0.0f, 0.0f, 1.0f };

	return transform;
}
Пример #11
0
QPoint ArrowMarker::endPoint() const {
  if (!plot())
    return QPoint();

  return QPoint(plot()->transform(xAxis(), d_rect.right()),
                plot()->transform(yAxis(), d_rect.bottom()));
}
Пример #12
0
BaseIF* makeVanes(const int&      num,
                  const Real&     thick,
                  const RealVect& normal,
                  const Real&     innerRadius,
                  const Real&     outerRadius,
                  const Real&     offset,
                  const Real&     height)
{
  RealVect zero(D_DECL(0.0,0.0,0.0));
  RealVect xAxis(D_DECL(1.0,0.0,0.0));

  BaseIF* oneVane = makeVane(thick,normal,innerRadius,outerRadius,offset,height);

  Vector<BaseIF*> eachVane;

  for (int i = 0; i < num; i++)
  {
    Real angle = i * 2*M_PI / num;

    TransformIF* currentVane = new TransformIF(*oneVane);
    currentVane->rotate(angle,zero,xAxis);

    eachVane.push_back(currentVane);
  }

  UnionIF* allVanes = new UnionIF(eachVane);

  return allVanes;
}
void QwtPlotScaleItem::updateBorders()
{
    const QwtPlot *plt = plot();
    if ( plt == NULL || !d_data->scaleDivFromAxis )
        return;
    
    const QRect r = plt->canvas()->contentsRect();
    d_data->canvasRectCache = r;

    QwtDoubleInterval interval;
    if ( d_data->scaleDraw->orientation() == Qt::Horizontal )
    {
        const QwtScaleMap map = plt->canvasMap(xAxis());
        interval.setMinValue(map.invTransform(r.left()));
        interval.setMaxValue(map.invTransform(r.right()));
    }
    else
    {
        const QwtScaleMap map = plt->canvasMap(yAxis());
        interval.setMinValue(map.invTransform(r.bottom()));
        interval.setMaxValue(map.invTransform(r.top()));
    }

    QwtScaleDiv scaleDiv = d_data->scaleDraw->scaleDiv();
    scaleDiv.setInterval(interval);
    d_data->scaleDraw->setScaleDiv(scaleDiv);
}
Пример #14
0
void Grid::enableZeroLineY(bool enable)
{
	Graph *d_plot = (Graph *)plot();
	if (!d_plot)
		return;

	if (!mrkY && enable) {
		mrkY = new QwtPlotMarker();
		d_plot->insertMarker(mrkY);
		mrkY->setRenderHint(QwtPlotItem::RenderAntialiased, false);
		mrkY->setAxis(xAxis(), yAxis());
		mrkY->setLineStyle(QwtPlotMarker::HLine);
		mrkY->setValue(0.0, 0.0);

		QColor c = Qt::black;
		if (d_plot->axisEnabled (QwtPlot::xBottom))
			c = d_plot->axisWidget(QwtPlot::xBottom)->palette().color(QPalette::Foreground);
		else if (d_plot->axisEnabled (QwtPlot::xTop))
			c = d_plot->axisWidget(QwtPlot::xTop)->palette().color(QPalette::Foreground);

		mrkY->setLinePen(QPen(c, d_plot->axesLinewidth(), Qt::SolidLine));
	} else if (mrkY && !enable){
		mrkY->detach();
		d_plot->replot();
		mrkY = NULL;
	}
}
Пример #15
0
Spectrogram* Spectrogram::copy(Graph *g)
{
	Spectrogram *new_s = new Spectrogram(g, matrix());
	new_s->setDisplayMode(QwtPlotSpectrogram::ImageMode, testDisplayMode(QwtPlotSpectrogram::ImageMode));
	new_s->setDisplayMode(QwtPlotSpectrogram::ContourMode, testDisplayMode(QwtPlotSpectrogram::ContourMode));
	new_s->setCustomColorMap(color_map);
	new_s->setAxis(xAxis(), yAxis());
	new_s->setDefaultContourPen(defaultContourPen());
	new_s->color_map_policy = color_map_policy;
	new_s->d_show_labels = d_show_labels;
	new_s->d_labels_angle = d_labels_angle;
	new_s->d_labels_color = d_labels_color;
	new_s->d_white_out_labels = d_white_out_labels;
	new_s->d_labels_font = d_labels_font;
	new_s->d_labels_x_offset = d_labels_x_offset;
	new_s->d_labels_y_offset = d_labels_y_offset;

	new_s->setContourLevels(contourLevels());

	if (defaultContourPen().style() == Qt::NoPen && !d_color_map_pen)
		new_s->setContourPenList(d_pen_list);
	else
		new_s->d_color_map_pen = d_color_map_pen;

	QList <PlotMarker *> lst = new_s->labelsList();
	int count = lst.size();
	for(int i = 0; i < count; i++){
		PlotMarker *m = lst[i];
		PlotMarker *mrk = d_labels_list[i];
		if (m && mrk)
			m->setLabelOffset(mrk->xLabelOffset(), mrk->yLabelOffset());
	}
	return new_s;
}
Пример #16
0
void ScrollZoomer::layoutScrollBars(const QRect &rect) {
  int hPos = xAxis();
  if (hScrollBarPosition() == OppositeToScale) hPos = oppositeAxis(hPos);

  int vPos = yAxis();
  if (vScrollBarPosition() == OppositeToScale) vPos = oppositeAxis(vPos);

  ScrollBar *hScrollBar = horizontalScrollBar();
  ScrollBar *vScrollBar = verticalScrollBar();

  const int hdim = hScrollBar ? hScrollBar->extent() : 0;
  const int vdim = vScrollBar ? vScrollBar->extent() : 0;

  if (hScrollBar && hScrollBar->isVisible())
    {
      int x = rect.x();
      int y = (hPos == QwtPlot::xTop) ? rect.top() : rect.bottom() - hdim + 1;
      int w = rect.width();

      if (vScrollBar && vScrollBar->isVisible())
        {
          if (vPos == QwtPlot::yLeft)
            x += vdim;
          w -= vdim;
        }

      hScrollBar->setGeometry(x, y, w, hdim);
    }
  if (vScrollBar && vScrollBar->isVisible())
    {
      int pos = yAxis();
      if (vScrollBarPosition() == OppositeToScale)
        pos = oppositeAxis(pos);

      int x = (vPos == QwtPlot::yLeft) ? rect.left() : rect.right() - vdim + 1;
      int y = rect.y();

      int h = rect.height();

      if (hScrollBar && hScrollBar->isVisible())
        {
          if (hPos == QwtPlot::xTop)
            y += hdim;

          h -= hdim;
        }

      vScrollBar->setGeometry(x, y, vdim, h);
    }
  if (hScrollBar && hScrollBar->isVisible() && vScrollBar
      && vScrollBar->isVisible())
    {
      if (d_cornerWidget)
        {
          QRect cornerRect(vScrollBar->pos().x(), hScrollBar->pos().y(), vdim,
              hdim);
          d_cornerWidget->setGeometry(cornerRect);
        }
    }
}
Пример #17
0
void Spectrogram::updateLabels(QPainter *p, const QwtScaleMap &, const QwtScaleMap &,
		const QwtRasterData::ContourLines &contourLines) const
{
	QwtValueList levels = contourLevels();
	const int numLevels = levels.size();
	int x_axis = xAxis();
	int y_axis = yAxis();
	for (int l = 0; l < numLevels; l++){
		const double level = levels[l];
		const QPolygonF &lines = contourLines[level];
		if (lines.isEmpty())
			continue;

		PlotMarker *mrk = d_labels_list[l];
		if (!mrk)
			return;

		QSize size = mrk->label().textSize();
		int dx = int((d_labels_x_offset + mrk->xLabelOffset())*0.01*size.height());
		int dy = -int(((d_labels_y_offset + mrk->yLabelOffset())*0.01 + 0.5)*size.height());

		int i = (int)lines.size()/2;
		double x = lines[i].x();
		double y = lines[i].y();

		int x2 = d_graph->transform(x_axis, x) + dx;
		int y2 = d_graph->transform(y_axis, y) + dy;

		if (p->device()->logicalDpiX() == plot()->logicalDpiX() ||
			p->device()->logicalDpiY() == plot()->logicalDpiY())
			mrk->setValue(d_graph->invTransform(x_axis, x2),
							d_graph->invTransform(y_axis, y2));
	}
}
Пример #18
0
void Grid::enableZeroLineY(bool enable) {
  Plot *d_plot = dynamic_cast<Plot *>(plot());
  if (!d_plot)
    return;

  if (mrkY < 0 && enable) {
    QwtPlotMarker *m = new QwtPlotMarker();
    mrkY = d_plot->insertMarker(m);
    m->setRenderHint(QwtPlotItem::RenderAntialiased, false);
    m->setAxis(xAxis(), yAxis());
    m->setLineStyle(QwtPlotMarker::HLine);
    m->setValue(0.0, 0.0);

    double width = 1;
    if (d_plot->canvas()->lineWidth())
      width = d_plot->canvas()->lineWidth();
    else if (d_plot->axisEnabled(QwtPlot::xBottom) ||
             d_plot->axisEnabled(QwtPlot::xTop))
      width = d_plot->axesLinewidth();

    m->setLinePen(QPen(Qt::black, width, Qt::SolidLine));
  } else if (mrkY >= 0 && !enable) {
    d_plot->removeMarker(mrkY);
    mrkY = -1;
  }
}
Пример #19
0
/*!
  Find the closest curve point for a specific position

  \param pos Position, where to look for the closest curve point
  \param dist If dist != NULL, closestPoint() returns the distance between
              the position and the clostest curve point
  \return Index of the closest curve point, or -1 if none can be found 
          ( f.e when the curve has no points )
  \note closestPoint() implements a dumb algorithm, that iterates 
        over all points
*/
int QwtPlotCurve::closestPoint(const QPoint &pos, double *dist) const
{
    if ( plot() == NULL || dataSize() <= 0 )
        return -1;

    const QwtScaleMap xMap = plot()->canvasMap(xAxis());
    const QwtScaleMap yMap = plot()->canvasMap(yAxis());

    int index = -1;
    double dmin = 1.0e10;

    for (int i=0; i < dataSize(); i++)
    {
        const double cx = xMap.xTransform(x(i)) - pos.x();
        const double cy = yMap.xTransform(y(i)) - pos.y();

        const double f = qwtSqr(cx) + qwtSqr(cy);
        if (f < dmin)
        {
            index = i;
            dmin = f;
        }
    }
    if ( dist )
        *dist = sqrt(dmin);

    return index;
}
Пример #20
0
QPoint ArrowMarker::startPoint() const {
  if (!plot())
    return QPoint();

  return QPoint(plot()->transform(xAxis(), d_rect.left()),
                plot()->transform(yAxis(), d_rect.top()));
}
Пример #21
0
BaseIF* makeVane(const Real&     thick,
                 const RealVect& normal,
                 const Real&     innerRadius,
                 const Real&     outerRadius,
                 const Real&     offset,
                 const Real&     height)
{
  RealVect zero(D_DECL(0.0,0.0,0.0));
  RealVect xAxis(D_DECL(1.0,0.0,0.0));
  bool inside = true;

  Vector<BaseIF*> vaneParts;

  // Each side of the vane (infinite)
  RealVect normal1(normal);
  RealVect point1(D_DECL(offset+height/2.0,-thick/2.0,0.0));
  PlaneIF plane1(normal1,point1,inside);

  vaneParts.push_back(&plane1);

  RealVect normal2(-normal);
  RealVect point2(D_DECL(offset+height/2.0,thick/2.0,0.0));
  PlaneIF plane2(normal2,point2,inside);

  vaneParts.push_back(&plane2);

  // Make sure we only get something to the right of the origin
  RealVect normal3(D_DECL(0.0,0.0,1.0));
  RealVect point3(D_DECL(0.0,0.0,0.0));
  PlaneIF plane3(normal3,point3,inside);

  vaneParts.push_back(&plane3);

  // Cut off the top and bottom
  RealVect normal4(D_DECL(1.0,0.0,0.0));
  RealVect point4(D_DECL(offset,0.0,0.0));
  PlaneIF plane4(normal4,point4,inside);

  vaneParts.push_back(&plane4);

  RealVect normal5(D_DECL(-1.0,0.0,0.0));
  RealVect point5(D_DECL(offset+height,0.0,0.0));
  PlaneIF plane5(normal5,point5,inside);

  vaneParts.push_back(&plane5);

  // The outside of the inner cylinder
  TiltedCylinderIF inner(innerRadius,xAxis,zero,!inside);

  vaneParts.push_back(&inner);

  // The inside of the outer cylinder
  TiltedCylinderIF outer(outerRadius,xAxis,zero,inside);

  vaneParts.push_back(&outer);

  IntersectionIF* vane = new IntersectionIF(vaneParts);

  return vane;
}
Пример #22
0
double LineMarker::dist(int x, int y)
{
const QwtScaleMap &xMap = d_plot->canvasMap(xAxis());
const QwtScaleMap &yMap = d_plot->canvasMap(yAxis());

const int x0 = xMap.transform(d_rect.left());
const int y0 = yMap.transform(d_rect.top());
const int x1 = xMap.transform(d_rect.right());
const int y1 = yMap.transform(d_rect.bottom());

int xmin=QMIN(x0,x1);
int xmax=QMAX(x0,x1);
int ymin=QMIN(y0,y1);
int ymax=QMAX(y0,y1);
	
if ( (x>xmax || x<xmin || xmin==xmax) && (ymax<y || ymin>y || ymin==ymax))
	//return the shortest distance to one of the ends
	return QMIN(sqrt(double((x-x0)*(x-x0)+(y-y0)*(y-y0))),
				sqrt(double((x-x1)*(x-x1)+(y-y1)*(y-y1))));
	
double d;
if (x0==x1)
	d=abs(x-x0);
else
	{
	double a=(double)(y1-y0)/(double)(x1-x0);
	double b=y0-a*x0;
	d=(a*x-y+b)/sqrt(a*a+1);
	}	
return fabs(d);
}
Пример #23
0
std::string Grid::saveToString() {
  TSVSerialiser tsv;
  tsv.writeLine("grid");

  tsv << xEnabled() << xMinEnabled();
  tsv << yEnabled() << yMinEnabled();

  tsv << majPenX().color().name();
  tsv << majPenX().style() - 1;
  tsv << majPenX().widthF();

  tsv << minPenX().color().name();
  tsv << minPenX().style() - 1;
  tsv << minPenX().widthF();

  tsv << majPenY().color().name();
  tsv << majPenY().style() - 1;
  tsv << majPenY().widthF();

  tsv << minPenY().color().name();
  tsv << minPenY().style() - 1;
  tsv << minPenY().widthF();

  tsv << xZeroLineEnabled() << yZeroLineEnabled();
  tsv << xAxis() << yAxis();
  tsv << testRenderHint(QwtPlotItem::RenderAntialiased);
  return tsv.outputLines();
}
Пример #24
0
QPoint LineMarker::startPoint()
{
const QwtScaleMap &xMap = d_plot->canvasMap(xAxis());
const QwtScaleMap &yMap = d_plot->canvasMap(yAxis());

return QPoint(xMap.transform(d_rect.left()), yMap.transform(d_rect.top()));
}
Пример #25
0
QPoint LineMarker::endPoint()
{
const QwtScaleMap &xMap = d_plot->canvasMap(xAxis());
const QwtScaleMap &yMap = d_plot->canvasMap(yAxis());

return QPoint(xMap.transform(d_rect.right()), yMap.transform(d_rect.bottom()));
}
Пример #26
0
void Grid::enableZeroLineX(bool enable)
{
    Plot *d_plot = (Plot *)plot();
    if (!d_plot)
        return;

    if (mrkX<0 && enable) {
        QwtPlotMarker *m = new QwtPlotMarker();
        mrkX = d_plot->insertMarker(m);
        m->setRenderHint(QwtPlotItem::RenderAntialiased, false);
        m->setAxis(xAxis(), yAxis());
        m->setLineStyle(QwtPlotMarker::VLine);
        m->setValue(0.0, 0.0);

        double width = 1;
        if (d_plot->canvas()->lineWidth())
            width = d_plot->canvas()->lineWidth();
        else if (d_plot->axisEnabled (QwtPlot::yLeft) || d_plot->axisEnabled (QwtPlot::yRight))
            width =  d_plot->axesLinewidth();

        m->setLinePen(QPen(Qt::black, width, Qt::SolidLine));
    } else if (mrkX >= 0 && !enable) {
        d_plot->removeMarker(mrkX);
        mrkX=-1;
    }
}
Пример #27
0
BaseIF* makeVanes(const int&      num,
                  const Real&     thick,
                  const RealVect& normal,
                  const Real&     innerRadius,
                  const Real&     outerRadius,
                  const Real&     offset,
                  const Real&     height)
{
  RealVect zeroVect(D_DECL(0.0,0.0,0.0));
  RealVect xAxis(D_DECL(1.0,0.0,0.0));

  Vector<BaseIF*> eachVane;

  for (int i = 0; i < num; i++)
  {
    Real angle = i*2.*M_PI/num;

    BaseIF* oneVane = makeVane(thick,normal,innerRadius,outerRadius,offset,height,angle);

    eachVane.push_back(oneVane);
  }

  UnionIF* allVanes = new UnionIF(eachVane);

  return allVanes;
}
Пример #28
0
QString Grid::saveToString()
{
    QString s = "grid\t";
    s += QString::number(xEnabled())+"\t";
    s += QString::number(xMinEnabled())+"\t";
    s += QString::number(yEnabled())+"\t";
    s += QString::number(yMinEnabled())+"\t";

    s += majPenX().color().name()+"\t";
    s += QString::number(majPenX().style() - 1)+"\t";
    s += QString::number(majPenX().widthF())+"\t";

    s += minPenX().color().name()+"\t";
    s += QString::number(minPenX().style() - 1)+"\t";
    s += QString::number(minPenX().widthF())+"\t";

    s += majPenY().color().name()+"\t";
    s += QString::number(majPenY().style() - 1)+"\t";
    s += QString::number(majPenY().widthF())+"\t";

    s += minPenY().color().name()+"\t";
    s += QString::number(minPenY().style() - 1)+"\t";
    s += QString::number(minPenY().widthF())+"\t";

    s += QString::number(xZeroLineEnabled())+"\t";
    s += QString::number(yZeroLineEnabled())+"\t";
    s += QString::number(xAxis())+"\t";
    s += QString::number(yAxis())+"\t";
    s += QString::number(testRenderHint(QwtPlotItem::RenderAntialiased))+"\n";
    return s;
}
Пример #29
0
/*!
  Find the closest curve point for a specific position

  \param pos Position, where to look for the closest curve point
  \param dist If dist != NULL, closestPoint() returns the distance between
              the position and the closest curve point
  \return Index of the closest curve point, or -1 if none can be found
          ( f.e when the curve has no points )
  \note closestPoint() implements a dumb algorithm, that iterates
        over all points
*/
int QwtPlotCurve::closestPoint( const QPoint &pos, double *dist ) const
{
    const size_t numSamples = dataSize();

    if ( plot() == NULL || numSamples <= 0 )
        return -1;

    const QwtSeriesData<QPointF> *series = data();

    const QwtScaleMap xMap = plot()->canvasMap( xAxis() );
    const QwtScaleMap yMap = plot()->canvasMap( yAxis() );

    int index = -1;
    double dmin = 1.0e10;

    for ( uint i = 0; i < numSamples; i++ )
    {
        const QPointF sample = series->sample( i );

        const double cx = xMap.transform( sample.x() ) - pos.x();
        const double cy = yMap.transform( sample.y() ) - pos.y();

        const double f = qwtSqr( cx ) + qwtSqr( cy );
        if ( f < dmin )
        {
            index = i;
            dmin = f;
        }
    }
    if ( dist )
        *dist = qSqrt( dmin );

    return index;
}
Пример #30
0
double QwtBarCurve::dataOffset() {
  if (bar_style == Vertical) {
    const QwtScaleMap &xMap = plot()->canvasMap(xAxis());
    int dx = abs(xMap.transform(x(1)) - xMap.transform(x(0)));
    double bar_width = dx * (1 - bar_gap * 0.01);
    if (plot()->isVisible()) {
      for (int i = 2; i < dataSize(); i++) {
        int min = abs(xMap.transform(x(i)) - xMap.transform(x(i - 1)));
        if (min <= dx) dx = min;
      }
      int x1 = xMap.transform(minXValue()) + int(bar_offset * 0.01 * bar_width);
      return xMap.invTransform(x1) - minXValue();
    } else
      return 0.5 * bar_offset * 0.01 * bar_width;
  } else {
    const QwtScaleMap &yMap = plot()->canvasMap(yAxis());
    int dy = abs(yMap.transform(y(1)) - yMap.transform(y(0)));
    double bar_width = dy * (1 - bar_gap * 0.01);
    if (plot()->isVisible()) {
      for (int i = 2; i < dataSize(); i++) {
        int min = abs(yMap.transform(y(i)) - yMap.transform(y(i - 1)));
        if (min <= dy) dy = min;
      }
      int y1 = yMap.transform(minYValue()) + int(bar_offset * 0.01 * bar_width);
      return yMap.invTransform(y1) - minYValue();
    } else
      return 0.5 * bar_offset * 0.01 * bar_width;
  }
  return 0;
}