-
Notifications
You must be signed in to change notification settings - Fork 409
/
vtkPVGL2PSExporter.cxx
129 lines (111 loc) · 3.61 KB
/
vtkPVGL2PSExporter.cxx
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
// SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkPVGL2PSExporter.h"
#include "vtkActorCollection.h"
#include "vtkCubeAxesActor.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkProp3DCollection.h"
#include "vtkPropCollection.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRendererCollection.h"
#include "vtksys/SystemTools.hxx"
#include <cstdio> // for rename
vtkStandardNewMacro(vtkPVGL2PSExporter);
//----------------------------------------------------------------------------
vtkPVGL2PSExporter::vtkPVGL2PSExporter()
: ExcludeCubeAxesActorsFromRasterization(true)
{
}
//----------------------------------------------------------------------------
vtkPVGL2PSExporter::~vtkPVGL2PSExporter() = default;
//----------------------------------------------------------------------------
void vtkPVGL2PSExporter::WriteData()
{
// Write the output to a temporary file (vtkGL2PSExporter takes a prefix
// and sets the extension itself, while the ParaView export mechanism uses the
// full filename). The full name of the temporary file will be
// this->FileName + ".pvtmp.[format extension]".
std::string tmpFilePrefix(this->FileName + ".pvtmp");
this->SetFilePrefix(tmpFilePrefix.c_str());
// Setup raster exclusions if needed
if (this->Write3DPropsAsRasterImage != 0)
{
if (this->RasterExclusions == nullptr)
{
vtkNew<vtkPropCollection> coll;
this->SetRasterExclusions(coll.GetPointer());
}
vtkRendererCollection* renCol = this->RenderWindow->GetRenderers();
vtkRenderer* ren;
for (renCol->InitTraversal(); (ren = renCol->GetNextItem());)
{
vtkActorCollection* actorCol = ren->GetActors();
vtkActor* actor;
for (actorCol->InitTraversal(); (actor = actorCol->GetNextItem());)
{
// Add cubeaxes actors to raster exclusions if requested
if (this->ExcludeCubeAxesActorsFromRasterization != 0 && actor->IsA("vtkCubeAxesActor") &&
!this->RasterExclusions->IsItemPresent(actor))
{
this->RasterExclusions->AddItem(actor);
}
}
vtkPropCollection* viewProps = ren->GetViewProps();
vtkProp* prop;
for (viewProps->InitTraversal(); (prop = viewProps->GetNextProp());)
{
// Always exclude instances of PVAxesActor from rasterization
if (prop->IsA("vtkPVAxesActor") && !this->RasterExclusions->IsItemPresent(prop))
{
this->RasterExclusions->AddItem(prop);
}
}
}
}
this->Superclass::WriteData();
// Move to the requested destination
std::string tmpFileName(tmpFilePrefix);
switch (this->FileFormat)
{
case PS_FILE:
tmpFileName += ".ps";
break;
case EPS_FILE:
tmpFileName += ".eps";
break;
case PDF_FILE:
tmpFileName += ".pdf";
break;
case TEX_FILE:
tmpFileName += ".tex";
break;
case SVG_FILE:
tmpFileName += ".svg";
break;
}
std::string fromPath(tmpFileName);
std::string toPath(this->FileName);
if (this->Compress)
{
fromPath += ".gz";
toPath += ".gz";
}
if (vtksys::SystemTools::FileExists(toPath))
{
vtksys::SystemTools::RemoveFile(toPath);
}
int result = std::rename(fromPath.c_str(), toPath.c_str());
if (result != 0)
{
std::perror("Could not rename exported graphics file");
vtkErrorMacro("Cannot rename exported graphics file.");
return;
}
}
//----------------------------------------------------------------------------
void vtkPVGL2PSExporter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}