Cleanup: remove redundant, invalid info from headers
[blender.git] / intern / openvdb / openvdb_capi.cc
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2015 Blender Foundation.
17  * All rights reserved.
18  */
19
20 #include "openvdb_capi.h"
21 #include "openvdb_dense_convert.h"
22 #include "openvdb_util.h"
23
24 struct OpenVDBFloatGrid { int unused; };
25 struct OpenVDBIntGrid { int unused; };
26 struct OpenVDBVectorGrid { int unused; };
27
28 int OpenVDB_getVersionHex()
29 {
30         return openvdb::OPENVDB_LIBRARY_VERSION;
31 }
32
33 OpenVDBFloatGrid *OpenVDB_export_grid_fl(
34         OpenVDBWriter *writer,
35         const char *name, float *data,
36                 const int res[3], float matrix[4][4], const float clipping,
37         OpenVDBFloatGrid *mask)
38 {
39         Timer(__func__);
40
41         using openvdb::FloatGrid;
42
43         FloatGrid *mask_grid = reinterpret_cast<FloatGrid *>(mask);
44         FloatGrid *grid = internal::OpenVDB_export_grid<FloatGrid>(
45                 writer,
46                 name,
47                 data,
48                 res,
49                 matrix,
50                         clipping,
51                 mask_grid);
52
53         return reinterpret_cast<OpenVDBFloatGrid *>(grid);
54 }
55
56 OpenVDBIntGrid *OpenVDB_export_grid_ch(
57         OpenVDBWriter *writer,
58         const char *name, unsigned char *data,
59                 const int res[3], float matrix[4][4], const float clipping,
60         OpenVDBFloatGrid *mask)
61 {
62         Timer(__func__);
63
64         using openvdb::FloatGrid;
65         using openvdb::Int32Grid;
66
67         FloatGrid *mask_grid = reinterpret_cast<FloatGrid *>(mask);
68         Int32Grid *grid = internal::OpenVDB_export_grid<Int32Grid>(
69                 writer,
70                 name,
71                 data,
72                 res,
73                 matrix,
74                         clipping,
75                 mask_grid);
76
77         return reinterpret_cast<OpenVDBIntGrid *>(grid);
78 }
79
80 OpenVDBVectorGrid *OpenVDB_export_grid_vec(struct OpenVDBWriter *writer,
81                 const char *name,
82                 const float *data_x, const float *data_y, const float *data_z,
83                 const int res[3], float matrix[4][4], short vec_type, const float clipping,
84                 const bool is_color, OpenVDBFloatGrid *mask)
85 {
86         Timer(__func__);
87
88         using openvdb::GridBase;
89         using openvdb::FloatGrid;
90         using openvdb::VecType;
91
92         FloatGrid *mask_grid = reinterpret_cast<FloatGrid *>(mask);
93         GridBase *grid = internal::OpenVDB_export_vector_grid(
94                 writer,
95                 name,
96                 data_x,
97                 data_y,
98                 data_z,
99                 res,
100                 matrix,
101                 static_cast<VecType>(vec_type),
102                 is_color,
103                         clipping,
104                 mask_grid);
105
106         return reinterpret_cast<OpenVDBVectorGrid *>(grid);
107 }
108
109 void OpenVDB_import_grid_fl(
110         OpenVDBReader *reader,
111         const char *name, float **data,
112         const int res[3])
113 {
114         Timer(__func__);
115
116         internal::OpenVDB_import_grid<openvdb::FloatGrid>(reader, name, data, res);
117 }
118
119 void OpenVDB_import_grid_ch(
120         OpenVDBReader *reader,
121         const char *name, unsigned char **data,
122         const int res[3])
123 {
124         internal::OpenVDB_import_grid<openvdb::Int32Grid>(reader, name, data, res);
125 }
126
127 void OpenVDB_import_grid_vec(
128         struct OpenVDBReader *reader,
129         const char *name,
130         float **data_x, float **data_y, float **data_z,
131         const int res[3])
132 {
133         Timer(__func__);
134
135         internal::OpenVDB_import_grid_vector(reader, name, data_x, data_y, data_z, res);
136 }
137
138 OpenVDBWriter *OpenVDBWriter_create()
139 {
140         return new OpenVDBWriter();
141 }
142
143 void OpenVDBWriter_free(OpenVDBWriter *writer)
144 {
145         delete writer;
146 }
147
148 void OpenVDBWriter_set_flags(OpenVDBWriter *writer, const int flag, const bool half)
149 {
150         int compression_flags = openvdb::io::COMPRESS_ACTIVE_MASK;
151
152 #ifdef WITH_OPENVDB_BLOSC
153         if (flag == 0) {
154                 compression_flags |= openvdb::io::COMPRESS_BLOSC;
155         }
156         else
157 #endif
158         if (flag == 1) {
159                 compression_flags |= openvdb::io::COMPRESS_ZIP;
160         }
161         else {
162                 compression_flags = openvdb::io::COMPRESS_NONE;
163         }
164
165         writer->setFlags(compression_flags, half);
166 }
167
168 void OpenVDBWriter_add_meta_fl(OpenVDBWriter *writer, const char *name, const float value)
169 {
170         writer->insertFloatMeta(name, value);
171 }
172
173 void OpenVDBWriter_add_meta_int(OpenVDBWriter *writer, const char *name, const int value)
174 {
175         writer->insertIntMeta(name, value);
176 }
177
178 void OpenVDBWriter_add_meta_v3(OpenVDBWriter *writer, const char *name, const float value[3])
179 {
180         writer->insertVec3sMeta(name, value);
181 }
182
183 void OpenVDBWriter_add_meta_v3_int(OpenVDBWriter *writer, const char *name, const int value[3])
184 {
185         writer->insertVec3IMeta(name, value);
186 }
187
188 void OpenVDBWriter_add_meta_mat4(OpenVDBWriter *writer, const char *name, float value[4][4])
189 {
190         writer->insertMat4sMeta(name, value);
191 }
192
193 void OpenVDBWriter_write(OpenVDBWriter *writer, const char *filename)
194 {
195         writer->write(filename);
196 }
197
198 OpenVDBReader *OpenVDBReader_create()
199 {
200         return new OpenVDBReader();
201 }
202
203 void OpenVDBReader_free(OpenVDBReader *reader)
204 {
205         delete reader;
206 }
207
208 void OpenVDBReader_open(OpenVDBReader *reader, const char *filename)
209 {
210         reader->open(filename);
211 }
212
213 void OpenVDBReader_get_meta_fl(OpenVDBReader *reader, const char *name, float *value)
214 {
215         reader->floatMeta(name, *value);
216 }
217
218 void OpenVDBReader_get_meta_int(OpenVDBReader *reader, const char *name, int *value)
219 {
220         reader->intMeta(name, *value);
221 }
222
223 void OpenVDBReader_get_meta_v3(OpenVDBReader *reader, const char *name, float value[3])
224 {
225         reader->vec3sMeta(name, value);
226 }
227
228 void OpenVDBReader_get_meta_v3_int(OpenVDBReader *reader, const char *name, int value[3])
229 {
230         reader->vec3IMeta(name, value);
231 }
232
233 void OpenVDBReader_get_meta_mat4(OpenVDBReader *reader, const char *name, float value[4][4])
234 {
235         reader->mat4sMeta(name, value);
236 }