I have been trying to apply a warpScalar filter to my dataset file and have it in color. I have done this in paraview(1st picture) but somehow I'm not able to do this in VTK code. I manage to apply color to a mapper or the warpScalar by itself. But can't merge them and have a warpped and colored plane.
Code:
int main(int, char *[])
{
vtkRenderer *ren = vtkRenderer::New();
ren->SetBackground(0.3, 0.2, 0.4);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
renWin->SetSize(900, 900);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();
iren->SetInteractorStyle(style);
vtkDataSetReader*read = vtkDataSetReader::New();
read->SetFileName("ubgrid.vtk");
read->ReadAllScalarsOn();
read->Update();
//WRAP
vtkNew<vtkWarpScalar> warp;
warp->SetInputConnection(read->GetOutputPort());
warp->SetInputArrayToProcess(vtkDataSetAttributes::SCALARS, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, "group/Scalar2"); //Warp by using group/scalar2
warp->SetScaleFactor(1.0);
warp->UseNormalOn();
warp->Update();
//MERGE
vtkMergeFilter*merge = vtkMergeFilter::New();
merge->SetGeometryInputData(warp->GetOutput());
merge->SetScalarsData(read->GetOutput());
//MAPPER
vtkDataSetMapper*mapper = vtkDataSetMapper::New();
mapper->SetInputConnection(merge->GetOutputPort());
mapper->SetColorModeToMapScalars();
mapper->ScalarVisibilityOn();
mapper->SetScalarModeToUseFieldData();
mapper->SelectColorArray("group/Scalar1");
mapper->ColorByArrayComponent("group/Scalar1", 0); //But color it in group/scalar1
//mapper->ImmediateModeRenderingOff();
//ACTOR
vtkActor*actor = vtkActor::New();
actor->SetMapper(mapper);
ren->ResetCamera();
ren->AddActor(actor);
renWin->Render();
iren->Start();
// Clean up
ren->Delete();
renWin->Delete();
iren->Delete();
mapper->Delete();
actor->Delete();
return(0);
}
Paraview output:
Only warpScalar output:
Color output without warpScalar: