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.
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 "vtkELNOSurfaceFilter.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 "vtkPVGeometryFilter.h"
31 #include "vtkShrinkFilter.h"
32 #include "vtkSmartPointer.h"
33 #include "vtkPointData.h"
34 #include "vtkCellData.h"
35 #include "vtkIdList.h"
37 //vtkCxxRevisionMacro(vtkELNOSurfaceFilter, "$Revision$")
39 vtkStandardNewMacro(vtkELNOSurfaceFilter)
42 vtkELNOSurfaceFilter::vtkELNOSurfaceFilter()
46 vtkELNOSurfaceFilter::~vtkELNOSurfaceFilter()
50 int vtkELNOSurfaceFilter::RequestData(vtkInformation *request, 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("vtkELNOSurfaceFilter no correctly configured : offsets = " << usg_offsets);
67 // first shrink the input
68 vtkUnstructuredGrid* usgInClone=usgIn->NewInstance();
70 usgInClone->ShallowCopy(usgIn);
72 vtkSmartPointer<vtkPVGeometryFilter> geomFilter=vtkSmartPointer<
73 vtkPVGeometryFilter>::New();
74 geomFilter->SetInputData(usgInClone);
75 geomFilter->SetPassThroughCellIds(1);
76 geomFilter->SetPassThroughPointIds(1);
77 geomFilter->SetUseOutline(0);
80 vtkPolyData* surface=vtkPolyData::SafeDownCast(geomFilter->GetOutput());
81 vtkIdTypeArray* originalCellIds=vtkIdTypeArray::SafeDownCast(
82 surface->GetCellData()->GetArray("vtkOriginalCellIds"));
83 vtkIdTypeArray* originalPointIds=vtkIdTypeArray::SafeDownCast(
84 surface->GetPointData()->GetArray("vtkOriginalPointIds"));
86 if( originalCellIds == NULL )
88 vtkErrorMacro("vtkPVGeometryFilter return NULL 'vtkOriginalCellIds' array");
92 if(originalPointIds==NULL)
94 vtkErrorMacro("It appears that your dataset is not reduced using vtkPVGeometryFilter (NULL 'vtkOriginalPointIds).\n==================================================================================================\nProbably your dataset is not 3D.\nIf it is not a 3D dataset you are expected to use ELNO Mesh filter instead of ELNO Surface filter.\n==================================================================================================\n");
98 vtkSmartPointer<vtkShrinkFilter> shrink=
99 vtkSmartPointer<vtkShrinkFilter>::New();
100 shrink->SetInputConnection(geomFilter->GetOutputPort(0));
101 shrink->SetShrinkFactor(0.9999);
104 vtkUnstructuredGrid* shrinked=shrink->GetOutput();
106 usgInClone->Delete();
108 usgOut->ShallowCopy(shrinked);
110 vtkIdTypeArray* offsets=vtkIdTypeArray::SafeDownCast(
111 shrinked->GetCellData()->GetArray(usg_offsets->GetName()));
113 // now copy ELNO data. Start by verifying if it is possible to
114 // shallow copy the array.
115 vtkInformation *info=offsets->GetInformation();
116 vtkInformationQuadratureSchemeDefinitionVectorKey *key=
117 vtkQuadratureSchemeDefinition::DICTIONARY();
120 vtkDebugMacro("Dictionary is not present in array " << offsets->GetName()
121 << " " << offsets << " Aborting." );
124 int dictSize=key->Size(info);
125 vtkQuadratureSchemeDefinition **dict=
126 new vtkQuadratureSchemeDefinition *[dictSize];
127 key->GetRange(info, dict, 0, 0, dictSize);
129 vtkIdType ncell=shrinked->GetNumberOfCells();
131 vtkFieldData* fielddata=usgIn->GetFieldData();
132 vtkIdList *ids=vtkIdList::New();
133 vtkIdList *surfaceIds=vtkIdList::New();
134 vtkIdList *originalIds=vtkIdList::New();
135 for(int index=0; index<fielddata->GetNumberOfArrays(); index++)
137 vtkDataArray* data=fielddata->GetArray(index);
141 vtkInformation* info=data->GetInformation();
142 const char* arrayOffsetName=info->Get(
143 vtkQuadratureSchemeDefinition::QUADRATURE_OFFSET_ARRAY_NAME());
145 if(arrayOffsetName == NULL ||
146 strcmp(arrayOffsetName, offsets->GetName())!=0)
148 usgOut->GetFieldData()->AddArray(data);
153 vtkDataArray* newArray=data->NewInstance();
154 newArray->SetName(data->GetName());
155 usgOut->GetPointData()->AddArray(newArray);
156 newArray->SetNumberOfComponents(data->GetNumberOfComponents());
157 newArray->SetNumberOfTuples(usgOut->GetNumberOfPoints());
158 newArray->CopyComponentNames(data);
161 for(vtkIdType cellId=0; cellId<ncell; cellId++)
163 vtkIdType offset=offsets->GetValue(cellId);
165 vtkIdType originalCellId=originalCellIds->GetValue(cellId);
166 int originalCellType=usgIn->GetCellType(originalCellId);
168 shrinked->GetCellPoints(cellId, ids);
169 surface->GetCellPoints(cellId, surfaceIds);
171 for(int id=0; id<ids->GetNumberOfIds(); id++)
173 vtkIdType surfaceId=surfaceIds->GetId(id);
174 vtkIdType shrinkedId=ids->GetId(id);
175 vtkIdType originalPointId = originalPointIds->GetValue(surfaceId);
177 usgIn->GetCellPoints(originalCellId, originalIds);
178 int originalLocalId=-1;
179 for(int li=0; li<originalIds->GetNumberOfIds(); li++)
181 if(originalPointId==originalIds->GetId(li))
187 if(originalLocalId==-1)
190 vtkErrorMacro("cannot find original id");
193 const double * w=dict[originalCellType]->GetShapeFunctionWeights(
196 for(j=0; j<dict[originalCellType]->GetNumberOfNodes(); j++)
201 if(j==dict[originalCellType]->GetNumberOfNodes())
203 //vtkErrorMacro("cannot find elno weigth.");
206 newArray->SetTuple(shrinkedId, offset+j, data);
212 surfaceIds->FastDelete();
213 originalIds->FastDelete();
219 void vtkELNOSurfaceFilter::PrintSelf(ostream& os, vtkIndent indent)
221 this->Superclass::PrintSelf(os, indent);