Hi I have code, which 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.
This code which gets all column names from actor index:
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;
}
This code colors the model of specific column.
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);
}
}
output.GetPointData().SetScalars(colors);
}
This code gets range of values from specific column.
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();
}
}
return null;
}
I think the problem is that you are appending gray colors gere in the code.
And I don’t see where you input your colors array in the setColors function
I have checked colors and are interpolated fine.
Please see color scale in image. Its my own label made, and uses that same color.
I verified following way:
var R = c.R;
var G = c.G;
var B = c.B;
Console.WriteLine("rgb(" + R + "," +G + "," + B +")");
/*
rgb(108,89,176) purple like
rgb(132,95,168) purple like
rgb(157,102,160) pink like
rgb(181,108,152) pink like
rgb(206,115,144) pink like
rgb(230,121,136) red like
rgb(255,128,128) red like
rgb(59,76,192) blue like
*/
I’m not clear about colors.InsertNextTuple3.
I started calling it twice, as vtp files working with twice and else raises unsafe errors.
But calling once or twice has no effect on VTU currently.
Although Actor.GetProperty().SetColor(color); works to color the model.
But it color whole model with same color.
Whereas I expected to interpolate colors according to percentages.
Here is an example that tells you how to do it… But if you need more help, let me know
Note: I think you should add scalars to the cells instead of the points, but more or less it should be similar.
Experiment with the lookup table definition, you only need two values “red” and “blue” defined as vectors as you were doing.
I tried following article and their resources, 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:
all vtp files work and all vtu files are fails
vtu file show colorful fine on paraview, but not in my code
I guess we need to handle vtu differently than normally we do.