def generate_vectorfield_2articulations_1(space, a, b, c, width): """ ONLY DIMENSION 2 generates a vector field corresponding to rotation centred on the 'finger ' with 2 articulations at a and b, with ending point at c, rotating the top part of the finger (2nd 'articulation) """ dim = 2 vector_ab_unit, vector_ab_norm_orth, ab_norm = cmp.compute_vect_unit(a, b) vector_bc_unit, vector_bc_norm_orth, bc_norm = cmp.compute_vect_unit(b, c) base_points_a = [ a - 0.5 * width * vector_ab_norm_orth, a + 0.5 * width * vector_ab_norm_orth ] base_points_c = [ c - 0.5 * width * vector_bc_norm_orth, c + 0.5 * width * vector_bc_norm_orth ] points = space.points().T limit = 0.3 * width base_points_b = [] base_points_b.append( cmp.solve_intersection(base_points_a[0], vector_ab_unit, base_points_c[0], vector_bc_unit, ab_norm).copy()) base_points_b.append( cmp.solve_intersection(base_points_a[1], vector_ab_unit, base_points_c[1], vector_bc_unit, ab_norm).copy()) points_prod_0_bc_orth = space.element( sum([(points[u] - base_points_b[0][u]) * vector_bc_norm_orth[u] for u in range(dim)])) centre_rot0 = base_points_b[0].copy() centre_rot1 = base_points_b[1].copy() points = space.points().T I = generate_image_2articulations_vectfield_1(space, a, b, c, width) points_dec0 = np.array([points[u] - centre_rot0[u] for u in range(dim)]) fac0 = ((points_prod_0_bc_orth - (width + limit))**2)**(1 / 2) vect0 = fac0 * space.tangent_bundle.element(Rot_inf(points_dec0.T).T) fac1 = (((points_prod_0_bc_orth - (-limit)))**2)**(1 / 2) points_dec1 = np.array([points[u] - centre_rot1[u] for u in range(dim)]) vect1 = fac1 * space.tangent_bundle.element(Rot_inf(points_dec1.T).T) return ((vect0 + vect1) / (fac0 + fac1)) * I
def generate_image_rectangle(space, a, b, width): """ ONLY DIMENSION 2 generates a black and white image of a 'finger' with 2 articulations at a and b, with ending point at c and constant width width """ dim = 2 points = space.points().T vector_ab_unit, vector_ab_norm_orth, vector_ab_norm = cmp.compute_vect_unit( a, b) #width_list = width * vector_ab_unit limit = 0.2 * vector_ab_norm limit_orth = 0.2 * width width_list_orth = width * vector_ab_norm_orth points_prod_ab = sum([(points[u] - a[u]) * vector_ab_unit[u] for u in range(dim)]) points_prod_ab_orth = sum([ (points[u] - a[u] + 0.5 * width_list_orth[u]) * vector_ab_norm_orth[u] for u in range(dim) ]) I_arti0 = (0 - limit <= points_prod_ab) * (points_prod_ab <= vector_ab_norm + limit) I_arti0 *= (points_prod_ab_orth >= 0 - limit_orth) * (points_prod_ab_orth <= width + limit_orth) return space.element((I_arti0 == 1))
def generate_image_2articulations_vectfield(space, a, b, c, width): """ ONLY DIMENSION 2 generates a black and white image of a 'finger' with 2 articulations at a and b, with ending point at c and constant width width """ dim = 2 points = space.points().T limit = 0.3 * width vector_ab_unit, vector_ab_norm_orth, vector_ab_norm = cmp.compute_vect_unit( a, b) vector_bc_unit, vector_bc_norm_orth, vector_bc_norm = cmp.compute_vect_unit( b, c) points_prod_ab = sum([(points[u] - a[u]) * vector_ab_unit[u] for u in range(dim)]) points_prod_bc = sum([(points[u] - b[u]) * vector_bc_unit[u] for u in range(dim)]) points_prod_ab_orth = sum([(points[u] - a[u]) * vector_ab_norm_orth[u] for u in range(dim)]) points_prod_bc_orth = sum([(points[u] - b[u]) * vector_bc_norm_orth[u] for u in range(dim)]) I_arti0 = (0 - limit <= points_prod_ab) * (points_prod_ab <= vector_ab_norm + limit) I_arti0 *= (points_prod_ab_orth >= 0 - limit) * (points_prod_ab_orth <= width + limit) I_arti1 = (0 - limit <= points_prod_bc) * (points_prod_bc <= vector_bc_norm + limit) I_arti1 *= (points_prod_bc_orth >= 0 - limit) * (points_prod_bc_orth <= width + limit) return space.element((I_arti0 == 1) + (I_arti1 == 1))
def generate_vectorfield_2articulations_0(space, a, b, c, width): """ ONLY DIMENSION 2 generates a vector field corresponding to rotation on the 'finger ' with 2 articulations at a and b, with ending point at c, rotating the whole finger (1st 'articulation) """ vector_ab_unit, vector_ab_norm_orth, vector_ab_norm = cmp.compute_vect_unit( a, b) limit_ab = 0.2 * vector_ab_norm centre_rot = a - limit_ab * vector_ab_norm_orth dim = 2 points = space.points().T I = generate_image_2articulations_vectfield(space, a, b, c, width) points_a = np.array([points[u] - centre_rot[u] for u in range(dim)]) vect = space.tangent_bundle.element(Rot_inf(points_a.T).T) return vect * I
#for i in range(nbdata): # a = a_list[i] # b = b_list[i] # c = c_list[i] # vector_fields_list.append(generate_vectorfield_2articulations_0(space, a, b, c, width)) # image_list.append(generate_image_2articulations(space, a, b, c, width)) ## r_b = 4 sigma = 0.1 nbdata = 10 param = generate_random_param(nbdata, r_b) points_list = [] vectors_list = [] vector_ab_unit, vector_ab_norm_orth, ab_norm = cmp.compute_vect_unit( param.T[0][0:2], param.T[0][2:4]) nb_ab = int((ab_norm + 0.4 * ab_norm) / sigma) + 1 nb_ab_orth = int(2 * width / sigma) + 1 for i in range(nbdata): a = param.T[i][0:2] b = param.T[i][2:4] truth_temp = generate_truth_from_param(param.T[i]).copy() image_list.append(generate_image_rectangle(space, a, b, width)) vector_fields_list.append(truth_temp.copy()) points, vectors = cmp.compute_pointsvectors_rectangle_nb( a, b, 1.2 * width, sigma, nb_ab, nb_ab_orth) points_list.append(points.copy()) vectors_list.append(vectors.copy()) #
def generate_image_2articulations(space, a, b, c, width): """ ONLY DIMENSION 2 generates a black and white image of a 'finger' with 2 articulations at a and b, with ending point at c and constant width width """ dim = 2 points = space.points().T #limit = 0.0*width vector_ab_unit, vector_ab_norm_orth, ab_norm = cmp.compute_vect_unit(a, b) vector_bc_unit, vector_bc_norm_orth, bc_norm = cmp.compute_vect_unit(b, c) base_points_a = [ a - 0.5 * width * vector_ab_norm_orth, a + 0.5 * width * vector_ab_norm_orth ] base_points_c = [ c - 0.5 * width * vector_bc_norm_orth, c + 0.5 * width * vector_bc_norm_orth ] base_points_b = [] base_points_b.append( cmp.solve_intersection(base_points_a[0], vector_ab_unit, base_points_c[0], vector_bc_unit, ab_norm).copy()) base_points_b.append( cmp.solve_intersection(base_points_a[1], vector_ab_unit, base_points_c[1], vector_bc_unit, ab_norm).copy()) limit_ab = 0.2 * ab_norm limit_bc = 0.2 * bc_norm limit_orth = 0.2 * width points_prod_0_ab = sum([ (points[u] - base_points_b[0][u]) * vector_ab_unit[u] for u in range(dim) ]) points_prod_0_bc = sum([ (points[u] - base_points_b[0][u]) * vector_bc_unit[u] for u in range(dim) ]) points_prod_0_ab_orth = sum([ (points[u] - base_points_b[0][u]) * vector_ab_norm_orth[u] for u in range(dim) ]) points_prod_0_bc_orth = sum([ (points[u] - base_points_b[0][u]) * vector_bc_norm_orth[u] for u in range(dim) ]) I_arti0 = (-ab_norm - limit_ab <= points_prod_0_ab) * (points_prod_0_ab <= 0 + 0 * limit_ab) I_arti0 *= (0 <= points_prod_0_ab_orth) * (points_prod_0_ab_orth <= width + 0 * limit_orth) I_arti1 = (0 <= points_prod_0_bc) * (points_prod_0_bc <= bc_norm + limit_bc) I_arti1 *= (0 <= points_prod_0_bc_orth) * (points_prod_0_bc_orth <= width + 0 * limit_orth) return space.element((I_arti0 == 1) + (I_arti1 == 1))
r_b = 4 r_c = 4 sigma = 0.3 nbdata = 10 param = generate_random_param(nbdata, r_b, r_c) points_list = [] vectors_list = [] a= param.T[0][0:2] b= param.T[0][2:4] c= param.T[0][4:6] vector_ab_unit, vector_ab_norm_orth, ab_norm = cmp.compute_vect_unit(a, b) vector_bc_unit, vector_bc_norm_orth, bc_norm = cmp.compute_vect_unit(b, c) base_points_a = [a - 0.5*width *vector_ab_norm_orth, a + 0.5*width *vector_ab_norm_orth ] base_points_c = [c - 0.5*width *vector_bc_norm_orth, c + 0.5*width *vector_bc_norm_orth ] base_points_b = [] base_points_b.append(cmp.solve_intersection(base_points_a[0], vector_ab_unit, base_points_c[0], vector_bc_unit, ab_norm).copy()) base_points_b.append(cmp.solve_intersection(base_points_a[1], vector_ab_unit, base_points_c[1], vector_bc_unit, ab_norm).copy()) vector_points_b_unit, vector_points_b_norm_orth, points_b_norm = cmp.compute_vect_unit(base_points_b[0], base_points_b[1]) n_orth = int((points_b_norm + 0.2*width) / sigma) +1 nb_ab = int((ab_norm + 0.2*width) / sigma) +1 nb_bc = int((bc_norm + 0.2*width) / sigma) +1