VMTK
Loading...
Searching...
No Matches
vtkvmtkUnstructuredGridNeighborhood.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkUnstructuredGridNeighborhood.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:46:44 $
7Version: $Revision: 1.3 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23
24#include "vtkObjectFactory.h"
25#include "vtkIdList.h"
26#include "vtkCell.h"
27
28
30
32{
33 vtkIdType i, j;
34 vtkIdType numCellsInStencil;
35 vtkIdList *cellIds, *ptIds, *stencilIds;
36 vtkUnstructuredGrid* ugdata = vtkUnstructuredGrid::SafeDownCast(this->DataSet);
37
38 if (ugdata==NULL)
39 {
40 vtkErrorMacro(<< "Input data NULL or not poly data");
41 }
42
43 vtkIdType pointId = this->DataSetPointId;
44
45 this->NPoints = 0;
46
47 cellIds = vtkIdList::New();
48 ptIds = vtkIdList::New();
49 stencilIds = vtkIdList::New();
50
51 ugdata->GetPointCells (pointId, cellIds);
52 numCellsInStencil = cellIds->GetNumberOfIds();
53 if (numCellsInStencil < 1)
54 {
55 // vtkWarningMacro("numCellsInStencil < 1: " << numCellsInStencil);
56 cellIds->Delete();
57 ptIds->Delete();
58 stencilIds->Delete();
59 return;
60 }
61
62 vtkIdType cellPointId;
63 for (i=0; i<numCellsInStencil; i++)
64 {
65 if (ugdata->GetCell(cellIds->GetId(i))->GetCellDimension() != 3)
66 {
67 continue;
68 }
69 ugdata->GetCellPoints(cellIds->GetId(i),ptIds);
70 for (j=0; j<ptIds->GetNumberOfIds(); j++)
71 {
72 cellPointId = ptIds->GetId(j);
73 if (cellPointId != pointId)
74 {
75 stencilIds->InsertUniqueId(cellPointId);
76 }
77 }
78 }
79
80 this->NPoints = stencilIds->GetNumberOfIds();
81 if (this->PointIds!=NULL)
82 {
83 delete[] this->PointIds;
84 this->PointIds = NULL;
85 }
86 this->PointIds = new vtkIdType[this->NPoints];
87 memcpy(this->PointIds,stencilIds->GetPointer(0),this->NPoints*sizeof(vtkIdType));
88
89 cellIds->Delete();
90 ptIds->Delete();
91 stencilIds->Delete();
92}
93
Apply a neighborhood to the vertices on of a unstructured grid data set.
vtkStandardNewMacro(vtkvmtkUnstructuredGridNeighborhood)