vil_openjpeg_pyramid_image_resource.cxx
Go to the documentation of this file.
1 #include <cmath>
3 //:
4 // \file
5 // Do not remove the following notice
6 // Approved for public Release, distribution unlimited
7 // DISTAR Case 14074
8 
9 #ifdef _MSC_VER
10 # include <vcl_msvc_warnings.h>
11 #endif
12 
13 // By definition, each level is a factor of 2 reduced in scale
14 static float scale_at_level(unsigned level)
15 {
16  if (level == 0)
17  return 1.0f;
18  float s = std::pow(2.0f, -static_cast<float>(level));
19  return s;
20 }
21 
24 : openjpeg_sptr_(openjpeg)
25 {
26  ptr_ = nullptr;
27  if (!openjpeg_sptr_)
28  return;
29  ptr_ = dynamic_cast<vil_openjpeg_image*>(openjpeg_sptr_.ptr());
30 }
31 
33 {
34  unsigned ret = 0;
35  if (ptr_)
36  ret = ptr_->nplanes();
37  return ret;
38 }
39 
40 //: The number of pixels in each row.
41 // Dimensions: Planes x ni x nj.
42 // This method refers to the base (max resolution) image
44 {
45  unsigned ret = 0;
46  if (ptr_)
47  ret = ptr_->ni();
48  return ret;
49 }
50 
51 //: The number of pixels in each column.
52 // Dimensions: Planes x ni x nj.
53 // This method refers to the base (max resolution) image
55 {
56  unsigned ret = 0;
57  if (ptr_)
58  ret = ptr_->nj();
59  return ret;
60 }
61 
62 //: Pixel Format.
64 {
65  if (ptr_)
66  return ptr_->pixel_format();
68 }
69 
70 //: Return a string describing the file format.
71 // Only file images have a format, others return 0
73 {
74  return "openjpeg_pyramid";
75 }
76 
77 
78  // === Methods particular to pyramid resource ===
79 
80 //: Number of pyramid levels.
82 {
83  if (!ptr_)
84  return 0;
85  return ptr_->nreductions() + 1;
86 }
87 
88 //: Get a partial view from the image from a specified pyramid level
91  unsigned j0, unsigned nj,
92  unsigned level) const
93 {
94  if (!ptr_||!(ptr_->is_valid()))
95  return nullptr;
96  if (level >= this->nlevels())
97  level = this->nlevels() - 1;
98  return ptr_->get_copy_view_reduced(i0, ni, j0, nj, level);
99 }
100 
101 //: Get a partial view from the image in the pyramid closest to scale.
102 // The origin and size parameters are in the coordinate system of the base image.
103 // The scale factor is with respect to the base image (base scale = 1.0).
106  unsigned j0, unsigned nj,
107  const float scale,
108  float& actual_scale) const
109 {
110  if (scale >= 1.0f)
111  {
112  actual_scale = 1.0f;
113  return this->get_copy_view(i0, ni, j0, nj, 0);
114  }
115  float f_lev = -std::log(scale) / std::log(2.0f);
116  auto level = static_cast<unsigned>(f_lev);
117  if (level >= this->nlevels())
118  level = this->nlevels()-1;
119  actual_scale = scale_at_level(level);
120  return this->get_copy_view(i0, ni, j0, nj, level);
121 }
122 
123 //: Get an image resource from the pyramid at the specified level
126 {
127  if (level == 0)
128  return openjpeg_sptr_;
129  return nullptr;
130 }
131 
132 //: for debug purposes
133 void vil_openjpeg_pyramid_image_resource::print(const unsigned /*level*/)
134 {
135 }
vil_pixel_format
Describes the type of the concrete data.
unsigned int nplanes() const override
Dimensions: Planes x ni x nj.
unsigned ni() const override
The number of pixels in each row.
virtual unsigned int nreductions() const
Reductions.
void print(const unsigned level) override
for debug purposes.
bool is_valid(void) const
enum vil_pixel_format pixel_format() const override
Pixel Format.
unsigned nj() const override
The number of pixels in each column.
enum vil_pixel_format pixel_format() const override
Pixel Format.
unsigned int nj() const override
Dimensions: Planes x ni x nj.
vil_image_view_base_sptr get_copy_view() const
Create a read/write view of a copy of all the data.
virtual vil_image_view_base_sptr get_copy_view_reduced(unsigned i0, unsigned ni, unsigned j0, unsigned nj, unsigned reduction) const
Create a read/write view of a copy of this data.
unsigned int ni() const override
Dimensions: Planes x ni x nj.
unsigned nplanes() const override
The number of planes (or components) in the image.
vil_image_resource_sptr get_resource(const unsigned level) const override
Get an image resource from the pyramid at the specified level.
Representation of a pyramid resolution hierarchy based on the openjpeg_image.
T * ptr() const
These methods all return the raw/dumb pointer.
char const * file_format() const override
Return a string describing the file format.
unsigned nlevels() const override
Number of pyramid levels.