Build the neighborhood.
33{
34 vtkIdType i, j, id;
35 vtkIdType numCellsInStencil;
36 vtkIdType startCell, nextCell;
37 vtkIdType p1, p2;
38 vtkIdType bp1, bp2;
39 vtkIdType K;
40 vtkIdType pointId;
41 vtkIdList *cellIds, *ptIds, *stencilIds;
42 vtkCell* cell;
43 vtkPolyData* pdata = vtkPolyData::SafeDownCast(this->
DataSet);
44
45 if (pdata==NULL)
46 {
47 vtkErrorMacro(<< "Input data NULL or not poly data");
48 }
49
51
53
54 cellIds = vtkIdList::New();
55 ptIds = vtkIdList::New();
56 stencilIds = vtkIdList::New();
57
58 pdata->GetPointCells (pointId, cellIds);
59 numCellsInStencil = cellIds->GetNumberOfIds();
60 if (numCellsInStencil < 1)
61 {
62
63 cellIds->Delete();
64 ptIds->Delete();
65 stencilIds->Delete();
66 return;
67 }
68
69 pdata->GetCellPoints(cellIds->GetId(0),ptIds);
70 p2 = ptIds->GetId(0);
71 i = 1;
72 while (pointId == p2)
73 {
74 p2 = ptIds->GetId(i++);
75 }
76
77 pdata->GetCellEdgeNeighbors (-1,pointId,p2,cellIds);
78
79 nextCell = cellIds->GetId(0);
80 bp2 = -1;
81 bp1 = p2;
82 if (cellIds->GetNumberOfIds() == 1)
83 {
84 startCell = -1;
85 }
86 else
87 {
88 startCell = cellIds->GetId(1);
89 }
90
91 stencilIds->InsertNextId(p2);
92
93
94 for (j=0; j<numCellsInStencil; j++)
95 {
96 cell = pdata->GetCell(nextCell);
97 p1 = -1;
98 for (i = 0; i < 3; i++)
99 {
100 if ((p1 = cell->GetPointId(i)) != pointId && cell->GetPointId(i) != p2)
101 {
102 break;
103 }
104 }
105
106 p2 = p1;
107 stencilIds->InsertNextId (p2);
108 pdata->GetCellEdgeNeighbors (nextCell, pointId, p2, cellIds);
109 if (cellIds->GetNumberOfIds() != 1)
110 {
111 bp2 = p2;
112 j++;
113 break;
114 }
115 nextCell = cellIds->GetId(0);
116 }
117
118
119
120 nextCell = startCell;
121 p2 = bp1;
122 for (; j<numCellsInStencil && startCell!=-1; j++)
123 {
124 cell = pdata->GetCell(nextCell);
125 p1 = -1;
126 for (i=0; i<3; i++)
127 {
128 if ((p1=cell->GetPointId(i))!=pointId && cell->GetPointId(i)!=p2)
129 {
130 break;
131 }
132 }
133 p2 = p1;
134 stencilIds->InsertNextId(p2);
135 pdata->GetCellEdgeNeighbors (nextCell, pointId, p2, cellIds);
136 if (cellIds->GetNumberOfIds() != 1)
137 {
138 bp1 = p2;
139 break;
140 }
141 nextCell = cellIds->GetId(0);
142 }
143
144 if (bp2 != -1)
145 {
147 id = stencilIds->IsId(bp2);
148 for (i=0; i<=id/2; i++)
149 {
150 p1 = stencilIds->GetId(i);
151 p2 = stencilIds->GetId(id-i);
152 stencilIds->SetId(i,p2);
153 stencilIds->SetId(id-i,p1);
154 }
155 }
156 else
157 {
159 K = stencilIds->GetNumberOfIds();
160
161 stencilIds->SetNumberOfIds(--K);
162 }
163
164 this->
NPoints = stencilIds->GetNumberOfIds();
166 {
169 }
171 memcpy(this->
PointIds,stencilIds->GetPointer(0),this->NPoints*
sizeof(vtkIdType));
172
173 cellIds->Delete();
174 ptIds->Delete();
175 stencilIds->Delete();
176}