1 // Copyright (C) 2010-2015 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
19 // Author : Roman NIKOLAEV
22 #include "vtkMEDQuadraturePointsGenerator.h"
23 #include "MEDFileFieldRepresentationTree.hxx"
26 #include <vtkObjectFactory.h>
27 #include <vtkInformation.h>
28 #include <vtkInformationVector.h>
29 #include <vtkUnstructuredGrid.h>
30 #include <vtkCellData.h>
31 #include <vtkPointData.h>
32 #include <vtkInformationQuadratureSchemeDefinitionVectorKey.h>
33 #include <vtkQuadratureSchemeDefinition.h>
35 //-----------------------------------------------------------------------------
36 vtkStandardNewMacro(vtkMEDQuadraturePointsGenerator);
38 //-----------------------------------------------------------------------------
39 vtkMEDQuadraturePointsGenerator::vtkMEDQuadraturePointsGenerator()
43 //-----------------------------------------------------------------------------
44 vtkMEDQuadraturePointsGenerator::~vtkMEDQuadraturePointsGenerator()
48 //-----------------------------------------------------------------------------
49 int vtkMEDQuadraturePointsGenerator::RequestData(
50 vtkInformation* request,
51 vtkInformationVector **input,
52 vtkInformationVector *output)
54 if (this->Superclass::RequestData(request, input, output) == 0 )
59 //Fill MED internal array
60 vtkDataObject *tmpDataObj;
63 tmpDataObj = input[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT());
64 vtkUnstructuredGrid *usgIn = vtkUnstructuredGrid::SafeDownCast(tmpDataObj);
66 tmpDataObj = output->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT());
67 vtkPolyData *pdOut = vtkPolyData::SafeDownCast(tmpDataObj);
68 vtkDataArray* offsets = this->GetInputArrayToProcess(0, input);
70 if (usgIn == NULL || pdOut == NULL || offsets == NULL )
72 vtkErrorMacro("Filter data has not been configured correctly. Aborting.");
76 vtkInformation *info = offsets->GetInformation();
77 vtkInformationQuadratureSchemeDefinitionVectorKey *key
78 = vtkQuadratureSchemeDefinition::DICTIONARY();
82 << "Dictionary is not present in array "
83 << offsets->GetName() << " " << offsets
88 vtkIdType nCells = usgIn->GetNumberOfCells();
89 int dictSize = key->Size(info);
90 vtkQuadratureSchemeDefinition **dict
91 = new vtkQuadratureSchemeDefinition *[dictSize];
92 key->GetRange(info, dict, 0, 0, dictSize);
94 // Loop over all fields to map the internal MED cell array to the points array
95 int nCArrays = usgIn->GetCellData()->GetNumberOfArrays();
96 for (int i = 0; i<nCArrays; ++i)
98 vtkDataArray* array = usgIn->GetCellData()->GetArray(i);
103 std::string arrName = array->GetName();
104 if ( arrName == MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME )
106 vtkDataArray *out_id_cells = array->NewInstance();
107 out_id_cells->SetName(MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME);
108 out_id_cells->SetNumberOfComponents(array->GetNumberOfComponents());
109 out_id_cells->CopyComponentNames( array );
110 for (int cellId = 0; cellId < nCells; cellId++)
112 int cellType = usgIn->GetCellType(cellId);
114 // a simple check to see if a scheme really exists for this cell type.
115 // should not happen if the cell type has not been modified.
116 if (dict[cellType] == NULL)
121 int np = dict[cellType]->GetNumberOfQuadraturePoints();
122 for (int id = 0; id < np; id++)
124 out_id_cells->InsertNextTuple(cellId, array);
127 out_id_cells->Squeeze();
128 pdOut->GetPointData()->AddArray(out_id_cells);
129 out_id_cells->Delete();