27 vtkUnstructuredGrid *treeArcs) {
28 auto treeNodeIdArray = treeNodes->GetPointData()->GetArray(
"TreeNodeId");
31 auto scalars = std::make_shared<Scalars>();
33 = treeNodes->GetPointData()->GetArray(
"Scalar");
34 scalars->size = nodesScalar->GetNumberOfTuples();
36 scalars->size = std::max(
37 (
ttk::SimplexId)treeNodeIdArray->GetRange()[1] + 1, scalars->size);
39 = std::make_shared<std::vector<dataType>>(scalars->size);
40 for(
int i = 0; i < nodesScalar->GetNumberOfTuples(); ++i) {
41 int const index = (treeNodeIdArray ? treeNodeIdArray->GetTuple1(i) : i);
42 (*scalarsValues)[index] = nodesScalar->GetTuple1(i);
44 scalars->values = (
void *)(scalarsValues->data());
47 auto params = std::make_shared<Params>();
52 for(vtkIdType i = 0; i < scalars->size; ++i) {
58 = treeArcs->GetCellData()->GetArray(
"upNodeId");
60 = treeArcs->GetCellData()->GetArray(
"downNodeId");
61 vtkIdType
const arcsNumTuples = arcsUp->GetNumberOfTuples();
63 = treeArcs->GetCellData()->GetArray(
"isDummyArc");
64 std::set<std::tuple<double, double>> added_arcs;
65 for(vtkIdType i = 0; i < arcsNumTuples; ++i) {
66 if(dummyArcArray !=
nullptr and dummyArcArray->GetTuple1(i) == 1)
68 double downId = arcsDown->GetTuple1(i);
69 double upId = arcsUp->GetTuple1(i);
71 downId = treeNodeIdArray->GetTuple1(downId);
72 upId = treeNodeIdArray->GetTuple1(upId);
74 auto it = added_arcs.find(std::make_tuple(downId, upId));
75 if(it == added_arcs.end()) {
77 added_arcs.insert(std::make_tuple(downId, upId));
94 bool useSadMaxPairs =
true) {
101 auto criticalTypeArray = persistenceDiagram->GetPointData()->GetArray(
105 = persistenceDiagram->GetPointData()->GetArray(
"TreeNodeId");
106 auto treeNodeId2Array
107 = persistenceDiagram->GetPointData()->GetArray(
"TreeNodeIdOrigin");
108 bool const gotNodeArrays = (treeNodeIdArray and treeNodeId2Array);
110 auto noPairs = birthArray->GetNumberOfTuples();
111 int noNodes = noPairs * 2;
113 for(vtkIdType i = 0; i < treeNodeIdArray->GetNumberOfTuples(); ++i) {
114 int const val = std::max(treeNodeIdArray->GetTuple1(i),
115 treeNodeId2Array->GetTuple1(i))
117 noNodes = std::max(noNodes, val);
120 std::vector<dataType> scalarsVector(noNodes);
124 = ttk::ftm::createEmptyMergeTree<dataType>(scalarsVector.size());
131 int minMaxPairIndex = -1;
132 for(vtkIdType i = 0; i < noPairs; ++i) {
134 vtkIdType
const *pts;
135 persistenceDiagram->GetCellPoints(i, npts, pts);
136 auto ct1 = criticalTypeArray->GetTuple1(pts[0]);
137 auto ct2 = criticalTypeArray->GetTuple1(pts[1]);
138 if((ct1 == locMin and ct2 == locMax)
139 or (ct1 == locMax and ct2 == locMin))
144 for(vtkIdType i = 0; i < noNodes; ++i)
146 for(vtkIdType i = 0; i < noPairs; ++i) {
147 auto pairType = pairTypeArray->GetTuple1(i);
149 vtkIdType
const *pts;
150 persistenceDiagram->GetCellPoints(i, npts, pts);
151 auto ct1 = criticalTypeArray->GetTuple1(pts[0]);
152 auto ct2 = criticalTypeArray->GetTuple1(pts[1]);
154 or (useSadMaxPairs and ct1 != locMax and ct2 != locMax)
155 or (not useSadMaxPairs and ct1 != locMin and ct2 != locMin))
156 and i != minMaxPairIndex)
159 = (gotNodeArrays ? treeNodeId2Array->GetTuple1(pts[0]) : i * 2);
161 = (gotNodeArrays ? treeNodeIdArray->GetTuple1(pts[0]) : i * 2 + 1);
164 scalarsVector[index1] = birthArray->GetTuple1(i);
165 scalarsVector[index2]
166 = birthArray->GetTuple1(i) + persArray->GetTuple1(i);
168 if(i != minMaxPairIndex) {
169 auto up = (gotNodeArrays ? treeNodeIdArray->GetTuple1(minMaxPairIndex)
170 : minMaxPairIndex * 2 + 1);
177 ttk::ftm::setTreeScalars<dataType>(mergeTree, scalarsVector);
184 vtkMultiBlockDataSet *blocks) {
185 if(blocks !=
nullptr) {
186 if(blocks->GetBlock(0)->IsA(
"vtkMultiBlockDataSet"))
188 vtkMultiBlockDataSet::SafeDownCast(blocks->GetBlock(0))
189 ->GetNumberOfBlocks());
190 else if(blocks->GetBlock(0)->IsA(
"vtkUnstructuredGrid"))
191 inputTrees.resize(blocks->GetNumberOfBlocks());
192 for(
size_t i = 0; i < inputTrees.size(); ++i) {
193 if(blocks->GetBlock(0)->IsA(
"vtkMultiBlockDataSet")) {
196 vtkBlock->SetNumberOfBlocks(blocks->GetNumberOfBlocks());
197 for(
unsigned int j = 0; j < blocks->GetNumberOfBlocks(); ++j)
199 j, vtkMultiBlockDataSet::SafeDownCast(blocks->GetBlock(j))
201 inputTrees[i] = vtkBlock;
202 }
else if(blocks->GetBlock(0)->IsA(
"vtkUnstructuredGrid")) {
205 vtkBlock->SetNumberOfBlocks(1);
207 0, vtkUnstructuredGrid::SafeDownCast(blocks->GetBlock(i)));
208 inputTrees[i] = vtkBlock;
218 std::vector<vtkUnstructuredGrid *> &treesNodes,
219 std::vector<vtkUnstructuredGrid *> &treesArcs,
220 std::vector<vtkDataSet *> &treesSegmentation,
221 std::vector<bool> useSadMaxPairs) {
222 bool isPersistenceDiagram =
false;
223 const int numInputs = inputTrees.size();
224 intermediateTrees.resize(numInputs);
225 treesNodes.resize(numInputs);
226 treesArcs.resize(numInputs);
227 treesSegmentation.resize(numInputs);
228 for(
int i = 0; i < numInputs; i++) {
229 if(inputTrees[i]->GetNumberOfBlocks() >= 2) {
231 = vtkUnstructuredGrid::SafeDownCast(inputTrees[i]->GetBlock(0));
233 = vtkUnstructuredGrid::SafeDownCast(inputTrees[i]->GetBlock(1));
234 if(inputTrees[i]->GetNumberOfBlocks() > 2)
236 = vtkDataSet::SafeDownCast(inputTrees[i]->GetBlock(2));
238 = makeTree<dataType>(treesNodes[i], treesArcs[i]);
241 = vtkUnstructuredGrid::SafeDownCast(inputTrees[i]->GetBlock(0));
242 vtkUnstructuredGrid *persistenceDiagram
243 = vtkUnstructuredGrid::SafeDownCast(inputTrees[i]->GetBlock(0));
244 intermediateTrees[i] = makeBDTreeFromPDGrid<dataType>(
245 persistenceDiagram, useSadMaxPairs[i]);
246 isPersistenceDiagram =
true;
249 return isPersistenceDiagram;
256 std::vector<vtkUnstructuredGrid *> &treesNodes,
257 std::vector<vtkUnstructuredGrid *> &treesArcs,
258 std::vector<vtkDataSet *> &treesSegmentation,
259 bool useSadMaxPairs =
true) {
260 std::vector<bool>
const useSadMaxPairsVec(
261 inputTrees.size(), useSadMaxPairs);
263 treesArcs, treesSegmentation, useSadMaxPairsVec);
270 bool useSadMaxPairs =
true) {
271 std::vector<vtkUnstructuredGrid *> treesNodes;
272 std::vector<vtkUnstructuredGrid *> treesArcs;
273 std::vector<vtkDataSet *> treesSegmentation;
275 treesArcs, treesSegmentation, useSadMaxPairs);
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)