98 vtkInformationVector *outputVector,
103 const int numInputs = inputTrees.size();
104 std::vector<MergeTree<dataType>> intermediateTrees, intermediateTrees2;
110 auto &inputTrees2ToUse
112 constructTrees(inputTrees2ToUse, intermediateTrees2, !useSadMaxPairs);
116 if(not UseFieldDataParameters) {
122 }
else if(Backend == 1) {
127 }
else if(Backend == 3) {
132 }
else if(Backend == 4) {
147 printMsg(
"NormalizedWasserstein is set to false since branch "
148 "decomposition is not asked.");
152 printMsg(
"Computation with normalized Wasserstein.");
154 printMsg(
"Computation without normalized Wasserstein.");
164 printMsg(
"Using Branch Mapping Distance.");
167 metric =
"Wasserstein Distance first degree";
169 metric =
"Wasserstein Distance second degree";
171 metric =
"Persistence difference";
173 metric =
"Shifting cost";
176 printMsg(
"BranchMetric: " + metric);
179 printMsg(
"Using Path Mapping Distance.");
182 metric =
"Persistence difference";
189 std::vector<std::vector<double>> treesDistMat(
190 numInputs, std::vector<double>(numInputs));
192 execute<dataType>(intermediateTrees, intermediateTrees2, treesDistMat);
194 execute<dataType>(intermediateTrees, treesDistMat);
197 auto treesDistTable = vtkTable::GetData(outputVector);
201 = [](std::string &colName,
const size_t numberCols,
const size_t colIdx) {
202 std::string
const max{std::to_string(numberCols - 1)};
203 std::string
const cur{std::to_string(colIdx)};
204 std::string
const zer(max.size() - cur.size(),
'0');
205 colName.append(zer).append(cur);
209 vtkNew<vtkIntArray> treeIds{};
210 treeIds->SetName(
"treeID");
211 treeIds->SetNumberOfTuples(numInputs);
212 for(
size_t i = 0; i < treesDistMat.size(); ++i) {
213 treeIds->SetTuple1(i, i);
215 std::string name{
"Tree"};
216 zeroPad(name, treesDistMat.size(), i);
217 vtkNew<vtkDoubleArray> col{};
218 col->SetNumberOfTuples(numInputs);
219 col->SetName(name.c_str());
220 for(
size_t j = 0; j < treesDistMat[i].size(); ++j) {
221 col->SetTuple1(j, treesDistMat[i][j]);
223 treesDistTable->AddColumn(col);
226 treesDistTable->AddColumn(treeIds);
229 vtkNew<vtkFieldData> allFieldData{}, allFieldDataCopy{};
230 for(
unsigned int i = 0; i < inputTrees.size(); ++i) {
231 for(
unsigned int j = 0; j < inputTrees[i]->GetNumberOfBlocks(); ++j) {
232 auto fd = inputTrees[i]->GetBlock(j)->GetFieldData();
233 for(
int k = 0; k < fd->GetNumberOfArrays(); ++k) {
234 auto array = fd->GetAbstractArray(k);
235 auto dataArray = vtkDataArray::SafeDownCast(array);
236 auto stringArray = vtkStringArray::SafeDownCast(array);
237 if(dataArray or stringArray)
238 allFieldData->AddArray(array);
242 allFieldDataCopy->DeepCopy(allFieldData);
244 for(
int k = 0; k < allFieldDataCopy->GetNumberOfArrays(); ++k) {
245 auto array = allFieldDataCopy->GetAbstractArray(k);
246 array->SetNumberOfTuples(inputTrees.size());
247 auto dataArray = vtkDataArray::SafeDownCast(array);
248 auto stringArray = vtkStringArray::SafeDownCast(array);
249 auto name = array->GetName();
250 for(
unsigned int i = 0; i < inputTrees.size(); ++i) {
251 bool foundArray =
false;
252 for(
unsigned int j = 0; j < inputTrees[i]->GetNumberOfBlocks(); ++j) {
254 = inputTrees[i]->GetBlock(j)->GetFieldData()->GetAbstractArray(name);
256 array->SetTuple(i, 0, inputArray);
258 }
else if(not foundArray) {
260 const double val = std::nan(
"");
261 dataArray->SetTuple(i, &val);
262 }
else if(stringArray) {
263 stringArray->SetValue(i,
"");
268 treesDistTable->AddColumn(array);
276 vtkInformationVector **inputVector,
277 vtkInformationVector *outputVector) {
279 auto blocks = vtkMultiBlockDataSet::GetData(inputVector[0], 0);
280 auto blocks2 = vtkMultiBlockDataSet::GetData(inputVector[1], 0);
283 std::vector<vtkSmartPointer<vtkMultiBlockDataSet>> inputTrees, inputTrees2;
288 if(UseFieldDataParameters) {
289 printMsg(
"Load parameters from field data.");
290 std::vector<std::string> paramNames;
292 for(
auto paramName : paramNames) {
293 auto array = blocks->GetFieldData()->GetArray(paramName.c_str());
295 double const value = array->GetTuple1(0);
297 printMsg(
" - " + paramName +
" = " + std::to_string(value));
299 printMsg(
" - " + paramName +
" was not found in the field data.");
303 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, std::vector< bool > useSadMaxPairs)