vtkMCubesReader.h 5.7 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.
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

=========================================================================*/
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/**
 * @class   vtkMCubesReader
 * @brief   read binary marching cubes file
 *
 * vtkMCubesReader is a source object that reads binary marching cubes
 * files. (Marching cubes is an isosurfacing technique that generates
 * many triangles.) The binary format is supported by W. Lorensen's
 * 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.
 *
 * @warning
 * Binary files assumed written in sun/hp/sgi (i.e., Big Endian) form.
 *
 * @warning
 * 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
 * actually created.
 *
 * @warning
 * The point merging does not take into account that the same point may have
 * 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.
 *
 * @warning
 * 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.
 *
 * @sa
 * vtkContourFilter vtkMarchingCubes vtkSliceCubes vtkLocator
51
 */
Will Schroeder's avatar
Will Schroeder committed
52

53 54
#ifndef vtkMCubesReader_h
#define vtkMCubesReader_h
Will Schroeder's avatar
Will Schroeder committed
55

56
#include "vtkIOGeometryModule.h" // For export macro
57
#include "vtkPolyDataAlgorithm.h"
Will Schroeder's avatar
Will Schroeder committed
58

59 60 61
#define VTK_FILE_BYTE_ORDER_BIG_ENDIAN 0
#define VTK_FILE_BYTE_ORDER_LITTLE_ENDIAN 1

62
class vtkIncrementalPointLocator;
Andy Cedilnik's avatar
Andy Cedilnik committed
63

64
class VTKIOGEOMETRY_EXPORT vtkMCubesReader : public vtkPolyDataAlgorithm
Will Schroeder's avatar
Will Schroeder committed
65 66
{
public:
67
  vtkTypeMacro(vtkMCubesReader, vtkPolyDataAlgorithm);
68
  void PrintSelf(ostream& os, vtkIndent indent) override;
Will Schroeder's avatar
Will Schroeder committed
69

70 71 72
  /**
   * Construct object with FlipNormals turned off and Normals set to true.
   */
73
  static vtkMCubesReader* New();
Ken Martin's avatar
Ken Martin committed
74

75 76 77 78
  //@{
  /**
   * Specify file name of marching cubes file.
   */
79
  vtkSetStringMacro(FileName);
80
  vtkGetStringMacro(FileName);
81
  //@}
Will Schroeder's avatar
Will Schroeder committed
82

83 84 85 86
  //@{
  /**
   * Set / get the file name of the marching cubes limits file.
   */
87
  vtkSetStringMacro(LimitsFileName);
88
  vtkGetStringMacro(LimitsFileName);
89
  //@}
Will Schroeder's avatar
Will Schroeder committed
90

91 92 93 94
  //@{
  /**
   * Specify a header size if one exists. The header is skipped and not used at this time.
   */
95 96
  vtkSetClampMacro(HeaderSize, int, 0, VTK_INT_MAX);
  vtkGetMacro(HeaderSize, int);
97 98 99 100 101 102 103 104 105
  //@}

  //@{
  /**
   * 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.
   */
106 107 108
  vtkSetMacro(FlipNormals, vtkTypeBool);
  vtkGetMacro(FlipNormals, vtkTypeBool);
  vtkBooleanMacro(FlipNormals, vtkTypeBool);
109
  //@}
Will Schroeder's avatar
Will Schroeder committed
110

111 112 113 114
  //@{
  /**
   * Specify whether to read normals.
   */
115 116 117
  vtkSetMacro(Normals, vtkTypeBool);
  vtkGetMacro(Normals, vtkTypeBool);
  vtkBooleanMacro(Normals, vtkTypeBool);
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
  //@}

  //@{
  /**
   * 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.
   */
134 135 136 137
  void SetDataByteOrderToBigEndian();
  void SetDataByteOrderToLittleEndian();
  int GetDataByteOrder();
  void SetDataByteOrder(int);
138
  const char* GetDataByteOrderAsString();
139
  //@}
140

141 142 143 144
  //@{
  /**
   * Turn on/off byte swapping.
   */
145 146 147
  vtkSetMacro(SwapBytes, vtkTypeBool);
  vtkGetMacro(SwapBytes, vtkTypeBool);
  vtkBooleanMacro(SwapBytes, vtkTypeBool);
148
  //@}
149

150 151 152 153 154
  //@{
  /**
   * Set / get a spatial locator for merging points. By default,
   * an instance of vtkMergePoints is used.
   */
155 156
  void SetLocator(vtkIncrementalPointLocator* locator);
  vtkGetObjectMacro(Locator, vtkIncrementalPointLocator);
157
  //@}
Will Schroeder's avatar
Will Schroeder committed
158

159 160 161
  /**
   * Create default locator. Used to create one when none is specified.
   */
Will Schroeder's avatar
Will Schroeder committed
162
  void CreateDefaultLocator();
163

164 165 166
  /**
   * Return the mtime also considering the locator.
   */
167
  vtkMTimeType GetMTime() override;
Will Schroeder's avatar
Will Schroeder committed
168 169

protected:
170
  vtkMCubesReader();
171
  ~vtkMCubesReader() override;
172

173
  int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
Will Schroeder's avatar
Will Schroeder committed
174

175 176 177
  char* FileName;
  char* LimitsFileName;
  vtkIncrementalPointLocator* Locator;
178
  vtkTypeBool SwapBytes;
179
  int HeaderSize;
180 181
  vtkTypeBool FlipNormals;
  vtkTypeBool Normals;
Will Schroeder's avatar
Will Schroeder committed
182

183
private:
184 185
  vtkMCubesReader(const vtkMCubesReader&) = delete;
  void operator=(const vtkMCubesReader&) = delete;
Will Schroeder's avatar
Will Schroeder committed
186 187 188
};

#endif