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";
181 printMsg(
"BranchMetric: " + metric);
184 printMsg(
"Using Path Mapping Distance.");
187 metric =
"Persistence difference";
197 std::vector<std::vector<double>> treesDistMat(
198 numInputs, std::vector<double>(numInputs));
202 auto treesDistTable = vtkTable::GetData(outputVector);
206 = [](std::string &colName,
const size_t numberCols,
const size_t colIdx) {
207 std::string
const max{std::to_string(numberCols - 1)};
208 std::string
const cur{std::to_string(colIdx)};
209 std::string
const zer(max.size() - cur.size(),
'0');
210 colName.append(zer).append(cur);
214 vtkNew<vtkIntArray> treeIds{};
215 treeIds->SetName(
"treeID");
216 treeIds->SetNumberOfTuples(numInputs);
217 for(
size_t i = 0; i < treesDistMat.size(); ++i) {
218 treeIds->SetTuple1(i, i);
220 std::string name{
"Tree"};
221 zeroPad(name, treesDistMat.size(), i);
222 vtkNew<vtkDoubleArray> col{};
223 col->SetNumberOfTuples(numInputs);
224 col->SetName(name.c_str());
225 for(
size_t j = 0; j < treesDistMat[i].size(); ++j) {
226 col->SetTuple1(j, treesDistMat[i][j]);
228 treesDistTable->AddColumn(col);
231 treesDistTable->AddColumn(treeIds);
234 vtkNew<vtkFieldData> allFieldData{}, allFieldDataCopy{};
235 for(
unsigned int i = 0; i < inputTrees.size(); ++i) {
236 for(
unsigned int j = 0; j < inputTrees[i]->GetNumberOfBlocks(); ++j) {
237 auto fd = inputTrees[i]->GetBlock(j)->GetFieldData();
238 for(
int k = 0; k < fd->GetNumberOfArrays(); ++k) {
239 auto array = fd->GetAbstractArray(k);
240 auto dataArray = vtkDataArray::SafeDownCast(array);
241 auto stringArray = vtkStringArray::SafeDownCast(array);
242 if(dataArray or stringArray)
243 allFieldData->AddArray(array);
247 allFieldDataCopy->DeepCopy(allFieldData);
249 for(
int k = 0; k < allFieldDataCopy->GetNumberOfArrays(); ++k) {
250 auto array = allFieldDataCopy->GetAbstractArray(k);
251 array->SetNumberOfTuples(inputTrees.size());
252 auto dataArray = vtkDataArray::SafeDownCast(array);
253 auto stringArray = vtkStringArray::SafeDownCast(array);
254 auto name = array->GetName();
255 for(
unsigned int i = 0; i < inputTrees.size(); ++i) {
256 bool foundArray =
false;
257 for(
unsigned int j = 0; j < inputTrees[i]->GetNumberOfBlocks(); ++j) {
259 = inputTrees[i]->GetBlock(j)->GetFieldData()->GetAbstractArray(name);
261 array->SetTuple(i, 0, inputArray);
263 }
else if(not foundArray) {
265 const double val = std::nan(
"");
266 dataArray->SetTuple(i, &val);
267 }
else if(stringArray) {
268 stringArray->SetValue(i,
"");
273 treesDistTable->AddColumn(array);
281 vtkInformationVector **inputVector,
282 vtkInformationVector *outputVector) {
284 auto blocks = vtkMultiBlockDataSet::GetData(inputVector[0], 0);
285 auto blocks2 = vtkMultiBlockDataSet::GetData(inputVector[1], 0);
288 std::vector<vtkSmartPointer<vtkMultiBlockDataSet>> inputTrees, inputTrees2;
293 if(UseFieldDataParameters) {
294 printMsg(
"Load parameters from field data.");
295 std::vector<std::string> paramNames;
297 for(
auto paramName : paramNames) {
298 auto array = blocks->GetFieldData()->GetArray(paramName.c_str());
300 double const value = array->GetTuple1(0);
302 printMsg(
" - " + paramName +
" = " + std::to_string(value));
304 printMsg(
" - " + paramName +
" was not found in the field data.");
308 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)