|
|
|
@ -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
|