Beispiel #1
0
//! Static member to draw a line with arrows at the ends
void QGLE::drawArrowLine(QPainter *p, qreal x0, qreal y0, qreal x1, qreal y1, qreal size, qreal angle, bool a0, bool a1, const QPen& pen) {
	double dx = x1 - x0;
	double dy = y1 - y0;
	GLEPoint start_pt((double)x0, (double)y0);
	GLEPoint end_pt((double)x1, (double)y1);
	GLEArrowPoints pts1, pts2;
	GLEGetArrowPointsNoProps(start_pt, dx,  dy, 1, size, angle, &pts1);
	GLEGetArrowPointsNoProps(end_pt,  -dx, -dy, 1, size, angle, &pts2);
	QPen new_pen = pen;
	new_pen.setJoinStyle(Qt::MiterJoin);
	new_pen.setMiterLimit(20);
	if (a0) start_pt.setXY(pts1.xl, pts1.yl);
	if (a1) end_pt.setXY(pts2.xl, pts2.yl);
	p->setPen(pen);
	p->drawLine(QPointF(start_pt.getX(), start_pt.getY()), QPointF(end_pt.getX(), end_pt.getY()));
	p->setPen(new_pen);
	if (a0) {
		QPointF poly[3];
		poly[0] = QPointF(pts1.xa, pts1.ya);
		poly[1] = QPointF(pts1.xt, pts1.yt);
		poly[2] = QPointF(pts1.xb, pts1.yb);
		p->setBrush(QBrush(Qt::black));
		p->drawConvexPolygon(poly, 3);
	}
	if (a1) {
		QPointF poly[3];
		poly[0] = QPointF(pts2.xa, pts2.ya);
		poly[1] = QPointF(pts2.xt, pts2.yt);
		poly[2] = QPointF(pts2.xb, pts2.yb);
		p->setBrush(QBrush(Qt::black));
		p->drawConvexPolygon(poly, 3);
	}
}
Beispiel #2
0
template <typename PointNT> void
pcl::GridProjection<PointNT>::getProjection (const Eigen::Vector4f &p,
                                             std::vector <int> &pt_union_indices, Eigen::Vector4f &projection)
{
  const double projection_distance = leaf_size_ * 3;
  std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > end_pt (2);
  std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > end_pt_vect (2);
  end_pt[0] = p;
  getVectorAtPoint (end_pt[0], pt_union_indices, end_pt_vect[0]);
  end_pt_vect[0].normalize();

  double dSecond = getD2AtPoint (end_pt[0], end_pt_vect[0], pt_union_indices);

  // Find another point which is projection_distance away from the p, do a
  // binary search between these two points, to find the projected point on the
  // surface
  if (dSecond > 0)
    end_pt[1] = end_pt[0] + Eigen::Vector4f (end_pt_vect[0][0] * projection_distance,
                                             end_pt_vect[0][1] * projection_distance,
                                             end_pt_vect[0][2] * projection_distance, 0);
  else
    end_pt[1] = end_pt[0] - Eigen::Vector4f (end_pt_vect[0][0] * projection_distance,
                                             end_pt_vect[0][1] * projection_distance,
                                             end_pt_vect[0][2] * projection_distance, 0);
  getVectorAtPoint (end_pt[1], pt_union_indices, end_pt_vect[1]);
  if (end_pt_vect[1].dot (end_pt_vect[0]) < 0)
  {
    Eigen::Vector4f mid_pt = end_pt[0] + (end_pt[1] - end_pt[0]) * 0.5;
    findIntersection (0, end_pt, end_pt_vect, mid_pt, pt_union_indices, projection);
  }
  else
    projection = p;
}
// Helper returns the mean gradient value for the horizontal row at the given
// y, (in the external coordinates) by subtracting the mean of the transformed
// row 2 pixels above from the mean of the transformed row 2 pixels below.
// This gives a positive value for a good top edge and negative for bottom.
// Returns the best result out of +2/-2, +3/-1, +1/-3 pixels from the edge.
int TextlineProjection::BestMeanGradientInRow(const DENORM* denorm,
                                              int16_t min_x, int16_t max_x, int16_t y,
                                              bool best_is_max) const {
  TPOINT start_pt(min_x, y);
  TPOINT end_pt(max_x, y);
  int upper = MeanPixelsInLineSegment(denorm, -2, start_pt, end_pt);
  int lower = MeanPixelsInLineSegment(denorm, 2, start_pt, end_pt);
  int best_gradient = lower - upper;
  upper = MeanPixelsInLineSegment(denorm, -1, start_pt, end_pt);
  lower = MeanPixelsInLineSegment(denorm, 3, start_pt, end_pt);
  int gradient = lower - upper;
  if ((gradient > best_gradient) == best_is_max)
    best_gradient = gradient;
  upper = MeanPixelsInLineSegment(denorm, -3, start_pt, end_pt);
  lower = MeanPixelsInLineSegment(denorm, 1, start_pt, end_pt);
  gradient = lower - upper;
  if ((gradient > best_gradient) == best_is_max)
    best_gradient = gradient;
  return best_gradient;
}
// Helper returns the mean gradient value for the vertical column at the
// given x, (in the external coordinates) by subtracting the mean of the
// transformed column 2 pixels left from the mean of the transformed column
// 2 pixels to the right.
// This gives a positive value for a good left edge and negative for right.
// Returns the best result out of +2/-2, +3/-1, +1/-3 pixels from the edge.
int TextlineProjection::BestMeanGradientInColumn(const DENORM* denorm, int16_t x,
                                                 int16_t min_y, int16_t max_y,
                                                 bool best_is_max) const {
  TPOINT start_pt(x, min_y);
  TPOINT end_pt(x, max_y);
  int left = MeanPixelsInLineSegment(denorm, -2, start_pt, end_pt);
  int right = MeanPixelsInLineSegment(denorm, 2, start_pt, end_pt);
  int best_gradient = right - left;
  left = MeanPixelsInLineSegment(denorm, -1, start_pt, end_pt);
  right = MeanPixelsInLineSegment(denorm, 3, start_pt, end_pt);
  int gradient = right - left;
  if ((gradient > best_gradient) == best_is_max)
    best_gradient = gradient;
  left = MeanPixelsInLineSegment(denorm, -3, start_pt, end_pt);
  right = MeanPixelsInLineSegment(denorm, 1, start_pt, end_pt);
  gradient = right - left;
  if ((gradient > best_gradient) == best_is_max)
    best_gradient = gradient;
  return best_gradient;
}
Beispiel #5
0
static int getPageLinks(lua_State *L) {
	CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");

	lua_newtable(L); // all links

	ldomXRangeList links;
	ldomXRangeList & sel = doc->text_view->getDocument()->getSelections();

	doc->text_view->getCurrentPageLinks( links );
	int linkCount = links.length();
	if ( linkCount ) {
		sel.clear();
		lvRect margin = doc->text_view->getPageMargins();
		int x_offset = margin.left;
		int y_offset = doc->text_view->GetPos() - doc->text_view->getPageHeaderHeight() - margin.top;
		for ( int i=0; i<linkCount; i++ ) {
			lString16 txt = links[i]->getRangeText();
			lString8 txt8 = UnicodeToLocal( txt );

			lString16 link = links[i]->getHRef();
			lString8 link8 = UnicodeToLocal( link );

			ldomXRange currSel;
			currSel = *links[i];

			lvPoint start_pt ( currSel.getStart().toPoint() );
			lvPoint end_pt ( currSel.getEnd().toPoint() );

				CRLog::debug("# link %d start %d %d end %d %d '%s' %s\n", i,
				start_pt.x, start_pt.y, end_pt.x, end_pt.y,
				txt8.c_str(), link8.c_str()
			);

			lua_newtable(L); // new link

			lua_pushstring(L, "start_x");
			lua_pushinteger(L, start_pt.x + x_offset);
			lua_settable(L, -3);
			lua_pushstring(L, "start_y");
			lua_pushinteger(L, start_pt.y - y_offset);
			lua_settable(L, -3);
			lua_pushstring(L, "end_x");
			lua_pushinteger(L, end_pt.x + x_offset);
			lua_settable(L, -3);
			lua_pushstring(L, "end_y");
			lua_pushinteger(L, end_pt.y - y_offset);
			lua_settable(L, -3);

			const char * link_to = link8.c_str();

			if ( link_to[0] == '#' ) {
				lua_pushstring(L, "section");
				lua_pushstring(L, link_to);
				lua_settable(L, -3);

				sel.add( new ldomXRange(*links[i]) ); // highlight
			} else {
				lua_pushstring(L, "uri");
				lua_pushstring(L, link_to);
				lua_settable(L, -3);
			}

			lua_rawseti(L, -2, i + 1);

		}
		doc->text_view->updateSelections();
	}

	return 1;
}