# Visualize Very large number of Lines, Points/Spheres with High Performance

**URL:** https://discourse.vtk.org/t/visualize-very-large-number-of-lines-points-spheres-with-high-performance/2353
**Category:** Development
**Created:** [December 28, 2019, 7:00am UTC](https://discourse.vtk.org/t/visualize-very-large-number-of-lines-points-spheres-with-high-performance/2353 "2019-12-28T07:00:30Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sharon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@sharon](https://discourse.vtk.org/u/sharon)
#### Post date: [December 28, 2019, 7:00am UTC](https://discourse.vtk.org/t/visualize-very-large-number-of-lines-points-spheres-with-high-performance/2353/1 "2019-12-28T07:00:30Z")

</div>

Dear Experts,

In my situation, i need visualize very large number of Lines, Points/Spheres, with high performance,  
Do you have any suggestions?

My current implementation is put group of lines into polyData, then put polyData into multiBlockData,  
in the way i can change color for each group of polyData, but seems the performance is not good…

Any suggestions?

---

<div class="post-metadata">

### Author: ![michael23](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael23/32/837_2.png) [@michael23](https://discourse.vtk.org/u/michael23)
#### Post date: [December 28, 2019, 6:37pm UTC](https://discourse.vtk.org/t/visualize-very-large-number-of-lines-points-spheres-with-high-performance/2353/2 "2019-12-28T18:37:13Z")

</div>

Hi,

have you already checked out vtkGlyph3D? I use it to visualize a large number of spheres and cylinders. You can still change the scale, color and orientation individually.

---

<div class="post-metadata">

### Author: ![sharon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@sharon](https://discourse.vtk.org/u/sharon)
#### Post date: [December 31, 2019, 4:02am UTC](https://discourse.vtk.org/t/visualize-very-large-number-of-lines-points-spheres-with-high-performance/2353/3 "2019-12-31T04:02:20Z")

</div>

Thank you Michael for your reply!

Havent tried, but [vtkGlyph3D](https://vtk.org/doc/nightly/html/classvtkGlyph3D.html) is an arrow, how you make it as spheres an cylinders?

---

<div class="post-metadata">

### Author: ![michael23](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael23/32/837_2.png) [@michael23](https://discourse.vtk.org/u/michael23)
#### Post date: [December 31, 2019, 1:29pm UTC](https://discourse.vtk.org/t/visualize-very-large-number-of-lines-points-spheres-with-high-performance/2353/4 "2019-12-31T13:29:58Z")

</div>

**Spheres:**

// Array for sphere positions  
Points = vtkSmartPointer::New();

// Array for sphere radii  
radii = vtkSmartPointer::New();  
radii-\>Initialize();  
radii-\>SetName(“radii”);

// Array for sphere colors  
colors = vtkSmartPointer::New();  
colors-\>Initialize();  
colors-\>SetNumberOfComponents(4);  
colors-\>SetName(“colors”);

// Set position, radius and color  
for (int i = 0; i \< NUMBER OF SPHERES; i++)  
{  
points-\>InsertNextPoint(X, Y, Z);  
radii-\>InsertNextValue(RADIUS);  
colors-\>InsertNextTypedTuple(R, G, B, ALPHA);  
}

// Create an unstructured grid  
grid = vtkSmartPointer::New();  
grid-\>SetPoints(points);  
grid-\>GetPointData()-\>AddArray(radii);  
grid-\>GetPointData()-\>AddArray(colors);  
grid-\>GetPointData()-\>SetActiveScalars(“radii”);

// The points should be visualized as spheres  
sourceBall = vtkSmartPointer::New();  
sourceBall-\>SetRadius(1);

// Use VTK’s Glyph3D filter to create a single VTK actor  
// which includes multiple spheres at certain locations  
source = vtkSmartPointer::New();  
source-\>SetColorModeToColorByScalar();  
source-\>SetSourceConnection(spSourceBall-\>GetOutputPort());  
source-\>SetInputData(grid);  
source-\>SetScaleModeToScaleByScalar();

// Create VTK actor / mapper  
vtkSmartPointer mapper = vtkSmartPointer::New();   
mapper-\>SetInputConnection(spSource-\>GetOutputPort());  
mapper-\>SetScalarModeToUsePointFieldData();  
mapper-\>SelectColorArray(“colors”);  
mapper-\>SetScalarVisibility(true);  
actor = vtkSmartPointer::New();  
actor-\>SetMapper(mapper);

**Cylinders:**

Just replace the sphere source with a cylinder source.

In order to orient the cylinders, create an additional array like this:

normals = vtkSmartPointer::New();  
normals-\>SetNumberOfComponents(3);

Add the normals to the unstructured grid:  
grid-\>GetPointData()-\>SetNormals(normals);

Moreover, you call the following method for the cylinder source:  
source-\>SetVectorModeToUseNormal();

I hope this helps.

---

<div class="post-metadata">

### Author: ![sharon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@sharon](https://discourse.vtk.org/u/sharon)
#### Post date: [January 12, 2020, 2:55am UTC](https://discourse.vtk.org/t/visualize-very-large-number-of-lines-points-spheres-with-high-performance/2353/5 "2020-01-12T02:55:44Z")

</div>

Thank you Michael very much for your sample code!!  
I will have a study of this!

Best Regards!
