1 // Copyright 2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <openvkl/openvkl.h>
7 #include <openvkl/vdb.h>
8 #include <list>
9 #include <string>
10 #include <vector>
11 #include <stdexcept>
12 
13 namespace openvkl {
14   namespace examples {
15 
16     struct VolumeParams;
17 
filterToString(VKLFilter filter)18     inline std::string filterToString(VKLFilter filter)
19     {
20       switch (filter) {
21       case VKL_FILTER_NEAREST:
22         return "nearest";
23       case VKL_FILTER_TRILINEAR:
24         return "trilinear";
25       case VKL_FILTER_TRICUBIC:
26         return "tricubic";
27       default:
28         break;
29       }
30       return "";
31     }
32 
stringToFilter(const std::string & filterArg)33     inline VKLFilter stringToFilter(const std::string &filterArg)
34     {
35       if (filterArg == "trilinear")
36         return VKL_FILTER_TRILINEAR;
37       else if (filterArg == "tricubic")
38         return VKL_FILTER_TRICUBIC;
39       else if (filterArg == "nearest")
40         return VKL_FILTER_NEAREST;
41       else
42         throw std::runtime_error("unsupported filter specified: " + filterArg);
43       return VKL_FILTER_TRILINEAR;
44     }
45 
46 
47     struct SamplerParams
48     {
49       int maxSamplingDepth = VKL_VDB_NUM_LEVELS - 1;
50       VKLFilter filter{VKL_FILTER_TRILINEAR};
51       VKLFilter gradientFilter{VKL_FILTER_TRILINEAR};
52 
53       void parseCommandLine(std::list<std::string> &args,
54           const VolumeParams &volumeParams);
55       static void usage();
56       void updateSampler(VKLSampler sampler) const;
57 
supportedFiltersSamplerParams58       static const std::vector<VKLFilter> &supportedFilters(
59           const std::string &volumeType)
60       {
61         if (volumeType == "structuredRegular"
62          || volumeType == "structuredSpherical"
63          || volumeType == "vdb")
64         {
65           static const std::vector<VKLFilter> types = {
66             VKL_FILTER_NEAREST,
67             VKL_FILTER_TRILINEAR,
68             VKL_FILTER_TRICUBIC
69           };
70           return types;
71         }
72 
73         static const std::vector<VKLFilter> types;
74         return types;
75       }
76 
77     private:
78       void validate(const VolumeParams &volumeParams) const;
79     };
80 
81   }  // namespace examples
82 }  // namespace openvkl
83