-
Notifications
You must be signed in to change notification settings - Fork 0
/
lineageTreeWriter.cxx
209 lines (181 loc) · 6.13 KB
/
lineageTreeWriter.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include <vtkSmartPointer.h>
#include <vtkGraphLayoutView.h>
#include <vtkMutableDirectedGraph.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkTree.h>
// points in the graph
#include <vtkPoints.h>
// information in the graph
#include <vtkDataSetAttributes.h>
#include <vtkStringArray.h>
#include <vtkFloatArray.h>
#include <vtkIntArray.h>
#include <vtkIdTypeArray.h>
#include <vtkDoubleArray.h>
// Write the tree
#include <vtkTreeWriter.h>
// vtkQT tree view
#include <QApplication>
#include <vtkQtTreeView.h>
int main (int argc, char *argv[])
{
//////////////////////////////////////////////////
// REQUIERED FIELDS
vtkSmartPointer<vtkMutableDirectedGraph> graph =
vtkSmartPointer<vtkMutableDirectedGraph>::New();
vtkIdType a = graph->AddVertex();
vtkIdType b = graph->AddChild(a);
vtkIdType c = graph->AddChild(a);
vtkIdType d = graph->AddChild(b);
vtkIdType e = graph->AddChild(c);
vtkIdType f = graph->AddChild(c);
vtkIdType g = graph->AddChild(c);
vtkIdType h = graph->AddChild(f);
vtkIdType i = graph->AddChild(f);
// First array: first column of the graph
vtkSmartPointer<vtkStringArray> cellType =
vtkSmartPointer<vtkStringArray>::New();
cellType->SetName("name");
cellType->InsertValue(a, "TypeA");
cellType->InsertValue(b, "TypeB");
cellType->InsertValue(c, "TypeC");
cellType->InsertValue(d, "TypeD");
cellType->InsertValue(e, "TypeE");
cellType->InsertValue(f, "TypeF");
cellType->InsertValue(g, "TypeG");
cellType->InsertValue(h, "TypeH");
cellType->InsertValue(i, "TypeI");
graph->GetVertexData()->AddArray(cellType);
// i.e. trackFamilyID for us-> to collapse a part of the tree
vtkSmartPointer<vtkIdTypeArray> pedigree =
vtkSmartPointer<vtkIdTypeArray>::New();
pedigree->SetName("PedigreeVertexId");
pedigree->InsertValue(a, 0); // has to start at 0!
pedigree->InsertValue(b, 1);
pedigree->InsertValue(c, 2);
pedigree->InsertValue(d, 3);
pedigree->InsertValue(e, 4);
pedigree->InsertValue(f, 5);
pedigree->InsertValue(g, 6);
pedigree->InsertValue(h, 7);
pedigree->InsertValue(i, 8);
graph->GetVertexData()->AddArray(pedigree);
////////////////////////////////////////////////
// ADDITIONAL FIELDS
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(0.0, 0.5, 0.0);
points->InsertNextPoint(1.0, 0.0, 0.0);
points->InsertNextPoint(0.0, 1.0, 0.0);
points->InsertNextPoint(0.0, 0.0, 2.0);
points->InsertNextPoint(0.0, 1.0, 2.0);
points->InsertNextPoint(1.0, 0.0, 2.0);
points->InsertNextPoint(1.0, 3.0, 2.0);
points->InsertNextPoint(1.0, 2.0, 5.0);
points->InsertNextPoint(3.0, 1.0, 2.0);
graph->SetPoints(points);
vtkSmartPointer<vtkFloatArray> size =
vtkSmartPointer<vtkFloatArray>::New();
size->SetName("size");
size->InsertValue(a, 1);
size->InsertValue(b, 2);
size->InsertValue(c, 3);
size->InsertValue(d, 4);
size->InsertValue(e, 5);
size->InsertValue(f, 6);
size->InsertValue(g, 7);
size->InsertValue(h, 8);
size->InsertValue(i, 9);
graph->GetVertexData()->AddArray(size);
vtkSmartPointer<vtkIntArray> gfps =
vtkSmartPointer<vtkIntArray>::New();
gfps->SetName("GPFs");
gfps->InsertValue(a, 1000);
gfps->InsertValue(b, 2000);
gfps->InsertValue(c, 3000);
gfps->InsertValue(d, 4000);
gfps->InsertValue(e, 5000);
gfps->InsertValue(f, 6000);
gfps->InsertValue(g, 7000);
gfps->InsertValue(h, 8000);
gfps->InsertValue(i, 9000);
graph->GetVertexData()->AddArray(gfps);
vtkSmartPointer<vtkDoubleArray> start =
vtkSmartPointer<vtkDoubleArray>::New();
start->SetName("StartTime");
start->InsertValue(a, 0);
start->InsertValue(b, 12);
start->InsertValue(c, 13);
start->InsertValue(d, 20);
start->InsertValue(e, 20);
start->InsertValue(f, 21);
start->InsertValue(g, 22);
start->InsertValue(h, 30);
start->InsertValue(i, 31);
graph->GetVertexData()->AddArray(start);
vtkSmartPointer<vtkDoubleArray> end =
vtkSmartPointer<vtkDoubleArray>::New();
end->SetName("EndTime");
end->InsertValue(a, 10);
end->InsertValue(b, 15);
end->InsertValue(c, 16);
end->InsertValue(d, 25);
end->InsertValue(e, 27);
end->InsertValue(f, 28);
end->InsertValue(g, 30);
end->InsertValue(h, 43);
end->InsertValue(i, 37);
graph->GetVertexData()->AddArray(end);
vtkSmartPointer<vtkDoubleArray> length =
vtkSmartPointer<vtkDoubleArray>::New();
length->SetName("Length");
length->InsertValue(a, 10);
length->InsertValue(b, 15);
length->InsertValue(c, 16);
length->InsertValue(d, 25);
length->InsertValue(e, 27);
length->InsertValue(f, 28);
length->InsertValue(g, 30);
length->InsertValue(h, 12);
length->InsertValue(i, 11);
graph->GetVertexData()->AddArray(length);
vtkSmartPointer<vtkDoubleArray> xPos =
vtkSmartPointer<vtkDoubleArray>::New();
xPos->SetName("XPos");
xPos->InsertValue(a, 113);
xPos->InsertValue(b, 51);
xPos->InsertValue(c, 21);
xPos->InsertValue(d, 1);
xPos->InsertValue(e, 51);
xPos->InsertValue(f, 5);
xPos->InsertValue(g, 7);
xPos->InsertValue(h, 116);
xPos->InsertValue(i, 219);
graph->GetVertexData()->AddArray(xPos);
//graph->GetVertexData()->SetActiveScalars("XPos");
//graph->GetVertexData()->SetActiveScalars("XPos");
vtkSmartPointer<vtkTree> tree =
vtkSmartPointer<vtkTree>::New();
tree->ShallowCopy(graph);
vtkSmartPointer<vtkGraphLayoutView> treeLayoutView =
vtkSmartPointer<vtkGraphLayoutView>::New();
treeLayoutView->AddRepresentationFromInput(tree);
treeLayoutView->SetLayoutStrategyToTree();
treeLayoutView->ResetCamera();
treeLayoutView->Render();
treeLayoutView->GetInteractor()->Start();
// Write Tree
vtkSmartPointer<vtkTreeWriter> writer = vtkSmartPointer<vtkTreeWriter>::New();
writer->SetInput(tree);
writer->SetFileName("lineageTree.vtk");
writer->Write();
// QT Application
// vtkQT tree view
QApplication app(argc, argv);
QCoreApplication::setOrganizationName("MegasonLab");
QCoreApplication::setOrganizationDomain("http://gofigure2.sourceforge.net");
vtkSmartPointer<vtkQtTreeView> qtTreeView =
vtkSmartPointer<vtkQtTreeView>::New();
qtTreeView->AddRepresentationFromInput(tree);
return EXIT_SUCCESS;
}