Salome HOME
Merge remote-tracking branch 'origin/rnv/vtk_opengl2_backend' into V8_1_BR
[modules/paravis.git] / src / Plugins / MEDReader / IO / vtkELNOMeshFilter.cxx
index c0bfddd4a089421896325b85f55c7089d113633a..62aa3e6e4ebd3058c1ecf34b1392359fa6c65a84 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2010-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2010-2016  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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -41,7 +41,7 @@
 
 vtkStandardNewMacro(vtkELNOMeshFilter);
 
-vtkELNOMeshFilter::vtkELNOMeshFilter()
+vtkELNOMeshFilter::vtkELNOMeshFilter():ShrinkFactor(0.9999)
 {
 }
 
@@ -71,7 +71,7 @@ int vtkELNOMeshFilter::RequestData(vtkInformation *request,
   usgInClone->ShallowCopy(usgIn);
   vtkSmartPointer<vtkShrinkFilter> shrink(vtkSmartPointer<vtkShrinkFilter>::New());
   shrink->SetInputData(usgInClone);
-  shrink->SetShrinkFactor(0.9999);
+  shrink->SetShrinkFactor(this->ShrinkFactor);
   shrink->Update();
   vtkUnstructuredGrid *shrinked(shrink->GetOutput());
   usgInClone->Delete();
@@ -108,7 +108,7 @@ int vtkELNOMeshFilter::RequestData(vtkInformation *request,
   for(int index = 0; index < fielddata->GetNumberOfArrays(); index++)
     {
       vtkDataArray *data(fielddata->GetArray(index));
-      vtkQuadratureSchemeDefinition **dict(0);
+      vtkQuadratureSchemeDefinition **dict = 0;
       vtkInformationQuadratureSchemeDefinitionVectorKey *key(vtkQuadratureSchemeDefinition::DICTIONARY());
       if(key->Has(data->GetInformation()))
         {
@@ -117,18 +117,23 @@ int vtkELNOMeshFilter::RequestData(vtkInformation *request,
           key->GetRange(data->GetInformation(),dict,0,0,dictSize);
         }
       if(data == NULL)
-        continue;
+        {
+          delete [] dict;
+          continue;
+        }
       
       vtkInformation *info(data->GetInformation());
-      const char *arrayOffsetName = info->Get(vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME());
-
-      bool isELGA(false);
+      const char *arrayOffsetName(info->Get(vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME()));
+      vtkIdTypeArray *offData(0);
+      bool isELGA(false),isELNO(false);
 
       if(arrayOffsetName)
         {
           vtkFieldData *cellData(usgIn->GetCellData());
-          vtkDataArray *offData(cellData->GetArray(arrayOffsetName));
-          isELGA=offData->GetInformation()->Get(MEDUtilities::ELGA())==1;
+          vtkDataArray *offDataTmp(cellData->GetArray(arrayOffsetName));
+          isELGA=offDataTmp->GetInformation()->Get(MEDUtilities::ELGA())==1;
+          isELNO=offDataTmp->GetInformation()->Get(MEDUtilities::ELNO())==1;
+          offData=dynamic_cast<vtkIdTypeArray *>(offDataTmp);
         }
 
       if(arrayOffsetName == NULL || isELGA)
@@ -137,43 +142,64 @@ int vtkELNOMeshFilter::RequestData(vtkInformation *request,
             usgOut->GetPointData()->AddArray(data);
           else
             shrinked->GetFieldData()->AddArray(data);
+          delete [] dict;
           continue;
         }
       else
         {
-          vtkDataArray* newArray = data->NewInstance();
+          vtkDataArray *newArray(data->NewInstance());
           newArray->SetName(data->GetName());
           usgOut->GetPointData()->AddArray(newArray);
           newArray->SetNumberOfComponents(data->GetNumberOfComponents());
           newArray->SetNumberOfTuples(usgOut->GetNumberOfPoints());
           newArray->CopyComponentNames(data);
           newArray->Delete();
-          vtkIdList *ids(vtkIdList::New());
-          vtkIdType offset(0);
-          for(vtkIdType cellId = 0; cellId < ncell; cellId++)
+          if(isELGA)
             {
-              int cellType = shrinked->GetCellType(cellId);
-              shrinked->GetCellPoints(cellId, ids);
-              for(int id = 0; id < dict[cellType]->GetNumberOfQuadraturePoints(); id++)
+              vtkIdList *ids(vtkIdList::New());
+              vtkIdType offset(0);
+              for(vtkIdType cellId=0;cellId<ncell;cellId++)
                 {
-                  const double * w = dict[cellType]->GetShapeFunctionWeights(id);
-                  int j;
-                  for(j = 0; j < dict[cellType]->GetNumberOfNodes(); j++)
+                  int cellType(shrinked->GetCellType(cellId));
+                  shrinked->GetCellPoints(cellId, ids);
+                  for(int id = 0; id < dict[cellType]->GetNumberOfQuadraturePoints(); id++)
                     {
-                      if(w[j] == 1.0)
-                        break;
+                      const double * w = dict[cellType]->GetShapeFunctionWeights(id);
+                      int j;
+                      for(j = 0; j < dict[cellType]->GetNumberOfNodes(); j++)
+                        {
+                          if(w[j] == 1.0)
+                            break;
+                        }
+                      if(j == dict[cellType]->GetNumberOfNodes())
+                        {
+                          j = id;
+                        }
+                      newArray->SetTuple(ids->GetId(id), offset + j, data);
                     }
-                  if(j == dict[cellType]->GetNumberOfNodes())
-                    {
-                      j = id;
-                    }
-                  newArray->SetTuple(ids->GetId(id), offset + j, data);
+                  vtkCell *cell(usgIn->GetCell(cellId));
+                  vtkIdType nbptsInCell(cell->GetNumberOfPoints());
+                  offset+=nbptsInCell;
                 }
-              vtkCell *cell(usgIn->GetCell(cellId));
-              vtkIdType nbptsInCell(cell->GetNumberOfPoints());
-              offset+=nbptsInCell;
+              ids->FastDelete();
+            }
+          else if(offData && isELNO)
+            {
+              vtkIdType *offsetPtr(offData->GetPointer(0));
+              vtkIdType zeId(0);
+              for(vtkIdType cellId=0;cellId<ncell;cellId++)
+                {
+                  vtkCell *cell(shrinked->GetCell(cellId));
+                  vtkIdType nbPoints(cell->GetNumberOfPoints()),offset(offsetPtr[cellId]);
+                  for(vtkIdType j=0;j<nbPoints;j++,zeId++)
+                    newArray->SetTuple(zeId,offsetPtr[cellId]+j,data);
+                }
+            }
+          else
+            {
+              delete [] dict;
+              continue ;
             }
-          ids->FastDelete();
         }
       delete [] dict;
     }