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 "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 "vtkInformationQuadratureSchemeDefinitionVectorKey.h"
28 #include "vtkQuadratureSchemeDefinition.h"
29 #include "vtkUnstructuredGrid.h"
31 //vtkCxxRevisionMacro(vtkELNOFilter, "$Revision$");
32 vtkStandardNewMacro(vtkELNOFilter);
34 vtkELNOFilter::vtkELNOFilter()
36 this->ShrinkFactor = 0.5;
39 vtkELNOFilter::~vtkELNOFilter()
43 int vtkELNOFilter::RequestData(vtkInformation *request,
44 vtkInformationVector **input, vtkInformationVector *output)
46 vtkUnstructuredGrid *usgIn = vtkUnstructuredGrid::SafeDownCast(
47 input[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
49 vtkPolyData *pdOut = vtkPolyData::SafeDownCast(
50 output->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
52 vtkDataArray* array = this->GetInputArrayToProcess(0, input);
53 vtkIdTypeArray* offsets = vtkIdTypeArray::SafeDownCast(
54 this->GetInputArrayToProcess(0, input));
56 if(usgIn == NULL || offsets == NULL || pdOut == NULL)
58 vtkDebugMacro("vtkELNOFilter no correctly configured : offsets = " << offsets);
62 vtkInformation *info = offsets->GetInformation();
63 vtkInformationQuadratureSchemeDefinitionVectorKey *key =
64 vtkQuadratureSchemeDefinition::DICTIONARY();
67 vtkDebugMacro("Dictionary is not present in array " << offsets->GetName() << " " << offsets << " Aborting." );
71 int res = this->Superclass::RequestData(request, input, output);
77 int dictSize = key->Size(info);
78 vtkQuadratureSchemeDefinition **dict =
79 new vtkQuadratureSchemeDefinition *[dictSize];
80 key->GetRange(info, dict, 0, 0, dictSize);
82 vtkIdType ncell = usgIn->GetNumberOfCells();
83 vtkPoints *points = pdOut->GetPoints();
85 for(vtkIdType cellId = 0; cellId < ncell; cellId++)
87 vtkIdType offset = offsets->GetValue(cellId);
88 int cellType = usgIn->GetCellType(cellId);
89 // a simple check to see if a scheme really exists for this cell type.
90 // should not happen if the cell type has not been modified.
91 if(dict[cellType] == NULL)
93 int np = dict[cellType]->GetNumberOfQuadraturePoints();
94 double center[3] = {0, 0, 0};
95 for(int id = start; id < start + np; id++)
97 double *position = points->GetPoint(id);
98 center[0] += position[0];
99 center[1] += position[1];
100 center[2] += position[2];
105 for(int id = start; id < start + np; id++)
107 double *position = points->GetPoint(id);
109 newpos[0] = position[0] * this->ShrinkFactor + center[0] * (1
110 - this->ShrinkFactor);
111 newpos[1] = position[1] * this->ShrinkFactor + center[1] * (1
112 - this->ShrinkFactor);
113 newpos[2] = position[2] * this->ShrinkFactor + center[2] * (1
114 - this->ShrinkFactor);
115 points->SetPoint(id, newpos);
123 void vtkELNOFilter::PrintSelf(ostream& os, vtkIndent indent)
125 this->Superclass::PrintSelf(os, indent);
127 os << indent << "ShrinkFactor : " << this->ShrinkFactor << endl;