ESA JPIP server  0.1
image_index.h
Go to the documentation of this file.
1 #ifndef _JPEG2000_INDEX_NODE_H_
2 #define _JPEG2000_INDEX_NODE_H_
3 
4 
5 //#define SHOW_TRACES
6 #include "trace.h"
7 
8 #include <list>
9 #include <vector>
10 #include "base.h"
11 #include "range.h"
12 #include "image_info.h"
13 #include "packet_index.h"
14 #include "ipc/rdwr_lock.h"
15 
16 
17 namespace jpeg2000
18 {
19 
20  using namespace std;
21  using namespace ipc;
22 
23 
36  class ImageIndex
37  {
38  private:
39  friend class IndexManager;
40 
45 
46  vector<int> last_plt;
47  vector<int> last_packet;
48  vector<uint64_t> last_offset_PLT;
49  vector<uint64_t> last_offset_packet;
50 
51  string path_name;
54  vector<int> max_resolution;
55 
56  vector<PacketIndex> packet_indexes;
57  vector<CodestreamIndex> codestreams;
58 
60  vector<list<ImageIndex>::iterator> hyper_links;
61 
62 
70  bool GetPLTLength(const File& file, int ind_codestream, uint64_t *length_packet);
71 
79  void GetOffsetPacket(const File& file, int ind_codestream, uint64_t length_packet);
80 
87  bool BuildIndex(int ind_codestream, int max_index);
88 
95  bool Init(const string& path_name, const ImageInfo& image_info);
96 
105  bool Init(const string& path_name, CodingParameters::Ptr coding_parameters,
106  const ImageInfo& image_info, int index);
107 
113 
114  public:
118  typedef list<ImageIndex>::iterator Ptr;
119 
120 
124  ImageIndex(const ImageIndex& image_index)
125  {
126  *this = image_index;
127  }
128 
132  int GetNumCodestreams() const
133  {
134  if(codestreams.size() > 0) return codestreams.size();
135  else return hyper_links.size();
136  }
137 
141  int GetNumMetadatas() const
142  {
143  return meta_data.meta_data.size();
144  }
145 
151  bool ReadLock(const Range& range = Range(0, 0));
152 
158  bool ReadUnlock(const Range& range = Range(0, 0));
159 
163  string GetPathName() const
164  {
165  return path_name;
166  }
167 
173  string GetPathName(int num_codestream) const
174  {
175  if(codestreams.size() > 0) return path_name;
176  else return hyper_links[num_codestream]->path_name;
177  }
178 
184  FileSegment GetMainHeader(int num_codestream) const
185  {
186  if(codestreams.size() > 0) return codestreams[num_codestream].header;
187  else return hyper_links[num_codestream]->codestreams.back().header;
188  }
189 
194  FileSegment GetMetadata(int num_metadata) const
195  {
196  return meta_data.meta_data[num_metadata];
197  }
198 
203  PlaceHolder GetPlaceHolder(int num_placeholder) const
204  {
205  return meta_data.place_holders[num_placeholder];
206  }
207 
215  FileSegment GetPacket(int num_codestream, const Packet& packet, int *offset = NULL);
216 
221  {
222  return coding_parameters;
223  }
224 
229  bool IsHyperLinked(int num_codestream) const
230  {
231  return (num_codestream < (int)hyper_links.size());
232  }
233 
238  Ptr GetHyperLink(int num_codestream) const
239  {
240  return hyper_links[num_codestream];
241  }
242 
246  int GetNumHyperLinks() const
247  {
248  return (int)hyper_links.size();
249  }
250 
251  operator CodingParameters::Ptr() const
252  {
253  return coding_parameters;
254  }
255 
256  ImageIndex& operator=(const ImageIndex& image_index)
257  {
258  rdwr_lock = image_index.rdwr_lock;
259 
260  meta_data = image_index.meta_data;
261  path_name = image_index.path_name;
262  num_references = image_index.num_references;
263  coding_parameters = image_index.coding_parameters;
264 
265  base::copy(max_resolution, image_index.max_resolution);
266  base::copy(last_plt, image_index.last_plt);
267  base::copy(last_packet, image_index.last_packet);
268  base::copy(codestreams, image_index.codestreams);
269  base::copy(hyper_links, image_index.hyper_links);
270  base::copy(packet_indexes, image_index.packet_indexes);
271  base::copy(last_offset_PLT, image_index.last_offset_PLT);
272  base::copy(last_offset_packet, image_index.last_offset_packet);
273 
274  return *this;
275  }
276 
277  friend ostream& operator <<(ostream &out, const ImageIndex &info_node)
278  {
279  out << "Image file name: " << info_node.path_name << endl
280  << *(info_node.coding_parameters)
281  << "Coding parameters ref: " << info_node.coding_parameters.use_count() << endl
282  << "Max resolution: ";
283  for (vector<int>::const_iterator i = info_node.max_resolution.begin(); i != info_node.max_resolution.end(); i++)
284  out << *i << " ";
285 
286  out << endl;
287 
288  for (vector<CodestreamIndex>::const_iterator i = info_node.codestreams.begin(); i != info_node.codestreams.end(); i++)
289  out << "Codestream index: " << endl << "----------------- " << endl << *i << endl << endl;
290 
291  out << "Packet indexes: " << endl << "--------------- " << endl;
292 
293  for (vector<PacketIndex>::const_iterator i = info_node.packet_indexes.begin(); i != info_node.packet_indexes.end(); i++)
294  for (int j = 0; j < i->Size(); j++)
295  out << j << " - " << (*i)[j] << endl;
296 
297  out << endl << "Num. Hyperlinks: " << info_node.hyper_links.size() << endl;
298 
299  for (vector<list<ImageIndex>::iterator>::const_iterator i = info_node.hyper_links.begin(); i != info_node.hyper_links.end(); i++)
300  out << "Hyperlinks: " << endl << "----------- " << endl << **i << endl << "----------- " << endl;
301 
302  out << endl << "Meta-data: ";
303  out << endl << info_node.meta_data;
304 
305  out << endl << "Num. References: " << info_node.num_references << endl;
306 
307  return out;
308  }
309 
310  virtual ~ImageIndex()
311  {
312  TRACE("Destroying the image index of '" << path_name << "'");
313  }
314  };
315 
316 }
317 
318 #endif /* _JPEG2000_INDEX_NODE_H_ */
319 
int GetNumCodestreams() const
Returns the number of codestreams.
Definition: image_index.h:132
CodingParameters::Ptr coding_parameters
Image coding parameters.
Definition: image_index.h:59
string GetPathName() const
Returns the path name of the image.
Definition: image_index.h:163
static void copy(std::vector< T > &dest, const std::vector< T > &src)
Copies a vector.
Definition: base.h:30
Manages the indexing information of a repository fo images.
Definition: index_manager.h:25
vector< list< ImageIndex >::iterator > hyper_links
Image hyperlinks.
Definition: image_index.h:60
vector< int > max_resolution
Maximum resolution number.
Definition: image_index.h:54
SHARED_PTR< CodingParameters > Ptr
Pointer to an object of this class.
Definition: coding_parameters.h:97
vector< CodestreamIndex > codestreams
Image code-streams.
Definition: image_index.h:57
vector< int > last_packet
Definition: image_index.h:47
Identifies a data segment of a file.
Definition: file_segment.h:20
vector< int > last_plt
Definition: image_index.h:46
STL namespace.
CodingParameters::Ptr GetCodingParameters() const
Returns a pointer to the coding parameters.
Definition: image_index.h:220
Contains the information of a place-holder.
Definition: place_holder.h:18
string GetPathName(int num_codestream) const
Returns the path name of a given codestream, if it is a hyperlinked codestream.
Definition: image_index.h:173
virtual ~ImageIndex()
Definition: image_index.h:310
Contains the indexing information of a JPEG2000 image.
Definition: image_info.h:24
Ptr GetHyperLink(int num_codestream) const
Returns a pointer to a hyperlink.
Definition: image_index.h:238
vector< uint64_t > last_offset_PLT
Definition: image_index.h:48
FileSegment GetMetadata(int num_metadata) const
Returns the file segment of a meta-data block.
Definition: image_index.h:194
ImageIndex & operator=(const ImageIndex &image_index)
Definition: image_index.h:256
vector< uint64_t > last_offset_packet
Definition: image_index.h:49
Represents a range of integer values, defined by two values, first and last, which are assumed to be ...
Definition: range.h:20
list< ImageIndex >::iterator Ptr
Pointer of an object of this class.
Definition: image_index.h:118
vector< PlaceHolder > place_holders
Associated place-holders.
Definition: meta_data.h:32
Contains classes for working with the IPC mechanisms available in Linux using the pthread library...
Definition: event.cc:7
RdWrLock::Ptr rdwr_lock
Read/write lock.
Definition: image_index.h:44
int GetNumHyperLinks() const
Returns the number of hyperlinks.
Definition: image_index.h:246
Set of classes for handling (reading and indexing) image files with the format defined in the Part 1 ...
Definition: codestream_index.h:10
string path_name
Image file name.
Definition: image_index.h:51
vector< PacketIndex > packet_indexes
Code-stream packet index.
Definition: image_index.h:56
#define TRACE(a)
Definition: trace.h:89
vector< FileSegment > meta_data
File segments of all the meta-data blocks.
Definition: meta_data.h:27
Metadata meta_data
Image Metadata.
Definition: image_index.h:52
int GetNumMetadatas() const
Returns the number of meta-data blocks.
Definition: image_index.h:141
ImageIndex()
Empty constructor.
Definition: image_index.h:112
bool IsHyperLinked(int num_codestream) const
Returns true if the image contains hyperlinks.
Definition: image_index.h:229
Contains the indexing information associated to the meta-data of a JPEG2000 image file...
Definition: meta_data.h:21
Contains the indexing information of a JPEG2000 image file that is managed by the index manager...
Definition: image_index.h:36
int num_references
Number of references.
Definition: image_index.h:53
ImageIndex(const ImageIndex &image_index)
Copy constructor.
Definition: image_index.h:124
PlaceHolder GetPlaceHolder(int num_placeholder) const
Returns the information of a place-holder.
Definition: image_index.h:203
FileSegment GetMainHeader(int num_codestream) const
Returns the file segment the main header of a given codestream.
Definition: image_index.h:184
SHARED_PTR< RdWrLock > Ptr
Pointer to a RdWrLock object.
Definition: rdwr_lock.h:27
Contains the information of a packet.
Definition: packet.h:15
ostream & operator<<(ostream &out, const Request &request)
Definition: request.cc:65