User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to optimize performance using DrawingContext to draw 10000 lines?

03 Sep 2021, 13:19

MeshGeometry is being used on our Window.cpp implementation (the Application Framework of the C++ SDK).

In the XAML, you need something like this:
<Path x:Name="histCPU" Fill="{StaticResource Brush.CPU}" Stretch="None"/>
You assign the MeshGeometry with something like this:
Path* pathHistCPU = xaml->FindName<Path>("histCPU");    
Ptr<MeshGeometry> geoHistCPU = *new MeshGeometry();
pathHistCPU->SetData(geoHistCPU);    
The geometry is filled this way in our code:
void Window::UpdateHistogram(uint16_t* data, float maxF, MeshGeometry* geometry) const
{
    geometry->SetBounds(Rect(mHistSize));

    float stepX = mHistSize.width / (NS_COUNTOF(mHistogramCPU) - 1);
    float baseH = mHistSize.height;
    float minH = baseH - 1.0f;

    geometry->SetNumVertices(2 * NS_COUNTOF(mHistogramCPU));
    Point* vertices = geometry->GetVertices();

    for (uint32_t i = 0; i < NS_COUNTOF(mHistogramCPU); i++)
    {
        float x = i * stepX;

        uint16_t f = data[(mHistPos + i) % NS_COUNTOF(mHistogramCPU)];
        float h = minH - (f * minH / maxF);

        vertices[2 * i] = Point(x, baseH);
        vertices[2 * i + 1] = Point(x, h);
    }

    geometry->SetNumIndices(6 * (NS_COUNTOF(mHistogramCPU) - 1));
    uint16_t* indices = geometry->GetIndices();

    for (uint16_t i = 0; i < NS_COUNTOF(mHistogramCPU) - 1; i++)
    {
        indices[6 * i] = 2 * i;
        indices[6 * i + 1] = 2 * i + 1;
        indices[6 * i + 2] = 2 * i + 2;

        indices[6 * i + 3] = 2 * i + 2;
        indices[6 * i + 4] = 2 * i + 1;
        indices[6 * i + 5] = 2 * i + 3;
    }

    geometry->Update();
}
 
decai
Topic Author
Posts: 54
Joined: 06 Jul 2016, 18:19

Re: How to optimize performance using DrawingContext to draw 10000 lines?

04 Sep 2021, 06:21

Hi,
Using meshGeometry with Path, we want to just draw the edge lines, if we set Path attributes as bellow there will draw nothing.
<Path Fill="Transparent" Stretch="None" Stroke="Black" StrokeThickness="1"/>
If we set Fill="Black", it will draw a black region on the screen.

And there is a DYNAMIC_VB_SIZE vertex bytes limit.
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to optimize performance using DrawingContext to draw 10000 lines?

08 Sep 2021, 14:14

Yes, with MeshGeometry you need to build a mesh (vertices + indices) yourself. Stroke won't work. That's why I said it was too low-level.
 
decai
Topic Author
Posts: 54
Joined: 06 Jul 2016, 18:19

Re: How to optimize performance using DrawingContext to draw 10000 lines?

08 Sep 2021, 14:19

Is that said every line we should draw 2 triangles?
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to optimize performance using DrawingContext to draw 10000 lines?

08 Sep 2021, 14:32

Yes with MeshGeometry
 
decai
Topic Author
Posts: 54
Joined: 06 Jul 2016, 18:19

Re: How to optimize performance using DrawingContext to draw 10000 lines?

08 Sep 2021, 15:56

Does MeshGeometry support 3 dimensions point?
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: How to optimize performance using DrawingContext to draw 10000 lines?

08 Sep 2021, 17:52

No, just 2D points ant 16-bit indices.

Who is online

Users browsing this forum: Google [Bot] and 84 guests