------------------------------------------------------------------------------ Render the polygon that displays the image data
| 322 | //------------------------------------------------------------------------------ |
| 323 | // Render the polygon that displays the image data |
| 324 | void vtkOpenGLImageSliceMapper::RenderPolygon( |
| 325 | vtkActor* actor, vtkPoints* points, const int extent[6], vtkRenderer* ren) |
| 326 | { |
| 327 | vtkOpenGLClearErrorMacro(); |
| 328 | |
| 329 | bool textured = (actor->GetTexture() != nullptr); |
| 330 | vtkPolyData* poly = vtkPolyDataMapper::SafeDownCast(actor->GetMapper())->GetInput(); |
| 331 | vtkPoints* polyPoints = poly->GetPoints(); |
| 332 | if (this->GetOutputPointsPrecision() == vtkAlgorithm::DOUBLE_PRECISION) |
| 333 | { |
| 334 | polyPoints->SetDataTypeToDouble(); |
| 335 | } |
| 336 | vtkCellArray* tris = poly->GetPolys(); |
| 337 | vtkDataArray* polyTCoords = poly->GetPointData()->GetTCoords(); |
| 338 | |
| 339 | // do we need to rebuild the cell array? |
| 340 | int numTris = 2; |
| 341 | if (points) |
| 342 | { |
| 343 | numTris = (points->GetNumberOfPoints() - 2); |
| 344 | } |
| 345 | if (tris->GetNumberOfConnectivityIds() != 3 * numTris) |
| 346 | { |
| 347 | tris->Initialize(); |
| 348 | tris->AllocateEstimate(numTris, 3); |
| 349 | // this wacky code below works for 2 and 4 triangles at least |
| 350 | for (vtkIdType i = 0; i < numTris; i++) |
| 351 | { |
| 352 | tris->InsertNextCell(3); |
| 353 | tris->InsertCellPoint(numTris + 1 - (i + 1) / 2); |
| 354 | tris->InsertCellPoint(i / 2); |
| 355 | tris->InsertCellPoint((i % 2 == 0) ? numTris - i / 2 : i / 2 + 1); |
| 356 | } |
| 357 | tris->Modified(); |
| 358 | } |
| 359 | |
| 360 | // now rebuild the points/tcoords as needed |
| 361 | if (!points) |
| 362 | { |
| 363 | double coords[12], tcoords[8]; |
| 364 | this->MakeTextureGeometry(extent, coords, tcoords); |
| 365 | |
| 366 | polyPoints->SetNumberOfPoints(4); |
| 367 | if (textured) |
| 368 | { |
| 369 | polyTCoords->SetNumberOfTuples(4); |
| 370 | } |
| 371 | for (int i = 0; i < 4; i++) |
| 372 | { |
| 373 | polyPoints->SetPoint(i, coords[3 * i], coords[3 * i + 1], coords[3 * i + 2]); |
| 374 | if (textured) |
| 375 | { |
| 376 | polyTCoords->SetTuple(i, &tcoords[2 * i]); |
| 377 | } |
| 378 | } |
| 379 | polyPoints->Modified(); |
| 380 | if (textured) |
| 381 | { |
no test coverage detected