Example #1
0
    def _condense_one(self, cutoff):
        """
        Condenses two adjacent projection points into one.

        :returns: True if a condensation was done, False if no condenstaion is possible.
        """
        for i, node1 in enumerate(self.proj_graph.nodes()):
            for j, node2 in enumerate(self.proj_graph.nodes()):
                if j <= i: continue
                if ftuv.vec_distance(node1, node2) < cutoff:
                    newnode = ftuv.middlepoint(node1, node2)
                    #self.proj_graph.add_node(newnode)
                    for neighbor in list(self.proj_graph.adj[node1].keys()):
                        self.proj_graph.add_edge(
                            newnode,
                            neighbor,
                            attr_dict=self.proj_graph.adj[node1][neighbor])
                    for neighbor in list(self.proj_graph.adj[node2].keys()):
                        self.proj_graph.add_edge(
                            newnode,
                            neighbor,
                            attr_dict=self.proj_graph.adj[node2][neighbor])
                    if newnode != node1:  #Equality can happen because of floating point inaccuracy
                        self.proj_graph.remove_node(node1)
                    if newnode != node2:
                        self.proj_graph.remove_node(node2)
                    return True
        return False
Example #2
0
 def _condense_pointWithLine_step(self, cutoff):
     """
     Used by `self.condense(cutoff)` as a single condensation step of a point
     with a line segment.
     """
     for i, source in enumerate(self.proj_graph.nodes()):
         for j, target in enumerate(self.proj_graph.nodes()):
             if j > i and self.proj_graph.has_edge(source, target):
                 for k, node in enumerate(self.proj_graph.nodes()):
                     if k == i or k == j:
                         continue
                     nearest = ftuv.closest_point_on_seg(
                         source, target, node)
                     nearest = tuple(nearest)
                     if nearest == source or nearest == target:
                         continue
                     if (ftuv.vec_distance(nearest, node) < cutoff):
                         newnode = ftuv.middlepoint(node, tuple(nearest))
                         attr_dict = self.proj_graph.adj[source][target]
                         self.proj_graph.remove_edge(source, target)
                         if source != newnode:
                             self.proj_graph.add_edge(
                                 source, newnode, attr_dict=attr_dict)
                         if target != newnode:
                             self.proj_graph.add_edge(target, newnode,
                                                      attr_dict=attr_dict)
                         if newnode != node:  # Equality possible bcse of floating point inaccuracy
                             for neighbor in self.proj_graph.adj[node].keys():
                                 attr_dict = self.proj_graph.adj[node][neighbor]
                                 self.proj_graph.add_edge(newnode, neighbor,
                                                          attr_dict=attr_dict)
                             self.proj_graph.remove_node(node)
                         return True
     return False
Example #3
0
    def _condense_one(self, cutoff):
        """
        Condenses two adjacent projection points into one.

        :returns: True if a condensation was done, False if no condenstaion is possible.
        """
        for i, node1 in enumerate(self.proj_graph.nodes()):
            for j, node2 in enumerate(self.proj_graph.nodes()):
                if j <= i:
                    continue
                if ftuv.vec_distance(node1, node2) < cutoff:
                    newnode = ftuv.middlepoint(node1, node2)
                    # self.proj_graph.add_node(newnode)
                    for neighbor in list(self.proj_graph.adj[node1].keys()):
                        self.proj_graph.add_edge(newnode, neighbor,
                                                 attr_dict=self.proj_graph.adj[node1][neighbor])
                    for neighbor in list(self.proj_graph.adj[node2].keys()):
                        self.proj_graph.add_edge(newnode, neighbor,
                                                 attr_dict=self.proj_graph.adj[node2][neighbor])
                    if newnode != node1:  # Equality can happen because of floating point inaccuracy
                        self.proj_graph.remove_node(node1)
                    if newnode != node2:
                        self.proj_graph.remove_node(node2)
                    return True
        return False
Example #4
0
 def test_middlepoint(self):
     self.assertIsInstance(ftuv.middlepoint((1,2,3),(4,5,6)), tuple)
     self.assertIsInstance(ftuv.middlepoint([1,2,3],[4,5,6]), list)
     self.assertIsInstance(ftuv.middlepoint(np.array([1,2,3]),np.array([4,5,6])), type(np.array([1,2,3])))
     self.assertEqual(ftuv.middlepoint((1,2),(3,4)), (2,3))
     self.assertEqual(ftuv.middlepoint([1,2,3],[5,6,7]), [3,4,5])
     mp=ftuv.middlepoint(np.array([1,2,-3]),np.array([1,0,-5]))
     self.assertTrue(((mp==np.array([1,1,-4])).all()), msg="Middlepoint for np arrays: {} "
                                                   "is not {}".format(mp, np.array([1,1,-4])))
Example #5
0
 def test_middlepoint(self):
     self.assertIsInstance(ftuv.middlepoint((1, 2, 3), (4, 5, 6)), tuple)
     self.assertIsInstance(ftuv.middlepoint([1, 2, 3], [4, 5, 6]), list)
     self.assertIsInstance(
         ftuv.middlepoint(np.array([1, 2, 3]), np.array([4, 5, 6])),
         type(np.array([1, 2, 3])))
     self.assertEqual(ftuv.middlepoint((1, 2), (3, 4)), (2, 3))
     self.assertEqual(ftuv.middlepoint([1, 2, 3], [5, 6, 7]), [3, 4, 5])
     mp = ftuv.middlepoint(np.array([1, 2, -3]), np.array([1, 0, -5]))
     self.assertTrue(((mp == np.array([1, 1, -4])).all()),
                     msg="Middlepoint for np arrays: {} "
                     "is not {}".format(mp, np.array([1, 1, -4])))
Example #6
0
 def _condense_pointWithLine_step(self, cutoff):
     """
     Used by `self.condense(cutoff)` as a single condensation step of a point
     with a line segment.
     """
     for i, source in enumerate(self.proj_graph.nodes()):
         for j, target in enumerate(self.proj_graph.nodes()):
             if j > i and self.proj_graph.has_edge(source, target):
                 for k, node in enumerate(self.proj_graph.nodes()):
                     if k == i or k == j:
                         continue
                     nearest = ftuv.closest_point_on_seg(
                         source, target, node)
                     nearest = tuple(nearest)
                     if nearest == source or nearest == target:
                         continue
                     if (ftuv.vec_distance(nearest, node) < cutoff):
                         newnode = ftuv.middlepoint(node, tuple(nearest))
                         attr_dict = self.proj_graph.adj[source][target]
                         self.proj_graph.remove_edge(source, target)
                         if source != newnode:
                             self.proj_graph.add_edge(source,
                                                      newnode,
                                                      attr_dict=attr_dict)
                         if target != newnode:
                             self.proj_graph.add_edge(target,
                                                      newnode,
                                                      attr_dict=attr_dict)
                         if newnode != node:  #Equality possible bcse of floating point inaccuracy
                             for neighbor in self.proj_graph.adj[node].keys(
                             ):
                                 attr_dict = self.proj_graph.adj[node][
                                     neighbor]
                                 self.proj_graph.add_edge(
                                     newnode, neighbor, attr_dict=attr_dict)
                             self.proj_graph.remove_node(node)
                         return True
     return False