Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Nektar
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
MMFSolver
Nektar
Commits
65fea4b5
Commit
65fea4b5
authored
Feb 21, 2013
by
Chris Cantwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up VtkToPng code.
Added option to fix scalar range.
parent
dc13d50b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
130 additions
and
94 deletions
+130
-94
utilities/PostProcessing/Extras/VtkToPng.cpp
utilities/PostProcessing/Extras/VtkToPng.cpp
+130
-94
No files found.
utilities/PostProcessing/Extras/VtkToPng.cpp
View file @
65fea4b5
/*
* VtkToPng.cpp
*
* Created on: 20 Feb 2013
* Author: cc
*/
//#include <vtkVersion.h>
//#if VTK_MAJOR_VERSION == 6
//int main(int, char *argv[])
//{
// std::cout << argv[0] << " requires VTK 5.10 or earlier. This VTK version is " << vtkVersion::GetVTKVersion() << std::endl;
// return EXIT_SUCCESS;
//}
//#else
///////////////////////////////////////////////////////////////////////////////
//
// File VtkToPng.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Render a VTK Unstructured Grid file as a PNG
//
///////////////////////////////////////////////////////////////////////////////
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
...
...
@@ -34,6 +54,15 @@ using namespace std;
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
!=
2
&&
argc
!=
4
)
{
cout
<<
"Usage: VtkToPng vtk-file [lower upper]"
<<
endl
;
exit
(
-
1
);
}
string
vInput
=
argv
[
1
];
string
vOutput
=
vInput
.
substr
(
0
,
vInput
.
find_last_of
(
'.'
))
+
".png"
;
// Setup offscreen rendering
vtkSmartPointer
<
vtkGraphicsFactory
>
graphics_factory
=
vtkSmartPointer
<
vtkGraphicsFactory
>::
New
();
...
...
@@ -44,20 +73,27 @@ int main(int argc, char * argv[])
vtkSmartPointer
<
vtkImagingFactory
>::
New
();
imaging_factory
->
SetUseMesaClasses
(
1
);
// Create a poly data reader
cout
<<
"Reading file: "
<<
argv
[
1
]
<<
endl
;
// Create a poly data reader and retrieve dataset from file
vtkXMLUnstructuredGridReader
*
reader
=
vtkXMLUnstructuredGridReader
::
New
();
reader
->
SetFileName
(
argv
[
1
]
);
reader
->
SetFileName
(
vInput
.
c_str
()
);
reader
->
Update
();
vtkDataSet
*
data
=
reader
->
GetOutputAsDataSet
();
vtkDataSet
*
data
=
reader
->
GetOutputAsDataSet
();
data
->
GetPointData
()
->
SetActiveScalars
(
"u"
);
double
scalar_range
[
2
];
data
->
GetScalarRange
(
scalar_range
);
if
(
argc
==
4
)
{
scalar_range
[
0
]
=
atof
(
argv
[
2
]);
scalar_range
[
1
]
=
atof
(
argv
[
3
]);
}
// Lookup table
vtkSmartPointer
<
vtkLookupTable
>
lookup
=
vtkSmartPointer
<
vtkLookupTable
>::
New
();
lookup
->
SetHueRange
(
0.0
,
1.0
);
lookup
->
SetSaturationRange
(
1
,
1
);
lookup
->
SetTableRange
(
data
->
GetScalarRange
()
);
lookup
->
SetTableRange
(
scalar_range
);
lookup
->
SetValueRange
(
1
,
1
);
lookup
->
Build
();
...
...
@@ -68,7 +104,8 @@ int main(int argc, char * argv[])
mapper
->
ImmediateModeRenderingOn
();
mapper
->
ScalarVisibilityOn
();
mapper
->
SetScalarModeToUsePointData
();
mapper
->
SetScalarRange
(
data
->
GetScalarRange
());
mapper
->
UseLookupTableScalarRangeOn
();
//mapper->SetScalarRange(data->GetScalarRange());
mapper
->
SetLookupTable
(
lookup
);
...
...
@@ -76,12 +113,11 @@ int main(int argc, char * argv[])
vtkSmartPointer
<
vtkActor
>::
New
();
actor
->
SetMapper
(
mapper
);
// The usual rendering stuff.
// Configure camera position and direction
vtkCamera
*
camera
=
vtkCamera
::
New
();
camera
->
SetPosition
(
0.0
,
-
1.0
,
1.0
);
camera
->
SetFocalPoint
(
0
,
0
,
0
);
// A renderer and render window
vtkSmartPointer
<
vtkRenderer
>
renderer
=
vtkSmartPointer
<
vtkRenderer
>::
New
();
...
...
@@ -98,19 +134,19 @@ int main(int argc, char * argv[])
renderWindow
->
Render
();
// Create an image of scene
vtkSmartPointer
<
vtkWindowToImageFilter
>
windowToImageFilter
=
vtkSmartPointer
<
vtkWindowToImageFilter
>::
New
();
windowToImageFilter
->
SetInput
(
renderWindow
);
windowToImageFilter
->
SetMagnification
(
4
);
windowToImageFilter
->
Update
();
cout
<<
"Writing file: "
<<
argv
[
2
]
<<
endl
;
// Write image to PNG
vtkSmartPointer
<
vtkPNGWriter
>
writer
=
vtkSmartPointer
<
vtkPNGWriter
>::
New
();
writer
->
SetFileName
(
argv
[
2
]
);
writer
->
SetFileName
(
vOutput
.
c_str
()
);
writer
->
SetInputConnection
(
windowToImageFilter
->
GetOutputPort
());
writer
->
Write
();
return
EXIT_SUCCESS
;
}
//#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment