Section 4 - A Pseudo-Datamatrix Class (Optional)

This section is optional. Ultimatly, it will be replaced by sections 6B.5 through 6B.7. You may proceed directly to those if you wish.

6B.4.1 A Strategy for the Solution Barcode Classes

We are ready for the actual class or classes that will be derived from BarcodeIO and contain, as an internal member object, a BarcodeImage.  Before we jump in and start creating this class, let's think about what its purpose is?  Are we ready to implement a specific barcode symbology like Datamatrix, or pdf-417

Maybe not.  A lot of the things we want to do next would apply to any symbology.  So a good design should subclass from BarcodeIO with an embedded string and BarcodeImage members into a new base class called ImageReaderWriter that does things like print a label and read in a label.  What we should not be doing at this level of abstraction is converting the image to text or vice versa, since that is symbology-dependent.  From the recommended ImageReaderWriter, we would subclass specific symbology classes.  When you think about it, you might ask what to do with the two interface methods, generateImageFromText() and translateImageToText().  They don't quite have an obvious place in ImageReaderWriter, since we need a symbology for their implementation.  However, we can give abstract and generic shells for these methods and require the subclasses do the implementation.

Anyway, the structure should be something like this:

second cass diag

The word "implements" above is Java-speak, and it is used because I made this scruffy picture originally for my CIS 27B class, way back.  Here it means that we would subclass BarcodeIO, defining some, but not all, virtual functions.  This is what it should look like.  What we will do, however, is skip the general base class ImageReaderWriter and go directly, instead, to DataMatrix.  This is to keep the example and assignment manageable.  So here is the diagram we will follow:

class pic 2

6B.4.2 The Target Class, DataMatrix

This class is a pseudo Datamatrix data structure, not a true Datamatrix implementation, because it does not contain any of the error correction or encoding in a real Datamatrix.  However, it does have the 2D array format and a left and bottom BLACK edge and an alternating right and top BLACK-WHITE pattern as seen in prior pages.

   DataMatrix Data

Note that there is no deep data here.

   DataMatrix Methods

Other Considerations for DataMatrix

As you can tell, the implementation of this is going to be your assignment this week.  I have provided some significant structure and also a lot of useful code that you can steal from the TwoDimImage class.

Do this one step-at-a-time, following my outline and also digesting what you are doing and why you are doing it at each juncture. I am here for questions, as usual.

6B.4.3  A Sample Main()

Here is a main() to use as a test of your code.  You should create simpler main()s as you work your way up to this:

int main()
{
string sImageIn[13] =
{
"                                                      ",
"                                                      ",
"                                                      ",
"* * * * * * * * * * * * * * * * * * * * * * * * * * * ",
"*                                                    *",
"**********   *** *********** * ****** **** *********  ",
"* *********** ****************************************",
"*     * *    * *   *     *     *    *          * *    ",
"*  *      *  **  ** * * *         ***  ***  * * * ** *",
"* ***   ***   **  * ********    * **   ***  ***  * *  ",
"**   **   *   *         *      *      ***    ***     *",
"*** *  * *   *** **  ***  *  *  **  * ***  * ** *  ** ",
"******************************************************"
};

string sImageIn_2[12] =
{
"                                      ",
"                                      ",
"* * * * * * * * * * * * * * * * * * * ",
"*                                    *",
"**** * * ******** ** ****** *** ****  ",
"* ******************* **********    **",
"*    *** *      * *  *   *  *   *  ** ",
"* *  *     * *     *   **    *      **",
"** *   *  **** *  **  ***** * * *   * ",
"*        *    * *  * *  **        ****",
"* *  * *  **** *   *  *** *   *  * ** ",
"**************************************"
};

BarcodeImage bc(sImageIn, 13);
DataMatrix dm(bc);

// First secret message
dm.translateImageToText();
dm.displayTextToConsole();
dm.displayImageToConsole();

// second secret message
bc = BarcodeImage(sImageIn_2, 12);
dm.scan(bc);
dm.translateImageToText();
dm.displayTextToConsole();
dm.displayImageToConsole();

// create your own message
dm.readText("CS 2B rocks more than Zeppelin");
dm.generateImageFromText();
dm.displayTextToConsole();
dm.displayImageToConsole();

return 0;
}