Ejemplo n.º 1
0
 def setUpClass(cls):
     cls.pickle_file = tempfile.mktemp()
     cls.marshal_file = tempfile.mktemp()
     cls.graph = Graph({
         1: {2: 1, 4: 1},
         2: {1: 1, 3: 1, 5: 1},
         3: {2: 1, 6: 1},
         4: {1: 1, 5: 1, 7: 1},
         5: {2: 1, 4: 1, 6: 1, 8: 1},
         6: {3: 1, 5: 1, 9: 1},
         7: {4: 1, 8: 1},
         8: {5: 1, 7: 1, 9: 1},
         9: {6: 1, 8: 1},
     })
Ejemplo n.º 2
0
    def _faltten_emp(self, z_drop):
        """
        Injective Transformation of the 3D mesh of the model into a 3
        channel squared image, with satisfying properties of continuity,
        locality preservance and invariability to scaling.

        Cons : Nearest Neighbor step is time consuming and unparallelable,
        taking up to 28min for the treatment of a full scan ~500_000 vertex.

        Arguments:
            z_drop {int} -- height in mm below which the points are dropped.

        Note : z_drop used to get ride of the socle in undirectly scanned
        models. set to zero for intraoral scans and socle_free models.
        """
        A, B, _ = self.bundle

        E = [tuple(i) for i in A.vertices]
        G = [(0, 0, 0)] if B is None else [tuple(i) for i in B.vertices]

        span = np.max(E + G, axis=0)
        data = [tuple(np.divide(i, span)) for i in E]

        graph, edge = DGraph(), A.edges

        # hyperparm for z of 2ndary importance
        org = sorted(E, key=lambda x: norm(x, (span[0] / 2, 0, 25)))[0]

        # creats an undirected graph representing the mesh of the model
        # eliminating the socle points
        for e in edge:
            u, v = E[e[0]], E[e[1]]
            if min(u[2], v[2]) > z_drop:
                graph.add_edge(u, v, {'cost': norm(u, v)})
                graph.add_edge(v, u, {'cost': norm(u, v)})

        def cost_func(u, v, e, prev_e):
            return e['cost']

        predecessor = compute_paths(graph=graph, s=org, cost_func=cost_func)

        idx = index.Index('E_P', overwrite=True)
        projection = []
        nounce = 0

        for i in E:
            x, y, z = i
            try:
                # R is total_cost of getting to i
                R = get_path(predecessor, i)[3]
                projection.append(
                    cyl2cart((R, np.arctan2(y, x - org[0]), z))[0:2])

            except LookupError:
                nounce += 1
                projection.append((0, 0))

        s = np.min(projection, axis=0)
        t = np.max(projection, axis=0)

        projection = [tuple(np.subtract(p, s) / (t - s)) for p in projection]

        for n, i in enumerate(projection):
            if i != (0, 0):
                idx.add(n, i)

        # side : numbre of pixels in the side of the image
        # nounce retreaves the unused socle points
        side = int((len(data) - nounce)**(1 / 2)) + 1
        side = side + 1 if side % 2 == 0 else side
        pixels = pix_array(side)

        img = {'span': span, 'side': side}
        for i in pixels:
            try:
                n = list(idx.nearest(i, 1))[0]
                img[i] = data[n]
                idx.delete(n, img[i][0:2])

            except LookupError:
                img[i] = (0, 0, 0)

        del idx
        os.remove('E_P.dat'), os.remove('E_P.idx')

        save(img, f'flat_e_{self.id_}')
        save_as_img(img, f'flat_e_{self.id_}', pixels, side)
Ejemplo n.º 3
0
 def test_2_load(self):
     graph = Graph.load(self.pickle_file)
     self._check_graph(graph)
Ejemplo n.º 4
0
 def test_delete_node(self):
     graph = Graph(undirected=True)
     graph.add_edge(1, 2)
     graph.add_edge(1, 3)
     graph.add_edge(2, 4)
     graph.add_edge(3, 4)
     self.assertEqual(graph.edge_count, 4)
     self.assertEqual(graph.node_count, 4)
     self.assertEqual(
         graph, {
             1: {
                 2: None,
                 3: None
             },
             2: {
                 1: None,
                 4: None
             },
             3: {
                 1: None,
                 4: None
             },
             4: {
                 2: None,
                 3: None
             },
         })
     self.assertEqual(
         graph._incoming, {
             1: {
                 2: None,
                 3: None
             },
             2: {
                 1: None,
                 4: None
             },
             3: {
                 1: None,
                 4: None
             },
             4: {
                 2: None,
                 3: None
             },
         })
     del graph[1]
     self.assertEqual(graph.edge_count, 2)
     self.assertEqual(graph.node_count, 3)
     self.assertEqual(graph, {
         2: {
             4: None
         },
         3: {
             4: None
         },
         4: {
             2: None,
             3: None
         },
     })
     self.assertEqual(graph._incoming, {
         2: {
             4: None
         },
         3: {
             4: None
         },
         4: {
             2: None,
             3: None
         },
     })
     del graph[4]
     self.assertEqual(graph.edge_count, 0)
     self.assertEqual(graph.node_count, 2)
     self.assertEqual(graph, {
         2: {},
         3: {},
     })
     self.assertEqual(graph._incoming, {})
Ejemplo n.º 5
0
    def setUpClass(cls):
        # Create by adding edges
        graph1 = Graph(undirected=True)
        graph1.add_edge(1, 2)
        graph1.add_edge(1, 3)
        graph1.add_edge(2, 4)
        graph1.add_edge(3, 4)
        cls.graph1 = graph1

        # Create by adding nodes with neighbors
        graph2 = Graph(undirected=True)
        graph2.add_node(1, {2: None, 3: None})
        graph2.add_node(2, {4: None})
        graph2.add_node(3, {4: None})
        cls.graph2 = graph2

        # Create with initial data (nodes & neighbors)
        graph3 = Graph({
            1: {
                2: None,
                3: None
            },
            2: {
                4: None
            },
            3: {
                4: None
            },
        },
                       undirected=True)
        cls.graph3 = graph3
Ejemplo n.º 6
0
 def test_2_unmarshal(self):
     graph = Graph.unmarshal(self.marshal_file)
     self._check_graph(graph)
Ejemplo n.º 7
0
 def test_2_unmarshal(self):
     graph = Graph.unmarshal(self.marshal_file)
     self.assertEqual(graph, self.graph)
     self.assertEqual(graph._data, self.graph._data)
     self.assertEqual(graph._incoming, self.graph._incoming)
Ejemplo n.º 8
0
 def test_2_load(self):
     graph = Graph.load(self.pickle_file)
     self.assertEqual(graph, self.graph)
     self.assertEqual(graph._data, self.graph._data)
     self.assertEqual(graph._incoming, self.graph._incoming)