Skip to content

Segmentation_Dijkstra_litt

affichesegmlitt Link

affichesegmlitt(pcd, G, segmentdict, c)

Displays a 3D point cloud and its corresponding graph representation.

This function visualizes a 3D point cloud along with its graph structure. It creates a graph representation where nodes correspond to the points in the point cloud, and edges are defined based on the provided segment dictionary. The visualization allows the user to see the structure of the graph overlayed on the point cloud.

Parameters:

  • pcd (PointCloud) –

    The 3D point cloud to be visualized.

  • G (Graph) –

    The base graph structure associated with the point cloud.

  • segmentdict (dict[int, list[int]]) –

    A dictionary where each key is a segment index and the value is a list of point indices representing a path in the graph.

  • c (int) –

    The number of graph segments to visualize. Segments in the range [1, c-1] from the segment dictionary are visualized.

Source code in spectral_clustering/Segmentation_Dijkstra_litt.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def affichesegmlitt(pcd, G, segmentdict, c):
    """Displays a 3D point cloud and its corresponding graph representation.

    This function visualizes a 3D point cloud along with its graph structure.
    It creates a graph representation where nodes correspond to the points in
    the point cloud, and edges are defined based on the provided segment
    dictionary. The visualization allows the user to see the structure of
    the graph overlayed on the point cloud.

    Parameters
    ----------
    pcd : open3d.geometry.PointCloud
        The 3D point cloud to be visualized.
    G : networkx.Graph
        The base graph structure associated with the point cloud.
    segmentdict : dict[int, list[int]]
        A dictionary where each key is a segment index and the value is a list
        of point indices representing a path in the graph.
    c : int
        The number of graph segments to visualize. Segments in the range
        [1, c-1] from the segment dictionary are visualized.

    """
    Gaffichage = nx.Graph()
    pts = np.array(pcd.points)
    N = len(pcd.points)
    for i in range(N):
        Gaffichage.add_node(i, pos=pts[i])
    for i in range(1, c):
        Gaffichage.add_path(segmentdict[i])
    edgelist = Gaffichage.edges
    print(Gaffichage.edges)
    cloption = o3d.visualization.RenderOption()
    graph = o3d.geometry.LineSet()
    graph.points = o3d.utility.Vector3dVector(pts)
    graph.lines = o3d.utility.Vector2iVector(edgelist)
    o3d.visualization.draw_geometries([graph, pcd])

sortienuagelitt Link

sortienuagelitt(pcd, G, segmentdict, c)

Sorts segments and labels points based on the shortest paths in a graph.

This function processes a point cloud and a graph representing segments, calculates the shortest paths from specified segments to all other points, and labels each point in the point cloud according to the segment it is associated with or assigns a default label if no segment is reachable. It outputs a classified point cloud with these labels.

Parameters:

  • pcd (PointCloud) –

    A point cloud object representing the spatial data. It is expected to have points that need to be classified.

  • G (MultiDiGraph) –

    A graph containing nodes and edges representing segments. The nodes correspond to points or locations in the graph, and the edges have associated weights used for shortest path calculations.

  • segmentdict (dict) –

    A dictionary where keys are segment identifiers (int or str) and values are lists of points or segment nodes. These represent specific paths or segments in the graph for label assignment.

  • c (int) –

    A default label assigned to points that do not belong to any segment or do not have a reachable shortest path.

Notes

The function saves the resulting classified point cloud data as a text file named pcdclassifdijkstra2.txt.

Raises:

  • ValueError

    If certain values could not be processed or matched during the segment identification process in the segment dictionary.

Source code in spectral_clustering/Segmentation_Dijkstra_litt.py
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def sortienuagelitt(pcd, G, segmentdict, c):
    """Sorts segments and labels points based on the shortest paths in a graph.

    This function processes a point cloud and a graph representing segments,
    calculates the shortest paths from specified segments to all other points,
    and labels each point in the point cloud according to the segment it is
    associated with or assigns a default label if no segment is reachable.
    It outputs a classified point cloud with these labels.

    Parameters
    ----------
    pcd : open3d.geometry.PointCloud
        A point cloud object representing the spatial data. It is expected
        to have points that need to be classified.
    G : networkx.classes.multidigraph.MultiDiGraph
        A graph containing nodes and edges representing segments. The nodes
        correspond to points or locations in the graph, and the edges have
        associated weights used for shortest path calculations.
    segmentdict : dict
        A dictionary where keys are segment identifiers (int or str) and
        values are lists of points or segment nodes. These represent specific
        paths or segments in the graph for label assignment.
    c : int
        A default label assigned to points that do not belong to any segment
        or do not have a reachable shortest path.

    Notes
    -----
    The function saves the resulting classified point cloud data as a text file named `pcdclassifdijkstra2.txt`.

    Raises
    ------
    ValueError
        If certain values could not be processed or matched during
        the segment identification process in the segment dictionary.
    """
    label = []
    chemintot = []
    N = len(pcd.points)
    for Seg, chemin in segmentdict.items():
        chemintot = chemintot + chemin
    # Transformation de la liste obtenue en set
    setsegments = set(chemintot)
    length, path = nx.multi_source_dijkstra(G, setsegments, weight='weight')
    for p in range(N):
        if p in length:
            # Sélection du chemin qui concerne le point d'intérêt
            j = 1
            ind = -1
            if length[p] == 0:
                parrive = p
            else:
                parrive = path[p][0]
            while ind == -1 and j < c:
                try:
                    ind = segmentdict[j].index(parrive)
                except ValueError:
                    ind = -1
                j = j + 1
            j = j - 1
            label = label + [j]
        else:
            label = label + [c]
    label = np.asarray(label)
    label = np.asarray(label.reshape(np.asarray(pcd.points).shape[0], 1), dtype=np.float64)
    pcdtabclassif = np.concatenate([np.asarray(pcd.points), label], axis=1)
    # FIXME: this should be a parameter:
    np.savetxt('pcdclassifdijkstra2.txt', pcdtabclassif, delimiter=",")