TTK
Loading...
Searching...
No Matches
ttkReebGraphStructures.h
Go to the documentation of this file.
1#pragma once
2
3#include <vtkCellData.h>
4#include <vtkCharArray.h>
5#include <vtkDataSet.h>
6#include <vtkDoubleArray.h>
7#include <vtkIntArray.h>
8#include <vtkNew.h>
9#include <vtkPointData.h>
10#include <vtkUnsignedCharArray.h>
11#include <vtkUnstructuredGrid.h>
12
13#include <FTRCommon.h>
14#include <FTRDataTypes.h>
15#include <Graph.h>
16
17namespace ttk {
18 namespace ftr {
19
22 struct ObjectData {
23 inline void allocArray(vtkDataArray *const arr,
24 const char *fieldName,
25 size_t nbElmnt) {
26 arr->SetName(fieldName);
27 arr->SetNumberOfComponents(1);
28 arr->SetNumberOfTuples(nbElmnt);
29
30#ifndef TTK_ENABLE_KAMIKAZE
31 if(!arr) {
32 Debug dbg{};
33 dbg.setDebugMsgPrefix("FTRGraph");
34 dbg.printErr("unable to allocate " + std::string{fieldName}
35 + " the program will likely crash");
36 }
37#endif
38 }
39 };
40
41 struct NodeData : public ObjectData {
42 vtkNew<vtkIntArray> ids{};
43 vtkNew<vtkIntArray> types{};
44 vtkNew<vtkDoubleArray> scalars{};
45
46 explicit NodeData(const ttk::ftr::idVertex nbNodes) {
47 allocArray(ids, "VertexId", nbNodes);
48 allocArray(types, "CriticalType", nbNodes);
49 allocArray(scalars, "Scalar", nbNodes);
50 }
51
52 void addNode(const ttk::ftr::Graph &graph,
53 const ttk::ftr::idNode n,
54 const double scalar) {
55 ids->SetTuple1(n, graph.getNode(n).getVertexIdentifier());
56 types->SetTuple1(n, (double)graph.getNode(n).getType());
57 scalars->SetTuple1(n, scalar);
58 }
59
60 void addArrays(vtkPointData *pointData,
62 pointData->AddArray(ids);
63 pointData->SetScalars(types);
64 pointData->AddArray(scalars);
65 }
66 };
67
68 struct ArcData : public ObjectData {
69 vtkNew<vtkIntArray> ids{};
70 vtkNew<vtkCharArray> reg{};
71#ifndef NDEBUG
72 vtkNew<vtkUnsignedCharArray> fromUp{};
73#endif
74 std::map<ttk::ftr::idVertex, vtkIdType> points;
75
77 allocArray(ids, "ArcId", nbArcs);
79#ifndef NDEBUG
80 allocArray(fromUp, "growUp", nbArcs);
81#endif
82 }
83
86 const vtkIdType skeletonVert,
87 bool r = false) {
88 reg->SetTuple1(skeletonVert, r);
89 }
90
91 void setArcInfo(const ttk::ftr::Graph &graph,
93 const vtkIdType skeletonCell) {
94 ids->SetTuple1(skeletonCell, a);
95#ifndef NDEBUG
96 fromUp->SetTuple1(skeletonCell, graph.getArc(a).getFromUp());
97#else
98 TTK_FORCE_USE(graph);
99#endif
100 }
101
102 void addArrays(vtkUnstructuredGrid *arcs,
104 // original size may be too large
105 ids->SetNumberOfTuples(arcs->GetNumberOfCells());
106 arcs->GetCellData()->SetScalars(ids);
107 reg->SetNumberOfTuples(arcs->GetNumberOfPoints());
108 arcs->GetPointData()->AddArray(reg);
109#ifndef NDEBUG
110 fromUp->SetNumberOfTuples(arcs->GetNumberOfCells());
111 arcs->GetCellData()->AddArray(fromUp);
112#endif
113 }
114 };
115
116 struct VertData : public ObjectData {
117 vtkNew<vtkIntArray> ids{};
118 vtkNew<vtkIntArray> regionType{};
119#ifdef TTK_ENABLE_FTR_VERT_STATS
120 vtkNew<vtkIntArray> touch{};
121 vtkNew<vtkIntArray> arcActif{};
122 vtkNew<vtkIntArray> taskActif{};
123#endif
124
125 explicit VertData(const ttk::ftr::idVertex nbVertices) {
126 allocArray(ids, "ArcId", nbVertices);
127 allocArray(regionType, "RegionType", nbVertices);
128#ifdef TTK_ENABLE_FTR_VERT_STATS
129 allocArray(touch, "Visit", nbVertices);
130 allocArray(arcActif, "Arc active", nbVertices);
131#endif
132 }
133
135 const ttk::ftr::idVertex v) {
136
137 if(!graph.isVisited(v)) {
138 // Problem, we should have visited all vertices
139 // return to avoid crash
140 return;
141 }
142
143 const ttk::ftr::idSuperArc curArcId = graph.getArcId(v);
144 ids->SetTuple1(v, curArcId);
145
146 int const downNodeType
147 = (int)graph.getNode(graph.getArc(curArcId).getDownNodeId())
148 .getType();
149 regionType->SetTuple1(v, downNodeType);
150
151#ifdef TTK_ENABLE_FTR_VERT_STATS
152 touch->SetTuple1(v, graph.getNbTouch(v));
153 arcActif->SetTuple1(v, graph.getNbArcActive(v));
154#endif
155 }
156
157 void addArrays(vtkDataSet *segmentation,
159 segmentation->GetPointData()->AddArray(ids);
160 segmentation->GetPointData()->SetActiveScalars(ids->GetName());
161 segmentation->GetPointData()->AddArray(regionType);
162#ifdef TTK_ENABLE_FTR_VERT_STATS
163 segmentation->GetPointData()->AddArray(touch);
164 segmentation->GetPointData()->AddArray(arcActif);
165#endif
166 }
167 };
168 }; // namespace ftr
169}; // namespace ttk
#define TTK_FORCE_USE(x)
Force the compiler to use the function/method parameter.
Definition BaseClass.h:57
#define ttkNotUsed(x)
Mark function/method parameters that are not used in the function body at all.
Definition BaseClass.h:47
Minimalist debugging class.
Definition Debug.h:88
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
TTK FTRGraph graph skeleton.
Definition Graph.h:38
idSuperArc getArcId(const idVertex v) const
Definition Graph.h:214
const SuperArc & getArc(const idSuperArc id) const
Definition Graph.h:121
const Node & getNode(const idNode id) const
Definition Graph.h:113
bool isVisited(const idVertex v) const
Definition Graph.h:129
idVertex getVertexIdentifier() const
Definition FTRNode.h:34
ftr::NodeType getType() const
Definition FTRNode.h:42
idNode getDownNodeId() const
Definition FTRSuperArc.h:57
bool getFromUp() const
long unsigned int idSuperArc
SuperArc index in vect_superArcs_.
SimplexId idVertex
Vertex index in scalars_.
unsigned int idNode
Node index in vect_nodes_.
The Topology ToolKit.
const char MaskScalarFieldName[]
default name for mask scalar field
Definition DataTypes.h:32
vtkNew< vtkUnsignedCharArray > fromUp
std::map< ttk::ftr::idVertex, vtkIdType > points
ArcData(const ttk::ftr::idSuperArc nbArcs)
void setPointInfo(const ttk::ftr::Graph &ttkNotUsed(graph), const ttk::ftr::idSuperArc ttkNotUsed(a), const vtkIdType skeletonVert, bool r=false)
vtkNew< vtkIntArray > ids
void addArrays(vtkUnstructuredGrid *arcs, ttk::ftr::Params ttkNotUsed(params))
vtkNew< vtkCharArray > reg
void setArcInfo(const ttk::ftr::Graph &graph, const ttk::ftr::idSuperArc a, const vtkIdType skeletonCell)
void addNode(const ttk::ftr::Graph &graph, const ttk::ftr::idNode n, const double scalar)
vtkNew< vtkDoubleArray > scalars
vtkNew< vtkIntArray > ids
vtkNew< vtkIntArray > types
void addArrays(vtkPointData *pointData, ttk::ftr::Params ttkNotUsed(params))
NodeData(const ttk::ftr::idVertex nbNodes)
void allocArray(vtkDataArray *const arr, const char *fieldName, size_t nbElmnt)
vtkNew< vtkIntArray > regionType
vtkNew< vtkIntArray > ids
void setVertexInfo(const ttk::ftr::Graph &graph, const ttk::ftr::idVertex v)
VertData(const ttk::ftr::idVertex nbVertices)
void addArrays(vtkDataSet *segmentation, ttk::ftr::Params ttkNotUsed(params))