forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkJSONSceneExporter.h
194 lines (166 loc) · 6.09 KB
/
vtkJSONSceneExporter.h
1
2
3
4
5
6
7
8
9
10
11
12
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*=========================================================================
Program: Visualization Toolkit
Module: vtkJSONSceneExporter.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkJSONSceneExporter
* @brief Export the content of a vtkRenderWindow into a directory with
* a JSON meta file describing the scene along with the http datasets
*
* @warning
* This writer assume LittleEndian by default. Additional work should be done to properly
* handle endianness.
*/
#ifndef vtkJSONSceneExporter_h
#define vtkJSONSceneExporter_h
#include "vtkExporter.h"
#include "vtkIOExportModule.h" // For export macro
#include "vtkSmartPointer.h" // For vtkSmartPointer
#include <map> // For member variables
#include <string> // For string parameter
#include <vector> // For member variables
class vtkActor;
class vtkColorTransferFunction;
class vtkDataObject;
class vtkDataSet;
class vtkPiecewiseFunction;
class vtkPolyData;
class vtkPropCollection;
class vtkScalarsToColors;
class vtkTexture;
class vtkVolume;
class vtkVolumeCollection;
class VTKIOEXPORT_EXPORT vtkJSONSceneExporter : public vtkExporter
{
public:
static vtkJSONSceneExporter* New();
vtkTypeMacro(vtkJSONSceneExporter, vtkExporter);
void PrintSelf(ostream& os, vtkIndent indent) override;
///@{
/**
* Specify file name of vtk data file to write.
* This correspond to the root directory of the data to write.
*/
vtkSetFilePathMacro(FileName);
vtkGetFilePathMacro(FileName);
///@}
///@{
/**
* Whether or not to write textures.
* Textures will be written in JPEG format.
* Default is false.
*/
vtkSetMacro(WriteTextures, bool);
vtkGetMacro(WriteTextures, bool);
///@}
///@{
/**
* Whether or not to write texture LODs.
* This will write out the textures in a series of decreasing
* resolution JPEG files, which are intended to be uploaded to the
* web. Each file will be 1/4 the size of the previous one. The files
* will stop being written out when one is smaller than the
* TextureLODsBaseSize.
* Default is false.
*/
vtkSetMacro(WriteTextureLODs, bool);
vtkGetMacro(WriteTextureLODs, bool);
///@}
///@{
/**
* The base size to be used for texture LODs. The texture LODs will
* stop being written out when one is smaller than this size.
* Default is 100 KB. Units are in bytes.
*/
vtkSetMacro(TextureLODsBaseSize, size_t);
vtkGetMacro(TextureLODsBaseSize, size_t);
///@}
///@{
/**
* The base URL to be used for texture LODs.
* Default is nullptr.
*/
vtkSetStringMacro(TextureLODsBaseUrl);
vtkGetStringMacro(TextureLODsBaseUrl);
///@}
///@{
/**
* Whether or not to write poly LODs.
* This will write out the poly LOD sources in a series of decreasing
* resolution data sets, which are intended to be uploaded to the
* web. vtkQuadricCluster is used to decrease the resolution of the
* poly data. Each will be approximately 1/4 the size of the previous
* one (unless certain errors occur, and then the defaults for quadric
* clustering will be used, which will produce an unknown size). The
* files will stop being written out when one is smaller than the
* PolyLODsBaseSize, or if the difference in the sizes of the two
* most recent LODs is less than 5%. The smallest LOD will be written
* into the vtkjs file, rather than with the rest of the LODs.
* Default is false.
*/
vtkSetMacro(WritePolyLODs, bool);
vtkGetMacro(WritePolyLODs, bool);
///@}
///@{
/**
* The base size to be used for poly LODs. The poly LODs will stop
* being written out when one is smaller than this size, or if the
* difference in the sizes of the two most recent LODs is less
* than 5%.
* Default is 100 KB. Units are in bytes.
*/
vtkSetMacro(PolyLODsBaseSize, size_t);
vtkGetMacro(PolyLODsBaseSize, size_t);
///@}
///@{
/**
* The base URL to be used for poly LODs.
* Default is nullptr.
*/
vtkSetStringMacro(PolyLODsBaseUrl);
vtkGetStringMacro(PolyLODsBaseUrl);
///@}
protected:
vtkJSONSceneExporter();
~vtkJSONSceneExporter() override;
void WritePropCollection(vtkPropCollection* collection, std::ostream& sceneComponents);
void WriteVolumeCollection(vtkVolumeCollection* volumeCollection, std::ostream& sceneComponents);
void WriteDataObject(ostream& os, vtkDataObject* dataObject, vtkActor* actor, vtkVolume* volume);
std::string ExtractPiecewiseFunctionSetup(vtkPiecewiseFunction* pwf);
std::string ExtractColorTransferFunctionSetup(vtkColorTransferFunction* volume);
std::string ExtractVolumeRenderingSetup(vtkVolume* volume);
std::string ExtractActorRenderingSetup(vtkActor* actor);
std::string WriteDataSet(vtkDataSet* dataset, const char* addOnMeta);
void WriteLookupTable(const char* name, vtkScalarsToColors* lookupTable);
void WriteData() override;
std::string CurrentDataSetPath() const;
std::string WriteTexture(vtkTexture* texture);
std::string WriteTextureLODSeries(vtkTexture* texture);
// The returned pointer is the smallest poly LOD, intended to be
// written out in the vtkjs file.
vtkSmartPointer<vtkPolyData> WritePolyLODSeries(vtkPolyData* polys, std::string& config);
char* FileName;
bool WriteTextures;
bool WriteTextureLODs;
size_t TextureLODsBaseSize;
char* TextureLODsBaseUrl;
bool WritePolyLODs;
size_t PolyLODsBaseSize;
char* PolyLODsBaseUrl;
int DatasetCount;
std::map<std::string, std::string> LookupTables;
std::map<vtkTexture*, std::string> TextureStrings;
std::map<vtkTexture*, std::string> TextureLODStrings;
// Files that subclasses should zip
std::vector<std::string> FilesToZip;
private:
vtkJSONSceneExporter(const vtkJSONSceneExporter&) = delete;
void operator=(const vtkJSONSceneExporter&) = delete;
};
#endif