001: package it.geosolutions.imageio.plugins.jhdf;
002:
003: import javax.imageio.metadata.IIOMetadata;
004: import javax.imageio.metadata.IIOMetadataNode;
005:
006: import ncsa.hdf.object.Dataset;
007:
008: public abstract class BaseHDFImageMetadata extends IIOMetadata {
009:
010: /** The Dataset Name */
011: protected String name = "";
012:
013: /** The Dataset Rank */
014: protected int rank = -1;
015:
016: /** The Dataset Dims Sizes.
017: * As an Instance, a Dataset may have (x,y,z,t) respectively (3200,2000,10,5)
018: */
019: protected long dims[] = null;
020:
021: /** The Dataset Chunk Size expressed as a String.
022: * As an Instance, a 2D Dataset may have a chunk size of 512*512
023: * In such a case, chunkSize value is "512,512".
024: * */
025: protected long chunkSize[] = null;
026:
027: public BaseHDFImageMetadata(
028: boolean standardMetadataFormatSupported,
029: String nativeMetadataFormatName,
030: String nativeMetadataFormatClassName,
031: String[] extraMetadataFormatNames,
032: String[] extraMetadataFormatClassNames) {
033: super (standardMetadataFormatSupported,
034: nativeMetadataFormatName,
035: nativeMetadataFormatClassName,
036: extraMetadataFormatNames, extraMetadataFormatClassNames);
037: }
038:
039: /**
040: * Returns a <code>IIOMetadataNode</code> which should be common to each
041: * specific {@link BaseHDFImageMetada} extension since each HDF dataset
042: * has a Rank, a Name, a set of dims length.
043: *
044: * @return the <code>IIOMetadataNode</code> common to each HDF metadata.
045: */
046: protected IIOMetadataNode getCommonDatasetNode() {
047: //The generated Node is common to each HDF metadata structure.
048:
049: /*
050: * root
051: * +-- datasetProperties (Name, Rank, Dims, ChunkSize)
052: */
053:
054: final IIOMetadataNode datasetNode = new IIOMetadataNode(
055: "DatasetProperties");
056: datasetNode.setAttribute("Name", name);
057: datasetNode.setAttribute("Rank", Integer.toString(rank));
058:
059: String sDims = "";
060: if (dims != null) {
061: final int dimsLength = dims.length;
062: final StringBuffer sb = new StringBuffer();
063: for (int i = 0; i < dimsLength; i++) {
064: sb.append(Long.toString(dims[i]));
065: if (i != dimsLength - 1)
066: sb.append(",");
067: }
068: sDims = sb.toString().trim();
069: }
070: datasetNode.setAttribute("Dims", sDims);
071:
072: String sChunkSize = "";
073: if (chunkSize != null) {
074: final int chunkSizeLength = chunkSize.length;
075: final StringBuffer sb = new StringBuffer();
076: for (int i = 0; i < chunkSizeLength; i++) {
077: sb.append(Long.toString(chunkSize[i]));
078: if (i != chunkSizeLength - 1)
079: sb.append(",");
080: }
081: sChunkSize = sb.toString().trim();
082: }
083:
084: datasetNode.setAttribute("ChunkSize", sChunkSize);
085: //TODO: Should I add envelope?
086: return datasetNode;
087: }
088:
089: protected void initializeCommonDatasetProperties(
090: SubDatasetInfo sdInfo) {
091: // setting dims (array copy)
092: final long dims[] = sdInfo.getDims();
093: if (dims != null) {
094: final int dimsLength = dims.length;
095: this .dims = new long[dimsLength];
096: for (int i = 0; i < dimsLength; i++)
097: this .dims[i] = dims[i];
098: }
099:
100: // setting chunkSize (array copy)
101: final long chunkSize[] = sdInfo.getChunkSize();
102: if (chunkSize != null) {
103: final int chunkSizeLength = chunkSize.length;
104: this .chunkSize = new long[chunkSizeLength];
105: for (int i = 0; i < chunkSizeLength; i++)
106: this .chunkSize[i] = chunkSize[i];
107: }
108:
109: // setting rank
110: this .rank = sdInfo.getRank();
111:
112: // setting name
113: this .name = sdInfo.getName();
114: }
115:
116: /**
117: * Set properties common to each HDF format (not a specific "profile").
118: * That is, any HDF dataset has a Rank, a Name, a set of dims length.
119: *
120: * @param dataset
121: */
122: protected void initializeCommonDatasetProperties(Dataset dataset) {
123: // setting dims (array copy)
124: final long dims[] = dataset.getDims();
125: if (dims != null) {
126: final int dimsLength = dims.length;
127: this .dims = new long[dimsLength];
128: for (int i = 0; i < dimsLength; i++)
129: this .dims[i] = dims[i];
130: }
131:
132: // setting chunkSize (array copy)
133: final long chunkSize[] = dataset.getChunkSize();
134: if (chunkSize != null) {
135: final int chunkSizeLength = chunkSize.length;
136: this .chunkSize = new long[chunkSizeLength];
137: for (int i = 0; i < chunkSizeLength; i++)
138: this .chunkSize[i] = chunkSize[i];
139: }
140:
141: // setting rank
142: this .rank = dataset.getRank();
143:
144: // setting name
145: this.name = dataset.getName();
146: }
147: }
|