------------------------------------------------------------------------------
| 427 | |
| 428 | //------------------------------------------------------------------------------ |
| 429 | bool vtkPOrderStatistics::Broadcast(std::map<vtkStdString, vtkIdType>& histogram, |
| 430 | vtkIdTypeArray* card, vtkStringArray* sVals, vtkIdType rProc) |
| 431 | { |
| 432 | vtkCommunicator* com = this->Controller->GetCommunicator(); |
| 433 | |
| 434 | // Concatenate string keys of histogram into single string and put values into resized array |
| 435 | std::string sPack; |
| 436 | StringHistoToBuffers(histogram, sPack, card); |
| 437 | |
| 438 | // Broadcast size of string buffer |
| 439 | vtkIdType nc = static_cast<vtkIdType>(sPack.size()); |
| 440 | if (!com->Broadcast(&nc, 1, rProc)) |
| 441 | { |
| 442 | vtkErrorMacro( |
| 443 | "Process " << com->GetLocalProcessId() << " could not broadcast size of string buffer."); |
| 444 | |
| 445 | return true; |
| 446 | } |
| 447 | |
| 448 | // Resize string so it can receive the broadcasted string buffer |
| 449 | sPack.resize(nc); |
| 450 | |
| 451 | // Broadcast histogram values |
| 452 | if (!com->Broadcast(&(*sPack.begin()), nc, rProc)) |
| 453 | { |
| 454 | vtkErrorMacro( |
| 455 | "Process " << com->GetLocalProcessId() << " could not broadcast histogram string values."); |
| 456 | |
| 457 | return true; |
| 458 | } |
| 459 | |
| 460 | // Unpack the packet of strings |
| 461 | std::vector<std::string> sVect; |
| 462 | StringBufferToStringVector(sPack, sVect); |
| 463 | |
| 464 | // Broadcast histogram cardinalities |
| 465 | if (!com->Broadcast(card, rProc)) |
| 466 | { |
| 467 | vtkErrorMacro( |
| 468 | "Process " << com->GetLocalProcessId() << " could not broadcast histogram cardinalities."); |
| 469 | |
| 470 | return true; |
| 471 | } |
| 472 | |
| 473 | // Now resize global histogram arrays to reduced size |
| 474 | sVals->SetNumberOfValues(static_cast<vtkIdType>(sVect.size())); |
| 475 | |
| 476 | // Then store reduced histogram into array |
| 477 | vtkIdType r = 0; |
| 478 | for (std::vector<std::string>::iterator vit = sVect.begin(); vit != sVect.end(); ++vit, ++r) |
| 479 | { |
| 480 | sVals->SetValue(r, *vit); |
| 481 | } |
| 482 | |
| 483 | return false; |
| 484 | } |
| 485 | VTK_ABI_NAMESPACE_END |