vtkSegYTraceReader.cxx 7.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkSegYTraceReader.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "vtkSegYTraceReader.h"
#include "vtkSegYIOUtils.h"

#include <iostream>

21 22 23 24 25 26 27 28 29 30 31 32 33 34
//-----------------------------------------------------------------------------
vtkSegYTraceReader::vtkSegYTraceReader()
{
  this->XCoordinate = 72;
  this->YCoordinate = 76;
}

//-----------------------------------------------------------------------------
void vtkSegYTraceReader::SetXYCoordBytePositions(int x, int y)
{
  this->XCoordinate = x;
  this->YCoordinate = y;
}

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
//-----------------------------------------------------------------------------
void vtkSegYTraceReader::PrintTraceHeader(std::ifstream& in, int startPos)
{
  int traceSequenceNumberInLine = vtkSegYIOUtils::Instance()->readLongInteger(
    startPos + traceHeaderBytesPos.TraceNumber, in);
  std::cout << "Trace sequence number in line : " << traceSequenceNumberInLine
            << std::endl;

  int traceSequenceNumberInFile =
    vtkSegYIOUtils::Instance()->readLongInteger(in);
  std::cout << "Trace sequence number in file : " << traceSequenceNumberInFile
            << std::endl;

  // Get number_of_samples from trace header position 115-116
  int numSamples = vtkSegYIOUtils::Instance()->readShortInteger(
    startPos + traceHeaderBytesPos.NumberSamples, in);
  std::cout << "number of samples: " << numSamples << std::endl;

  short sampleInterval = vtkSegYIOUtils::Instance()->readShortInteger(
    startPos + traceHeaderBytesPos.SampleInterval, in);
  std::cout << "sample interval: " << sampleInterval << std::endl;

  // Get inline number from trace header position 189-192
  int inlineNum = vtkSegYIOUtils::Instance()->readLongInteger(
    startPos + traceHeaderBytesPos.InlineNumber, in);
  std::cout << "Field record number (inline number) : " << inlineNum
            << std::endl;

  int crosslineNum = vtkSegYIOUtils::Instance()->readLongInteger(
    startPos + traceHeaderBytesPos.CrosslineNumber, in);
  std::cout << "cross-line number (ensemble number) : " << crosslineNum
            << std::endl;

  int traceNumberWithinEnsemble = vtkSegYIOUtils::Instance()->readLongInteger(
    startPos + traceHeaderBytesPos.TraceNumberWithinEnsemble, in);
  std::cout << "trace number within ensemble : " << traceNumberWithinEnsemble
            << std::endl;

  short coordinateMultiplier = vtkSegYIOUtils::Instance()->readShortInteger(
    startPos + traceHeaderBytesPos.CoordinateMultiplier, in);
  std::cout << "coordinate multiplier : " << coordinateMultiplier << std::endl;

  int xCoordinate = vtkSegYIOUtils::Instance()->readLongInteger(
78
    startPos + this->XCoordinate, in);
79 80 81 82
  std::cout << "X coordinate for ensemble position of the trace : "
            << xCoordinate << std::endl;

  int yCoordinate = vtkSegYIOUtils::Instance()->readLongInteger(
83
    startPos + this->YCoordinate, in);
84 85 86 87 88 89 90 91 92
  std::cout << "Y coordinate for ensemble position of the trace : "
            << yCoordinate << std::endl;

  short coordinateUnits = vtkSegYIOUtils::Instance()->readShortInteger(
    startPos + traceHeaderBytesPos.CoordinateUnits, in);
  std::cout << "coordinateUnits: " << coordinateUnits << std::endl;
}

//-----------------------------------------------------------------------------
Dan Lipsa's avatar
Dan Lipsa committed
93 94 95 96
void vtkSegYTraceReader::ReadTrace(int& startPos,
                                   std::ifstream& in,
                                   int formatCode,
                                   vtkSegYTrace* trace)
97
{
98
  trace->InlineNumber = vtkSegYIOUtils::Instance()->readLongInteger(
99
    startPos + traceHeaderBytesPos.InlineNumber, in);
100
  trace->CrosslineNumber = vtkSegYIOUtils::Instance()->readLongInteger(
Dan Lipsa's avatar
Dan Lipsa committed
101
    startPos + traceHeaderBytesPos.CrosslineNumber, in);
102 103
  int numSamples = vtkSegYIOUtils::Instance()->readShortInteger(
    startPos + traceHeaderBytesPos.NumberSamples, in);
Dan Lipsa's avatar
Dan Lipsa committed
104 105
  trace->CoordinateMultiplier = vtkSegYIOUtils::Instance()->readShortInteger(
    startPos + traceHeaderBytesPos.CoordinateMultiplier, in);
106
  trace->XCoordinate = vtkSegYIOUtils::Instance()->readLongInteger(
107
    startPos + this->XCoordinate, in);
108
  trace->YCoordinate = vtkSegYIOUtils::Instance()->readLongInteger(
109
    startPos + this->YCoordinate, in);
110 111 112 113
  trace->SampleInterval = vtkSegYIOUtils::Instance()->readShortInteger(
    startPos + traceHeaderBytesPos.SampleInterval, in);

  in.seekg(startPos + 240, in.beg);
Dan Lipsa's avatar
Dan Lipsa committed
114 115
  float value;
  switch (formatCode)
116
  {
Dan Lipsa's avatar
Dan Lipsa committed
117 118 119 120
  case 1:
    for (int i = 0; i < numSamples; i++)
    {
      value = vtkSegYIOUtils::Instance()->readIBMFloat(in);
121
      trace->Data.push_back(value);
Dan Lipsa's avatar
Dan Lipsa committed
122 123
    }
    break;
124 125 126 127 128 129 130
  case 3:
    for (int i = 0; i < numSamples; i++)
    {
      value = vtkSegYIOUtils::Instance()->readShortInteger(in);
      trace->Data.push_back(value);
    }
    break;
Dan Lipsa's avatar
Dan Lipsa committed
131 132 133 134
  case 5:
    for (int i = 0; i < numSamples; i++)
    {
      value = vtkSegYIOUtils::Instance()->readFloat(in);
135
      trace->Data.push_back(value);
Dan Lipsa's avatar
Dan Lipsa committed
136 137 138 139
    }
    break;
  case 8:
    for (int i = 0; i < numSamples; i++)
140
    {
Dan Lipsa's avatar
Dan Lipsa committed
141
      value = vtkSegYIOUtils::Instance()->readChar(in);
142
      trace->Data.push_back(value);
143
    }
Dan Lipsa's avatar
Dan Lipsa committed
144 145 146 147 148
    break;
  default:
    std::cerr << "Data sample format code " << formatCode
              << " not supported." << std::endl;
    value = 0;
149 150
  }

Dan Lipsa's avatar
Dan Lipsa committed
151
  startPos += 240 + this->GetTraceSize(numSamples, formatCode);
152 153
}

Dan Lipsa's avatar
Dan Lipsa committed
154 155

//-----------------------------------------------------------------------------
156 157 158 159 160 161
void vtkSegYTraceReader::ReadInlineCrossline(
  int& startPos,
  std::ifstream& in,
  int formatCode,
  int* inlineNumber, int* crosslineNumber,
  int* xCoord, int* yCoord, short* coordMultiplier)
Dan Lipsa's avatar
Dan Lipsa committed
162 163 164 165 166 167 168
{
  *inlineNumber = vtkSegYIOUtils::Instance()->readLongInteger(
    startPos + traceHeaderBytesPos.InlineNumber, in);
  *crosslineNumber = vtkSegYIOUtils::Instance()->readLongInteger(
    startPos + traceHeaderBytesPos.CrosslineNumber, in);
  int numSamples = vtkSegYIOUtils::Instance()->readShortInteger(
    startPos + traceHeaderBytesPos.NumberSamples, in);
169 170 171 172 173 174 175

  *xCoord = vtkSegYIOUtils::Instance()->readLongInteger(
    startPos + this->XCoordinate, in);
  *yCoord = vtkSegYIOUtils::Instance()->readLongInteger(
    startPos + this->YCoordinate, in);
  *coordMultiplier = vtkSegYIOUtils::Instance()->readShortInteger(
    startPos + traceHeaderBytesPos.CoordinateMultiplier, in);
Dan Lipsa's avatar
Dan Lipsa committed
176 177 178 179
  startPos += 240 + this->GetTraceSize(numSamples, formatCode);
}


180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
//-----------------------------------------------------------------------------
int vtkSegYTraceReader::GetTraceSize(int numSamples, int formatCode)
{
  if (formatCode == 1 || formatCode == 2 || formatCode == 4 || formatCode == 5)
  {
    return 4 * numSamples;
  }
  if (formatCode == 3)
  {
    return 2 * numSamples;
  }
  if (formatCode == 8)
  {
    return numSamples;
  }
  std::cerr << "Unsupported data format code : " << formatCode << std::endl;
196
  return -1;
197
}