Note: You will need to include GridSurfaceData to your Module Dependencies list.
We load an grid surface called filePath and print the access keys' name and range. If your application requires a file chooser for selecting the grid surface file, you can use the one provided with INTViewer. See section Using the Grid Surface File Chooser below for an example.
import com.interactive.intviewerapi.data.IData;
import com.interactive.intviewerapi.data.gridsurface.IGrid SurfaceData;
import com.interactive.intviewerapi.data.gridsurface.IGridSurfaceDataCollection;
...
try {
IGridSurfaceDataCollection hd = IData.factory.createNewInstance(filePath, IGridSurfaceDataCollection.class);
} catch (Exception ex) {
DialogManager.getDefault().showMessageDialog("Error loading grid: " + filePath,
"Error Loading Grid Surface", DialogManager.ERROR);
return;
}
for (IGridSurfaceDataCollection shd: hd.getAllGridSurfaceData()){
List<IKeyRange> klist = shd.getDataRange();
for (IKeyRange kr:klist) {
System.out.println(kr);
}
}
Internally, the default factory uses Netbeans FileObject and DataObject to load the grid surface. Netbeans filesystem supports the notion of a data pool, so that if you open several times the same file, you will get the same data object instance.
This example shows how to let a user select a grid surface file using the built-in grid surface file selection dialog in INTViewer. The chooser is automatically setup to filter valid grid surface filenames. By default, the chooser enables multiple grid surface file selection.
To select one dataset:
import com.interactive.intviewerapi.data.ISingleDataChooser;
// get the chooser for grid surface data type
ISingleDataChooser<IGridSurfaceDataCollection> singleChooser = ISingleDataChooser.Factory.createNewInstance(IDataChooser.GRID_SURFACE);
// popup the chooser dialog
int rc = singleChooser.setDataChooserVisible(true);
if (rc == JFileChooser.APPROVE_OPTION) {
IGridSurfaceDataCollection gridSurfaceData = singleChooser.getSelectedData();
}
To select multiple datasets:
import com.interactive.intviewerapi.data.IMultipleDataChooser;
// get the file chooser for grid surface data type
IMultipleDataChooser<IGridSurfaceDataCollection> multipleChooser = IMultipleDataChooser.Factory.createNewInstance(IDataChooser.GRID_SURFACE);
// popup the chooser dialog
int rc = multipleChooser.setDataChooserVisible(true);
if (rc == JFileChooser.APPROVE_OPTION) {
for (IGridSurfaceDataCollection gridSurfaceData : multipleChooser.getSelectedData()) {
}
}
Range keys provide information about how to access the horizon data. They can be accessed as follows:
List<IKeyRange> keyRangeList = gsd.getDataRange();
Unlike in seismic datasets, the last key of a grid surface dataset is usually NOT the time key as it is a non-indexed attribute. The key names of a grid surface are X and Y. Time, Amplitude are usually non-indexed attributes.
We create a grid surface with:
import com.interactive.intviewerapi.data.gridsurface.GridSurfaceUtil;
import com.interactive.intviewerapi.data.FieldDesc;
...
float[][] attributeValues = new float[2][50*40];
IGridSurfaceData gsd = GridSurfaceUtil.createGridSurfaceData("tmp",
new FieldDesc[]{
new FieldDesc("Time", 0),
new FieldDesc("Amplitude", 1)
}, new Point2D.Double(0, 0), 80, 90, 50, 40, (float) Math.PI/4d, attributeValues);
We retrieve all the points for row 40 for the dataset created above.
IGridSurfaceData gsd = ...
for (int columnIndex = 0; columnIndex < gsd.getColumnCount(); columnIndex++) {
double currentTime = gsd.getValueAt(40, columnIndex, 0);
double currentAmplitude = gsd.getValueAt(40, columnIndex, 1);
}
Grid surface datasets are read-only. You cannot add, update or delete points.
You could do the following to save a grid surface:
ISingleDataSaver ds = ISingleDataSaver.Factory.createNewInstance(IDataChooser.GRID_SURFACE);
if (ds.setDataSaverVisible(true, gridSurfaceData.getDataPath(), gridSurfaceData) == JFileChooser.APPROVE_OPTION) {
GridSurfaceDataCollection savingGridSurfaces = GridSurfaceUtil.createGridSurfaceDataCollection("temp");
savingGridSurfaces.addGridSurfaceData(gridSurfaceData);
FileObject fo = (FileObject) ds.saveDataAndWait(savingGridSurfaces);
if (fo != null) {
String absoluteDataPath = FileUtil.toFile(fo).getAbsolutePath();
if (gridSurfaceData.getDataPath() == null || gridSurfaceData.getDataPath().length() == 0) {
gridSurfaceData.setDataPath(absoluteDataPath);
}
}
}
This would display a dialog to let the users select the fileName in which they want to save the IGridSurfaceData.
Note: in your project module properties, you will need to include File System API to your Module Dependencies list.
This example shows how to extract a single IGridSurfaceData object out of an IData object that could be IGridSurfaceData or IGridSurfaceDataCollection.
if (data instanceof IGridSurfaceData) {
return ( IGridSurfaceData ) data;
} else if (data instanceof IGridSurfaceDataCollection) {
IGridSurfaceData currentData = null;
if (data.getDataName() != null) {
currentData = ((IGridSurfaceDataCollection) data).getGridSurfaceData(data.getDataName());
}
if (currentData == null) {
currentData = ((IGridSurfaceDataCollection) data).getAllGridSurfaceData()[0];
}
return (IGridSurfaceData) currentData;
} else {
return null;
}