/usr/include/paraview/vtkStaticCellLinksTemplate.txx is in paraview-dev 5.0.1+dfsg1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | /*=========================================================================
Program: Visualization Toolkit
Module: vtkStaticCellLinksTemplate.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkStaticCellLinksTemplate.h"
#ifndef vtkStaticCellLinksTemplate_txx
#define vtkStaticCellLinksTemplate_txx
#include "vtkCellArray.h"
#include "vtkDataSet.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
//----------------------------------------------------------------------------
// Note: this class is a faster, serial version of vtkCellLinks. Future work
// to parallelize this class is possible. This includes:
// = using a parallel prefix sum operation
// = using atomics to update counts (i.e., number of cells using a point)
//----------------------------------------------------------------------------
// Clean up any previously allocated memory
template <typename TIds> void vtkStaticCellLinksTemplate<TIds>::
Initialize()
{
if ( this->Links )
{
delete [] this->Links;
this->Links = NULL;
}
if ( this->Offsets )
{
delete [] this->Offsets;
this->Offsets = NULL;
}
}
//----------------------------------------------------------------------------
// Build the link list array for any dataset type. Specialized methods are
// used for dataset types that use vtkCellArrays to represent cells.
template <typename TIds> void vtkStaticCellLinksTemplate<TIds>::
BuildLinks(vtkDataSet *ds)
{
// Use a fast path if polydata or unstructured grid
if ( ds->GetDataObjectType() == VTK_POLY_DATA )
{
return this->BuildLinks(static_cast<vtkPolyData*>(ds));
}
else if ( ds->GetDataObjectType() == VTK_UNSTRUCTURED_GRID )
{
return this->BuildLinks(static_cast<vtkUnstructuredGrid*>(ds));
}
// Any other type of dataset. Generally this is not called as datasets have
// their own, more efficient ways of getting similar information.
// Make sure that we clear out previous allocation.
this->NumCells = ds->GetNumberOfCells();
this->NumPts = ds->GetNumberOfPoints();
vtkIdType npts, ptId;
vtkIdType cellId, j;
vtkIdList *cellPts = vtkIdList::New();
// Traverse data to determine number of uses of each point. Also count the
// number of links to allocate.
this->Offsets = new TIds[this->NumPts+1];
std::fill_n(this->Offsets, this->NumPts, 0);
for (this->LinksSize=0, cellId=0; cellId < this->NumCells; cellId++)
{
ds->GetCellPoints(cellId,cellPts);
npts = cellPts->GetNumberOfIds();
for (j=0; j < npts; j++)
{
this->Offsets[cellPts->GetId(j)]++;
this->LinksSize++;
}
}
// Allocate space for links. Perform prefix sum.
this->Links = new TIds[this->LinksSize+1];
this->Links[this->LinksSize] = this->NumPts;
for ( ptId=0; ptId < this->NumPts; ++ptId )
{
npts = this->Offsets[ptId+1];
this->Offsets[ptId+1] = this->Offsets[ptId] + npts;
}
// Now build the links. The summation from the prefix sum indicates where
// the cells are to be inserted. Each time a cell is inserted, the offset
// is decremented. In the end, the offset array is also constructed as it
// points to the beginning of each cell run.
for ( cellId=0; cellId < this->NumCells; ++cellId )
{
ds->GetCellPoints(cellId,cellPts);
npts = cellPts->GetNumberOfIds();
for (j=0; j<npts; ++j)
{
ptId = cellPts->GetId(j);
this->Offsets[ptId]--;
this->Links[this->Offsets[ptId]] = cellId;
}
}
this->Offsets[this->NumPts] = this->LinksSize;
cellPts->Delete();
}
//----------------------------------------------------------------------------
// Build the link list array for unstructured grids
template <typename TIds> void vtkStaticCellLinksTemplate<TIds>::
BuildLinks(vtkUnstructuredGrid *ugrid)
{
// Basic information about the grid
this->NumCells = ugrid->GetNumberOfCells();
this->NumPts = ugrid->GetNumberOfPoints();
// We're going to get into the guts of the class
vtkCellArray *cellArray = ugrid->GetCells();
const vtkIdType *cells = cellArray->GetPointer();
// I love this trick: the size of the Links array is equal to
// the size of the cell array, minus the number of cells.
this->LinksSize =
cellArray->GetNumberOfConnectivityEntries() - this->NumCells;
// Extra one allocated to simplify later pointer manipulation
this->Links = new TIds[this->LinksSize+1];
this->Links[this->LinksSize] = this->NumPts;
this->Offsets = new TIds[this->NumPts+1];
std::fill_n(this->Offsets, this->NumPts, 0);
// Now create the links.
vtkIdType npts, cellId, ptId;
const vtkIdType *cell=cells;
int i;
// Count number of point uses
for ( cellId=0; cellId < this->NumCells; ++cellId )
{
npts = *cell++;
for (i=0; i<npts; ++i)
{
this->Offsets[*cell++]++;
}
}
// Perform prefix sum
for ( ptId=0; ptId < this->NumPts; ++ptId )
{
npts = this->Offsets[ptId+1];
this->Offsets[ptId+1] = this->Offsets[ptId] + npts;
}
// Now build the links. The summation from the prefix sum indicates where
// the cells are to be inserted. Each time a cell is inserted, the offset
// is decremented. In the end, the offset array is also constructed as it
// points to the beginning of each cell run.
for ( cell=cells, cellId=0; cellId < this->NumCells; ++cellId )
{
npts = *cell++;
for (i=0; i<npts; ++i)
{
this->Offsets[*cell]--;
this->Links[this->Offsets[*cell++]] = cellId;
}
}
this->Offsets[this->NumPts] = this->LinksSize;
}
//----------------------------------------------------------------------------
// Build the link list array for poly data. This is more complex because there
// are potentially fout different cell arrays to contend with.
template <typename TIds> void vtkStaticCellLinksTemplate<TIds>::
BuildLinks(vtkPolyData *pd)
{
// Basic information about the grid
this->NumCells = pd->GetNumberOfCells();
this->NumPts = pd->GetNumberOfPoints();
vtkCellArray *cellArrays[4];
vtkIdType numCells[4];
vtkIdType sizes[4];
int i, j;
cellArrays[0] = pd->GetVerts();
cellArrays[1] = pd->GetLines();
cellArrays[2] = pd->GetPolys();
cellArrays[3] = pd->GetStrips();
for (i=0; i<4; ++i)
{
if ( cellArrays[i] != NULL )
{
numCells[i] = cellArrays[i]->GetNumberOfCells();
sizes[i] = cellArrays[i]->GetNumberOfConnectivityEntries() - numCells[i];
}
else
{
numCells[i] = 0;
sizes[i] = 0;
}
}//for the four polydata arrays
// Allocate
this->LinksSize = sizes[0] + sizes[1] + sizes[2] + sizes[3];
this->Links = new TIds[this->LinksSize+1];
this->Links[this->LinksSize] = this->NumPts;
this->Offsets = new TIds[this->NumPts+1];
this->Offsets[this->NumPts] = this->LinksSize;
std::fill_n(this->Offsets, this->NumPts, 0);
// Now create the links.
vtkIdType npts, cellId, CellId, ptId;
const vtkIdType *cell;
// Visit the four arrays
for ( CellId=0, j=0; j < 4; ++j )
{
// Count number of point uses
cell = cellArrays[j]->GetPointer();
for ( cellId=0; cellId < numCells[j]; ++cellId )
{
npts = *cell++;
for (i=0; i<npts; ++i)
{
this->Offsets[CellId+(*cell++)]++;
}
}
CellId += numCells[j];
} //for each of the four polydata cell arrays
// Perform prefix sum
for ( ptId=0; ptId < this->NumPts; ++ptId )
{
npts = this->Offsets[ptId+1];
this->Offsets[ptId+1] = this->Offsets[ptId] + npts;
}
// Now build the links. The summation from the prefix sum indicates where
// the cells are to be inserted. Each time a cell is inserted, the offset
// is decremented. In the end, the offset array is also constructed as it
// points to the beginning of each cell run.
for ( CellId=0, j=0; j < 4; ++j )
{
cell = cellArrays[j]->GetPointer();
for ( cellId=0; cellId < numCells[j]; ++cellId )
{
npts = *cell++;
for (i=0; i<npts; ++i)
{
this->Offsets[*cell]--;
this->Links[this->Offsets[*cell++]] = CellId+cellId;
}
}
CellId += numCells[j];
}//for each of the four polydata arrays
this->Offsets[this->NumPts] = this->LinksSize;
}
#endif
|