Example #1
0
 def test_convert_xyz_returns_correct_X_Y_Z_for_simple_array(self):
     test_array = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]])
     result = GLConverter().convert_xyz(test_array)
     self.assertEqual((4, 8), result.shape)
     self.assertListAlmostEqual([1, 1, 1], result[0][:3])
     self.assertListAlmostEqual([2, 2, 2], result[1][:3])
     self.assertListAlmostEqual([3, 3, 3], result[2][:3])
     self.assertListAlmostEqual([4, 4, 4], result[3][:3])
Example #2
0
 def test_convert_xyz_returns_correct_X_Y_Z_for_simple_array_with_scale(
         self):
     test_array = np.array([[9, 8, 8], [7, 6, 8], [5, 4, 8], [3, 2, 8]])
     result = GLConverter().convert_xyz(test_array, scale=0.1)
     self.assertEqual((4, 8), result.shape)
     self.assertListAlmostEqual([0.9, 0.8, 0.8], result[0, :3])
     self.assertListAlmostEqual([0.7, 0.6, 0.8], result[1, :3])
     self.assertListAlmostEqual([0.5, 0.4, 0.8], result[2, :3])
     self.assertListAlmostEqual([0.3, 0.2, 0.8], result[3, :3])
Example #3
0
 def test_convert_xyz_calculates_texture_coordanates(self):
     test_array = np.array([[1, 1, 1], [-1, -1, -1], [-1, 1, 1],
                            [1, -1, -1]])
     result = GLConverter().convert_xyz(test_array)
     self.assertEqual((4, 8), result.shape)
     self.assertListAlmostEqual([0.125, 0.644], result[0, 6:8], decimals=3)
     self.assertListAlmostEqual([0.625, 0.356], result[1, 6:8], decimals=3)
     self.assertListAlmostEqual([0.875, 0.644], result[2, 6:8], decimals=3)
     self.assertListAlmostEqual([0.375, 0.356], result[3, 6:8], decimals=3)
Example #4
0
 def test_convert_xyz_calculates_simple_normals(self):
     test_array = np.array([[9, 8, 8], [7, 6, 8], [5, 4, 8], [3, 2, 8]])
     unit_vectors = test_array / np.linalg.norm(test_array)
     result = GLConverter().convert_xyz(test_array)
     self.assertEqual((4, 8), result.shape)
     self.assertListAlmostEqual(unit_vectors[0], result[0, 3:6])
     self.assertListAlmostEqual(unit_vectors[1], result[1, 3:6])
     self.assertListAlmostEqual(unit_vectors[2], result[2, 3:6])
     self.assertListAlmostEqual(unit_vectors[3], result[3, 3:6])
Example #5
0
 def test_convert_xyz_is_fast(self):
     points = 10000
     test_array = np.random.rand(points, 3)
     start = time.time()
     result = GLConverter().convert_xyz(test_array)
     total = time.time() - start
     print "Total time: {}".format(total)
     print "ms per point: {}".format((total * 1000) / points)
     print "pps: {:.0f}".format(points / total)
     self.assertTrue(total < 1 / 120.0)
Example #6
0
 def setUp(self):
     self.stub_point_thinner = StubPointThinner()
     self.writer = PLYWriter(GLConverter(), self.stub_point_thinner)
Example #7
0
 def __init__(self, scanner, **kwargs):
     super(PointsCapture, self).__init__(**kwargs)
     self.scanner = scanner
     self._converter = GLConverter()
     self.raw_points_xyz = np.array([])
Example #8
0
class PointsCapture(Screen):
    def __init__(self, scanner, **kwargs):
        super(PointsCapture, self).__init__(**kwargs)
        self.scanner = scanner
        self._converter = GLConverter()
        self.raw_points_xyz = np.array([])

    def on_pre_enter(self):
        self.go_buttons.clear_widgets()
        self.clear()
        laser_pos = [("{: 5.2f}".format(np.rad2deg(rad)), rad) for rad in self.scanner.get_scanner_posisitions()]
        for (human, rad) in laser_pos:
            button = GoButton(rad, self.start_points_capture, text=str(human))
            self.go_buttons.add_widget(button)

    def on_leave(self):
        self.go_buttons.clear_widgets()
        self.clear()

    def clear(self,):
        # self.image_box.clear()
        self.render.clear()
        self.raw_points_xyz = np.array([])

    def start_points_capture(self, theta):
        self._disable_all()
        points = self.raw_points_xyz if self.raw_points_xyz.size != 0 else None
        self.scanner.capture_points_xyz(theta, points=points, call_back=self._capture_points_callback)
        # self.scanner.capture_image(self._capture_image_callback, 200 - 25)

    # def _capture_image_callback(self, handler):
    #     self._image = handler.image
    #     Clock.schedule_once(self._update_image)

    def _capture_points_callback(self, handler):
        self.raw_points_xyz = handler.points_xyz
        self.progress.value = int(handler.status * 100)
        if handler.complete:
            self._enable_all()
            # Logger.info('Done: {}'.format(self.raw_points_tyr))
            self.save_button.disabled = False
        Clock.unschedule(self.update_model)
        Clock.schedule_once(self.update_model)

    def dismiss_popup(self):
        self._popup.dismiss()

    def show_save(self):
        content = SaveDialog(save=self.save_points, cancel=self.dismiss_popup)
        self._popup = Popup(title="Save file", content=content,
                            size_hint=(0.9, 0.9))
        self._popup.open()

    def save_points(self, path, filename):
        with open(os.path.join(path, filename), 'w') as afile:
            thinner = PointThinner()
            converter = GLConverter()
            PLYWriter(converter, thinner).write_cartisien_points(afile, self.raw_points_xyz)
        self.dismiss_popup()

    def _enable_all(self):
        self.go_buttons.disabled = False
        self.clear_button.disabled = False

    def _disable_all(self):
        self.go_buttons.disabled = True
        self.clear_button.disabled = True

    # def _update_image(self, *args):
    #     if hasattr(self, '_image'):
    #         self.image_box.set_image(self._image)
    #         self.render.update_texture(self.image_box.texture)

    def update_model(self, *largs):
        amax = np.amax(self.raw_points_xyz)
        if amax > 0:
            scale = min(0.05, 1.0 / np.amax(self.raw_points_xyz))

            points = self._converter.convert_xyz(self.raw_points_xyz, scale=scale)
            self.render.update_mesh(points)
Example #9
0
 def save_points(self, path, filename):
     with open(os.path.join(path, filename), 'w') as afile:
         thinner = PointThinner()
         converter = GLConverter()
         PLYWriter(converter, thinner).write_cartisien_points(afile, self.raw_points_xyz)
     self.dismiss_popup()
Example #10
0
 def test_convert_xyz_returns_empty_for_empty_array(self):
     result = GLConverter().convert_xyz(np.array([]))
     self.assertEqual(0, len(result))