dipy logo

Site Navigation

NIPY Community

Previous topic

dipy.core.rng

Next topic

dipy.core.sphere_stats

dipy.core.triangle_subdivide

Create a unit sphere by subdividing all triangles of an octahedron recursively.

The unit sphere has a radius of 1, which also means that all points in this sphere (assumed to have centre at [0, 0, 0]) have an absolute value (modulus) of 1. Another feature of the unit sphere is that the unit normals of this sphere are exactly the same as the vertices.

This recursive method will avoid the common problem of the polar singularity, produced by 2d (lon-lat) parameterization methods.

If you require a sphere with another radius than that of 1, simply multiply every single value in the vertex array by this new radius (although this will break the “vertex array equal to unit normal array” property)

dipy.core.triangle_subdivide.create_half_unit_sphere(recursion_level=2)

Creates a unit sphere and returns the top half

Starting with a symmetric sphere of points, removes half the points so that for any pair of points a, -a only one is kept. Removes half the edges so for any pair of edges [a, b]; [-a, -b] only one is kept. The new edges are constructed in a way so that references to any removed point, r, is replaced by a reference to -r. Removes half the triangles in the same way.

Parameters :

recursion_level : int

Level of subdivision, recursion_level=1 will return an octahedron, anything bigger will return a more subdivided sphere.

Returns :

vertices : array

A 2d array with the x, y, and z coordinates of vertices on a unit sphere.

edges : array

A 2d array of vertex pairs for every set of neighboring vertexes on a unit sphere.

triangles : array

A 2d array of edge triplets representing triangles on the surface of a unit sphere.

See also

create_half_sphere, divide_all

dipy.core.triangle_subdivide.create_unit_sphere(recursion_level=2)

Creates a unit sphere by subdividing a unit octahedron.

Starts with a unit octahedron and subdivides the faces, projecting the resulting points onto the surface of a unit sphere.

Parameters :

recursion_level : int

Level of subdivision, recursion_level=1 will return an octahedron, anything bigger will return a more subdivided sphere.

Returns :

vertices : array

A 2d array with the x, y, and z coordinates of vertices on a unit sphere.

edges : array

A 2d array of vertex pairs for every set of neighboring vertexes on a unit sphere.

triangles : array

A 2d array of edge triplets representing triangles on the surface of a unit sphere.

See also

create_half_sphere, divide_all

dipy.core.triangle_subdivide.divide_all(vertices, edges, triangles)

Subdivides a triangle

Parameters :

vertices : ndarray

A Vx3 array with the x, y, and z coordinates of of each vertex

edges : ndarray

An Ex2 array were each pair of values is an index

Returns :

vertices : array

A 2d array with the x, y, and z coordinates of vertices

edges : array

A 2d array of vertex pairs for every set of neighboring vertexes

triangles : array

A 2d array of edge triplets representing triangles

Notes

Subdivide each triangle in the old approximation and normalize the new points thus generated to lie on the surface of the unit sphere.

Each input triangle with vertices labelled [0,1,2], as shown below, is represented by a set of edges. The edges are written in such a way so that the second vertex in each edge is the first vertex in the next edge. For example:

[0, 1]
[1, 2]
[2, 0]

Make new points:

b = (0+1)/2
c = (1+2)/2
a = (2+0)/2

Construct new triangles:

t1 [0b,ba,a0]
t2 [1c,cb,b1]
t3 [2a,ac,c2]
t4 [ba,ac,cb]

Like this:

       1
      /\
     /  \
   b/____\ c
   /\    /\
  /  \  /  \
 /____\/____\
0      a     2

Normalize a, b, c.

When constructed this way edges[triangles,0] or edges[triangles,1] will both return the three vertices that make up each triangle (in a different order):

Code was adjusted from dlampetest website http://sites.google.com/site/dlampetest/python/triangulating-a-sphere-recursively

dipy.core.triangle_subdivide.normalize_v3(arr)

Normalize a numpy array of 3 component vectors shape=(n,3)

dipy.core.triangle_subdivide.remove_half_sphere(v, e, t)

Returns a triangulated half sphere

Removes half the vertices, edges, and triangles from a unit sphere created by create_unit_sphere