OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / include / vtk / vtkXMLReader.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkXMLReader.h,v $
5   Language:  C++
6   Date:      $Date: 2002/11/27 00:16:04 $
7   Version:   $Revision: 1.3 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
13      This software is distributed WITHOUT ANY WARRANTY; without even 
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15      PURPOSE.  See the above copyright notice for more information.
16
17 =========================================================================*/
18 // .NAME vtkXMLReader - Superclass for VTK's XML format readers.
19 // .SECTION Description
20 // vtkXMLReader uses vtkXMLDataParser to parse a VTK XML input file.
21 // Concrete subclasses then traverse the parsed file structure and
22 // extract data.
23
24 #ifndef __vtkXMLReader_h
25 #define __vtkXMLReader_h
26
27 #include "vtkSource.h"
28
29 class vtkCallbackCommand;
30 class vtkDataArray;
31 class vtkDataArraySelection;
32 class vtkDataSet;
33 class vtkDataSetAttributes;
34 class vtkXMLDataElement;
35 class vtkXMLDataParser;
36
37 class VTK_IO_EXPORT vtkXMLReader : public vtkSource
38 {
39 public:
40   vtkTypeRevisionMacro(vtkXMLReader,vtkSource);
41   void PrintSelf(ostream& os, vtkIndent indent);
42   
43   // Description:
44   // Get/Set the name of the input file.
45   vtkSetStringMacro(FileName);
46   vtkGetStringMacro(FileName);
47   
48   // Description:
49   // Test whether the file with the given name can be read by this
50   // reader.
51   virtual int CanReadFile(const char* name);
52   
53   // Description:
54   // Get the output as a vtkDataSet pointer.
55   vtkDataSet* GetOutputAsDataSet();
56   
57   // Description:
58   // Get the data array selection tables used to configure which data
59   // arrays are loaded by the reader.
60   vtkGetObjectMacro(PointDataArraySelection, vtkDataArraySelection);
61   vtkGetObjectMacro(CellDataArraySelection, vtkDataArraySelection);
62   
63   // Description:  
64   // Get the number of point or cell arrays available in the input.
65   int GetNumberOfPointArrays();
66   int GetNumberOfCellArrays();
67   
68   // Description:
69   // Get the name of the point or cell array with the given index in
70   // the input.
71   const char* GetPointArrayName(int index);
72   const char* GetCellArrayName(int index);
73   
74   // Description:
75   // Get/Set whether the point or cell array with the given name is to
76   // be read.
77   int GetPointArrayStatus(const char* name);
78   int GetCellArrayStatus(const char* name);
79   void SetPointArrayStatus(const char* name, int status);  
80   void SetCellArrayStatus(const char* name, int status);  
81   
82 protected:
83   vtkXMLReader();
84   ~vtkXMLReader();
85   
86   // Standard pipeline exectution methods.
87   void ExecuteInformation();
88   void ExecuteData(vtkDataObject* output);
89   
90   // Pipeline execution methods to be defined by subclass.  Called by
91   // corresponding Execute methods after appropriate setup has been
92   // done.
93   virtual void ReadXMLInformation();
94   virtual void ReadXMLData();
95   
96   // Get the name of the data set being read.
97   virtual const char* GetDataSetName()=0;
98   
99   // Test if the reader can read a file with the given version number.
100   virtual int CanReadFileVersion(int major, int minor);
101   
102   // Setup the output with no data available.  Used in error cases.
103   virtual void SetupEmptyOutput()=0;
104   
105   // Setup the output's information and data without allocation.
106   virtual void SetupOutputInformation();
107   
108   // Setup the output's information and data with allocation.
109   virtual void SetupOutputData();
110   
111   // Read the primary element from the file.  This is the element
112   // whose name is the value returned by GetDataSetName().
113   virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
114   
115   // Read the top-level element from the file.  This is always the
116   // VTKFile element.
117   int ReadVTKFile(vtkXMLDataElement* eVTKFile);  
118   
119   // Create a vtkDataArray from its cooresponding XML representation.
120   // Does not allocate.
121   vtkDataArray* CreateDataArray(vtkXMLDataElement* da);
122   
123   // Internal utility methods.
124   int OpenVTKFile();
125   void CloseVTKFile();
126   void CreateXMLParser();
127   void DestroyXMLParser();
128   void SetupCompressor(const char* type);
129   int CanReadFileVersionString(const char* version);
130   
131   // Utility methods for subclasses.
132   int IntersectExtents(int* extent1, int* extent2, int* result);
133   int Min(int a, int b);
134   int Max(int a, int b);
135   void ComputeDimensions(int* extent, int* dimensions, int isPoint);
136   void ComputeIncrements(int* extent, int* increments, int isPoint);
137   unsigned int GetStartTuple(int* extent, int* increments,
138                              int i, int j, int k);
139   void ReadAttributeIndices(vtkXMLDataElement* eDSA,
140                             vtkDataSetAttributes* dsa);
141   char** CreateStringArray(int numStrings);
142   void DestroyStringArray(int numStrings, char** strings);  
143   
144   // Setup the data array selections for the input's set of arrays.
145   void SetDataArraySelections(vtkXMLDataElement* eDSA,
146                               vtkDataArraySelection* sel);
147   
148   // Check whether the given array element is an enabled array.
149   int PointDataArrayIsEnabled(vtkXMLDataElement* ePDA);
150   int CellDataArrayIsEnabled(vtkXMLDataElement* eCDA);
151   
152   // Callback registered with the SelectionObserver.
153   static void SelectionModifiedCallback(vtkObject* caller, unsigned long eid,
154                                         void* clientdata, void* calldata);
155   
156   // The vtkXMLDataParser instance used to hide XML reading details.
157   vtkXMLDataParser* XMLParser;
158   
159   // The input file's name.
160   char* FileName;
161   
162   // The file stream used to read the input file.
163   ifstream* FileStream;
164   
165   // The array selections.
166   vtkDataArraySelection* PointDataArraySelection;
167   vtkDataArraySelection* CellDataArraySelection;
168   
169   // The observer to modify this object when the array selections are
170   // modified.
171   vtkCallbackCommand* SelectionObserver;
172   
173   // Whether there was an error reading the file in ExecuteInformation.
174   int InformationError;
175   
176   // Whether there was an error reading the file in ExecuteData.
177   int DataError;
178   
179 private:
180   vtkXMLReader(const vtkXMLReader&);  // Not implemented.
181   void operator=(const vtkXMLReader&);  // Not implemented.
182 };
183
184 #endif