本文整理汇总了C++中MeshType::getNeighbors方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshType::getNeighbors方法的具体用法?C++ MeshType::getNeighbors怎么用?C++ MeshType::getNeighbors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshType
的用法示例。
在下文中一共展示了MeshType::getNeighbors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
// Check arguments
if (argc < 3) {
std::cerr << "Usage: shallow_water NODES_FILE TRIS_FILE\n";
exit(1);
}
auto start = std::chrono::high_resolution_clock::now();
MeshType mesh;
// HW4B: Need node_type before this can be used!
std::vector<typename MeshType::node_type> mesh_node;
// Read all Points and add them to the Mesh
std::ifstream nodes_file(argv[1]);
Point p;
while (CS207::getline_parsed(nodes_file, p)) {
mesh_node.push_back(mesh.add_node(p));
}
// Read all mesh triangles and add them to the Mesh
std::ifstream tris_file(argv[2]);
std::array<int,3> t;
while (CS207::getline_parsed(tris_file, t)) {
// HW4B: Need to implement add_triangle before this can be used!
mesh.add_triangle(mesh_node[t[0]], mesh_node[t[1]], mesh_node[t[2]]);
}
// Print out the stats
std::cout << mesh.num_nodes() << " "
<< mesh.num_edges() << " "
<< mesh.num_triangles() << std::endl;
//Start of nearest neighor. Put all positions that you want inspected in a vector of type double
std::vector<double> pos;
for (auto it = mesh.node_begin(); it != mesh.node_end(); ++it )
pos.push_back((*it).position().z);
unsigned num_neighbors = 10; //num of neighors to return
unsigned object_idx = 5; // do this if you want to examine the neighbors of a specific idx
MeshType::NearestNeighbor a = mesh.calculateNearestNeighbors(num_neighbors ,pos);
auto idx = mesh.getNeighbors(a,object_idx);
auto dist = mesh.getNeighborDistances(a,object_idx);
/*auto all_n = mesh.getAllNeighbors(a);
auto all_d = mesh.getAllNeighborDistances(a);*/
for (unsigned i = 0; i < idx.size(); ++i)
std::cout << "Node " << object_idx << "'s " << i << " neighbor is: node " << idx[i] << " with distance of " << dist[i] << endl;
/*//Uncomment to view results for all nodes
for (unsigned j = 0; j < pos.size(); ++j){
std::cout << endl;
for (unsigned i = 0; i < num_neighbors; ++i)
std::cout << "For node " << j << " neighbor " << i << " is index " << all_n[i+j*num_neighbors] << " and distance is " << all_d[i+j*num_neighbors] << endl;
}*/
// HW4B Initialization
// Set the initial conditions
int wave = 0, peddle=0, dam=1;
if (wave){
for ( auto it = mesh.node_begin(); it!= mesh.node_end(); ++it){
auto x = (*it).position().x;
auto y = (*it).position().y;
double h = 1-0.75 * exp(-80 * ( (x-0.75)*(x-0.75) + y*y ));
mesh.value((*it),QVar( h,0,0));
}
}
else if (peddle){
for ( auto it = mesh.node_begin(); it!= mesh.node_end(); ++it){
auto x = (*it).position().x;
auto y = (*it).position().y;
double h = (x-0.75)*(x-0.75) + y*y -0.15*0.15 ;
int H =0;
if (h < 0)
H = 1;
mesh.value((*it), QVar(1+0.75*H,0,0));
}
}
else if (dam){
for ( auto it = mesh.node_begin(); it!= mesh.node_end(); ++it){
auto x = (*it).position().x;
int H =0;
if (x < 0)
H = 1;
mesh.value((*it), QVar(1+0.75*H,0,0));
}
}
// Perform any needed precomputation
// initialize triangle
for (auto it = mesh.tri_begin(); it != mesh.tri_end(); ++it ) {
(*it).value() = ((*it).node1().value() + (*it).node2().value() + (*it).node3().value())/3.0;
}
//.........这里部分代码省略.........