Working with PointSet Data
Note: You will need to include PointSetData to your Module Dependencies list.
Loading a pointset from a file
import com.interactive.intviewerapi.data.IData;
import com.interactive.intviewerapi.data.pointset.IPointSetData;
import com.interactive.intviewerapi.data.pointset.IPointsetDataCollection;
...
try {
IPointSetData hd = IData.factory.createNewInstance(filePath, IPointSetData.class);
} catch (Exception ex) {
DialogManager.getDefault().showMessageDialog("Error loading pointset: " + filename,
"Error Loading Pointset", DialogManager.ERROR);
return;
}
List<IKeyRange> klist = hd.getDataRange();
for (IKeyRange kr:klist) {
System.out.println(kr);
}
Using the pointset file chooser
To select one dataset:
import com.interactive.intviewerapi.data.ISingleDataChooser;
// get the chooser for pointset data type
ISingleDataChooser<IPointSetData> singleChooser = ISingleDataChooser.Factory.createNewInstance(IDataChooser.POINTSET);
// popup the chooser dialog
int rc = singleChooser.setDataChooserVisible(true);
if (rc == JFileChooser.APPROVE_OPTION) {
IPointSetData pointSetData = singleChooser.getSelectedData();
}
To select multiple datasets:
import com.interactive.intviewerapi.data.IMultipleDataChooser;
// get the file chooser for pointset data type
IMultipleDataChooser<IPointSetData> multipleChooser = IMultipleDataChooser.Factory.createNewInstance(IDataChooser.POINTSET);
// popup the chooser dialog
int rc = multipleChooser.setDataChooserVisible(true);
if (rc == JFileChooser.APPROVE_OPTION) {
for (IPointSetData pointSetData: multipleChooser.getSelectedData()) {
}
}
Creating a pointset from scratch
You can use the PointSetUtil.createPointSetData method to create a pointset from scratch. The time key should be specified using the setTimeKey method.
IPointSetData hd = PointSetUtil.createPointSetData("tmp",
new FieldDesc[]{
new FieldDesc("INLINE", 0, true),
new FieldDesc("XLINE", 1, true),
new FieldDesc("Time", 2, true),
new FieldDesc("Amplitude", 3)
});
hd.setTimeKey(2);
Getting information about the data keys
Range keys provide information about how to access the horizon data. They can be accessed as follows:
List<IKeyRange> keyRangeList = hd.getDataRange();
Unlike in horizons where the time key is usually not indexed, the last key of a pointset dataset can be the Time key. The key names of a pointset are typically INLINE, XLINE and Time.Amplitude is usually a non-indexed attribute.
Adding points
The following example shows how to populate the empty pointSet created in the previous section.
import com.interactive.intviewerapi.data.PointData;
...
for (int inline= 0; inline < 400; inline++) {
for (int xline = 0; xline < 400; xline++) {
PointData pd = new PointData(4);
pd.setValues(new float[] {inline, xline,
inline*0.1f, (xline+inline)*13.45f});
hd.addPoint(pd);
}
}
Each time a point is added, a PointDataEvent is sent. This can cause performance issues when a large number of points has to be added. Wrap this code inside a IPointSetData.update method to reduce the event overhead.
hd.update(new Runnable() {
@Override
public void run() {
for (int inline= 0; inline < 400; inline++) {
for (int xline = 0; xline < 400; xline++) {
PointData pd = hd.createPointData();
pd.setValues(new float[] {inline, xline,
inline*0.1f, (xline+inline)*13.45f});
hd.addPoint(pd);
}
}
}
});
Deleting points
We delete all the points within INLINE 20-21 and XLINE 30-31.
import com.interactive.intviewerapi.data.IPointSelection;
import com.interactive.intviewerapi.data.KeyRange;
import com.interactive.intviewerapi.data.query.RangeQuery;
...
RangeQuery rq = new RangeQuery();
rq.addKeyRange(new KeyRange("INLINE", 20, 21 ));
rq.addKeyRange(new KeyRange("XLINE", 30, 31 ));
IPointSelection ps = hd.select(rq);
hd.delete(ps);
Querying points
We retrieve all the points for INLINE 40.
RangeQuery rq = new RangeQuery();
rq.addKeyRange(new KeyRange("INLINE", 40, 40 ));
IPointSelection ps = hd.select(rq);
List<PointData> dataList = ps.getData();
Saving a pointset
You could do the following to save a pointset:
ISingleDataSaver ds = ISingleDataSaver.Factory.createNewInstance(IDataChooser.POINTSET);
if (ds.setDataSaverVisible(true, pointsetData.getDataPath()) == JFileChooser.APPROVE_OPTION) {
FileObject fo = (FileObject) ds.saveDataAndWait(pointsetData);
String path = FileUtil.toFile(fo).getAbsolutePath();
if (pointsetData.getDataPath() != null || pointsetData.getDataPath().length() != 0) {
pointsetData.setDataPath(path);
}
}
}
This would display a dialog to let the users select the fileName in which they want to save the IPointSetData.