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
19 // Author : Anthony Geay
21 #include "vtkGenerateVectors.h"
22 #include "vtkDoubleArray.h"
23 #include "vtkInformation.h"
24 #include "vtkQuadratureSchemeDefinition.h"
25 #include "MEDUtilities.hxx"
26 #define protected public
27 #include "vtkFieldData.h"
29 void vtkGenerateVectors::Operate(vtkFieldData *fd)
33 const int nbOfArrs(fd->GetNumberOfArrays());
34 for(int i=0;i<nbOfArrs;i++)
36 vtkDataArray *arr(fd->GetArray(i));
39 vtkDoubleArray *arrc(vtkDoubleArray::SafeDownCast(arr));
42 int nbOfCompo(arrc->GetNumberOfComponents());
43 if(nbOfCompo<=1 || nbOfCompo==3)
46 fd->SetArray(i,Operate2Compo(arrc));
48 fd->SetArray(i,OperateMoreThan3Compo(arrc));
52 vtkDoubleArray *vtkGenerateVectors::Operate2Compo(vtkDoubleArray *oldArr)
54 static const int VTK_DATA_ARRAY_FREE=vtkDataArrayTemplate<double>::VTK_DATA_ARRAY_FREE;
55 vtkDoubleArray *ret(vtkDoubleArray::New());
56 std::size_t nbOfTuples(oldArr->GetNumberOfTuples());
57 const double *inPt(oldArr->GetPointer(0));
58 double *pt((double *)malloc(nbOfTuples*3*sizeof(double)));
59 for(std::size_t i=0;i<nbOfTuples;i++)
61 pt[3*i+0]=inPt[2*i+0];
62 pt[3*i+1]=inPt[2*i+1];
65 ret->SetNumberOfComponents(3);
66 ret->SetName(oldArr->GetName());
67 ret->SetComponentName(0,oldArr->GetComponentName(0));
68 ret->SetComponentName(1,oldArr->GetComponentName(1));
69 ret->SetArray(pt,3*nbOfTuples,0,VTK_DATA_ARRAY_FREE);
70 UpdateInformationOfArray(oldArr,ret);
74 vtkDoubleArray *vtkGenerateVectors::OperateMoreThan3Compo(vtkDoubleArray *oldArr)
76 static const int VTK_DATA_ARRAY_FREE=vtkDataArrayTemplate<double>::VTK_DATA_ARRAY_FREE;
77 vtkDoubleArray *ret(vtkDoubleArray::New());
78 int nbOfCompo(oldArr->GetNumberOfComponents());
79 std::size_t nbOfTuples(oldArr->GetNumberOfTuples());
80 const double *inPt(oldArr->GetPointer(0));
81 double *pt((double *)malloc(nbOfTuples*3*sizeof(double)));
82 for(std::size_t i=0;i<nbOfTuples;i++)
84 pt[3*i+0]=inPt[nbOfCompo*i+0];
85 pt[3*i+1]=inPt[nbOfCompo*i+1];
86 pt[3*i+2]=inPt[nbOfCompo*i+2];
88 ret->SetNumberOfComponents(3);
89 ret->SetName(oldArr->GetName());
90 ret->SetComponentName(0,oldArr->GetComponentName(0));
91 ret->SetComponentName(1,oldArr->GetComponentName(1));
92 ret->SetComponentName(2,oldArr->GetComponentName(2));
93 ret->SetArray(pt,3*nbOfTuples,0,VTK_DATA_ARRAY_FREE);
94 UpdateInformationOfArray(oldArr,ret);
98 void vtkGenerateVectors::UpdateInformationOfArray(vtkDoubleArray *oldArr, vtkDoubleArray *arr)
100 if(oldArr->GetInformation()->Has(vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME()))
102 arr->GetInformation()->Set(vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME(),oldArr->GetInformation()->Get((vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME())));
104 if(oldArr->GetInformation()->Get(MEDUtilities::ELGA()))
105 arr->GetInformation()->Set(MEDUtilities::ELGA(),1);
106 if(oldArr->GetInformation()->Get(MEDUtilities::ELNO()))
107 arr->GetInformation()->Set(MEDUtilities::ELNO(),1);