| 1136 | } |
| 1137 | |
| 1138 | void vtkImageToPolyDataFilter::BuildPolygons(vtkUnsignedCharArray* vtkNotUsed(pointDescr), |
| 1139 | vtkPolyData* edges, int numPolys, vtkUnsignedCharArray* polyColors) |
| 1140 | { |
| 1141 | vtkPoints* points = edges->GetPoints(); |
| 1142 | vtkIdType numPts = points->GetNumberOfPoints(), ptId; |
| 1143 | int i, j, k, *polyId, *polyId2, edgeId; |
| 1144 | vtkIdType* cells; |
| 1145 | const vtkIdType* pts; |
| 1146 | vtkIdType* cells2; |
| 1147 | vtkIdType npts; |
| 1148 | vtkIdType cellId; |
| 1149 | int numPolyPts, p1, p2; |
| 1150 | vtkIdType ncells, ncells2; |
| 1151 | unsigned char* ptr; |
| 1152 | vtkCellArray* newPolys; |
| 1153 | |
| 1154 | // Make sure we can topological info |
| 1155 | edges->BuildLinks(); |
| 1156 | |
| 1157 | // Mark all polygons as unvisited |
| 1158 | std::vector<unsigned char> polyVisited(numPolys, 0); |
| 1159 | |
| 1160 | // Create connectivity array for polygon definition |
| 1161 | newPolys = vtkCellArray::New(); |
| 1162 | newPolys->AllocateEstimate(numPolys, 25); |
| 1163 | |
| 1164 | // Loop over all edge points tracking around each polygon |
| 1165 | for (ptId = 0; ptId < numPts; ptId++) |
| 1166 | { |
| 1167 | edges->GetPointCells(ptId, ncells, cells); |
| 1168 | if (ncells < 2) |
| 1169 | { |
| 1170 | vtkErrorMacro(<< "Bad mojo"); |
| 1171 | return; |
| 1172 | } |
| 1173 | // for each edge, walk around polygon (if not visited before) |
| 1174 | for (i = 0; i < ncells; i++) |
| 1175 | { |
| 1176 | edgeId = cells[i]; |
| 1177 | polyId = this->EdgeUses->GetPointer(2 * edgeId); |
| 1178 | for (j = 0; j < 2; j++) |
| 1179 | { |
| 1180 | if (polyId[j] != -1 && !polyVisited[polyId[j]]) |
| 1181 | { // build loop |
| 1182 | polyVisited[polyId[j]] = 1; |
| 1183 | numPolyPts = 1; |
| 1184 | cellId = newPolys->InsertNextCell(0); // will update count later |
| 1185 | newPolys->InsertCellPoint(ptId); |
| 1186 | |
| 1187 | // Update polygonal color |
| 1188 | ptr = this->PolyColors->GetPointer(3 * polyId[j]); |
| 1189 | polyColors->SetValue(3 * cellId, ptr[0]); // assign poly color |
| 1190 | polyColors->SetValue(3 * cellId + 1, ptr[1]); |
| 1191 | polyColors->SetValue(3 * cellId + 2, ptr[2]); |
| 1192 | |
| 1193 | p1 = ptId; |
| 1194 | while (true) |
| 1195 | { |
no test coverage detected