1 | /* ------------------------------------------------------------------------- |
---|
2 | * NPhoton.c |
---|
3 | * |
---|
4 | * --- |
---|
5 | * |
---|
6 | * Copyright (c) 2010 N.Sakaki, Y.Takizawa, Y.Kawasaki |
---|
7 | * All rights reserved. |
---|
8 | * $Id$ |
---|
9 | * ------------------------------------------------------------------------- |
---|
10 | */ |
---|
11 | #include <stdio.h> |
---|
12 | #include <stdlib.h> |
---|
13 | #include "Nphoton.hh" |
---|
14 | #include "EConst.hh" |
---|
15 | |
---|
16 | using namespace NTraceLens; |
---|
17 | |
---|
18 | int NTraceLens::StorePhotonHistory(NPhoton *p){ |
---|
19 | PhPosition *pos,*temp; |
---|
20 | |
---|
21 | pos=(PhPosition *)malloc(sizeof(PhPosition)); |
---|
22 | if(!pos) |
---|
23 | { |
---|
24 | #ifdef DEBUG |
---|
25 | /* stderr to be replaced with fplog */ |
---|
26 | fprintf(stderr,"memory allocation error in StorePhotonHistory()\n"); |
---|
27 | #endif |
---|
28 | return -1; |
---|
29 | } |
---|
30 | pos->x[0]=p->x[0]; |
---|
31 | pos->x[1]=p->x[1]; |
---|
32 | pos->x[2]=p->x[2]; |
---|
33 | pos->next=NULL; |
---|
34 | |
---|
35 | temp=p->history; |
---|
36 | if(temp) |
---|
37 | { |
---|
38 | while(temp->next){ |
---|
39 | temp=temp->next; |
---|
40 | } |
---|
41 | temp->next=pos; |
---|
42 | } |
---|
43 | else |
---|
44 | p->history=pos; |
---|
45 | p->id=0; |
---|
46 | |
---|
47 | return 0; |
---|
48 | } |
---|
49 | |
---|
50 | int NTraceLens::ShowPhotonHistory(NPhoton *p){ |
---|
51 | PhPosition *pos; |
---|
52 | |
---|
53 | if(p) |
---|
54 | { |
---|
55 | pos=p->history; |
---|
56 | while(pos){ |
---|
57 | printf("[HIST] %f %f %f\n",pos->x[0],pos->x[1],pos->x[2]); |
---|
58 | pos=pos->next; |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | return 0; |
---|
63 | } |
---|
64 | |
---|
65 | int NTraceLens::ClearPhotonHistory(NPhoton *p) |
---|
66 | { |
---|
67 | PhPosition *temp,*history; |
---|
68 | |
---|
69 | if(p) |
---|
70 | { |
---|
71 | history=p->history; |
---|
72 | |
---|
73 | while(history!=NULL) |
---|
74 | { |
---|
75 | temp=history->next; |
---|
76 | free(history); |
---|
77 | history=temp; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | return 0; |
---|
82 | } |
---|
83 | |
---|
84 | int NTraceLens::DeletePhoton(NPhoton *p) |
---|
85 | { |
---|
86 | |
---|
87 | if(p) |
---|
88 | { |
---|
89 | ClearPhotonHistory(p); |
---|
90 | free(p); |
---|
91 | } |
---|
92 | |
---|
93 | return 0; |
---|
94 | } |
---|
95 | |
---|
96 | int NTraceLens::SetPhotonDirection(NPhoton *p, double ex, double ey, double ez) |
---|
97 | { |
---|
98 | p->px[0]=ex; |
---|
99 | p->px[1]=ey; |
---|
100 | p->px[2]=ez; |
---|
101 | return 0; |
---|
102 | } |
---|
103 | |
---|
104 | int NTraceLens::SetPhotonPosition(NPhoton *p, double x, double y, double z, double t) |
---|
105 | { |
---|
106 | p->x[0]=x; |
---|
107 | p->x[1]=y; |
---|
108 | p->x[2]=z; |
---|
109 | return 0; |
---|
110 | } |
---|
111 | |
---|
112 | int NTraceLens::MovePhoton(NPhoton *p, double dist, double rindex) |
---|
113 | { |
---|
114 | int i; |
---|
115 | |
---|
116 | for(i=0;i<3;i++) |
---|
117 | p->x[i]+=p->px[i]*dist*rindex/EConst::Clight(); |
---|
118 | |
---|
119 | p->t+=dist*rindex/EConst::Clight(); |
---|
120 | return 0; |
---|
121 | } |
---|