VTK  9.6.20260626
vtkRenderMaterialLibrary.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
7
8#ifndef vtkRenderMaterialLibrary_h
9#define vtkRenderMaterialLibrary_h
10
11#include "vtkObject.h"
12#include "vtkRenderingCoreModule.h" // For export macro
13#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
14
15#include <initializer_list>
16#include <iosfwd>
17#include <map>
18#include <set>
19#include <string>
20#include <vector>
21
22VTK_ABI_NAMESPACE_BEGIN
23class vtkRenderMaterialLibraryInternals;
24class vtkTexture;
25struct TextureInfo;
26
27class VTKRENDERINGCORE_EXPORT VTK_MARSHALAUTO vtkRenderMaterialLibrary : public vtkObject
28{
29public:
32 void PrintSelf(ostream& os, vtkIndent indent) override;
33
48
49 using ParametersMap = std::map<std::string, ParameterType>;
50
57 bool ReadFile(const char* FileName);
58
64 bool ReadBuffer(const char* Buffer);
65
70 const std::set<std::string>& GetMaterialNames() const;
71
78 std::string LookupImplName(const std::string& nickname) const;
79
85 std::vector<std::string> GetDoubleShaderVariableList(const std::string& nickname) const;
86
93 virtual std::vector<double> GetDoubleShaderVariable(
94 const std::string& nickname, const std::string& varname) const;
95
101 std::vector<std::string> GetTextureList(const std::string& nickname) const;
102
109 vtkTexture* GetTexture(const std::string& nickname, const std::string& varname) const;
110
117 virtual const TextureInfo* GetTextureInfo(
118 const std::string& nickname, const std::string& varname) const;
119
126 std::string GetTextureName(const std::string& nickname, const std::string& varname) const;
127
134 std::string GetTextureFilename(const std::string& nickname, const std::string& varname) const;
135
142 virtual void AddMaterial(const std::string& nickname, const std::string& implname);
143
149 void RemoveMaterial(const std::string& nickname);
150
160 virtual void AddTexture(const std::string& nickname, const std::string& varname, vtkTexture* tex,
161 const std::string& texturename = "unnamedTexture", const std::string& filename = "");
162
171 virtual void AddShaderVariable(
172 const std::string& nickname, const std::string& variablename, int numVars, const double* x);
173
181 void AddShaderVariable(const std::string& nickname, const std::string& variablename,
182 const std::initializer_list<double>& data)
183 {
184 this->AddShaderVariable(nickname, variablename, static_cast<int>(data.size()), data.begin());
185 }
186
192 void RemoveShaderVariable(const std::string& nickname, const std::string& variablename);
193
198 void RemoveAllShaderVariables(const std::string& nickname);
199
205 void RemoveTexture(const std::string& nickname, const std::string& varname);
206
211 void RemoveAllTextures(const std::string& nickname);
212
219 const char* WriteBuffer(bool writeImageInline = true);
220
227 void WriteFile(const std::string& filename, bool writeImageInline = false);
228
229protected:
240 virtual bool ReadTextureFileOrData(const std::string& texFilenameOrData, bool fromfile,
241 const std::string& parentDir, vtkTexture* textr, std::string& textureName,
242 std::string& textureFilename);
243
244 bool InternalParse(const char* filename, bool fromfile);
245 virtual bool InternalParseJSON(const char* filename, bool fromfile, std::istream* doc);
246 bool InternalParseMTL(const char* filename, bool fromfile, std::istream* doc);
247
248 virtual const std::map<std::string, ParametersMap>& GetParametersDictionary() const;
249
255 std::string FilePathToTextureName(const std::string& path);
256
262 std::string Trim(const std::string& s);
263
266
267 virtual const char* GetFamilyName() const { return "Generic"; }
268 virtual const char* GetAcceptedFamilyName() const { return nullptr; }
269 std::string InternalGetImplName(const std::string& nickname) const;
270
271private:
273 void operator=(const vtkRenderMaterialLibrary&) = delete;
274
275 vtkRenderMaterialLibraryInternals* Internal;
276};
277
278VTK_ABI_NAMESPACE_END
279#endif
a simple class to control print indentation
Definition vtkIndent.h:108
virtual bool ReadTextureFileOrData(const std::string &texFilenameOrData, bool fromfile, const std::string &parentDir, vtkTexture *textr, std::string &textureName, std::string &textureFilename)
Load texture from file or inline data.
bool ReadBuffer(const char *Buffer)
Parse material data from a buffer in memory.
std::vector< std::string > GetTextureList(const std::string &nickname) const
Get the list of texture variables for a material.
void RemoveTexture(const std::string &nickname, const std::string &varname)
Remove a texture from a material.
virtual bool InternalParseJSON(const char *filename, bool fromfile, std::istream *doc)
virtual const std::map< std::string, ParametersMap > & GetParametersDictionary() const
std::string GetTextureName(const std::string &nickname, const std::string &varname) const
Get the registered name of a texture variable.
static vtkRenderMaterialLibrary * New()
std::vector< std::string > GetDoubleShaderVariableList(const std::string &nickname) const
Get the list of double-valued shader variables for a material.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual std::vector< double > GetDoubleShaderVariable(const std::string &nickname, const std::string &varname) const
Get the value of a double shader variable for a material.
virtual void AddMaterial(const std::string &nickname, const std::string &implname)
Add a new material to the library or replace an existing one.
void WriteFile(const std::string &filename, bool writeImageInline=false)
Write the material library to a file on disk.
void AddShaderVariable(const std::string &nickname, const std::string &variablename, const std::initializer_list< double > &data)
Add a shader variable from an initializer list of doubles.
void RemoveAllTextures(const std::string &nickname)
Remove all textures from a material.
std::string LookupImplName(const std::string &nickname) const
Look up the implementation name for a material nickname.
vtkTexture * GetTexture(const std::string &nickname, const std::string &varname) const
Get a texture object for a material variable.
std::string GetTextureFilename(const std::string &nickname, const std::string &varname) const
Get the filename path of a texture variable.
virtual const char * GetFamilyName() const
std::map< std::string, ParameterType > ParametersMap
std::string Trim(const std::string &s)
Remove leading and trailing whitespace from a string.
bool ReadFile(const char *FileName)
Read a material file from disk.
~vtkRenderMaterialLibrary() override
bool InternalParse(const char *filename, bool fromfile)
const char * WriteBuffer(bool writeImageInline=true)
Write the material library to a string buffer.
void RemoveMaterial(const std::string &nickname)
Remove a material from the library.
std::string FilePathToTextureName(const std::string &path)
Convert a file path to a texture name by extracting the filename without extension.
virtual void AddTexture(const std::string &nickname, const std::string &varname, vtkTexture *tex, const std::string &texturename="unnamedTexture", const std::string &filename="")
Add a texture to a material.
virtual const TextureInfo * GetTextureInfo(const std::string &nickname, const std::string &varname) const
Get texture information for a material variable.
void RemoveShaderVariable(const std::string &nickname, const std::string &variablename)
Remove a shader variable from a material.
virtual void AddShaderVariable(const std::string &nickname, const std::string &variablename, int numVars, const double *x)
Add a shader variable to a material.
std::string InternalGetImplName(const std::string &nickname) const
const std::set< std::string > & GetMaterialNames() const
Get the set of all material nicknames currently in the library.
void RemoveAllShaderVariables(const std::string &nickname)
Remove all shader variables from a material.
virtual const char * GetAcceptedFamilyName() const
bool InternalParseMTL(const char *filename, bool fromfile, std::istream *doc)
handles properties associated with a texture map
Definition vtkTexture.h:168
#define VTK_MARSHALAUTO