]> SALOME platform Git repositories - modules/paravis.git/commitdiff
Salome HOME
Merge branch 'master' into V7_5_BR
authorvsr <vsr@opencascade.com>
Fri, 12 Dec 2014 08:54:35 +0000 (11:54 +0300)
committervsr <vsr@opencascade.com>
Fri, 12 Dec 2014 08:54:35 +0000 (11:54 +0300)
src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.cxx
src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.hxx
src/Plugins/MEDReader/Test/CMakeLists.txt
src/Plugins/MEDReader/Test/testMEDReader15.py [new file with mode: 0644]

index f9df2d33974bacfe112dee019db869aff28bb8e5..6cf1d8034caae68beeeadd883a4de46d51dd91c9 100644 (file)
@@ -1104,6 +1104,14 @@ void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileNam
         {
 #ifdef MEDREADER_USE_MPI
           _ms=ParaMEDFileMeshes::New(iPart,nbOfParts,fileName);
+          int nbMeshes(_ms->getNumberOfMeshes());
+          for(int i=0;i<nbMeshes;i++)
+            {
+              ParaMEDMEM::MEDFileMesh *tmp(_ms->getMeshAtPos(i));
+              ParaMEDMEM::MEDFileUMesh *tmp2(dynamic_cast<ParaMEDMEM::MEDFileUMesh *>(tmp));
+              if(tmp2)
+                MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp3(tmp2->zipCoords());
+            }
           _fields=MEDFileFields::LoadPartOf(fileName,false,_ms);//false is important to not read the values
 #else
           std::ostringstream oss; oss << "MEDFileFieldRepresentationTree::loadMainStructureOfFile : request for iPart/nbOfParts=" << iPart << "/" << nbOfParts << " whereas Plugin not compiled with MPI !";
@@ -1387,6 +1395,8 @@ void MEDFileFieldRepresentationTree::printMySelf(std::ostream& os) const
 
 void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms, ParaMEDMEM::MEDFileFields *ret)
 {
+  if(!ret)
+    throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationTree::AppendFieldFromMeshes : internal error ! NULL ret !");
   for(int i=0;i<ms->getNumberOfMeshes();i++)
     {
       MEDFileMesh *mm(ms->getMeshAtPos(i));
@@ -1407,7 +1417,7 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED
                  arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
                  arr->iota();
                  f->setArray(arr);
-                 f->setName(mm->getName());
+                 f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
                  f1tsMultiLev->setFieldNoProfileSBT(f);
                }
            }
@@ -1422,7 +1432,7 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED
                  ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> arr(ParaMEDMEM::DataArrayDouble::New()); arr->alloc(m->getNumberOfNodes());
                  arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
                  arr->iota(); f->setArray(arr);
-                 f->setName(mm->getName());
+                 f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
                  f1tsMultiLev->setFieldNoProfileSBT(f);
                }
              else
@@ -1438,7 +1448,7 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED
          arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA));
          arr->iota();
          f->setArray(arr);
-         f->setName(mm->getName());
+         f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret));
          f1tsMultiLev->setFieldNoProfileSBT(f);
        }
       //
@@ -1448,6 +1458,20 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED
     }
 }
 
+std::string MEDFileFieldRepresentationTree::BuildAUniqueArrayNameForMesh(const std::string& meshName, const ParaMEDMEM::MEDFileFields *ret)
+{
+  static const char KEY_STR_TO_AVOID_COLLIDE[]="MESH@";
+  if(!ret)
+    throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationTree::BuildAUniqueArrayNameForMesh : internal error ! NULL ret !");
+  std::vector<std::string> fieldNamesAlreadyExisting(ret->getFieldsNames());
+  if(std::find(fieldNamesAlreadyExisting.begin(),fieldNamesAlreadyExisting.end(),meshName)==fieldNamesAlreadyExisting.end())
+    return meshName;
+  std::string tmpName(KEY_STR_TO_AVOID_COLLIDE); tmpName+=meshName;
+  while(std::find(fieldNamesAlreadyExisting.begin(),fieldNamesAlreadyExisting.end(),tmpName)!=fieldNamesAlreadyExisting.end())
+    tmpName=std::string(KEY_STR_TO_AVOID_COLLIDE)+tmpName;
+  return tmpName;
+}
+
 ParaMEDMEM::MEDFileFields *MEDFileFieldRepresentationTree::BuildFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms)
 {
   ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFields> ret(ParaMEDMEM::MEDFileFields::New());
index d184aa5791c53e016431d25d055ea4790508272b..4e557b59ed57ea3147f7412a327e749b007420d6 100644 (file)
@@ -163,6 +163,7 @@ private:
   const MEDFileFieldRepresentationLeaves& getTheSingleActivated(int& lev0, int& lev1, int& lev2) const;
   static ParaMEDMEM::MEDFileFields *BuildFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms);
   static void AppendFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms, ParaMEDMEM::MEDFileFields *ret);
+  static std::string BuildAUniqueArrayNameForMesh(const std::string& meshName, const ParaMEDMEM::MEDFileFields *ret);
   static std::vector<std::string> SplitFieldNameIntoParts(const std::string& fullFieldName, char sep);
 private:
   // 1st : timesteps, 2nd : meshName, 3rd : common support
index 44c5417e7efabee8415ca834870a5dd66cf5dd1e..bac570f67b269ce9cef5bcc6f9b82e3ab0a28292 100644 (file)
@@ -48,3 +48,5 @@ ADD_TEST(testMEDReader13 ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testME
 SET_TESTS_PROPERTIES(testMEDReader13 PROPERTIES ENVIRONMENT "${tests_env}")
 ADD_TEST(testMEDReader14 ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testMEDReader14.py)
 SET_TESTS_PROPERTIES(testMEDReader14 PROPERTIES ENVIRONMENT "${tests_env}")
+ADD_TEST(testMEDReader15 ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/testMEDReader15.py)
+SET_TESTS_PROPERTIES(testMEDReader15 PROPERTIES ENVIRONMENT "${tests_env}")
diff --git a/src/Plugins/MEDReader/Test/testMEDReader15.py b/src/Plugins/MEDReader/Test/testMEDReader15.py
new file mode 100644 (file)
index 0000000..2dbab65
--- /dev/null
@@ -0,0 +1,82 @@
+#  -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+#
+# 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
+#
+# Author : Anthony Geay (EDF R&D)
+
+from MEDLoader import *
+
+""" This test is a non regression test that checks the behaviour of MEDReader when a mesh has the same name than a field.
+"""
+
+fname="testMEDReader15.med"
+outImgName="testMEDReader15.png"
+
+zeName="zeName"
+c=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(0.,1.,0.)])
+m=MEDFileUMesh()
+m.setCoords(c)
+m.setName(zeName)
+m.write(fname,2)
+f=MEDCouplingFieldDouble(ON_NODES)
+f.setName(zeName)
+f.setArray(DataArrayDouble([(-1.,1.,0.),(0.,1.,0.),(1.,1.,0.)]))
+tmp=MEDCouplingUMesh.Build0DMeshFromCoords(m.getCoords()) ; tmp.setName(zeName)
+f.setMesh(tmp)
+MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f)
+#
+
+from paraview.simple import *
+
+paraview.simple._DisableFirstRenderCameraReset()
+reader=MEDReader(FileName=fname)
+ExpectedEntries=['TS0/zeName/ComSup0/zeName@@][@@P1','TS0/zeName/ComSup0/MESH@zeName@@][@@P1']
+assert(reader.GetProperty("FieldsTreeInfo")[::2]==ExpectedEntries)
+
+
+#
+glyph1=Glyph(Input=reader,GlyphType='Arrow',Scalars='FamilyIdNode',Vectors='zeName',GlyphMode='All Points',ScaleFactor=0.1,GlyphTransform='Transform2')
+
+renderView1=GetActiveViewOrCreate('RenderView')
+renderView1.InteractionMode='3D'
+zeNameLUT = GetColorTransferFunction('zeName')
+zeNameLUT.RGBPoints = [1.0, 0.231373, 0.298039, 0.752941, 1.2071067811865475, 0.865003, 0.865003, 0.865003, 1.4142135623730951, 0.705882, 0.0156863, 0.14902]
+zeNameLUT.ScalarRangeInitialized = 1.
+zeNameLUT.VectorMode = 'Component'
+
+glyph1Display=Show(glyph1,renderView1)
+glyph1Display.ColorArrayName = ['POINTS', 'FamilyIdNode']
+glyph1Display.LookupTable = zeNameLUT
+glyph1Display.OpacityArray = [None, '']
+glyph1Display.RadiusArray = [None, '']
+glyph1Display.RadiusRange = [-0.0707106813788414, 1.0099999904632568]
+glyph1Display.ConstantRadius = 1.0099999904632568
+glyph1Display.PointSpriteDefaultsInitialized = 1
+glyph1Display.SelectInputVectors = ['POINTS', 'GlyphVector']
+glyph1Display.WriteLog = ''
+# show color bar/color legend
+glyph1Display.SetScalarBarVisibility(renderView1, True)
+# set scalar coloring
+ColorBy(glyph1Display, ('POINTS', 'zeName'))
+# rescale color and/or opacity maps used to include current data range
+glyph1Display.RescaleTransferFunctionToDataRange(True)
+# show color bar/color legend
+glyph1Display.SetScalarBarVisibility(renderView1, True)
+#
+Render()
+WriteImage(outImgName)