添加后处理vtu、pvtu格式支持,优化cgns格式的读取以及其它问题优化

master
禅元天道 2023-06-07 10:15:08 +08:00
parent 2b3fb38cea
commit d148d592f3
197 changed files with 2361 additions and 1717 deletions

View File

@ -149,7 +149,7 @@ PointerAlignment: Left
# 允许重新排版注释 # 允许重新排版注释
ReflowComments: true ReflowComments: true
# 允许排序#include # 允许排序#include
SortIncludes: CaseInsensitive SortIncludes: Never
# 在C风格类型转换后添加空格 # 在C风格类型转换后添加空格
SpaceAfterCStyleCast: false SpaceAfterCStyleCast: false
# 在赋值运算符之前添加空格 # 在赋值运算符之前添加空格

1
.gitignore vendored
View File

@ -1,6 +1,5 @@
.vscode .vscode
.vs .vs
.idea
/build /build
/install /install
/extlib /extlib

View File

@ -66,6 +66,7 @@ option(FASTCAE_ENABLE_OPENMP "使用OpenMP" OFF)
option(FASTCAE_ENABLE_MPI "使用MPI" OFF) option(FASTCAE_ENABLE_MPI "使用MPI" OFF)
option(FASTCAE_DOXYGEN_DOC "生成Doxygen文档" OFF) option(FASTCAE_DOXYGEN_DOC "生成Doxygen文档" OFF)
option(FASTCAE_INSTALLATION_PACKAGE "生成${PROJECT_NAME}安装包" ON) option(FASTCAE_INSTALLATION_PACKAGE "生成${PROJECT_NAME}安装包" ON)
option(FASTCAE_DEBUG_INFO "输出调试信息" ON)
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# #
@ -109,6 +110,13 @@ if(FASTCAE_ENABLE_MPI)
endif() endif()
endif() endif()
#-----------------------------------------------------------------------------
#
#-----------------------------------------------------------------------------
if(FASTCAE_DEBUG_INFO)
add_definitions(-DOUTPUT_DEBUG_INFO)
endif()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Qt,Qt # Qt,Qt
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------

View File

@ -10,6 +10,7 @@ Version2.5.x
- 加入OpenGL版本检测函数当环境OPenGL版本低于3.3时,给出错误提示。 - 加入OpenGL版本检测函数当环境OPenGL版本低于3.3时,给出错误提示。
- 新增自动打包功能Windows需要NSIS 3.03+、Linux需要dpkg-deb或者rpmbuild(需要python3 - 新增自动打包功能Windows需要NSIS 3.03+、Linux需要dpkg-deb或者rpmbuild(需要python3
- 新增文档自动生成功能需要安装Doxygen和Graphviz。 - 新增文档自动生成功能需要安装Doxygen和Graphviz。
- 增加vtu、pvtu格式的后处理文件支持
**功能优化** **功能优化**
- 代码全部采用cmake进行管理可任意选择vscode、Visual Studio、Clion、Qtcreator等支持cmake系统的IDE。 - 代码全部采用cmake进行管理可任意选择vscode、Visual Studio、Clion、Qtcreator等支持cmake系统的IDE。
@ -17,6 +18,9 @@ Version2.5.x
- 删除Qt浏览器组建及相关依赖Qt安装不再需要QWebEngine组件 - 删除Qt浏览器组建及相关依赖Qt安装不再需要QWebEngine组件
- 优化Python调用不再依赖系统配置简化操作。 - 优化Python调用不再依赖系统配置简化操作。
- 从依赖库中移除未使用的VTK、OpenCASCADE模块。 - 从依赖库中移除未使用的VTK、OpenCASCADE模块。
- 优化CGNS后处理文件解析添加MIXED类型单元区域的解析。
- 优化后处理属性面板场变量数据类型的显示方式。
- 优化日志输出方式,便于错误定位
**功能修复** **功能修复**
- 修复linux环境卸载插件时崩溃的问题 - 修复linux环境卸载插件时崩溃的问题

View File

@ -9,6 +9,39 @@
- src FastCAE源码 - src FastCAE源码
- test 包含单元测试代码(待整理) - test 包含单元测试代码(待整理)
## 构建编译
### FastCAE相关的cmake构建选项说明
- `FASTCAE_AUTO_DOWNLOAD`如果源码目录不存在extlib目录时是否会自动从gitee克隆依赖包。
- `FASTCAE_DOXYGEN_DOC`是否需要构建目标Doxygen需要本地安装Doxygen软件
- `FASTCAE_ENABLE_DEV`:是否在构建完成时自动拷贝依赖文件到调试目录。(开启该选项会在每次编译完拷贝第三方依赖库文件到构建目录,会增加构建时间)
- `FASTCAE_ENABLE_MPI`是否开启MPI支持目前无效
- `FASTCAE_ENABLE_OPENMP`是否开启OpenMP。
- `FASTCAE_ENABLE_TEST`:是否构建单元测试模块(目前无效)。
- `FASTCAE_INSTALLATION_PACKAGE`是否构建安装包制作PACKAGE。
### cmake预定义目标说明
- ALL_BUILD生成所有项目。
- INSTALL安装FastCAE到CMAKE_INSTALL_PREFIX定义的目录。
- PACKAGE或者package: 在Visual Studio中该目标为大写在其它构建系统中该目标为小写用于将FastCAE打包成安装包exe、deb、rpm
- DOXYGEN: 生成FastCAE的Doxygen格式文档html
### 编译视频教程
#### Windows
- <a href="https://www.bilibili.com/video/BV1U24y1R73n/" target="_blank">cmake 3.24.1 + Visual Studio Community 2017</a>
- <a href="https://www.bilibili.com/video/BV1FX4y1y7T4/" target="_blank">QtCreator编译</a>
#### Linux
- <a href="https://www.bilibili.com/video/BV1iW4y1Y79p/" target="_blank">cmake + GNU GCC + make</a>
- <a href="https://www.bilibili.com/video/BV1xd4y1q7Cm/" target="_blank">借助vscode构建、编译、安装、打包</a>
### 编译说明
- windows环境下使用vscode时编译工具链只能使用Visual Studio目前不支持MinGW工具
### extlib目录结构 ### extlib目录结构

111
src/Common/DebugLogger.cpp Normal file
View File

@ -0,0 +1,111 @@
#include "DebugLogger.h"
#include <cstdio>
#include <cstring>
#include <ctime>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#define filename(x) strrchr(x, '\\') ? strrchr(x, '\\') + 1 : x
#else
#define filename(x) strrchr(x, '/') ? strrchr(x, '/') + 1 : x
#endif
namespace Common {
void DebugLogger::info(const char* file, int line, const char* format, ...)
{
va_list args;
va_start(args, format);
output(file, line, format, 0, args);
va_end(args);
}
void DebugLogger::warning(const char* file, int line, const char* format, ...)
{
va_list args;
va_start(args, format);
output(file, line, format, 1, args);
va_end(args);
}
void DebugLogger::error(const char* file, int line, const char* format, ...)
{
va_list args;
va_start(args, format);
output(file, line, format, 2, args);
va_end(args);
}
char* DebugLogger::currentTime()
{
time_t rawtime;
struct tm* timeS;
char* buffer = new char[80];
time(&rawtime);
timeS = localtime(&rawtime);
sprintf(buffer, "%d-%s%d-%s%d %s%d:%s%d:%s%d", timeS->tm_year + 1900,
timeS->tm_mon < 10 ? "0" : "", timeS->tm_mon, timeS->tm_mday < 10 ? "0" : "",
timeS->tm_mday, timeS->tm_hour < 10 ? "0" : "", timeS->tm_hour,
timeS->tm_min < 10 ? "0" : "", timeS->tm_min, timeS->tm_sec < 10 ? "0" : "",
timeS->tm_sec);
return buffer;
}
/**
* ESC[{attr1};{attr2};;{attrn}m
*
* 0
* 1便
* 2
* 22
* 4线
* 5
* 25
* 7
* 27
* 8
*
*
* 30
* 31
* 32绿
* 33
* 34
* 35
* 36
* 37
*
* 40
* 41
* 42绿
* 43
* 44
* 45
* 46
* 47
*/
void DebugLogger::output(const char* file, int line, const char* format, int level,
va_list args)
{
char type[15] = "";
switch(level) {
case 1:
printf("\033[33m"); // 红色
strcpy(type, "WARNING");
break;
case 2:
printf("\033[31m"); // 黄色
strcpy(type, "ERROR");
break;
default:
strcpy(type, "INFO");
break;
}
printf("[%s][%s:%d][%s]: ", currentTime(), filename(file), line, type);
vprintf(format, args);
printf("\033[0m");
}
} // namespace Common

58
src/Common/DebugLogger.h Normal file
View File

@ -0,0 +1,58 @@
/**
* @file DebugLogger.h
* @brief
* @author FastCAE(fastcae@diso.cn)
* @version 2.5.0
* @date 2023-05-11 16:12
* @copyright Copyright (c) Since 2020 All rights reserved.
*
* ============================================================================
* Program: FastCAE
*
* Copyright (c) Since 2020 All rights reserved.
* See License or http://www.fastcae.com/ for details.
*
* BSD 3-Clause License
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED.
* ==================================================================================
*/
#ifndef DEBUGLOGGER_H
#define DEBUGLOGGER_H
#include "CommonAPI.h"
#include <cstdarg>
namespace Common {
class COMMONAPI DebugLogger {
public:
DebugLogger() = delete;
~DebugLogger() = delete;
public:
static void info(const char* file, int line, const char* format, ...);
static void warning(const char* file, int line, const char* format, ...);
static void error(const char* file, int line, const char* format, ...);
protected:
static char* currentTime();
static void output(const char* file, int line, const char* format, int level, va_list args);
};
} // namespace Common
// 用宏OUTPUT_DEBUG_INFO控制调试信息是否输出的开关
#ifdef OUTPUT_DEBUG_INFO
#define DebugInfo(FORMAT, ...) Common::DebugLogger::info(__FILE__, __LINE__, FORMAT, __VA_ARGS__)
#define DebugWarn(FORMAT, ...) Common::DebugLogger::warning(__FILE__, __LINE__, FORMAT, __VA_ARGS__)
#define DebugError(FORMAT, ...) Common::DebugLogger::error(__FILE__, __LINE__, FORMAT, __VA_ARGS__)
#else
#define DebugInfo(FORMAT, ...)
#define DebugWarn(FORMAT, ...)
#define DebugError(FORMAT, ...)
#endif // OUTPUT_DEBUG_INFO
#endif

View File

@ -31,7 +31,7 @@ set_property(DIRECTORY ${CMAKE_SOURCE_DIR}
VS_STARTUP_PROJECT FastCAE VS_STARTUP_PROJECT FastCAE
) )
list(APPEND _depend_library PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence MainWindow) list(APPEND _depend_library Common PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence MainWindow)
if(_WIN_) if(_WIN_)
#list(APPEND _depend_library XGenerateReport License) #list(APPEND _depend_library XGenerateReport License)
endif() endif()

View File

@ -20,19 +20,21 @@
* DISCLAIMED. * DISCLAIMED.
* ================================================================================== * ==================================================================================
*/ */
#include "CommandLine.h"
#include "FastCAEVersionMacros.h"
#include "MainWindow/MainWindow.h"
#include "XBeautyUI.h"
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QProcess>
#include <QOpenGLContext>
#include <QMessageBox> #include <QMessageBox>
#include "MainWindow/MainWindow.h" #include <QOpenGLContext>
#include "XBeautyUI.h" #include <QProcess>
#include "CommandLine.h"
#include "FastCAEVersionMacros.h"
// #include "ConfigOptions/ConfigDataReader.h" // #include "ConfigOptions/ConfigDataReader.h"
// #include "ConfigOptions/ConfigOptions.h" // #include "ConfigOptions/ConfigOptions.h"
// #include "ConfigOptions/GlobalConfig.h" // #include "ConfigOptions/GlobalConfig.h"
#include "Common/DebugLogger.h"
#include "Settings/BusAPI.h" #include "Settings/BusAPI.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -49,21 +51,22 @@ bool testOpenGL()
bool supportOpenGLCore = false; bool supportOpenGLCore = false;
QString currentOpenGLVersion = ""; QString currentOpenGLVersion = "";
QOpenGLContext ctx; QOpenGLContext ctx;
if (ctx.create()) if(ctx.create()) {
{
auto version = ctx.format(); auto version = ctx.format();
if (version.majorVersion() > 3 || (version.majorVersion() == 3 && version.minorVersion() >= 3)) if(version.majorVersion() > 3
{ || (version.majorVersion() == 3 && version.minorVersion() >= 3)) {
supportOpenGLCore = true; supportOpenGLCore = true;
} } else {
else currentOpenGLVersion =
{ QString("%1.%2").arg(version.majorVersion()).arg(version.minorVersion());
currentOpenGLVersion = QString("%1.%2").arg(version.majorVersion()).arg(version.minorVersion());
} }
} }
if (!supportOpenGLCore) if(!supportOpenGLCore) {
{ QMessageBox::critical(nullptr, "OpenGL Error",
QMessageBox::critical(nullptr, "OpenGL Error", "Startup failed: FastCAE requires OpenGL version greater than or equal to 3.3, but the current version is " + currentOpenGLVersion, QMessageBox::Ok); "Startup failed: FastCAE requires OpenGL version greater than or "
"equal to 3.3, but the current version is "
+ currentOpenGLVersion,
QMessageBox::Ok);
} }
return supportOpenGLCore; return supportOpenGLCore;
} }
@ -86,15 +89,14 @@ int main(int argc, char *argv[])
return 1; return 1;
QApplication app(argc, argv); QApplication app(argc, argv);
if (!testOpenGL()) if(!testOpenGL()) {
{
return 1; return 1;
} }
// QString path = qApp->applicationDirPath(); // QString path = qApp->applicationDirPath();
// ConfigOption::ConfigDataReader reader(path + "/../ConfigFiles/", ConfigOption::ConfigOption::getInstance()); // ConfigOption::ConfigDataReader reader(path + "/../ConfigFiles/",
// reader.read(); // ConfigOption::ConfigOption::getInstance()); reader.read(); QString qUseRibbon =
// QString qUseRibbon = ConfigOption::ConfigOption::getInstance()->getGlobalConfig()->getUseRibbon(); // ConfigOption::ConfigOption::getInstance()->getGlobalConfig()->getUseRibbon(); bool
// bool bUseRibbon = qUseRibbon == "yes" ? true : false; // bUseRibbon = qUseRibbon == "yes" ? true : false;
bool isRibbon = Setting::BusAPI::instance()->isUseRibbon(); bool isRibbon = Setting::BusAPI::instance()->isUseRibbon();
@ -107,8 +109,7 @@ int main(int argc, char *argv[])
//**************加载qss****************** //**************加载qss******************
QFile qssFile(qssFileName); QFile qssFile(qssFileName);
if (qssFile.exists()) if(qssFile.exists()) {
{
qssFile.open(QIODevice::ReadOnly); qssFile.open(QIODevice::ReadOnly);
QString style = qssFile.readAll(); QString style = qssFile.readAll();
qApp->setStyleSheet(style); qApp->setStyleSheet(style);
@ -147,8 +148,7 @@ int main(int argc, char *argv[])
#endif #endif
#endif #endif
if (e == -1000) if(e == -1000) {
{
QProcess::startDetached(qApp->applicationFilePath(), QStringList()); QProcess::startDetached(qApp->applicationFilePath(), QStringList());
return 0; return 0;
} }

View File

@ -38,7 +38,7 @@ add_library(MainWindow
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
target_compile_definitions(MainWindow PRIVATE "MAINWINDOW_API") target_compile_definitions(MainWindow PRIVATE "MAINWINDOW_API")
list(APPEND _depend_library PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostRenderData PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence Common) list(APPEND _depend_library Common PythonModule SARibbonBar Settings DataProperty MeshData Material Geometry ConfigOptions SelfDefObject ModelData ModuleBase PluginManager GmshModule PostInterface PostRenderData PostWidgets ProjectTree GeometryCommand GeometryWidgets IO SolverControl MainWidgets UserGuidence Common)
if(_WIN_) if(_WIN_)
list(APPEND _depend_library XGenerateReport) list(APPEND _depend_library XGenerateReport)
endif() endif()

View File

@ -1248,7 +1248,7 @@ namespace GUI {
FileDirectoryDialog dlg; FileDirectoryDialog dlg;
QStringList filterTypes = { "VTK(*.vtk)", "CGNS(*.cgns)", "Plot3D(*.x)", QStringList filterTypes = { "VTK(*.vtk)", "CGNS(*.cgns)", "Plot3D(*.x)",
"Tecplot(*.szplt)" }; "Tecplot(*.szplt)","VTU(*.vtu)","PVTU(*.pvtu)" };
dlg.iniFileFilterType(filterTypes); dlg.iniFileFilterType(filterTypes);
if(dlg.exec() != QDialog::Accepted) if(dlg.exec() != QDialog::Accepted)
return; return;

View File

@ -5,7 +5,7 @@
#include <QDebug> #include <QDebug>
#include <QStringList> #include <QStringList>
#include <QTranslator> #include <QTranslator>
#include "Common/DebugLogger.h"
namespace GUI { namespace GUI {
const static QStringList Lang_List = { const static QStringList Lang_List = {
":/translations/MainWindow_zh_CN", ":/translations/MainWidgets_zh_CN", ":/translations/MainWindow_zh_CN", ":/translations/MainWidgets_zh_CN",
@ -34,8 +34,11 @@ namespace GUI {
_app->removeTranslator(tranlator); _app->removeTranslator(tranlator);
const QString lang = Lang_List.at(i); const QString lang = Lang_List.at(i);
bool ok = tranlator->load(lang); bool ok = tranlator->load(lang);
qDebug() << lang; if(ok) {
assert(ok); DebugInfo("Success to load lang file: %s\n", lang.toStdString().c_str());
} else {
DebugError("Failed to load lang file: %s\n", lang.toStdString().c_str());
}
_app->installTranslator(tranlator); _app->installTranslator(tranlator);
} }
} }

View File

@ -1,33 +1,36 @@
#include "CGNSReaderAlgorithm.h" #include "CGNSReaderAlgorithm.h"
// #include <vtkCGNSReader.h> // #include <vtkCGNSReader.h>
#include <vtkSmartPointer.h>
#include <vtkAppendFilter.h> #include <vtkAppendFilter.h>
#include <vtkMultiBlockDataSet.h> #include <vtkMultiBlockDataSet.h>
#include <vtkSmartPointer.h>
// #include <vtkDataSetMapper.h> // #include <vtkDataSetMapper.h>
#include <vtkDataSet.h>
#include <vtkUnstructuredGrid.h>
#include <vtkPointData.h>
#include <vtkCellData.h> #include <vtkCellData.h>
#include <vtkDataArray.h> #include <vtkDataArray.h>
#include <vtkDataSet.h>
#include <vtkDemandDrivenPipeline.h>
#include <vtkDoubleArray.h> #include <vtkDoubleArray.h>
#include <vtkFieldData.h> #include <vtkFieldData.h>
#include <vtkInformation.h> #include <vtkInformation.h>
#include <vtkDemandDrivenPipeline.h> #include <vtkPointData.h>
#include <vtkStreamingDemandDrivenPipeline.h> #include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkUnstructuredGrid.h>
// #include <vtkCGNSFileSeriesReader.h> // #include <vtkCGNSFileSeriesReader.h>
#include <vtkInformation.h>
#include "FCGNSReader.h" #include "FCGNSReader.h"
#include <vtkInformationStringKey.h>
#include <cgns_io.h> #include <cgns_io.h>
#include <cgnslib.h> #include <cgnslib.h>
#include <QDebug> #include <QDebug>
#include <vtkInformation.h>
#include <vtkInformationStringKey.h>
#define MAXBLOCKNUM 2000 #define MAXBLOCKNUM 2000
CGNSReaderAlgorithm::CGNSReaderAlgorithm() CGNSReaderAlgorithm::CGNSReaderAlgorithm()
{ {
this->FileName = NULL; this->FileName = NULL;
// 设置输入端口的数量
this->SetNumberOfInputPorts(0); this->SetNumberOfInputPorts(0);
// 设置输出端口的数量
this->SetNumberOfOutputPorts(MAXBLOCKNUM + 1); this->SetNumberOfOutputPorts(MAXBLOCKNUM + 1);
for(int i = 0; i < MAXBLOCKNUM; ++i) for(int i = 0; i < MAXBLOCKNUM; ++i)
@ -39,38 +42,47 @@ CGNSReaderAlgorithm::~CGNSReaderAlgorithm()
this->FileName = NULL; this->FileName = NULL;
} }
int CGNSReaderAlgorithm::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector) /**
* ProcessRequest()
* ProcessRequest()
*/
int CGNSReaderAlgorithm::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{ {
if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) // vtkDemandDrivenPipeline::REQUEST_INFORMATION()定义请求以确保输出信息是最新的
{ if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) {
return this->RequestInformation(request, inputVector, return this->RequestInformation(request, inputVector, outputVector);
outputVector);
} }
if (request->Has( // vtkDemandDrivenPipeline::REQUEST_DATA()定义了向上游传播更新范围的请求。
vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT())) if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT())) {
{ return this->RequestUpdateExtent(request, inputVector, outputVector);
return this->RequestUpdateExtent(request, inputVector,
outputVector);
} }
if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) // vtkDemandDrivenPipeline::REQUEST_DATA()定义请求以确保输出数据是最新的
{ if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) {
return this->RequestData(request, inputVector, outputVector); return this->RequestData(request, inputVector, outputVector);
} }
return this->Superclass::ProcessRequest(request, inputVector, return this->Superclass::ProcessRequest(request, inputVector, outputVector);
outputVector);
} }
/**
* @brief
int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) * @param[in]
{ * @param[in] vtkInformationVector**
if (!this->FileName) * vtkInformationVector
* @param[in]
* outputVectorvtkInformationVector
* @note
* vtkDataObjectvtkDataObobject::DATA_OBJECT()
* @since 2.5.0
*/
int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**,
vtkInformationVector* outputVector)
{ {
if(!this->FileName) {
vtkErrorMacro("A FileName must be specified."); vtkErrorMacro("A FileName must be specified.");
return 0; return 0;
} }
_blockList.clear(); _blockList.clear();
_blockNames.clear(); _blockNames.clear();
@ -97,12 +109,13 @@ int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**, vt
vtkSmartPointer<vtkAppendFilter> appFilter = vtkSmartPointer<vtkAppendFilter>::New(); vtkSmartPointer<vtkAppendFilter> appFilter = vtkSmartPointer<vtkAppendFilter>::New();
appFilter->MergePointsOn(); appFilter->MergePointsOn();
if (mBlock == nullptr) return 0; if(mBlock == nullptr)
return 0;
getBlocks(mBlock); getBlocks(mBlock);
for (int i =0;i< _blockList.size(); ++i) for(int i = 0; i < _blockList.size(); ++i) {
{ if(!_visibleStates[i])
if(!_visibleStates[i]) continue; continue;
auto dataset = _blockList.at(i); auto dataset = _blockList.at(i);
fillPointArray(dataset); fillPointArray(dataset);
@ -110,7 +123,6 @@ int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**, vt
appFilter->AddInputData(dataset); appFilter->AddInputData(dataset);
} }
appFilter->Update(); appFilter->Update();
vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector); vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector);
@ -118,9 +130,9 @@ int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**, vt
output->GetPointData()->PassData(appFilter->GetOutput()->GetPointData()); output->GetPointData()->PassData(appFilter->GetOutput()->GetPointData());
output->GetCellData()->PassData(appFilter->GetOutput()->GetCellData()); output->GetCellData()->PassData(appFilter->GetOutput()->GetCellData());
for (int i =1;i<=_blockList.size();i++) for(int i = 1; i <= _blockList.size(); i++) {
{ if(i > MAXBLOCKNUM)
if (i > MAXBLOCKNUM) break; break;
auto data = _blockList.at(i - 1); auto data = _blockList.at(i - 1);
vtkUnstructuredGrid* outData = vtkUnstructuredGrid::GetData(outputVector, i); vtkUnstructuredGrid* outData = vtkUnstructuredGrid::GetData(outputVector, i);
vtkSmartPointer<vtkAppendFilter> appFilter = vtkSmartPointer<vtkAppendFilter>::New(); vtkSmartPointer<vtkAppendFilter> appFilter = vtkSmartPointer<vtkAppendFilter>::New();
@ -128,7 +140,8 @@ int CGNSReaderAlgorithm::RequestData(vtkInformation*, vtkInformationVector**, vt
appFilter->Update(); appFilter->Update();
outData->CopyStructure(appFilter->GetOutput()); outData->CopyStructure(appFilter->GetOutput());
outData->GetPointData()->PassData(appFilter->GetOutput()->GetPointData()); outData->GetPointData()->PassData(appFilter->GetOutput()->GetPointData());
outData->GetCellData()->PassData(appFilter->GetOutput()->GetCellData());; outData->GetCellData()->PassData(appFilter->GetOutput()->GetCellData());
;
} }
return 1; return 1;
} }
@ -137,40 +150,34 @@ bool CGNSReaderAlgorithm::useVTKCGNSReader()
{ {
int currentFileIndex = 0; int currentFileIndex = 0;
int OK = cg_open(FileName, CG_MODE_READ, &currentFileIndex); int OK = cg_open(FileName, CG_MODE_READ, &currentFileIndex);
if (CG_OK != OK) return false; if(CG_OK != OK)
return false;
bool useVTK = false; bool useVTK = false;
int nBase = 0; int nBase = 0;
OK = cg_nbases(currentFileIndex, &nBase); OK = cg_nbases(currentFileIndex, &nBase);
for (int ibase = 1; ibase <= nBase; ++ibase) for(int ibase = 1; ibase <= nBase; ++ibase) {
{
int zone_node_number = 0; int zone_node_number = 0;
cg_nzones(currentFileIndex, ibase, &zone_node_number); cg_nzones(currentFileIndex, ibase, &zone_node_number);
for (int izone = 1; izone <= zone_node_number; ++izone) for(int izone = 1; izone <= zone_node_number; ++izone) {
{
CGNS_ENUMT(ZoneType_t) zonetype; CGNS_ENUMT(ZoneType_t) zonetype;
cg_zone_type(currentFileIndex, ibase, izone, &zonetype); cg_zone_type(currentFileIndex, ibase, izone, &zonetype);
if (zonetype == CGNS_ENUMV(Unstructured)) if(zonetype == CGNS_ENUMV(Unstructured)) {
{
int nSection{ 0 }; int nSection{ 0 };
cg_nsections(currentFileIndex, ibase, izone, &nSection); cg_nsections(currentFileIndex, ibase, izone, &nSection);
for (int iSec = 1;iSec <= nSection; ++iSec) for(int iSec = 1; iSec <= nSection; ++iSec) {
{
char sectionName[33] = { 0 }; char sectionName[33] = { 0 };
cgsize_t istart = 0, iend = 0; cgsize_t istart = 0, iend = 0;
int nbndry = 0, iparent_flag = 0; int nbndry = 0, iparent_flag = 0;
CGNS_ENUMT(ElementType_t) itype; CGNS_ENUMT(ElementType_t) itype;
OK = cg_section_read(currentFileIndex, ibase, izone, iSec, sectionName, &itype OK = cg_section_read(currentFileIndex, ibase, izone, iSec, sectionName, &itype,
, &istart, &iend, &nbndry, &iparent_flag); &istart, &iend, &nbndry, &iparent_flag);
if (itype >= 20) if(itype >= 20) {
{
cg_close(currentFileIndex); cg_close(currentFileIndex);
return true; return true;
} }
} }
} }
} }
} }
@ -185,7 +192,6 @@ CGNSReaderAlgorithm* CGNSReaderAlgorithm::New()
return reader; return reader;
} }
void CGNSReaderAlgorithm::PrintSelf(ostream& os, vtkIndent indent) void CGNSReaderAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
{ {
this->Superclass::PrintSelf(os, indent); this->Superclass::PrintSelf(os, indent);
@ -194,7 +200,8 @@ void CGNSReaderAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
void CGNSReaderAlgorithm::setVisible(int blockIndex, bool vis) void CGNSReaderAlgorithm::setVisible(int blockIndex, bool vis)
{ {
if (blockIndex >= MAXBLOCKNUM) return; if(blockIndex >= MAXBLOCKNUM)
return;
_visibleStates[blockIndex] = vis; _visibleStates[blockIndex] = vis;
// this->Modified(); // this->Modified();
} }
@ -214,9 +221,17 @@ QStringList CGNSReaderAlgorithm::getBlockBCTypes()
return _bcTypes; return _bcTypes;
} }
int CGNSReaderAlgorithm::FillOutputPortInformation(int port, vtkInformation* info) int CGNSReaderAlgorithm::FillInputPortInformation(int, vtkInformation*)
{
// 该算法没有输入端口
// info->Set(vtkAlgorithm::INPUT_IS_REPEATABLE(), 1);
// info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1);
// info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataSet");
return 1;
}
int CGNSReaderAlgorithm::FillOutputPortInformation(int, vtkInformation* info)
{ {
Q_UNUSED(port)
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUnstructuredGrid"); info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUnstructuredGrid");
return 1; return 1;
} }
@ -225,21 +240,18 @@ void CGNSReaderAlgorithm::getBlocks(vtkDataObject* blockData,const char* Name)
{ {
auto block = vtkMultiBlockDataSet::SafeDownCast(blockData); auto block = vtkMultiBlockDataSet::SafeDownCast(blockData);
if (block == nullptr) if(block == nullptr) {
{
auto dataset = vtkDataSet::SafeDownCast(blockData); auto dataset = vtkDataSet::SafeDownCast(blockData);
if (dataset == nullptr) return; if(dataset == nullptr)
return;
dataset->Modified(); dataset->Modified();
QString totalName = QString::fromLocal8Bit(Name); QString totalName = QString::fromLocal8Bit(Name);
QStringList NameBC = totalName.split("!|||!"); QStringList NameBC = totalName.split("!|||!");
if (NameBC.size() == 2) if(NameBC.size() == 2) {
{
_blockNames.append(NameBC.at(0)); _blockNames.append(NameBC.at(0));
_bcTypes.append(NameBC.at(1)); _bcTypes.append(NameBC.at(1));
} } else {
else
{
_blockNames.append(totalName); _blockNames.append(totalName);
_bcTypes.append("None"); _bcTypes.append("None");
} }
@ -253,8 +265,7 @@ void CGNSReaderAlgorithm::getBlocks(vtkDataObject* blockData,const char* Name)
block->Modified(); block->Modified();
const int nBlock = block->GetNumberOfBlocks(); const int nBlock = block->GetNumberOfBlocks();
for (int i = 0; i < nBlock; i++) for(int i = 0; i < nBlock; i++) {
{
vtkDataObject* obj = block->GetBlock(i); vtkDataObject* obj = block->GetBlock(i);
const char* currentName = block->GetMetaData(i)->Get(vtkCompositeDataSet::NAME()); const char* currentName = block->GetMetaData(i)->Get(vtkCompositeDataSet::NAME());
getBlocks(obj, currentName); getBlocks(obj, currentName);
@ -263,44 +274,50 @@ void CGNSReaderAlgorithm::getBlocks(vtkDataObject* blockData,const char* Name)
void CGNSReaderAlgorithm::getPointArray(vtkDataSet* dataset) void CGNSReaderAlgorithm::getPointArray(vtkDataSet* dataset)
{ {
if (dataset == nullptr) return; if(dataset == nullptr)
return;
auto pointData = dataset->GetPointData(); auto pointData = dataset->GetPointData();
if (pointData == nullptr) return; if(pointData == nullptr)
return;
const int nPointArray = pointData->GetNumberOfArrays(); const int nPointArray = pointData->GetNumberOfArrays();
for (int i = 0; i < nPointArray; i++) for(int i = 0; i < nPointArray; i++) {
{
const char* aName = pointData->GetArrayName(i); const char* aName = pointData->GetArrayName(i);
auto dataArray = pointData->GetArray(aName); auto dataArray = pointData->GetArray(aName);
if (dataArray == nullptr) return; //continue; if(dataArray == nullptr)
return; // continue;
int aNum[2]{ 0 }; int aNum[2]{ 0 };
aNum[0] = dataArray->GetNumberOfComponents(); aNum[0] = dataArray->GetNumberOfComponents();
aNum[1] = dataArray->GetNumberOfTuples(); aNum[1] = dataArray->GetNumberOfTuples();
if (_pointDataArray.contains(aName)) continue; if(_pointDataArray.contains(aName))
continue;
_pointDataArray.insert(aName, aNum); _pointDataArray.insert(aName, aNum);
} }
} }
void CGNSReaderAlgorithm::getCellArray(vtkDataSet* dataset) void CGNSReaderAlgorithm::getCellArray(vtkDataSet* dataset)
{ {
if (dataset == nullptr) return; if(dataset == nullptr)
return;
auto cellData = dataset->GetCellData(); auto cellData = dataset->GetCellData();
if (cellData == nullptr) return; if(cellData == nullptr)
return;
const int nCellArray = cellData->GetNumberOfArrays(); const int nCellArray = cellData->GetNumberOfArrays();
for (int i = 0; i < nCellArray; i++) for(int i = 0; i < nCellArray; i++) {
{
const char* aName = cellData->GetArrayName(i); const char* aName = cellData->GetArrayName(i);
auto dataArray = cellData->GetArray(aName); auto dataArray = cellData->GetArray(aName);
if (dataArray == nullptr) return; //continue; if(dataArray == nullptr)
return; // continue;
int aNum[2]{ 0 }; int aNum[2]{ 0 };
aNum[0] = dataArray->GetNumberOfComponents(); aNum[0] = dataArray->GetNumberOfComponents();
aNum[1] = dataArray->GetNumberOfTuples(); aNum[1] = dataArray->GetNumberOfTuples();
if (_cellDataArray.contains(aName)) continue; if(_cellDataArray.contains(aName))
continue;
_cellDataArray.insert(aName, aNum); _cellDataArray.insert(aName, aNum);
} }
} }
@ -329,7 +346,6 @@ void CGNSReaderAlgorithm::fillPointArray(vtkDataSet* dataset)
// //
// pointData->AddArray(dataArray); // pointData->AddArray(dataArray);
// } // }
} }
void CGNSReaderAlgorithm::fillCellArray(vtkDataSet* dataset) void CGNSReaderAlgorithm::fillCellArray(vtkDataSet* dataset)

View File

@ -3,24 +3,34 @@
#include "PostAlgorithmAPI.h" #include "PostAlgorithmAPI.h"
#include "PostRenderData/Macros.hxx" #include "PostRenderData/Macros.hxx"
#include <vtkUnstructuredGridAlgorithm.h>
#include <QString>
#include <QHash> #include <QHash>
#include <QString>
#include <vtkUnstructuredGridAlgorithm.h>
ForwardDeclar(vtkInformation) ForwardDeclar(vtkInformation);
ForwardDeclar(vtkDataSet) ForwardDeclar(vtkDataSet);
ForwardDeclar(vtkDataObject) ForwardDeclar(vtkDataObject);
ForwardDeclar(vtkDataArray) ForwardDeclar(vtkDataArray);
class POSTALGORITHMAPI CGNSReaderAlgorithm :public vtkUnstructuredGridAlgorithm class POSTALGORITHMAPI CGNSReaderAlgorithm : public vtkUnstructuredGridAlgorithm {
{
public: public:
static CGNSReaderAlgorithm* New(); static CGNSReaderAlgorithm* New();
vtkTypeMacro(CGNSReaderAlgorithm, vtkUnstructuredGridAlgorithm); vtkTypeMacro(CGNSReaderAlgorithm, vtkUnstructuredGridAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent); /**
* @brief ()
*
* @param[in] os
* @param[in] indent
*/
void PrintSelf(ostream& os, vtkIndent indent) override;
/** @name Set/Get宏
* setter/gettervtkSetMacro(FileName, char*)/vtkGetMacro(FileName, char*)
* @{
*/
vtkSetStringMacro(FileName); vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName); vtkGetStringMacro(FileName);
/** @} */
void setVisible(int blockIndex, bool vis); void setVisible(int blockIndex, bool vis);
@ -30,7 +40,16 @@ public:
QStringList getBlockBCTypes(); QStringList getBlockBCTypes();
int FillOutputPortInformation(int port, vtkInformation* info); /**
* @brief
* @param[in] port 0
*/
int FillInputPortInformation(int port, vtkInformation* info) override;
/**
* @brief
* @param[in] port 0
*/
int FillOutputPortInformation(int port, vtkInformation* info) override;
/** /**
* @brief * @brief
@ -62,8 +81,22 @@ protected:
CGNSReaderAlgorithm(); CGNSReaderAlgorithm();
~CGNSReaderAlgorithm(); ~CGNSReaderAlgorithm();
int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector); /**
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*); * @brief VTK/
*
* vtkAlgorithm::ProcessRequest()
*
* ProcessRequest().
*
* \param request
* \param inputVector
* \param outputVector
* \return
*/
int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector) override;
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
bool useVTKCGNSReader(); bool useVTKCGNSReader();

View File

@ -28,6 +28,8 @@ add_library(PostAlgorithm
target_compile_definitions(PostAlgorithm PRIVATE "POSTALGORITHM_API") target_compile_definitions(PostAlgorithm PRIVATE "POSTALGORITHM_API")
#target_compile_definitions(PostAlgorithm PRIVATE "H5_BUILT_AS_DYNAMIC_LIB") #target_compile_definitions(PostAlgorithm PRIVATE "H5_BUILT_AS_DYNAMIC_LIB")
list(APPEND _depend_library Common)
list(APPEND _runtimes_libraries list(APPEND _runtimes_libraries
FASTCAE::CGNS FASTCAE::HDF5 FASTCAE::HDF5CPP FASTCAE::TECIO Qt5::Core VTK::CommonColor VTK::CommonComputationalGeometry VTK::CommonCore VTK::CommonDataModel VTK::CommonExecutionModel VTK::CommonMath VTK::CommonMisc VTK::CommonSystem VTK::CommonTransforms VTK::DICOMParser VTK::FiltersCore VTK::FiltersExtraction VTK::FiltersGeneral VTK::FiltersGeometry VTK::FiltersHybrid VTK::FiltersModeling VTK::FiltersParallel VTK::FiltersSources VTK::FiltersStatistics VTK::FiltersTexture VTK::IOCore VTK::IOGeometry VTK::IOImage VTK::IOLegacy VTK::IOParallel VTK::IOXML VTK::IOXMLParser VTK::ImagingCore VTK::ImagingFourier VTK::ImagingSources VTK::ParallelCore VTK::ParallelDIY VTK::RenderingCore VTK::doubleconversion VTK::expat VTK::jpeg VTK::jsoncpp VTK::lz4 VTK::lzma VTK::metaio VTK::png VTK::pugixml VTK::sys VTK::tiff VTK::zlib FASTCAE::CGNS FASTCAE::HDF5 FASTCAE::HDF5CPP FASTCAE::TECIO Qt5::Core VTK::CommonColor VTK::CommonComputationalGeometry VTK::CommonCore VTK::CommonDataModel VTK::CommonExecutionModel VTK::CommonMath VTK::CommonMisc VTK::CommonSystem VTK::CommonTransforms VTK::DICOMParser VTK::FiltersCore VTK::FiltersExtraction VTK::FiltersGeneral VTK::FiltersGeometry VTK::FiltersHybrid VTK::FiltersModeling VTK::FiltersParallel VTK::FiltersSources VTK::FiltersStatistics VTK::FiltersTexture VTK::IOCore VTK::IOGeometry VTK::IOImage VTK::IOLegacy VTK::IOParallel VTK::IOXML VTK::IOXMLParser VTK::ImagingCore VTK::ImagingFourier VTK::ImagingSources VTK::ParallelCore VTK::ParallelDIY VTK::RenderingCore VTK::doubleconversion VTK::expat VTK::jpeg VTK::jsoncpp VTK::lz4 VTK::lzma VTK::metaio VTK::png VTK::pugixml VTK::sys VTK::tiff VTK::zlib
) )
@ -37,8 +39,14 @@ list(APPEND _runtimes_libraries
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
target_link_libraries(PostAlgorithm PRIVATE target_link_libraries(PostAlgorithm PRIVATE
${_runtimes_libraries} ${_runtimes_libraries}
${_depend_library}
) )
#-----------------------------------------------------------------------------
#
#-----------------------------------------------------------------------------
add_dependencies(PostAlgorithm ${_depend_library})
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# #
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------

View File

@ -1,15 +1,17 @@
#include "FCGNSGridReaderBase.h" #include "FCGNSGridReaderBase.h"
#include <cgnstypes.h>
#include "Common/DebugLogger.h"
#include <cgns_io.h> #include <cgns_io.h>
#include <cgnslib.h> #include <cgnslib.h>
#include <QDebug> #include <cgnstypes.h>
#include <vtkDataSet.h>
#include <vtkPointData.h>
#include <vtkCellData.h> #include <vtkCellData.h>
#include <vtkDataSet.h>
#include <vtkDoubleArray.h> #include <vtkDoubleArray.h>
#include <vtkFloatArray.h> #include <vtkFloatArray.h>
#include <vtkStructuredGrid.h>
#include <vtkNew.h> #include <vtkNew.h>
#include <vtkPointData.h>
#include <vtkStructuredGrid.h>
FCGNSGridReaderBase::FCGNSGridReaderBase(vtkMultiBlockDataSet* root) FCGNSGridReaderBase::FCGNSGridReaderBase(vtkMultiBlockDataSet* root)
: _root(root) : _root(root)
@ -23,72 +25,78 @@ void FCGNSGridReaderBase::setInfo(int fileIndex, int baseIndex, int zoneIndex)
_zoneIndex = zoneIndex; _zoneIndex = zoneIndex;
} }
void FCGNSGridReaderBase::readCoordinate(int dim, int count, cgsize_t rangeMin[3], cgsize_t rangeMax[3]) void FCGNSGridReaderBase::readCoordinate(int dim, int count, cgsize_t rangeMin[3],
cgsize_t rangeMax[3])
{ {
_vertexList.clear(); _vertexList.clear();
_vertexList.fill(VPoint(), count); _vertexList.fill(VPoint(), count);
// 坐标名称CoordinateXCoordinateYCoordinateZCoordinateRCoordinateThetaCoordinatePhi等
// 参考http://cgns.github.io/CGNS_docs_current/sids/dataname.html#dataname_grid
char coordinate_name[33] = { 0 }; char coordinate_name[33] = { 0 };
CGNS_ENUMV(DataType_t) // 坐标值的数据类型RealSingle 或者 RealDouble
datatype; CGNS_ENUMV(DataType_t) datatype;
int OK = 0; int result = 0;
for (int i = 1; i <= dim; ++i) for(int i = 1; i <= dim; ++i) {
{ // 读取坐标信息,构建数据存储数组
OK = cg_coord_info(_fileIndex, _baseIndex, _zoneIndex, i, &datatype, coordinate_name); result = cg_coord_info(_fileIndex, _baseIndex, _zoneIndex, i, &datatype, coordinate_name);
if (CG_OK != OK) if(CG_OK != result) {
continue; DebugError("Failed to get coordinate(index = %d) info\n", i);
break;
}
void* xyz{ nullptr }; void* xyz{ nullptr };
if (datatype == CGNS_ENUMV(RealSingle)) if(datatype == CGNS_ENUMV(RealSingle)) {
xyz = new float[count]; xyz = new float[count];
else if (datatype == CGNS_ENUMV(RealDouble)) } else if(datatype == CGNS_ENUMV(RealDouble)) {
xyz = new double[count]; xyz = new double[count];
if (xyz == nullptr) } else {
continue; DebugError("Invalid data type for coordinate: %s\n", coordinate_name);
break;
}
OK = cg_coord_read(_fileIndex, _baseIndex, _zoneIndex, coordinate_name, datatype, rangeMin, rangeMax, xyz); // 读取坐标数据
if (OK != 0) // 官方文档datatype不需要区分RealSingle或者RealDouble可以自动处理但是由于数据量一般比较大考虑
continue; // 节约内存也可以做区分The function cg_coord_read returns the coordinate array
// coord_array, for the range prescribed by range_min and range_max. The array is returned
// to the application in the data type requested in mem_datatype. This data type does not
// need to be the same as the one in which the coordinates are stored in the file. A
// coordinate array stored as double precision in the CGNS file can be returned to the
// application as single precision, or vice versa. The functions cg_coord_general_read and
// cg_coord_general_write allow for type conversion when both reading from and writing to
// the file.
result = cg_coord_read(_fileIndex, _baseIndex, _zoneIndex, coordinate_name, datatype,
rangeMin, rangeMax, xyz);
if(CG_OK != result) {
DebugError("Failed to read grid coordinate: %s\n", coordinate_name);
break;
}
if (!strcmp(coordinate_name, "CoordinateX")) if(strcmp(coordinate_name, "CoordinateX") == 0) {
{ if(datatype == CGNS_ENUMV(RealDouble)) {
if (datatype == CGNS_ENUMV(RealDouble))
{
auto* c = static_cast<double*>(xyz); auto* c = static_cast<double*>(xyz);
for(int ipt = 0; ipt < count; ++ipt) for(int ipt = 0; ipt < count; ++ipt)
_vertexList[ipt].x = c[ipt]; _vertexList[ipt].x = c[ipt];
} } else if(datatype == CGNS_ENUMV(RealSingle)) {
else if (datatype == CGNS_ENUMV(RealSingle))
{
auto* c = static_cast<float*>(xyz); auto* c = static_cast<float*>(xyz);
for(int ipt = 0; ipt < count; ++ipt) for(int ipt = 0; ipt < count; ++ipt)
_vertexList[ipt].x = c[ipt]; _vertexList[ipt].x = c[ipt];
} }
} } else if(strcmp(coordinate_name, "CoordinateY") == 0) {
else if (!strcmp(coordinate_name, "CoordinateY")) if(datatype == CGNS_ENUMV(RealDouble)) {
{
if (datatype == CGNS_ENUMV(RealDouble))
{
auto* c = static_cast<double*>(xyz); auto* c = static_cast<double*>(xyz);
for(int ipt = 0; ipt < count; ++ipt) for(int ipt = 0; ipt < count; ++ipt)
_vertexList[ipt].y = c[ipt]; _vertexList[ipt].y = c[ipt];
} } else if(datatype == CGNS_ENUMV(RealSingle)) {
else if (datatype == CGNS_ENUMV(RealSingle))
{
auto* c = static_cast<float*>(xyz); auto* c = static_cast<float*>(xyz);
for(int ipt = 0; ipt < count; ++ipt) for(int ipt = 0; ipt < count; ++ipt)
_vertexList[ipt].y = c[ipt]; _vertexList[ipt].y = c[ipt];
} }
} } else if(dim == 3 && (strcmp(coordinate_name, "CoordinateZ") == 0)) {
else if (!strcmp(coordinate_name, "CoordinateZ")) if(datatype == CGNS_ENUMV(RealDouble)) {
{
if (datatype == CGNS_ENUMV(RealDouble))
{
auto* c = static_cast<double*>(xyz); auto* c = static_cast<double*>(xyz);
for(int ipt = 0; ipt < count; ++ipt) for(int ipt = 0; ipt < count; ++ipt)
_vertexList[ipt].z = c[ipt]; _vertexList[ipt].z = c[ipt];
} } else if(datatype == CGNS_ENUMV(RealSingle)) {
else if (datatype == CGNS_ENUMV(RealSingle))
{
auto* c = static_cast<float*>(xyz); auto* c = static_cast<float*>(xyz);
for(int ipt = 0; ipt < count; ++ipt) for(int ipt = 0; ipt < count; ++ipt)
_vertexList[ipt].z = c[ipt]; _vertexList[ipt].z = c[ipt];
@ -97,30 +105,36 @@ void FCGNSGridReaderBase::readCoordinate(int dim, int count, cgsize_t rangeMin[3
} }
if(datatype == CGNS_ENUMV(RealSingle)) if(datatype == CGNS_ENUMV(RealSingle))
delete (float *)xyz; delete[](float*)xyz;
else if(datatype == CGNS_ENUMV(RealDouble)) else if(datatype == CGNS_ENUMV(RealDouble))
delete (double *)xyz; delete[](double*)xyz;
} }
} }
void FCGNSGridReaderBase::readFlowSolution(vtkDataSet* grid) void FCGNSGridReaderBase::readFlowSolution(vtkDataSet* grid)
{ {
int OK = 0; int result = 0;
int nsol = 0; int nsol = 0;
OK = cg_nsols(_fileIndex, _baseIndex, _zoneIndex, &nsol); result = cg_nsols(_fileIndex, _baseIndex, _zoneIndex, &nsol);
if (CG_OK != OK) if(CG_OK != result) {
DebugError("Failed to read number of flow solution\n");
return; return;
} else {
DebugInfo("Number of flow solution is %d\n", nsol);
}
_dataSet = grid; _dataSet = grid;
for (int isol = 1; isol <= nsol; ++isol) for(int isol = 1; isol <= nsol; ++isol) {
{ CGNS_ENUMT(GridLocation_t) varloc;
CGNS_ENUMT(GridLocation_t)
varloc;
char sol_name[33] = { 0 }; char sol_name[33] = { 0 };
OK = cg_sol_info(_fileIndex, _baseIndex, _zoneIndex, isol, sol_name, &varloc); result = cg_sol_info(_fileIndex, _baseIndex, _zoneIndex, isol, sol_name, &varloc);
if (CG_OK != OK) if(CG_OK != result) {
continue; DebugError("Failed to read info of flow solution\n");
qDebug() << sol_name << varloc; return;
} else {
DebugInfo("Flow solution: %s, var location: %d\n", sol_name, varloc);
}
QList<QString> varNames; QList<QString> varNames;
QList<void*> values; QList<void*> values;
@ -137,32 +151,39 @@ void FCGNSGridReaderBase::readFlowSolution(vtkDataSet *grid)
} }
void FCGNSGridReaderBase::readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t) loc, void FCGNSGridReaderBase::readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t) loc,
QList<QString> &varNames, QList<int> &valueType, QList<void *> &values) QList<QString>& varNames, QList<int>& valueType,
QList<void*>& values)
{ {
qDebug() << loc;
if(loc != CGNS_ENUMT(Vertex) && loc != CGNS_ENUMT(CellCenter)) if(loc != CGNS_ENUMT(Vertex) && loc != CGNS_ENUMT(CellCenter))
return;
int OK = 0;
int var_num = 0;
OK = cg_nfields(_fileIndex, _baseIndex, _zoneIndex, solIndex, &var_num);
if (CG_OK != OK)
return;
int valNum = 0;
for (int iFiled = 1; iFiled <= var_num; ++iFiled)
{ {
CGNS_ENUMT(DataType_t) DebugError("Unsupported grid location: %d\n", loc);
datatype; return;
char var_name[33] = {0}; }
OK = cg_field_info(_fileIndex, _baseIndex, _zoneIndex, solIndex, iFiled, &datatype, var_name); int OK = 0;
int nFields = 0;
OK = cg_nfields(_fileIndex, _baseIndex, _zoneIndex, solIndex, &nFields);
if(CG_OK != OK) if(CG_OK != OK)
continue; {
qDebug() << var_name << datatype; DebugError("Failed to read number of fields\n");
return;
}
int valNum = 0;
for(int iField = 1; iField <= nFields; ++iField) {
CGNS_ENUMT(DataType_t) datatype;
char fieldName[33] = { 0 };
OK = cg_field_info(_fileIndex, _baseIndex, _zoneIndex, solIndex, iField, &datatype,
fieldName);
if(CG_OK != OK) {
DebugError("Failed to read info of field[%d]\n", iField);
return;
} else
{
DebugInfo("Begin to parse field: %s\n", fieldName);
}
cgsize_t min[3] = { 1, 1, 1 }, max[3] = { 0 }; cgsize_t min[3] = { 1, 1, 1 }, max[3] = { 0 };
if (!_isStructedGrid) if(!_isStructedGrid) {
{ switch(loc) {
switch (loc)
{
case CGNS_ENUMT(Vertex): case CGNS_ENUMT(Vertex):
valNum = max[0] = max[1] = max[2] = _dataSet->GetNumberOfPoints(); valNum = max[0] = max[1] = max[2] = _dataSet->GetNumberOfPoints();
break; break;
@ -172,14 +193,11 @@ void FCGNSGridReaderBase::readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t)
default: default:
break; break;
} }
} } else {
else
{
auto sG = vtkStructuredGrid::SafeDownCast(_dataSet); auto sG = vtkStructuredGrid::SafeDownCast(_dataSet);
int dims[3]; int dims[3];
sG->GetDimensions(dims); sG->GetDimensions(dims);
switch (loc) switch(loc) {
{
case CGNS_ENUMT(Vertex): case CGNS_ENUMT(Vertex):
max[0] = dims[0]; max[0] = dims[0];
max[1] = dims[1]; max[1] = dims[1];
@ -204,36 +222,38 @@ void FCGNSGridReaderBase::readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t)
else if(datatype == CGNS_ENUMT(RealDouble)) else if(datatype == CGNS_ENUMT(RealDouble))
valuesArr = new double[valNum]; valuesArr = new double[valNum];
OK = cg_field_read(_fileIndex, _baseIndex, _zoneIndex, solIndex, var_name, datatype, min, max, valuesArr); OK = cg_field_read(_fileIndex, _baseIndex, _zoneIndex, solIndex, fieldName, datatype, min,
if (CG_OK != OK) max, valuesArr);
continue; if(CG_OK != OK) {
DebugError("Failed to read flow solution for %s\n", fieldName);
return;
}
varNames.append(var_name); varNames.append(fieldName);
values.append(valuesArr);
valueType.append(datatype); valueType.append(datatype);
values.append(valuesArr);
} }
} }
void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc, void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc, QList<QString> varNames,
QList<QString> varNames, QList<int> vType, QList<void *> valueList) QList<int> vType, QList<void*> valueList)
{ {
QHash<QString, QHash<QString, QString>> vectorName; QHash<QString, QHash<QString, QString>> vectorName;
QStringList scalarName; QStringList scalarName;
for (QString varName : varNames) for(QString varName : varNames) {
{
QString component, vecName; QString component, vecName;
bool isV = isVectorComponent(varName, vecName, component); bool isV = isVectorComponent(varName, vecName, component);
if (!isV) if(isV) {
vectorName[vecName].insert(component.toLower(), varName);
} else
{ {
scalarName.append(varName); scalarName.append(varName);
continue;
} }
vectorName[vecName].insert(component.toLower(), varName);
} }
QStringList vecKeys = vectorName.keys(); QStringList vecKeys = vectorName.keys();
QStringList unVkeys; QStringList unVkeys;
for (QString vecKey : vecKeys) for(QString vecKey : vecKeys) {
{
QHash<QString, QString> vvs = vectorName.value(vecKey); QHash<QString, QString> vvs = vectorName.value(vecKey);
if(vvs.size() == _dim) if(vvs.size() == _dim)
continue; continue;
@ -243,12 +263,10 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
for(QString uk : unVkeys) for(QString uk : unVkeys)
vectorName.remove(uk); vectorName.remove(uk);
if (CGNS_ENUMT(Vertex) == loc) if(CGNS_ENUMT(Vertex) == loc) {
{
int nc = _dataSet->GetNumberOfPoints(); int nc = _dataSet->GetNumberOfPoints();
auto pointArray = _dataSet->GetPointData(); auto* pointArray = _dataSet->GetPointData();
for (QString sca : scalarName) for(QString sca : scalarName) {
{
int index = varNames.indexOf(sca); int index = varNames.indexOf(sca);
int type = vType.at(index); int type = vType.at(index);
void* v = valueList.at(index); void* v = valueList.at(index);
@ -256,8 +274,7 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
pointArray->AddArray(array); pointArray->AddArray(array);
} }
for (QString vec : vectorName.keys()) for(QString vec : vectorName.keys()) {
{
QHash<QString, QString> comps = vectorName.value(vec); QHash<QString, QString> comps = vectorName.value(vec);
QString comp = comps.value("x"); QString comp = comps.value("x");
int index = varNames.indexOf(comp); int index = varNames.indexOf(comp);
@ -273,8 +290,7 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
index = varNames.indexOf(comp); index = varNames.indexOf(comp);
void* z = nullptr; void* z = nullptr;
int ztype = 0; int ztype = 0;
if (index >= 0) if(index >= 0) {
{
z = valueList.at(index); z = valueList.at(index);
ztype = vType.at(index); ztype = vType.at(index);
} }
@ -282,13 +298,10 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
auto array = generateVectorArray(vec, nc, xtype, x, ytype, y, ztype, z); auto array = generateVectorArray(vec, nc, xtype, x, ytype, y, ztype, z);
pointArray->AddArray(array); pointArray->AddArray(array);
} }
} } else if(CGNS_ENUMT(CellCenter) == loc) {
else if (CGNS_ENUMT(CellCenter) == loc)
{
int nc = _dataSet->GetNumberOfCells(); int nc = _dataSet->GetNumberOfCells();
auto cellArray = _dataSet->GetCellData(); auto cellArray = _dataSet->GetCellData();
for (QString sca : scalarName) for(QString sca : scalarName) {
{
int index = varNames.indexOf(sca); int index = varNames.indexOf(sca);
void* v = valueList.at(index); void* v = valueList.at(index);
int type = vType.at(index); int type = vType.at(index);
@ -296,8 +309,7 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
cellArray->AddArray(array); cellArray->AddArray(array);
} }
for (QString vec : vectorName.keys()) for(QString vec : vectorName.keys()) {
{
QHash<QString, QString> comps = vectorName.value(vec); QHash<QString, QString> comps = vectorName.value(vec);
QString comp = comps.value("x"); QString comp = comps.value("x");
int index = varNames.indexOf(comp); int index = varNames.indexOf(comp);
@ -313,8 +325,7 @@ void FCGNSGridReaderBase::addValueToGrid(CGNS_ENUMT(GridLocation_t) loc,
index = varNames.indexOf(comp); index = varNames.indexOf(comp);
void* z = nullptr; void* z = nullptr;
int ztype = 0; int ztype = 0;
if (index >= 0) if(index >= 0) {
{
z = valueList.at(index); z = valueList.at(index);
ztype = vType.at(index); ztype = vType.at(index);
} }
@ -330,8 +341,7 @@ bool FCGNSGridReaderBase::isVectorComponent(QString name, QString &vecName, QStr
QRegExp pattern("\\s*x$|\\s*X$|\\s*y$|\\s*Y$|\\s*z$|\\s*Z$"); QRegExp pattern("\\s*x$|\\s*X$|\\s*y$|\\s*Y$|\\s*z$|\\s*Z$");
bool is = false; bool is = false;
is = name.contains(pattern); is = name.contains(pattern);
if (is) if(is) {
{
comp = name.right(1); comp = name.right(1);
vecName = name.remove(comp); vecName = name.remove(comp);
if(vecName.isEmpty()) if(vecName.isEmpty())
@ -350,8 +360,7 @@ vtkDataArray *FCGNSGridReaderBase::generateScalarArray(QString varName, int num,
{ {
array = vtkFloatArray::New(); array = vtkFloatArray::New();
valueFloat = static_cast<float*>(va); valueFloat = static_cast<float*>(va);
} } else if(type == 4) // double
else if (type == 4) // double
{ {
array = vtkDoubleArray::New(); array = vtkDoubleArray::New();
valueDouble = static_cast<double*>(va); valueDouble = static_cast<double*>(va);
@ -359,10 +368,8 @@ vtkDataArray *FCGNSGridReaderBase::generateScalarArray(QString varName, int num,
double v = 0; double v = 0;
array->SetName(varName.toLatin1().data()); array->SetName(varName.toLatin1().data());
for (int i = 0; i < num; ++i) for(int i = 0; i < num; ++i) {
{ switch(type) {
switch (type)
{
case 3: case 3:
v = valueFloat[i]; v = valueFloat[i];
break; break;
@ -377,12 +384,11 @@ vtkDataArray *FCGNSGridReaderBase::generateScalarArray(QString varName, int num,
double range[2]; double range[2];
array->GetRange(range); array->GetRange(range);
qDebug() << varName << range[0] << range[1];
return array; return array;
} }
vtkDataArray *FCGNSGridReaderBase::generateVectorArray(QString varName, int num, vtkDataArray* FCGNSGridReaderBase::generateVectorArray(QString varName, int num, int xType, void* x,
int xType, void *x, int yType, void *y, int zType, void *z) int yType, void* y, int zType, void* z)
{ {
auto array = vtkDoubleArray::New(); auto array = vtkDoubleArray::New();
array->SetName(varName.toLatin1().data()); array->SetName(varName.toLatin1().data());
@ -410,10 +416,8 @@ vtkDataArray *FCGNSGridReaderBase::generateVectorArray(QString varName, int num,
zDV = static_cast<double*>(z); zDV = static_cast<double*>(z);
double vx = 0, vy = 0, vz = 0; double vx = 0, vy = 0, vz = 0;
for (int i = 0; i < num; ++i) for(int i = 0; i < num; ++i) {
{ switch(xType) {
switch (xType)
{
case 3: case 3:
vx = xFV[i]; vx = xFV[i];
break; break;
@ -424,8 +428,7 @@ vtkDataArray *FCGNSGridReaderBase::generateVectorArray(QString varName, int num,
break; break;
} }
switch (yType) switch(yType) {
{
case 3: case 3:
vy = yFV[i]; vy = yFV[i];
break; break;
@ -436,8 +439,7 @@ vtkDataArray *FCGNSGridReaderBase::generateVectorArray(QString varName, int num,
break; break;
} }
switch (zType) switch(zType) {
{
case 3: case 3:
vz = zFV[i]; vz = zFV[i];
break; break;

View File

@ -1,58 +1,153 @@
#ifndef _FCGNSGRIDREADER_H__ #ifndef _FCGNSGRIDREADER_H__
#define _FCGNSGRIDREADER_H__ #define _FCGNSGRIDREADER_H__
#include <QVector>
#include <cgnstypes.h>
#include <cgnslib.h> #include <cgnslib.h>
#include <cgnstypes.h>
#include <QHash> #include <QHash>
#include <QVector>
class vtkMultiBlockDataSet; class vtkMultiBlockDataSet;
class vtkDataSet; class vtkDataSet;
class vtkDataArray; class vtkDataArray;
struct VPoint /**
{ * @brief
* @since 2.5.0
*/
struct VPoint {
double x{ 0 }; double x{ 0 };
double y{ 0 }; double y{ 0 };
double z{ 0 }; double z{ 0 };
}; };
class FCGNSGridReaderBase class FCGNSGridReaderBase {
{
public: public:
/**
* @brief
* @param[out] root vtkMultiBlockDataSet
*/
FCGNSGridReaderBase(vtkMultiBlockDataSet* root); FCGNSGridReaderBase(vtkMultiBlockDataSet* root);
virtual ~FCGNSGridReaderBase() = default; virtual ~FCGNSGridReaderBase() = default;
/**
* @brief zone
*
* @param[in] fileIndex
* @param[in] baseIndex base
* @param[in] zoneIndex zone
*/
void setInfo(int fileIndex, int baseIndex, int zoneIndex); void setInfo(int fileIndex, int baseIndex, int zoneIndex);
/**
* @brief zone
* @since 2.5.0
*/
virtual void read() = 0; virtual void read() = 0;
protected: protected:
/**
* @brief zone
* @param[in] dim
* @param[in] count
* @param[out] range_from 1
* @param[out] range_to
* @since 2.5.0
*/
void readCoordinate(int dim, int count, cgsize_t range_from[3], cgsize_t range_to[3]); void readCoordinate(int dim, int count, cgsize_t range_from[3], cgsize_t range_to[3]);
/**
* @brief zone
* @param[out] grid vtkDataSet
* @since 2.5.0
*/
void readFlowSolution(vtkDataSet* grid); void readFlowSolution(vtkDataSet* grid);
/**
* @brief
* @param[in] solIndex
* @param[in] loc
* @param[out] varNames
* @param[out] valueType
* @param[out] values
* @since 2.5.0
*/
void readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t) loc, QList<QString>& varNames, void readFieldData(int solIndex, CGNS_ENUMT(GridLocation_t) loc, QList<QString>& varNames,
QList<int>& valueType, QList<void*>& values); QList<int>& valueType, QList<void*>& values);
/**
* @brief vtk
* @param[in] loc
* @param[in] varNames
* @param[in] valueType
* @param[in] values
* @since 2.5.0
*/
void addValueToGrid(CGNS_ENUMT(GridLocation_t) loc, QList<QString> varNames, void addValueToGrid(CGNS_ENUMT(GridLocation_t) loc, QList<QString> varNames,
QList<int> valueType, QList<void*> values); QList<int> valueType, QList<void*> values);
/**
* @brief
* @param[in] name
* @param[out] vecName x,y,z
* @param[out] comp (x,y,z)
* @note x,y,z()
* @since 2.5.0
*/
bool isVectorComponent(QString name, QString& vecName, QString& comp); bool isVectorComponent(QString name, QString& vecName, QString& comp);
/**
* @brief vtkDataArray
* @param[in] varName
* @param[in] num
* @param[in] type
* @param[in] va
* @since 2.5.0
*/
vtkDataArray* generateScalarArray(QString varName, int num, int type, void* va); vtkDataArray* generateScalarArray(QString varName, int num, int type, void* va);
vtkDataArray* generateVectorArray(QString varName, int num, /**
int xtype, void * x,int ytype, void* y, int ztype, void* z); * @brief vtkDataArray
* @param[in] varName
* @param[in] num
* @param[in] xtype x
* @param[in] x x
* @param[in] ytype y
* @param[in] y y
* @param[in] ztype z
* @param[in] z z
* @since 2.5.0
*/
vtkDataArray* generateVectorArray(QString varName, int num, int xtype, void* x, int ytype,
void* y, int ztype, void* z);
protected: protected:
/**
* @brief
*/
vtkMultiBlockDataSet* _root{}; vtkMultiBlockDataSet* _root{};
int _fileIndex{ -1 }, _baseIndex{ -1 }, _zoneIndex{ -1 }; /**
* @brief CGNS
*/
int _fileIndex{ -1 };
/**
* @brief base
*/
int _baseIndex{ -1 };
/**
* @brief zone
*/
int _zoneIndex{ -1 };
/**
* @brief
*/
bool _isStructedGrid{ false }; bool _isStructedGrid{ false };
/**
* @brief
*/
int _dim{ 2 }; int _dim{ 2 };
vtkDataSet* _dataSet{}; vtkDataSet* _dataSet{};
QString _zoneName; QString _zoneName;
/**
* @brief
* @since 2.5.0
*/
QVector<VPoint> _vertexList{}; QVector<VPoint> _vertexList{};
}; };

View File

@ -1,15 +1,18 @@
#include "FCGNSReader.h" #include "FCGNSReader.h"
#include "Common/DebugLogger.h"
#include "FCGNSStructureZoneReader.h"
#include "FCGNSUnStructureZoneReader.h"
#include <cgns_io.h>
#include <cgnslib.h>
#include <QFile>
#include <vtkDemandDrivenPipeline.h>
#include <vtkInformation.h> #include <vtkInformation.h>
#include <vtkInformationVector.h> #include <vtkInformationVector.h>
#include <vtkDemandDrivenPipeline.h>
#include <vtkStreamingDemandDrivenPipeline.h>
#include <vtkMultiBlockDataSet.h> #include <vtkMultiBlockDataSet.h>
#include <vtkSetGet.h> #include <vtkSetGet.h>
#include <QFile> #include <vtkStreamingDemandDrivenPipeline.h>
#include <cgnslib.h>
#include <cgns_io.h>
#include "FCGNSUnStructureZoneReader.h"
#include "FCGNSStructureZoneReader.h"
FCGNSReader* FCGNSReader::New() FCGNSReader* FCGNSReader::New()
{ {
@ -31,93 +34,90 @@ FCGNSReader::FCGNSReader()
this->FileName = nullptr; this->FileName = nullptr;
} }
FCGNSReader::~FCGNSReader() FCGNSReader::~FCGNSReader() {}
void FCGNSReader::readZone(int fileIndex, int baseIndex, int zoneIndex,
vtkMultiBlockDataSet* output)
{ {
// 读取zonetypeStructured 或 Unstructured
CGNS_ENUMT(ZoneType_t) zonetype;
if(CG_OK != cg_zone_type(fileIndex, baseIndex, zoneIndex, &zonetype)){
DebugError("Failed to read zone(index = %d) type\n", zoneIndex);
return;
} }
void FCGNSReader::readZone(int fileIndex, int baseIndex, int zoneIndex, vtkMultiBlockDataSet* output) if(zonetype == CGNS_ENUMV(Structured)) {
{
CGNS_ENUMT(ZoneType_t) zonetype;
if (CG_OK != cg_zone_type(fileIndex, baseIndex, zoneIndex, &zonetype))
return ;
if (zonetype == CGNS_ENUMV(Structured))
{
FCGNSStructeGridReader r(output); FCGNSStructeGridReader r(output);
r.setInfo(fileIndex, baseIndex, zoneIndex); r.setInfo(fileIndex, baseIndex, zoneIndex);
r.setReadBC(_readBC); r.setReadBC(_readBC);
r.read(); r.read();
} } else if(zonetype == CGNS_ENUMV(Unstructured)) {
else if (zonetype == CGNS_ENUMV(Unstructured))
{
FCGNSUnStructeGridReader r(output); FCGNSUnStructeGridReader r(output);
r.setInfo(fileIndex, baseIndex, zoneIndex); r.setInfo(fileIndex, baseIndex, zoneIndex);
r.read(); r.read();
} }
} }
int FCGNSReader::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector) int FCGNSReader::ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector)
{ {
if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) {
{ return this->RequestInformation(request, inputVector, outputVector);
return this->RequestInformation(request, inputVector,
outputVector);
} }
if (request->Has( if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT())) {
vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT())) return this->RequestUpdateExtent(request, inputVector, outputVector);
{
return this->RequestUpdateExtent(request, inputVector,
outputVector);
} }
if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) {
{
return this->RequestData(request, inputVector, outputVector); return this->RequestData(request, inputVector, outputVector);
} }
return this->Superclass::ProcessRequest(request, inputVector, return this->Superclass::ProcessRequest(request, inputVector, outputVector);
outputVector);
} }
int FCGNSReader::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) int FCGNSReader::RequestData(vtkInformation*, vtkInformationVector**,
vtkInformationVector* outputVector)
{ {
auto output = vtkMultiBlockDataSet::GetData(outputVector); auto output = vtkMultiBlockDataSet::GetData(outputVector);
bool ok = canReadFile(); bool ok = canReadFile();
if (!ok) return 0; if(!ok) {
return 0;
}
// 打开文件
int currentFileIndex = 0; int currentFileIndex = 0;
if (cg_open(FileName, CG_MODE_READ, &currentFileIndex)) if(CG_OK != cg_open(FileName, CG_MODE_READ, &currentFileIndex)) {
{ DebugError("Failed to open file %s\n", FileName);
return 0; return 0;
} else {
DebugInfo("Success to open file %s\n", FileName);
} }
// 获取CGNS数据库的单库CGNSBase_t的数量一般为1
int nBase = 0; int nBase = 0;
if (cg_nbases(currentFileIndex, &nBase)) if(CG_OK != cg_nbases(currentFileIndex, &nBase)) {
{ DebugError("Failed to get number of base\n");
return 0; return 0;
} }
for (int ibase = 1; ibase <= nBase; ++ibase) // 遍历读取zonebase和zone节点的索引都是从1开始的
{ for(int ibase = 1; ibase <= nBase; ++ibase) {
int zone_node_number = 0; int zone_node_number = 0;
if (cg_nzones(currentFileIndex, ibase, &zone_node_number)) if(CG_OK != cg_nzones(currentFileIndex, ibase, &zone_node_number)) {
{
return false; return false;
} }
for (int izone = 1; izone <= zone_node_number; ++izone) for(int izone = 1; izone <= zone_node_number; ++izone) {
{
readZone(currentFileIndex, ibase, izone, output); readZone(currentFileIndex, ibase, izone, output);
} }
} }
cgio_close_file(currentFileIndex); // 关闭文件
cg_close(currentFileIndex);
return 1; return 1;
} }
bool FCGNSReader::canReadFile() bool FCGNSReader::canReadFile()
{ {
int cgioFile; int cgioFile;
int ierr = 1; bool ierr = true;
double rootNodeId; double rootNodeId;
double childId; double childId;
float FileVersion = 0.0; float FileVersion = 0.0;
@ -126,100 +126,154 @@ bool FCGNSReader::canReadFile()
char errmsg[CGIO_MAX_ERROR_LENGTH + 1]; char errmsg[CGIO_MAX_ERROR_LENGTH + 1];
int ndim = 0; int ndim = 0;
cgsize_t dimVals[12]; cgsize_t dimVals[12];
int fileType = CG_FILE_NONE; int fileType = CGIO_FILE_NONE;
char* fileTypeStr = new char[20];
if (cgio_open_file(FileName, CG_MODE_READ, CG_FILE_NONE, &cgioFile) != CG_OK) // 检查文件文件名以确定它是否是有效的数据库
{ auto result = cgio_check_file(FileName, &fileType);
if(CGIO_ERR_NONE != result || CGIO_FILE_NONE == fileType) {
DebugError("%s is a invalid database!\n", FileName);
return false;
} else {
DebugInfo("Check database: %s?\tpass!\n", FileName);
}
// 确定当前库是否支持fileType给出的数据库类型
// 始终支持CGIO_FILE_ADF;如果库是用HDF5构建的则支持CGIO_FILE_HDF5;在32位模式下构建时支持CGIO_FILE_ADF2。
result = cgio_is_supported(fileType);
switch(fileType) {
case CGIO_FILE_ADF:
strcpy(fileTypeStr, "CGIO_FILE_ADF");
break;
case CGIO_FILE_HDF5:
strcpy(fileTypeStr, "CGIO_FILE_HDF5");
break;
case CGIO_FILE_ADF2:
strcpy(fileTypeStr, "CGIO_FILE_ADF2");
break;
case CGIO_FILE_NONE:
strcpy(fileTypeStr, "CGIO_FILE_NONE");
break;
default:
fileTypeStr = "Unknown";
break;
}
if(CGIO_ERR_FILE_TYPE == result) {
DebugError("FileType: %s is not support!\n", fileTypeStr);
return false;
} else {
DebugInfo("FileType: support by library?\tyes!\n");
}
// 打开数据库设置数据库标识cgioFile用于后续操作
if(cgio_open_file(FileName, CG_MODE_READ, fileType, &cgioFile) != CG_OK) {
cgio_error_message(errmsg); cgio_error_message(errmsg);
vtkErrorMacro(<< "vtkCGNSReader::CanReadFile : " << errmsg); DebugError("Failed to open file %s, error: %s\n", FileName, errmsg);
return 0; return 0;
} else {
DebugInfo("Success to open file %s, identifier = %d\n", FileName, cgioFile);
} }
cgio_get_root_id(cgioFile, &rootNodeId); // 获取数据库中根节点的标识
cgio_get_file_type(cgioFile, &fileType); if(CG_OK != cgio_get_root_id(cgioFile, &rootNodeId)) {
DebugError("Failed to get root node identifier of database(%d)\n", cgioFile);
goto CloseDataBase;
} else {
DebugInfo("Success to get root node identifier of database(%d), identifier = %d\n",
cgioFile, rootNodeId);
}
if (cgio_get_node_id(cgioFile, rootNodeId, "CGNSLibraryVersion", &childId)) // 为什么还要获取一次fileType
{ // cgio_get_file_type(cgioFile, &fileType);
// 获取生成文件的CGNS动态库版本
if(CG_OK != cgio_get_node_id(cgioFile, rootNodeId, "CGNSLibraryVersion", &childId)) {
cgio_error_message(errmsg); cgio_error_message(errmsg);
vtkErrorMacro(<< "vtkCGNSReader::CanReadFile : " << errmsg); DebugError("Failed to get CGNSLibraryVersion node, error: %s\n", errmsg);
ierr = 0; ierr = false;
goto CanReadError; goto CloseDataBase;
} else {
DebugInfo("Success to get CGNSLibraryVersion node, identifier = %f\n", childId);
} }
if (cgio_get_data_type(cgioFile, childId, dataType)) // 获取CGNSLibraryVersion节点的数据类型 "MT", "I4", "I8", "U4", "U8", "R4", "C1", "B1"
{ // "MT" 不包含数据的空节点
vtkErrorMacro(<< "CGNS Version data type"); // "I4" 32位整数(4字节)
ierr = 0; // "I8" 64位整数(8字节)
goto CanReadError; // "U4" 32位无符号整数(4字节)
// "U8" 64位无符号整数(8字节)
// "R4" 32位实数(4字节)
// "R8" 64位实数(8字节)
// "C1" 字符
// "B1" 无符号字节
if(CG_OK != cgio_get_data_type(cgioFile, childId, dataType)) {
cgio_error_message(errmsg);
DebugError("Failed to get CGNSLibraryVersion value type, error: %s\n", errmsg);
ierr = false;
goto CloseDataBase;
} else {
DebugInfo("Success to get CGNSLibraryVersion value type: %s\n", dataType);
} }
if (cgio_get_dimensions(cgioFile, childId, &ndim, dimVals)) // 获取CGNSLibraryVersion节点的数据的维度
{ if(CG_OK != cgio_get_dimensions(cgioFile, childId, &ndim, dimVals)) {
vtkErrorMacro(<< "cgio_get_dimensions"); cgio_error_message(errmsg);
ierr = 0; DebugError("Failed to get CGNSLibraryVersion value dimensions, error: %s\n", errmsg);
goto CanReadError; ierr = false;
goto CloseDataBase;
} else {
DebugInfo("Success to get CGNSLibraryVersion value dimensions, num of dimensions: %d\n",
ndim);
} }
// check data type // 检查CGNSLibraryVersion节点的数据类型float参考cg_version函数http://cgns.github.io/CGNS_docs_current/midlevel/fileops.html
if (strcmp(dataType, "R4") != 0) if(strcmp(dataType, "R4") != 0) {
{ DebugError("Unexpected data type for CGNS library version: %s\n", dataType);
vtkErrorMacro(<< "Unexpected data type for CGNS-Library-Version=" << dataType); ierr = false;
ierr = 0; goto CloseDataBase;
goto CanReadError;
} }
// check data dim // 检查CGNSLibraryVersion节点的数据的维度
if ((ndim != 1) || (dimVals[0] != 1)) if((ndim != 1) || (dimVals[0] != 1)) {
{ DebugError("Invalid data dimension for CGNS library version\n");
vtkDebugMacro(<< "Wrong data dimension for CGNS-Library-Version"); ierr = false;
ierr = 0; goto CloseDataBase;
goto CanReadError;
} }
// read data // 读取CGNSLibraryVersion节点的数据
if (cgio_read_all_data_type(cgioFile, childId, "R4", &FileVersion)) if(cgio_read_all_data_type(cgioFile, childId, "R4", &FileVersion)) {
{ DebugError("An error occurred reading the CGNS library version\n");
vtkErrorMacro(<< "read CGNS version number"); ierr = false;
ierr = 0; goto CloseDataBase;
goto CanReadError; } else {
DebugInfo("CGNS library version: %f\n", FileVersion);
} }
// Check that the library version is at least as recent as the one used // 检测生成CGNS文件的库版本号是否比当前版本FastCAE使用的CGNS库版本更新
// to create the file being read
intFileVersion = static_cast<int>(FileVersion * 1000 + 0.5); intFileVersion = static_cast<int>(FileVersion * 1000 + 0.5);
if (intFileVersion > CGNS_VERSION) if(intFileVersion > CGNS_VERSION) {
{ // 主版本号一样的,可以读取
// This code allows reading version newer than the lib, if(floor(intFileVersion / 1000) > floor(CGNS_VERSION / 1000)) {
// as long as the 1st digit of the versions are equal DebugError("The file %s was written with a more newer version of the CGNS library\n",
if ((intFileVersion / 1000) > (CGNS_VERSION / 1000)) FileName);
{ ierr = false;
vtkErrorMacro(<< "The file " << FileName
<< " was written with a more recent version"
"of the CGNS library. You must update your CGNS"
"library before trying to read this file.");
ierr = 0;
} }
// warn only if different in second digit // warn only if different in second digit
if ((intFileVersion / 100) > (CGNS_VERSION / 100)) if((intFileVersion / 100) > (CGNS_VERSION / 100)) {
{
vtkWarningMacro(<< "The file being read is more recent" vtkWarningMacro(<< "The file being read is more recent"
"than the CGNS library used"); "than the CGNS library used");
} }
} }
if ((intFileVersion / 10) < 255) if((intFileVersion / 10) < 255) {
{
vtkWarningMacro(<< "The file being read was written with an old version" vtkWarningMacro(<< "The file being read was written with an old version"
"of the CGNS library. Please update your file" "of the CGNS library. Please update your file"
"to a more recent version."); "to a more recent version.");
} }
vtkDebugMacro(<< "FileVersion=" << FileVersion << "\n");
CanReadError: CloseDataBase:
cgio_close_file(cgioFile); cgio_close_file(cgioFile);
return ierr ? true : false; return ierr;
} }
void FCGNSReader::setReadBC(bool read) void FCGNSReader::setReadBC(bool read)

View File

@ -3,21 +3,27 @@
#include <vtkMultiBlockDataSetAlgorithm.h> #include <vtkMultiBlockDataSetAlgorithm.h>
class FCGNSReader : public vtkMultiBlockDataSetAlgorithm class FCGNSReader : public vtkMultiBlockDataSetAlgorithm {
{
public: public:
static FCGNSReader* New(); static FCGNSReader* New();
vtkTypeMacro(FCGNSReader, vtkMultiBlockDataSetAlgorithm); vtkTypeMacro(FCGNSReader, vtkMultiBlockDataSetAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override; void PrintSelf(ostream& os, vtkIndent indent) override;
/**@name Getter和Setter宏
* setter/gettervtkSetMacro(FileName, char*)/vtkGetMacro(FileName, char*)
* @{
*/
vtkSetStringMacro(FileName); vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName); vtkGetStringMacro(FileName);
//@}
int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector,
vtkInformationVector* outputVector) override;
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
/**
int ProcessRequest(vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector); * @brief CGNS
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*); */
bool canReadFile(); bool canReadFile();
void setReadBC(bool read); void setReadBC(bool read);
@ -27,7 +33,14 @@ public:
private: private:
FCGNSReader(); FCGNSReader();
~FCGNSReader(); ~FCGNSReader();
/**
* @brief CGNSzone
* @param[in] fileIndex
* @param[in] baseIndex base1
* @param[in] zoneIndex zone1
* @param[out] output
* @since 2.5.0
*/
void readZone(int fileIndex, int baseIndex, int zoneIndex, vtkMultiBlockDataSet* output); void readZone(int fileIndex, int baseIndex, int zoneIndex, vtkMultiBlockDataSet* output);
protected: protected:

View File

@ -1,19 +1,19 @@
#include "FCGNSStructureZoneReader.h" #include "FCGNSStructureZoneReader.h"
#include <vtkStructuredGrid.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkInformation.h>
#include <vtkDataSetWriter.h>
#include <vtkPointData.h>
#include <QDebug>
#include <cgnstypes.h>
#include <cgnslib.h>
#include <cgns_io.h>
#include <vtkFloatArray.h>
#include <vtkDoubleArray.h>
#include <vtkInformationStringKey.h>
#include <vtkNew.h>
#include "PostRenderData/Macros.hxx" #include "PostRenderData/Macros.hxx"
#include <cgns_io.h>
#include <cgnslib.h>
#include <cgnstypes.h>
#include <vtkDataSetWriter.h>
#include <vtkDoubleArray.h>
#include <vtkFloatArray.h>
#include <vtkInformation.h>
#include <vtkInformationStringKey.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkNew.h>
#include <vtkPointData.h>
#include <vtkStructuredGrid.h>
FCGNSStructeGridReader::FCGNSStructeGridReader(vtkMultiBlockDataSet* root) FCGNSStructeGridReader::FCGNSStructeGridReader(vtkMultiBlockDataSet* root)
: FCGNSGridReaderBase(root) : FCGNSGridReaderBase(root)
@ -21,22 +21,22 @@ FCGNSStructeGridReader::FCGNSStructeGridReader(vtkMultiBlockDataSet* root)
_isStructedGrid = true; _isStructedGrid = true;
} }
void FCGNSStructeGridReader::read() void FCGNSStructeGridReader::read()
{ {
char zone_name[33] = { 0 }; char zone_name[33] = { 0 };
cgsize_t zoneSize[3][3] = { 0 }; cgsize_t zoneSize[3][3] = { 0 };
int OK = cg_zone_read(_fileIndex, _baseIndex, _zoneIndex, zone_name, zoneSize[0]); int OK = cg_zone_read(_fileIndex, _baseIndex, _zoneIndex, zone_name, zoneSize[0]);
if (CG_OK != OK) return; if(CG_OK != OK)
return;
_zoneName = QString(zone_name); _zoneName = QString(zone_name);
int dim{ 0 }; int dim{ 0 };
OK = cg_ncoords(_fileIndex, _baseIndex, _zoneIndex, &dim); OK = cg_ncoords(_fileIndex, _baseIndex, _zoneIndex, &dim);
if (CG_OK != OK) return; if(CG_OK != OK)
return;
cgsize_t read_range[2][3] = { 0 }; cgsize_t read_range[2][3] = { 0 };
for (int ijk = 0; ijk < 3; ++ijk) for(int ijk = 0; ijk < 3; ++ijk) {
{
read_range[0][ijk] = 1; read_range[0][ijk] = 1;
read_range[1][ijk] = zoneSize[0][ijk]; read_range[1][ijk] = zoneSize[0][ijk];
} }
@ -62,7 +62,6 @@ void FCGNSStructeGridReader::read()
this->readBC(); this->readBC();
this->spllitSection(sGrid); this->spllitSection(sGrid);
} }
void FCGNSStructeGridReader::setReadBC(bool r) void FCGNSStructeGridReader::setReadBC(bool r)
@ -79,9 +78,9 @@ void FCGNSStructeGridReader::readBC()
{ {
int nbc{ 0 }; int nbc{ 0 };
int OK = cg_nbocos(_fileIndex, _baseIndex, _zoneIndex, &nbc); int OK = cg_nbocos(_fileIndex, _baseIndex, _zoneIndex, &nbc);
if (CG_OK != OK) return; if(CG_OK != OK)
for (int ibc = 1; ibc <= nbc; ++ibc) return;
{ for(int ibc = 1; ibc <= nbc; ++ibc) {
CGNS_ENUMT(BCType_t) bctype; CGNS_ENUMT(BCType_t) bctype;
CGNS_ENUMT(PointSetType_t) ptype; CGNS_ENUMT(PointSetType_t) ptype;
// CGNS_ENUMT(GridLocation_t) location; // CGNS_ENUMT(GridLocation_t) location;
@ -91,19 +90,21 @@ void FCGNSStructeGridReader::readBC()
cgsize_t np = 0, is = 0; cgsize_t np = 0, is = 0;
int ib = 0; int ib = 0;
OK = cg_boco_info(_fileIndex,_baseIndex, _zoneIndex, ibc, bc_name, &bctype, OK = cg_boco_info(_fileIndex, _baseIndex, _zoneIndex, ibc, bc_name, &bctype, &ptype, &np,
&ptype, &np, nrmlindex, &is, &datatype, &ib); nrmlindex, &is, &datatype, &ib);
if (CG_OK != OK) continue; if(CG_OK != OK)
if(ptype != CGNS_ENUMV(PointRange)) continue; continue;
if(ptype != CGNS_ENUMV(PointRange))
continue;
cgsize_t* pnpnts = new cgsize_t[6]; cgsize_t* pnpnts = new cgsize_t[6];
OK = cg_boco_read(_fileIndex, _baseIndex, _zoneIndex, ibc, pnpnts, NULL); OK = cg_boco_read(_fileIndex, _baseIndex, _zoneIndex, ibc, pnpnts, NULL);
if(OK != CG_OK) continue; if(OK != CG_OK)
continue;
BCInfo info(bc_name, pnpnts, bctype); BCInfo info(bc_name, pnpnts, bctype);
_bcList.append(info); _bcList.append(info);
} }
} }
void FCGNSStructeGridReader::spllitSection(vtkStructuredGrid* gird) void FCGNSStructeGridReader::spllitSection(vtkStructuredGrid* gird)
@ -118,18 +119,13 @@ void FCGNSStructeGridReader::spllitSection(vtkStructuredGrid* gird)
void FCGNSStructeGridReader::extractBCs(vtkStructuredGrid* grid) void FCGNSStructeGridReader::extractBCs(vtkStructuredGrid* grid)
{ {
qDebug() << "BC in zone: " << _zoneName;
int dim[3] = { 0 }; int dim[3] = { 0 };
grid->GetDimensions(dim); grid->GetDimensions(dim);
for (BCInfo bc: _bcList) for(BCInfo bc : _bcList) {
{
QList<int> ptIndexs; QList<int> ptIndexs;
for (int k = bc.kMin; k <= bc.kMax; ++k) for(int k = bc.kMin; k <= bc.kMax; ++k) {
{ for(int j = bc.jMin; j <= bc.jMax; ++j) {
for (int j = bc.jMin; j <= bc.jMax; ++j) for(int i = bc.iMin; i <= bc.iMax; ++i) {
{
for (int i = bc.iMin; i <= bc.iMax; ++i)
{
int index = dim[0] * dim[1] * k + dim[0] * j + i; int index = dim[0] * dim[1] * k + dim[0] * j + i;
ptIndexs.append(index); ptIndexs.append(index);
} }
@ -137,12 +133,10 @@ void FCGNSStructeGridReader::extractBCs(vtkStructuredGrid *grid)
} }
extractBCGrid(grid, &bc, ptIndexs); extractBCGrid(grid, &bc, ptIndexs);
} }
} }
void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info,
void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info, QList<int> & indexs) QList<int>& indexs)
{ {
vtkStructuredGrid* bcMesh = vtkStructuredGrid::New(); vtkStructuredGrid* bcMesh = vtkStructuredGrid::New();
const int iDim = info->iMax - info->iMin + 1; const int iDim = info->iMax - info->iMin + 1;
@ -151,12 +145,7 @@ void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info
bcMesh->SetDimensions(iDim, jDim, kDim); bcMesh->SetDimensions(iDim, jDim, kDim);
qDebug() << indexs.size(); DecCreVTKSmartPtr(vtkPoints, points) for(int index : indexs)
qDebug() << iDim * jDim*kDim;
// vtkNew<vtkPoints> points;
DecCreVTKSmartPtr(vtkPoints,points)
for (int index : indexs)
{ {
double* coor = grid->GetPoint(index); double* coor = grid->GetPoint(index);
points->InsertNextPoint(coor); points->InsertNextPoint(coor);
@ -166,8 +155,7 @@ void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info
vtkPointData* pointData = grid->GetPointData(); vtkPointData* pointData = grid->GetPointData();
const int nArray = pointData->GetNumberOfArrays(); const int nArray = pointData->GetNumberOfArrays();
for (int iArray = 0; iArray < nArray; ++iArray) for(int iArray = 0; iArray < nArray; ++iArray) {
{
const char* name = pointData->GetArrayName(iArray); const char* name = pointData->GetArrayName(iArray);
vtkDataArray* array = pointData->GetArray(name); vtkDataArray* array = pointData->GetArray(name);
const int nComp = array->GetNumberOfComponents(); const int nComp = array->GetNumberOfComponents();
@ -178,27 +166,24 @@ void FCGNSStructeGridReader::extractBCGrid(vtkStructuredGrid* grid, BCInfo* info
copyArray = vtkDoubleArray::New(); copyArray = vtkDoubleArray::New();
else if(array->IsA("vtkFloatArray")) else if(array->IsA("vtkFloatArray"))
copyArray = vtkFloatArray::New(); copyArray = vtkFloatArray::New();
if(copyArray == nullptr) continue; if(copyArray == nullptr)
continue;
copyArray->SetName(name); copyArray->SetName(name);
copyArray->SetNumberOfComponents(nComp); copyArray->SetNumberOfComponents(nComp);
for (int ic = 0; ic < nComp; ++ic) for(int ic = 0; ic < nComp; ++ic) {
{
const char* arrName = array->GetComponentName(ic); const char* arrName = array->GetComponentName(ic);
copyArray->SetComponentName(ic, arrName); copyArray->SetComponentName(ic, arrName);
} }
// copyArray->Resize(indexs.size()); // copyArray->Resize(indexs.size());
for (int in =0;in<indexs.size(); ++in) for(int in = 0; in < indexs.size(); ++in) {
{
int index = indexs.at(in); int index = indexs.at(in);
for (int ic = 0; ic < nComp; ++ic) for(int ic = 0; ic < nComp; ++ic) {
{
double v = array->GetComponent(index, ic); double v = array->GetComponent(index, ic);
copyArray->InsertComponent(in, ic, v); copyArray->InsertComponent(in, ic, v);
} }
} }
bcMesh->GetPointData()->AddArray(copyArray); bcMesh->GetPointData()->AddArray(copyArray);
} }
int n = _root->GetNumberOfBlocks(); int n = _root->GetNumberOfBlocks();
@ -211,33 +196,22 @@ QString GetBCType(QString name, int bcType)
{ {
QString sBCType{ "None" }; QString sBCType{ "None" };
QString sName = name.toLower(); QString sName = name.toLower();
if (bcType == 7) if(bcType == 7) {
{
sBCType = "Far"; sBCType = "Far";
return sBCType; return sBCType;
} } else if(bcType >= 16 && bcType <= 17) {
else if (bcType >= 16 && bcType <= 17)
{
sBCType = "Sym"; sBCType = "Sym";
return sBCType; return sBCType;
} } else if(bcType >= 20 && bcType <= 24) {
else if (bcType >= 20 && bcType <= 24)
{
sBCType = "Wall"; sBCType = "Wall";
return sBCType; return sBCType;
} } else if(sName.contains("far")) {
else if(sName.contains("far"))
{
sBCType = "Far"; sBCType = "Far";
return sBCType; return sBCType;
} } else if(sName.contains("sym")) {
else if (sName.contains("sym"))
{
sBCType = "Sym"; sBCType = "Sym";
return sBCType; return sBCType;
} } else if(sName.contains("wall")) {
else if (sName.contains("wall"))
{
sBCType = "Wall"; sBCType = "Wall";
return sBCType; return sBCType;
} }

View File

@ -1,21 +1,23 @@
#include "FCGNSUnStructureZoneReader.h" #include "FCGNSUnStructureZoneReader.h"
#include <vtkMultiBlockDataSet.h>
#include <cgnstypes.h> #include "Common/DebugLogger.h"
#include "PostRenderData/Macros.hxx"
#include <cgns_io.h> #include <cgns_io.h>
#include <cgnslib.h> #include <cgnslib.h>
#include <cgnstypes.h>
#include <QDebug> #include <QDebug>
#include <vtkUnstructuredGrid.h> #include <vtkCellType.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkDataSetWriter.h> #include <vtkDataSetWriter.h>
#include <vtkSelectionNode.h>
#include <vtkSelection.h>
#include <vtkExtractSelection.h> #include <vtkExtractSelection.h>
#include <vtkIdTypeArray.h> #include <vtkIdTypeArray.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkInformation.h> #include <vtkInformation.h>
#include <vtkCellType.h> #include <vtkMultiBlockDataSet.h>
#include "PostRenderData/Macros.hxx" #include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkSelection.h>
#include <vtkSelectionNode.h>
#include <vtkUnstructuredGrid.h>
FCGNSUnStructeGridReader::FCGNSUnStructeGridReader(vtkMultiBlockDataSet* root) FCGNSUnStructeGridReader::FCGNSUnStructeGridReader(vtkMultiBlockDataSet* root)
: FCGNSGridReaderBase(root) : FCGNSGridReaderBase(root)
@ -25,188 +27,361 @@ FCGNSUnStructeGridReader::FCGNSUnStructeGridReader(vtkMultiBlockDataSet *root)
void FCGNSUnStructeGridReader::read() void FCGNSUnStructeGridReader::read()
{ {
char zone_name[33] = {0}; if(_fileIndex < 0 || _baseIndex < 0 || _zoneIndex < 0) {
cgsize_t zoneSize[3] = {0, 0, 0}; DebugError("Invalid zone(file: %d, base: %d, zone: %d)\n", _fileIndex, _baseIndex,
int OK = cg_zone_read(_fileIndex, _baseIndex, _zoneIndex, zone_name, zoneSize); _zoneIndex);
if (CG_OK != OK)
return; return;
}
DebugInfo("Start reading zone(file: %d, base: %d, zone: %d)...\n", _fileIndex, _baseIndex,
_zoneIndex);
// 读取zone信息
char zone_name[33] = { 0 };
// 在非结构化网格数据中zonesize的元素分别对应NVertex, NCell, NBoundVertex
cgsize_t zoneSize[3] = { 0, 0, 0 };
auto result = cg_zone_read(_fileIndex, _baseIndex, _zoneIndex, zone_name, zoneSize);
if(CG_OK != result) {
DebugError("Failed to read zone(index = %d) information\n", _zoneIndex);
return;
} else {
DebugInfo("NVertex = %d, NCell = %d, NBoundVertex = %d\n", zoneSize[0], zoneSize[1],
zoneSize[2]);
}
_zoneName = QString(zone_name); _zoneName = QString(zone_name);
const int nVertex = zoneSize[0], nCell = zoneSize[1], nBoundary = zoneSize[2]; const int nVertex = zoneSize[0], nCell = zoneSize[1], nBoundary = zoneSize[2];
// 坐标数组的个数
int dim{ 0 }; int dim{ 0 };
OK = cg_ncoords(_fileIndex, _baseIndex, _zoneIndex, &dim); result = cg_ncoords(_fileIndex, _baseIndex, _zoneIndex, &dim);
if (CG_OK != OK) if(CG_OK != result) {
DebugError("Failed to read number of coordinate arrays for zone %d\n", _zoneIndex);
return; return;
} else {
DebugInfo("Number of coordinate arrays for zone %d is %d\n", _zoneIndex, dim);
}
// vtkUnstructuredGrid* unsGrid = vtkUnstructuredGrid::New(); // 需要读取全部数据所以range=[1,nVertex]
DecCreVTKSmartPtr(vtkUnstructuredGrid, unsGrid)
cgsize_t read_range[2][3] = { 0 }; cgsize_t read_range[2][3] = { 0 };
for (int ijk = 0; ijk < 3; ++ijk) for(int ijk = 0; ijk < 3; ++ijk) {
{
read_range[0][ijk] = 1; read_range[0][ijk] = 1;
read_range[1][ijk] = nVertex; read_range[1][ijk] = nVertex;
} }
// 读取坐标数据信息
this->readCoordinate(dim, nVertex, read_range[0], read_range[1]); this->readCoordinate(dim, nVertex, read_range[0], read_range[1]);
if(_vertexList.size() != nVertex) {
DecCreVTKSmartPtr(vtkPoints, points) //形成整体点集合 DebugError("Failed to read coordinate arrays for zone %d\n", _zoneIndex);
for (int i = 0; i < _vertexList.size(); ++i) return;
{
VPoint po = _vertexList.at(i);
points->InsertNextPoint(po.x, po.y, po.z);
} }
// 准备vtk数据并插入点
DecCreVTKSmartPtr(vtkPoints, points);
for(int i = 0; i < _vertexList.size(); ++i) {
auto po = _vertexList.at(i);
points->InsertNextPoint(po.x, po.y, po.z);
}
DecCreVTKSmartPtr(vtkUnstructuredGrid, unsGrid);
unsGrid->SetPoints(points); unsGrid->SetPoints(points);
// 获取网格单元的节点数量
int nSection{ 0 }; int nSection{ 0 };
cg_nsections(_fileIndex, _baseIndex, _zoneIndex, &nSection); result = cg_nsections(_fileIndex, _baseIndex, _zoneIndex, &nSection);
if(CG_OK != result) {
DebugError("Failed to get number of element sections\n");
return;
} else {
DebugInfo("Number of element sections is %d\n", nSection);
}
QList<int> sectionList = sectionOrder(nSection); QList<int> sectionList = sectionOrder(nSection);
if(sectionList.size() == 0) {
DebugError("Failed to order sections\n");
return;
}
for (int iSection : sectionList) for(int iSection : sectionList) {
{
char sectionName[33] = { 0 }; char sectionName[33] = { 0 };
cgsize_t istart = 0, iend = 0; cgsize_t istart = 0, iend = 0;
int nbndry = 0, iparent_flag = 0; int nbndry = 0, iparent_flag = 0;
CGNS_ENUMT(ElementType_t) CGNS_ENUMT(ElementType_t)
itype; itype;
OK = cg_section_read(_fileIndex, _baseIndex, _zoneIndex, iSection, sectionName, &itype, &istart, &iend, &nbndry, &iparent_flag); result = cg_section_read(_fileIndex, _baseIndex, _zoneIndex, iSection, sectionName, &itype,
const int ncellCount = iend - istart + 1; &istart, &iend, &nbndry, &iparent_flag);
qDebug() << QString(sectionName) << istart << iend; if(CG_OK != result) {
DebugError("Failed to read element section: %d\n", iSection);
return;
} else {
DebugInfo("element section: %s, element type: %d, first element index: %d, last "
"element index: %d\n",
sectionName, static_cast<int>(itype), istart, iend);
}
const int ncellCount = iend - istart + 1;
cgsize_t elementDataSize = 0; cgsize_t elementDataSize = 0;
OK = cg_ElementDataSize(_fileIndex, _baseIndex, _zoneIndex, iSection, &elementDataSize); result = cg_ElementDataSize(_fileIndex, _baseIndex, _zoneIndex, iSection, &elementDataSize);
if (CG_OK != 0) if(CG_OK != result) {
continue; DebugError("Failed to get size of element connectivity data array\n");
return;
}
cgsize_t* elements = new cgsize_t[elementDataSize]; cgsize_t* elements = new cgsize_t[elementDataSize];
OK = cg_elements_read(_fileIndex, _baseIndex, _zoneIndex, iSection, elements, NULL); cgsize_t* connectOffset = nullptr;
if (CG_OK != 0) /** */
continue;
FSection section(QString(sectionName), istart, iend); //记录section if(itype == CGNS_ENUMT(MIXED)) {
connectOffset = new cgsize_t[elementDataSize];
result = cg_poly_elements_read(_fileIndex, _baseIndex, _zoneIndex, iSection, elements,
connectOffset, NULL);
} else {
// 只能读取固定大小的单元类型
result = cg_elements_read(_fileIndex, _baseIndex, _zoneIndex, iSection, elements, NULL);
}
if(CG_OK != result) {
DebugError("Failed to read fixed size element data, error: %s\n", cg_get_error());
return;
}
FSection section(QString(sectionName), istart, iend);
_sections.append(section); _sections.append(section);
this->addCells(unsGrid, ncellCount, itype, elements); this->addCells(unsGrid, ncellCount, itype, elements, connectOffset);
} }
this->readFlowSolution(unsGrid); this->readFlowSolution(unsGrid);
this->spllitSection(unsGrid); this->spllitSection(unsGrid);
} }
void FCGNSUnStructeGridReader::addCells(vtkUnstructuredGrid *grid, int ncell, CGNS_ENUMT(ElementType_t) type, cgsize_t *elements) /**
* typehttp://cgns.github.io/CGNS_docs_current/sids/conv.html#unstructgrid
* ElementTypeNull, ElementTypeUserDefined, NODE, BAR_2, BAR_3, TRI_3, TRI_6, QUAD_4, QUAD_8,
* QUAD_9, TETRA_4, TETRA_10, PYRA_5, PYRA_14, PENTA_6, PENTA_15, PENTA_18, HEXA_8, HEXA_20,
* HEXA_27, MIXED, PYRA_13, NGON_n, NFACE_n, BAR_4, TRI_9, TRI_10, QUAD_12, QUAD_16, TETRA_16,
* TETRA_20, PYRA_21, PYRA_29, PYRA_30, PENTA_24, PENTA_38, PENTA_40, HEXA_32, HEXA_56, HEXA_64,
* BAR_5, TRI_12, TRI_15, QUAD_P4_16, QUAD_25, TETRA_22, TETRA_34, TETRA_35, PYRA_P4_29, PYRA_50,
* PYRA_55, PENTA_33, PENTA_66, PENTA_75, HEXA_44, HEXA_98, HEXA_125
*
* CGNS1VTK0
*/
void FCGNSUnStructeGridReader::addCells(vtkUnstructuredGrid* grid, int ncell,
CGNS_ENUMT(ElementType_t) type, cgsize_t* elements,
cgsize_t* connectOffset)
{ {
if(CGNS_ENUMT(TRI_3) == type) // 三角形 if(CGNS_ENUMT(TRI_3) == type) // 三角形
{ {
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
addTri3Cell(grid, elements[iCnt * 3 + 0] - 1, elements[iCnt * 3 + 1] - 1,
elements[iCnt * 3 + 2] - 1);
}
} else if(CGNS_ENUMT(BAR_2) == type) // 二节点梁单元
{
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
addBar2Cell(grid, elements[iCnt * 2 + 0] - 1, elements[iCnt * 2 + 1] - 1);
}
} else if(CGNS_ENUMT(TETRA_4) == type) // 四节点四面体
{
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
addTetra4Cell(grid, elements[iCnt * 4 + 0] - 1, elements[iCnt * 4 + 1] - 1,
elements[iCnt * 4 + 2] - 1, elements[iCnt * 4 + 3] - 1);
}
} else if(CGNS_ENUMT(QUAD_4) == type) // 四节点四边形
{
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
addQuad4Cell(grid, elements[iCnt * 4 + 0] - 1, elements[iCnt * 4 + 1] - 1,
elements[iCnt * 4 + 2] - 1, elements[iCnt * 4 + 3] - 1);
}
} else if(CGNS_ENUMT(HEXA_8) == type) // 八节点六面体
{
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
addHexa8Cell(grid, elements[iCnt * 8 + 0] - 1, elements[iCnt * 8 + 1] - 1,
elements[iCnt * 8 + 2] - 1, elements[iCnt * 8 + 3] - 1,
elements[iCnt * 8 + 4] - 1, elements[iCnt * 8 + 5] - 1,
elements[iCnt * 8 + 6] - 1, elements[iCnt * 8 + 7] - 1);
}
} else if(CGNS_ENUMT(PENTA_6) == type) // 六节点三棱柱
{
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
addPenta6Cell(grid, elements[iCnt * 6 + 0] - 1, elements[iCnt * 6 + 1] - 1,
elements[iCnt * 6 + 2] - 1, elements[iCnt * 6 + 3] - 1,
elements[iCnt * 6 + 4] - 1, elements[iCnt * 6 + 5] - 1);
}
} else if(CGNS_ENUMT(PYRA_5) == type) // 金字塔单元
{
for(int iCnt = 0; iCnt < ncell; ++iCnt) {
addPyra5Cell(grid, elements[iCnt * 5 + 0] - 1, elements[iCnt * 5 + 1] - 1,
elements[iCnt * 5 + 2] - 1, elements[iCnt * 5 + 3] - 1,
elements[iCnt * 5 + 4] - 1);
}
} else if(CGNS_ENUMT(MIXED) == type && connectOffset != nullptr) { // 混合单元
int iCnt = 0;
int iEle = 0;
while((iCnt < ncell) && (iEle == connectOffset[iCnt])) {
// 混合单元比其他单元多存储一个值,即第一个值存储单元类型,后面是节点编号
auto type = elements[iEle];
switch(type) {
case CGNS_ENUMT(BAR_2): {
auto id1 = elements[++iEle] - 1;
auto id2 = elements[++iEle] - 1;
addBar2Cell(grid, id1, id2);
} break;
case CGNS_ENUMT(TRI_3): {
auto id1 = elements[++iEle] - 1;
auto id2 = elements[++iEle] - 1;
auto id3 = elements[++iEle] - 1;
addTri3Cell(grid, id1, id2, id3);
} break;
case CGNS_ENUMT(TETRA_4): {
auto id1 = elements[++iEle] - 1;
auto id2 = elements[++iEle] - 1;
auto id3 = elements[++iEle] - 1;
auto id4 = elements[++iEle] - 1;
addTetra4Cell(grid, id1, id2, id3, id4);
} break;
case CGNS_ENUMT(QUAD_4): {
auto id1 = elements[++iEle] - 1;
auto id2 = elements[++iEle] - 1;
auto id3 = elements[++iEle] - 1;
auto id4 = elements[++iEle] - 1;
addQuad4Cell(grid, id1, id2, id3, id4);
} break;
case CGNS_ENUMT(HEXA_8): {
auto id1 = elements[++iEle] - 1;
auto id2 = elements[++iEle] - 1;
auto id3 = elements[++iEle] - 1;
auto id4 = elements[++iEle] - 1;
auto id5 = elements[++iEle] - 1;
auto id6 = elements[++iEle] - 1;
auto id7 = elements[++iEle] - 1;
auto id8 = elements[++iEle] - 1;
addHexa8Cell(grid, id1, id2, id3, id4, id5, id6, id7, id8);
} break;
case CGNS_ENUMT(PENTA_6): {
auto id1 = elements[++iEle] - 1;
auto id2 = elements[++iEle] - 1;
auto id3 = elements[++iEle] - 1;
auto id4 = elements[++iEle] - 1;
auto id5 = elements[++iEle] - 1;
auto id6 = elements[++iEle] - 1;
addPenta6Cell(grid, id1, id2, id3, id4, id5, id6);
} break;
case CGNS_ENUMT(PYRA_5): {
auto id1 = elements[++iEle] - 1;
auto id2 = elements[++iEle] - 1;
auto id3 = elements[++iEle] - 1;
auto id4 = elements[++iEle] - 1;
auto id5 = elements[++iEle] - 1;
addPyra5Cell(grid, id1, id2, id3, id4, id5);
} break;
default:
DebugError("Unsupported element type was found: %d\n", static_cast<int>(type));
break;
}
++iEle;
++iCnt;
}
} else {
DebugError("Unsupported element type was found: %d\n", static_cast<int>(type));
}
}
for (int iCnt = 0; iCnt < ncell; ++iCnt) vtkIdType FCGNSUnStructeGridReader::addBar2Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
vtkIdType id2)
{ {
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New(); auto idlist = vtkSmartPointer<vtkIdList>::New();
idlist->InsertNextId(elements[iCnt * 3 + 0] - 1); idlist->InsertNextId(id1);
idlist->InsertNextId(elements[iCnt * 3 + 1] - 1); idlist->InsertNextId(id2);
idlist->InsertNextId(elements[iCnt * 3 + 2] - 1); return grid->InsertNextCell(VTK_LINE, idlist);
grid->InsertNextCell(VTK_TRIANGLE, idlist);
} }
}
else if (CGNS_ENUMT(BAR_2) == type) //二节点梁单元 vtkIdType FCGNSUnStructeGridReader::addTri3Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
vtkIdType id2, vtkIdType id3)
{ {
for (int iCnt = 0; iCnt < ncell; ++iCnt) auto idlist = vtkSmartPointer<vtkIdList>::New();
idlist->InsertNextId(id1);
idlist->InsertNextId(id2);
idlist->InsertNextId(id3);
return grid->InsertNextCell(VTK_TRIANGLE, idlist);
}
vtkIdType FCGNSUnStructeGridReader::addTetra4Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
vtkIdType id2, vtkIdType id3, vtkIdType id4)
{ {
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New(); auto idlist = vtkSmartPointer<vtkIdList>::New();
idlist->InsertNextId(elements[iCnt * 2 + 0] - 1); idlist->InsertNextId(id1);
idlist->InsertNextId(elements[iCnt * 2 + 1] - 1); idlist->InsertNextId(id2);
grid->InsertNextCell(VTK_LINE, idlist); idlist->InsertNextId(id3);
idlist->InsertNextId(id4);
return grid->InsertNextCell(VTK_TETRA, idlist);
} }
}
else if (CGNS_ENUMT(TETRA_4) == type) //四节点四面体 vtkIdType FCGNSUnStructeGridReader::addQuad4Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
vtkIdType id2, vtkIdType id3, vtkIdType id4)
{ {
for (int iCnt = 0; iCnt < ncell; ++iCnt) auto idlist = vtkSmartPointer<vtkIdList>::New();
idlist->InsertNextId(id1);
idlist->InsertNextId(id2);
idlist->InsertNextId(id3);
idlist->InsertNextId(id4);
return grid->InsertNextCell(VTK_QUAD, idlist);
}
vtkIdType FCGNSUnStructeGridReader::addHexa8Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
vtkIdType id2, vtkIdType id3, vtkIdType id4,
vtkIdType id5, vtkIdType id6, vtkIdType id7,
vtkIdType id8)
{ {
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New(); auto idlist = vtkSmartPointer<vtkIdList>::New();
idlist->InsertNextId(elements[iCnt * 4 + 0] - 1); idlist->InsertNextId(id1);
idlist->InsertNextId(elements[iCnt * 4 + 1] - 1); idlist->InsertNextId(id2);
idlist->InsertNextId(elements[iCnt * 4 + 2] - 1); idlist->InsertNextId(id3);
idlist->InsertNextId(elements[iCnt * 4 + 3] - 1); idlist->InsertNextId(id4);
grid->InsertNextCell(VTK_TETRA, idlist); idlist->InsertNextId(id5);
idlist->InsertNextId(id6);
return grid->InsertNextCell(VTK_WEDGE, idlist);
} }
}
else if (CGNS_ENUMT(QUAD_4) == type) //四节点四边形 vtkIdType FCGNSUnStructeGridReader::addPenta6Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
vtkIdType id2, vtkIdType id3, vtkIdType id4,
vtkIdType id5, vtkIdType id6)
{ {
for (int iCnt = 0; iCnt < ncell; ++iCnt) auto idlist = vtkSmartPointer<vtkIdList>::New();
idlist->InsertNextId(id1);
idlist->InsertNextId(id2);
idlist->InsertNextId(id3);
idlist->InsertNextId(id4);
idlist->InsertNextId(id5);
idlist->InsertNextId(id6);
return grid->InsertNextCell(VTK_WEDGE, idlist);
}
vtkIdType FCGNSUnStructeGridReader::addPyra5Cell(vtkUnstructuredGrid* grid, vtkIdType id1,
vtkIdType id2, vtkIdType id3, vtkIdType id4,
vtkIdType id5)
{ {
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New(); auto idlist = vtkSmartPointer<vtkIdList>::New();
idlist->InsertNextId(elements[iCnt * 4 + 0] - 1); idlist->InsertNextId(id1);
idlist->InsertNextId(elements[iCnt * 4 + 1] - 1); idlist->InsertNextId(id2);
idlist->InsertNextId(elements[iCnt * 4 + 2] - 1); idlist->InsertNextId(id3);
idlist->InsertNextId(elements[iCnt * 4 + 3] - 1); idlist->InsertNextId(id4);
grid->InsertNextCell(VTK_QUAD, idlist); idlist->InsertNextId(id5);
} return grid->InsertNextCell(VTK_PYRAMID, idlist);
}
else if (CGNS_ENUMT(HEXA_8) == type) //八节点六面体
{
for (int iCnt = 0; iCnt < ncell; ++iCnt)
{
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
idlist->InsertNextId(elements[iCnt * 8 + 0] - 1);
idlist->InsertNextId(elements[iCnt * 8 + 1] - 1);
idlist->InsertNextId(elements[iCnt * 8 + 2] - 1);
idlist->InsertNextId(elements[iCnt * 8 + 3] - 1);
idlist->InsertNextId(elements[iCnt * 8 + 4] - 1);
idlist->InsertNextId(elements[iCnt * 8 + 5] - 1);
idlist->InsertNextId(elements[iCnt * 8 + 6] - 1);
idlist->InsertNextId(elements[iCnt * 8 + 7] - 1);
grid->InsertNextCell(VTK_HEXAHEDRON, idlist);
}
}
else if (CGNS_ENUMT(PENTA_6) == type) //六节点三棱柱
{
for (int iCnt = 0; iCnt < ncell; ++iCnt)
{
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
idlist->InsertNextId(elements[iCnt * 6 + 0] - 1);
idlist->InsertNextId(elements[iCnt * 6 + 1] - 1);
idlist->InsertNextId(elements[iCnt * 6 + 2] - 1);
idlist->InsertNextId(elements[iCnt * 6 + 3] - 1);
idlist->InsertNextId(elements[iCnt * 6 + 4] - 1);
idlist->InsertNextId(elements[iCnt * 6 + 5] - 1);
grid->InsertNextCell(VTK_WEDGE, idlist);
}
}
else if (CGNS_ENUMT(PYRA_5) == type) //金字塔单元
{
for (int iCnt = 0; iCnt < ncell; ++iCnt)
{
vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
idlist->InsertNextId(elements[iCnt * 5 + 0] - 1);
idlist->InsertNextId(elements[iCnt * 5 + 1] - 1);
idlist->InsertNextId(elements[iCnt * 5 + 2] - 1);
idlist->InsertNextId(elements[iCnt * 5 + 3] - 1);
idlist->InsertNextId(elements[iCnt * 5 + 4] - 1);
// idlist->InsertNextId(elements[iCnt * 5 + 0] - 1);
grid->InsertNextCell(VTK_PYRAMID, idlist);
}
}
} }
void FCGNSUnStructeGridReader::spllitSection(vtkUnstructuredGrid* gird) void FCGNSUnStructeGridReader::spllitSection(vtkUnstructuredGrid* gird)
{ {
if (_sections.isEmpty()) if(_sections.isEmpty()) {
{
int n = _root->GetNumberOfBlocks(); int n = _root->GetNumberOfBlocks();
_root->SetBlock(n, gird); _root->SetBlock(n, gird);
QString NameBC = _zoneName + "!|||!" + "None"; QString NameBC = _zoneName + "!|||!" + "None";
_root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), NameBC.toLatin1().data()); _root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), NameBC.toLatin1().data());
} }
for (FSection sec : _sections) for(FSection sec : _sections) {
{
// vtkNew<vtkIdTypeArray> ids; // vtkNew<vtkIdTypeArray> ids;
DecCreVTKSmartPtr(vtkIdTypeArray, ids) DecCreVTKSmartPtr(vtkIdTypeArray, ids) ids->SetNumberOfComponents(1);
ids->SetNumberOfComponents(1);
for(int i = sec._begin - 1; i <= sec._end - 1; ++i) for(int i = sec._begin - 1; i <= sec._end - 1; ++i)
ids->InsertNextValue(i); ids->InsertNextValue(i);
// vtkNew<vtkSelectionNode> node; // vtkNew<vtkSelectionNode> node;
DecCreVTKSmartPtr(vtkSelectionNode, node) DecCreVTKSmartPtr(vtkSelectionNode, node) node->SetFieldType(vtkSelectionNode::CELL);
node->SetFieldType(vtkSelectionNode::CELL);
node->SetContentType(vtkSelectionNode::INDICES); node->SetContentType(vtkSelectionNode::INDICES);
node->SetSelectionList(ids); node->SetSelectionList(ids);
@ -215,8 +390,7 @@ void FCGNSUnStructeGridReader::spllitSection(vtkUnstructuredGrid *gird)
section->AddNode(node); section->AddNode(node);
// vtkNew<vtkExtractSelection> exctra; // vtkNew<vtkExtractSelection> exctra;
DecCreVTKSmartPtr(vtkExtractSelection, exctra) DecCreVTKSmartPtr(vtkExtractSelection, exctra) exctra->SetInputData(0, gird);
exctra->SetInputData(0, gird);
exctra->SetInputData(1, section); exctra->SetInputData(1, section);
exctra->Update(); exctra->Update();
@ -226,14 +400,14 @@ void FCGNSUnStructeGridReader::spllitSection(vtkUnstructuredGrid *gird)
_root->SetBlock(n, secGrid); _root->SetBlock(n, secGrid);
QString NameBC = sec._name + "!|||!" + "None"; QString NameBC = sec._name + "!|||!" + "None";
_root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), NameBC.toLatin1().data()); _root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), NameBC.toLatin1().data());
// _root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(), sec._name.toLatin1().data()); // _root->GetMetaData(n)->Set(vtkCompositeDataSet::NAME(),
// sec._name.toLatin1().data());
} }
} }
QList<int> FCGNSUnStructeGridReader::sectionOrder(int nsec) QList<int> FCGNSUnStructeGridReader::sectionOrder(int nsec)
{ {
struct sectionInfo struct sectionInfo {
{
sectionInfo(int index, int s) sectionInfo(int index, int s)
{ {
Index = index; Index = index;
@ -242,30 +416,32 @@ QList<int> FCGNSUnStructeGridReader::sectionOrder(int nsec)
int Index; int Index;
int startNum; int startNum;
}; };
auto compare = [](const sectionInfo &s1, const sectionInfo &s2) -> bool auto compare = [](const sectionInfo& s1, const sectionInfo& s2) -> bool {
{
return s1.startNum <= s2.startNum; return s1.startNum <= s2.startNum;
}; };
QList<sectionInfo> secs; QList<sectionInfo> secs;
for (int iSection = 1; iSection <= nsec; ++iSection) for(int iSection = 1; iSection <= nsec; ++iSection) {
{
char sectionName[33] = { 0 }; char sectionName[33] = { 0 };
cgsize_t istart = 0, iend = 0; cgsize_t istart = 0, iend = 0;
int nbndry = 0, iparent_flag = 0; // 最后一个边界单元的索引如果单元未排序则设为0
CGNS_ENUMT(ElementType_t) int nbndry = 0;
itype; // 指示父级数据是否定义如果存在则为1否则为0
int OK = cg_section_read(_fileIndex, _baseIndex, _zoneIndex, iSection, sectionName, &itype, &istart, &iend, &nbndry, &iparent_flag); int iparent_flag = 0;
if (OK != CG_OK) CGNS_ENUMT(ElementType_t) itype;
continue; int result = cg_section_read(_fileIndex, _baseIndex, _zoneIndex, iSection, sectionName,
&itype, &istart, &iend, &nbndry, &iparent_flag);
if(result != CG_OK) {
DebugError("Failed to get info for an element section\n");
return {};
}
sectionInfo sinfo(iSection, istart); sectionInfo sinfo(iSection, istart);
secs.append(sinfo); secs.append(sinfo);
} }
std::sort(secs.begin(), secs.end(), compare); std::sort(secs.begin(), secs.end(), compare);
QList<int> secOrders; QList<int> secOrders;
for (auto s : secs) for(auto s : secs) {
{
secOrders.append(s.Index); secOrders.append(s.Index);
} }
return secOrders; return secOrders;

View File

@ -2,22 +2,42 @@
#define _FCGNSUNSTRUCTEGRIDREADER_H__ #define _FCGNSUNSTRUCTEGRIDREADER_H__
#include "FCGNSGridReaderBase.h" #include "FCGNSGridReaderBase.h"
#include <cgnslib.h>
#include <cgnstypes.h>
#include <QList> #include <QList>
#include <QString> #include <QString>
#include <cgnstypes.h>
#include <cgnslib.h>
#include <vtkUnstructuredGrid.h> #include <vtkUnstructuredGrid.h>
struct FSection /**
* @brief section
* @since 2.5.0
*/
struct FSection {
FSection(QString name, int b, int e)
: _name(name)
, _begin(b)
, _end(e)
{ {
FSection(QString name, int b, int e) :_name(name),_begin(b), _end(e){} }
/**
* @brief
* @since 2.5.0
*/
QString _name{}; QString _name{};
/**
* @brief
* @since 2.5.0
*/
int _begin{ 0 }; int _begin{ 0 };
/**
* @brief
* @since 2.5.0
*/
int _end{ 0 }; int _end{ 0 };
}; };
class FCGNSUnStructeGridReader :public FCGNSGridReaderBase class FCGNSUnStructeGridReader : public FCGNSGridReaderBase {
{
public: public:
FCGNSUnStructeGridReader(vtkMultiBlockDataSet* root); FCGNSUnStructeGridReader(vtkMultiBlockDataSet* root);
~FCGNSUnStructeGridReader() = default; ~FCGNSUnStructeGridReader() = default;
@ -25,7 +45,31 @@ public:
void read() override; void read() override;
private: private:
void addCells(vtkUnstructuredGrid* grid, int ncell, CGNS_ENUMT(ElementType_t) type, cgsize_t* eles); /**
* @brief vtkUnstructuredGrid
* @param[out] grid vtkUnstructuredGrid
* @param[in] ncell
* @param[in] type
* @param[in] eles
* @param[in] connectOffset type=mixed
* @since 2.5.0
*/
void addCells(vtkUnstructuredGrid* grid, int ncell, CGNS_ENUMT(ElementType_t) type,
cgsize_t* eles, cgsize_t* connectOffset);
vtkIdType addBar2Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2);
vtkIdType addTri3Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3);
vtkIdType addTetra4Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3,
vtkIdType id4);
vtkIdType addQuad4Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3,
vtkIdType id4);
vtkIdType addHexa8Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3,
vtkIdType id4, vtkIdType id5, vtkIdType id6, vtkIdType id7,
vtkIdType id8);
vtkIdType addPenta6Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3,
vtkIdType id4, vtkIdType id5, vtkIdType id6);
vtkIdType addPyra5Cell(vtkUnstructuredGrid* grid, vtkIdType id1, vtkIdType id2, vtkIdType id3,
vtkIdType id4, vtkIdType id5);
void spllitSection(vtkUnstructuredGrid* gird); void spllitSection(vtkUnstructuredGrid* gird);
@ -33,7 +77,6 @@ private:
private: private:
QList<FSection> _sections; QList<FSection> _sections;
}; };
#endif #endif

View File

@ -1,17 +1,19 @@
#include "DialogCreateCalculate.h" #include "DialogCreateCalculate.h"
#include "ui_DialogCreateCalculate.h"
#include "PostTreeWidget.h"
#include "RenderDirector.h"
#include "PostRenderData/RenderDataObject.h"
#include "PostRenderData/CalculateRenderDataAlg.h" #include "PostRenderData/CalculateRenderDataAlg.h"
#include "PostRenderData/RenderDataObject.h"
#include "PostTreeWidget.h"
#include "PythonModule/PyAgent.h" #include "PythonModule/PyAgent.h"
#include "RenderDirector.h"
#include "ui_DialogCreateCalculate.h"
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
namespace Post namespace Post {
{ CreateCalculateDialog::CreateCalculateDialog(PostTreeWidget* tree, QWidget* parent)
CreateCalculateDialog::CreateCalculateDialog(PostTreeWidget *tree, QWidget *parent) : PostFunctionDialogBase(tree, parent), : PostFunctionDialogBase(tree, parent)
_ui(new Ui::CreateCalculateDialog) , _ui(new Ui::CreateCalculateDialog)
{ {
_ui->setupUi(this); _ui->setupUi(this);
init(); init();
@ -37,8 +39,7 @@ namespace Post
void CreateCalculateDialog::accept() void CreateCalculateDialog::accept()
{ {
if (_parentObject == nullptr) if(_parentObject == nullptr) {
{
QMessageBox::warning(this, tr("Warning!"), tr("No selected data!")); QMessageBox::warning(this, tr("Warning!"), tr("No selected data!"));
return; return;
} }
@ -83,7 +84,8 @@ namespace Post
// alg->update(); // alg->update();
// //
// _parentObject->appendSubObjects(alg); // _parentObject->appendSubObjects(alg);
// RenderDirector::getInstance()->renderDataObjectToWindow(alg, _parentObject->getRenderWinID()); // RenderDirector::getInstance()->renderDataObjectToWindow(alg,
// _parentObject->getRenderWinID());
// _tree->updatePostTree(); // _tree->updatePostTree();
QDialog::accept(); QDialog::accept();
this->close(); this->close();
@ -104,39 +106,31 @@ namespace Post
_scalarMenu->clear(); _scalarMenu->clear();
_vectorMenu->clear(); _vectorMenu->clear();
auto createMenu = [=, &action](QStringList arrayList) auto createMenu = [=, &action](QStringList arrayList) {
{ for(auto array : arrayList) {
for (auto array : arrayList) auto type = _parentObject->variableType(1, array);
{ if(type == "scalar") {
int type = _parentObject->variableType(1, array);
if (type == 1)
{
action = _scalarMenu->addAction(array); action = _scalarMenu->addAction(array);
connect(action, &QAction::triggered, [=] connect(action, &QAction::triggered, [=] {
{
setExpression(array); setExpression(array);
if(!_scalarList.contains(array)) if(!_scalarList.contains(array))
_scalarList.append(array); }); _scalarList.append(array);
} });
else if (type == 2) } else if(type == "vector") {
{
action = _vectorMenu->addAction(array); action = _vectorMenu->addAction(array);
connect(action, &QAction::triggered, [=] connect(action, &QAction::triggered, [=] {
{
setExpression(array); setExpression(array);
if(!_vectorList.contains(array)) if(!_vectorList.contains(array))
_vectorList.append(array); }); _vectorList.append(array);
});
} }
} }
}; };
if (_isPoint) if(_isPoint) {
{
QStringList pArray = _parentObject->getPointDataArray(); QStringList pArray = _parentObject->getPointDataArray();
createMenu(pArray); createMenu(pArray);
} } else {
else
{
QStringList cArray = _parentObject->getCellDataArray(); QStringList cArray = _parentObject->getCellDataArray();
createMenu(cArray); createMenu(cArray);
} }
@ -356,4 +350,4 @@ namespace Post
_isPoint = false; _isPoint = false;
} }
} } // namespace Post

View File

@ -1,20 +1,19 @@
#include "DialogRenderSetting.h" #include "DialogRenderSetting.h"
#include "ui_DialogRenderSetting.h"
#include "GraphWidget.h" #include "GraphWidget.h"
#include "PostTreeWidget.h" #include "PostInterface/RenderWindowManager.h"
#include "PostRenderData/RenderDataObject.h" #include "PostRenderData/RenderDataObject.h"
#include "PostRenderData/RenderProperty.h" #include "PostRenderData/RenderProperty.h"
#include "PostInterface/RenderWindowManager.h" #include "PostTreeWidget.h"
#include "PythonModule/PyAgent.h" #include "PythonModule/PyAgent.h"
#include "ui_DialogRenderSetting.h"
#include <QColorDialog> #include <QColorDialog>
#include <QHeaderView> #include <QHeaderView>
namespace Post namespace Post {
{ // RenderSettingDialog::RenderSettingDialog(RenderDataObject* obj, int index, QWidget *parent)
// RenderSettingDialog::RenderSettingDialog(RenderDataObject* obj, int index, QWidget *parent) : // : QDialog(parent), _ui(new Ui::RenderSettingDialog), _dataObject(obj)
// QDialog(parent),
// _ui(new Ui::RenderSettingDialog),
// _dataObject(obj)
// { // {
// _ui->setupUi(this); // _ui->setupUi(this);
// this->setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint); // this->setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint);
@ -31,15 +30,19 @@ namespace Post
// //
// init(); // init();
// //
// connect(_ui->variableTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(setColorByVariable(QTreeWidgetItem*))); // connect(_ui->variableTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this,
// connect(_ui->transparencyHorizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(setTransparency(const int))); // SLOT(setColorByVariable(QTreeWidgetItem*))); connect(_ui->transparencyHorizontalSlider,
// connect(_ui->transparencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(setTransparency(const int))); // SIGNAL(valueChanged(int)), this, SLOT(setTransparency(const int)));
// connect(_ui->transparencySpinBox, SIGNAL(valueChanged(int)), this,
// SLOT(setTransparency(const int)));
// } // }
RenderSettingDialog::RenderSettingDialog(PostTreeWidget *tree, RenderDataObject *obj, QWidget *parent /*= nullptr*/) : QDialog(parent), RenderSettingDialog::RenderSettingDialog(PostTreeWidget* tree, RenderDataObject* obj,
_ui(new Ui::RenderSettingDialog), QWidget* parent /*= nullptr*/)
_dataObject(obj), : QDialog(parent)
_tree(tree) , _ui(new Ui::RenderSettingDialog)
, _dataObject(obj)
, _tree(tree)
{ {
_ui->setupUi(this); _ui->setupUi(this);
@ -47,7 +50,8 @@ namespace Post
this->setAttribute(Qt::WA_DeleteOnClose); this->setAttribute(Qt::WA_DeleteOnClose);
_ui->variableTreeWidget->header()->setSectionResizeMode(QHeaderView::Stretch); _ui->variableTreeWidget->header()->setSectionResizeMode(QHeaderView::Stretch);
_renderWindow = RenderWindowManager::getInstance()->getRenderWindowByID(_dataObject->getRenderWinID()); _renderWindow =
RenderWindowManager::getInstance()->getRenderWindowByID(_dataObject->getRenderWinID());
init(); init();
} }
@ -59,9 +63,7 @@ namespace Post
void RenderSettingDialog::init() void RenderSettingDialog::init()
{ {
auto initInterfaceUI = [=](RenderProperty* pro) {
auto initInterfaceUI = [=](RenderProperty *pro)
{
double color[3] = { 0 }; double color[3] = { 0 };
pro->getPropertyColor(color); pro->getPropertyColor(color);
_ui->variableColorPushButton->setStyleSheet(QString("background-color: rgb(%1,%2,%3);") _ui->variableColorPushButton->setStyleSheet(QString("background-color: rgb(%1,%2,%3);")
@ -72,15 +74,12 @@ namespace Post
_ui->transparencyHorizontalSlider->setValue(trans * 100); _ui->transparencyHorizontalSlider->setValue(trans * 100);
_ui->transparencySpinBox->setValue(trans * 100); _ui->transparencySpinBox->setValue(trans * 100);
auto type = pro->getVariableType(); auto type = pro->getVariableType();
if (type == 0) if(type == 0) {
{
_ui->colorBarCheckBox->setChecked(false); _ui->colorBarCheckBox->setChecked(false);
_ui->colorBarCheckBox->setEnabled(false); _ui->colorBarCheckBox->setEnabled(false);
_ui->variableColorCheckBox->setChecked(false); _ui->variableColorCheckBox->setChecked(false);
_ui->variableColorCheckBox->setEnabled(false); _ui->variableColorCheckBox->setEnabled(false);
} } else {
else
{
_ui->colorBarCheckBox->setChecked(pro->getShowColorMap()); _ui->colorBarCheckBox->setChecked(pro->getShowColorMap());
_ui->colorBarCheckBox->setEnabled(true); _ui->colorBarCheckBox->setEnabled(true);
_ui->variableColorCheckBox->setChecked(true); _ui->variableColorCheckBox->setChecked(true);
@ -90,18 +89,14 @@ namespace Post
QMultiHash<int, int> dataList = _tree->getSelectedData(_dataObject); QMultiHash<int, int> dataList = _tree->getSelectedData(_dataObject);
if (dataList.size() > 0) if(dataList.size() > 0) {
{
auto id = dataList.uniqueKeys().at(0); auto id = dataList.uniqueKeys().at(0);
auto index = dataList.values(id).at(0); auto index = dataList.values(id).at(0);
if (index == -1) if(index == -1) {
{
auto obj = _dataObject->getObjectByID(id); auto obj = _dataObject->getObjectByID(id);
auto objPro = obj->getPropertyListAt(0); auto objPro = obj->getPropertyListAt(0);
initInterfaceUI(objPro); initInterfaceUI(objPro);
} } else {
else
{
auto objPro = _dataObject->getPropertyListAt(index); auto objPro = _dataObject->getPropertyListAt(index);
initInterfaceUI(objPro); initInterfaceUI(objPro);
} }
@ -112,9 +107,12 @@ namespace Post
initVariableTreeWidget(1, pArrayList); initVariableTreeWidget(1, pArrayList);
initVariableTreeWidget(2, cArrayList); initVariableTreeWidget(2, cArrayList);
connect(_ui->variableTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(setColorByVariable(QTreeWidgetItem *))); connect(_ui->variableTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this,
connect(_ui->transparencyHorizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(setTransparency(const int))); SLOT(setColorByVariable(QTreeWidgetItem*)));
connect(_ui->transparencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(setTransparency(const int))); connect(_ui->transparencyHorizontalSlider, SIGNAL(valueChanged(int)), this,
SLOT(setTransparency(const int)));
connect(_ui->transparencySpinBox, SIGNAL(valueChanged(int)), this,
SLOT(setTransparency(const int)));
} }
void RenderSettingDialog::initVariableTreeWidget(int loc, QStringList arrayList) void RenderSettingDialog::initVariableTreeWidget(int loc, QStringList arrayList)
@ -128,8 +126,7 @@ namespace Post
// //
// getCurrentVariable(cVariable, cType, cIndex); // getCurrentVariable(cVariable, cType, cIndex);
auto createTreeItem = [=](QString name, QString type, int loc, int index = -1) auto createTreeItem = [=](QString name, QString type, int loc, int index = -1) {
{
auto item = new QTreeWidgetItem; auto item = new QTreeWidgetItem;
item->setText(0, name); item->setText(0, name);
item->setText(1, type); item->setText(1, type);
@ -144,23 +141,15 @@ namespace Post
// } // }
}; };
for (auto name : arrayList) for(auto name : arrayList) {
{ const auto vType = _dataObject->variableType(loc, name);
const int vType = _dataObject->variableType(loc, name); if(vType == "scalar") {
if (vType == 0)
;
else if (vType == 1)
{
createTreeItem(name, tr("%1Scalar").arg(locName), loc); createTreeItem(name, tr("%1Scalar").arg(locName), loc);
} } else if(vType == "vector") {
else if (vType == 2)
{
createTreeItem(name, tr("%1Vector-X").arg(locName), loc, 0); createTreeItem(name, tr("%1Vector-X").arg(locName), loc, 0);
createTreeItem(name, tr("%1Vector-Y").arg(locName), loc, 1); createTreeItem(name, tr("%1Vector-Y").arg(locName), loc, 1);
createTreeItem(name, tr("%1Vector-Z").arg(locName), loc, 2); createTreeItem(name, tr("%1Vector-Z").arg(locName), loc, 2);
} } else if(vType == "tensor") {
else if (vType == 3)
{
createTreeItem(name, tr("%1Tensor").arg(locName), loc); createTreeItem(name, tr("%1Tensor").arg(locName), loc);
} }
} }
@ -173,8 +162,7 @@ namespace Post
locName = tr("Cell"); locName = tr("Cell");
QString typeName; QString typeName;
switch (type) switch(type) {
{
case 1: case 1:
typeName = tr("Scalar"); typeName = tr("Scalar");
break; break;
@ -201,11 +189,9 @@ namespace Post
Q_UNUSED(index) Q_UNUSED(index)
// if (_renderProperty == nullptr) // if (_renderProperty == nullptr)
// { // {
// auto pro = _dataObject->getPropertyListAt(_dataObject->getPropertyListCount() - 1); // auto pro = _dataObject->getPropertyListAt(_dataObject->getPropertyListCount() -
// if (pro == nullptr) return; // 1); if (pro == nullptr) return; name = pro->getVariableName(); loc =
// name = pro->getVariableName(); // pro->getVariableType(); index = pro->getComponentIndex();
// loc = pro->getVariableType();
// index = pro->getComponentIndex();
// } // }
// else // else
// { // {
@ -221,23 +207,18 @@ namespace Post
QMultiHash<int, int> dataList = _tree->getSelectedData(_dataObject); QMultiHash<int, int> dataList = _tree->getSelectedData(_dataObject);
for (auto id : dataList.uniqueKeys()) for(auto id : dataList.uniqueKeys()) {
{
auto obj = _dataObject->getObjectByID(id); auto obj = _dataObject->getObjectByID(id);
if(obj == nullptr) if(obj == nullptr)
continue; continue;
for (auto bIndex : dataList.values(id)) for(auto bIndex : dataList.values(id)) {
{ if(bIndex == -1) {
if (bIndex == -1)
{
auto cPro = obj->getPropertyListAt(0); auto cPro = obj->getPropertyListAt(0);
if(cPro == nullptr) if(cPro == nullptr)
continue; continue;
_propertyList.append(cPro); _propertyList.append(cPro);
} } else {
else
{
auto bPro = obj->getPropertyListAt(bIndex); auto bPro = obj->getPropertyListAt(bIndex);
if(bPro == nullptr) if(bPro == nullptr)
continue; continue;
@ -252,8 +233,7 @@ namespace Post
QColor c = _ui->variableColorPushButton->palette().color(QPalette::Background); QColor c = _ui->variableColorPushButton->palette().color(QPalette::Background);
QColor color = QColorDialog::getColor(c, this); QColor color = QColorDialog::getColor(c, this);
if (color.isValid()) if(color.isValid()) {
{
_ui->variableColorCheckBox->setChecked(false); _ui->variableColorCheckBox->setChecked(false);
_ui->variableColorCheckBox->setEnabled(false); _ui->variableColorCheckBox->setEnabled(false);
_ui->colorBarCheckBox->setChecked(false); _ui->colorBarCheckBox->setChecked(false);
@ -272,13 +252,14 @@ namespace Post
QStringList codes{}; QStringList codes{};
codes += QString("variablecolor = PostProcess.VariableColor()"); codes += QString("variablecolor = PostProcess.VariableColor()");
codes += QString("variablecolor.setColor(%1,%2,%3)").arg(color.redF()).arg(color.greenF()).arg(color.blueF()); codes += QString("variablecolor.setColor(%1,%2,%3)")
.arg(color.redF())
.arg(color.greenF())
.arg(color.blueF());
for (auto obj : dataHash.uniqueKeys()) for(auto obj : dataHash.uniqueKeys()) {
{
auto blockList = dataHash.values(obj); auto blockList = dataHash.values(obj);
for (auto block : blockList) for(auto block : blockList) {
{
codes += QString("variablecolor.appendBlock(%1,%2)").arg(obj).arg(block); codes += QString("variablecolor.appendBlock(%1,%2)").arg(obj).arg(block);
} }
} }
@ -294,8 +275,7 @@ namespace Post
void RenderSettingDialog::on_variableColorCheckBox_clicked() void RenderSettingDialog::on_variableColorCheckBox_clicked()
{ {
if (!_ui->variableColorCheckBox->isChecked()) if(!_ui->variableColorCheckBox->isChecked()) {
{
_ui->variableColorCheckBox->setEnabled(false); _ui->variableColorCheckBox->setEnabled(false);
_ui->colorBarCheckBox->setChecked(false); _ui->colorBarCheckBox->setChecked(false);
_ui->colorBarCheckBox->setEnabled(false); _ui->colorBarCheckBox->setEnabled(false);
@ -310,13 +290,14 @@ namespace Post
QStringList codes{}; QStringList codes{};
codes += QString("variablecolor = PostProcess.VariableColor()"); codes += QString("variablecolor = PostProcess.VariableColor()");
codes += QString("variablecolor.setColor(%1,%2,%3)").arg(color.redF()).arg(color.greenF()).arg(color.blueF()); codes += QString("variablecolor.setColor(%1,%2,%3)")
.arg(color.redF())
.arg(color.greenF())
.arg(color.blueF());
for (auto obj : dataHash.uniqueKeys()) for(auto obj : dataHash.uniqueKeys()) {
{
auto blockList = dataHash.values(obj); auto blockList = dataHash.values(obj);
for (auto block : blockList) for(auto block : blockList) {
{
codes += QString("variablecolor.appendBlock(%1,%2)").arg(obj).arg(block); codes += QString("variablecolor.appendBlock(%1,%2)").arg(obj).arg(block);
} }
} }
@ -332,7 +313,6 @@ namespace Post
void RenderSettingDialog::on_colorBarCheckBox_clicked() void RenderSettingDialog::on_colorBarCheckBox_clicked()
{ {
bool show = _ui->colorBarCheckBox->isChecked(); bool show = _ui->colorBarCheckBox->isChecked();
getRenderPropertyList(); getRenderPropertyList();
@ -387,11 +367,9 @@ namespace Post
codes += QString("variablecolor = PostProcess.VariableColor()"); codes += QString("variablecolor = PostProcess.VariableColor()");
codes += QString("variablecolor.selectVariable(%1,'%2',%3)").arg(type).arg(name).arg(index); codes += QString("variablecolor.selectVariable(%1,'%2',%3)").arg(type).arg(name).arg(index);
for (auto obj : dataHash.uniqueKeys()) for(auto obj : dataHash.uniqueKeys()) {
{
auto blockList = dataHash.values(obj); auto blockList = dataHash.values(obj);
for (auto block : blockList) for(auto block : blockList) {
{
codes += QString("variablecolor.appendBlock(%1,%2)").arg(obj).arg(block); codes += QString("variablecolor.appendBlock(%1,%2)").arg(obj).arg(block);
} }
} }
@ -405,4 +383,4 @@ namespace Post
_tree->updatePostTree(); _tree->updatePostTree();
} }
} } // namespace Post

View File

@ -1,21 +1,23 @@
#include "PostInfoWidget.h" #include "PostInfoWidget.h"
#include "ui_PostInfoWidget.h"
#include "PostRenderData/RenderDataAlgorithm.h"
#include "PostRenderData/RenderDataImportSteady.h"
#include "PostRenderData/RenderDataImportUnSteady.h"
#include "PostRenderData/RenderDataManager.h" #include "PostRenderData/RenderDataManager.h"
#include "PostRenderData/RenderDataObject.h" #include "PostRenderData/RenderDataObject.h"
#include "PostRenderData/RenderProperty.h" #include "PostRenderData/RenderProperty.h"
#include "PostRenderData/RenderDataAlgorithm.h" #include "ui_PostInfoWidget.h"
#include "PostRenderData/RenderDataImportUnSteady.h"
#include "PostRenderData/RenderDataImportSteady.h" #include <QDebug>
#include <QLabel> #include <QLabel>
#include <QStringList> #include <QStringList>
#include <QDebug>
namespace Post {
namespace Post PostInfoWidget::PostInfoWidget(GUI::MainWindow* m, QWidget* parent)
{ : _ui(new Ui::PostInfoWidget)
, _parent(parent)
PostInfoWidget::PostInfoWidget(GUI::MainWindow* m, QWidget* parent) : , _mainWindow(m)
_ui(new Ui::PostInfoWidget), _parent(parent), _mainWindow(m)
{ {
_ui->setupUi(this); _ui->setupUi(this);
_dataManager = RenderDataManager::getInstance(); _dataManager = RenderDataManager::getInstance();
@ -25,7 +27,6 @@ namespace Post
_ui->tableWidget->setHorizontalHeaderLabels(header); _ui->tableWidget->setHorizontalHeaderLabels(header);
_ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); _ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
_ui->tableWidget->verticalHeader()->setVisible(false); _ui->tableWidget->verticalHeader()->setVisible(false);
} }
PostInfoWidget::~PostInfoWidget() PostInfoWidget::~PostInfoWidget()
@ -36,16 +37,11 @@ namespace Post
QString PostInfoWidget::enumToString(Post::ObjType type) QString PostInfoWidget::enumToString(Post::ObjType type)
{ {
QString types; QString types;
if(type == Post::ObjType::Alg) if(type == Post::ObjType::Alg) {
{
types = "Alg"; types = "Alg";
} } else if(type == Post::ObjType::Imp) {
else if(type == Post::ObjType::Imp)
{
types = tr("Imp"); types = tr("Imp");
} } else if(type == Post::ObjType::TNone) {
else if(type == Post::ObjType::TNone)
{
types = "TNone"; types = "TNone";
} }
return types; return types;
@ -66,30 +62,46 @@ namespace Post
{ {
QString sType = "TNone"; QString sType = "TNone";
auto type = obj->getDataType(); auto type = obj->getDataType();
if (type == Post::ObjType::Alg) if(type == Post::ObjType::Alg) {
{
sType = tr("Alg"); sType = tr("Alg");
auto alg = RenderDataAlgorithm::SafeDownCast(obj); auto alg = RenderDataAlgorithm::SafeDownCast(obj);
if (alg == nullptr) return sType; if(alg == nullptr)
return sType;
switch (alg->getAlgoType()) switch(alg->getAlgoType()) {
{ case Post::ISO:
case Post::ISO: sType = tr("ISOSurface"); break; sType = tr("ISOSurface");
case Post::ISOCurve: sType = tr("ISOCurve"); break; break;
case Post::Vector: sType = tr("Vector"); break; case Post::ISOCurve:
case Post::Slice: sType = tr("Slice"); break; sType = tr("ISOCurve");
case Post::Clip: sType = tr("Clip"); break; break;
case Post::StreamLine: sType = tr("StreamLine"); break; case Post::Vector:
case Post::Simplify: sType = tr("Simplify"); break; sType = tr("Vector");
case Post::Calculator: sType = tr("Calculator"); break; break;
case Post::Reflection: sType = tr("Reflection"); break; case Post::Slice:
sType = tr("Slice");
break;
case Post::Clip:
sType = tr("Clip");
break;
case Post::StreamLine:
sType = tr("StreamLine");
break;
case Post::Simplify:
sType = tr("Simplify");
break;
case Post::Calculator:
sType = tr("Calculator");
break;
case Post::Reflection:
sType = tr("Reflection");
break;
} }
} } else if(type == Post::ObjType::Imp) {
else if (type == Post::ObjType::Imp)
{
sType = tr("Steady"); sType = tr("Steady");
auto usteady = RenderDataImportUnSteady::SafeDownCast(obj); auto usteady = RenderDataImportUnSteady::SafeDownCast(obj);
if (usteady != nullptr) sType = tr("UnSteady"); if(usteady != nullptr)
sType = tr("UnSteady");
} }
return sType; return sType;
@ -97,46 +109,44 @@ namespace Post
void PostInfoWidget::updatePostTable(QTreeWidgetItem* item) void PostInfoWidget::updatePostTable(QTreeWidgetItem* item)
{ {
if (item == nullptr) return; if(item == nullptr)
return;
bool ok = false; bool ok = false;
int id = item->data(0, Qt::UserRole).toInt(&ok); int id = item->data(0, Qt::UserRole).toInt(&ok);
if (!ok)return; if(!ok)
return;
auto obj = _dataManager->getObjectByID(id); auto obj = _dataManager->getObjectByID(id);
if (obj == nullptr) return; if(obj == nullptr)
return;
int index = item->data(1, Qt::UserRole).toInt(&ok); int index = item->data(1, Qt::UserRole).toInt(&ok);
if (!ok) return; if(!ok)
return;
auto setRangeItem = [=](int row, int type, QString var) { auto setRangeItem = [=](int row, int type, QString var) {
int vtype = obj->variableType(type, var); auto vtype = obj->variableType(type, var);
double range[2]{ 0 }; double range[2]{ 0 };
QString sRange; QString sRange;
if (vtype == 1) if(vtype == "scalar") {
{
obj->getRange(range, type, var, -1); obj->getRange(range, type, var, -1);
sRange = QString("[%1,%2]").arg(range[0]).arg(range[1]); sRange = QString("[%1,%2]").arg(range[0]).arg(range[1]);
} } else if(vtype == "vector") {
else if (vtype == 2)
{
obj->getRange(range, type, var, 0); obj->getRange(range, type, var, 0);
sRange = QString("[%1,%2];").arg(range[0]).arg(range[1]); sRange = QString("[%1,%2];").arg(range[0]).arg(range[1]);
obj->getRange(range, type, var, 1); obj->getRange(range, type, var, 1);
sRange += QString("[%1,%2];").arg(range[0]).arg(range[1]); sRange += QString("[%1,%2];").arg(range[0]).arg(range[1]);
obj->getRange(range, type, var, 2); obj->getRange(range, type, var, 2);
sRange += QString("[%1,%2]").arg(range[0]).arg(range[1]); sRange += QString("[%1,%2]").arg(range[0]).arg(range[1]);
} } else
else return; return;
_ui->tableWidget->setItem(row, 3, new QTableWidgetItem(sRange)); _ui->tableWidget->setItem(row, 3, new QTableWidgetItem(sRange));
}; };
if (index == -1) if(index == -1) {
{
_ui->FileNameValue->setText(obj->getName()); _ui->FileNameValue->setText(obj->getName());
_ui->TypeValue->setText(getRenderDataObjectType(obj)); _ui->TypeValue->setText(getRenderDataObjectType(obj));
_ui->PointNumValue->setText(QString::number(obj->getPointDataNum())); _ui->PointNumValue->setText(QString::number(obj->getPointDataNum()));
@ -150,29 +160,27 @@ namespace Post
int Rowcount = PointData.size() + CellData.size(); int Rowcount = PointData.size() + CellData.size();
_ui->tableWidget->setRowCount(Rowcount); _ui->tableWidget->setRowCount(Rowcount);
for(int i = 0; i < PointData.size(); i++) {
for (int i = 0; i < PointData.size(); i++)
{
double range[2]{ 0 }; double range[2]{ 0 };
obj->getRange(range, 1, PointData[i], -1); obj->getRange(range, 1, PointData[i], -1);
_ui->tableWidget->setItem(i, 0, new QTableWidgetItem(tr("PointProperty"))); _ui->tableWidget->setItem(i, 0, new QTableWidgetItem(tr("PointProperty")));
_ui->tableWidget->setItem(i, 1, new QTableWidgetItem(PointData[i])); _ui->tableWidget->setItem(i, 1, new QTableWidgetItem(PointData[i]));
_ui->tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(obj->variableType(1, PointData[i])))); _ui->tableWidget->setItem(i, 2,
new QTableWidgetItem(obj->variableType(1, PointData[i])));
// qDebug() << obj->variableType(1, PointData[i]); // qDebug() << obj->variableType(1, PointData[i]);
setRangeItem(i, 1, PointData[i]); setRangeItem(i, 1, PointData[i]);
} }
for (int j = 0; j < CellData.size(); j++) for(int j = 0; j < CellData.size(); j++) {
{ _ui->tableWidget->setItem(PointData.size() + j, 0,
_ui->tableWidget->setItem(PointData.size() + j, 0, new QTableWidgetItem(tr("CellProperty"))); new QTableWidgetItem(tr("CellProperty")));
_ui->tableWidget->setItem(PointData.size() + j, 1, new QTableWidgetItem(CellData[j])); _ui->tableWidget->setItem(PointData.size() + j, 1,
_ui->tableWidget->setItem(PointData.size() + j, 2, new QTableWidgetItem(QString::number(obj->variableType(2, CellData[j])))); new QTableWidgetItem(CellData[j]));
_ui->tableWidget->setItem(PointData.size() + j, 2,
new QTableWidgetItem(obj->variableType(2, CellData[j])));
setRangeItem(PointData.size() + j, 2, CellData[j]); setRangeItem(PointData.size() + j, 2, CellData[j]);
} }
} } else {
else
{
_ui->FileNameValue->setText(obj->getBlockName(index)); _ui->FileNameValue->setText(obj->getBlockName(index));
_ui->TypeValue->setText(getRenderDataObjectType(obj)); _ui->TypeValue->setText(getRenderDataObjectType(obj));
_ui->PointNumValue->setText(QString::number(obj->getNumberOfBlockPoints(index + 1))); _ui->PointNumValue->setText(QString::number(obj->getNumberOfBlockPoints(index + 1)));
@ -186,22 +194,24 @@ namespace Post
int Rowcount = PointData.size() + CellData.size(); int Rowcount = PointData.size() + CellData.size();
_ui->tableWidget->setRowCount(Rowcount); _ui->tableWidget->setRowCount(Rowcount);
for (int i = 0; i < PointData.size(); i++) for(int i = 0; i < PointData.size(); i++) {
{
double range[2]{ 0 }; double range[2]{ 0 };
obj->getRange(range, 1, PointData[i], -1); obj->getRange(range, 1, PointData[i], -1);
_ui->tableWidget->setItem(i, 0, new QTableWidgetItem(tr("PointProperty"))); _ui->tableWidget->setItem(i, 0, new QTableWidgetItem(tr("PointProperty")));
_ui->tableWidget->setItem(i, 1, new QTableWidgetItem(PointData[i])); _ui->tableWidget->setItem(i, 1, new QTableWidgetItem(PointData[i]));
_ui->tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(obj->variableType(1, PointData[i])))); _ui->tableWidget->setItem(i, 2,
new QTableWidgetItem(obj->variableType(1, PointData[i])));
// qDebug() << obj->variableType(1, PointData[i]); // qDebug() << obj->variableType(1, PointData[i]);
setRangeItem(i, 1, PointData[i]); setRangeItem(i, 1, PointData[i]);
} }
for (int j = 0; j < CellData.size(); j++) for(int j = 0; j < CellData.size(); j++) {
{ _ui->tableWidget->setItem(PointData.size() + j, 0,
_ui->tableWidget->setItem(PointData.size() + j, 0, new QTableWidgetItem(tr("CellProperty"))); new QTableWidgetItem(tr("CellProperty")));
_ui->tableWidget->setItem(PointData.size() + j, 1, new QTableWidgetItem(CellData[j])); _ui->tableWidget->setItem(PointData.size() + j, 1,
_ui->tableWidget->setItem(PointData.size() + j, 2, new QTableWidgetItem(QString::number(obj->variableType(2, CellData[j])))); new QTableWidgetItem(CellData[j]));
_ui->tableWidget->setItem(PointData.size() + j, 2,
new QTableWidgetItem(obj->variableType(2, CellData[j])));
setRangeItem(PointData.size() + j, 2, CellData[j]); setRangeItem(PointData.size() + j, 2, CellData[j]);
} }
} }
@ -230,15 +240,19 @@ namespace Post
// //
// _ui->tableWidget->setItem(i,0,new QTableWidgetItem("PointProperty")); // _ui->tableWidget->setItem(i,0,new QTableWidgetItem("PointProperty"));
// _ui->tableWidget->setItem(i,1,new QTableWidgetItem(PointData[i])); // _ui->tableWidget->setItem(i,1,new QTableWidgetItem(PointData[i]));
// _ui->tableWidget->setItem(i,2,new QTableWidgetItem(QString::number(obj->variableType(1,PointData[i])))); // _ui->tableWidget->setItem(i,2,new
// QTableWidgetItem(QString::number(obj->variableType(1,PointData[i]))));
// qDebug()<<obj->variableType(1,PointData[i]); // qDebug()<<obj->variableType(1,PointData[i]);
// //
// } // }
// for(int j=0; j<CellData.size(); j++) // for(int j=0; j<CellData.size(); j++)
// { // {
// _ui->tableWidget->setItem(PointData.size()+j,0,new QTableWidgetItem("CellProperty")); // _ui->tableWidget->setItem(PointData.size()+j,0,new
// _ui->tableWidget->setItem(PointData.size()+j,1,new QTableWidgetItem(CellData[j])); // QTableWidgetItem("CellProperty"));
// _ui->tableWidget->setItem(PointData.size()+j,2,new QTableWidgetItem(QString::number(obj->variableType(2,CellData[j])))); // _ui->tableWidget->setItem(PointData.size()+j,1,new
// QTableWidgetItem(CellData[j]));
// _ui->tableWidget->setItem(PointData.size()+j,2,new
// QTableWidgetItem(QString::number(obj->variableType(2,CellData[j]))));
// } // }
// } // }
// //
@ -262,23 +276,23 @@ namespace Post
// //
// _ui->tableWidget->setItem(i,0,new QTableWidgetItem("PointProperty")); // _ui->tableWidget->setItem(i,0,new QTableWidgetItem("PointProperty"));
// _ui->tableWidget->setItem(i,1,new QTableWidgetItem(PointData[i])); // _ui->tableWidget->setItem(i,1,new QTableWidgetItem(PointData[i]));
// _ui->tableWidget->setItem(i,2,new QTableWidgetItem(QString::number(obj->variableType(1,PointData[i])))); // _ui->tableWidget->setItem(i,2,new
// QTableWidgetItem(QString::number(obj->variableType(1,PointData[i]))));
// qDebug()<<obj->variableType(1,PointData[i]); // qDebug()<<obj->variableType(1,PointData[i]);
// //
// } // }
// for(int j=0; j<CellData.size(); j++) // for(int j=0; j<CellData.size(); j++)
// { // {
// _ui->tableWidget->setItem(PointData.size()+j,0,new QTableWidgetItem("CellProperty")); // _ui->tableWidget->setItem(PointData.size()+j,0,new
// _ui->tableWidget->setItem(PointData.size()+j,1,new QTableWidgetItem(CellData[j])); // QTableWidgetItem("CellProperty"));
// _ui->tableWidget->setItem(PointData.size()+j,2,new QTableWidgetItem(QString::number(obj->variableType(2,CellData[j])))); // _ui->tableWidget->setItem(PointData.size()+j,1,new
// QTableWidgetItem(CellData[j]));
// _ui->tableWidget->setItem(PointData.size()+j,2,new
// QTableWidgetItem(QString::number(obj->variableType(2,CellData[j]))));
// } // }
// //
// //
// } // }
} }
} // namespace Post
}

View File

@ -17,7 +17,6 @@
#include "PostRenderData/StreamLineRenderDataAlg.h" #include "PostRenderData/StreamLineRenderDataAlg.h"
#include "PostRenderData/CalculateRenderDataAlg.h" #include "PostRenderData/CalculateRenderDataAlg.h"
#include "PostRenderData/ReflectionRenderDataAlg.h" #include "PostRenderData/ReflectionRenderDataAlg.h"
#include "MainWindow/MainWindow.h"
namespace Post namespace Post
{ {
@ -57,10 +56,13 @@ namespace Post
{ {
RenderDataObject *dataObj = nullptr; RenderDataObject *dataObj = nullptr;
if (FileDirectoryDialog::isGourpFiles(file)) if (FileDirectoryDialog::isGourpFiles(file))
{
dataObj = new RenderDataImportUnSteady(file); dataObj = new RenderDataImportUnSteady(file);
}
else else
{
dataObj = new RenderDataImportSteady(file); dataObj = new RenderDataImportSteady(file);
}
dataObj->update(); dataObj->update();
auto dataset = dataObj->getOutputData(); auto dataset = dataObj->getOutputData();

View File

@ -18,6 +18,8 @@
#include <vtkDataSetWriter.h> #include <vtkDataSetWriter.h>
#include <QFile> #include <QFile>
#include <QString> #include <QString>
#include <vtkXMLUnstructuredGridReader.h>
#include <vtkXMLPUnstructuredGridReader.h>
namespace Post namespace Post
{ {
@ -97,6 +99,26 @@ namespace Post
mapper->SetInputConnection(_vtkAlg->GetOutputPort(i + 1)); mapper->SetInputConnection(_vtkAlg->GetOutputPort(i + 1));
} }
} }
else if (_Suffix == "vtu")
{
CreateVTKSmartPtr(vtkXMLUnstructuredGridReader, _vtkAlg) auto r = vtkXMLUnstructuredGridReader::SafeDownCast(_vtkAlg);
QString2Char(_FileName, c);
r->SetFileName(c);
r->Update();
_blockNumber = 1;
auto mapper = createMapper(true);
mapper->SetInputConnection(_vtkAlg->GetOutputPort(0));
}
else if (_Suffix == "pvtu")
{
CreateVTKSmartPtr(vtkXMLPUnstructuredGridReader, _vtkAlg) auto r = vtkXMLPUnstructuredGridReader::SafeDownCast(_vtkAlg);
QString2Char(_FileName, c);
r->SetFileName(c);
r->Update();
_blockNumber = 1;
auto mapper = createMapper(true);
mapper->SetInputConnection(_vtkAlg->GetOutputPort(0));
}
} }
RenderDataImportSteady *RenderDataImportSteady::SafeDownCast(RenderDataObject *obj) RenderDataImportSteady *RenderDataImportSteady::SafeDownCast(RenderDataObject *obj)

View File

@ -5,6 +5,8 @@
#include "PostAlgorithm/CGNSReaderAlgorithm.h" #include "PostAlgorithm/CGNSReaderAlgorithm.h"
#include "PostAlgorithm/Plot3DReaderAlgorithm.h" #include "PostAlgorithm/Plot3DReaderAlgorithm.h"
#include "Macros.hxx" #include "Macros.hxx"
#include <vtkXMLUnstructuredGridReader.h>
#include <vtkXMLPUnstructuredGridReader.h>
namespace Post { namespace Post {
QStringList getSelectGroupFiles(const QString path) QStringList getSelectGroupFiles(const QString path)
@ -124,7 +126,26 @@ namespace Post {
auto mapper = createMapper(true); auto mapper = createMapper(true);
mapper->SetInputConnection(_vtkAlg->GetOutputPort(i + 1)); mapper->SetInputConnection(_vtkAlg->GetOutputPort(i + 1));
} }
}
else if (Suffix == "vtu")
{
CreateVTKSmartPtr(vtkXMLUnstructuredGridReader, _vtkAlg)
auto r = vtkXMLUnstructuredGridReader::SafeDownCast(_vtkAlg);
QString2Char(fileName, c)
r->SetFileName(c);
_blockNumber = 1;
auto mapper = createMapper(true);
mapper->SetInputConnection(_vtkAlg->GetOutputPort(0));
}
else if (Suffix == "pvtu")
{
CreateVTKSmartPtr(vtkXMLPUnstructuredGridReader, _vtkAlg)
auto r = vtkXMLPUnstructuredGridReader::SafeDownCast(_vtkAlg);
QString2Char(fileName, c)
r->SetFileName(c);
_blockNumber = 1;
auto mapper = createMapper(true);
mapper->SetInputConnection(_vtkAlg->GetOutputPort(0));
} }
} }
@ -149,6 +170,18 @@ namespace Post {
QString2Char(f, c); QString2Char(f, c);
r->SetFileName(c); r->SetFileName(c);
} }
else if (this->getSuffix() == "vtu")
{
auto r = vtkXMLUnstructuredGridReader::SafeDownCast(_vtkAlg);
QString2Char(f, c);
r->SetFileName(c);
}
else if (this->getSuffix() == "pvtu")
{
auto r = vtkXMLPUnstructuredGridReader::SafeDownCast(_vtkAlg);
QString2Char(f, c);
r->SetFileName(c);
}
} }
RenderDataImportUnSteady::~RenderDataImportUnSteady() RenderDataImportUnSteady::~RenderDataImportUnSteady()

View File

@ -201,9 +201,9 @@ QStringList RenderDataObject::getBlockCellDataArray(int index)
return nameList; return nameList;
} }
int RenderDataObject::variableType(int vaLocation, QString vaName) QString RenderDataObject::variableType(int vaLocation, QString vaName)
{ {
int type = 0; QString type = "Unknown";
vtkDataSet* data = getOutputData(); vtkDataSet* data = getOutputData();
if (data == nullptr) return 0; if (data == nullptr) return 0;
QString2Char(vaName, cName) QString2Char(vaName, cName)
@ -215,11 +215,11 @@ int RenderDataObject::variableType(int vaLocation, QString vaName)
if (dataArray == nullptr) return 0; if (dataArray == nullptr) return 0;
const int cNum = dataArray->GetNumberOfComponents(); const int cNum = dataArray->GetNumberOfComponents();
if (cNum == 1) if (cNum == 1)
type = 1; type = "scalar";
else if (cNum == 3) else if (cNum == 3)
type = 2; type = "vector";
else if (cNum >= 4) else if (cNum == 9)
type = 3; type = "tensor";
return type; return type;
} }

View File

@ -120,9 +120,10 @@ namespace Post {
* @brief * @brief
* @param vaLocation 1-pointData 2-cellData * @param vaLocation 1-pointData 2-cellData
* @param vaName * @param vaName
* @return int 1- 2- 3- 0- * @return QString :scalar\vector\tensor\Unknown
* @note vtk
*/ */
int variableType(int vaLocation, QString vaName); QString variableType(int vaLocation, QString vaName);
/** /**
* @brief * @brief
* @param vaLocation 1-pointData 2-cellData * @param vaLocation 1-pointData 2-cellData

View File

@ -27,6 +27,8 @@ add_library(PythonModule
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
target_compile_definitions(PythonModule PRIVATE "PYTHONMODULE_API") target_compile_definitions(PythonModule PRIVATE "PYTHONMODULE_API")
list(APPEND _depend_library Common)
list(APPEND _runtimes_libraries list(APPEND _runtimes_libraries
Qt5::Widgets FASTCAE::PYTHON Qt5::Widgets FASTCAE::PYTHON
) )
@ -39,7 +41,14 @@ endif()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# #
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
target_link_libraries(PythonModule ${_runtimes_libraries}) target_link_libraries(PythonModule
${_runtimes_libraries}
${_depend_library})
#-----------------------------------------------------------------------------
#
#-----------------------------------------------------------------------------
add_dependencies(PythonModule ${_depend_library})
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# #

View File

@ -1,17 +1,16 @@
#include <Python.h> #include <Python.h>
#include "PyAgent.h"
#include <QString>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QFile>
#include <QString>
#include <QTextStream>
#include <wchar.h>
#include "PyAgent.h"
#include "MainWindow/MainWindow.h" #include "MainWindow/MainWindow.h"
#include "PyInterpreter.h" #include "PyInterpreter.h"
#include "RecordScript.h" #include "RecordScript.h"
#include "ScriptReader.h" #include "ScriptReader.h"
#include <QFile>
#include <QDebug>
#include <QTextStream>
#include <wchar.h>
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
#include <atlconv.h> #include <atlconv.h>
@ -19,8 +18,7 @@
#include <locale.h> #include <locale.h>
namespace Py namespace Py {
{
PythonAgent* PythonAgent::_instance = nullptr; PythonAgent* PythonAgent::_instance = nullptr;
PythonAgent* PythonAgent::getInstance() PythonAgent* PythonAgent::getInstance()
@ -33,7 +31,8 @@ namespace Py
void PythonAgent::connectSignals() void PythonAgent::connectSignals()
{ {
connect(this, SIGNAL(printInfo(Common::Message, QString)), _mainWindow, SIGNAL(printMessageSig(Common::Message, QString))); connect(this, SIGNAL(printInfo(Common::Message, QString)), _mainWindow,
SIGNAL(printMessageSig(Common::Message, QString)));
connect(this, SIGNAL(closeMainWindow()), _mainWindow, SIGNAL(closeMainWindow())); connect(this, SIGNAL(closeMainWindow()), _mainWindow, SIGNAL(closeMainWindow()));
} }
@ -54,33 +53,6 @@ namespace Py
{ {
_mainWindow = m; _mainWindow = m;
connectSignals(); connectSignals();
/*
QString path = qApp->applicationDirPath() + "/../python37";
path = QDir::cleanPath(path);
char *ch;
QByteArray ba = path.toLocal8Bit();
ch = ba.data();
wchar_t *wc;
#ifdef Q_OS_WIN32
USES_CONVERSION;
wc = A2W(ch);
#endif
#ifdef Q_OS_LINUX
setlocale(LC_CTYPE, "zh_CN.utf8");
int w_size = mbstowcs(NULL, ba, 0) + 1;
wc = new wchar_t[w_size];
mbstowcs(wc, ba, strlen(ba) + 1);
#endif
QDir d(path);
if (d.exists())
{
#ifdef Q_OS_WIN32
Py_SetPythonHome(wc);
#endif
}*/
Py_SetProgramName(L"FastCAE"); Py_SetProgramName(L"FastCAE");
Py_Initialize(); Py_Initialize();
if(!_interpreter->init(this)) if(!_interpreter->init(this))
@ -93,10 +65,8 @@ namespace Py
void PythonAgent::finalize() void PythonAgent::finalize()
{ {
if (_reader != nullptr) if(_reader != nullptr) {
{ if(_reader->isRunning()) {
if (_reader->isRunning())
{
_reader->stop(); _reader->stop();
_reader->quit(); _reader->quit();
_reader->wait(); _reader->wait();
@ -121,13 +91,10 @@ namespace Py
void PythonAgent::submit(QString code, bool s) void PythonAgent::submit(QString code, bool s)
{ {
// this->lock();
qDebug() << "submit: " << code;
emit printInfo(Common::Message::Python, code); emit printInfo(Common::Message::Python, code);
// lock(); // lock();
int ok = _interpreter->execCode(code, s); int ok = _interpreter->execCode(code, s);
if (ok == -1) if(ok == -1) {
{
if(_reader != nullptr) if(_reader != nullptr)
_reader->restart(); _reader->restart();
} }
@ -136,8 +103,7 @@ namespace Py
void PythonAgent::submit(QStringList codes, bool save /*= true*/) void PythonAgent::submit(QStringList codes, bool save /*= true*/)
{ {
const int n = codes.size(); const int n = codes.size();
for (int i = 0; i < n; ++i) for(int i = 0; i < n; ++i) {
{
this->submit(codes.at(i), save); this->submit(codes.at(i), save);
} }
} }
@ -145,15 +111,13 @@ namespace Py
void PythonAgent::saveScript(QString fileName) void PythonAgent::saveScript(QString fileName)
{ {
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::Text | QIODevice::WriteOnly)) if(!file.open(QIODevice::Text | QIODevice::WriteOnly)) {
{
emit printInfo(Common::Message::Error, tr("Script open failed")); emit printInfo(Common::Message::Error, tr("Script open failed"));
return; return;
} }
QTextStream stream(&file); QTextStream stream(&file);
const int n = _interpreter->getCodeCount(); const int n = _interpreter->getCodeCount();
for (int i = 0; i < n; ++i) for(int i = 0; i < n; ++i) {
{
QString s = _interpreter->getCodeAt(i); QString s = _interpreter->getCodeAt(i);
stream << s << endl; stream << s << endl;
} }
@ -229,4 +193,4 @@ namespace Py
{ {
_interpreter->execCode(code, false); _interpreter->execCode(code, false);
} }
} } // namespace Py

View File

@ -8,14 +8,13 @@
#include <string> #include <string>
#include <QReadWriteLock> #include <QReadWriteLock>
#include "Common/Types.h" #include "Common/Types.h"
#include "Common/DebugLogger.h"
namespace Py namespace Py {
{
bool PyInterpreter::init(PythonAgent* agent) bool PyInterpreter::init(PythonAgent* agent)
{ {
if (!Py_IsInitialized()) if(!Py_IsInitialized()) {
{
return false; return false;
} }
_agent = agent; _agent = agent;
@ -31,8 +30,7 @@ namespace Py
suffix << "*.py"; suffix << "*.py";
dir.setNameFilters(suffix); dir.setNameFilters(suffix);
QList<QFileInfo> files = dir.entryInfoList(suffix); QList<QFileInfo> files = dir.entryInfoList(suffix);
for (int i = 0; i < files.size(); ++i) for(int i = 0; i < files.size(); ++i) {
{
QFileInfo fileinfo = files.at(i); QFileInfo fileinfo = files.at(i);
QString name = fileinfo.baseName(); QString name = fileinfo.baseName();
QString command = QString("import %1").arg(name); QString command = QString("import %1").arg(name);
@ -48,12 +46,12 @@ namespace Py
lock.lockForRead(); lock.lockForRead();
std::string s = code.toStdString(); std::string s = code.toStdString();
const char* c = s.c_str(); const char* c = s.c_str();
qDebug() << "exec: " << code;
DebugInfo("Exec python script: %s\n", code.toStdString().c_str());
int ok = PyRun_SimpleStringFlags(c, NULL); int ok = PyRun_SimpleStringFlags(c, NULL);
if (ok == -1) if(ok == -1) {
{
QString error = QString(tr("Exception occurred at: \"%1\"")).arg(code); QString error = QString(tr("Exception occurred at: \"%1\"")).arg(code);
_agent->printInfo(Common::Message::Warning, error); _agent->printInfo(Common::Message::Warning, error);
} }
@ -96,4 +94,4 @@ namespace Py
{ {
return _codelist; return _codelist;
} }
} } // namespace Py

View File

@ -47,7 +47,6 @@ SARibbonMainWindow::SARibbonMainWindow(QWidget *parent, bool useRibbon)
{ {
m_d->init(); m_d->init();
m_d->useRibbon = useRibbon; m_d->useRibbon = useRibbon;
qDebug() << windowFlags();
if (useRibbon) { if (useRibbon) {
qDebug() << "sa ribbon version:" << SA_RIBBON_BAR_VERSION_STR; qDebug() << "sa ribbon version:" << SA_RIBBON_BAR_VERSION_STR;
setRibbonTheme(ribbonTheme()); setRibbonTheme(ribbonTheme());

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1011 B

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1010 B

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1014 B

After

Width:  |  Height:  |  Size: 120 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1016 B

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 475 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 377 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 152 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1013 B

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1018 B

After

Width:  |  Height:  |  Size: 127 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 462 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 405 KiB

After

Width:  |  Height:  |  Size: 360 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 961 B

After

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 886 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 991 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 691 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 680 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 513 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 602 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 534 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 532 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 753 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 572 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 948 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 504 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 562 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 499 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 754 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 457 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 768 B

Some files were not shown because too many files have changed in this diff Show More