E57 Foundation API v1.1.312
Aug. 10, 2011
|
example: get info about a SourceDestBuffer More...
Functions | |
int | main (int, char **) |
Example use of SourceDestBuffer functions. |
example: get info about a SourceDestBuffer
Also see listing at end of this page for source without line numbers (to cut&paste from).
00001 /*** SourceDestBufferFunctions.cpp example: get info about a SourceDestBuffer */ 00004 #include <iostream> 00005 #include "E57Foundation.h" 00006 using namespace e57; 00007 using namespace std; 00008 00010 int main(int /*argc*/, char** /*argv*/) { 00011 const int N = 4; 00012 00013 try { 00014 ImageFile imf("temp._e57", "w"); 00015 StructureNode root = imf.root(); 00016 cout << " imf.isWritable()=" << imf.isWritable() << endl << endl; 00017 00018 StructureNode prototype(imf); 00019 prototype.set("cartesianX", FloatNode(imf)); 00020 00021 VectorNode codecs(imf, true); 00022 00023 CompressedVectorNode points(imf, prototype, codecs); 00024 root.set("points", points); 00025 00026 static double cartesianX[N] = {1.0, 2.0, 3.0, 4.0}; 00027 vector<SourceDestBuffer> sbufs; 00028 sbufs.push_back(SourceDestBuffer(imf, "cartesianX", cartesianX, N)); 00029 00030 { 00031 cout << " imf.writerCount()=" << imf.writerCount() << endl << endl; 00032 00033 CompressedVectorWriter writer = points.writer(sbufs); 00034 00035 cout << " imf.writerCount()=" << imf.writerCount() << endl; 00036 cout << " writer.isOpen()=" << writer.isOpen() << endl << endl; 00037 00038 writer.write(N); 00039 00040 cout << " imf.writerCount()=" << imf.writerCount() << endl; 00041 cout << " writer.isOpen()=" << writer.isOpen() << endl << endl; 00042 00043 writer.close(); // don't forget to explicitly close the CompressedVectorWriter 00044 00045 cout << " imf.writerCount()=" << imf.writerCount() << endl; 00046 cout << " writer.isOpen()=" << writer.isOpen() << endl; 00047 } 00048 cout << " imf.writerCount()=" << imf.writerCount() << endl; 00049 00050 cout << "pathName = " << sbufs[0].pathName() << endl; 00051 cout << "memoryRepresentation = " << sbufs[0].memoryRepresentation() << endl; 00052 cout << "capacity = " << sbufs[0].capacity() << endl; 00053 cout << "doConversion = " << sbufs[0].doConversion() << endl; 00054 cout << "doScaling = " << sbufs[0].doScaling() << endl; 00055 cout << "stride = " << sbufs[0].stride() << endl; 00056 00057 imf.close(); // don't forget to explicitly close the ImageFile 00058 cout << " imf.isWritable()=" << imf.isWritable() << endl; 00059 } catch(E57Exception& ex) { 00060 ex.report(__FILE__, __LINE__, __FUNCTION__); 00061 return(-1); 00062 } 00063 00064 cout << "================" << endl; 00065 cout << "Opening file for reading" << endl; 00066 try { 00068 ImageFile imf("temp._e57", "r"); 00069 StructureNode root = imf.root(); 00070 cout << " imf.isWritable()=" << imf.isWritable() << endl << endl; 00071 CompressedVectorNode points(root.get("/points")); 00072 00073 double values[N]; 00074 vector<SourceDestBuffer> dbufs; 00075 dbufs.push_back(SourceDestBuffer(imf, "cartesianX", values, N, true)); 00076 00077 unsigned gotCount = 0; 00078 { 00079 cout << " imf.readerCount()=" << imf.readerCount() << endl << endl; 00080 00081 CompressedVectorReader reader = points.reader(dbufs); 00082 00083 cout << " imf.readerCount()=" << imf.readerCount() << endl; 00084 cout << " reader.isOpen()=" << reader.isOpen() << endl << endl; 00085 00086 gotCount = reader.read(); 00087 00088 cout << " imf.readerCount()=" << imf.readerCount() << endl; 00089 cout << " reader.isOpen()=" << reader.isOpen() << endl << endl; 00090 00091 reader.close(); // don't forget to explicitly close the CompressedVectorReader 00092 00093 cout << " imf.readerCount()=" << imf.readerCount() << endl; 00094 cout << " reader.isOpen()=" << reader.isOpen() << endl; 00095 } 00096 cout << " imf.readerCount()=" << imf.readerCount() << endl << endl; 00097 00098 cout << "gotCount=" << gotCount << " records" << endl; 00099 00100 for (unsigned i=0; i < gotCount; i++) 00101 cout << "value[" << i << "]=" << values[i] << endl; 00102 00103 imf.close(); // don't forget to explicitly close the ImageFile 00104 } catch(E57Exception& ex) { 00105 ex.report(__FILE__, __LINE__, __FUNCTION__); 00106 return(-1); 00107 } 00108 return(0); 00109 }
This example program illustrates the state interrogation functions for SourceDestBuffer, CompressedVectorWriter, and CompressedVectorReader. A very simple CompressedVectorNode is written and then read back in. See the HelloWorld.cpp example for discussion of the use of include files, constructing an ImageFile, and the try/catch block to handle exceptions. See CompressedVectorCreate.cpp example for discussion about the writing/reading a CompressedVectorNode.
ImageFile::isWritable is called on source lines 16 and 70. In the CompressedVectorWriter nested block on source lines 30-47, ImageFile::writerCount is called before, during, and after the use of the CompressedVectorWriter object to show how many writers a open. Also CompressedVectorWriter::isOpen is called three times to show is behavior after close is called.
Source lines 50-55 show the use of the functions that interrogate the state of a SourceDestBuffer. Note in output lines 17-19, the default values for doConversion
and doScaling
are false, and the default value for stride
with a double
buffer is sizeof(double) == 8.
In the reader section on source lines 68-103, similar printouts are produced for ImageFile::readerCount, and CompressedVectorReader::isOpen.
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:
/*** SourceDestBufferFunctions.cpp example: get info about a SourceDestBuffer */ #include <iostream> #include "E57Foundation.h" using namespace e57; using namespace std; int main(int /*argc*/, char** /*argv*/) { const int N = 4; try { ImageFile imf("temp._e57", "w"); StructureNode root = imf.root(); cout << " imf.isWritable()=" << imf.isWritable() << endl << endl; StructureNode prototype(imf); prototype.set("cartesianX", FloatNode(imf)); VectorNode codecs(imf, true); CompressedVectorNode points(imf, prototype, codecs); root.set("points", points); static double cartesianX[N] = {1.0, 2.0, 3.0, 4.0}; vector<SourceDestBuffer> sbufs; sbufs.push_back(SourceDestBuffer(imf, "cartesianX", cartesianX, N)); { cout << " imf.writerCount()=" << imf.writerCount() << endl << endl; CompressedVectorWriter writer = points.writer(sbufs); cout << " imf.writerCount()=" << imf.writerCount() << endl; cout << " writer.isOpen()=" << writer.isOpen() << endl << endl; writer.write(N); cout << " imf.writerCount()=" << imf.writerCount() << endl; cout << " writer.isOpen()=" << writer.isOpen() << endl << endl; writer.close(); // don't forget to explicitly close the CompressedVectorWriter cout << " imf.writerCount()=" << imf.writerCount() << endl; cout << " writer.isOpen()=" << writer.isOpen() << endl; } cout << " imf.writerCount()=" << imf.writerCount() << endl; cout << "pathName = " << sbufs[0].pathName() << endl; cout << "memoryRepresentation = " << sbufs[0].memoryRepresentation() << endl; cout << "capacity = " << sbufs[0].capacity() << endl; cout << "doConversion = " << sbufs[0].doConversion() << endl; cout << "doScaling = " << sbufs[0].doScaling() << endl; cout << "stride = " << sbufs[0].stride() << endl; imf.close(); // don't forget to explicitly close the ImageFile cout << " imf.isWritable()=" << imf.isWritable() << endl; } catch(E57Exception& ex) { ex.report(__FILE__, __LINE__, __FUNCTION__); return(-1); } cout << "================" << endl; cout << "Opening file for reading" << endl; try { ImageFile imf("temp._e57", "r"); StructureNode root = imf.root(); cout << " imf.isWritable()=" << imf.isWritable() << endl << endl; CompressedVectorNode points(root.get("/points")); double values[N]; vector<SourceDestBuffer> dbufs; dbufs.push_back(SourceDestBuffer(imf, "cartesianX", values, N, true)); unsigned gotCount = 0; { cout << " imf.readerCount()=" << imf.readerCount() << endl << endl; CompressedVectorReader reader = points.reader(dbufs); cout << " imf.readerCount()=" << imf.readerCount() << endl; cout << " reader.isOpen()=" << reader.isOpen() << endl << endl; gotCount = reader.read(); cout << " imf.readerCount()=" << imf.readerCount() << endl; cout << " reader.isOpen()=" << reader.isOpen() << endl << endl; reader.close(); // don't forget to explicitly close the CompressedVectorReader cout << " imf.readerCount()=" << imf.readerCount() << endl; cout << " reader.isOpen()=" << reader.isOpen() << endl; } cout << " imf.readerCount()=" << imf.readerCount() << endl << endl; cout << "gotCount=" << gotCount << " records" << endl; for (unsigned i=0; i < gotCount; i++) cout << "value[" << i << "]=" << values[i] << endl; imf.close(); // don't forget to explicitly close the ImageFile } catch(E57Exception& ex) { ex.report(__FILE__, __LINE__, __FUNCTION__); return(-1); } return(0); }