Salome HOME
PR: synchro V7_main tag mergefrom_V6_main_06Mar13
[modules/smesh.git] / src / SMDS / SMDS_UnstructuredGrid.cxx
index 03b5d2337c676987b8237dffd32df6ebedf38ced..d3ea0b6209b38f50eb2cf7eec3763b69caecc765 100644 (file)
@@ -1,4 +1,22 @@
-#define CHRONODEF
+// Copyright (C) 2010-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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
+//
+
 #include "SMDS_UnstructuredGrid.hxx"
 #include "SMDS_Mesh.hxx"
 #include "SMDS_MeshInfo.hxx"
@@ -8,7 +26,9 @@
 #include "utilities.h"
 
 #include <vtkCellArray.h>
+#include <vtkCellData.h>
 #include <vtkCellLinks.h>
+#include <vtkDoubleArray.h>
 #include <vtkIdTypeArray.h>
 #include <vtkUnsignedCharArray.h>
 
@@ -23,14 +43,14 @@ SMDS_CellLinks* SMDS_CellLinks::New()
   return new SMDS_CellLinks();
 }
 
-vtkCellLinks::Link* SMDS_CellLinks::ResizeL(vtkIdType sz)
-{
-  return vtkCellLinks::Resize(sz);
-}
-
-vtkIdType SMDS_CellLinks::GetLinksSize()
+void SMDS_CellLinks::ResizeForPoint(vtkIdType vtkID)
 {
-  return this->Size;
+  if ( vtkID > this->MaxId )
+  {
+    this->MaxId = vtkID;
+    if ( vtkID >= this->Size ) 
+      vtkCellLinks::Resize( vtkID+SMDS_Mesh::chunkSize );
+  }
 }
 
 SMDS_CellLinks::SMDS_CellLinks() :
@@ -67,7 +87,8 @@ unsigned long SMDS_UnstructuredGrid::GetMTime()
   MESSAGE("vtkUnstructuredGrid::GetMTime: " << mtime);
   return mtime;
 }
-
+// OUV_PORTING_VTK6: seems to be useless
+/*
 void SMDS_UnstructuredGrid::Update()
 {
   MESSAGE("SMDS_UnstructuredGrid::Update");
@@ -79,7 +100,7 @@ void SMDS_UnstructuredGrid::UpdateInformation()
   MESSAGE("SMDS_UnstructuredGrid::UpdateInformation");
   return vtkUnstructuredGrid::UpdateInformation();
 }
-
+*/
 vtkPoints* SMDS_UnstructuredGrid::GetPoints()
 {
   // TODO erreur incomprehensible de la macro vtk GetPoints apparue avec la version paraview de fin aout 2010
@@ -133,7 +154,7 @@ void SMDS_UnstructuredGrid::setSMDS_mesh(SMDS_Mesh *mesh)
 void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int newNodeSize,
                                         std::vector<int>& idCellsOldToNew, int newCellSize)
 {
-  MESSAGE("------------------------- SMDS_UnstructuredGrid::compactGrid " << newNodeSize << " " << newCellSize);CHRONO(1);
+  MESSAGE("------------------------- SMDS_UnstructuredGrid::compactGrid " << newNodeSize << " " << newCellSize);//CHRONO(1);
   int alreadyCopied = 0;
 
   // --- if newNodeSize, create a new compacted vtkPoints
@@ -199,10 +220,12 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int n
       ++i;
     int endBloc = i;
     if ( endBloc > startBloc )
-      copyBloc(newTypes, idCellsOldToNew, idNodesOldToNew, newConnectivity, newLocations, pointsCell,
-               alreadyCopied, startBloc, endBloc);
+      copyBloc(newTypes,
+               idCellsOldToNew, idNodesOldToNew,
+               newConnectivity, newLocations,
+               pointsCell, alreadyCopied,
+               startBloc, endBloc);
   }
-
   newConnectivity->Squeeze();
 
   if (1/*newNodeSize*/)
@@ -212,6 +235,19 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int n
       MESSAGE("NumberOfPoints: " << this->GetNumberOfPoints());
     }
 
+  if (vtkDoubleArray* diameters =
+      vtkDoubleArray::SafeDownCast( vtkDataSet::CellData->GetScalars() )) // Balls
+  {
+    for (int oldCellID = 0; oldCellID < oldCellSize; oldCellID++)
+    {
+      if (this->Types->GetValue(oldCellID) == VTK_EMPTY_CELL)
+        continue;
+      int newCellId = idCellsOldToNew[ oldCellID ];
+      if (newTypes->GetValue(newCellId) == VTK_POLY_VERTEX)
+        diameters->SetValue( newCellId, diameters->GetValue( oldCellID ));
+    }
+  }
+
   if (this->FaceLocations)
     {
       vtkIdTypeArray *newFaceLocations = vtkIdTypeArray::New();
@@ -256,7 +292,9 @@ void SMDS_UnstructuredGrid::compactGrid(std::vector<int>& idNodesOldToNew, int n
       newFaces->Delete();
     }
   else
+  {
     this->SetCells(newTypes, newLocations, newConnectivity, FaceLocations, Faces);
+  }
 
   newPoints->Delete();
   newTypes->Delete();
@@ -280,10 +318,15 @@ void SMDS_UnstructuredGrid::copyNodes(vtkPoints *newPoints, std::vector<int>& id
     }
 }
 
-void SMDS_UnstructuredGrid::copyBloc(vtkUnsignedCharArray *newTypes, std::vector<int>& idCellsOldToNew,
-                                     std::vector<int>& idNodesOldToNew, vtkCellArray* newConnectivity,
-                                     vtkIdTypeArray* newLocations, vtkIdType* pointsCell, int& alreadyCopied,
-                                     int start, int end)
+void SMDS_UnstructuredGrid::copyBloc(vtkUnsignedCharArray *newTypes,
+                                     std::vector<int>&     idCellsOldToNew,
+                                     std::vector<int>&     idNodesOldToNew,
+                                     vtkCellArray*         newConnectivity,
+                                     vtkIdTypeArray*       newLocations,
+                                     vtkIdType*            pointsCell,
+                                     int&                  alreadyCopied,
+                                     int                   start,
+                                     int                   end)
 {
   MESSAGE("copyBloc " << alreadyCopied << " " << start << " " << end << " size: " << end - start << " total: " << alreadyCopied + end - start);
   for (int j = start; j < end; j++)
@@ -312,7 +355,12 @@ void SMDS_UnstructuredGrid::copyBloc(vtkUnsignedCharArray *newTypes, std::vector
 
 int SMDS_UnstructuredGrid::CellIdToDownId(int vtkCellId)
 {
-  // ASSERT((vtkCellId >= 0) && (vtkCellId < _cellIdToDownId.size()));
+  if((vtkCellId < 0) || (vtkCellId >= _cellIdToDownId.size()))
+    {
+      //MESSAGE("SMDS_UnstructuredGrid::CellIdToDownId structure not up to date: vtkCellId="
+      //    << vtkCellId << " max="<< _cellIdToDownId.size());
+      return -1;
+    }
   return _cellIdToDownId[vtkCellId];
 }
 
@@ -348,73 +396,83 @@ void SMDS_UnstructuredGrid::BuildDownwardConnectivity(bool withEdges)
 
   // --- create SMDS_Downward structures (in _downArray vector[vtkCellType])
 
-  _downArray.resize(VTK_MAXTYPE + 1, 0); // --- max. type value = VTK_QUADRATIC_PYRAMID
-
-  _downArray[VTK_LINE] = new SMDS_DownEdge(this);
-  _downArray[VTK_QUADRATIC_EDGE] = new SMDS_DownQuadEdge(this);
-  _downArray[VTK_TRIANGLE] = new SMDS_DownTriangle(this);
-  _downArray[VTK_QUADRATIC_TRIANGLE] = new SMDS_DownQuadTriangle(this);
-  _downArray[VTK_QUAD] = new SMDS_DownQuadrangle(this);
-  _downArray[VTK_QUADRATIC_QUAD] = new SMDS_DownQuadQuadrangle(this);
-  _downArray[VTK_TETRA] = new SMDS_DownTetra(this);
-  _downArray[VTK_QUADRATIC_TETRA] = new SMDS_DownQuadTetra(this);
-  _downArray[VTK_PYRAMID] = new SMDS_DownPyramid(this);
-  _downArray[VTK_QUADRATIC_PYRAMID] = new SMDS_DownQuadPyramid(this);
-  _downArray[VTK_WEDGE] = new SMDS_DownPenta(this);
-  _downArray[VTK_QUADRATIC_WEDGE] = new SMDS_DownQuadPenta(this);
-  _downArray[VTK_HEXAHEDRON] = new SMDS_DownHexa(this);
-  _downArray[VTK_QUADRATIC_HEXAHEDRON] = new SMDS_DownQuadHexa(this);
+  _downArray.resize(VTK_MAXTYPE + 1, 0);
+
+  _downArray[VTK_LINE]                    = new SMDS_DownEdge(this);
+  _downArray[VTK_QUADRATIC_EDGE]          = new SMDS_DownQuadEdge(this);
+  _downArray[VTK_TRIANGLE]                = new SMDS_DownTriangle(this);
+  _downArray[VTK_QUADRATIC_TRIANGLE]      = new SMDS_DownQuadTriangle(this);
+  _downArray[VTK_QUAD]                    = new SMDS_DownQuadrangle(this);
+  _downArray[VTK_QUADRATIC_QUAD]          = new SMDS_DownQuadQuadrangle(this);
+  _downArray[VTK_BIQUADRATIC_QUAD]        = new SMDS_DownQuadQuadrangle(this);
+  _downArray[VTK_TETRA]                   = new SMDS_DownTetra(this);
+  _downArray[VTK_QUADRATIC_TETRA]         = new SMDS_DownQuadTetra(this);
+  _downArray[VTK_PYRAMID]                 = new SMDS_DownPyramid(this);
+  _downArray[VTK_QUADRATIC_PYRAMID]       = new SMDS_DownQuadPyramid(this);
+  _downArray[VTK_WEDGE]                   = new SMDS_DownPenta(this);
+  _downArray[VTK_QUADRATIC_WEDGE]         = new SMDS_DownQuadPenta(this);
+  _downArray[VTK_HEXAHEDRON]              = new SMDS_DownHexa(this);
+  _downArray[VTK_QUADRATIC_HEXAHEDRON]    = new SMDS_DownQuadHexa(this);
+  _downArray[VTK_TRIQUADRATIC_HEXAHEDRON] = new SMDS_DownQuadHexa(this);
+  _downArray[VTK_HEXAGONAL_PRISM]         = new SMDS_DownPenta(this);
 
   // --- get detailed info of number of cells of each type, allocate SMDS_downward structures
 
   const SMDS_MeshInfo &meshInfo = _mesh->GetMeshInfo();
 
-  int nbLinTetra = meshInfo.NbTetras(ORDER_LINEAR);
-  int nbQuadTetra = meshInfo.NbTetras(ORDER_QUADRATIC);
-  int nbLinPyra = meshInfo.NbPyramids(ORDER_LINEAR);
-  int nbQuadPyra = meshInfo.NbPyramids(ORDER_QUADRATIC);
-  int nbLinPrism = meshInfo.NbPrisms(ORDER_LINEAR);
-  int nbQuadPrism = meshInfo.NbPrisms(ORDER_QUADRATIC);
-  int nbLinHexa = meshInfo.NbHexas(ORDER_LINEAR);
-  int nbQuadHexa = meshInfo.NbHexas(ORDER_QUADRATIC);
-
-  int nbLineGuess = int((4.0 / 3.0) * nbLinTetra + 2 * nbLinPrism + 2.5 * nbLinPyra + 3 * nbLinHexa);
+  int nbLinTetra  = meshInfo.NbTetras  (ORDER_LINEAR);
+  int nbQuadTetra = meshInfo.NbTetras  (ORDER_QUADRATIC);
+  int nbLinPyra   = meshInfo.NbPyramids(ORDER_LINEAR);
+  int nbQuadPyra  = meshInfo.NbPyramids(ORDER_QUADRATIC);
+  int nbLinPrism  = meshInfo.NbPrisms  (ORDER_LINEAR);
+  int nbQuadPrism = meshInfo.NbPrisms  (ORDER_QUADRATIC);
+  int nbLinHexa   = meshInfo.NbHexas   (ORDER_LINEAR);
+  int nbQuadHexa  = meshInfo.NbHexas   (ORDER_QUADRATIC);
+  int nbHexPrism  = meshInfo.NbHexPrisms();
+
+  int nbLineGuess     = int((4.0 / 3.0) * nbLinTetra + 2 * nbLinPrism + 2.5 * nbLinPyra + 3 * nbLinHexa);
   int nbQuadEdgeGuess = int((4.0 / 3.0) * nbQuadTetra + 2 * nbQuadPrism + 2.5 * nbQuadPyra + 3 * nbQuadHexa);
-  int nbLinTriaGuess = 2 * nbLinTetra + nbLinPrism + 2 * nbLinPyra;
+  int nbLinTriaGuess  = 2 * nbLinTetra + nbLinPrism + 2 * nbLinPyra;
   int nbQuadTriaGuess = 2 * nbQuadTetra + nbQuadPrism + 2 * nbQuadPyra;
-  int nbLinQuadGuess = int((2.0 / 3.0) * nbLinPrism + (1.0 / 2.0) * nbLinPyra + 3 * nbLinHexa);
+  int nbLinQuadGuess  = int((2.0 / 3.0) * nbLinPrism + (1.0 / 2.0) * nbLinPyra + 3 * nbLinHexa);
   int nbQuadQuadGuess = int((2.0 / 3.0) * nbQuadPrism + (1.0 / 2.0) * nbQuadPyra + 3 * nbQuadHexa);
 
-  int GuessSize[VTK_QUADRATIC_TETRA];
-  GuessSize[VTK_LINE] = nbLineGuess;
-  GuessSize[VTK_QUADRATIC_EDGE] = nbQuadEdgeGuess;
-  GuessSize[VTK_TRIANGLE] = nbLinTriaGuess;
-  GuessSize[VTK_QUADRATIC_TRIANGLE] = nbQuadTriaGuess;
-  GuessSize[VTK_QUAD] = nbLinQuadGuess;
-  GuessSize[VTK_QUADRATIC_QUAD] = nbQuadQuadGuess;
-  GuessSize[VTK_TETRA] = nbLinTetra;
-  GuessSize[VTK_QUADRATIC_TETRA] = nbQuadTetra;
-  GuessSize[VTK_PYRAMID] = nbLinPyra;
-  GuessSize[VTK_QUADRATIC_PYRAMID] = nbQuadPyra;
-  GuessSize[VTK_WEDGE] = nbLinPrism;
-  GuessSize[VTK_QUADRATIC_WEDGE] = nbQuadPrism;
-  GuessSize[VTK_HEXAHEDRON] = nbLinHexa;
-  GuessSize[VTK_QUADRATIC_HEXAHEDRON] = nbQuadHexa;
-
-  _downArray[VTK_LINE]->allocate(nbLineGuess);
-  _downArray[VTK_QUADRATIC_EDGE]->allocate(nbQuadEdgeGuess);
-  _downArray[VTK_TRIANGLE]->allocate(nbLinTriaGuess);
-  _downArray[VTK_QUADRATIC_TRIANGLE]->allocate(nbQuadTriaGuess);
-  _downArray[VTK_QUAD]->allocate(nbLinQuadGuess);
-  _downArray[VTK_QUADRATIC_QUAD]->allocate(nbQuadQuadGuess);
-  _downArray[VTK_TETRA]->allocate(nbLinTetra);
-  _downArray[VTK_QUADRATIC_TETRA]->allocate(nbQuadTetra);
-  _downArray[VTK_PYRAMID]->allocate(nbLinPyra);
-  _downArray[VTK_QUADRATIC_PYRAMID]->allocate(nbQuadPyra);
-  _downArray[VTK_WEDGE]->allocate(nbLinPrism);
-  _downArray[VTK_QUADRATIC_WEDGE]->allocate(nbQuadPrism);
-  _downArray[VTK_HEXAHEDRON]->allocate(nbLinHexa);
-  _downArray[VTK_QUADRATIC_HEXAHEDRON]->allocate(nbQuadHexa);
+  int GuessSize[VTK_MAXTYPE];
+  GuessSize[VTK_LINE]                    = nbLineGuess;
+  GuessSize[VTK_QUADRATIC_EDGE]          = nbQuadEdgeGuess;
+  GuessSize[VTK_TRIANGLE]                = nbLinTriaGuess;
+  GuessSize[VTK_QUADRATIC_TRIANGLE]      = nbQuadTriaGuess;
+  GuessSize[VTK_QUAD]                    = nbLinQuadGuess;
+  GuessSize[VTK_QUADRATIC_QUAD]          = nbQuadQuadGuess;
+  GuessSize[VTK_BIQUADRATIC_QUAD]        = nbQuadQuadGuess;
+  GuessSize[VTK_TETRA]                   = nbLinTetra;
+  GuessSize[VTK_QUADRATIC_TETRA]         = nbQuadTetra;
+  GuessSize[VTK_PYRAMID]                 = nbLinPyra;
+  GuessSize[VTK_QUADRATIC_PYRAMID]       = nbQuadPyra;
+  GuessSize[VTK_WEDGE]                   = nbLinPrism;
+  GuessSize[VTK_QUADRATIC_WEDGE]         = nbQuadPrism;
+  GuessSize[VTK_HEXAHEDRON]              = nbLinHexa;
+  GuessSize[VTK_QUADRATIC_HEXAHEDRON]    = nbQuadHexa;
+  GuessSize[VTK_TRIQUADRATIC_HEXAHEDRON] = nbQuadHexa;
+  GuessSize[VTK_HEXAGONAL_PRISM]         = nbHexPrism;
+
+  _downArray[VTK_LINE]                   ->allocate(nbLineGuess);
+  _downArray[VTK_QUADRATIC_EDGE]         ->allocate(nbQuadEdgeGuess);
+  _downArray[VTK_TRIANGLE]               ->allocate(nbLinTriaGuess);
+  _downArray[VTK_QUADRATIC_TRIANGLE]     ->allocate(nbQuadTriaGuess);
+  _downArray[VTK_QUAD]                   ->allocate(nbLinQuadGuess);
+  _downArray[VTK_QUADRATIC_QUAD]         ->allocate(nbQuadQuadGuess);
+  _downArray[VTK_BIQUADRATIC_QUAD]       ->allocate(nbQuadQuadGuess);
+  _downArray[VTK_TETRA]                  ->allocate(nbLinTetra);
+  _downArray[VTK_QUADRATIC_TETRA]        ->allocate(nbQuadTetra);
+  _downArray[VTK_PYRAMID]                ->allocate(nbLinPyra);
+  _downArray[VTK_QUADRATIC_PYRAMID]      ->allocate(nbQuadPyra);
+  _downArray[VTK_WEDGE]                  ->allocate(nbLinPrism);
+  _downArray[VTK_QUADRATIC_WEDGE]        ->allocate(nbQuadPrism);
+  _downArray[VTK_HEXAHEDRON]             ->allocate(nbLinHexa);
+  _downArray[VTK_QUADRATIC_HEXAHEDRON]   ->allocate(nbQuadHexa);
+  _downArray[VTK_TRIQUADRATIC_HEXAHEDRON]->allocate(nbQuadHexa);
+  _downArray[VTK_HEXAGONAL_PRISM]        ->allocate(nbHexPrism);
 
   // --- iteration on vtkUnstructuredGrid cells, only faces
   //     for each vtk face:
@@ -705,7 +763,7 @@ void SMDS_UnstructuredGrid::BuildDownwardConnectivity(bool withEdges)
  * @param vtkId the vtk id of the cell
  * @return number of neighbors
  */
-int SMDS_UnstructuredGrid::GetNeighbors(int* neighborsVtkIds, int* downIds, unsigned char* downTypes, int vtkId)
+int SMDS_UnstructuredGrid::GetNeighbors(int* neighborsVtkIds, int* downIds, unsigned char* downTypes, int vtkId, bool getSkin)
 {
   int vtkType = this->GetCellType(vtkId);
   int cellDim = SMDS_Downward::getCellDimension(vtkType);
@@ -740,9 +798,27 @@ int SMDS_UnstructuredGrid::GetNeighbors(int* neighborsVtkIds, int* downIds, unsi
           downIds[nb] = downId;
           downTypes[nb] = cellType;
           nb++;
+          if (nb >= NBMAXNEIGHBORS)
+            {
+              INFOS("SMDS_UnstructuredGrid::GetNeighbors problem: NBMAXNEIGHBORS=" <<NBMAXNEIGHBORS << " not enough");
+              return nb;
+            }
+        }
+      if (getSkin)
+        {
+          if (cellDim == 3 && nbUp == 1) // this face is on the skin of the volume
+            {
+              neighborsVtkIds[nb] = _downArray[cellType]->getVtkCellId(downId); // OK if skin present
+              downIds[nb] = downId;
+              downTypes[nb] = cellType;
+              nb++;
+              if (nb >= NBMAXNEIGHBORS)
+                {
+                  INFOS("SMDS_UnstructuredGrid::GetNeighbors problem: NBMAXNEIGHBORS=" <<NBMAXNEIGHBORS << " not enough");
+                  return nb;
+                }
+            }
         }
-      if (nb >= NBMAXNEIGHBORS)
-        assert(0);
     }
   return nb;
 }
@@ -757,18 +833,21 @@ int SMDS_UnstructuredGrid::GetParentVolumes(int* volVtkIds, int vtkId)
   int vtkType = this->GetCellType(vtkId);
   int dim = SMDS_Downward::getCellDimension(vtkType);
   int nbFaces = 0;
-  int faces[1000];
   unsigned char cellTypes[1000];
   int downCellId[1000];
   if (dim == 1)
     {
       int downId = this->CellIdToDownId(vtkId);
+      if (downId < 0)
+        {
+          MESSAGE("Downward structure not up to date: new edge not taken into account");
+          return 0;
+        }
       nbFaces = _downArray[vtkType]->getNumberOfUpCells(downId);
       const int *upCells = _downArray[vtkType]->getUpCells(downId);
       const unsigned char* upTypes = _downArray[vtkType]->getUpTypes(downId);
       for (int i=0; i< nbFaces; i++)
         {
-          faces[i] = _downArray[upTypes[i]]->getVtkCellId(upCells[i]);
           cellTypes[i] = upTypes[i];
           downCellId[i] = upCells[i];
         }
@@ -776,9 +855,14 @@ int SMDS_UnstructuredGrid::GetParentVolumes(int* volVtkIds, int vtkId)
   else if (dim == 2)
     {
       nbFaces = 1;
-      faces[0] = vtkId;
       cellTypes[0] = this->GetCellType(vtkId);
-      downCellId[0] = this->CellIdToDownId(vtkId);
+      int downId = this->CellIdToDownId(vtkId);
+      if (downId < 0)
+        {
+          MESSAGE("Downward structure not up to date: new face not taken into account");
+          return 0;
+        }
+      downCellId[0] = downId;
     }
 
   int nbvol =0;
@@ -810,7 +894,6 @@ int SMDS_UnstructuredGrid::GetParentVolumes(int* volVtkIds, int downId, unsigned
   int vtkType = downType;
   int dim = SMDS_Downward::getCellDimension(vtkType);
   int nbFaces = 0;
-  int faces[1000];
   unsigned char cellTypes[1000];
   int downCellId[1000];
   if (dim == 1)
@@ -820,7 +903,6 @@ int SMDS_UnstructuredGrid::GetParentVolumes(int* volVtkIds, int downId, unsigned
       const unsigned char* upTypes = _downArray[vtkType]->getUpTypes(downId);
       for (int i=0; i< nbFaces; i++)
         {
-          faces[i] = _downArray[upTypes[i]]->getVtkCellId(upCells[i]);
           cellTypes[i] = upTypes[i];
           downCellId[i] = upCells[i];
         }
@@ -889,15 +971,17 @@ void SMDS_UnstructuredGrid::ModifyCellNodes(int vtkVolId, std::map<int, int> loc
  * @param orderedNodes list of nodes to reorder (in out)
  * @return size of the list
  */
-int SMDS_UnstructuredGrid::getOrderedNodesOfFace(int vtkVolId, std::vector<vtkIdType>& orderedNodes)
+int SMDS_UnstructuredGrid::getOrderedNodesOfFace(int vtkVolId, int& dim, std::vector<vtkIdType>& orderedNodes)
 {
   int vtkType = this->GetCellType(vtkVolId);
-  int cellDim = SMDS_Downward::getCellDimension(vtkType);
-  if (cellDim != 3)
-    return 0;
-  SMDS_Down3D *downvol = static_cast<SMDS_Down3D*> (_downArray[vtkType]);
-  int downVolId = this->_cellIdToDownId[vtkVolId];
-  downvol->getOrderedNodesOfFace(downVolId, orderedNodes);
+  dim = SMDS_Downward::getCellDimension(vtkType);
+  if (dim == 3)
+    {
+      SMDS_Down3D *downvol = static_cast<SMDS_Down3D*> (_downArray[vtkType]);
+      int downVolId = this->_cellIdToDownId[vtkVolId];
+      downvol->getOrderedNodesOfFace(downVolId, orderedNodes);
+    }
+  // else nothing to do;
   return orderedNodes.size();
 }
 
@@ -930,7 +1014,7 @@ void SMDS_UnstructuredGrid::BuildLinks()
  * @param nodeDomains: map(original id --> map(domain --> duplicated node id))
  * @return ok if success.
  */
-SMDS_MeshVolume* SMDS_UnstructuredGrid::extrudeVolumeFromFace(int vtkVolId,
+SMDS_MeshCell* SMDS_UnstructuredGrid::extrudeVolumeFromFace(int vtkVolId,
                                                   int domain1,
                                                   int domain2,
                                                   std::set<int>& originalNodes,
@@ -944,65 +1028,136 @@ SMDS_MeshVolume* SMDS_UnstructuredGrid::extrudeVolumeFromFace(int vtkVolId,
   for (; it != originalNodes.end(); ++it)
     orderedOriginals.push_back(*it);
 
-  int nbNodes = this->getOrderedNodesOfFace(vtkVolId, orderedOriginals);
+  int dim = 0;
+  int nbNodes = this->getOrderedNodesOfFace(vtkVolId, dim, orderedOriginals);
   vector<vtkIdType> orderedNodes;
 
+  bool isQuadratic = false;
   switch (orderedOriginals.size())
   {
     case 3:
-    case 4:
-      for (int i = 0; i < nbNodes; i++)
-        orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain1]);
-      for (int i = 0; i < nbNodes; i++)
-        orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain2]);
+      if (dim == 2)
+        isQuadratic = true;
       break;
     case 6:
     case 8:
-      {
-        long dom1 = domain1;
-        long dom2 = domain2;
-        long dom1_2; // for nodeQuadDomains
-        if (domain1 < domain2)
-          dom1_2 = dom1 + INT_MAX * dom2;
-        else
-          dom1_2 = dom2 + INT_MAX * dom1;
-        //cerr << "dom1=" << dom1 << " dom2=" << dom2 << " dom1_2=" << dom1_2 << endl;
-        int ima = orderedOriginals.size();
-        int mid = orderedOriginals.size() / 2;
-        //cerr << "ima=" << ima << " mid=" << mid << endl;
-        for (int i = 0; i < mid; i++)
-          orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain1]);
-        for (int i = 0; i < mid; i++)
-          orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain2]);
-        for (int i = mid; i < ima; i++)
-          orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain1]);
-        for (int i = mid; i < ima; i++)
-          orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain2]);
-        for (int i = 0; i < mid; i++)
-          {
-            int oldId = orderedOriginals[i];
-            int newId;
-            if (nodeQuadDomains.count(oldId) && nodeQuadDomains[oldId].count(dom1_2))
-              newId = nodeQuadDomains[oldId][dom1_2];
-            else
-              {
-                double *coords = this->GetPoint(oldId);
-                SMDS_MeshNode *newNode = _mesh->AddNode(coords[0], coords[1], coords[2]);
-                newId = newNode->getVtkId();
-                std::map<long, int> emptyMap;
-                nodeQuadDomains[oldId] = emptyMap;
-                nodeQuadDomains[oldId][dom1_2] = newId;
-              }
-            orderedNodes.push_back(newId);
-          }
-      }
+      isQuadratic = true;
       break;
     default:
-      ASSERT(0);
+      isQuadratic = false;
+      break;
   }
 
-  SMDS_MeshVolume *vol = _mesh->AddVolumeFromVtkIds(orderedNodes);
+  if (isQuadratic)
+    {
+      long dom1 = domain1;
+      long dom2 = domain2;
+      long dom1_2; // for nodeQuadDomains
+      if (domain1 < domain2)
+        dom1_2 = dom1 + INT_MAX * dom2;
+      else
+        dom1_2 = dom2 + INT_MAX * dom1;
+      //cerr << "dom1=" << dom1 << " dom2=" << dom2 << " dom1_2=" << dom1_2 << endl;
+      int ima = orderedOriginals.size();
+      int mid = orderedOriginals.size() / 2;
+      //cerr << "ima=" << ima << " mid=" << mid << endl;
+      for (int i = 0; i < mid; i++)
+        orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain1]);
+      for (int i = 0; i < mid; i++)
+        orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain2]);
+      for (int i = mid; i < ima; i++)
+        orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain1]);
+      for (int i = mid; i < ima; i++)
+        orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain2]);
+      for (int i = 0; i < mid; i++)
+        {
+          int oldId = orderedOriginals[i];
+          int newId;
+          if (nodeQuadDomains.count(oldId) && nodeQuadDomains[oldId].count(dom1_2))
+            newId = nodeQuadDomains[oldId][dom1_2];
+          else
+            {
+              double *coords = this->GetPoint(oldId);
+              SMDS_MeshNode *newNode = _mesh->AddNode(coords[0], coords[1], coords[2]);
+              newId = newNode->getVtkId();
+              std::map<long, int> emptyMap;
+              nodeQuadDomains[oldId] = emptyMap;
+              nodeQuadDomains[oldId][dom1_2] = newId;
+            }
+          orderedNodes.push_back(newId);
+        }
+    }
+  else
+    {
+      for (int i = 0; i < nbNodes; i++)
+        orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain1]);
+      if (dim == 3)
+        for (int i = 0; i < nbNodes; i++)
+          orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain2]);
+      else
+        for (int i = nbNodes-1; i >= 0; i--)
+          orderedNodes.push_back(nodeDomains[orderedOriginals[i]][domain2]);
+
+    }
 
-  // TODO update subshape list of elements and nodes
-  return vol;
+  if (dim == 3)
+    {
+      SMDS_MeshVolume *vol = _mesh->AddVolumeFromVtkIds(orderedNodes);
+      return vol;
+    }
+  else if (dim == 2)
+    {
+      SMDS_MeshFace *face = _mesh->AddFaceFromVtkIds(orderedNodes);
+      return face;
+    }
+
+  // TODO update sub-shape list of elements and nodes
+  return 0;
+}
+
+//================================================================================
+/*!
+ * \brief Allocates data array for ball diameters
+ *  \param MaxVtkID - max ID of a ball element
+ */
+//================================================================================
+
+void SMDS_UnstructuredGrid::AllocateDiameters( vtkIdType MaxVtkID )
+{
+  SetBallDiameter( MaxVtkID, 0 );
+}
+
+//================================================================================
+/*!
+ * \brief Sets diameter of a ball element
+ *  \param vtkID - vtk id of the ball element
+ *  \param diameter - diameter of the ball element
+ */
+//================================================================================
+
+void SMDS_UnstructuredGrid::SetBallDiameter( vtkIdType vtkID, double diameter )
+{
+  vtkDoubleArray* array = vtkDoubleArray::SafeDownCast( vtkDataSet::CellData->GetScalars() );
+  if ( !array )
+  {
+    array = vtkDoubleArray::New();
+    array->SetNumberOfComponents(1);
+    vtkDataSet::CellData->SetScalars( array );
+  }
+  array->InsertValue( vtkID, diameter );
 }
+
+//================================================================================
+/*!
+ * \brief Returns diameter of a ball element
+ *  \param vtkID - vtk id of the ball element
+ */
+//================================================================================
+
+double SMDS_UnstructuredGrid::GetBallDiameter( vtkIdType vtkID ) const
+{
+  if ( vtkDataSet::CellData )
+    return vtkDoubleArray::SafeDownCast( vtkDataSet::CellData->GetScalars() )->GetValue( vtkID );
+  return 0;
+}
+