Writing a raster reader for DEM data

To read a new Digital Elevation Model (DEM format), you should write a subclass of IlvRasterAbstractReader with an addMap method. If you want to take advantage of map load and save features, you have to manage the serialization of the reader, that is, provide methods that perform the required functions.
To create the reader:
  1. Load a list of raster DEM files as shown in the following example.
    public class MyDEMReader extends IlvRasterAbstractReader {
        // list of files to be read.
        private ArrayList filenameList = new ArrayList();
        /** default constructor */
        public MyDEMReader() {
        }
    
  2. Write an addMap method to compute the IlvRasterProperties and IlvRasterMappedBuffer attached to the file name, see Raster image management, and then add this information to the list managed by the reader. As this step is heavily dependent upon format, only a summary is provided here.
    public void addMap(final String filename) throws IOException {
         IlvRasterProperties loadingRaster = read/compute raster properties ...
         IlvRasterMappedBuffer source= read/compute raster pixel values...
        loadingRaster.setBaseName(filename);
        // to retrieve the file name when serializing data.
        addRaster(loadingRaster, source);
          }
    
To use the map load and save features:
  1. Serialize all the necessary information to rebuild the images - in this example, only the filenames.
        public void write(IlvOutputStream stream) throws IOException {
            super.write(stream);
            int imageCount = getImageCount();
            for (int i = 0; i < imageCount; i++) {
                IlvRasterProperties props=getRasterProperties(i);
                stream.write("filename"+i,props.getBaseName());
            }
        }
    
  2. Rebuild the reader from serialized data. Because the image data may have been saved in an IMG file associated with the map, you should only read the filenames of the raster DEM not the files themselves:
     public MyDEMReader(IlvInputStream stream) throws IlvReadFileException {
          super(stream);
          try {
                 for(int count=0;true;count++) {
                  String filename = stream.readString("filename"+count);
                  filenameList.add(filename);
              }
          } catch (IlvReadFileException e1) {
              // No more filenames to read
          }
        }
    
  3. If the complete map data is saved, the raw image data is reconnected by standard mechanisms. However, to reload files when the user has only saved the description of the map and not its data, write a reload method:
        public void reload(IlvThreadMonitoringData monitorInfo) {
            super.reload(monitorInfo);
            // clear all images
            dispose();
            // save the known filenames in a temporary array – the addMap would 
    else add them again.
            String[] filenames = (String[])filenameList.toArray(new String[0]);
            // clear the file name list
            filenameList.clear();
            for (int i = 0; i < filenames.length; i++) {
                try {
                    // load each file
                    addMap(filenames[i]);
                    if (monitorInfo != null) {
                        // update the thread monitoring information, if 
    necessary
                        int percent = Math.round(i/(float)filenames.length
                        * 100);
                        monitorInfo.updateProgress(percent);
                    }
                } catch (IOException e) {
                    new IlvExceptionMessage(e,null);
                }
            }
        }