98 vtkInformationVector *outputVector,
103 const int numInputs = inputTrees.size();
104 std::vector<MergeTree<dataType>> intermediateTrees, intermediateTrees2;
105 bool const useSecondPairsType
108 inputTrees, intermediateTrees, useSecondPairsType, DiagramPairTypes);
111 auto &inputTrees2ToUse
113 constructTrees(inputTrees2ToUse, intermediateTrees2, !useSecondPairsType,
118 if(not UseFieldDataParameters) {
124 }
else if(Backend == 1) {
129 }
else if(Backend == 3) {
134 }
else if(Backend == 4) {
149 printMsg(
"NormalizedWasserstein is set to false since branch "
150 "decomposition is not asked.");
154 printMsg(
"Computation with normalized Wasserstein.");
156 printMsg(
"Computation without normalized Wasserstein.");
166 printMsg(
"Using Branch Mapping Distance.");
169 metric =
"Wasserstein Distance first degree";
171 metric =
"Wasserstein Distance second degree";
173 metric =
"Persistence difference";
175 metric =
"Shifting cost";
178 printMsg(
"BranchMetric: " + metric);
181 printMsg(
"Using Path Mapping Distance.");
184 metric =
"Persistence difference";
191 std::vector<std::vector<double>> treesDistMat(
192 numInputs, std::vector<double>(numInputs));
199 auto treesDistTable = vtkTable::GetData(outputVector);
203 = [](std::string &colName,
const size_t numberCols,
const size_t colIdx) {
204 std::string
const max{std::to_string(numberCols - 1)};
205 std::string
const cur{std::to_string(colIdx)};
206 std::string
const zer(max.size() - cur.size(),
'0');
207 colName.append(zer).append(cur);
211 vtkNew<vtkIntArray> treeIds{};
212 treeIds->SetName(
"treeID");
213 treeIds->SetNumberOfTuples(numInputs);
214 for(
size_t i = 0; i < treesDistMat.size(); ++i) {
215 treeIds->SetTuple1(i, i);
217 std::string name{
"Tree"};
218 zeroPad(name, treesDistMat.size(), i);
219 vtkNew<vtkDoubleArray> col{};
220 col->SetNumberOfTuples(numInputs);
221 col->SetName(name.c_str());
222 for(
size_t j = 0; j < treesDistMat[i].size(); ++j) {
223 col->SetTuple1(j, treesDistMat[i][j]);
225 treesDistTable->AddColumn(col);
228 treesDistTable->AddColumn(treeIds);
231 vtkNew<vtkFieldData> allFieldData{}, allFieldDataCopy{};
232 for(
unsigned int i = 0; i < inputTrees.size(); ++i) {
233 for(
unsigned int j = 0; j < inputTrees[i]->GetNumberOfBlocks(); ++j) {
234 auto fd = inputTrees[i]->GetBlock(j)->GetFieldData();
235 for(
int k = 0; k < fd->GetNumberOfArrays(); ++k) {
236 auto array = fd->GetAbstractArray(k);
237 auto dataArray = vtkDataArray::SafeDownCast(array);
238 auto stringArray = vtkStringArray::SafeDownCast(array);
239 if(dataArray or stringArray)
240 allFieldData->AddArray(array);
244 allFieldDataCopy->DeepCopy(allFieldData);
246 for(
int k = 0; k < allFieldDataCopy->GetNumberOfArrays(); ++k) {
247 auto array = allFieldDataCopy->GetAbstractArray(k);
248 array->SetNumberOfTuples(inputTrees.size());
249 auto dataArray = vtkDataArray::SafeDownCast(array);
250 auto stringArray = vtkStringArray::SafeDownCast(array);
251 auto name = array->GetName();
252 for(
unsigned int i = 0; i < inputTrees.size(); ++i) {
253 bool foundArray =
false;
254 for(
unsigned int j = 0; j < inputTrees[i]->GetNumberOfBlocks(); ++j) {
256 = inputTrees[i]->GetBlock(j)->GetFieldData()->GetAbstractArray(name);
258 array->SetTuple(i, 0, inputArray);
260 }
else if(not foundArray) {
262 const double val = std::nan(
"");
263 dataArray->SetTuple(i, &val);
264 }
else if(stringArray) {
265 stringArray->SetValue(i,
"");
270 treesDistTable->AddColumn(array);
278 vtkInformationVector **inputVector,
279 vtkInformationVector *outputVector) {
281 auto blocks = vtkMultiBlockDataSet::GetData(inputVector[0], 0);
282 auto blocks2 = vtkMultiBlockDataSet::GetData(inputVector[1], 0);
285 std::vector<vtkSmartPointer<vtkMultiBlockDataSet>> inputTrees, inputTrees2;
290 if(UseFieldDataParameters) {
291 printMsg(
"Load parameters from field data.");
292 std::vector<std::string> paramNames;
294 for(
auto paramName : paramNames) {
295 auto array = blocks->GetFieldData()->GetArray(paramName.c_str());
297 double const value = array->GetTuple1(0);
299 printMsg(
" - " + paramName +
" = " + std::to_string(value));
301 printMsg(
" - " + paramName +
" was not found in the field data.");
305 return run<float>(outputVector, inputTrees, inputTrees2);
bool constructTrees(std::vector< vtkSmartPointer< vtkMultiBlockDataSet > > &inputTrees, std::vector< MergeTree< dataType > > &intermediateTrees, std::vector< vtkUnstructuredGrid * > &treesNodes, std::vector< vtkUnstructuredGrid * > &treesArcs, std::vector< vtkDataSet * > &treesSegmentation, const std::vector< bool > &useSecondPairsTypeVec, int diagramPairTypes=0)