VTK  9.3.20240328
vtkDataEncoder.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
24 #ifndef vtkDataEncoder_h
25 #define vtkDataEncoder_h
26 
27 #include "vtkObject.h"
28 #include "vtkSmartPointer.h" // needed for vtkSmartPointer
29 #include "vtkWebCoreModule.h" // needed for exports
30 #include <memory> // for std::unique_ptr
31 
32 VTK_ABI_NAMESPACE_BEGIN
34 class vtkImageData;
35 
36 class VTKWEBCORE_EXPORT vtkDataEncoder : public vtkObject
37 {
38 public:
39  static vtkDataEncoder* New();
40  vtkTypeMacro(vtkDataEncoder, vtkObject);
41  void PrintSelf(ostream& os, vtkIndent indent) override;
42 
44 
48  void SetMaxThreads(vtkTypeUInt32);
49  vtkGetMacro(MaxThreads, vtkTypeUInt32);
51 
56  void Initialize();
57 
64  void Push(vtkTypeUInt32 key, vtkImageData* data, int quality, int encoding = 1);
65 
74 
81  void Flush(vtkTypeUInt32 key);
82 
86  const char* EncodeAsBase64Png(vtkImageData* img, int compressionLevel = 5);
87 
91  const char* EncodeAsBase64Jpg(vtkImageData* img, int quality = 50);
92 
96  void Finalize();
97 
98 protected:
100  ~vtkDataEncoder() override;
101 
102  vtkTypeUInt32 MaxThreads;
103 
104 private:
105  vtkDataEncoder(const vtkDataEncoder&) = delete;
106  void operator=(const vtkDataEncoder&) = delete;
107 
108  class vtkInternals;
109  std::unique_ptr<vtkInternals> Internals;
110 };
111 
112 VTK_ABI_NAMESPACE_END
113 #endif
class used to compress/encode images using threads.
const char * EncodeAsBase64Jpg(vtkImageData *img, int quality=50)
Take an image data and synchronously convert it to a base-64 encoded jpg.
void Finalize()
This method will wait for any running thread to terminate.
vtkTypeUInt32 MaxThreads
const char * EncodeAsBase64Png(vtkImageData *img, int compressionLevel=5)
Take an image data and synchronously convert it to a base-64 encoded png.
bool GetLatestOutput(vtkTypeUInt32 key, vtkSmartPointer< vtkUnsignedCharArray > &data)
Get access to the most-recent fully encoded result corresponding to the given key,...
~vtkDataEncoder() override
static vtkDataEncoder * New()
void Flush(vtkTypeUInt32 key)
Flushes the encoding pipe and blocks till the most recently pushed image for the particular key has b...
void Initialize()
Re-initializes the encoder.
void SetMaxThreads(vtkTypeUInt32)
Define the number of worker threads to use.
void Push(vtkTypeUInt32 key, vtkImageData *data, int quality, int encoding=1)
Push an image into the encoder.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
topologically and geometrically regular array of data
Definition: vtkImageData.h:155
a simple class to control print indentation
Definition: vtkIndent.h:108
abstract base class for most VTK objects
Definition: vtkObject.h:161
dynamic, self-adjusting array of unsigned char
@ key
Definition: vtkX3D.h:257
@ data
Definition: vtkX3D.h:315