1 // Copyright (C) 2010-2013 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.
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 "vtkObjectFactory.h"
24 #include "vtkPolyDataAlgorithm.h"
25 #include "vtkPolyData.h"
26 #include "vtkIdTypeArray.h"
27 #include "vtkInformationQuadratureSchemeDefinitionVectorKey.h"
28 #include "vtkQuadratureSchemeDefinition.h"
29 #include "vtkUnstructuredGrid.h"
30 #include "vtkShrinkFilter.h"
31 #include "vtkSmartPointer.h"
32 #include "vtkPointData.h"
33 #include "vtkCellData.h"
34 #include "vtkIdList.h"
36 //vtkCxxRevisionMacro(vtkELNOMeshFilter, "$Revision$")
38 vtkStandardNewMacro(vtkELNOMeshFilter)
41 vtkELNOMeshFilter::vtkELNOMeshFilter()
45 vtkELNOMeshFilter::~vtkELNOMeshFilter()
49 int vtkELNOMeshFilter::RequestData(vtkInformation *request,
50 vtkInformationVector **input, vtkInformationVector *output)
52 vtkUnstructuredGrid *usgIn = vtkUnstructuredGrid::SafeDownCast(
53 input[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
55 vtkUnstructuredGrid *usgOut = vtkUnstructuredGrid::SafeDownCast(
56 output->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
58 vtkIdTypeArray* usg_offsets = vtkIdTypeArray::SafeDownCast(
59 this->GetInputArrayToProcess(0, input));
61 if(usgIn == NULL || usg_offsets == NULL || usgOut == NULL)
63 vtkDebugMacro("vtkELNOMeshFilter no correctly configured : offsets = " << usg_offsets);
67 vtkIdTypeArray* a = vtkIdTypeArray::SafeDownCast(
68 usgIn->GetCellData()->GetArray(usg_offsets->GetName()));
70 vtkInformationVector *inArrayVec =
71 this->Information->Get(INPUT_ARRAYS_TO_PROCESS());
73 // first shrink the input
74 vtkUnstructuredGrid* usgInClone = usgIn->NewInstance();
76 usgInClone->ShallowCopy(usgIn);
78 vtkSmartPointer<vtkShrinkFilter> shrink =
79 vtkSmartPointer<vtkShrinkFilter>::New();
80 shrink->SetInputData(usgInClone);
81 shrink->SetShrinkFactor(0.9999);
83 vtkUnstructuredGrid* shrinked = shrink->GetOutput();
87 usgOut->ShallowCopy(shrinked);
89 vtkIdTypeArray* offsets = vtkIdTypeArray::SafeDownCast(
90 shrinked->GetCellData()->GetArray(usg_offsets->GetName()));
92 // now copy ELNO data. Start by verifying if it is possible to
93 // shallow copy the array.
94 vtkInformation *info = offsets->GetInformation();
95 vtkInformationQuadratureSchemeDefinitionVectorKey *key =
96 vtkQuadratureSchemeDefinition::DICTIONARY();
99 vtkDebugMacro("Dictionary is not present in array " << offsets->GetName() << " " << offsets << " Aborting." );
102 int dictSize = key->Size(info);
103 vtkQuadratureSchemeDefinition **dict =
104 new vtkQuadratureSchemeDefinition *[dictSize];
105 key->GetRange(info, dict, 0, 0, dictSize);
107 vtkIdType nVerts = shrinked->GetNumberOfPoints();
108 vtkIdType ncell = usgIn->GetNumberOfCells();
109 // first loop through all cells to check if a shallow copy is possible
110 bool shallowok = true;
111 vtkIdType previous = 0;
113 for(vtkIdType cellId = 0; cellId < ncell; cellId++)
115 vtkIdType offset = offsets->GetValue(cellId);
116 if(offset != previous)
121 int cellType = usgIn->GetCellType(cellId);
123 if(dict[cellType] == NULL)
129 previous = offset + dict[cellType]->GetNumberOfQuadraturePoints();
132 if(previous != nVerts)
137 vtkFieldData* fielddata = usgIn->GetFieldData();
138 for(int index = 0; index < fielddata->GetNumberOfArrays(); index++)
140 vtkDataArray* data = fielddata->GetArray(index);
144 vtkInformation* info = data->GetInformation();
145 const char* arrayOffsetName = info->Get(
146 vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME());
148 if(arrayOffsetName == NULL ||
149 strcmp(arrayOffsetName, offsets->GetName()) != 0)
151 shrinked->GetFieldData()->AddArray(data);
157 usgOut->GetPointData()->AddArray(data);
161 vtkDataArray* newArray = data->NewInstance();
162 newArray->SetName(data->GetName());
163 usgOut->GetPointData()->AddArray(newArray);
164 newArray->SetNumberOfComponents(data->GetNumberOfComponents());
165 newArray->SetNumberOfTuples(usgOut->GetNumberOfPoints());
166 newArray->CopyComponentNames(data);
168 vtkIdList *ids = vtkIdList::New();
170 for(vtkIdType cellId = 0; cellId < ncell; cellId++)
172 vtkIdType offset = offsets->GetValue(cellId);
173 int cellType = shrinked->GetCellType(cellId);
174 shrinked->GetCellPoints(cellId, ids);
175 for(int id = 0; id < dict[cellType]->GetNumberOfQuadraturePoints(); id++)
177 const double * w = dict[cellType]->GetShapeFunctionWeights(id);
179 for(j = 0; j < dict[cellType]->GetNumberOfNodes(); j++)
184 if(j == dict[cellType]->GetNumberOfNodes())
188 newArray->SetTuple(ids->GetId(id), offset + j, data);
200 void vtkELNOMeshFilter::PrintSelf(ostream& os, vtkIndent indent)
202 this->Superclass::PrintSelf(os, indent);