[vtkusers] Problem with color interpolation with a vtk structured grid

rafsalas teq87121 at aol.com
Mon Sep 9 03:50:56 EDT 2013


I currently have a structured grid  with the deminsions(16,16,14) that
resembles a nuclear reactor, and I'm trying to interpolate colors on its
surface but all I have achieved so far is to give the cells discrete colors.
I don't want the colors to look blocky. I have tried another approach also
by using vtkpolydata and the same grid points, but I am having problems with
that too. I use a cube source to fill in between the points and I set scalar
values for the polydata points then try to apply a colormap but it ends up
changing the surface texture of the polydata structure. I want a flat
surface that on every side and colors that use interpolation so that I don't
get a blocky look. 

I'm a newb at this, so if any body can give me any ideas of how to achieve
this it would be greatly appreciated.

-Raf

p.s.
Here is a copy of the poly data try:
int main(){
	vtkSmartPointer<vtkPoints> points=//points used to set deminsions of grid
		vtkSmartPointer<vtkPoints>::New();
// cube source 
	 vtkSmartPointer<vtkCubeSource> cube = 
		vtkSmartPointer<vtkCubeSource>::New();
	 cube->SetZLength(2);
 //-----------------------------------------------Make points-------
	vtkSmartPointer<vtkPolyData> polydata =
		vtkSmartPointer<vtkPolyData>::New();
	 points->Allocate(3136);
	 for(int i=0;i<27;++i){
		 if(i!=0){i+=1;}
		for(int j=4;j<12;++j){	
			points->InsertNextPoint(j, 0, (i));	
		}
		for(int k=2;k<14;++k){
			points->InsertNextPoint(k, 1, i);
			}			
		for(int m=2;m<4;++m)							
			for(int l=1;l<15;++l){
				points->InsertNextPoint(l, m, i);
				}
		for(int n=4;n<12;++n)
			for(int p=0;p<16;++p){
				points->InsertNextPoint(p, n, i);
				}
		for(int q=12;q<14;++q)	
			for(int r=1;r<15;++r){
				points->InsertNextPoint(r, q, i);
				}
		for(int s=2;s<14;++s){
			points->InsertNextPoint(s, 14, i);
			}
		for(int t=4;t<12;++t){
			points->InsertNextPoint(t, 15, i);
			}
		}
//-----------------------------------build scalor
array---------------------------------------------
vtkSmartPointer<vtkFloatArray> sarray=
				vtkSmartPointer<vtkFloatArray>::New();
			sarray->SetNumberOfValues(3136);
			for(int i=0;i<3136;++i){
			if(i<1)
				sarray->InsertValue(i,1);
			
			else if(i<2)
				sarray->InsertValue(i,2);
			else
				sarray->InsertValue(i,1);
			}
			vtkSmartPointer<vtkLookupTable>cTable =
vtkSmartPointer<vtkLookupTable>::New();
	int tableSize =  10;// not sure if I need this
	cTable->SetNumberOfTableValues(tableSize);// not sure if I need this
	cTable->Build();

//--------------------------------------------------------------------------------
polydata->SetPoints(points);
polydata->BuildCells();
polydata->GetPointData()->SetScalars(sarray);
  //--------------------------------------------- 
-----------------------------------------------------------------------------

  vtkSmartPointer<vtkGlyph3DMapper> mapper = 
    vtkSmartPointer<vtkGlyph3DMapper>::New();
 mapper->SetSourceConnection(cube->GetOutputPort());
#if VTK_MAJOR_VERSION <= 5
  mapper->SetInputConnection(polydata->GetProducerPort());
#else
  glyph3Dmapper->SetInputData(polydata);
#endif
		mapper->Update();
  		mapper->SetScalarRange(1, 10);
		mapper->SetLookupTable(cTable);
		mapper->InterpolateScalarsBeforeMappingOn();	
//----------------------------------------------------------------------------------------
  vtkSmartPointer<vtkActor> actor = 
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
  actor->GetProperty()->SetPointSize(3);

//-------------------------------------------------------------------------------------
  // Visualize
  vtkSmartPointer<vtkRenderer> renderer = 
    vtkSmartPointer<vtkRenderer>::New();

  vtkSmartPointer<vtkRenderWindow> renderWindow = 
    vtkSmartPointer<vtkRenderWindow>::New();

  renderWindow->AddRenderer(renderer);
  
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
    vtkSmartPointer<vtkRenderWindowInteractor>::New();

  renderWindowInteractor->SetRenderWindow(renderWindow);
  
  renderer->AddActor(actor);
  renderer->SetBackground(.2, .3, .4);
  renderer->ResetCamera();
  renderWindow->Render();
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}



--
View this message in context: http://vtk.1045678.n5.nabble.com/Problem-with-color-interpolation-with-a-vtk-structured-grid-tp5723332.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list