vtkStructuredPointsWriter.cxx 3.35 KB
Newer Older
Will Schroeder's avatar
Will Schroeder committed
1 2
/*=========================================================================

Ken Martin's avatar
Ken Martin committed
3
  Program:   Visualization Toolkit
Ken Martin's avatar
Ken Martin committed
4
  Module:    vtkStructuredPointsWriter.cxx
Will Schroeder's avatar
Will Schroeder committed
5

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
Ken Martin's avatar
Ken Martin committed
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
Will Schroeder's avatar
Will Schroeder committed
13 14

=========================================================================*/
Ken Martin's avatar
Ken Martin committed
15
#include "vtkStructuredPointsWriter.h"
16

17
#include "vtkInformation.h"
18
#include "vtkObjectFactory.h"
19
#include "vtkStructuredPoints.h"
20

21 22
#if !defined(_WIN32) || defined(__CYGWIN__)
# include <unistd.h> /* unlink */
Bill Hoffman's avatar
Bill Hoffman committed
23 24
#else
# include <io.h> /* unlink */
25
#endif
26

Bill Hoffman's avatar
Bill Hoffman committed
27

Brad King's avatar
Brad King committed
28
vtkStandardNewMacro(vtkStructuredPointsWriter);
Will Schroeder's avatar
Will Schroeder committed
29

Ken Martin's avatar
Ken Martin committed
30
void vtkStructuredPointsWriter::WriteData()
Will Schroeder's avatar
Will Schroeder committed
31
{
32
  ostream *fp;
33
  vtkImageData *input= vtkImageData::SafeDownCast(this->GetInput());
Will Schroeder's avatar
Will Schroeder committed
34
  int dim[3];
35
  int *ext;
Ken Martin's avatar
Ken Martin committed
36
  double spacing[3], origin[3];
Will Schroeder's avatar
Will Schroeder committed
37

Ken Martin's avatar
Ken Martin committed
38
  vtkDebugMacro(<<"Writing vtk structured points...");
Will Schroeder's avatar
Will Schroeder committed
39

Ken Martin's avatar
Ken Martin committed
40
  if ( !(fp=this->OpenVTKFile()) || !this->WriteHeader(fp) )
Bill Lorensen's avatar
Bill Lorensen committed
41
      {
42 43 44 45 46 47 48
      if (fp)
        {
        vtkErrorMacro("Ran out of disk space; deleting file: "
                      << this->FileName);
        this->CloseVTKFile(fp);
        unlink(this->FileName);
        }
Will Schroeder's avatar
Will Schroeder committed
49
      return;
Bill Lorensen's avatar
Bill Lorensen committed
50
      }
51 52 53 54
  //
  // Write structured points specific stuff
  //
  *fp << "DATASET STRUCTURED_POINTS\n";
Will Schroeder's avatar
Will Schroeder committed
55

56
  // Write data owned by the dataset
57 58 59 60 61 62 63
  if (!this->WriteDataSetData(fp, input))
    {
    vtkErrorMacro("Ran out of disk space; deleting file: " << this->FileName);
    this->CloseVTKFile(fp);
    unlink(this->FileName);
    return;
    }
64

Will Schroeder's avatar
Will Schroeder committed
65
  input->GetDimensions(dim);
66
  *fp << "DIMENSIONS " << dim[0] << " " << dim[1] << " " << dim[2] << "\n";
Will Schroeder's avatar
Will Schroeder committed
67

Will Schroeder's avatar
Will Schroeder committed
68
  input->GetSpacing(spacing);
69
  *fp << "SPACING " << spacing[0] << " " << spacing[1] << " " << spacing[2] << "\n";
Will Schroeder's avatar
Will Schroeder committed
70 71

  input->GetOrigin(origin);
72 73 74 75 76 77
  // Do the electric slide. Move origin to min corner of extent.
  // The alternative is to change the format to include an extent instead of dimensions.
  ext = input->GetExtent();
  origin[0] += ext[0] * spacing[0];
  origin[1] += ext[2] * spacing[1];
  origin[2] += ext[4] * spacing[2];
78
  *fp << "ORIGIN " << origin[0] << " " << origin[1] << " " << origin[2] << "\n";
Will Schroeder's avatar
Will Schroeder committed
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93
  if (!this->WriteCellData(fp, input))
    {
    vtkErrorMacro("Ran out of disk space; deleting file: " << this->FileName);
    this->CloseVTKFile(fp);
    unlink(this->FileName);
    return;
    }
  if (!this->WritePointData(fp, input))
    {
    vtkErrorMacro("Ran out of disk space; deleting file: " << this->FileName);
    this->CloseVTKFile(fp);
    unlink(this->FileName);
    return;
    }
Will Schroeder's avatar
Will Schroeder committed
94

Ken Martin's avatar
Ken Martin committed
95
  this->CloseVTKFile(fp);
Will Schroeder's avatar
Will Schroeder committed
96
}
97

98 99 100 101 102 103 104
int vtkStructuredPointsWriter::FillInputPortInformation(int,
                                                        vtkInformation *info)
{
  info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkImageData");
  return 1;
}

105 106 107 108 109 110 111 112 113 114
vtkImageData* vtkStructuredPointsWriter::GetInput()
{
  return vtkImageData::SafeDownCast(this->Superclass::GetInput());
}

vtkImageData* vtkStructuredPointsWriter::GetInput(int port)
{
  return vtkImageData::SafeDownCast(this->Superclass::GetInput(port));
}

115
void vtkStructuredPointsWriter::PrintSelf(ostream& os, vtkIndent indent)
116
{
Brad King's avatar
Brad King committed
117
  this->Superclass::PrintSelf(os,indent);
118
}