Ejemplo n.º 1
0
Segment* Articulation::segment() const
      {
      ChordRest* cr = chordRest();
      if (!cr)
            return 0;

      Segment* s = 0;
      if (cr->isGrace()) {
            if (cr->parent())
                  s = toSegment(cr->parent()->parent());
            }
      else
            s = toSegment(cr->parent());

      return s;
      }
Ejemplo n.º 2
0
bool 
CurveIntersection::check(const std::vector<Polyline2DPtr>& lines)
{
#ifdef WITH_CGAL
   // Construct the first arrangement, containing a polyline 1.
	std::list<Segment_2>   arrs;
   // std::vector<Segment_2> segments;
	for(std::vector<Polyline2DPtr>::const_iterator itLines = lines.begin(); itLines != lines.end(); ++itLines){
	  // Arrangement_2   arr;
      for (Point2Array::const_iterator it1 = (*itLines)->getPointList()->begin()+1; it1 != (*itLines)->getPointList()->end(); ++it1)
	     // insert_non_intersecting_curve(arrs,Segment_2(Point_2((it1-1)->x(),(it1-1)->y()),Point_2(it1->x(),it1->y())));
		 if (norm(*(it1-1)-*it1) > GEOM_EPSILON)
			arrs.push_back(toSegment(*(it1-1),*it1));
	}
	
   std::list<Point_2>     pts;
   // check whether an intersection exists
   return CGAL::do_curves_intersect (arrs.begin(), arrs.end());
#else
#ifdef _MSC_VER
#pragma message("CGAL not included. CurveIntersection routine will not work.")
#else
#warning "CGAL not included. CurveIntersection routine will not work."
#endif
	pglError("CGAL not included. CurveIntersection routine will not work.");
	return false;
#endif

}
Ejemplo n.º 3
0
Point2ArrayPtr 
CurveIntersection::compute(const std::vector<Polyline2DPtr>& lines)
{
#ifdef WITH_CGAL
   // Construct the first arrangement, containing a polyline 1.
	std::list<Segment_2>   arrs;
   // std::vector<Segment_2> segments;
	for(std::vector<Polyline2DPtr>::const_iterator itLines = lines.begin(); itLines != lines.end(); ++itLines){
	  // Arrangement_2   arr;
      for (Point2Array::const_iterator it1 = (*itLines)->getPointList()->begin()+1; it1 != (*itLines)->getPointList()->end(); ++it1)
	     // insert_non_intersecting_curve(arrs,Segment_2(Point_2((it1-1)->x(),(it1-1)->y()),Point_2(it1->x(),it1->y())));
		 if (norm(*(it1-1)-*it1) > GEOM_EPSILON)
			arrs.push_back(toSegment(*(it1-1),*it1));
	}
	
   std::list<Point_2>     pts;
   // note the endpoints bool value, whether we include the segment points in the count or not
   CGAL::compute_intersection_points (arrs.begin(), arrs.end(), std::back_inserter (pts), false);
   Point2ArrayPtr     respts(new Point2Array());
   for(std::list<Point_2>::const_iterator itPoints = pts.begin(); itPoints != pts.end(); ++itPoints)
	   respts->push_back(toVec2(*itPoints));
   return respts;
#else
#ifdef _MSC_VER
#pragma message("CGAL not included. CurveIntersection routine will not work.")
#else
#warning "CGAL not included. CurveIntersection routine will not work."
#endif
	pglError("CGAL not included. CurveIntersection routine will not work.");
	return Point2ArrayPtr();
#endif
}
Ejemplo n.º 4
0
void InspectorClef::setElement()
      {
      otherClef = nullptr;                      // no 'other clef' yet
      InspectorElementBase::setElement();

      // try to locate the 'other clef' of a courtesy / main pair
      Clef* clef = toClef(inspector->element());
      // if not in a clef-segment-measure hierarchy, do nothing
      if (!clef->parent() || clef->parent()->type() != ElementType::SEGMENT)
            return;
      Segment*    segm = toSegment(clef->parent());
      int         segmTick = segm->tick();
      if (!segm->parent() || segm->parent()->type() != ElementType::MEASURE)
            return;

      Measure* meas = toMeasure(segm->parent());
      Measure* otherMeas = nullptr;
      Segment* otherSegm = nullptr;
      if (segmTick == meas->tick())                         // if clef segm is measure-initial
            otherMeas = meas->prevMeasure();                // look for a previous measure
      else if (segmTick == meas->tick()+meas->ticks())      // if clef segm is measure-final
            otherMeas = meas->nextMeasure();                // look for a next measure
      // look for a clef segment in the 'other' measure at the same tick of this clef segment
      if (otherMeas)
            otherSegm = otherMeas->findSegment(SegmentType::Clef, segmTick);
      // if any 'other' segment found, look for a clef in the same track as this
      if (otherSegm)
            otherClef = toClef(otherSegm->element(clef->track()));
      }
Ejemplo n.º 5
0
Clef* Clef::otherClef()
      {
      // if not in a clef-segment-measure hierarchy, do nothing
      if (!parent() || !parent()->isSegment())
            return nullptr;
      Segment* segm = toSegment(parent());
      int segmTick = segm->tick();
      if (!segm->parent() || !segm->parent()->isMeasure())
            return nullptr;
      Measure* meas = toMeasure(segm->parent());
      Measure* otherMeas = nullptr;
      Segment* otherSegm = nullptr;
      if (segmTick == meas->tick())                         // if clef segm is measure-initial
            otherMeas = meas->prevMeasure();                // look for a previous measure
      else if (segmTick == meas->tick() + meas->ticks())    // if clef segm is measure-final
            otherMeas = meas->nextMeasure();                // look for a next measure
      if (!otherMeas)
            return nullptr;
      // look for a clef segment in the 'other' measure at the same tick of this clef segment
      otherSegm = otherMeas->findSegment(SegmentType::Clef | SegmentType::HeaderClef, segmTick);
      if (!otherSegm)
            return nullptr;
      // if any 'other' segment found, look for a clef in the same track as this
      return toClef(otherSegm->element(track()));
      }
Ejemplo n.º 6
0
Segment* StaffTextBase::segment() const
      {
      if (!parent()->isSegment()) {
            qDebug("parent %s", parent()->name());
            return 0;
            }
      Segment* s = toSegment(parent());
      return s;
      }
Ejemplo n.º 7
0
QLineF FretDiagram::dragAnchor() const
      {
      qreal xp = 0.0;
      for (Element* e = parent(); e; e = e->parent())
            xp += e->x();
      qreal yp;
      if (parent()->isSegment()) {
            System* system = toSegment(parent())->measure()->system();
            yp = system->staffCanvasYpage(staffIdx());
            }
      else
            yp = parent()->canvasPos().y();
      QPointF p1(xp, yp);
      return QLineF(p1, canvasPos());
#if 0 // TODOxx
      if (parent()->type() == ElementType::SEGMENT) {
            Segment* s     = toSegment(parent());
            Measure* m     = s->measure();
            System* system = m->system();
            qreal yp      = system->staff(staffIdx())->y() + system->y();
            qreal xp      = m->tick2pos(s->tick()) + m->pagePos().x();
            QPointF p1(xp, yp);

            qreal x  = 0.0;
            qreal y  = 0.0;
            qreal tw = width();
            qreal th = height();
            if (_align & Align::BOTTOM)
                  y = th;
            else if (_align & Align::VCENTER)
                  y = (th * .5);
            else if (_align & Align::BASELINE)
                  y = baseLine();
            if (_align & Align::RIGHT)
                  x = tw;
            else if (_align & Align::HCENTER)
                  x = (tw * .5);
            return QLineF(p1, abbox().topLeft() + QPointF(x, y));
            }
      return QLineF(parent()->pagePos(), abbox().topLeft());
#endif
      }
Ejemplo n.º 8
0
QPointF FretDiagram::pagePos() const
      {
      if (parent() == 0)
            return pos();
      if (parent()->isSegment()) {
            Measure* m = toSegment(parent())->measure();
            System* system = m->system();
            qreal yp = y();
            if (system)
                  yp += system->staffYpage(staffIdx());
            return QPointF(pageX(), yp);
            }
      else
            return Element::pagePos();
      }
Ejemplo n.º 9
0
bool ImageSegmentation::toSegment(const std::vector<std::vector<cv::Point>> &contours, const std::vector<cv::Vec4i> &hierarchy, const size_t index,
                                  Segment &seg, const size_t minSize, const size_t minHoleSize, const cv::Rect &roi)
{
  seg.rect = cv::boundingRect(contours[index]);
  if(!roi.contains(seg.rect.tl()) || !roi.contains(seg.rect.br()))
  {
    // outside ROI
    return false;
  }

  seg.area = cv::contourArea(contours[index]);
  seg.childrenArea = 0;
  seg.holes = 0;

  if(seg.area < minSize)
  {
    return false;
  }

  Segment child;
  for(int32_t childIndex = hierarchy[index][2]; childIndex >= 0; childIndex = hierarchy[childIndex][0])
  {
    if(toSegment(contours, hierarchy, childIndex, child, minHoleSize, minHoleSize, roi))
    {
      seg.children.push_back(child);
      seg.area -= child.area;
      seg.childrenArea += child.area;
      ++seg.holes;
    }
  }

  if(seg.area < minSize)
  {
    return false;
  }

  seg.contour = contours[index];
  computeMoments(contours, hierarchy, index, seg);
  compute2DAttributes(seg);

  return true;
}
Ejemplo n.º 10
0
QPointF BSymbol::canvasPos() const
      {
      if (parent() && (parent()->type() == ElementType::SEGMENT)) {
            QPointF p(pos());
            Segment* s = toSegment(parent());

            System* system = s->measure()->system();
            if (system) {
                  int si = staffIdx();
                  p.ry() += system->staff(si)->y() + system->y();
                  Page* page = system->page();
                  if (page)
                        p.ry() += page->y();
                  }
            p.rx() = canvasX();
            return p;
            }
      else
            return Element::canvasPos();
      }
Ejemplo n.º 11
0
void InputState::moveInputPos(Element* e)
      {
      if (e == 0)
            return;

      Segment* s;
      if (e->isChordRest1())
            s = toChordRest(e)->segment();
      else
            s = toSegment(e);

      if (s->isSegment()) {
            if (s->measure()->isMMRest()) {
                  Measure* m = s->measure()->mmRestFirst();
                  s = m->findSegment(Segment::Type::ChordRest, m->tick());
                  }
            _lastSegment = _segment;
            _segment = s;
            }
      }
Ejemplo n.º 12
0
void ImageSegmentation::segment(const cv::Mat &bin, std::vector<Segment> &segments, const size_t minSize, const size_t minHoleSize, const cv::Rect &roi)
{
  std::vector<std::vector<cv::Point>> contours;
  std::vector<cv::Vec4i> hierarchy;

  segments.clear();

  cv::findContours(bin.clone(), contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);

  for(int32_t i = 0; i < contours.size(); ++i)
  {
    Segment seg;
    const int32_t parent = hierarchy[i][3];
    if(parent >= 0)
    {
      // not a root segment
      continue;
    }
    if(toSegment(contours, hierarchy, i, seg, minSize, minHoleSize, roi))
    {
      segments.push_back(seg);
    }
  }
}
Ejemplo n.º 13
0
GeometryPtr 
Overlay::process(const Polyline2DPtr& p1, const Polyline2DPtr& p2)
{
	if (!p1 || !p2 || p1->getPointListSize() < 2 || p2->getPointListSize() < 2) return GeometryPtr();
#ifdef WITH_CGAL

  // Construct the first arrangement, containing a polyline 1.
  Arrangement_2          arr1;

  for (Point2Array::const_iterator it1 = p1->getPointList()->begin()+1; it1 != p1->getPointList()->end(); ++it1)
	insert_non_intersecting_curve(arr1,toSegment(*(it1-1),*it1));

  // to be a closed face, first and last point should be exactly the same.
  // However we should not duplicate the same point twice at the end.
  Vector2& fp1 = p1->getPointList()->getAt(0);
  Vector2& lp1 = *(p1->getPointList()->end()-1);
  if (fp1.x() != lp1.x() || fp1.y() != lp1.y())
	insert_non_intersecting_curve(arr1,toSegment(lp1,fp1));

  // std::cerr << arr1.number_of_vertices() << " " << arr1.number_of_edges() << " " << arr1.number_of_faces() << std::endl;

  // Mark just the bounded face.
  Arrangement_2::Face_iterator   fit;

  CGAL_assertion (arr1.number_of_faces() == 2);
  for (fit = arr1.faces_begin(); fit != arr1.faces_end(); ++fit)
    fit->set_data (fit != arr1.unbounded_face());

  // Construct the second arrangement.
  Arrangement_2          arr2;

  for (Point2Array::const_iterator it2 = p2->getPointList()->begin()+1; it2 != p2->getPointList()->end(); ++it2)
	 	insert(arr2,toSegment(*(it2-1),*it2));

  // to be a closed face, first and last point should be exactly the same.
  // However we should not duplicate the same point twice at the end.
  Vector2& fp2 = p2->getPointList()->getAt(0);
  Vector2& lp2 = *(p2->getPointList()->end()-1);
  if (fp2.x() != lp2.x() || fp2.y() != lp2.y())
	insert(arr2,toSegment(lp2,fp2)); 

  // std::cerr << arr2.number_of_vertices() << " " << arr2.number_of_edges() << " " << arr2.number_of_faces() << std::endl;

  CGAL_assertion (arr2.number_of_faces() == 2);
  for (fit = arr2.faces_begin(); fit != arr2.faces_end(); ++fit)
    fit->set_data (fit != arr2.unbounded_face());

  // Compute the overlay of the two arrangements.
  Arrangement_2          overlay_arr;
  Overlay_traits         overlay_traits;

  overlay (arr1, arr2, overlay_arr, overlay_traits);

  // std::cerr << overlay_arr.number_of_vertices() << " " << overlay_arr.number_of_edges() << " " << overlay_arr.number_of_faces() << std::endl;

  // conversion between cgal structures and plantgl ones.
  GeometryArrayPtr geomarray(new GeometryArray(0));
  for (Arrangement_2::Face_iterator face = overlay_arr.faces_begin(); face != overlay_arr.faces_end(); ++face)
  {
    if (face->is_fictitious () || face->is_unbounded())
		continue;
    if (! face->data())
      continue;
   
    Arrangement_2::Ccb_halfedge_circulator curr = face->outer_ccb();
	Point2ArrayPtr pointSet( new Point2Array(1,toVec2(curr->source()->point())));
    do
    {
	  pointSet->push_back(toVec2(curr->target()->point()));
      ++curr;
    } while (curr != face->outer_ccb());
	if (pointSet->size() == 1){
		geomarray->push_back(GeometryPtr(new PointSet2D(pointSet)));
	}
	else if(pointSet->size() > 1){
		geomarray->push_back(GeometryPtr(new Polyline2D(pointSet)));
	}
  }
  if (geomarray->empty())return GeometryPtr();
  else if (geomarray->size() == 1) return geomarray->getAt(0);
  else return GeometryPtr(new Group(geomarray));

#else
#ifdef _MSC_VER
#pragma message("CGAL not included. Overlay routine will not work.")
#else
#warning "CGAL not included. Overlay routine will not work."
#endif
	pglError("CGAL not included. Overlay routine will not work.");
	return GeometryPtr();
#endif

}