VTK  9.1.0
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=========================================================================*/
25#ifndef vtkOSPRayMaterialLibrary_h
26#define vtkOSPRayMaterialLibrary_h
27
28#include "vtkObject.h"
29#include "vtkRenderingRayTracingModule.h" // For export macro
30
31#include <initializer_list> //for initializer_list!
32#include <map> //for map!
33#include <set> //for set!
34#include <string> //for string!
35#include <vector> //for vector!
36
37class vtkOSPRayMaterialLibraryInternals;
38class vtkTexture;
39struct TextureInfo;
40
41class VTKRENDERINGRAYTRACING_EXPORT vtkOSPRayMaterialLibrary : public vtkObject
42{
43public:
46 void PrintSelf(ostream& os, vtkIndent indent) override;
47
51 void Fire();
52
58 bool ReadFile(const char* FileName);
59
66 const char* WriteBuffer(bool writeImageInline = true);
67
74 void WriteFile(const std::string& filename, bool writeImageInline = false);
75
81 bool ReadBuffer(const char* Buffer);
82
86 std::set<std::string> GetMaterialNames();
87
92
96 std::vector<std::string> GetDoubleShaderVariableList(const std::string& nickname);
97
101 std::vector<double> GetDoubleShaderVariable(
102 const std::string& nickname, const std::string& varname);
103
107 std::vector<std::string> GetTextureList(const std::string& nickname);
108
112 vtkTexture* GetTexture(const std::string& nickname, const std::string& varname);
113
118 const TextureInfo* GetTextureInfo(const std::string& nickname, const std::string& varname);
119
124 std::string GetTextureName(const std::string& nickname, const std::string& varname);
125
129 std::string GetTextureFilename(const std::string& nickname, const std::string& varname);
130
136 void AddMaterial(const std::string& nickname, const std::string& implname);
137
143 void RemoveMaterial(const std::string& nickname);
144
155 void AddTexture(const std::string& nickname, const std::string& varname, vtkTexture* tex,
156 const std::string& texturename = "unnamedTexture", const std::string& filename = "");
157
163 void RemoveTexture(const std::string& nickname, const std::string& varname);
164
168 void RemoveAllTextures(const std::string& nickname);
169
176 const std::string& nickname, const std::string& variablename, int numVars, const double* x);
177 void AddShaderVariable(const std::string& nickname, const std::string& variablename,
178 const std::initializer_list<double>& data)
179 {
180 this->AddShaderVariable(nickname, variablename, static_cast<int>(data.size()), data.begin());
181 }
189 void RemoveShaderVariable(const std::string& nickname, const std::string& variablename);
190
195
199 enum class ParameterType : unsigned char
200 {
201 FLOAT,
202 NORMALIZED_FLOAT,
203 FLOAT_DATA,
204 VEC3,
205 COLOR_RGB,
206 BOOLEAN,
207 TEXTURE,
208 VEC2,
209 VEC4
210 };
211
212 using ParametersMap = std::map<std::string, ParameterType>;
213
217 static const std::map<std::string, ParametersMap>& GetParametersDictionary();
218
219protected:
222
223 bool InternalParse(const char* name, bool IsFile);
224 bool InternalParseJSON(const char* name, bool IsFile, std::istream* doc);
225 bool InternalParseMTL(const char* name, bool IsFile, std::istream* doc);
226 bool ReadTextureFileOrData(const std::string& texFilenameOrData, bool fromfile,
227 const std::string& parentDir, vtkTexture* textr, std::string& textureName,
228 std::string& textureFilename);
229
230private:
232 void operator=(const vtkOSPRayMaterialLibrary&) = delete;
233
234 vtkOSPRayMaterialLibraryInternals* Internal;
235};
236
237#endif
a simple class to control print indentation
Definition: vtkIndent.h:113
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:73
handles properties associated with a texture map
Definition: vtkTexture.h:175
@ name
Definition: vtkX3D.h:225
@ data
Definition: vtkX3D.h:321
@ string
Definition: vtkX3D.h:496