123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- from PyQt5.QtGui import *
- from PyQt5.QtWidgets import *
- from CustomFrame import *
- import os
- import datetime
- class MainWindow(QMainWindow):
- """docstring for Mainwindow"""
- def __init__(self, parent = None):
- super(MainWindow,self).__init__(parent)
- self.basic()
- self.Controller = ControlFrame()
- self.viewerFrame = ViewerFrame(self.Controller.OnAction)
- self.Controller.btnSaveAllCloud.clicked.connect(self.saveAllCloud)
- self.Controller.btnSaveWheelSampleCloud.clicked.connect(self.saveWheelSampleCloud)
- splitter= self.split_()
- self.setCentralWidget(splitter)
- def saveAllCloud(self):
- # fileName2, ok2 = QFileDialog.getSaveFileName(self, "文件保存", "C:/","All Files (*);;Text Files (*.txt)")
- # if fileName2=="":
- # return
- fileName2="./cloud/all.txt"
- with open(fileName2,"w+") as f:
- for point in self.viewerFrame.pcViewer1.pointCloud:
- prob=point[3]
- 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)))
- for point in self.viewerFrame.pcViewer2.pointCloud:
- prob=point[3]
- 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)))
- for point in self.viewerFrame.pcViewer3.pointCloud:
- prob=point[3]
- 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)))
- for point in self.viewerFrame.pcViewer4.pointCloud:
- prob=point[3]
- 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)))
- #窗口基础属性
- def saveWheelSampleCloud(self):
- print(" save wheel sample")
- path="./cloud"
- folder=os.path.exists(path)
- if not folder:
- os.mkdir(path)
- str=datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
- sampleFolder=path+"/"+str
- folder2=os.path.exists(sampleFolder)
- if not folder2:
- os.mkdir(sampleFolder)
- with open(sampleFolder+"/1.txt","w+") as f:
- for point in self.viewerFrame.pcViewer1.pointCloud:
- prob=point[3]
- if prob>0.8:
- f.write("%f %f %f\n"%(point[0],point[1],point[2]))
- with open(sampleFolder+"/2.txt","w+") as f:
- for point in self.viewerFrame.pcViewer2.pointCloud:
- prob=point[3]
- if prob>0.8:
- f.write("%f %f %f\n"%(point[0],point[1],point[2]))
- with open(sampleFolder+"/3.txt","w+") as f:
- for point in self.viewerFrame.pcViewer3.pointCloud:
- prob=point[3]
- if prob>0.8:
- f.write("%f %f %f\n"%(point[0],point[1],point[2]))
- with open(sampleFolder+"/4.txt","w+") as f:
- for point in self.viewerFrame.pcViewer4.pointCloud:
- prob=point[3]
- if prob>0.8:
- f.write("%f %f %f\n"%(point[0],point[1],point[2]))
- text="样本已保存到:%s 文件夹下"%(sampleFolder)
- QMessageBox.information(self, '保存轮胎样本',text,QMessageBox.Ok,QMessageBox.Ok)
- subprocess.Popen(["cloudcompare.CloudCompare",sampleFolder+"/1.txt",sampleFolder+"/2.txt",
- sampleFolder+"/3.txt",sampleFolder+"/4.txt"])
- def basic(self):
- #设置标题,大小,图标
- self.setWindowTitle("RPC3DView")
- self.resize(490*2+300, 370*2)
- #self.setWindowIcon(QIcon("./image/Gt.png"))
- #居中显示
- screen = QDesktopWidget().geometry()
- self_size = self.geometry()
- self.move(int((screen.width() - self_size.width())/2),int((screen.height() - self_size.height())/2))
- def closeEvent(self, QCloseEvent):
- self.Controller.close()
- self.viewerFrame.close()
- #分割窗口
- def split_(self):
- splitter = QSplitter(Qt.Horizontal)
- splitter.addWidget(self.viewerFrame)
- splitter.addWidget(self.Controller)
- splitter.setStretchFactor(0,11)
- splitter.setStretchFactor(1,4)
- return splitter
- def OnImagesHandle(self,images:pb.ResImage):
- self.viewerFrame.DisplayImage(images)
- self.Controller.OnImages(images)
- def OnCloudHandle(self,clouds:pb.ResCloud):
- self.viewerFrame.DisplayCloud(clouds)
- def OnMeasureDataHandle(self,measure:pb.MeasureInfo):
- self.Controller.DisplayMeasureInfo(measure)
|