#ifndef STIM_NETWORK_H #define STIM_NETWORK_H #include #include #include #include #include #include #include #include #include #include #include #include namespace stim{ /** This is the a class that interfaces with gl_spider in order to store the currently * segmented network. The following data is stored and can be extracted: * 1)Network geometry and centerline. * 2)Network connectivity (a graph of nodes and edges), reconstructed using ANN library. */ template class network{ ///Each edge is a fiber with two nodes. ///Each node is an in index to the endpoint of the fiber in the nodes array. class edge : public fiber { public: unsigned v[2]; //unique id's designating the starting and ending /// Constructor - creates an edge from a list of points by calling the stim::fiber constructor ///@param p is a position in space edge(std::vector< stim::vec > p) : fiber(p){} /// Output the edge information as a string std::string str(){ std::stringstream ss; ss<<"("<::N<<")\tl = "< { public: //std::vector edges; //indices of edges connected to this node. std::vector e[2]; //indices of edges going out (e[0]) and coming in (e[1]) //stim::vec p; //position of this node in physical space. //constructor takes a stim::vec vertex(stim::vec p) : stim::vec(p){} /// Output the vertex information as a string std::string str(){ std::stringstream ss; ss<<"\t(x, y, z) = "<::str(); if(e[0].size() > 0){ ss<<"\t> "; for(unsigned int o = 0; o < e[0].size(); o++) ss< 0){ ss<<"\t< "; for(unsigned int i = 0; i < e[1].size(); i++) ss< E; //list of edges std::vector V; //list of vertices. public: ///Returns the number of edges in the network. unsigned int edges(){ return E.size(); } ///Returns the number of nodes in the network. unsigned int vertices(){ return V.size(); } //load a network from an OBJ file void load_obj(std::string filename){ stim::obj O; //create an OBJ object O.load(filename); //load the OBJ file as an object //prints each line in the obj file - vertex positions and fibers std::cout< id2vert; //this list stores the OBJ vertex ID associated with each network vertex unsigned i[2]; //temporary, IDs associated with the first and last points in an OBJ line //for each line in the OBJ object for(unsigned int l = 1; l <= O.numL(); l++){ std::vector< stim::vec > c; //allocate an array of points for the vessel centerline O.getLine(l, c); //get the fiber centerline edge e = c; //create an edge from the given centerline //get the first and last vertex IDs for the line std::vector< unsigned > id; //create an array to store the centerline point IDs O.getLinei(l, id); //get the list of point IDs for the line i[0] = id.front(); //get the OBJ ID for the first element of the line i[1] = id.back(); //get the OBJ ID for the last element of the line std::vector::iterator it; //create an iterator for searching the id2vert array unsigned it_idx; //create an integer for the id2vert entry index //find out if the nodes for this fiber have already been created it = find(id2vert.begin(), id2vert.end(), i[0]); //look for the first node it_idx = std::distance(id2vert.begin(), it); if(it == id2vert.end()){ //if i[0] hasn't already been used vertex v = e[0]; //create a new vertex, assign it a position v.e[0].push_back(E.size()); //add the current edge as outgoing e.v[0] = V.size(); //add the new vertex to the edge V.push_back(v); //add the new vertex to the vertex list id2vert.push_back(i[0]); //add the ID to the ID->vertex conversion list } else{ //if the vertex already exists V[it_idx].e[0].push_back(E.size()); //add the current edge as outgoing e.v[0] = it_idx; } it = find(id2vert.begin(), id2vert.end(), i[1]); //look for the second ID it_idx = std::distance(id2vert.begin(), it); if(it == id2vert.end()){ //if i[1] hasn't already been used vertex v = e.back(); //create a new vertex, assign it a position v.e[1].push_back(E.size()); //add the current edge as incoming e.v[1] = V.size(); V.push_back(v); //add the new vertex to the vertex list id2vert.push_back(i[1]); //add the ID to the ID->vertex conversion list } else{ //if the vertex already exists V[it_idx].e[1].push_back(E.size()); //add the current edge as incoming e.v[1] = it_idx; } /*lines to be added for resampling each fiber in the network class //std::vector< stim::vec > newFiberPos, fiberPos; //fiberPos = e.centerline(); //newFiberPos = e.Resample(fiberPos); //edge newEdge = newFiberPos; //E.push_back(newEdge); */ E.push_back(e); //push the edge to the list } } /// Output the network as a string std::string str(){ std::stringstream ss; ss<<"Nodes ("<