Line data Source code
1 : /******************************************************************************
2 : *
3 : * Purpose: Block directory API.
4 : *
5 : ******************************************************************************
6 : * Copyright (c) 2011
7 : * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada.
8 : *
9 : * Permission is hereby granted, free of charge, to any person obtaining a
10 : * copy of this software and associated documentation files (the "Software"),
11 : * to deal in the Software without restriction, including without limitation
12 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 : * and/or sell copies of the Software, and to permit persons to whom the
14 : * Software is furnished to do so, subject to the following conditions:
15 : *
16 : * The above copyright notice and this permission notice shall be included
17 : * in all copies or substantial portions of the Software.
18 : *
19 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 : * DEALINGS IN THE SOFTWARE.
26 : ****************************************************************************/
27 :
28 : #ifndef PCIDSK_BLOCK_TILE_LAYER_H
29 : #define PCIDSK_BLOCK_TILE_LAYER_H
30 :
31 : #include "blockdir/blocklayer.h"
32 : #include "blockdir/blocktiledir.h"
33 : #include "pcidsk_mutex.h"
34 : #include <string>
35 :
36 : namespace PCIDSK
37 : {
38 :
39 : /************************************************************************/
40 : /* class BlockTileLayer */
41 : /************************************************************************/
42 :
43 : /**
44 : * Class used as the base class for all block tile layers.
45 : *
46 : * @see BlockLayer
47 : */
48 : class PCIDSK_DLL BlockTileLayer : public BlockLayer
49 : {
50 : protected:
51 : #pragma pack(push, 1)
52 :
53 : /// The block tile info structure.
54 : struct BlockTileInfo
55 : {
56 : uint64 nOffset;
57 : uint32 nSize;
58 : };
59 :
60 : #pragma pack(pop)
61 :
62 : /// The block info list type.
63 : typedef std::vector<BlockTileInfo> BlockTileInfoList;
64 :
65 : /// The block layer info type.
66 : typedef BlockTileDir::BlockLayerInfo BlockLayerInfo;
67 :
68 : /// The tile layer info type.
69 : typedef BlockTileDir::TileLayerInfo TileLayerInfo;
70 :
71 : /// The block layer info.
72 : BlockLayerInfo * mpsBlockLayer;
73 :
74 : /// The tile layer info.
75 : TileLayerInfo * mpsTileLayer;
76 :
77 : /// The block tile info list.
78 : BlockTileInfoList moTileList;
79 :
80 : /// The tile list mutex.
81 : Mutex * mpoTileListMutex;
82 :
83 : /// If the block tile layer is modified.
84 : bool mbModified;
85 :
86 : mutable char mszDataType[5];
87 : mutable char mszCompress[9];
88 :
89 : /**
90 : * Sets the type of the layer.
91 : *
92 : * @param nLayerType The type of the layer.
93 : */
94 0 : virtual void _SetLayerType(uint16 nLayerType) override
95 : {
96 0 : mpsBlockLayer->nLayerType = nLayerType;
97 0 : }
98 :
99 : /**
100 : * Sets the number of blocks in the block layer.
101 : *
102 : * @param nBlockCount The number of blocks in the block layer.
103 : */
104 40 : virtual void _SetBlockCount(uint32 nBlockCount) override
105 : {
106 40 : mpsBlockLayer->nBlockCount = nBlockCount;
107 40 : }
108 :
109 : /**
110 : * Sets the size in bytes of the layer.
111 : *
112 : * @param nLayerSize The size in bytes of the layer.
113 : */
114 24 : virtual void _SetLayerSize(uint64 nLayerSize) override
115 : {
116 24 : mpsBlockLayer->nLayerSize = nLayerSize;
117 24 : }
118 :
119 : /**
120 : * Writes the tile list to disk.
121 : */
122 : virtual void WriteTileList(void) = 0;
123 :
124 : /**
125 : * Reads the tile list from disk.
126 : */
127 : virtual void ReadTileList(void) = 0;
128 :
129 : BlockTileInfo * GetTileInfo(uint32 nCol, uint32 nRow);
130 :
131 : public:
132 : BlockTileLayer(BlockDir * poBlockDir, uint32 nLayer,
133 : BlockLayerInfo * psBlockLayer,
134 : TileLayerInfo * psTileLayer);
135 :
136 : virtual ~BlockTileLayer(void);
137 :
138 : void Sync(void);
139 :
140 : bool IsCorrupted(void) const;
141 :
142 : uint32 GetTileCount(void) const;
143 : uint32 GetTilePerRow(void) const;
144 : uint32 GetTilePerCol(void) const;
145 :
146 : uint32 GetTileSize(void) const;
147 :
148 : uint32 GetDataTypeSize(void) const;
149 :
150 : bool IsTileValid(uint32 nCol, uint32 nRow);
151 :
152 : uint32 GetTileDataSize(uint32 nCol, uint32 nRow);
153 :
154 : bool WriteSparseTile(const void * pData,
155 : uint32 nCol, uint32 nRow);
156 :
157 : void WriteTile(const void * pData,
158 : uint32 nCol, uint32 nRow, uint32 nSize = 0);
159 :
160 : bool ReadSparseTile(void * pData,
161 : uint32 nCol, uint32 nRow);
162 :
163 : uint32 ReadTile(void * pData, uint32 nCol, uint32 nRow, uint32 nSize);
164 :
165 : bool ReadPartialSparseTile(void * pData,
166 : uint32 nCol, uint32 nRow,
167 : uint32 nOffset, uint32 nSize);
168 :
169 : bool ReadPartialTile(void * pData,
170 : uint32 nCol, uint32 nRow,
171 : uint32 nOffset, uint32 nSize);
172 :
173 : void SetTileLayerInfo(uint32 nXSize, uint32 nYSize,
174 : uint32 nTileXSize, uint32 nTileYSize,
175 : const std::string & oDataType,
176 : const std::string & oCompress,
177 : bool bNoDataValid = false,
178 : double dfNoDataValue = 0.0);
179 :
180 : /**
181 : * Gets the type of the layer.
182 : *
183 : * @return The type of the layer.
184 : */
185 410 : virtual uint16 GetLayerType(void) const override
186 : {
187 410 : return mpsBlockLayer->nLayerType;
188 : }
189 :
190 : /**
191 : * Gets the number of blocks in the block layer.
192 : *
193 : * @return The number of blocks in the block layer.
194 : */
195 318 : virtual uint32 GetBlockCount(void) const override
196 : {
197 318 : return mpsBlockLayer->nBlockCount;
198 : }
199 :
200 : /**
201 : * Gets the size in bytes of the layer.
202 : *
203 : * @return The size in bytes of the layer.
204 : */
205 122 : virtual uint64 GetLayerSize(void) const override
206 : {
207 122 : return mpsBlockLayer->nLayerSize;
208 : }
209 :
210 : /**
211 : * Gets the width of the tile layer.
212 : *
213 : * @return The width of the tile layer.
214 : */
215 207 : uint32 GetXSize(void) const
216 : {
217 207 : return mpsTileLayer->nXSize;
218 : }
219 :
220 : /**
221 : * Gets the height of the tile layer.
222 : *
223 : * @return The height of the tile layer.
224 : */
225 100 : uint32 GetYSize(void) const
226 : {
227 100 : return mpsTileLayer->nYSize;
228 : }
229 :
230 : /**
231 : * Gets the width of a tile.
232 : *
233 : * @return The width of a tile.
234 : */
235 538 : uint32 GetTileXSize(void) const
236 : {
237 538 : return mpsTileLayer->nTileXSize;
238 : }
239 :
240 : /**
241 : * Gets the height of a tile.
242 : *
243 : * @return The height of a tile.
244 : */
245 324 : uint32 GetTileYSize(void) const
246 : {
247 324 : return mpsTileLayer->nTileYSize;
248 : }
249 :
250 : const char * GetDataType(void) const;
251 :
252 : const char * GetCompressType(void) const;
253 :
254 : /**
255 : * Checks if the NoData value is valid.
256 : *
257 : * @return If the NoData value is valid.
258 : */
259 : bool IsNoDataValid(void) const
260 : {
261 : return mpsTileLayer->bNoDataValid != 0;
262 : }
263 :
264 : /**
265 : * Gets the NoData value of the tile layer.
266 : *
267 : * @return The NoData value of the tile layer.
268 : */
269 : double GetNoDataValue(void) const
270 : {
271 : return mpsTileLayer->dfNoDataValue;
272 : }
273 : };
274 :
275 : } // namespace PCIDSK
276 :
277 : #endif
|