File: VTKCompatibility.hpp

package info (click to toggle)
yade 2025.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,308 kB
  • sloc: cpp: 93,298; python: 50,409; sh: 577; makefile: 162
file content (74 lines) | stat: -rw-r--r-- 2,818 bytes parent folder | download | duplicates (3)
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
// 2019 Janek Kozicki

/*
vtk changed their function name in vtk8, this is annoying. And we don't want to litter the code with
#ifdefs everywhere. Better to clean it up with vim comamnds:

:grep -E "InsertNextTupleValue" --include="*" . -R --exclude ChangeLog --exclude tags --exclude CMakeLists.txt
:%s/InsertNextTupleValue(\([^)]\+\))/INSERT_NEXT_TUPLE(\1)/gc

And use a macro in these places:
*/
#pragma once

#ifdef YADE_VTK
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wsuggest-override"
#include <vtkVersion.h>
// fix InsertNextTupleValue → InsertNextTuple name change
#if VTK_MAJOR_VERSION < 8
#define INSERT_NEXT_TUPLE(a) InsertNextTupleValue(a)
#define INSERT_NEXT_TYPED_TUPLE(a) InsertNextTupleValue(a)
#else
#define INSERT_NEXT_TUPLE(a) InsertNextTuple(a)
#define INSERT_NEXT_TYPED_TUPLE(a) InsertNextTypedTuple(a)
#endif
// (and others in the future)

#include <lib/base/Math.hpp>
#include <vtkDoubleArray.h>
#include <vtkPoints.h>
#include <vtkSampleFunction.h>
#include <vtkTransform.h>
#pragma GCC diagnostic pop

// these classes serve the purpose of converting Real to double without macros.
// Maybe VTK in the future will support non-double types. If that will be needed,
// the interface can be updated below.

struct vtkPointsReal : public vtkPoints {
	static vtkPointsReal* New() { return new vtkPointsReal; }; // a design decision made by VTK developers
	vtkIdType             InsertNextPoint(const ::yade::Vector3r&);
};

struct vtkSampleFunctionReal : public vtkSampleFunction {
	static vtkSampleFunctionReal* New() { return new vtkSampleFunctionReal; }; // a design decision made by VTK developers
	void                          SetModelBounds(const ::yade::Vector3r& min, const ::yade::Vector3r& max);
};

struct vtkTransformReal : public vtkTransform {
	static vtkTransformReal* New() { return new vtkTransformReal; }; // a design decision made by VTK developers
	void                     Translate(const ::yade::Vector3r&);
};

struct vtkDoubleArrayFromReal : public vtkDoubleArray {
	static vtkDoubleArrayFromReal* New() { return new vtkDoubleArrayFromReal; }; // a design decision made by VTK developers
	vtkIdType                      InsertNextTuple(const ::yade::Vector3r&);
	vtkIdType                      InsertNextTuple(const ::yade::Matrix3r&);
	vtkIdType                      InsertNextValue(const ::yade::Real&);
};

#endif


/*
# At first I wanted to do this inside cmake, but it turns out that function definitions
# are not supoprted: https://cmake.org/cmake/help/v3.0/prop_dir/COMPILE_DEFINITIONS.html#prop_dir:COMPILE_DEFINITIONS

IF(${VTK_MAJOR_VERSION} LESS 8)
  ADD_DEFINITIONS("-DINSERT_NEXT_TUPLE(a)=InsertNextTupleValue(a)")
ELSE()
  ADD_DEFINITIONS("-DINSERT_NEXT_TUPLE(a)=InsertNextTuple(a)")
ENDIF()
*/