-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGeometryScene.cpp
executable file
·1355 lines (1151 loc) · 57.8 KB
/
GeometryScene.cpp
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <QtDebug>
#include <QFileDialog>
#include <QFile>
#include "GeometryScene.h"
#include "GeometryNode.h"
#include <stdio.h> //FILE, fopen(), fclose()
#include <stdlib.h>
#include <sys/stat.h> //stat, stat()
#include <string> //string
#include <fstream> //fstream
#include <iostream> //cout
// #include "hdf5.h" //C API
#include "H5Cpp.h" //C++ API
#include "H5File.h"
// #include "H5Gloc.h"
#include "math.h"
#include <QVector>
#include "Inventor/details/SoFaceDetail.h"
#include "Inventor/details/SoPointDetail.h"
#include <Inventor/details/SoLineDetail.h>
#include <Inventor/details/SoCylinderDetail.h>
#include "Inventor/nodes/SoDirectionalLight.h"
// using namespace H5;
// forward declaration
SoSeparator* bic_graphics_file_to_iv( const char* filename );
GeometryScene::GeometryScene(const QVector<QVariant> &data,
ResourceForm *rf, TreeItem *parent)
: TreeItem(data, rf, parent){
setData(0, "Geometry Scene");
scene = new SoSeparator();
// light
//scene->addChild(new SoDirectionalLight);
geometry = new GeometryNode(scene, data, rf, this);
childItems.insert(childCount(), geometry);
this->rf = rf;
this->data = data;
flag_new_edge = FALSE;
num_clicked = 0;
connectingVect.resize(0);
}
//delete the edge from the lists and the viewer
void GeometryScene::deleteThisEdge(){
//qDebug() << "\nGeometryScene::deleteThisEdge() "<< num_edge_total;
//qDebug() << "NodeId " << nodeId <<"="<< nodeIDs[e_num][0]<< " Vessel segment number " << e_num << " is edge ("<< edgesVect[2*e_num] << "," << edgesVect[2*e_num+1] << ") with label# " << labelVect[e_num] << " : " << label_num2Name(labelVect[e_num])<< " will be deleted!";
/*
for (int i=0; i<num_edge_total; i++){
std::cout <<"\n"<< i << ": " << std::flush;
for (int j=0; j<childIDs[i].size(); j++){
std::cout<< j << "("<< childIDs[i][j] << ")" << nodeIDs[i][j] <<"="<< root->getChild(childIDs[i][j])->getNodeId() << " " << std::flush;
}
}
*/
rf->uilabel.DeleteEdge->setEnabled ( FALSE );
rf->uilabel.label->setEnabled ( FALSE );
rf->uilabel.LabelVessel->setEnabled ( FALSE );
//r u sure u want to delete this edge?
QString response = QString("Are you sure you want to delete selected vessel segment?");
int answer = QMessageBox::question(0, "Delete vessel?", response, QMessageBox::Yes | QMessageBox::No);
if (answer == QMessageBox::Yes){
//delete edge
//qDebug() << "root children : " << root->getNumChildren() ;
int childid = childIDs[e_num][0];
for (int i=0; i<childIDs[e_num].size(); i++){
root->removeChild(childid);
}
for (int i=e_num+1; i<childIDs.size(); i++){
for (int j=0; j< childIDs[i].size(); j++){
childIDs[i][j]-=childIDs[e_num].size();
}
}
/*
nodeIDs.remove(e_num);
childIDs.remove(e_num);
labelVect.remove(e_num);
edgesVect.remove(2*e_num+1);
edgesVect.remove(2*e_num);
cylmatVect.remove(e_num);
cylradiusVect.remove(e_num);
for (int i=0; i<cylnum_transparency0_5.size(); i++){
if (cylnum_transparency0_5[i] == e_num){
cylnum_transparency0_5.remove(i);
}
if (cylnum_transparency0_5[i] > e_num){
cylnum_transparency0_5[i]--;
}
}
*/
/*
SoChildList * childrenlist = root->getChildren();
for (int i=0; i<root->getNumChildren(); i++){
if (childrenlist[i]->getNodeId() == nodeId){
qDebug() << "found child : " << root->findChild(childrenlist[i]) ;
}
}
geometry->updateCylTransparency(cylmatVect[e_num].size(), cylmatVect[e_num], .8);
qDebug() << "root children : " << root->getNumChildren();
rf->somethingChanged();
*/
num_edge_total--;
del_edgesVect.append(e_num);
//if ( verboseAction->isChecked() )
rf->emitVerboseSignal();
if (rf->getVerboseStatus())
qDebug() << /*"NodeId " << nodeId <<"="<< nodeIDs[e_num][0]<< " Vessel segment number " << e_num << " is*/ "edge ("<< edgesVect[2*e_num] << "," << edgesVect[2*e_num+1] << ") with label #" << labelVect[e_num] << " : " << label_num2Name(labelVect[e_num]) << " and diameter "<< diamVect[e_num]<< " is deleted!\n";
}
//qDebug() << "\nGeometryScene::deleteThisEdge() "<< num_edge_total;
}
//start making the new edge by preparing the vector and wait for 2 edges to be clicked on
void GeometryScene::createNewEdge(){
rf->uilabel.Saveh5->setEnabled ( FALSE );
rf->uilabel.Saveash5->setEnabled ( FALSE );
rf->uilabel.DeleteEdge->setEnabled ( FALSE );
rf->uilabel.AddEdge->setEnabled ( FALSE );
rf->uilabel.label->setEnabled ( FALSE );
rf->uilabel.LabelVessel->setEnabled ( FALSE );
flag_new_edge = TRUE;
num_clicked = 0;
connectingVect.resize(0);
}
bool GeometryScene::edgeExists(int vertx0,int vertx1,QVector <int> Vect){
bool return_val = FALSE;
for (int i=0; i < Vect.size()-1; i++){
if (Vect[i]==vertx0 && Vect[i+1]==vertx1){
return_val=TRUE;
break;
}
}
return return_val;
}
//once the 2 edges to be connected are clicked, add the new edge to lists and the viewer
void GeometryScene::addNewEdge(){
///{add to edgesVect,and add corresponding to label and nodeId (when showing it) and calc cyl_stuff and show! and activate Saveh5, in Saveh5:save edgesVect too}
rf->uilabel.Saveh5->setEnabled ( TRUE );
rf->uilabel.Saveash5->setEnabled ( TRUE );
rf->uilabel.AddEdge->setEnabled ( TRUE );
rf->uilabel.DeleteEdge->setEnabled ( FALSE );
rf->uilabel.label->setEnabled ( FALSE );
rf->uilabel.LabelVessel->setEnabled ( FALSE );
if (connectingVect.size()!=2){
qDebug() <<"ERROR: the number of vertices in the new edge is " << connectingVect.size() << "\nAborted!";
exit(0);
}
//sort the edge (v0,v1) so that v0<v1
if (connectingVect[1]<connectingVect[0]){
int tmpval=connectingVect[1];
connectingVect[1]=connectingVect[0];
connectingVect[0]=tmpval;
}
if (!edgeExists(connectingVect[0],connectingVect[1],edgesVect)){
//if ( verboseAction->isChecked() )
rf->emitVerboseSignal();
if (rf->getVerboseStatus())
qDebug() << "New edge ("<<connectingVect[0] << "," << connectingVect[1]<< ") is added!\n";
edgesVect.append(connectingVect[0]);
edgesVect.append(connectingVect[1]);
new_edgesVect.append(connectingVect[0]);
new_edgesVect.append(connectingVect[1]);
labelVect.append(int(0));
//qDebug() << "labelVect.size() "<< labelVect.size() ;
num_edge_total++;
float a1 = vertices_centreVect[3*connectingVect[0]]; float b1 = vertices_centreVect[3*connectingVect[0]+1]; float c1 = vertices_centreVect[3*connectingVect[0]+2];
float a2 = vertices_centreVect[3*connectingVect[1]]; float b2 = vertices_centreVect[3*connectingVect[1]+1]; float c2 = vertices_centreVect[3*connectingVect[1]+2];
//qDebug() << "edge (" << connectingVect[0] << ","<< connectingVect[1] <<") has vertices' centres at [" << a1 << " " << b1 << " " << c1 << "] and [" << a2 << " " << b2 << " " << c2 << "]";
float centreX = (a1+a2)/2; float centreY = (b1+b2)/2; float centreZ = (c1+c2)/2;
float heights = sqrt((a2-a1)*(a2-a1)+(b2-b1)*(b2-b1)+(c2-c1)*(c2-c1));
float tangentX = (a2-a1)/heights; float tangentY = (b2-b1)/heights; float tangentZ = (c2-c1)/heights;
float newedge_rad=0;
for (int c=0; c<cylradiusVect[edge1_indx].size(); c++){
newedge_rad += cylradiusVect[edge1_indx][c];
}
for (int c=0; c<cylradiusVect[edge2_indx].size(); c++){
newedge_rad += cylradiusVect[edge2_indx][c];
}
newedge_rad = newedge_rad/(cylradiusVect[edge1_indx].size() + cylradiusVect[edge2_indx].size());
diamVect.append(2*newedge_rad);
// /*hvl_ti* new_*/nodeIDs = (hvl_ti2*) realloc (nodeIDs, (int)(num_edge_total)*sizeof(hvl_ti2));
// nodeIDs[num_edge_total-1].len = 1;
// nodeIDs[num_edge_total-1].p = (int*) calloc((unsigned long)(nodeIDs[num_edge_total-1].len), sizeof(int) );
// nodeIDs[num_edge_total-1].q = (int*) calloc((unsigned long)(nodeIDs[num_edge_total-1].len), sizeof(int) );
//QVector <SoMaterial *> tmp_cylmatVect;
// /*hvl_t* new_*/cylradiusVect = (hvl_t*) realloc(cylradiusVect,(int)(num_edge_total)*sizeof(hvl_t) );
//cylradiusVect[num_edge_total-1].len = 1;
//cylradiusVect[num_edge_total-1].p = (float*) calloc((unsigned long)(cylradiusVect[num_edge_total-1].len), sizeof(float) );
scene = new SoSeparator(); //create one node for each cylinder and show them into Scene Graph
geometry = new GeometryNode(scene, data, rf, this);
childItems.insert(childCount(), geometry);
//this->rf = rf;
root->addChild(scene);
GeometryNode::load_Cylinder_output_type output_loadCylinder;
QFile new_edge_name("additional_edge");
output_loadCylinder = geometry->loadCylinder(new_edge_name,centreX,centreY,centreZ,newedge_rad,tangentX,tangentY,tangentZ,heights,0);
tmp_cylmatVect.append(output_loadCylinder.nodematerial);
tmp_nodeid.append(output_loadCylinder.nodeid);
tmp_childid.append(root->getNumChildren()-1); //so that number of children-1 becomes the children indeces
cylmatVect.append(tmp_cylmatVect);
tmp_cylradiusVect.append(output_loadCylinder.noderadius);
cylradiusVect.append(tmp_cylradiusVect);
// cylradiusVect[num_edge_total-1].p[0] = output_loadCylinder.noderadius;
// nodeIDs[num_edge_total-1].p[0]= output_loadCylinder.nodeid;
// nodeIDs[num_edge_total-1].q[0]= root->getNumChildren()-1;
nodeIDs.append(tmp_nodeid);
childIDs.append(tmp_childid);
new_radius.append(newedge_rad);
new_heights.append(heights);
new_cntrx.append(centreX); new_cntry.append(centreY); new_cntrz.append(centreZ);
new_tangx.append(tangentX); new_tangy.append(tangentY); new_tangz.append(tangentZ);
tmp_cylmatVect.resize(0); tmp_cylradiusVect.resize(0); tmp_nodeid.resize(0); tmp_childid.resize(0);
}
else{
qDebug() << "New edge ("<<connectingVect[0] << "," << connectingVect[1]<< ") already exists!";
}
num_clicked = 0;
connectingVect.resize(0);
}
bool GeometryScene::loadGeometry(QFile &file, const QVector<QVariant> &data,
ResourceForm *rf, TreeItem *parent){
root = viewer->getRootSeparator();
QFileInfo fileInfo(file);
QString ext = fileInfo.suffix();
if (ext == "h5") {
////read the h5 file and pass the radius and tangent height and center of vetex v
struct h5_output_type h5_output_data = H5_reader ((char*)file.fileName().toLatin1().data());
//qDebug() << "Successfully read the h5 file " << file.fileName().toLatin1().data() << "!" ;
num_edge_total = h5_output_data.num_edge;
for (int i =0; i < num_edge_total; i++)
{
labelVect.append(h5_output_data.label[i]);
float thisedge_rad=0;
for (int c=0; c<h5_output_data.radius[i].len; c++){
thisedge_rad += h5_output_data.radius[i].p[c];
}
thisedge_rad = thisedge_rad/(h5_output_data.radius[i].len );
diamVect.append(2*thisedge_rad);
edgesVect.append(h5_output_data.edges[2*i]);
edgesVect.append(h5_output_data.edges[2*i+1]);
}
for (int i =0; i < h5_output_data.num_vertex; i++)
{
vertices_centreVect.append(h5_output_data.vertices[3*i]);
vertices_centreVect.append(h5_output_data.vertices[3*i+1]);
vertices_centreVect.append(h5_output_data.vertices[3*i+2]);
}
//qDebug() << "Size of edges " << num_edge_total ;
////save unique cylinder NodeId in order of cylinder numbers from GeometryNode::loadCylinder in here
// /*hvl_ti **/nodeIDs = (hvl_ti2*) malloc((int)(num_edge_total)*sizeof(hvl_ti2) );
//cylmatVect = (hvl_tSoMat*) malloc((int)(num_edge_total)*sizeof(hvl_tSoMat) );
//cylradiusVect = (hvl_t*) malloc((int)(num_edge_total)*sizeof(hvl_t) );
GeometryNode::load_Cylinder_output_type output_loadCylinder;
for( int e = 0; e < num_edge_total; e++ ) {
//nodeIDs[e].len = h5_output_data.centreX[e].len;
//nodeIDs[e].p = (int*) malloc((unsigned long)(nodeIDs[e].len)*sizeof(int) );
//nodeIDs[e].q = (int*) malloc((unsigned long)(nodeIDs[e].len)*sizeof(int) );
//cylmatVect[e].len = h5_output_data.centreX[e].len;
//(cylmatVect[e].p).resize(cylmatVect[e].len);
//cylradiusVect[e].len = h5_output_data.centreX[e].len;
//cylradiusVect[e].p = (float*) calloc((unsigned long)(cylradiusVect[e].len),sizeof(float) );
for (int c =0; c < h5_output_data.centreX[e].len ; c++){
scene = new SoSeparator(); //create one node for each cylinder and show them into Scene Graph
//scene->addChild(new SoDirectionalLight); // light
geometry = new GeometryNode(scene, data, rf, this);
childItems.insert(childCount(), geometry);
//this->rf = rf;
root->addChild(scene);
output_loadCylinder = geometry->loadCylinder(file,h5_output_data.centreX[e].p[c],h5_output_data.centreY[e].p[c],h5_output_data.centreZ[e].p[c],h5_output_data.radius[e].p[c],h5_output_data.tangentX[e].p[c],h5_output_data.tangentY[e].p[c],h5_output_data.tangentZ[e].p[c],1.1*h5_output_data.heights[e].p[c],h5_output_data.label[e]);
tmp_nodeid.append(output_loadCylinder.nodeid);
tmp_childid.append(root->getNumChildren()-1);
//nodeIDs[e].p[c]= output_loadCylinder.nodeid;
//nodeIDs[e].q[c]= root->getNumChildren()-1;
//qDebug() << "parent num children : " << root->getNumChildren() ;
//cylmatVect[e].p[c]= output_loadCylinder.nodematerial;
tmp_cylmatVect.append(output_loadCylinder.nodematerial);
tmp_cylradiusVect.append(output_loadCylinder.noderadius);
//cylradiusVect[e].p[c]= output_loadCylinder.noderadius;
}
cylmatVect.append(tmp_cylmatVect);
cylradiusVect.append(tmp_cylradiusVect);
nodeIDs.append(tmp_nodeid);
childIDs.append(tmp_childid);
tmp_cylmatVect.resize(0); tmp_cylradiusVect.resize(0); tmp_nodeid.resize(0); tmp_childid.resize(0);
}
free (h5_output_data.centreX); free (h5_output_data.centreY); free (h5_output_data.centreZ);
free (h5_output_data.tangentX); free (h5_output_data.tangentY); free (h5_output_data.tangentZ);
free (h5_output_data.radius); free (h5_output_data.heights); free (h5_output_data.label);
free (h5_output_data.edges); free (h5_output_data.vertices);
radiusCalc(cylradiusVect);
//if ( verboseAction->isChecked() )
rf->emitVerboseSignal();
if (rf->getVerboseStatus())
qDebug() << "min and max radius: "<<radiusmin << ", " << radiusmax ;
////create the labeling and radius widget
createLabelForm();
h5_filename=file.fileName(); //QString type
}
if (ext == "obj") {
VIO_File_formats format;
int num_objects;
object_struct** object_list;
// FIXME: fix bicpl for constness on these damn strings!!!
if ( input_graphics_file( (char*)file.fileName().toLatin1().data(), &format, &num_objects, &object_list ) != VIO_OK ) {
return false;
}
if (num_objects > 1) {
//if ( verboseAction->isChecked() )
rf->emitVerboseSignal();
if (rf->getVerboseStatus())
qDebug() << "number of objects is: " << num_objects ;
}
for ( int i = 0; i < num_objects; ++i ) {
scene = new SoSeparator();
geometry = new GeometryNode(scene, data, rf, this);
childItems.insert(childCount(), geometry);
this->rf = rf;
root->addChild(scene);
bool status = geometry->loadObj(file,i);
Q_ASSERT_X(status == true, "GeometryScene::loadGeometry", "loadObj returned False");
//qDebug() << "Debug: << geometry->loadObj #" <<i <<" status = " << status;
}
}
return true;
}
void GeometryScene::createLabelForm() {
this->rf = rf;
connect(rf->uilabel.radiusSlider, SIGNAL(valueChanged(int)),
this, SLOT(updateRadiusTransparency(int)));
connect(rf->uilabel.LabelVessel, SIGNAL(activated( int )),
this, SLOT(getUserLabel()));
connect(rf->uilabel.Saveh5, SIGNAL(clicked()),
this, SLOT(saveLabel()));
connect(rf->uilabel.Saveash5, SIGNAL(clicked()),
this, SLOT(saveasLabel()));
connect(rf->uilabel.DeleteEdge, SIGNAL(clicked()),
this, SLOT(deleteThisEdge()));
connect(rf->uilabel.AddEdge, SIGNAL(clicked()),
this, SLOT(createNewEdge()));
/* connect(this, SIGNAL(createEdgeSignal()),
this, SLOT(addNewEdge()));*/
rf->uilabel.DeleteEdge->setEnabled ( FALSE );
rf->uilabel.AddEdge->setEnabled ( TRUE );
rf->uilabel.label->setEnabled ( FALSE );
rf->uilabel.LabelVessel->setEnabled ( FALSE );
rf->uilabel.Saveh5->setEnabled ( TRUE );
rf->uilabel.Saveash5->setEnabled ( TRUE );
rf->uilabel.radiusSlider->setEnabled ( TRUE );
rf->uilabel.radius->setEnabled ( TRUE );
}
void GeometryScene::saveasLabel(){
QString slname = QFileDialog::getSaveFileName(0,
tr("Save h5 to File"), QString(), tr("Files (*.h5)"));
if (! slname.isNull()) {
QFile slfile(slname);
QFileInfo fileInfo(slfile);
QString abspath = fileInfo.absoluteFilePath();
//qDebug() << "construct a new file " + slfile.fileName() ;
QFile currfile(h5_filename);
QFileInfo currfileInfo(currfile);
QString currabspath = currfileInfo.absoluteFilePath();
//qDebug() << "old " << currabspath.toLatin1().data() <<" new " << abspath.toLatin1().data() << " compare " << currabspath.compare( abspath);
if ((int)currabspath.compare(abspath) != 0){ //if file specified in saveas is not the same as the file originally opened
saveh5FileFunc(slfile);
}
else {
saveLabel();
}
}
}
void GeometryScene::saveh5FileFunc(QFile &newfile){
if (QFile::exists(newfile.fileName())){
bool status2 = QFile::remove (newfile.fileName());
//qDebug() << "\nGeometryScene::saveh5FileFunc() remove existing file " + newfile.fileName()+ " " +status2 ;
}
// copy h5_filename to filename and replace the name of h5_filename, then call saveLabel
/*QFile currentfile;
currentfile.setFileName(h5_filename);
*/QFile newfile2;
newfile2.setFileName(newfile.fileName());
if(!QFile::copy ( h5_filename,newfile2.fileName() ))
// if(!QFile::copy(filename.fileName(), h5_filename))
//if(!file.copy(newfile))
{
qDebug() << "\n File copy failed .. " + h5_filename + " to " + newfile2.fileName() + " Error : " + newfile2.errorString();
}
else{
//qDebug() << "\n File copied .. " + h5_filename + " to " + newfile2.fileName();
h5_filename = newfile2.fileName();
saveLabel();
}
}
void GeometryScene::saveLabel(){
QFile tmpfile( "tmp.h5"); ///there is a random unresolved error where sometimes this function fails with Segmentation Fault,so we save the current changes in a tmp file for now until this bug is fixed, so that your most recent changes won't get lost
if (QFile::exists(tmpfile.fileName())){QFile::remove(tmpfile.fileName());}
QFile::copy(h5_filename,tmpfile.fileName() );
//qDebug() <<del_edgesVect.size() << " "<<del_edgesVect ;
qSort (del_edgesVect);
//qDebug() <<del_edgesVect.size() << " "<<del_edgesVect ;
for (int i=del_edgesVect.size()-1; i>-1;i--){
int tmp_e_num=del_edgesVect[i];
//qDebug() << "e_num deleted:" << tmp_e_num;
nodeIDs.remove(tmp_e_num);
childIDs.remove(tmp_e_num);
labelVect.remove(tmp_e_num);
diamVect.remove(tmp_e_num);
edgesVect.remove(2*tmp_e_num+1);
edgesVect.remove(2*tmp_e_num);
cylmatVect.remove(tmp_e_num);
cylradiusVect.remove(tmp_e_num);
//qDebug() << "e_num deleted2:" << tmp_e_num;
for (int i=0; i<cylnum_transparency0_5.size(); i++){
if (cylnum_transparency0_5[i] == tmp_e_num){
cylnum_transparency0_5.remove(i);
}
}
}
for (int i=del_edgesVect.size()-1; i>-1;i--){
int tmp_e_num=del_edgesVect[i];
for (int i=0; i<cylnum_transparency0_5.size(); i++){
if (cylnum_transparency0_5[i] > tmp_e_num){
cylnum_transparency0_5[i]--;
}
}
}
if (labelVect.size()!= (edgesVect.size()/2)){
qDebug() <<"ERROR: Numbe of new edges added to the label and edges are not equal!\nAborted!!";
return;
}
if ( (new_radius.size()!=(new_edgesVect.size()/2)) || (new_radius.size()!=new_heights.size()) || (new_radius.size()!=new_cntrx.size()) || (new_radius.size()!=new_cntry.size()) || (new_radius.size()!=new_cntrz.size()) || (new_radius.size()!=new_tangx.size()) || (new_radius.size()!=new_tangy.size()) || (new_radius.size()!=new_tangz.size())){
qDebug() <<"ERROR: Numbe of new edges added to the new_radius and edges are not equal!\nAborted!!";
return;
}
//qDebug() << new_edgesVect.size()/2 << " " <<new_radius.size() << " " <<new_heights.size()<< " " <<new_cntrx.size()<< " " <<new_tangx.size()<<" new edges have been created";
//qDebug() << edgesVect.size()/2 << " total number of edges="<< num_edge_total;
///since the dataset is not chunked extend function will not work for it. C++ API does not have the dataset delete function => we use C API
int *Label_buf = (int*) malloc( sizeof(int) * labelVect.size() );
for (int i=0; i<labelVect.size(); i++){
Label_buf[i]=labelVect[i];
}
hid_t file_id, group_id, dataset, dataspace, hdf_plist;
herr_t status;
int rank = 2;
hsize_t dims[2]; dims[0] = labelVect.size(); dims[1] = 1;
file_id = H5Fopen(h5_filename.toLatin1().data(), H5F_ACC_RDWR, H5P_DEFAULT);
///write the labels to the graph
group_id = H5Gopen (file_id, "/vessel_graph/edge_properties", H5P_DEFAULT);
status = H5Ldelete (group_id, "cyl_label", H5P_DEFAULT);
dataspace = H5Screate_simple(rank, dims, NULL);
dataset = H5Dcreate2(group_id, "cyl_label", H5T_NATIVE_INT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, Label_buf);
status = H5Dclose(dataset);
status = H5Gclose (group_id);
status = H5Fclose (file_id);
free(Label_buf);
if (new_edgesVect.size()>0 or del_edgesVect.size()>0){
int num_new_e = new_edgesVect.size()/2;
file_id = H5Fopen(h5_filename.toLatin1().data(), H5F_ACC_RDWR, H5P_DEFAULT);
int status_n;
///write the edges to the graph
int *edge_buf = (int*) malloc( sizeof(int) * edgesVect.size() );
for (int i=0; i<edgesVect.size(); i++){
edge_buf[i]=edgesVect[i];
}
dims[0] = labelVect.size(); dims[1] = 2;
group_id = H5Gopen (file_id, "/vessel_graph", H5P_DEFAULT);
status = H5Ldelete (group_id, "edges", H5P_DEFAULT);
dataspace = H5Screate_simple(rank, dims, NULL);
dataset = H5Dcreate2(group_id, "edges", H5T_NATIVE_INT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, edge_buf);
status = H5Dclose(dataset);
status = H5Gclose (group_id);
status = H5Fclose (file_id);
free(edge_buf);
/*//write new_edges
int *new_edge_buf = (int*) malloc( sizeof(int) * new_edgesVect.size() );
for (int i=0; i<new_edgesVect.size(); i++){
new_edge_buf[i]=new_edgesVect[i];
}
dims[0] = new_edgesVect.size()/2; dims[1] = 2;
status = H5Lexists(group_id,"new_edges", H5P_DEFAULT);
if (!status){ ///new_edges doesn't exist => create and write
dataspace = H5Screate_simple(rank, dims, NULL);
dataset = H5Dcreate2(group_id, "new_edges", H5T_NATIVE_INT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, new_edge_buf);
status= H5Dclose(dataset);
status = H5Gclose (group_id);
}
else { ///new_edges exist => read to buffer, resize buffer to write new edges, delete new_edges and write the new one!
dataset = H5Dopen2(group_id, "new_edges", H5P_DEFAULT);
dataspace = H5Dget_space(dataset); // dataspace handle
rank = H5Sget_simple_extent_ndims(dataspace);
status_n = H5Sget_simple_extent_dims(dataspace, dims, NULL);
qDebug() << "new_edges dataset rank " << rank << " dims[0][1] " << dims[0] << "," << dims[1];
int *new_edge_buf_i = (int*) malloc( sizeof(int) * dims[0]*dims[1] );
status = H5Dread(dataset, H5T_NATIVE_INT, dataspace, dataspace, H5P_DEFAULT, new_edge_buf_i);
qDebug() << "new_edges [0][1]" << new_edge_buf_i[0] << " " << new_edge_buf_i[1];
new_edge_buf_i = (int*) realloc (new_edge_buf_i, sizeof(int)*((unsigned long)(dims[0]*dims[1])+new_edgesVect.size()));
for (int i=0; i<new_edgesVect.size() ; i++){
new_edge_buf_i[i+(dims[0]*dims[1])] = new_edge_buf[i];
}
status= H5Dclose(dataset);
dims[0] += new_edgesVect.size()/2;
status = H5Ldelete (group_id, "new_edges", H5P_DEFAULT);
dataspace = H5Screate_simple(rank, dims, NULL);
dataset = H5Dcreate2(group_id, "new_edges", H5T_NATIVE_INT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, new_edge_buf_i);
status = H5Dclose(dataset);
status = H5Gclose (group_id);
free(new_edge_buf_i);
}
free(new_edge_buf);
*/
///write intermediaries
// rank = 1;
// hsize_t dims_cyl[1];
// hid_t datatype;
// file_id = H5Fopen(h5_filename.toLatin1().data(), H5F_ACC_RDWR, H5P_DEFAULT);
// group_id = H5Gopen (file_id, "/vessel_graph/edge_properties", H5P_DEFAULT);
//
// hid_t dataset_intm,dataspace_intm,datatype_intm;
// dataset_intm = H5Dopen2(group_id, "intermediaries", H5P_DEFAULT);
// dataspace_intm = H5Dget_space(dataset_intm); // dataspace handle
// rank = H5Sget_simple_extent_ndims(dataspace_intm);
// status_n = H5Sget_simple_extent_dims(dataspace_intm, dims_cyl, NULL);
// hvl_ti* new_buf_i_intm = (hvl_ti*) malloc( sizeof(hvl_ti) * (unsigned long)(dims_cyl[0]) );
// qDebug() << "intermediaries dataset rank " << rank << " dims_cyl[0] " << dims_cyl[0] << " intermediaries.size " << num_new_e ;
// datatype_intm = H5Dget_type(dataset_intm); // datatype handle
// status = H5Dread(dataset_intm, datatype_intm, dataspace_intm, dataspace_intm, H5P_DEFAULT, new_buf_i_intm);
// qDebug() << "intermediaries [0][1]" << new_buf_i_intm[0].p[0] << " " << new_buf_i_intm[1].p[0];
// new_buf_i_intm = (hvl_ti*) realloc (new_buf_i_intm, sizeof(hvl_ti) * (unsigned long)(dims_cyl[0]+num_new_e) );
// for (int i=0; i<num_new_e; i++){
// new_buf_i_intm[i+dims_cyl[0]].len =1;
// new_buf_i_intm[i+dims_cyl[0]].p = (int *) malloc( sizeof(int) );
// new_buf_i_intm[i+dims_cyl[0]].p[0]= -1; /// ??? what to do with the intermediaries of new edges to be empty => should add new_interm to be empty or in graph2graph if its -1 then put []
// }
// dims_cyl[0] += num_new_e;
// qDebug() << "dims_cyl[0]" << dims_cyl[0];
// if (del_edgesVect.size()>0){
// hsize_t del_dims_cyl[1]; del_dims_cyl[0] = num_edge_total; //if there is del_edgesVect
// qDebug() << "final dims_cyl[0]" << del_dims_cyl[0];
// for (int i=0; i<del_edgesVect.size(); i++){
// qDebug() << "i=" << i << " edge #"<< del_edgesVect[i];
// new_buf_i_intm[del_edgesVect[i]].len=0;
// }
// hvl_ti* new_buf_o_intm = (hvl_ti*) malloc(sizeof(hvl_ti) * (unsigned long)(del_dims_cyl[0]));
// int j =0;
// for (int i=0; i< dims_cyl[0]; i++){
// if (new_buf_i_intm[i].len!=0){
// new_buf_o_intm[j].len = new_buf_i_intm[i].len;
// new_buf_o_intm[j].p = (int *) malloc(sizeof(int)*new_buf_i_intm[i].len);
// for (int k=0; k<new_buf_i_intm[i].len; k++){
// new_buf_o_intm[j].p[k]=new_buf_i_intm[i].p[k];
// }
// j++;
// }
// }
// status = H5Dset_extent(dataset_intm, del_dims_cyl);
// status = H5Dwrite(dataset_intm, datatype_intm, H5S_ALL, H5S_ALL, H5P_DEFAULT, new_buf_o_intm);
// free(new_buf_o_intm);
// }
// //status = H5Dextend (dataset_cx, dims_cyl);
// /*//status = H5Ldelete (group_id, "cyl_centreX", H5P_DEFAULT);
// //dataspace_cx = H5Screate_simple(rank, dims_cyl, NULL);
// //dataset_cx = H5Dcreate2(group_id, "cyl_centreX", datatype_cx, dataspace_cx, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);*/
// else {
// status = H5Dextend (dataset_intm, dims_cyl);
// status = H5Dwrite(dataset_intm, datatype_intm, H5S_ALL, H5S_ALL, H5P_DEFAULT, new_buf_i_intm);
// }
// status = H5Dclose(dataset_intm);
// free(new_buf_i_intm);
// status = H5Gclose (group_id);
// status = H5Fclose (file_id);
//
///write cyl_properties
char* cyl_prop = "cyl_centreX";
writeCylProp2H5(cyl_prop,num_new_e, new_cntrx, del_edgesVect);
cyl_prop = "cyl_centreY";
writeCylProp2H5(cyl_prop,num_new_e, new_cntry, del_edgesVect);
cyl_prop = "cyl_centreZ";
writeCylProp2H5(cyl_prop,num_new_e, new_cntrz, del_edgesVect);
cyl_prop = "cyl_radius";
writeCylProp2H5(cyl_prop,num_new_e, new_radius, del_edgesVect);
cyl_prop = "cyl_height";
writeCylProp2H5(cyl_prop,num_new_e, new_heights, del_edgesVect);
cyl_prop = "cyl_tangentX";
writeCylProp2H5(cyl_prop,num_new_e, new_tangx, del_edgesVect);
cyl_prop = "cyl_tangentY";
writeCylProp2H5(cyl_prop,num_new_e, new_tangy, del_edgesVect);
cyl_prop = "cyl_tangentZ";
writeCylProp2H5(cyl_prop,num_new_e, new_tangz, del_edgesVect);
///empty the vectors of new edge properties after they were written into the file
new_radius.resize(0);
new_heights.resize(0);
new_cntrx.resize(0); new_cntry.resize(0); new_cntrz.resize(0);
new_tangx.resize(0); new_tangy.resize(0); new_tangz.resize(0);
new_edgesVect.resize(0);
del_edgesVect.resize(0);
}
/* ///with C++ API
H5::H5File Lh5file = H5::H5File();
Lh5file.openFile(h5_filename.toLatin1().data(), H5F_ACC_RDWR );
H5::Group edge_properties_group = Lh5file.openGroup("/vessel_graph/edge_properties");
qDebug()<< "opening label dataset to write the user label" ;
H5::DataSet dataset_label = edge_properties_group.openDataSet("label");
H5::DataSpace dataspace = dataset_label.getSpace(); //Get dataspace of the dataset.
hsize_t dims_out[1];// Get the dimension size of each dimension in the dataspace and display them.
int rank = dataspace.getSimpleExtentDims( dims_out, NULL);
// qDebug() << "/vessel_graph/edge_properties/label dims_out[0],[1]: " <<dims_out[0] << "," << dims_out[1]<< " , ndims = " << ndims <<" , rank = " << rank ;
if (labelVect.size()> dims_out[0])
{
dims_out[0] = labelVect.size();
}
// hsize_t maxdims[2] = {H5::H5S_UNLIMITED, H5::H5S_UNLIMITED};
H5::DataSpace fspace( rank, dims_out); // , maxdims //Create dataspace for the dataset in the file.
H5::DSetCreatPropList cparms;
hsize_t chunk_dims[2] ={1, 1};
cparms.setChunk( rank, chunk_dims );
int fill_val = 0;
cparms.setFillValue( H5::PredType::NATIVE_INT, &fill_val);
qDebug() << "cparms" ;
H5::DataSet* new_dataset_l = new H5::DataSet(edge_properties_group.createDataSet("new_label2", H5::PredType::NATIVE_INT, fspace,cparms)); //Create dataset and write it into the file.
qDebug() << "New dataset created!" ;
dims_out[0]+=1;
new_dataset_l->extend( dims_out );
qDebug() << "New dataset extended!" ;
// dataset_label.extend( dims_out );
// qDebug() << "old dataset extended!" ;
int *Label_buf = (int*) malloc( sizeof(int) * labelVect.size() );
for (int i=0; i<labelVect.size(); i++){
Label_buf[i]=labelVect[i];
}
new_dataset_l->write(Label_buf,H5::PredType::NATIVE_INT, fspace, fspace);
//dataset_label.write(Label_buf,H5::PredType::NATIVE_INT, fspace, fspace);
new_dataset_l->close();
dataset_label.close();
edge_properties_group.close();
///write the new edges to the graph
H5::Group e_group = Lh5file.openGroup("/vessel_graph");
H5::DataSet dataset_edge = e_group.openDataSet("edges");
H5::DataSpace dataspace_e = dataset_edge.getSpace(); //Get dataspace of the dataset.
hsize_t dims_out_e[2];// Get the dimension size of each dimension in the dataspace and display them.
int rank_e = dataspace_e.getSimpleExtentDims( dims_out_e, NULL);
// qDebug() << "/vessel_graph/edge_properties/label dims_out[0],[1]: " <<dims_out[0] << "," << dims_out[1]<< " , ndims = " << ndims <<" , rank = " << rank ;
if ((edgesVect.size()/2)> dims_out_e[0])
{
dims_out_e[0] = edgesVect.size()/2;
}
H5::DataSpace fspace_e( rank_e, dims_out_e );
int *edge_buf = (int*) malloc( sizeof(int) * edgesVect.size()*dims_out_e[1] );
for (int i=0; i<edgesVect.size(); i++){
edge_buf[i]=edgesVect[i];
//edge_buf[2*i+1]=edgesVect[2*i+1];
}
dataset_edge.write(edge_buf,H5::PredType::NATIVE_INT, fspace_e, fspace_e);
dataset_edge.close();
e_group.close();
Lh5file.close();
*/
//if ( verboseAction->isChecked() )
rf->emitVerboseSignal();
if (rf->getVerboseStatus())
qDebug() << "Debug. >>GeometryScene::saveLabel()...Successfully wrote the labeled H5 file" << h5_filename.toLatin1().data()<<"!\n";
}
/** function to write cylinder cx,cy,cz,h,r,tx,ty,tz properties as part of the save function
* global variables used: h5_filename,num_edge_total
*/
void GeometryScene::writeCylProp2H5(char * prop_name,int num_new_edge, QVector <float> new_edges_prop_val, QVector <int> deleted_edgesVect){
hid_t file_id, group_id, dataset, dataspace, datatype, hdf_plist;
herr_t status;
int rank = 1;
hsize_t dims[1];
int status_n;
file_id = H5Fopen(h5_filename.toLatin1().data(), H5F_ACC_RDWR, H5P_DEFAULT);
group_id = H5Gopen (file_id, "/vessel_graph/edge_properties", H5P_DEFAULT);
dataset = H5Dopen2(group_id, prop_name, H5P_DEFAULT);
dataspace = H5Dget_space(dataset); // dataspace handle
rank = H5Sget_simple_extent_ndims(dataspace);
status_n = H5Sget_simple_extent_dims(dataspace, dims, NULL);
hvl_tf* buf_i = (hvl_tf*) malloc( sizeof(hvl_tf) * (unsigned long)(dims[0]) );
//qDebug() << "cyl_centreX dataset rank " << rank << " dims[0] " << dims[0] << " num_new_edge " << num_new_edge ;
datatype = H5Dget_type(dataset); // datatype handle
status = H5Dread(dataset, datatype, dataspace, dataspace, H5P_DEFAULT, buf_i);
//qDebug() << status << prop_name<<"[0][1]" << buf_i[0].p[0] << " " << buf_i[1].p[0] ;
if (num_new_edge>0)
{
buf_i = (hvl_tf*) realloc (buf_i, sizeof(hvl_tf) * (unsigned long)(dims[0]+num_new_edge) );
for (int i=0; i<num_new_edge; i++){
buf_i[i+dims[0]].len =1;
buf_i[i+dims[0]].p = (float *) malloc( sizeof(float) );
buf_i[i+dims[0]].p[0]= new_edges_prop_val[i];
}
dims[0] += num_new_edge;
//qDebug() << "dims[0]" << dims[0] ;
}
if (deleted_edgesVect.size()>0){
hsize_t del_dims[1]; del_dims[0] = num_edge_total; //if there is deleted_edgesVect
// qDebug() << "final dims[0]" << del_dims[0] ;
for (int i=0; i<deleted_edgesVect.size(); i++){
buf_i[deleted_edgesVect[i]].len=0;
//qDebug() << "i=" << i << " edge #"<< deleted_edgesVect[i];
}
hvl_tf* buf_o = (hvl_tf*) malloc(sizeof(hvl_tf) * (unsigned long)(del_dims[0]));
int j =0;
for (int i=0; i< dims[0]; i++){
if (buf_i[i].len!=0){
buf_o[j].len = buf_i[i].len;
buf_o[j].p = (float *) malloc(sizeof(float)*buf_i[i].len);
for (int k=0; k<buf_i[i].len; k++){
buf_o[j].p[k]=buf_i[i].p[k];
}
j++;
}
}
//qDebug() << j << " done deleting";
status = H5Dset_extent(dataset, del_dims);
status = H5Dwrite(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_o);
free(buf_o);
}
else {
status = H5Dextend (dataset, dims);
status = H5Dwrite(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf_i);
}
status = H5Dclose(dataset);
free(buf_i);
status = H5Gclose (group_id);
status = H5Fclose (file_id);
}
void GeometryScene::getUserLabel(){
int userLabelnum = 0;
QString userLabel;
// bool ok;
//for the selected cylinder I get the NodeID which corresponds to a cylinder number N=> open H5 and read the N-th segment_ID , then save label as new field for all the edges that have that segment_ID
//we then read this in python to assign labels to actual corrected output of vessel tracking
// int e_num;
// for (int i=0; i< num_edge_total ; i++){
// for (int c=0; c<nodeIDs[i].len ; c++){
// if (nodeIDs[i].p[c]== nodeId){
// e_num=i;
// break; //e_num will have the number of the picked cylinder object
// }
// }
// }
//qDebug() << "user entered a label ..." ;
// userLabel = QInputDialog::getInteger(0, "Label selected vessel segment", "Label number [1:255.0]:", labelVect[e_num],0,255.0,1,&ok); //opens a dialog with title Label selected vessel segment, inside it message Label number
userLabel = rf->uilabel.LabelVessel->currentText();
//if ( verboseAction->isChecked() )
rf->emitVerboseSignal();
if (rf->getVerboseStatus())
qDebug() << "user entered label " << userLabel ;
// //if user cancled entering label dont' do following steps
// if (!ok){
// return;
// }
// //qDebug() << "User entered Label " <<userLabel << " for vessel segment with NodeId " << nodeId << " of selected cylinder number " << e_num << " with label " << labelVect[e_num] ;
userLabelnum = label_Name2num (userLabel);
//check if this vessel segment was labeled before differently? if it wasnt 0 and different from userLabel, ask relable?
if (labelVect[e_num]!=userLabelnum && labelVect[e_num]!=0) { //it has been labeled with a different label from new userLabel
// if (labelVect[e_num].compare(userLabel)!=0 && labelVect[e_num].compare (QString("No label\0"))!=0) { //it has been labeled with a different label from new userLabel
QString response = QString("Selected vessel was labelled before.Do you want to relabel?");
int answer = QMessageBox::question(0, "Relabel vessel?", response, QMessageBox::Yes | QMessageBox::No);
if (answer == QMessageBox::Yes){
//relabel
labelVect[e_num]=userLabelnum;
}
}
else if (labelVect[e_num]==0 ){ //it wasn't labeled before =>label
labelVect[e_num]=userLabelnum;
}
//qDebug() << "labelVect.size() "<< labelVect.size() << " : " << e_num << " "<< labelVect[e_num];
//color the selected vessel segment to color from lookup table based on label, transpar=0.5
if (labelVect[e_num]!=0 ){ //it was labeled before => color and transparency
// if (labelVect[e_num].compare (QString("No label\0"))!=0 ){ //it was labeled before => color and transparency
geometry->updateCylinderColour(/*cylmatVect[e_num].len, cylmatVect[e_num].p*/cylmatVect[e_num].size(), cylmatVect[e_num],labelVect[e_num]);
if (!cylnum_transparency0_5.contains(e_num)){
cylnum_transparency0_5.append(e_num);
}
}
//color the selected vessel segment to undo labeling: r=255.0, g=255.0, b=255.0, transpar=0.0
else{
geometry->updateCylinderColour(/*cylmatVect[e_num].len, cylmatVect[e_num].p*/cylmatVect[e_num].size(), cylmatVect[e_num], 0,0.0);
int trans_ind= cylnum_transparency0_5.lastIndexOf(e_num);
if (trans_ind !=-1){
cylnum_transparency0_5.remove(trans_ind);
}
}
}
void GeometryScene::updateRadiusTransparency(int newVal){
//find the threshold radius, find all radius in QVect smaller than threshold and call geometrynode::updateCylTransparency
float radthresh= (newVal*(radiusmax- radiusmin)/100)+radiusmin;
for (int e=0; e<num_edge_total; e++){
float mean_rad=0;
for (int c=0; c<cylradiusVect[e].size(); c++){
mean_rad += cylradiusVect[e][c];
}
mean_rad = mean_rad/cylradiusVect[e].size();
if (mean_rad<=radthresh) {
geometry->updateCylTransparency( /*cylmatVect[e].len, cylmatVect[e].p*/cylmatVect[e].size(), cylmatVect[e], 1);
}
else if (mean_rad>radthresh) {
if (cylnum_transparency0_5.contains(e)){
geometry->updateCylTransparency( /*cylmatVect[e].len, cylmatVect[e].p*/cylmatVect[e].size(), cylmatVect[e], 0.5);
}
else{
geometry->updateCylTransparency( /*cylmatVect[e].len, cylmatVect[e].p*/cylmatVect[e].size(), cylmatVect[e], 0.0);
}
}
}
}
GeometryScene::h5_output_type GeometryScene::H5_reader (char* dbfile){
H5::H5File h5file = H5::H5File();
h5file.openFile(dbfile, H5F_ACC_RDONLY); //read only access. H5F_ACC_RDWR :read and write access
//qDebug() << "File: " << h5file.getFileName() << "\nSize:" << h5file.getFileSize() << "\nObject Count:" << h5file.getObjCount() ;
H5::Group edge_properties_group = h5file.openGroup("/vessel_graph/edge_properties");
//qDebug() << "edge_properties group has " << edge_properties_group.getNumObjs() << " object in it. Its ID is " << edge_properties_group.getId() ;
struct h5_output_type h5_data;
/*/// using C++ API
qDebug() << "reading segment ID (type variable length array of int)..." ;
H5::DataSet dataset_segmentID = edge_properties_group.openDataSet("cyl_segment_ID");
H5::DataSpace dataspace_ID = dataset_segmentID.getSpace(); //Get filespace for rank and dimension of the dataset.
//int rank = dataspace_ID.getSimpleExtentNdims();//Get the number of dimensions in the file dataspace.
hsize_t dims_ID[1];// dataset dimensions
int rank_ID = dataspace_ID.getSimpleExtentDims( dims_ID, NULL);//Get the number of dimensions and the dimension sizes of the file dataspace
hssize_t num_element_ID = dataspace_ID.getSimpleExtentNpoints(); //Get number of elements in a dataspace
qDebug() << "dims_ID[0],[1] = " <<dims_ID[0]<< " , rank_ID = " << rank_ID << " , num_element_ID = " << num_element_ID ;
H5::DataSpace memspace_ID( rank_ID, dims_ID );
H5::DataType dtype = dataset_segmentID.getDataType();
//hsize_t buff_size_ID = dataset_segmentID.getVlenBufSize(dtype,dataspace_ID );
hvl_ti * segmentID_data = (hvl_ti*) malloc((unsigned long)(dims_ID[0])*sizeof(hvl_ti));
dataset_segmentID.read(segmentID_data ,dtype ,memspace_ID, dataspace_ID);
///// dataset_segmentID.read(segmentID_data,H5::H5T_VARIABLE,memspace_ID, dataspace_ID);
qDebug() << segmentID_data[0].len << " , " << segmentID_data[1].len << " , " << segmentID_data[2].len << " , " << segmentID_data[3].len << " , ";
qDebug() << segmentID_data[0].p[0] << " , " << segmentID_data[0].p[1] << " , " << segmentID_data[1].p[0] << " , " << segmentID_data[2].p[1] << " , "<< segmentID_data[6].p[0] ;
dataset_segmentID.close();
*/
/*/// using C API
edge_properties_group.close();
h5file.close();
hid_t file_id, dataset_id;
herr_t status;
// hsize_t size;
hid_t tid1 = H5Tvlen_create (H5T_NATIVE_INT);
file_id = H5Fopen(dbfile, H5F_ACC_RDWR, H5P_DEFAULT);
dataset_id = H5Dopen(file_id, "/vessel_graph/edge_properties/cyl_segment_ID", H5P_DEFAULT);
hvl_t * rdataid = (hvl_t*) malloc((unsigned long)(dims[0])*sizeof(hvl_t));
status =H5Dread(dataset_id, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdataid);
qDebug() << rdataid[0].len << " , " << rdataid[1].len << " , " << rdataid[2].len << " , " << rdataid[3].len << " , " << rdataid[0].p[0] << " , " << rdataid[0].p[1] << " , " << rdataid[1].p[0] << " , " << rdataid[2].p[1] << " , "<< rdataid[6].p[0] ;
status = H5Dclose(dataset_id);
status = H5Fclose(file_id);
h5file.openFile(dbfile, H5F_ACC_RDONLY); //read only access. H5F_ACC_RDWR :read and write access
edge_properties_group = h5file.openGroup("/vessel_graph/edge_properties");
*/
//qDebug() << "\n\n\nreading edge centres X,Y,Z (type variable length array of float)..." ;
H5::DataSet dataset_centreX =edge_properties_group.openDataSet("cyl_centreX");
H5::DataSet dataset_centreY =edge_properties_group.openDataSet("cyl_centreY");
H5::DataSet dataset_centreZ =edge_properties_group.openDataSet("cyl_centreZ");
H5::DataSpace dataspace_c = dataset_centreX.getSpace(); //Get dataspace of the dataset.
hsize_t dims_c[1];// Get the dimension size of each dimension in the dataspace and display them.
int rank_c = dataspace_c.getSimpleExtentDims( dims_c, NULL);
H5::DataSpace memspace_c ( rank_c, dims_c );
H5::DataType ctype = dataset_centreX.getDataType();
h5_data.centreX /*hvl_t * centreX_struc*/ = (hvl_tf*) malloc((unsigned long)(dims_c[0])*sizeof(hvl_tf));
h5_data.centreY /*hvl_t * centreY_struc*/ = (hvl_tf*) malloc((unsigned long)(dims_c[0])*sizeof(hvl_tf));
h5_data.centreZ /*hvl_t * centreZ_struc*/ = (hvl_tf*) malloc((unsigned long)(dims_c[0])*sizeof(hvl_tf));
dataset_centreX.read(h5_data.centreX ,ctype ,memspace_c, dataspace_c);
dataset_centreY.read(h5_data.centreY ,ctype ,memspace_c, dataspace_c);
dataset_centreZ.read(h5_data.centreZ ,ctype ,memspace_c, dataspace_c);
//qDebug() << h5_data.centreX[0].len << " , " << h5_data.centreX[1].len << " , " << h5_data.centreX[2].len << " , " << h5_data.centreX[3].len << " , " << h5_data.centreX[0].p[0] << " , " << h5_data.centreX[0].p[1] << " , " << h5_data.centreX[1].p[0] << " , " << h5_data.centreX[2].p[1] << " , "<< h5_data.centreX[6].p[0] ;
dataset_centreX.close();
dataset_centreY.close();