| 448 | } |
| 449 | |
| 450 | void ExportVisFunctions(py::module &m) { |
| 451 | m.def("_GetVisualizationData", [] (shared_ptr<ngcomp::MeshAccess> ma, map<ngfem::ELEMENT_TYPE, IntegrationRule> irs) { |
| 452 | struct ElementInformation { |
| 453 | ElementInformation( ngfem::ELEMENT_TYPE type_, bool curved_=false) |
| 454 | : type(type_), curved(curved_), nelements(0) { } |
| 455 | Array<int> data; // the data that will go into the gpu texture buffer |
| 456 | ngfem::ELEMENT_TYPE type; |
| 457 | bool curved; |
| 458 | int nelements; |
| 459 | }; |
| 460 | |
| 461 | auto getVB = [](int codim) { |
| 462 | switch(codim) { |
| 463 | case 0: return VOL; |
| 464 | case 1: return BND; |
| 465 | case 2: return BBND; |
| 466 | case 3: return BBBND; |
| 467 | default: throw Exception("invalid codim"); |
| 468 | } |
| 469 | }; |
| 470 | |
| 471 | Vector<> min(3); |
| 472 | min = std::numeric_limits<double>::max(); |
| 473 | Vector<> max(3); |
| 474 | max = std::numeric_limits<double>::lowest(); |
| 475 | |
| 476 | ngstd::Array<float> vertices; |
| 477 | vertices.SetAllocSize(ma->GetNV()*3); |
| 478 | for ( auto vi : Range(ma->GetNV()) ) { |
| 479 | auto v = ma->GetPoint<3>(vi); |
| 480 | for (auto i : Range(3)) { |
| 481 | vertices.Append(v[i]); |
| 482 | min[i] = min2(min[i], v[i]); |
| 483 | max[i] = max2(max[i], v[i]); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | LocalHeap lh(1000000, "GetMeshData"); |
| 488 | auto toDict = [] (ElementInformation &ei) { |
| 489 | py::dict res; |
| 490 | res["data"] = py::cast(ei.data); |
| 491 | res["type"] = py::cast(ei.type); |
| 492 | res["curved"] = py::cast(ei.curved); |
| 493 | res["nelements"] = py::cast(ei.nelements); |
| 494 | return res; |
| 495 | }; |
| 496 | |
| 497 | const int dim = ma->GetDimension(); |
| 498 | |
| 499 | std::map<VorB, py::list> element_data; |
| 500 | ElementInformation points(ET_POINT); |
| 501 | points.nelements = ma->GetNE(getVB(dim)); |
| 502 | points.data.SetAllocSize(points.nelements); |
| 503 | for(auto el : ma->Elements(getVB(dim))) |
| 504 | points.data.Append(el.vertices[0]); |
| 505 | element_data[getVB(dim)].append(toDict(points)); |
| 506 | |
| 507 | ElementInformation edges(ET_SEGM); |
no test coverage detected