// VtkScalarBug.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "vtkRenderWindowInteractor.h" #include "vtkRenderWindow.h" #include "vtkRenderer.h" #include "vtkActor.h" #include "vtkPolyDataMapper.h" #include "vtkLookupTable.h" #include "vtkCamera.h" #include "vtkWin32OpenGLRenderWindow.h" #include "vtkWin32RenderWindowInteractor.h" #include "vtkProperty.h" #include "vtkPolyDataReader.h" #include "vtkFloatArray.h" #include "vtkPointData.h" #include "vtkPlaneSource.h" #include "vtkSphereSource.h" int _tmain(int argc, _TCHAR* argv[]) { vtkWin32OpenGLRenderWindow *renWin = vtkWin32OpenGLRenderWindow::New(); vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWin); iren->Initialize(); vtkRenderer *renderer = vtkRenderer::New(); renWin->AddRenderer(renderer); if(1) { if (1) { vtkSphereSource* sphere = vtkSphereSource::New(); const int res = 500; sphere->SetPhiResolution(res); sphere->SetThetaResolution(res); sphere->Update(); const double setval = 0.8; vtkPolyDataMapper* mapper = vtkPolyDataMapper::New(); mapper->SetInput(sphere->GetOutput()); sphere->Delete(); mapper->SetScalarRange(0,setval); vtkLookupTable* lut = vtkLookupTable::New(); lut->SetNumberOfColors(2); lut->Build(); lut->SetTableValue(1,setval,0,0); lut->SetTableValue(0,setval,setval,setval); mapper->SetLookupTable(lut); lut->Delete(); vtkPolyData* SpherePoly = mapper->GetInput(); int NumLiverPoints = SpherePoly->GetNumberOfPoints(); vtkFloatArray* scalars = vtkFloatArray::New(); const int fullrange = 50; const int half = fullrange/2; for (int i=0;iInsertTuple1(i,(i%fullrange)>half?0:setval); } SpherePoly->GetPointData()->SetScalars(scalars); scalars->Delete(); SpherePoly->Modified(); vtkActor* cubeA = vtkActor::New(); renderer->AddActor(cubeA); cubeA->SetMapper(mapper); cubeA->GetProperty()->SetOpacity(0.5); mapper->Delete(); cubeA->Delete(); } renderer->ResetCamera(); renderer->Render(); } iren->Start(); renderer->Delete(); renWin->Delete(); iren->Delete(); return 0; }