增加网格面片删除、复制、裁剪

pull/1/head
剑古敛锋 2024-07-23 10:39:28 +08:00
parent 619c9ec065
commit 3d7795b494
7 changed files with 341 additions and 204 deletions

View File

@ -58,9 +58,9 @@ namespace MainWidget
connect(this, SIGNAL(WorldPointMouseMove(double, double, double)),mw,SIGNAL(showStateToolbarPositionSIGNGAL(double, double, double)));
// 网格操作
connect(this, SIGNAL(deleteMeshSig(GUI::MainWindow *)), this, SLOT(deleteMesh(GUI::MainWindow *)));
connect(this, SIGNAL(copyMeshSig(GUI::MainWindow *)), this, SLOT(copyMesh(GUI::MainWindow *)));
connect(this, SIGNAL(clipMeshSig(GUI::MainWindow *)), this, SLOT(clipMesh(GUI::MainWindow *)));
// connect(this, SIGNAL(deleteMeshSig(GUI::MainWindow *)), this, SLOT(deleteMesh(GUI::MainWindow *)));
// connect(this, SIGNAL(copyMeshSig(GUI::MainWindow *)), this, SLOT(copyMesh(GUI::MainWindow *)));
// connect(this, SIGNAL(clipMeshSig(GUI::MainWindow *)), this, SLOT(clipMesh(GUI::MainWindow *)));
connect(this->_meshProvider, SIGNAL(importMeshDataSetSig(vtkDataSet*)), this, SIGNAL(importMeshDataSetSig(vtkDataSet*)));

View File

@ -89,13 +89,11 @@ namespace MainWidget
void setMeshSelectMode(int model);
void highLighDataSet(vtkDataSet *dataset);
void clearMeshSetHighLight();
//
void highLightGeoComponentSig(Geometry::GeoComponent *aGC);
// 网格
void importMeshDataSetSig(vtkDataSet* dataset);
public slots:
//设置选择模式
void setSelectModel(int mode) override;

View File

@ -10,6 +10,7 @@
#include "MeshOperator.h"
#include <QObject>
#include <QMessageBox>
#include "ModuleBase/CommonFunctions.h"
#include "MainWidgets/meshViewProvider.h"
#include "MainWidgets/meshKernalViewObject.h"
#include "MainWidgets/preWindow.h"
@ -36,6 +37,12 @@
#include <QFileDialog>
#include <vtkUnstructuredGridWriter.h>
#include <QMessageBox>
#include <vtkThreshold.h>
#include <BRepMesh_IncrementalMesh.hxx>
#include <StlAPI_Writer.hxx>
#include <vtkSTLReader.h>
#include "PointCloudOperator/MeshOpearatorCommon.h"
namespace MeshData {
MeshOperator::MeshOperator(GUI::MainWindow* _mainwindow): QObject(_mainwindow){
@ -45,20 +52,42 @@ namespace MeshData {
_selectModel = _preWindow->getSelectModel();
_meshProvider = _preWindow->getMeshViewProvider();
// 网格边界菜单
QString meshMenuName = "menumeshedit";
_meshMenu = _mainwindow->getMenu(meshMenuName); // 获取菜单
if(nullptr!=_meshMenu) {
DebugInfo("MeshEidt menu init success\n");
}
// connect(_mainwindow, SIGNAL(on_deleteMeshSIGNAL(GUI::MainWindow*)), this,
// SLOT(on_deleteMesh(GUI::MainWindow*)));
// connect(_mainwindow, SIGNAL(on_copyMeshSIGNAL(GUI::MainWindow*)), this,
// SLOT(on_copyMesh(GUI::MainWindow*)));
// connect(_mainwindow, SIGNAL(on_clipMeshSIGNAL(GUI::MainWindow*)), this,
// SLOT(on_clipMesh(GUI::MainWindow*)));
// connect(_mainwindow, SIGNAL(on_saveMeshSIGNAL(GUI::MainWindow*)), this,
// SLOT(on_saveMesh(GUI::MainWindow*)));
}
MeshOperator::~MeshOperator(){
}
void MeshOperator::on_deleteMesh(){
QMultiHash<int, int> *selectItems = _preWindow->getSelectItems(); // 选择 mesh
this->_selectModel=_preWindow->getSelectModel();
this->deleteMesh(selectItems);
}
void MeshOperator::on_copyMesh(){
QMultiHash<int, int> *selectItems = _preWindow->getSelectItems(); // 选择 mesh
this->_selectModel=_preWindow->getSelectModel();
this->copyMesh(selectItems);
}
void MeshOperator::on_clipMesh(){
QMultiHash<int, int> *selectItems = _preWindow->getSelectItems(); // 选择 mesh
this->_selectModel=_preWindow->getSelectModel();
this->clipMesh(selectItems);
}
@ -76,6 +105,9 @@ namespace MeshData {
for (auto dataset : datasetList)
{
auto k = _meshData->getKernalByID(dataset); // 获取对应的kernal
if(!(k->isVisible())){
continue;
}
auto vObjs = _meshProvider->getViewObjects(k); // 获取对应的view对象
QList<int> members = items->values(); // 获取所有的value
if (vObjs == nullptr)
@ -94,8 +126,9 @@ namespace MeshData {
//vObjs->getDisplayData()->DeepCopy(k->getMeshData());
vObjs->modifyPointDisplay();
}
_preWindow->reRender();
// 保存模型中的点集数据
qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")<<" MeshViewProvider::deleteMesh finish ";
}
@ -119,6 +152,14 @@ namespace MeshData {
{
auto k = _meshData->getKernalByID(dataset); // 获取对应的kernal
auto vObjs = _meshProvider->getViewObjects(k); // 获取对应的view对象
if(!(k->isVisible())){
continue;
}
vtkSmartPointer<vtkGeometryFilter> geofilter=vtkSmartPointer<vtkGeometryFilter>::New();
geofilter->AddInputData(k->getMeshData());
geofilter->Update();
vtkSmartPointer<vtkPolyData> searchData=vtkSmartPointer<vtkPolyData>::New();
searchData->DeepCopy(geofilter->GetOutput());
QList<int> members = items->values(); //
if (vObjs == nullptr)
@ -127,88 +168,45 @@ namespace MeshData {
continue;
}
if(_selectModel == ModuleBase::BoxMeshNode || _selectModel == ModuleBase::MeshNode||_selectModel==ModuleBase::BoxMeshSurfaceNode) { // 复制Points
vtkPointData* points=k->getMeshData()->GetPointData();
vtkDataArray* pids=points->GetArray("IDS");
int ppid=-1;
int npoint=k->getMeshData()->GetNumberOfPoints(); // 点的数量
std::set<int> memberSet(members.begin(),members.end()); // 点集
vtkSmartPointer<vtkIdTypeArray> idArray = vtkSmartPointer<vtkIdTypeArray>::New(); // 复制点
for(int pid=0;pid<npoint;++pid){
double* p=pids->GetTuple2(pid);
ppid=p[1];
if(memberSet.find(ppid)!=memberSet.end()){ // 目标点直接复制
idArray->InsertNextValue(pid);
}
}
qDebug()<<QString("Cell %1 %2").arg(npoint,idArray->GetNumberOfValues());
// 复制点集
vtkSmartPointer<vtkSelectionNode> selectionNode = vtkSmartPointer<vtkSelectionNode>::New();
selectionNode->SetFieldType(vtkSelectionNode::POINT);
selectionNode->SetContentType(vtkSelectionNode::INDICES);
selectionNode->SetSelectionList(idArray);
vtkSmartPointer<vtkSelection> selection = vtkSmartPointer<vtkSelection>::New();
selection->AddNode(selectionNode);
vtkSmartPointer<vtkExtractSelection> extractionSelection = vtkSmartPointer<vtkExtractSelection>::New();
extractionSelection->SetInputData(0, k->getMeshData());
extractionSelection->SetInputData(1, selection);
extractionSelection->Update();
appf->AddInputData(extractionSelection->GetOutput());
vtkDataSet* copyVtkdata=appf->GetOutput();
qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")<<" MeshViewProvider::copyMesh finish "<<QString(" copyVtkdata number: %1").arg(copyVtkdata->GetNumberOfPoints());
qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")<<" MeshViewProvider::copyMesh finish "<<QString(" copyVtkdata point value ids : %1").arg(idArray->GetNumberOfValues());
} else if(_selectModel == ModuleBase::BoxMeshCell || _selectModel == ModuleBase::MeshCell||_selectModel==ModuleBase::BoxMeshSurfaceCell) { // 绘制cell
int ppid=-1;
int npoint=k->getMeshData()->GetNumberOfPoints(); // 点的数量
// 复制面片
vtkSmartPointer<vtkIdTypeArray> idArray = vtkSmartPointer<vtkIdTypeArray>::New();
std::set<int> memberSet(members.begin(),members.end()); // 点集
int ncell=k->getMeshData()->GetNumberOfCells();
vtkDataArray* pids=k->getMeshData()->GetPointData()->GetArray("IDS");
for(size_t cellId=0;cellId<ncell;cellId++){
vtkCell* cell = k->getMeshData()->GetCell(cellId);
vtkIdList* pointIds = cell->GetPointIds();
for (vtkIdType j = 0; j < pointIds->GetNumberOfIds(); ++j)
{
vtkIdType pointId = pointIds->GetId(j);
double *p = pids->GetTuple2(pointId);
ppid=p[1];
if(memberSet.find(ppid)!=memberSet.end()){ // 目标点直接复制
idArray->InsertNextValue(cellId);
break;
}
}
}
vtkSmartPointer<vtkSelectionNode> selectionNode = vtkSmartPointer<vtkSelectionNode>::New();
selectionNode->SetFieldType(vtkSelectionNode::CELL);
selectionNode->SetContentType(vtkSelectionNode::INDICES);
selectionNode->SetSelectionList(idArray);
vtkSmartPointer<vtkSelection> selection = vtkSmartPointer<vtkSelection>::New();
selection->AddNode(selectionNode);
vtkSmartPointer<vtkExtractSelection> extractionSelection = vtkSmartPointer<vtkExtractSelection>::New();
extractionSelection->SetInputData(0, k->getMeshData());
extractionSelection->SetInputData(1, selection);
extractionSelection->Update();
appf->AddInputData(extractionSelection->GetOutput());
vtkDataSet* copyVtkdata=appf->GetOutput();
qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")<<" MeshViewProvider::copyMesh finish "<<QString(" copyVtkdata number: %1").arg(copyVtkdata->GetNumberOfPoints());
qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")<<" MeshViewProvider::copyMesh finish "<<QString(" copyVtkdata cell value ids : %1").arg(idArray->GetNumberOfValues());
// 初始化
for(int i=0;i<searchData->GetNumberOfPoints();i++){
searchData->GetPointData()->GetArray("SHOW")->SetComponent(i,0,0);
}
for(int i=0;i<searchData->GetNumberOfCells();i++){
searchData->GetCellData()->GetArray("SHOW")->SetComponent(i,0,0);
}
}
if(_selectModel == ModuleBase::BoxMeshNode || _selectModel == ModuleBase::MeshNode||_selectModel==ModuleBase::BoxMeshSurfaceNode) { // 复制Points
this->SearchPoints(searchData,members,1);
// 复制点
vtkSmartPointer<vtkThreshold> threshold = vtkSmartPointer<vtkThreshold>::New();
threshold->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, "SHOW");
threshold->SetInputData(searchData);
threshold->SetLowerThreshold(0.5); // 设置筛选条件,大于 0.5 的面将被保留
threshold->SetUpperThreshold(1.5);
threshold->Update();
appf->AddInputData(threshold->GetOutput());
} else if(_selectModel == ModuleBase::BoxMeshCell || _selectModel == ModuleBase::MeshCell||_selectModel==ModuleBase::BoxMeshSurfaceCell) { // 绘制cell
//this->SearchPoints(searchData,members,1);
this->SearchCells(searchData,members,1);
// 复制单元
vtkSmartPointer<vtkThreshold> threshold = vtkSmartPointer<vtkThreshold>::New();
threshold->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_CELLS, "SHOW");
threshold->SetInputData(searchData);
threshold->SetLowerThreshold(0.5); // 设置筛选条件,大于 0.5 的面将被保留
threshold->SetUpperThreshold(1.5);
threshold->Update();
appf->AddInputData(threshold->GetOutput());
}
}
appf->Update();
vtkDataSet* copyVtkdata=appf->GetOutput();
qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")<<" MeshViewProvider::copyMesh finish "<<QString(" copyVtkdata number: %1").arg(copyVtkdata->GetNumberOfPoints());
qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")<<" MeshViewProvider::copyMesh finish "<<QString(" copyVtkdata cells: %1").arg(copyVtkdata->GetNumberOfCells());
// 复制数据
if(QFileInfo(fileName).exists()){
QFile(fileName).remove();
}else{}
vtkSmartPointer<vtkUnstructuredGridWriter> writer = vtkSmartPointer<vtkUnstructuredGridWriter>::New();
writer->SetInputData(copyVtkdata);
writer->SetFileTypeToBinary();
@ -230,124 +228,8 @@ namespace MeshData {
}
// 模型裁剪
void MeshOperator::clipMesh(QMultiHash<int, int>* items) {
// qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")<<" MeshViewProvider::clipMesh start ";
// // 设置文件保存地址
// QString fileName = QFileDialog::getSaveFileName(nullptr, tr("Save Mesh File"), "", tr("VTK(*.vtk)"));
// if(fileName.isEmpty()){
// return;
// }else{}
// if (items->isEmpty())
// return;
// _highLightSelectItems = *items;
// QColor c = Setting::BusAPI::instance()->getGraphOption()->getHighLightColor();
// QList<int> datasetList = items->uniqueKeys(); // 获取所有的key
// qDebug()<<QString("kernel size: %1").arg(datasetList.size());
// vtkPolyData *polyData = vtkPolyData::New();// 创建新的对象
// vtkSmartPointer<vtkAppendFilter> appf = vtkSmartPointer<vtkAppendFilter>::New();
// for (auto dataset : datasetList)
// {
// auto k = _meshData->getKernalByID(dataset); // 获取对应的kernal
// auto vObjs = _viewObjects.value(k); // 获取对应的view对象
// QList<int> members = items->values(); //
//
// if (vObjs == nullptr)
// continue;
// if(members.isEmpty()){
// continue;
// }
//
// if(_selectModel == ModuleBase::BoxMeshNode || _selectModel == ModuleBase::MeshNode||_selectModel==ModuleBase::BoxMeshSurfaceNode) { // 复制Points
// vtkPointData* points=k->getMeshData()->GetPointData();
// vtkDataArray* pids=points->GetArray("IDS");
// int ppid=-1;
// int npoint=k->getMeshData()->GetNumberOfPoints(); // 点的数量
// std::set<int> memberSet(members.begin(),members.end()); // 点集
// vtkSmartPointer<vtkIdTypeArray> idArray = vtkSmartPointer<vtkIdTypeArray>::New(); // 复制点
// for(int pid=0;pid<npoint;++pid){
// double* p=pids->GetTuple2(pid);
// ppid=p[1];
// if(memberSet.find(ppid)!=memberSet.end()){ // 目标点直接复制
// idArray->InsertNextValue(pid);
// }
// }
// // 复制点集
// vtkSmartPointer<vtkSelectionNode> selectionNode = vtkSmartPointer<vtkSelectionNode>::New();
// selectionNode->SetFieldType(vtkSelectionNode::POINT);
// selectionNode->SetContentType(vtkSelectionNode::INDICES);
// selectionNode->SetSelectionList(idArray);
// vtkSmartPointer<vtkSelection> selection = vtkSmartPointer<vtkSelection>::New();
// selection->AddNode(selectionNode);
//
// vtkSmartPointer<vtkExtractSelection> extractionSelection = vtkSmartPointer<vtkExtractSelection>::New();
// extractionSelection->SetInputData(0, k->getMeshData());
// extractionSelection->SetInputData(1, selection);
// extractionSelection->Update();
// appf->AddInputData(extractionSelection->GetOutput());
//
// } else if(_selectModel == ModuleBase::BoxMeshCell || _selectModel == ModuleBase::MeshCell||_selectModel==ModuleBase::BoxMeshSurfaceCell) { // 绘制cell
// int ppid=-1;
// int npoint=k->getMeshData()->GetNumberOfPoints(); // 点的数量
// // 复制面片
// vtkSmartPointer<vtkIdTypeArray> idArray = vtkSmartPointer<vtkIdTypeArray>::New();
// std::set<int> memberSet(members.begin(),members.end()); // 点集
// int ncell=k->getMeshData()->GetNumberOfCells();
// vtkDataArray* pids=k->getMeshData()->GetPointData()->GetArray("IDS");
// for(size_t cellId=0;cellId<ncell;cellId++){
// vtkCell* cell = k->getMeshData()->GetCell(cellId);
//
// vtkIdList* pointIds = cell->GetPointIds();
// for (vtkIdType j = 0; j < pointIds->GetNumberOfIds(); ++j)
// {
// vtkIdType pointId = pointIds->GetId(j);
// double *p = pids->GetTuple2(pointId);
// ppid=p[1];
// if(memberSet.find(ppid)!=memberSet.end()){ // 目标点直接复制
// idArray->InsertNextValue(cellId);
// break;
// }
// }
// }
// vtkSmartPointer<vtkSelectionNode> selectionNode = vtkSmartPointer<vtkSelectionNode>::New();
// selectionNode->SetFieldType(vtkSelectionNode::CELL);
// selectionNode->SetContentType(vtkSelectionNode::INDICES);
// selectionNode->SetSelectionList(idArray);
// vtkSmartPointer<vtkSelection> selection = vtkSmartPointer<vtkSelection>::New();
// selection->AddNode(selectionNode);
//
// vtkSmartPointer<vtkExtractSelection> extractionSelection = vtkSmartPointer<vtkExtractSelection>::New();
// extractionSelection->SetInputData(0, k->getMeshData());
// extractionSelection->SetInputData(1, selection);
// extractionSelection->Update();
// appf->AddInputData(extractionSelection->GetOutput());
// }
//
// }
//
// appf->Update();
// vtkDataSet* copyVtkdata=appf->GetOutput();
// // 复制数据
// if(QFileInfo(fileName).exists()){
// QFile(fileName).remove();
// }else{}
// vtkSmartPointer<vtkUnstructuredGridWriter> writer = vtkSmartPointer<vtkUnstructuredGridWriter>::New();
// writer->SetInputData(copyVtkdata);
// writer->SetFileTypeToBinary();
// writer->SetFileName(fileName.toLocal8Bit().constData());
// writer->Write();
// // 重新加载数据
// if(QFileInfo(fileName).exists()){
// QString pyCode = QString("MainWindow.importMesh(\"%1\",\"%2\",%3)")
// .arg(fileName)
// .arg("VTK(*.vtk)")
// .arg(-1);
// Py::PythonAgent::getInstance()->submit(pyCode); // 加载数据
// }else{
// QMessageBox::warning(nullptr,"Warning","Copy Mesh File Save Failed !");
// //emit _mainWindow->importMeshDataSetSig(copyVtkdata);
// }
//
//
this->copyMesh(items);
this->deleteMesh(items);
qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")<<" MeshViewProvider::clipMesh finish ";
//模型裁剪
}
@ -366,4 +248,126 @@ namespace MeshData {
k->getMeshData()->DeepCopy(vObjs->getDisplayData());
}
}
void MeshOperator::SearchPoints(vtkDataSet* dataSet,const QList<int>& index ,int value)
{
std::set<int> indexSet(index.begin(), index.end());
// 判断是否需要显示
vtkDataArray* showArray = dataSet->GetPointData()->GetArray("SHOW");
vtkDataArray* IDSArray=dataSet->GetPointData()->GetArray("IDS");
if(nullptr==IDSArray||nullptr == showArray)
return;
int pointid = -1;
for(int i = 0; i < showArray->GetNumberOfTuples(); ++i) {
int pointid =IDSArray->GetComponent(i, 1);
if(indexSet.find(pointid) != indexSet.end()) // 判断是否正确
{
showArray->SetComponent(i, 0, value);
}
}
// 更新cell显示
QList<int> hideCells;
hideCells.clear();
// 计算联通单元
size_t ncell = dataSet->GetNumberOfCells();
vtkDataArray* cids = dataSet->GetCellData()->GetArray("IDS");
for(size_t cellId = 0; cellId < ncell; cellId++) {
vtkCell* cell = dataSet->GetCell(cellId);
vtkIdList* pointIds = cell->GetPointIds();
for(vtkIdType j = 0; j < pointIds->GetNumberOfIds(); ++j) {
vtkIdType pointId = pointIds->GetId(j);
if(fabs(showArray->GetComponent(pointId, 0)) < 0.5) // 存在一个隐藏
{
hideCells.push_back(cids->GetComponent(cellId, 1));
break;
}
}
}
this->SearchCells(dataSet,hideCells, value);
}
void MeshOperator::SearchCells(vtkDataSet* dataSet,const QList<int>& indexs, int value)
{
// auto dataSet = _kernal->getMeshData();
vtkDataArray* showArray = dataSet->GetCellData()->GetArray("SHOW");
vtkDataArray* IDSArray = dataSet->GetCellData()->GetArray("IDS");
if(nullptr==IDSArray||nullptr == showArray)
return;
std::set<int> indexSet(indexs.begin(), indexs.end());
for(int i = 0; i < showArray->GetNumberOfTuples(); ++i) {
int cellid = IDSArray->GetComponent(i, 1);
if(indexSet.find(cellid) != indexSet.end()) // 判断是否正确
{
showArray->SetComponent(i, 0, value);
}
}
}
void MeshOperator::actionMeshOptimizationOCCT(vtkDataSet* dataSet, vtkDataSet* surfaceData) {
QString tempFolderPath=Setting::BusAPI::instance()->getTemperturePath(); // 获取临时文件夹
//dataset 转换为 OCCT 数据
TopoDS_Shape* vtkshp=MeshOpearator::MeshOpearatorCommon::vtkdataSetToOCC(dataSet);
if(nullptr==vtkshp){
DebugInfo("vtkshp is nullptr\n");
return ;
}
// 设置网格的精度1.0是相对较粗的网格
double linearDeflection = 1.0;
bool relativeMode = false;
double angularDeflection = 0.5; // 角度偏差,用于更好的捕捉曲面细节
BRepMesh_IncrementalMesh meshOptimization(*vtkshp, linearDeflection, relativeMode, angularDeflection, true);
// 判断效果
if(!meshOptimization.IsDone()){
emit _mainwindow->printMessage(Common::Message::Error, "Mesh Optimization Failed");
return ;
}
else{}
QString tempStl_name=QString("stl_optimization_%1.stl").arg(generateRandomString(8));
QString tempStl_path=QString("%1/%2").arg(tempFolderPath).arg(tempStl_name);
// 保存结果
StlAPI_Writer writer;
writer.Write(*vtkshp,tempStl_path.toLocal8Bit().constData());
vtkSmartPointer<vtkSTLReader> _stlReader = vtkSmartPointer<vtkSTLReader>::New();
_stlReader->SetFileName(tempStl_path.toLocal8Bit().constData());
_stlReader->SetMerging(true);
_stlReader->Update();
surfaceData->DeepCopy(_stlReader->GetOutput());
}
QString MeshOperator::actionMeshOptimizationOCCT(vtkDataSet* dataSet,double linearDeflection , bool relativeMode ,double angularDeflection )
{
QString tempFolderPath=Setting::BusAPI::instance()->getTemperturePath(); // 获取临时文件夹
//dataset 转换为 OCCT 数据
TopoDS_Shape* vtkshp=MeshOpearator::MeshOpearatorCommon::vtkdataSetToOCC(dataSet);
if(nullptr==vtkshp){
DebugInfo("vtkshp is nullptr\n");
return "";
}
BRepMesh_IncrementalMesh meshOptimization(*vtkshp, linearDeflection, relativeMode, angularDeflection, true);
meshOptimization.Perform();
// 判断效果
if(!meshOptimization.IsDone()){
emit _mainwindow->printMessage(Common::Message::Error, "Mesh Optimization Failed");
return "";
}
else{}
QString tempStl_name=QString("stl_optimization_%1.stl").arg(generateRandomString(8));
QString tempStl_path=QString("%1/%2").arg(tempFolderPath).arg(tempStl_name);
// 保存结果
StlAPI_Writer writer;
writer.Write(*vtkshp,tempStl_path.toLocal8Bit().constData());
return tempStl_path;
}
} // namespace MeshData

View File

@ -1,6 +1,6 @@
/**
* @file MeshOperator.h
* @brief None
* @brief
* @author (3045316072@qq.com)
* @version 2.5.0
* @date 24-7-8
@ -45,14 +45,22 @@ namespace MeshData {
void on_copyMesh();
void on_clipMesh();
void on_saveMesh();
void on_selectMeshChange(int);
void SearchPoints(vtkDataSet* dataSet,const QList<int>& index,int value=0);
void SearchCells(vtkDataSet* dataSet,const QList<int>& indexs, int value=0);
// 网格表面优化算法
void actionMeshOptimizationOCCT(vtkDataSet* dataSet,vtkDataSet* surfaceData);
QString actionMeshOptimizationOCCT(vtkDataSet* dataSet,double linearDeflection , bool relativeMode ,double angularDeflection );
private:
GUI::MainWindow* _mainwindow;
GUI::MainWindow* _mainwindow;
MeshData* _meshData;
ModuleBase::SelectModel _selectModel{ModuleBase::None};
MainWidget::PreWindow* _preWindow;
MainWidget::MeshViewProvider* _meshProvider;
QMenu* _meshMenu;// 网格编辑菜单
};
} // namespace MeshData

View File

@ -0,0 +1,93 @@
/**
* @file MeshOperatorMenu.cpp
* @brief None
* @author (3045316072@qq.com)
* @version 2.5.0
* @date 24-7-14
* @copyright Copyright (c) Since 2024 All rights reserved.
*/
#include "MeshOperatorMenu.h"
#include "BDFdataExchange.h"
#include "CGNSdataExchange.h"
#include "CNTMdataExchange.h"
#include "INPdataExchange.h"
#include "IO/IOConfig.h"
#include "KEYdataExchange.h"
#include "ModelData/modelDataBase.h"
#include "ModuleBase/ThreadControl.h"
#include "ModuleBase/ThreadTaskManager.h"
#include "MSHdataExchange.h"
#include "NEUdataExchange.h"
#include "PDBdataExchange.h"
#include "SU2dataExchange.h"
#include "VTKdataExchange.h"
#include "FoamDataExchange.h"
#include "PointClouddataExchange.h"
#include "Dialogmeshsurfacesampling.h"
#include "dialogimportmodeldataset.h"
#include "Common/DebugLogger.h"
#include "AsciiOpenDialog.h"
#include <QFileInfo>
#include "MeshOperator.h"
#include "wavemodel.h"
#include <QDebug>
#include "DialogMeshOptimizationOCCT.h"
namespace MeshData {
MeshOperatorMenu::MeshOperatorMenu(GUI::MainWindow* m) {
_mainwindow = m;
QString menuName= QString("menuMeshEdit");
_menuMeshOperator=_mainwindow->getMenu(menuName);
_menuMeshOperator->setTitle(u8"网格操作");
// create
QAction *actionReLoad=_menuMeshOperator->addAction(u8"重加载网格");
QAction *actionSaveMesh=_menuMeshOperator->addAction(u8"保存边界");
_menuMeshOperator->addSeparator(); // 添加分隔符
QAction *actionMeshDelete=_menuMeshOperator->addAction(u8"网格删除");
QAction *actionMeshCopy=_menuMeshOperator->addAction(u8"网格复制");
QAction *actionMeshClip=_menuMeshOperator->addAction(u8"网格裁剪");
_menuMeshOperator->addSeparator(); // 添加分隔符
QAction *actionMeshOptimizationOCCT=_menuMeshOperator->addAction(u8"网格表面优化算法");
// slot
connect(actionMeshDelete, SIGNAL(triggered()), this,SLOT(on_deleteMesh()));
connect(actionMeshCopy, SIGNAL(triggered()), this,SLOT(on_copyMesh()));
connect(actionMeshClip, SIGNAL(triggered()), this,SLOT(on_clipMesh()));
connect(actionSaveMesh, SIGNAL(triggered()), this,SLOT(on_saveMesh()));
connect(actionMeshOptimizationOCCT, SIGNAL(triggered()), this,SLOT(on_actionMeshOptimizationOCCT()));
}
void MeshOperatorMenu::on_deleteMesh()
{
MeshOperator* _meshOperator = new MeshOperator(_mainwindow);
_meshOperator->on_deleteMesh();
}
void MeshOperatorMenu::on_copyMesh()
{
MeshOperator* _meshOperator = new MeshOperator(_mainwindow);
_meshOperator->on_copyMesh();
}
void MeshOperatorMenu::on_clipMesh()
{
MeshOperator* _meshOperator = new MeshOperator(_mainwindow);
_meshOperator->on_clipMesh();
}
void MeshOperatorMenu::on_saveMesh()
{
MeshOperator* _meshOperator = new MeshOperator(_mainwindow);
_meshOperator->on_saveMesh();
}
void MeshOperatorMenu::on_actionMeshOptimizationOCCT() {
qDebug()<<"on_actionMeshOptimizationOCCT";
MainWidget::DialogMeshOptimizationOCCT* meshOptimizationOCCT=new MainWidget::DialogMeshOptimizationOCCT(_mainwindow);
meshOptimizationOCCT->show();
}
} // namespace MeshData

View File

@ -0,0 +1,37 @@
/**
* @file MeshOperatorMenu.h
* @brief None
* @author (3045316072@qq.com)
* @version 2.5.0
* @date 24-7-14
* @copyright Copyright (c) Since 2024 All rights reserved.
*/
#ifndef LAMPCAE_MESHOPERATORMENU_H
#define LAMPCAE_MESHOPERATORMENU_H
#include "meshDataExchangePluginAPI.h"
#include "PluginManager/pluginBase.h"
#include <QMenuBar>
#include <QMenu>
namespace MeshData {
class MESHDATAEXCHANGEPLUGINAPI MeshOperatorMenu : public QObject {
Q_OBJECT
public:
MeshOperatorMenu(GUI::MainWindow* m);
~MeshOperatorMenu() = default;
private:
GUI::MainWindow* _mainwindow;
QMenu* _menuMeshOperator= nullptr;
public slots:
void on_deleteMesh();
void on_copyMesh();
void on_clipMesh();
void on_saveMesh();
void on_actionMeshOptimizationOCCT();
};
} // namespace MeshData
#endif // LAMPCAE_MESHOPERATORMENU_H

View File

@ -59,9 +59,6 @@ namespace MeshOperator {
bool OpenMeshOperator::OpenMesh2VCG(vtkSmartPointer<vtkPolyData> polydata, VCGMesh& mesh)
{
return false;
}
} // namespace MeshOperator