E57 Foundation API v1.1.312
Aug. 10, 2011
|
example: creating ScaledIntegerNodes More...
Functions | |
void | printScaledIntegerInfo (ImageFile imf, ustring pathName) |
Get and print some info about a ScaledIntegerNode. | |
int | main (int, char **) |
Example use of ScaledIntegerNode functions. |
example: creating ScaledIntegerNodes
Also see listing at end of this page for source without line numbers (to cut&paste from).
00001 /*** ScaledIntegerCreate.cpp example: creating ScaledIntegerNodes */ 00004 #include <iostream> 00005 #include "E57Foundation.h" 00006 using namespace e57; 00007 using namespace std; 00008 00010 void printScaledIntegerInfo(ImageFile imf, ustring pathName) 00011 { 00012 cout << pathName << ":" << endl; 00013 00014 StructureNode root = imf.root(); 00015 00016 if (root.isDefined(pathName)) { 00017 Node n = root.get(pathName); 00018 if (n.type() == E57_SCALED_INTEGER) { 00019 ScaledIntegerNode si = static_cast<ScaledIntegerNode>(n); 00020 cout << " rawValue = " << si.rawValue() << endl; 00021 cout << " scaledValue = " << si.scaledValue() << endl; 00022 cout << " minimum = " << si.minimum() << endl; 00023 cout << " maximum = " << si.maximum() << endl; 00024 cout << " scale = " << si.scale() << endl; 00025 cout << " offset = " << si.offset() << endl; 00026 } else 00027 cout << "oops " << n.pathName() << " isn't an ScaledInteger" << endl; 00028 } 00029 } 00030 00032 int main(int /*argc*/, char** /*argv*/) { 00033 try { 00034 ImageFile imf("temp._e57", "w"); 00035 StructureNode root = imf.root(); 00036 00037 // Create 5 example ScaledIntegers 00038 root.set("si1", ScaledIntegerNode(imf, int64_t(), E57_INT64_MIN, E57_INT64_MAX)); 00039 root.set("si2", ScaledIntegerNode(imf, int64_t(123), E57_INT64_MIN, E57_INT64_MAX)); 00040 root.set("si3", ScaledIntegerNode(imf, 123, 0, 1023)); 00041 root.set("si4", ScaledIntegerNode(imf, 123, 0, 1023, .001)); 00042 root.set("si5", ScaledIntegerNode(imf, 123, 0, 1023, .001, 100.0)); 00043 00044 printScaledIntegerInfo(imf, "/si1"); 00045 printScaledIntegerInfo(imf, "/si2"); 00046 printScaledIntegerInfo(imf, "/si3"); 00047 printScaledIntegerInfo(imf, "/si4"); 00048 printScaledIntegerInfo(imf, "/si5"); 00049 00050 imf.close(); // don't forget to explicitly close the ImageFile 00051 } catch(E57Exception& ex) { 00052 ex.report(__FILE__, __LINE__, __FUNCTION__); 00053 return(-1); 00054 } 00055 return(0); 00056 }
This example program writes an ImageFile containing 5 ScaledIntegerNodes. It then prints out some basic information about the state of each ScaledIntegerNode. See the HelloWorld.cpp example for discussion of the use of include files, constructing an ImageFile, and the try/catch block to handle exceptions. Also see discussion in the IntegerCreate.cpp example concerning downcasting.
Source lines 38-42 illustrate the use of the default arguments in the ScaledIntegerNode constructor. It only make sense to use a ScaledIntegerNode object when the scale or offset is specified explicitly as in source lines 41-42 (otherwise the representation domain is the same as an IntegerNode element).
In source lines 40-42, if the specified raw value had been chosen outside the given minimum/maximum bounds, an exception would have been thrown (since the ASTM spec requires the value be within the bounds).
Note that in output listing lines 23-24, the scaled value is 0.001 times the size of the raw value (using the specified scale factor 0.001). Also in output line 31, an additional offset of 100.0 has been added.
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:
/*** ScaledIntegerCreate.cpp example: creating ScaledIntegerNodes */ #include <iostream> #include "E57Foundation.h" using namespace e57; using namespace std; void printScaledIntegerInfo(ImageFile imf, ustring pathName) { cout << pathName << ":" << endl; StructureNode root = imf.root(); if (root.isDefined(pathName)) { Node n = root.get(pathName); if (n.type() == E57_SCALED_INTEGER) { ScaledIntegerNode si = static_cast<ScaledIntegerNode>(n); cout << " rawValue = " << si.rawValue() << endl; cout << " scaledValue = " << si.scaledValue() << endl; cout << " minimum = " << si.minimum() << endl; cout << " maximum = " << si.maximum() << endl; cout << " scale = " << si.scale() << endl; cout << " offset = " << si.offset() << endl; } else cout << "oops " << n.pathName() << " isn't an ScaledInteger" << endl; } } int main(int /*argc*/, char** /*argv*/) { try { ImageFile imf("temp._e57", "w"); StructureNode root = imf.root(); // Create 5 example ScaledIntegers root.set("si1", ScaledIntegerNode(imf, int64_t(), E57_INT64_MIN, E57_INT64_MAX)); root.set("si2", ScaledIntegerNode(imf, int64_t(123), E57_INT64_MIN, E57_INT64_MAX)); root.set("si3", ScaledIntegerNode(imf, 123, 0, 1023)); root.set("si4", ScaledIntegerNode(imf, 123, 0, 1023, .001)); root.set("si5", ScaledIntegerNode(imf, 123, 0, 1023, .001, 100.0)); printScaledIntegerInfo(imf, "/si1"); printScaledIntegerInfo(imf, "/si2"); printScaledIntegerInfo(imf, "/si3"); printScaledIntegerInfo(imf, "/si4"); printScaledIntegerInfo(imf, "/si5"); imf.close(); // don't forget to explicitly close the ImageFile } catch(E57Exception& ex) { ex.report(__FILE__, __LINE__, __FUNCTION__); return(-1); } return(0); }