| 509 | } |
| 510 | |
| 511 | vtkSmartPointer<vtkPolyData> mitk::LabelSetImageVtkMapper2D::CreateOutlinePolyData(mitk::BaseRenderer *renderer, |
| 512 | vtkImageData *image, |
| 513 | int pixelValue) |
| 514 | { |
| 515 | LocalStorage *localStorage = this->GetLocalStorage(renderer); |
| 516 | |
| 517 | // get the min and max index values of each direction |
| 518 | int *extent = image->GetExtent(); |
| 519 | int xMin = extent[0]; |
| 520 | int xMax = extent[1]; |
| 521 | int yMin = extent[2]; |
| 522 | int yMax = extent[3]; |
| 523 | |
| 524 | int *dims = image->GetDimensions(); // dimensions of the image |
| 525 | int line = dims[0]; // how many pixels per line? |
| 526 | int x = xMin; // pixel index x |
| 527 | int y = yMin; // pixel index y |
| 528 | |
| 529 | // get the depth for each contour |
| 530 | float depth = this->CalculateLayerDepth(renderer); |
| 531 | |
| 532 | vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); // the points to draw |
| 533 | vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New(); // the lines to connect the points |
| 534 | |
| 535 | // We take the pointer to the first pixel of the image |
| 536 | auto *currentPixel = static_cast<mitk::Label::PixelType *>(image->GetScalarPointer()); |
| 537 | |
| 538 | while (y <= yMax) |
| 539 | { |
| 540 | // if the current pixel value is set to something |
| 541 | if ((currentPixel) && (*currentPixel == pixelValue)) |
| 542 | { |
| 543 | // check in which direction a line is necessary |
| 544 | // a line is added if the neighbor of the current pixel has the value 0 |
| 545 | // and if the pixel is located at the edge of the image |
| 546 | |
| 547 | // if vvvvv not the first line vvvvv |
| 548 | if (y > yMin && *(currentPixel - line) != pixelValue) |
| 549 | { // x direction - bottom edge of the pixel |
| 550 | // add the 2 points |
| 551 | vtkIdType p1 = |
| 552 | points->InsertNextPoint(x * localStorage->m_mmPerPixel[0], y * localStorage->m_mmPerPixel[1], depth); |
| 553 | vtkIdType p2 = |
| 554 | points->InsertNextPoint((x + 1) * localStorage->m_mmPerPixel[0], y * localStorage->m_mmPerPixel[1], depth); |
| 555 | // add the line between both points |
| 556 | lines->InsertNextCell(2); |
| 557 | lines->InsertCellPoint(p1); |
| 558 | lines->InsertCellPoint(p2); |
| 559 | } |
| 560 | |
| 561 | // if vvvvv not the last line vvvvv |
| 562 | if (y < yMax && *(currentPixel + line) != pixelValue) |
| 563 | { // x direction - top edge of the pixel |
| 564 | vtkIdType p1 = |
| 565 | points->InsertNextPoint(x * localStorage->m_mmPerPixel[0], (y + 1) * localStorage->m_mmPerPixel[1], depth); |
| 566 | vtkIdType p2 = points->InsertNextPoint( |
| 567 | (x + 1) * localStorage->m_mmPerPixel[0], (y + 1) * localStorage->m_mmPerPixel[1], depth); |
| 568 | lines->InsertNextCell(2); |
no test coverage detected