0021952: Add an option to write planar meshes as 3D meshes in MED files

This commit is contained in:
eap 2013-06-05 15:13:53 +00:00
parent dfe28da84c
commit 4fecefcc2b
14 changed files with 167 additions and 101 deletions

View File

@ -16,23 +16,43 @@ idbox = geompy.addToStudy(box, "box")
# create a mesh
tetra = smesh.Mesh(box, "MeshBox")
algo1D = tetra.Segment()
algo1D.NumberOfSegments(7)
algo2D = tetra.Triangle()
algo2D.MaxElementArea(800.)
algo3D = tetra.Tetrahedron()
algo3D.MaxElementVolume(900.)
tetra.Segment().NumberOfSegments(7)
tetra.Triangle()
tetra.Tetrahedron()
# compute the mesh
tetra.Compute()
# export the mesh in a MED file
tetra.ExportMED("/tmp/meshMED.med", 0)
import tempfile
medFile = tempfile.NamedTemporaryFile(suffix=".med").name
tetra.ExportMED( medFile, 0 )
# export a group in a MED file
face = geompy.SubShapeAll( box, geompy.ShapeType["FACE"])[0] # a box side
group = tetra.GroupOnGeom( face, "face group" ) # group of 2D elements on the <face>
tetra.ExportMED("/tmp/groupMED.med", meshPart=group)
tetra.ExportMED( medFile, meshPart=group )
# ========================
# autoDimension parameter
# ========================
face = geompy.MakeFaceHW( 10, 10, 1, "rectangle" )
mesh2D = smesh.Mesh( face, "mesh2D" )
mesh2D.AutomaticHexahedralization(0)
import MEDLoader, os
# exported mesh is in 2D space because it is a planar mesh lying
# on XOY plane, and autoDimension=True by default
mesh2D.ExportMED( medFile )
medMesh = MEDLoader.MEDLoader.ReadUMeshFromFile(medFile,mesh2D.GetName(),0)
print "autoDimension==True, exported mesh is in %sD"%medMesh.getSpaceDimension()
# exported mesh is in 3D space, same as in Mesh module,
# thanks to autoDimension=False
mesh2D.ExportMED( medFile, autoDimension=False )
medMesh = MEDLoader.MEDLoader.ReadUMeshFromFile(medFile,mesh2D.GetName(),0)
print "autoDimension==False, exported mesh is in %sD"%medMesh.getSpaceDimension()
os.remove( medFile )

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -2,19 +2,22 @@
\page importing_exporting_meshes_page Importing and exporting meshes
\n In MESH there is a functionality allowing importation/exportation
\n In MESH there is a functionality allowing import/export
of meshes from/to \b MED, \b UNV (I-DEAS 10), \b DAT (simple ascii format), \b STL,
\b GMF (internal format of DISTENE products, namely BLSurf, GHS3D and Hexotic algorithms) and \b CGNS format files. You can also export a group as a whole mesh.
\b GMF (internal format of DISTENE products, namely BLSurf, GHS3D and
Hexotic algorithms) and \b CGNS format files. You can also export a
group as a whole mesh.
<em>To import a mesh:</em>
<ol>
<li>From the \b File menu choose the \b Import item, from its sub-menu
select the corresponding format (MED, UNV, STL, GMF and CGNS) of the file containing
your mesh.</li>
select the corresponding format (MED, UNV, STL, GMF and CGNS) of the
file containing your mesh.</li>
<li>In the standard <b>Search File</b> dialog box find the file for
importation. It is possible to select multiple files to be imported all at once. </li>
import. It is possible to select multiple files to be imported all at
once. </li>
<li>Click the \b OK button.</li>
</ol>
@ -35,6 +38,24 @@ exported file and enter its name.</li>
\image html meshexportmesh.png
At export to MED and SAUV format files additional parameters are available.
<ul>
<li><b>Automatically create groups</b> check-box specifies whether to
create groups of all mesh entities of available dimensions or
not. If checked, the created groups have names like "Group_On_All_Nodes",
"Group_On_All_Faces" etc.</li>
<li><b>Automatically define space dimension</b> check-box specifies
whether to define space dimension for export by mesh configuration
or not. Usually the mesh is exported as a mesh in 3D space, just as
it is in Mesh module. The mesh can be exported as a mesh in lower
dimension in following cases, provided that this check-box is
checked.
<ul>
<li> 1D: if all mesh nodes lie on OX coordinate axis. </li>
<li> 2D: if all mesh nodes lie on XOY coordinate plane. </li>
</ul>
</li>
</ul>
<br><b>See Also</b> a sample TUI Script of an \ref tui_export_mesh "Export Mesh" operation.
*/

View File

@ -20,7 +20,7 @@
<br>
\anchor tui_editing_mesh
<h2>Editing of a mesh</h2>
<h2>Editing a mesh</h2>
\tui_script{creating_meshes_ex04.py}
<br>

View File

@ -596,7 +596,7 @@ module SMESH
boolean HasDuplicatedGroupNamesMED();
/*!
* Export Mesh to different MED Formats
* Export Mesh to a MED Format file
* @params
* - file : name of the MED file
* - auto_groups : boolean parameter for creating/not creating
@ -604,11 +604,18 @@ module SMESH
* the typical use is auto_groups=false.
* - version : define the version of format of MED file, that will be created
* - overwrite : boolean parameter for overwriting/not overwriting the file, if it exists
* - autoDimension: if @c True (default), a space dimension of a MED mesh can be either
* - 1D if all mesh nodes lie on OX coordinate axis, or
* - 2D if all mesh nodes lie on XOY coordinate plane, or
* - 3D in the rest cases.
*
* If @a autoDimension is @c False, the space dimension is always 3.
*/
void ExportToMEDX( in string file,
in boolean auto_groups,
in MED_VERSION version,
in boolean overwrite ) raises (SALOME::SALOME_Exception);
in boolean overwrite,
in boolean autoDimension ) raises (SALOME::SALOME_Exception);
/*!
* Export a part of Mesh into a MED file
@ -617,15 +624,20 @@ module SMESH
* - file : name of the MED file
* - version : define the version of format of MED file, that will be created
* - overwrite : boolean parameter for overwriting/not overwriting the file, if it exists
* - autoDimension: if @c True, a space dimension for export is defined by mesh
* configuration; for example a planar mesh lying on XOY plane
* will be exported as a mesh in 2D space.
* If @a autoDimension == @c False, the space dimension is 3.
*/
void ExportPartToMED( in SMESH_IDSource meshPart,
in string file,
in boolean auto_groups,
in MED_VERSION version,
in boolean overwrite ) raises (SALOME::SALOME_Exception);
in boolean overwrite,
in boolean autoDimension ) raises (SALOME::SALOME_Exception);
/*!
* Export Mesh to different MED Formats
* Export Mesh to a MED Format file
* Works, just the same as ExportToMEDX, with overwrite parameter equal to true.
* The method is kept in order to support old functionality
*/

View File

@ -52,7 +52,8 @@ DriverMED_W_SMESHDS_Mesh::DriverMED_W_SMESHDS_Mesh():
myDoGroupOfFaces (false),
myDoGroupOfVolumes (false),
myDoGroupOf0DElems(false),
myDoGroupOfBalls(false)
myDoGroupOfBalls(false),
myAutoDimension(true)
{}
void DriverMED_W_SMESHDS_Mesh::SetFile(const std::string& theFileName,
@ -120,7 +121,8 @@ void DriverMED_W_SMESHDS_Mesh::AddGroupOfVolumes()
myDoGroupOfVolumes = true;
}
namespace{
namespace
{
typedef double (SMDS_MeshNode::* TGetCoord)() const;
typedef const char* TName;
typedef const char* TUnit;
@ -311,12 +313,13 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform()
}
// Mesh dimension definition
TInt aSpaceDimension;
TInt aSpaceDimension = 3;
TCoordHelperPtr aCoordHelperPtr;
{
bool anIsXDimension = false;
bool anIsYDimension = false;
bool anIsZDimension = false;
if ( myAutoDimension )
{
SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
double aBounds[6];

View File

@ -48,6 +48,7 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh
virtual void SetFile(const std::string& theFileName);
void SetFile(const std::string& theFileName, MED::EVersion theId);
void SetAutoDimension(bool toFindOutDimension) { myAutoDimension = toFindOutDimension; }
static std::string GetVersionString(const MED::EVersion theVersion, int theNbDigits=2);
/*! sets file name; only for usage with Add(), not Write()
@ -81,6 +82,7 @@ class MESHDRIVERMED_EXPORT DriverMED_W_SMESHDS_Mesh: public Driver_SMESHDS_Mesh
bool myDoGroupOfVolumes;
bool myDoGroupOf0DElems;
bool myDoGroupOfBalls;
bool myAutoDimension;
};

View File

@ -1248,7 +1248,8 @@ void SMESH_Mesh::ExportMED(const char * file,
const char* theMeshName,
bool theAutoGroups,
int theVersion,
const SMESHDS_Mesh* meshPart)
const SMESHDS_Mesh* meshPart,
bool theAutoDimension)
throw(SALOME_Exception)
{
Unexpect aCatch(SalomeException);
@ -1256,6 +1257,7 @@ void SMESH_Mesh::ExportMED(const char * file,
DriverMED_W_SMESHDS_Mesh myWriter;
myWriter.SetFile ( file, MED::EVersion(theVersion) );
myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
myWriter.SetAutoDimension( theAutoDimension );
if ( !theMeshName )
myWriter.SetMeshId ( _id );
else {

View File

@ -229,11 +229,12 @@ public:
*/
bool HasDuplicatedGroupNamesMED();
void ExportMED(const char *file,
void ExportMED(const char * theFile,
const char* theMeshName = NULL,
bool theAutoGroups = true,
int theVersion = 0,
const SMESHDS_Mesh* meshPart = 0)
const SMESHDS_Mesh* theMeshPart = 0,
bool theAutoDimension = false)
throw(SALOME_Exception);
void ExportDAT(const char * file,

View File

@ -591,6 +591,7 @@
if ( resMgr )
toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
bool toOverwrite = true;
bool toFindOutDim = true;
QString aFilter, aTitle = QObject::tr("SMESH_EXPORT_MESH");
QString anInitialPath = "";
@ -612,32 +613,6 @@
anInitialPath + QString("/") + aMeshName,
aFilter, aTitle, false);
}
// else if ( isGMF )// Export to GMF
// {
// SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
// ( SMESHGUI::desktop(), false, QObject::tr("SMESH_REQUIRED_GROUPS"), true, true );
// QStringList filters;
// filters << QObject::tr( "GMF_ASCII_FILES_FILTER" ) + " (*.mesh)"
// << QObject::tr( "GMF_BINARY_FILES_FILTER" ) + " (*.meshb)";
// fd->setWindowTitle( aTitle );
// fd->setNameFilters( filters );
// if ( !aMeshOrGroup->_is_equivalent( aMesh ))
// toCreateGroups = false;
// else
// toCreateGroups = ( aMesh->NbGroups() > 0 );
// fd->SetChecked( true );
// if ( !anInitialPath.isEmpty() )
// fd->setDirectory( anInitialPath );
// fd->selectFile(aMeshName);
// if ( fd->exec() )
// aFilename = fd->selectedFile();
// toCreateGroups = fd->IsChecked();
// delete fd;
// }
else if ( isCGNS )// Export to CGNS
{
SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
@ -705,13 +680,16 @@
if (it.value() == SMESH::MED_V2_2)
aDefaultFilter = it.key();
}
QStringList checkBoxes;
checkBoxes << QObject::tr("SMESH_AUTO_GROUPS") << QObject::tr("SMESH_AUTO_DIM");
SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg
( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS"), true, true );
SalomeApp_CheckFileDlg* fd =
new SalomeApp_CheckFileDlg ( SMESHGUI::desktop(), false, checkBoxes, true, true );
fd->setWindowTitle( aTitle );
fd->setNameFilters( filters );
fd->selectNameFilter(aDefaultFilter);
fd->SetChecked(toCreateGroups);
fd->SetChecked(0,toCreateGroups);
fd->SetChecked(1,toFindOutDim);
if ( !anInitialPath.isEmpty() )
fd->setDirectory( anInitialPath );
fd->selectFile(aMeshName);
@ -794,7 +772,8 @@
}
}
}
toCreateGroups = fd->IsChecked();
toCreateGroups = fd->IsChecked(0);
toFindOutDim = fd->IsChecked(1);
delete fd;
}
else
@ -833,10 +812,10 @@
SMESH::SMESH_Mesh_var aMeshItem = aMeshOrGroup->GetMesh();
if ( aMeshOrGroup->_is_equivalent( aMeshItem ))
aMeshItem->ExportToMEDX( aFilename.toLatin1().data(), toCreateGroups,
aFormat, toOverwrite && aMeshIndex == 0 );
aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim );
else
aMeshItem->ExportPartToMED( aMeshOrGroup, aFilename.toLatin1().data(), toCreateGroups,
aFormat, toOverwrite && aMeshIndex == 0 );
aFormat, toOverwrite && aMeshIndex == 0, toFindOutDim );
}
}
else if ( isSAUV )

View File

@ -1269,6 +1269,10 @@ Please enter correct values and try again</translation>
<source>SMESH_AUTO_GROUPS</source>
<translation>Automatically create groups</translation>
</message>
<message>
<source>SMESH_AUTO_DIM</source>
<translation>Automatically define space dimension</translation>
</message>
<message>
<source>SMESH_REQUIRED_GROUPS</source>
<translation>Create groups of required entities</translation>

View File

@ -2708,7 +2708,8 @@ string SMESH_Mesh_i::prepareMeshNameAndGroups(const char* file,
void SMESH_Mesh_i::ExportToMEDX (const char* file,
CORBA::Boolean auto_groups,
SMESH::MED_VERSION theVersion,
CORBA::Boolean overwrite)
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension)
throw(SALOME::SALOME_Exception)
{
Unexpect aCatch(SALOME_SalomeException);
@ -2717,9 +2718,11 @@ void SMESH_Mesh_i::ExportToMEDX (const char* file,
string aMeshName = prepareMeshNameAndGroups(file, overwrite);
TPythonDump() << _this() << ".ExportToMEDX( r'"
<< file << "', " << auto_groups << ", " << theVersion << ", " << overwrite << " )";
<< file << "', " << auto_groups << ", "
<< theVersion << ", " << overwrite << ", "
<< autoDimension << " )";
_impl->ExportMED( file, aMeshName.c_str(), auto_groups, theVersion );
_impl->ExportMED( file, aMeshName.c_str(), auto_groups, theVersion, 0, autoDimension );
}
//================================================================================
@ -2848,10 +2851,19 @@ void SMESH_Mesh_i::ExportPartToMED(::SMESH::SMESH_IDSource_ptr meshPart,
const char* file,
CORBA::Boolean auto_groups,
::SMESH::MED_VERSION version,
::CORBA::Boolean overwrite)
::CORBA::Boolean overwrite,
::CORBA::Boolean autoDimension)
throw (SALOME::SALOME_Exception)
{
Unexpect aCatch(SALOME_SalomeException);
TPythonDump pyDump;
if ( SMESH_Mesh_i * mesh = SMESH::DownCast< SMESH_Mesh_i* >( meshPart ))
{
mesh->ExportToMEDX( file, auto_groups, version, autoDimension );
}
else
{
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
@ -2867,10 +2879,11 @@ void SMESH_Mesh_i::ExportPartToMED(::SMESH::SMESH_IDSource_ptr meshPart,
}
}
SMESH_MeshPartDS partDS( meshPart );
_impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, &partDS );
TPythonDump() << _this() << ".ExportPartToMED( " << meshPart << ", r'" << file << "', "
<< auto_groups << ", " << version << ", " << overwrite << " )";
_impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, &partDS, autoDimension );
}
pyDump << _this() << ".ExportPartToMED( " << meshPart << ", r'" << file << "', "
<< auto_groups << ", " << version << ", " << overwrite << ", "
<< autoDimension << " )";
}
//================================================================================

View File

@ -231,7 +231,8 @@ public:
void ExportToMEDX( const char* file,
CORBA::Boolean auto_groups,
SMESH::MED_VERSION version,
CORBA::Boolean overwrite ) throw (SALOME::SALOME_Exception);
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension=true) throw (SALOME::SALOME_Exception);
void ExportToMED ( const char* file,
CORBA::Boolean auto_groups,
SMESH::MED_VERSION version ) throw (SALOME::SALOME_Exception);
@ -254,7 +255,8 @@ public:
const char* file,
CORBA::Boolean auto_groups,
SMESH::MED_VERSION version,
CORBA::Boolean overwrite) throw (SALOME::SALOME_Exception);
CORBA::Boolean overwrite,
CORBA::Boolean autoDim=true) throw (SALOME::SALOME_Exception);
void ExportPartToDAT(SMESH::SMESH_IDSource_ptr meshPart,
const char* file) throw (SALOME::SALOME_Exception);
void ExportPartToUNV(SMESH::SMESH_IDSource_ptr meshPart,

View File

@ -1567,14 +1567,21 @@ class Mesh:
# @param version MED format version(MED_V2_1 or MED_V2_2)
# @param overwrite boolean parameter for overwriting/not overwriting the file
# @param meshPart a part of mesh (group, sub-mesh) to export instead of the mesh
# @param autoDimension: if @c True (default), a space dimension of a MED mesh can be either
# - 1D if all mesh nodes lie on OX coordinate axis, or
# - 2D if all mesh nodes lie on XOY coordinate plane, or
# - 3D in the rest cases.
#
# If @a autoDimension is @c False, the space dimension is always 3.
# @ingroup l2_impexp
def ExportMED(self, f, auto_groups=0, version=MED_V2_2, overwrite=1, meshPart=None):
def ExportMED(self, f, auto_groups=0, version=MED_V2_2,
overwrite=1, meshPart=None, autoDimension=True):
if meshPart:
if isinstance( meshPart, list ):
meshPart = self.GetIDSource( meshPart, SMESH.ALL )
self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite )
self.mesh.ExportPartToMED( meshPart, f, auto_groups, version, overwrite, autoDimension)
else:
self.mesh.ExportToMEDX(f, auto_groups, version, overwrite)
self.mesh.ExportToMEDX(f, auto_groups, version, overwrite, autoDimension)
## Exports the mesh in a file in SAUV format
# @param f is the file name