E57 Foundation API v1.1.312  Aug. 10, 2011
Functions
examples/ImageFileDump.cpp File Reference

example: print diagnostics about an ImageFile and other objects More...

Include dependency graph for ImageFileDump.cpp:

Functions

int main (int, char **)
 Example use of various dump functions.

Detailed Description

example: print diagnostics about an ImageFile and other objects

Also see listing at end of this page for source without line numbers (to cut&paste from).

00001 /*** ImageFileDump.cpp example: print diagnostics about an ImageFile and other objects */
00004 #include <iostream>
00005 #include "E57Foundation.h"
00006 using namespace e57;
00007 using namespace std;
00008 
00010 int main(int /*argc*/, char** /*argv*/) {
00011     try {
00012         ImageFile imf("temp._e57", "w");
00013         StructureNode root = imf.root();
00014 
00015         // Add three elements: /child1, /child1/grandchild, /child2
00016         cout << "================" << endl;
00017         StructureNode child1  = StructureNode(imf);
00018         StructureNode child2  = StructureNode(imf);
00019         StringNode grandchild = StringNode(imf, "I'm a grandchild");
00020         root.set("child1", child1);
00021         root.set("child2", child2);
00022         child1.set("grandchild", grandchild);
00023         cout << "root node:" << endl;
00024         root.dump(4);
00025 
00026         cout << "================" << endl;
00027         Node n = root.get("child2");
00028         cout << n.pathName() << " generic Node:" << endl;
00029         n.dump(4);
00030 
00031         // Create vector /exampleVector, with 2 child elements
00032         cout << "================" << endl;
00033         VectorNode v(imf, false);
00034         root.set("exampleVector", v);
00035         v.append(IntegerNode(imf, 100));
00036         v.append(IntegerNode(imf, 101));
00037         cout << v.pathName() << " VectorNode:" << endl;
00038         v.dump(4);
00039 
00040         cout << "================" << endl;
00041         IntegerNode iNode(imf, 100);
00042         root.set("exampleInteger", iNode);
00043         cout << iNode.pathName() << " IntegerNode:" << endl;
00044         iNode.dump(4);
00045 
00046         cout << "================" << endl;
00047         ScaledIntegerNode si(imf, 123, 0, 1023, .001, 100.0);
00048         root.set("si1", si);
00049         cout << si.pathName() << " ScaledIntegerNode:" << endl;
00050         si.dump(4);
00051 
00052         cout << "================" << endl;
00053         FloatNode f(imf, 123.45F);
00054         root.set("f1", f);
00055         cout << f.pathName() << " FloatNode:" << endl;
00056         f.dump(4);
00057 
00058         cout << "================" << endl;
00059         StringNode s(imf, "a random string");
00060         root.set("s1", s);
00061         cout << s.pathName() << " StringNode:" << endl;
00062         s.dump(4);
00063 
00064         cout << "================" << endl;
00065         const int blobLength = 10;
00066         static uint8_t buf[blobLength] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
00067         BlobNode b = BlobNode(imf, blobLength);
00068         root.set("blob1", b);
00069         b.write(buf, 0, blobLength);
00070         cout << b.pathName() << " BlobNode:" << endl;
00071         b.dump(4);
00072 
00073         cout << "================" << endl;
00074         StructureNode prototype(imf);
00075         prototype.set("cartesianX", FloatNode(imf));
00076         prototype.set("cartesianY", FloatNode(imf));
00077         prototype.set("cartesianZ", FloatNode(imf));
00078         
00079         VectorNode codecs(imf, true);
00080 
00081         CompressedVectorNode cv(imf, prototype, codecs);
00082         root.set("points", cv);
00083 
00084         const int N = 4;
00085         static double cartesianX[N] = {1.0, 2.0, 3.0, 4.0};
00086         static double cartesianY[N] = {1.1, 2.1, 3.1, 4.1};
00087         static double cartesianZ[N] = {1.2, 2.2, 3.2, 4.2};
00088         vector<SourceDestBuffer> sourceBuffers;
00089         sourceBuffers.push_back(SourceDestBuffer(imf, "cartesianX",  cartesianX,  N));
00090         sourceBuffers.push_back(SourceDestBuffer(imf, "cartesianY",  cartesianY,  N));
00091         sourceBuffers.push_back(SourceDestBuffer(imf, "cartesianZ",  cartesianZ,  N));
00092 
00093         {
00094             CompressedVectorWriter writer = cv.writer(sourceBuffers);
00095             writer.write(N);
00096 
00097             cout << "CompressedVectorWriter:" << endl;
00098             writer.dump(4);
00099         }
00100 
00101         cout << "================" << endl;
00102         cout << cv.pathName() << " CompressedVectorNode:" << endl;
00103         cv.dump(4);
00104 
00105         cout << "================" << endl;
00106         imf.extensionsAdd("ext1", "http://www.example.com/MyExtension1");
00107         root.set("ext1:greeting", StringNode(imf, "Hello world."));
00108         cout << imf.fileName() << " ImageFile:" << endl;
00109         imf.dump(4);
00110 
00111         imf.close(); // don't forget to explicitly close the ImageFile
00112     } catch(E57Exception& ex) {
00113         ex.report(__FILE__, __LINE__, __FUNCTION__);
00114         return(-1);
00115     }
00116 
00117     try {
00118         ImageFile imf("temp._e57", "r");
00119         StructureNode root = imf.root();
00120 
00121         CompressedVectorNode cv = static_cast<CompressedVectorNode> (root.get("points"));
00122 
00123         const int N = 2;
00124         static double cartesianX[N];
00125         static double cartesianY[N];
00126         static double cartesianZ[N];
00127         vector<SourceDestBuffer> destBuffers;
00128         destBuffers.push_back(SourceDestBuffer(imf, "cartesianX", cartesianX, N));
00129         destBuffers.push_back(SourceDestBuffer(imf, "cartesianY", cartesianY, N));
00130         destBuffers.push_back(SourceDestBuffer(imf, "cartesianZ", cartesianZ, N));
00131 
00132         cout << cv.pathName() << " has " << cv.childCount() << " child elements" << endl;
00133         if (cv.prototype().type() != E57_STRUCTURE)
00134             return(-1);
00135         StructureNode prototype = static_cast<StructureNode>(cv.prototype());
00136         cout << "The prototype has " << prototype.childCount() << " child elements" << endl;
00137         {
00138             CompressedVectorReader reader = cv.reader(destBuffers);
00139             
00140             uint64_t totalRead = 0;
00141             unsigned nRead = 0;
00142             while ((nRead = reader.read(destBuffers)) > 0) {
00143                 cout << "Got " << nRead << " points" << endl;
00144                 for (unsigned i = 0; i < nRead; i++) {
00145                     cout << "point " << totalRead + i << endl;
00146                     cout << "  cartesianX = " << cartesianX[i] << endl;
00147                     cout << "  cartesianY = " << cartesianY[i] << endl;
00148                     cout << "  cartesianZ = " << cartesianZ[i] << endl;
00149                 }
00150                 totalRead += nRead;
00151 
00152             }
00153             cout << "================" << endl;
00154             cout << "CompressedVectorReader:" << endl;
00155             reader.dump(4);
00156 
00157             reader.close(); // don't forget to explicitly close the CompressedVectorReader
00158         }
00159 
00160         imf.close(); // don't forget to explicitly close the ImageFile
00161     } catch(E57Exception& ex) {
00162         ex.report(__FILE__, __LINE__, __FUNCTION__);
00163         return(-1);
00164     }
00165     return(0);
00166 }

This example program creates an ImageFile, then creates various kinds of nodes, dumps out their internal state to the console, then reads back the ImageFile and dumps out some more objects' state. See the HelloWorld.cpp example for discussion of the use of include files, constructing an ImageFile, and the try/catch block to handle exceptions.

The format of the output isn't documented and may vary from one API implementation to another. However several observations can be made about the Reference Implementation output: The indenting is used to show the nesting of objects and sub-objects or sub-children. The entire sub-tree is printed recursively, with children being more indented. The output listing is very comprehensive, but can be very long. Some of the dump functions (e.g. CompressedVectorWriter::dump) have detail that is only understandable to the implementation author, but others (like Node::dump) show a lot of state that is already visible through the API.

The following console output is produced:

The XML section of the temp._e57 E57 file produced by this example program is as follows:

Here is the source code without line numbers to cut&paste from:

/*** ImageFileDump.cpp example: print diagnostics about an ImageFile and other objects */
#include <iostream>
#include "E57Foundation.h"
using namespace e57;
using namespace std;

int main(int /*argc*/, char** /*argv*/) {
    try {
        ImageFile imf("temp._e57", "w");
        StructureNode root = imf.root();

        // Add three elements: /child1, /child1/grandchild, /child2
        cout << "================" << endl;
        StructureNode child1  = StructureNode(imf);
        StructureNode child2  = StructureNode(imf);
        StringNode grandchild = StringNode(imf, "I'm a grandchild");
        root.set("child1", child1);
        root.set("child2", child2);
        child1.set("grandchild", grandchild);
        cout << "root node:" << endl;
        root.dump(4);

        cout << "================" << endl;
        Node n = root.get("child2");
        cout << n.pathName() << " generic Node:" << endl;
        n.dump(4);

        // Create vector /exampleVector, with 2 child elements
        cout << "================" << endl;
        VectorNode v(imf, false);
        root.set("exampleVector", v);
        v.append(IntegerNode(imf, 100));
        v.append(IntegerNode(imf, 101));
        cout << v.pathName() << " VectorNode:" << endl;
        v.dump(4);

        cout << "================" << endl;
        IntegerNode iNode(imf, 100);
        root.set("exampleInteger", iNode);
        cout << iNode.pathName() << " IntegerNode:" << endl;
        iNode.dump(4);

        cout << "================" << endl;
        ScaledIntegerNode si(imf, 123, 0, 1023, .001, 100.0);
        root.set("si1", si);
        cout << si.pathName() << " ScaledIntegerNode:" << endl;
        si.dump(4);

        cout << "================" << endl;
        FloatNode f(imf, 123.45F);
        root.set("f1", f);
        cout << f.pathName() << " FloatNode:" << endl;
        f.dump(4);

        cout << "================" << endl;
        StringNode s(imf, "a random string");
        root.set("s1", s);
        cout << s.pathName() << " StringNode:" << endl;
        s.dump(4);

        cout << "================" << endl;
        const int blobLength = 10;
        static uint8_t buf[blobLength] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
        BlobNode b = BlobNode(imf, blobLength);
        root.set("blob1", b);
        b.write(buf, 0, blobLength);
        cout << b.pathName() << " BlobNode:" << endl;
        b.dump(4);

        cout << "================" << endl;
        StructureNode prototype(imf);
        prototype.set("cartesianX", FloatNode(imf));
        prototype.set("cartesianY", FloatNode(imf));
        prototype.set("cartesianZ", FloatNode(imf));
        
        VectorNode codecs(imf, true);

        CompressedVectorNode cv(imf, prototype, codecs);
        root.set("points", cv);

        const int N = 4;
        static double cartesianX[N] = {1.0, 2.0, 3.0, 4.0};
        static double cartesianY[N] = {1.1, 2.1, 3.1, 4.1};
        static double cartesianZ[N] = {1.2, 2.2, 3.2, 4.2};
        vector<SourceDestBuffer> sourceBuffers;
        sourceBuffers.push_back(SourceDestBuffer(imf, "cartesianX",  cartesianX,  N));
        sourceBuffers.push_back(SourceDestBuffer(imf, "cartesianY",  cartesianY,  N));
        sourceBuffers.push_back(SourceDestBuffer(imf, "cartesianZ",  cartesianZ,  N));

        {
            CompressedVectorWriter writer = cv.writer(sourceBuffers);
            writer.write(N);

            cout << "CompressedVectorWriter:" << endl;
            writer.dump(4);
        }

        cout << "================" << endl;
        cout << cv.pathName() << " CompressedVectorNode:" << endl;
        cv.dump(4);

        cout << "================" << endl;
        imf.extensionsAdd("ext1", "http://www.example.com/MyExtension1");
        root.set("ext1:greeting", StringNode(imf, "Hello world."));
        cout << imf.fileName() << " ImageFile:" << endl;
        imf.dump(4);

        imf.close(); // don't forget to explicitly close the ImageFile
    } catch(E57Exception& ex) {
        ex.report(__FILE__, __LINE__, __FUNCTION__);
        return(-1);
    }

    try {
        ImageFile imf("temp._e57", "r");
        StructureNode root = imf.root();

        CompressedVectorNode cv = static_cast<CompressedVectorNode> (root.get("points"));

        const int N = 2;
        static double cartesianX[N];
        static double cartesianY[N];
        static double cartesianZ[N];
        vector<SourceDestBuffer> destBuffers;
        destBuffers.push_back(SourceDestBuffer(imf, "cartesianX", cartesianX, N));
        destBuffers.push_back(SourceDestBuffer(imf, "cartesianY", cartesianY, N));
        destBuffers.push_back(SourceDestBuffer(imf, "cartesianZ", cartesianZ, N));

        cout << cv.pathName() << " has " << cv.childCount() << " child elements" << endl;
        if (cv.prototype().type() != E57_STRUCTURE)
            return(-1);
        StructureNode prototype = static_cast<StructureNode>(cv.prototype());
        cout << "The prototype has " << prototype.childCount() << " child elements" << endl;
        {
            CompressedVectorReader reader = cv.reader(destBuffers);
            
            uint64_t totalRead = 0;
            unsigned nRead = 0;
            while ((nRead = reader.read(destBuffers)) > 0) {
                cout << "Got " << nRead << " points" << endl;
                for (unsigned i = 0; i < nRead; i++) {
                    cout << "point " << totalRead + i << endl;
                    cout << "  cartesianX = " << cartesianX[i] << endl;
                    cout << "  cartesianY = " << cartesianY[i] << endl;
                    cout << "  cartesianZ = " << cartesianZ[i] << endl;
                }
                totalRead += nRead;

            }
            cout << "================" << endl;
            cout << "CompressedVectorReader:" << endl;
            reader.dump(4);

            reader.close(); // don't forget to explicitly close the CompressedVectorReader
        }

        imf.close(); // don't forget to explicitly close the ImageFile
    } catch(E57Exception& ex) {
        ex.report(__FILE__, __LINE__, __FUNCTION__);
        return(-1);
    }
    return(0);
}
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines