#include #include #include "TRandom3.h" #include "JMarkov/JPhotonPath.hh" #include "JMarkov/JPhotonPathReader.hh" #include "JMarkov/JPhotonPathWriter.hh" using namespace JGEOMETRY3D ; using namespace JMARKOV ; using namespace std ; void printPolyline( JPolyline3D& pl ) { for( int i=0 ; i<(int)pl.size()-1 ; ++i ) cout << "(" << pl[i] << ")-" ; if( pl.size()>0 ) cout << "(" << pl.back() << ")" ; } /** * \file Usage example of JPhotonPathReader and JPhotonPathWriter Generates a number of random JPhotonPaths and writes them to a file. Then reads them back from the same file. **/ int main( int argc, char** argv ) { // initialization TRandom* ran = new TRandom3(0) ; const int npaths = 5 ; char fname[100] = "out.paths" ; // write some example paths to a file cout << "Writing some example paths to '" << fname << "'." << endl ; JMARKOV::JPhotonPathWriter writer ; writer.open(fname) ; for( int n=0 ; nInteger(6) ; // how often the photon scatters JPhotonPath path(nscat) ; // loop over the vertices for( JPhotonPath::iterator it=path.begin() ; it!=path.end() ; ++it ) { double x = ran->Integer(50) ; double y = ran->Integer(50) ; double z = ran->Integer(50) ; it->setPosition( JGEOMETRY3D::JVector3D(x,y,z) ) ; } // print the path printPolyline( path ) ; cout << endl ; // write the path writer.put(path) ; } writer.close() ; cout << endl ; // read paths from a file JMARKOV::JPhotonPathReader reader ; reader.open("out.paths") ; int nread = 0 ; JPhotonPath* p = NULL ; cout << "Reading file" << endl ; while( reader.hasNext() ) { p = reader.next() ; printPolyline( *p ) ; cout << endl ; ++nread ; } cout << "Done reading file. Read " << nread << " paths from it." << endl ; cout << endl ; cout << "Done!" << endl ; return 0 ; }