Updates will be applied - 12:30pm EDT (UTC -400). Site will be down for around 30

Commit 548842a7 authored by Dan Lipsa's avatar Dan Lipsa

Use SegYReader for both 2D and 3D data.

parent 7e882559
set(Module_SRCS
vtkSegY2DReader.cxx
vtkSegY3DReader.cxx
vtkSegYReader.cxx
)
set (Module_PRIVATE_SRCS
vtkSegYIOUtils.cxx
vtkSegYReader.cxx
vtkSegYReaderInternal.cxx
vtkSegYTraceReader.cxx
)
......
......@@ -12,11 +12,11 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME Test of vtkSegY2DReader
// .NAME Test of vtkSegYReader
// .SECTION Description
//
#include "vtkSegY2DReader.h"
#include "vtkSegYReader.h"
#include "vtkActor.h"
#include "vtkCamera.h"
......@@ -59,7 +59,7 @@ int TestSegY2DReader(int argc, char* argv[])
lut->AddRGBPoint(0.0, 0.86, 0.86, 0.86);
lut->AddRGBPoint(6.6, 0.70, 0.02, 0.15);
vtkNew<vtkSegY2DReader> reader[5];
vtkNew<vtkSegYReader> reader[5];
vtkNew<vtkDataSetMapper> mapper[5];
vtkNew<vtkActor> actor[5];
......
......@@ -12,11 +12,11 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME Test of vtkSegY2DReader
// .NAME Test of vtkSegYReader
// .SECTION Description
//
#include "vtkSegY2DReader.h"
#include "vtkSegYReader.h"
#include "vtkActor.h"
#include "vtkCamera.h"
......@@ -49,7 +49,7 @@ int TestSegY2DReaderZoom(int argc, char* argv[])
char* fname =
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/SegY/lineA.sgy");
vtkNew<vtkSegY2DReader> reader;
vtkNew<vtkSegYReader> reader;
vtkNew<vtkDataSetMapper> mapper;
vtkNew<vtkActor> actor;
......@@ -60,7 +60,7 @@ int TestSegY2DReaderZoom(int argc, char* argv[])
int retVal = 0;
double range[2];
vtkStructuredGrid* output = reader->GetOutput();
vtkDataSet* output = reader->GetOutput();
output->GetScalarRange(range);
......
......@@ -12,11 +12,11 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME Test of vtkSegY2DReader
// .NAME Test of vtkSegYReader
// .SECTION Description
//
#include "vtkSegY3DReader.h"
#include "vtkSegYReader.h"
#include "vtkActor.h"
#include "vtkCamera.h"
......@@ -51,7 +51,7 @@ int TestSegY3DReader(int argc, char* argv[])
lut->AddRGBPoint(0.0, 0.86, 0.86, 0.86);
lut->AddRGBPoint(126, 0.70, 0.02, 0.15);
vtkNew<vtkSegY3DReader> reader;
vtkNew<vtkSegYReader> reader;
vtkNew<vtkDataSetMapper> mapper;
vtkNew<vtkActor> actor;
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSegY2DReader.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 "vtkSegY2DReader.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkSegYReader.h"
#include <chrono>
vtkStandardNewMacro(vtkSegY2DReader);
//-----------------------------------------------------------------------------
vtkSegY2DReader::vtkSegY2DReader()
{
this->FileName = nullptr;
this->SetNumberOfInputPorts(0);
this->Reader = new vtkSegYReader();
this->XYCoordMode = VTK_SEGY_SOURCE;
this->XCoordByte = 73;
this->YCoordByte = 77;
this->VerticalCRS = VTK_SEGY_VERTICAL_HEIGHTS;
}
//-----------------------------------------------------------------------------
vtkSegY2DReader::~vtkSegY2DReader()
{
this->SetFileName(nullptr);
delete this->Reader;
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),
vtkInformationVector* outputVector)
{
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkStructuredGrid* output =
vtkStructuredGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
if (!this->FileName)
{
vtkErrorMacro(<< "A File Name must be specified.");
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->SetVerticalCRS(this->VerticalCRS);
this->Reader->LoadFromFile(FileName);
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
vtkDebugMacro(<< "Exporting to poly data ...");
this->Reader->ExportData2D(output);
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
vtkDebugMacro(<< "Elapsed time: " << elapsed_seconds.count());
output->Squeeze();
return 1;
}
//-----------------------------------------------------------------------------
void vtkSegY2DReader::PrintSelf(ostream& os, vtkIndent indent)
{
os << indent << "FileName: " << (this->FileName ? this->FileName : "(none)")
<< endl;
switch (this->XYCoordMode)
{
case VTK_SEGY_SOURCE:
os << indent << "XYCoordMode: VTK_SEGY_SOURCE" << endl;
break;
case VTK_SEGY_CDP:
os << indent << "XYCoordMode: VTK_SEGY_CDP" << endl;
break;
case VTK_SEGY_CUSTOM:
os << indent << "XYCoordMode: VTK_SEGY_CUSTOM" << endl;
break;
default:
os << indent << "XYCoordMode: (unidentified)" << endl;
}
os << indent << "XCoordByte " << this->XCoordByte << endl;
os << indent << "YCoordByte " << this->YCoordByte << endl;
os << indent
<< "VerticalCRS: " << (this->VerticalCRS ? "VTK_SEGY_VERTICAL_DEPTHS"
: "VTK_SEGY_VERTICAL_HEIGHTS")
<< endl;
Superclass::PrintSelf(os, indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSegY2DReader.h
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.
=========================================================================*/
#ifndef vtkSegY2DReader_h
#define vtkSegY2DReader_h
#include "vtkStructuredGridAlgorithm.h"
#include <vtkIOSegYModule.h> // For export macro
// Forward declarations
class vtkSegYReader;
class VTKIOSEGY_EXPORT vtkSegY2DReader : public vtkStructuredGridAlgorithm
{
public:
static vtkSegY2DReader* New();
vtkTypeMacro(vtkSegY2DReader, vtkStructuredGridAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override;
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);
//@}
enum VTKSegYVerticalCRS
{
VTK_SEGY_VERTICAL_HEIGHTS = 0, // default
VTK_SEGY_VERTICAL_DEPTHS
};
//@{
/**
* Specify whether the vertical coordinates in the SEG-Y file are heights
* (positive up) or depths (positive down). By default, the vertical
* coordinates are treated as heights (i.e. positive up). This means that the
* Z-axis of the dataset goes from 0 (surface) to -ve depth (last sample).
* \note As per the SEG-Y rev 2.0 specification, this information is defined
* in the Location Data Stanza of the Extended Textual Header. However, as of
* this revision, vtkSegY2DReader does not support reading the extended
* textual header.
*/
vtkSetMacro(VerticalCRS, int);
vtkGetMacro(VerticalCRS, int);
//@}
protected:
int RequestData(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector) override;
int XYCoordMode;
// Custom XY coordinate byte positions
int XCoordByte;
int YCoordByte;
int VerticalCRS;
private:
char* FileName;
vtkSegYReader* Reader;
private:
vtkSegY2DReader(const vtkSegY2DReader&) = delete;
void operator=(const vtkSegY2DReader&) = delete;
};
#endif // vtkSegY2DReader_h
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSegY3DReader.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 "vtkImageData.h"
#include "vtkInformationVector.h"
#include "vtkInformation.h"
#include "vtkObjectFactory.h"
#include "vtkSegYReader.h"
#include "vtkSmartPointer.h"
#include "vtkSegY3DReader.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStructuredGrid.h"
#include <algorithm>
#include <iostream>
#include <iterator>
vtkStandardNewMacro(vtkSegY3DReader);
//-----------------------------------------------------------------------------
vtkSegY3DReader::vtkSegY3DReader()
{
this->SetNumberOfInputPorts(0);
this->Reader = new vtkSegYReader();
this->FileName = nullptr;
this->Is3D = false;
this->DataOrigin[0] = this->DataOrigin[1] = this->DataOrigin[2] = 0.0;
this->DataSpacing[0] = this->DataSpacing[1] = this->DataSpacing[2] = 1.0;
this->DataExtent[0] = this->DataExtent[2] = this->DataExtent[4] = 0;
this->DataExtent[1] = this->DataExtent[3] = this->DataExtent[5] = 0;
this->XYCoordMode = VTK_SEGY_SOURCE;
this->XCoordByte = 73;
this->YCoordByte = 77;
this->VerticalCRS = VTK_SEGY_VERTICAL_HEIGHTS;
}
//-----------------------------------------------------------------------------
vtkSegY3DReader::~vtkSegY3DReader()
{
delete this->Reader;
}
//-----------------------------------------------------------------------------
void vtkSegY3DReader::SetXYCoordModeToSource()
{
this->SetXYCoordMode(VTK_SEGY_SOURCE);
}
//-----------------------------------------------------------------------------
void vtkSegY3DReader::SetXYCoordModeToCDP()
{
this->SetXYCoordMode(VTK_SEGY_CDP);
}
//-----------------------------------------------------------------------------
void vtkSegY3DReader::SetXYCoordModeToCustom()
{
this->SetXYCoordMode(VTK_SEGY_CUSTOM);
}
//-----------------------------------------------------------------------------
void vtkSegY3DReader::PrintSelf(ostream& os, vtkIndent indent)
{
Superclass::PrintSelf(os, indent);
}
//-----------------------------------------------------------------------------
int vtkSegY3DReader::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector)
{
vtkInformation* outInfo = outputVector->GetInformationObject(0);
if (!outInfo)
{
return 0;
}
vtkDataObject* output = outInfo->Get(vtkDataObject::DATA_OBJECT());
if (!output)
{
return 0;
}
if (this->Is3D)
{
this->Reader->LoadTraces();
this->Reader->ExportData3D(vtkImageData::SafeDownCast(output),
this->DataExtent, this->DataOrigin, this->DataSpacing);
}
else
{
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;
}
}
vtkStructuredGrid* grid = vtkStructuredGrid::SafeDownCast(output);
this->Reader->SetVerticalCRS(this->VerticalCRS);
this->Reader->LoadTraces();
this->Reader->ExportData2D(grid);
grid->Squeeze();
}
this->Reader->In.close();
std::cout << "RequestData" << std::endl;
return 1;
}
//-----------------------------------------------------------------------------
int vtkSegY3DReader::RequestInformation(vtkInformation * vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *outputVector)
{
if (this->Is3D)
{
vtkInformation* outInfo = outputVector->GetInformationObject(0);
if (!outInfo)
{
vtkErrorMacro("Invalid output information object");
return 0;
}
std::cout << "DataExtent: ";
std::copy(this->DataExtent, this->DataExtent + 6, std::ostream_iterator<int>(std::cout, " "));
std::cout << "\nDataOrigin: ";
std::copy(this->DataOrigin, this->DataOrigin + 3, std::ostream_iterator<double>(std::cout, " "));
std::cout << "\nDataSpacing: ";
std::copy(this->DataSpacing, this->DataSpacing + 3, std::ostream_iterator<double>(std::cout, " "));
std::cout << std::endl;
outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
this->DataExtent, 6);
outInfo->Set(vtkDataObject::ORIGIN(), this->DataOrigin, 3);
outInfo->Set(vtkDataObject::SPACING(), this->DataSpacing, 3);
}
return 1;
}
//----------------------------------------------------------------------------
int vtkSegY3DReader::FillOutputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
const char* outputTypeName = this->Is3D ? "vtkImageData" : "vtkStructuredGrid";
info->Set(vtkDataObject::DATA_TYPE_NAME(), outputTypeName);
std::cout << "FillOutputPortInformation" << std::endl;
return 1;
}
//----------------------------------------------------------------------------
int vtkSegY3DReader::RequestDataObject(
vtkInformation*,
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector)
{
vtkInformation* info = outputVector->GetInformationObject(0);
vtkDataSet *output = vtkDataSet::SafeDownCast(
info->Get(vtkDataObject::DATA_OBJECT()));
if (!this->FileName)
{
vtkErrorMacro("Requires valid input file name") ;
return 0;
}
this->Reader->In.open(this->FileName, std::ifstream::binary);
if (!this->Reader->In)
{
std::cerr << "File not found:" << this->FileName << std::endl;
return 0;
}
this->Is3D = this->Reader->Is3DComputeParameters(
this->DataExtent, this->DataOrigin, this->DataSpacing);
const char* outputTypeName = this->Is3D ? "vtkImageData" : "vtkStructuredGrid";
if (!output || !output->IsA(outputTypeName))
{
vtkDataSet* newOutput = nullptr;
if (this->Is3D)
{
newOutput = vtkImageData::New();
}
else
{
newOutput = vtkStructuredGrid::New();
}
info->Set(vtkDataObject::DATA_OBJECT(), newOutput);
newOutput->Delete();
}
std::cout << "RequestDataObject" << std::endl;
return 1;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSegY3DReader.h
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.
=========================================================================*/
#ifndef vtkSegY3DReader_h
#define vtkSegY3DReader_h
#include "vtkDataSetAlgorithm.h"
#include <vtkIOSegYModule.h> // For export macro
// Forward declarations
class vtkImageData;
class vtkSegYReader;
class VTKIOSEGY_EXPORT vtkSegY3DReader : public vtkDataSetAlgorithm
{
public:
static vtkSegY3DReader* New();
vtkTypeMacro(vtkSegY3DReader, vtkDataSetAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override;
vtkSegY3DReader();
~vtkSegY3DReader();
vtkSetStringMacro(FileName);
vtkGetStringMacro(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);
//@}
enum VTKSegYVerticalCRS
{
VTK_SEGY_VERTICAL_HEIGHTS = 0, // default
VTK_SEGY_VERTICAL_DEPTHS
};
//@{
/**
* Specify whether the vertical coordinates in the SEG-Y file are heights
* (positive up) or depths (positive down). By default, the vertical
* coordinates are treated as heights (i.e. positive up). This means that the
* Z-axis of the dataset goes from 0 (surface) to -ve depth (last sample).
* \note As per the SEG-Y rev 2.0 specification, this information is defined
* in the Location Data Stanza of the Extended Textual Header. However, as of
* this revision, vtkSegY2DReader does not support reading the extended
* textual header.
*/
vtkSetMacro(VerticalCRS, int);
vtkGetMacro(VerticalCRS, int);
//@}
protected:
int RequestData(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector) override;
int RequestInformation(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector) override;
int FillOutputPortInformation(int port, vtkInformation* info) override;
int RequestDataObject(vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector) override;
protected:
vtkSegYReader* Reader;
char *FileName;
bool Is3D;
double DataOrigin[3];
double DataSpacing[3];
int DataExtent[6];
int XYCoordMode;
// Custom XY coordinate byte positions
int XCoordByte;
int YCoordByte;
int VerticalCRS;
private:
vtkSegY3DReader(const vtkSegY3DReader&) = delete;
void operator=(const vtkSegY3DReader&) = delete;
};
#endif // vtkSegY3DReader_h
This diff is collapsed.
......@@ -15,54 +15,119 @@
#ifndef vtkSegYReader_h
#define vtkSegYReader_h
#ifndef __VTK_WRAP__