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_testing.h" 8 9 #include <rkcommon/math/constants.h> 10 #include <rkcommon/math/vec.h> 11 12 #include <cstdint> 13 #include <list> 14 #include <map> 15 #include <memory> 16 #include <string> 17 #include <vector> 18 19 namespace openvkl { 20 namespace examples { 21 22 using namespace rkcommon::math; 23 using namespace openvkl::testing; 24 stringToVoxelType(const std::string & type)25 inline VKLDataType stringToVoxelType(const std::string &type) 26 { 27 static const std::map<std::string, VKLDataType> map = { 28 {"uchar", VKL_UCHAR}, 29 {"short", VKL_SHORT}, 30 {"ushort", VKL_USHORT}, 31 {"half", VKL_HALF}, 32 {"float", VKL_FLOAT}, 33 {"double", VKL_DOUBLE}}; 34 35 const auto it = map.find(type); 36 if (it == map.end()) { 37 return VKL_UNKNOWN; 38 } 39 40 return it->second; 41 } 42 voxelTypeToString(VKLDataType type)43 inline const std::string &voxelTypeToString(VKLDataType type) 44 { 45 static const std::map<VKLDataType, std::string> map = { 46 {VKL_UCHAR, "uchar"}, 47 {VKL_SHORT, "short"}, 48 {VKL_USHORT, "ushort"}, 49 {VKL_HALF, "half"}, 50 {VKL_FLOAT, "float"}, 51 {VKL_DOUBLE, "double"}}; 52 53 const auto it = map.find(type); 54 if (it == map.end()) { 55 static const std::string uk = "unknown"; 56 return uk; 57 } 58 59 return it->second; 60 } 61 62 struct VolumeParams 63 { 64 std::string volumeType{supportedVolumeTypes()[0]}; 65 std::string source{supportedSources("structuredRegular")[0]}; 66 std::string filename; 67 std::string field{supportedFields("structuredRegular")[0]}; 68 std::string fieldInFile{"density"}; 69 VKLDataType voxelType{VKL_FLOAT}; 70 float background{VKL_BACKGROUND_UNDEFINED}; 71 int numParticles{1000}; 72 73 vec3i dimensions{128}; 74 vec3f gridOrigin{rkcommon::math::nan}; 75 vec3f gridSpacing{rkcommon::math::nan}; 76 77 bool multiAttribute{false}; 78 79 bool motionBlurStructured{false}; 80 bool motionBlurUnstructured{false}; 81 std::vector<float> motionBlurUnstructuredTimeSamples{ 82 0.f, 0.15f, 0.3f, 0.65f, 0.9f, 1.0f}; 83 uint8_t motionBlurStructuredNumTimesteps{6}; 84 85 void parseCommandLine(std::list<std::string> &args); 86 static void usage(); 87 88 // This method will throw if there is an error in creating the volume. 89 std::unique_ptr<testing::TestingVolume> createVolume() const; 90 91 private: 92 void validate() const; 93 TemporalConfig createTemporalConfig() const; 94 95 std::unique_ptr<testing::TestingVolume> createStructuredRegularVolume() 96 const; 97 std::unique_ptr<testing::TestingVolume> createStructuredSphericalVolume() 98 const; 99 std::unique_ptr<testing::TestingVolume> createUnstructuredVolume() const; 100 std::unique_ptr<testing::TestingVolume> createAmrVolume() const; 101 std::unique_ptr<testing::TestingVolume> createVdbVolume() const; 102 std::unique_ptr<testing::TestingVolume> createParticleVolume() const; 103 104 public: 105 void generateGridTransform(); 106 107 // Shared volume params. Only include things here that are valid for 108 // all volume types, and should remain the same when switching volume 109 // types. supportedVolumeTypesVolumeParams110 static const std::vector<std::string> &supportedVolumeTypes() 111 { 112 static std::vector<std::string> sup = {"structuredRegular", 113 "structuredSpherical", 114 "unstructured", 115 "amr", 116 "vdb", 117 "particle"}; 118 return sup; 119 }; 120 supportedVoxelTypesVolumeParams121 static const std::vector<VKLDataType> &supportedVoxelTypes( 122 const std::string &volumeType) 123 { 124 if (volumeType == "structuredRegular" || 125 volumeType == "structuredSpherical") { 126 static const std::vector<VKLDataType> types = {VKL_UCHAR, 127 VKL_SHORT, 128 VKL_USHORT, 129 VKL_HALF, 130 VKL_FLOAT, 131 VKL_DOUBLE}; 132 return types; 133 } 134 135 else if (volumeType == "vdb") { 136 static const std::vector<VKLDataType> types = {VKL_HALF, VKL_FLOAT}; 137 return types; 138 } 139 140 static const std::vector<VKLDataType> types; 141 return types; 142 } 143 supportedSourcesVolumeParams144 static const std::vector<std::string> &supportedSources( 145 const std::string &volumeType) 146 { 147 if (volumeType == "structuredRegular" || volumeType == "vdb") { 148 static const std::vector<std::string> sources = { 149 "procedural", "file"}; 150 return sources; 151 } 152 static const std::vector<std::string> sources = { 153 "procedural"}; 154 return sources; 155 }; 156 157 supportedFieldsVolumeParams158 static const std::vector<std::string> &supportedFields( 159 const std::string &volumeType) 160 { 161 if (volumeType == "unstructured") { 162 static const std::vector<std::string> fields = { 163 "wavelet", "xyz", "sphere", "mixed"}; 164 return fields; 165 } 166 167 static const std::vector<std::string> fields = { 168 "wavelet", "xyz", "sphere"}; 169 return fields; 170 }; 171 }; 172 173 } // namespace examples 174 } // namespace openvkl 175