本文整理汇总了C++中Neighbors类的典型用法代码示例。如果您正苦于以下问题:C++ Neighbors类的具体用法?C++ Neighbors怎么用?C++ Neighbors使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Neighbors类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: fmin
TEMPLATE_HEADER
typename LR::Data LR::solveNormalEqn( Coordinate & c, Neighbors & nset ){
if( y.size().rows != Basis::size ){
A.resize( Basis::size, Basis::size );
y.resize( Basis::size, 1);
}
// find bounds for points
Coordinate lb = nset[0].point, rb = nset[0].point, tmp;
for( int j = 0; j < Coordinate::Dims ; j++ ){
for( int i = 1; i < nset.size(); i++ ){
lb[j] = fmin(nset[i].point[j],lb[j]);
rb[j] = fmax(nset[i].point[j],rb[j]);
}
}
// compute weights
std::vector<double> weights(nset.size());
wfunc(weights,nset);
// store values for A
A = 0;
for(int j = 0; j < Basis::size; j++ ){
for( int k = j; k < Basis::size; k++ ){
for( int i = 0; i < nset.size(); i++ ){
scale(lb,rb,nset[i].point,tmp);
A(j,k) += basis(k, tmp)*basis(j, tmp)*weights[i];
}
}
}
// store values for y
y = 0;
for(int j = 0; j < Basis::size; j++ ){
for( int i = 0; i < nset.size(); i++ ){
scale(lb,rb,nset[i].point,tmp);
y[j] += basis(j, tmp)*weights[i]*nset[i].data;
}
}
// solve system of equations
la::solve(A,y,coef);
// compute point
Data output = 0;
for( int i = 0; i < Basis::size; i++ ){
scale(lb,rb,c,tmp);
output += coef[i]*basis(i,tmp);
}
return output;
}
示例4: e1
void Mesh::FindAdjacencies(const aiMesh* paiMesh, vector<unsigned int>& Indices)
{
// Step 1 - find the two triangles that share every edge
for (uint i = 0 ; i < paiMesh->mNumFaces ; i++) {
const aiFace& face = paiMesh->mFaces[i];
Face Unique;
// If a position vector is duplicated in the VB we fetch the
// index of the first occurrence.
for (uint j = 0 ; j < 3 ; j++) {
uint Index = face.mIndices[j];
aiVector3D& v = paiMesh->mVertices[Index];
if (m_posMap.find(v) == m_posMap.end()) {
m_posMap[v] = Index;
}
else {
Index = m_posMap[v];
}
Unique.Indices[j] = Index;
}
m_uniqueFaces.push_back(Unique);
Edge e1(Unique.Indices[0], Unique.Indices[1]);
Edge e2(Unique.Indices[1], Unique.Indices[2]);
Edge e3(Unique.Indices[2], Unique.Indices[0]);
m_indexMap[e1].AddNeigbor(i);
m_indexMap[e2].AddNeigbor(i);
m_indexMap[e3].AddNeigbor(i);
}
// Step 2 - build the index buffer with the adjacency info
for (uint i = 0 ; i < paiMesh->mNumFaces ; i++) {
const Face& face = m_uniqueFaces[i];
for (uint j = 0 ; j < 3 ; j++) {
Edge e(face.Indices[j], face.Indices[(j + 1) % 3]);
assert(m_indexMap.find(e) != m_indexMap.end());
Neighbors n = m_indexMap[e];
uint OtherTri = n.GetOther(i);
assert(OtherTri != -1);
const Face& OtherFace = m_uniqueFaces[OtherTri];
uint OppositeIndex = OtherFace.GetOppositeIndex(e);
Indices.push_back(face.Indices[j]);
Indices.push_back(OppositeIndex);
}
}
}
示例5: indexOf
// Zhu et al. "A Rank-Order Distance based Clustering Algorithm for Face Tagging", CVPR 2011
// Ob(x) in eq. 1, modified to consider 0/1 as ground truth imposter/genuine.
static int indexOf(const Neighbors &neighbors, int i)
{
for (int j=0; j<neighbors.size(); j++) {
const Neighbor &neighbor = neighbors[j];
if (neighbor.first == i) {
if (neighbor.second == 0) return neighbors.size()-1;
else if (neighbor.second == 1) return 0;
else return j;
}
}
return -1;
}
示例6: neighbors_distances_matrix
SparseMatrix neighbors_distances_matrix(RandomAccessIterator begin, RandomAccessIterator end,
const Neighbors& neighbors, DistanceCallback callback,
ScalarType& average_distance)
{
const IndexType k = neighbors[0].size();
const IndexType n = neighbors.size();
if ((end-begin)!=n)
throw std::runtime_error("Wrong size");
SparseTriplets sparse_triplets;
sparse_triplets.reserve(k*n);
average_distance = 0;
ScalarType current_distance;
for (IndexType i = 0; i < n; ++i)
{
const LocalNeighbors& current_neighbors = neighbors[i];
for (IndexType j = 0; j < k; ++j)
{
current_distance = callback.distance(begin[i], begin[current_neighbors[j]]);
average_distance += current_distance;
SparseTriplet triplet(i, current_neighbors[j], current_distance);
sparse_triplets.push_back(triplet);
}
}
average_distance /= (k*n);
return sparse_matrix_from_triplets(sparse_triplets, n, n);
}
示例7:
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);
}
示例8: 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;
}
示例9: add_cofaces
void add_cofaces (const Graph& graph, Simplex& tau,
const Neighbors& neighbors,
Complex& complex, const std::size_t dimension) {
typedef typename Neighbors::const_iterator Neighbor_iterator;
complex.insert_open_cell(tau);
if(tau.dimension() >= dimension) { return; }
Neighbors lower_neighbors;
Neighbors final_neighbors;
for(Neighbor_iterator i = neighbors.begin(); i != neighbors.end(); ++i){
lower_neighbors.clear();
Simplex sigma( tau);
sigma.insert( *i);
get_lower_neighbors(graph, *i, lower_neighbors);
final_neighbors.clear();
set_intersection(lower_neighbors.begin(),lower_neighbors.end(),
neighbors.begin(),neighbors.end(),
back_inserter(final_neighbors));
add_cofaces(graph, sigma, final_neighbors, complex, dimension);
}
}
示例10: main
int main()
{
Nodes nodes;
Neighbors neighbors;
int n = 0, edges = 0, index = 0, nodeX = 0, nodeY = 0;
while (true)
{
cin >> n;
if (!n)
{
break;
}
nodes.clear();
neighbors.clear();
for (index = 0; index < n; index++)
{
nodes[index] = Uncolored;
}
cin >> edges;
while (edges)
{
cin >> nodeX >> nodeY;
neighbors[nodeX].push_back(nodeY);
neighbors[nodeY].push_back(nodeX);
edges--;
}
cout << (Colorable(nodes, neighbors)? "BICOLORABLE." : "NOT BICOLORABLE.") << endl;
}
return 0;
}
示例11: find_neighbors_covertree_impl
Neighbors find_neighbors_covertree_impl(RandomAccessIterator begin, RandomAccessIterator end,
PairwiseCallback callback, IndexType k)
{
timed_context context("Covertree-based neighbors search");
typedef CoverTreePoint<RandomAccessIterator> TreePoint;
v_array<TreePoint> points;
for (RandomAccessIterator iter=begin; iter!=end; ++iter)
push(points, TreePoint(iter, callback(*iter,*iter)));
node<TreePoint> ct = batch_create(callback, points);
v_array< v_array<TreePoint> > res;
++k; // because one of the neighbors will be the actual query point
k_nearest_neighbor(callback,ct,ct,res,k);
Neighbors neighbors;
neighbors.resize(end-begin);
assert(end-begin==res.index);
for (int i=0; i<res.index; ++i)
{
LocalNeighbors local_neighbors;
local_neighbors.reserve(k);
for (IndexType j=1; j<=k; ++j) // j=0 is the query point
{
// The actual query point is found as a neighbor, just ignore it
if (res[i][j].iter_-begin==res[i][0].iter_-begin)
continue;
local_neighbors.push_back(res[i][j].iter_-begin);
}
neighbors[res[i][0].iter_-begin] = local_neighbors;
free(res[i].elements);
};
free(res.elements);
free_children(ct);
free(points.elements);
return neighbors;
}
示例12: generateMove
Moves MoveGenerator::generateMove(const Board& board) const
{
Moves result;
for(int from=0; from<23; ++from)
if(board.getManAt(from) == board.getSelfColor())
{
Neighbors neighbors = Board::getNeighbors(from);
for(Neighbors::iterator it = neighbors.begin(); it != neighbors.end(); ++it)
if(board.isEmpty(*it))
{
Board next = board.makeChild();
next.move(from, *it);
if(next.closeMill(*it))
{
Moves removeMoves = generateRemove(next, board.getOpponentColor());
copy(removeMoves.begin(), removeMoves.end(), back_inserter(result));
}
else
result.push_back(next);
}
}
return result;
}
示例13: 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();
}
示例14: findNeighbors
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;
}
}
示例15: 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;
}