Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |
 User Name: Password: Remember me

New Free Tools on Dev Shed!
We're Excited to announce that Dev Shed now has 70 free tools on the site. To learn more, click here!

 Dev Shed Forums Sponsor:
#1
September 5th, 2013, 07:15 AM
 h4ever
Registered User

Join Date: Jan 2011
Posts: 20
Time spent in forums: 5 h 34 m 40 sec
Reputation Power: 0

Hi,
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[1][23] ... 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.

#2
September 5th, 2013, 02:21 PM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,858
Time spent in forums: 3 Months 1 Day 5 h 51 m 7 sec
Reputation Power: 2199
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.

#3
September 6th, 2013, 03:46 AM
 h4ever
Registered User

Join Date: Jan 2011
Posts: 20
Time spent in forums: 5 h 34 m 40 sec
Reputation Power: 0

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:

Code:
```        // 1 - y row    0 - line number
resultsArr[1][groupNum][0][x1]={
x2, // this is the upper limit of the black line
byteArray // keeps color in BGR
}```

And I want them to move the elements (delete and add)
under

Code:
`resultsArr[1][groupNum][0][0]`

to the following sub array:

Code:
```        // 1 - y row    0 - line number
resultsArr[1][groupNum][0][1]={
x2,
byteArray
}```

which way to copy and delete should I use?

To copy should I use
resultsArr[1][groupNum][0][1]=resultsArr[1][groupNum][1][0]

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

resultsArr[1][groupNum][0][0]=null
or this
resultsArr[1][groupNum][0][0]=0
or
delete resultsArr[1][groupNum][0][0]
?

As during declaration of multidimensional array, Do I must declare type for every level of array?

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Access to array (C++)

## Developer Shed Advertisers and Affiliates

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |