My whole source code is present here including block.vtu file for testing purpose. I will discuss important functions here.
This code can color *.vtp, *.vtk. But same code fails to color *.vtu.
I have list of vtkactors. And I specify which actor to set properties from.
public static List<string> getColumns(int actorIndex)
{
List<string> colums = new List<string>();
vtkActor actor = actors[actorIndex];
var output = actor.GetMapper().GetInputAsDataSet();
var cell = output.GetCellData();
for (int i = 0; i < cell.GetNumberOfArrays(); i++)
{
var colm = cell.GetArrayName(i);
if (colm != null) colums.Add(colm);
}
return colums; //['CU_OK','D1','Domain','IJK','IX','IY'...]
}
public static void setColors(int actorIndex, string column)
{
List<string> colums = new List<string>();
vtkActor actor = actors[actorIndex];
var output = actor.GetMapper().GetInputAsDataSet();
var colors = vtkUnsignedCharArray.New();
colors.SetNumberOfComponents(3);
colors.SetName("Colors");
var cell = output.GetCellData();
for (int i = 0; i < cell.GetNumberOfArrays(); i++)
{
var cells = cell.GetArray(i);
if (cells == null) continue;
if (column != cell.GetArrayName(i)) continue;
for (int j = 0; j < cells.GetNumberOfTuples(); j++)
{
var c = color_range((cells.GetComponent(i, j) / cell.GetArray(i).GetRange()[1]) * 100);
var R = c.R;
var G = c.G;
var B = c.B;
colors.InsertNextTuple3((double)R, (double)G, (double)B);
colors.InsertNextTuple3((double)R, (double)G, (double)B); //even tried with and without inserting second tuple
}
}
output.GetPointData().SetScalars(colors); //even tried with GetCellData(), but no luck
}
public static double[] getRange(int actorIndex, string column)
{
List<string> colums = new List<string>();
vtkActor actor = actors[actorIndex];
var output = actor.GetMapper().GetInputAsDataSet();
var cell = output.GetCellData();
for (int i = 0; i < cell.GetNumberOfArrays(); i++)
{
var colm = cell.GetArrayName(i);
var arr = cell.GetArray(i);
if (column == colm)
{
if (arr == null) return null;
return arr.GetRange(); // new double[] { min, max }
}
}
return null;
}
The result is fine. This is how drillholes are shown in by my code.
See how its colored. This is what PARAVIEW software can show:
This is how my code show that model:
I tried following question, but vtu color has no effect. I tried cell data too instead of point data. I also tried lookup table, it do shows with color scalebar but has no effect on model color.
The strange things are that:
I am not sure if this is a proper solution, but it might work if you create a new mapper at the end of the setColors
function.
output.GetPointData().SetScalars(colors);
+ vtkDataSetMapper mapper = vtkDataSetMapper.New();
+ mapper.SetInput(output);
+ actor.SetMapper(mapper);
}