int main(int argc, char** argv) { // Check arguments if (argc < 3) { std::cerr << "Usage: " << argv[0] << " NODES_FILE TETS_FILE\n"; exit(1); } // Construct a Graph typedef Graph<int, int> GraphType; GraphType graph; std::vector<GraphType::node_type> nodes; // Create a nodes_file from the first input argument std::ifstream nodes_file(argv[1]); // Interpret each line of the nodes_file as a 3D Point and add to the Graph Point p; while (CME212::getline_parsed(nodes_file, p)) nodes.push_back(graph.add_node(p)); // Create a tets_file from the second input argument std::ifstream tets_file(argv[2]); // Interpret each line of the tets_file as four ints which refer to nodes std::array<int,4> t; while (CME212::getline_parsed(tets_file, t)) for (unsigned i = 1; i < t.size(); ++i) for (unsigned j = 0; j < i; ++j) graph.add_edge(nodes[t[i]], nodes[t[j]]); // Print out the stats std::cout << graph.num_nodes() << " " << graph.num_edges() << std::endl; // Launch the SDLViewer CME212::SDLViewer viewer; viewer.launch(); auto node_map = viewer.empty_node_map(graph); Point pref = Point(-1, 0, 1); int path = shortest_path_lengths(graph, pref); PathColorFn pcf = PathColorFn(path); viewer.add_nodes(graph.node_begin(), graph.node_end(), pcf, node_map); // Test the PositionColorFn, the color is presented according to the nodes' x coordinats. //PositionColorFn pocf = PositionColorFn(); //viewer.add_nodes(graph.node_begin(), graph.node_end(), pocf, node_map); viewer.add_edges(graph.edge_begin(), graph.edge_end(), node_map); viewer.center_view(); return 0; }
int main(int argc, char* argv[]) { // Check arguments if (argc < 2) { std::cerr << "Usage: " << argv[0] << " NODES_FILE TETS_FILE\n"; exit(1); } // Construct a Graph typedef Graph<int> GraphType; GraphType graph; std::vector<GraphType::node_type> nodes; // Create a nodes_file from the first input argument std::ifstream nodes_file(argv[1]); // Interprit each line of the nodes_file as a 3D Point and add to the Graph Point p; while (CS207::getline_parsed(nodes_file, p)) nodes.push_back(graph.add_node(p)); // Create a tets_file from the second input argument std::ifstream tets_file(argv[2]); // Interprit each line of the tets_file as four ints which refer to nodes std::array<int,4> t; while (CS207::getline_parsed(tets_file, t)) for (unsigned i = 1; i < t.size(); ++i) for (unsigned j = 0; j < i; ++j) graph.add_edge(nodes[t[i]], nodes[t[j]]); // Print out the stats std::cout << graph.num_nodes() << " " << graph.num_edges() << std::endl; // Launch the SDLViewer CS207::SDLViewer viewer; viewer.launch(); // Use shortest_path_lengths to set the node values to the path lengths // Construct a Color functor and view with the SDLViewer auto node_map = viewer.empty_node_map(graph); int distance = shortest_path_lengths(graph, {-1,0,1}); viewer.add_nodes(graph.node_begin(), graph.node_end(), Color(distance), node_map); viewer.add_edges(graph.edge_begin(), graph.edge_end(), node_map); return 0; }