1 // Copyright (C) 2010-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "vtkELNOMeshFilter.h"
21 #include "vtkInformation.h"
22 #include "vtkInformationVector.h"
23 #include "vtkInformationIntegerKey.h"
24 #include "vtkObjectFactory.h"
25 #include "vtkPolyDataAlgorithm.h"
26 #include "vtkPolyData.h"
27 #include "vtkIdTypeArray.h"
28 #include "vtkQuadratureSchemeDefinition.h"
29 #include "vtkInformationQuadratureSchemeDefinitionVectorKey.h"
30 #include "vtkUnstructuredGrid.h"
31 #include "vtkShrinkFilter.h"
32 #include "vtkSmartPointer.h"
33 #include "vtkPointData.h"
34 #include "vtkCellData.h"
35 #include "vtkIdList.h"
38 #include "MEDUtilities.hxx"
42 vtkStandardNewMacro(vtkELNOMeshFilter);
44 vtkELNOMeshFilter::vtkELNOMeshFilter()
48 vtkELNOMeshFilter::~vtkELNOMeshFilter()
52 int vtkELNOMeshFilter::RequestData(vtkInformation *request,
53 vtkInformationVector **input, vtkInformationVector *output)
55 vtkUnstructuredGrid *usgIn = vtkUnstructuredGrid::SafeDownCast(
56 input[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
58 vtkUnstructuredGrid *usgOut = vtkUnstructuredGrid::SafeDownCast(
59 output->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
61 if(usgIn == NULL || usgOut == NULL)
63 vtkDebugMacro("vtkELNOMeshFilter not correctly configured : Invalid input or output !");
67 // creates offsets array
69 // first shrink the input
70 vtkUnstructuredGrid* usgInClone = usgIn->NewInstance();
71 usgInClone->ShallowCopy(usgIn);
72 vtkSmartPointer<vtkShrinkFilter> shrink(vtkSmartPointer<vtkShrinkFilter>::New());
73 shrink->SetInputData(usgInClone);
74 shrink->SetShrinkFactor(0.9999);
76 vtkUnstructuredGrid *shrinked(shrink->GetOutput());
78 usgOut->ShallowCopy(shrinked);
81 // now copy ELNO data. Start by verifying if it is possible to
82 // shallow copy the array.
83 vtkInformation *info(usgIn->GetInformation());
85 vtkIdType nVerts(shrinked->GetNumberOfPoints()),ncell(usgIn->GetNumberOfCells());
86 // first loop through all cells to check if a shallow copy is possible
87 bool shallowok(true);// Anthony : checks that shrink works well. Really necessary ?
88 vtkIdType previous(0),offset(0);
90 for(vtkIdType cellId = 0; cellId < ncell; cellId++)
92 if(offset != previous)
97 vtkCell *cell(usgIn->GetCell(cellId));
98 vtkIdType nbptsInCell(cell->GetNumberOfPoints());
99 previous = offset + nbptsInCell;
101 offset += nbptsInCell ;
105 shallowok = (previous == nVerts);
107 vtkFieldData *fielddata(usgIn->GetFieldData());
108 for(int index = 0; index < fielddata->GetNumberOfArrays(); index++)
110 vtkDataArray *data(fielddata->GetArray(index));
111 vtkQuadratureSchemeDefinition **dict(0);
112 vtkInformationQuadratureSchemeDefinitionVectorKey *key(vtkQuadratureSchemeDefinition::DICTIONARY());
113 if(key->Has(data->GetInformation()))
115 int dictSize(key->Size(data->GetInformation()));
116 dict=new vtkQuadratureSchemeDefinition *[dictSize];
117 key->GetRange(data->GetInformation(),dict,0,0,dictSize);
122 vtkInformation *info(data->GetInformation());
123 const char *arrayOffsetName(info->Get(vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME()));
124 vtkIdTypeArray *offData(0);
125 bool isELGA(false),isELNO(false);
129 vtkFieldData *cellData(usgIn->GetCellData());
130 vtkDataArray *offDataTmp(cellData->GetArray(arrayOffsetName));
131 isELGA=offDataTmp->GetInformation()->Get(MEDUtilities::ELGA())==1;
132 isELNO=offDataTmp->GetInformation()->Get(MEDUtilities::ELNO())==1;
133 offData=dynamic_cast<vtkIdTypeArray *>(offDataTmp);
136 if(arrayOffsetName == NULL || isELGA)
138 if(shallowok && data->GetNumberOfTuples()==nVerts )// Anthony : is it not a little confusing to assign a FieldData on Points because the number of tuples fits the number of nodes of shrinked mesh ?
139 usgOut->GetPointData()->AddArray(data);
141 shrinked->GetFieldData()->AddArray(data);
146 vtkDataArray *newArray(data->NewInstance());
147 newArray->SetName(data->GetName());
148 usgOut->GetPointData()->AddArray(newArray);
149 newArray->SetNumberOfComponents(data->GetNumberOfComponents());
150 newArray->SetNumberOfTuples(usgOut->GetNumberOfPoints());
151 newArray->CopyComponentNames(data);
155 vtkIdList *ids(vtkIdList::New());
157 for(vtkIdType cellId=0;cellId<ncell;cellId++)
159 int cellType(shrinked->GetCellType(cellId));
160 shrinked->GetCellPoints(cellId, ids);
161 for(int id = 0; id < dict[cellType]->GetNumberOfQuadraturePoints(); id++)
163 const double * w = dict[cellType]->GetShapeFunctionWeights(id);
165 for(j = 0; j < dict[cellType]->GetNumberOfNodes(); j++)
170 if(j == dict[cellType]->GetNumberOfNodes())
174 newArray->SetTuple(ids->GetId(id), offset + j, data);
176 vtkCell *cell(usgIn->GetCell(cellId));
177 vtkIdType nbptsInCell(cell->GetNumberOfPoints());
182 else if(offData && isELNO)
184 vtkIdType *offsetPtr(offData->GetPointer(0));
186 for(vtkIdType cellId=0;cellId<ncell;cellId++)
188 vtkCell *cell(shrinked->GetCell(cellId));
189 vtkIdType nbPoints(cell->GetNumberOfPoints()),offset(offsetPtr[cellId]);
190 for(vtkIdType j=0;j<nbPoints;j++,zeId++)
191 newArray->SetTuple(zeId,offsetPtr[cellId]+j,data);
202 void vtkELNOMeshFilter::PrintSelf(ostream& os, vtkIndent indent)
204 this->Superclass::PrintSelf(os, indent);