#include <ApproxRaytracer.hpp>
Inheritance diagram for LOSR::ApproxRaytracer::
Public Methods | |
ApproxRaytracer (unsigned int inSize=0) | |
Construct an approximative raytracer of the size given as argument. More... | |
ApproxRaytracer (const LOSR::OpticalSystem &inOpticalSystem) | |
Construct an approximative raytracer using an optical system. More... | |
~ApproxRaytracer () | |
Destructor (do nothing). | |
ApproxRaytracer& | operator= (const LOSR::OpticalSystem &inOpticalSystem) |
Reinitialize the raytracer using the optical system given as argument. More... | |
void | initialize (const LOSR::OpticalSystem &inOpticalSystem) |
Initialize the raytracer using the optical system given as argument. More... | |
void | read (std::istream &ioIs=std::cin) |
Read a y-nu trace from a C++ input stream. More... | |
bool | trace (ApproxRaytracer::iterator inStartingPoint) |
Do the y-nu trace, backward and forward from the starting point, using actual ray values. More... | |
bool | trace (ApproxRaytracer::iterator inStartingPoint, long double inY, long double inU) |
Do the y-nu trace, backward and forward from the starting point, using ray values given. More... | |
bool | traceBackward (ApproxRaytracer::iterator inActualEntry, ApproxRaytracer::iterator inStopEntry) |
Do backward y-nu trace from actual entry to ending entry, using next entry values. More... | |
bool | traceForward (ApproxRaytracer::iterator inActualEntry, ApproxRaytracer::iterator inStopEntry) |
Do forward y-nu trace from actual entry to ending entry, using previous entry values. More... | |
void | write (std::ostream &ioOs=std::cout) const |
Write a y-nu trace into a C++ output stream. More... |
LOSR::ApproxRaytracer is an approximative raytracer table, using y-nu trace algorithms. It describes a table containing the entries of the y-nu table and the methods to do the traces, analysing it and manage it. An approximative raytracer usually take an optical system as input, before doing the ray trace. See chapter 5 of {\sl Elements of modern optical design}, Donald C. O'Shea, New York, Wiley, c1985, for details about the y-nu algorithm.
|
Construct an approximative raytracer of the size given as argument.
00196 : 00197 std::vector<Y_NU>(inSize) 00198 { } |
|
Construct an approximative raytracer using an optical system.
00206 : 00207 std::vector<Y_NU>(inOpticalSystem.size()) 00208 { 00209 initialize(inOpticalSystem); 00210 } |
|
Initialize the raytracer using the optical system given as argument.
00232 { 00233 resize(inOpticalSystem.size()); 00234 for(unsigned int i=0; i<size(); i++) (*this)[i] = inOpticalSystem[i]; 00235 } |
|
Reinitialize the raytracer using the optical system given as argument.
00220 { 00221 initialize(inOpticalSystem); 00222 return *this; 00223 } |
|
Read a y-nu trace from a C++ input stream.
00244 { 00245 char c1 ='\0', c2='\0'; 00246 unsigned int sz = 0; 00247 char buf[2048]; 00248 00249 // Extract and ignore the rest of lines starting with a # 00250 for(ioIs >> c1; c1=='#'; ioIs >> c1) ioIs.getline(buf,2048,'\n'); 00251 if(!ioIs) throw LOSR_RuntimeErrorM("Premature end of stream!"); 00252 00253 // Looking for the number of surface, between parenthesis 00254 ioIs >> sz >> c2; 00255 if((c1!='(') || (c2!=')')) throw LOSR_RuntimeErrorM("Bad file format!"); 00256 resize(sz); 00257 00258 // Read each surfaces from the stream 00259 for(unsigned int i=0; i<sz; i++) { 00260 if(!ioIs) throw LOSR_RuntimeErrorM("Premature end of stream!"); 00261 ioIs >> (*this)[i]; 00262 } 00263 } |
|
Do the y-nu trace, backward and forward from the starting point, using ray values given. NOTE: The value of U in an y-nu (approximative) ray trace is not the same than the U in a QU (exact) ray trace (U_ynu is equivalent to the tangent of U_QU).
00307 { 00308 #ifndef NDEBUG 00309 if(inStartingPoint == end()) 00310 throw LOSR_RuntimeErrorM("Cannot trace from the ending iterator of a raytracer!"); 00311 #endif // NDEBUG 00312 inStartingPoint->mY = inY; 00313 inStartingPoint->mU = inU; 00314 return trace(inStartingPoint); 00315 } |
|
Do the y-nu trace, backward and forward from the starting point, using actual ray values. It is assumed that the ray values of the actual entry (y and u) are correctly set.
00275 { 00276 #ifndef NDEBUG 00277 if(inStartingPoint == end()) 00278 throw LOSR_RuntimeErrorM("Cannot trace from the ending iterator of a raytracer!"); 00279 #endif // NDEBUG 00280 00281 // Evaluate NU 00282 inStartingPoint->mNU = inStartingPoint->mU * inStartingPoint->mN; 00283 00284 bool lResponse = true; 00285 if(inStartingPoint != begin()) { 00286 if(traceBackward(inStartingPoint-1,begin()) == false) lResponse = false; 00287 } 00288 if(inStartingPoint != end()-1) { 00289 if(traceForward(inStartingPoint+1,end()) == false) lResponse = false; 00290 } 00291 return lResponse; 00292 } |
|
Do backward y-nu trace from actual entry to ending entry, using next entry values. The actual y-nu entry ray values must be correctly set before the call.
00328 { 00329 #ifndef NDEBUG 00330 // Misc tests and assertions 00331 if(inActualEntry == end()) 00332 throw LOSR_RuntimeErrorM("Cannot trace the ending iterator of a raytracer!"); 00333 if(inActualEntry == end()-1) 00334 throw LOSR_RuntimeErrorM("Cannot backtrace the previous-to-ending iterator of a raytracer!"); 00335 if((inActualEntry == begin()) && (inActualEntry != inStopEntry)) 00336 throw LOSR_RuntimeErrorM("The stop entry iterator is not reacheable!"); 00337 #endif // NDEBUG 00338 00339 // Get an iterator to the next entry 00340 iterator lNextEntry = inActualEntry+1; 00341 00342 // Apply the y-nu equations 00343 inActualEntry->mNU = lNextEntry->mNU + 00344 ( lNextEntry->mY * lNextEntry->mC * ( lNextEntry->mN - inActualEntry->mN ) ); 00345 inActualEntry->mU = inActualEntry->mNU / inActualEntry->mN; 00346 inActualEntry->mY = lNextEntry->mY - 00347 ( inActualEntry->mNU * inActualEntry->mT / inActualEntry->mN ); 00348 00349 // Recursive call to do the y-nu trace 00350 bool lResponse = true; 00351 if(inActualEntry != inStopEntry) lResponse = traceBackward(inActualEntry-1,inStopEntry); 00352 if(std::fabs(inActualEntry->mY) > std::fabs(inActualEntry->mR)) return false; 00353 return lResponse; 00354 } |
|
Do forward y-nu trace from actual entry to ending entry, using previous entry values. The actual y-nu entry ray values must be correctly set before the call.
00367 { 00368 #ifndef NDEBUG 00369 // Misc tests and assertions 00370 if(inActualEntry == end()) 00371 throw LOSR_RuntimeErrorM("Cannot trace the ending iterator of a raytracer!"); 00372 if(inActualEntry == begin()) 00373 throw LOSR_RuntimeErrorM("Cannot forward trace the begining iterator of a raytracer!"); 00374 if((inActualEntry == end()-1) && (inActualEntry+1 != inStopEntry)) 00375 throw LOSR_RuntimeErrorM("The stop entry iterator is not reacheable!"); 00376 #endif // NDEBUG 00377 00378 // Get an iterator to the previous entry 00379 iterator lPreviousEntry = inActualEntry-1; 00380 00381 // Apply the y-nu equations 00382 inActualEntry->mY = lPreviousEntry->mY + 00383 ( lPreviousEntry->mT * ( lPreviousEntry->mNU / lPreviousEntry->mN ) ); 00384 inActualEntry->mNU = lPreviousEntry->mNU - 00385 ( inActualEntry->mY * inActualEntry->mC * ( inActualEntry->mN - lPreviousEntry->mN ) ); 00386 inActualEntry->mU = inActualEntry->mNU / inActualEntry->mN; 00387 00388 // Recursive call to do the y-nu trace 00389 bool lResponse = true; 00390 if(inActualEntry+1 != inStopEntry) lResponse = traceForward(inActualEntry+1,inStopEntry); 00391 if(std::fabs(inActualEntry->mY) > std::fabs(inActualEntry->mR)) return false; 00392 return lResponse; 00393 } |
|
Write a y-nu trace into a C++ output stream.
00402 { 00403 ioOs << '(' << size() << ')' << std::endl; 00404 for(unsigned int i=0; i<size(); i++) { 00405 ioOs << (*this)[i]; 00406 } 00407 } |