81 | | We could in principal continue to raise the sample_res but it gets computationally expensive... A better approach would be to sample along each ray at some interval... Then the sampling is pixel based instead of volume based - and should reduce the aliasing... |
| 81 | We could in principal continue to raise the sample_res but it gets computationally expensive... A better approach would be to sample along each ray at some interval... Then the sampling is pixel based instead of volume based - and should reduce the aliasing... Or we could calculate the optical depth across each cell for each ray that intersects the cell. Given that our mesh is cartesian this is not as hard as it might sound. |
| 82 | |
| 83 | * Find what rays could intersect the cell |
| 84 | * For each ray find what which two faces the ray intersects and the corresponding points of entry and exit |
| 85 | * The contribution to the pixel will be the the value of the cell times the distance between those points. |
| 86 | |
| 87 | {{{ |
| 88 | |
| 89 | SUBROUTINE BinCell(Camera, pos, dx, data, rho) |
| 90 | TYPE(CameraDef), POINTER :: Camera |
| 91 | REAL(KIND=qPREC) :: pos(3),xpos(3) |
| 92 | REAL(KIND=qPREC) :: dx, ddx, xbounds(3,2), my_pixel(2) |
| 93 | REAL(KIND=qPREC), DIMENSION(:,:) :: data |
| 94 | REAL(KIND=qPREC) :: rho,a,intersection(6,3), ray(3), max_distance |
| 95 | INTEGER :: ipos(2), sample_res, i, j, k, npoints, min_pixels(2), max_pixels(2), pixel(2), dim, odim(2), edge |
| 96 | xbounds(:,1)=(pos-half*dx) |
| 97 | xbounds(:,2)=(pos+half*dx) |
| 98 | min_pixels=huge(min_pixels(1)) |
| 99 | max_pixels=0 |
| 100 | DO i=1,2 |
| 101 | DO j=1,2 |
| 102 | DO k=1,2 |
| 103 | my_pixel=GetPixel(Camera, (/xbounds(1,i), xbounds(2,j), xbounds(3,k)/))*shape(data)+half |
| 104 | min_pixels=max(1,min(min_pixels, floor(my_pixel))) |
| 105 | max_pixels=min(shape(data),max(max_pixels, ceiling(my_pixel))) |
| 106 | END DO |
| 107 | END DO |
| 108 | END DO |
| 109 | DO i=min_pixels(1), max_pixels(1) |
| 110 | DO j=min_pixels(2), max_pixels(2) |
| 111 | pixel=(/i,j/)-half |
| 112 | Ray=GetRay(Camera, REAL(pixel,KIND=qPREC)/REAL(shape(data), KIND=qPREC)) |
| 113 | npoints=0 |
| 114 | DO dim=1,3 |
| 115 | DO edge=1,2 |
| 116 | ! Camera%pos(dim)+a*ray(dim)=xbounds(dim,edge) |
| 117 | a=(xbounds(dim,edge)-Camera%pos(dim))/ray(dim) |
| 118 | xpos=Camera%pos+a*ray |
| 119 | odim=modulo((/dim,dim+1/),3)+1 |
| 120 | IF (ALL(xpos(odim) >= xbounds(odim,1) .AND. xpos(odim) <= xbounds(odim,2))) THEN |
| 121 | npoints=npoints+1 |
| 122 | intersection(npoints,:)=xpos |
| 123 | END IF |
| 124 | END DO |
| 125 | END DO |
| 126 | IF (npoints == 0) CYCLE |
| 127 | max_distance=0d0 |
| 128 | DO k=1,npoints |
| 129 | max_distance=max(max_distance, sqrt(sum((intersection(k,:)-intersection(1,:))**2))) |
| 130 | END DO |
| 131 | data(i,j)=data(i,j)+rho*max_distance |
| 132 | END DO |
| 133 | END DO |
| 134 | END SUBROUTINE BinCell |
| 135 | }}} |