MPEG CDVA Experimentation Model (CXM)  1.0
Compact Descriptors for Visual Analisys
DescriptorTimeMap.h
Go to the documentation of this file.
1 /*
2 The copyright in this software is being made available under this MPEG Reference Software Copyright License. This software may be subject to other third party and contributor rights, including patent rights, and no such rights are granted under this license.
3 
4 Copyright (c) 2016-2017, Joanneum Research, Mitsubishi Electric Research Labs, Peking University, Telecom Italia, University of Surrey, Visual Atoms
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 * Neither the names of Joanneum Research, Mitsubishi Electric Research Labs, Peking University, Telecom Italia, University of Surrey, Visual Atoms nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 */
12 
13 #pragma once
14 
15 
16 #include <math.h>
17 #include <assert.h>
18 
19 #include <vector>
20 
21 namespace mpeg7cdva
22 {
23 
25 
26 private:
27  int bufsz;
28 
29 protected:
30  char* m_buffer;
31  int m_nDescr; // number of local descriptors
32  int m_nAbsDescr; // number of descriptors
33  int m_nFrames; // number of frames being described (incl medoid)
34 
35  int m_nbits; // number of bits needed by buffer
36 
37  std::vector< std::vector<unsigned short> > descIndex;
38 
39 public:
40  std::vector<int> ldOffsets;
41 
42  /* if the object is created using the default contructur, init must be called before using the object */
44 
46 
47  DescriptorTimeMap(int nDescr, int nAbsDescr, int nFrames);
48 
52  DescriptorTimeMap(int nDescr, int nAbsDescr, int nFrames, char* buf);
53 
54  virtual ~DescriptorTimeMap();
55 
57 
58  void init(int nDescr, int nAbsDescr, int nFrames);
59 
60  void add(int descIdx, int frameIdx) {
61  int idx = (int)floor((descIdx*m_nFrames + frameIdx) * 4 / 8.0);
62 
63  int sh = (descIdx*m_nFrames + frameIdx) % 2 == 0 ? 0 : 4;
64 
65  m_buffer[idx] = m_buffer[idx] + (1 << sh);
66 
67  descIndex[frameIdx].push_back(descIdx);
68 
69  }
70 
71  bool get(int descIdx, int frameIdx) {
72  return getCount(descIdx, frameIdx) > 0;
73  }
74 
75  int getCount(int descIdx, int frameIdx) {
76  int idx = (int)floor((descIdx*m_nFrames + frameIdx)*4 / 8.0);
77 
78  int sh = (descIdx*m_nFrames + frameIdx) % 2 == 0 ? 0 : 4;
79 
80  return ((m_buffer[idx] & (0xf << sh)) >> sh) ;
81  }
82 
83  int getFeatureStartIndex(int descIdx, int frameIdx) {
84  int cnt = 0;
85  for (int i = 0; i < descIdx; i++) {
86  cnt += getCount(i, frameIdx);
87  }
88  return cnt;
89  }
90 
91  int getBitSize() const { return m_nbits; }
92 
93  char* getBuffer() const { return m_buffer; }
94 
95  int getNDescr() const { return m_nDescr; }
96 
97  int getNAbsDescr() const { return m_nAbsDescr; }
98 
99  int getNFrames() const { return m_nFrames; }
100 
101  std::vector<unsigned short>& getDescIndex(int frameIdx) { return descIndex[frameIdx]; }
102 
103  void addDescIndex(std::vector<unsigned short>& di, int frame);
104 
105  void writeDescIndex(unsigned char* buffer, bool compressed, int & outIdx) const;
106 
107  void parseDescIndex(unsigned char* buffer, std::vector<unsigned int>& nLocalDesc, bool compressed) ;
108 
109  void clear();
110 
111 };
112 
113 
114 } // end of namespace
void addDescIndex(std::vector< unsigned short > &di, int frame)
int m_nbits
Definition: DescriptorTimeMap.h:35
int m_nFrames
Definition: DescriptorTimeMap.h:33
int getFeatureStartIndex(int descIdx, int frameIdx)
Definition: DescriptorTimeMap.h:83
char * m_buffer
Definition: DescriptorTimeMap.h:30
std::vector< unsigned short > & getDescIndex(int frameIdx)
Definition: DescriptorTimeMap.h:101
void writeDescIndex(unsigned char *buffer, bool compressed, int &outIdx) const
Definition: DescriptorTimeMap.h:24
Namespace used to encapsulate all MPEG-7 CDVA declarations.
Definition: Buffer.h:14
void parseDescIndex(unsigned char *buffer, std::vector< unsigned int > &nLocalDesc, bool compressed)
int getCount(int descIdx, int frameIdx)
Definition: DescriptorTimeMap.h:75
int getNFrames() const
Definition: DescriptorTimeMap.h:99
int getBitSize() const
Definition: DescriptorTimeMap.h:91
void add(int descIdx, int frameIdx)
Definition: DescriptorTimeMap.h:60
std::vector< std::vector< unsigned short > > descIndex
Definition: DescriptorTimeMap.h:37
int m_nAbsDescr
Definition: DescriptorTimeMap.h:32
DescriptorTimeMap & operator=(const DescriptorTimeMap &other)
std::vector< int > ldOffsets
Definition: DescriptorTimeMap.h:40
char * getBuffer() const
Definition: DescriptorTimeMap.h:93
void init(int nDescr, int nAbsDescr, int nFrames)
int m_nDescr
Definition: DescriptorTimeMap.h:31
int getNAbsDescr() const
Definition: DescriptorTimeMap.h:97
int getNDescr() const
Definition: DescriptorTimeMap.h:95