VTK  9.3.20240423
vtkOSPRayMaterialLibrary.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
16#ifndef vtkOSPRayMaterialLibrary_h
17#define vtkOSPRayMaterialLibrary_h
18
19#include "vtkObject.h"
20#include "vtkRenderingRayTracingModule.h" // For export macro
21
22#include <initializer_list> //for initializer_list!
23#include <map> //for map!
24#include <set> //for set!
25#include <string> //for string!
26#include <vector> //for vector!
27
28VTK_ABI_NAMESPACE_BEGIN
29class vtkOSPRayMaterialLibraryInternals;
30class vtkTexture;
31struct TextureInfo;
32
33class VTKRENDERINGRAYTRACING_EXPORT vtkOSPRayMaterialLibrary : public vtkObject
34{
35public:
38 void PrintSelf(ostream& os, vtkIndent indent) override;
39
43 void Fire();
44
50 bool ReadFile(const char* FileName);
51
58 const char* WriteBuffer(bool writeImageInline = true);
59
66 void WriteFile(const std::string& filename, bool writeImageInline = false);
67
73 bool ReadBuffer(const char* Buffer);
74
78 std::set<std::string> GetMaterialNames();
79
83 std::string LookupImplName(const std::string& nickname);
84
88 std::vector<std::string> GetDoubleShaderVariableList(const std::string& nickname);
89
93 std::vector<double> GetDoubleShaderVariable(
94 const std::string& nickname, const std::string& varname);
95
99 std::vector<std::string> GetTextureList(const std::string& nickname);
100
104 vtkTexture* GetTexture(const std::string& nickname, const std::string& varname);
105
110 const TextureInfo* GetTextureInfo(const std::string& nickname, const std::string& varname);
111
116 std::string GetTextureName(const std::string& nickname, const std::string& varname);
117
121 std::string GetTextureFilename(const std::string& nickname, const std::string& varname);
122
128 void AddMaterial(const std::string& nickname, const std::string& implname);
129
135 void RemoveMaterial(const std::string& nickname);
136
147 void AddTexture(const std::string& nickname, const std::string& varname, vtkTexture* tex,
148 const std::string& texturename = "unnamedTexture", const std::string& filename = "");
149
155 void RemoveTexture(const std::string& nickname, const std::string& varname);
156
160 void RemoveAllTextures(const std::string& nickname);
161
168 const std::string& nickname, const std::string& variablename, int numVars, const double* x);
169 void AddShaderVariable(const std::string& nickname, const std::string& variablename,
170 const std::initializer_list<double>& data)
171 {
172 this->AddShaderVariable(nickname, variablename, static_cast<int>(data.size()), data.begin());
173 }
181 void RemoveShaderVariable(const std::string& nickname, const std::string& variablename);
182
186 void RemoveAllShaderVariables(const std::string& nickname);
187
191 enum class ParameterType : unsigned char
192 {
193 FLOAT,
194 NORMALIZED_FLOAT,
195 FLOAT_DATA,
196 VEC3,
197 COLOR_RGB,
198 BOOLEAN,
199 TEXTURE,
200 VEC2,
201 VEC4
202 };
203
204 using ParametersMap = std::map<std::string, ParameterType>;
205
209 static const std::map<std::string, ParametersMap>& GetParametersDictionary();
210
211protected:
214
215 bool InternalParse(const char* name, bool IsFile);
216 bool InternalParseJSON(const char* name, bool IsFile, std::istream* doc);
217 bool InternalParseMTL(const char* name, bool IsFile, std::istream* doc);
218 bool ReadTextureFileOrData(const std::string& texFilenameOrData, bool fromfile,
219 const std::string& parentDir, vtkTexture* textr, std::string& textureName,
220 std::string& textureFilename);
221
222private:
224 void operator=(const vtkOSPRayMaterialLibrary&) = delete;
225
226 vtkOSPRayMaterialLibraryInternals* Internal;
227};
228
229VTK_ABI_NAMESPACE_END
230#endif
a simple class to control print indentation
Definition vtkIndent.h:108
a collection of materials for vtk apps to draw from
void RemoveMaterial(const std::string &nickname)
Remove Material Removes a material nickname from the set of known materials.
void AddShaderVariable(const std::string &nickname, const std::string &variablename, const std::initializer_list< double > &data)
Add control variable Adds a new control variable.
std::vector< double > GetDoubleShaderVariable(const std::string &nickname, const std::string &varname)
Returns a uniform variable.
const TextureInfo * GetTextureInfo(const std::string &nickname, const std::string &varname)
Returns the texture information (name, texture and filename) of this varname.
bool ReadBuffer(const char *Buffer)
DeSerialize contents from an in memory buffer as ReadFile does from a file or set of files.
std::string GetTextureFilename(const std::string &nickname, const std::string &varname)
Returns the filename associated ti a texture (if any).
std::vector< std::string > GetDoubleShaderVariableList(const std::string &nickname)
Returns list of variable names set for a specific material.
bool InternalParseJSON(const char *name, bool IsFile, std::istream *doc)
std::string LookupImplName(const std::string &nickname)
Return an implementation name for the given material nickname.
void RemoveTexture(const std::string &nickname, const std::string &varname)
Remove Texture Removes a texture for a specific materal nickname and shader variable varname.
void WriteFile(const std::string &filename, bool writeImageInline=false)
Serialize contents to a file specified by filename.
std::string GetTextureName(const std::string &nickname, const std::string &varname)
Returns the name (and not the shader variable name) associated to a texture.
std::set< std::string > GetMaterialNames()
Returns the set of material nicknames.
bool InternalParseMTL(const char *name, bool IsFile, std::istream *doc)
const char * WriteBuffer(bool writeImageInline=true)
Serialize contents to an in memory buffer.
void RemoveAllTextures(const std::string &nickname)
Remove all textures of a specific material.
std::vector< std::string > GetTextureList(const std::string &nickname)
Returns list of texture names set for a specific material.
vtkTexture * GetTexture(const std::string &nickname, const std::string &varname)
Returns a texture.
void RemoveShaderVariable(const std::string &nickname, const std::string &variablename)
Remove control variable Removes a new control variable.
bool InternalParse(const char *name, bool IsFile)
void AddMaterial(const std::string &nickname, const std::string &implname)
Add Material Adds a new material nickname to the set of known materials.
std::map< std::string, ParameterType > ParametersMap
void AddShaderVariable(const std::string &nickname, const std::string &variablename, int numVars, const double *x)
Add control variable Adds a new control variable.
static vtkOSPRayMaterialLibrary * New()
void AddTexture(const std::string &nickname, const std::string &varname, vtkTexture *tex, const std::string &texturename="unnamedTexture", const std::string &filename="")
Add Texture Given a material nickname and a shader variable varname, set its data to a specific textu...
bool ReadTextureFileOrData(const std::string &texFilenameOrData, bool fromfile, const std::string &parentDir, vtkTexture *textr, std::string &textureName, std::string &textureFilename)
void RemoveAllShaderVariables(const std::string &nickname)
Remove all control variables of a specific material.
static const std::map< std::string, ParametersMap > & GetParametersDictionary()
Get the dictionary of all possible materials based on OSPRay documentation.
ParameterType
Lists all different parameter types.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool ReadFile(const char *FileName)
Reads the given file of materials and creates the in memory data structures needed to display objects...
void Fire()
Called to kick off events in all followers.
~vtkOSPRayMaterialLibrary() override
abstract base class for most VTK objects
Definition vtkObject.h:162
handles properties associated with a texture map
Definition vtkTexture.h:167