1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkVRMLImporter.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 /**
16  * @class   vtkVRMLImporter
17  * @brief   imports VRML 2.0 files.
18  *
19  *
20  * vtkVRMLImporter imports VRML 2.0 files into VTK.
21  *
22  * @warning
23  * These nodes are currently supported:
24  *      Appearance                              IndexedFaceSet
25  *      Box                                     IndexedLineSet
26  *      Color                                   Material
27  *      Cone                                    Shape
28  *      Coordinate                              Sphere
29  *      Cylinder                                Transform
30  *      DirectionalLight
31  *
32  * @warning
33  * As you can see this implementation focuses on getting the geometry
34  * translated.  The routes and scripting nodes are ignored since they deal
35  * with directly accessing a nodes internal structure based on the VRML
36  * spec. Since this is a translation the internal data structures differ
37  * greatly from the VRML spec and the External Authoring Interface (see the
38  * VRML spec). The DEF/USE mechanism does allow the VTK user to extract
39  * objects from the scene and directly manipulate them using the native
40  * language (Python, Java, or whatever language VTK is wrapped
41  * in). This, in a way, removes the need for the route and script mechanism
42  * (not completely though).
43  * Texture coordinates are attached to the mesh is available but
44  * image textures are not loaded.
45  * Viewpoints (camera presets) are not imported.
46  *
47  * @par Thanks:
48  *  Thanks to Russ Coucher of Areva for numerous bug fixes and a new test.
49  *
50  * @sa
51  * vtkImporter
52 */
53 
54 #ifndef vtkVRMLImporter_h
55 #define vtkVRMLImporter_h
56 
57 #include "vtkIOImportModule.h" // For export macro
58 #include "vtkImporter.h"
59 
60 class vtkActor;
61 class vtkAlgorithm;
62 class vtkProperty;
63 class vtkLight;
64 class vtkTransform;
65 class vtkLookupTable;
66 class vtkFloatArray;
67 class vtkPolyDataMapper;
68 class vtkPoints;
69 class vtkIdTypeArray;
70 class vtkVRMLImporterInternal;
71 class vtkVRMLYaccData;
72 class vtkCellArray;
73 
74 class VTKIOIMPORT_EXPORT vtkVRMLImporter : public vtkImporter
75 {
76 public:
77   static vtkVRMLImporter *New();
78 
79   vtkTypeMacro(vtkVRMLImporter, vtkImporter);
80   void PrintSelf(ostream& os, vtkIndent indent) override;
81 
82   //@{
83   /**
84    * Specify the name of the file to read.
85    */
86   vtkSetStringMacro(FileName);
87   vtkGetStringMacro(FileName);
88   //@}
89 
90   //@{
91   /**
92    * Specify the resolution for Sphere, Cone and Cylinder shape sources.
93    * Default is 12.
94    */
95   vtkSetMacro(ShapeResolution, int);
96   vtkGetMacro(ShapeResolution, int);
97   //@}
98 
99   /**
100    * In the VRML spec you can DEF and USE nodes (name them),
101    * This routine will return the associated VTK object which
102    * was created as a result of the DEF mechanism
103    * Send in the name from the VRML file, get the VTK object.
104    * You will have to check and correctly cast the object since
105    * this only returns vtkObjects.
106    */
107   vtkObject* GetVRMLDEFObject(const char *name);
108 
109 protected:
110   vtkVRMLImporter();
111   ~vtkVRMLImporter() override;
112 
113   int OpenImportFile();
114   int ImportBegin() override;
115   void ImportEnd() override;
ImportActors(vtkRenderer *)116   void ImportActors(vtkRenderer*) override {}
ImportCameras(vtkRenderer *)117   void ImportCameras(vtkRenderer*) override {}
ImportLights(vtkRenderer *)118   void ImportLights(vtkRenderer*) override {}
ImportProperties(vtkRenderer *)119   void ImportProperties(vtkRenderer*) override {}
120 
121   //@{
122   /**
123    * Needed by the yacc/lex grammar used
124    */
125   virtual void enterNode(const char*);
126   virtual void exitNode();
127   virtual void enterField(const char*);
128   virtual void exitField();
129   virtual void useNode(const char*);
130   //@}
131 
132   /**
133    * Return the file pointer to the open file.
134    */
GetFileFD()135   FILE *GetFileFD() { return this->FileFD; }
136 
137   char *FileName;
138   FILE *FileFD;
139   int ShapeResolution;
140 
141   friend class vtkVRMLYaccData;
142 
143 private:
144   vtkPoints* PointsNew();
145   vtkFloatArray* FloatArrayNew();
146   vtkIdTypeArray* IdTypeArrayNew();
147 
148   void DeleteObject(vtkObject*);
149 
150   vtkVRMLImporterInternal* Internal;
151   vtkVRMLYaccData* Parser;
152   vtkActor* CurrentActor;
153   vtkProperty* CurrentProperty;
154   vtkLight* CurrentLight;
155   vtkTransform* CurrentTransform;
156   vtkAlgorithm* CurrentSource;
157   vtkPoints* CurrentPoints;
158   vtkFloatArray* CurrentNormals;
159   vtkCellArray* CurrentNormalCells;
160   vtkFloatArray* CurrentTCoords;
161   vtkCellArray* CurrentTCoordCells;
162   vtkLookupTable* CurrentLut;
163   vtkFloatArray* CurrentScalars;
164   vtkPolyDataMapper* CurrentMapper;
165 
166 private:
167   vtkVRMLImporter(const vtkVRMLImporter&) = delete;
168   void operator=(const vtkVRMLImporter&) = delete;
169 };
170 
171 #endif
172