Blender V5.0
BKE_volume_grid_type_traits.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Foundation
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#ifdef WITH_OPENVDB
12
14
15# include "BKE_volume_enums.hh"
16# include "openvdb_fwd.hh"
17
18namespace blender::bke {
19
30template<typename T> struct VolumeGridTraits {
34 using BlenderType = void;
38 using PrimitiveType = void;
42 using TreeType = void;
46 static constexpr VolumeGridType EnumType = VOLUME_GRID_UNKNOWN;
47};
48
49template<> struct VolumeGridTraits<bool> {
50 using BlenderType = bool;
51 using PrimitiveType = bool;
52 using TreeType = openvdb::BoolTree;
53 static constexpr VolumeGridType EnumType = VOLUME_GRID_BOOLEAN;
54
55 static bool to_openvdb(const bool &value)
56 {
57 return value;
58 }
59 static bool to_blender(const bool &value)
60 {
61 return value;
62 }
63};
64
65template<> struct VolumeGridTraits<int> {
66 using BlenderType = int;
67 using PrimitiveType = int;
68 using TreeType = openvdb::Int32Tree;
69 static constexpr VolumeGridType EnumType = VOLUME_GRID_INT;
70
71 static int to_openvdb(const int &value)
72 {
73 return value;
74 }
75 static int to_blender(const int &value)
76 {
77 return value;
78 }
79};
80
81template<> struct VolumeGridTraits<float> {
82 using BlenderType = float;
83 using PrimitiveType = float;
84 using TreeType = openvdb::FloatTree;
85 static constexpr VolumeGridType EnumType = VOLUME_GRID_FLOAT;
86
87 static float to_openvdb(const float &value)
88 {
89 return value;
90 }
91 static float to_blender(const float &value)
92 {
93 return value;
94 }
95};
96
97template<> struct VolumeGridTraits<float3> {
98 using BlenderType = float3;
99 using PrimitiveType = openvdb::Vec3f;
100 using TreeType = openvdb::Vec3STree;
101 static constexpr VolumeGridType EnumType = VOLUME_GRID_VECTOR_FLOAT;
102
103 static openvdb::Vec3f to_openvdb(const float3 &value)
104 {
105 return openvdb::Vec3f(value.x, value.y, value.z);
106 }
107 static float3 to_blender(const openvdb::Vec3f &value)
108 {
109 return float3(value.asV());
110 }
111};
112
113template<typename T> using OpenvdbTreeType = typename VolumeGridTraits<T>::TreeType;
114template<typename T> using OpenvdbGridType = openvdb::Grid<OpenvdbTreeType<T>>;
115
116} // namespace blender::bke
117
118#endif /* WITH_OPENVDB */
VolumeGridType
@ VOLUME_GRID_VECTOR_FLOAT
@ VOLUME_GRID_UNKNOWN
@ VOLUME_GRID_BOOLEAN
@ VOLUME_GRID_INT
@ VOLUME_GRID_FLOAT
nullptr float
VecBase< float, 3 > float3
PrimitiveType
VecBase< float, 3 > float3
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136