Ejemplo n.º 1
0
 void set(BaseLink ptr) {
     if (is_set()) {
         neighbour()->erase_simple(this);
     }
     this->set_simple(ptr);
     neighbour()->set_simple(this);
 }
Ejemplo n.º 2
0
int RotateHelper::define_position(void)
{

	/* Conclude all facts about current position */
	if(neighbour(z,0,500))
		vertical=1;
	else
		vertical=0;

	if(z>=0)
		face_up=1;
	else
		face_up=0;

	if(neighbour(x,-1000,300))
		left=1;
	else
		left=0;

	if(neighbour(x,1000,300))
		right=1;
	else
		right=0;

	if(neighbour(y,1000,300))
		down=1;
	else
		down=0;

	if(neighbour(y,-1000,300))
		up=1;
	else
		up=0;

	if(down) current_pos=DOWN;
	else if(up) current_pos=UP;
	else if(left) current_pos=LEFT;
	else if(right) current_pos=RIGHT;

	if(debug)
	{
		qDebug("v(x,y,z)=(% 5d,% 5d,% 5d) == ",x,y,z);

		qDebug(" face %s", face_up?"up":"down");
		qDebug(" %s-ish", vertical?"vertical":"horizontal");
		if(left) qDebug(" left");
		if(right) qDebug(" right");
		if(up) qDebug(" up");
		if(down) qDebug(" down");

		qDebug("\n");
	}

	return current_pos;
}
Ejemplo n.º 3
0
void		solve_cell(t_list *list, t_maze *data, t_generating *var)
{
  int		nb;

  nb = (data->type == PARFAIT) ? (1) : (0);
  if (data->type == IMPARFAIT)
    while (nb == 0)
      nb = my_rand() % 3;
  if (data->maze[var->x][var->y] == UNVISITED)
    {
      if (neighbour(data, var->x, var->y) > nb)
	{
	  data->maze[var->x][var->y] = WALL;
	  var->x = list->last->x;
	  var->y = list->last->y;
	  popback(list);
	  while (list->last != NULL && neighbors_around(data, var->x, var->y) == KO)
	    {
	      var->x = list->last->x;
	      var->y = list->last->y;
	      popback(list);
	    }
	}
      else
	data->maze[var->x][var->y] = VISITED;
    }
}
Ejemplo n.º 4
0
void CF::intNBItem()
{
#pragma omp parallel for
	for (auto i = nbi.begin(); i != nbi.end(); i++)
	{
		i->second.neighbors = new ID_TYPE[NBI_LEN];
		list<Pair> neighbour(NBI_LEN);
		double pearsonValue = 0;
		for (auto j = nbi.begin(); j != nbi.end(); j++)
		{
			pearsonValue = abs(getItemPearson(i->first, j->first));
			if (pearsonValue <= neighbour.back().value)
			{//最后一个直接跳过,减少循环次数
				continue;
			}
			for (auto n = neighbour.begin(); n != neighbour.end(); ++n)
			{
				if (n->value <= pearsonValue)
				{//插入较大值,删除行尾
					Pair p(j->first, pearsonValue);
					neighbour.insert(n, p);
					neighbour.pop_back();
					break;
				}
			}
		}
		int k = 0;
		//取出前NBU_LEN,结果归0
		for (auto n = neighbour.begin(); n != neighbour.end(); ++n)
		{
			i->second.neighbors[k++] = n->id;
		}
		neighbour.clear();
	}
}
Ejemplo n.º 5
0
static int neighbour_right (unsigned short row,
                            unsigned short col,
                            unsigned char curr_dir,
                            unsigned short *nb_row,
                            unsigned short *nb_col)
{
   neighbour (row, col, (DIRECTION_RIGHT(curr_dir)), nb_row, nb_col);
   return 0;
}
Ejemplo n.º 6
0
    inline void LifeGamev2::evolve(const int x, const int y) {
        int n = neighbour(x, y);

        if (isAlive(x, y)) {
            if (n <= 1 || n >= 4) { die(x, y); } else { reAlive(x, y); }
        } else {
            if (n == 3) { reAlive(x, y); } else { die(x, y); }
        }
    }
Ejemplo n.º 7
0
int main(int argc, char **argv){
  
  int rank, size, *buf, **bufs, i, sum = 0, count = 0;
  MPI_Status status;
  MPI_Request request;
  
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank); 
  MPI_Comm_size(MPI_COMM_WORLD, &size);

  bufs = malloc(sizeof(int*) * size);
  buf = malloc(sizeof(int));
  buf[0] = rank;
  bufs[0] = buf;

  MPI_Issend(buf, 1, MPI_INT, neighbour(rank, size), 0, MPI_COMM_WORLD, &request);
  printf("Processor %d sent message with value %d\n", rank, buf[0]);

  while (count < size){
    count++;    
    
    buf = malloc(sizeof(int));
    bufs[count] = buf;

    MPI_Recv(buf, 1, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
    if (buf[0] == rank) {
      printf("Processor %d received self message\n", rank);
    } else {
      MPI_Issend(buf, 1, MPI_INT, neighbour(rank, size), 0, MPI_COMM_WORLD, &request);
      printf("Processor %d received and sent message with value %d\n", rank, buf[0]);
    }

    sum += buf[0];
  }

  for (i = 0; i < size; i++){
    free(bufs[i]);
  }
  free(bufs);
  
  printf("Processor %d stoped, sum = %d\n", rank, sum);
  MPI_Finalize();
  return 0;
}
Ejemplo n.º 8
0
int main(){
	// freopen("in","r",stdin);
	// freopen("out","w",stdout);

	int TT; scanf("%d",&TT);
	bool line = false;
	while(TT--){
		if(line) printf("\n");
		line = true;

		init();
		scanf("%d",&Y);
		int y,x;
		char str[100];
		fgets(str,sizeof(str),stdin); // blank after the number of years
		while(fgets(str,sizeof(str),stdin)){
			if(str[0] == '\n') break;
			sscanf(str,"%d %d",&y,&x);
			T[y][x] = true;	
			// printf("[%s] %d %d\n",str,y,x);
		}	

		for(int i=1;i<=Y;i++){
			printline();
			print();
			for(int i=1;i<=20;i++) for(int j=1;j<=20;j++){
				if(T[i][j]){
					int xx = neighbour(i,j);
					if(xx >= 2 and xx <= 3) newT[i][j] = true;
					else if(xx >= 4 or xx <= 1) newT[i][j] = false;
				}else{
					if(neighbour(i,j) == 3) newT[i][j] = true;
				}
			}

			for(int i=1;i<=20;i++) for(int j=1;j<=20;j++){
				T[i][j] = newT[i][j];
				newT[i][j] = false;
			}
		}
		printline();
	}
	return 0;
}
Ejemplo n.º 9
0
// Returns the number of side neighbours that are of type BRT_NOISE.
int BLOBNBOX::NoisyNeighbours() const {
  int count = 0;
  for (int dir = 0; dir < BND_COUNT; ++dir) {
    BlobNeighbourDir bnd = static_cast<BlobNeighbourDir>(dir);
    BLOBNBOX* blob = neighbour(bnd);
    if (blob != NULL && blob->region_type() == BRT_NOISE)
      ++count;
  }
  return count;
}
Ejemplo n.º 10
0
void flood(const cv::Mat &edges, const cv::Point &anchor,
           const unsigned short label, cv::Mat &labels,
           const uchar edge, const unsigned int threshold)
{
    assert(label > 0);
    assert(edges.type()  == CV_8UC1);
    assert(labels.type() == CV_16UC1);
    assert(edges.rows == labels.rows);
    assert(edges.cols == labels.cols);

    cv::Mat mask(edges.rows, edges.cols, CV_8UC1, cv::Scalar::all(FLOOD_MASK_DEFAULT));

    if(edges.at<uchar>(anchor.y, anchor.x) == edge)
        return;

    std::deque<cv::Point> Q;
    Q.push_back(anchor);

    const static int N_X[] = {-1, 0, 0, 1};
    const static int N_Y[] = { 0,-1, 1, 0};
    unsigned int size = 0;

    while(!Q.empty()) {
        cv::Point ca = Q.front();
        Q.pop_front();

        /// ALREADY VISITED

        if(labels.at<unsigned short>(ca.y, ca.x) != FLOOD_LABEL_DEFAULT ||
                mask.at<uchar>(ca.y, ca.x) != FLOOD_MASK_DEFAULT)
            continue;

        /// NOT ALREADY VISITED
        mask.at<uchar>(ca.y, ca.x) = FLOOD_MASK_SET;
        ++size;

        for(int n = 0 ; n < 4 ; ++n) {
            cv::Point neighbour(ca.x + N_X[n], ca.y + N_Y[n]);
            if(neighbour.x < 0 || neighbour.x >= edges.cols ||
               neighbour.y < 0 || neighbour.y >= edges.rows)
                continue;

            if(edges.at<uchar>(neighbour.y, neighbour.x) != edge) {
                Q.push_back(neighbour);
            }
        }
    }

    if(size > threshold) {
        labels.setTo(cv::Scalar::all(label), mask);
    } else {
        labels.setTo(cv::Scalar::all(FLOOD_LABEL_IMPLODE), mask);
    }
}
Ejemplo n.º 11
0
const bool addNearestSuccessor(const LevelMap& map, std::vector<MapSearchNode>& neighbours,
	int16_t x_, int16_t y_, MapSearchNode parent)
{
	MapSearchNode neighbour(map, x_, y_, parent.direction);
	neighbour.x = x_;
	neighbour.y = y_;
	if ((neighbour.IsPassable() == true) && !((parent.x == x_) && (parent.y == y_)))
	{
		neighbours.push_back(neighbour);
		return true;
	}
	return false;
}
Ejemplo n.º 12
0
unsigned int ff_unwrap_dilate(double        *ipm,
                              double        *vm,
                              double        *iwm,
                              double        *mask,
                              unsigned int  dim[3],
                              double        thres,
                              double        *opm,
                              double        *owm)
{
   int           i=0, j=0, k=0;
   int           ii = 0;
   unsigned int  nwrapped = 0;
   double        np = 0;

   for (i=0; i<dim[0]; i++)
   {
      for (j=0; j<dim[1]; j++)
      {
         for (k=0; k<dim[2]; k++)
         {
        ii=index(i,j,k,dim);
        if (mask[ii] && !iwm[ii] && vm[ii] < thres)
        {
           if (np = neighbour(i,j,k,dim,iwm,ipm,6))
           {
          owm[ii] = 1.0;
                  opm[ii] = ipm[ii];
                  while ((opm[ii] - np) > PI) {opm[ii] -= 2*PI;}
                  while ((opm[ii] - np) < -PI) {opm[ii] += 2*PI;}
                  nwrapped++;
               }
               else
           {
          owm[ii] = iwm[ii];
                  opm[ii] = ipm[ii];
               }
        }
            else
        {
           owm[ii] = iwm[ii];
               opm[ii] = ipm[ii];
            }         
         }
      }
   }

   return(nwrapped);
}
Ejemplo n.º 13
0
Space * space_ini(){
	int i;
	Space *s;
	s = (Space *) malloc (sizeof(Space));
	if(!s)
		return NULL;
	sId(s) = -1;
	for(i = 0; i < 8; i++)
		neighbour(s)[i] = -1;
	sDesc(s) = NULL;
	lDesc(s) = NULL;
	light(s) = FALSE;
	isLocked(s) = FALSE;
	map(s) = NULL;
	rows(s) = -1;
	cols(s) = -1;
	return s;

}
Ejemplo n.º 14
0
void flood(const cv::Mat &edges, const cv::Point &anchor,
           const unsigned short label,
           cv::Mat &labels, const uchar edge)
{
    assert(label > 0);
    assert(edges.type()  == CV_8UC1);
    assert(labels.type() == CV_16UC1);
    assert(edges.rows == labels.rows);
    assert(edges.cols == labels.cols);

    if(edges.at<uchar>(anchor.y, anchor.x) == edge)
        return;

    std::deque<cv::Point> Q;
    Q.push_back(anchor);

    const static int N_X[] = {-1, 0, 0, 1};
    const static int N_Y[] = { 0,-1, 1, 0};

    while(!Q.empty()) {
        cv::Point ca = Q.front();
        Q.pop_front();

        /// ALREADY VISITED
        if(labels.at<unsigned short>(ca.y, ca.x) != FLOOD_LABEL_DEFAULT)
            continue;

        /// NOT ALREADY VISITED
        labels.at<unsigned short>(ca.y, ca.x) = label;

        for(int n = 0 ; n < 4 ; ++n) {
            cv::Point neighbour(ca.x + N_X[n], ca.y + N_Y[n]);
            if(neighbour.x < 0 || neighbour.x >= edges.cols ||
                    neighbour.y < 0 || neighbour.y >= edges.rows)
                continue;
            if(edges.at<uchar>(neighbour.y, neighbour.x) != edge) {
                Q.push_back(neighbour);
            }
        }
    }
}
/**
 * Loop principal del algoritmo Simulated Annealing.
 *
 * @instance  :: Instancia del BACP
 * @iter      :: Numero maximo de iteraciones para una temperatura t_current
 * @t_current :: Temperatura inicial
 * @t_min     :: Temperatura minima (eps)
 * @alpha     :: Velocidad de decaimiento de la temperatura
 */
void run(struct bacp_instance *instance, int iter, float t_current, float t_min, float alpha)
{
  unsigned short int i;
  unsigned short int new_cost;
  unsigned short int *s_c      = instance->period;
  unsigned short int old_cost  = cost(instance);
  unsigned short int best_cost = old_cost;
  unsigned short int *s_best   = copy_solution(instance->period, instance->n_courses);

  instance->period = NULL;
  while (t_current > t_min) {
    i = 0;
    while (++i <= iter) {
      if (instance->period) free(instance->period);

      instance->period = s_c;
      instance->period = neighbour(instance);
      new_cost         = cost(instance);

      if (new_cost < old_cost || (exp(-abs(new_cost - old_cost)/t_current) > aceptar())) {
        free(s_c);
        s_c              = instance->period;
        old_cost         = new_cost;
        instance->period = NULL;
      }

      if ( best_cost > new_cost ) {
        if (s_best) free(s_best);
        s_best    = copy_solution(s_c, instance->n_courses);
        best_cost = new_cost;
      }
    }
    t_current = t_current * alpha;
  }

  if (instance->period) free(instance->period);
  if (s_c) free(s_c);

  instance->period = s_best;
}
Ejemplo n.º 16
0
void tlife::step() {
    for (int y = 0; y < h; ++y) {
        for (int x = 0; x < w; ++x) {
            int n = neighbour(x, y);

            bool g = (grid[y][x]);
            bool less = (n < 2);
            bool more = (n > 3);
            bool eq = (n == 3);

            buff[y][x] = (g || eq) && !(less || more);
        }
    }

    for (int y = 0; y < h; ++y) {
        for (int x = 0; x < w; ++x) {
            grid[y][x] = buff[y][x];
        }
    }

    ++stage;
}
Ejemplo n.º 17
0
/* Naieve Approach, O(n) */
std::pair<bool,int> find_peak(std::vector<int> lst) {
  bool peak = false;
  int index = -1;
  int size = lst.size();
  std::cout << "find_peak()\n";
  std::cout << "\t peak: " << (peak ? "true" : "false") << "\n";
  std::cout << "\t index: " << index << "\n";
  std::cout << "\t list.size(): " << size << "\n";

  while( !peak && (index < size) ) {
    index++;
    if (!boundary(index,lst.size())) {
      /* General Case */
      peak = peak || ((lst[index] >= lst[index-1]) &&
                      (lst[index] >= lst[index+1]));
    } else {
      /* Boundary Case */
      peak = peak || lst[index] >= lst[neighbour(index,lst.size())];
    }
  }
  return std::make_pair(peak,index);
}
Ejemplo n.º 18
0
 int count(unsigned char **p, int i, int j)
{
  int x,y,z,xy;
  int c;
  
  c=0;
  
  /* If not near edge then don't bother checking for going off side. */
  if ( (i>radius) && (i<SCR_WIDTH-radius) && (j>radius) && (j<SCR_HEIGHT-radius)) {
    
    for (x=-radius; x<=radius; x++) {
    z=sqrt(radius*radius-x*x);
    for (y=-z; y<=z; y++) {
      xy=sqrt(x*x+y+y)+1;
      c=c+accuracy*p[i+x][j+y]*xy;
    }
    }

  /* Otherwise do. */
  } else {
  
    for (x=-radius; x<=radius; x++) {
    z=sqrt(radius*radius-x*x);
    for (y=-z; y<=z; y++) {
      xy=sqrt(x*x+y+y)+1;
      if (neighbour(p,i+x,j+y)==1)
        c=c+accuracy*xy;
    }
    }

  }
  
  if ( c<(t*0.5) )
    return 0;
  else
    return 1;
  
}
Ejemplo n.º 19
0
//计算用户的邻近点
void CF::initNBUser()
{
	nbu = new ID_TYPE*[USER_SIZE];
#pragma omp parallel for
	for (size_t i = 0; i < USER_SIZE; i++)
	{
		nbu[i] = new ID_TYPE[NBU_LEN];
		Pair defaultp(-1, 0.0);
		list<Pair> neighbour(NBU_LEN, defaultp);
		double pearsonValue = 0;
		//统计最大的PEARSON相关度最大的前NBU_LEN个
		for (size_t j = 0; j < USER_SIZE; j++)
		{
			pearsonValue = abs(getUserPearson(i, j));
			if (pearsonValue <= neighbour.back().value)
			{//最后一个直接跳过,减少循环次数
				continue;
			}
			for (auto n = neighbour.begin(); n != neighbour.end(); ++n)
			{
				if (n->value <= pearsonValue)
				{//插入较大值,删除行尾
					Pair p(j, pearsonValue);
					neighbour.insert(n, p);
					neighbour.pop_back();
					break;
				}
			}
		}
		int k = 0;
		//取出前NBU_LEN,结果归0
		for (auto n = neighbour.begin(); n != neighbour.end(); ++n)
		{
			nbu[i][k++] = n->id;
		}
		neighbour.clear();
	}
}
// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
void Foam::twoStrokeEngine::checkMotionFluxes()
{
/*

    //checking the motion fluxes for the cutFaceZone

    Info << "Checking the motion fluxes in the cut-face zone" << endl;

    const labelList& cutFaceZoneAddressing =
        faceZones()[faceZones().findZoneID("cutFaceZone")];

    boolList calculatedMeshPhi(V().size(), false);
    scalarField sumMeshPhi(V().size(), 0.0);

    forAll(cutFaceZoneAddressing, i)
    {
        label facei = cutFaceZoneAddressing[i];

        calculatedMeshPhi[owner()[facei]] = true;
        calculatedMeshPhi[neighbour()[facei]] = true;
    }

    Info << "Checking the motion fluxes in the liner zone" << endl;

    const labelList& linerAddressing =
        faceZones()[faceZones().findZoneID(scavInCylPatchName_ + "Zone")];

    forAll(linerAddressing, i)
    {
        label facei = linerAddressing[i];

        calculatedMeshPhi[owner()[facei]] = true;
        calculatedMeshPhi[neighbour()[facei]] = true;
    }

    const polyPatch& wallPatch =
        boundaryMesh()[boundaryMesh().findPatchID("wall")];

    labelList wallLabels(wallPatch.size());

    forAll (wallLabels, i)
    {
        wallLabels[i] = wallPatch.start() + i;
    }

    forAll(wallLabels, i)
    {
        label facei = wallLabels[i];

        calculatedMeshPhi[owner()[facei]] = true;
        calculatedMeshPhi[neighbour()[facei]] = true;
    }

    forAll(owner(), facei)
    {
        sumMeshPhi[owner()[facei]] += phi()[facei];
        sumMeshPhi[neighbour()[facei]] -= phi()[facei];
    }

    forAll(boundary(), patchi)
    {
        const unallocLabelList& pFaceCells =
            boundary()[patchi].faceCells();

        const fvsPatchField<scalar>& pssf = phi().boundaryField()[patchi];

        forAll(boundary()[patchi], facei)
        {
            sumMeshPhi[pFaceCells[facei]] += pssf[facei];
        }
    }

    sumMeshPhi /= V();

    dynamicLabelList checkMeshPhi;
    label checkMeshPhiSize = 0;

    forAll(calculatedMeshPhi, i)
    {
        if(calculatedMeshPhi[i] == true)
        {
            checkMeshPhi.append(i);
            checkMeshPhiSize++;
        }
    }

    Info << "checkMeshPhiSize = " << checkMeshPhiSize << endl;

    checkMeshPhi.setSize(checkMeshPhiSize);

    scalarField dVdt(checkMeshPhiSize, 0.0);

    forAll(dVdt, i)
    {
        label celli = checkMeshPhi[i];

        dVdt[i] = (1.0 - V0()[celli]/V()[celli])/engTime().deltaT().value();
    }

    Info << "checking mesh flux in the cutFaces" << endl;

    label nOutCheck = 0;

    forAll(checkMeshPhi, i)
    {
        scalar sumCheck = dVdt[i] - sumMeshPhi[checkMeshPhi[i]];
        if(mag(sumCheck) > 1)
        {
            Info<< "LOCAL sumCheck[" << checkMeshPhi[i] <<  "] = "
                << sumCheck << endl;
            nOutCheck++;
        }
    }

    Info<< "found " << nOutCheck << " cells with inconsistent motion fluxes"
        << endl;
    Info << "end " <<  endl;

*/
    {

        scalarField dVdt = (1.0 - V0()/V())/engTime().deltaT();

        scalarField sumMeshPhi(V().size(), 0.0);

        forAll(owner(), facei)
        {
            sumMeshPhi[owner()[facei]] += phi()[facei];
            sumMeshPhi[neighbour()[facei]] -= phi()[facei];
        }

        forAll(boundary(), patchi)
        {
            const unallocLabelList& pFaceCells =
                boundary()[patchi].faceCells();

            const fvsPatchField<scalar>& pssf = phi().boundaryField()[patchi];

            forAll(boundary()[patchi], facei)
            {
                sumMeshPhi[pFaceCells[facei]] += pssf[facei];
            }
        }

        sumMeshPhi /= V();

        scalarField sumCheck = dVdt - sumMeshPhi;

        label nOutCheck = 0;

        forAll(sumCheck, celli)
        {
            if(mag(sumCheck[celli]) > 1)
            {
                Info<< "sumCheck GLOBAL[" << celli << "] = "
                    << sumCheck[celli] << endl;
                nOutCheck++;
            }
        }

        Info<< "found " << nOutCheck
            << " cells with inconsistent motion fluxes GLOBAL" << endl;

    }
Ejemplo n.º 21
0
int initializeAdjacencyLists(bool isInside, int sourceNodeId, int destNodeId)
{
	/*****************************************IC MEKAN************************************/

	// remember to insert edges both ways for an undirected graph

	// 0 = A Robotik
	informations::adjacencyListIndoor[0].push_back(neighbour(1, 5));  // Robotik-Z02 = 3
	informations::adjacencyListIndoor[0].push_back(neighbour(10, 5)); // Robotik-X4 = 2
	// 1 = B Z02
	informations::adjacencyListIndoor[1].push_back(neighbour(0, 5)); // Z02-Robotik = 3
	informations::adjacencyListIndoor[1].push_back(neighbour(2, 5)); // Z02-arkaKapý = 3
	// 2 = C arkaKapi
	informations::adjacencyListIndoor[2].push_back(neighbour(1, 5)); // arkaKapi-Z04 = 2
	informations::adjacencyListIndoor[2].push_back(neighbour(3, 5)); // arkaKapi-Z02 = 3
	// 2 = D Z04
	informations::adjacencyListIndoor[3].push_back(neighbour(1, 5)); // Z04-arkaKapi = 2
	informations::adjacencyListIndoor[3].push_back(neighbour(3, 5)); // Z04-Z05 = 4
	// 3 = E Z05
	informations::adjacencyListIndoor[4].push_back(neighbour(2, 5)); // Z05-Z04 = 4
	informations::adjacencyListIndoor[4].push_back(neighbour(4, 5)); // Z05-X1 = 1
	// 3 = F Z05-Z10 arasýndaki köþe X1
	informations::adjacencyListIndoor[5].push_back(neighbour(2, 5)); // X1-Z05 = 1
	informations::adjacencyListIndoor[5].push_back(neighbour(4, 5)); // X1-Z10 = 3
	// 4 = G Z10
	informations::adjacencyListIndoor[6].push_back(neighbour(3, 5)); // Z10-X1 = 3
	informations::adjacencyListIndoor[6].push_back(neighbour(5, 5)); // Z10-X2 = 1
	// 4 = H Z10-Mikro arasi duz köse X2
	informations::adjacencyListIndoor[7].push_back(neighbour(3, 5)); // X2-Z10 = 1
	informations::adjacencyListIndoor[7].push_back(neighbour(5, 5)); // X2-X3 = 2
	// 5 = G Z10-Mikro arasi yan kose X3
	informations::adjacencyListIndoor[8].push_back(neighbour(4, 5)); // X3-X2 = 2
	informations::adjacencyListIndoor[8].push_back(neighbour(6, 5)); // X3-MikroLab = 2
	// 5 = H MikroLab
	informations::adjacencyListIndoor[9].push_back(neighbour(4, 5));  // MikroLab-X3 = 2
	informations::adjacencyListIndoor[9].push_back(neighbour(6, 5)); // MikroLab-WcKiz = 2
	// 10 = I WcKiz
	informations::adjacencyListIndoor[10].push_back(neighbour(9, 5));  // WcKýz-MikroLab = 2
	informations::adjacencyListIndoor[10].push_back(neighbour(0, 5)); // WcKýz-DevreLab = 0

	/*****************************************DIS MEKAN************************************/
	// 0 = BilMuh OnKapi Sol Kose
	informations::adjacencyListOutdoor[0].push_back(neighbour(1, 5));
	informations::adjacencyListOutdoor[0].push_back(neighbour(7, 5));
	informations::adjacencyListOutdoor[0].push_back(neighbour(15, 20));
	// 1 = Bil Muh On kapı
	informations::adjacencyListOutdoor[1].push_back(neighbour(0, 5));
	informations::adjacencyListOutdoor[1].push_back(neighbour(2, 5));
	// 2 = Bil Muh On kapı Sag kose
	informations::adjacencyListOutdoor[2].push_back(neighbour(1, 5));
	informations::adjacencyListOutdoor[2].push_back(neighbour(8, 10));
	informations::adjacencyListOutdoor[2].push_back(neighbour(3, 5));
	// 3 = Bil muh Sag Taraf
	informations::adjacencyListOutdoor[3].push_back(neighbour(2, 5));
	informations::adjacencyListOutdoor[3].push_back(neighbour(4, 5));
	// 4 =
	informations::adjacencyListOutdoor[4].push_back(neighbour(3, 5));
	informations::adjacencyListOutdoor[4].push_back(neighbour(5, 5));
	// 5 = Bil Muh Arka Taraf
	informations::adjacencyListOutdoor[5].push_back(neighbour(4, 5));
	informations::adjacencyListOutdoor[5].push_back(neighbour(6, 5));
	// 6 =
	informations::adjacencyListOutdoor[6].push_back(neighbour(5, 5));
	informations::adjacencyListOutdoor[6].push_back(neighbour(7, 5));
	// 7 = Bil muh sol taraf
	informations::adjacencyListOutdoor[7].push_back(neighbour(0, 5));
	informations::adjacencyListOutdoor[7].push_back(neighbour(6, 5));
	// 8 = Bil muh soldaki yol
	informations::adjacencyListOutdoor[8].push_back(neighbour(2, 10));
	informations::adjacencyListOutdoor[8].push_back(neighbour(9, 10));
	// 9 =
	informations::adjacencyListOutdoor[9].push_back(neighbour(8, 10));
	informations::adjacencyListOutdoor[9].push_back(neighbour(10, 20));
	// 10 = kütüphaneye giden uzun yol
	informations::adjacencyListOutdoor[10].push_back(neighbour(9, 20));
	informations::adjacencyListOutdoor[10].push_back(neighbour(11, 20));
	// 11 = kütüphaneden önceki köşe
	informations::adjacencyListOutdoor[11].push_back(neighbour(12, 10));
	informations::adjacencyListOutdoor[11].push_back(neighbour(17, 20));
	// 12 = kütüphane
	informations::adjacencyListOutdoor[12].push_back(neighbour(11, 10));
	informations::adjacencyListOutdoor[12].push_back(neighbour(13, 10));
	// 13 = biyoloji yolu
	informations::adjacencyListOutdoor[13].push_back(neighbour(12, 10));
	informations::adjacencyListOutdoor[13].push_back(neighbour(14, 10));
	// 14 = biyoloji - kimya
	informations::adjacencyListOutdoor[14].push_back(neighbour(13, 10));
	// 15 = Bil Müh sağdaki uzun yol
	informations::adjacencyListOutdoor[15].push_back(neighbour(0, 20));
	informations::adjacencyListOutdoor[15].push_back(neighbour(16, 20));
	// 16 =
	informations::adjacencyListOutdoor[16].push_back(neighbour(15, 20));
	informations::adjacencyListOutdoor[16].push_back(neighbour(17, 10));
	informations::adjacencyListOutdoor[16].push_back(neighbour(18, 10));
	// 17 =
	informations::adjacencyListOutdoor[17].push_back(neighbour(16, 20));
	informations::adjacencyListOutdoor[17].push_back(neighbour(11, 20));
	// 18 =
	informations::adjacencyListOutdoor[18].push_back(neighbour(16, 10));
	informations::adjacencyListOutdoor[18].push_back(neighbour(19, 10));
	// 19 =
	informations::adjacencyListOutdoor[19].push_back(neighbour(18, 10));
	/**************************************************************************************/
	vector<weight_t> min_distance;
	vector<vertex_t> previous;

	// Inside
	if (isInside) {
		cout << "Su anda bulunulan node : " << sourceNodeId << endl;
		cout << "Gidilecek node : " << destNodeId << endl;

		DijkstraComputePaths(sourceNodeId, informations::adjacencyListIndoor, min_distance, previous);
		cout << "Distance from " << sourceNodeId << " to " << destNodeId << "  ->  " << min_distance[destNodeId] << endl;
		list<vertex_t> path = DijkstraGetShortestPathTo(destNodeId, previous);
		cout << "Path : ";
		copy(path.begin(), path.end(), ostream_iterator<vertex_t>(cout, " "));
		cout << endl;
		list<vertex_t>::iterator it2 = path.begin();
		it2++;
		for (list<vertex_t>::iterator it = path.begin(); it != path.end(); ++it) {
			if (it == --path.end())
				break;
			else{
				cout << informations::directionMatrixIndoor[*it][*it2] << " - ";
				it2++;
			}
		}
	}
	// Outside
	else{
		cout << "Su anda bulunulan node : " << sourceNodeId << endl;
		cout << "Gidilecek node : " << destNodeId << endl;

		DijkstraComputePaths(sourceNodeId, informations::adjacencyListOutdoor, min_distance, previous);
		cout << "Distance from " << sourceNodeId << " to " << destNodeId << "  ->  " << min_distance[destNodeId] << endl;
		list<vertex_t> path = DijkstraGetShortestPathTo(destNodeId, previous);
		cout << "Path : ";
		copy(path.begin(), path.end(), ostream_iterator<vertex_t>(cout, " "));
		cout << endl;
		list<vertex_t>::iterator it2 = path.begin();
		it2++;
		for (list<vertex_t>::iterator it = path.begin(); it != path.end(); ++it) {
			if (it == --path.end())
				break;
			else{
				cout << informations::directionMatrixOutdoor[*it][*it2] << " - ";
				it2++;
			}
		}
	}
	return 0;
}
Ejemplo n.º 22
0
	static std::vector< bool > randomHamming1Neighbour( const std::vector< bool >& incumbent ) {
		std::vector< bool > neighbour( incumbent );
		const int randomIndex = RNG::nextInt( neighbour.size() );
		neighbour[ randomIndex ] = !neighbour[ randomIndex ];
		return neighbour;
	}
Ejemplo n.º 23
0
 void erase() {
     if (is_set()) { // IS IT NEEDED ??
         neighbour()->erase_simple(this);
         this->erase_simple();
     }
 }
Ejemplo n.º 24
0
 void unload() {
     if (is_loaded()) {
         neighbour()->unload_simple(this, this->host()->id());
         this->unload_simple(this, neighbour()->host()->id());
     }
 }
Ejemplo n.º 25
0
 TO* to() {
     return neighbour()->host();
 }
Ejemplo n.º 26
0
void Algorithm::findPath(const Location& start, const Location& end,
                         PathVector& output) {
    NodeMap l_open;
    NodeMap l_closed;
    std::priority_queue<Node> l_priority;

    // Create Start Node
    Location origin;
    Node startNode(start, 0, 0, origin);

    // Add start to priority queue and open set
    l_priority.push(startNode);
    l_open[start] = startNode;

    while (!l_priority.empty()) {
        Node l_current = l_priority.top();
        l_priority.pop();

        l_open.erase(l_current.location);
        l_closed[l_current.location] = l_current;

        // Check whether this is the target node
        if (l_current.location == end) {
            Location current = l_current.location;
            while (current != start) {
                // output.push_back (index);
                output.insert(output.begin(), current);
                NodeMapIter open_iter = l_closed.find(current);
                current = open_iter->second.origin;
                if (current.x == UINT_MAX)
                    break;
            }
            return;
        }

        // Process neighbours
        Location* neighbours = new Location[m_numNeighbours];
        unsigned int validNeighbours =
            m_neighbourFunction(l_current.location, neighbours, m_customData);
        for (size_t ii = 0; ii < validNeighbours; ii++) {
            // TODO: not needed? if (neighbours[ii] < 0) continue; // Not a
            // valid neighbour
            int cost = m_costFunction(neighbours[ii], m_customData);
            // If cost is -ve, we will close the node

            unsigned int path = l_current.distance + cost;
            unsigned int priority =
                path + m_distanceFunction(neighbours[ii], end, m_customData) +
                1;
            Node neighbour(neighbours[ii], path, priority, l_current.location);

            // Is it closed?
            NodeMapIter closed_iter = l_closed.find(neighbours[ii]);
            if (closed_iter != l_closed.end()) {
                // But dow we now have a better path?
                if (cost > 0 && path < closed_iter->second.distance) {
                    l_closed.erase(closed_iter);
                } else {
                    continue; // It's closed and there's no better path
                }
            }

            NodeMapIter open_iter = l_open.find(neighbours[ii]);
            if (open_iter != l_open.end()) {
                // Remove it from open if there's a better path now
                l_open.erase(open_iter);
            } else if (cost >= 0) {
                // Neighbour not in open
                l_open[neighbours[ii]] = neighbour;
                l_priority.push(neighbour);
            }
        }
        delete[] neighbours;
    }
}
Ejemplo n.º 27
0
int main()
{
    TPZManVector<REAL,3> x0(3,0.),x1(3,1.);
    x1[2] = 0.;
    TPZManVector<int,2> nelx(2,4);
    nelx[0] = 8;
    TPZGenGrid gengrid(nelx,x0,x1);
    gengrid.SetElementType(ETriangle);
    TPZGeoMesh *gmesh = new TPZGeoMesh;
    gmesh->SetDimension(2);
    gengrid.Read(gmesh);
    {
        std::ofstream out("gmesh.vtk");
        TPZVTKGeoMesh::PrintGMeshVTK(gmesh, out, true);
    }
    TPZExtendGridDimension extend(gmesh,0.5);
    extend.SetElType(1);
    TPZGeoMesh *gmesh3d = extend.ExtendedMesh(4);
    {
        std::ofstream out("gmesh3d.vtk");
        TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true);
    }
    {
        int numel = nelx[1];
        for(int el=0; el<numel; el++)
        {
            TPZManVector<int64_t, 3> nodes(2);
            nodes[0] = 2+(nelx[0]+1)*el+el;
            nodes[1] = 2+(nelx[0]+1)*(el+1)+1+el;
            int matid = 2;
            int64_t index;
            gmesh3d->CreateGeoElement(EOned, nodes, matid, index);

        }
        {
            std::ofstream out("gmesh3dbis.vtk");
            TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true);
        }
    }
    gmesh3d->BuildConnectivity();
    gRefDBase.InitializeRefPatterns();
    std::set<int> matids;
    matids.insert(2);
    TPZRefPatternTools::RefineDirectional(gmesh3d, matids);
    {
        std::ofstream out("gmesh3dtris.vtk");
        TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true);
    }
    {
        int64_t nel = gmesh3d->NElements();
        for (int64_t el = 0; el<nel; el++) {
            TPZGeoEl *gel = gmesh3d->Element(el);
            if(gel->Father()) gel->SetMaterialId(3);
        }
        for (int64_t el = 0; el<nel; el++) {
            TPZGeoEl *gel = gmesh3d->Element(el);
            if(gel->Dimension() == 1)
            {
                for(int side=0; side < gel->NSides(); side++)
                {
                    TPZGeoElSide gelside(gel,side);
                    TPZGeoElSide neighbour(gelside.Neighbour());
                    while (neighbour != gelside) {
                        if(neighbour.Element()->Father())
                        {
                            neighbour.Element()->SetMaterialId(4);
                        }
                        neighbour = neighbour.Neighbour();
                    }
                }
            }
        }

    }
    {
        std::ofstream out("gmesh3dtris.vtk");
        TPZVTKGeoMesh::PrintGMeshVTK(gmesh3d, out, true);
    }

    return 0;
}
Ejemplo n.º 28
0
static int trace_contour_4 (
                unsigned short start_row,
                unsigned short start_col,
                unsigned char **bin_image,
                long **symb_image,
                long curr_reg_nr,
                simple_REGIONC_list *reg_curr,
                char contour_orientation,
				char center)
{
   /********************************************************************/
   /* Um die Subregion herumlaufen und die Randpunkte abspeichern.     */
   /* contour_orientation = 1 bedeutet, gegen den Uhrzeigersinn um die */ 
   /* Vordergrundregion herumlaufen, d.h. der Hintergrund liegt        */ 
   /* rechts; es muss sich um eine äußere Randkette handeln.           */
   /* contour_orientation = -1 bedeutet, mit dem Uhrzeigersinn um die  */ 
   /* Hintergrundregion herumlaufen, d.h. der Hintergrund liegt        */
   /* rechts; es muss sich um eine innere Randkette handeln.           */
   /********************************************************************/


   /********************************************************************/
   /* "direction" bedeutet die Richtung entlang der Randkette, so dass */
   /* der Hintergrund jeweils rechts liegt. Die Richtung nach außen    */ 
   /* ist also:                                                        */ 
   /*    outward_direction = direction - 1                             */
   /* (start_row, start_col) bezieht sich jeweils auf das Pixel das    */
   /* schon / noch zum Vordergrund gehört! Vorsicht beim Aufruf!       */ 
   /********************************************************************/

   unsigned short row;
   unsigned short col;
   unsigned short nb_row;
   unsigned short nb_col;
   unsigned short next_row;
   unsigned short next_col;
   long label;
   long inout;
   unsigned char curr_dir;
   unsigned char dir_try;
   unsigned char dir_right;
   unsigned char direction_start;
   char k;
   simple_PIXELC_list *first;
   simple_PIXELC_list *last;


   inout = 2 - contour_orientation; /* nur für die Markierung des Randes im symbolischen Bild  */
   row = start_row;
   col = start_col;

   last = (simple_PIXELC_list *) malloc (sizeof(simple_PIXELC_list));
   memset (last, 0x00, sizeof(simple_PIXELC_list));
   first = last;

   if (contour_orientation == 1)
   {
      direction_start = 4;
      label = curr_reg_nr * 10 + 8;
      reg_curr -> first_pix = last;
      reg_curr -> last_pix = last;
      symb_image [row][col-1] = inout;
   }
   else 
   {
      direction_start = 2;
      label = curr_reg_nr * 10 + 5;
      reg_curr -> inner_last -> first_pix = last;
      reg_curr -> inner_last -> last_pix = last;
      symb_image [row][col+1] = inout;
   }

   symb_image [row][col] = label;

   /********************************************************************/
   /* Wir drehen hier so lange zurück (im Uhrzeigersinn), bis das      */
   /* Nachbarpixel in Gegenrichtung von direction_start ein            */
   /* Vordergrundpixel ist. direction_start ist damit die Richtung,    */
   /* bei der wir am Ende wieder herauskommen müssen.                  */
   /********************************************************************/

   for (k = 0; k < 3; k ++)
   {
      dir_try = DIRECTION_RIGHT(direction_start);  
      dir_right = DIRECTION_RIGHT(dir_try);  

      neighbour (row, col, dir_right, &nb_row, &nb_col);
      
      if (bin_image [nb_row][nb_col] == 0)
      {
         symb_image [nb_row][nb_col] = inout;
         direction_start = dir_try;
      }
      else
         break;
   }

   last -> row = row;
   last -> col = col;
   
   if (k == 3)
   {
      /*****************************************************************/
      /* Es handelt sich um ein einzelnes Vordergrundpixel             */
      /*****************************************************************/
      
      if (center == 0)
	  {
         set_contour_point (last, 1, row, col);

         for (curr_dir = 2; curr_dir < 5; curr_dir ++)
	     {
            append_new_simple_PIXELC_list (&first, &last);
		    set_contour_point (last, curr_dir, row, col);
	     }
	  }

      return 0;
   }

   curr_dir = direction_start;

   if (center == 0)
   {
      set_contour_point (last, direction_start, row, col);
   }
   else
   {
      last -> row = row;
      last -> col = col;
   }

   do
   {
      if (center == 0)
	  {
         next_border_pixel_0 (row, 
                              col, 
                              &curr_dir, 
                              bin_image,
                              symb_image,
                              inout,
                              label,
							  &first,
                              &last,
                              &next_row,
                              &next_col);
	  }
	  else
	  {
         next_border_pixel_1 (row, 
                              col, 
                              &curr_dir, 
                              bin_image,
                              symb_image,
                              inout,
                              label,
							  &first,
                              &last,
                              &next_row,
                              &next_col);
	  }

      row = next_row;
      col = next_col;
   }
   while (row != start_row || col != start_col || 
          curr_dir != direction_start);

   if (contour_orientation == 1)
      reg_curr -> last_pix = last;
   else 
      reg_curr -> inner_last -> last_pix = last;

   return 0;
}
Ejemplo n.º 29
0
// ------------------------------------------------------------------------------------------------
void TempMesh::FixupFaceOrientation()
{
	const IfcVector3 vavg = Center();

	// create a list of start indices for all faces to allow random access to faces
	std::vector<size_t> faceStartIndices(vertcnt.size());
	for( size_t i = 0, a = 0; a < vertcnt.size(); i += vertcnt[a], ++a )
		faceStartIndices[a] = i;

	// list all faces on a vertex
	std::map<IfcVector3, std::vector<size_t>, CompareVector> facesByVertex;
	for( size_t a = 0; a < vertcnt.size(); ++a )
	{
		for( size_t b = 0; b < vertcnt[a]; ++b )
			facesByVertex[verts[faceStartIndices[a] + b]].push_back(a);
	}
	// determine neighbourhood for all polys
	std::vector<size_t> neighbour(verts.size(), SIZE_MAX);
	std::vector<size_t> tempIntersect(10);
	for( size_t a = 0; a < vertcnt.size(); ++a )
	{
		for( size_t b = 0; b < vertcnt[a]; ++b )
		{
			size_t ib = faceStartIndices[a] + b, nib = faceStartIndices[a] + (b + 1) % vertcnt[a];
			const std::vector<size_t>& facesOnB = facesByVertex[verts[ib]];
			const std::vector<size_t>& facesOnNB = facesByVertex[verts[nib]];
			// there should be exactly one or two faces which appear in both lists. Our face and the other side
			std::vector<size_t>::iterator sectstart = tempIntersect.begin();
			std::vector<size_t>::iterator sectend = std::set_intersection(
				facesOnB.begin(), facesOnB.end(), facesOnNB.begin(), facesOnNB.end(), sectstart);

			if( std::distance(sectstart, sectend) != 2 )
				continue;
			if( *sectstart == a )
				++sectstart;
			neighbour[ib] = *sectstart;
		}
	}

	// now we're getting started. We take the face which is the farthest away from the center. This face is most probably
	// facing outwards. So we reverse this face to point outwards in relation to the center. Then we adapt neighbouring 
	// faces to have the same winding until all faces have been tested.
	std::vector<bool> faceDone(vertcnt.size(), false);
	while( std::count(faceDone.begin(), faceDone.end(), false) != 0 )
	{
		// find the farthest of the remaining faces
		size_t farthestIndex = SIZE_MAX;
		IfcFloat farthestDistance = -1.0;
		for( size_t a = 0; a < vertcnt.size(); ++a )
		{
			if( faceDone[a] )
				continue;
			IfcVector3 faceCenter = std::accumulate(verts.begin() + faceStartIndices[a],
				verts.begin() + faceStartIndices[a] + vertcnt[a], IfcVector3(0.0)) / IfcFloat(vertcnt[a]);
			IfcFloat dst = (faceCenter - vavg).SquareLength();
			if( dst > farthestDistance ) { farthestDistance = dst; farthestIndex = a; }
		}

		// calculate its normal and reverse the poly if its facing towards the mesh center
		IfcVector3 farthestNormal = ComputePolygonNormal(verts.data() + faceStartIndices[farthestIndex], vertcnt[farthestIndex]);
		IfcVector3 farthestCenter = std::accumulate(verts.begin() + faceStartIndices[farthestIndex],
			verts.begin() + faceStartIndices[farthestIndex] + vertcnt[farthestIndex], IfcVector3(0.0))
			/ IfcFloat(vertcnt[farthestIndex]);
		// We accapt a bit of negative orientation without reversing. In case of doubt, prefer the orientation given in 
		// the file.
		if( (farthestNormal * (farthestCenter - vavg).Normalize()) < -0.4 )
		{
			size_t fsi = faceStartIndices[farthestIndex], fvc = vertcnt[farthestIndex];
			std::reverse(verts.begin() + fsi, verts.begin() + fsi + fvc);
			std::reverse(neighbour.begin() + fsi, neighbour.begin() + fsi + fvc);
			// because of the neighbour index belonging to the edge starting with the point at the same index, we need to 
			// cycle the neighbours through to match the edges again.
			// Before: points A - B - C - D with edge neighbour p - q - r - s
			// After: points D - C - B - A, reversed neighbours are s - r - q - p, but the should be
			//                r   q   p   s
			for( size_t a = 0; a < fvc - 1; ++a )
				std::swap(neighbour[fsi + a], neighbour[fsi + a + 1]);
		}
		faceDone[farthestIndex] = true;
		std::vector<size_t> todo;
		todo.push_back(farthestIndex);

		// go over its neighbour faces recursively and adapt their winding order to match the farthest face 
		while( !todo.empty() )
		{
			size_t tdf = todo.back();
			size_t vsi = faceStartIndices[tdf], vc = vertcnt[tdf];
			todo.pop_back();

			// check its neighbours
			for( size_t a = 0; a < vc; ++a )
			{
				// ignore neighbours if we already checked them
				size_t nbi = neighbour[vsi + a];
				if( nbi == SIZE_MAX || faceDone[nbi] )
					continue;

				const IfcVector3& vp = verts[vsi + a];
				size_t nbvsi = faceStartIndices[nbi], nbvc = vertcnt[nbi];
				std::vector<IfcVector3>::iterator it = std::find_if(verts.begin() + nbvsi, verts.begin() + nbvsi + nbvc, FindVector(vp));
				ai_assert(it != verts.begin() + nbvsi + nbvc);
				size_t nb_vidx = std::distance(verts.begin() + nbvsi, it);
				// two faces winded in the same direction should have a crossed edge, where one face has p0->p1 and the other
				// has p1'->p0'. If the next point on the neighbouring face is also the next on the current face, we need 
				// to reverse the neighbour
				nb_vidx = (nb_vidx + 1) % nbvc;
				size_t oursideidx = (a + 1) % vc;
				if( FuzzyVectorCompare(1e-6)(verts[vsi + oursideidx], verts[nbvsi + nb_vidx]) )
				{
					std::reverse(verts.begin() + nbvsi, verts.begin() + nbvsi + nbvc);
					std::reverse(neighbour.begin() + nbvsi, neighbour.begin() + nbvsi + nbvc);
					for( size_t a = 0; a < nbvc - 1; ++a )
						std::swap(neighbour[nbvsi + a], neighbour[nbvsi + a + 1]);
				}

				// either way we're done with the neighbour. Mark it as done and continue checking from there recursively
				faceDone[nbi] = true;
				todo.push_back(nbi);
			}
		}

		// no more faces reachable from this part of the surface, start over with a disjunct part and its farthest face
	}
}
Ejemplo n.º 30
0
static int next_border_pixel_1 (unsigned short row,
                                unsigned short col,
                                unsigned char *curr_dir,
                                unsigned char **bin_image,
                                long **symb_image,
                                long inout,
                                long label,
                                simple_PIXELC_list **first,
                                simple_PIXELC_list **last,
                                unsigned short *next_row,
                                unsigned short *next_col)
{
   unsigned short nb_row;
   unsigned short nb_col;
   unsigned short im_row;
   unsigned short im_col;
   unsigned char zw_dir;
   short k;


   for (k = 0; k < 3; k ++)
   {
      neighbour (row, col, *curr_dir, &nb_row, &nb_col);

      if (bin_image [nb_row][nb_col] == 0)
      {
         /**************************************************************/
         /* Wir drehen so lange gegen den Uhrzeigersinn weiter, bis    */
         /* das Nachbarpixel auch zum Vordergrund gehört.              */
         /**************************************************************/
         
         symb_image [nb_row][nb_col] = inout;
         (*curr_dir) = DIRECTION_LEFT(*curr_dir);
      }
      else
         break;
   }

   /*********************************************************************/
   /* Es muss geprüft werden, ob das rechte Nachbarpixel des neuen      */
   /* Pixels auch zum Hintergrund gehört. Wenn nicht gehen wir gleich   */
   /* noch eins weiter "rechts um die Ecke".                            */
   /*********************************************************************/

   zw_dir = DIRECTION_RIGHT(*curr_dir);
   neighbour (nb_row, nb_col, zw_dir, &im_row, &im_col);

   if (bin_image [im_row][im_col] != 0)
   {
      symb_image [nb_row][nb_col] = label;
      append_new_simple_PIXELC_list (first, last);
      (*last) -> row = nb_row;
	  (*last) -> col = nb_col;

      nb_row = im_row;
      nb_col = im_col;
      *curr_dir = zw_dir;
   }
   else
      symb_image [im_row][im_col] = inout;

   *next_row = nb_row;
   *next_col = nb_col;
   symb_image [nb_row][nb_col] = label;

   append_new_simple_PIXELC_list (first, last);
   (*last) -> row = nb_row;
   (*last) -> col = nb_col;

   return 0;
}