MainWnd.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. from PyQt5.QtGui import *
  2. from PyQt5.QtWidgets import *
  3. from CustomFrame import *
  4. import os
  5. import datetime
  6. class MainWindow(QMainWindow):
  7. """docstring for Mainwindow"""
  8. def __init__(self, parent = None):
  9. super(MainWindow,self).__init__(parent)
  10. self.basic()
  11. self.Controller = ControlFrame()
  12. self.viewerFrame = ViewerFrame(self.Controller.OnAction)
  13. self.Controller.btnSaveAllCloud.clicked.connect(self.saveAllCloud)
  14. self.Controller.btnSaveWheelSampleCloud.clicked.connect(self.saveWheelSampleCloud)
  15. splitter= self.split_()
  16. self.setCentralWidget(splitter)
  17. def saveAllCloud(self):
  18. # fileName2, ok2 = QFileDialog.getSaveFileName(self, "文件保存", "C:/","All Files (*);;Text Files (*.txt)")
  19. # if fileName2=="":
  20. # return
  21. fileName2="./cloud/all.txt"
  22. with open(fileName2,"w+") as f:
  23. for point in self.viewerFrame.pcViewer1.pointCloud:
  24. prob=point[3]
  25. f.write("%f %f %f %d %d %d\n"%(point[0],point[1],point[2],int(255*prob),int(255-prob*255),255-int(prob*255)))
  26. for point in self.viewerFrame.pcViewer2.pointCloud:
  27. prob=point[3]
  28. f.write("%f %f %f %d %d %d\n"%(point[0],point[1],point[2],int(255*prob),int(255-prob*255),255-int(prob*255)))
  29. for point in self.viewerFrame.pcViewer3.pointCloud:
  30. prob=point[3]
  31. f.write("%f %f %f %d %d %d\n"%(point[0],point[1],point[2],int(255*prob),int(255-prob*255),255-int(prob*255)))
  32. for point in self.viewerFrame.pcViewer4.pointCloud:
  33. prob=point[3]
  34. f.write("%f %f %f %d %d %d\n"%(point[0],point[1],point[2],int(255*prob),int(255-prob*255),255-int(prob*255)))
  35. #窗口基础属性
  36. def saveWheelSampleCloud(self):
  37. print(" save wheel sample")
  38. path="./cloud"
  39. folder=os.path.exists(path)
  40. if not folder:
  41. os.mkdir(path)
  42. str=datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
  43. sampleFolder=path+"/"+str
  44. folder2=os.path.exists(sampleFolder)
  45. if not folder2:
  46. os.mkdir(sampleFolder)
  47. with open(sampleFolder+"/1.txt","w+") as f:
  48. for point in self.viewerFrame.pcViewer1.pointCloud:
  49. prob=point[3]
  50. if prob>0.8:
  51. f.write("%f %f %f\n"%(point[0],point[1],point[2]))
  52. with open(sampleFolder+"/2.txt","w+") as f:
  53. for point in self.viewerFrame.pcViewer2.pointCloud:
  54. prob=point[3]
  55. if prob>0.8:
  56. f.write("%f %f %f\n"%(point[0],point[1],point[2]))
  57. with open(sampleFolder+"/3.txt","w+") as f:
  58. for point in self.viewerFrame.pcViewer3.pointCloud:
  59. prob=point[3]
  60. if prob>0.8:
  61. f.write("%f %f %f\n"%(point[0],point[1],point[2]))
  62. with open(sampleFolder+"/4.txt","w+") as f:
  63. for point in self.viewerFrame.pcViewer4.pointCloud:
  64. prob=point[3]
  65. if prob>0.8:
  66. f.write("%f %f %f\n"%(point[0],point[1],point[2]))
  67. text="样本已保存到:%s 文件夹下"%(sampleFolder)
  68. QMessageBox.information(self, '保存轮胎样本',text,QMessageBox.Ok,QMessageBox.Ok)
  69. subprocess.Popen(["cloudcompare.CloudCompare",sampleFolder+"/1.txt",sampleFolder+"/2.txt",
  70. sampleFolder+"/3.txt",sampleFolder+"/4.txt"])
  71. def basic(self):
  72. #设置标题,大小,图标
  73. self.setWindowTitle("RPC3DView")
  74. self.resize(490*2+300, 370*2)
  75. #self.setWindowIcon(QIcon("./image/Gt.png"))
  76. #居中显示
  77. screen = QDesktopWidget().geometry()
  78. self_size = self.geometry()
  79. self.move(int((screen.width() - self_size.width())/2),int((screen.height() - self_size.height())/2))
  80. def closeEvent(self, QCloseEvent):
  81. self.Controller.close()
  82. self.viewerFrame.close()
  83. #分割窗口
  84. def split_(self):
  85. splitter = QSplitter(Qt.Horizontal)
  86. splitter.addWidget(self.viewerFrame)
  87. splitter.addWidget(self.Controller)
  88. splitter.setStretchFactor(0,11)
  89. splitter.setStretchFactor(1,4)
  90. return splitter
  91. def OnImagesHandle(self,images:pb.ResImage):
  92. self.viewerFrame.DisplayImage(images)
  93. self.Controller.OnImages(images)
  94. def OnCloudHandle(self,clouds:pb.ResCloud):
  95. self.viewerFrame.DisplayCloud(clouds)
  96. def OnMeasureDataHandle(self,measure:pb.MeasureInfo):
  97. self.Controller.DisplayMeasureInfo(measure)