------------------------------------------------------------------------------
| 454 | |
| 455 | //------------------------------------------------------------------------------ |
| 456 | std::string vtkJSONSceneExporter::WriteDataSet( |
| 457 | vtkDataSet* dataset, const char* addOnMeta, const char* name) |
| 458 | { |
| 459 | if (!dataset) |
| 460 | { |
| 461 | return ""; |
| 462 | } |
| 463 | |
| 464 | std::string dsPath = this->CurrentDataSetPath(); |
| 465 | ++this->DatasetCount; |
| 466 | |
| 467 | auto* polyData = vtkPolyData::SafeDownCast(dataset); |
| 468 | vtkSmartPointer<vtkPolyData> newDataset; |
| 469 | std::string polyLODsConfig; |
| 470 | if (this->WritePolyLODs && polyData) |
| 471 | { |
| 472 | newDataset = this->WritePolyLODSeries(polyData, polyLODsConfig); |
| 473 | // Write the smallest poly LOD to the vtkjs file |
| 474 | dataset = newDataset.Get(); |
| 475 | } |
| 476 | |
| 477 | vtkNew<vtkJSONDataSetWriter> dsWriter; |
| 478 | dsWriter->SetInputData(dataset); |
| 479 | dsWriter->GetArchiver()->SetArchiveName(dsPath.c_str()); |
| 480 | |
| 481 | // When the dataset is given a name, ie when we're working with a named actor map, |
| 482 | // disable all arrays by default, and select only the ones that are mapped. |
| 483 | if (name) |
| 484 | { |
| 485 | dsWriter->GetPointArraySelection()->SetUnknownArraySetting(0); |
| 486 | dsWriter->GetCellArraySelection()->SetUnknownArraySetting(0); |
| 487 | |
| 488 | // Parse MapPointArrays's list of arrays, filter the ones that start with "propName:X", and |
| 489 | // forward information about X to the writer |
| 490 | for (int id = 0; id < this->PointArraySelection->GetNumberOfArrays(); id++) |
| 491 | { |
| 492 | std::string currentName = this->PointArraySelection->GetArrayName(id); |
| 493 | if (currentName.find(name) != std::string::npos && |
| 494 | currentName[std::string(name).size()] == ':') |
| 495 | { |
| 496 | std::string arrayName = currentName.substr(std::string(name).size() + 1); |
| 497 | dsWriter->GetPointArraySelection()->SetArraySetting( |
| 498 | arrayName.c_str(), this->PointArraySelection->ArrayIsEnabled(currentName.c_str())); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | // Same for cell arrays |
| 503 | for (int id = 0; id < this->CellArraySelection->GetNumberOfArrays(); id++) |
| 504 | { |
| 505 | std::string currentName = this->CellArraySelection->GetArrayName(id); |
| 506 | if (currentName.find(name) != std::string::npos && |
| 507 | currentName[std::string(name).size()] == ':') |
| 508 | { |
| 509 | std::string arrayName = currentName.substr(std::string(name).size() + 1); |
| 510 | dsWriter->GetCellArraySelection()->SetArraySetting( |
| 511 | arrayName.c_str(), this->CellArraySelection->ArrayIsEnabled(currentName.c_str())); |
| 512 | } |
| 513 | } |
no test coverage detected