void normalCase(Point start, Point end, double slope, Points &points) const {
    double inverseSlope = 1/slope;
    double b = start.y - slope*start.x;

    bool isLeftRight = start.x < end.x;
    if (!isLeftRight) {
      Point tmp = start;
      start = end;
      end = tmp;
    }

    double xStart = ceil(start.x);
    double xEnd = end.x;
    for (double x = xStart; x < xEnd; x += step_)
      points.push_back(Point(x, slope*x + b));

    bool isBottomTop = start.y < end.y;
    if (!isBottomTop) {
      Point tmp = start;
      start = end;
      end = tmp;
    }

    double yStart = ceil(start.y);
    double yEnd = end.y;
    for (double y = yStart; y < yEnd; y += step_)
      points.push_back(Point((y - b)*inverseSlope, y));

    if (isLeftRight)
      std::sort(points.begin(), points.end(), sort_x());
    else
      std::sort(points.begin(), points.end(), sort_reverse_x());
  }
Example #2
0
void BriefingScreen::draw_system_map() const {
    Point off = offset();
    {
        Points points;
        for (int i = 0; i < _system_stars.size(); ++i) {
            const Star& star       = _system_stars[i];
            RgbColor    star_color = GetRGBTranslateColorShade(Hue::GRAY, star.shade + DARKEST);
            Point       location   = star.location;
            location.offset(off.h, off.v);
            points.draw(location, star_color);
        }
    }

    coordPointType corner;
    int32_t        scale;
    Rect           pix_bounds = _bounds.size().as_rect();
    GetLevelFullScaleAndCorner(0, &corner, &scale, &pix_bounds);
    Rect bounds = _bounds;
    bounds.offset(off.h, off.v);
    draw_arbitrary_sector_lines(corner, scale, 16, bounds);
    draw_briefing_objects(bounds.origin(), 32, pix_bounds, corner, scale);
}
Example #3
0
sp_mat make_ball_basis(const Points & points,
                       const Points & centers,
                       uint R){
  /*
    Make a set of balls.
    Each ball has unique points via set subtraction
    (think "moon shape" if two balls overlap)
    Each ball should have exactly R points, but there may be
    Fewer if we run out of points.
   */
  uint N = points.n_rows;
  uint K = centers.n_rows;
  sp_mat basis = sp_mat(N,K);

  bvec mask = zeros<bvec>(N);
  vec dist;
  uvec idx;
  double r;
  uint k;
  for(k = 0; k < K; k++){
    dist = lp_norm(points.each_row() - centers.row(k),2,1);
    r = find_radius(dist,mask,R);
    idx = find(dist < r);
    for(uint i = 0; i < idx.n_elem; i++){
      // Paint all elements of idx that aren't
      // already in another basis
      if(0 == mask(idx(i)))
        basis(idx(i),k) = 1.0 / (double) idx.n_elem;
    }
    
    mask(idx).fill(1); // Add to mask
    if(N == sum(mask)){
      break;
    }
  }
  basis.resize(N,k); // Avoid all zero
  basis = sp_normalise(basis,2,0); // Should be almost ortho
  return basis;
}
Example #4
0
SCurvedHistogram::Points SCurvedHistogram::getControlPoints(const ::fwData::Histogram::csptr& _histogram) const
{
    ::fwData::Histogram::fwHistogramValues histogramValues = _histogram->getValues();
    const float binsWidth    = _histogram->getBinsWidth();
    const float histogramMin = _histogram->getMinValue();

    Point p;
    Points controlPoints;
    const size_t nbValues = histogramValues.size();

    // WARNING: we shouldn't add all the points of the histogram into the vector of controlPoints
    // (testing...)
    for(size_t i = 0; i < nbValues; ++i)
    {
        p.first  = static_cast<double>(histogramMin + i * binsWidth);
        p.second = histogramValues[i];

        controlPoints.push_back( p );
    }

    return controlPoints;
}
Example #5
0
 const Points& chebpoints(size_t n) {
   if (pointsCache.count(n)) {
     return pointsCache.at(n);
   }
   if (n==0) {
     pointsCache[0] = Points{};
     return pointsCache.at(0);
   }
   Points out;
   out.reserve(n);
   // for(size_t i=0; i <= n; i++) {
   //   CPLX arg(0,PI * i / (1.0 * n));
   //   CPLX z = std::exp(arg);
   //   out.push_back(z.real());
   // }
   for(size_t i=0; i < n; i++) {
     
     out.push_back(std::cos((2*i+1.0) / (2.0 * n)*cheb::PI));
   }
   pointsCache[n] = out;
   return pointsCache.at(n);
 }
CurvedHistogram::Points CurvedHistogram::getControlPoints( ::fwData::Histogram::sptr _histogram)
{
    ::fwData::Histogram::fwHistogramValues histogramValues = _histogram->getValues();
    const float binsWidth = _histogram->getBinsWidth();
    const float histogramMin = _histogram->getMinValue();

    Point p;
    Points controlPoints;
    const unsigned int nbValues = (int) histogramValues.size();

    // WARNING: we shouldn't add all the points of the histogram into the vector of controlPoints
    // (testing...)
    for(unsigned int i = 0; i < nbValues; ++i)
    {
        p.first = (double)(histogramMin + i * binsWidth);
        p.second = histogramValues[i];

        controlPoints.push_back( p );
    }

    return controlPoints;
}
Points ReadPoints(std::ifstream& input) {
  Points data;
  for (std::string id_str;
      std::getline(input, id_str, '\t');) {
    Point point;
    char last_delimiter;
    for (last_delimiter = '\t';
        last_delimiter != '\r' && last_delimiter != '\n'; last_delimiter =
            input.get()) {
      std::string component_str;
      input >> component_str;
      point.push_back(std::atof(component_str.c_str()));
    }
    if (last_delimiter == '\r') {
      const char slash_n = input.get();
    }

    data.emplace_back(std::move(point));
  }

  return data;
}
void FindWithinflattenDescendLists(int totalfound,int* indices,REAL* distances,int N,int* pi,Points& points,Cover::DescendList* descendlists) {
    //total found it the sum of the descendlists counts
    //found must point to totalfound ints
    //upon return found will have the indices of the points on the descendlists
    //N is the number of descendlists, one for each query point
    //pi must point to 2*N ints
    
    vector<DescendNodePtr> vect(totalfound);
    
    int* numfound=pi;
    int* offsets=pi+N;
    numfound[0]=descendlists[0].getCount();
    offsets[0]=0;
    int j=0;
    for(DescendNode* node=descendlists[0].first();node;node=descendlists[0].next(node),j++){
        new(&vect[j]) DescendNodePtr(node);
    }
    sort(&vect[0],&vect[0]+j);
    for(int k=0;k<j;k++) {
        DescendNode* dnode=vect[k].getPtr();
        indices[k]=points.getIndex(dnode->getCoverNode()->getPoint());
        distances[k]=dnode->getDist();
    }
    for(int i=1;i<N;i++) {
        numfound[i]=descendlists[i].getCount();
        offsets[i]=offsets[i-1]+numfound[i-1];
        int j=0;
        for(DescendNode* node=descendlists[i].first();node;node=descendlists[i].next(node),j++){
            new(&vect[j]) DescendNodePtr(node);
        }
        sort(&vect[0],&vect[0]+j);
        for(int k=0;k<j;k++) {
            DescendNode* dnode=vect[k].getPtr();
            indices[offsets[i]+k]=points.getIndex(dnode->getCoverNode()->getPoint());
            distances[offsets[i]+k]=dnode->getDist();
        }
    }
}
Example #9
0
Points generate::circle_filled(int x, int y, int r)
{
	using namespace math;

	Points points;
	points.points.reserve((r+1)*4);

	float xdif;
	int rsqr = sqr(r), x1,x2;
	for (int i = 0; i <= r; i++)
	{
		xdif = sqrt((float) (rsqr - sqr(i)));
		x1 = x +((int) round(-xdif)); x2 = x +((int) round(xdif)) -1;
		// Top half of circle
		points.add(x1, y-i);
		points.add(x2, y-i);
		// Bottom half of circle
		points.add(x1, y+i-1);
		points.add(x2, y+i-1);
	}

	return points;
}
  void zeroSlope(Point start, Point end, Points &points) const {
    if ((start.x - end.x)==0) {
      bool isBottomTop = start.y < end.y;
      if (!isBottomTop) {
        Point tmp = start;
        start = end;
        end = tmp;
      }

      double yStart = ceil(start.y);
      double yEnd = end.y;
      for (double y = yStart; y < yEnd; y += step_)
        points.push_back(Point(start.x, y));

      if (isBottomTop)
        std::sort(points.begin(), points.end(), sort_y());
      else
        std::sort(points.begin(), points.end(), sort_reverse_y());
    } else {
      bool isLeftRight = start.x < end.x;
      if (!isLeftRight) {
        Point tmp = start;
        start = end;
        end = tmp;
      }

      double xStart = ceil(start.x);
      double xEnd = end.x;
      for (double x = xStart; x < xEnd; x += step_)
        points.push_back(Point(x, start.y));

      if (isLeftRight)
        std::sort(points.begin(), points.end(), sort_x());
      else
        std::sort(points.begin(), points.end(), sort_reverse_x());
    }
  }
Example #11
0
Points DubinsCarSimulator::next(const Points & points,
                                const vec & actions) const{
  assert(DUBINS_DIM == points.n_cols);
  assert(points.is_finite());
  assert(DUBINS_ACTION_DIM == actions.n_elem);

  Points new_points = Points(points);
  double u1 = actions(0); // linear velocity
  double u2 = actions(1); // angular velocity
  
  new_points.col(0) += m_step * u1 * cos(points.col(2)); // x
  new_points.col(1) += m_step * u1 * sin(points.col(2)); // y
  new_points.col(2) += m_step * u1*u2; // theta

  // Angle wrap
  uvec wrap_idx = uvec{2};
  mat bbox = {{datum::nan,datum::nan},
              {datum::nan,datum::nan},
              {-datum::pi,datum::pi}};
  wrap(new_points,wrap_idx,bbox);

  // May be out of bounds
  return new_points;
}
Example #12
0
/* This method finds the point that is closest to both this point and the supplied one */
size_t
Point::nearest_waypoint_index(const Points &points, const Point &dest) const
{
    size_t idx = -1;
    double distance = -1;  // double because long is limited to 2147483647 on some platforms and it's not enough

    for (Points::const_iterator p = points.begin(); p != points.end(); ++p) {
        // distance from this to candidate
        double d = pow(this->x - p->x, 2) + pow(this->y - p->y, 2);

        // distance from candidate to dest
        d += pow(p->x - dest.x, 2) + pow(p->y - dest.y, 2);

        // if the total distance is greater than current min distance, ignore it
        if (distance != -1 && d > distance) continue;

        idx = p - points.begin();
        distance = d;

        if (distance < EPSILON) break;
    }

    return idx;
}
Example #13
0
void MainWindow::on_actionOpen_File_triggered()
{
    QString fileName = QFileDialog::getOpenFileName(this);
    if (fileName.isEmpty())
        return ;
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly))
        QMessageBox::warning(this, tr("No File Opened!"), tr("Please check your input."), QMessageBox::Abort);
    else {
        QTextStream fin(&file);
        Points points;
        int num;
        fin >> num;
        for (int i = 0; i < num; i++) {
            Point tmp;
            fin >> tmp.first >> tmp.second;
            points.push_back(tmp);
        }
        file.close();
        graph->setPoints(points);
        drawWidget->transform->setFocusPolicy();
        statusBar()->showMessage(QString("Open File: %1").arg(fileName));
    }
}
Example #14
0
/**
 * txt to binary
 */
int Format1(int argc, char** argv)
{
  assert(argv[1][0] == '1' && argv[1][1] == 0);
  if (argc != 4 && argc != 6) {
    cout
        << "-- For type 1, read binary file and output txt file [start_line] and [end_line] is optional"
        << endl;
    cout << "   " << argv[0]
        << " 1 binary_file_in txt_file_out [start_line] [end_line]" << endl;
    return -1;
  }

  Points<DefaultDataTypes> points;
  points.LoadPoints(argv[2]);
  int start_line = 0;
  int end_line = points.size_;
  if (argc == 6) {
    start_line = atoi(argv[4]);
    end_line = atoi(argv[5]);
  }
  points.WriteTextFile(argv[3], start_line, end_line);

  return -1;
}
Example #15
0
void TableCloth::Find_place(Point& start, int x_dir, int y_dir, char cookie, Points& list)
{
  Points buf_points(8);
  for (int i = start.x + x_dir, j = start.y + y_dir; ; i += x_dir, j += y_dir)
  {
    if (! CheckIndex(i, j) ) return;
    if ( m_table_cloth[i][j] == '.') return;
    if ( m_table_cloth[i][j] == cookie)
    {
      list.Add_last(buf_points);
      return;
    }
    buf_points.Add_last(i, j);
  }
}
Example #16
0
// ##### add() #######################################################
void Solids::add(Element object, Color color) {
  assert (object != NULL);

  Points points;
  cerr << "Solids::add()" << endl;
  for (int i= 0; i < object->getBorderPointCount(); ++i) {
    cerr << "find ";
    ((*object)[i]).print();
    cerr << endl;
    Iterator it= find((*object)[i], color);
    while (exist(it)) {
      cerr << "in exist";
      points+= it.solidIt->points;
      objs.erase(it.solidIt);
    }
  }
  cerr << "add-points" << endl;
  points.add(object);
  Solid newSolid;
  newSolid.points= points;
  newSolid.color= color;
  objs.insert(objs.begin(), newSolid);
  cerr << "solid-add end" << endl;
}
Example #17
0
vec gaussian(const Points & points,
             const vec & center,
             const mat & cov){
  uint N = points.n_rows;
  uint D = points.n_cols;
  assert(D == center.n_elem);
  assert(size(D,D) == size(cov));
  
  vec gauss = vec(N);
  for(uint i = 0; i < N; i++){
    vec x = points.row(i).t() - center;
    gauss(i) = exp(- dot(x, cov * x));
  }
  return gauss;
}
void ExportOrdinalsSmooth::loadSplinePairsWithTransformation (const Points &points,
                                                              const Transformation &transformation,
                                                              bool isLogXTheta,
                                                              bool isLogYRadius,
                                                              vector<double> &t,
                                                              vector<SplinePair> &xy) const
{
  LOG4CPP_INFO_S ((*mainCat)) << "ExportOrdinalsSmooth::loadSplinePairsWithTransformation";

  LinearToLog linearToLog;

  Points::const_iterator itrP;
  for (itrP = points.begin(); itrP != points.end(); itrP++) {
    const Point &point = *itrP;
    QPointF posScreen = point.posScreen();
    QPointF posGraph;
    transformation.transformScreenToRawGraph (posScreen,
                                              posGraph);

    t.push_back (point.ordinal ());
    xy.push_back (SplinePair (linearToLog.linearize (posGraph.x(), isLogXTheta),
                              linearToLog.linearize (posGraph.y(), isLogYRadius)));
  }
}
Example #19
0
void Game::drawCircle(int n_cx, int n_cy, int radius, Color color) {
    double error = static_cast<double>(-radius);
    double x = static_cast<double>(radius) -0.5;
    double y = static_cast<double>(0.5);
    double cx = static_cast<double>(n_cx) -0.5;
    double cy = static_cast<double>(n_cy) -0.5;

    struct Points {
        std::vector<SDL_Point> v;
        SDL_Point p;
        void add(int x, int y) { p.x = x; p.y = y; v.push_back(p); }
        SDL_Point* get() { return &v[0]; }
        int size() { return v.size(); }
    };

    Points points;

    while (x >= y) {
        points.add(cx + x, cy + y);
        points.add(cx + y, cy + x);

        if (x != 0) {
            points.add(cx - x, cy + y);
            points.add(cx + y, cy - x);
        }

        if (y != 0) {
            points.add(cx + x, cy - y);
            points.add(cx - y, cy + x);
        }

        if (x != 0 && y != 0) {
            points.add(cx - x, cy - y);
            points.add(cx - y, cy - x);
        }

        error += y;
        ++y;
        error += y;

        if (error >= 0) {
            --x;
            error -= x;
            error -= x;
        }
    }

    SDL_SetRenderDrawColor(_renderer, color.r, color.g, color.b, color.a);
    SDL_RenderDrawPoints(_renderer, points.get(), points.size());
}
Example #20
0
int Cluster::mergeClusters(double mergeLength, Points &centers, vector<Points> &clusteredPts) {

	bool mergeDone = false;

	while (mergeDone != true) {

		CvPoint toFrom = findMostSimilar(mergeLength, &mergeDone, centers);

		if (mergeDone == false)
			merge(toFrom, centers, clusteredPts);

	}

	return centers.size();

}
// cn_PnPoly(): crossing number test for a point in a polygon
//      Input:   P = a point,
//               V[] = vertex points of a polygon V[n+1] with V[n]=V[0]
//      Return:  0 = outside, 1 = inside
// This code is patterned after [Franklin, 2000]
int PointInPolygonTest::cn_PnPoly(const Point& P, const Points& V)
{
    int cn = 0;    // the  crossing number counter

    // loop through all edges of the polygon
    for (std::size_t i = 0; i< V.size() - 1; ++i) {    // edge from V[i]  to V[i+1]
       if (((V[i].y <= P.y + ::EPS) && (V[i+1].y > P.y - ::EPS))     // an upward crossing
        || ((V[i].y > P.y - ::EPS) && (V[i+1].y <=  P.y + ::EPS))) { // a downward crossing
            // compute  the actual edge-ray intersect x-coordinate
            double vt = static_cast<double>((P.y  - V[i].y) / (V[i+1].y - V[i].y));
            if (P.x <  V[i].x + vt * (V[i+1].x - V[i].x) + ::EPS) // P.x < intersect
                 ++cn;   // a valid crossing of y=P.y right of P.x
        }
    }
    return cn & 1;    // 0 if even (out), and 1 if  odd (in)

}
Example #22
0
void Cluster::getClusterCenters(const vector<Points> &clusteredPts, Points &centers) {

	for (unsigned int i = 0; i < clusteredPts.size(); i++) {

		int x = 0, y = 0;
		vector<CvPoint> tempClass(clusteredPts[i]);

		for (unsigned int j = 0; j < tempClass.size(); j++) {
			x += tempClass[j].x;
			y += tempClass[j].y;
		}

		centers.push_back(cvPoint(x / tempClass.size(), y / tempClass.size()));

	}

}
CurvedHistogram::Points CurvedHistogram::getResampledBSplinePoints( Points & _bSplinePoints )
{
    SLM_TRACE_FUNC();

    Points points;
    Points::iterator it;

    Point point = _bSplinePoints.front();

    double dx, dy;
    const double maxLength = 2000;
    double segmentLength = 0;

    points.push_back( point );

    for(it = _bSplinePoints.begin() + 1; it != _bSplinePoints.end(); ++it)
    {
        dx = abs((*it).first - point.first);    // theoretically positive
        dy = abs((*it).second - point.second);

        segmentLength += sqrt( dx * dx + dy * dy );

        if(segmentLength > maxLength)
        {
            points.push_back( *it );
            segmentLength = 0;
        }

        point = *it;
    }

    points.push_back( _bSplinePoints.back() );

    OSLM_TRACE("B-Spline points size moved from " << _bSplinePoints.size() << " to " << points.size());

    return points;
}
Example #24
0
vec gabor_wavelet(const Points & points,
                  const vec & center,
                  const vec & freq,
                  const double bandwidth,
                  const double shift){
  uint N = points.n_rows;
  uint D = points.n_cols;

  assert(D == center.n_elem);
  assert(D == freq.n_elem);
  
  // Gabor wavelet (real valued frequencies only)
  vec sqdist = sum(pow(points.each_row() - center.t(),2),1);
  vec gauss = exp(-bandwidth*sqdist);
  vec wave = sin(2.0 * datum::pi * (points * freq) + shift);
  
  return gauss % wave;
}
void
ExtrusionEntityCollection::chained_path_from(Point start_near, ExtrusionEntityCollection* retval, bool no_reverse, std::vector<size_t>* orig_indices) const
{
    if (this->no_sort) {
        *retval = *this;
        return;
    }
    retval->entities.reserve(this->entities.size());
    retval->orig_indices.reserve(this->entities.size());
    
    // if we're asked to return the original indices, build a map
    std::map<ExtrusionEntity*,size_t> indices_map;
    
    ExtrusionEntitiesPtr my_paths;
    for (ExtrusionEntitiesPtr::const_iterator it = this->entities.begin(); it != this->entities.end(); ++it) {
        ExtrusionEntity* entity = (*it)->clone();
        my_paths.push_back(entity);
        if (orig_indices != NULL) indices_map[entity] = it - this->entities.begin();
    }
    
    Points endpoints;
    for (ExtrusionEntitiesPtr::iterator it = my_paths.begin(); it != my_paths.end(); ++it) {
        endpoints.push_back((*it)->first_point());
        if (no_reverse) {
            endpoints.push_back((*it)->first_point());
        } else {
            endpoints.push_back((*it)->last_point());
        }
    }
    
    while (!my_paths.empty()) {
        // find nearest point
        int start_index = start_near.nearest_point_index(endpoints);
        int path_index = start_index/2;
        ExtrusionEntity* entity = my_paths.at(path_index);
        // never reverse loops, since it's pointless for chained path and callers might depend on orientation
        if (start_index % 2 && !no_reverse && !entity->is_loop()) {
            entity->reverse();
        }
        retval->entities.push_back(my_paths.at(path_index));
        if (orig_indices != NULL) orig_indices->push_back(indices_map[entity]);
        my_paths.erase(my_paths.begin() + path_index);
        endpoints.erase(endpoints.begin() + 2*path_index, endpoints.begin() + 2*path_index + 2);
        start_near = retval->entities.back()->last_point();
    }
}
Example #26
0
mat make_rbf_basis(const Points & points,
                   const Points & centers,
                   double bandwidth,
                   double cutoff_thresh){
  uint N = points.n_rows;
  uint K = centers.n_rows;
  
  mat basis = zeros<mat>(N,K+1);
  basis.col(K) = ones<vec>(N);
  for(uint k = 0; k < K; k++){
    basis.col(k) = gaussian(points,centers.row(k).t(),bandwidth);
  }
  //basis(find(basis < cutoff_thresh)).fill(0);
  basis = orth(basis); // Not ortho at all; need to do explicitly
  if(basis.n_cols < (K+1)){
    cerr << "WARNING: Basis degenerate..." << endl;
  }
  return basis;
}
// wn_PnPoly(): winding number test for a point in a polygon
//      Input:   P = a point,
//               V[] = vertex points of a polygon V[n+1] with V[n]=V[0]
//      Return:  wn = the winding number (=0 only when P is outside)
int PointInPolygonTest::wn_PnPoly( const Point& P, const Points& V)
{
    int wn = 0;    // the  winding number counter

    // loop through all edges of the polygon
    for (std::size_t i = 0; i < V.size() - 1; ++i) {   // edge from V[i] to  V[i+1]
        if (V[i].y <= P.y + ::EPS) {          // start y <= P.y
            if (V[i+1].y  > P.y - ::EPS)      // an upward crossing
                 if (isLeft( V[i], V[i+1], P) > -::EPS)  // P left of  edge
                     ++wn;            // have  a valid up intersect
        }
        else {                        // start y > P.y (no test needed)
            if (V[i+1].y  <= P.y + ::EPS)     // a downward crossing
                 if (isLeft( V[i], V[i+1], P) < ::EPS)  // P right of  edge
                     --wn;            // have  a valid down intersect
        }
    }
    return wn;
}
Example #28
0
File: n4.cpp Project: Effet/acm
Planes ConvexHull_3D(Points &P)
{
    Planes CH;
    int n = P.size(), i, j, k, l;
    
    for (i = 0; i < n; i++)
        for (j = i+1; j < n; j++)
            for (k = i+1; k < n; k++)
            {
                Plane pl = {P[i], P[j], P[k]};
                Point p = pl.normal();
                for (l = 0; l < n; l++)
                    if (l != i && l != j && l != k && ! pl.same_side(p, P[l]))
                        break;
                if (l == n)
                    CH.push_back(pl);
            }
    return CH;
}
Example #29
0
std::vector<Points> fastPartition(const Points &polygon)
{
    // Hertel-Mehlhorn partitioning

    // Triangulate polygon
    std::vector<int> triangles = triProcess(polygon);

    // Get a list of unique diagonals
    // Every edge not part of the outline is a diagonal.
    // Outline edges are all consecutive.
    std::vector<Diagonal> diagonals;
    std::unordered_set<int> dset;
    const int c = polygon.size();
    for(unsigned int i=0;i<triangles.size();i+=3) {
        addDiagonal(triangles, i,   i+1, c, diagonals, dset);
        addDiagonal(triangles, i+1, i+2, c, diagonals, dset);
        addDiagonal(triangles, i+2, i,   c, diagonals, dset);
    }

    // Order diagonal list: v1 ascending, v2 descending
    std::sort(diagonals.begin(), diagonals.end(), [](const Diagonal &i, const Diagonal &j)->bool {
        if(i.v1 == j.v1)
            return i.v2>=j.v2;
        return i.v1<j.v1;
    });

    // Check which vertices are reflex.
	std::vector<bool> reflex;
    reflex.push_back(isReflex(polygon[polygon.size()-1], polygon[0], polygon[1]));
    for(unsigned int i=1;i<polygon.size()-1;++i)
        reflex.push_back(isReflex(polygon[i-1], polygon[i], polygon[i+1]));
    reflex.push_back(isReflex(polygon[polygon.size()-2], polygon[polygon.size()-1], polygon[0]));

    // Remove inessential diagonals.
    for(unsigned int i=0;i<diagonals.size();++i) {
        Diagonal &di = diagonals[i];
        // See if removing this diagonal would create a reflex vertex
        di.removed =
            !(reflex[di.v1] && isDiagonalEssential1(polygon, diagonals, i)) &&
            !(reflex[di.v2] && isDiagonalEssential2(polygon, diagonals, i));
    }

	// Split into polygons
    std::vector<Points> result(1);
	std::vector<bool> visited(polygon.size());
    polySplit(polygon, diagonals, 0, 0, visited, result);

    result.pop_back(); // remove the last empty polygon
    return result;
}
Example #30
0
ExportValuesOrdinal ExportFileRelations::ordinalsAtIntervalsStraightGraph (double pointsIntervalRelations,
                                                                           const Transformation &transformation,
                                                                           const Points &points) const
{
  LOG4CPP_INFO_S ((*mainCat)) << "ExportFileRelations::ordinalsAtIntervalsStraightGraph";

  ExportValuesOrdinal ordinals;

  // Prevent infinite loop when there are no points or will be too many points
  if ((pointsIntervalRelations > 0) &&
      (points.count() > 0)) {

    ExportOrdinalsStraight ordinalsStraight;

    ordinals = ordinalsStraight.ordinalsAtIntervalsGraphWithTransformation (points,
                                                                            transformation,
                                                                            pointsIntervalRelations);
  }

  return ordinals;
}