visu performance on 50k elements

natalia

Moderator
Staff member
On the visualization lesson stream, it was asked:
'How could I create/display dynamic position/path of a 3D point/edge. There would be some >50.000 points/edges at a rate of 50 msec update.
Maybe there is a better way in OCCT to do this?'
 

natalia

Moderator
Staff member
For points, the better way is AIS_PointCloud using.
Lots of AIS_Point is not recommended as it gives poor performance/memory spent.

Below the results on AIS_PointCloud with the expected scenario is attached.
This check shows that the performance seems to be appropriate but surely depends on the PC capabilities where it's checked.

Some comments about the attached video:

1. on start of the video there is a shape prepared with more than 50k points (55 841).
2. click on 'AIS_Shape' creates and visualizes AIS_Shape filled with the shape in the shading mode (with default gold color)
3. click on 'AIS_PointCloud' extracts points from the shape to fill a presentation based on the points
and create and visualize AIS_PointCloud for these points
4. click on 'Run' starts animation of the points change in 50 msecs (set new points for created AIS_PointCloud on each timer step)
5. enter rate equal to 10 msesc changes animation rate to 10
6. click on 'Run' starts animation in the new rate.

Here, the update of points is moving each point in the direction to the center of the ring multiplied on some coefficient in each step.

For lots of lines, there is no ready presentation in AIS package. The proposal is implementing some custom presentation in the way as AIS_PointCloud implemented.
point_cloud_rate.gif
 

udoS

Looking around for some CAD
@natalia
My setup: Linux Debian 10; OCCT 7.6; Qt 5.15.2; QtCtreator 5.0.3

The picture: That is the working head of a cnc or could be 3D-Printhead.

Now I poll every 20msec for the actual position and get a point in 3d-space.
Then making an edge from the previous to the actual point. ( two different colors for hight/blue and low/yellow -speed).
Then context->Display(Ais_Shape, Standard_False);
Speed is ok up to about 1000 - 1500 edges, after that the display/update is jerky too much.

I tried to put points into vector and then make a compound (loosing the color) but with the same result.
For now I have limited the edges only displaying the last 1000 edges. Just as a compromise.

For cnc-path view not nice but workable.
For 3d-print path not possible.
Do you see any way to make this work.

 

Attachments

  • PathView_2021-12-25_11-16-33.png
    PathView_2021-12-25_11-16-33.png
    39.9 KB · Views: 10
  • Bildschirmfoto_2022-01-05_17-46-51.png
    Bildschirmfoto_2022-01-05_17-46-51.png
    164.4 KB · Views: 5
Last edited:

natalia

Moderator
Staff member
Using AIS_Shape/TopoDS_Shape for 50k edges is too expensive. The better way to visualize them and provide such animation is implementing own presentation. We may redefine Compute of this presentation in the following way:
Code:
void viewerLines_linePresentation::Compute(const Handle(PrsMgr_PresentationManager)& prsMgr,
  const Handle(Prs3d_Presentation)& prs, const Standard_Integer mode)
{
  if (m_points.IsNull())
    return;

  const Standard_Integer nbVertices = m_points->VertexNumber();
  Handle(Graphic3d_ArrayOfPolylines) prims = new Graphic3d_ArrayOfPolylines(nbVertices);
  for (Standard_Integer pointsIt = 1; pointsIt <= nbVertices; ++pointsIt)
  {
    prims->AddVertex(m_points->Vertice(pointsIt));
  }

  Handle(Graphic3d_Group) group = prs->NewGroup();
  group->SetGroupPrimitivesAspect(Attributes()->LineAspect()->Aspect());
  group->AddPrimitiveArray(prims);
}

The whole code of this test sample is available in ‘https://gitlab.com/ssv/lessons’, branch ‘viewerLines’. The sample directory is 'medium_viewerLines'.

The result of comparison is on the video:
50k_lines_2022-01-11-01-00-24.gif
 

udoS

Looking around for some CAD
Hallo Natalia
Thanks a lot for this. Finally I got it to work with QtCreator with Linux Debian10.
Now. : I create the line from live-points that come from an actual cnc-position.
There are two situation: high and low speed; changing at any given time.
I like to display this in two different colors of the line.
In your example while running wirelines_presentations press a bottom to change color. How to ?
A little help would be nice.
Thanks again.
 

Attachments

  • PathView_2021-12-25_11-16-33.png
    PathView_2021-12-25_11-16-33.png
    39.9 KB · Views: 5

JSlyadne

Administrator
Staff member
Hallo Natalia
Thanks a lot for this. Finally I got it to work with QtCreator with Linux Debian10.
Now. : I create the line from live-points that come from an actual cnc-position.
There are two situation: high and low speed; changing at any given time.
I like to display this in two different colors of the line.
In your example while running wirelines_presentations press a bottom to change color. How to ?
A little help would be nice.
Thanks again.
Hey @udoS! I would very appreciate if you elaborate a bit on whether the custom presentation resolves the performance issue? Does it work for you? How much complex toolpath you can create display with acceptable speed now?
 

natalia

Moderator
Staff member
Hi @udoS!
For having an additional color in this presentation just add into Compute a group painted with another line aspect:
C++:
void viewerLines_linePresentation::Compute(const Handle(PrsMgr_PresentationManager)& /*prsMgr*/,
  const Handle(Prs3d_Presentation)& prs, const Standard_Integer /*mode*/)
{
  if (m_points.IsNull())
    return;

  const Standard_Integer nbVertices = m_points->VertexNumber();
  Handle(Graphic3d_ArrayOfPolylines) prims = new Graphic3d_ArrayOfPolylines(nbVertices);
  for (Standard_Integer pointsIt = 1; pointsIt <= nbVertices; ++pointsIt)
  {
    prims->AddVertex(m_points->Vertice(pointsIt));
  }

  Handle(Graphic3d_Group) group = prs->NewGroup();
  group->SetGroupPrimitivesAspect(Attributes()->LineAspect()->Aspect());
  group->AddPrimitiveArray(prims);

  // visualization of the lines in additional color
  // Here each point is translated on a fixed value and painted in blue color.
  Handle(Prs3d_LineAspect) color2Style = new Prs3d_LineAspect(Quantity_NOC_BLUE, Aspect_TOL_SOLID, 1);

  Handle(Graphic3d_ArrayOfPolylines) prims2 = new Graphic3d_ArrayOfPolylines(nbVertices);
  for (Standard_Integer pointsIt = 1; pointsIt <= nbVertices; ++pointsIt)
  {
    prims2->AddVertex(m_points->Vertice(pointsIt).XYZ() + gp_Pnt(0.5, 0.5, 0.).XYZ());
  }

  Handle(Graphic3d_Group) group2 = prs->NewGroup();
  group2->SetGroupPrimitivesAspect(color2Style->Aspect());
  group2->AddPrimitiveArray(prims2);
}

The result is:
 

Attachments

  • 50k_lines_two_color.png
    50k_lines_two_color.png
    20.9 KB · Views: 4

udoS

Looking around for some CAD
Sorry Natalia,
it's the same ( one ) Line with two different colors.
Like the first nnn segments blue, then following some nnn segments green, then nnn back to blue and so on.
One Line with different color depending on condition during time of getting the Point.
Sorry for the misunderstanding.
 

natalia

Moderator
Staff member
This is just a sample of how to unite two colours for lines in one presentation)
For your case, it seems, it would be a good solution to have two presentations like viewerLines_linePresentation. Each one will have its own points and colour and will be updated when you need it.
 

udoS

Looking around for some CAD
@natalia,
this works very nice :cool:
Handle(Graphic3d_ArrayOfPolylines) prims = new Graphic3d_ArrayOfPolylines(nbVertices,0,nbVertices,1,0);
for (Standard_Integer pointsIt = 1; pointsIt <= nbVertices; ++pointsIt)
if(something....)
{
prims->AddVertex(m_points->Vertice(pointsIt),Quantity_Color(Quantity_NOC_BLUE);
}
else prims->AddVertex(m_points->Vertice(pointsIt),Quantity_Color(Quantity_NOC_GREEN);
Handle(Graphic3d_Group) group = prs->NewGroup();
group->SetGroupPrimitivesAspect(Attributes()->LineAspect()->Aspect());
group->AddPrimitiveArray(prims);

Thanks for your help; I'm really great full.
 
Top