vtkMCubesReader.h 5.45 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:    vtkMCubesReader.h
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
// .NAME vtkMCubesReader - read binary marching cubes file
Will Schroeder's avatar
Will Schroeder committed
16
// .SECTION Description
Ken Martin's avatar
Ken Martin committed
17
// vtkMCubesReader is a source object that reads binary marching cubes
18
// files. (Marching cubes is an isosurfacing technique that generates 
19
// many triangles.) The binary format is supported by W. Lorensen's
Will Schroeder's avatar
Will Schroeder committed
20 21 22 23
// marching cubes program (and the vtkSliceCubes object). The format 
// repeats point coordinates, so this object will merge the points 
// with a vtkLocator object. You can choose to supply the vtkLocator 
// or use the default.
Ken Martin's avatar
Ken Martin committed
24

Will Schroeder's avatar
Will Schroeder committed
25
// .SECTION Caveats
26
// Binary files assumed written in sun/hp/sgi (i.e., Big Endian) form.
Will Schroeder's avatar
Will Schroeder committed
27 28 29
//
// Because points are merged when read, degenerate triangles may be removed.
// Thus the number of triangles read may be fewer than the number of triangles
30
// actually created.
31
//
32
// The point merging does not take into account that the same point may have
Ken Martin's avatar
Ken Martin committed
33 34 35 36
// different normals. For example, running vtkPolyDataNormals after
// vtkContourFilter may split triangles because of the FeatureAngle
// ivar. Subsequent reading with vtkMCubesReader will merge the points and
// use the first point's normal. For the most part, this is undesirable.
37
//
Ken Martin's avatar
Ken Martin committed
38 39 40 41 42
// Normals are generated from the gradient of the data scalar values. Hence
// the normals may on occasion point in a direction inconsistent with the
// ordering of the triangle vertices. If this happens, the resulting surface
// may be "black".  Reverse the sense of the FlipNormals boolean flag to
// correct this.
43

Will Schroeder's avatar
Will Schroeder committed
44
// .SECTION See Also
45
// vtkContourFilter vtkMarchingCubes vtkSliceCubes vtkLocator
Will Schroeder's avatar
Will Schroeder committed
46

Ken Martin's avatar
Ken Martin committed
47 48
#ifndef __vtkMCubesReader_h
#define __vtkMCubesReader_h
Will Schroeder's avatar
Will Schroeder committed
49

50
#include "vtkPolyDataAlgorithm.h"
Will Schroeder's avatar
Will Schroeder committed
51

52 53 54
#define VTK_FILE_BYTE_ORDER_BIG_ENDIAN 0
#define VTK_FILE_BYTE_ORDER_LITTLE_ENDIAN 1

Andy Cedilnik's avatar
Andy Cedilnik committed
55 56
class vtkPointLocator;

57
class VTK_IO_EXPORT vtkMCubesReader : public vtkPolyDataAlgorithm 
Will Schroeder's avatar
Will Schroeder committed
58 59
{
public:
60
  vtkTypeRevisionMacro(vtkMCubesReader,vtkPolyDataAlgorithm);
61
  void PrintSelf(ostream& os, vtkIndent indent);
Will Schroeder's avatar
Will Schroeder committed
62

Ken Martin's avatar
Ken Martin committed
63 64
  // Description:
  // Construct object with FlipNormals turned off and Normals set to true.
65
  static vtkMCubesReader *New();
Ken Martin's avatar
Ken Martin committed
66

Will Schroeder's avatar
Will Schroeder committed
67 68
  // Description:
  // Specify file name of marching cubes file.
Ken Martin's avatar
Ken Martin committed
69
  vtkSetStringMacro(FileName);
Will Schroeder's avatar
Will Schroeder committed
70
  vtkGetStringMacro(FileName);
Will Schroeder's avatar
Will Schroeder committed
71 72

  // Description:
Ken Martin's avatar
Ken Martin committed
73
  // Set / get the file name of the marching cubes limits file.
Ken Martin's avatar
Ken Martin committed
74
  vtkSetStringMacro(LimitsFileName);
Will Schroeder's avatar
Will Schroeder committed
75
  vtkGetStringMacro(LimitsFileName);
Will Schroeder's avatar
Will Schroeder committed
76

77 78 79 80 81
  // Description:
  // Specify a header size if one exists. The header is skipped and not used at this time.
  vtkSetClampMacro(HeaderSize,int,0,VTK_LARGE_INTEGER);
  vtkGetMacro(HeaderSize,int);

Will Schroeder's avatar
Will Schroeder committed
82
  // Description:
Ken Martin's avatar
Ken Martin committed
83 84 85 86
  // Specify whether to flip normals in opposite direction. Flipping ONLY
  // changes the direction of the normal vector. Contrast this with flipping
  // in vtkPolyDataNormals which flips both the normal and the cell point
  // order.
Ken Martin's avatar
Ken Martin committed
87 88 89
  vtkSetMacro(FlipNormals,int);
  vtkGetMacro(FlipNormals,int);
  vtkBooleanMacro(FlipNormals,int);
Will Schroeder's avatar
Will Schroeder committed
90 91 92

  // Description:
  // Specify whether to read normals.
Ken Martin's avatar
Ken Martin committed
93 94 95
  vtkSetMacro(Normals,int);
  vtkGetMacro(Normals,int);
  vtkBooleanMacro(Normals,int);
Will Schroeder's avatar
Will Schroeder committed
96

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
  // Description:
  // These methods should be used instead of the SwapBytes methods.
  // They indicate the byte ordering of the file you are trying
  // to read in. These methods will then either swap or not swap
  // the bytes depending on the byte ordering of the machine it is
  // being run on. For example, reading in a BigEndian file on a
  // BigEndian machine will result in no swapping. Trying to read
  // the same file on a LittleEndian machine will result in swapping.
  // As a quick note most UNIX machines are BigEndian while PC's
  // and VAX tend to be LittleEndian. So if the file you are reading
  // in was generated on a VAX or PC, SetDataByteOrderToLittleEndian otherwise
  // SetDataByteOrderToBigEndian. 
  void SetDataByteOrderToBigEndian();
  void SetDataByteOrderToLittleEndian();
  int GetDataByteOrder();
  void SetDataByteOrder(int);
  const char *GetDataByteOrderAsString();

  // Description:
  // Turn on/off byte swapping.
  vtkSetMacro(SwapBytes,int);
  vtkGetMacro(SwapBytes,int);
  vtkBooleanMacro(SwapBytes,int);

Ken Martin's avatar
Ken Martin committed
121 122 123
  // Description:
  // Set / get a spatial locator for merging points. By default, 
  // an instance of vtkMergePoints is used.
124 125
  void SetLocator(vtkPointLocator *locator);
  vtkGetObjectMacro(Locator,vtkPointLocator);
Will Schroeder's avatar
Will Schroeder committed
126 127 128 129

  // Description:
  // Create default locator. Used to create one when none is specified.
  void CreateDefaultLocator();
Charles Law's avatar
Charles Law committed
130
  
Ken Martin's avatar
Ken Martin committed
131 132 133
  // Description:
  // Return the mtime also considering the locator.
  unsigned long GetMTime();
Will Schroeder's avatar
Will Schroeder committed
134 135

protected:
136 137 138
  vtkMCubesReader();
  ~vtkMCubesReader();

139
  int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
Will Schroeder's avatar
Will Schroeder committed
140

Will Schroeder's avatar
Will Schroeder committed
141 142
  char *FileName;
  char *LimitsFileName;
143
  vtkPointLocator *Locator;
144 145
  int SwapBytes;
  int HeaderSize;
Will Schroeder's avatar
Will Schroeder committed
146 147 148
  int FlipNormals;
  int Normals;

149 150 151
private:
  vtkMCubesReader(const vtkMCubesReader&);  // Not implemented.
  void operator=(const vtkMCubesReader&);  // Not implemented.
Will Schroeder's avatar
Will Schroeder committed
152 153 154
};

#endif