Example #1
0
void KantShelling::SetAdjFaces()  
/* set Brin2Face, Face2Brin, IsOuterV, IsOuterE.
       b = Face2Brin[num]
       b and acir[b] defines an angle
       Moving along a face: cir[-b] or -acir[b]
    */
  {tbrin b, b0;
  // Mark the vertices incident to the last face
  Prop<short> ecolor(G.Set(tedge()),PROP_COLOR);
  Prop<int> ewidth(G.Set(tedge()),PROP_WIDTH);
  b = b0 = FirstBrin();
  do
      {BelongToLastFace[G.vin[b]()] = 1;
      if(debug()) {ecolor[b.GetEdge()] = Green2;ewidth[b.GetEdge()] = 3;}
      }while((b = -G.cir[b]) != b0);

  IntList Brins;  // Brins: list of all brins 
  for(int i = -G.ne();i <= G.ne();i++)
      if(i)Brins.push(i);
  // the edge {v_1,v_2}. IsOuterE is set to 0.
  Brin2Face[FirstBrin()]=1;			  
  IsOuterV[v_1] = 1;
  Brins.del(FirstBrin());

  // the outer face is indexed 1
  b = G.cir[-FirstBrin];
  do 
      {Brins.del(b());
      Brin2Face[b()] = 1;
      IsOuterE[b.GetEdge()] = 1;
      IsOuterV[G.vin[b]()] = 1;
      }while ((b = G.cir[-b])  != FirstBrin);
  Face2Brin[1]=FirstBrin();

  // indexing other faces.
  int FaceIndex=2;
  while (!Brins.empty()) 
      {b0 = b =Brins.first();
       if(debug())cout << "face:" << FaceIndex << endl;
      do 
          {Brins.del(b());
          Brin2Face[b]=FaceIndex;
           if(debug())cout << G.vin[b]() << " " <<endl;
          } 
      while((b = G.cir[-b]) != b0);

      Face2Brin[FaceIndex]=b();
      FaceIndex++;
      }
  }
Example #2
0
TEST(FastListTest, test)
{
    IntList flist;
    flist.new_node(1);
    IntList::RemovableElementHandler two = flist.new_node(2);
    flist.new_node(3);

    std::list<int> rlist;
    rlist.push_back(1);
    rlist.push_back(2);
    rlist.push_back(3);
    ASSERT_TRUE(compare(flist, rlist));

    // remove 'two'
    two.destroy();
    flist.shrink();
    rlist.remove(2);
    ASSERT_TRUE(compare(flist, rlist));

    two = flist.new_node(2);
    rlist.push_back(2);
    ASSERT_TRUE(compare(flist, rlist));

    for (int i = 10; i < 20; ++i)
    {
        flist.new_node(i);
        rlist.push_back(i);
    }
    ASSERT_TRUE(compare(flist, rlist));

    flist.clear();
    flist.shrink();
    rlist.clear();
    ASSERT_TRUE(flist.empty());
    ASSERT_TRUE(compare(flist, rlist));

    for (int i = 10; i < 30; ++i)
    {
        flist.new_node(i);
        rlist.push_back(i);
    }
    ASSERT_TRUE(compare(flist, rlist));
}
Example #3
0
std::tuple<Tensor,Tensor> max_pool1d(
    const Tensor & self, IntList kernel_size, IntList stride, IntList padding,
    IntList dilation, bool ceil_mode) {

  if (stride.empty()) {
    stride = kernel_size;
  }
  checkDim("max_pool1d", TensorArg(self, "self", 1), 3);
  check1d("kernel_size", kernel_size);
  check1d("stride", stride);
  check1d("padding", padding);
  check1d("dilation", dilation);

  Tensor output, indices;
  std::tie(output, indices) = at::max_pool2d(
      self.unsqueeze(2),
      {1, kernel_size[0]},
      {1, stride[0]},
      {0, padding[0]},
      {1, dilation[0]},
      ceil_mode);

  return std::make_tuple(output.squeeze(2), indices.squeeze(2));
}
Example #4
0
/*----------------------------------------------------------------------- */
SEXP
watershed (SEXP x, SEXP _tolerance, SEXP _ext) {
    SEXP res;
    int im, i, j, nx, ny, nz, ext, nprotect = 0;
    double tolerance;

    nx = INTEGER ( GET_DIM(x) )[0];
    ny = INTEGER ( GET_DIM(x) )[1];
    nz = getNumberOfFrames(x,0);
    tolerance = REAL( _tolerance )[0];
    ext = INTEGER( _ext )[0];

    PROTECT ( res = Rf_duplicate(x) );
    nprotect++;
  
    int * index = new int[ nx * ny ];

    for ( im = 0; im < nz; im++ ) {

        double * src = &( REAL(x)[ im * nx * ny ] );
        double * tgt = &( REAL(res)[ im * nx * ny ] );

        /* generate pixel index and negate the image -- filling wells */
        for ( i = 0; i < nx * ny; i++ ) {
	  tgt[ i ] = -src[ i ];
	  index[ i ] = i;
        }
        /* from R includes R_ext/Utils.h */
        /* will resort tgt as well */
        rsort_with_index( tgt, index, nx * ny );
        /* reassign tgt as it was reset above but keep new index */
        for ( i = 0; i < nx * ny; i++ )
            tgt[ i ] = -src[ i ];

        SeedList seeds;  /* indexes of all seed starting points, i.e. lowest values */

        IntList  equals; /* queue of all pixels on the same gray level */
        IntList  nb;     /* seed values of assigned neighbours */
        int ind, indxy, nbseed, x, y, topseed = 0;
        IntList::iterator it;
        TheSeed newseed;
        PointXY pt;
        bool isin;
        /* loop through the sorted index */
        for ( i = 0; i < nx * ny && src[ index[i] ] > BG; ) {
            /* pool a queue of equally lowest values */
            ind = index[ i ];
            equals.push_back( ind );
            for ( i = i + 1; i < nx * ny; ) {
                if ( src[ index[i] ] != src[ ind ] ) break;
                equals.push_back( index[i] );
                i++;
            }
            while ( !equals.empty() ) {
                /* first check through all the pixels if we can assign them to
                 * existing objects, count checked and reset counter on each assigned
                 * -- exit when counter equals queue length */
                for ( j = 0; j < (int) equals.size(); ) {
		  if ((j%1000)==0) R_CheckUserInterrupt();
                    ind = equals.front();
                    equals.pop_front();
                    /* check neighbours:
                     * - if exists one, assign
                     * - if two or more check what should be combined and assign to the steepest
                     * - if none, push back */
                    /* reset j to 0 every time we assign another pixel to restart the loop */
                    nb.clear();
                    pt = pointFromIndex( ind, nx );
                    /* determine which neighbour we have, push them to nb */
                    for ( x = pt.x - ext; x <= pt.x + ext; x++ )
                        for ( y = pt.y - ext; y <= pt.y + ext; y++ ) {
                            if ( x < 0 || y < 0 || x >= nx || y >= ny || (x == pt.x && y == pt.y) ) continue;
                            indxy = x + y * nx;
                            nbseed = (int) tgt[ indxy ];
                            if ( nbseed < 1 ) continue;
                            isin = false;
                            for ( it = nb.begin(); it != nb.end() && !isin; it++ )
                                if ( nbseed == *it ) isin = true;
                            if ( !isin ) nb.push_back( nbseed );
                        }
                    if ( nb.size() == 0 ) {
                        /* push the pixel back and continue with the next one */
                        equals.push_back( ind );
                        j++;
                        continue;
                    }
                    tgt[ ind ] = check_multiple(tgt, src, ind, nb, seeds, tolerance, nx, ny );
                    /* we assigned the pixel, reset j to restart neighbours detection */
                    j = 0;
                }
                /* now we have assigned all that we could */
                if ( !equals.empty() ) {
                    /* create a new seed for one pixel only and go back to assigning neighbours */
                    topseed++;
                    newseed.index = equals.front();
                    newseed.seed = topseed;
                    equals.pop_front();
                    tgt[ newseed.index ] = topseed;
                    seeds.push_back( newseed );
                }
            } // assigning equals
        } // sorted index

        /* now we need to reassign indexes while some seeds could be removed */
        double * finseed = new double[ topseed ];
        for ( i = 0; i < topseed; i++ )
            finseed[ i ] = 0;
        i = 0;
        while ( !seeds.empty() ) {
            newseed = seeds.front();
            seeds.pop_front();
            finseed[ newseed.seed - 1 ] = i + 1;
            i++;
        }
        for ( i = 0; i < nx * ny; i++ ) {
            j = (int) tgt[ i ];
            if ( 0 < j && j <= topseed )
                tgt[ i ] = finseed[ j - 1 ];
        }
        delete[] finseed;

    } // loop through images

    delete[] index;

    UNPROTECT (nprotect);
    return res;
}
Example #5
0
	TestList()
	{
		typedef List<char, DebugAllocator<int> > IntList;

		IntList a;
		a.push_back('1');
		a.push_back('2');
		a.push_back('3');
		LIST_ASSERT(*a.begin() == '1');
		LIST_ASSERT(*++a.begin() == '2');
		LIST_ASSERT(*++++a.begin() == '3');
		LIST_ASSERT(++++++a.begin() == a.end());

		IntList b;
		b.push_back('a');
		b.push_back('b');
		b.push_back('c');
		LIST_ASSERT(*b.begin() == 'a');
		LIST_ASSERT(*++b.begin() == 'b');
		LIST_ASSERT(*++++b.begin() == 'c');
		LIST_ASSERT(++++++b.begin() == b.end());

		// swap full lists
		a.swap(b);
		LIST_ASSERT(*a.begin() == 'a');
		LIST_ASSERT(*++a.begin() == 'b');
		LIST_ASSERT(*++++a.begin() == 'c');
		LIST_ASSERT(++++++a.begin() == a.end());
		LIST_ASSERT(*b.begin() == '1');
		LIST_ASSERT(*++b.begin() == '2');
		LIST_ASSERT(*++++b.begin() == '3');
		LIST_ASSERT(++++++b.begin() == b.end());

		// swap to/from empty list
		IntList c;
		c.swap(b);
		LIST_ASSERT(b.empty());
		LIST_ASSERT(*c.begin() == '1');
		LIST_ASSERT(*++c.begin() == '2');
		LIST_ASSERT(*++++c.begin() == '3');
		LIST_ASSERT(++++++c.begin() == c.end());

		c.swap(b);
		LIST_ASSERT(c.empty());
		LIST_ASSERT(*b.begin() == '1');
		LIST_ASSERT(*++b.begin() == '2');
		LIST_ASSERT(*++++b.begin() == '3');
		LIST_ASSERT(++++++b.begin() == b.end());

		IntList d;
		c.swap(d);
		LIST_ASSERT(c.empty());
		LIST_ASSERT(d.empty());

		c.splice(c.end(), d);
		LIST_ASSERT(c.empty());
		LIST_ASSERT(d.empty());

		// splice full with empty
		b.splice(b.end(), c);
		LIST_ASSERT(c.empty());
		LIST_ASSERT(*b.begin() == '1');
		LIST_ASSERT(*++b.begin() == '2');
		LIST_ASSERT(*++++b.begin() == '3');
		LIST_ASSERT(++++++b.begin() == b.end());

		// splice empty with full
		c.splice(c.end(), b);
		LIST_ASSERT(b.empty());
		LIST_ASSERT(*c.begin() == '1');
		LIST_ASSERT(*++c.begin() == '2');
		LIST_ASSERT(*++++c.begin() == '3');
		LIST_ASSERT(++++++c.begin() == c.end());

		// splice full with full
		c.splice(c.end(), a);
		LIST_ASSERT(a.empty());
		LIST_ASSERT(*c.begin() == '1');
		LIST_ASSERT(*++c.begin() == '2');
		LIST_ASSERT(*++++c.begin() == '3');
		LIST_ASSERT(*++++++c.begin() == 'a');
		LIST_ASSERT(*++++++++c.begin() == 'b');
		LIST_ASSERT(*++++++++++c.begin() == 'c');
		LIST_ASSERT(++++++++++++c.begin() == c.end());


		c.pop_back();
		LIST_ASSERT(!c.empty());
		c.pop_back();
		LIST_ASSERT(!c.empty());
		c.pop_back();
		LIST_ASSERT(!c.empty());
		c.pop_back();
		LIST_ASSERT(!c.empty());
		c.pop_back();
		LIST_ASSERT(!c.empty());
		c.pop_back();
		LIST_ASSERT(c.empty());
	}