Hi,<br><br>I have a display problem using this method. The 2 attached pictures show it, and the code to obtain them is also attached.<br><br>In the following example I have a cube with scalars on the PointData, and i apply a lut to its mapper.<br>
I also ave a 2D line in the scene.<br>If I do not call InterpolateScalarsBeforeMappingOn on the cube's mapper, the line is correctly red, but if I call it, then it looks like the lut is interferring with the rendering of the line.<br>
And if i have more 2D actors, the first one that is added to the renderer always presents the same problem.<br><br>Can someone can explain me why is this happening? is this the correct behaviour or is it a bug?<br><br>Thanks!<br>
<br><br><br>#include <limits><br><br>#include <vtk/vtkActor.h><br>#include <vtk/vtkActor2D.h><br>#include <vtk/vtkCleanPolyData.h><br>#include <vtk/vtkCubeSource.h><br>#include <vtk/vtkDoubleArray.h><br>
#include <vtk/vtkLineSource.h><br>#include <vtk/vtkLinearSubdivisionFilter.h><br>#include <vtk/vtkLookupTable.h><br>#include <vtk/vtkPointData.h><br>#include <vtk/vtkPolyData.h><br>#include <vtk/vtkPolyDataMapper.h><br>
#include <vtk/vtkPolyDataMapper2D.h><br>#include <vtk/vtkProperty.h><br>#include <vtk/vtkProperty2D.h><br>#include <vtk/vtkRenderer.h><br>#include <vtk/vtkRenderWindow.h><br>#include <vtk/vtkRenderWindowInteractor.h><br>
#include <vtk/vtkSmartPointer.h><br>#include <vtk/vtkTriangleFilter.h><br><br>#define MY_SP(class, variable)\<br> vtkSmartPointer<class> variable = vtkSmartPointer<class>::New();<br><br>//----------------------------------------------------------------------------------------------------<br>
<br>// implemented after the main<br>void RepresPositionCtrl2D(double dSize, vtkRenderer *ren);<br>void SetScalars(vtkMapper *Mapper);<br>void ConfigureMapperLut(vtkMapper *mapper);<br><br>//---------------------------------------------------------------------------------------------<br>
<br>int main(int , char* [])<br>{<br> /////////////////////////////////////////////////////////<br> MY_SP(vtkRenderer, ren1);<br> ren1->SetBackground(0.2, 0.2, 0.2);<br> MY_SP(vtkRenderWindow, renWin);<br> renWin->SetSize( 1000, 896 );<br>
renWin->AddRenderer(ren1);<br> MY_SP(vtkRenderWindowInteractor, iren);<br> iren->SetRenderWindow(renWin);<br><br> /////////////////////////////////////////////////////////<br> MY_SP(vtkCubeSource, src);<br>
src->SetBounds(0,2,0,2,0,2);<br> src->Update();<br><br> MY_SP(vtkTriangleFilter, tri);<br> tri->SetInputConnection(src->GetOutputPort());<br> tri->Update();<br><br> MY_SP(vtkCleanPolyData, clean);<br>
clean->SetInputConnection(tri->GetOutputPort());<br> clean->Update();<br><br> MY_SP(vtkLinearSubdivisionFilter, sub);<br> sub->SetInputConnection(clean->GetOutputPort());<br> sub->SetNumberOfSubdivisions(1);<br>
sub->Update();<br><br> vtkPolyData *cube = sub->GetOutput();<br><br> MY_SP(vtkPolyDataMapper, Map);<br> Map->SetInput(cube);<br><br> MY_SP(vtkActor, Act);<br> Act->SetMapper(Map);<br> Act->GetProperty()->SetInterpolationToFlat();<br>
<br> ren1->AddActor(Act);<br><br> /////////////////////////////////////////////////////////<br> RepresPositionCtrl2D(0.2, ren1);<br><br> SetScalars(Map);<br> ConfigureMapperLut(Map);<br><br> /////////////////////////////////////////////////////////<br>
ren1->ResetCamera();<br> renWin->Render();<br> iren->Start();<br><br> /////////////////////////////////////////////////////////<br> return 0;<br>}<br><br>//---------------------------------------------------------------------------------------------<br>
<br>void RepresPositionCtrl2D(double dSize, vtkRenderer *ren)<br>{<br> MY_SP(vtkLineSource, m_LineH);<br> m_LineH->SetPoint1(0.0, 0.0, 0.0);<br> m_LineH->SetPoint2(dSize, 0.0, 0.0);<br><br> MY_SP(vtkPolyDataMapper2D, m_MapperLH);<br>
m_MapperLH->SetInputConnection(m_LineH->GetOutputPort());<br> m_MapperLH->ScalarVisibilityOff();<br><br> MY_SP(vtkActor2D, m_ActorLH);<br> m_ActorLH->GetProperty()->SetColor(1.0, 0.0, 0.0);<br> m_ActorLH->GetProperty()->SetLineWidth(5);<br>
m_ActorLH->SetMapper(m_MapperLH);<br> m_ActorLH->PickableOff();<br><br> MY_SP(vtkCoordinate, pCoord);<br> pCoord->SetCoordinateSystemToWorld();<br><br> vtkSmartPointer<vtkCoordinate> coord = vtkSmartPointer<vtkCoordinate>::New();<br>
coord->SetCoordinateSystemToNormalizedViewport();<br> coord->SetReferenceCoordinate(pCoord);<br> m_MapperLH->SetTransformCoordinate(coord);<br><br> ren->AddActor2D(m_ActorLH);<br>}<br><br>void SetScalars(vtkMapper *Mapper)<br>
{<br> MY_SP(vtkDoubleArray, distArray);<br> int numPts = Mapper->GetInput()->GetNumberOfPoints();<br> distArray->SetNumberOfValues(numPts);<br><br> double *scalars = distArray->WritePointer(0, numPts);<br>
std::fill(scalars, scalars+numPts, std::numeric_limits<double>::max());<br> scalars[0] = -1.0;<br> scalars[1] = -0.1;<br> scalars[2] = 0.0;<br> scalars[3] = 0.2;<br> scalars[4] = 0.4;<br> scalars[5] = 0.6;<br>
scalars[6] = 0.8;<br> scalars[7] = 10.0;<br><br> distArray->Modified();<br><br> Mapper->GetInput()->GetPointData()->SetScalars(distArray);<br> Mapper->GetInput()->GetPointData()->Modified();<br>
Mapper->Update();<br>}<br><br>void ConfigureMapperLut(vtkMapper *mapper)<br>{<br> if(!mapper)<br> return;<br><br> MY_SP(vtkLookupTable, lut);<br> lut->SetNumberOfColors(7);<br> lut->Build();<br> lut->SetTableValue(0, 0.5, 0.0, 1);<br>
lut->SetTableValue(1, 0, 1.0, 0);<br> lut->SetTableValue(2, 1, 0, 0.5);<br> lut->SetTableValue(3, 0.0, 0.5, 0.0);<br> lut->SetTableValue(4, 0.0, 1, 0.5);<br> lut->SetTableValue(5, 0, 0.5, 1);<br>
lut->SetTableValue(6, 1.0, 1.0, 1.0);<br> lut->SetTableRange(-0.2, 1.0);<br><br> mapper->ScalarVisibilityOn();<br> mapper->SetLookupTable(lut);<br> mapper->UseLookupTableScalarRangeOn();<br> ////////////////////////////////////////////////////<br>
mapper->InterpolateScalarsBeforeMappingOn(); // what's wrong?<br> ////////////////////////////////////////////////////<br> mapper->Update();<br>}<br><br>