def calculate_table(n_sampling, quaternions, weights=None): """Calculate the table.""" number_of_rotations = quaternions.shape[0] list_of_points = icosahedral_sphere.sphere_sampling(n_sampling) number_of_bins = len(list_of_points) rotated_coordinates = numpy.array([ rotations.rotate(quaternion, [1., 0., 0.]) for quaternion in quaternions ]) table = numpy.zeros(number_of_rotations, dtype="float64") table_weights = numpy.zeros(number_of_bins, dtype="float64") for i, coordinate in enumerate(rotated_coordinates): progress = float(i) / float(number_of_rotations) sys.stdout.write("\r [{0}{1}] {2:.1f}%".format( "#" * int(progress * 40.), "-" * (40 - int(progress * 40.)), progress * 100.)) sys.stdout.flush() index = closest_coordinate(coordinate, list_of_points) table[i] = index if not weights is None: table_weights[index] += weights[i] else: table_weights[index] += 1. sys.stdout.write("\n") return table, table_weights
def sphere_poly_data(): rotations_n = 1 coordinates = numpy.array(icosahedral_sphere.sphere_sampling(rotations_n)) #create points object points = vtk.vtkPoints() for c in coordinates: points.InsertNextPoint(c[0], c[1], c[2]) #coordinates = icosahedral_sphere.icosahedron_vertices() base_coordinates = icosahedral_sphere.icosahedron_vertices() edges, edge_indices = icosahedron_edges() faces, face_indices = icosahedron_faces() edge_points = [] for e in edges: origin = e[0] base = e[1] - e[0] for i in range(1, rotations_n): edge_points.append(origin + i / float(rotations_n) * base) def get_index(i, j): return int((rotations_n + 1) * j + float(j) / 2. - float(j)**2 / 2. + i) face_points = [] print "start loop" print zip(faces, face_indices) for f, fi in zip(enumerate(faces), face_indices): base_index = f[0] * (((rotations_n + 1)**2 + rotations_n) / 2) print base_index for i in range(0, rotations_n): for j in range(0, rotations_n): if i + j < rotations_n: face_indices.append((base_index + get_index(i, j), base_index + get_index(i, j + 1), base_index + get_index(i + 1, j))) # full_list = [numpy.array(c) for c in coordinates] + edge_points + face_points # normalized_list =[l/numpy.linalg.norm(l) for l in full_list] points = vtk.vtkPoints() for c in coordinates: points.InsertNextPoint(c[0], c[1], c[2]) print "number of points = {0}".format(points.GetNumberOfPoints()) polygons = vtk.vtkCellArray() for p in face_indices: polygon = vtk.vtkPolygon() polygon.GetPointIds().SetNumberOfIds(3) for i, pi in enumerate(p): polygon.GetPointIds().SetId(i, pi) polygons.InsertNextCell(polygon) poly_data = vtk.vtkPolyData() poly_data.SetPoints(points) poly_data.SetPolys(polygons) return poly_data
def calculate_table(n_sampling, quaternions, weights=None): """Calculate the table.""" number_of_rotations = quaternions.shape[0] list_of_points = icosahedral_sphere.sphere_sampling(n_sampling) number_of_bins = len(list_of_points) rotated_coordinates = numpy.array([ rotations.rotate(quaternion, [1., 0., 0.]) for quaternion in quaternions ]) table = numpy.zeros(number_of_rotations, dtype="float64") table_weights = numpy.zeros(number_of_bins, dtype="float64") for i, coordinate in enumerate(rotated_coordinates): index = closest_coordinate(coordinate, list_of_points) table[i] = index if not weights is None: table_weights[index] += weights[i] else: table_weights[index] += 1. return table, table_weights
def calculate_table(n_sampling, quaternions, weights=None): """Calculate the table.""" number_of_rotations = quaternions.shape[0] list_of_points = icosahedral_sphere.sphere_sampling(n_sampling) number_of_bins = len(list_of_points) rotated_coordinates = numpy.array([rotations.rotate(quaternion, [1., 0., 0.]) for quaternion in quaternions]) table = numpy.zeros(number_of_rotations, dtype="float64") table_weights = numpy.zeros(number_of_bins, dtype="float64") for i, coordinate in enumerate(rotated_coordinates): progress = float(i) / float(number_of_rotations) sys.stdout.write("\r [{0}{1}] {2:.1f}%".format("#"*int(progress*40.),"-"*(40-int(progress*40.)), progress*100.)) sys.stdout.flush() index = closest_coordinate(coordinate, list_of_points) table[i] = index if not weights is None: table_weights[index] += weights[i] else: table_weights[index] += 1. sys.stdout.write("\n") return table, table_weights
def sphere_poly_data(): rotations_n = 1 coordinates = numpy.array(icosahedral_sphere.sphere_sampling(rotations_n)) # create points object points = vtk.vtkPoints() for c in coordinates: points.InsertNextPoint(c[0], c[1], c[2]) # coordinates = icosahedral_sphere.icosahedron_vertices() base_coordinates = icosahedral_sphere.icosahedron_vertices() edges, edge_indices = icosahedron_edges() faces, face_indices = icosahedron_faces() edge_points = [] for e in edges: origin = e[0] base = e[1] - e[0] for i in range(1, rotations_n): edge_points.append(origin + i / float(rotations_n) * base) def get_index(i, j): return int((rotations_n + 1) * j + float(j) / 2.0 - float(j) ** 2 / 2.0 + i) face_points = [] print "start loop" print zip(faces, face_indices) for f, fi in zip(enumerate(faces), face_indices): base_index = f[0] * (((rotations_n + 1) ** 2 + rotations_n) / 2) print base_index for i in range(0, rotations_n): for j in range(0, rotations_n): if i + j < rotations_n: face_indices.append( ( base_index + get_index(i, j), base_index + get_index(i, j + 1), base_index + get_index(i + 1, j), ) ) # full_list = [numpy.array(c) for c in coordinates] + edge_points + face_points # normalized_list =[l/numpy.linalg.norm(l) for l in full_list] points = vtk.vtkPoints() for c in coordinates: points.InsertNextPoint(c[0], c[1], c[2]) print "number of points = {0}".format(points.GetNumberOfPoints()) polygons = vtk.vtkCellArray() for p in face_indices: polygon = vtk.vtkPolygon() polygon.GetPointIds().SetNumberOfIds(3) for i, pi in enumerate(p): polygon.GetPointIds().SetId(i, pi) polygons.InsertNextCell(polygon) poly_data = vtk.vtkPolyData() poly_data.SetPoints(points) poly_data.SetPolys(polygons) return poly_data