How to creat a color map out of a strucduregrid or poly data using vtk?
I am trying to create a color map on out of poly data. Who's points make
up the structure of a nuclear reactor.I Have written out code but it seem
the every time I change color the size of the cells change depending on
the scalar value I put in them. I just want a color map which shows
interpolated color between the cells of my structure or even points. This
is the code that causes my color map to change the size of the cells.
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);
//-----------------------------------------------
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<2000)
sarray->InsertValue(i,1);
else
sarray->InsertValue(i,10);
}
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);
No comments:
Post a Comment