1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkSTLReader.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME vtkSTLReader - read ASCII or binary stereo lithography files
16 // .SECTION Description
17 // vtkSTLReader is a source object that reads ASCII or binary stereo
18 // lithography files (.stl files). The FileName must be specified to
19 // vtkSTLReader. The object automatically detects whether the file is
20 // ASCII or binary.
21 //
22 // .stl files are quite inefficient since they duplicate vertex
23 // definitions. By setting the Merging boolean you can control whether the
24 // point data is merged after reading. Merging is performed by default,
25 // however, merging requires a large amount of temporary storage since a
26 // 3D hash table must be constructed.
27 
28 // .SECTION Caveats
29 // Binary files written on one system may not be readable on other systems.
30 // vtkSTLWriter uses VAX or PC byte ordering and swaps bytes on other systems.
31 
32 #ifndef vtkSTLReader_h
33 #define vtkSTLReader_h
34 
35 #include "vtkIOGeometryModule.h" // For export macro
36 #include "vtkPolyDataAlgorithm.h"
37 
38 class vtkCellArray;
39 class vtkFloatArray;
40 class vtkIncrementalPointLocator;
41 class vtkPoints;
42 
43 class VTKIOGEOMETRY_EXPORT vtkSTLReader : public vtkPolyDataAlgorithm
44 {
45 public:
46   vtkTypeMacro(vtkSTLReader,vtkPolyDataAlgorithm);
47   void PrintSelf(ostream& os, vtkIndent indent);
48 
49   // Description:
50   // Construct object with merging set to true.
51   static vtkSTLReader *New();
52 
53   // Description:
54   // Overload standard modified time function. If locator is modified,
55   // then this object is modified as well.
56   unsigned long GetMTime();
57 
58   // Description:
59   // Specify file name of stereo lithography file.
60   vtkSetStringMacro(FileName);
61   vtkGetStringMacro(FileName);
62 
63   // Description:
64   // Turn on/off merging of points/triangles.
65   vtkSetMacro(Merging,int);
66   vtkGetMacro(Merging,int);
67   vtkBooleanMacro(Merging,int);
68 
69   // Description:
70   // Turn on/off tagging of solids with scalars.
71   vtkSetMacro(ScalarTags,int);
72   vtkGetMacro(ScalarTags,int);
73   vtkBooleanMacro(ScalarTags,int);
74 
75   // Description:
76   // Specify a spatial locator for merging points. By
77   // default an instance of vtkMergePoints is used.
78   void SetLocator(vtkIncrementalPointLocator *locator);
79   vtkGetObjectMacro(Locator,vtkIncrementalPointLocator);
80 
81 protected:
82   vtkSTLReader();
83   ~vtkSTLReader();
84 
85   // Description:
86   // Create default locator. Used to create one when none is specified.
87   vtkIncrementalPointLocator* NewDefaultLocator();
88 
89   char *FileName;
90   int Merging;
91   int ScalarTags;
92   vtkIncrementalPointLocator *Locator;
93 
94   int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
95   bool ReadBinarySTL(FILE *fp, vtkPoints*, vtkCellArray*);
96   bool ReadASCIISTL(FILE *fp, vtkPoints*, vtkCellArray*,
97                     vtkFloatArray* scalars=0);
98   int GetSTLFileType(const char *filename);
99 private:
100   vtkSTLReader(const vtkSTLReader&);  // Not implemented.
101   void operator=(const vtkSTLReader&);  // Not implemented.
102 };
103 
104 #endif
105