| 191 | } |
| 192 | |
| 193 | void vtkImageToPolyDataFilter::PixelizeImage(vtkUnsignedCharArray* pixels, int dims[3], |
| 194 | double origin[3], double spacing[3], vtkPolyData* output) |
| 195 | { |
| 196 | int numPts, numCells, i, j, id; |
| 197 | vtkIdType pts[4]; |
| 198 | vtkPoints* newPts; |
| 199 | vtkCellArray* newPolys; |
| 200 | double x[3]; |
| 201 | vtkUnsignedCharArray* polyColors; |
| 202 | unsigned char *ptr, *colors = pixels->GetPointer(0); |
| 203 | |
| 204 | // create the points - see whether to create or append |
| 205 | numPts = (dims[0] + 1) * (dims[1] + 1); |
| 206 | newPts = vtkPoints::New(); |
| 207 | newPts->SetNumberOfPoints(numPts); |
| 208 | |
| 209 | x[2] = 0.0; |
| 210 | for (id = 0, j = 0; j <= dims[1]; j++) |
| 211 | { |
| 212 | x[1] = origin[1] + j * spacing[1]; |
| 213 | for (i = 0; i <= dims[0]; i++) |
| 214 | { |
| 215 | x[0] = origin[0] + i * spacing[0]; |
| 216 | newPts->SetPoint(id, x); |
| 217 | id++; |
| 218 | } |
| 219 | } |
| 220 | output->SetPoints(newPts); |
| 221 | newPts->Delete(); |
| 222 | |
| 223 | // create the cells and cell colors |
| 224 | // |
| 225 | numCells = dims[0] * dims[1]; |
| 226 | newPolys = vtkCellArray::New(); |
| 227 | newPolys->AllocateEstimate(numCells, 4); |
| 228 | |
| 229 | polyColors = vtkUnsignedCharArray::New(); |
| 230 | polyColors->SetNumberOfValues(3 * numCells); // for rgb |
| 231 | polyColors->SetNumberOfComponents(3); |
| 232 | |
| 233 | // loop over all pixels, creating a quad per pixel. |
| 234 | // Note: copying point data (pixel values) to cell data (quad colors). |
| 235 | for (id = 0, j = 0; j < dims[1]; j++) |
| 236 | { |
| 237 | for (i = 0; i < dims[0]; i++) |
| 238 | { |
| 239 | pts[0] = i + j * (dims[0] + 1); |
| 240 | pts[1] = pts[0] + 1; |
| 241 | pts[2] = pts[1] + dims[0] + 1; |
| 242 | pts[3] = pts[2] - 1; |
| 243 | newPolys->InsertNextCell(4, pts); |
| 244 | ptr = colors + 3 * id; |
| 245 | polyColors->SetValue(3 * id, ptr[0]); |
| 246 | polyColors->SetValue(3 * id + 1, ptr[1]); |
| 247 | polyColors->SetValue(3 * id + 2, ptr[2]); |
| 248 | id++; |
| 249 | } |
| 250 | } |
no test coverage detected