[vtkusers] Missing pixel with vtkPolyDataMapper2D and vtkCoordinate

Cory Quammen cory.quammen at kitware.com
Fri Jul 3 10:49:27 EDT 2015


Hi,

Thank you for providing the complete code example that shows the problem. I
compiled and ran it and see the same problem you report. Thanks also for
your suggestion about what to modify. I tried adding 0.5 to the coordinates
returned by this->TransformCoordinate->GetComputedDoubleViewportValue(),
but this just led to blank pixels on the bottom of the window.

I think this may indeed be a bug in the conversion from viewport
coordinates to window coordinates. Right now, the transformation appears to
be placing coordinates (1, 1) in the lower left corner of the upper right
pixel, where I think it should be in the upper right corner of the pixel.
When I modify vtkViewport::DisplayToNormalizedDisplay() to divide the u and
v coordinates by size-1 instead of just size, the quad fills the window.
This calculation should be putting the (1,1) coordinate in the upper right
corner of the pixel.

Would you mind posting this but on the bug tracker [1]?

Thanks,
Cory

[1] http://www.vtk.org/Bug/view_all_bug_page.php

On Wed, Jul 1, 2015 at 4:55 AM, Xabi Riobe <xabivtk at gmail.com> wrote:

> Here is an example and a screenshot to illustrate the issue.
>
> I'm wondering if the coordinates returned in
> vtkOpenGLPolyDataMapper2D::RenderOverlay by the call to
> this->TransformCoordinate->GetComputedDoubleViewportValue(viewport);
> should be then shifted with the extra 0.5 to be in the center of the pixel
> and not in the border.
>
>
> #define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,
> vtkRenderingOpenGL, vtkRenderingFreeType,vtkRenderingFreeTypeOpenGL)
>
> #include <vtkActor2D.h>
> #include <vtkPolyDataMapper2D.h>
> #include <vtkRenderer.h>
> #include <vtkPlaneSource.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkSmartPointer.h>
> #include <vtkCoordinate.h>
> #include <vtkPointData.h>
>
> int main(int, char* [])
> {
>    vtkSmartPointer<vtkRenderer> ren1= vtkSmartPointer<vtkRenderer>::New();
>    vtkSmartPointer<vtkRenderWindow> renWin=
> vtkSmartPointer<vtkRenderWindow>::New();
>    renWin->SetSize( 1533, 792 );
>    renWin->AddRenderer(ren1);
>
>    vtkSmartPointer<vtkRenderWindowInteractor> iren=
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
>    iren->SetRenderWindow(renWin);
>
>    vtkSmartPointer<vtkPlaneSource> source =
> vtkSmartPointer<vtkPlaneSource>::New();
>    source->SetOrigin(0.0, 0.0, 0.0);
>    source->SetPoint1(1.0, 0.0, 0.0);
>    source->SetPoint2(0.0, 1.0, 0.0);
>    source->Update();
>
>    vtkSmartPointer<vtkUnsignedCharArray> scalars =
> vtkSmartPointer<vtkUnsignedCharArray>::New();
>    double bottom[3] = {255.0, 0, 0};
>    double top[3] = {0, 255.0, 0};
>    scalars->Initialize();
>    scalars->SetNumberOfComponents(3);
>    scalars->SetNumberOfTuples(4);
>    scalars->InsertTuple(0, bottom);
>    scalars->InsertTuple(1, bottom);
>    scalars->InsertTuple(2, top);
>    scalars->InsertTuple(3, top);
>    source->GetOutput()->GetPointData()->SetScalars(scalars);
>
>    vtkSmartPointer<vtkCoordinate> coordinateSystem =
> vtkSmartPointer<vtkCoordinate>::New();
>    coordinateSystem->SetCoordinateSystemToNormalizedViewport();
>
>    vtkSmartPointer<vtkPolyDataMapper2D> mapper =
> vtkSmartPointer<vtkPolyDataMapper2D>::New();
>    mapper->SetInputConnection(source->GetOutputPort());
>    mapper->SetTransformCoordinate(coordinateSystem);
>    mapper->TransformCoordinateUseDoubleOn();
>
>    vtkSmartPointer<vtkActor2D> actor2d =
> vtkSmartPointer<vtkActor2D>::New();
>    actor2d->SetMapper(mapper);
>
>    ren1->AddActor(actor2d);
>
>    ren1->ResetCamera();
>    renWin->Render();
>    iren->Start();
> }
>
> [image: Images intégrées 1]
>
> 2015-06-30 18:18 GMT+02:00 Xabi Riobe <xabivtk at gmail.com>:
>
>> Hi,
>>
>> I want to display a plane as a background.
>> For that i have in a vtkActor2D a vtkPolyDataMapper2D filled with a
>> vtkPlaneSource going from 0,0,0 to 1,1,1
>> I add to the mapper a vtkCoordinate with
>> SetCoordinateSystemToNormalizedViewport
>>
>> with that, everything seems fine and i don't have to take care of it when
>> my view is resized.
>>
>> but if i put some color on it and look at it carefully i can see an extra
>> line and column of black pixels
>>
>> I looked at the code of vtkCoordinate and vtkViewport and the combination
>> of the coordinates transformations leads to a final size of the polygon
>> rendered 1 pixel short in both x and y directions.
>>
>> Is this considered a normal behaviour due to the computation involved, or
>> is it definitively a bug?
>>
>> A quick workaround is to set my plane source a little bit larger, but for
>> future features of my app, i would need the exact size...
>>
>> Thanks for any comments/suggestions
>>
>>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150703/a7350848/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 11349 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150703/a7350848/attachment.png>


More information about the vtkusers mailing list