I have file that looks like this
gene_id_100100 sp|Q53IZ1|ASDP_PSESP 35.81 148 90 2 13 158 6 150 6e-27 109 158 531
gene_id_100600 sp|Q49W80|Y1834_STAS1 31.31 99 63 2 1 95 279 376 7e-07 50.1 113 402
gene_id_100 sp|A7TSV7|PAN1_VANPO 36.36 44 24 1 41 80 879 922 1.9 32.3 154 1492
gene_id_10100 sp|P37348|YECE_ECOLI 32.77 177 104 6 3 172 2 170 2e-13 71.2 248 272
gene_id_101100 sp|B0U4U5|SURE_XYLFM 29.11 79 41 3 70 148 143 206 0.14 35.8 175 262
gene_id_101600 sp|Q5AWD4|BGLM_EMENI 35.90 39 25 0 21 59 506 544 4.9 30.4 129 772
gene_id_102100 sp|P20374|COX1_APILI 38.89 36 22 0 3 38 353 388 0.54 32.0 92 521
gene_id_102600 sp|Q46127|SYW_CLOLO 79.12 91 19 0 1 91 1 91 5e-44 150 92 341
gene_id_103100 sp|Q9UJX6|ANC2_HUMAN 53.57 28 13 0 11 38 608 635 2.1 28.9 42 822
gene_id_103600 sp|C1DA02|SYL_LARHH 35.59 59 30 2 88 138 382 440 4.6 30.8 140 866
gene_id_104100 sp|B8DHP2|PROB_LISMH 25.88 85 50 2 37 110 27 109 0.81 32.3 127 276
gene_id_105100 sp|A1ALU1|RL3_PELPD 31.88 69 42 2 14 77 42 110 2.2 31.6 166 209
gene_id_105600 sp|P59696|T200_SALTY 64.00 125 45 0 5 129 3 127 9e-58 182 129 152
gene_id_10600 sp|G3XDA3|CTPH_PSEAE 28.38 74 48 1 4 77 364 432 0.56 31.6 81 568
gene_id_106100 sp|P94369|YXLA_BACSU 35.00 100 56 3 25 120 270 364 4e-08 53.9 120 457
gene_id_106600 sp|P34706|SDC3_CAEEL 60.00 20 8 0 18 37 1027 1046 2.3 32.7 191 2150
Now, I need to extract the gene ID, which is the one between || in the second column. In other words, I need an output that looks like this:
Q53IZ1
Q49W80
A7TSV7
P37348
B0U4U5
Q5AWD4
P20374
Q46127
Q9UJX6
C1DA02
B8DHP2
A1ALU1
P59696
G3XDA3
P94369
P34706
I have been trying to do it using the following command:
awk '{for(i=1;i<=NF;++i){ if($i==/[A-Z][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]/){print $i} } }'
but it doesn't seem to work.
Pattern matching is not really necessary. I'd suggest
awk -F\| '{print $2}' filename
This splits the line into |-delimited fields and prints the second of them.
Alternatively,
cut -d\| -f 2 filename
achieves the same.
Related
I have a data frame with over 4000 pts. Each point has 2 ID columns that identify a hierarchical grouping system let's call them l_1 and l_2. l_1 indicates points that are grouped together. I want to make a convex hull for each of these groups and then measure the area for each convex hull polygon.
Then, I want to estimate the average convex hull area based on the second grouping ID named l_2. Ideally the outcome would be a data frame with a row for the average convex polygon area for each unique l_2 identifier.
So far I am trying to create a list of data frames based on the l_1 column. Something like:
areas <- lapply(df$l_1, function(x){
sfObs<-df %>% filter(l_1 == x) %>%
st_as_sf(., coords = c('x', 'y'), crs = 4326)
areas<-st_convex_hull(st_union(chk)) %>% st_area()
return(areas)
})
But I only get empty polygons so far. It works with a single value for x but when I run it as a list of values it spits out empty polygons.
After that, I would average convex polygon area by using group_by and summarise(mean()) as follows, employing the l_2 ID column.
df.areas<-do.call(areas, 'rbind') %>% cbind(unique(df$l_1), .)%>%
left_join(., df, by=l_1) %>%
group_by(l_2)%>%
summarise(aveArea=mean(area))
But as I can't get past the first bit so I am stuck. I would be grateful for any ideas on how to achieve the end goal, but please only using sf functions.
A subset of the data:
l_2 l_1 x y
1 17 149 151.8930 -23.42907
2 17 149 151.8815 -23.41670
3 17 149 151.8805 -23.42031
4 17 149 151.8532 -23.41637
5 17 149 151.8284 -23.41455
6 17 149 151.8212 -23.40360
7 17 149 151.8057 -23.39490
8 17 149 151.7897 -23.39090
9 17 149 151.8055 -23.40893
10 17 149 151.8041 -23.40735
11 17 149 151.7980 -23.41180
12 17 149 151.7958 -23.41051
13 17 149 151.8015 -23.40578
14 17 149 151.8023 -23.40141
15 17 149 151.7873 -23.39065
16 17 149 151.7690 -23.39123
17 17 149 151.7663 -23.38577
18 17 149 151.7654 -23.39139
19 17 151 151.8086 -23.44059
20 17 151 151.7972 -23.43462
21 17 151 151.8080 -23.43974
22 17 153 151.7794 -23.36882
23 17 153 151.7792 -23.34290
24 17 153 151.7802 -23.34012
25 17 157 151.7664 -23.37117
26 17 157 151.7783 -23.37342
27 17 157 151.7962 -23.36544
28 17 157 151.8079 -23.35681
29 17 157 151.8006 -23.35412
30 17 157 151.8030 -23.35334
31 17 157 151.8030 -23.36052
32 17 157 151.8075 -23.36844
33 17 157 151.8057 -23.37128
34 17 157 151.7990 -23.37499
35 17 157 151.7937 -23.37959
36 17 159 151.8643 -23.42937
37 17 159 151.8726 -23.41774
38 17 159 151.8905 -23.42103
39 17 159 151.9041 -23.43649
40 17 161 151.8440 -23.38699
41 17 161 151.8498 -23.37978
42 17 161 151.8499 -23.36631
43 17 161 151.8344 -23.33939
44 17 161 151.8332 -23.33175
45 17 161 151.8370 -23.33839
46 17 161 151.8384 -23.33640
47 17 161 151.8440 -23.33435
48 17 161 151.8317 -23.34718
49 17 161 151.8279 -23.34407
50 17 161 151.8310 -23.34102
51 17 161 151.8337 -23.34140
52 17 163 151.8272 -23.36147
53 17 163 151.8161 -23.35445
54 17 163 151.8159 -23.34914
55 17 163 151.8134 -23.33415
56 6 649 151.9532 -23.42466
57 6 649 151.9680 -23.42602
58 6 649 151.9744 -23.42791
59 6 649 151.9925 -23.42612
60 6 649 152.0139 -23.42027
61 6 649 152.0235 -23.41462
62 6 649 152.0243 -23.41289
63 6 649 152.0236 -23.40959
64 6 649 152.0268 -23.40911
65 6 649 152.0276 -23.40897
66 6 649 152.0259 -23.40767
67 6 651 151.8505 -23.44435
68 6 651 151.8516 -23.44453
69 6 651 151.8400 -23.44005
70 6 651 151.8260 -23.44468
71 6 651 151.8196 -23.44625
72 6 651 151.8213 -23.44360
73 6 651 151.8111 -23.42271
74 6 651 151.8220 -23.40930
75 6 651 151.8160 -23.42438
76 6 651 151.8115 -23.43400
77 6 651 151.8269 -23.44965
78 6 651 151.8485 -23.45157
79 6 651 151.8471 -23.45342
80 6 651 151.8506 -23.45705
81 6 651 151.8489 -23.45228
82 6 651 151.8562 -23.45304
83 6 651 151.8552 -23.45212
84 6 651 151.8579 -23.44707
85 6 651 151.8644 -23.44840
86 6 651 151.8667 -23.44603
87 6 651 151.8775 -23.44708
88 6 653 151.9705 -23.42842
89 6 653 151.9733 -23.42767
90 6 655 151.9024 -23.41702
91 6 655 151.9138 -23.40610
92 6 655 151.9095 -23.40876
93 6 655 151.9015 -23.39602
94 6 655 151.9252 -23.37706
95 6 655 151.9308 -23.37199
96 6 655 151.9307 -23.36946
97 6 655 151.9805 -23.39567
98 6 655 152.0065 -23.41577
99 6 655 152.0196 -23.41305
100 6 655 152.0211 -23.41244
101 6 655 152.0113 -23.41101
102 6 655 152.0142 -23.40985
103 6 655 152.0150 -23.40754
104 6 655 152.0041 -23.40394
105 8 669 151.8945 -23.64410
106 8 669 151.8890 -23.66261
107 8 669 151.9000 -23.66387
108 8 669 151.9067 -23.66830
109 8 669 151.9094 -23.68123
110 8 669 151.8967 -23.69244
111 8 669 151.9107 -23.69545
112 8 669 151.9192 -23.69091
113 8 669 151.9273 -23.68480
114 8 669 151.9409 -23.66136
115 8 669 151.9361 -23.66283
116 8 669 151.9396 -23.66090
117 8 669 151.9432 -23.65804
118 8 669 151.9488 -23.65748
119 8 669 151.9521 -23.65517
120 8 669 151.9595 -23.65920
121 8 669 151.9666 -23.66185
122 8 669 151.9724 -23.65896
123 8 669 151.9802 -23.65798
124 8 669 151.9735 -23.63510
125 8 669 151.9558 -23.61360
126 8 669 151.9589 -23.61100
127 8 669 151.9623 -23.60884
128 8 669 151.9645 -23.61030
129 8 669 151.9685 -23.61122
130 8 669 151.9681 -23.60686
131 8 669 151.9612 -23.60467
132 8 671 151.9500 -23.47789
133 8 671 151.9495 -23.47786
134 8 671 151.9456 -23.47541
135 8 671 151.9448 -23.47416
136 8 671 151.9606 -23.48151
137 8 671 151.9637 -23.47959
138 8 671 151.9766 -23.47657
139 8 673 151.9711 -23.53105
140 8 673 151.9903 -23.51980
141 8 673 152.0149 -23.52661
142 8 673 152.0172 -23.52828
143 8 673 152.0168 -23.53076
144 8 673 152.0146 -23.53149
145 8 673 152.0108 -23.53228
146 8 673 152.0114 -23.53236
147 8 673 152.0145 -23.53364
148 8 675 152.0148 -23.47530
149 8 675 152.0200 -23.46649
150 8 675 152.0185 -23.46562
151 8 675 152.0181 -23.44782
152 8 675 152.0190 -23.43633
153 8 675 152.0049 -23.41639
154 8 675 152.0067 -23.40699
155 8 675 152.0127 -23.41182
156 8 675 152.0138 -23.41197
157 8 675 152.0136 -23.40980
158 8 675 152.0183 -23.40843
159 8 675 152.0190 -23.40862
160 8 677 151.8494 -23.55435
161 8 677 151.8476 -23.54912
162 8 679 151.8122 -23.62238
163 8 679 151.8100 -23.61953
164 8 679 151.8074 -23.61739
165 8 679 151.8040 -23.61299
166 8 679 151.8101 -23.61499
167 8 679 151.8097 -23.61255
168 8 679 151.8049 -23.61203
169 8 679 151.8048 -23.60668
170 8 679 151.8048 -23.60774
171 8 679 151.8209 -23.61589
172 8 679 151.8223 -23.60883
173 8 679 151.8217 -23.61741
174 8 679 151.8229 -23.61998
175 8 679 151.8241 -23.62179
176 8 679 151.8394 -23.62616
177 8 679 151.8384 -23.62278
178 8 681 151.8474 -23.62581
179 8 681 151.8470 -23.62196
180 8 681 151.8505 -23.62026
181 8 681 151.8511 -23.61996
182 8 681 151.8506 -23.62811
183 8 681 151.8394 -23.65246
184 8 681 151.8179 -23.65648
185 8 681 151.8081 -23.65494
186 8 681 151.8008 -23.65538
187 8 681 151.8032 -23.64207
188 8 681 151.8129 -23.64435
189 8 681 151.8141 -23.64182
190 8 681 151.8167 -23.63823
It's my first time using CGAL and I'm trying to use CGAL isotropic_remeshing following CGAL guide and examples.
typedef CGAL::Simple_cartesian<double> geometric_kernel;
typedef CGAL::Surface_mesh<geometric_kernel::Point_3> triangle_mesh;
typedef boost::graph_traits<triangle_mesh>::edge_descriptor edge_descriptor;
typedef boost::graph_traits<triangle_mesh>::halfedge_descriptor halfedge_descriptor;
struct halfedge2edge
{
halfedge2edge(const triangle_mesh& m, std::vector<edge_descriptor>& edges)
: m_mesh(m), m_edges(edges)
{}
void operator()(const halfedge_descriptor& h) const
{
m_edges.push_back(edge(h, m_mesh));
}
const triangle_mesh& m_mesh;
std::vector<edge_descriptor>& m_edges;
};
void remesh(std::string fname) {
fmt::print("reading input file {}\n", fname);
std::ifstream input(fname);
bool b = CGAL::IO::read_PLY(input, _mesh);
input.close();
if (!b) throw std::runtime_error("cannot read input file");
// this returns false (initial mesh is ok)
fmt::print("Self-intersaction: {}", CGAL::Polygon_mesh_processing::does_self_intersect(faces(_mesh), _mesh) ? "YES\n" : "NO\n");
std::vector<edge_descriptor> border;
PMP::border_halfedges(faces(_mesh), _mesh, boost::make_function_output_iterator(halfedge2edge(_mesh, border)));
split_long_edges(border, 0.05, _mesh);
CGAL::Polygon_mesh_processing::isotropic_remeshing(faces(_mesh), 0.05, _mesh, CGAL::Polygon_mesh_processing::parameters::number_of_iterations(3).protect_constraints(true));
// this returns true ...
fmt::print("Self-intersaction: {}", CGAL::Polygon_mesh_processing::does_self_intersect(faces(_mesh), _mesh) ? "YES\n" : "NO\n");
}
and this is the PLY file:
ply
format ascii 1.0
element vertex 240
property double x
property double y
property double z
element face 416
property list uchar int vertex_indices
end_header
-0.0677552 1.75428e-11 0.359551
0.559233 -5.07748e-11 -0.00371597
-0.422648 -0.0809302 0.0767055
-0.422648 0.0809302 0.0767055
0.353976 -0.31933 -0.0764848
0.353976 0.31933 -0.0764848
0.18628 -0.105913 0.136968
0.18628 0.105913 0.136968
0.0734964 -0.042885 0.171005
0.0734964 0.042885 0.171005
0.000894007 -0.101015 0.219853
0.000894007 0.101015 0.219853
-0.317115 -0.490302 -0.14088
-0.317115 0.490302 -0.14088
0.0363557 -0.18484 0.0595056
0.0363557 0.18484 0.0595056
0.679924 -0.284836 -0.185795
0.679924 0.284836 -0.185795
-0.902296 1.60765e-11 -0.0147902
-0.334173 -0.308304 -0.0317029
-0.226906 -0.388018 -0.0664415
0.238526 -0.495303 -0.175104
0.682336 -0.249117 -0.140847
-0.527435 -0.227159 0.105247
-0.915072 -0.285449 -0.0849493
-0.588108 -0.384526 0.0274976
-0.414261 -0.558083 -0.173693
-0.709628 -0.546197 -0.209069
-0.279147 -0.551078 -0.191796
-0.441742 -0.0761666 0.0919278
0.0750773 -0.548552 -0.169267
0.151201 -0.0861054 0.142655
-0.328035 -0.0785272 0.130721
-0.188634 -0.160355 0.0781907
-0.319349 -0.157333 -0.00956133
-0.695544 -0.0781028 0.0827349
-0.207819 -0.26498 -0.0189174
-0.186662 -0.497279 -0.102856
-0.0315025 -0.481533 -0.0632797
-0.101123 -0.565625 -0.138967
-0.954181 -0.0987909 -0.0469328
-0.448314 -0.217296 0.00954906
-0.855668 -0.454036 -0.168054
-0.685034 -0.225247 0.0590258
-0.19149 -0.085893 0.23609
-0.346289 -0.446491 -0.0910963
-0.0677861 -0.240685 0.03329
-0.570304 -0.563494 -0.181845
-0.0991308 -0.373187 -0.0199879
0.0256409 -0.0662504 0.220869
0.12104 -0.443556 -0.0725518
-0.559714 -0.0601683 0.126809
0.7294 -0.0778938 -0.0619168
-0.485049 -0.500588 -0.0492544
0.0544319 -0.163186 0.072704
-0.659303 -0.466641 -0.0854264
-0.769765 -0.338041 -0.0415794
-0.0697669 -0.153351 0.179993
0.0177175 -0.341852 0.0051975
0.142156 -0.249748 0.0257109
0.395681 -0.491973 -0.246075
0.585311 -0.0507501 -0.00507005
0.579522 -0.360325 -0.214198
0.375654 -0.398838 -0.122424
-0.0771929 -0.0805348 0.321587
-0.83454 -0.127215 0.00225332
-0.445651 -0.371942 0.010079
0.584187 -0.166126 -0.0560823
0.491718 -0.270257 -0.0989297
-0.334173 0.308304 -0.0317029
-0.226906 0.388018 -0.0664415
0.238526 0.495303 -0.175104
0.682336 0.249117 -0.140847
-0.527435 0.227159 0.105247
-0.915072 0.285449 -0.0849493
-0.588108 0.384526 0.0274976
-0.414261 0.558083 -0.173693
-0.709628 0.546197 -0.209069
-0.279147 0.551078 -0.191796
-0.441742 0.0761666 0.0919278
0.0750773 0.548552 -0.169267
0.151201 0.0861054 0.142655
-0.328035 0.0785272 0.130721
-0.188634 0.160355 0.0781907
-0.319349 0.157333 -0.00956133
-0.695544 0.0781028 0.0827349
-0.207819 0.26498 -0.0189174
-0.186662 0.497279 -0.102856
-0.0315025 0.481533 -0.0632797
-0.101123 0.565625 -0.138967
-0.954181 0.0987909 -0.0469328
-0.448314 0.217296 0.00954906
-0.855668 0.454036 -0.168054
-0.685034 0.225247 0.0590258
-0.19149 0.085893 0.23609
-0.346289 0.446491 -0.0910963
-0.0677861 0.240685 0.03329
-0.570304 0.563494 -0.181845
-0.0991308 0.373187 -0.0199879
0.0256409 0.0662504 0.220869
0.12104 0.443556 -0.0725518
-0.559714 0.0601683 0.126809
0.7294 0.0778938 -0.0619168
-0.485049 0.500588 -0.0492544
0.0544319 0.163186 0.072704
-0.659303 0.466641 -0.0854264
-0.769765 0.338041 -0.0415794
-0.0697669 0.153351 0.179993
0.0177175 0.341852 0.0051975
0.142156 0.249748 0.0257109
0.395681 0.491973 -0.246075
0.585311 0.0507501 -0.00507006
0.579522 0.360325 -0.214198
0.375654 0.398838 -0.122424
-0.0771929 0.0805348 0.321587
-0.83454 0.127215 0.00225332
-0.445651 0.371942 0.010079
0.584187 0.166126 -0.0560823
0.491718 0.270257 -0.0989297
0.244787 0.44166 -0.124611
0.224863 0.422926 -0.103295
0.203555 0.403002 -0.0851674
0.181818 0.382468 -0.0666096
0.160161 0.361466 -0.0494549
0.138703 0.340243 -0.0343855
0.116587 0.315975 -0.0211481
0.0930881 0.292328 -0.010644
0.0683716 0.270062 -0.00112955
0.0437934 0.247639 0.00896137
0.0147427 0.229286 0.0184032
0.244787 -0.44166 -0.124611
0.224863 -0.422926 -0.103295
0.203555 -0.403002 -0.0851674
0.181818 -0.382468 -0.0666096
0.160161 -0.361466 -0.0494549
0.138703 -0.340243 -0.0343855
0.116587 -0.315975 -0.0211481
0.0930881 -0.292328 -0.010644
0.0683716 -0.270062 -0.00112955
0.0437934 -0.247639 0.00896137
0.0147427 -0.229286 0.0184032
0.353943 0.318951 -0.0768402
0.318176 0.310251 -0.0529674
0.28752 0.294134 -0.0220852
0.263653 0.270201 0.00932505
0.248486 0.239857 0.0406095
0.237599 0.20638 0.0706802
0.228386 0.170062 0.097771
0.220138 0.131333 0.121548
0.221814 0.0891843 0.140093
0.237727 0.0468576 0.144191
0.240837 -4.4941e-11 0.144112
0.353943 -0.318951 -0.0768402
0.318176 -0.310251 -0.0529674
0.28752 -0.294134 -0.0220852
0.263653 -0.270201 0.00932505
0.248486 -0.239857 0.0406095
0.237599 -0.20638 0.0706802
0.228386 -0.170062 0.097771
0.220138 -0.131333 0.121548
0.221814 -0.0891843 0.140093
0.237727 -0.0468576 0.144191
0.334994 0.290335 -0.0602502
0.324017 0.260279 -0.0388522
0.31833 0.233087 -0.011531
0.312891 0.206844 0.0165917
0.306376 0.17827 0.0421742
0.301065 0.146996 0.0646615
0.297445 0.113434 0.0839683
0.295181 0.07813 0.10025
0.293328 0.0406645 0.110471
0.290482 2.27582e-11 0.115974
0.334994 -0.290335 -0.0602502
0.324017 -0.260279 -0.0388522
0.31833 -0.233087 -0.011531
0.312891 -0.206844 0.0165917
0.306376 -0.17827 0.0421742
0.301065 -0.146996 0.0646615
0.297445 -0.113434 0.0839683
0.295181 -0.07813 0.10025
0.293328 -0.0406645 0.110471
0.347914 0.280814 -0.0613852
0.33858 0.251578 -0.0407904
0.333526 0.224505 -0.0155032
0.330611 0.199101 0.010933
0.326488 0.172047 0.0361431
0.321941 0.142269 0.0582371
0.318458 0.109138 0.0750352
0.316637 0.0738964 0.0871513
0.31877 0.0372044 0.0929536
0.318747 -5.36519e-12 0.0939851
0.347914 -0.280814 -0.0613852
0.33858 -0.251578 -0.0407904
0.333526 -0.224505 -0.0155032
0.330611 -0.199101 0.010933
0.326488 -0.172047 0.0361431
0.321941 -0.142269 0.0582371
0.318458 -0.109138 0.0750352
0.316637 -0.0738964 0.0871513
0.31877 -0.0372044 0.0929536
0.383912 0.288495 -0.0737723
0.401167 0.260743 -0.0567028
0.416481 0.23323 -0.0356612
0.427658 0.205483 -0.0128446
0.433461 0.176582 0.0104455
0.435967 0.146037 0.0318464
0.436745 0.113498 0.0486202
0.434922 0.0783314 0.0602004
0.432704 0.0414137 0.0672302
0.439201 4.6519e-12 0.0584096
0.383912 -0.288495 -0.0737723
0.401167 -0.260743 -0.0567028
0.416481 -0.23323 -0.0356612
0.427658 -0.205483 -0.0128446
0.433461 -0.176582 0.0104455
0.435967 -0.146037 0.0318464
0.436745 -0.113498 0.0486202
0.434922 -0.0783314 0.0602004
0.432704 -0.0414137 0.0672302
-0.399426 0.601789 -0.253601
-0.434361 0.571336 -0.18351
-0.469967 0.544585 -0.115531
-0.50467 0.50818 -0.052334
-0.524224 0.45265 0.00308497
-0.529609 0.384371 0.046803
-0.53244 0.309845 0.0804658
-0.54185 0.233414 0.106686
-0.558825 0.155064 0.120583
-0.554692 0.074207 0.125803
-0.526166 3.22982e-11 0.133583
-0.399426 -0.601789 -0.253601
-0.434361 -0.571336 -0.18351
-0.469967 -0.544585 -0.115531
-0.50467 -0.50818 -0.052334
-0.524224 -0.45265 0.00308497
-0.529609 -0.384371 0.046803
-0.53244 -0.309845 0.0804658
-0.54185 -0.233414 0.106686
-0.558825 -0.155064 0.120583
-0.554692 -0.074207 0.125803
3 221 76 220
3 131 21 130
3 33 46 57
3 2 32 82
3 82 94 83
3 37 20 45
3 235 234 66
3 2 3 79
3 82 32 94
3 39 30 38
3 12 37 45
3 50 21 131
3 189 190 208
3 2 41 34
3 13 76 103
3 77 97 219
3 94 0 114
3 124 109 143
3 86 84 83
3 47 27 230
3 234 53 45
3 107 94 114
3 26 12 53
3 18 40 65
3 27 47 55
3 37 39 38
3 25 55 234
3 20 19 45
3 237 23 238
3 160 6 159
3 36 20 48
3 40 18 90
3 74 115 106
3 35 18 65
3 56 25 43
3 227 3 91
3 18 35 85
3 19 20 36
3 32 2 34
3 229 29 79
3 3 82 84
3 3 2 82
3 13 95 87
3 46 36 48
3 21 30 60
3 36 46 33
3 44 57 64
3 30 21 50
3 140 14 57
3 210 62 68
3 132 131 63
3 59 14 139
3 54 59 158
3 57 14 54
3 3 84 91
3 223 75 224
3 149 81 150
3 64 54 10
3 215 214 67
3 104 81 147
3 158 6 31
3 18 85 115
3 85 93 115
3 75 225 224
3 115 93 106
3 106 75 105
3 84 69 91
3 80 88 100
3 69 70 95
3 87 70 98
3 69 86 70
3 15 109 128
3 95 70 87
3 96 107 129
3 100 124 123
3 13 87 78
3 80 89 88
3 71 80 100
3 80 71 110
3 206 207 111
3 61 52 111
3 141 5 142
3 118 17 112
3 24 42 56
3 55 25 56
3 232 26 53
3 42 27 56
3 27 55 56
3 40 24 65
3 43 35 65
3 37 12 28
3 230 26 231
3 47 230 231
3 231 26 232
3 47 231 232
3 55 47 233
3 47 232 233
3 12 26 28
3 26 230 28
3 233 232 53
3 53 12 45
3 55 233 234
3 233 53 234
3 25 235 236
3 45 19 66
3 28 230 39
3 37 28 39
3 25 234 235
3 234 45 66
3 235 66 236
3 43 25 236
3 85 35 51
3 23 41 238
3 66 19 236
3 236 19 41
3 236 23 237
3 43 236 237
3 23 236 41
3 239 238 29
3 32 33 44
3 38 50 58
3 24 56 65
3 56 43 65
3 90 18 115
3 74 90 115
3 35 43 238
3 43 237 238
3 238 41 29
3 35 238 239
3 51 35 239
3 41 2 29
3 51 239 29
3 29 2 79
3 41 19 34
3 19 36 34
3 34 36 33
3 32 34 33
3 51 29 229
3 85 51 101
3 101 51 229
3 101 229 79
3 93 85 227
3 85 101 228
3 227 85 228
3 228 101 79
3 3 227 79
3 227 228 79
3 86 69 84
3 84 82 83
3 107 114 11
3 83 94 107
3 38 30 50
3 130 60 63
3 50 131 132
3 154 133 153
3 133 132 153
3 59 134 154
3 63 60 62
3 21 60 130
3 20 37 48
3 37 38 48
3 48 38 58
3 46 48 58
3 46 140 57
3 138 59 139
3 139 14 140
3 58 138 139
3 46 58 140
3 58 139 140
3 134 133 154
3 59 138 137
3 134 59 135
3 50 132 133
3 135 59 136
3 50 133 134
3 58 50 135
3 50 134 135
3 136 59 137
3 58 135 136
3 138 58 137
3 58 136 137
3 195 194 213
3 152 4 210
3 4 62 210
3 59 154 155
3 4 152 153
3 59 155 156
3 155 154 172
3 131 130 63
3 211 210 68
3 4 63 62
3 63 4 153
3 132 63 153
3 153 152 172
3 154 153 172
3 156 155 173
3 155 172 173
3 156 173 174
3 192 191 210
3 191 152 210
3 157 174 175
3 156 174 157
3 62 16 68
3 22 52 67
3 193 192 211
3 192 210 211
3 193 211 212
3 194 212 213
3 211 68 212
3 68 16 67
3 0 94 44
3 94 32 44
3 0 44 64
3 33 57 44
3 0 64 49
3 14 59 54
3 64 57 54
3 6 160 31
3 158 157 175
3 59 156 157
3 10 54 31
3 59 157 158
3 6 158 159
3 161 180 151
3 31 161 151
3 54 158 31
3 49 10 31
3 8 0 49
3 64 10 49
3 0 8 9
3 8 49 31
3 108 88 98
3 86 83 96
3 99 9 81
3 31 160 161
3 109 15 104
3 114 0 99
3 0 9 99
3 11 99 81
3 114 99 11
3 15 107 104
3 107 11 104
3 104 11 81
3 81 7 147
3 8 31 151
3 149 7 81
3 7 149 148
3 146 109 147
3 160 159 178
3 193 212 194
3 158 175 176
3 159 158 177
3 158 176 177
3 16 22 67
3 213 68 214
3 159 177 178
3 212 68 213
3 214 68 67
3 196 195 214
3 195 213 214
3 196 214 215
3 150 81 151
3 198 197 216
3 196 215 197
3 161 160 179
3 160 178 179
3 9 8 151
3 161 179 180
3 197 215 216
3 216 215 67
3 81 9 151
3 1 61 111
3 150 151 170
3 199 198 217
3 198 216 217
3 218 217 61
3 199 217 218
3 217 216 67
3 67 52 61
3 1 218 61
3 217 67 61
3 218 1 209
3 170 151 171
3 151 180 171
3 150 170 169
3 148 149 168
3 149 150 169
3 199 218 190
3 190 218 209
3 208 1 111
3 208 190 209
3 1 208 209
3 167 148 168
3 168 149 169
3 186 187 205
3 147 167 166
3 189 208 207
3 188 189 207
3 187 188 206
3 204 117 118
3 165 147 166
3 205 187 206
3 205 117 204
3 206 188 207
3 207 208 111
3 111 52 102
3 205 206 117
3 206 111 117
3 117 111 102
3 97 221 220
3 93 75 106
3 106 77 92
3 74 106 92
3 97 77 105
3 77 106 105
3 226 73 225
3 91 69 225
3 93 227 226
3 227 73 226
3 73 227 91
3 73 91 225
3 75 93 225
3 93 226 225
3 105 75 223
3 105 223 222
3 224 225 116
3 225 69 116
3 95 13 103
3 223 224 116
3 95 223 116
3 69 95 116
3 223 95 103
3 97 105 222
3 103 76 221
3 221 97 222
3 103 221 222
3 223 103 222
3 88 89 87
3 88 87 98
3 76 13 78
3 87 89 78
3 219 97 220
3 76 219 220
3 219 76 78
3 89 219 78
3 128 96 129
3 83 107 96
3 109 145 144
3 128 109 127
3 107 15 129
3 15 128 129
3 70 86 98
3 96 128 108
3 108 128 127
3 143 109 144
3 145 109 146
3 109 104 147
3 7 148 147
3 145 146 164
3 148 167 147
3 146 147 165
3 127 109 126
3 108 127 126
3 124 108 125
3 109 124 125
3 125 108 126
3 109 125 126
3 119 120 113
3 110 71 119
3 163 145 164
3 144 145 163
3 86 96 98
3 96 108 98
3 108 124 100
3 88 108 100
3 122 143 142
3 124 143 123
3 121 100 122
3 121 122 142
3 122 100 123
3 143 122 123
3 71 100 119
3 100 121 120
3 119 100 120
3 110 119 113
3 182 201 200
3 143 144 163
3 182 183 201
3 164 146 165
3 186 205 204
3 183 184 202
3 185 186 204
3 184 185 203
3 5 141 200
3 143 163 162
3 201 183 202
3 200 201 118
3 202 184 203
3 117 17 118
3 203 185 204
3 203 204 118
3 142 5 113
3 120 121 113
3 121 142 113
3 142 143 162
3 141 142 162
3 113 5 112
3 181 182 200
3 141 181 200
3 202 203 118
3 201 202 118
3 17 117 72
3 117 102 72
3 5 200 112
3 200 118 112
3 110 113 112
As my program reads the PLY file containing the mesh (which is stored in _mesh and does not self-intersect), isotropic remeshing is done but, after that, CGAL does_self_intersect returns true. Is it normal? If not, What did I do wrong?
I noticed that I was using Simple_cartesian kernel, so I changed it with Exact_predicates_inexact_constructions_kernel.
Now, with those same parameters (target_edge_length = 0.05, nb_iter = 3) CGAL::Polygon_mesh_processing::does_self_intersect returns False
I am working on a program where I need to read ints from a file into an array and use the array to do work. not super complicated and shouldtm take next to no time at all.
i am still a student learning c++ and i've exhausted all my options trying to get this to function as I understand it.
The text file has 200 lines each line contains a int followed by a '\n' newline character.
When I read the file in the main function into an int it works as expected. when I pass the ifstream by reference into the function that does the exact same for loop it breaks giving me an uninitialized in as the only value.
#include<iostream> // required
#include<fstream>
#include<random>
#include<string>
using namespace std; // using standard namespace as for this entire program
void readNumbers(ifstream&, int[], int); // passing a input filestream by reference, c style array, and an integer for the array length
int totalInts(ifstream&); // this will read how many lines the file has
int main()
{
ifstream is("numbers.txt"); // this is the text file that we are reading from
int ar[200]; // the array of length 200 that everything will be read into
int temp; // temporary holding for our ints
if (!is) // error checking
cout << "somethings <expletive deleted>";
else {
for (int i = 0; i < 200; i++) // iterating through the file 200 times and inputting the int into the temp holding, this is being used to test if this method works as expected.
{
is >> temp;
cout << i << ' ' << temp << '\n'; // prints it out for troubleshooting
}
// cout << totalInts(is);
readNumbers(is, ar, 200);
}
return 0;
}
int totalInts(ifstream& file)
{
string i;
int intNum;
intNum = 0;
while (getline(file, i))
{
intNum++;
}
return intNum;
}
void readNumbers(ifstream &reading, int papi[], int rayLength) // where we really want to read the file
{
int temp; // for temp holding while we troubleshoot
if (!reading)
cout << "somethings fucked";
else
{
for (int i = 0; i < rayLength;i++) // reads the file for as many time as we have space in the array.
{
reading >> temp; // reads into temp
cout << temp; // outputs for troubleshooting
}
}
}
the program outputs below
0 41
1 485
2 340
3 526
4 188
5 739
6 489
7 387
8 988
9 488
10 710
11 173
12 304
13 843
14 970
15 491
16 997
17 953
18 831
19 441
20 423
21 618
22 905
23 153
24 292
25 394
26 438
27 734
28 737
29 914
30 452
31 747
32 785
33 549
34 870
35 931
36 692
37 325
38 52
39 903
40 731
41 834
42 353
43 363
44 690
45 668
46 156
47 718
48 281
49 874
50 572
51 671
52 694
53 789
54 57
55 871
56 731
57 750
58 556
59 778
60 328
61 38
62 212
63 843
64 288
65 136
66 49
67 950
68 283
69 670
70 473
71 828
72 905
73 735
74 394
75 365
76 21
77 132
78 417
79 551
80 648
81 635
82 108
83 973
84 774
85 851
86 970
87 383
88 944
89 334
90 960
91 471
92 650
93 334
94 542
95 559
96 134
97 84
98 951
99 557
100 837
101 146
102 643
103 687
104 726
105 939
106 990
107 308
108 704
109 408
110 26
111 773
112 950
113 91
114 276
115 834
116 803
117 588
118 102
119 528
120 10
121 303
122 170
123 654
124 377
125 791
126 678
127 589
128 35
129 64
130 377
131 151
132 957
133 745
134 979
135 433
136 138
137 221
138 25
139 348
140 472
141 299
142 780
143 393
144 959
145 917
146 241
147 767
148 245
149 606
150 428
151 970
152 533
153 43
154 429
155 197
156 900
157 623
158 780
159 656
160 427
161 365
162 651
163 557
164 569
165 489
166 622
167 45
168 605
169 374
170 301
171 866
172 383
173 31
174 600
175 45
176 375
177 222
178 687
179 508
180 289
181 738
182 53
183 1
184 444
185 965
186 906
187 791
188 145
189 467
190 731
191 907
192 672
193 505
194 824
195 423
196 324
197 623
198 835
199 523
-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460
E:\Github Repo's\assignment 3.2\Debug\assignment 3.2.exe (process 12832) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
as you can see the output for the first for loop is exactly as expected, however the function which has all the same functionality is not working and is showing an uninitialized int for temp.
this means that it is not reading from the ifstream which I passed to the function. so wrote another function that reads the file using a newly created ifstream as well as the passed ifstream and prints what is read from both streams.
totalInts(ifstream &file)
{
ifstream tester("numbers.txt");
string l,i;
int intNum;
intNum = 0;
for (int j = 0; j < 200; j++)
{
file >> l;
tester >> i;
intNum++;
cout << intNum << ' ' << i << ' ' << l << '\n';
}
file.close();
return intNum;
}
when this is used the output is as expected, so passing the ifstream as a param using reference is the issue, as when I make a new ifstream the program runs fine using that ifstream and reading the file as expected where as the passed ifstream shows no values read.
0 41
1 485
2 340
3 526
4 188
5 739
6 489
7 387
8 988
9 488
10 710
11 173
12 304
13 843
14 970
15 491
16 997
17 953
18 831
19 441
20 423
21 618
22 905
23 153
24 292
25 394
26 438
27 734
28 737
29 914
30 452
31 747
32 785
33 549
34 870
35 931
36 692
37 325
38 52
39 903
40 731
41 834
42 353
43 363
44 690
45 668
46 156
47 718
48 281
49 874
50 572
51 671
52 694
53 789
54 57
55 871
56 731
57 750
58 556
59 778
60 328
61 38
62 212
63 843
64 288
65 136
66 49
67 950
68 283
69 670
70 473
71 828
72 905
73 735
74 394
75 365
76 21
77 132
78 417
79 551
80 648
81 635
82 108
83 973
84 774
85 851
86 970
87 383
88 944
89 334
90 960
91 471
92 650
93 334
94 542
95 559
96 134
97 84
98 951
99 557
100 837
101 146
102 643
103 687
104 726
105 939
106 990
107 308
108 704
109 408
110 26
111 773
112 950
113 91
114 276
115 834
116 803
117 588
118 102
119 528
120 10
121 303
122 170
123 654
124 377
125 791
126 678
127 589
128 35
129 64
130 377
131 151
132 957
133 745
134 979
135 433
136 138
137 221
138 25
139 348
140 472
141 299
142 780
143 393
144 959
145 917
146 241
147 767
148 245
149 606
150 428
151 970
152 533
153 43
154 429
155 197
156 900
157 623
158 780
159 656
160 427
161 365
162 651
163 557
164 569
165 489
166 622
167 45
168 605
169 374
170 301
171 866
172 383
173 31
174 600
175 45
176 375
177 222
178 687
179 508
180 289
181 738
182 53
183 1
184 444
185 965
186 906
187 791
188 145
189 467
190 731
191 907
192 672
193 505
194 824
195 423
196 324
197 623
198 835
199 523
1 41
2 485
3 340
4 526
5 188
6 739
7 489
8 387
9 988
10 488
11 710
12 173
13 304
14 843
15 970
16 491
17 997
18 953
19 831
20 441
21 423
22 618
23 905
24 153
25 292
26 394
27 438
28 734
29 737
30 914
31 452
32 747
33 785
34 549
35 870
36 931
37 692
38 325
39 52
40 903
41 731
42 834
43 353
44 363
45 690
46 668
47 156
48 718
49 281
50 874
51 572
52 671
53 694
54 789
55 57
56 871
57 731
58 750
59 556
60 778
61 328
62 38
63 212
64 843
65 288
66 136
67 49
68 950
69 283
70 670
71 473
72 828
73 905
74 735
75 394
76 365
77 21
78 132
79 417
80 551
81 648
82 635
83 108
84 973
85 774
86 851
87 970
88 383
89 944
90 334
91 960
92 471
93 650
94 334
95 542
96 559
97 134
98 84
99 951
100 557
101 837
102 146
103 643
104 687
105 726
106 939
107 990
108 308
109 704
110 408
111 26
112 773
113 950
114 91
115 276
116 834
117 803
118 588
119 102
120 528
121 10
122 303
123 170
124 654
125 377
126 791
127 678
128 589
129 35
130 64
131 377
132 151
133 957
134 745
135 979
136 433
137 138
138 221
139 25
140 348
141 472
142 299
143 780
144 393
145 959
146 917
147 241
148 767
149 245
150 606
151 428
152 970
153 533
154 43
155 429
156 197
157 900
158 623
159 780
160 656
161 427
162 365
163 651
164 557
165 569
166 489
167 622
168 45
169 605
170 374
171 301
172 866
173 383
174 31
175 600
176 45
177 375
178 222
179 687
180 508
181 289
182 738
183 53
184 1
185 444
186 965
187 906
188 791
189 145
190 467
191 731
192 907
193 672
194 505
195 824
196 423
197 324
198 623
199 835
200 523
E:\Github Repo's\assignment 3.2\Debug\assignment 3.2.exe (process 24600) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
If this was up to me I would just be passing the filename through to the functions as a string param and making new ifstreams in these functions to get the thing to work, however the requirement for this is to have ad least one function that passes an ifstream through reference and utilize it. however after lots of troubleshooting and reading stackexange posts on the topic I cannot get it to function as expected.
what am I doing wrong?
any help would be appreciated.
I have an input in format as shown in below Image.I am using the vector graph[200] to read input. Let's suppose program read first number of first row and column (as shown in Image) . Now I want to add all vertices which is connected to first node like graph[1].push_back(next integer in same row) and so on . But when should I stop reading input for particular Node(graph[i]). Because after reading first row I need to add vertices into another graph[i+1] to node's corresponding list . If you don't understand my questions plz have a look to my code.
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[201];
int main()
{
int n=2,i,node,temp;
for(i=1;i<=n;i++)
{
cin>>node;
while(scanf("%d",&temp)!=EOF/*What is the correct conditon to stop loop*/)
{
graph[node].push_back(temp);
}
}
return 0;
}
Input format :
1 37 79 164 155 32 87 39 113 15 18 78 175 140 200 4 160 97 191 100 91 20 69 198 196
20 123 134 10 141 13 12 43 47 3 177 101 179 77 182 117 116 36 103 51 154 162 128 30
3 48 123 134 109 41 17 159 49 136 16 130 141 29 176 2 190 66 153 157 70 114 65 173 104 194 54
14 91 171 118 125 158 76 107 18 73 140 42 193 127 100 84 121 60 81 99 80 150 55 1 35 23 93
5 193 156 102 118 175 39 124 119 19 99 160 75 20 112 37 23 145 135 146 73 35
60 155 56 52 120 131 160 124 119 14 196 144 25 75 76 166 35 87 26 20
7 156 185 178 79 27 52 144 107 78 22 71 26 31 15 56 76 112 39 8 113 93
8 185 155 171 178 108 64 164 53 140 25 100 133 9 52 191 46 20 150 144 39 62 131 42 119 127 31 7
9 91 155 8 160 107 132 195 26 20 133 39 76 100 78 122 127 38 156 191 196
10 190 184 154 49 2 182 173 170 161 47 189 101 153 50 30 109 177 148 179 16 163 116 13 90 185
111 123 134 163 41 12 28 130 13 101 83 77 109 114 21 82 88 74 24 94 48 33
12 161 109 169 21 24 36 65 50 2 101 159 148 54 192 88 47 11 142 43 70 182 177 179 189 194 33
13 161 141 157 44 83 90 181 41 2 176 10 29 116 134 182 170 165 173 190 159 47 82 111 142 72 154 110 21 103 130 11 33 138 152
and so on...
Here is the screenshot of my input format
Assuming you want to read line-by-line basis, you could do following:
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[201];
int main(){
string line;
int n=2,i,node,temp;
for(i=1;i<=n;i++){
getline(cin, line);
istringstream in( line );
in>>node;
while(in>>temp){
graph[node].push_back(temp);
}
}
return 0;
}
When I try to print a really long array, it gets cut off at a certain length
[-1 -40 -1 -32 0 16 74 70 73 70 0 1 1 0 0 1 0 1 0 0 -1
-37 0 67 0 8 6 6 7 6 5 8 7 7 7 9 9 8 10 12 20 13 12 11
11 12 25 18 19 15 20 29 26 31 30 29 26 28 28 32 36 46 39
32 34 44 35 28 28 40 55 41 44 48 49 52 52 52 31 39 57 61
56 50 60 46 51 52 50 -1 -37 0 67 1 9 9 9 12 11 12 ...]
I would like it not to do that if I'm persisting a data structure to file. How can this be done?
The special variable *print-length* determines how much of a given structure is printed. Like any other dynamic var, you can use binding to set its value in a block.
user> (binding [*print-length* 2] (prn (range 200)))
(0 1 ...)
nil
user> (binding [*print-length* nil] (prn (range 200)))
(0 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)
nil