1 /****************************************************************************
2  *      session.cc: YafaRay Session control
3  *      This is part of the yafray package
4  *		Copyright (C) 2016 David Bluecame
5  * 		Session control and persistent objects between renders
6  *
7  *      This library is free software; you can redistribute it and/or
8  *      modify it under the terms of the GNU Lesser General Public
9  *      License as published by the Free Software Foundation; either
10  *      version 2.1 of the License, or (at your option) any later version.
11  *
12  *      This library is distributed in the hope that it will be useful,
13  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *      Lesser General Public License for more details.
16  *
17  *      You should have received a copy of the GNU Lesser General Public
18  *      License along with this library; if not, write to the Free Software
19  *      Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21 #include <core_api/session.h>
22 #include <yafraycore/photon.h>
23 
24 #if defined(_WIN32)
25 	#include <windows.h>
26 #endif
27 
28 __BEGIN_YAFRAY
29 
30 // Initialization of the master instance of yafLog
31 yafarayLog_t yafLog = yafarayLog_t();
32 
33 // Initialization of the master session instance
34 session_t session = session_t();
35 
session_t(const session_t &)36 session_t::session_t(const session_t&)	//We need to redefine the copy constructor to avoid trying to copy the mutex (not copiable). This copy constructor will not copy anything, but we only have one session object anyway so it should be ok.
37 {
38 }
39 
session_t()40 session_t::session_t()
41 {
42 	Y_VERBOSE << "Session:started" << yendl;
43 #if defined(_WIN32)
44 	SetConsoleOutputCP(65001);	//set Windows Console to UTF8 so the image path can be displayed correctly
45 #endif
46 	causticMap = new photonMap_t;
47 	causticMap->setName("Caustic Photon Map");
48 	diffuseMap = new photonMap_t;
49 	diffuseMap->setName("Diffuse Photon Map");
50 	radianceMap = new photonMap_t;
51 	radianceMap->setName("FG Radiance Photon Map");
52 }
53 
~session_t()54 session_t::~session_t()
55 {
56 	delete radianceMap;
57 	delete diffuseMap;
58 	delete causticMap;
59 	Y_VERBOSE << "Session: ended" << yendl;
60 }
61 
setStatusRenderStarted()62 void session_t::setStatusRenderStarted()
63 {
64 	mutx.lock();
65 
66 	mRenderInProgress = true;
67 	mRenderFinished = false;
68 	mRenderResumed = false;
69 	mRenderAborted = false;
70 	mTotalPasses = 0;
71 	mCurrentPass = 0;
72 	mCurrentPassPercent = 0.f;
73 
74 	mutx.unlock();
75 }
76 
setStatusRenderResumed()77 void session_t::setStatusRenderResumed()
78 {
79 	mutx.lock();
80 
81 	mRenderInProgress = true;
82 	mRenderFinished = false;
83 	mRenderResumed = true;
84 	mRenderAborted = false;
85 
86 	mutx.unlock();
87 }
88 
setStatusRenderFinished()89 void session_t::setStatusRenderFinished()
90 {
91 	mutx.lock();
92 
93 	mRenderInProgress = false;
94 	mRenderFinished = true;
95 
96 	mutx.unlock();
97 }
98 
setStatusRenderAborted()99 void session_t::setStatusRenderAborted()
100 {
101 	mutx.lock();
102 
103 	mRenderInProgress = false;
104 	mRenderAborted = true;
105 
106 	mutx.unlock();
107 }
108 
setStatusTotalPasses(int total_passes)109 void session_t::setStatusTotalPasses(int total_passes)
110 {
111 	mutx.lock();
112 	mTotalPasses = total_passes;
113 	mutx.unlock();
114 }
115 
setStatusCurrentPass(int current_pass)116 void session_t::setStatusCurrentPass(int current_pass)
117 {
118 	mutx.lock();
119 	mCurrentPass = current_pass;
120 	mutx.unlock();
121 }
122 
setStatusCurrentPassPercent(float current_pass_percent)123 void session_t::setStatusCurrentPassPercent(float current_pass_percent)
124 {
125 	mutx.lock();
126 	mCurrentPassPercent = current_pass_percent;
127 	mutx.unlock();
128 }
129 
setInteractive(bool interactive)130 void session_t::setInteractive(bool interactive)
131 {
132 	mutx.lock();
133 	mInteractive = interactive;
134 	mutx.unlock();
135 }
136 
setPathYafaRayXml(std::string path)137 void session_t::setPathYafaRayXml(std::string path)
138 {
139 	mutx.lock();
140 	mPathYafaRayXml = path;
141 	mutx.unlock();
142 }
143 
setPathImageOutput(std::string path)144 void session_t::setPathImageOutput(std::string path)
145 {
146 	mutx.lock();
147 	mPathImageOutput = path;
148 	mutx.unlock();
149 }
150 
renderInProgress()151 bool session_t::renderInProgress()
152 {
153 	return mRenderInProgress;
154 }
155 
renderResumed()156 bool session_t::renderResumed()
157 {
158 	return mRenderResumed;
159 }
160 
renderFinished()161 bool session_t::renderFinished()
162 {
163 	return mRenderFinished;
164 }
165 
renderAborted()166 bool session_t::renderAborted()
167 {
168 	return mRenderAborted;
169 }
170 
totalPasses()171 int session_t::totalPasses()
172 {
173 	return mTotalPasses;
174 }
175 
currentPass()176 int session_t::currentPass()
177 {
178 	return mCurrentPass;
179 }
180 
currentPassPercent()181 float session_t::currentPassPercent()
182 {
183 	return mCurrentPassPercent;
184 }
185 
isInteractive()186 bool session_t::isInteractive()
187 {
188 	return mInteractive;
189 }
190 
getPathYafaRayXml()191 std::string session_t::getPathYafaRayXml()
192 {
193 	return mPathYafaRayXml;
194 }
195 
getPathImageOutput()196 std::string session_t::getPathImageOutput()
197 {
198 	return mPathImageOutput;
199 }
200 
201 __END_YAFRAY
202 
203