MCPcopy Create free account
hub / github.com/Kitware/VTK / DrawPixels

Method DrawPixels

Rendering/OpenGL2/vtkOpenGLImageMapper.cxx:630–679  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

628}
629
630void vtkOpenGLImageMapper::DrawPixels(
631 vtkViewport* viewport, int width, int height, int numComponents, void* data)
632{
633 int* actorPos = this->Actor->GetActualPositionCoordinate()->GetComputedViewportValue(viewport);
634 int* actorPos2 = this->Actor->GetActualPosition2Coordinate()->GetComputedViewportValue(viewport);
635
636 float xscale = 1.0;
637 float yscale = 1.0;
638 if (this->GetRenderToRectangle())
639 {
640 int rectwidth = (actorPos2[0] - actorPos[0]) + 1;
641 int rectheight = (actorPos2[1] - actorPos[1]) + 1;
642 xscale = static_cast<float>(rectwidth) / width;
643 yscale = static_cast<float>(rectheight) / height;
644 }
645
646 vtkPolyData* pd = vtkPolyDataMapper2D::SafeDownCast(this->Actor->GetMapper())->GetInput();
647 vtkPoints* points = pd->GetPoints();
648 points->SetPoint(0, 0.0, 0.0, 0);
649 points->SetPoint(1, width * xscale, 0.0, 0);
650 points->SetPoint(2, width * xscale, height * yscale, 0);
651 points->SetPoint(3, 0.0, height * yscale, 0);
652 points->GetData()->Modified();
653
654 vtkDataArray* tcoords = pd->GetPointData()->GetTCoords();
655 float tmp[2];
656 tmp[0] = 0;
657 tmp[1] = 0;
658 tcoords->SetTuple(0, tmp);
659 tmp[0] = 1.0;
660 tcoords->SetTuple(1, tmp);
661 tmp[1] = 1.0;
662 tcoords->SetTuple(2, tmp);
663 tmp[0] = 0.0;
664 tcoords->SetTuple(3, tmp);
665 tcoords->Modified();
666
667 vtkImageData* id = vtkImageData::New();
668 id->SetExtent(0, width - 1, 0, height - 1, 0, 0);
669 vtkUnsignedCharArray* uca = vtkUnsignedCharArray::New();
670 uca->SetNumberOfComponents(numComponents);
671 uca->SetArray((unsigned char*)data, width * height * numComponents, true);
672 id->GetPointData()->SetScalars(uca);
673 uca->Delete();
674
675 this->Actor->GetTexture()->SetInputData(id);
676
677 this->Actor->RenderOverlay(viewport);
678 id->Delete();
679}
680
681void vtkOpenGLImageMapper::PrintSelf(ostream& os, vtkIndent indent)
682{

Calls 15

GetMapperMethod · 0.80
SetScalarsMethod · 0.80
DeleteMethod · 0.65
NewFunction · 0.50
GetInputMethod · 0.45
GetPointsMethod · 0.45
SetPointMethod · 0.45
ModifiedMethod · 0.45
GetDataMethod · 0.45
GetTCoordsMethod · 0.45
GetPointDataMethod · 0.45

Tested by

no test coverage detected