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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOSPRayMaterialLibrary.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkOSPRayMaterialLibrary
* @brief a collection of materials for vtk apps to draw from
*
* A singleton instance of this class manages a collection of materials.
* The materials can be read in from disk or created programmatically.
*
* @sa vtkOSPRayMaterialHelpers
*/
#ifndef vtkOSPRayMaterialLibrary_h
#define vtkOSPRayMaterialLibrary_h
#include "vtkObject.h"
#include "vtkRenderingRayTracingModule.h" // For export macro
#include <initializer_list> //for initializer_list!
#include <map> //for map!
#include <set> //for set!
#include <string> //for string!
#include <vector> //for vector!
VTK_ABI_NAMESPACE_BEGIN
class vtkOSPRayMaterialLibraryInternals;
class vtkTexture;
struct TextureInfo;
class VTKRENDERINGRAYTRACING_EXPORT vtkOSPRayMaterialLibrary : public vtkObject
{
public:
static vtkOSPRayMaterialLibrary* New();
vtkTypeMacro(vtkOSPRayMaterialLibrary, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Called to kick off events in all followers.
*/
void Fire();
/**
* Reads the given file of materials and creates the in memory data
* structures needed to display objects with them. Returns false only if
* file could not be meaningfully interpreted.
*/
bool ReadFile(const char* FileName);
/**
* Serialize contents to an in memory buffer.
* If writeImageInline, all textures are stored in a XML format.
* Else, store the texture using its filename stored in its TextureInfo struct.
* Warning: you must free the return value using delete.
*/
const char* WriteBuffer(bool writeImageInline = true);
/**
* Serialize contents to a file specified by \p filename.
* If writeImageInline, all textures are stored in a XML format.
* Else, store the texture using its filename stored in its TextureInfo struct
* Warning: if \p filename exists, its content is discarded.
*/
void WriteFile(const std::string& filename, bool writeImageInline = false);
/**
* DeSerialize contents from an in memory buffer as ReadFile does from a
* file or set of files. Returns false only if buffer could not be
* meaningfully interpreted.
*/
bool ReadBuffer(const char* Buffer);
/**
* Returns the set of material nicknames.
*/
std::set<std::string> GetMaterialNames();
/**
* Return an implementation name for the given material nickname.
*/
std::string LookupImplName(const std::string& nickname);
/**
* Returns list of variable names set for a specific material.
*/
std::vector<std::string> GetDoubleShaderVariableList(const std::string& nickname);
/**
* Returns a uniform variable.
*/
std::vector<double> GetDoubleShaderVariable(
const std::string& nickname, const std::string& varname);
/**
* Returns list of texture names set for a specific material.
*/
std::vector<std::string> GetTextureList(const std::string& nickname);
/**
* Returns a texture.
*/
vtkTexture* GetTexture(const std::string& nickname, const std::string& varname);
/**
* Returns the texture information (name, texture and filename) of this \p varname.
* If not found, return nullptr;
*/
const TextureInfo* GetTextureInfo(const std::string& nickname, const std::string& varname);
/**
* Returns the name (and not the shader variable name) associated to a
* texture.
*/
std::string GetTextureName(const std::string& nickname, const std::string& varname);
/**
* Returns the filename associated ti a texture (if any).
*/
std::string GetTextureFilename(const std::string& nickname, const std::string& varname);
/**
* Add Material
* Adds a new material nickname to the set of known materials.
* If the name is a repeat, we replace the old one.
**/
void AddMaterial(const std::string& nickname, const std::string& implname);
/**
* Remove Material
* Removes a material nickname from the set of known materials.
* Do nothing if material does not exist.
**/
void RemoveMaterial(const std::string& nickname);
/**
* Add Texture
* Given a material @c nickname and a shader variable @c varname, set its data
* to a specific texture @c tex named @c texturename. If not specified the texture
* is called "unnamedTexture".
* The last parameter, filename, is defaulted to empty. If specified, the absolute path
* to find the texture will be stored. Useful when writing the library into a file.
*
* Replaces any previous content.
**/
void AddTexture(const std::string& nickname, const std::string& varname, vtkTexture* tex,
const std::string& texturename = "unnamedTexture", const std::string& filename = "");
/**
* Remove Texture
* Removes a texture for a specific materal @c nickname and shader variable @c varname.
* Do nothing if texture does not exist.
**/
void RemoveTexture(const std::string& nickname, const std::string& varname);
/**
* Remove all textures of a specific material
**/
void RemoveAllTextures(const std::string& nickname);
/**
* Add control variable
* Adds a new control variable. Replaces any previous content.
* @{
**/
void AddShaderVariable(
const std::string& nickname, const std::string& variablename, int numVars, const double* x);
void AddShaderVariable(const std::string& nickname, const std::string& variablename,
const std::initializer_list<double>& data)
{
this->AddShaderVariable(nickname, variablename, static_cast<int>(data.size()), data.begin());
}
/**@}*/
/**
* Remove control variable
* Removes a new control variable.
* Do nothing if variable does not exist.
**/
void RemoveShaderVariable(const std::string& nickname, const std::string& variablename);
/**
* Remove all control variables of a specific material
**/
void RemoveAllShaderVariables(const std::string& nickname);
/**
* Lists all different parameter types
*/
enum class ParameterType : unsigned char
{
FLOAT,
NORMALIZED_FLOAT,
FLOAT_DATA,
VEC3,
COLOR_RGB,
BOOLEAN,
TEXTURE,
VEC2,
VEC4
};
using ParametersMap = std::map<std::string, ParameterType>;
/**
* Get the dictionary of all possible materials based on OSPRay documentation.
*/
static const std::map<std::string, ParametersMap>& GetParametersDictionary();
protected:
vtkOSPRayMaterialLibrary();
~vtkOSPRayMaterialLibrary() override;
bool InternalParse(const char* name, bool IsFile);
bool InternalParseJSON(const char* name, bool IsFile, std::istream* doc);
bool InternalParseMTL(const char* name, bool IsFile, std::istream* doc);
bool ReadTextureFileOrData(const std::string& texFilenameOrData, bool fromfile,
const std::string& parentDir, vtkTexture* textr, std::string& textureName,
std::string& textureFilename);
private:
vtkOSPRayMaterialLibrary(const vtkOSPRayMaterialLibrary&) = delete;
void operator=(const vtkOSPRayMaterialLibrary&) = delete;
vtkOSPRayMaterialLibraryInternals* Internal;
};
VTK_ABI_NAMESPACE_END
#endif
|