本文整理汇总了C++中Neighborhood类的典型用法代码示例。如果您正苦于以下问题:C++ Neighborhood类的具体用法?C++ Neighborhood怎么用?C++ Neighborhood使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Neighborhood类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isHappy
bool Shape::isHappy( const Neighborhood &n,
unsigned int pos_x,
unsigned int pos_y) const{
if (n.get(pos_x, pos_y).getType() == "empty")
return true;
// find the min and max coordinates of possible neighbors
unsigned int x_min = (pos_x == 0) ? pos_x : pos_x - 1;
unsigned int y_min = (pos_y == 0) ? pos_y : pos_y - 1;
unsigned int x_max = (pos_x == n.size_x-1) ? pos_x : pos_x + 1;
unsigned int y_max = (pos_y == n.size_y-1) ? pos_y : pos_y + 1;
double alike = 0;
double different = 0;
// evaluate each neighbor to deteremine likeness
for (int x=x_min; x <= x_max; x++) {
for (int y=y_min; y <= y_max; y++) {
if (x == pos_x && y == pos_y)
continue;
else if (n.get(x, y).getType() == "empty")
continue;
else if (n.get(x, y).getType() == n.get(pos_x, pos_y).getType())
alike++;
else
different++;
}
}
// returns true if the shape is happy
return ( different || alike )
&& ( different == 0 || alike / different >= RATIO_ALIKE_HAPPY )
&& ( alike == 0 || different / alike >= RATIO_DIFFERENT_HAPPY);
}
示例2: stopChangingPressure
void PressureDoor::stopChangingPressure() {
Neighborhood *owner;
switch (GameState.getNoradSubRoomPressure()) {
case 11:
_typeMovie.setSegment(kMaxPressureLoopStart * _typeScale, kMaxPressureLoopStop * _typeScale);
_typeMovie.setFlags(kLoopTimeBase);
_typeMovie.show();
_typeMovie.start();
break;
case 10:
_typeMovie.setSegment(kCautionLoopStart * _typeScale, kCautionLoopStop * _typeScale);
_typeMovie.setFlags(kLoopTimeBase);
_typeMovie.show();
_typeMovie.start();
break;
case kNormalSubRoomPressure:
owner = getOwner();
_typeMovie.setSegment(kOpeningDoorLoopStart * _typeScale, kOpeningDoorLoopStop * _typeScale);
_typeMovie.setFlags(kLoopTimeBase);
_typeMovie.show();
_gameState = kPlayingDoneMessage;
owner->requestDelay(2, 1, kFilterNoInput, kDelayCompletedFlag);
_typeMovie.start();
break;
default:
_typeMovie.hide();
break;
}
}
示例3: isHappy
bool Shape::isHappy(const Neighborhood & n, unsigned int pos_x, unsigned int pos_y) const {
if (n.get(pos_x, pos_y).getType() == "Empty")
return true;
unsigned int x_min = (pos_x == 0) ? pos_x : pos_x - 1;
unsigned int y_min = (pos_y == 0) ? pos_y : pos_y - 1;
unsigned int x_max = (pos_x == n.size_x - 1) ? pos_x : pos_x + 1;
unsigned int y_max = (pos_y == n.size_y - 1) ? pos_y : pos_y + 1;
double alike = 0;
double different = 0;
for (int x = x_min; x <= x_max; x++) {
for (int y = y_min; y <= y_max; y++) {
if (x == pos_x && y == pos_y)
continue;
else if (n.get(x, y).getType() == "Empty")
continue;
else if (n.get(x, y).getType() == n.get(pos_x, pos_y).getType())
alike++;
else
different++;
}
}
return (different || alike)
&& (different == 0 || alike / different >= RATIO_ALIKE_HAPPY)
&& (alike == 0 || different / alike >= RATIO_DIFFERENT_HAPPY);
}
示例4: Neighborhood
/**
* Helper method to determine if any cubes are neighboured
*/
bool Phonemic::noNeighbors() {
for(CubeID cube: CubeSet::connected())
{
Neighborhood hood = Neighborhood(cube);
if(hood.hasCubeAt(LEFT) || hood.hasCubeAt(RIGHT))
return false;
}
return true;
}
示例5: knnFromSimmat
Neighborhood br::knnFromSimmat(const QList<cv::Mat> &simmats, int k)
{
Neighborhood neighborhood;
float globalMax = -std::numeric_limits<float>::max();
float globalMin = std::numeric_limits<float>::max();
int numGalleries = (int)sqrt((float)simmats.size());
if (numGalleries*numGalleries != simmats.size())
qFatal("Incorrect number of similarity matrices.");
// Process each simmat
for (int i=0; i<numGalleries; i++) {
QVector<Neighbors> allNeighbors;
int currentRows = -1;
int columnOffset = 0;
for (int j=0; j<numGalleries; j++) {
cv::Mat m = simmats[i * numGalleries + j];
if (j==0) {
currentRows = m.rows;
allNeighbors.resize(currentRows);
}
if (currentRows != m.rows) qFatal("Row count mismatch.");
// Get data row by row
for (int k=0; k<m.rows; k++) {
Neighbors &neighbors = allNeighbors[k];
neighbors.reserve(neighbors.size() + m.cols);
for (int l=0; l<m.cols; l++) {
float val = m.at<float>(k,l);
if ((i==j) && (k==l)) continue; // Skips self-similarity scores
if (val != -std::numeric_limits<float>::max()
&& val != -std::numeric_limits<float>::infinity()
&& val != std::numeric_limits<float>::infinity()) {
globalMax = std::max(globalMax, val);
globalMin = std::min(globalMin, val);
}
neighbors.append(Neighbor(l+columnOffset, val));
}
}
columnOffset += m.cols;
}
// Keep the top matches
for (int j=0; j<allNeighbors.size(); j++) {
Neighbors &val = allNeighbors[j];
const int cutoff = k; // Number of neighbors to keep
int keep = std::min(cutoff, val.size());
std::partial_sort(val.begin(), val.begin()+keep, val.end(), compareNeighbors);
neighborhood.append((Neighbors)val.mid(0, keep));
}
}
return neighborhood;
}
示例6: neighborhoodsOverlap
bool neighborhoodsOverlap(const Neighborhood &n1, const Neighborhood &n2) {
// both neighborhoods are assumed to be in the same frame
Neighborhood::const_iterator it1, it2;
for (it1 = n1.begin(); it1!=n1.end(); it1++)
for (it2 = n2.begin(); it2 != n2.end(); it2++) {
if ( *it1 == *it2 )
return true;
}
return false;
}
示例7: assert
pcl2::Neighborhood
pcl2::computeFixedRadiusNeighborhood (Cloud & cloud, const MatF & query, float r)
{
// Convert point cloud
MatF xyz = cloud["xyz"];
assert (xyz.rows () >= 1);
assert (xyz.cols () == 3);
pcl::PointCloud<pcl::PointXYZ>::Ptr input (new pcl::PointCloud<pcl::PointXYZ>);
input->width = cloud.size ();
input->height = 1;
input->is_dense = false;
input->points.resize (cloud.size ());
for (size_t i = 0; i < xyz.rows (); ++i)
{
input->points[i].x = xyz (i, 0);
input->points[i].y = xyz (i, 1);
input->points[i].z = xyz (i, 2);
}
// Convert query point
assert (query.rows () == 1);
assert (query.cols () == 3);
pcl::PointXYZ q;
q.x = query (0, 0);
q.y = query (0, 1);
q.z = query (0, 2);
// Perform neighbor search
pcl::KdTreeFLANN<pcl::PointXYZ> tree;
tree.setInputCloud (input);
std::vector<int> idx_vec;
std::vector<float> dist_vec;
size_t k = (size_t) tree.radiusSearch (q, r, idx_vec, dist_vec);
assert (k == idx_vec.size ());
// Convert output
EigenMat<int> neighbor_indices (k, 1);
EigenMat<float> squared_distances (k, 1);
for (size_t i = 0; i < k; ++i)
{
neighbor_indices (i, 0) = idx_vec[i];
squared_distances (i, 0) = dist_vec[i];
}
//Cloud neighborhood = cloud (neighbor_indices);
Neighborhood neighborhood (cloud, neighbor_indices);
neighborhood.insert ("dist", squared_distances);
return (neighborhood);
}
示例8: drawSideIndicator
static void drawSideIndicator(BG0ROMDrawable &draw, Neighborhood &nb,
Int2 topLeft, Int2 size, Side s)
{
unsigned nbColor = draw.ORANGE;
draw.fill(topLeft, size,
nbColor | (nb.hasNeighborAt(s) ? draw.SOLID_FG : draw.SOLID_BG));
}
示例9: KdTree
void
SoftBody::updateNeighborhoods()
{
auto kdTree = KdTree(posRest);
std::vector<uint32_t> indices;
indices.reserve(Neighborhood::MAX_SIZE + 1);
auto neighbor_it = neighborhoods.begin();
auto radius_it = radii.begin();
uint32_t index = 0;
for (auto& u : posRest) {
//
// A particle's neighborhood should not include itself. However, this
// kdTree will return an index for the current particle. So increment
// the neighbor count by 1, and then remove the "self" particle when
// we're done.
//
kdTree.neighbors(posRest, u, Neighborhood::MAX_SIZE + 1, *radius_it, indices);
auto selfLocation = std::find(indices.begin(), indices.end(), index);
if (selfLocation != indices.end()) {
indices.erase(selfLocation);
}
// If we find a neighbor we didn't already have, add it with an initial
// weight of zero.
//
Neighborhood newNeighbors;
for (auto j : indices) {
if (neighbor_it->hasNeighbor(j)) {
newNeighbors.push_back(neighbor_it->findNeighbor(j));
} else {
Vector3d u_ij = posRest[j] - u;
Neighbor n(j, u_ij, 0.0);
newNeighbors.push_back(n);
}
}
*neighbor_it = newNeighbors;
++neighbor_it;
++radius_it;
++index;
}
}
示例10: mergeNeighborhoods
void mergeNeighborhoods(Neighborhood &n1, Neighborhood &n2)
{
Neighborhood::iterator it1, it2;
bool present;
for (it2 = n2.begin(); it2 != n2.end(); it2++) {
present = false;
for (it1 = n1.begin(); it1 != n1.end(); it1++) {
if ( *it1 == *it2 ) {
present = true;
break;
}
}
if (!present) {
n1.push_back( *it2 );
}
}
}
示例11: leftmostNeighbor
/**
* Helper method to decide if a series of cubes
* spells the current word.
*/
void Phonemic::checkForWord(unsigned id) {
// Find leftmost cube
CubeID nextID = leftmostNeighbor(id);
Neighborhood hood = Neighborhood(nextID);
// Find the sequence of symbols spelled by
// the sequence of cubes
int wordAttempt[MAX_WORD_SIZE];
wordAttempt[0] = cubes[nextID].symbol;
int i = 1;
while(hood.hasCubeAt(RIGHT)) {
nextID = hood.cubeAt(RIGHT);
hood = Neighborhood(nextID);
wordAttempt[i] = cubes[nextID].symbol;
i++;
}
wordAttempt[i] = -1;
// Check for a match
bool match = true;
for(int i = 0; i < /*MAX_WORD_SIZE*/ length; i++) {
if(/*order[i]*/ wordFamilies[level].phonemes[word][i] != wordAttempt[i])
{
match = false;
break;
}
//if(wordFamilies[level].phonemes[word][i] == -1) break;
}
// Recognize match
if(match) {
//sounding.play(SfxChime);
//sounding.play(SfxCat);
sounding.play(/*SfxChime*/ *wordFamilies[level].words[word].sound);
allSmiles();
System::paint();
state = WORD_FOUND;
}
}
示例12: mark
void Application::connectedComponents(SparseGraph &G,
Vector<Neighborhood> &components)
{
int N=G.getNumVertices(), componentId=1;
Array1D<bool> mark(N);
mark.setAllTo(false);
for(VertexId i=0 ; i<N ; ++i) {
if(mark[i]) continue;
Neighborhood component;
dfs(G,i,mark,component);
components.push_back(component);
int size=component.size();
cout<<"Component #"<<componentId++<<" "<<size<<" vertices:"<<endl;
for(Neighborhood::iterator cur=component.begin(), end=component.end() ;
cur!=end ; ++cur) {
VertexId id=*cur;
cout<<G.getLabel(id)<<"\t";
}
cout<<endl;
}
}
示例13: while
/**
* Helper method to sounds out the sequence of cubes.
*/
void Phonemic::soundOut(unsigned id) {
// Wait for audio channel to be clear
if(sounding.isPlaying()) return;
// Highlight the current cube
cubes[id].vid.bg0.image(vec(0,0), *cubes[id].images[1]);
System::paint();
System::finish();
// Play the current cube's sound
sounding.play(*cubes[id].sound);
while(sounding.isPlaying()) {
System::yield();
}
// Return the cube to its normal appearance
cubes[id].vid.bg0.image(vec(0,0), *cubes[id].images[0]);
// Play any cube connected to the right
Neighborhood hood = Neighborhood(id);
if(hood.hasCubeAt(RIGHT)) soundOut(hood.cubeAt(RIGHT));
}
示例14: getOwner
void PressureDoor::doSolve() {
if (_playingAgainstRobot) {
GameState.setNoradSubRoomPressure(11);
_levelsMovie.setTime((11 + kPressureBase) * _levelsScale);
_levelsMovie.redrawMovieWorld();
_typeMovie.setSegment(kMaxPressureLoopStart * _typeScale, kMaxPressureLoopStop * _typeScale);
_typeMovie.setFlags(kLoopTimeBase);
_typeMovie.show();
_typeMovie.start();
g_AIArea->checkMiddleArea();
} else {
GameState.setNoradSubRoomPressure(kNormalSubRoomPressure);
_levelsMovie.setTime((kNormalSubRoomPressure + kPressureBase) * _levelsScale);
_levelsMovie.redrawMovieWorld();
_typeMovie.setSegment(kOpeningDoorLoopStart * _typeScale, kOpeningDoorLoopStop * _typeScale);
_typeMovie.setFlags(kLoopTimeBase);
_typeMovie.show();
Neighborhood *owner = getOwner();
owner->requestDelay(2, 1, kFilterNoInput, kDelayCompletedFlag);
_gameState = kPlayingDoneMessage;
_typeMovie.start();
g_AIArea->checkMiddleArea();
}
}
示例15: while
void Application::dfs(SparseGraph &G,VertexId v,Array1D<bool> &mark,
Neighborhood &component)
{
Stack<VertexId> S;
S.push(v);
mark[v]=true;
while(!S.isEmpty()) {
VertexId v=S.pop();
component.insert(v);
bool shouldDelete;
Neighborhood &children=*G.getNeighborsOf(v,shouldDelete);
for(Neighborhood::iterator cur=children.begin(), end=children.end() ;
cur!=end ; ++cur) {
VertexId child=*cur;
if(mark[child]) continue;
S.push(child);
mark[child]=true;
//component.insert(child);
}
}
}