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
the problem is in the int main()
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
using namespace std;
const int R = 15;
const int C = 20;
void clearArray(int arr[R][C])
{
for (int i = 0; i < R; i++)
{
for (int j = 0; j < C; j++)
{
arr[i][j] = 0;
}
}
}
void makeSpiral(int arr[R][C],int r , int c)
{
int i, a = 0, b = 0;
int value = 1;
while (a < r && b < c)
{
for (i = a; i < r; ++i)
{
arr[i][b] = value++;
}
b++;
for (i = b; i < c; ++i)
{
arr[r - 1][i] = value++;
}
r--;
if (a < r)
{
for (i = r - 1; i >= a; --i)
{
arr[i][c-1] = value++;
}
c--;
}
if (b < c)
{
for (i = c - 1; i >= b; --i)
{
arr[a][i] = value++;
}
a++;
}
}
}
void printSpiral(int arr[R][C],int r , int c, char str[])
{
str[30];
ofstream fout;
fout.open(str, ios::out | ios::app);
if (!fout)
{
cout << "Error: file could not be opened" << endl;
exit(1);
}
fout << endl;
fout << "---------------------------------------------";
for (int i = 0; i < r; i++)
{
fout << endl;
for (int j = 0; j < c; j++)
{
fout <<setw(5)<< arr[i][j] << " ";
}
}
fout.close();
}
int main(int argc, char *argv[])
{
char str[30];
ofstream fout;
int r,c;
int i,j,t;
int arr[R][C];
if (argc < 2)
{
cout << "Error missing file name!" << endl;
return -1;
}
strcpy(str, argv[1]);
int matrix [R][C] = {{1,1},{2,2},{3,3},{4,4},{5,5},{4,7},{7,4},{15,20}};
for (i = 0 ; i < 8 ; i++)
{
clearArray(matrix);
makeSpiral(matrix,R,C);
printSpiral (matrix,R,C,str);
}
return 0;
}
I'm a new C++ programmer please go easy on me. So i have this piece of code, the professor requires me to store corner sizes of a spiral matrix into a table, then use a loop to call out my functions so i don't have to call my functions repeatedly like this:
clearArray(matrix);
makeSpiral(matrix,1,1);
printSpiral (matrix,1,1,str);
clearArray(matrix);
makeSpiral(matrix,2,2);
printSpiral (matrix,2,2,str);
clearArray(matrix);
makeSpiral(matrix,3,3);
printSpiral (matrix,3,3,str);
clearArray(matrix);
makeSpiral(matrix,4,4);
printSpiral (matrix,4,4,str);
I want to print a counter-clockwise matrix 8 times which with corner 1 by 1 ; 2 by 2; 3 by 3; 4 by 4; 5 by 5; 4 by 7; 7 by 4; and 15 by 20.
My code doesn't give me the correct output, can you tell me where I did wrong, thank you!
The output that i supposed to have
---------------------------------
1
---------------------------------
1 3
---------------------------------
3
2
---------------------------------
1 4
2 3
---------------------------------
1 8 7
2 9 6
3 4 5
---------------------------------
1 12 11 10
2 13 16 9
3 14 15 8
4 5 6 7
---------------------------------
1 16 15 14 13
2 17 24 23 12
3 18 25 22 11
4 19 20 21 10
5 6 7 8 9
---------------------------------
1 18 17 16 15 14 13
2 19 28 27 26 25 12
3 20 21 22 23 24 11
4 5 6 7 8 9 10
---------------------------------
1 18 17 16
2 19 28 15
3 20 27 14
4 21 26 13
5 22 25 12
6 23 24 11
7 8 9 10
---------------------------------
1 20 19 18 17 16 15 14
2 21 32 31 30 29 28 13
3 22 23 24 25 26 27 12
4 5 6 7 8 9 10 11
---------------------------------
1 16 15 14
2 17 24 13
3 18 23 12
4 19 22 11
5 20 21 10
6 7 8 9
What my code output looks like:
---------------------------------------------------------
1 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48
2 67 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 47
3 68 125 174 173 172 171 170 169 168 167 166 165 164 163 162 161 160 107 46
4 69 126 175 216 215 214 213 212 211 210 209 208 207 206 205 204 159 106 45
5 70 127 176 217 250 249 248 247 246 245 244 243 242 241 240 203 158 105 44
6 71 128 177 218 251 276 275 274 273 272 271 270 269 268 239 202 157 104 43
7 72 129 178 219 252 277 294 293 292 291 290 289 288 267 238 201 156 103 42
8 73 130 179 220 253 278 295 296 297 298 299 300 287 266 237 200 155 102 41
9 74 131 180 221 254 279 280 281 282 283 284 285 286 265 236 199 154 101 40
10 75 132 181 222 255 256 257 258 259 260 261 262 263 264 235 198 153 100 39
11 76 133 182 223 224 225 226 227 228 229 230 231 232 233 234 197 152 99 38
12 77 134 183 184 185 186 187 188 189 190 191 192 193 194 195 196 151 98 37
13 78 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 97 36
14 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 35
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
------------------------------------------------------------
1 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48
2 67 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 47
3 68 125 174 173 172 171 170 169 168 167 166 165 164 163 162 161 160 107 46
4 69 126 175 216 215 214 213 212 211 210 209 208 207 206 205 204 159 106 45
5 70 127 176 217 250 249 248 247 246 245 244 243 242 241 240 203 158 105 44
6 71 128 177 218 251 276 275 274 273 272 271 270 269 268 239 202 157 104 43
7 72 129 178 219 252 277 294 293 292 291 290 289 288 267 238 201 156 103 42
8 73 130 179 220 253 278 295 296 297 298 299 300 287 266 237 200 155 102 41
9 74 131 180 221 254 279 280 281 282 283 284 285 286 265 236 199 154 101 40
10 75 132 181 222 255 256 257 258 259 260 261 262 263 264 235 198 153 100 39
11 76 133 182 223 224 225 226 227 228 229 230 231 232 233 234 197 152 99 38
12 77 134 183 184 185 186 187 188 189 190 191 192 193 194 195 196 151 98 37
13 78 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 97 36
14 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 35
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
---------------------------------------------------------
1 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48
2 67 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 47
3 68 125 174 173 172 171 170 169 168 167 166 165 164 163 162 161 160 107 46
4 69 126 175 216 215 214 213 212 211 210 209 208 207 206 205 204 159 106 45
5 70 127 176 217 250 249 248 247 246 245 244 243 242 241 240 203 158 105 44
6 71 128 177 218 251 276 275 274 273 272 271 270 269 268 239 202 157 104 43
7 72 129 178 219 252 277 294 293 292 291 290 289 288 267 238 201 156 103 42
8 73 130 179 220 253 278 295 296 297 298 299 300 287 266 237 200 155 102 41
9 74 131 180 221 254 279 280 281 282 283 284 285 286 265 236 199 154 101 40
10 75 132 181 222 255 256 257 258 259 260 261 262 263 264 235 198 153 100 39
11 76 133 182 223 224 225 226 227 228 229 230 231 232 233 234 197 152 99 38
12 77 134 183 184 185 186 187 188 189 190 191 192 193 194 195 196 151 98 37
13 78 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 97 36
14 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 35
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
--------------------------------------------------------
......
It prints the 15x20 corner size 8 times.
In your main function, arguments to makeSpiral are fixed R and C. This means makeSpiral always tries to fill a 15 rows, 20 columns spiral matrix to your matrix:
makeSpiral(matrix,R,C);
printSpiral(matrix,R,C,str);
You may want this instead:
int matrix[R][C]; // no need of initialization
int matrixSize[8][2] = {{1,1},{2,2},{3,3},{4,4},{5,5},{4,7},{7,4},{15,20}};
for (i = 0 ; i < 8 ; i++) {
clearArray(matrix, matrixSize[i][0], matrixSize[i][1]);
makeSpiral(matrix, matrixSize[i][0], matrixSize[i][1]);
printSpiral (matrix, matrixSize[i][0], matrixSize[i][1], str);
}
Here you use an assist matrixSize to store expected matrix sizes. Within the for loop makeSpiral will fill matrixSize[i][0] rows, matrixSize[i][1] columns only, so does printSpiral.
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;
}
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.
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