* \param mesh - TetraHedron mesh to create dual from
* \param meshName - a name of the new mesh
* \param adaptToShape - if True project boundary point on shape
+ * \param simplify - if True merge coplanar faces of a polyhedra
+ * \param eps - epislon tp define coplanar faces
*/
SMESH_Mesh CreateDualMesh(in SMESH_IDSource mesh,
in string meshName,
- in boolean adaptToShape)
+ in boolean adaptToShape,
+ in boolean simplify,
+ in double eps)
raises ( SALOME::SALOME_Exception );
/*!
#include <QRadioButton>
#include <QButtonGroup>
#include <QGroupBox>
+#include <QDoubleValidator>
#include <QFrame>
#include <QHBoxLayout>
#include <QGridLayout>
myProjShape = new QCheckBox(QString(tr("PROJ_SHAPE")), mainFrame());
myProjShape->toggle();
+ mySimplify = new QCheckBox(QString(tr("SIMPLIFY")), mainFrame());
+ mySimplify->toggle();
+
+ mySimpEps = new QLineEdit(mainFrame());
+
+ QDoubleValidator *validator = new QDoubleValidator(1e-16, 100, 1000, mySimpEps);
+
+ mySimpEps->setValidator(validator);
+ mySimpEps->setText("1e-4");
+
myWarning = new QLabel(QString("<b>%1</b>").arg(tr("NON_TETRA_MESH_WARNING")), mainFrame());
// Fill layout
aLay->addWidget( objectWg( 0, Label ), 0, 0 );
aLay->addWidget( objectWg( 0, Btn ), 0, 1 );
aLay->addWidget( objectWg( 0, Control ), 0, 2 );
- aLay->addWidget( myWarning, 3, 0, 1, 3 );
aLay->addWidget( myMeshNameLabel, 1, 0 );
aLay->addWidget( myMeshName, 1, 2 );
- aLay->addWidget( myProjShape, 2, 0 );
+ aLay->addWidget( myProjShape, 2, 0 );
+ aLay->addWidget( mySimplify, 3, 0 );
+ aLay->addWidget( mySimpEps, 3, 1 );
+ aLay->addWidget( myWarning, 4, 0, 1, 3 );
}
bool SMESHGUI_CreateDualMeshDlg::isWarningShown()
{
return myWarning->isVisible();
-}
\ No newline at end of file
+}
+
+void SMESHGUI_CreateDualMeshDlg::DisplayEps(bool on)
+{
+ std::cout << "DisplayEps" << on << std::endl;
+ if ( on )
+ mySimpEps->setEnabled(true);
+ else
+ mySimpEps->setDisabled(true);
+}
virtual ~SMESHGUI_CreateDualMeshDlg();
void ShowWarning(bool);
+ void DisplayEps(bool);
bool isWarningShown();
QLineEdit* myMeshName;
QCheckBox* myProjShape;
+ QCheckBox* mySimplify;
+ QLineEdit* mySimpEps;
signals:
void onClicked( int );
myDlg = new SMESHGUI_CreateDualMeshDlg( );
}
connect( myDlg, SIGNAL( onClicked( int ) ), SLOT( ConnectRadioButtons( int ) ) );
+ connect( myDlg->mySimplify, SIGNAL( toggled( bool ) ), SLOT( DisplayEps( bool ) ) );
myHelpFileName = "create_dual_mesh.html";
SMESH::SMESH_Mesh_var newMesh;
QByteArray newMeshName=myDlg->myMeshName->text().toUtf8();
bool adapt_to_shape=myDlg->myProjShape->isChecked();
+ bool simplify=myDlg->mySimplify->isChecked();
+ double eps=myDlg->mySimpEps->text().toDouble();
+ std::cout << "eps" << eps << std::endl;
try
{
- newMesh = gen->CreateDualMesh(mesh, newMeshName.constData(), adapt_to_shape);
+ newMesh = gen->CreateDualMesh(mesh, newMeshName.constData(), adapt_to_shape, simplify, eps);
if ( !newMesh->_is_nil() )
if ( _PTR(SObject) aSObject = SMESH::ObjectToSObject( newMesh ) )
<source>PROJ_SHAPE</source>
<translation>Project boundary elements on shape</translation>
</message>
+ <message>
+ <source>SIMPLIFY</source>
+ <translation>Simplify polyhedrons</translation>
+ </message>
</context>
<context>
<name>SMESHGUI_ConvToQuadOp</name>
<source>2D_FROM_3D_ELEMENTS</source>
<translation>2D from 3D</translation>
</message>
-</context>
+</context>
<context>
<name>SMESHGUI_Make2DFrom3DDlg</name>
<message>
<source>PROJ_SHAPE</source>
<translation>Projection des élements de bord sur la géométrie</translation>
</message>
+ <message>
+ <source>SIMPLIFY</source>
+ <translation>Simplification des polyèdres</translation>
+ </message>
</context>
<context>
<name>SMESHGUI_ConvToQuadOp</name>
<source>2D_FROM_3D_ELEMENTS</source>
<translation>Faces des éléments volumiques</translation>
</message>
-</context>
+</context>
<context>
<name>SMESHGUI_Make2DFrom3DDlg</name>
<message>
SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateDualMesh(SMESH::SMESH_IDSource_ptr mesh,
const char* meshName,
- CORBA::Boolean adapt_to_shape)
+ CORBA::Boolean adapt_to_shape,
+ CORBA::Boolean simplify,
+ CORBA::Double eps_poly
+ )
{
Unexpect aCatch(SALOME_SalomeException);
gstate = PyGILState_Ensure();
- std::string ats;
+ // Converting arugments in string
+ std::string ats = "False";
if(adapt_to_shape)
ats = "True";
- else
- ats = "False";
- std::string cmd="import salome.smesh.smesh_tools as smt\n";
- cmd +="smt.smesh_create_dual_mesh(\"" + mesh_ior + "\", r\"" +
- dual_mesh_file.string() + "\", mesh_name=\"" + mesh_name + "\", adapt_to_shape=" + ats + ")";
- MESSAGE(cmd);
+ std::string sp="False";
+ if(simplify)
+ sp = "True";
+ std::ostringstream ss;
+ ss << eps_poly;
+
+ std::string cmd="import salome.smesh.smesh_tools as smt\n";
+ cmd +="smt.smesh_create_dual_mesh(\"" + mesh_ior + "\"" +
+ ", r\"" + dual_mesh_file.string() + "\"" +
+ ", mesh_name=\"" + mesh_name + "\"" +
+ ", adapt_to_shape=" + ats +
+ ", simplify_poly=" + sp +
+ ", eps_poly=" + ss.str() + ")";
+ MESSAGE("Dual mesh python command" + cmd);
+
+ // Calling code in Python Interperter
PyObject *py_main = PyImport_AddModule("__main__");
PyObject *py_dict = PyModule_GetDict(py_main);
PyObject *local_dict = PyDict_New();
// Create dual mesh of a tetrahedron mesh
SMESH::SMESH_Mesh_ptr CreateDualMesh(SMESH::SMESH_IDSource_ptr meshPart,
const char* meshName,
- CORBA::Boolean adapt_to_shape);
+ CORBA::Boolean adapt_to_shape,
+ CORBA::Boolean simplify,
+ CORBA::Double eps);
// Copy a part of mesh
SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
aMesh = Mesh( self, self.geompyD, aSmeshMesh, name=name )
return aMesh
- def CreateDualMesh( self, mesh, meshName, adaptToShape):
+ def CreateDualMesh( self, mesh, meshName="", adaptToShape=True, simplify=False, eps=1e-4):
"""
Create a dual of a mesh.
:class:`mesh, <SMESH.SMESH_IDSource>`.
meshName: a name of the new mesh
- adpatToShape: if true project boundary points on shape
+ adaptToShape: if true project boundary points on shape
+ simplify: if true will merge coplanar face of polyhedrons
+ eps: threshold to define if two face are coplanar
Returns:
an instance of class :class:`Mesh`
"""
if isinstance( mesh, Mesh ):
mesh = mesh.GetMesh()
- dualMesh = SMESH._objref_SMESH_Gen.CreateDualMesh(self, mesh, meshName, adaptToShape)
+ dualMesh = SMESH._objref_SMESH_Gen.CreateDualMesh(self, mesh, meshName,
+ adaptToShape, simplify, eps)
return Mesh(self, self.geompyD, dualMesh)
#!/usr/bin/env python3
+from os import environ
import salome
import medcoupling as mc
from salome.kernel.logger import Logger
logger = Logger("salome.smesh.smesh_tools")
-logger.setLevel("WARNING")
+if environ.get("SALOME_VERBOSE", "0") > "1":
+ logger.setLevel("DEBUG")
+else:
+ logger.setLevel("WARNING")
# prefix for groups with internal usage
# i.e. used to transfer the faces and edges sub-shapes ids to the mesh
pass
def smesh_create_dual_mesh(mesh_ior, output_file, adapt_to_shape=True,
- mesh_name="MESH"):
+ mesh_name="MESH", simplify_poly=False, eps_poly=1e-4):
""" Create a dual of the mesh in input_file into output_file
Args:
shape = mesh.GetShapeToMesh()
if adapt_to_shape:
+ logger.debug("Projecting on shape")
faces = geompy.SubShapeAll(shape, geompy.ShapeType["FACE"])
faces_ids = geompy.GetSubShapesIDs(shape, faces)
tetras = mc.MEDCoupling1SGTUMesh(tetras)
# Create the polyhedra from the tetrahedra (main goal of this function)
+ logger.debug("Computing dual mesh")
polyh = tetras.computeDualMesh()
+ umesh = polyh.buildUnstructured()
+
+ if (simplify_poly):
+ logger.debug("Simplifying polyhedrons")
+ umesh.simplifyPolyhedra(eps_poly)
+ logger.debug("Colinearize edges")
+ #umesh.colinearizeEdges(eps_poly)
+
+ bad_cells = umesh.arePolyhedronsNotCorrectlyOriented()
+ if not bad_cells.empty():
+ logger.debug("Reorienting polyhedrons")
+ try:
+ umesh.orientCorrectlyPolyhedrons()
+ except Exception as exp:
+ print("Could not reorient Polyhedron")
+ print(exp)
## Adding skin + transfering groups on faces from tetras mesh
- mesh2d = polyh.buildUnstructured().computeSkin()
+ logger.debug("Computing Skin")
+ mesh2d = umesh.computeSkin()
mesh2d.setName(mesh_name)
- polyh_coords = polyh.getCoords()
+ polyh_coords = umesh.getCoords()
treated_edges = []
mc_groups = []
+ logger.debug("Transferring groups")
for grp_name in mc_mesh_file.getGroupsOnSpecifiedLev(-1):
# This group is created by the export
if grp_name == "Group_Of_All_Faces":
logger.debug("Creating file with mesh: "+mesh_name)
myfile = mc.MEDFileUMesh()
myfile.setName(mesh_name)
- polyh.setName(mesh_name)
- myfile.setMeshAtLevel(0, polyh)
+ umesh.setName(mesh_name)
+ myfile.setMeshAtLevel(0, umesh)
myfile.setMeshAtLevel(-1, mesh2d)
for group in mc_groups: