ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping.Voxel Namespace / VoxelVariableProfile Class / Renderer Property
Example

In This Topic
    Renderer Property (VoxelVariableProfile)
    In This Topic
    Gets the variable profile renderer.
    Syntax
    public CIMVoxelRenderer Renderer {get;}
    Public ReadOnly Property Renderer As CIMVoxelRenderer
    Remarks
    Example
    Subscribe for Changes to a Voxel Layer
    {
      MapMemberPropertiesChangedEvent.Subscribe((args) =>
      {
        var voxel = args.MapMembers.OfType<VoxelLayer>().FirstOrDefault();
        if (voxel == null)
        {
          return;
        }
        //Anything changed on a voxel layer?
        if (args.EventHints.Any(hint => hint == MapMemberEventHint.VoxelSelectedVariable))
        {
          //Voxel variable profile selection changed
          var changed_variable_name = voxel.SelectedVariableProfile.Variable;
          //TODO respond to change, use QueuedTask if needed
    
        }
        else if (args.EventHints.Any(hint => hint == MapMemberEventHint.Renderer))
        {
          //This can fire when a renderer becomes ready on a new layer; the selected variable profile
          //is changed; visualization is changed, etc.
          var renderer = voxel.SelectedVariableProfile.Renderer;
          //TODO respond to change, use QueuedTask if needed
    
        }
      });
    
      VoxelAssetChangedEvent.Subscribe((args) =>
      {
        //An asset changed on a voxel layer
        System.Diagnostics.Debug.WriteLine("");
        System.Diagnostics.Debug.WriteLine("VoxelAssetChangedEvent");
        System.Diagnostics.Debug.WriteLine($" AssetType: {args.AssetType}, ChangeType: {args.ChangeType}");
    
        if (args.ChangeType == VoxelAssetEventArgs.VoxelAssetChangeType.Remove)
        {
          return;
        }
        //Get "what"changed - add or update
        //eg IsoSurface
        VoxelLayer voxelLayer = null;
        if (args.AssetType == VoxelAssetEventArgs.VoxelAssetType.Isosurface)
        {
          var surface = MapView.Active.GetSelectedIsosurfaces().FirstOrDefault();
          //there will only be one selected...
          if (surface != null)
          {
            voxelLayer = surface.Layer;
            //TODO respond to change, use QueuedTask if needed
          }
        }
        //Repeat for Slices, Sections, LockedSections...
        //GetSelectedSlices(), GetSelectedSections(), GetSelectedLockedSections();
      });
    }
    Get the Variable Renderer
    {
      var variable = voxelLayer.GetVariableProfiles().First();
      var renderer = variable.Renderer;
      if (variable.DataType == VoxelVariableDataType.Continuous)
      {
        //Renderer will be stretch
        var stretchRenderer = renderer as CIMVoxelStretchRenderer;
        //access the renderer
    
      }
      else //VoxelVariableDataType.Discrete
      {
        //Renderer will be unique value
        var uvr = renderer as CIMVoxelUniqueValueRenderer;
        //access the renderer
      }
    }
    Access Stats and Color Range for a Stretch Renderer
    {
      //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;
      }
    }
    Change Stretch Renderer Color Range
    {
      //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);
      });
    }
    Change The Visibility on a CIMVoxelColorUniqueValue class
    {
      await QueuedTask.Run(() =>
      {
        //Get the variable profile whose renderer will be changed
        var variable = voxelLayer.SelectedVariableProfile;
    
        //Check DataType
        if (variable.DataType != VoxelVariableDataType.Discrete)
        {
          return;//must be Discrete to have a UV Renderer...
        }
    
        var renderer = variable.Renderer as CIMVoxelUniqueValueRenderer;
    
        //A CIMVoxelUniqueValueRenderer consists of a collection of
        //CIMVoxelColorUniqueValue classes - one per discrete value
        //in the associated variable profile value array
    
        //Get the first class
        var classes = renderer.Classes.ToList();
        var unique_value_class = classes.First();
        //Set its visibility off
        unique_value_class.Visible = false;
    
        //Apply the change to the renderer
        renderer.Classes = classes.ToArray();
        //apply the changes
        variable.SetRenderer(renderer);
      });
    }
    Create Isosurface
    {
      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
          });
        }
      });
    }
    How to Change Value and Color on an Isosurface
    {
      await QueuedTask.Run(() =>
      {
        var variable = voxelLayer.SelectedVariableProfile;
    
        //Change the color of the first surface for the given profile
        var surface = variable.GetIsosurfaces().FirstOrDefault();
        if (surface != null)
        {
          if (voxelLayer.Visualization != VoxelVisualization.Surface)
          {
            voxelLayer.SetVisualization(VoxelVisualization.Surface);
          }
    
          //Change the iso surface voxel value
          surface.Value = surface.Value * 0.9;
    
          //get a random color
          var count = new Random().Next(0, 100);
          var colors = ColorFactory.Instance.GenerateColorsFromColorRamp(
            ((CIMVoxelStretchRenderer)variable.Renderer).ColorRamp, count);
    
          var idx = new Random().Next(0, count - 1);
          surface.Color = colors[idx];
          //set the custom color flag true to lock the color
          //locking the color prevents it from being changed if the
          //renderer color range or color theme is updated
          surface.IsCustomColor = true;
    
          //update the surface
          variable.UpdateIsosurface(surface);
        }
      });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also