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 "vtkELNOFilter.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 "vtkFieldData.h"
28 #include "vtkCellData.h"
29 #include "vtkPointData.h"
31 #include "vtkInformationQuadratureSchemeDefinitionVectorKey.h"
32 #include "vtkQuadratureSchemeDefinition.h"
33 #include "vtkUnstructuredGrid.h"
35 #include "MEDUtilities.hxx"
37 //vtkCxxRevisionMacro(vtkELNOFilter, "$Revision: 1.2.2.2 $");
38 vtkStandardNewMacro(vtkELNOFilter);
40 vtkELNOFilter::vtkELNOFilter()
42 this->ShrinkFactor = 0.5;
45 vtkELNOFilter::~vtkELNOFilter()
49 int vtkELNOFilter::RequestData(vtkInformation *request, vtkInformationVector **input, vtkInformationVector *output)
51 vtkUnstructuredGrid *usgIn(vtkUnstructuredGrid::SafeDownCast( input[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT())));
52 vtkPolyData *pdOut(vtkPolyData::SafeDownCast(output->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT())));
54 vtkDataArray *array(this->GetInputArrayToProcess(0, input));
55 vtkIdTypeArray* offsets(vtkIdTypeArray::SafeDownCast(this->GetInputArrayToProcess(0, input)));
57 if(usgIn == NULL || offsets == NULL || pdOut == NULL)
59 vtkDebugMacro("vtkELNOFilter no correctly configured : offsets = " << offsets);
63 vtkInformation *info(offsets->GetInformation());
64 vtkInformationQuadratureSchemeDefinitionVectorKey *key(vtkQuadratureSchemeDefinition::DICTIONARY());
67 vtkDebugMacro("Dictionary is not present in array " << offsets->GetName() << " " << offsets << " Aborting." );
71 int res(this->Superclass::RequestData(request, input, output));
75 int dictSize(key->Size(info));
76 vtkQuadratureSchemeDefinition **dict(new vtkQuadratureSchemeDefinition *[dictSize]);
77 key->GetRange(info, dict, 0, 0, dictSize);
79 vtkIdType ncell(usgIn->GetNumberOfCells());
80 vtkPoints *points(pdOut->GetPoints());
82 for(vtkIdType cellId = 0; cellId < ncell; cellId++)
84 vtkIdType offset(offsets->GetValue(cellId));
85 int cellType(usgIn->GetCellType(cellId));
86 // a simple check to see if a scheme really exists for this cell type.
87 // should not happen if the cell type has not been modified.
88 if(dict[cellType] == NULL)
90 int np = dict[cellType]->GetNumberOfQuadraturePoints();
91 double center[3] = {0, 0, 0};
92 for(int id = start; id < start + np; id++)
94 double *position = points->GetPoint(id);
95 center[0] += position[0];
96 center[1] += position[1];
97 center[2] += position[2];
102 for(int id = start; id < start + np; id++)
104 double *position = points->GetPoint(id);
106 newpos[0] = position[0] * this->ShrinkFactor + center[0] * (1 - this->ShrinkFactor);
107 newpos[1] = position[1] * this->ShrinkFactor + center[1] * (1 - this->ShrinkFactor);
108 newpos[2] = position[2] * this->ShrinkFactor + center[2] * (1 - this->ShrinkFactor);
109 points->SetPoint(id, newpos);
113 //// bug EDF 8407 PARAVIS - mantis 22610
114 vtkFieldData *fielddata(usgIn->GetFieldData());
115 for(int index=0;index<fielddata->GetNumberOfArrays();index++)
117 vtkDataArray *data(fielddata->GetArray(index));
118 vtkInformation *info(data->GetInformation());
119 const char *arrayOffsetName(info->Get(vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME()));
120 vtkIdTypeArray *offData(0);
124 vtkCellData *cellData(usgIn->GetCellData());
125 vtkDataArray *offDataTmp(cellData->GetArray(arrayOffsetName));
126 isELNO=offDataTmp->GetInformation()->Get(MEDUtilities::ELNO())==1;
127 offData=dynamic_cast<vtkIdTypeArray *>(offDataTmp);
129 if(isELNO && offData)
131 vtkIdType nbCellsInput(usgIn->GetNumberOfCells());
133 continue ;//no cells -> no fields
134 // First trying to detected if we are in the special case where data can be used directly. To detect that look at offData. If offData.front()==0 && offData->back()+NbOfNodesInLastCell==data->GetNumberOfTuples() OK.
135 vtkCell *cell(usgIn->GetCell(nbCellsInput-1));
136 bool statement0(offData->GetTuple1(0)==0);
137 bool statement1(offData->GetTuple1(nbCellsInput-1)+cell->GetNumberOfPoints()==data->GetNumberOfTuples());
138 if(statement0 && statement1)
139 pdOut->GetPointData()->AddArray(data);//We are lucky ! No extraction needed.
141 {//not lucky ! Extract values from data. A previous threshold has been done... Bug EDF8662
142 vtkDataArray *newArray(data->NewInstance());
143 newArray->SetName(data->GetName());
144 pdOut->GetPointData()->AddArray(newArray);
145 newArray->SetNumberOfComponents(data->GetNumberOfComponents());
146 newArray->SetNumberOfTuples(pdOut->GetNumberOfPoints());
147 newArray->CopyComponentNames(data);
149 vtkIdType *offsetPtr(offData->GetPointer(0));
151 for(vtkIdType cellId=0;cellId<nbCellsInput;cellId++)
153 vtkCell *cell(usgIn->GetCell(cellId));
154 vtkIdType nbPoints(cell->GetNumberOfPoints()),offset(offsetPtr[cellId]);
155 for(vtkIdType j=0;j<nbPoints;j++,zeId++)
156 newArray->SetTuple(zeId,offsetPtr[cellId]+j,data);
164 void vtkELNOFilter::PrintSelf(ostream& os, vtkIndent indent)
166 this->Superclass::PrintSelf(os, indent);
167 os << indent << "ShrinkFactor : " << this->ShrinkFactor << endl;