def __init__(self): super(PointsShow, self).__init__() self._screen_size = QApplication.primaryScreen().size() # WIDGET self._widget = QWidget(self) self._widget.setAttribute(Qt.WA_TranslucentBackground) self.setCentralWidget(self._widget) self._widget.resize(self._screen_size) # VTK self._vtk_widget = QVTKRenderWindowInteractor(self._widget) self._vtk_widget.SetInteractorStyle(all.vtkInteractorStyleMultiTouchCamera()) self._vtk_widget.resize(self._screen_size) self._ren_win = self._vtk_widget.GetRenderWindow() self._render = all.vtkRenderer() sw, sh = self._screen_size.width(), self._screen_size.height() self.resize(int(sw * 0.9), int(sh * 0.9)) self.move(int(sw * (1 - 0.8) / 2), int(sh * (1 - 0.8) / 2)) # POINTS self._points = VtkPoints(size=3, opacity=1) self._render.AddActor(self._points.actor) # LINE self._lines = VtkLine(color=(1, 0, 0), width=4) self._lines.set_point([0.0, 0.0, 0.0]) self._lines.set_point([1.0, 0.0, 0.0]) self._lines.set_line(0, 0) self._render.AddActor(self._lines.actor) # COPY_FUN self.add_points = self._points.add_points self.set_color = self._points.set_color # SHOW self._ren_win.AddRenderer(self._render) self._vtk_widget.Start() self._render.Render()
def __init__(self): super(Vtk, self).__init__() self._screen_size = QApplication.primaryScreen().size() # WIDGET self._widget = QWidget(self) self._widget.setAttribute(Qt.WA_TranslucentBackground) self.setCentralWidget(self._widget) self._widget.resize(self._screen_size) # VTK self._vtk_widget = QVTKRenderWindowInteractor(self._widget) self._vtk_widget.SetInteractorStyle( all.vtkInteractorStyleMultiTouchCamera()) self._vtk_widget.resize(self._screen_size) self._ren_win = self._vtk_widget.GetRenderWindow() self._render = all.vtkRenderer() sw, sh = self._screen_size.width(), self._screen_size.height() self.resize(int(sw * 0.9), int(sh * 0.9)) self.move(int(sw * (1 - 0.8) / 2), int(sh * (1 - 0.8) / 2)) # POINTS self._points = Point(pos=(10, 10, 10), size=1, color=(100, 0, 0)) self._render.AddActor(self._points.actor) for column in range(1): for row in range(1): self._points.points.InsertNextPoint(row * 0.125, 1 - column * 0.016, 0) self._points.points.Modified() # VTK_SHOW self._ren_win.AddRenderer(self._render) self._vtk_widget.Start() self._render.Render()
def __init__(self): super(LedShow, self).__init__() self.resize(2000, 1500) # WIDGET self._widget = QWidget(self) self.setCentralWidget(self._widget) self._widget.setAttribute(Qt.WA_TranslucentBackground) self._widget.resize(2000, 1500) # VTK self._vtk_widget = QVTKRenderWindowInteractor(self._widget) self._vtk_widget.SetInteractorStyle( all.vtkInteractorStyleMultiTouchCamera()) self._ren_win = self._vtk_widget.GetRenderWindow() self._render = all.vtkRenderer() self._vtk_widget.resize(2000, 1500) # POINTS self._points = Points(render=self._render) self._ren_win.AddRenderer(self._render) self._vtk_widget.Start() # HANDLE self._handle = HandleVideo(rbg_callback=self._rgb_callback, video_path=os.getcwd()) # TIMER self._timer = QTimer() self._timer.start(100) self._timer.timeout.connect(self._render_once)
def __init__(self, ui: Ui_MainWindow, led: LedWall): super().__init__() # SIGNAL SIGNAL.sign_is_online.connect(self._is_online) self._screen_size = QApplication.primaryScreen().size() # WIDGET self._widget = QWidget(self) self._widget.setAttribute(Qt.WA_TranslucentBackground) self.setCentralWidget(self._widget) self.resize(self._screen_size) self._widget.setStyleSheet(""" QWidget { border: 1px solid black; background-color: rgba(255, 255, 255, 0.2); } """) # VTK_WIDGET self._vtk_widget = QVTKRenderWindowInteractor(self._widget) self._vtk_widget.SetInteractorStyle(all.vtkInteractorStyleMultiTouchCamera()) self._vtk_widget.resize(self._screen_size) self._ren_win = self._vtk_widget.GetRenderWindow() self._render = VtkRenderer(ren_win=self._ren_win) # SCREEN_SIZE sw, sh = self._screen_size.width(), self._screen_size.height() self.resize(int(sw * 0.7), int(sh * 0.7)) self.move(int(sw * 0.3 / 2), int(sh * 0.3 / 2)) # UI self._ui = ui self._ui.setupUi(self._widget) # TCP_LED self._tcp_led = {1: self._ui.led_bot1, 2: self._ui.led_bot2} # LED self._led = led self._led.set_render(render=self._render) # BTN self._ui.link.stateChanged.connect(self._set_link) # COLOR self._ui.btn_r.clicked.connect(self._set_r) self._ui.btn_g.clicked.connect(self._set_g) self._ui.btn_b.clicked.connect(self._set_b) self._ui.btn_colorful.clicked.connect(self._set_colorful) # SHOW self._ui.btn_img.clicked.connect(self._read_img) self._ui.btn_video.clicked.connect(self._read_video) # VTK_START self._vtk_widget.Start()
def __init__(self): super(PointsDisplay, self).__init__() # WIDGET self.resize(2000, 1000) self._widget = QWidget(self) self._widget.setAttribute(Qt.WA_TranslucentBackground) self.setCentralWidget(self._widget) self._widget.resize(2000, 1000) # VTK_WIDGET self._vtk_widget = QVTKRenderWindowInteractor(self._widget) self._vtk_widget.SetInteractorStyle(all.vtkInteractorStyleMultiTouchCamera()) self._ren_win = self._vtk_widget.GetRenderWindow() self._render = all.vtkRenderer() self._vtk_widget.resize(2000, 1000) # POINTS self._points = Points(render=self._render) self._ren_win.AddRenderer(self._render) self._vtk_widget.Start() # RENDER rgb_dict = dict() for idx, rgb in enumerate(rgb_data): rgb_dict[idx] = rgb new_rgb_dict = rgb_dict self._render.Render() a = list() for i in range(9600): a.append(i) b = np.array(a).reshape(64, 150) c = list(b) for idx, one_list in enumerate(c): if idx % 2 != 0: c[idx] = list(reversed(one_list)) d = np.array(c) cid = 0 for one_list in list(d.T): for id in one_list: new_rgb_dict[id] = rgb_dict[cid] # print(f'new={id} old={cid}') cid += 1 for key, rgb in new_rgb_dict.items(): self._points.set_point_color(key, rgb) self._render.Render()
def __init__(self, render_frequency: float, window_zoom: int = 0.7): super().__init__() self._screen_size = QApplication.primaryScreen().size() self._central_widget = QWidget(self) self._central_widget.setAttribute(Qt.WA_AcceptTouchEvents | Qt.WA_TranslucentBackground) self._central_widget.setWindowFlags(Qt.NoDropShadowWindowHint) self._central_widget.resize(self._screen_size) self._vtk_widget = QVTKRenderWindowInteractor(self._central_widget) self._vtk_widget.SetInteractorStyle( vtk.vtkInteractorStyleMultiTouchCamera()) self._vtk_widget.resize(self._screen_size) self.setCentralWidget(self._central_widget) sw, sh = self._screen_size.width(), self._screen_size.height() self.resize(sw * window_zoom, sh * window_zoom) self.move(sw * (1 - window_zoom) / 2, sh * (1 - window_zoom) / 2) self._central_widget.setFocus() # UI # self._ui = Ui_Form() # self._ui.setupUi(Form=self._central_widget) for widget in self._central_widget.children(): widget.setStyleSheet(f""" QGroupBox {{ background-color: rgba(200, 200, 200, 1); border-radius: 5; }}""") # QT_STYLE self.setWindowFlags(Qt.NoDropShadowWindowHint) self._render = vtk.vtkRenderer() self._ren_win = self._vtk_widget.GetRenderWindow() self._ren_win.AddRenderer(self._render) self._interactor = self._ren_win.GetInteractor() # TIMER self._timer = QTimer() self._timer.setInterval(int(1000 / render_frequency)) self._timer.timeout.connect(self._working) self._is_running = False self.set_render_ena(False)
def __init__(self): stl_writer = vtk.vtkSTLWriter() append_poly = vtk.vtkAppendPolyData() reader1 = vtk.vtkSTLReader() reader1.SetFileName(file1) reader1.Update() reader2 = vtk.vtkSTLReader() reader2.SetFileName(file2) reader2.Update() mapper1 = vtk.vtkPolyDataMapper() mapper1.SetInputData(vtk.vtkPolyData()) mapper2 = vtk.vtkPolyDataMapper() mapper2.SetInputData(vtk.vtkPolyData()) actor1 = vtk.vtkActor() actor1.SetMapper(mapper1) actor2 = vtk.vtkActor() actor2.SetMapper(mapper2) actor1.GetMapper().SetInputData(reader1.GetOutput()) actor2.GetMapper().SetInputData(reader2.GetOutput()) h_center = actor2.GetCenter() c_center = actor1.GetCenter() c_h = actor1.GetBounds()[2] x = h_center[0] - c_center[0] y = 0.07 - c_h z = h_center[2] - c_center[2] actor1.SetPosition(x, y, z) # append_poly.AddInputData(reader1.GetOutput()) # append_poly.AddInputData(reader2.GetOutput()) reader1.FastDelete() reader2.FastDelete() render = vtk.vtkRenderer() ren_win = vtk.vtkRenderWindow() ren_win.AddRenderer(render) ren_win.SetSize(2000, 2000) i_ren = vtk.vtkRenderWindowInteractor() i_ren.SetInteractorStyle(vtk.vtkInteractorStyleMultiTouchCamera()) i_ren.SetRenderWindow(ren_win) render.AddActor(actor1) render.AddActor(actor2) ren_win.Render() actors = render.GetActors() actor_items = actors.GetNumberOfItems() actors.InitTraversal() for i in range(actor_items): actor = actors.GetNextActor() position = list(actor.GetPosition()) actor.SetPosition(position[0], position[1], position[2]) mapper = actor.GetMapper() poly = mapper.GetInput() if position != (0, 0, 0): # 如果发生平移则把每个点的坐标都做一下平移 points = poly.GetPoints() sum_pts = points.GetNumberOfPoints() for x in range(sum_pts): pos_point = list(points.GetPoint(x)) for y in range(3): pos_point[y] += position[y] points.SetPoint(x, pos_point) append_poly.AddInputData(poly) append_poly.Update() filter = vtk.vtkTriangleFilter() filter.SetInputConnection(append_poly.GetOutputPort()) stl_writer.SetFileName('STL/1.stl') stl_writer.SetInputConnection(filter.GetOutputPort()) stl_writer.Update() stl_writer.Write() i_ren.Start()
def __init__(self): append_poly = vtk.vtkAppendPolyData() reader1 = vtk.vtkSTLReader() reader1.SetFileName(file1) reader1.Update() reader2 = vtk.vtkSTLReader() reader2.SetFileName(file2) reader2.Update() mapper1 = vtk.vtkPolyDataMapper() mapper1.SetInputData(vtk.vtkPolyData()) mapper2 = vtk.vtkPolyDataMapper() mapper2.SetInputData(vtk.vtkPolyData()) actor1 = vtk.vtkActor() actor1.SetMapper(mapper1) actor2 = vtk.vtkActor() actor2.SetMapper(mapper2) actor1.GetMapper().SetInputData(reader1.GetOutput()) actor2.GetMapper().SetInputData(reader2.GetOutput()) h_center = actor2.GetCenter() c_center = actor1.GetCenter() c_h = actor1.GetBounds()[2] x = h_center[0] - c_center[0] y = 0.07 - c_h z = h_center[2] - c_center[2] actor1.SetPosition(x, y, z) # append_poly.AddInputData(reader1.GetOutput()) # append_poly.AddInputData(reader2.GetOutput()) # reader1.FastDelete() # reader2.FastDelete() render = vtk.vtkRenderer() ren_win = vtk.vtkRenderWindow() ren_win.AddRenderer(render) ren_win.SetSize(2000, 2000) i_ren = vtk.vtkRenderWindowInteractor() i_ren.SetInteractorStyle(vtk.vtkInteractorStyleMultiTouchCamera()) i_ren.SetRenderWindow(ren_win) actor_list = [actor1, actor2] for actor in actor_list: position = list(actor.GetPosition()) actor.SetPosition(position[0], position[1], position[2]) mapper = actor.GetMapper() poly = mapper.GetInput() if position != (0, 0, 0): points = poly.GetPoints() sum_pts = points.GetNumberOfPoints() for x in range(sum_pts): pos_point = list(points.GetPoint(x)) for y in range(3): pos_point[y] += position[y] points.SetPoint(x, pos_point) append_poly.AddInputData(poly) append_poly.Update() mapper = vtk.vtkPolyDataMapper() mapper.SetInputData(append_poly.GetOutput()) actor = vtk.vtkActor() actor.SetMapper(mapper) render.AddActor(actor) ren_win.Render() i_ren.Start()
@staticmethod def axis(): actor = vtk.vtkAxesActor() actor.SetTotalLength(0.5, 0.5, 0.5) actor.SetShaftType(0) actor.SetCylinderRadius(0.01) actor.GetXAxisCaptionActor2D().SetWidth(0.01) actor.GetYAxisCaptionActor2D().SetWidth(0.01) actor.GetZAxisCaptionActor2D().SetWidth(0.01) return actor if __name__ == '__main__': test = Test() test.load_floor_file(file_path='STL/1.stl') # test.load_car_file(file_path='STL/FTAlpha2020.stl') test.splicing() render = vtk.vtkRenderer() render.AddActor(test.floor_actor) render.AddActor(test.car_actor) render.AddActor(test.axis()) ren_win = vtk.vtkRenderWindow() ren_win.AddRenderer(render) ren_win.SetSize(2000, 2000) ren_win.Render() i_ren = vtk.vtkRenderWindowInteractor() i_ren.SetInteractorStyle(vtk.vtkInteractorStyleMultiTouchCamera()) i_ren.SetRenderWindow(ren_win) i_ren.Start()
transfo.Translate(x, y, z) filter = vtk.vtkTransformPolyDataFilter() filter.SetInputConnection(textSource.GetOutputPort()) filter.SetTransform(transfo) filter.Update() # Create a mapper and actor mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(filter.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetColor(1.0, 0.0, 0.0) # Create a renderer, render window, and interactor renderer = vtk.vtkRenderer() renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer) renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) renderer.AddActor(actor) renderer.AddActor(vtk.vtkAxesActor()) renderer.SetBackground(0.4, 0.3, 0.2) renderWindow.Render() style = vtk.vtkInteractorStyleMultiTouchCamera() renderWindowInteractor.SetInteractorStyle(style) renderWindowInteractor.Start()
def __init__(self): super().__init__() self.resize(1000, 1000) self._widget = QWidget(self) self.setCentralWidget(self._widget) self._widget.resize(1000, 1000) self._widget.setWindowFlags(Qt.NoDropShadowWindowHint) # VTK self._vtk_widget = QVTKRenderWindowInteractor(self._widget) self._vtk_widget.SetInteractorStyle( vtk.vtkInteractorStyleMultiTouchCamera()) self._vtk_widget.resize(1000, 1000) self.setWindowFlags(Qt.NoDropShadowWindowHint) # PAINTER # UI self._ui = Ui_Form() self._ui.setupUi(self._widget) self._ui.widget.move(30, 30) self._ui.widget.setVisible(False) self._ui.widget.setWindowFlags(Qt.NoDropShadowWindowHint) # 设置边边的颜色 self._pal = self._ui.widget.palette() self._pal.setColor(QPalette.Background, QtGui.QColor(0, 0, 0)) self._ui.widget.setAutoFillBackground(True) # 把QTapWidget的边边拿出来 self._ui.widget.setPalette(self._pal) self._ui2 = Ui_hello() self._ui2.setupUi(self._widget) self._ui2.widget.move(30, 200) self._ui2.widget.setVisible(False) self._ui2.widget.setWindowFlags(Qt.NoDropShadowWindowHint) # BTN self._btn1 = QPushButton('BTN1', self._widget) self._btn1.resize(50, 70) self._btn1.move(500, 50) self._btn1.show() self._btn2 = QPushButton('BTN2', self._widget) self._btn2.resize(50, 70) self._btn2.move(500, 150) self._btn2.show() # SIGNAL self._btn1.clicked.connect(self._set_widget1_visible) self._btn2.clicked.connect(self._set_widget2_visible) # ATTR self._ui_ena = False self._ui_ena2 = False sheet = """ QTabWidget::tab-bar { background-color: black; } QTabBar::tab { background-color: black; border-color:white; font: bold 12px 'Arial'; color: white; height:60px; } QTabBar::tab:!selected { background-color: black; color: white; } QTabWidget::pane { position: absolute; background-color: black; } """ self._ui.widget.setStyleSheet(sheet) self._ui2.widget.setAutoFillBackground(True)