[vtkusers] Missing pixel with vtkPolyDataMapper2D and vtkCoordinate
Xabi Riobe
xabivtk at gmail.com
Wed Jul 1 04:55:02 EDT 2015
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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150701/891af231/attachment-0001.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/20150701/891af231/attachment-0001.png>
More information about the vtkusers
mailing list