Ejemplo n.º 1
0
    def __init__(self,
                 pv_points,
                 pv_vectors,
                 tri_mesh_obj,
                 consider_collision_with_object,
                 radio_ratio=2):
        '''
        Measures the max reachable distance of provenances vectors in a interaction
        :param pv_points: IBS key points, origin of provenance vectors
        :param pv_vectors: Provenance vectors
        :param tri_mesh_obj: objects triangular mesh
        :param consider_collision_with_object: consider collision with object to determine ray intersections
        '''
        self.consider_collision_with_object = consider_collision_with_object
        self.radio_ratio = radio_ratio
        self.influence_radio, self.influence_center = util.influence_sphere(
            tri_mesh_obj, radio_ratio)

        self.sphere_of_influence = trimesh.primitives.Sphere(
            radius=self.influence_radio,
            center=self.influence_center,
            subdivisions=5)

        expected_intersections = pv_points + pv_vectors

        scene_to_collide_rays = self.sphere_of_influence

        # measure collision with object itself
        if self.consider_collision_with_object:
            scene_to_collide_rays += tri_mesh_obj

        # looking for the nearest ray intersections
        (__, idx_ray,
         calculated_intersections) = scene_to_collide_rays.ray.intersects_id(
             ray_origins=pv_points,
             ray_directions=pv_vectors,
             return_locations=True,
             multiple_hits=False)

        self.max_distances = np.linalg.norm(calculated_intersections -
                                            expected_intersections,
                                            axis=1)
        self.sum_max_distances = np.sum(self.max_distances)
Ejemplo n.º 2
0
                                                   'tri_mesh_env']))
            tri_mesh_obj = trimesh.load_mesh(
                os.path.join(directory, to_test.at[index_label,
                                                   'tri_mesh_obj']))

            o3d_cloud_sources_ibs = o3d.io.read_point_cloud(
                os.path.join(directory, to_test.at[index_label,
                                                   'o3d_cloud_sources_ibs']))
            np_cloud_env = np.asarray(o3d_cloud_sources_ibs.points)

            tri_mesh_ibs = trimesh.load_mesh(
                os.path.join(directory, to_test.at[index_label,
                                                   'tri_mesh_ibs']))

            influence_radio_ratio = 1.2
            sphere_ro, sphere_center = util.influence_sphere(
                tri_mesh_obj, influence_radio_ratio)
            tri_mesh_ibs_segmented = util.slide_mesh_by_sphere(
                tri_mesh_ibs, sphere_center, sphere_ro)

            for rate_r in range(2, 40, 2):

                rate_ibs_samples = rate_s
                rate_random_samples = rate_r

                start = time.time()  # timing execution

                sampler_poissondisc_weighted = PoissonDiscWeightedSampler(
                    rate_ibs_samples, rate_random_samples)
                trainer_weighted = Trainer(tri_mesh_ibs_segmented,
                                           tri_mesh_env,
                                           sampler_poissondisc_weighted)
Ejemplo n.º 3
0
    environment = trimesh.load_mesh('./data/it/gates400.ply', process=False)

    # testing_point = [-0.48689266781021423, -0.15363679409350514,0.8177121144402457]
    testing_point = [-0.97178262, -0.96805501,
                     0.82738298]  #in the edge of table, but with floor
    # testing_point = [-2.8, 1., 0.00362764]  # half inside the scene, half outside

    testing_point = [0, 0, 0]

    influence_radio_ratio = 1.0

    # visualizing
    tri_mesh_object_file = tester.objs_filenames[0]
    tri_mesh_obj = trimesh.load_mesh(tri_mesh_object_file, process=False)
    ro, center = util.influence_sphere(tri_mesh_obj,
                                       radio_ratio=influence_radio_ratio)

    influence_sphere = trimesh.primitives.Sphere(radius=ro,
                                                 center=center,
                                                 subdivisions=5)

    pv_points = tester.compiled_pv_begin[0:512]
    pv_vectors = tester.compiled_pv_direction[0:512]

    expected_pv_end = pv_points + pv_vectors

    # looking for the nearest ray intersections
    (__, idx_ray, intersections) = influence_sphere.ray.intersects_id(
        ray_origins=pv_points,
        ray_directions=pv_vectors,
        return_locations=True,
Ejemplo n.º 4
0
    od3_cloud_env_poisson = o3d.io.read_point_cloud('./data/ibs/cloud_env_1000_points.pcd')
    od3_cloud_obj_poisson = o3d.io.read_point_cloud('./data/ibs/cloud_obj_1000_points.pcd')

    np_cloud_env_poisson = np.asarray(od3_cloud_env_poisson.points)
    np_cloud_obj_poisson = np.asarray(od3_cloud_obj_poisson.points)

    print("IBS calculation ...")
    start = time.time()  # timing execution
    ibs_calculator = IBS(np_cloud_env_poisson, np_cloud_obj_poisson)
    end = time.time()  # timing execution
    print(end - start, " seconds on IBS calculation (2,000 points)")  # timing execution

    # ### VISUALIZATION

    tri_mesh_obj = trimesh.load_mesh("./data/interactions/table_bowl/bowl.ply")
    radio, np_pivot = util.influence_sphere(tri_mesh_obj, radio_ratio=influence_radio_ratio)

    [idx_extracted, np_ibs_vertices_extracted] = util.extract_cloud_by_sphere(ibs_calculator.vertices, np_pivot, radio)

    edges_from, edges_to = util.get_edges(ibs_calculator.vertices, ibs_calculator.ridge_vertices, idx_extracted)

    tri_cloud_obj = trimesh.points.PointCloud(np.asarray(od3_cloud_obj_poisson.points), colors=[0, 255, 0, 255])
    tri_cloud_env = trimesh.points.PointCloud(np.asarray(od3_cloud_env_poisson.points), colors=[100, 100, 100, 255])

    tri_cloud_ibs_vertices_extracted = trimesh.points.PointCloud(np_ibs_vertices_extracted, colors=[0, 0, 255, 255])
    tri_path_ibs_edges_extracted = trimesh.load_path(np.hstack((edges_from, edges_to)).reshape(-1, 2, 3))

    visualizer = trimesh.Scene([tri_cloud_ibs_vertices_extracted, tri_cloud_obj,
                                tri_cloud_env, tri_path_ibs_edges_extracted])

    # display the environment with callback
    interactions_data = pd.read_csv("./data/interactions/interaction.csv")
    to_test = 'hang_boater'
    interaction = interactions_data[interactions_data['interaction'] ==
                                    to_test]
    tri_mesh_env = trimesh.load_mesh(
        os.path.join(interaction.iloc[0]['directory'],
                     interaction.iloc[0]['tri_mesh_env']))
    tri_mesh_obj = trimesh.load_mesh(
        os.path.join(interaction.iloc[0]['directory'],
                     interaction.iloc[0]['tri_mesh_obj']))
    obj_name = interaction.iloc[0]['obj']
    env_name = interaction.iloc[0]['env']

    influence_radio_bb = 2

    extension, middle_point = util.influence_sphere(
        tri_mesh_obj, radio_ratio=influence_radio_bb)

    tri_mesh_env_segmented = util.slide_mesh_by_bounding_box(
        tri_mesh_env, middle_point, extension)

    influence_radio_ratio = 1.5

    # calculating cropping sphere parameters
    radio, np_pivot = util.influence_sphere(tri_mesh_obj,
                                            radio_ratio=influence_radio_ratio)

    # execution parameters
    improve_by_collision = True
    in_collision = True
    resamplings = 2
    sampled_points = 600
Ejemplo n.º 6
0
    interactions_data = pd.read_csv("./data/interactions/interaction.csv")
    to_test = 'place'
    interaction = interactions_data[interactions_data['interaction'] ==
                                    to_test]
    tri_mesh_env = trimesh.load_mesh(
        os.path.join(interaction.iloc[0]['directory'],
                     interaction.iloc[0]['tri_mesh_env']))
    tri_mesh_obj = trimesh.load_mesh(
        os.path.join(interaction.iloc[0]['directory'],
                     interaction.iloc[0]['tri_mesh_obj']))
    obj_name = interaction.iloc[0]['obj']
    env_name = interaction.iloc[0]['env']

    influence_radio_ratio = 1.5

    extension, middle_point = util.influence_sphere(
        tri_mesh_obj, radio_ratio=influence_radio_ratio)

    tri_mesh_env_segmented = util.slide_mesh_by_bounding_box(
        tri_mesh_env, middle_point, extension)

    start = time.time()  # timing execution
    ibs_calculator = IBSMesh(600, 2)
    ibs_calculator.execute(tri_mesh_env_segmented, tri_mesh_obj)
    end = time.time()  # timing execution
    print(end - start, " seconds on IBS calculation (600 original points)"
          )  # timing execution

    ################################
    # GENERATING AND SEGMENTING IBS MESH
    ################################
    start = time.time()  # timing execution