def test_vector_alignment_find_rotation_random_vectors(self): x = np.random.normal(size=(3,)) y = np.random.normal(size=(3,)) r = vector_alignment_find_rotation(x, y) SurfingSurfaceTests._assert_rotation_maps_vector(r, x, y)
def test_vector_alignment_find_rotation_random_vectors(self): x = np.random.normal(size=(3,)) y = np.random.normal(size=(3,)) r = vector_alignment_find_rotation(x, y) SurfingSurfaceTests._assert_rotation_maps_vector(r, x, y)
def flat_surface2xy(surface, max_deformation): '''Returns a tuple with x and y coordinates of a flat surface Parameters ---------- surface: Surface flat surface max_deformation: float maximum deformation to make a non-flat surface flat. The normals of each face must have a dot product with the average face normal that is not less than (1-max_deformation); otherwise an exception is raised. The rationale for this option is that certain surfaces may be almost flat, and those can be made flat without problem; but surfaces that are not flat, such as inflated surfaces, should not be flattable. Returns ------- x: np.ndarray x coordinates y: np.ndarray y coordinates Notes ----- If the surface is not flat (any z coordinate is non-zero), an exception is raised. ''' s = surf.from_any(surface) face_normals = s.face_normals msk = np.all(np.logical_not(np.isnan(face_normals)), 1) avg_face_normal = s.nanmean_face_normal deformations = abs( 1 - abs(np.dot(avg_face_normal[np.newaxis], face_normals[msk].T))) too_deformed = np.nonzero(deformations > max_deformation)[0] if len(too_deformed) > 0: raise ValueError('Surface is not sufficiently flat with ' 'max_deformation=%.3f' % max_deformation) # find rotation so that surface is more or less orthogonal to # the unit vector (0,0,1) v = s.vertices z_axis = np.asarray([0, 0, 1.]) r = vector_alignment_find_rotation(avg_face_normal, z_axis) # apply rotation v_rotated = r.dot(v.T) # discard z-coordinate x = v_rotated[0] y = v_rotated[1] return x, y
def flat_surface2xy(surface, max_deformation): '''Returns a tuple with x and y coordinates of a flat surface Parameters ---------- surface: Surface flat surface max_deformation: float maximum deformation to make a non-flat surface flat. The normals of each face must have a dot product with the average face normal that is not less than (1-max_deformation); otherwise an exception is raised. The rationale for this option is that certain surfaces may be almost flat, and those can be made flat without problem; but surfaces that are not flat, such as inflated surfaces, should not be flattable. Returns ------- x: np.ndarray x coordinates y: np.ndarray y coordinates Notes ----- If the surface is not flat (any z coordinate is non-zero), an exception is raised. ''' s = surf.from_any(surface) face_normals = s.face_normals msk = np.all(np.logical_not(np.isnan(face_normals)), 1) avg_face_normal = s.nanmean_face_normal deformations = abs( 1 - abs(np.dot(avg_face_normal[np.newaxis], face_normals[msk].T))) too_deformed = np.nonzero(deformations > max_deformation)[0] if len(too_deformed) > 0: raise ValueError('Surface is not sufficiently flat with ' 'max_deformation=%.3f' % max_deformation) # find rotation so that surface is more or less orthogonal to # the unit vector (0,0,1) v = s.vertices z_axis = np.asarray([0, 0, 1.]) r = vector_alignment_find_rotation(avg_face_normal, z_axis) # apply rotation v_rotated = r.dot(v.T) # discard z-coordinate x = v_rotated[0] y = v_rotated[1] return x, y
def test_vector_alignment_find_rotation_canonical_vectors(self): for i in xrange(3): x = np.zeros((3,)) x[i] = 1 for j in xrange(3): y = np.zeros((3,)) y[j] = 1 r = vector_alignment_find_rotation(x, y) SurfingSurfaceTests._assert_rotation_maps_vector(r, x, y)
def test_vector_alignment_find_rotation_canonical_vectors(self): for i in xrange(3): x = np.zeros((3,)) x[i] = 1 for j in xrange(3): y = np.zeros((3,)) y[j] = 1 r = vector_alignment_find_rotation(x, y) SurfingSurfaceTests._assert_rotation_maps_vector(r, x, y)