cpp_api/lux_api.h
author Omni Flux <omniflux@omniflux.com>
Mon Apr 16 21:20:04 2012 -0600 (13 months ago)
changeset 3650 0488d0d3ad0a
parent 2982 6f3e6edd5454
child 4364 943ddaf604c2
permissions -rw-r--r--
Add a first order filter to samples per second statistic to smooth the values
     1 /***************************************************************************
     2  *   Copyright (C) 1998-2009 by authors (see AUTHORS.txt )                 *
     3  *                                                                         *
     4  *   This file is part of LuxRender.                                       *
     5  *                                                                         *
     6  *   Lux Renderer is free software; you can redistribute it and/or modify  *
     7  *   it under the terms of the GNU General Public License as published by  *
     8  *   the Free Software Foundation; either version 3 of the License, or     *
     9  *   (at your option) any later version.                                   *
    10  *                                                                         *
    11  *   Lux Renderer is distributed in the hope that it will be useful,       *
    12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    14  *   GNU General Public License for more details.                          *
    15  *                                                                         *
    16  *   You should have received a copy of the GNU General Public License     *
    17  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
    18  *                                                                         *
    19  *   This project is based on PBRT ; see http://www.pbrt.org               *
    20  *   Lux Renderer website : http://www.luxrender.net                       *
    21  ***************************************************************************/
    22 
    23 #ifndef LUX_CPP_API_H	// LUX_API_H already used by Lux core/api.h
    24 #define LUX_CPP_API_H
    25 
    26 #include <vector>
    27 
    28 #include <boost/thread.hpp>
    29 
    30 // LuxRender core includes
    31 #include "context.h"
    32 #include "queryable.h"
    33 #include "paramset.h"
    34 
    35 // CPP API Includes
    36 #include "lux_instance.h"
    37 #include "lux_paramset.h"
    38 
    39 class lux_wrapped_context : public lux_instance {
    40 public:
    41 	lux_wrapped_context(const char* _name);
    42 	~lux_wrapped_context();
    43 
    44 	// context metadata
    45 	const char* version();
    46 	const char* getName();
    47 
    48 	// file parsing methods
    49 	bool parse(const char* filename, bool async);
    50 	bool parsePartial(const char* filename, bool async);
    51 	bool parseSuccessful();
    52 	
    53 	// rendering control
    54 	void pause();
    55 	void start();
    56 	void setHaltSamplesPerPixel(int haltspp, bool haveEnoughSamplesPerPixel, bool suspendThreadsWhenDone);
    57 	unsigned int addThread();
    58 	void removeThread();
    59 	void abort();
    60 	void wait();
    61 	void exit();
    62 	void cleanup();
    63 
    64 	// scene description methods
    65 	void accelerator(const char *aName, const lux_paramset* params);
    66 	void areaLightSource(const char *aName, const lux_paramset* params);
    67 	void attributeBegin();
    68 	void attributeEnd();
    69 	void camera(const char *cName, const lux_paramset* params);
    70 	void concatTransform(float tx[16]);
    71 	void coordinateSystem(const char *cnName);
    72 	void coordSysTransform(const char *cnName);
    73 	void exterior(const char *eName);
    74 	void film(const char *fName, const lux_paramset* params);
    75 	void identity();
    76 	void interior(const char *iName);
    77 	void lightGroup(const char *lName, const lux_paramset* params);
    78 	void lightSource(const char *lName, const lux_paramset* params);
    79 	void lookAt(float ex, float ey, float ez, float lx, float ly, float lz, float ux, float uy, float uz);
    80 	void makeNamedMaterial(const char *mName, const lux_paramset* params);
    81 	void makeNamedVolume(const char *vName, const char *vType, const lux_paramset* params);
    82 	void material(const char *mName, const lux_paramset* params);
    83 	void motionInstance(const char *mName, float startTime, float endTime, const char *toTransform);
    84 	void namedMaterial(const char *mName);
    85 	void objectBegin(const char *oName);
    86 	void objectEnd();
    87 	void objectInstance(const char *oName);
    88 	void pixelFilter(const char *pName, const lux_paramset* params);
    89 	void portalInstance(const char *pName);
    90 	void portalShape(const char *pName, const lux_paramset* params);
    91 	void renderer(const char *rName, const lux_paramset* params);
    92 	void reverseOrientation();
    93 	void rotate(float angle, float ax, float ay, float az);
    94 	void sampler(const char *sName, const lux_paramset* params);
    95 	void scale(float sx, float sy, float sz);
    96 	void shape(const char *sName, const lux_paramset* params);
    97 	void surfaceIntegrator(const char *sName, const lux_paramset* params);
    98 	void texture(const char *tName, const char *tVariant, const char *tType, const lux_paramset* params);
    99 	void transform(float tx[16]);
   100 	void transformBegin();
   101 	void transformEnd();
   102 	void translate(float dx, float dy, float dz);
   103 	void volume(const char *vName, const lux_paramset* params);	
   104 	void volumeIntegrator(const char *vName, const lux_paramset* params);
   105 	void worldBegin();
   106 	void worldEnd();
   107 
   108 	// I/O and imaging
   109 	void loadFLM(const char* fName);
   110 	void saveFLM(const char* fName);
   111 	void saveEXR(const char *filename, bool useHalfFloat, bool includeZBuffer, bool tonemapped);
   112 	void overrideResumeFLM(const char *fName);
   113 	void updateFramebuffer();
   114 	const unsigned char* framebuffer();
   115 	const float* floatFramebuffer();
   116 	const float* alphaBuffer();
   117 	const float* zBuffer();
   118 	const unsigned char* getHistogramImage(unsigned int width, unsigned int height, int options);
   119 
   120 	// Old-style parameter update interface
   121 	// To implement these requires exporting further luxComponent* symbols; In most cases the 
   122 	// new Queryable system should be preferred anyhow.
   123 	// void setParameterValue(luxComponent comp, luxComponentParameters param, double value, unsigned int index);
   124 	// double getParameterValue(luxComponent comp, luxComponentParameters param, unsigned int index);
   125 	// double getDefaultParameterValue(luxComponent comp, luxComponentParameters param, unsigned int index);
   126 	// void setStringParameterValue(luxComponent comp, luxComponentParameters param, const char* value, unsigned int index);
   127 	// unsigned int getStringParameterValue(luxComponent comp, luxComponentParameters param, char* dst, unsigned int dstlen, unsigned int index);
   128 	// unsigned int getDefaultStringParameterValue(luxComponent comp, luxComponentParameters param, char* dst, unsigned int dstlen, unsigned int index);
   129 
   130 	// Queryable interface
   131 	const char* getAttributes();
   132 	// TODO; this requires a get*Attribute()/set*Attribute() method for each data type.
   133 	// void* getAttribute(const char *objectName, const char *attributeName);
   134 	// void setAttribute(const char *objectName, const char *attributeName, void* value);
   135 
   136 	// Networking interface
   137 	void addServer(const char *sName);
   138 	void removeServer(const char *sName);
   139 	unsigned int getServerCount();
   140 	void updateFilmFromNetwork();
   141 	void setNetworkServerUpdateInterval(int updateInterval);
   142 	int getNetworkServerUpdateInterval();
   143 	// How to return data from this one? Export another data type?
   144 	// boost::python::tuple getRenderingServersStatus();
   145 
   146 	// Stats
   147 	double statistics(const char* statName);
   148 	const char* printableStatistics(const bool addTotal);	// Deprecated
   149 	void updateStatisticsWindow();
   150 
   151 	// Debugging interface
   152 	void enableDebugMode();
   153 	void disableRandomMode();
   154 	void setEpsilon(const float minValue, const float maxValue);
   155 
   156 private:
   157 	const char* name;
   158 	lux::Context* ctx;
   159 	std::vector<boost::thread*> render_threads;
   160 	void checkContext()
   161 	{
   162 		if (ctx == NULL)
   163 			ctx = new lux::Context(name);
   164 
   165 		lux::Context::SetActive(ctx);
   166 	}
   167 	void world_end_thread()
   168 	{
   169 		ctx->WorldEnd();
   170 	}
   171 };
   172 
   173 class lux_wrapped_paramset : public lux_paramset {
   174 public:
   175 	lux_wrapped_paramset();
   176 	~lux_wrapped_paramset();
   177 
   178 	lux::ParamSet* GetParamSet() { return ps; };
   179 
   180 	void AddFloat(const char*, const float *, u_int nItems = 1);
   181 	void AddInt(const char*, const int *, u_int nItems = 1);
   182 	void AddBool(const char*, const bool *, u_int nItems = 1);
   183 	void AddPoint(const char*, const float *, u_int nItems = 1);
   184 	void AddVector(const char*, const float *, u_int nItems = 1);
   185 	void AddNormal(const char*, const float *, u_int nItems = 1);
   186 	void AddRGBColor(const char*, const float *, u_int nItems = 1);
   187 	void AddString(const char*, const char*, u_int nItems = 1);
   188 	void AddTexture(const char*, const char*);
   189 
   190 private:
   191 	lux::ParamSet* ps;
   192 };
   193 
   194 // exported factory and cleanup functions
   195 CPP_EXPORT CPP_API lux_instance* CreateLuxInstance(const char* _name);
   196 CPP_EXPORT CPP_API void DestroyLuxInstance(lux_instance* inst);
   197 
   198 CPP_EXPORT CPP_API lux_paramset* CreateLuxParamSet();
   199 CPP_EXPORT CPP_API void DestroyLuxParamSet(lux_paramset* ps);
   200 
   201 #endif	// LUX_CPP_API_H