1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "VTKViewer_CellCenters.h"
26 #include <vtkCellData.h>
27 #include <vtkDataSet.h>
28 #include <vtkInformation.h>
29 #include <vtkInformationVector.h>
30 #include <vtkObjectFactory.h>
31 #include <vtkPointData.h>
32 #include <vtkPoints.h>
33 #include <vtkPolyData.h>
34 #include <vtkCellArray.h>
36 vtkCxxRevisionMacro(VTKViewer_CellCenters, "$Revision$");
37 vtkStandardNewMacro(VTKViewer_CellCenters);
40 * Class : VTKViewer_CellCenters
41 * Description : Filter computing geometrical centers of given cells
42 * (differs from native vtk filter by small fix for VTK_CONVEX_POINT_SET cells)
48 VTKViewer_CellCenters::VTKViewer_CellCenters()
55 int VTKViewer_CellCenters::RequestData(
56 vtkInformation *vtkNotUsed(request),
57 vtkInformationVector **inputVector,
58 vtkInformationVector *outputVector)
60 // get the info objects
61 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
62 vtkInformation *outInfo = outputVector->GetInformationObject(0);
64 // get the input and ouptut
65 vtkDataSet *input = vtkDataSet::SafeDownCast(
66 inInfo->Get(vtkDataObject::DATA_OBJECT()));
67 vtkPolyData *output = vtkPolyData::SafeDownCast(
68 outInfo->Get(vtkDataObject::DATA_OBJECT()));
70 vtkIdType cellId, numCells;
76 double x[3], pcoords[3];
79 inCD=input->GetCellData();
80 outPD=output->GetPointData();
82 if ( (numCells = input->GetNumberOfCells()) < 1 )
84 vtkWarningMacro(<<"No cells to generate center points for");
88 newPts = vtkPoints::New();
89 newPts->SetNumberOfPoints(numCells);
90 weights = new double [input->GetMaxCellSize()];
93 vtkIdType progressInterval = numCells/10 + 1;
94 int hasEmptyCells = 0;
95 for (cellId=0; cellId < numCells && !abort; cellId++)
97 if ( ! (cellId % progressInterval) )
99 vtkDebugMacro(<<"Processing #" << cellId);
100 this->UpdateProgress (0.5*cellId/numCells);
101 abort = this->GetAbortExecute();
104 cell = input->GetCell(cellId);
105 if (cell->GetCellType() != VTK_EMPTY_CELL)
107 // fix for VTK_CONVEX_POINT_SET cells
108 if (cell->GetCellType() == VTK_CONVEX_POINT_SET )
110 x[0] = x[1] = x[2] = 0;
111 vtkPoints* aPoints = cell->GetPoints();
112 int aNbPoints = aPoints->GetNumberOfPoints();
113 for( int i = 0; i < aNbPoints; i++ )
116 aPoints->GetPoint( i, aCoord );
127 subId = cell->GetParametricCenter(pcoords);
128 cell->EvaluateLocation(subId, pcoords, x, weights);
130 newPts->SetPoint(cellId,x);
138 if ( this->VertexCells )
141 vtkCellData *outCD=output->GetCellData();
142 vtkCellArray *verts = vtkCellArray::New();
143 verts->Allocate(verts->EstimateSize(1,numCells),1);
145 for (cellId=0; cellId < numCells && !abort; cellId++)
147 if ( ! (cellId % progressInterval) )
149 vtkDebugMacro(<<"Processing #" << cellId);
150 this->UpdateProgress (0.5+0.5*cellId/numCells);
151 abort = this->GetAbortExecute();
154 cell = input->GetCell(cellId);
155 if (cell->GetCellType() != VTK_EMPTY_CELL)
158 verts->InsertNextCell(1,pts);
162 output->SetVerts(verts);
166 outCD->PassData(inCD); //only if verts are generated
170 // clean up and update output
171 output->SetPoints(newPts);
176 outPD->PassData(inCD); //because number of points = number of cells