Jpp
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JMarkov
JPhotonPathIO.cc
Go to the documentation of this file.
1
#include <iostream>
2
#include <fstream>
3
4
#include "TRandom3.h"
5
6
#include "
JMarkov/JPhotonPath.hh
"
7
#include "
JMarkov/JPhotonPathReader.hh
"
8
#include "
JMarkov/JPhotonPathWriter.hh
"
9
using namespace
JGEOMETRY3D ;
10
using namespace
JMARKOV ;
11
using namespace
std ;
12
13
void
printPolyline
(
JPolyline3D
& pl ) {
14
for
(
int
i=0 ; i<(int)pl.size()-1 ; ++i )
15
cout <<
"("
<< pl[i] <<
")-"
;
16
if
( pl.size()>0 ) cout <<
"("
<< pl.back() <<
")"
;
17
}
18
19
/**
20
* \file Usage example of JPhotonPathReader and JPhotonPathWriter
21
22
Generates a number of random JPhotonPaths and writes them to a file.
23
Then reads them back from the same file.
24
**/
25
int
main
(
int
argc,
char
** argv ) {
26
// initialization
27
TRandom* ran =
new
TRandom3(0) ;
28
const
int
npaths = 5 ;
29
char
fname[100] =
"out.paths"
;
30
31
// write some example paths to a file
32
cout <<
"Writing some example paths to '"
<< fname <<
"'."
<< endl ;
33
34
JMARKOV::JPhotonPathWriter
writer ;
35
writer.
open
(fname) ;
36
for
(
int
n
=0 ;
n
<npaths ; ++
n
) {
37
// create path
38
int
nscat = ran->Integer(6) ;
// how often the photon scatters
39
JPhotonPath
path
(nscat) ;
40
// loop over the vertices
41
for
( JPhotonPath::iterator it=path.begin() ; it!=path.end() ; ++it ) {
42
double
x = ran->Integer(50) ;
43
double
y = ran->Integer(50) ;
44
double
z = ran->Integer(50) ;
45
it->setPosition(
JGEOMETRY3D::JVector3D
(x,y,z) ) ;
46
}
47
// print the path
48
printPolyline
( path ) ;
49
cout << endl ;
50
// write the path
51
writer.
put
(path) ;
52
}
53
writer.
close
() ;
54
cout << endl ;
55
56
// read paths from a file
57
JMARKOV::JPhotonPathReader
reader ;
58
reader.
open
(
"out.paths"
) ;
59
60
int
nread = 0 ;
61
JPhotonPath
* p = NULL ;
62
cout <<
"Reading file"
<< endl ;
63
while
( reader.
hasNext
() ) {
64
p = reader.
next
() ;
65
printPolyline
( *p ) ;
66
cout << endl ;
67
++nread ;
68
}
69
70
cout <<
"Done reading file. Read "
<< nread <<
" paths from it."
<< endl ;
71
cout << endl ;
72
cout <<
"Done!"
<< endl ;
73
74
return
0 ;
75
}
JMARKOV::JPhotonPathReader
Definition:
JPhotonPathReader.hh:16
JLANG::JAccessibleBinaryOutputStream::open
virtual void open(const char *file_name) override
Open file.
Definition:
JAccessibleBinaryStream.hh:92
JLANG::JAccessibleBinaryInputStream::open
virtual void open(const char *file_name) override
Open file.
Definition:
JAccessibleBinaryStream.hh:52
JLANG::JAbstractObjectIterator::hasNext
virtual bool hasNext() override
Check availability of next element.
Definition:
JAbstractObjectIterator.hh:56
JLANG::JAbstractObjectIterator::next
virtual const pointer_type & next() override
Get next element.
Definition:
JAbstractObjectIterator.hh:71
JMARKOV::JPhotonPath
A photon path.
Definition:
JPhotonPath.hh:38
JMARKOV::JPhotonPathWriter
Definition:
JPhotonPathWriter.hh:16
path
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
Definition:
software/JDataWriter/JDataWriter.sh:143
JGEOMETRY3D::JVector3D
Data structure for vector in three dimensions.
Definition:
JVector3D.hh:34
JPhotonPathWriter.hh
JIO::JWriterObjectOutput::put
virtual bool put(const T &object) override
Object output.
Definition:
JWriterObjectOutput.hh:50
n
alias put_queue eval echo n
Definition:
qlib.csh:19
JLANG::JAccessibleOutputStream::close
virtual void close()
Close file.
Definition:
JAccessibleStream.hh:142
JPhotonPath.hh
JGEOMETRY3D::JPolyline3D
Data structure for polyline in three dimensions.
Definition:
JPolyline3D.hh:25
JPhotonPathReader.hh
printPolyline
void printPolyline(const JPolyline3D &pl)
Definition:
JPolyline3D.cc:8
main
int main(int argc, char *argv[])
Definition:
Main.cpp:15
Generated by
1.8.5