Commit 90ee8a73 authored by Sankhesh Jhaveri's avatar Sankhesh Jhaveri

SEG-Y: Switch between source, CDP and custom bytes for XY coordinates

This change allows one to set whether the segy file uses source or
CDP coodinates. The reader also exposes a custom mode which allows the
user to set custom byte positions for trace X/Y coordinates.
parent 2776fd15
......@@ -30,6 +30,10 @@ vtkSegY2DReader::vtkSegY2DReader()
this->FileName = nullptr;
this->SetNumberOfInputPorts(0);
this->Reader = new vtkSegYReader();
this->XYCoordMode = VTK_SEGY_SOURCE;
this->XCoordByte = 73;
this->YCoordByte = 77;
}
//-----------------------------------------------------------------------------
......@@ -40,6 +44,24 @@ vtkSegY2DReader::~vtkSegY2DReader()
this->Reader = nullptr;
}
//-----------------------------------------------------------------------------
void vtkSegY2DReader::SetXYCoordModeToSource()
{
this->SetXYCoordMode(VTK_SEGY_SOURCE);
}
//-----------------------------------------------------------------------------
void vtkSegY2DReader::SetXYCoordModeToCDP()
{
this->SetXYCoordMode(VTK_SEGY_CDP);
}
//-----------------------------------------------------------------------------
void vtkSegY2DReader::SetXYCoordModeToCustom()
{
this->SetXYCoordMode(VTK_SEGY_CUSTOM);
}
//-----------------------------------------------------------------------------
int vtkSegY2DReader::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
......@@ -55,6 +77,31 @@ int vtkSegY2DReader::RequestData(vtkInformation* vtkNotUsed(request),
return 0;
}
switch(this->XYCoordMode)
{
case VTK_SEGY_SOURCE:
{
this->Reader->SetXYCoordBytePositions(72, 76);
break;
}
case VTK_SEGY_CDP:
{
this->Reader->SetXYCoordBytePositions(180, 184);
break;
}
case VTK_SEGY_CUSTOM:
{
this->Reader->SetXYCoordBytePositions(this->XCoordByte - 1,
this->YCoordByte - 1);
break;
}
default:
{
vtkErrorMacro(<< "Unknown value for XYCoordMode " << this->XYCoordMode);
return 1;
}
}
this->Reader->LoadFromFile(FileName);
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
......
......@@ -30,16 +30,60 @@ public:
vtkTypeMacro(vtkSegY2DReader, vtkStructuredGridAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
vtkSetStringMacro(FileName);
vtkSegY2DReader();
~vtkSegY2DReader();
vtkSetStringMacro(FileName);
enum VTKSegYCoordinateModes
{
VTK_SEGY_SOURCE = 0, // default
VTK_SEGY_CDP = 1,
VTK_SEGY_CUSTOM = 2
};
//@{
/**
* Specify whether to use source x/y coordinates or CDP coordinates or custom
* byte positions for data position in the SEG-Y trace header. Defaults to
* source x/y coordinates.
*
* As per SEG-Y rev 2.0 specification,
* Source XY coordinate bytes = (73, 77)
* CDP XY coordinate bytes = (181, 185)
*/
vtkSetClampMacro(XYCoordMode, int, VTK_SEGY_SOURCE, VTK_SEGY_CUSTOM);
vtkGetMacro(XYCoordMode, int);
vtkBooleanMacro(XYCoordMode, int);
void SetXYCoordModeToSource();
void SetXYCoordModeToCDP();
void SetXYCoordModeToCustom();
//@}
//@{
/**
* Specify X and Y byte positions for custom XYCoordinateMode.
* By default, XCoordByte = 73, YCoordByte = 77 i.e. source xy.
*
* \sa SetXYCoordinatesModeToCustom()
*/
vtkSetMacro(XCoordByte, int);
vtkGetMacro(XCoordByte, int);
vtkSetMacro(YCoordByte, int);
vtkGetMacro(YCoordByte, int);
//@}
protected:
int RequestData(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector) VTK_OVERRIDE;
int XYCoordMode;
// Custom XY coordinate byte positions
int XCoordByte;
int YCoordByte;
private:
char* FileName;
vtkSegYReader* Reader;
......
......@@ -47,6 +47,12 @@ vtkSegYReader::~vtkSegYReader()
delete trace;
}
//-----------------------------------------------------------------------------
void vtkSegYReader::SetXYCoordBytePositions(int x, int y)
{
this->TraceReader->SetXYCoordBytePositions(x, y);
}
//-----------------------------------------------------------------------------
bool vtkSegYReader::LoadFromFile(std::string path)
{
......
......@@ -39,6 +39,7 @@ public:
bool LoadFromFile(std::string path);
void ExportData2D(vtkStructuredGrid*);
void AddScalars(vtkStructuredGrid*);
void SetXYCoordBytePositions(int x, int y);
private:
bool ReadHeader(std::ifstream& in);
......
......@@ -24,14 +24,15 @@ public:
int CrosslineNumber;
int TraceNumberWithinEnsemble;
int CoordinateMultiplier;
int XCoordinate;
int YCoordinate;
int CoordinateUnits;
int NumberSamples;
int SampleInterval;
public:
vtkSegYTraceHeaderBytesPositions() { initDefaultValues(); }
vtkSegYTraceHeaderBytesPositions()
{
initDefaultValues();
}
private:
void initDefaultValues()
......@@ -41,8 +42,6 @@ private:
CrosslineNumber = 20;
TraceNumberWithinEnsemble = 24;
CoordinateMultiplier = 70;
XCoordinate = 72;
YCoordinate = 76;
CoordinateUnits = 88;
NumberSamples = 114;
SampleInterval = 116;
......
......@@ -18,6 +18,20 @@
#include <iostream>
//-----------------------------------------------------------------------------
vtkSegYTraceReader::vtkSegYTraceReader()
{
this->XCoordinate = 72;
this->YCoordinate = 76;
}
//-----------------------------------------------------------------------------
void vtkSegYTraceReader::SetXYCoordBytePositions(int x, int y)
{
this->XCoordinate = x;
this->YCoordinate = y;
}
//-----------------------------------------------------------------------------
void vtkSegYTraceReader::PrintTraceHeader(std::ifstream& in, int startPos)
{
......@@ -61,12 +75,12 @@ void vtkSegYTraceReader::PrintTraceHeader(std::ifstream& in, int startPos)
std::cout << "coordinate multiplier : " << coordinateMultiplier << std::endl;
int xCoordinate = vtkSegYIOUtils::Instance()->readLongInteger(
startPos + traceHeaderBytesPos.XCoordinate, in);
startPos + this->XCoordinate, in);
std::cout << "X coordinate for ensemble position of the trace : "
<< xCoordinate << std::endl;
int yCoordinate = vtkSegYIOUtils::Instance()->readLongInteger(
startPos + traceHeaderBytesPos.YCoordinate, in);
startPos + this->YCoordinate, in);
std::cout << "Y coordinate for ensemble position of the trace : "
<< yCoordinate << std::endl;
......@@ -96,9 +110,9 @@ bool vtkSegYTraceReader::ReadTrace(int& startPos,
int numSamples = vtkSegYIOUtils::Instance()->readShortInteger(
startPos + traceHeaderBytesPos.NumberSamples, in);
trace->xCoordinate = vtkSegYIOUtils::Instance()->readLongInteger(
startPos + traceHeaderBytesPos.XCoordinate, in);
startPos + this->XCoordinate, in);
trace->yCoordinate = vtkSegYIOUtils::Instance()->readLongInteger(
startPos + traceHeaderBytesPos.YCoordinate, in);
startPos + this->YCoordinate, in);
trace->CoordinateMultiplier = vtkSegYIOUtils::Instance()->readShortInteger(
startPos + traceHeaderBytesPos.CoordinateMultiplier, in);
trace->SampleInterval = vtkSegYIOUtils::Instance()->readShortInteger(
......
......@@ -44,7 +44,13 @@ class vtkSegYTraceReader
private:
vtkSegYTraceHeaderBytesPositions traceHeaderBytesPos;
int XCoordinate;
int YCoordinate;
public:
vtkSegYTraceReader();
void SetXYCoordBytePositions(int x, int y);
void PrintTraceHeader(std::ifstream& in, int startPos);
bool ReadTrace(int& startPos,
std::ifstream& in,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment