{
//Get the variable profile on which to access the data
var variable = voxelLayer.SelectedVariableProfile;
//or use ...voxelLayer.GetVariableProfiles()
//Data range
var min = variable.Statistics.MinimumValue;
var max = variable.Statistics.MaximumValue;
//Color range (Continuous only)
double color_min, color_max;
if (variable.DataType == VoxelVariableDataType.Continuous)
{
var renderer = variable.Renderer as CIMVoxelStretchRenderer;
color_min = renderer.ColorRangeMin;
color_max = renderer.ColorRangeMax;
}
}
{
//Typically, the default color range covers the most
//commonly occurring voxel values. Usually, the data
//range is much broader than the color range
await QueuedTask.Run(() =>
{
//Get the variable profile whose renderer will be changed
var variable = voxelLayer.SelectedVariableProfile;
//Check DataType
if (variable.DataType != VoxelVariableDataType.Continuous)
{
//must be continuous to have a Stretch Renderer...
}
var renderer = variable.Renderer as CIMVoxelStretchRenderer;
var color_min = renderer.ColorRangeMin;
var color_max = renderer.ColorRangeMax;
//increase range by 10% of the current difference
var dif = (color_max - color_min) * 0.05;
color_min -= dif;
color_max += dif;
//make sure we do not exceed data range
if (color_min < variable.Statistics.MinimumValue)
{
color_min = variable.Statistics.MinimumValue;
}
if (color_max > variable.Statistics.MaximumValue)
{
color_max = variable.Statistics.MaximumValue;
}
//variable.Statistics.MinimumValue
renderer.ColorRangeMin = color_min;
renderer.ColorRangeMax = color_max;
//apply changes
variable.SetRenderer(renderer);
});
}
{
await QueuedTask.Run(() =>
{
//Visualization must be surface
if (voxelLayer.Visualization != VoxelVisualization.Surface)
{
voxelLayer.SetVisualization(VoxelVisualization.Surface);
}
//Get the variable profile on which to create the iso surface
var variable = voxelLayer.SelectedVariableProfile;
// o Visualization must be Surface
// o Variable profile must be continuous
// o Variable MaxNumberofIsoSurfaces must not have been reached...
if (variable.CanCreateIsosurface)
{
//Note: calling create if variable.CanCreateIsosurface == false
//will trigger an InvalidOperationException
//Specify a voxel value for the iso surface
var min = variable.Statistics.MinimumValue;
var max = variable.Statistics.MaximumValue;
var mid = (max + min) / 2;
//color range (i.e. values that are being rendered)
var renderer = variable.Renderer as CIMVoxelStretchRenderer;
var color_min = renderer.ColorRangeMin;
var color_max = renderer.ColorRangeMax;
//keep the surface within the current color range (or it
//won't render)
if (mid < color_min)
{
mid = renderer.ColorRangeMin;
}
else if (mid > color_max)
{
mid = renderer.ColorRangeMax;
}
//Create the iso surface
var suffix = Math.Truncate(mid * 100) / 100;
variable.CreateIsosurface(new IsosurfaceDefinition()
{
Name = $"Surface {suffix}",
Value = mid,
IsVisible = true
});
}
});
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)