Line3D Segment3D::as_line() { Point3D start_pt3d = start_pt(); Vector3D line_vect = as_versor(); return Line3D(start_pt3d, line_vect); };
//! 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); } }
bool Segment3D::is_point_projection_in_segment(Point3D pt_3d) { Vector3D pt_vector = Segment3D( start_pt(), pt_3d ).as_vector(); double scal_prod = as_vector().scalar_prod( pt_vector ); double segm_length = length(); if (0 <= scal_prod and scal_prod <= segm_length*segm_length) { return true; } else { return false; }; };
// 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; }
// 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; }
void initThread() { int numInit = 10; double noise_factor = 0.0; vector<Vector3d> vertices; vector<double> angles; Vector3d start_pt(18, -50, 125); vertices.push_back(start_pt); angles.push_back(0.0); //push back unitx so first tangent matches start_frame vertices.push_back(start_pt + Vector3d::UnitX()*_rest_length); angles.push_back(0.0); Vector3d direction; direction(0) = 1.0; direction(1) = 0.0; direction(2) = -1.0; direction.normalize(); for (int i=0; i < numInit; i++) { Vector3d noise( ((double)(rand()%10000)) / 10000.0, ((double)(rand()%10000)) / 10000.0, ((double)(rand()%10000)) / 10000.0); noise *= noise_factor; Vector3d next_Vec = vertices.back()+(direction+noise).normalized()*_rest_length; vertices.push_back(next_Vec); angles.push_back(0.0); //std::cout << positions[i] << std::endl << std::endl; } //change direction direction(0) = 1.0; direction(1) = 0.0; direction(2) = 1.0; direction.normalize(); for (int i=0; i < numInit; i++) { Vector3d noise( ((double)(rand()%10000)) / 10000.0, ((double)(rand()%10000)) / 10000.0, ((double)(rand()%10000)) / 10000.0); noise *= noise_factor; Vector3d next_Vec = vertices.back()+(direction+noise).normalized()*_rest_length; vertices.push_back(next_Vec); angles.push_back(0.0); } //push back unitx so last tangent matches end_frame vertices.push_back(vertices.back()+Vector3d::UnitX()*_rest_length); angles.push_back(0.0); angles.resize(vertices.size()); rotations[0] = Matrix3d::Identity(); rotations[1] = Matrix3d::Identity(); /* Vector3d tan = (_thread_pieces[1].vertex() - _thread_pieces[0].vertex()).normalized(); Vector3d toRotAxis; Matrix3d rot_for_frame; if ( (tan -Vector3d::UnitX()).norm() < 0.01 ) { rot_for_frame = Matrix3d::Identity(); } else { toRotAxis = Vector3d::UnitX().cross(tan); double Axisnorm = toRotAxis.norm(); double toRotAng = asin(Axisnorm); toRotAxis /= Axisnorm; // std::cout << "axis: " << toRotAxis << std::endl; // std::cout << "ang: " << toRotAng << std::endl; rot_for_frame = (Eigen::AngleAxisd(toRotAng, toRotAxis)); } //std::cout << "rot for frame: " << rot_for_frame << std::endl; _start_rot = rot_for_frame*Matrix3d::Identity(); //std::cout << "start frame: " << _start_rot << std::endl; std::cout << "energy: " << calculate_energy() << std::endl; */ thread = new Thread(vertices, angles, rotations[0], rotations[1]); updateThreadPoints(); }
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; }