September 5th, 2013, 06:15 AM
Access to array (C++)
I am just starting to learn C++ and I need to ask you. Is it possible to create array or object where I could create element under index starting not from zero but e.g. 25?
Situation which I want to describe. I have image with white background. First row contains few pixels in black color. There are pixels (x coord) 23, 24 and 25 are black. There can be also some other black areas, but let's suppose 26 is white. According formula Iyn=[x1,x2] I want to get the lower value (x1) of the limit and the upper value (x2). So I want to make method to get ( in this particular case the limit Iyn=[23,25] ) .
(Illustration of the black pixels in the image row 1-5, up to column 26; the grid illustrates the positions of the pixels; the pixels are the big black blots)
I would like to do it like so:
I plan to read image row by row (or column by column). For every row I would like to use for loop to analyse whether the previous pixel has same color (*) - if yes, then set a value in array. However to have efficient performance I need this direct access. So if I analyse row=1 and found that pixel with coord x=25 is same color like the previous pixel (x=24), later I wound need to access it directly by value 25. If I found that the next pixel does not contain same color so I would save the lower limit x1 into the array myarr[y][x1]=x2.
I know that C++ makes arrays starting from index 0 and probably this is not possible to do by array, but maybe some kind of object? The reason why I want to do so is that later, when I would want to use the array to analyse the groups (black lines), I would need to compare pixel from previous row and group (e.g. first row and first black line) with the actual row (e.g. second row and first line in this row). In the case that they are same color, I would simply join the one group with the second group (So I would found that these two lines from different rows are common area, black shape or rectangle). When doing this comparison it would be much more faster to make condition testing access to certain element like myarr ... if true, then ok, these lines are together. If this element does not exist, than it means, that there is different color...
I tried to explain this as simple as possible, I hope you can understand what I try to do.
* Notes - I can make method to compare with a fuzz, so the goal for comparison method would be to find similar color, which has certain fuzz. But for simplicity of this example, lets use just two colors.
September 5th, 2013, 01:21 PM
Yes. Create a class. It would contain a standard zero-base array. It would also overload the  operator which would take the 25-to-whatever index that you're working in and translate it to the zero-base index to access the actual array. I believe that you should be able to find many examples floating about cyber-space.
September 6th, 2013, 02:46 AM
Yet one more question regarding moving of data from one array to another subarray.
Lets suppose I have one group of pixels (as a result) saved in array:
And I want them to move the elements (delete and add)
// 1 - y row 0 - line number
x2, // this is the upper limit of the black line
byteArray // keeps color in BGR
to the following sub array:
which way to copy and delete should I use?
// 1 - y row 0 - line number
To copy should I use
or some sophisticated method to copy objects before I delete the original? Here I am not sure if should I use handler or not when I could want to copy the array.
And the, should I delete the original like this
As during declaration of multidimensional array, Do I must declare type for every level of array?