Re: How to optimize performance using DrawingContext to draw 10000 lines?
Posted: 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:
You assign the MeshGeometry with something like this:
The geometry is filled this way in our code:
In the XAML, you need something like this:
Code: Select all
<Path x:Name="histCPU" Fill="{StaticResource Brush.CPU}" Stretch="None"/>
Code: Select all
Path* pathHistCPU = xaml->FindName<Path>("histCPU");
Ptr<MeshGeometry> geoHistCPU = *new MeshGeometry();
pathHistCPU->SetData(geoHistCPU);
Code: Select all
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();
}