From 4c37db10649da95ae06ea551df58768740b7bab4 Mon Sep 17 00:00:00 2001 From: penghaiyi Date: Tue, 16 May 2023 14:45:18 +0800 Subject: [PATCH] add load rendering --- src/Framework/VirtualAttach.h | 38 ++++ src/MxSimPre/DataProcess/ShowLoad.cpp | 91 +++++++++ src/MxSimPre/DataProcess/ShowLoad.h | 35 ++++ src/MxSimPre/DataPropertyUi/Mx_BCUi.cpp | 38 ++-- src/MxSimPre/DataPropertyUi/Mx_FixedBCUi.cpp | 53 ++--- src/MxSimPre/DataPropertyUi/Mx_FixedBCUi.h | 2 +- src/MxSimPre/DataPropertyUi/Mx_LoadUi.cpp | 182 ++++-------------- .../DataPropertyUi/Mx_PrepostProcessUi.cpp | 76 ++++---- src/MxSimPre/MBasicFunction/mLoadBCEnum.h | 2 + src/MxSimPre/MDataLoadBC/mDis.cpp | 12 +- src/MxSimPre/MDataLoadBC/mDistrForce.cpp | 3 +- src/MxSimPre/MDataLoadBC/mDomainLoad.cpp | 10 +- src/MxSimPre/MDataLoadBC/mFixed.cpp | 7 +- src/MxSimPre/MDataLoadBC/mFixed.h | 6 +- src/MxSimPre/MDataLoadBC/mForce.cpp | 15 +- src/MxSimPre/MDataLoadBC/mForce.h | 3 +- src/MxSimPre/MDataLoadBC/mGravity.cpp | 15 +- src/MxSimPre/MDataLoadBC/mInitBoundary.cpp | 21 +- src/MxSimPre/MDataLoadBC/mLineLoad.cpp | 11 +- src/MxSimPre/MDataLoadBC/mLoadBCBase.cpp | 72 ++++--- src/MxSimPre/MDataLoadBC/mLoadBCBase.h | 81 +++----- src/MxSimPre/MDataLoadBC/mPressure.cpp | 6 +- src/MxSimPre/MDataLoadBC/mPretensionLoad.cpp | 13 +- src/MxSimPre/MDataLoadBC/mSuportBC.cpp | 13 +- src/MxSimPre/MDataLoadBC/mTransientLoad.cpp | 9 +- src/MxSimPre/MxDataField/DataField.cpp | 24 +-- src/MxSimPre/PreprocessNode/BC.cpp | 16 +- src/MxSimPre/PreprocessNode/Load.cpp | 106 ++++++---- src/MxSimPre/PreprocessNode/Load.h | 4 + .../PreprocessNode/PrepostProcess.cpp | 30 +-- .../Module/GLPointAttachmentVisualModule.cpp | 134 +++++++++++++ .../Module/GLPointAttachmentVisualModule.h | 65 +++++++ .../GLSurfaceAttachmentVisualModule.cpp | 148 ++++++++++++++ .../Module/GLSurfaceAttachmentVisualModule.h | 67 +++++++ src/Rendering/Engine/OpenGL/gl/Shader.cpp | 52 +++++ src/Rendering/Engine/OpenGL/gl/Shader.h | 1 + .../OpenGL/shader/point_attachment.frag | 13 ++ .../OpenGL/shader/point_attachment.geom | 77 ++++++++ .../OpenGL/shader/point_attachment.vert | 41 ++++ .../OpenGL/shader/surface_attachment.frag | 13 ++ .../OpenGL/shader/surface_attachment.geom | 103 ++++++++++ .../OpenGL/shader/surface_attachment.vert | 26 +++ src/Rendering/Engine/OpenGL/shader/utils.glsl | 41 ++++ 43 files changed, 1299 insertions(+), 476 deletions(-) create mode 100644 src/Framework/VirtualAttach.h create mode 100644 src/MxSimPre/DataProcess/ShowLoad.cpp create mode 100644 src/MxSimPre/DataProcess/ShowLoad.h create mode 100644 src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLPointAttachmentVisualModule.cpp create mode 100644 src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLPointAttachmentVisualModule.h create mode 100644 src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLSurfaceAttachmentVisualModule.cpp create mode 100644 src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLSurfaceAttachmentVisualModule.h create mode 100644 src/Rendering/Engine/OpenGL/shader/point_attachment.frag create mode 100644 src/Rendering/Engine/OpenGL/shader/point_attachment.geom create mode 100644 src/Rendering/Engine/OpenGL/shader/point_attachment.vert create mode 100644 src/Rendering/Engine/OpenGL/shader/surface_attachment.frag create mode 100644 src/Rendering/Engine/OpenGL/shader/surface_attachment.geom create mode 100644 src/Rendering/Engine/OpenGL/shader/surface_attachment.vert create mode 100644 src/Rendering/Engine/OpenGL/shader/utils.glsl diff --git a/src/Framework/VirtualAttach.h b/src/Framework/VirtualAttach.h new file mode 100644 index 00000000..9c665601 --- /dev/null +++ b/src/Framework/VirtualAttach.h @@ -0,0 +1,38 @@ +/** + * Copyright 2021 XunKun Luo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once +#include "Module.h" + +namespace dyno +{ + enum class AttachShape { + Arrow = 0, + Boundary + }; + + struct PointAttachAttribute { + std::vector index_set; + Vec3f color; + Vec3f direction; + AttachShape shape {AttachShape::Arrow}; + }; + + struct SurfaceAttachAttribute { + std::vector index_set; + Vec3f color; + AttachShape shape {AttachShape::Arrow}; + }; +} diff --git a/src/MxSimPre/DataProcess/ShowLoad.cpp b/src/MxSimPre/DataProcess/ShowLoad.cpp new file mode 100644 index 00000000..d6a5cf5d --- /dev/null +++ b/src/MxSimPre/DataProcess/ShowLoad.cpp @@ -0,0 +1,91 @@ +#include "ShowLoad.h" + +#include + +#include "MDataLoadBC/mForce.h" +#include "MDataLoadBC/mPressure.h" + +using namespace MDataLoadBC; + +namespace { + template + T string_convert(const std::string& str); + template<> + double string_convert(const std::string& str) { + return std::stod(str); + } + template<> + float string_convert(const std::string& str) { + return std::stof(str); + } + template<> + int string_convert(const std::string& str) { + return std::stoi(str); + } + + template + T to(const std::string& str) { + try + { + return string_convert(str); + } + catch (const std::invalid_argument& ex) + { + } + catch (const std::out_of_range& ex) + { + } + return {}; + } +} + +namespace dyno +{ + IMPLEMENT_CLASS(ShowMxLoad); + ShowMxLoad::ShowMxLoad() + { + } + + ShowMxLoad::~ShowMxLoad() + { + } + + void ShowMxLoad::updateImpl() + { + this->outTriangleSet()->setDataPtr(this->inTriangleSet()->constDataPtr()); + + auto load_list = this->inLoadList()->constDataPtr(); + if (load_list) { + std::vector point_attrs; + std::vector surface_attrs; + for (auto& el : *load_list) { + auto type = el.load->type(); + switch (type) { + case LoadBCType::LBCForce: { + PointAttachAttribute pa; + auto force = static_cast(el.load.get()); + pa.index_set = el.index_set; + pa.direction = Vec3f(to(force->u1), to(force->u2), to(force->u3)); + pa.color = Vec3f(1.0, 1.0, 0.0); + pa.shape = AttachShape::Arrow; + point_attrs.push_back(pa); + break; + } + case LoadBCType::LBCPressure: { + SurfaceAttachAttribute sa; + auto pressure = static_cast(el.load.get()); + sa.index_set = el.index_set; + sa.color = Vec3f(0.0, 1.0, 0.0); + sa.shape = AttachShape::Arrow; + surface_attrs.push_back(sa); + break; + } + default: + break; + } + } + this->outPointAttachAttributes()->setValue(std::move(point_attrs)); + this->outSurfaceAttachAttributes()->setValue(std::move(surface_attrs)); + } + } +} \ No newline at end of file diff --git a/src/MxSimPre/DataProcess/ShowLoad.h b/src/MxSimPre/DataProcess/ShowLoad.h new file mode 100644 index 00000000..388d44c3 --- /dev/null +++ b/src/MxSimPre/DataProcess/ShowLoad.h @@ -0,0 +1,35 @@ +#pragma once +#include "Module.h" +#include "Topology/TriangleSet.h" + +#include "GeometryData/Mx_Geometrydata.h" +#include "GeometryData/Mx_Geometrypart.h" +#include "MDataLoadBC/mLoadBCBase.h" + +#include "VirtualAttach.h" + +//OCC +#include +#include + + +namespace dyno +{ + class ShowMxLoad : public Module + { + DECLARE_CLASS(ShowMxLoad); + public: + + ShowMxLoad(); + ~ShowMxLoad(); + + DEF_INSTANCE_IN(TriangleSet, TriangleSet, "TriangleSet"); + DEF_VAR_IN(std::vector, LoadList, ""); + + DEF_INSTANCE_OUT(TriangleSet, TriangleSet, "TriangleSet"); + DEF_VAR_OUT(std::vector, PointAttachAttributes, ""); + DEF_VAR_OUT(std::vector, SurfaceAttachAttributes, ""); + public: + void updateImpl() override; + }; +} \ No newline at end of file diff --git a/src/MxSimPre/DataPropertyUi/Mx_BCUi.cpp b/src/MxSimPre/DataPropertyUi/Mx_BCUi.cpp index 53670973..59ce409e 100644 --- a/src/MxSimPre/DataPropertyUi/Mx_BCUi.cpp +++ b/src/MxSimPre/DataPropertyUi/Mx_BCUi.cpp @@ -124,62 +124,64 @@ namespace MBCUi std::vector tempData = BC->getAllBC(); BC->setIsAssign(true); - if (loadType == tr("固定/对称/反对称")) - { - mFixed* fixed = new mFixed(); - fixed->_loadBCName = m_newBC.edit->text().toStdString(); + auto set_common = [this](mLoadBCBase& base) { + base.setName(m_newBC.edit->text().toStdString()); std::string loadcase = m_BCCaseList.m_caseList->currentItem()->text().toStdString(); - fixed->_loadcase.push_back(loadcase); + base.appendLoadCase(loadcase); + }; + + if (loadType == ("固定/对称/反对称")) + { + mFixed* fixed{ nullptr }; if (m_Fixed->fixed->isChecked()) { - fixed->_loadBCType = LoadBCType::LBCDFixed; + fixed = new mFixed("", LoadBCType::LBCDFixed); fixed->_type = std::string("完全固定"); } else if (m_Fixed->joint->isChecked()) { - fixed->_loadBCType = LoadBCType::LBCDFixed; + fixed = new mFixed("", LoadBCType::LBCDFixed); fixed->_type = std::string("铰接(U1=U2=U3=0)"); } else if (m_Fixed->symmetryX->isChecked()) { - fixed->_loadBCType = LoadBCType::LBCDSymmetry; + fixed = new mFixed("", LoadBCType::LBCDSymmetry); fixed->_type = std::string("关于X轴对称(U1=UR2=UR3=0"); } else if (m_Fixed->symmetryY->isChecked()) { - fixed->_loadBCType = LoadBCType::LBCDSymmetry; + fixed = new mFixed("", LoadBCType::LBCDSymmetry); fixed->_type = std::string("关于Y轴对称(U2=UR1=UR3=0"); } else if (m_Fixed->symmetryZ->isChecked()) { - fixed->_loadBCType = LoadBCType::LBCDSymmetry; + fixed = new mFixed("", LoadBCType::LBCDSymmetry); fixed->_type = std::string("关于Z轴对称(U3=UR1=UR2=0"); } else if (m_Fixed->antiSymmetryX->isChecked()) { - fixed->_loadBCType = LoadBCType::LBCDSymmetry; + fixed = new mFixed("", LoadBCType::LBCDSymmetry); fixed->_type = std::string("关于X轴反对称(U2=U3=UR1=0"); } else if (m_Fixed->antiSymmetryY->isChecked()) { - fixed->_loadBCType = LoadBCType::LBCDSymmetry; + fixed = new mFixed("", LoadBCType::LBCDSymmetry); fixed->_type = std::string("关于Y轴反对称(U1=U3=UR2=0"); } else if (m_Fixed->antiSymmetryZ->isChecked()) { - fixed->_loadBCType = LoadBCType::LBCDSymmetry; + fixed = new mFixed("", LoadBCType::LBCDSymmetry); fixed->_type = std::string("关于Z轴反对称(U1=U2=UR3=0"); } + set_common(*fixed); + tempData.push_back(fixed); } else if (loadType == tr("位移/转角")) { mDis* dis = new mDis(); - dis->_loadBCType = LoadBCType::LBCDisplacement; - dis->_loadBCName = m_newBC.edit->text().toStdString(); - std::string loadcase = m_BCCaseList.m_caseList->currentItem()->text().toStdString(); - dis->_loadcase.push_back(loadcase); + set_common(*dis); if (m_Dis->U1->isChecked()) { dis->bu1 = true; @@ -329,7 +331,7 @@ namespace MBCUi { int row_count = m_BCMatchList.m_matchList->rowCount(); m_BCMatchList.m_matchList->insertRow(row_count); - QString name = (tempData[i]->_loadBCName.c_str()); + QString name = (tempData[i]->name().c_str()); m_BCMatchList.m_matchList->setItem(row_count, 0, new QTableWidgetItem(name)); QString type = (tempData[i]->getLoadBCTypeStr().c_str()); m_BCMatchList.m_matchList->setItem(row_count, 1, new QTableWidgetItem(type)); diff --git a/src/MxSimPre/DataPropertyUi/Mx_FixedBCUi.cpp b/src/MxSimPre/DataPropertyUi/Mx_FixedBCUi.cpp index 3d40d516..5cb30766 100644 --- a/src/MxSimPre/DataPropertyUi/Mx_FixedBCUi.cpp +++ b/src/MxSimPre/DataPropertyUi/Mx_FixedBCUi.cpp @@ -1,4 +1,5 @@ #include "Mx_FixedBCUi.h" +#include "MDataLoadBC/mFixed.h" #include #include #include @@ -28,14 +29,14 @@ namespace MBCUi QGridLayout* g_main = new QGridLayout; main->setLayout(g_main); - fixed = new QCheckBox(tr("完全固定(U1=U2=U3=UR1=UR2=UR3=0)"), this); - joint = new QCheckBox(tr("铰接(U1=U2=U3=0)"), this); - symmetryX = new QCheckBox(tr("关于X轴对称(U1=UR2=UR3=0)"), this); - symmetryY = new QCheckBox(tr("关于Y轴对称(U2=UR1=UR3=0)"), this); - symmetryZ = new QCheckBox(tr("关于Z轴对称(U3=UR1=UR2=0)"), this); - antiSymmetryX = new QCheckBox(tr("关于X轴反对称(U2=U3=UR1=0)"), this); - antiSymmetryY = new QCheckBox(tr("关于Y轴反对称(U1=U3=UR2=0)"), this); - antiSymmetryZ = new QCheckBox(tr("关于Z轴反对称(U1=U2=UR3=0)"), this); + fixed = new QCheckBox(("完全固定(U1=U2=U3=UR1=UR2=UR3=0)"), this); + joint = new QCheckBox(("铰接(U1=U2=U3=0)"), this); + symmetryX = new QCheckBox(("关于X轴对称(U1=UR2=UR3=0)"), this); + symmetryY = new QCheckBox(("关于Y轴对称(U2=UR1=UR3=0)"), this); + symmetryZ = new QCheckBox(("关于Z轴对称(U3=UR1=UR2=0)"), this); + antiSymmetryX = new QCheckBox(("关于X轴反对称(U2=U3=UR1=0)"), this); + antiSymmetryY = new QCheckBox(("关于Y轴反对称(U1=U3=UR2=0)"), this); + antiSymmetryZ = new QCheckBox(("关于Z轴反对称(U1=U2=UR3=0)"), this); //QPushButton* pickLabel = new QPushButton(tr("作用对象"), this); @@ -177,47 +178,49 @@ namespace MBCUi } - void Mx_FixedBCUi::BCData(mFixed& fix) + mFixed* Mx_FixedBCUi::BCData() const { + mFixed* f = nullptr; if (fixed->isChecked()) { - fix._loadBCType = LoadBCType::LBCDFixed; - fix._type = std::string("完全固定"); + f = new mFixed("", LoadBCType::LBCDFixed); + f->_type = std::string("完全固定"); } else if (joint->isChecked()) { - fix._loadBCType = LoadBCType::LBCDFixed; - fix._type = std::string("铰接(U1=U2=U3=0)"); + f = new mFixed("", LoadBCType::LBCDFixed); + f->_type = std::string("铰接(U1=U2=U3=0)"); } else if (symmetryX->isChecked()) { - fix._loadBCType = LoadBCType::LBCDSymmetry; - fix._type = std::string("关于X轴对称(U1=UR2=UR3=0"); + f = new mFixed("", LoadBCType::LBCDSymmetry); + f->_type = std::string("关于X轴对称(U1=UR2=UR3=0"); } else if (symmetryY->isChecked()) { - fix._loadBCType = LoadBCType::LBCDSymmetry; - fix._type = std::string("关于Y轴对称(U2=UR1=UR3=0"); + f = new mFixed("", LoadBCType::LBCDSymmetry); + f->_type = std::string("关于Y轴对称(U2=UR1=UR3=0"); } else if (symmetryZ->isChecked()) { - fix._loadBCType = LoadBCType::LBCDSymmetry; - fix._type = std::string("关于Z轴对称(U3=UR1=UR2=0"); + f = new mFixed("", LoadBCType::LBCDSymmetry); + f->_type = std::string("关于Z轴对称(U3=UR1=UR2=0"); } else if (antiSymmetryX->isChecked()) { - fix._loadBCType = LoadBCType::LBCDSymmetry; - fix._type = std::string("关于X轴反对称(U2=U3=UR1=0"); + f = new mFixed("", LoadBCType::LBCDSymmetry); + f->_type = std::string("关于X轴反对称(U2=U3=UR1=0"); } else if (antiSymmetryY->isChecked()) { - fix._loadBCType = LoadBCType::LBCDSymmetry; - fix._type = std::string("关于Y轴反对称(U1=U3=UR2=0"); + f = new mFixed("", LoadBCType::LBCDSymmetry); + f->_type = std::string("关于Y轴反对称(U1=U3=UR2=0"); } else if (antiSymmetryZ->isChecked()) { - fix._loadBCType = LoadBCType::LBCDSymmetry; - fix._type = std::string("关于Z轴反对称(U1=U2=UR3=0"); + f = new mFixed("", LoadBCType::LBCDSymmetry); + f->_type = std::string("关于Z轴反对称(U1=U2=UR3=0"); } + return f; } } \ No newline at end of file diff --git a/src/MxSimPre/DataPropertyUi/Mx_FixedBCUi.h b/src/MxSimPre/DataPropertyUi/Mx_FixedBCUi.h index 12311522..f195d1d1 100644 --- a/src/MxSimPre/DataPropertyUi/Mx_FixedBCUi.h +++ b/src/MxSimPre/DataPropertyUi/Mx_FixedBCUi.h @@ -21,7 +21,7 @@ namespace MBCUi Mx_FixedBCUi(); ~Mx_FixedBCUi() {} - void BCData(mFixed& ); + mFixed* BCData() const; public: QCheckBox* fixed; diff --git a/src/MxSimPre/DataPropertyUi/Mx_LoadUi.cpp b/src/MxSimPre/DataPropertyUi/Mx_LoadUi.cpp index 7a60d38c..dfd3834a 100644 --- a/src/MxSimPre/DataPropertyUi/Mx_LoadUi.cpp +++ b/src/MxSimPre/DataPropertyUi/Mx_LoadUi.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,18 @@ using namespace MDataLoadBC; namespace MLoadBCUi { + QString to_local_string(LoadBCType t) { + const char* out{""}; + switch (t) { + case LoadBCType::LBCForce: out = QT_TRANSLATE_NOOP("LoadBCType", "Force"); break; + case LoadBCType::LBCGravity: out = QT_TRANSLATE_NOOP("LoadBCType", "Gravity"); break; + case LoadBCType::LBCPressure: out = QT_TRANSLATE_NOOP("LoadBCType", "Pressure"); break; + default: + out = QT_TRANSLATE_NOOP("LoadBCType", "Unknown"); + } + return QCoreApplication::translate("LoadBCType", out); + } + Mx_LoadUi::Mx_LoadUi(FBase* field) { QTextCodec* codec = QTextCodec::codecForName("GB2312"); @@ -65,13 +78,9 @@ namespace MLoadBCUi } - std::vector loadType = Load->getAllLoadType(); - if (loadType.size() != 0) - { - for (int i = 0; i < loadType.size(); ++i) - { - m_loadTypeList.m_typeList->addItem(tr(loadType[i].c_str())); - } + std::vector loadType = Load->getLoadTypes(); + for (auto& el : loadType) { + m_loadTypeList.m_typeList->addItem(to_local_string(el), (int)el); } m_Force = new mForceUi(); @@ -80,72 +89,17 @@ namespace MLoadBCUi connect(m_loadTypeList.m_typeList, static_cast(&QComboBox::activated), [=]() { - QString type = m_loadTypeList.m_typeList->currentText(); - if (type == tr("集中力")) - { + auto load_type = (LoadBCType) m_loadTypeList.m_typeList->currentData().toInt(); + switch (load_type) { + case LoadBCType::LBCForce: m_Force->show(); - m_Force->setWindowTitle(tr("集中力")); - } - else if (type == tr("力矩")) - { - - } - else if (type == tr("重力")) - { + break; + case LoadBCType::LBCGravity: m_Gravity->show(); - } - else if (type == tr("压强")) - { + break; + case LoadBCType::LBCPressure: m_Pressure->show(); - m_Pressure->setWindowTitle(tr("压强")); - } - else if (type == tr("瞬态载荷")) - { - - } - else if (type == tr("频域载荷")) - { - - } - else if (type == tr("线载荷")) - { - - } - else if (type == tr("预紧力")) - { - - } - else if (type == tr("热流密度")) - { - - } - else if (type == tr("对流换热载荷")) - { - - } - else if (type == tr("热辐射载荷")) - { - - } - else if (type == tr("温度载荷")) - { - - } - else if (type == tr("内部热源")) - { - - } - else if (type == tr("电荷")) - { - - } - else if (type == tr("电荷密度")) - { - - } - else if (type == tr("离心力")) - { - + break; } }); @@ -158,17 +112,20 @@ namespace MLoadBCUi m_loadMatchList.m_matchList->setItem(row_count, 0, new QTableWidgetItem(m_newLoad.edit->text())); m_loadMatchList.m_matchList->setItem(row_count, 1, new QTableWidgetItem(m_loadTypeList.m_typeList->currentText())); - QString loadType = m_loadTypeList.m_typeList->currentText(); std::vector tempData = Load->getAllLoad(); Load->setIsAssign(true); - if (loadType == tr("集中力")) - { - mForce* force = new mForce(); - force->_loadBCName = m_newLoad.edit->text().toStdString(); - force->_loadBCType = LoadBCType::LBCForce; + auto set_common = [this](mLoadBCBase& base) { + base.setName(m_newLoad.edit->text().toStdString()); std::string loadcase = m_caseList.m_caseList->currentItem()->text().toStdString(); - force->_loadcase.push_back(loadcase); + base.appendLoadCase(loadcase); + }; + + auto load_type = (LoadBCType) m_loadTypeList.m_typeList->currentData().toInt(); + switch (load_type) { + case LoadBCType::LBCForce: { + mForce* force = new mForce(); + set_common(*force); if (m_Force->inF1->text().toStdString() == "") { @@ -196,81 +153,26 @@ namespace MLoadBCUi } tempData.push_back(force); + break; } - else if (loadType == tr("力矩")) - { - - } - else if (loadType == tr("重力")) - { + case LoadBCType::LBCGravity: { mGravity* force = new mGravity(); - force->_loadBCName = m_newLoad.edit->text().toStdString(); - std::string loadcase = m_caseList.m_caseList->currentItem()->text().toStdString(); - force->_loadcase.push_back(loadcase); + set_common(*force); m_Gravity->LoadData(*force); tempData.push_back(force); + break; } - else if (loadType == tr("压强")) - { + case LoadBCType::LBCPressure: { mPressure* pressure = new mPressure(); - pressure->_loadBCName = m_newLoad.edit->text().toStdString(); - pressure->_loadBCType = LoadBCType::LBCPressure; - std::string loadcase = m_caseList.m_caseList->currentItem()->text().toStdString(); - pressure->_loadcase.push_back(loadcase); + set_common(*pressure); pressure->_value = m_Pressure->inValue->text().toStdString(); pressure->_preMeshType = m_Pressure->inType->currentText().toStdString(); tempData.push_back(pressure); + break; } - else if (loadType == tr("瞬态载荷")) - { - - } - else if (loadType == tr("频域载荷")) - { - - } - else if (loadType == tr("线载荷")) - { - - } - else if (loadType == tr("预紧力")) - { - - } - else if (loadType == tr("热流密度")) - { - - } - else if (loadType == tr("对流换热载荷")) - { - - } - else if (loadType == tr("热辐射载荷")) - { - - } - else if (loadType == tr("温度载荷")) - { - - } - else if (loadType == tr("内部热源")) - { - - } - else if (loadType == tr("电荷")) - { - - } - else if (loadType == tr("电荷密度")) - { - - } - else if (loadType == tr("离心力")) - { - } Load->setAllLoad(tempData); @@ -418,7 +320,7 @@ namespace MLoadBCUi { int row_count = m_loadMatchList.m_matchList->rowCount(); m_loadMatchList.m_matchList->insertRow(row_count); - QString name = (tempData[i]->_loadBCName.c_str()); + QString name = (tempData[i]->name().c_str()); m_loadMatchList.m_matchList->setItem(row_count, 0, new QTableWidgetItem(name)); QString type = (tempData[i]->getLoadBCTypeStr().c_str()); m_loadMatchList.m_matchList->setItem(row_count, 1, new QTableWidgetItem(type)); diff --git a/src/MxSimPre/DataPropertyUi/Mx_PrepostProcessUi.cpp b/src/MxSimPre/DataPropertyUi/Mx_PrepostProcessUi.cpp index e3ca9f07..d21d2111 100644 --- a/src/MxSimPre/DataPropertyUi/Mx_PrepostProcessUi.cpp +++ b/src/MxSimPre/DataPropertyUi/Mx_PrepostProcessUi.cpp @@ -1,5 +1,6 @@ #include "Mx_PrepostProcessUi.h" #include "Forms/ui_Mx_PrepostProcessUi.h" +#include "MBasicFunction/mLoadBCEnum.h" #include using namespace std::chrono; @@ -677,10 +678,9 @@ void mPrepostProcessUi::AssignLoadData(DataField& field) if (loadType == tr("集中力")) { mForce* force = new mForce(); - force->_loadBCName = m_Load->m_newLoad.edit->text().toStdString(); - force->_loadBCType = LoadBCType::LBCForce; + force->setName(m_Load->m_newLoad.edit->text().toStdString()); std::string loadcase = case_seclected.at(0)->text().toStdString(); - force->_loadcase.push_back(loadcase); + force->appendLoadCase(loadcase); m_Load->m_Force->LoadData(*force); field.appendLoadBCData(force); emit fieldChanged(); @@ -688,9 +688,9 @@ void mPrepostProcessUi::AssignLoadData(DataField& field) else if (loadType == tr("重力")) { mGravity* force = new mGravity(); - force->_loadBCName = m_Load->m_newLoad.edit->text().toStdString(); + force->setName(m_Load->m_newLoad.edit->text().toStdString()); std::string loadcase = m_Load->m_caseList.m_caseList->currentItem()->text().toStdString(); - force->_loadcase.push_back(loadcase); + force->appendLoadCase(loadcase); m_Load->m_Gravity->LoadData(*force); field.appendLoadBCData(force); emit fieldChanged(); @@ -698,10 +698,9 @@ void mPrepostProcessUi::AssignLoadData(DataField& field) else if (loadType == tr("压强")) { mPressure* pressure = new mPressure(); - pressure->_loadBCName = m_Load->m_newLoad.edit->text().toStdString(); - pressure->_loadBCType = LoadBCType::LBCPressure; + pressure->setName(m_Load->m_newLoad.edit->text().toStdString()); std::string loadcase = m_Load->m_caseList.m_caseList->currentItem()->text().toStdString(); - pressure->_loadcase.push_back(loadcase); + pressure->appendLoadCase(loadcase); m_Load->m_Pressure->LoadData(*pressure); field.appendLoadBCData(pressure); emit fieldChanged(); @@ -735,21 +734,21 @@ void mPrepostProcessUi::AssignBCData(DataField& field) QString loadType = m_BC->m_BCTypeList.m_typeList->currentText(); if (loadType == tr("固定/对称/反对称")) { - mFixed* fixed = new mFixed(); - fixed->_loadBCName = m_BC->m_newBC.edit->text().toStdString(); + mFixed* fixed = m_BC->m_Fixed->BCData(); + fixed->setName(m_BC->m_newBC.edit->text().toStdString()); std::string loadcase = m_BC->m_BCCaseList.m_caseList->currentItem()->text().toStdString(); - fixed->_loadcase.push_back(loadcase); - m_BC->m_Fixed->BCData(*fixed); + fixed->appendLoadCase(loadcase); + field.appendLoadBCData(fixed); emit fieldChanged(); } else if (loadType == tr("位移/转角")) { mDis* dis = new mDis(); - dis->_loadBCType = LoadBCType::LBCDisplacement; - dis->_loadBCName = m_BC->m_newBC.edit->text().toStdString(); + dis->setLoadBCType(LoadBCType::LBCDisplacement); + dis->setName(m_BC->m_newBC.edit->text().toStdString()); std::string loadcase = m_BC->m_BCCaseList.m_caseList->currentItem()->text().toStdString(); - dis->_loadcase.push_back(loadcase); + dis->appendLoadCase(loadcase); m_BC->m_Dis->BCData(*dis); field.appendLoadBCData(dis); emit fieldChanged(); @@ -1798,7 +1797,7 @@ void mPrepostProcessUi::showLoadTips(int row, int column, DataField dataField) std::string Name = nameItem->text().toStdString(); mLoadBCBase* data = dataField.getLoadBCData(Name); - std::vector caseName = data->_loadcase; + std::vector caseName = data->loadCases(); std::string Type = typeItem->text().toStdString(); if (Type == "集中力") { mForce* load = dynamic_cast(data); @@ -1814,8 +1813,8 @@ void mPrepostProcessUi::showLoadTips(int row, int column, DataField dataField) } m_ParaList->setItem(0, 1, new QTableWidgetItem((Name.c_str()))); m_ParaList->setItem(1, 1, new QTableWidgetItem((Type.c_str()))); - if(!load->_loadcase.empty()) - m_ParaList->setItem(2, 1, new QTableWidgetItem((load->_loadcase[0].c_str()))); + if(!load->loadCases().empty()) + m_ParaList->setItem(2, 1, new QTableWidgetItem((load->loadCases()[0].c_str()))); QString N, F1, F2, F3, C, Coor; QStringList valueList; valueList << N << F1 << F2 << F3 << C << Coor; @@ -1853,8 +1852,8 @@ void mPrepostProcessUi::showLoadTips(int row, int column, DataField dataField) } m_ParaList->setItem(0, 1, new QTableWidgetItem((Name.c_str()))); m_ParaList->setItem(1, 1, new QTableWidgetItem((Type.c_str()))); - if (!load->_loadcase.empty()) - m_ParaList->setItem(2, 1, new QTableWidgetItem((load->_loadcase[0].c_str()))); + if (!load->loadCases().empty()) + m_ParaList->setItem(2, 1, new QTableWidgetItem((load->loadCases()[0].c_str()))); QString X, Y, Z, C, Coor; QStringList valueList; valueList << X << Y << Z << C << Coor; @@ -1883,8 +1882,8 @@ void mPrepostProcessUi::showLoadTips(int row, int column, DataField dataField) } m_ParaList->setItem(0, 1, new QTableWidgetItem((Name.c_str()))); m_ParaList->setItem(1, 1, new QTableWidgetItem((Type.c_str()))); - if (!load->_loadcase.empty()) - m_ParaList->setItem(2, 1, new QTableWidgetItem((load->_loadcase[0].c_str()))); + if (!load->loadCases().empty()) + m_ParaList->setItem(2, 1, new QTableWidgetItem((load->loadCases()[0].c_str()))); QString value, C; QStringList valueList; valueList << value << C; @@ -1926,8 +1925,8 @@ void mPrepostProcessUi::updateLoadData(int row, int column, DataField& dataField mForce* oldLoad = dynamic_cast(oldBase); std::string oldSetName = oldLoad->_setName; mForce* newLoad = new mForce(); - newLoad->_loadBCName = name; - newLoad->_loadcase.push_back(caseName); + newLoad->setName(name); + newLoad->appendLoadCase(caseName); m_Load->m_Force->LoadData(*newLoad); dataField.deleteSetData(oldSetName); dataField.m_UpdateLoadBCName = name; @@ -1939,8 +1938,8 @@ void mPrepostProcessUi::updateLoadData(int row, int column, DataField& dataField mGravity* oldLoad = dynamic_cast(oldBase); std::string oldSetName = oldLoad->_setName; mGravity* newLoad = new mGravity(); - newLoad->_loadBCName = name; - newLoad->_loadcase.push_back(caseName); + newLoad->setName(name); + newLoad->appendLoadCase(caseName); m_Load->m_Gravity->LoadData(*newLoad); dataField.deleteSetData(oldSetName); dataField.m_UpdateLoadBCName = name; @@ -1952,8 +1951,8 @@ void mPrepostProcessUi::updateLoadData(int row, int column, DataField& dataField mPressure* oldLoad = dynamic_cast(oldBase); std::string oldSetName = oldLoad->_setName; mPressure* newLoad = new mPressure(); - newLoad->_loadBCName = name; - newLoad->_loadcase.push_back(caseName); + newLoad->setName(name); + newLoad->appendLoadCase(caseName); m_Load->m_Pressure->LoadData(*newLoad); dataField.deleteSetData(oldSetName); dataField.m_UpdateLoadBCName = name; @@ -2032,7 +2031,7 @@ void mPrepostProcessUi::showBCTips(int row, int column, DataField dataField) std::string Name = nameItem->text().toStdString(); mLoadBCBase* data = dataField.getLoadBCData(Name); - std::vector caseName = data->_loadcase; + std::vector caseName = data->loadCases(); std::string Type = typeItem->text().toStdString(); if (Type == "固定/对称/反对称") { mFixed* BC = dynamic_cast(data); @@ -2047,8 +2046,8 @@ void mPrepostProcessUi::showBCTips(int row, int column, DataField dataField) } m_ParaList->setItem(0, 1, new QTableWidgetItem((Name.c_str()))); m_ParaList->setItem(1, 1, new QTableWidgetItem((Type.c_str()))); - if (!BC->_loadcase.empty()) - m_ParaList->setItem(2, 1, new QTableWidgetItem((BC->_loadcase[0].c_str()))); + if (!BC->loadCases().empty()) + m_ParaList->setItem(2, 1, new QTableWidgetItem((BC->loadCases()[0].c_str()))); QString N, Ty; QStringList valueList; valueList << N << Ty; @@ -2083,8 +2082,8 @@ void mPrepostProcessUi::showBCTips(int row, int column, DataField dataField) } m_ParaList->setItem(0, 1, new QTableWidgetItem((Name.c_str()))); m_ParaList->setItem(1, 1, new QTableWidgetItem((Type.c_str()))); - if (!BC->_loadcase.empty()) - m_ParaList->setItem(2, 1, new QTableWidgetItem((BC->_loadcase[0].c_str()))); + if (!BC->loadCases().empty()) + m_ParaList->setItem(2, 1, new QTableWidgetItem((BC->loadCases()[0].c_str()))); QString N, U1, U2, U3, UR1, UR2, UR3, C; QStringList valueList; valueList << N << U1 << U2 << U3 << UR1 << UR2 << UR3 << C; @@ -2138,10 +2137,9 @@ void mPrepostProcessUi::updateBCData(int row, int column, DataField& dataField) if (type == "固定/对称/反对称") { mFixed* oldBC = dynamic_cast(oldBase); std::string oldSetName = oldBC->_setName; - mFixed* newBC = new mFixed(); - newBC->_loadBCName = name; - newBC->_loadcase.push_back(caseName); - m_BC->m_Fixed->BCData(*newBC); + mFixed* newBC = m_BC->m_Fixed->BCData(); + newBC->setName(name); + newBC->appendLoadCase(caseName); dataField.deleteSetData(oldSetName); dataField.m_UpdateLoadBCName = name; dataField.replaceLoadBCData(newBC); @@ -2152,8 +2150,8 @@ void mPrepostProcessUi::updateBCData(int row, int column, DataField& dataField) mDis* oldBC = dynamic_cast(oldBase); std::string oldSetName = oldBC->_setName; mDis* newBC = new mDis(); - newBC->_loadBCName = name; - newBC->_loadcase.push_back(caseName); + newBC->setName(name); + newBC->appendLoadCase(caseName); m_BC->m_Dis->BCData(*newBC); dataField.deleteSetData(oldSetName); dataField.m_UpdateLoadBCName = name; diff --git a/src/MxSimPre/MBasicFunction/mLoadBCEnum.h b/src/MxSimPre/MBasicFunction/mLoadBCEnum.h index 15c46c04..32dc4fe5 100644 --- a/src/MxSimPre/MBasicFunction/mLoadBCEnum.h +++ b/src/MxSimPre/MBasicFunction/mLoadBCEnum.h @@ -175,5 +175,7 @@ namespace MDataLoadBC LBCInitStress, LBCInitVelocity, + + LBCUnknown, }; } \ No newline at end of file diff --git a/src/MxSimPre/MDataLoadBC/mDis.cpp b/src/MxSimPre/MDataLoadBC/mDis.cpp index dca7e7c8..34fd5bed 100644 --- a/src/MxSimPre/MDataLoadBC/mDis.cpp +++ b/src/MxSimPre/MDataLoadBC/mDis.cpp @@ -3,9 +3,8 @@ namespace MDataLoadBC { - mDis::mDis() :mLoadBCBase() + mDis::mDis() :mLoadBCBase("", LoadBCType::LBCDisplacement) { - this->setLoadBCType(LBCDisplacement); u1 = "0"; u2 = "0"; u3 = "0"; @@ -13,14 +12,9 @@ namespace MDataLoadBC ur2 = "0"; ur3 = "0"; } - mDis::mDis(const std::string& name) : mLoadBCBase(name, LBCDisplacement) + mDis::mDis(const std::string& name) : mDis() { - u1 = "0"; - u2 = "0"; - u3 = "0"; - ur1 = "0"; - ur2 = "0"; - ur3 = "0"; + setName(name); } void mDis::getParameterList(mDataList* dl) diff --git a/src/MxSimPre/MDataLoadBC/mDistrForce.cpp b/src/MxSimPre/MDataLoadBC/mDistrForce.cpp index 05ddffd1..f9260b4a 100644 --- a/src/MxSimPre/MDataLoadBC/mDistrForce.cpp +++ b/src/MxSimPre/MDataLoadBC/mDistrForce.cpp @@ -3,8 +3,7 @@ namespace MDataLoadBC { - mDistrForce::mDistrForce() :mLoadBCBase() { - this->setLoadBCType(LBCDistributed); + mDistrForce::mDistrForce() :mLoadBCBase("", LoadBCType::LBCDistributed) { } mDistrForce::mDistrForce(const std::string& name) : mLoadBCBase(name, LBCDistributed) { diff --git a/src/MxSimPre/MDataLoadBC/mDomainLoad.cpp b/src/MxSimPre/MDataLoadBC/mDomainLoad.cpp index 7707b81c..990fc367 100644 --- a/src/MxSimPre/MDataLoadBC/mDomainLoad.cpp +++ b/src/MxSimPre/MDataLoadBC/mDomainLoad.cpp @@ -3,20 +3,16 @@ namespace MDataLoadBC { - mDomainLoad::mDomainLoad() + mDomainLoad::mDomainLoad() : mLoadBCBase("", LoadBCType::LBCDomain) { - this->setLoadBCType(LBCDomain); - _rloadType == "力"; _delay = 0.0; _phaseAngle = 0.0; } - mDomainLoad::mDomainLoad(const std::string& name) :mLoadBCBase(name, LBCDomain) + mDomainLoad::mDomainLoad(const std::string& name) : mDomainLoad() { - _rloadType == "力"; - _delay = 0.0; - _phaseAngle = 0.0; + setName(name); } mDomainLoad::~mDomainLoad() diff --git a/src/MxSimPre/MDataLoadBC/mFixed.cpp b/src/MxSimPre/MDataLoadBC/mFixed.cpp index 24f5c4de..6111c9f2 100644 --- a/src/MxSimPre/MDataLoadBC/mFixed.cpp +++ b/src/MxSimPre/MDataLoadBC/mFixed.cpp @@ -3,15 +3,12 @@ namespace MDataLoadBC { - mFixed::mFixed() : mLoadBCBase() + mFixed::mFixed() : mLoadBCBase("", LBCDFixed) { - this->setLoadBCType(LBCDFixed); - _type = std::string("完全固定(U1=U2=U3=UR1=UR2=UR3=0)"); } - mFixed::mFixed(const std::string& name) : mLoadBCBase(name, LBCDFixed) - { + mFixed::mFixed(const std::string& name, LoadBCType type): mLoadBCBase(name, type) { _type = std::string("完全固定(U1=U2=U3=UR1=UR2=UR3=0)"); } mFixed::~mFixed() {} diff --git a/src/MxSimPre/MDataLoadBC/mFixed.h b/src/MxSimPre/MDataLoadBC/mFixed.h index 14449abf..c4e3a1d2 100644 --- a/src/MxSimPre/MDataLoadBC/mFixed.h +++ b/src/MxSimPre/MDataLoadBC/mFixed.h @@ -12,12 +12,10 @@ namespace MDataLoadBC class mFixed : public mLoadBCBase { public: - //默认构造 mFixed(); - //有参构造 mFixed(const std::string& name); - //析构函数 - ~mFixed(); + mFixed(const std::string& name, LoadBCType); + virtual ~mFixed(); /* * 重写基类函数 diff --git a/src/MxSimPre/MDataLoadBC/mForce.cpp b/src/MxSimPre/MDataLoadBC/mForce.cpp index f5e5c5dc..d9a5295d 100644 --- a/src/MxSimPre/MDataLoadBC/mForce.cpp +++ b/src/MxSimPre/MDataLoadBC/mForce.cpp @@ -4,21 +4,16 @@ namespace MDataLoadBC { - mForce::mForce() :mLoadBCBase() { - this->setLoadBCType(LBCForce); - - u1 = std::string("0"); - u2 = std::string("0"); - u3 = std::string("0"); + mForce::mForce() :mLoadBCBase("", LoadBCType::LBCForce), u1("0"), u2("0"), u3("0") { _datumName = std::string("全局"); } - mForce::mForce(const std::string& name) : mLoadBCBase(name, LBCForce) { - u1 = std::string("0"); - u2 = std::string("0"); - u3 = std::string("0"); + mForce::mForce(const std::string& name) : mForce() { + setName(name); _datumName = std::string("全局"); } + mForce::~mForce() {} + void mForce::getParameterList(mDataList* dl) { if (dl != nullptr) diff --git a/src/MxSimPre/MDataLoadBC/mForce.h b/src/MxSimPre/MDataLoadBC/mForce.h index 763f944b..c5039850 100644 --- a/src/MxSimPre/MDataLoadBC/mForce.h +++ b/src/MxSimPre/MDataLoadBC/mForce.h @@ -15,7 +15,8 @@ namespace MDataLoadBC //默认构造 mForce(); //有参构造 - mForce(const std::string&name); + mForce(const std::string&name); + virtual ~mForce(); /* * 重写基类函数 diff --git a/src/MxSimPre/MDataLoadBC/mGravity.cpp b/src/MxSimPre/MDataLoadBC/mGravity.cpp index 81b8d8d6..e8485d89 100644 --- a/src/MxSimPre/MDataLoadBC/mGravity.cpp +++ b/src/MxSimPre/MDataLoadBC/mGravity.cpp @@ -3,20 +3,11 @@ namespace MDataLoadBC { - mGravity::mGravity() :mLoadBCBase() { - this->setLoadBCType(LBCGravity); - - //初始化 - _u1 = "0.0"; - _u2 = "0.0"; - _u3 = "0.0"; + mGravity::mGravity() :mLoadBCBase("", LoadBCType::LBCGravity), _u1("0.0"), _u2("0.0"), _u3("0.0") { _datumName = "全局"; } - mGravity::mGravity(const std::string& name) : mLoadBCBase(name, LBCGravity) { - //初始化 - _u1 = "0.0"; - _u2 = "0.0"; - _u3 = "0.0"; + mGravity::mGravity(const std::string& name) : mGravity() { + setName(name); _datumName = "全局"; } diff --git a/src/MxSimPre/MDataLoadBC/mInitBoundary.cpp b/src/MxSimPre/MDataLoadBC/mInitBoundary.cpp index 99387c81..3941c2ba 100644 --- a/src/MxSimPre/MDataLoadBC/mInitBoundary.cpp +++ b/src/MxSimPre/MDataLoadBC/mInitBoundary.cpp @@ -3,9 +3,8 @@ namespace MDataLoadBC { - mInitBoundary::mInitBoundary() + mInitBoundary::mInitBoundary():mLoadBCBase("", LoadBCType::LBCInitBoundary) { - this->setLoadBCType(LBCInitBoundary); _type = "位移"; _bu1 = false; @@ -23,23 +22,9 @@ namespace MDataLoadBC _ur3val = 0; } - mInitBoundary::mInitBoundary(const std::string& name) :mLoadBCBase(name, LBCInitBoundary) + mInitBoundary::mInitBoundary(const std::string& name) : mInitBoundary() { - _type = "位移"; - - _bu1 = false; - _bu2 = false; - _bu3 = false; - _bur1 = false; - _bur2 = false; - _bur3 = false; - - _u1val = 0; - _u2val = 0; - _u3val = 0; - _ur1val = 0; - _ur2val = 0; - _ur3val = 0; + setName(name); } mInitBoundary::~mInitBoundary() diff --git a/src/MxSimPre/MDataLoadBC/mLineLoad.cpp b/src/MxSimPre/MDataLoadBC/mLineLoad.cpp index 7016b795..373c64fc 100644 --- a/src/MxSimPre/MDataLoadBC/mLineLoad.cpp +++ b/src/MxSimPre/MDataLoadBC/mLineLoad.cpp @@ -4,10 +4,8 @@ namespace MDataLoadBC { - mLineLoad::mLineLoad() + mLineLoad::mLineLoad() : mLoadBCBase("", LoadBCType::LBCLineLoad) { - this->setLoadBCType(LBCLineLoad); - _loadValue = 0.0; _direction.x = 1; _direction.y = 1; @@ -15,12 +13,9 @@ namespace MDataLoadBC _lineMeshType = "二维三维网格边线"; } - mLineLoad::mLineLoad(const std::string& name) :mLoadBCBase(name, LBCLineLoad) + mLineLoad::mLineLoad(const std::string& name) : mLineLoad() { - _loadValue = 0.0; - _direction.x = 1; - _direction.y = 1; - _direction.z = 1; + setName(name); } mLineLoad::~mLineLoad() diff --git a/src/MxSimPre/MDataLoadBC/mLoadBCBase.cpp b/src/MxSimPre/MDataLoadBC/mLoadBCBase.cpp index bd0cfa32..c05a1bd1 100644 --- a/src/MxSimPre/MDataLoadBC/mLoadBCBase.cpp +++ b/src/MxSimPre/MDataLoadBC/mLoadBCBase.cpp @@ -3,48 +3,66 @@ //MBasicData #include "MBasicFunction/mDataList.h" + +namespace MDataLoadBC { + // old api + void mLoadBCBase::setLoadBCName(const std::string& name) { + m_name = name; + } + std::string mLoadBCBase::getLoadBCName() { + return m_name; + } + LoadBCType mLoadBCBase::getLoadBCType() { + return m_type; + } + void mLoadBCBase::setLoadBCType(LoadBCType type) { + m_type = type; + } + void mLoadBCBase::setLoadBCVisible(bool visible) {} + bool mLoadBCBase::getLoadBCVisible() { + return m_visible; + } +} + namespace MDataLoadBC { - mLoadBCBase::mLoadBCBase() - { - //初始化 - _loadBCVisible = true; - } + mLoadBCBase::mLoadBCBase():m_type(LoadBCType::LBCUnknown),m_visible(true) {} mLoadBCBase::mLoadBCBase(const std::string& name, LoadBCType type) - :_loadBCName(name), _loadBCType(type) - { - //初始化 - _loadBCVisible = true; - } + :m_name(name), m_type(type), m_visible(true) {} mLoadBCBase::~mLoadBCBase() { } - void mLoadBCBase::setLoadBCName(const std::string& name) + void mLoadBCBase::setName(const std::string& name) { - _loadBCName = name; + m_name = name; } - std::string mLoadBCBase::getLoadBCName() + const std::string& mLoadBCBase::name() const { - return _loadBCName; + return m_name; } - void mLoadBCBase::setLoadBCType(LoadBCType type) + LoadBCType mLoadBCBase::type() const { - _loadBCType = type; + return m_type; } - LoadBCType mLoadBCBase::getLoadBCType() - { - return _loadBCType; + const std::vector& mLoadBCBase::loadCases() const { + return m_loadcase; + } + void mLoadBCBase::appendLoadCase(const std::string& name) { + m_loadcase.push_back(name); + } + void mLoadBCBase::setLoadCase(const std::vector& cases) { + m_loadcase = cases; } std::string mLoadBCBase::getLoadBCTypeStr() { - switch (_loadBCType) + switch (m_type) { case MDataLoadBC::LBCForce: return std::string("集中力"); @@ -173,17 +191,21 @@ namespace MDataLoadBC } } - void mLoadBCBase::setLoadBCVisible(bool visible) + void mLoadBCBase::setVisible(bool visible) { - _loadBCVisible = visible; + m_visible = visible; } - bool mLoadBCBase::getLoadBCVisible() + bool mLoadBCBase::visible() const { - return _loadBCVisible; + return m_visible; } - LoadData::LoadData() + LoadData::LoadData() : m_load_types({ + LoadBCType::LBCForce, + LoadBCType::LBCPressure, + LoadBCType::LBCGravity, + }) { all_Load_Type.push_back("集中力"); //all_Load_Type.push_back("力矩"); diff --git a/src/MxSimPre/MDataLoadBC/mLoadBCBase.h b/src/MxSimPre/MDataLoadBC/mLoadBCBase.h index 95db5188..5398da55 100644 --- a/src/MxSimPre/MDataLoadBC/mLoadBCBase.h +++ b/src/MxSimPre/MDataLoadBC/mLoadBCBase.h @@ -4,8 +4,10 @@ //#include "mdataloadbc_global.h" #include "MBasicFunction/mLoadBCEnum.h" +#include "Array/Array.h" #include #include +#include namespace MBasicData { @@ -17,76 +19,42 @@ namespace MDataLoadBC class mLoadBCBase { public: - /* - * 默认构造函数 - */ mLoadBCBase(); - - /* - * 重载构造函数 - */ mLoadBCBase(const std::string& name, LoadBCType type); + virtual ~mLoadBCBase(); - /* - * 析构函数 - */ - ~mLoadBCBase(); - - /* - * 设置载荷边界名 - */ + // old api void setLoadBCName(const std::string& name); - - /* - * 获取载荷边界名 - */ std::string getLoadBCName(); - - /* - * 设置载荷边界类型 - */ void setLoadBCType(LoadBCType type); - - /* - * 获取载荷边界类型 - */ LoadBCType getLoadBCType(); - - /* - * 获取载荷边界类型字符串 - */ std::string getLoadBCTypeStr(); - - /* - * 设置载荷边界可见性 - */ void setLoadBCVisible(bool visible); - - /* - * 获取载荷边界可见性 - */ bool getLoadBCVisible(); - - /* - * 获取参数列表 - */ virtual void getParameterList(mDataList* dl) {} - public: - //载荷边界名 - std::string _loadBCName; + // new api + const std::string& name() const; + void setName(const std::string& name); - //载荷边界类型 - LoadBCType _loadBCType; + LoadBCType type() const; - //可见性 - bool _loadBCVisible; + bool visible() const; + void setVisible(bool visible); - //载荷工况 - std::vector _loadcase; + void appendLoadCase(const std::string&); + const std::vector& loadCases() const; + void setLoadCase(const std::vector&); + + private: + std::string m_name; + LoadBCType m_type; // should be const after removing old api + bool m_visible; + + std::vector m_loadcase; //计算域名字 - std::string _computedname; + std::string m_computed_name; }; class LoadData @@ -100,6 +68,7 @@ namespace MDataLoadBC void setAllLoad(std::vector vec) { all_Load = vec; } std::vector getAllLoadType() { return all_Load_Type; } + std::vector getLoadTypes() { return m_load_types; } void setAllCase(std::vector cas) { all_Case = cas; } std::vector getAllCase() { return all_Case; } @@ -109,6 +78,7 @@ namespace MDataLoadBC private: std::vector all_Load; std::vector all_Load_Type; + std::vector m_load_types; bool _is_Assign {false}; std::vector all_Case; }; @@ -136,6 +106,11 @@ namespace MDataLoadBC bool _is_Assign {false}; std::vector all_Case; }; + + struct LoadWithSet { + std::shared_ptr load; + std::vector index_set; + }; } #define DEF_MXLOAD(name,desc) \ diff --git a/src/MxSimPre/MDataLoadBC/mPressure.cpp b/src/MxSimPre/MDataLoadBC/mPressure.cpp index c05c5334..d0042a2f 100644 --- a/src/MxSimPre/MDataLoadBC/mPressure.cpp +++ b/src/MxSimPre/MDataLoadBC/mPressure.cpp @@ -4,9 +4,8 @@ namespace MDataLoadBC { - mPressure::mPressure() + mPressure::mPressure() : mLoadBCBase("", LoadBCType::LBCPressure) { - this->setLoadBCType(LBCPressure); //初始化 _value = std::string("0"); _preMeshType = "三维网格表面"; @@ -15,9 +14,8 @@ namespace MDataLoadBC mPressure::mPressure(const std::string& name) :mLoadBCBase(name, LBCPressure) { //初始化 - _value = std::string("0"); first_value = std::string("0"); - _preMeshType = "三维网格表面"; + setName(name); } mPressure::~mPressure() diff --git a/src/MxSimPre/MDataLoadBC/mPretensionLoad.cpp b/src/MxSimPre/MDataLoadBC/mPretensionLoad.cpp index b7f27e8b..47e413b7 100644 --- a/src/MxSimPre/MDataLoadBC/mPretensionLoad.cpp +++ b/src/MxSimPre/MDataLoadBC/mPretensionLoad.cpp @@ -3,9 +3,8 @@ namespace MDataLoadBC { - mPretensionLoad::mPretensionLoad() + mPretensionLoad::mPretensionLoad() : mLoadBCBase("", LoadBCType::LBCPreload) { - this->setLoadBCType(LBCPreload); _dimType = "3D螺栓预紧"; _preType = "力"; _preValue = 0; @@ -16,15 +15,9 @@ namespace MDataLoadBC _pickType = false; } - mPretensionLoad::mPretensionLoad(const std::string& name) :mLoadBCBase(name, LBCPreload) + mPretensionLoad::mPretensionLoad(const std::string& name) :mPretensionLoad() { - _dimType = "3D螺栓预紧"; - _preType = "力"; - _preValue = 0; - _hasPreVector = false; - _preVector.x = 0; - _preVector.y = 0; - _preVector.z = 0; + setName(name); } mPretensionLoad::~mPretensionLoad() diff --git a/src/MxSimPre/MDataLoadBC/mSuportBC.cpp b/src/MxSimPre/MDataLoadBC/mSuportBC.cpp index 6a482f79..4f39f73c 100644 --- a/src/MxSimPre/MDataLoadBC/mSuportBC.cpp +++ b/src/MxSimPre/MDataLoadBC/mSuportBC.cpp @@ -3,10 +3,8 @@ namespace MDataLoadBC { - mSuportBC::mSuportBC() + mSuportBC::mSuportBC() : mLoadBCBase("", LoadBCType::LBCSuport) { - this->setLoadBCType(LBCSuport); - _u1 = true; _u2 = true; _u3 = true; @@ -15,14 +13,9 @@ namespace MDataLoadBC _ur3 = true; } - mSuportBC::mSuportBC(const std::string& name) :mLoadBCBase(name, LBCSuport) + mSuportBC::mSuportBC(const std::string& name) : mSuportBC() { - _u1 = true; - _u2 = true; - _u3 = true; - _ur1 = true; - _ur2 = true; - _ur3 = true; + setName(name); } mSuportBC::~mSuportBC() diff --git a/src/MxSimPre/MDataLoadBC/mTransientLoad.cpp b/src/MxSimPre/MDataLoadBC/mTransientLoad.cpp index e124ed73..ce45a307 100644 --- a/src/MxSimPre/MDataLoadBC/mTransientLoad.cpp +++ b/src/MxSimPre/MDataLoadBC/mTransientLoad.cpp @@ -3,18 +3,15 @@ namespace MDataLoadBC { - mTransientLoad::mTransientLoad() + mTransientLoad::mTransientLoad() : mLoadBCBase("", LoadBCType::LBCTransient) { - this->setLoadBCType(LBCTransient); - _tloadType = "力"; _delay = 0.0; } - mTransientLoad::mTransientLoad(const std::string& name) :mLoadBCBase(name, LBCTransient) + mTransientLoad::mTransientLoad(const std::string& name) :mTransientLoad() { - _tloadType = "力"; - _delay = 0.0; + setName(name); } mTransientLoad::~mTransientLoad() diff --git a/src/MxSimPre/MxDataField/DataField.cpp b/src/MxSimPre/MxDataField/DataField.cpp index ab4f7291..9819f7c2 100644 --- a/src/MxSimPre/MxDataField/DataField.cpp +++ b/src/MxSimPre/MxDataField/DataField.cpp @@ -664,14 +664,14 @@ namespace MxDataField mLoadBCBase* tepLB = _loadBCData.at(i); if (tepLB != nullptr) { - LoadBCType type = tepLB->getLoadBCType(); + LoadBCType type = tepLB->type(); if (type == LBCDFixed || type == LBCDSymmetry || type == LBCDisplacement || type == LBCVelocity || type == LBCAcceleration || type == LBCSuport || type == LBCInitBoundary || type == LBCTempBoundary || type == LBCMagnetic || type == LBCPotential || type == EXLBCDisplacement || type == EXLBCVelocity || type == EXLBCAcceleration || type == EXLBCInitBoundary || type == LBCPiezoelectricPotential) { - names.push_back(tepLB->getLoadBCName()); + names.push_back(tepLB->name()); } } } @@ -697,14 +697,14 @@ namespace MxDataField { return; } - std::string lName = lbdata->getLoadBCName(); + std::string lName = lbdata->name(); const int nlbc = _loadBCData.size(); for (int i = 0; i < nlbc; ++i) { mLoadBCBase* tepLBC = _loadBCData.at(i); if (tepLBC != nullptr) { - std::string name = tepLBC->getLoadBCName(); + std::string name = tepLBC->name(); if (name == lName) { _loadBCData[i] = lbdata; @@ -718,7 +718,7 @@ namespace MxDataField { if (!lbData) return; _loadBCData.push_back(lbData); - Log::sendMessage(Log::Info, lbData->_loadBCName + "载荷创建成功!"); + Log::sendMessage(Log::Info, lbData->name() + "载荷创建成功!"); } int DataField::getLoadBCDataCount() @@ -764,7 +764,7 @@ namespace MxDataField mLoadBCBase* tepLB = _loadBCData.at(i); if (tepLB != nullptr) { - LoadBCType type = tepLB->getLoadBCType(); + LoadBCType type = tepLB->type(); if (type == LBCForce || type == LBCMoment || type == LBCGravity || type == LBCBodyForce || type == LBCDistributed || type == LBCPressure || type == LBCTransient || type == LBCDomain || type == LBCLineLoad || type == LBCPreload @@ -778,7 +778,7 @@ namespace MxDataField || type == EXLBCInitFryingPoint || type == EXLBCInitStress || type == EXLBCInitStrain || type == EXLBCSPHInitStress || type == EXLBCInitVelocity) { - names.push_back(tepLB->getLoadBCName()); + names.push_back(tepLB->name()); } } } @@ -837,7 +837,7 @@ namespace MxDataField { continue; } - LoadBCType type = load_bc_base->getLoadBCType(); + LoadBCType type = load_bc_base->type(); if (type == LBCForce || type == LBCMoment || type == LBCGravity || type == LBCBodyForce || type == LBCDistributed || type == LBCPressure || type == LBCLineLoad || type == LBCHeatFlux || type == LBCHeatTransfer || type == LBCHeatRadiation || type == LBCCentrifugal || @@ -879,7 +879,7 @@ namespace MxDataField { continue; } - if (load_bc_base->getLoadBCType() == LBCPreload) + if (load_bc_base->type() == LBCPreload) { res.push_back(loadName); } @@ -910,7 +910,7 @@ namespace MxDataField { continue; } - LoadBCType type = load_bc_base->getLoadBCType(); + LoadBCType type = load_bc_base->type(); if (type == LBCDFixed || type == LBCDSymmetry || type == LBCDisplacement || type == LBCVelocity || type == LBCAcceleration || type == LBCMagnetic || type == LBCTempBoundary || type == LBCPotential || @@ -945,7 +945,7 @@ namespace MxDataField { continue; } - if (load_bc_base->getLoadBCType() == LBCSuport) + if (load_bc_base->type() == LBCSuport) { res.push_back(bcName); } @@ -1239,7 +1239,7 @@ namespace MxDataField mLoadBCBase* tepLB = _loadBCData.at(i); if (tepLB != nullptr) { - std::string lbName = tepLB->getLoadBCName(); + std::string lbName = tepLB->name(); if (lbName == name) { return tepLB; diff --git a/src/MxSimPre/PreprocessNode/BC.cpp b/src/MxSimPre/PreprocessNode/BC.cpp index c8433227..3dd2f9e2 100644 --- a/src/MxSimPre/PreprocessNode/BC.cpp +++ b/src/MxSimPre/PreprocessNode/BC.cpp @@ -470,7 +470,7 @@ namespace dyno int n = bc_in.size(); MDataLoadBC::mLoadBCBase* bc_data = bc_in[n - 1]; - auto load_type = bc_data->getLoadBCType(); + auto load_type = bc_data->type(); switch (load_type) { @@ -495,10 +495,9 @@ namespace dyno MDataLoadBC::mFixed* fix_bc = dynamic_cast(force); - for (int i = 0; i < force->_loadcase.size(); i++) - { - MDataCase::mCaseBase* select_case = field->getCaseData(force->_loadcase[i]); - select_case->appendCaseBCName(force->_loadBCName); + for (auto& el : force->loadCases()) { + MDataCase::mCaseBase* select_case = field->getCaseData(el); + select_case->appendCaseBCName(force->name()); } //编号数组 @@ -524,10 +523,9 @@ namespace dyno MDataLoadBC::mDis* dis_bc = dynamic_cast(dis); - for (int i = 0; i < dis->_loadcase.size(); i++) - { - MDataCase::mCaseBase* select_case = field->getCaseData(dis->_loadcase[i]); - select_case->appendCaseBCName(dis->_loadBCName); + for (auto& el : dis->loadCases()) { + MDataCase::mCaseBase* select_case = field->getCaseData(el); + select_case->appendCaseBCName(dis->name()); } //编号数组 diff --git a/src/MxSimPre/PreprocessNode/Load.cpp b/src/MxSimPre/PreprocessNode/Load.cpp index 7d480b53..757d4534 100644 --- a/src/MxSimPre/PreprocessNode/Load.cpp +++ b/src/MxSimPre/PreprocessNode/Load.cpp @@ -22,6 +22,13 @@ #include "MDataConnect/mConnectPart.h" #include "MDataConnect/mRigid.h" +#include "DataProcess/ShowLoad.h" + +#include "GLPointAttachmentVisualModule.h" +#include "GLSurfaceAttachmentVisualModule.h" + +#include + namespace dyno { IMPLEMENT_TCLASS(MxLoad, TDataType) @@ -41,9 +48,9 @@ namespace dyno this->SetPartUI(); this->updateRenderData(); - surfaceInteractor->inInitialTriangleSet()->setDataPtr(m_triangles); - edgeInteractor->inInitialEdgeSet()->setDataPtr(m_triangles); - pointInteractor->inInitialPointSet()->setDataPtr(m_triangles); + this->stateTriangleSet()->connect(surfaceInteractor->inInitialTriangleSet()); + this->stateTriangleSet()->connect(edgeInteractor->inInitialEdgeSet()); + this->stateTriangleSet()->connect(pointInteractor->inInitialPointSet()); this->varFloodAngle()->connect(surfaceInteractor->varFloodAngle()); @@ -111,6 +118,28 @@ namespace dyno this->pointInteractor->outOtherPointSet()->connect(pointRender2->inPointSet()); this->graphicsPipeline()->pushModule(pointRender2); + { + m_show_load = std::make_shared(); + auto gl_point_attach = std::make_shared(); + auto gl_surface_attach = std::make_shared(); + + // state input + this->stateLoadList()->connect(m_show_load->inLoadList()); + this->stateTriangleSet()->connect(m_show_load->inTriangleSet()); + + // visual module + m_show_load->outTriangleSet()->connect(gl_point_attach->inPointSet()); + m_show_load->outTriangleSet()->connect(gl_surface_attach->inTriangleSet()); + m_show_load->outPointAttachAttributes()->connect(gl_point_attach->inPointAttachAttributes()); + m_show_load->outSurfaceAttachAttributes()->connect(gl_surface_attach->inSurfaceAttachAttributes()); + // need this to give gl module a valid input at beginning + m_show_load->outTriangleSet()->allocate(); + + this->graphicsPipeline()->pushModule(m_show_load); + this->graphicsPipeline()->pushModule(gl_point_attach); + this->graphicsPipeline()->pushModule(gl_surface_attach); + } + auto pointRender3 = std::make_shared(); pointRender3->varPointSize()->setValue(0.5f); pointRender3->setColor(Vec3f(0, 0, 1.0f)); @@ -202,7 +231,10 @@ namespace dyno void MxLoad::updateRenderData() { auto field = this->inDataField()->getDataPtr(); - m_triangles = std::make_shared>(); + auto triangles = std::make_shared>(); + this->stateTriangleSet()->setDataPtr(triangles); + this->stateTriangleSet()->tack(); + if (field != nullptr) { std::vector partial = this->varMxShowPartData()->getDataPtr()->getPartVector(); @@ -306,8 +338,8 @@ namespace dyno f_index += part_Tri_Num; } - m_triangles->setPoints(_ver_Current); - m_triangles->setTriangles(_tri_Current); + triangles->setPoints(_ver_Current); + triangles->setTriangles(_tri_Current); } } @@ -377,24 +409,21 @@ namespace dyno } } - if (m_triangles.get() != nullptr) m_triangles->update(); - - surfaceInteractor->inInitialTriangleSet()->setDataPtr(m_triangles); - edgeInteractor->inInitialEdgeSet()->setDataPtr(m_triangles); - pointInteractor->inInitialPointSet()->setDataPtr(m_triangles); + auto triangles = this->stateTriangleSet()->getDataPtr(); + triangles->update(); this->surfaceInteractor->outOtherTriangleSet()->setDataPtr(std::make_shared>()); this->surfaceInteractor->outSelectedTriangleSet()->setDataPtr(std::make_shared>()); this->surfaceInteractor->outSelectedTriangleSet()->getDataPtr()->getTriangles().resize(0); - this->surfaceInteractor->outOtherTriangleSet()->getDataPtr()->copyFrom(*(m_triangles.get())); + this->surfaceInteractor->outOtherTriangleSet()->getDataPtr()->copyFrom(*triangles); this->edgeInteractor->outOtherEdgeSet()->setDataPtr(std::make_shared>()); this->edgeInteractor->outSelectedEdgeSet()->setDataPtr(std::make_shared>()); - this->edgeInteractor->outOtherEdgeSet()->getDataPtr()->copyFrom(*(m_triangles.get())); + this->edgeInteractor->outOtherEdgeSet()->getDataPtr()->copyFrom(*triangles); this->pointInteractor->outOtherPointSet()->setDataPtr(std::make_shared>()); this->pointInteractor->outSelectedPointSet()->setDataPtr(std::make_shared>()); - this->pointInteractor->outOtherPointSet()->getDataPtr()->copyFrom(*(m_triangles.get())); + this->pointInteractor->outOtherPointSet()->getDataPtr()->copyFrom(*triangles); LoadAssign(); } @@ -472,7 +501,7 @@ namespace dyno int n = load_in.size(); MDataLoadBC::mLoadBCBase* load_data = load_in[n - 1]; - auto load_type = load_data->getLoadBCType(); + auto load_type = load_data->type(); switch (load_type) { @@ -493,25 +522,36 @@ namespace dyno } } + template + void appendLoadList(TLoadList& load_list, const TLoadBC& load_bc, const CArray& carr) { + auto list = load_list.getDataPtr(); + { + LoadWithSet load; + load.load = std::make_shared(load_bc); + std::copy(carr.begin(), carr.begin() + carr.size(), std::back_inserter(load.index_set)); + list->emplace_back(std::move(load)); + } + load_list.tack(); + } + template void MxLoad::setLBCForce(MDataLoadBC::mLoadBCBase* force) { auto field = this->inDataField()->getDataPtr(); - for (int i = 0; i < force->_loadcase.size(); i++) - { - MDataCase::mCaseBase* select_case = field->getCaseData(force->_loadcase[i]); - select_case->appendCaseLoadName(force->_loadBCName); + for (auto& el : force->loadCases()) { + MDataCase::mCaseBase* select_case = field->getCaseData(el); + select_case->appendCaseLoadName(force->name()); } - MDataLoadBC::mForce* con_laod = dynamic_cast(force); + MDataLoadBC::mForce* con_load = dynamic_cast(force); //编号数组 auto setArray_p = getOutIndex(); MxSetData::MxNodeSet* node_set = new MxSetData::MxNodeSet("load_set_" + std::to_string(_set_count)); - con_laod->_setName = "load_set_" + std::to_string(_set_count); + con_load->_setName = "load_set_" + std::to_string(_set_count); for (int i = 0; i < setArray_p.size(); i++) { @@ -521,8 +561,9 @@ namespace dyno } field->AppendSetData(node_set); - field->appendLoadBCData(con_laod); + field->appendLoadBCData(con_load); + appendLoadList(*(this->stateLoadList()), *con_load, setArray_p); _set_count++; } @@ -531,10 +572,9 @@ namespace dyno { auto field = this->inDataField()->getDataPtr(); - for (int i = 0; i < force->_loadcase.size(); i++) - { - MDataCase::mCaseBase* select_case = field->getCaseData(force->_loadcase[i]); - select_case->appendCaseLoadName(force->_loadBCName); + for (auto& el : force->loadCases()) { + MDataCase::mCaseBase* select_case = field->getCaseData(el); + select_case->appendCaseLoadName(force->name()); } auto con_laod = dynamic_cast(force); @@ -564,19 +604,18 @@ namespace dyno { auto field = this->inDataField()->getDataPtr(); - MDataLoadBC::mPressure* press_laod = dynamic_cast(force); + MDataLoadBC::mPressure* press_load = dynamic_cast(force); - for (int i = 0; i < force->_loadcase.size(); i++) - { - MDataCase::mCaseBase* select_case = field->getCaseData(force->_loadcase[i]); - select_case->appendCaseLoadName(force->_loadBCName); + for (auto& el : force->loadCases()) { + MDataCase::mCaseBase* select_case = field->getCaseData(el); + select_case->appendCaseLoadName(force->name()); } //编号数组 auto setArray_s = getOutIndex(); MxSetData::MxElementSurfaceSet* face_set = new MxSetData::MxElementSurfaceSet("load_set_" + std::to_string(_set_count)); - press_laod->_setName = "load_set_" + std::to_string(_set_count); + press_load->_setName = "load_set_" + std::to_string(_set_count); for (int i = 0; i < setArray_s.size(); i++) { @@ -590,8 +629,9 @@ namespace dyno } field->AppendSetData(face_set); - field->appendLoadBCData(press_laod); + field->appendLoadBCData(press_load); + appendLoadList(*(this->stateLoadList()), *press_load, setArray_s); _set_count++; } diff --git a/src/MxSimPre/PreprocessNode/Load.h b/src/MxSimPre/PreprocessNode/Load.h index 6afafa23..180ed16a 100644 --- a/src/MxSimPre/PreprocessNode/Load.h +++ b/src/MxSimPre/PreprocessNode/Load.h @@ -17,6 +17,7 @@ #include "PointInteraction.h" #include "MxDataField/MxPickerData.h" +#include "DataProcess/ShowLoad.h" namespace mxdyno @@ -66,6 +67,8 @@ namespace dyno DEF_INSTANCE_IN(MxDataField::DataField, DataField, "DataSet"); DEF_INSTANCE_OUT(MxDataField::DataField, DataField, "DataSet"); + DEF_INSTANCE_STATE(TriangleSet, TriangleSet, ""); + DEF_VAR_STATE(std::vector, LoadList, std::vector(), "LoadList"); //拾取数据 DEF_MXPICKERDATA(PickData, "PickData"); //显隐数据 @@ -100,6 +103,7 @@ namespace dyno std::shared_ptr> surfaceInteractor; std::shared_ptr> edgeInteractor; std::shared_ptr> pointInteractor; + std::shared_ptr m_show_load; std::vector _all_Part; mxdyno::mesh::MeshModelData* _mesh_Model; diff --git a/src/MxSimPre/PreprocessNode/PrepostProcess.cpp b/src/MxSimPre/PreprocessNode/PrepostProcess.cpp index 399a372f..ae74751c 100644 --- a/src/MxSimPre/PreprocessNode/PrepostProcess.cpp +++ b/src/MxSimPre/PreprocessNode/PrepostProcess.cpp @@ -293,10 +293,10 @@ void PrepostProcess::setForceData(mLoadBCBase* data) } dataField->AppendSetData(node_set); - for (int i = 0; i < data->_loadcase.size(); i++) + for (int i = 0; i < data->loadCases().size(); i++) { - MDataCase::mCaseBase* select_case = dataField->getCaseData(data->_loadcase[i]); - select_case->appendCaseLoadName(data->_loadBCName); + MDataCase::mCaseBase* select_case = dataField->getCaseData(data->loadCases()[i]); + select_case->appendCaseLoadName(data->name()); } mForce* force = dynamic_cast(data); force->_setName = "load_set_" + std::to_string(m_setCount); @@ -324,10 +324,10 @@ void PrepostProcess::setGravityData(mLoadBCBase* data) } dataField->AppendSetData(node_set); - for (int i = 0; i < data->_loadcase.size(); i++) + for (int i = 0; i < data->loadCases().size(); i++) { - MDataCase::mCaseBase* select_case = dataField->getCaseData(data->_loadcase[i]); - select_case->appendCaseLoadName(data->_loadBCName); + MDataCase::mCaseBase* select_case = dataField->getCaseData(data->loadCases()[i]); + select_case->appendCaseLoadName(data->name()); } mGravity* force = dynamic_cast(data); @@ -340,10 +340,10 @@ template void PrepostProcess::setPressureData(mLoadBCBase* data) { auto dataField = this->varDataField()->getDataPtr(); - for (int i = 0; i < data->_loadcase.size(); i++) + for (int i = 0; i < data->loadCases().size(); i++) { - MDataCase::mCaseBase* select_case = dataField->getCaseData(data->_loadcase[i]); - select_case->appendCaseLoadName(data->_loadBCName); + MDataCase::mCaseBase* select_case = dataField->getCaseData(data->loadCases()[i]); + select_case->appendCaseLoadName(data->name()); } mPressure* force = dynamic_cast(data); //编号数组 @@ -421,10 +421,10 @@ void PrepostProcess::setFixedData(MDataLoadBC::mLoadBCBase* force) field->AppendSetData(node_set); mFixed* fix_bc = dynamic_cast(force); - for (int i = 0; i < force->_loadcase.size(); i++) + for (int i = 0; i < force->loadCases().size(); i++) { - MDataCase::mCaseBase* select_case = field->getCaseData(force->_loadcase[i]); - select_case->appendCaseBCName(force->_loadBCName); + MDataCase::mCaseBase* select_case = field->getCaseData(force->loadCases()[i]); + select_case->appendCaseBCName(force->name()); } fix_bc->_setName = "bc_set_" + std::to_string(m_setCount); @@ -452,10 +452,10 @@ void PrepostProcess::setDisplacementData(MDataLoadBC::mLoadBCBase* fo field->AppendSetData(node_set); MDataLoadBC::mDis* dis_bc = dynamic_cast(force); - for (int i = 0; i < force->_loadcase.size(); i++) + for (int i = 0; i < force->loadCases().size(); i++) { - MDataCase::mCaseBase* select_case = field->getCaseData(force->_loadcase[i]); - select_case->appendCaseBCName(force->_loadBCName); + MDataCase::mCaseBase* select_case = field->getCaseData(force->loadCases()[i]); + select_case->appendCaseBCName(force->name()); } dis_bc->_setName = "bc_set_" + std::to_string(m_setCount); diff --git a/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLPointAttachmentVisualModule.cpp b/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLPointAttachmentVisualModule.cpp new file mode 100644 index 00000000..75a96ec2 --- /dev/null +++ b/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLPointAttachmentVisualModule.cpp @@ -0,0 +1,134 @@ +#include "GLPointAttachmentVisualModule.h" +#include "GLRenderEngine.h" + +#include +#include + +#include +#include + +// opengl +#include +// cuda +#include + +namespace dyno +{ + IMPLEMENT_CLASS(GLPointAttachmentVisualModule) + + GLPointAttachmentVisualModule::GLPointAttachmentVisualModule() : m_draw_count(0),m_shader_program(nullptr) + { + this->setName("point_attachment_renderer"); + this->inPointAttachAttributes()->tagOptional(true); + } + + GLPointAttachmentVisualModule::~GLPointAttachmentVisualModule() + { + } + + bool GLPointAttachmentVisualModule::initializeGL() + { + m_buffer_vertex.create(GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW); + + m_vertex_array.create(); + m_vertex_array.bindVertexBuffer(&m_buffer_vertex, 0, 3, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, position), 0); + m_vertex_array.bindVertexBuffer(&m_buffer_vertex, 1, 3, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, color), 0); + m_vertex_array.bindVertexBuffer(&m_buffer_vertex, 2, 3, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, direction), 0); + m_vertex_array.bindVertexBuffer(&m_buffer_vertex, 3, 1, GL_INT, sizeof(Vertex), offsetof(Vertex, shape), 0); + + m_shader_program = gl::ShaderFactory::createShaderProgram("point_attachment.vert", "point_attachment.frag", "point_attachment.geom"); + + gl::glCheckError(); + + return true; + } + + void GLPointAttachmentVisualModule::destroyGL() + { + if (isGLInitialized) + { + m_shader_program->release(); + delete m_shader_program; + + m_buffer_vertex.release(); + m_vertex_array.release(); + + isGLInitialized = false; + } + } + + void GLPointAttachmentVisualModule::updateGL() + { + updateMutex.lock(); + + m_buffer_vertex.load(m_gpu_vertex); + + updateMutex.unlock(); + } + + void GLPointAttachmentVisualModule::updateGraphicsContext() + { + updateMutex.lock(); + + CArray cpu_points; + cpu_points.assign(this->inPointSet()->getDataPtr()->getPoints()); + + auto p_attr = this->inPointAttachAttributes()->getDataPtr(); + if (p_attr) { + CArray cpu_vertex; + + auto pos = cpu_vertex.begin(); + for (auto& el: *p_attr) { + for (int idx : el.index_set) { + if (idx < 0 || idx >= (int)cpu_points.size()) continue; + + Vertex v; + v.position = cpu_points[idx]; + v.color = el.color; + v.direction = el.direction; + v.shape = (int)el.shape; + cpu_vertex.pushBack(v); + } + } + + m_gpu_vertex.assign(cpu_vertex); + m_draw_count = m_gpu_vertex.size(); + } + else { + m_draw_count = 0; + } + + GLVisualModule::updateGraphicsContext(); + updateMutex.unlock(); + } + + void GLPointAttachmentVisualModule::paintGL(GLRenderPass pass) + { + if (m_draw_count <= 0) + return; + + m_shader_program->use(); + m_shader_program->setFloat("uAlpha", this->varAlpha()->getData()); + + if (pass == GLRenderPass::COLOR) + { + // glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &subroutine); + } + else if (pass == GLRenderPass::SHADOW) + { + return; + } + else if (pass == GLRenderPass::TRANSPARENCY) + { + return; + } + else + { + return; + } + + m_vertex_array.bind(); + glDrawArrays(GL_POINTS, 0, m_gpu_vertex.size()); + gl::glCheckError(); + } +} diff --git a/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLPointAttachmentVisualModule.h b/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLPointAttachmentVisualModule.h new file mode 100644 index 00000000..a0d129c5 --- /dev/null +++ b/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLPointAttachmentVisualModule.h @@ -0,0 +1,65 @@ +/** + * Copyright 2017-2021 Jian SHI + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include "Topology/PointSet.h" + +#include "GLVisualModule.h" +#include "gl/GPUBuffer.h" +#include "gl/VertexArray.h" +#include "gl/Shader.h" + +#include "VirtualAttach.h" + + +namespace dyno +{ + class GLPointAttachmentVisualModule : public GLVisualModule + { + DECLARE_CLASS(GLPointAttachmentVisualModule) + public: + GLPointAttachmentVisualModule(); + ~GLPointAttachmentVisualModule(); + + public: + DEF_INSTANCE_IN(PointSet, PointSet, ""); + DEF_VAR_IN(std::vector, PointAttachAttributes, ""); + + protected: + virtual void updateGraphicsContext() override; + + virtual void paintGL(GLRenderPass pass) override; + virtual void updateGL() override; + virtual bool initializeGL() override; + virtual void destroyGL() override; + private: + struct Vertex { + Vec3f position; + Vec3f color; + Vec3f direction; + int shape {(int) AttachShape::Arrow}; + }; + + private: + int m_draw_count; + gl::XBuffer m_buffer_vertex; + + gl::VertexArray m_vertex_array; + gl::Program* m_shader_program; + + DArray m_gpu_vertex; + }; +}; diff --git a/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLSurfaceAttachmentVisualModule.cpp b/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLSurfaceAttachmentVisualModule.cpp new file mode 100644 index 00000000..cf8fcf05 --- /dev/null +++ b/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLSurfaceAttachmentVisualModule.cpp @@ -0,0 +1,148 @@ +#include "GLSurfaceAttachmentVisualModule.h" +#include "GLRenderEngine.h" + +#include +#include + +#include +#include +#include + +// opengl +#include +// cuda +#include + +namespace dyno +{ + IMPLEMENT_CLASS(GLSurfaceAttachmentVisualModule) + + GLSurfaceAttachmentVisualModule::GLSurfaceAttachmentVisualModule() : m_draw_count(0),m_shader_program(nullptr) + { + this->setName("surface_attchment_renderer"); + this->inSurfaceAttachAttributes()->tagOptional(true); + } + + GLSurfaceAttachmentVisualModule::~GLSurfaceAttachmentVisualModule() + { + } + + bool GLSurfaceAttachmentVisualModule::initializeGL() + { + m_buffer_vertex.create(GL_ARRAY_BUFFER, GL_DYNAMIC_DRAW); + m_buffer_index.create(GL_ELEMENT_ARRAY_BUFFER, GL_DYNAMIC_DRAW); + + m_vertex_array.create(); + m_vertex_array.bindIndexBuffer(&m_buffer_index); + m_vertex_array.bindVertexBuffer(&m_buffer_vertex, 0, 3, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, position), 0); + m_vertex_array.bindVertexBuffer(&m_buffer_vertex, 1, 3, GL_FLOAT, sizeof(Vertex), offsetof(Vertex, color), 0); + m_vertex_array.bindVertexBuffer(&m_buffer_vertex, 2, 1, GL_INT, sizeof(Vertex), offsetof(Vertex, shape), 0); + + m_shader_program = gl::ShaderFactory::createShaderProgram("surface_attachment.vert", "surface_attachment.frag", "surface_attachment.geom"); + + gl::glCheckError(); + + return true; + } + + void GLSurfaceAttachmentVisualModule::destroyGL() + { + if (isGLInitialized) + { + m_shader_program->release(); + delete m_shader_program; + + m_buffer_vertex.release(); + m_buffer_index.release(); + m_vertex_array.release(); + + isGLInitialized = false; + } + } + + void GLSurfaceAttachmentVisualModule::updateGL() + { + updateMutex.lock(); + + m_buffer_vertex.load(m_gpu_vertex); + m_buffer_index.load(m_gpu_triangle); + + updateMutex.unlock(); + } + + void GLSurfaceAttachmentVisualModule::updateGraphicsContext() + { + updateMutex.lock(); + auto in_trianle_set = this->inTriangleSet()->getDataPtr(); + + CArray cpu_points; + CArray cpu_triangle_all; + cpu_points.assign(in_trianle_set->getPoints()); + cpu_triangle_all.assign(in_trianle_set->getTriangles()); + + auto p_attr = this->inSurfaceAttachAttributes()->getDataPtr(); + if (p_attr) { + CArray cpu_vertexs; + CArray cpu_triangles; + + auto pos = cpu_vertexs.begin(); + for (auto& el: *p_attr) { + for (int idx : el.index_set) { + if (idx < 0 || idx >= cpu_triangle_all.size()) continue; + TopologyModule::Triangle triangle = cpu_triangle_all[idx]; + for (int i = 0; i < 3; i++) { + Vertex v; + v.position = cpu_points[triangle[i]]; + v.color = el.color; + v.shape = (int)el.shape; + + triangle[i] = cpu_vertexs.size(); + cpu_vertexs.pushBack(v); + } + cpu_triangles.pushBack(triangle); + } + } + + m_gpu_vertex.assign(cpu_vertexs); + m_gpu_triangle.assign(cpu_triangles); + m_draw_count = m_gpu_triangle.size() * 3; + } + else { + m_draw_count = 0; + } + + GLVisualModule::updateGraphicsContext(); + updateMutex.unlock(); + } + + void GLSurfaceAttachmentVisualModule::paintGL(GLRenderPass pass) + { + if (m_draw_count <= 0) { + return; + } + + m_shader_program->use(); + m_shader_program->setFloat("uAlpha", this->varAlpha()->getData()); + + if (pass == GLRenderPass::COLOR) + { + // glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &subroutine); + } + else if (pass == GLRenderPass::SHADOW) + { + return; + } + else if (pass == GLRenderPass::TRANSPARENCY) + { + return; + } + else + { + return; + } + + m_vertex_array.bind(); + glDrawElements(GL_TRIANGLES, m_draw_count, GL_UNSIGNED_INT, 0); + gl::glCheckError(); + } +} diff --git a/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLSurfaceAttachmentVisualModule.h b/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLSurfaceAttachmentVisualModule.h new file mode 100644 index 00000000..2a1469f1 --- /dev/null +++ b/src/Rendering/Engine/OpenGL/Backend/Cuda/Module/GLSurfaceAttachmentVisualModule.h @@ -0,0 +1,67 @@ +/** + * Copyright 2017-2021 Jian SHI + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include "Topology/PointSet.h" +#include "Topology/TriangleSet.h" + +#include "GLVisualModule.h" +#include "gl/GPUBuffer.h" +#include "gl/VertexArray.h" +#include "gl/Shader.h" + +#include "VirtualAttach.h" + + +namespace dyno +{ + class GLSurfaceAttachmentVisualModule : public GLVisualModule + { + DECLARE_CLASS(GLSurfaceAttachmentVisualModule) + public: + GLSurfaceAttachmentVisualModule(); + ~GLSurfaceAttachmentVisualModule(); + + public: + DEF_INSTANCE_IN(TriangleSet, TriangleSet, ""); + DEF_VAR_IN(std::vector, SurfaceAttachAttributes, ""); + + protected: + virtual void updateGraphicsContext() override; + + virtual void paintGL(GLRenderPass pass) override; + virtual void updateGL() override; + virtual bool initializeGL() override; + virtual void destroyGL() override; + private: + struct Vertex { + Vec3f position; + Vec3f color; + int shape {(int)AttachShape::Arrow}; + }; + + private: + int m_draw_count; + gl::XBuffer m_buffer_vertex; + gl::XBuffer m_buffer_index; + + gl::VertexArray m_vertex_array; + gl::Program* m_shader_program; + + DArray m_gpu_triangle; + DArray m_gpu_vertex; + }; +}; diff --git a/src/Rendering/Engine/OpenGL/gl/Shader.cpp b/src/Rendering/Engine/OpenGL/gl/Shader.cpp index c8b0e25d..e13505b3 100644 --- a/src/Rendering/Engine/OpenGL/gl/Shader.cpp +++ b/src/Rendering/Engine/OpenGL/gl/Shader.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "shader_header.h" @@ -153,6 +154,57 @@ namespace gl { return initialized; } + Program* ShaderFactory::createShaderProgramFromFile(std::string dir, const char* vs, const char* fs, const char* gs) + { + ShaderFactory::initialize(); + + Program* program = new Program; + program->create(); + + Shader vshader; + Shader fshader; + Shader gshader; + + auto create_shader = [program, dir](const char* name, Shader& shader, unsigned int type) { + auto file = std::ifstream(dir + name); + std::string src; + { + std::stringstream stream; + stream << file.rdbuf(); + src = stream.str(); + } + if (shader.createFromSource(type, src)) + program->attachShader(shader); + else + printf("Failed to compile shader: %s\n", name); + }; + + if (vs != 0) + { + create_shader(vs, vshader, GL_VERTEX_SHADER); + } + + if (fs != 0) + { + create_shader(fs, vshader, GL_FRAGMENT_SHADER); + } + + if (gs != 0) + { + create_shader(gs, vshader, GL_GEOMETRY_SHADER); + } + + if (!program->link()) + { + printf("Failed to link shader program: %s\n", fs); + } + + vshader.release(); + fshader.release(); + gshader.release(); + + return program; + } Program* ShaderFactory::createShaderProgram(const char* vs, const char* fs, const char* gs) { diff --git a/src/Rendering/Engine/OpenGL/gl/Shader.h b/src/Rendering/Engine/OpenGL/gl/Shader.h index be953598..7ec57e13 100644 --- a/src/Rendering/Engine/OpenGL/gl/Shader.h +++ b/src/Rendering/Engine/OpenGL/gl/Shader.h @@ -63,6 +63,7 @@ namespace gl { public: static bool initialize(); static Program* createShaderProgram(const char* vs, const char* fs, const char* gs = 0); + static Program* createShaderProgramFromFile(std::string dir, const char* vs, const char* fs, const char* gs = 0); }; } \ No newline at end of file diff --git a/src/Rendering/Engine/OpenGL/shader/point_attachment.frag b/src/Rendering/Engine/OpenGL/shader/point_attachment.frag new file mode 100644 index 00000000..6c18a79e --- /dev/null +++ b/src/Rendering/Engine/OpenGL/shader/point_attachment.frag @@ -0,0 +1,13 @@ +#version 440 + +#extension GL_ARB_shading_language_include : require +#include "common.glsl" + +layout(location = 0) out vec4 fragColor; + +in GS_OUT { vec3 color; } +fg_in; + +uniform float uAlpha; + +void main(void) { fragColor = vec4(fg_in.color, uAlpha); } diff --git a/src/Rendering/Engine/OpenGL/shader/point_attachment.geom b/src/Rendering/Engine/OpenGL/shader/point_attachment.geom new file mode 100644 index 00000000..3e5d107f --- /dev/null +++ b/src/Rendering/Engine/OpenGL/shader/point_attachment.geom @@ -0,0 +1,77 @@ +#version 440 + +#extension GL_ARB_shading_language_include : require + +#include "common.glsl" +#include "utils.glsl" + +#define SHAPE_ARROW 0 +#define SHAPE_BOUNDARY 1 + +layout(points) in; +layout(line_strip, max_vertices = 33) out; + +in VS_OUT { + mat4 transform; + vec3 color; + int shape; +} +gs_in[]; + +out GS_OUT { vec3 color; } +gs_out; + +// 0 - arrow +// 1 - boundary +uniform int uShape = 0; + +const vec3 arrow_points[6] = { + {0.0, 0.0, 0.0}, {0.5, 5.0, 0.5}, {0.5, 5.0, -0.5}, + {-0.5, 5.0, -0.5}, {-0.5, 5.0, 0.5}, {0.0, 8.0, 0.0}, +}; +const int arrow_lines[12] = {0, 5, 1, 2, 5, 4, 3, 5, 2, 3, 4, 1}; + +const vec3 boundary_points[5] = { + {0.0, 0.0, 0.0}, {0.5, 3.0, 0.5}, {0.5, 3.0, -0.5}, + {-0.5, 3.0, -0.5}, {-0.5, 3.0, 0.5}, +}; +const int boundary_lines[11] = {0, 1, 2, 3, 0, 2, 3, 4, 1, 4, 0}; + +void main() { + int shape = gs_in[0].shape; + vec3 color = gs_in[0].color; + mat4 transform = gs_in[0].transform; + + // draw arrow + if (shape == SHAPE_ARROW) { + vec4 points_[6]; + for (int i = 0; i < 6; i++) { + points_[i] = transform * vec4(arrow_points[i], 1.0); + } + + for (int i = 0; i < 12; i++) { + gs_out.color = color; + gl_Position = points_[arrow_lines[i]]; + EmitVertex(); + } + } else if (shape == SHAPE_BOUNDARY) { + vec4 points_[5]; + vec3 up = vec3(0.0, 1.0, 0.0); + vec3 dir[3] = {{-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, -1.0}}; + + for (int d = 0; d < 3; d++) { + mat4 transform_ = transform * build_rotate_align(up, normalize(dir[d])); + for (int i = 0; i < 5; i++) { + points_[i] = transform_ * vec4(boundary_points[i], 1.0); + } + + for (int i = 0; i < 11; i++) { + gs_out.color = color; + gl_Position = points_[boundary_lines[i]]; + EmitVertex(); + } + } + } + + EndPrimitive(); +} diff --git a/src/Rendering/Engine/OpenGL/shader/point_attachment.vert b/src/Rendering/Engine/OpenGL/shader/point_attachment.vert new file mode 100644 index 00000000..4e75fda0 --- /dev/null +++ b/src/Rendering/Engine/OpenGL/shader/point_attachment.vert @@ -0,0 +1,41 @@ +#version 440 + +#extension GL_ARB_shading_language_include : require + +#include "common.glsl" +#include "utils.glsl" + +// input +layout(location = 0) in vec3 aPosition; +layout(location = 1) in vec3 aColor; +layout(location = 2) in vec3 aDirection; +layout(location = 3) in int aShape; + +// output +out VS_OUT { + mat4 transform; + vec3 color; + int shape; +} +vs_out; + +float get_scale(mat4 mvp) { + const float k = 1.0 / 200.0; + vec4 ori = mvp * vec4(0.0, 0.0, 0.0, 1.0); + return k * ori.w; +} + +void main(void) { + mat4 mvp = uTransform.proj * uTransform.view * uTransform.model; + + vec3 up = vec3(0.0, 1.0, 0.0); + vec3 dir = normalize(aDirection); + + vs_out.transform = + mvp * build_translate(aPosition) * build_rotate_align(up, dir) * build_scale(get_scale(mvp)); + vs_out.color = aColor; + vs_out.shape = aShape; + + gl_Position = mvp * vec4(aPosition, 1.0); + gl_PointSize = 1; +} \ No newline at end of file diff --git a/src/Rendering/Engine/OpenGL/shader/surface_attachment.frag b/src/Rendering/Engine/OpenGL/shader/surface_attachment.frag new file mode 100644 index 00000000..6c18a79e --- /dev/null +++ b/src/Rendering/Engine/OpenGL/shader/surface_attachment.frag @@ -0,0 +1,13 @@ +#version 440 + +#extension GL_ARB_shading_language_include : require +#include "common.glsl" + +layout(location = 0) out vec4 fragColor; + +in GS_OUT { vec3 color; } +fg_in; + +uniform float uAlpha; + +void main(void) { fragColor = vec4(fg_in.color, uAlpha); } diff --git a/src/Rendering/Engine/OpenGL/shader/surface_attachment.geom b/src/Rendering/Engine/OpenGL/shader/surface_attachment.geom new file mode 100644 index 00000000..2cc9cf4b --- /dev/null +++ b/src/Rendering/Engine/OpenGL/shader/surface_attachment.geom @@ -0,0 +1,103 @@ +#version 440 + +#extension GL_ARB_shading_language_include : require + +#include "common.glsl" +#include "utils.glsl" + +#define SHAPE_ARROW 0 +#define SHAPE_BOUNDARY 1 + +layout(triangles) in; +layout(line_strip, max_vertices = 33) out; + +in VS_OUT { + vec3 color; + int shape; +} +gs_in[]; + +out GS_OUT { vec3 color; } +gs_out; + +uniform int uShape = 0; + +float get_scale(mat4 mvp) { + const float k = 1.0 / 200.0; + vec4 ori = mvp * vec4(0.0, 0.0, 0.0, 1.0); + return k * ori.w; +} + +vec3 build_triangle_normal(vec3 a, vec3 b, vec3 c) { + vec3 ac = a - c; + vec3 ab = a - b; + return normalize(cross(ac, ab)); +} + +vec3 get_triangle_centroid(vec3 a, vec3 b, vec3 c) { + return vec3(a.x + b.x + c.x, a.y + b.y + c.y, a.z + b.z + c.z) / 3.0; +} + +mat4 get_transfrom() { + mat4 mvp = uTransform.proj * uTransform.view * uTransform.model; + vec3 up = vec3(0.0, 1.0, 0.0); + + vec3 a = vec3(gl_in[0].gl_Position); + vec3 b = vec3(gl_in[1].gl_Position); + vec3 c = vec3(gl_in[2].gl_Position); + + vec3 dir = build_triangle_normal(a, b, c); + return mvp * build_translate(get_triangle_centroid(a, b, c)) * build_rotate_align(up, dir) * + build_scale(get_scale(mvp)); +} + +const vec3 arrow_points[6] = { + {0.0, 0.0, 0.0}, {0.5, 5.0, 0.5}, {0.5, 5.0, -0.5}, + {-0.5, 5.0, -0.5}, {-0.5, 5.0, 0.5}, {0.0, 8.0, 0.0}, +}; +const int arrow_lines[12] = {0, 5, 1, 2, 5, 4, 3, 5, 2, 3, 4, 1}; + +const vec3 boundary_points[5] = { + {0.0, 0.0, 0.0}, {0.5, 3.0, 0.5}, {0.5, 3.0, -0.5}, + {-0.5, 3.0, -0.5}, {-0.5, 3.0, 0.5}, +}; +const int boundary_lines[11] = {0, 1, 2, 3, 0, 2, 3, 4, 1, 4, 0}; + +void main() { + mat4 transform = get_transfrom(); + int shape = gs_in[0].shape; + vec3 color = gs_in[0].color; + + // draw arrow + if (shape == SHAPE_ARROW) { + vec4 points_[6]; + for (int i = 0; i < 6; i++) { + points_[i] = transform * vec4(arrow_points[i], 1.0); + } + + for (int i = 0; i < 12; i++) { + gs_out.color = color; + gl_Position = points_[arrow_lines[i]]; + EmitVertex(); + } + } else if (shape == SHAPE_BOUNDARY) { + vec4 points_[5]; + vec3 up = vec3(0.0, 1.0, 0.0); + vec3 dir[3] = {{-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, -1.0}}; + + for (int d = 0; d < 3; d++) { + mat4 trans = transform * build_rotate_align(up, normalize(dir[d])); + for (int i = 0; i < 5; i++) { + points_[i] = trans * vec4(boundary_points[i], 1.0); + } + + for (int i = 0; i < 11; i++) { + gs_out.color = color; + gl_Position = points_[boundary_lines[i]]; + EmitVertex(); + } + } + } + + EndPrimitive(); +} \ No newline at end of file diff --git a/src/Rendering/Engine/OpenGL/shader/surface_attachment.vert b/src/Rendering/Engine/OpenGL/shader/surface_attachment.vert new file mode 100644 index 00000000..c6c52334 --- /dev/null +++ b/src/Rendering/Engine/OpenGL/shader/surface_attachment.vert @@ -0,0 +1,26 @@ +#version 440 + +#extension GL_ARB_shading_language_include : require + +#include "common.glsl" +#include "utils.glsl" + +// input +layout(location = 0) in vec3 aPosition; +layout(location = 1) in vec3 aColor; +layout(location = 2) in int aShape; + +// output +out VS_OUT { + vec3 color; + int shape; +} +vs_out; + +void main(void) { + vs_out.color = aColor; + vs_out.shape = aShape; + + gl_Position = vec4(aPosition, 1.0); + gl_PointSize = 1; +} \ No newline at end of file diff --git a/src/Rendering/Engine/OpenGL/shader/utils.glsl b/src/Rendering/Engine/OpenGL/shader/utils.glsl new file mode 100644 index 00000000..82aff8c0 --- /dev/null +++ b/src/Rendering/Engine/OpenGL/shader/utils.glsl @@ -0,0 +1,41 @@ +mat4 build_rotate_align(vec3 a, vec3 b) { + vec3 axis = cross(a, b); + const float cos_a = dot(a, b); + const float w = 1.0 + cos_a; + float k = 0.0; + // cos_a != -1 + if (w > 0.0001) { + k = 1.0 / w; + } + + // clang-format off + return mat4( + (axis.x * axis.x * k) + cos_a, (axis.x * axis.y * k) - axis.z, (axis.z * axis.x * k) + axis.y, 0.0, + (axis.x * axis.y * k) + axis.z, (axis.y * axis.y * k) + cos_a, (axis.y * axis.z * k) - axis.x, 0.0, + (axis.z * axis.x * k) - axis.y, (axis.y * axis.z * k) + axis.x, (axis.z * axis.z * k) + cos_a, 0.0, + 0.0, 0.0, 0.0, 1.0 + ); + // clang-format on +} + +mat4 build_translate(vec3 t) { + // clang-format off + return mat4( + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + t.x, t.y, t.z, 1 + ); + // clang-format on +} + +mat4 build_scale(float s) { + // clang-format off + return mat4( + s, 0, 0, 0, + 0, s, 0, 0, + 0, 0, s, 0, + 0, 0, 0, 1 + ); + // clang-format on +} \ No newline at end of file -- Gitee