本文整理汇总了C++中Neighbors::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ Neighbors::push_back方法的具体用法?C++ Neighbors::push_back怎么用?C++ Neighbors::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Neighbors
的用法示例。
在下文中一共展示了Neighbors::push_back方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNeighbors
Neighbors Board::getNeighbors(int pos)
{
// row is current position, elements are its neighbors, at most 4, -1 means null
static const int rawData[][4] =
{
{1,3,8,-1},
{0,2,4,-1},
{1,5,13,-1},
{0,4,6,9},
{1,3,5,-1},
{2,4,7,12},
{3,7,10,-1},
{5,6,11,-1},
{0,9,20,-1},
{3,8,10,17},
{6,9,14,-1},
{7,12,16,-1},
{5,11,13,19},
{2,12,22,-1},
{10,15,17,-1},
{14,16,18,-1},
{11,15,19,-1},
{9,14,18,20},
{15,17,19,21},
{12,16,18,22},
{8,17,21,-1},
{18,20,22,-1},
{13,19,21,-1}
};
Neighbors result;
for(int j=0; j<4; ++j)
if(rawData[pos][j] > -1)
result.push_back(rawData[pos][j]);
return result;
}
示例2: find_neighbors_bruteforce_impl
Neighbors find_neighbors_bruteforce_impl(const RandomAccessIterator& begin, const RandomAccessIterator& end,
Callback callback, IndexType k)
{
timed_context context("Distance sorting based neighbors search");
typedef std::pair<RandomAccessIterator, ScalarType> DistanceRecord;
typedef std::vector<DistanceRecord> Distances;
Neighbors neighbors;
neighbors.reserve(end-begin);
for (RandomAccessIterator iter=begin; iter!=end; ++iter)
{
Distances distances;
for (RandomAccessIterator around_iter=begin; around_iter!=end; ++around_iter)
distances.push_back(std::make_pair(around_iter, callback.distance(iter,around_iter)));
std::nth_element(distances.begin(),distances.begin()+k+1,distances.end(),
distances_comparator<DistanceRecord>());
LocalNeighbors local_neighbors;
local_neighbors.reserve(k);
for (typename Distances::const_iterator neighbors_iter=distances.begin();
neighbors_iter!=distances.begin()+k+1; ++neighbors_iter)
{
if (neighbors_iter->first != iter)
local_neighbors.push_back(neighbors_iter->first - begin);
}
neighbors.push_back(local_neighbors);
}
return neighbors;
}
示例3:
void Surface3D::addLayer(const AllNeighbors& totalNeighbors, int sX, int sY, int sZ) {
Surface2D surfaceXY;
surfaceXY.reserve(sY);
for (int y = 0; y < sY; ++y) {
Surface1D surfaceX;
surfaceX.reserve(sX);
for (int x = 0; x < sX; ++x) {
Atoms atoms;
atoms.reserve(totalNeighbors.size());
for (auto const& neighbors : totalNeighbors) {
Neighbors neighbs;
// First neighbors count
char numberNeighbs = 0;
for (int nb = 0; nb < 4; ++nb) {
if (x + neighbors[nb].x >= 0
&& y + neighbors[nb].y >= 0
&& x + neighbors[nb].x < sX
&& y + neighbors[nb].y < sY) {
++numberNeighbs;
AtomType neighb = {x + neighbors[nb].x,
y + neighbors[nb].y, sZ + neighbors[nb].z,
neighbors[nb].type, false};
neighbs.push_back(neighb);
}
}
AtomInfo atom;
atom.neighbors = neighbs;
atom.firstNeighborsCount = numberNeighbs;
atom.deleted = numberNeighbs == 0;
atoms.push_back(atom);
}
surfaceX.push_back(Cell(atoms));
}
surfaceXY.push_back(surfaceX);
}
push_back(surfaceXY);
}
示例4: find_neighbors_vptree_impl
Neighbors find_neighbors_vptree_impl(const RandomAccessIterator& begin, const RandomAccessIterator& end,
Callback callback, IndexType k)
{
timed_context context("VP-Tree based neighbors search");
Neighbors neighbors;
neighbors.reserve(end-begin);
VantagePointTree<RandomAccessIterator,Callback> tree(begin,end,callback);
for (RandomAccessIterator i=begin; i!=end; ++i)
{
LocalNeighbors local_neighbors = tree.search(i,k+1);
std::remove(local_neighbors.begin(),local_neighbors.end(),i-begin);
neighbors.push_back(local_neighbors);
}
return neighbors;
}
示例5: main
int main(int argc, char *argv[]) {
std::string input;
int width;
int height;
int row = 0;
int attempt = 0;
while(std::getline(std::cin, input)) {
char c = input.at(0);
if(c == '.' || c == 'X' || c == '*') {
++row;
neighbors.clear();
for(int pos = 0; pos < (int) input.length(); ++pos) {
VertexWeight vertexWeight;
vertexWeight.first = pos;
char temp = input.at(pos);
if(temp == '.') {
vertexWeight.second = 1;
} else if(temp == '*') {
vertexWeight.second = 2;
} else {
vertexWeight.second = 3;
}
neighbors.push_back(vertexWeight);
}
adjList.push_back(neighbors);
if(height == row) {
visited.clear();
for(int index = 0; index < height; ++index) {
visited.push_back(std::vector<bool>(width, false));
}
for(int i = 0; i < height; ++i) {
for(int j = 0; j < width; ++j) {
if((visited[i])[j] == false && ((adjList[i])[j]).second != 1) {
area = 0;
floodFill(i, j, ((adjList[i])[j]).second);
if(area)
areas.push_back(area);
}
}
}
std::cout << "Throw " << ++attempt << std::endl;
std::sort(areas.begin(), areas.end());
int numAreas = (int)areas.size() - 1;
for(std::vector<int>::iterator it = areas.begin(); it != areas.end(); ++it) {
std::cout << *it;
if(numAreas--) {
std::cout << " ";
}
}
std::cout << std::endl;
std::cout << std::endl;
}
} else {
row = 0;
std::stringstream sbuf;
sbuf << input;
sbuf >> width >> height;
adjList.clear();
areas.clear();
if(width == 0 && height == 0) {
break;
}
}
}
return 0;
}
示例6: newDocument
void newDocument() {
mask.clear();
etchingAction->setEnabled(true);
maskAction->setEnabled(true);
saveAct->setEnabled(true);
QTime t;
z_min = 0;
int const xMax = SIZE_X;
int const yMax = SIZE_Y;
int const zMax = SIZE_Z;
z_center = z_min + (zMax - 2 - z_min) / 2;
cell = Cell(h, k, l);
Xsize = cell.getXSize();
Ysize = cell.getYSize();
Zsize = cell.getZSize();
Vx = cell.getVx();
Vy = cell.getVy();
Vz = cell.getVz();
cell.optimize();
auto const numberOfAtomInCell =
static_cast<unsigned int>(cell.size());
neighbors = cell.findNeighbors(Xsize, Ysize, Zsize);
surfaceXYZ.reset(new Surface3D(cell));
surfaceXYZ->clear();
surfaceXYZ->reserve(SIZE_Z);
for (int z = 0; z < SIZE_Z; ++z) {
Surface2D surfaceXY;
surfaceXY.reserve(SIZE_Y);
for (int y = 0; y < SIZE_Y; ++y) {
Surface1D surfaceX;
surfaceX.reserve(SIZE_X);
for (int x = 0; x < SIZE_X; ++x) {
Cell cell;
for (unsigned char a = 0; a < numberOfAtomInCell; ++a) {
Neighbors neighbs;
char numberNeighbs = 0; // number of the first neighbors
for (int nb = 0; nb < 4; ++nb) {
auto& neighborsANb = neighbors[a][nb];
if (x + neighborsANb.x >= 0
&& y + neighborsANb.y >= 0
&& z + neighborsANb.z >= 0
&& x + neighborsANb.x < xMax
&& y + neighborsANb.y < yMax
&& z + neighborsANb.z < zMax + 1) {
++numberNeighbs;
AtomType neighb = {x + neighborsANb.x, y + neighborsANb.y,
z + neighborsANb.z, neighborsANb.type,
false};
neighbs.push_back(neighb);
}
}
AtomInfo atom;
atom.neighbors = neighbs;
atom.firstNeighborsCount = numberNeighbs;
atom.deleted = numberNeighbs == 0;
// TODO: atom.type =
cell.addAtom(atom);
}
surfaceX.push_back(cell);
}
surfaceXY.push_back(surfaceX);
}
surfaceXYZ->push_back(surfaceXY);
}
surfaceXYZ->rebuildSurfaceAtoms();
drawResult();
}
示例7: run_cluster
void ClustererDBSCAN::run_cluster(Points samples)
{
ClusterId cid = 1;
// foreach pid
for (PointId pid = 0; pid < samples.size(); pid++)
{
// not already visited
if (!_visited[pid]){
_visited[pid] = true;
// get the neighbors
Neighbors ne = findNeighbors(pid, _eps);
// not enough support -> mark as noise
if (ne.size() < _minPts)
{
_noise[pid] = true;
}
else
{
//else it's a core point
_core[pid] = true;
// Add p to current cluster
CCluster c; // a new cluster
c.push_back(pid); // assign pid to cluster
_pointId_to_clusterId[pid]=cid;
// go to neighbors
for (unsigned int i = 0; i < ne.size(); i++)
{
PointId nPid = ne[i];
// not already visited
if (!_visited[nPid])
{
_visited[nPid] = true;
// go to neighbors
Neighbors ne1 = findNeighbors(nPid, _eps);
// enough support
if (ne1.size() >= _minPts)
{
_core[nPid] = true;
// join
BOOST_FOREACH(Neighbors::value_type n1, ne1)
{
// join neighbord
ne.push_back(n1);
}
}
}
// not already assigned to a cluster
if (!_pointId_to_clusterId[nPid])
{
// add it to the current cluster
c.push_back(nPid);
_pointId_to_clusterId[nPid]=cid;
}
}