使用查找表的方法为
1,读入标量或者向最,用一个vtkFloatArray存储,里面的标量可以代表不同的艳色
2,建立查找表,用setNuberofcolors()分配空间,然后赋值再用build()建立
3,把标量数组和vtkfloatarray和多边形联起来,同时把查找表和vtkmapper联起来
注意,查找表用float型
具体代码如下
m_Abstractreader->SetFile();//联上管道
mypoints->InsertNextPoint(0.0, 0.0, 0.0);
for (int kk = 0; kk < m_Abstractreader->NumNode; kk++)
{
mypoints->InsertNextPoint(m_Abstractreader->node[kk][0], m_Abstractreader->node[kk][1], m_Abstractreader->node[kk][2]);
}
mygrid->SetPoints(mypoints);
mygrid->Allocate(2000, 1000);///////////
for (int kkk = 0; kkk < m_Abstractreader->NumEle; kkk++)
{
mygrid->InsertNextCell(12, 8, m_Abstractreader->ele[kkk]);
}
//////////////////////////////设置向量
myarray->SetNumberOfTuples(m_Abstractreader->NumEle);
for (int mmm = 0; mmm < m_Abstractreader->NumEle; mmm++)
{
myarray->InsertTuple(mmm, &m_Abstractreader->vec[mmm]);
}
mygrid->GetCellData()->SetScalars(myarray);
mytable->SetNumberOfColors(9);
mytable->SetTableRange(0, 8);
mytable->SetTableValue(0, 1.0, 0.0, 0.0);
mytable->SetTableValue(1, 0.0, 1.0, 0.0);
mytable->SetTableValue(2, 0.0, 0.0, 1.0);
mytable->SetTableValue(3, 1.0, 1.0, 0.0);
mytable->SetTableValue(4, 0.0, 1.0, 1.0);
mytable->SetTableValue(5, 1.0, 0.0, 1.0);
mytable->SetTableValue(6, 0.5, 2.0, 0.8);
mytable->SetTableValue(7, 1.0, 0.0, 0.0);
mytable->SetTableValue(8, 1.0, 0.4, 0.5);
mytable->Build();
filter->SetInput(mygrid);
//////////////////////////////实体绘制
normals->SetInputConnection(filter->GetOutputPort());
normals->FlipNormalsOn();
normals->SetFlipNormals(1);
coneMapper->SetInputConnection(normals->GetOutputPort());
////////////////////////////使用查找表
coneMapper->SetScalarModeToUseCellData();
coneMapper->UseLookupTableScalarRangeOn();
coneMapper->SetLookupTable(mytable);
////////////////////////////////////////////////////////////
///////////////线框绘制///////////////////////////////////
normalswire->SetInputConnection(filter->GetOutputPort());
normalswire->FlipNormalsOn();
normalswire->SetFlipNormals(1);
actorMapper->SetInputConnection(normalswire->GetOutputPort());
actorMapper->SetResolveCoincidentTopologyToPolygonOffset();