1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 vtkStandardNewMacro(VTKViewer_CellCenters);
39 * Class : VTKViewer_CellCenters
40 * Description : Filter computing geometrical centers of given cells
41 * (differs from native vtk filter by small fix for VTK_CONVEX_POINT_SET cells)
47 VTKViewer_CellCenters::VTKViewer_CellCenters()
54 int VTKViewer_CellCenters::RequestData(
55 vtkInformation *vtkNotUsed(request),
56 vtkInformationVector **inputVector,
57 vtkInformationVector *outputVector)
59 // get the info objects
60 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
61 vtkInformation *outInfo = outputVector->GetInformationObject(0);
63 // get the input and ouptut
64 vtkDataSet *input = vtkDataSet::SafeDownCast(
65 inInfo->Get(vtkDataObject::DATA_OBJECT()));
66 vtkPolyData *output = vtkPolyData::SafeDownCast(
67 outInfo->Get(vtkDataObject::DATA_OBJECT()));
69 vtkIdType cellId, numCells;
75 double x[3], pcoords[3];
78 inCD=input->GetCellData();
79 outPD=output->GetPointData();
81 if ( (numCells = input->GetNumberOfCells()) < 1 )
83 vtkWarningMacro(<<"No cells to generate center points for");
87 newPts = vtkPoints::New();
88 newPts->SetNumberOfPoints(numCells);
89 weights = new double [input->GetMaxCellSize()];
92 vtkIdType progressInterval = numCells/10 + 1;
93 int hasEmptyCells = 0;
94 for (cellId=0; cellId < numCells && !abort; cellId++)
96 if ( ! (cellId % progressInterval) )
98 vtkDebugMacro(<<"Processing #" << cellId);
99 this->UpdateProgress (0.5*cellId/numCells);
100 abort = this->GetAbortExecute();
103 cell = input->GetCell(cellId);
104 if (cell->GetCellType() != VTK_EMPTY_CELL)
106 // fix for VTK_CONVEX_POINT_SET cells
107 if (cell->GetCellType() == VTK_CONVEX_POINT_SET )
109 x[0] = x[1] = x[2] = 0;
110 vtkPoints* aPoints = cell->GetPoints();
111 int aNbPoints = aPoints->GetNumberOfPoints();
112 for( int i = 0; i < aNbPoints; i++ )
115 aPoints->GetPoint( i, aCoord );
126 subId = cell->GetParametricCenter(pcoords);
127 cell->EvaluateLocation(subId, pcoords, x, weights);
129 newPts->SetPoint(cellId,x);
137 if ( this->VertexCells )
140 vtkCellData *outCD=output->GetCellData();
141 vtkCellArray *verts = vtkCellArray::New();
142 verts->Allocate(verts->EstimateSize(1,numCells),1);
144 for (cellId=0; cellId < numCells && !abort; cellId++)
146 if ( ! (cellId % progressInterval) )
148 vtkDebugMacro(<<"Processing #" << cellId);
149 this->UpdateProgress (0.5+0.5*cellId/numCells);
150 abort = this->GetAbortExecute();
153 cell = input->GetCell(cellId);
154 if (cell->GetCellType() != VTK_EMPTY_CELL)
157 verts->InsertNextCell(1,pts);
161 output->SetVerts(verts);
165 outCD->PassData(inCD); //only if verts are generated
169 // clean up and update output
170 output->SetPoints(newPts);
175 outPD->PassData(inCD); //because number of points = number of cells