Skip to content

Commit

Permalink
Merge pull request #15266 from pcafrica/vtk_support
Browse files Browse the repository at this point in the history
Added support for VTK
  • Loading branch information
luca-heltai committed Jun 8, 2023
2 parents 5ac9d67 + 072d8ca commit 9d9ae9a
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
-D DEAL_II_WITH_PETSC="ON" \
-D DEAL_II_WITH_METIS="ON" \
-D DEAL_II_WITH_HDF5="ON" \
-D DEAL_II_WITH_VTK="ON" \
-D DEAL_II_COMPONENT_EXAMPLES="OFF" \
..
- name: print detailed.log
Expand All @@ -104,7 +105,7 @@ jobs:
export OMPI_MCA_btl_base_warn_component_unused='0'
cd build
make -j2 setup_tests_simplex
make -j2 setup_tests_simplex setup_tests_vtk
ctest --output-on-failure -j2
- name: failed test log
if: ${{ failure() }}
Expand Down
20 changes: 20 additions & 0 deletions cmake/configure/configure_50_vtk.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## ---------------------------------------------------------------------
##
## Copyright (C) 2012 - 2015 by the deal.II authors
##
## This file is part of the deal.II library.
##
## The deal.II library is free software; you can use it, redistribute
## it, and/or modify it under the terms of the GNU Lesser General
## Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## The full text of the license can be found in the file LICENSE.md at
## the top level directory of deal.II.
##
## ---------------------------------------------------------------------

#
# Configuration for the VTK library:
#

configure_feature(VTK)
65 changes: 65 additions & 0 deletions cmake/modules/FindDEAL_II_VTK.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
## ---------------------------------------------------------------------
##
## Copyright (C) 2023 by the deal.II authors
##
## This file is part of the deal.II library.
##
## The deal.II library is free software; you can use it, redistribute
## it, and/or modify it under the terms of the GNU Lesser General
## Public License as published by the Free Software Foundation; either
## version 2.1 of the License, or (at your option) any later version.
## The full text of the license can be found in the file LICENSE.md at
## the top level directory of deal.II.
##
## ---------------------------------------------------------------------

#
# Try to find the VTK libraries
#
# This module exports:
#
# VTK_INCLUDE_DIR
# VTK_VERSION_MAJOR
# VTK_VERSION_MINOR
# VTK_LIBRARIES
#

set(VTK_DIR "" CACHE PATH "An optional hint to a VTK installation")
set_if_empty(VTK_DIR "$ENV{VTK_DIR}")

if(NOT "${VTK_DIR}" STREQUAL "")
set(VTK_DIR ${VTK_DIR})
endif()

find_package(VTK 9.0.0 QUIET HINTS ${VTK_DIR})

if(VTK_FOUND)
set(VTK_VERSION "${VTK_VERSION}")
set(VTK_MAJOR_VERSION "${VTK_MAJOR_VERSION}")
set(VTK_MINOR_VERSION "${VTK_MINOR_VERSION}")

set(VTK_INCLUDE_DIR
${VTK_PREFIX_PATH}/include/vtk-${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION})

# Try to find full paths from targets contained in VTK_LIBRARIES.
set(_libraries)
foreach(_library ${VTK_LIBRARIES})
if(NOT ${_library} MATCHES "Python"
AND NOT ${_library} MATCHES "MPI4Py")
get_target_property(_configurations ${_library} IMPORTED_CONFIGURATIONS)

if(_configurations)
foreach(_configuration ${_configurations})
get_target_property(_imported_location ${_library} IMPORTED_LOCATION_${_configuration})
list(APPEND _libraries ${_imported_location})
endforeach()
endif()
endif()
endforeach()
endif()

process_feature(VTK
LIBRARIES REQUIRED _libraries
INCLUDE_DIRS REQUIRED VTK_INCLUDE_DIR
CLEAR VTK_INCLUDE_DIR VTK_LIBRARIES _libraries
)
1 change: 1 addition & 0 deletions contrib/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ RUN cd /usr/src && \
-DDEAL_II_WITH_TBB=ON \
-DDEAL_II_WITH_TRILINOS=ON \
-DDEAL_II_WITH_UMFPACK=ON \
-DDEAL_II_WITH_VTK=ON \
-DDEAL_II_WITH_ZLIB=ON \
.. \
&& ninja -j 2 install \
Expand Down
1 change: 1 addition & 0 deletions doc/doxygen/options.dox.in
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ PREDEFINED = DOXYGEN=1 \
DEAL_II_TRILINOS_WITH_ZOLTAN=1 \
DEAL_II_TRILINOS_VERSION_GTE=1 \
DEAL_II_WITH_UMFPACK=1 \
DEAL_II_WITH_VTK=1 \
DEAL_II_WITH_ZLIB=1

# do not expand exception declarations
Expand Down
3 changes: 3 additions & 0 deletions doc/news/changes/major/20230524Africa
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
New: Added support for the VTK library (https://vtk.org/).
<br>
(Pasquale Africa, 2023/05/24)
17 changes: 17 additions & 0 deletions doc/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,23 @@ <h4>Optional interfaces to other software packages</h4>
</dd>
</dl>

<dt><a name="vtk"/>
<a href="https://vtk.org/" target="_top">VTK</a></dt>
<dd>
<p>
The <a href="https://vtk.org/" target="_top">Visualization Toolkit (VTK)</a> is an open-source,
freely available software system for 3D computer graphics, modeling, image processing, volume rendering,
scientific visualization, and 2D plotting.

It supports a wide variety of visualization algorithms and advanced modeling techniques,
and it takes advantage of both threaded and distributed memory parallel processing for speed and scalability,
respectively.

In order to use VTK, add
<code>-DVTK_DIR=/path/to/vtk</code> to the deal.II CMake call.
</p>
</dd>

<dt><a name="zlib"/>
<a href="http://zlib.net/" target="_top">zlib</a></dt>
<dd>
Expand Down
1 change: 1 addition & 0 deletions doc/users/cmake_dealii.html
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ <h3>Feature configuration</h3>
DEAL_II_WITH_TBB
DEAL_II_WITH_TRILINOS
DEAL_II_WITH_UMFPACK
DEAL_II_WITH_VTK
DEAL_II_WITH_ZLIB
</pre>
They all have standard meanings with the exception of one:
Expand Down
1 change: 1 addition & 0 deletions doc/users/config.sample
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
# set(DEAL_II_WITH_TBB "ON" CACHE BOOL "")
# set(DEAL_II_WITH_TRILINOS "ON" CACHE BOOL "")
# set(DEAL_II_WITH_UMFPACK "ON" CACHE BOOL "")
# set(DEAL_II_WITH_VTK "ON" CACHE BOOL "")
# set(DEAL_II_WITH_ZLIB "ON" CACHE BOOL "")
#

Expand Down
1 change: 1 addition & 0 deletions include/deal.II/base/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#cmakedefine DEAL_II_WITH_TRILINOS
#cmakedefine DEAL_II_WITH_UMFPACK
#cmakedefine DEAL_II_FEATURE_UMFPACK_BUNDLED_CONFIGURED
#cmakedefine DEAL_II_WITH_VTK
#cmakedefine DEAL_II_WITH_ZLIB

#ifdef DEAL_II_WITH_TBB
Expand Down
81 changes: 81 additions & 0 deletions include/deal.II/vtk/utilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2023 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------

#ifndef dealii_vtk_utilities_h
#define dealii_vtk_utilities_h

#include <deal.II/base/config.h>

#include <deal.II/base/exceptions.h>

#ifdef DEAL_II_WITH_VTK

# include <vtkDoubleArray.h>

DEAL_II_NAMESPACE_OPEN

/**
* Interface to the Visualization Toolkit (VTK).
*
* VTK is an open-source, freely available software system for 3D computer
* graphics, modeling, image processing, volume rendering, scientific
* visualization, and 2D plotting.
* It supports a wide variety of visualization algorithms and advanced
* modeling techniques, and it takes advantage of both threaded and distributed
* memory parallel processing for speed and scalability, respectively.
*
* You can learn more about the VTK library at https://vtk.org/
*/
namespace VTKWrappers
{
/**
* Convert from a deal.II Point to a VTK double array.
*
* @tparam dim Dimension of the point
* @param [in] p An input deal.II Point<dim>
* @return A VTK smart pointer to the data array.
*/
template <int dim>
inline vtkSmartPointer<vtkDoubleArray>
dealii_point_to_vtk_array(const dealii::Point<dim> &p);

# ifndef DOXYGEN
// Template implementations

template <int dim>
inline vtkSmartPointer<vtkDoubleArray>
dealii_point_to_vtk_array(const dealii::Point<dim> &p)
{
vtkSmartPointer<vtkDoubleArray> p_vtk =
vtkSmartPointer<vtkDoubleArray>::New();

p_vtk->SetNumberOfComponents(dim);
p_vtk->SetNumberOfTuples(1);

for (int d = 0; d < dim; ++d)
p_vtk->FillComponent(d, p[d]);

return p_vtk;
}

# endif

} // namespace VTKWrappers

DEAL_II_NAMESPACE_CLOSE

#endif
#endif
6 changes: 6 additions & 0 deletions tests/vtk/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.13.4)
include(../setup_testsubproject.cmake)
project(testsuite CXX)
if(DEAL_II_WITH_VTK)
deal_ii_pickup_tests()
endif()
39 changes: 39 additions & 0 deletions tests/vtk/vtk_01.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2023 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------

// Test conversion from deal.II Point to VTK double array

#include <deal.II/base/point.h>

#include <deal.II/vtk/utilities.h>

#include "../tests.h"

int
main()
{
initlog();

// Test conversion from deal.II Point to VTK array.
{
const Point<3> point_dealii(1.0, 2.0, 3.0);
const auto point_vtk = VTKWrappers::dealii_point_to_vtk_array(point_dealii);
deallog << "VTK Point: " << point_vtk->GetComponent(0, 0) << ", "
<< point_vtk->GetComponent(0, 1) << ", "
<< point_vtk->GetComponent(0, 2) << std::endl;
}

return 0;
}
2 changes: 2 additions & 0 deletions tests/vtk/vtk_01.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

DEAL::VTK Point: 1.00000, 2.00000, 3.00000

0 comments on commit 9d9ae9a

Please sign in to comment.