Форум » C/C++ для начинающих (C/C++ for beginners) » split a 2D vector based on (x & y) coordinates » Ответить

split a 2D vector based on (x & y) coordinates

ramees: i need a class with functionality like group an area of a 2D vector based on coordinate (x & y ) eg: this is my 2D vector values 54 , 78 , 89 , 25 , 45 12 , 45 , 45 , 45 , 45 54 , 78 , 89 , 25 , 45 12 , 45 , 45 , 45 , 45 54 , 78 , 89 , 25 , 45 12 , 45 , 45 , 45 , 45 so in this case 2D vector coordinate look like this 01 , 02 , 03 , 04 , 05 06 , 07 , 08 , 09 , 10 11 , 12 , 13 , 14 , 15 16 , 17 , 18 , 19 , 20 21 , 22 , 23 , 24 , 25 26 , 27 , 28 , 29 , 30 you can see red number in coordinate if i input that value to class or function i need to split that area for later calculation , edit value or remove also print edited 2D vector completely how can i done this split-ed area 07,08,09 12,13,14,15 17,18,19 22,23,24

Ответов - 6

Сыроежка: I do not know a ready to use implementation of such a class. So you should either write the class yourself or maybe direct your attention to some free matrix software where such functionality is already realized. Unfortunately I did not deal with such a software.

ramees: what u mean by free matrix software its a library of code like open cv . can u show me a reference site

Сыроежка: All was done before us.:) i think that the similar task was already done by someone and I suppose that there might be an open source project. I was not interested in such a task so I am unable to point out the free software where the similar class is already written. If you need a ready to use program then you should search the internet and ask the question in other forums. Maybe somebody will help you.


ramees: ok thanks

Сыроежка: As i see nobody helped you at stackoverflow The task conld be simpler if the selected numbers would not specify ranges as in this row from your example 11 , 12 , 13 , 14 , 15 That is instead of 12, 13, 14, 15 you were to get only elements with indices 12 and 15. In this case the straightforward approach could look the following way [pre2] #include <iostream> #include <vector> #include <iterator> int main() { std::vector<std::vector<int>> v = { { 54 , 78 , 89 , 25 , 45 }, { 12 , 45 , 45 , 45 , 45 }, { 54 , 78 , 89 , 25 , 45 }, { 12 , 45 , 45 , 45 , 45 }, { 54 , 78 , 89 , 25 , 45 }, { 12 , 45 , 45 , 45 , 45 } }; for ( const std::vector<int> &v1 : v ) { for ( int x : v1 ) std::cout << x << ' '; std::cout << std::endl; } std::cout << std::endl; size_t a[] = { 7, 8, 9, 12, 17, 19, 22, 23, 24 }; std::vector<std::vector<int>> v2; size_t *p = a; std::vector<int>::size_type n = 1; for ( const std::vector<int> &v1 : v ) { std::vector<int> tmp; std::vector<int>::size_type i = 0; for ( ; i < v1.size(); i++ ) { if ( ( p != std::end( a ) ) && ( i + n == *p ) ) { tmp.push_back( v1 ); ++p; } } n += i; if ( !tmp.empty() ) v2.push_back( tmp ); } for ( const std::vector<int> &v1 : v2 ) { for ( int x : v1 ) std::cout << x << ' '; std::cout << std::endl; } std::cout << std::endl; return 0; } [/pre2] The output is [pre2] 54 78 89 25 45 12 45 45 45 45 54 78 89 25 45 12 45 45 45 45 54 78 89 25 45 12 45 45 45 45 45 45 45 78 45 45 78 89 25 [/pre2] It is not what you want to get but it is close to the aim.

ramees: i know no one going to help in stackoverflow because this task is little big i think , but i sure i will get sum clue about it . i really appreciate your help thank u , all i wants a shape now i got it i will complete this code



полная версия страницы