IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New What's the best way to do this? Loop or do a block 1 time.
Hi,

This is probably a simple question, but I'm stumped. I'm a C/C++ novice.

I'm modifying a Borland C++ Builder program to plot a bitmap of maps of up to 25 sets data. When the data are plotted to the screen, the maps are scaled and shown for a single data set, one at a time, based on the user's choice of map to show. When the data are printed, up to 25 of the maps are scaled and printed together on one piece of paper.

I can get both types of plotting/printing to work fine - individually. I'd like to come up with some sort of construct that will let me do something like:

\nif (hardcopy == true) // we're printing all the maps on 1 page\n{\n   for (int k=0; k < 25; k++)\n   {\n      ((do lots of stuff to construct the maps))\n   }\n   (do the stuff to send the page to the printer)\n}\nelse // displaying a single map on the screen\n{\n   k = SelectedMap;\n   ((do the stuff to construct the single map))\n   (display the map on the screen)\n}\n


without duplicating so much code in the (( )) block.

How can I construct the code so that if (hardcopy == true) it loops but if (hardcopy == false) then it only uses a single supplied index? I think I want something like a combined if statement with a for loop as a single condition statement, but I don't know of a way to do that.

Thanks very much for any pointers.

Cheers,
Scott.
New Query...how different is it
to do one item vs several?

ie: is it possible to create two functions
function a(map, item) (( does stuff ))
and
function b(map, vector<items>)
{
    for (i = vector<items>.begin(); i != vector<items>.end(); i++)
    {
        function a(map, *i)
    }
}
New There's almost no difference. 1 potential rub though.
The information is the same in both cases, only the scaling of the images, and the position of the image on the page changes. After that, the details of constructing the bitmap to the screen or printing is slightly different.

I'll have to think on your suggestion some more. I've not seen constructions like that before. It looks promising at first blush.

Thanks!

[edit:] One complication is that the bitmaps are fairly large, and I need to also be able to save them at fairly high resolution. At the moment, the screen bitmap is 1392w x 1800h. The printer bitmap depends on the printer (and is read by Windows), but is larger.

I ended up going this route (of showing and saving individual maps) because I wasn't able to figure out a way to save up to 25 of these maps with high enough resolution to be useful without hitting the "JPEG Error #36" error that strikes when the jpeg is 1-2 MB in size. Different jpeg libraries don't have this error, but they introduce other problems (the code isn't mine and I don't want to introduce other dependencies). Plus, it's better to save the figures as separate jpegs anyway.

Based on the fact that the "canvas"es are different for the screen and the printer, I don't think I can make the two functions you propose totally separate. But I'm still thinking on it.

Cheers,
Scott.
Expand Edited by Another Scott Dec. 6, 2006, 01:27:24 PM EST
New Should you be using Jpeg to save the data at all?
It's a lossy compression algo, which means that if you're using them to keep the maps between runs of the program, you might be losing your data too.
New They're just pictures for pasting in documents.
I'm able to set the jpeg quality at 100% so there's no compression (unless the Error 36 bites) and it looks pretty good even when expanded some.

Borland C++ Builder 5 only has graphics routines for .jpeg .bmp (and similar). Saving the images as an uncompressed bitmap is very wasteful for what we're doing (e.g. 10 MB .bmp versus 434 kB for 100% quality .jpeg). More graphics formats would be nice, but we don't want to upgrade, etc.

Thanks.

Cheers,
Scott.
(Who is thinking about trying to port this to Python as a tutorial when/if he gets a chance.)
New May not be what you need...
for (int k=0; k < (hardcopy:25?0); k++) { ... }

Not necessarily what you want, but it's probably a strict interpretation of what you are asking for.
New Neat. I'll have to try that. Thanks!
New From a purist standpoint...
...you'd rather use a foreach type of iteration rather than an index counter. In that case, you collection would either be 1 in length or 25 in length, and the foreach iterator would simply run through the collection one by one - i.e. it wouldn't care whether it be one in length or a thousand.
Expand Edited by ChrisR Dec. 6, 2006, 04:19:47 PM EST
New I appreciate elegant solutions, but ...
your [link|http://mathbits.com/MathBits/CompSci/looping/operator2.htm|Conditional Operator] solution was perfect.

It works!

I just have a couple of final things to clean up, then it'll be done.

\n   for (int k=0; k <= (hardcopy ? (MaxHeader-1) : 0); k++)\n   {\n   // Immediately check to see if this is only a single map.\n      if (!hardcopy) k = SelectedHeader;\n      \n      (( lots of other stuff))\n      \n   }\n


I had to add the equality to the for statement, otherwise the loop doesn't execute if I'm not printing. That meant that the end count had to be adjusted too.

Thanks very much for your help! I never would have figured this out without a pointer. :-)

Cheers,
Scott.
New A seasoned C guy
would leave the conditions as

for (int k=0; k < (hardcopy ? (MaxHeader) : 1); k++)

Less operations and more like the usual array traversal where to traverse n elements you say
for(int i = 0; i < n; ++i)



[link|http://www.blackbagops.net|Black Bag Operations Log]

[link|http://www.objectiveclips.com|Artificial Intelligence]

[link|http://www.badpage.info/seaside/html|Scrutinizer]
New Ah, so! Thanks.
     What's the best way to do this? Loop or do a block 1 time. - (Another Scott) - (10)
         Query...how different is it - (Simon_Jester) - (3)
             There's almost no difference. 1 potential rub though. - (Another Scott) - (2)
                 Should you be using Jpeg to save the data at all? - (jake123) - (1)
                     They're just pictures for pasting in documents. - (Another Scott)
         May not be what you need... - (ChrisR) - (5)
             Neat. I'll have to try that. Thanks! -NT - (Another Scott) - (4)
                 From a purist standpoint... - (ChrisR) - (3)
                     I appreciate elegant solutions, but ... - (Another Scott) - (2)
                         A seasoned C guy - (tuberculosis) - (1)
                             Ah, so! Thanks. -NT - (Another Scott)

What was that "kneejerk" emoticon again?
133 ms