PointClouds
Point clouds are an useful visualization tool in RobotStudio.
Special areas, paths, shapes and many more things can be represented with a point cloud.
In this topic, we will show how to create a Point
The steps contained in this topic are:
Declare a cube-shaped a Point
Cloud object.Assign a color to each point of the Point
Cloud .Display the Point
Cloud .
Note
You can easily try out this example using the RobotStudio Empty Add-in template from Visual Studio.
Solution
Declare a Point
Cloud object. In this example we will build a cube-shaped point cloud. Since we will build a (5,5,5) cube, and the Points array has only one dimension, we will assign a 125 element array to it. We will assign another array with the same size to the Colors member and we will set the size of the points to 7.PointCloud p = new PointCloud(); p.Points = new Vector3[125]; // 5 x 5 x 5 size array p.Colors = new Color[125]; // color of every single point p.PointSize = 7; // size of the points
Using a three For-Loops, one for every dimension (x,y and z), we will place the points in space assigning one of the elements of the Points member and set the color of the point in the Colors array.
// Set the position and color of every single point int i = 0; for (double x = -0.5; x < 0.6; x = x + 0.25) { for (double y = -0.5; y < 0.6; y = y + 0.25) { for (double z = 0.5; z < 1.6; z = z + 0.25) { p.Points[i] = new Vector3(x, y, z); // place the point p.Colors[i] = Color.FromArgb(255 - i * 2, 0, i * 2); // make a red-blue gradient i++; // increase the index } } }
Finally, we display the point cloud using the following statements:
Station station = Project.ActiveProject as Station; station.PointClouds.Add(p); // Add the pointCloud
Caution
It is necessary to assign the Points array before assigning the Colors one, since having a non-null Colors array with a size that differs with the Points array size will issue an exception during runtime.
Example
The complete code for this example is shown below:
private static void pointCloudDemo()
{
PointCloud p = new PointCloud();
p.Points = new Vector3[125]; // 5 x 5 x 5 size array
p.Colors = new Color[125]; // color of every single point
p.PointSize = 7; // size of the points
// Set the position and color of every single point
int i = 0;
for (double x = -0.5; x < 0.6; x = x + 0.25)
{
for (double y = -0.5; y < 0.6; y = y + 0.25)
{
for (double z = 0.5; z < 1.6; z = z + 0.25)
{
p.Points[i] = new Vector3(x, y, z); // place the point
p.Colors[i] = Color.FromArgb(255 - i * 2, 0, i * 2); // make a red-blue gradient
i++; // increase the index
}
}
}
Station station = Project.ActiveProject as Station;
station.PointClouds.Add(p); // Add the pointCloud
}
Required Namespaces
ABB.