VMTK
Loading...
Searching...
No Matches
vtkvmtkPNGWriter Class Reference

Writes .png files. More...

#include <vtkvmtkPNGWriter.h>

Inheritance diagram for vtkvmtkPNGWriter:
[legend]
Collaboration diagram for vtkvmtkPNGWriter:
[legend]

Public Types

typedef vtkPNGWriter Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkPNGWriter * NewInstance () const
void PrintSelf (std::ostream &os, vtkIndent indent) override
virtual void Write () override
virtual char * GetBase64Image ()
virtual void SetBase64Image (const char *)
virtual void SetWriteToBase64 (int)
virtual int GetWriteToBase64 ()
virtual void WriteToBase64On ()
virtual void WriteToBase64Off ()
virtual void SetFlipImage (int)
virtual int GetFlipImage ()
virtual void FlipImageOn ()
virtual void FlipImageOff ()

Static Public Member Functions

static vtkvmtkPNGWriter * New ()
static int IsTypeOf (const char *type)
static vtkvmtkPNGWriter * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkPNGWriter ()
 ~vtkvmtkPNGWriter ()

Protected Attributes

char * Base64Image
int WriteToBase64
int FlipImage

Detailed Description

Writes .png files.

Definition at line 32 of file vtkvmtkPNGWriter.h.

Member Typedef Documentation

◆ Superclass

typedef vtkPNGWriter vtkvmtkPNGWriter::Superclass

Definition at line 36 of file vtkvmtkPNGWriter.h.

Constructor & Destructor Documentation

◆ vtkvmtkPNGWriter()

vtkvmtkPNGWriter::vtkvmtkPNGWriter ( )
protected

Definition at line 90 of file vtkvmtkPNGWriter.cxx.

91{
92 this->Base64Image = NULL;
93 this->WriteToBase64 = 0;
94 this->FlipImage = 0;
95}

◆ ~vtkvmtkPNGWriter()

vtkvmtkPNGWriter::~vtkvmtkPNGWriter ( )
protected

Definition at line 97 of file vtkvmtkPNGWriter.cxx.

98{
99 if (this->Base64Image)
100 {
101 delete[] this->Base64Image;
102 this->Base64Image = NULL;
103 }
104}

Member Function Documentation

◆ New()

vtkvmtkPNGWriter * vtkvmtkPNGWriter::New ( )
static

◆ IsTypeOf()

int vtkvmtkPNGWriter::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkPNGWriter::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkPNGWriter * vtkvmtkPNGWriter::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkPNGWriter::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkPNGWriter * vtkvmtkPNGWriter::NewInstance ( ) const

◆ PrintSelf()

void vtkvmtkPNGWriter::PrintSelf ( std::ostream & os,
vtkIndent indent )
override

Definition at line 233 of file vtkvmtkPNGWriter.cxx.

234{
235 vtkPNGWriter::PrintSelf(os,indent);
236}

◆ GetBase64Image()

virtual char * vtkvmtkPNGWriter::GetBase64Image ( )
virtual

Get/set the base64-encoded PNG image data. This is populated by Write() when WriteToBase64 is on (the Set accessor is used internally for that purpose); read it after Write() to retrieve the encoded image without going through disk. Default: NULL.

◆ SetBase64Image()

virtual void vtkvmtkPNGWriter::SetBase64Image ( const char * )
virtual

Get/set the base64-encoded PNG image data. This is populated by Write() when WriteToBase64 is on (the Set accessor is used internally for that purpose); read it after Write() to retrieve the encoded image without going through disk. Default: NULL.

◆ SetWriteToBase64()

virtual void vtkvmtkPNGWriter::SetWriteToBase64 ( int )
virtual

Set/get whether Write() encodes the written image as a base64 string (retrievable through GetBase64Image) instead of the default vtkPNGWriter behavior of writing only to disk/memory. Default: off.

◆ GetWriteToBase64()

virtual int vtkvmtkPNGWriter::GetWriteToBase64 ( )
virtual

Set/get whether Write() encodes the written image as a base64 string (retrievable through GetBase64Image) instead of the default vtkPNGWriter behavior of writing only to disk/memory. Default: off.

◆ WriteToBase64On()

virtual void vtkvmtkPNGWriter::WriteToBase64On ( )
virtual

Set/get whether Write() encodes the written image as a base64 string (retrievable through GetBase64Image) instead of the default vtkPNGWriter behavior of writing only to disk/memory. Default: off.

◆ WriteToBase64Off()

virtual void vtkvmtkPNGWriter::WriteToBase64Off ( )
virtual

Set/get whether Write() encodes the written image as a base64 string (retrievable through GetBase64Image) instead of the default vtkPNGWriter behavior of writing only to disk/memory. Default: off.

◆ SetFlipImage()

virtual void vtkvmtkPNGWriter::SetFlipImage ( int )
virtual

Set/get whether the image is flipped vertically (rows reversed) before being written/encoded. Default: off.

◆ GetFlipImage()

virtual int vtkvmtkPNGWriter::GetFlipImage ( )
virtual

Set/get whether the image is flipped vertically (rows reversed) before being written/encoded. Default: off.

◆ FlipImageOn()

virtual void vtkvmtkPNGWriter::FlipImageOn ( )
virtual

Set/get whether the image is flipped vertically (rows reversed) before being written/encoded. Default: off.

◆ FlipImageOff()

virtual void vtkvmtkPNGWriter::FlipImageOff ( )
virtual

Set/get whether the image is flipped vertically (rows reversed) before being written/encoded. Default: off.

◆ Write()

void vtkvmtkPNGWriter::Write ( )
overridevirtual

Write the input image to PNG. If WriteToBase64 is off, this simply forwards to the standard vtkPNGWriter behavior (writing to FileName/FilePattern or to memory). If WriteToBase64 is on, the image is instead (optionally flipped, see FlipImage, and) written to an in-memory PNG buffer which is then base64-encoded and stored in Base64Image.

Definition at line 106 of file vtkvmtkPNGWriter.cxx.

107{
108 if (!this->WriteToBase64) {
109 Superclass::Write();
110 return;
111 }
112
113 int previousWriteToMemory = this->GetWriteToMemory();
114
115 this->WriteToMemoryOn();
116
117 //Superclass::Write();
118
119 this->SetErrorCode(vtkErrorCode::NoError);
120
121 // Error checking
122 if ( this->GetInput() == NULL )
123 {
124 vtkErrorMacro(<<"Write:Please specify an input!");
125 return;
126 }
127 if (!this->WriteToMemory && !this->GetFileName() && !this->GetFilePattern())
128 {
129 vtkErrorMacro(<<"Write:Please specify either a FileName or a file prefix and pattern");
130 this->SetErrorCode(vtkErrorCode::NoFileNameError);
131 return;
132 }
133
134 // Make sure the file name is allocated
135 this->InternalFileName =
136 new char[(this->GetFileName() ? strlen(this->GetFileName()) : 1) +
137 (this->GetFilePrefix() ? strlen(this->GetFilePrefix()) : 1) +
138 (this->GetFilePattern() ? strlen(this->GetFilePattern()) : 1) + 10];
139
140 // Fill in image information.
141 int *wExtent;
142 this->UpdateInformation();
143 vtkInformation *inInfoImage = this->GetInputPortInformation(0);
144 inInfoImage->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wExtent);
145
146 this->FileNumber = wExtent[4];
147 this->MinimumFileNumber = this->MaximumFileNumber = this->FileNumber;
148 this->FilesDeleted = 0;
149 this->UpdateProgress(0.0);
150 // loop over the z axis and write the slices
151 for (this->FileNumber = wExtent[4]; this->FileNumber <= wExtent[5];
152 ++this->FileNumber)
153 {
154 this->MaximumFileNumber = this->FileNumber;
155 int updatedExtent[6] = {wExtent[0], wExtent[1],
156 wExtent[2], wExtent[3],
157 this->FileNumber,
158 this->FileNumber};
159 // determine the name
160 if (this->GetFileName())
161 {
162 sprintf(this->InternalFileName,"%s",this->GetFileName());
163 }
164 else
165 {
166 if (this->GetFilePrefix())
167 {
168 sprintf(this->InternalFileName, this->GetFilePattern(),
169 this->GetFilePrefix(), this->FileNumber);
170 }
171 else
172 {
173 sprintf(this->InternalFileName, this->GetFilePattern(), this->FileNumber);
174 }
175 }
176
177 if (!this->FlipImage)
178 {
179 this->WriteSlice(this->GetInput(), updatedExtent);
180 }
181 else
182 {
183 vtkImageData* flippedInput = vtkImageData::New();
184 flippedInput->DeepCopy(this->GetInput());
185 vtkDataArray* inputArray = this->GetInput()->GetPointData()->GetScalars();
186 vtkDataArray* flippedInputArray = flippedInput->GetPointData()->GetScalars();
187 for (int i=0; i<wExtent[3]-wExtent[2]+1; i++)
188 {
189 for (int j=0; j<wExtent[1]-wExtent[0]+1; j++)
190 {
191 flippedInputArray->SetTuple((wExtent[3]-wExtent[2]-i)*(wExtent[1]-wExtent[0]+1)+j,inputArray->GetTuple(i*(wExtent[1]-wExtent[0]+1)+j));
192 }
193 }
194 this->WriteSlice(flippedInput, updatedExtent);
195 flippedInput->Delete();
196 }
197
198 if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
199 {
200 this->DeleteFiles();
201 break;
202 }
203 this->UpdateProgress((this->FileNumber - wExtent[4])/
204 (wExtent[5] - wExtent[4] + 1.0));
205 }
206 delete [] this->InternalFileName;
207 this->InternalFileName = NULL;
208
209 vtkUnsignedCharArray* result = this->GetResult();
210 char* data = (char*)result->GetPointer(0);
211 int length = result->GetNumberOfTuples() * result->GetNumberOfComponents();
212
213 char* flipped_data = new char[length];
214 if (this->FlipImage)
215 {
216 for (int i=0; i<length; i++)
217 {
218 flipped_data[i] = data[length-i-1];
219 }
220 data = flipped_data;
221 }
222
223 char* encoded_data = new char[2*length];
224 int output_length = base64_encode(encoded_data,data,length);
225 this->SetBase64Image(encoded_data);
226
227 delete[] encoded_data;
228 delete[] flipped_data;
229
230 this->SetWriteToMemory(previousWriteToMemory);
231}
virtual void SetBase64Image(const char *)
long base64_encode(char *to, char *from, unsigned int len)

Member Data Documentation

◆ Base64Image

char* vtkvmtkPNGWriter::Base64Image
protected

Definition at line 82 of file vtkvmtkPNGWriter.h.

◆ WriteToBase64

int vtkvmtkPNGWriter::WriteToBase64
protected

Definition at line 83 of file vtkvmtkPNGWriter.h.

◆ FlipImage

int vtkvmtkPNGWriter::FlipImage
protected

Definition at line 84 of file vtkvmtkPNGWriter.h.


The documentation for this class was generated from the following files: