示例#1
0
  void dump_grid_range_highlight(const Grid & grid,
				 ssize_t ix0, ssize_t iy0,
				 ssize_t ix1, ssize_t iy1,
				 ssize_t ixhigh, ssize_t iyhigh,
				 FILE * stream)
  {
    PVDEBUG("%zu   %zu   %zu   %zu   %zu   %zu\n",
	    ix0, iy0, ix1, iy1, ixhigh, iyhigh);
    fprintf(stream, " ");
    for(ssize_t ix(ix0); ix <= ix1; ++ix)
      if(ix == ixhigh) fprintf(stream, " ***********");
      else             fprintf(stream, "            ");
    fprintf(stream, " \n");
    ssize_t iy(iy1);
    for(/**/; iy != iy0; --iy){
      const char * high(iy == iyhigh ? "*" : " ");
      linesep(grid, stream, ix0, ix1, 0, " ");
      line1(grid, stream, iy, ix0, ix1, 0, high);
      line2(grid, stream, iy, ix0, ix1, 0, high);
      line3(grid, stream, iy, ix0, ix1, 0, high);
      line4(grid, stream, iy, ix0, ix1, 0, high);
    }
    const char * high(iy == iyhigh ? "*" : " ");
    linesep(grid, stream, ix0, ix1, 0, " ");
    line1(grid, stream, iy, ix0, ix1, 0, high);
    line2(grid, stream, iy, ix0, ix1, 0, high);
    line3(grid, stream, iy, ix0, ix1, 0, high);
    line4(grid, stream, iy, ix0, ix1, 0, high);
    linesep(grid, stream, ix0, ix1, 0, " ");
    fprintf(stream, " ");
    for(ssize_t ix(ix0); ix <= ix1; ++ix)
      if(ix == ixhigh) fprintf(stream, " ***********");
      else             fprintf(stream, "            ");
    fprintf(stream, " \n");
  }
示例#2
0
文件: tst_qray3d.cpp 项目: RSATom/Qt
void tst_QRay3D::contains_ray()
{
    QFETCH(QVector3D, origin);
    QFETCH(QVector3D, direction);
    QFETCH(QVector3D, point);
    QFETCH(bool, contains);

    Qt3DRender::RayCasting::QRay3D line(origin, direction);
    if (contains) {
        Qt3DRender::RayCasting::QRay3D line2(point, direction);
        QVERIFY(line.contains(line2));
        QVERIFY(line2.contains(line));

        // Reversed direction is also contained.
        Qt3DRender::RayCasting::QRay3D line3(point, -direction);
        QVERIFY(line.contains(line2));
        QVERIFY(line2.contains(line));

        // Different direction.
        Qt3DRender::RayCasting::QRay3D line4(point, QVector3D(direction.y(), direction.x(), direction.z()));
        QVERIFY(!line.contains(line4));
        QVERIFY(!line4.contains(line));
    } else {
        Qt3DRender::RayCasting::QRay3D line2(point, direction);
        QVERIFY(!line.contains(line2));
        QVERIFY(!line2.contains(line));
    }
}
示例#3
0
  void dump_grid_range(const Grid & grid,
		       ssize_t ix0, ssize_t iy0, ssize_t ix1, ssize_t iy1,
		       FILE * stream)
  {
    PVDEBUG("%zu   %zu   %zu   %zu\n", ix0, iy0, ix1, iy1);
    const char * even("");
    const char * oddsep;
    const char * oddpre;
    if (grid.GetNeighborhood() == Grid::SIX) {
      oddsep = "+-----";
      oddpre = "      ";
    }
    else {
      oddsep = even;
      oddpre = even;
    }
    ssize_t iy(iy1);
    const char * prefix;
    for(/**/; iy != iy0; --iy){
      if(iy % 2){
	linesep(grid, stream, ix0, ix1, oddsep, 0);
	prefix = oddpre;
      }
      else{
	linesep(grid, stream, ix0, ix1, even, 0);
	prefix = even;
      }
      line1(grid, stream, iy, ix0, ix1, prefix, 0);
      line2(grid, stream, iy, ix0, ix1, prefix, 0);
      line3(grid, stream, iy, ix0, ix1, prefix, 0);
      line4(grid, stream, iy, ix0, ix1, prefix, 0);
    }
    if(iy % 2){
      linesep(grid, stream, ix0, ix1, oddsep, 0);
      prefix = oddpre;
    }
    else{
      linesep(grid, stream, ix0, ix1, even, 0);
      prefix = even;
    }
    line1(grid, stream, iy, ix0, ix1, prefix, 0);
    line2(grid, stream, iy, ix0, ix1, prefix, 0);
    line3(grid, stream, iy, ix0, ix1, prefix, 0);
    line4(grid, stream, iy, ix0, ix1, prefix, 0);
    if(iy % 2)
      linesep(grid, stream, ix0, ix1, even, 0);
    else
      linesep(grid, stream, ix0, ix1, oddsep, 0);
  }
示例#4
0
void test_circuit_rc()
{
	ngdc dc("dc1", 5);
	ngresistor r("r1", 5);
	ngcapacitor c("c1", 0.2);
	ngground gnd;

	ngline line1(dc[0], r[0]);
	ngline line2(r[1], c[0]);
	ngline line3(c[1], dc[1]);
	ngline line4(dc[0], gnd[0]);

	schema sch("design1");
	sch.AddDevice(&dc);
	sch.AddDevice(&r);
	sch.AddDevice(&c);
	sch.AddDevice(&gnd);

	sch.AddLine(&line1);
	sch.AddLine(&line2);
	sch.AddLine(&line3);
	sch.AddLine(&line4);

	circuit cir(&sch);
	cir.Tran("1s");
	
	do 
	{
		Sleep(200);
	} while (cir.IsRunning());
}
示例#5
0
bool LineSegConeIntersect(const LineSegment * line, const Cone * cone)
{
	Circle circle(cone->GetVertex(), cone->GetHeight());
	if (Intersect(line, &circle) == true)
	{
		if ((cone->ContainsPoint(line->GetPoint1()) == true) || (cone->ContainsPoint(line->GetPoint2()) == true) || (line->ContainsPoint(cone->GetVertex()) == true))
		{
			return true;
		}

		Vector3D direction(cone->GetVertex(), cone->GetVertex() + cone->GetDirection());
		Float angle = direction.GetZeroAngleD();

		Float angle1 = angle + cone->GetAngle();
		Float angle2 = angle - cone->GetAngle();

		Float height = cone->GetHeight();
		Point3D vertex = cone->GetVertex();

		LineSegment line1(vertex, Point3D(vertex.GetX() + (CosD(angle1) * height), vertex.GetY() + (SinD(angle1) * height), 0));
		LineSegment line2(vertex, Point3D(vertex.GetX() + (CosD(angle2) * height), vertex.GetY() + (SinD(angle2) * height), 0));

		return ((Intersect(line, &line1) == true) || (Intersect(line, &line2) == true));
	}
	return false;
}
Label TemplatePrinter::templateFiller(const char * templateFilePath)
{
    /* THIS IMPLEMENTATION IS TEMPORARY
     * In the future, TemplatePrinter will have a container of fields and columns
     * just like the label. The templateFiller will loop through the fields and columns to
     * A) format the label object with enough columns and fields and B) fill in the data from
     * the text fields of the gui. DO NOT rely on this implementation in the future!
     */
    Label tempLabel;
    QFile xmlFile(templateFilePath);
    LabelParser parser(xmlFile, tempLabel);
    parser.start();
    QString line1(ui->lineEdit->displayText());
    QString line2(ui->lineEdit_2->displayText());
    QString line3(ui->lineEdit_3->displayText());

    Column* column = &((tempLabel.getColumns())->at(0));
    Field* field1 = &(column->fields.at(0));
    field1->value = line1;
    Field* field2 = &(column->fields.at(1));
    field2->value = line2;
    Column* column2 = &((tempLabel.getColumns())->at(1));
    Field* field3 = &(column2->fields.at(1));
    field3->value = line3;

    return tempLabel;
}
示例#7
0
void Rectangle::draw(Frame* fr) {
    /* 
     * x1y2-------x2y2
     * |             |
     * |             |
     * |             |
     * x1y1-------x2y1
     */
    if(x1 > x2 && y1 > y2) {
        std::swap(x1, x2);
        std::swap(y1, y2);
    }
    if(is_valid(fr)) {
        // Create 4 lines
        Line line1(x1, y1, x1, y2);
        Line line2(x1, y2, x2, y2);
        Line line3(x2, y2, x2, y1);
        Line line4(x2, y1, x1, y1);
        // Draw them
        line1.draw(fr);
        line2.draw(fr);
        line3.draw(fr);
        line4.draw(fr);
    } else {
        throw std::runtime_error("Rechteck nicht korrekt!");
    }
}
vector<Pixel> Rectangle::getPixels() const{

	Point p1(mPositionX,mPositionY);
	Point p2(mPositionX+mWidth,mPositionY);
	Point p3(mPositionX,mPositionY+mHeight);
	Point p4(mPositionX+mWidth,mPositionY+mHeight);

	Line line1(p1,p2,mColor);
	Line line2(p2,p4,mColor);
	Line line3(p3,p4,mColor);
	Line line4(p1,p3,mColor);

	vector<Pixel> linePixels1 = line1.getPixels();
	vector<Pixel> linePixels2 = line2.getPixels();
	vector<Pixel> linePixels3 = line3.getPixels();
	vector<Pixel> linePixels4 = line4.getPixels();

	vector<Pixel> pixels;

	pixels.insert(pixels.end(),linePixels1.begin(),linePixels1.end());
	pixels.insert(pixels.end(),linePixels2.begin(),linePixels2.end());
	pixels.insert(pixels.end(),linePixels3.begin(),linePixels3.end());
	pixels.insert(pixels.end(),linePixels4.begin(),linePixels4.end());

	return pixels;
}
示例#9
0
void main()
{
	ifstream inStream;
	int cases;

	inStream.open("input.txt");
	if(inStream.fail())
	{
		cerr<<"Input file opening failed\n";
		exit(1);
	}

	inStream>>cases;

	for(int i=0;i<cases;i++)
	{
		int p1x, p2x, p3x, p4x, p1y, p2y, p3y, p4y;

		inStream>>p1x>>p1y>>p2x>>p2y>>p3x>>p3y>>p4x>>p4y;

		point p1(p1x, p1y), p2(p2x, p2y), p3(p3x, p3y), p4(p4x, p4y);
		linesegment line1(p1, p2);
		linesegment line2(p3, p4);

		if(line1.properintersection(line2) || line2.properintersection(line1))
			cout<<"1"<<endl;
		else if(line1.improperintersection(line2) || line2.improperintersection(line1))
			cout<<"2"<<endl;
		else
			cout<<"0"<<endl;
	}
	inStream.close();
}
示例#10
0
bool CircleConeIntersect(const Circle * c, const Cone * cone)
{
	Circle circle(cone->GetVertex(), cone->GetHeight());
	if (Intersect(c, &circle) == true)
	{
		if ((c->ContainsPoint(cone->GetVertex()) == true) || (cone->ContainsPoint(c->GetCenter()) == true))
		{
			return true;
		}


		Vector3D direction(cone->GetVertex(), cone->GetVertex() + cone->GetDirection());
		Vector3D centerDirection(cone->GetVertex(), c->GetCenter());
		Float angle = direction.GetZeroAngleD();
		Float angleDif = centerDirection.GetZeroAngleD() - angle;

		if (AbsVal(angleDif) < cone->GetAngle())
		{
			return true;
		}

		Float angle1 = angle + cone->GetAngle();
		Float angle2 = angle - cone->GetAngle();

		Float height = cone->GetHeight();
		Point3D vertex = cone->GetVertex();

		LineSegment line1(vertex, Point3D(vertex.GetX() + (CosD(angle1) * height), vertex.GetY() + (SinD(angle1) * height), 0));
		LineSegment line2(vertex, Point3D(vertex.GetX() + (CosD(angle2) * height), vertex.GetY() + (SinD(angle2) * height), 0));

		return ((Intersect(c, &line1) == true) || (Intersect(c, &line2) == true));
	}
	return false;
}
示例#11
0
Connection *ConnectionManager::getConnection(int x, int y, int &point, QPointF *intersectPnt) {
	QPointF from;
	QPointF to;

	for (ConnectionList::iterator it = m_conns.begin(); it != m_conns.end(); ++it) {
		Connection *c = *it;
		from = c->points[0];
		for (int i = 1; i < c->points.size(); ++i) {
			to = c->points[i];
			QLineF line(from, to);
			QLineF line2(x-5, y-5, x+5, y+5);
			if (line.intersect(line2, intersectPnt)==QLineF::BoundedIntersection) {
				point = i;
				return (*it);
			}
			else {
				QLineF line3(x-5, y+5, x+5, y-5);
				if (line.intersect(line3, intersectPnt)==QLineF::BoundedIntersection) {
					point = i;
					return (*it);
				}
			}
			from = to;
		}
	}

	return 0;
}
示例#12
0
文件: bridge.cpp 项目: yannicklm/bear
/**
 * \brief Apply the angle of the slope to a colliding item.
 * \param that The other item in the collision.
 * \param info Informations on the collision.
 */
void bear::bridge::apply_angle_to
( engine::base_item& that, const universe::collision_info& info) const
{
  universe::position_type left_pos(that.get_bottom_left());
  universe::position_type right_pos(that.get_bottom_right());
  universe::position_type previous_pos;
  universe::position_type next_pos;
  
  compute_neighboor
    (that.get_bottom_left(),previous_pos,next_pos);
  claw::math::line_2d<universe::coordinate_type> line1
    ( previous_pos, next_pos - previous_pos );
  left_pos.y = line1.y_value(that.get_left());

  compute_neighboor
    (that.get_bottom_right(),previous_pos,next_pos);
  claw::math::line_2d<universe::coordinate_type> line2
    ( previous_pos, next_pos - previous_pos );
  right_pos.y = line2.y_value(that.get_right());
  
  claw::math::line_2d<universe::coordinate_type> line
    ( left_pos, right_pos - left_pos );
  double angle = std::atan(line.direction.y / line.direction.x);
  
  that.set_contact_angle(angle);

  info.get_collision_repair().set_contact_normal
    (that, that.get_x_axis().get_orthonormal_anticlockwise());
} // bridge::apply_angle_to()
void OscilloscopeScreen::drawScaleLines(QPainter& painter)
{
    // 画刻度线
    QPen pen ;
    pen.setStyle(Qt::DotLine);
    pen.setColor(core()->axisColor());
    pen.setWidth(1);
    painter.setPen(pen);

    int height = this->height() / 2 ;	// y轴有正负,所以高度除以2
    int width = this->width() ;			// x轴无正负。

    // 横线
    for(int i=0;i<core()->scaleLinesInY();i++)
    {
        int deltaY = i*height / (core()->scaleLinesInY()) ;
        QLineF line ( 0, height-deltaY , width , height-deltaY );
        painter.drawLine(line);
        QLineF line2 ( 0, height+deltaY , width , height+deltaY );
        painter.drawLine(line2);
    }

    // 竖线
    for(int i=0;i<core()->scaleLinesInX();i++)
    {
        int deltaX = i*width / core()->scaleLinesInX() ;
        QLineF line ( deltaX, 0 , deltaX , height*2 );
        painter.drawLine(line);
    }
}
示例#14
0
void GraphicMoteur::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    qreal x = _dp.x();
    qreal y = _dp.y();

    QPolygonF polygone1, polygone2;

    QLineF line1(x+9, y+32, x+15, y+32);
    QLineF line2(x+31, y+32, x+25, y+32);

    polygone1 << QPointF(x, y) << QPointF(x+40, y) << QPointF(x+40, y+13) << QPointF(x, y+13);

    polygone2 << QPointF(x+6, y+13) << QPointF(x+34, y+13) << QPointF(x+34, y+25) << QPointF(x+28, y+48)
              << QPointF(x+12, y+48) << QPointF(x+6, y+25);

    painter->setPen(pen);

    painter->drawText(x+14, y+11, _nom);

    QPainterPath path;
    path.addPolygon(polygone2);

    painter->fillPath(path, brushDefault);

    painter->drawPolygon(polygone1);
    painter->drawPolygon(polygone2);
    painter->drawLine(line1);
    painter->drawLine(line2);
}
示例#15
0
bool Knob::sceneEvent(QEvent *event)
{
    switch (event->type()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    {
        QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);

        if (touchEvent->touchPoints().count() == 2) {
            const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first();
            const QTouchEvent::TouchPoint &touchPoint2 = touchEvent->touchPoints().last();

            QLineF line1(touchPoint1.lastScenePos(), touchPoint2.lastScenePos());
            QLineF line2(touchPoint1.scenePos(), touchPoint2.scenePos());

            rotate(line2.angleTo(line1));
        }

        break;
    }

    default:
        return QGraphicsItem::sceneEvent(event);
    }

    return true;
}
示例#16
0
void Inkscape::LineSnapper::constrainedSnap(SnappedConstraints &sc,
                                               Inkscape::SnapCandidatePoint const &p,
                                               Geom::OptRect const &/*bbox_to_snap*/,
                                               ConstraintLine const &c,
                                               std::vector<SPItem const *> const */*it*/) const

{
    if (_snap_enabled == false || _snapmanager->snapprefs.getSnapFrom(p.getSourceType()) == false) {
        return;
    }

    /* Get the lines that we will try to snap to */
    const LineList lines = _getSnapLines(p.getPoint());

    for (LineList::const_iterator i = lines.begin(); i != lines.end(); i++) {
        if (Geom::L2(c.getDirection()) > 0) { // Can't do a constrained snap without a constraint
            // constraint line
            Geom::Point const point_on_line = c.hasPoint() ? c.getPoint() : p.getPoint();
            Geom::Line line1(point_on_line, point_on_line + c.getDirection());

            // grid/guide line
            Geom::Point const p1 = i->second; // point at guide/grid line
            Geom::Point const p2 = p1 + Geom::rot90(i->first); // 2nd point at guide/grid line
            Geom::Line line2(p1, p2);

            Geom::OptCrossing inters = Geom::OptCrossing(); // empty by default
            try
            {
                inters = Geom::intersection(line1, line2);
            }
            catch (Geom::InfiniteSolutions e)
            {
                // We're probably dealing with parallel lines, so snapping doesn't make any sense here
                continue; // jump to the next iterator in the for-loop
            }

            if (inters) {
                Geom::Point t = line1.pointAt((*inters).ta);
                const Geom::Coord dist = Geom::L2(t - p.getPoint());
                if (dist < getSnapperTolerance()) {
                    // When doing a constrained snap, we're already at an intersection.
                    // This snappoint is therefore fully constrained, so there's no need
                    // to look for additional intersections; just return the snapped point
                    // and forget about the line
                    _addSnappedPoint(sc, t, dist, p.getSourceType(), p.getSourceNum(), true);
                    // For any line that's within range, we will also look at it's "point on line" p1. For guides
                    // this point coincides with its origin; for grids this is of no use, but we cannot
                    // discern between grids and guides here
                    Geom::Coord const dist_p1 = Geom::L2(p1 - p.getPoint());
                    if (dist_p1 < getSnapperTolerance()) {
                        _addSnappedLinesOrigin(sc, p1, dist_p1, p.getSourceType(), p.getSourceNum(), true);
                        // Only relevant for guides; grids don't have an origin per line
                        // Therefore _addSnappedLinesOrigin() will only be implemented for guides
                    }
                }
            }
        }
    }
}
示例#17
0
void Sonar2DUtils::DouglasPeucker(const Sonar2DUtils::tBottomLine& bottomLineFt, float epsilon, Sonar2DUtils::tBottomLine& returnResults)
{
    const unsigned int minPoints = 3;

    if(bottomLineFt.size() < minPoints)
    {
        returnResults = bottomLineFt;
    }
    else
    {
        Sonar2DUtils::tBottomLine lineSegment;
        lineSegment.push_back( *bottomLineFt.begin() );
        lineSegment.push_back( bottomLineFt.back() );
        
        float dMax = 0.0f;
        Sonar2DUtils::tBottomLine::const_iterator iterMax;
        Sonar2DUtils::tBottomLine::const_iterator iterEnd = bottomLineFt.begin() + (bottomLineFt.size() - 2);
        // Find the point with maximum distance, excluding the first and last point of the segment.
        for(Sonar2DUtils::tBottomLine::const_iterator iter=bottomLineFt.begin()+1; iter!=iterEnd; ++iter )
        {
            float d = ShortestDistanceToSegment( *iter, lineSegment );
            if( d > dMax )
            {
                dMax = d;
                iterMax = iter;
            }
        }

        // If max distance is greater than epsilon, recursively simplify
        if( dMax > epsilon)
        {
            // Split up new lines
            Sonar2DUtils::tBottomLine line1( bottomLineFt.begin(), (iterMax+1) );
            Sonar2DUtils::tBottomLine line2( iterMax, bottomLineFt.end() );

            Sonar2DUtils::tBottomLine results1;
            DouglasPeucker(line1, epsilon, results1 );

            Sonar2DUtils::tBottomLine results2;
            DouglasPeucker(line2, epsilon, results2 );

            if(results1.size() < minPoints)
            {
                returnResults.push_back( *results1.begin() );
            }
            else
            {
                returnResults = Sonar2DUtils::tBottomLine( results1.begin(), (results1.begin() + results1.size() - 2) );
            }

            returnResults.insert( returnResults.end(), results2.begin(), results2.end() );
        }
        else
        {
            returnResults.push_back( *bottomLineFt.begin() );
            returnResults.push_back( bottomLineFt.back() );
        }
    }
}
示例#18
0
void SphereTest::collisionLine() {
    Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
    Shapes::Line3D line({1.0f, 1.5f, 3.5f}, {1.0f, 2.5f, 2.5f});
    Shapes::Line3D line2({1.0f, 2.0f, 5.1f}, {1.0f, 3.0f, 5.1f});

    VERIFY_COLLIDES(sphere, line);
    VERIFY_NOT_COLLIDES(sphere, line2);
}
示例#19
0
void SphereTest::collisionLineSegment() {
    Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
    Shapes::LineSegment3D line({1.0f, 2.0f, 4.9f}, {1.0f, 2.0f, 7.0f});
    Shapes::LineSegment3D line2({1.0f, 2.0f, 5.1f}, {1.0f, 2.0f, 7.0f});

    VERIFY_COLLIDES(sphere, line);
    VERIFY_NOT_COLLIDES(sphere, line2);
}
示例#20
0
line2 line2::interpolate(line2 const& l, double fraction) const
{
	return line2(
		denormalize(fraction, x1(), l.x1()),
		denormalize(fraction, y1(), l.y1()),
		denormalize(fraction, x2(), l.x2()),
		denormalize(fraction, y2(), l.y2())
	);
}
示例#21
0
FlowOperator::FlowOperator(const int rows, const int cols) : _b(2 * rows * cols, true, 0), _rows(rows), _cols(cols), _cells(rows * cols), FMxD(rows, cols, OPTFLOW_TYPE), FMxd(rows, cols, OPTFLOW_TYPE), FMyD(rows, cols, OPTFLOW_TYPE), FMyd(rows, cols, OPTFLOW_TYPE){
	//construct consts
		//FMx/Fx const
	//FMx contains the FMxD mat on its main diagonal and FMxd on the -cols(in matlab its -rows) diagonal
	FArray zeros(_cols, true, 0);
	FArray ones(_cols, true, 1);
	FArray nones(_cols, true, -1);

	/*
	0  1  1  1       0  0  0  0
	0  1  1  1  ->   1  1  1  1
	0  1  1  1       1  1  1  1
	0  1  1  1       1  1  1  1
	*/
	//cv::Mat FMxD(_rows, _cols, OPTFLOW_TYPE);
	memcpy(FMxD.ptr<float>(0), zeros.ptr, _cols * sizeof(float));
	for(int i = 1; i < _rows; ++i)
		memcpy(FMxD.ptr<float>(i), ones.ptr, _cols * sizeof(float));
	/*
	-1 -1 -1  0      -1 -1 -1 -1
	-1 -1 -1  0  ->  -1 -1 -1 -1
	-1 -1 -1  0      -1 -1 -1 -1
	-1 -1 -1  0       0  0  0  0
	*/
	//cv::Mat FMxd(_rows, _cols, OPTFLOW_TYPE, cv::Scalar(-1)); increases quality
	//cv::Mat FMxd(_rows, _cols, OPTFLOW_TYPE);
	for(int i = 1; i < _rows; ++i)
		memcpy(FMxd.ptr<float>(i), nones.ptr, _cols * sizeof(float));
	memcpy(FMxd.ptr<float>(0), zeros.ptr, _cols * sizeof(float));


	//FMy/Fy const

	/*
	 0  0  0  0       0  1  1  1
	 1  1  1  1  ->   0  1  1  1
	 1  1  1  1       0  1  1  1
	 1  1  1  1       0  1  1  1
	*/
	FArray line1(_cols, true, 1);
	*(line1.ptr) = 0;	
	//cv::Mat FMyD(_rows, _cols, OPTFLOW_TYPE);
	for(int i = 0; i < _rows; ++i)
		memcpy(FMyD.ptr<float>(i), line1.ptr, _cols * sizeof(float));
	
	/*
	-1 -1 -1 -1       -1 -1 -1  0
	-1 -1 -1 -1   ->  -1 -1 -1  0
	-1 -1 -1 -1       -1 -1 -1  0
	 0  0  0  0       -1 -1 -1  0
	*/
	FArray line2(_cols, true, -1);
	*(line2.ptr + _cols - 1) = 0;
	//cv::Mat FMyd(_rows, _cols, OPTFLOW_TYPE);
	for(int i = 0; i < _rows; ++i)
		memcpy(FMyd.ptr<float>(i), line2.ptr, _cols * sizeof(float));
}
示例#22
0
//在指定列表中查找卡
bool CDlgAddCards::FindCardLine(CCardLine* pLine,vector<CCardLine*> vecLine)
{
	if ( !pLine || vecLine.empty())
		return false;

	switch (m_type)
	{
	case TYPE_BUS:
	case TYPE_GEN:
		{
			string name1 = pLine->m_card.FindValueByKeyname(_T("NAME"));
			double volt1 = std::stod(pLine->m_card.FindValueByKeyname(_T("VOLT")));
			CSimpleBus bus1(name1,volt1);
			for (vector<CCardLine*>::iterator it = vecLine.begin();
				it != vecLine.end();
				++it)
			{
				CCardLine* pLine2 = *it;
				if( !pLine2)
					continue;
				string name2 = pLine2->m_card.FindValueByKeyname(_T("NAME"));
				double volt2 = std::stod(pLine2->m_card.FindValueByKeyname(_T("VOLT")));
				CSimpleBus bus2(name2,volt2);
				if(bus1.IsSameAs(bus2))
					return true;
			}
		}
		break;
	case TYPE_LINE:
		{
			string name = pLine->m_card.FindValueByKeyname(_T("NAME"));
			double volt = std::stod(pLine->m_card.FindValueByKeyname(_T("VOLT")));
			string name1 = pLine->m_card.FindValueByKeyname(_T("NAME1"));
			double volt1 = std::stod(pLine->m_card.FindValueByKeyname(_T("VOLT1")));
			string circuit = pLine->m_card.FindValueByKeyname(_T("CIRCUIT"));
			CSimpleLine line1(name,volt,name1,volt1,circuit);
			for (vector<CCardLine*>::iterator it = vecLine.begin();
				it != vecLine.end();
				++it)
			{
				CCardLine* pLine2 = *it;
				if( !pLine2)
					continue;
				name = pLine2->m_card.FindValueByKeyname(_T("NAME"));
				volt = std::stod(pLine2->m_card.FindValueByKeyname(_T("VOLT")));
				name1 = pLine2->m_card.FindValueByKeyname(_T("NAME1"));
				volt1 = std::stod(pLine2->m_card.FindValueByKeyname(_T("VOLT1")));
				circuit = pLine2->m_card.FindValueByKeyname(_T("CIRCUIT"));
				CSimpleLine line2(name,volt,name1,volt1,circuit);
				if(line1.IsSameAs(line2))
					return true;
			}
		}
		break;
	}
	return false;
}
示例#23
0
std::string Diagnostics::GetFrameOverlayString(const GPUStats& aStats) {
  TimeStamp now = TimeStamp::Now();
  unsigned fps = unsigned(mCompositeFps.AddFrameAndGetFps(now));
  unsigned txnFps = unsigned(mTransactionFps.GetFPS(now));

  float pixelFillRatio =
      aStats.mInvalidPixels
          ? float(aStats.mPixelsFilled) / float(aStats.mInvalidPixels)
          : 0.0f;
  float screenFillRatio = aStats.mScreenPixels ? float(aStats.mPixelsFilled) /
                                                     float(aStats.mScreenPixels)
                                               : 0.0f;

  if (aStats.mDrawTime) {
    mGPUDrawMs.Add(aStats.mDrawTime.value());
  }

  std::string gpuTimeString;
  if (mGPUDrawMs.Empty()) {
    gpuTimeString = "N/A";
  } else {
    gpuTimeString = nsPrintfCString("%0.1fms", mGPUDrawMs.Average()).get();
  }

  // DL  = nsDisplayListBuilder
  // FLB = FrameLayerBuilder
  // R   = ClientLayerManager::EndTransaction
  // CP  = ShadowLayerForwarder::EndTransaction (txn build)
  // TX  = LayerTransactionChild::SendUpdate (IPDL serialize+send)
  // UP  = LayerTransactionParent::RecvUpdate (IPDL deserialize, update, APZ
  //                                           update)
  // CC_BUILD = Container prepare/composite frame building
  // CC_EXEC  = Container render/composite drawing
  nsPrintfCString line1("FPS: %d (TXN: %d)", fps, txnFps);
  nsPrintfCString line2(
      "[CC] Build: %0.1fms Exec: %0.1fms GPU: %s Fill Ratio: %0.1f/%0.1f",
      mPrepareMs.Average(), mCompositeMs.Average(), gpuTimeString.c_str(),
      pixelFillRatio, screenFillRatio);
  nsCString line3;
  if (mDlb2Ms.Average() != 0.0f) {
    line3 += nsPrintfCString(
        "[Content] DL: %0.1f/%0.1fms FLB: %0.1fms Raster: %0.1fms",
        mDlb2Ms.Average(), mDlbMs.Average(), mFlbMs.Average(),
        mRasterMs.Average());
  } else {
    line3 += nsPrintfCString(
        "[Content] DL: %0.1fms FLB: %0.1fms Raster: %0.1fms", mDlbMs.Average(),
        mFlbMs.Average(), mRasterMs.Average());
  }
  nsPrintfCString line4("[IPDL] Build: %0.1fms Send: %0.1fms Update: %0.1fms",
                        mSerializeMs.Average(), mSendMs.Average(),
                        mUpdateMs.Average());

  return std::string(line1.get()) + "\n" + std::string(line2.get()) + "\n" +
         std::string(line3.get()) + "\n" + std::string(line4.get());
}
示例#24
0
void PlaneTest::collisionLineSegment() {
    Shapes::Plane plane(Vector3(), Vector3::yAxis());
    Shapes::LineSegment3D line({0.0f, -0.1f, 0.0f}, {0.0f, 7.0f, 0.0f});
    Shapes::LineSegment3D line2({0.0f, 0.1f, 0.0f}, {0.0f, 7.0f, 0.0f});
    Shapes::LineSegment3D line3({0.0f, -7.0f, 0.0f}, {0.0f, -0.1f, 0.0f});

    VERIFY_COLLIDES(plane, line);
    VERIFY_NOT_COLLIDES(plane, line2);
    VERIFY_NOT_COLLIDES(plane, line3);
}
示例#25
0
void calibration() {
    line2();
    writeLCD("DC OFFSET");

    while (1) {
        uint24_t status = readRegister(STATUS_REG);
        if (status & 0x800000) {
            break;
        }
    }

    LATC0 = 1;
    LATC1 = 1;
    TRISC0 = 0;
    TRISC1 = 0;


    SPIWriteByte(0xD9);

    while (1) {
        uint24_t status = readRegister(STATUS_REG);
        if (status & 0x800000) {
            break;
        }
    }

    writeLCD("AC OFFSET");
    SPIWriteByte(0xDD);

    while (1) {
        uint24_t status = readRegister(STATUS_REG);
        if (status & 0x800000) {
            break;
        }
    }


    LATC0 = 0;
    LATC1 = 0;
    line2();
    writeLCD("DONE");
}
示例#26
0
void
MFD::setPage ( MfdPage page )
{
    std::string line1(page.getLine1());
    std::string line2(page.getLine2());
    std::string line3(page.getLine3());
    if(isUpdateEnabled) {
        MFD::setLine1(line1, true);
        MFD::setLine2(line2, true);
        MFD::setLine3(line3, true);
    }
}
示例#27
0
void SphereTest::collisionLineSegment() {
    Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
    Physics::LineSegment3D line({1.0f, 2.0f, 4.9f}, {1.0f, 2.0f, 7.0f});
    Physics::LineSegment3D line2({1.0f, 2.0f, 5.1f}, {1.0f, 2.0f, 7.0f});

    randomTransformation(sphere);
    randomTransformation(line);
    randomTransformation(line2);

    VERIFY_COLLIDES(sphere, line);
    VERIFY_NOT_COLLIDES(sphere, line2);
}
//-----------------------------------------------------------------------
Shape RoundedCornerSpline2::realizeShape()
{
	assert(!mPoints.empty());

	Shape shape;
	unsigned int numPoints = mClosed ? mPoints.size() : (mPoints.size() - 2);
	if (!mClosed)
			shape.addPoint(mPoints[0]);
		
	for (unsigned int i = 0; i < numPoints; ++i)
	{
		const Vector2& p0 = safeGetPoint(i);
		const Vector2& p1 = safeGetPoint(i+1);
		const Vector2& p2 = safeGetPoint(i+2);

		Vector2 vBegin = p1-p0;
		Vector2 vEnd = p2-p1;
		
		// We're capping the radius if it's too big compared to segment length
		Real radius = mRadius;
		Real smallestSegLength = std::min(vBegin.length(), vEnd.length());
		if (smallestSegLength < 2 * mRadius)
			radius = smallestSegLength / 2.0f;
		
		Vector2 pBegin = p1 - vBegin.normalisedCopy() * radius;
		Vector2 pEnd = p1 + vEnd.normalisedCopy() * radius;
		Line2D line1(pBegin, vBegin.perpendicular());
		Line2D line2(pEnd, vEnd.perpendicular());
		Vector2 center;
		line1.findIntersect(line2, center);
		Vector2 vradBegin = pBegin - center;
		Vector2 vradEnd = pEnd - center;		
		Radian angleTotal = Utils::angleBetween(vradBegin, vradEnd);
		if (vradBegin.crossProduct(vradEnd)<0)
			angleTotal = -angleTotal;
				
		for (unsigned int j=0;j<=mNumSeg;j++)
		{
			Vector2 deltaVector = Utils::rotateVector2(vradBegin, (Real)j * angleTotal / (Real)mNumSeg);
			shape.addPoint(center + deltaVector);
		}
	}

	if (!mClosed)
		shape.addPoint(mPoints[mPoints.size()-1]);

	if (mClosed)
			shape.close();
		shape.setOutSide(mOutSide);

	return shape;
}
示例#29
0
bool pointInTriangle(QPointF point, const Triangle &triangle) {
	QPointF a = triangle[0], b = triangle[1], c = triangle[2];
	if (point == a || point == b || point == c)
		return true;
	QLineF line0(point, a), line1(point, b), line2(point, c);
	qreal angle0 = line0.angleTo(line1);
	angle0 = NORMALIZE_ANGLE(angle0);
	qreal angle1 = line1.angleTo(line2);
	angle1 = NORMALIZE_ANGLE(angle1);
	qreal angle2 = line2.angleTo(line0);
	angle2 = NORMALIZE_ANGLE(angle2);
	return qAbs(angle0 + angle1 + angle2 - 360) < EPS;
}
示例#30
0
void QMyCanvas::DrawLines()
{
    QLineF line(0+BORDER_SIZE+COORDINATE_X1,mousePoint.y(),this->width()-(BORDER_SIZE+COORDINATE_X1),mousePoint.y());
    QLineF line2(mousePoint.x(),BORDER_SIZE+COORDINATE_Y1,mousePoint.x(),this->height()-(BORDER_SIZE+COORDINATE_Y2));
    QPainter painter(this);
    QPen     pen;
    pen.setColor(m_Color);
    pen.setWidth(1);
    painter.setPen(pen);
    painter.drawLine(line);
    painter.drawLine(line2);
    DrawTips();
}