VTK  9.2.6
vtkOSPRayMaterialLibrary.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkOSPRayMaterialLibrary.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
28#ifndef vtkOSPRayMaterialLibrary_h
29#define vtkOSPRayMaterialLibrary_h
30
31#include "vtkObject.h"
32#include "vtkRenderingRayTracingModule.h" // For export macro
33
34#include <initializer_list> //for initializer_list!
35#include <map> //for map!
36#include <set> //for set!
37#include <string> //for string!
38#include <vector> //for vector!
39
40class vtkOSPRayMaterialLibraryInternals;
41class vtkTexture;
42struct TextureInfo;
43
44class VTKRENDERINGRAYTRACING_EXPORT vtkOSPRayMaterialLibrary : public vtkObject
45{
46public:
49 void PrintSelf(ostream& os, vtkIndent indent) override;
50
54 void Fire();
55
61 bool ReadFile(const char* FileName);
62
69 const char* WriteBuffer(bool writeImageInline = true);
70
77 void WriteFile(const std::string& filename, bool writeImageInline = false);
78
84 bool ReadBuffer(const char* Buffer);
85
89 std::set<std::string> GetMaterialNames();
90
94 std::string LookupImplName(const std::string& nickname);
95
99 std::vector<std::string> GetDoubleShaderVariableList(const std::string& nickname);
100
104 std::vector<double> GetDoubleShaderVariable(
105 const std::string& nickname, const std::string& varname);
106
110 std::vector<std::string> GetTextureList(const std::string& nickname);
111
115 vtkTexture* GetTexture(const std::string& nickname, const std::string& varname);
116
121 const TextureInfo* GetTextureInfo(const std::string& nickname, const std::string& varname);
122
127 std::string GetTextureName(const std::string& nickname, const std::string& varname);
128
132 std::string GetTextureFilename(const std::string& nickname, const std::string& varname);
133
139 void AddMaterial(const std::string& nickname, const std::string& implname);
140
146 void RemoveMaterial(const std::string& nickname);
147
158 void AddTexture(const std::string& nickname, const std::string& varname, vtkTexture* tex,
159 const std::string& texturename = "unnamedTexture", const std::string& filename = "");
160
166 void RemoveTexture(const std::string& nickname, const std::string& varname);
167
171 void RemoveAllTextures(const std::string& nickname);
172
179 const std::string& nickname, const std::string& variablename, int numVars, const double* x);
180 void AddShaderVariable(const std::string& nickname, const std::string& variablename,
181 const std::initializer_list<double>& data)
182 {
183 this->AddShaderVariable(nickname, variablename, static_cast<int>(data.size()), data.begin());
184 }
192 void RemoveShaderVariable(const std::string& nickname, const std::string& variablename);
193
197 void RemoveAllShaderVariables(const std::string& nickname);
198
202 enum class ParameterType : unsigned char
203 {
204 FLOAT,
205 NORMALIZED_FLOAT,
206 FLOAT_DATA,
207 VEC3,
208 COLOR_RGB,
209 BOOLEAN,
210 TEXTURE,
211 VEC2,
212 VEC4
213 };
214
215 using ParametersMap = std::map<std::string, ParameterType>;
216
220 static const std::map<std::string, ParametersMap>& GetParametersDictionary();
221
222protected:
225
226 bool InternalParse(const char* name, bool IsFile);
227 bool InternalParseJSON(const char* name, bool IsFile, std::istream* doc);
228 bool InternalParseMTL(const char* name, bool IsFile, std::istream* doc);
229 bool ReadTextureFileOrData(const std::string& texFilenameOrData, bool fromfile,
230 const std::string& parentDir, vtkTexture* textr, std::string& textureName,
231 std::string& textureFilename);
232
233private:
235 void operator=(const vtkOSPRayMaterialLibrary&) = delete;
236
237 vtkOSPRayMaterialLibraryInternals* Internal;
238};
239
240#endif
a simple class to control print indentation
Definition vtkIndent.h:40
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:63
handles properties associated with a texture map
Definition vtkTexture.h:69