Search code examples
c#sharpdxpoint-cloudshelix-3d-toolkithelix

Apply color for each and every point in PointCloud Using HelixToolkit


I have created a point cloud in HelixToolKit. I need to apply color for each and every point . When I am using PointVisual3D there is no options for setting color for each and every point . It set color for the whole point cloud. When I am using PointGeometryModel3D (using SharpDX) inside the Helix tool kit also I cant able to set the color for each and every point. There is any possibility to set the color for each and every point in Point Cloud.

Thanks...


Solution

  • Usually, this is done by setting the Colors property in the PointGeometry3D object of your PointGeometryModel3D. You have to build the Geometry on your own.

    1. Create the render positions
    2. Create the colors
    3. Tell the renderer the order of your position and colors (List indices in Positions/Colors)

             //create PointGeometryModel3D object
          PointGeometryModel3D pgm = new PointGeometryModel3D();
      
          //create positions
          pgm.Geometry.Positions = new HelixToolkit.Wpf.SharpDX.Core.Vector3Collection();
      
          pgm.Geometry.Positions.AddRange(
              new SharpDX.Vector3[]
              {   new SharpDX.Vector3(0,1,2), 
                  new SharpDX.Vector3(1,2,3), 
                  new SharpDX.Vector3(3,2,3), 
              });
      
          //create colors
          pgm.Geometry.Colors = new HelixToolkit.Wpf.SharpDX.Core.Color4Collection();
      
          pgm.Geometry.Colors.AddRange(
              new SharpDX.Color4[]
              {   
                  new SharpDX.Color4(1f,0,0,1), 
                  new SharpDX.Color4(0,1f,0,1), 
                  new SharpDX.Color4(0,0,1f,1) 
              });
      
          //create indices
          pgm.Geometry.Indices = new HelixToolkit.Wpf.SharpDX.Core.IntCollection();
      
          pgm.Geometry.Indices.AddRange(
              new int[]
              {   
                  0,
                  1,
                  2,
              });
      

    Please let me know if it worked for you. I couldn't make it work with LineGeometry3D and different line colors. There must somewhere be an option to make the renderer use the Color vertices instead of the (single) color property.