From 40167e4f2b0634ae5d2c9e44777e80bb66aedcd3 Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 13 Dec 2010 06:38:22 +0000 Subject: [PATCH] Merge from V5_1_main 10/12/2010 --- idl/NETGENPlugin_Algorithm.idl | 14 + resources/NETGENPlugin.xml | 12 +- src/GUI/NETGENPluginGUI.cxx | 3 +- src/GUI/NETGENPluginGUI_HypothesisCreator.cxx | 272 ++++++++++-------- src/GUI/NETGENPluginGUI_HypothesisCreator.h | 1 + src/NETGENPlugin/Makefile.am | 4 + .../NETGENPlugin_Hypothesis_2D.cxx | 1 - .../NETGENPlugin_Hypothesis_2D_ONLY_i.cxx | 72 +++++ .../NETGENPlugin_Hypothesis_2D_ONLY_i.hxx | 57 ++++ .../NETGENPlugin_Hypothesis_3D_i.cxx | 71 +++++ .../NETGENPlugin_Hypothesis_3D_i.hxx | 59 ++++ .../NETGENPlugin_NETGEN_2D_ONLY.cxx | 147 ++++++---- .../NETGENPlugin_NETGEN_2D_ONLY.hxx | 9 +- src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx | 235 +++++++-------- src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx | 13 +- src/NETGENPlugin/NETGENPlugin_i.cxx | 16 +- 16 files changed, 663 insertions(+), 323 deletions(-) create mode 100644 src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_ONLY_i.cxx create mode 100644 src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_ONLY_i.hxx create mode 100644 src/NETGENPlugin/NETGENPlugin_Hypothesis_3D_i.cxx create mode 100644 src/NETGENPlugin/NETGENPlugin_Hypothesis_3D_i.hxx diff --git a/idl/NETGENPlugin_Algorithm.idl b/idl/NETGENPlugin_Algorithm.idl index d342a94..f64defe 100644 --- a/idl/NETGENPlugin_Algorithm.idl +++ b/idl/NETGENPlugin_Algorithm.idl @@ -109,6 +109,20 @@ module NETGENPlugin boolean GetQuadAllowed(); }; + /*! + * interface of "NETGEN 2D parameters" hypothesis used by NETGENPlugin_NETGEN_2D_ONLY algoritm + */ + interface NETGENPlugin_Hypothesis_2D_ONLY : NETGENPlugin_Hypothesis_2D + { + }; + + /*! + * interface of "NETGEN 3D parameters" hypothesis used by NETGENPlugin_NETGEN_3D algorithm + */ + interface NETGENPlugin_Hypothesis_3D : NETGENPlugin_Hypothesis + { + }; + /*! * NETGENPlugin_Hypothesis: interface of "NETGEN 2D simple parameters" hypothesis */ diff --git a/resources/NETGENPlugin.xml b/resources/NETGENPlugin.xml index 0d3ec83..a03b5ae 100644 --- a/resources/NETGENPlugin.xml +++ b/resources/NETGENPlugin.xml @@ -41,6 +41,14 @@ label-id="NETGEN 2D Parameters" icon-id="mesh_hypo_netgen_2d.png" dim="2"/> + + @@ -76,7 +84,7 @@ isValid(msg,true) && res; res = myGrowthRate->isValid(msg,true) && res; ; - res = myNbSegPerEdge->isValid(msg,true) && res; - res = myNbSegPerRadius->isValid(msg,true) && res; + if ( myNbSegPerEdge ) + res = myNbSegPerEdge->isValid(msg,true) && res; + if ( myNbSegPerRadius ) + res = myNbSegPerRadius->isValid(msg,true) && res; return res; } @@ -148,11 +152,15 @@ QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame() myMaxSize->RangeStepAndValidator( 1e-07, 1e+06, 10., "length_precision" ); aGroupLayout->addWidget( myMaxSize, row, 1 ); row++; - - mySecondOrder = new QCheckBox( tr( "NETGEN_SECOND_ORDER" ), GroupC1 ); - aGroupLayout->addWidget( mySecondOrder, row, 0 ); - row++; - + + mySecondOrder = 0; + if ( !myIsONLY ) + { + mySecondOrder = new QCheckBox( tr( "NETGEN_SECOND_ORDER" ), GroupC1 ); + aGroupLayout->addWidget( mySecondOrder, row, 0 ); + row++; + } + aGroupLayout->addWidget( new QLabel( tr( "NETGEN_FINENESS" ), GroupC1 ), row, 0 ); myFineness = new QComboBox( GroupC1 ); QStringList types; @@ -168,76 +176,86 @@ QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame() aGroupLayout->addWidget( myGrowthRate, row, 1 ); row++; - const double VALUE_MAX = 1.0e+6; + myNbSegPerEdge = 0; + myNbSegPerRadius = 0; + if ( !myIsONLY ) + { + const double VALUE_MAX = 1.0e+6; - aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_EDGE" ), GroupC1 ), row, 0 ); - myNbSegPerEdge = new SMESHGUI_SpinBox( GroupC1 ); - myNbSegPerEdge->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" ); - aGroupLayout->addWidget( myNbSegPerEdge, row, 1 ); - row++; - - aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_RADIUS" ), GroupC1 ), row, 0 ); - myNbSegPerRadius = new SMESHGUI_SpinBox( GroupC1 ); - myNbSegPerRadius->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" ); - aGroupLayout->addWidget( myNbSegPerRadius, row, 1 ); - row++; + aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_EDGE" ), GroupC1 ), row, 0 ); + myNbSegPerEdge = new SMESHGUI_SpinBox( GroupC1 ); + myNbSegPerEdge->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" ); + aGroupLayout->addWidget( myNbSegPerEdge, row, 1 ); + row++; - if ( hypType()=="NETGEN_Parameters_2D" ) + aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_RADIUS" ), GroupC1 ), row, 0 ); + myNbSegPerRadius = new SMESHGUI_SpinBox( GroupC1 ); + myNbSegPerRadius->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" ); + aGroupLayout->addWidget( myNbSegPerRadius, row, 1 ); + row++; + } + myAllowQuadrangles = 0; + if ( myIs2D ) { myAllowQuadrangles = new QCheckBox( tr( "NETGEN_ALLOW_QUADRANGLES" ), GroupC1 ); aGroupLayout->addWidget( myAllowQuadrangles, row, 0 ); - myIs2D = true; row++; } - myOptimize = new QCheckBox( tr( "NETGEN_OPTIMIZE" ), GroupC1 ); - aGroupLayout->addWidget( myOptimize, row, 0 ); - row++; - + myOptimize = 0; + if ( !myIs2D ) + { + myOptimize = new QCheckBox( tr( "NETGEN_OPTIMIZE" ), GroupC1 ); + aGroupLayout->addWidget( myOptimize, row, 0 ); + row++; + } connect( myFineness, SIGNAL( activated( int ) ), this, SLOT( onFinenessChanged() ) ); - QWidget* localSizeGroup = new QWidget(); - QGridLayout* localSizeLayout = new QGridLayout(localSizeGroup); - - myLocalSizeTable = new QTableWidget(0, LSZ_NB_COLUMNS, localSizeGroup); - localSizeLayout->addWidget(myLocalSizeTable, 1, 0, 8, 1); - QStringList localSizeHeaders; - localSizeHeaders << tr( "LSZ_ENTRY_COLUMN" )<< tr( "LSZ_NAME_COLUMN" ) << tr( "LSZ_LOCALSIZE_COLUMN" ); - myLocalSizeTable->setHorizontalHeaderLabels(localSizeHeaders); - myLocalSizeTable->horizontalHeader()->hideSection(LSZ_ENTRY_COLUMN); - myLocalSizeTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive); - myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN); - myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN); - myLocalSizeTable->setAlternatingRowColors(true); - myLocalSizeTable->verticalHeader()->hide(); - - QPushButton* addVertexButton = new QPushButton(tr("NETGEN_LSZ_VERTEX"), localSizeGroup); - localSizeLayout->addWidget(addVertexButton, LSZ_VERTEX_BTN, 1, 1, 1); - QPushButton* addEdgeButton = new QPushButton(tr("NETGEN_LSZ_EDGE"), localSizeGroup); - localSizeLayout->addWidget(addEdgeButton, LSZ_EDGE_BTN, 1, 1, 1); + myLocalSizeTable = 0; + if ( !myIsONLY ) + { + QWidget* localSizeGroup = new QWidget(); + QGridLayout* localSizeLayout = new QGridLayout(localSizeGroup); + + myLocalSizeTable = new QTableWidget(0, LSZ_NB_COLUMNS, localSizeGroup); + localSizeLayout->addWidget(myLocalSizeTable, 1, 0, 8, 1); + QStringList localSizeHeaders; + localSizeHeaders << tr( "LSZ_ENTRY_COLUMN" )<< tr( "LSZ_NAME_COLUMN" ) << tr( "LSZ_LOCALSIZE_COLUMN" ); + myLocalSizeTable->setHorizontalHeaderLabels(localSizeHeaders); + myLocalSizeTable->horizontalHeader()->hideSection(LSZ_ENTRY_COLUMN); + myLocalSizeTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive); + myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN); + myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN); + myLocalSizeTable->setAlternatingRowColors(true); + myLocalSizeTable->verticalHeader()->hide(); + + QPushButton* addVertexButton = new QPushButton(tr("NETGEN_LSZ_VERTEX"), localSizeGroup); + localSizeLayout->addWidget(addVertexButton, LSZ_VERTEX_BTN, 1, 1, 1); + QPushButton* addEdgeButton = new QPushButton(tr("NETGEN_LSZ_EDGE"), localSizeGroup); + localSizeLayout->addWidget(addEdgeButton, LSZ_EDGE_BTN, 1, 1, 1); #ifdef NETGEN_NEW - QPushButton* addFaceButton = new QPushButton(tr("NETGEN_LSZ_FACE"), localSizeGroup); - localSizeLayout->addWidget(addFaceButton, LSZ_FACE_BTN, 1, 1, 1); + QPushButton* addFaceButton = new QPushButton(tr("NETGEN_LSZ_FACE"), localSizeGroup); + localSizeLayout->addWidget(addFaceButton, LSZ_FACE_BTN, 1, 1, 1); #endif - - QFrame *line2 = new QFrame(localSizeGroup); - line2->setFrameShape(QFrame::HLine); - line2->setFrameShadow(QFrame::Sunken); - localSizeLayout->addWidget(line2, LSZ_SEPARATOR2, 1, 1, 1); - - QPushButton* removeButton = new QPushButton(tr("NETGEN_LSZ_REMOVE"), localSizeGroup); - localSizeLayout->addWidget(removeButton, LSZ_REMOVE_BTN, 1, 1, 1); - - connect( addVertexButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnVertex())); - connect( addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnEdge())); + + QFrame *line2 = new QFrame(localSizeGroup); + line2->setFrameShape(QFrame::HLine); + line2->setFrameShadow(QFrame::Sunken); + localSizeLayout->addWidget(line2, LSZ_SEPARATOR2, 1, 1, 1); + + QPushButton* removeButton = new QPushButton(tr("NETGEN_LSZ_REMOVE"), localSizeGroup); + localSizeLayout->addWidget(removeButton, LSZ_REMOVE_BTN, 1, 1, 1); + + connect( addVertexButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnVertex())); + connect( addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnEdge())); #ifdef NETGEN_NEW - connect( addFaceButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnFace())); + connect( addFaceButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnFace())); #endif - connect( removeButton, SIGNAL(clicked()), this, SLOT(onRemoveLocalSizeOnShape())); - connect( myLocalSizeTable, SIGNAL(cellChanged(int, int)), this, SLOT(onSetLocalSize(int, int))); - - tab->insertTab(LSZ_TAB, localSizeGroup, tr("NETGEN_LOCAL_SIZE")); + connect( removeButton, SIGNAL(clicked()), this, SLOT(onRemoveLocalSizeOnShape())); + connect( myLocalSizeTable, SIGNAL(cellChanged(int, int)), this, SLOT(onSetLocalSize(int, int))); + tab->insertTab(LSZ_TAB, localSizeGroup, tr("NETGEN_LOCAL_SIZE")); + } return fr; } @@ -252,9 +270,11 @@ void NETGENPluginGUI_HypothesisCreator::retrieveParams() const myMaxSize->setValue( data.myMaxSize ); else myMaxSize->setText( data.myMaxSizeVar ); - - mySecondOrder->setChecked( data.mySecondOrder ); - myOptimize->setChecked( data.myOptimize ); + + if ( mySecondOrder ) + mySecondOrder->setChecked( data.mySecondOrder ); + if ( myOptimize ) + myOptimize->setChecked( data.myOptimize ); myFineness->setCurrentIndex( data.myFineness ); if(data.myGrowthRateVar.isEmpty()) @@ -262,44 +282,53 @@ void NETGENPluginGUI_HypothesisCreator::retrieveParams() const else myGrowthRate->setText( data.myGrowthRateVar ); - if(data.myNbSegPerEdgeVar.isEmpty()) - myNbSegPerEdge->setValue( data.myNbSegPerEdge ); - else - myNbSegPerEdge->setText( data.myNbSegPerEdgeVar ); - - if(data.myNbSegPerRadiusVar.isEmpty()) - myNbSegPerRadius->setValue( data.myNbSegPerRadius ); - else - myNbSegPerRadius->setText( data.myNbSegPerRadiusVar ); - - if (myIs2D) + if ( myNbSegPerEdge ) + { + if(data.myNbSegPerEdgeVar.isEmpty()) + myNbSegPerEdge->setValue( data.myNbSegPerEdge ); + else + myNbSegPerEdge->setText( data.myNbSegPerEdgeVar ); + } + if ( myNbSegPerRadius ) + { + if(data.myNbSegPerRadiusVar.isEmpty()) + myNbSegPerRadius->setValue( data.myNbSegPerRadius ); + else + myNbSegPerRadius->setText( data.myNbSegPerRadiusVar ); + } + if (myAllowQuadrangles) myAllowQuadrangles->setChecked( data.myAllowQuadrangles ); // update widgets bool isCustom = (myFineness->currentIndex() == UserDefined); myGrowthRate->setEnabled(isCustom); - myNbSegPerEdge->setEnabled(isCustom); - myNbSegPerRadius->setEnabled(isCustom); + if ( myNbSegPerEdge ) + myNbSegPerEdge->setEnabled(isCustom); + if ( myNbSegPerRadius ) + myNbSegPerRadius->setEnabled(isCustom); - NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this; - QMapIterator i(myLocalSizeMap); - GeomSelectionTools* geomSelectionTools = that->getGeomSelectionTools(); - while (i.hasNext()) { - i.next(); - const QString entry = i.key(); - std::string shapeName = geomSelectionTools->getNameFromEntry(entry.toStdString()); - const QString localSize = i.value(); - int row = myLocalSizeTable->rowCount(); - myLocalSizeTable->setRowCount(row+1); - myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(entry)); - myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->setFlags(0); - myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName))); - myLocalSizeTable->item(row, LSZ_NAME_COLUMN)->setFlags(0); - myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize)); - myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled); + if ( myLocalSizeTable ) + { + NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this; + QMapIterator i(myLocalSizeMap); + GeomSelectionTools* geomSelectionTools = that->getGeomSelectionTools(); + while (i.hasNext()) { + i.next(); + const QString entry = i.key(); + std::string shapeName = geomSelectionTools->getNameFromEntry(entry.toStdString()); + const QString localSize = i.value(); + int row = myLocalSizeTable->rowCount(); + myLocalSizeTable->setRowCount(row+1); + myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(entry)); + myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->setFlags(0); + myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName))); + myLocalSizeTable->item(row, LSZ_NAME_COLUMN)->setFlags(0); + myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize)); + myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled); + } + myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN); + myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN); } - myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN); - myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN); } QString NETGENPluginGUI_HypothesisCreator::storeParams() const @@ -454,30 +483,38 @@ bool NETGENPluginGUI_HypothesisCreator::readParamsFromWidgets( NetgenHypothesisD h_data.myName = myName ? myName->text() : ""; h_data.myMaxSize = myMaxSize->value(); h_data.myMaxSizeVar = myMaxSize->text(); - h_data.mySecondOrder = mySecondOrder->isChecked(); - h_data.myOptimize = myOptimize->isChecked(); + if ( mySecondOrder ) + h_data.mySecondOrder = mySecondOrder->isChecked(); + if ( myOptimize ) + h_data.myOptimize = myOptimize->isChecked(); h_data.myFineness = myFineness->currentIndex(); h_data.myGrowthRate = myGrowthRate->value(); - h_data.myNbSegPerEdge = myNbSegPerEdge->value(); - h_data.myNbSegPerRadius = myNbSegPerRadius->value(); + if ( myNbSegPerEdge ) + h_data.myNbSegPerEdge = myNbSegPerEdge->value(); + if ( myNbSegPerRadius ) + h_data.myNbSegPerRadius = myNbSegPerRadius->value(); - h_data.myGrowthRateVar = myGrowthRate->text(); - h_data.myNbSegPerEdgeVar = myNbSegPerEdge->text(); - h_data.myNbSegPerRadiusVar = myNbSegPerRadius->text(); + h_data.myGrowthRateVar = myGrowthRate->text(); + if ( myNbSegPerEdge ) + h_data.myNbSegPerEdgeVar = myNbSegPerEdge->text(); + if ( myNbSegPerRadius ) + h_data.myNbSegPerRadiusVar = myNbSegPerRadius->text(); - if ( myIs2D ) + if ( myAllowQuadrangles ) h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked(); - - NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this; - int nbRows = myLocalSizeTable->rowCount(); - for(int row=0 ; row < nbRows ; row++) + + if ( myLocalSizeTable ) + { + NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this; + int nbRows = myLocalSizeTable->rowCount(); + for(int row=0 ; row < nbRows ; row++) { QString entry = myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->text(); QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed(); that->myLocalSizeMap[entry] = localSize; } - + } return true; } @@ -486,8 +523,10 @@ void NETGENPluginGUI_HypothesisCreator::onFinenessChanged() bool isCustom = (myFineness->currentIndex() == UserDefined); myGrowthRate->setEnabled(isCustom); - myNbSegPerEdge->setEnabled(isCustom); - myNbSegPerRadius->setEnabled(isCustom); + if ( myNbSegPerEdge ) + myNbSegPerEdge->setEnabled(isCustom); + if ( myNbSegPerRadius ) + myNbSegPerRadius->setEnabled(isCustom); if (!isCustom) { @@ -524,8 +563,10 @@ void NETGENPluginGUI_HypothesisCreator::onFinenessChanged() } myGrowthRate->setValue( aGrowthRate ); - myNbSegPerEdge->setValue( aNbSegPerEdge ); - myNbSegPerRadius->setValue( aNbSegPerRadius ); + if ( myNbSegPerEdge ) + myNbSegPerEdge->setValue( aNbSegPerEdge ); + if ( myNbSegPerRadius ) + myNbSegPerRadius->setValue( aNbSegPerRadius ); } } @@ -645,6 +686,7 @@ GeomSelectionTools* NETGENPluginGUI_HypothesisCreator::getGeomSelectionTools() { _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); if (myGeomSelectionTools == NULL || myGeomSelectionTools->getMyStudy() != aStudy) { + delete myGeomSelectionTools; myGeomSelectionTools = new GeomSelectionTools(aStudy); } return myGeomSelectionTools; diff --git a/src/GUI/NETGENPluginGUI_HypothesisCreator.h b/src/GUI/NETGENPluginGUI_HypothesisCreator.h index 9706cd6..684bcc4 100644 --- a/src/GUI/NETGENPluginGUI_HypothesisCreator.h +++ b/src/GUI/NETGENPluginGUI_HypothesisCreator.h @@ -101,6 +101,7 @@ private: QCheckBox* myAllowQuadrangles; bool myIs2D; + bool myIsONLY; QTableWidget* myLocalSizeTable; GeomSelectionTools* myGeomSelectionTools; diff --git a/src/NETGENPlugin/Makefile.am b/src/NETGENPlugin/Makefile.am index 4d7ea9a..8b82423 100644 --- a/src/NETGENPlugin/Makefile.am +++ b/src/NETGENPlugin/Makefile.am @@ -39,6 +39,8 @@ salomeinclude_HEADERS = \ NETGENPlugin_Hypothesis_i.hxx \ NETGENPlugin_Hypothesis_2D.hxx \ NETGENPlugin_Hypothesis_2D_i.hxx \ + NETGENPlugin_Hypothesis_3D_i.hxx \ + NETGENPlugin_Hypothesis_2D_ONLY_i.hxx \ NETGENPlugin_SimpleHypothesis_2D.hxx \ NETGENPlugin_SimpleHypothesis_3D.hxx \ NETGENPlugin_SimpleHypothesis_2D_i.hxx \ @@ -62,6 +64,8 @@ dist_libNETGENEngine_la_SOURCES = \ NETGENPlugin_Hypothesis_i.cxx \ NETGENPlugin_Hypothesis_2D.cxx \ NETGENPlugin_Hypothesis_2D_i.cxx \ + NETGENPlugin_Hypothesis_3D_i.cxx \ + NETGENPlugin_Hypothesis_2D_ONLY_i.cxx \ NETGENPlugin_Mesher.cxx \ NETGENPlugin_SimpleHypothesis_2D.cxx \ NETGENPlugin_SimpleHypothesis_3D.cxx \ diff --git a/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D.cxx b/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D.cxx index b1ea231..aaa8bc2 100644 --- a/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D.cxx @@ -25,7 +25,6 @@ // Author : Michael Sazonov (OCN) // Date : 28/03/2006 // Project : SALOME -// $Header$ //============================================================================= // #include "NETGENPlugin_Hypothesis_2D.hxx" diff --git a/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_ONLY_i.cxx b/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_ONLY_i.cxx new file mode 100644 index 0000000..f2d3a02 --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_ONLY_i.cxx @@ -0,0 +1,72 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// NETGENPlugin : C++ implementation +// File : NETGENPlugin_Hypothesis_2D_ONLY_i.cxx +// Project : SALOME +//============================================================================= +// +#include "NETGENPlugin_Hypothesis_2D_ONLY_i.hxx" +#include "SMESH_Gen.hxx" + +#include "Utils_CorbaException.hxx" +#include "utilities.h" + +//============================================================================= +/*! + * Constructor + */ +//============================================================================= +NETGENPlugin_Hypothesis_2D_ONLY_i:: +NETGENPlugin_Hypothesis_2D_ONLY_i (PortableServer::POA_ptr thePOA, + int theStudyId, + ::SMESH_Gen* theGenImpl) + : SALOME::GenericObj_i( thePOA ), + SMESH_Hypothesis_i( thePOA ), + NETGENPlugin_Hypothesis_2D_i( thePOA, theStudyId, theGenImpl ) +{ + MESSAGE( "NETGENPlugin_Hypothesis_2D_ONLY_i::NETGENPlugin_Hypothesis_2D_ONLY_i" ); + myBaseImpl = new ::NETGENPlugin_Hypothesis_2D (theGenImpl->GetANewId(), + theStudyId, + theGenImpl); +} + +//============================================================================= +/*! + * Destructor + */ +//============================================================================= + +NETGENPlugin_Hypothesis_2D_ONLY_i::~NETGENPlugin_Hypothesis_2D_ONLY_i() +{ + MESSAGE( "NETGENPlugin_Hypothesis_2D_ONLY_i::~NETGENPlugin_Hypothesis_2D_ONLY_i" ); +} +//================================================================================ +/*! + * \brief Redefine hypothesis type + */ +//================================================================================ + +char* NETGENPlugin_Hypothesis_2D_ONLY_i::GetName() +{ + return CORBA::string_dup("NETGEN_Parameters_2D_ONLY"); +} diff --git a/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_ONLY_i.hxx b/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_ONLY_i.hxx new file mode 100644 index 0000000..d2857ce --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_Hypothesis_2D_ONLY_i.hxx @@ -0,0 +1,57 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// NETGENPlugin : C++ implementation +// File : NETGENPlugin_Hypothesis_2D_ONLY_i.hxx +// Project : SALOME +//============================================================================= +// +#ifndef _NETGENPlugin_Hypothesis_2D_ONLY_i_HXX_ +#define _NETGENPlugin_Hypothesis_2D_ONLY_i_HXX_ + +#include "NETGENPlugin_Defs.hxx" + +#include +#include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm) + +#include "NETGENPlugin_Hypothesis_2D_i.hxx" + +class SMESH_Gen; + +// NETGENPlugin parameters hypothesis ("2D only" case) + +class NETGENPLUGIN_EXPORT NETGENPlugin_Hypothesis_2D_ONLY_i: + public virtual POA_NETGENPlugin::NETGENPlugin_Hypothesis_2D_ONLY, + public NETGENPlugin_Hypothesis_2D_i +{ + public: + // Constructor + NETGENPlugin_Hypothesis_2D_ONLY_i (PortableServer::POA_ptr thePOA, + int theStudyId, + ::SMESH_Gen* theGenImpl); + // Destructor + virtual ~NETGENPlugin_Hypothesis_2D_ONLY_i(); + + char* GetName(); +}; + +#endif diff --git a/src/NETGENPlugin/NETGENPlugin_Hypothesis_3D_i.cxx b/src/NETGENPlugin/NETGENPlugin_Hypothesis_3D_i.cxx new file mode 100644 index 0000000..364f3de --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_Hypothesis_3D_i.cxx @@ -0,0 +1,71 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// NETGENPlugin : C++ implementation +// File : NETGENPlugin_Hypothesis_3D_i.cxx +// Project : SALOME +//============================================================================= +// +#include "NETGENPlugin_Hypothesis_3D_i.hxx" +#include "SMESH_Gen.hxx" + +#include "Utils_CorbaException.hxx" +#include "utilities.h" + +using namespace std; + +//============================================================================= +/*! + * Constructor + */ +//============================================================================= +NETGENPlugin_Hypothesis_3D_i:: +NETGENPlugin_Hypothesis_3D_i (PortableServer::POA_ptr thePOA, + int theStudyId, + ::SMESH_Gen* theGenImpl) + : SALOME::GenericObj_i( thePOA ), + SMESH_Hypothesis_i( thePOA ), + NETGENPlugin_Hypothesis_i( thePOA, theStudyId, theGenImpl ) +{ + MESSAGE( "NETGENPlugin_Hypothesis_3D_i::NETGENPlugin_Hypothesis_3D_i" ); +} + +//============================================================================= +/*! + * Destructor + */ +//============================================================================= +NETGENPlugin_Hypothesis_3D_i::~NETGENPlugin_Hypothesis_3D_i() +{ + MESSAGE( "NETGENPlugin_Hypothesis_3D_i::~NETGENPlugin_Hypothesis_3D_i" ); +} + +//================================================================================ +/*! + * \brief Redefine hypothesis type + */ +//================================================================================ + +char* NETGENPlugin_Hypothesis_3D_i::GetName() +{ + return CORBA::string_dup("NETGEN_Parameters_3D"); +} diff --git a/src/NETGENPlugin/NETGENPlugin_Hypothesis_3D_i.hxx b/src/NETGENPlugin/NETGENPlugin_Hypothesis_3D_i.hxx new file mode 100644 index 0000000..073cc6b --- /dev/null +++ b/src/NETGENPlugin/NETGENPlugin_Hypothesis_3D_i.hxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// NETGENPlugin : C++ implementation +// File : NETGENPlugin_Hypothesis_2D_i.hxx +// Project : SALOME +//============================================================================= +// +#ifndef _NETGENPlugin_Hypothesis_3D_i_HXX_ +#define _NETGENPlugin_Hypothesis_3D_i_HXX_ + +#include "NETGENPlugin_Defs.hxx" + +#include +#include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm) + +#include "NETGENPlugin_Hypothesis_i.hxx" + +class SMESH_Gen; + +// NETGENPlugin parameters hypothesis (3D "only" case) + +class NETGENPLUGIN_EXPORT NETGENPlugin_Hypothesis_3D_i: + public virtual POA_NETGENPlugin::NETGENPlugin_Hypothesis_3D, + public NETGENPlugin_Hypothesis_i +{ + public: + // Constructor + NETGENPlugin_Hypothesis_3D_i (PortableServer::POA_ptr thePOA, + int theStudyId, + ::SMESH_Gen* theGenImpl); + + // Get type name of hypothesis + char* GetName(); + + // Destructor + virtual ~NETGENPlugin_Hypothesis_3D_i(); +}; + +#endif diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx index 7533949..5fe1108 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.cxx @@ -24,6 +24,7 @@ #include "NETGENPlugin_NETGEN_2D_ONLY.hxx" #include "NETGENPlugin_Mesher.hxx" +#include "NETGENPlugin_Hypothesis_2D.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" @@ -86,10 +87,12 @@ NETGENPlugin_NETGEN_2D_ONLY::NETGENPlugin_NETGEN_2D_ONLY(int hypId, int studyId, _compatibleHypothesis.push_back("MaxElementArea"); _compatibleHypothesis.push_back("LengthFromEdges"); _compatibleHypothesis.push_back("QuadranglePreference"); + _compatibleHypothesis.push_back("NETGEN_Parameters_2D"); _hypMaxElementArea = 0; _hypLengthFromEdges = 0; _hypQuadranglePreference = 0; + _hypParameters = 0; } //============================================================================= @@ -140,21 +143,21 @@ bool NETGENPlugin_NETGEN_2D_ONLY::CheckHypothesis (SMESH_Mesh& aMesh, _hypLengthFromEdges = static_cast (hyp); else if ( hypName == "QuadranglePreference" ) _hypQuadranglePreference = static_cast(hyp); + else if ( hypName == "NETGEN_Parameters_2D" ) + _hypParameters = static_cast(hyp); else { aStatus = HYP_INCOMPATIBLE; return false; } } - if ( _hypMaxElementArea && _hypLengthFromEdges ) { + int nbHyps = bool(_hypMaxElementArea) + bool(_hypLengthFromEdges) + bool(_hypParameters ); + if ( nbHyps > 1 ) aStatus = HYP_CONCURENT; - return false; - } - - if ( _hypMaxElementArea || _hypLengthFromEdges || _hypQuadranglePreference) + else if ( nbHyps == 1) aStatus = HYP_OK; - return aStatus == HYP_OK; + return ( aStatus == HYP_OK ); } //================================================================================ @@ -289,7 +292,12 @@ static TError AddSegmentsToMesh(netgen::Mesh& ngMesh, } ngMesh.AddSegment (seg); - + { + netgen::Point3d ngP1(n->X(), n->Y(), n->Z()); + n = uvPtVec[ i+1 ].node; + netgen::Point3d ngP2(n->X(), n->Y(), n->Z()); + ngMesh.RestrictLocalH( netgen::Center( ngP1,ngP2), Dist(ngP1,ngP2)); + } #ifdef DUMP_SEGMENTS cout << "Segment: " << seg.edgenr << endl << "\tp1: " << seg[0] << endl @@ -377,6 +385,49 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, return error(COMPERR_BAD_INPUT_MESH, SMESH_Comment("Too few segments: ")<NbSegments()); + // -------------------- + // compute edge length + // -------------------- + + NETGENPlugin_Mesher aMesher( &aMesh, aShape, /*isVolume=*/false); + netgen::OCCGeometry occgeo; + aMesher.PrepareOCCgeometry( occgeo, F, aMesh ); + occgeo.fmap.Clear(); // face can be reversed, which is wrong in this case (issue 19978) + occgeo.fmap.Add( F ); + + if ( _hypParameters ) + { + aMesher.SetParameters(_hypParameters); + } + else + { + double edgeLength = 0; + if (_hypLengthFromEdges || (!_hypLengthFromEdges && !_hypMaxElementArea)) + { + int nbSegments = 0; + for ( int iW = 0; iW < nbWires; ++iW ) + { + edgeLength += wires[ iW ]->Length(); + nbSegments += wires[ iW ]->NbSegments(); + } + if ( nbSegments ) + edgeLength /= nbSegments; + } + if ( _hypMaxElementArea ) + { + double maxArea = _hypMaxElementArea->GetMaxArea(); + edgeLength = sqrt(2. * maxArea/sqrt(3.0)); + } + if ( edgeLength < DBL_MIN ) + edgeLength = occgeo.GetBoundingBox().Diam(); + + //cout << " edgeLength = " << edgeLength << endl; + + netgen::mparam.maxh = edgeLength; + netgen::mparam.quad = _hypQuadranglePreference ? 1 : 0; + //ngMesh->SetGlobalH ( edgeLength ); + } + // ------------------------- // Make input netgen mesh // ------------------------- @@ -384,46 +435,16 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, NETGENPlugin_NetgenLibWrapper ngLib; netgen::Mesh * ngMesh = (netgen::Mesh*) ngLib._ngMesh; - netgen::OCCGeometry occgeo; - NETGENPlugin_Mesher::PrepareOCCgeometry( occgeo, F, aMesh ); - occgeo.fmap.Clear(); // face can be reversed, which is wrong in this case (issue 19978) - occgeo.fmap.Add( F ); + Box<3> bb = occgeo.GetBoundingBox(); + bb.Increase (bb.Diam()/10); + ngMesh->SetLocalH (bb.PMin(), bb.PMax(), netgen::mparam.grading); + ngMesh->SetGlobalH (netgen::mparam.maxh); vector< const SMDS_MeshNode* > nodeVec; problem = AddSegmentsToMesh( *ngMesh, occgeo, wires, helper, nodeVec ); if ( problem && !problem->IsOK() ) return error( problem ); - // -------------------- - // compute edge length - // -------------------- - - double edgeLength = 0; - if (_hypLengthFromEdges || !_hypLengthFromEdges && !_hypMaxElementArea) - { - int nbSegments = 0; - for ( int iW = 0; iW < nbWires; ++iW ) - { - edgeLength += wires[ iW ]->Length(); - nbSegments += wires[ iW ]->NbSegments(); - } - if ( nbSegments ) - edgeLength /= nbSegments; - } - if ( _hypMaxElementArea ) - { - double maxArea = _hypMaxElementArea->GetMaxArea(); - edgeLength = sqrt(2. * maxArea/sqrt(3.0)); - } - if ( edgeLength < DBL_MIN ) - edgeLength = occgeo.GetBoundingBox().Diam(); - - //cout << " edgeLength = " << edgeLength << endl; - - netgen::mparam.maxh = edgeLength; - netgen::mparam.quad = _hypQuadranglePreference ? 1 : 0; - //ngMesh->SetGlobalH ( edgeLength ); - // ------------------------- // Generate surface mesh // ------------------------- @@ -438,20 +459,22 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, OCC_CATCH_SIGNALS; #endif err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); + if ( err ) + error(SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task); } - catch (Standard_Failure& ex) { - string comment = ex.DynamicType()->Name(); - if ( ex.GetMessageString() && strlen( ex.GetMessageString() )) { - comment += ": "; - comment += ex.GetMessageString(); - } - error(COMPERR_OCC_EXCEPTION, comment); - } - catch (NgException exc) { - error( SMESH_Comment("NgException: ") << exc.What() ); + catch (Standard_Failure& ex) + { + SMESH_Comment str("Exception in netgen::OCCGenerateMesh()"); + str << " at " << netgen::multithread.task + << ": " << ex.DynamicType()->Name(); + if ( ex.GetMessageString() && strlen( ex.GetMessageString() )) + str << ": " << ex.GetMessageString(); + error(str); } catch (...) { - error(COMPERR_EXCEPTION,"Exception in netgen::OCCGenerateMesh()"); + SMESH_Comment str("Exception in netgen::OCCGenerateMesh()"); + str << " at " << netgen::multithread.task; + error(str); } // ---------------------------------------------------- @@ -478,13 +501,16 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, // create faces bool reverse = ( aShape.Orientation() == TopAbs_REVERSED ); - for ( int i = 1; i <= nbFaces ; ++i ) + int i,j; + for ( i = 1; i <= nbFaces ; ++i ) { const Element2d& elem = ngMesh->SurfaceElement(i); vector nodes( elem.GetNP() ); - for (int j=1; j <= elem.GetNP(); ++j) + for (j=1; j <= elem.GetNP(); ++j) { int pind = elem.PNum(j); + if ( pind-1 < 0 ) + break; const SMDS_MeshNode* node = nodeVec.at(pind-1); if ( reverse ) nodes[ nodes.size()-j ] = node; @@ -496,11 +522,14 @@ bool NETGENPlugin_NETGEN_2D_ONLY::Compute(SMESH_Mesh& aMesh, meshDS->SetNodeOnFace((SMDS_MeshNode*)node, faceID, pgi.u, pgi.v); } } - SMDS_MeshFace* face = 0; - if ( elem.GetType() == TRIG ) - face = helper.AddFace(nodes[0],nodes[1],nodes[2]); - else - face = helper.AddFace(nodes[0],nodes[1],nodes[2],nodes[3]); + if ( j > elem.GetNP() ) + { + SMDS_MeshFace* face = 0; + if ( elem.GetType() == TRIG ) + face = helper.AddFace(nodes[0],nodes[1],nodes[2]); + else + face = helper.AddFace(nodes[0],nodes[1],nodes[2],nodes[3]); + } } return !err; diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.hxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.hxx index 35369a8..b608caf 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.hxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_2D_ONLY.hxx @@ -30,6 +30,7 @@ class StdMeshers_MaxElementArea; class StdMeshers_LengthFromEdges; class StdMeshers_QuadranglePreference; +class NETGENPlugin_Hypothesis_2D; /*! * \brief Mesher generating 2D elements on a geometrical face taking @@ -55,17 +56,11 @@ public: virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, MapShapeNbElems& aResMap); - /*static TError AddSegmentsToMesh(netgen::Mesh& ngMesh, - OCCGeometry& geom, - const TSideVector& wires, - SMESH_MesherHelper& helper, - vector< const SMDS_MeshNode* > & nodeVec); //amv*/ - protected: const StdMeshers_MaxElementArea* _hypMaxElementArea; const StdMeshers_LengthFromEdges* _hypLengthFromEdges; const StdMeshers_QuadranglePreference* _hypQuadranglePreference; - // const NETGENPlugin_Hypothesis* _hypothesis; + const NETGENPlugin_Hypothesis_2D* _hypParameters; }; #endif diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx index ef2d18d..1b498a2 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx @@ -30,7 +30,7 @@ // #include "NETGENPlugin_NETGEN_3D.hxx" -#include "NETGENPlugin_Mesher.hxx" +#include "NETGENPlugin_Hypothesis.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" @@ -42,6 +42,7 @@ #include "SMESH_MesherHelper.hxx" #include "SMESH_MeshEditor.hxx" #include "StdMeshers_QuadToTriaAdaptor.hxx" +#include "StdMeshers_MaxElementVolume.hxx" #include #include @@ -69,6 +70,11 @@ namespace nglib { #include } +namespace netgen { + extern int OCCGenerateMesh (OCCGeometry&, Mesh*&, int, int, char*); + extern MeshingParameters mparam; + extern volatile multithreadt multithread; +} using namespace nglib; using namespace std; @@ -86,12 +92,13 @@ NETGENPlugin_NETGEN_3D::NETGENPlugin_NETGEN_3D(int hypId, int studyId, _name = "NETGEN_3D"; _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type _compatibleHypothesis.push_back("MaxElementVolume"); + _compatibleHypothesis.push_back("NETGEN_Parameters"); + _requireShape = false; // can work without shape _maxElementVolume = 0.; _hypMaxElementVolume = NULL; - - _requireShape = false; // can work without shape + _hypParameters = NULL; } //============================================================================= @@ -118,6 +125,7 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh, MESSAGE("NETGENPlugin_NETGEN_3D::CheckHypothesis"); _hypMaxElementVolume = NULL; + _hypParameters = NULL; _maxElementVolume = DBL_MAX; list::const_iterator itl; @@ -128,7 +136,6 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh, if (!nbHyp) { aStatus = SMESH_Hypothesis::HYP_OK; - //aStatus = SMESH_Hypothesis::HYP_MISSING; return true; // can work with no hypothesis } @@ -137,20 +144,21 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh, string hypName = theHyp->GetName(); - bool isOk = false; - if (hypName == "MaxElementVolume") { _hypMaxElementVolume = static_cast (theHyp); - ASSERT(_hypMaxElementVolume); _maxElementVolume = _hypMaxElementVolume->GetMaxVolume(); - isOk =true; + aStatus = SMESH_Hypothesis::HYP_OK; + } + else if (hypName == "NETGEN_Parameters") + { + _hypParameters = static_cast (theHyp); aStatus = SMESH_Hypothesis::HYP_OK; } else aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE; - return isOk; + return ( aStatus == SMESH_Hypothesis::HYP_OK ); } //============================================================================= @@ -171,13 +179,9 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, helper.SetElementsOnShape( true ); int Netgen_NbOfNodes = 0; - int Netgen_param2ndOrder = 0; - double Netgen_paramFine = 1.; - double Netgen_paramSize = pow( 72, 1/6. ) * pow( _maxElementVolume, 1/3. ); double Netgen_point[3]; int Netgen_triangle[3]; - int Netgen_tetrahedron[4]; NETGENPlugin_NetgenLibWrapper ngLib; Ng_Mesh * Netgen_mesh = ngLib._ngMesh; @@ -313,7 +317,6 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, (netgen::Mesh&) *Netgen_mesh, nodeVec, internals); - Netgen_NbOfNodes = Ng_GetNP(Netgen_mesh); } } @@ -321,42 +324,83 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, // Generate the volume mesh // ------------------------- - Ng_Meshing_Parameters Netgen_param; + return compute( aMesh, helper, nodeVec, Netgen_mesh); +} + +//================================================================================ +/*! + * \brief set parameters and generate the volume mesh + */ +//================================================================================ - Netgen_param.secondorder = Netgen_param2ndOrder; - Netgen_param.fineness = Netgen_paramFine; - Netgen_param.maxh = Netgen_paramSize; +bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh, + SMESH_MesherHelper& helper, + vector< const SMDS_MeshNode* >& nodeVec, + Ng_Mesh * Netgen_mesh) +{ + netgen::Mesh* ngMesh = (netgen::Mesh*)Netgen_mesh; + int Netgen_NbOfNodes = Ng_GetNP(Netgen_mesh); - Ng_Result status; + char *optstr = 0; + int startWith = netgen::MESHCONST_MESHVOLUME; + int endWith = netgen::MESHCONST_OPTVOLUME; + int err = 1; - try { + NETGENPlugin_Mesher aMesher( &aMesh, helper.GetSubShape(), /*isVolume=*/true ); + netgen::OCCGeometry occgeo; + + if ( _hypParameters ) + { + aMesher.SetParameters( _hypParameters ); + if ( !_hypParameters->GetOptimize() ) + endWith = netgen::MESHCONST_MESHVOLUME; + } + else if ( _hypMaxElementVolume ) + { + netgen::mparam.maxh = pow( 72, 1/6. ) * pow( _maxElementVolume, 1/3. ); + } + else if ( aMesh.HasShapeToMesh() ) + { + aMesher.PrepareOCCgeometry( occgeo, helper.GetSubShape(), aMesh ); + netgen::mparam.maxh = occgeo.GetBoundingBox().Diam()/2; + } + else + { + netgen::Point3d pmin, pmax; + ngMesh->GetBox (pmin, pmax); + netgen::mparam.maxh = Dist(pmin, pmax)/2; + } + + try + { #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 OCC_CATCH_SIGNALS; #endif - status = Ng_GenerateVolumeMesh(Netgen_mesh, &Netgen_param); - } - catch (Standard_Failure& exc) { - error(COMPERR_OCC_EXCEPTION, exc.GetMessageString()); - status = NG_VOLUME_FAILURE; + ngMesh->CalcLocalH(); + err = netgen::OCCGenerateMesh(occgeo, ngMesh, startWith, endWith, optstr); + if ( err ) + error(SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task); } - catch (...) { - error("Exception in Ng_GenerateVolumeMesh()"); - status = NG_VOLUME_FAILURE; + catch (Standard_Failure& ex) + { + SMESH_Comment str("Exception in netgen::OCCGenerateMesh()"); + str << " at " << netgen::multithread.task + << ": " << ex.DynamicType()->Name(); + if ( ex.GetMessageString() && strlen( ex.GetMessageString() )) + str << ": " << ex.GetMessageString(); + error(str); } - if ( GetComputeError()->IsOK() ) { - switch ( status ) { - case NG_SURFACE_INPUT_ERROR:error( status, "NG_SURFACE_INPUT_ERROR"); - case NG_VOLUME_FAILURE: error( status, "NG_VOLUME_FAILURE"); - case NG_STL_INPUT_ERROR: error( status, "NG_STL_INPUT_ERROR"); - case NG_SURFACE_FAILURE: error( status, "NG_SURFACE_FAILURE"); - case NG_FILE_NOT_FOUND: error( status, "NG_FILE_NOT_FOUND"); - }; + catch (...) + { + SMESH_Comment str("Exception in netgen::OCCGenerateMesh()"); + str << " at " << netgen::multithread.task; + error(str); } int Netgen_NbOfNodesNew = Ng_GetNP(Netgen_mesh); int Netgen_NbOfTetra = Ng_GetNE(Netgen_mesh); - MESSAGE("End of Volume Mesh Generation. status=" << status << + MESSAGE("End of Volume Mesh Generation. err=" << err << ", nb new nodes: " << Netgen_NbOfNodesNew - Netgen_NbOfNodes << ", nb tetra: " << Netgen_NbOfTetra); @@ -364,16 +408,19 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, // Feed back the SMESHDS with the generated Nodes and Volume Elements // ------------------------------------------------------------------- - if ( status == NG_VOLUME_FAILURE ) + if ( err ) { - SMESH_ComputeErrorPtr err = NETGENPlugin_Mesher::readErrors(nodeVec); - if ( err && !err->myBadElements.empty() ) - error( err ); + SMESH_ComputeErrorPtr ce = NETGENPlugin_Mesher::readErrors(nodeVec); + if ( ce && !ce->myBadElements.empty() ) + error( ce ); } bool isOK = ( /*status == NG_OK &&*/ Netgen_NbOfTetra > 0 );// get whatever built if ( isOK ) { + double Netgen_point[3]; + int Netgen_tetrahedron[4]; + // create and insert new nodes into nodeVec nodeVec.resize( Netgen_NbOfNodesNew + 1, 0 ); int nodeIndex = Netgen_NbOfNodes + 1; @@ -387,14 +434,20 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, for ( int elemIndex = 1; elemIndex <= Netgen_NbOfTetra; ++elemIndex ) { Ng_GetVolumeElement(Netgen_mesh, elemIndex, Netgen_tetrahedron); - helper.AddVolume (nodeVec.at( Netgen_tetrahedron[0] ), - nodeVec.at( Netgen_tetrahedron[1] ), - nodeVec.at( Netgen_tetrahedron[2] ), - nodeVec.at( Netgen_tetrahedron[3] )); + try + { + helper.AddVolume (nodeVec.at( Netgen_tetrahedron[0] ), + nodeVec.at( Netgen_tetrahedron[1] ), + nodeVec.at( Netgen_tetrahedron[2] ), + nodeVec.at( Netgen_tetrahedron[3] )); + } + catch (...) + { + } } } - return (status == NG_OK); + return !err; } //================================================================================ @@ -406,7 +459,7 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, SMESH_MesherHelper* aHelper) { - MESSAGE("NETGENPlugin_NETGEN_3D::Compute with maxElmentsize = " << _maxElementVolume); + MESSAGE("NETGENPlugin_NETGEN_3D::Compute with maxElmentsize = " << _maxElementVolume); const int invalid_ID = -1; bool _quadraticMesh = false; typedef map< const SMDS_MeshNode*, int, TIDCompare > TNodeToIDMap; @@ -462,14 +515,10 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, // Feed the Netgen with surface mesh // --------------------------------- - int Netgen_NbOfNodes = 0; - int Netgen_param2ndOrder = 0; - double Netgen_paramFine = 1.; - double Netgen_paramSize = pow( 72, 1/6. ) * pow( _maxElementVolume, 1/3. ); - + int Netgen_NbOfNodes = 0; double Netgen_point[3]; - int Netgen_triangle[3]; - int Netgen_tetrahedron[4]; + int Netgen_triangle[3]; + int Netgen_tetrahedron[4]; NETGENPlugin_NetgenLibWrapper ngLib; Ng_Mesh * Netgen_mesh = ngLib._ngMesh; @@ -516,85 +565,9 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh, // Generate the volume mesh // ------------------------- - Ng_Meshing_Parameters Netgen_param; - - Netgen_param.secondorder = Netgen_param2ndOrder; - Netgen_param.fineness = Netgen_paramFine; - Netgen_param.maxh = Netgen_paramSize; - - Ng_Result status; - - try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 - OCC_CATCH_SIGNALS; -#endif - status = Ng_GenerateVolumeMesh(Netgen_mesh, &Netgen_param); - } - catch (Standard_Failure& exc) { - error(COMPERR_OCC_EXCEPTION, exc.GetMessageString()); - status = NG_VOLUME_FAILURE; - } - catch (...) { - error("Exception in Ng_GenerateVolumeMesh()"); - status = NG_VOLUME_FAILURE; - } - if ( GetComputeError()->IsOK() ) { - switch ( status ) { - case NG_SURFACE_INPUT_ERROR:error( status, "NG_SURFACE_INPUT_ERROR"); - case NG_VOLUME_FAILURE: error( status, "NG_VOLUME_FAILURE"); - case NG_STL_INPUT_ERROR: error( status, "NG_STL_INPUT_ERROR"); - case NG_SURFACE_FAILURE: error( status, "NG_SURFACE_FAILURE"); - case NG_FILE_NOT_FOUND: error( status, "NG_FILE_NOT_FOUND"); - }; - } - - int Netgen_NbOfNodesNew = Ng_GetNP(Netgen_mesh); - - int Netgen_NbOfTetra = Ng_GetNE(Netgen_mesh); - - MESSAGE("End of Volume Mesh Generation. status=" << status << - ", nb new nodes: " << Netgen_NbOfNodesNew - Netgen_NbOfNodes << - ", nb tetra: " << Netgen_NbOfTetra); - - // ------------------------------------------------------------------- - // Feed back the SMESHDS with the generated Nodes and Volume Elements - // ------------------------------------------------------------------- - - if ( status == NG_VOLUME_FAILURE ) - { - SMESH_ComputeErrorPtr err = NETGENPlugin_Mesher::readErrors(nodeVec); - if ( err && !err->myBadElements.empty() ) - error( err ); - } - - bool isOK = ( Netgen_NbOfTetra > 0 );// get whatever built - if ( isOK ) - { - // create and insert new nodes into nodeVec - nodeVec.resize( Netgen_NbOfNodesNew + 1 ); - int nodeIndex = Netgen_NbOfNodes + 1; - - for ( ; nodeIndex <= Netgen_NbOfNodesNew; ++nodeIndex ) - { - Ng_GetPoint( Netgen_mesh, nodeIndex, Netgen_point ); - nodeVec.at(nodeIndex) = aHelper->AddNode(Netgen_point[0],Netgen_point[1],Netgen_point[2]); - } - - // create tetrahedrons - for ( int elemIndex = 1; elemIndex <= Netgen_NbOfTetra; ++elemIndex ) - { - Ng_GetVolumeElement(Netgen_mesh, elemIndex, Netgen_tetrahedron); - aHelper->AddVolume (nodeVec.at( Netgen_tetrahedron[0] ), - nodeVec.at( Netgen_tetrahedron[1] ), - nodeVec.at( Netgen_tetrahedron[2] ), - nodeVec.at( Netgen_tetrahedron[3] )); - } - } - - return (status == NG_OK); + return compute( aMesh, *aHelper, nodeVec, Netgen_mesh); } - //============================================================================= /*! * diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx index 520cb44..d54c3cc 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.hxx @@ -26,19 +26,21 @@ // Created : lundi 27 Janvier 2003 // Author : Nadir BOUHAMOU (CEA) // Project : SALOME -// $Header$ //============================================================================= // #ifndef _NETGENPlugin_NETGEN_3D_HXX_ #define _NETGENPlugin_NETGEN_3D_HXX_ #include "NETGENPlugin_Defs.hxx" +#include "NETGENPlugin_Mesher.hxx" #include "SMESH_3D_Algo.hxx" #include "SMESH_Mesh.hxx" -#include "StdMeshers_MaxElementVolume.hxx" #include "Utils_SALOME_Exception.hxx" +class NETGENPlugin_Hypothesis; +class StdMeshers_MaxElementVolume; + class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_3D: public SMESH_3D_Algo { public: @@ -60,9 +62,16 @@ public: MapShapeNbElems& aResMap); protected: + + bool compute(SMESH_Mesh& mesh, + SMESH_MesherHelper& helper, + vector< const SMDS_MeshNode* >& nodeVec, + nglib::Ng_Mesh* ngMesh); + double _maxElementVolume; const StdMeshers_MaxElementVolume* _hypMaxElementVolume; + const NETGENPlugin_Hypothesis* _hypParameters; }; #endif diff --git a/src/NETGENPlugin/NETGENPlugin_i.cxx b/src/NETGENPlugin/NETGENPlugin_i.cxx index c8a9eda..e7a356d 100644 --- a/src/NETGENPlugin/NETGENPlugin_i.cxx +++ b/src/NETGENPlugin/NETGENPlugin_i.cxx @@ -28,12 +28,14 @@ // #include "utilities.h" -#include "NETGENPlugin_NETGEN_3D_i.hxx" -#include "NETGENPlugin_NETGEN_2D_i.hxx" -#include "NETGENPlugin_NETGEN_2D_ONLY_i.hxx" -#include "NETGENPlugin_NETGEN_2D3D_i.hxx" -#include "NETGENPlugin_Hypothesis_i.hxx" +#include "NETGENPlugin_Hypothesis_2D_ONLY_i.hxx" #include "NETGENPlugin_Hypothesis_2D_i.hxx" +#include "NETGENPlugin_Hypothesis_3D_i.hxx" +#include "NETGENPlugin_Hypothesis_i.hxx" +#include "NETGENPlugin_NETGEN_2D3D_i.hxx" +#include "NETGENPlugin_NETGEN_2D_ONLY_i.hxx" +#include "NETGENPlugin_NETGEN_2D_i.hxx" +#include "NETGENPlugin_NETGEN_3D_i.hxx" #include "NETGENPlugin_SimpleHypothesis_2D_i.hxx" #include "NETGENPlugin_SimpleHypothesis_3D_i.hxx" @@ -74,6 +76,10 @@ extern "C" aCreator = new NETGENPlugin_Creator_i; else if (strcmp(aHypName, "NETGEN_Parameters_2D") == 0) aCreator = new NETGENPlugin_Creator_i; + else if (strcmp(aHypName, "NETGEN_Parameters_3D") == 0) + aCreator = new NETGENPlugin_Creator_i; + else if (strcmp(aHypName, "NETGEN_Parameters_2D_ONLY") == 0) + aCreator = new NETGENPlugin_Creator_i; else if (strcmp(aHypName, "NETGEN_SimpleParameters_2D") == 0) aCreator = new NETGENPlugin_Creator_i; else if (strcmp(aHypName, "NETGEN_SimpleParameters_3D") == 0) -- 2.39.2