LuxCore  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
luxcore.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright 1998-2018 by authors (see AUTHORS.txt) *
3  * *
4  * This file is part of LuxCoreRender. *
5  * *
6  * Licensed under the Apache License, Version 2.0 (the "License"); *
7  * you may not use this file except in compliance with the License. *
8  * You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, software *
13  * distributed under the License is distributed on an "AS IS" BASIS, *
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.*
15  * See the License for the specific language governing permissions and *
16  * limitations under the License. *
17  ***************************************************************************/
18 
37 #ifndef _LUXCORE_H
38 #define _LUXCORE_H
39 
40 #include <cstddef>
41 #include <stdexcept>
42 #include <string>
43 
44 #include <luxcore/cfg.h>
45 #include <luxrays/utils/exportdefs.h>
48 
61 namespace luxcore {
62 
63 CPP_EXPORT CPP_API void (*LuxCore_LogHandler)(const char *msg); // LuxCore Log Handler
64 
65 #define LC_LOG(a) { if (luxcore::LuxCore_LogHandler) { std::stringstream _LUXCORE_LOG_LOCAL_SS; _LUXCORE_LOG_LOCAL_SS << a; luxcore::LuxCore_LogHandler(_LUXCORE_LOG_LOCAL_SS.str().c_str()); } }
66 
74 CPP_EXPORT CPP_API void Init(void (*LogHandler)(const char *) = NULL);
75 
83 CPP_EXPORT CPP_API void SetLogHandler(void (*LogHandler)(const char *) = NULL);
84 
92 CPP_EXPORT CPP_API void ParseLXS(const std::string &fileName, luxrays::Properties &renderConfig, luxrays::Properties &scene);
93 
104 CPP_EXPORT CPP_API void KernelCacheFill(const luxrays::Properties &config, void (*ProgressHandler)(const size_t, const size_t) = NULL);
105 
118 CPP_EXPORT CPP_API luxrays::Properties GetPlatformDesc();
119 
141 CPP_EXPORT CPP_API luxrays::Properties GetOpenCLDeviceDescs();
142 
143 class RenderSession;
144 class RenderState;
145 
150 CPP_EXPORT class CPP_API Film {
151 public:
155  typedef enum {
156  // This list must be aligned with slg::FilmOutputs::FilmOutputType
186  OUTPUT_CONVERGENCE
187  } FilmOutputType;
188 
192  typedef enum {
193  // This list must be aligned with slg::Film::FilmChannelType
194  CHANNEL_RADIANCE_PER_PIXEL_NORMALIZED = 1 << 0,
195  CHANNEL_RADIANCE_PER_SCREEN_NORMALIZED = 1 << 1,
196  CHANNEL_ALPHA = 1 << 2,
197  CHANNEL_IMAGEPIPELINE = 1 << 3,
198  CHANNEL_DEPTH = 1 << 4,
199  CHANNEL_POSITION = 1 << 5,
200  CHANNEL_GEOMETRY_NORMAL = 1 << 6,
201  CHANNEL_SHADING_NORMAL = 1 << 7,
202  CHANNEL_MATERIAL_ID = 1 << 8,
203  CHANNEL_DIRECT_DIFFUSE = 1 << 9,
204  CHANNEL_DIRECT_GLOSSY = 1 << 10,
205  CHANNEL_EMISSION = 1 << 11,
206  CHANNEL_INDIRECT_DIFFUSE = 1 << 12,
207  CHANNEL_INDIRECT_GLOSSY = 1 << 13,
208  CHANNEL_INDIRECT_SPECULAR = 1 << 14,
209  CHANNEL_MATERIAL_ID_MASK = 1 << 15,
210  CHANNEL_DIRECT_SHADOW_MASK = 1 << 16,
211  CHANNEL_INDIRECT_SHADOW_MASK = 1 << 17,
212  CHANNEL_UV = 1 << 18,
213  CHANNEL_RAYCOUNT = 1 << 19,
214  CHANNEL_BY_MATERIAL_ID = 1 << 20,
215  CHANNEL_IRRADIANCE = 1 << 21,
216  CHANNEL_OBJECT_ID = 1 << 22,
217  CHANNEL_OBJECT_ID_MASK = 1 << 23,
218  CHANNEL_BY_OBJECT_ID = 1 << 24,
219  CHANNEL_FRAMEBUFFER_MASK = 1 << 25,
220  CHANNEL_SAMPLECOUNT = 1 << 26,
221  CHANNEL_CONVERGENCE = 1 << 27
222  } FilmChannelType;
223 
224  virtual ~Film();
225 
232  static Film *Create(const std::string &fileName);
244  static Film *Create(const luxrays::Properties &props,
245  const bool hasPixelNormalizedChannel,
246  const bool hasScreenNormalizedChannel);
247 
253  virtual unsigned int GetWidth() const = 0;
259  virtual unsigned int GetHeight() const = 0;
266  virtual luxrays::Properties GetStats() const = 0;
275  virtual float GetFilmY(const unsigned int imagePipelineIndex = 0) const = 0;
279  virtual void Clear() = 0;
286  virtual void AddFilm(const Film &film) = 0;
299  virtual void AddFilm(const Film &film,
300  const unsigned int srcOffsetX, const unsigned int srcOffsetY,
301  const unsigned int srcWidth, const unsigned int srcHeight,
302  const unsigned int dstOffsetX, const unsigned int dstOffsetY) = 0;
307  virtual void SaveOutputs() const = 0;
308 
323  virtual void SaveOutput(const std::string &fileName, const FilmOutputType type, const luxrays::Properties &props) const = 0;
324 
330  virtual void SaveFilm(const std::string &fileName) const = 0;
331 
337  virtual double GetTotalSampleCount() const = 0;
345  virtual size_t GetOutputSize(const FilmOutputType type) const = 0;
353  virtual bool HasOutput(const FilmOutputType type) const = 0;
361  virtual unsigned int GetOutputCount(const FilmOutputType type) const = 0;
367  virtual unsigned int GetRadianceGroupCount() const = 0;
378  template<class T> void GetOutput(const FilmOutputType type, T *buffer, const unsigned int index = 0) {
379  throw std::runtime_error("Called Film::GetOutput() with wrong type");
380  }
388  virtual bool HasChannel(const FilmChannelType type) const = 0;
396  virtual unsigned int GetChannelCount(const FilmChannelType type) const = 0;
409  template<class T> const T *GetChannel(const FilmChannelType type, const unsigned int index = 0) {
410  throw std::runtime_error("Called Film::GetChannel() with wrong type");
411  }
419  virtual void Parse(const luxrays::Properties &props) = 0;
426  virtual void DeleteAllImagePipelines() = 0;
427 
428 protected:
429  virtual void GetOutputFloat(const FilmOutputType type, float *buffer, const unsigned int index) = 0;
430  virtual void GetOutputUInt(const FilmOutputType type, unsigned int *buffer, const unsigned int index) = 0;
431 
432  virtual const float *GetChannelFloat(const FilmChannelType type, const unsigned int index) = 0;
433  virtual const unsigned int *GetChannelUInt(const FilmChannelType type, const unsigned int index) = 0;
434 };
435 
436 template<> CPP_API void Film::GetOutput<float>(const FilmOutputType type, float *buffer, const unsigned int index);
437 template<> CPP_API void Film::GetOutput<unsigned int>(const FilmOutputType type, unsigned int *buffer, const unsigned int index);
438 template<> CPP_API const float *Film::GetChannel<float>(const FilmChannelType type, const unsigned int index);
439 template<> CPP_API const unsigned int *Film::GetChannel<unsigned int>(const FilmChannelType type, const unsigned int index);
440 
441 class Scene;
442 
446 CPP_EXPORT class CPP_API Camera {
447 public:
451  typedef enum {
452  // This list must be aligned with slg::Camera::CameraType
456  ENVIRONMENT
457  } CameraType;
458 
459  virtual ~Camera();
460 
466  virtual const CameraType GetType() const = 0;
473  virtual void Translate(const float x, const float y, const float z) const = 0;
480  virtual void TranslateLeft(const float t) const = 0;
487  virtual void TranslateRight(const float t) const = 0;
494  virtual void TranslateForward(const float t) const = 0;
501  virtual void TranslateBackward(const float t) const = 0;
502 
510  virtual void Rotate(const float angle, const float x, const float y, const float z) const = 0;
517  virtual void RotateLeft(const float angle) const = 0;
524  virtual void RotateRight(const float angle) const = 0;
531  virtual void RotateUp(const float angle) const = 0;
538  virtual void RotateDown(const float angle) const = 0;
539 };
540 
544 CPP_EXPORT class CPP_API Scene {
545 public:
549  typedef enum {
550  // This list must be aligned with slg::ImageMapStorage::ChannelSelectionType
558  RGB
559  } ChannelSelectionType;
563  typedef enum {
564  // This list must be aligned with slg::ImageMapStorage::WrapType
568  CLAMP
569  } WrapType;
573  typedef enum {
574  // This list must be aligned with slg::StrendsShape::TessellationType
578  TESSEL_SOLID_ADAPTIVE
579  } StrandsTessellationType;
580 
586  static Scene *Create(const float imageScale = 1.f);
593  static Scene *Create(const luxrays::Properties &props, const float imageScale = 1.f);
604  static Scene *Create(const std::string &fileName, const float imageScale = 1.f);
605 
606  virtual ~Scene();
607 
613  virtual void GetBBox(float min[3], float max[3]) const = 0;
620  virtual const Camera &GetCamera() const = 0;
634  template<class T> void DefineImageMap(const std::string &imgMapName,
635  T *pixels, const float gamma, const unsigned int channels,
636  const unsigned int width, const unsigned int height,
637  ChannelSelectionType selectionType = DEFAULT,
638  WrapType wrapType = REPEAT) {
639  throw std::runtime_error("Called Scene::DefineImageMap() with wrong type");
640  }
648  virtual bool IsImageMapDefined(const std::string &imgMapName) const = 0;
655  virtual void SetDeleteMeshData(const bool v) = 0;
676  virtual void DefineMesh(const std::string &meshName,
677  const long plyNbVerts, const long plyNbTris,
678  float *p, unsigned int *vi, float *n, float *uv,
679  float *cols, float *alphas) = 0;
688  virtual void SaveMesh(const std::string &meshName, const std::string &fileName) = 0;
704  virtual void DefineStrands(const std::string &shapeName, const luxrays::cyHairFile &strandsFile,
705  const StrandsTessellationType tesselType,
706  const unsigned int adaptiveMaxDepth, const float adaptiveError,
707  const unsigned int solidSideCount, const bool solidCapBottom, const bool solidCapTop,
708  const bool useCameraPosition) = 0;
716  virtual bool IsMeshDefined(const std::string &meshName) const = 0;
724  virtual bool IsTextureDefined(const std::string &texName) const = 0;
732  virtual bool IsMaterialDefined(const std::string &matName) const = 0;
738  virtual const unsigned int GetLightCount() const = 0;
744  virtual const unsigned int GetObjectCount() const = 0;
745 
755  virtual void Parse(const luxrays::Properties &props) = 0;
756 
764  virtual void DuplicateObject(const std::string &srcObjName, const std::string &dstObjName,
765  const float *transMat) = 0;
777  virtual void DuplicateObject(const std::string &srcObjName, const std::string &dstObjNamePrefix,
778  const unsigned int count, const float *transMat) = 0;
788  virtual void DuplicateObject(const std::string &srcObjName, const std::string &dstObjName,
789  const unsigned int steps, const float *times, const float *transMat) = 0;
804  virtual void DuplicateObject(const std::string &srcObjName, const std::string &dstObjNamePrefix,
805  const unsigned int count, const unsigned int steps, const float *times, const float *transMat) = 0;
812  virtual void UpdateObjectTransformation(const std::string &objName, const float *transMat) = 0;
819  virtual void UpdateObjectMaterial(const std::string &objName, const std::string &matName) = 0;
820 
826  virtual void DeleteObject(const std::string &objName) = 0;
827 
834  virtual void DeleteLight(const std::string &lightName) = 0;
835 
839  virtual void RemoveUnusedImageMaps() = 0;
843  virtual void RemoveUnusedTextures() = 0;
847  virtual void RemoveUnusedMaterials() = 0;
851  virtual void RemoveUnusedMeshes() = 0;
852 
858  virtual const luxrays::Properties &ToProperties() const = 0;
864  virtual void Save(const std::string &fileName) const = 0;
865 
869  static float *AllocVerticesBuffer(const unsigned int meshVertCount);
873  static unsigned int *AllocTrianglesBuffer(const unsigned int meshTriCount);
874 
875 protected:
876  virtual void DefineImageMapUChar(const std::string &imgMapName,
877  unsigned char *pixels, const float gamma, const unsigned int channels,
878  const unsigned int width, const unsigned int height,
879  ChannelSelectionType selectionType, WrapType wrapType) = 0;
880  virtual void DefineImageMapHalf(const std::string &imgMapName,
881  unsigned short *pixels, const float gamma, const unsigned int channels,
882  const unsigned int width, const unsigned int height,
883  ChannelSelectionType selectionType, WrapType wrapType) = 0;
884  virtual void DefineImageMapFloat(const std::string &imgMapName,
885  float *pixels, const float gamma, const unsigned int channels,
886  const unsigned int width, const unsigned int height,
887  ChannelSelectionType selectionType, WrapType wrapType) = 0;
888 };
889 
890 template<> void CPP_API Scene::DefineImageMap<unsigned char>(const std::string &imgMapName,
891  unsigned char *pixels, const float gamma, const unsigned int channels,
892  const unsigned int width, const unsigned int height,
893  Scene::ChannelSelectionType selectionType, Scene::WrapType wrapType);
894 template<> void CPP_API Scene::DefineImageMap<unsigned short>(const std::string &imgMapName,
895  unsigned short *pixels, const float gamma, const unsigned int channels,
896  const unsigned int width, const unsigned int height,
897  Scene::ChannelSelectionType selectionType, Scene::WrapType wrapType);
898 template<> void CPP_API Scene::DefineImageMap<float>(const std::string &imgMapName,
899  float *pixels, const float gamma, const unsigned int channels,
900  const unsigned int width, const unsigned int height,
901  Scene::ChannelSelectionType selectionType, Scene::WrapType wrapType);
902 
907 CPP_EXPORT class CPP_API RenderConfig {
908 public:
919  static RenderConfig *Create(const luxrays::Properties &props, Scene *scene = NULL);
926  static RenderConfig *Create(const std::string &fileName);
935  static RenderConfig *Create(const std::string &fileName, RenderState **startState, Film **startFilm);
936 
937  virtual ~RenderConfig();
938 
944  virtual const luxrays::Properties &GetProperties() const = 0;
951  virtual const luxrays::Property GetProperty(const std::string &name) const = 0;
952 
959  virtual const luxrays::Properties &ToProperties() const = 0;
960 
966  virtual Scene &GetScene() const = 0;
967 
974  virtual void Parse(const luxrays::Properties &props) = 0;
982  virtual void Delete(const std::string &prefix) = 0;
983 
998  virtual bool GetFilmSize(unsigned int *filmFullWidth, unsigned int *filmFullHeight,
999  unsigned int *filmSubRegion) const = 0;
1000 
1005  virtual void DeleteSceneOnExit() = 0;
1006 
1011  virtual void Save(const std::string &fileName) = 0;
1017  virtual void Export(const std::string &dirName) = 0;
1018 
1024  static const luxrays::Properties &GetDefaultProperties();
1025 };
1026 
1030 CPP_EXPORT class CPP_API RenderState {
1031 public:
1037  static RenderState *Create(const std::string &fileName);
1038  virtual ~RenderState();
1039 
1045  virtual void Save(const std::string &fileName) const = 0;
1046 };
1047 
1051 CPP_EXPORT class CPP_API RenderSession {
1052 public:
1063  static RenderSession *Create(const RenderConfig *config, RenderState *startState = NULL, Film *startFilm = NULL);
1064 
1073  static RenderSession *Create(const RenderConfig *config, const std::string &startStateFileName, const std::string &startFilmFileName);
1074 
1075  virtual ~RenderSession();
1076 
1083  virtual const RenderConfig &GetRenderConfig() const = 0;
1084 
1091  virtual RenderState *GetRenderState() = 0;
1092 
1096  virtual void Start() = 0;
1100  virtual void Stop() = 0;
1101 
1105  virtual bool IsStarted() const = 0;
1106 
1110  virtual void BeginSceneEdit() = 0;
1114  virtual void EndSceneEdit() = 0;
1115 
1119  virtual bool IsInSceneEdit() const = 0;
1120 
1124  virtual void Pause() = 0;
1125 
1129  virtual void Resume() = 0;
1130 
1134  virtual bool IsInPause() const = 0;
1135 
1139  virtual bool HasDone() const = 0;
1140 
1144  virtual void WaitForDone() const = 0;
1145 
1150  virtual void WaitNewFrame() = 0;
1151 
1157  virtual Film &GetFilm() = 0;
1158 
1164  virtual void UpdateStats() = 0;
1172  virtual const luxrays::Properties &GetStats() const = 0;
1173 
1180  virtual void Parse(const luxrays::Properties &props) = 0;
1181 
1189  virtual void SaveResumeFile(const std::string &fileName) = 0;
1190 };
1191 
1192 }
1193 
1194 #endif /* _LUXCORE_H */
CPP_EXPORT CPP_API void(* LuxCore_LogHandler)(const char *msg)
Definition: luxcore.h:63
Scene stores textures, materials and objects definitions.
Definition: luxcore.h:544
A generic container for values.
Definition: properties.h:153
RenderConfig stores all the configuration settings used to render a scene.
Definition: luxcore.h:907
void DefineImageMap(const std::string &imgMapName, T *pixels, const float gamma, const unsigned int channels, const unsigned int width, const unsigned int height, ChannelSelectionType selectionType=DEFAULT, WrapType wrapType=REPEAT)
Defines an image map (to be later used in textures, infinite lights, etc.). The memory allocated for ...
Definition: luxcore.h:634
void GetOutput(const FilmOutputType type, T *buffer, const unsigned int index=0)
Fills the buffer with a Film output channel.
Definition: luxcore.h:378
HAIR file class.
Definition: cyHairFile.h:75
RenderSession executes a rendering based on the RenderConfig provided.
Definition: luxcore.h:1051
Camera stores camera definitions.
Definition: luxcore.h:446
CPP_EXPORT CPP_API luxrays::Properties GetPlatformDesc()
Return a list of properties describing the features available. The properties currently supported are...
CPP_EXPORT CPP_API void ParseLXS(const std::string &fileName, luxrays::Properties &renderConfig, luxrays::Properties &scene)
Parses a scene described using LuxRender SDL (Scene Description Language).
CPP_EXPORT CPP_API luxrays::Properties GetOpenCLDeviceDescs()
Return the list of OpenCL devices available. For instance:
A container for multiple Property.
Definition: properties.h:502
ChannelSelectionType
Types of image map channel selection.
Definition: luxcore.h:549
FilmChannelType
Types of Film channel available.
Definition: luxcore.h:192
Film stores all the outputs of a rendering. It can be obtained from a RenderSession or as stand alone...
Definition: luxcore.h:150
CPP_EXPORT CPP_API void Init(void(*LogHandler)(const char *)=NULL)
Initializes LuxCore API. This function has to be called before anything else. This function is thread...
CPP_EXPORT CPP_API void SetLogHandler(void(*LogHandler)(const char *)=NULL)
Initializes LuxCore API. This function can be called if you want to update the log handler...
FilmOutputType
Types of Film channel available.
Definition: luxcore.h:155
CPP_EXPORT CPP_API void KernelCacheFill(const luxrays::Properties &config, void(*ProgressHandler)(const size_t, const size_t)=NULL)
File the OpenCL kernel cache with entries.
class for HAIR file type
WrapType
Types of image map wrap mode.
Definition: luxcore.h:563
const T * GetChannel(const FilmChannelType type, const unsigned int index=0)
Returns a pointer to the type of channel requested. The channel is not normalized (if it has a weight...
Definition: luxcore.h:409
RenderState is used to resume a rendering from a previous saved point.
Definition: luxcore.h:1030