Note that there are some explanatory texts on larger screens.

plurals
  1. PONetwork X , which depth searching option to select for this use?
    primarykey
    data
    text
    <p>I am trying to ensure a global correct orientation of my normals. I.e make sure they point outwards everywhere.</p> <p>This is my method:</p> <ol> <li>I have a coordinate list <code>x y c n</code> . At each point in coordinate list I create edges from the point to its 5 nearest neighbours.</li> <li>I Weight each edge with (<code>1-n1.n2</code>).</li> <li>Compute a minimal spanning tree.</li> <li>Traverse this tree in depth first order.</li> <li>Start traversing at the point with the greatest <code>z</code> value, force the normal of this point to be orientated towards the positive <code>z</code> axis. </li> <li>Assign orientation to subsequent points that are consistent with their preceeding point, for example if current point <code>p1</code> has orientation <code>n1</code>, and next point visited is <code>p2</code>, if <code>n1.n2&lt;0</code> then <code>n2</code> is replaced by <code>-n2</code>.</li> </ol> <p>I am not sure how to do the depth first traversing and implement steps 5,6. My code is below.</p> <p>Many thanks!</p> <pre><code>import numpy as np from sklearn.neighbors import NearestNeighbors import networkx as nx #Get coordinates f_name = 'Bunnylarge' coord = np.genfromtxt(str(f_name)+'.txt',autostrip=True) #Fit nearest neighbours to coordinates neigh = NearestNeighbors(5) neigh.fit(coord[:,:3]) #Get the point with highest z value , this will be used as the starting point for my depth search z_max_point = np.where(coord[:,2]==np.max(coord[:,2])) z_max_point=int(z_max_point[0]) #Create a graph G = nx.Graph() #Add all points and there neighbours to graph, make the weight equal to the distance between points for i in range(0,len(coord)): d = neigh.kneighbors(coord[i,:3]) k = 5 for c in range(1,k): p1 = d[1][0][0] p2 = d[1][0][c] n1 = coord[d[1][0][0],3:6] n2 = coord[d[1][0][c],3:6] dot = np.dot(n1,n2) G.add_edge(p1,p2,weight =1-dot) #Get minimum spanning tree of graph #M = nx.minimum_spanning_edges(G,weight = 'weight',data=True) M = nx.minimum_spanning_edges(G) edgelist = list(M) #Convert minimum spanning tree into graph to be able to depth searched D = nx.from_edgelist(edgelist) if coord[z_max_point,5] &lt; 0 : #ie normal doesnt point out coord[z_max_point,3:6]=-coord[z_max_point,3:6] #Compute the DFS, start at the z_max_point T = nx.dfs_tree(D,source = z_max_point) #Go through the depth searched order and if subsequent points have for example a n1*n2&lt;0 then make n2=-n2 #for i in list(T.edges()): #for i in nx.dfs_successors(D,z_max_point): n1 = coord[z_max_point,3:6] #for i in nx.dfs_postorder_nodes(D,z_max_point): for i in nx.dfs_tree(D,z_max_point): print i n2 = coord[i,3:6] if np.dot(n1,n2)&lt;0: coord[i,3:6]=-coord[i,3:6] n2 = n1 print 'done' np.savetxt('testnormals2.xyz',coord) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload