VTK  9.7.1
vtkJSONSceneExporter.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
13 #ifndef vtkJSONSceneExporter_h
14 #define vtkJSONSceneExporter_h
15 
16 #include "vtkDataArraySelection.h" // Instantiated
17 #include "vtkExporter.h"
18 #include "vtkIOExportModule.h" // For export macro
19 #include "vtkNew.h" // For vtkDataArraySelection
20 #include "vtkSmartPointer.h" // For vtkSmartPointer
21 
22 #include <map> // For member variables
23 #include <string> // For string parameter
24 #include <vector> // For member variables
25 
26 VTK_ABI_NAMESPACE_BEGIN
27 class vtkActor;
29 class vtkDataObject;
30 class vtkDataSet;
32 class vtkPolyData;
33 class vtkPropCollection;
34 class vtkScalarsToColors;
35 class vtkTexture;
36 class vtkVolume;
38 
39 class VTKIOEXPORT_EXPORT vtkJSONSceneExporter : public vtkExporter
40 {
41 public:
42  static vtkJSONSceneExporter* New();
44  void PrintSelf(ostream& os, vtkIndent indent) override;
45 
47 
51  vtkSetFilePathMacro(FileName);
52  vtkGetFilePathMacro(FileName);
54 
56 
61  vtkSetMacro(WriteTextures, bool);
62  vtkGetMacro(WriteTextures, bool);
64 
66 
75  vtkSetMacro(WriteTextureLODs, bool);
76  vtkGetMacro(WriteTextureLODs, bool);
78 
80 
85  vtkSetMacro(TextureLODsBaseSize, size_t);
86  vtkGetMacro(TextureLODsBaseSize, size_t);
88 
90 
94  vtkSetStringMacro(TextureLODsBaseUrl);
95  vtkGetStringMacro(TextureLODsBaseUrl);
97 
99 
113  vtkSetMacro(WritePolyLODs, bool);
114  vtkGetMacro(WritePolyLODs, bool);
116 
118 
125  vtkSetMacro(PolyLODsBaseSize, size_t);
126  vtkGetMacro(PolyLODsBaseSize, size_t);
128 
130 
134  vtkSetStringMacro(PolyLODsBaseUrl);
135  vtkGetStringMacro(PolyLODsBaseUrl);
137 
139 
146  vtkGetObjectMacro(PointArraySelection, vtkDataArraySelection);
147  vtkGetObjectMacro(CellArraySelection, vtkDataArraySelection);
149 
151 
159  void SetNamedActorsMap(std::map<std::string, vtkActor*>& map);
160  std::map<std::string, vtkActor*> GetNamedActorsMap();
162 
163 protected:
165  ~vtkJSONSceneExporter() override;
166 
167  void WritePropCollection(vtkPropCollection* collection, std::ostream& sceneComponents);
168  void WriteVolumeCollection(vtkVolumeCollection* volumeCollection, std::ostream& sceneComponents);
169 
170  std::string ExtractPiecewiseFunctionSetup(vtkPiecewiseFunction* pwf);
171  std::string ExtractColorTransferFunctionSetup(vtkColorTransferFunction* volume);
172  std::string ExtractVolumeRenderingSetup(vtkVolume* volume);
173  std::string ExtractActorRenderingSetup(vtkActor* actor);
174  void WriteLookupTable(const char* name, vtkScalarsToColors* lookupTable);
175 
176  void WriteData() override;
177 
179 
183  std::string GetTemporaryPath() const;
185  std::string CurrentDataSetPath() const;
186 
187  std::string WriteTexture(vtkTexture* texture);
188  std::string WriteTextureLODSeries(vtkTexture* texture);
189 
190  // The returned pointer is the smallest poly LOD, intended to be
191  // written out in the vtkjs file.
192  vtkSmartPointer<vtkPolyData> WritePolyLODSeries(vtkPolyData* polys, std::string& config);
193 
194  char* FileName;
203  std::map<std::string, std::string> LookupTables;
204  std::map<vtkTexture*, std::string> TextureStrings;
205  std::map<vtkTexture*, std::string> TextureLODStrings;
206 
207  // Files that subclasses should zip
208  std::vector<std::string> FilesToZip;
209 
210 private:
212  void operator=(const vtkJSONSceneExporter&) = delete;
213 
217  void WriteNamedActors(std::map<std::string, vtkActor*>& actorMap, std::ostream& sceneComponents);
218 
222  std::string WriteDataSet(vtkDataSet* dataset, const char* addOnMeta, const char* name);
223 
231  void WriteDataObject(
232  ostream& os, vtkDataObject* dataObject, vtkActor* actor, vtkVolume* volume, const char* name);
233 
234  // Map named sources with their data array selection
235  vtkNew<vtkDataArraySelection> PointArraySelection;
236  vtkNew<vtkDataArraySelection> CellArraySelection;
237  std::map<std::string, vtkActor*> NamedActorsMap;
238 };
239 
240 VTK_ABI_NAMESPACE_END
241 #endif
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:40
abstract class to write a scene to a file
Definition: vtkExporter.h:38
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:41
virtual void WriteData()=0
std::map< vtkTexture *, std::string > TextureStrings
Defines a 1D piecewise function.
Export the content of a vtkRenderWindow into a directory with a JSON meta file describing the scene a...
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
an ordered list of Props
Superclass for mapping scalar values to colors.
a simple class to control print indentation
Definition: vtkIndent.h:28
Store on/off settings for data arrays, etc.
an ordered list of volumes
std::vector< std::string > FilesToZip
handles properties associated with a texture map
Definition: vtkTexture.h:58
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
std::map< vtkTexture *, std::string > TextureLODStrings
void WriteDataSet(vtkUnstructuredGrid *grid, const std::string &file)
Defines a transfer function for mapping a property to an RGB color value.
std::map< std::string, std::string > LookupTables
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
general representation of visualization data
Definition: vtkDataObject.h:55