Exemplo n.º 1
0
pairs* bforce(point P[], int size)
{
	if(!P)
		return NULL;
	pairs* closest = NULL;
	long double delta = DBL_MAX;
	point* min1 = newpoint(0.0,0.0);
	point* min2 = newpoint(0.0,0.0);
	int i;
	int j;
	for(i=0; i < size; i++)
	{
		for(j= 0; j < size; j++)
		{
			long double dist = distance(P[i],P[j]);
			if(distance(dist < delta)
			{
				min1 =  *(P+i);
				min2 = *(P+j);
				delta = dist;
			}
		}
	}
	pairs* closest = newpairs(min1,min2,delta);
	return closest;
}
Exemplo n.º 2
0
void
uwinterference::addToCollisionCounters(
		PKT_TYPE type, double starttime, int incr_value)
{
	CollisionFunction::iterator it;
	for (it = cp.begin(); it != cp.end();) {
		if (it->time < starttime - maxinterval_) {
			it = cp.erase(it);
		} else {
			break;
		}
	}

	if (cp.empty()) {
		if (type == CTRL) {
			CollisionType newpoint(incr_value, 0, NOW);
			cp.push_back(newpoint);
		} else if (type == DATA) {
			CollisionType newpoint(0, incr_value, NOW);
			cp.push_back(newpoint);
		}
	} else {
		CollisionType lastcollision(cp.back());
		if (type == CTRL) {
			CollisionType newcollision(lastcollision.CtrlPkts + incr_value,
					lastcollision.DataPkts,
					NOW);
			if ((newcollision.CtrlPkts < 0) || (newcollision.DataPkts < 0)) {
				if (debug_)
					cout << "WARNING: cancellation error" << endl;
				if (newcollision.CtrlPkts < 0) {
					newcollision.CtrlPkts = 0;
				} else {
					newcollision.DataPkts = 0;
				}
			}
			cp.push_back(newcollision);

		} else if (type == DATA) {
			CollisionType newcollision(lastcollision.CtrlPkts,
					lastcollision.DataPkts + incr_value,
					NOW);
			if ((newcollision.CtrlPkts < 0) || (newcollision.DataPkts < 0)) {
				if (debug_)
					cout << "WARNING: cancellation error" << endl;
				if (newcollision.CtrlPkts < 0) {
					newcollision.CtrlPkts = 0;
				} else {
					newcollision.DataPkts = 0;
				}
			}
			cp.push_back(newcollision);
		} else {
			cerr << "Type of the packet not valid!!!" << endl;
			exit(1);
		}
	}
}
void StereoReconstructor::translateCoordinate(std::string cordsys, std::string points, std::string newPoints) {
  std::ifstream cord(cordsys.c_str());
  if (!cord) {
    std::cout << cordsys << " file open failed!" << std::endl;
    return;
  }
  std::vector<cv::Point3f> coord;
  cv::Point3f p;
  while (cord >> p.x >> p.y >> p.z) {
    coord.push_back(p);
  }

  std::ifstream point(points.c_str());
  if (!point) {
    std::cout << points << " file open failed!" << std::endl;
    return;
  }

  std::vector<cv::Point3f> pointsv;
  while (point >> p.x >> p.y >> p.z) {
    pointsv.push_back(p);
  }

  std::ofstream newpoint(newPoints);
  if (!newpoint) {
    std::cout << "new_points.txt open failed" << std::endl;
    return;
  }
  for (size_t i = 0; i != pointsv.size(); i++) {
    cv::Point3f p = coordinateChange(pointsv[i], coord);
    newpoint << p.x << '\t' << p.y << '\t' << p.z << std::endl;
  }
  newpoint.close();
}
Exemplo n.º 4
0
void MythUIText::SetCanvasPosition(int x, int y)
{
    QPoint newpoint(x, y);

    if (newpoint == m_Canvas.topLeft())
        return;

    m_Canvas.moveTopLeft(newpoint);
    SetRedraw();
}
Exemplo n.º 5
0
void MythUIText::MoveDrawRect(const int x, const int y)
{
    int newx = m_drawRect.x() + x;
    int newy = m_drawRect.y() + y;

    QPoint newpoint(newx,newy);
    if (newpoint == m_drawRect.topLeft())
        return;

    m_drawRect.moveTopLeft(QPoint(newx,newy));
    SetRedraw();
}
Exemplo n.º 6
0
void MythUIText::SetDrawRectPosition(const int x, const int y)
{
    int startx = m_Area.x() + x;
    int starty = m_Area.y() + y;

    QPoint newpoint(startx,starty);
    if (newpoint == m_drawRect.topLeft())
        return;

    m_drawRect.moveTopLeft(QPoint(startx,starty));
    SetRedraw();
}
Exemplo n.º 7
0
double integratePlainMonteCarlo (Integrand& f,  const unsigned dimension, const ulong maxSamples) {

    //init random number genrator
    std::default_random_engine generator;
    std::uniform_real_distribution<double> distribution(0.0, 1.0);

    double sum = 0;
    double weight = double(1) / maxSamples ;
    std::vector<double> newpoint(dimension);
    for ( ulong i=0; i < maxSamples ; ++i) {
        for (uint j=0; j<dimension; ++j) {
            newpoint[j] = distribution(generator);
        }
        sum += weight * f(newpoint);
    }

    return sum;
}
Exemplo n.º 8
0
int main(int argc, char const *argv[])
{	
	point* pares[100];
	int size = 100 
	srand(time(NULL));
	int i;
	for (i = 0; i < size; i++) {
		int x = rand();
		int y = rand();
		pares[i] = newpoint(x, y);
	}
	otro_y = copia(pares, size)
	qsort(pares,size,sizeof(point), compareX);
	qsort(pares,size,sizeof(point), compareY);
	pairs* min_x = closest(pares, size);
	pairs* min_y = closest(pares, size);
	pairs* min_abs =  min_x->dist < min_y->dist ? min_x : min_y;
	printpairs (min_abs);
	return 0;
}
Exemplo n.º 9
0
static int point__recv (lua_State *L) {
  const char *s = luaL_checkstring(L, 1);
  newpoint(L, (double) lpq_getfloat8(&s[0]), /* x */
      (double) lpq_getfloat8(&s[8])); /* y */
  return 1;
}
Exemplo n.º 10
0
static int point_call (lua_State *L) {
  newpoint(L, luaL_optnumber(L, 1, 0), luaL_optnumber(L, 2, 0));
  return 1;
}
Exemplo n.º 11
0
void ATO::Integrator<T>::getSurfaceTris(
            std::vector< Vector3D >& points,
            std::vector< Tri >& tris,
            const Intrepid::FieldContainer<T>& topoVals, 
            const Intrepid::FieldContainer<T>& coordCon, 
            T zeroVal, C compare)
//******************************************************************************//
{

    const CellTopologyData& cellData = *(cellTopology->getBaseCellTopologyData());

    // find intersections
    std::vector<Intersection> intersections;
    uint nEdges = cellData.edge_count;
    int nDims  = coordCon.dimension(1);
    for(int edge=0; edge<nEdges; edge++){
      uint i = cellData.edge[edge].node[0], j = cellData.edge[edge].node[1];
      if((topoVals(i)-zeroVal)*(topoVals(j)-zeroVal) < 0.0){
        Vector3D newpoint(Intrepid::ZEROS);
        T factor = fabs(topoVals(i)-zeroVal)/(fabs(topoVals(i)-zeroVal)+fabs(topoVals(j)-zeroVal));
        for(uint k=0; k<nDims; k++) newpoint(k) = (1.0-factor)*coordCon(i,k) + factor*coordCon(j,k);
        std::pair<int,int> newIntx(i,j);
        if(topoVals(i) > zeroVal){int tmp=newIntx.first; newIntx.first=newIntx.second; newIntx.second=tmp;}
        intersections.push_back(Intersection(newpoint,newIntx));
      }
    }

    std::vector<std::pair<Vector3D,Vector3D> > segment;

    // if there are four intersections, then there are two interfaces:
    if( intersections.size() == 4 ){
      segment.resize(2);
      int numNodes = basis->getCardinality();
      RealType cntrVal = 0.0;
      for(int node=0; node<numNodes; node++)
        cntrVal += topoVals(node);
      cntrVal /= numNodes;
      // if topoVal at centroid is negative, interssected segments share a positive valued node
      if( cntrVal < zeroVal ){
        int second = intersections[0].connect.second;
        if( second == intersections[1].connect.second ){
          segment[0].first = intersections[0].point; segment[0].second = intersections[1].point;
          segment[1].first = intersections[2].point; segment[1].second = intersections[3].point;
        } else 
        if( second == intersections[2].connect.second ){
          segment[0].first = intersections[0].point; segment[0].second = intersections[2].point;
          segment[1].first = intersections[1].point; segment[1].second = intersections[3].point;
        } else 
        if( second == intersections[3].connect.second ){
          segment[0].first = intersections[0].point; segment[0].second = intersections[3].point;
          segment[1].first = intersections[1].point; segment[1].second = intersections[2].point;
        }
      } else {
        int first = intersections[0].connect.first;
        if( first == intersections[1].connect.first ){
          segment[0].first = intersections[0].point; segment[0].second = intersections[1].point;
          segment[1].first = intersections[2].point; segment[1].second = intersections[3].point;
        } else 
        if( first == intersections[2].connect.first ){
          segment[0].first = intersections[0].point; segment[0].second = intersections[2].point;
          segment[1].first = intersections[1].point; segment[1].second = intersections[3].point;
        } else 
        if( first == intersections[3].connect.first ){
          segment[0].first = intersections[0].point; segment[0].second = intersections[3].point;
          segment[1].first = intersections[1].point; segment[1].second = intersections[2].point;
        }
      }
    } else
    if( intersections.size() == 2){
      segment.resize(1);
      segment[0].first = intersections[0].point; segment[0].second = intersections[1].point;
    }

    std::vector< Teuchos::RCP<MiniPoly> > polys;
    int npoints = coordCon.dimension(0), ndims = coordCon.dimension(1);
    Teuchos::RCP<MiniPoly> poly = Teuchos::rcp(new MiniPoly(npoints));
    std::vector<Vector3D>& pnts = poly->points;
    std::vector<int>& map = poly->mapToBase;
    for(int pt=0; pt<npoints; pt++){
      for(int dim=0; dim<ndims; dim++) pnts[pt](dim) = coordCon(pt,dim);
      map[pt] = pt;
    }
    polys.push_back(poly);

    int nseg = segment.size();
    for(int seg=0; seg<nseg; seg++)
      partitionBySegment(polys, segment[seg]);

    typename std::vector< Teuchos::RCP<MiniPoly> >::iterator itpoly;
    for(itpoly=polys.begin(); itpoly!=polys.end(); itpoly++)
      if( included(*itpoly,topoVals,zeroVal,compare) ) trisFromPoly(points, tris, *itpoly);
}
Exemplo n.º 12
0
point operatorSub(point a, point b){
  return newpoint(a.x-b.x, a.y-b.y);
}