forked from ossimlabs/ossim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_open.cpp
More file actions
126 lines (105 loc) · 4.7 KB
/
Copy pathimage_open.cpp
File metadata and controls
126 lines (105 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*!
*
* OVERVIEW:
*
* this app is a simple image open.
* It should open any image supported by the ossim library.
* Once the image is open it prints out some general information
* about the image.
*
* PURPOSE:
*
* Learn how to open an image and query attributes. Also learn which
* headers are required to perform these tasks.
*
*/
// iostream is used for general output
//
#include <iostream>
// within this program ossimCommon is used for ossimGetScalarSizeInBytes.
// This header will have some common globabl inline and non-inline functions
//
#include "base/common/ossimCommon.h"
#include "base/data_types/ossimFilename.h"
// used to get the string name of the scalar type for the handler. The scalar
// type specifies if its unsigned char, float, double, ...etc
//
#include "base/misc/lookup_tables/ossimScalarTypeLut.h"
// This is the majic number factory. All loader are registered to this factory.
// it will lookp through all factories to try to open the passed in image file
//
#include "imaging/factory/ossimImageHandlerRegistry.h"
// Base pointer for the passed back object type
//
#include "imaging/formats/ossimImageHandler.h"
// this is the most important class and is called as the first line of all applications.
// without this alll the important factories are not created.
//
#include "init/ossimInit.h"
using namespace std;
int main(int argc, char* argv[])
{
ossimInit::instance()->initialize(argc, argv);
if(argc == 2)
{
// call the registries open and let it traverse through all registered
// factories to open up an image.
//
ossimImageHandler *handler = ossimImageHandlerRegistry::instance()->open(ossimFilename(argv[1]));
if(handler)
{
// includes full resolution so if there are no overviews this value should be
// 1. Note: resolution levels or overviews or indexed from 0 being full
// resolution to (number of decimations or overviews -1..
//
// Overviews are very import for resampling images to different resolutions efficiently.
// The overviews are generally power of 2 decimations. Assume we have an image that has
// full resolution of 1024x1024 in size. When we are talking about resolution 0 then
// we are talking about the full res 1024x1024, but when we are talking
// about resolution level 1 then we are looking at the start of the overview and referes to
// a decimation of 2^1 which is 512x512 image. So when we ask for resolution level N then
// we are talking about a decimation of 2^N
//
// So again, when we query the number of decimation levels this includes resolution layer 0.
//
int overviews = handler->getNumberOfDecimationLevels();
// the image bounds can take an argument to specify which resolution I would like to get
// the bounding rect of. By default if no argument is given it assumes full resolution or
// resolution 0.
//
ossimIrect bounds = handler->getBoundingRect(0);
// scalar type cooresponds to the pixel radiometry type. The pixel can be of precision
// float, double, unsigned char, unsigned short, signed short data values. Look at
// ossimScalarType enumeration found in base/common/ossimConstants.h for supporting types
//
ossimScalarType scalarType = handler->getOutputScalarType();
// This is a utility class that maps enumeration values to strings. So we will use this
// when we query the scalar type from the image and wish to print the text version of it.
//
//
ossimScalarTypeLut* lut = ossimScalarTypeLut::instance();
cout <<"filename = " << handler->getFilename() << endl
<< "width = " << bounds.width() << endl
<< "height = " << bounds.height() << endl
<< "overview count = " << (overviews-1) << endl
<< "scalar type = " << lut->getEntryString(handler->getOutputScalarType()) << endl
// ossimGetScalarSizeInBytes is a utility functions found in base/common/ossimCommon.h
// it will return the byte size of the scalar type.
//
<< "pixel size = " << ossimGetScalarSizeInBytes(scalarType) << " byte(s)" <<endl
<< "Handler used = " << handler->getClassName() << endl;
delete handler;
}
else
{
cout << "Unable to open image = " << argv[1] << endl;
}
}
else
{
cout << "usage: open_image <file name>" << endl;
}
// call the finalize so the ossim can cleanup if needed.
ossimInit::instance()->finalize();
return 0;
}