22
X-RAY AND MIP VOLUME RENDERING FAYAN TAO (1509853F-II20-0019) 1. Introduction Ray casting[1] is an image-order direct volume rendering algorithm, which uses straight- forward numerical evaluation of the volume rendering integral. For each pixel of the image, a single ray is cast into the scene. At equi-spaced intervals along the ray, the discrete volume data are resampled, usually using trilinear interpolation as reconstruction filter. That is, for each resampling location, the scalar values of eight neighboring voxels are weighted according to their distance to the actual location for which a data value is needed. After resampling, the scalar data value is mapped to optical properties via a lookup table, which yields an RGBA quadruplet that subsumes the corresponding emission and absorption coefficients for this location. The solution of the volume rendering integral is then approximated via alpha blending in either front-to-back or back-to-front order, where usually the former is used in ray casting. In this project, we just consider X-Ray and maximum intensity projection (MIP) volume rendering. And the scalar values are grey values. 2. Design outline We follow that two main algorithms about X-Ray and MIP provided in section 2 to implement X-Ray and MIP volume rendering, respectively, which is based on orthographic projection. Rotation and scaling the image are implemented in this project. 2.1. Underlying theorems–Continuous forms. X-Ray projection In order to get the intensity I i,j of the image on the location(i, j ), we should accumulate (integrate) the volumetric function f (x, y) along the ray in the continuous forms. I i,j = Z L 0 f (P i,j + t · r i,j )dt MIP To find the maximum of f (x, y) along the ray and write it to image location(i, j ), we employ following formula. I i,j = max(f (P i,j + t · r i,j )) 2.2. Underlying theorems–Discrete forms. Since volumetric integrals that cannot be solved in closed form (i.e. analytically) and therefore must be approximated by discrete rays. X-Ray projection 1

TAO Fayan_X-Ray and MIP volume rendering

Embed Size (px)

Citation preview

Page 1: TAO Fayan_X-Ray and MIP volume rendering

X-RAY AND MIP VOLUME RENDERING

FAYAN TAO (1509853F-II20-0019)

1. Introduction

Ray casting[1] is an image-order direct volume rendering algorithm, which uses straight-forward numerical evaluation of the volume rendering integral. For each pixel of the image,a single ray is cast into the scene. At equi-spaced intervals along the ray, the discrete volumedata are resampled, usually using trilinear interpolation as reconstruction filter. That is, foreach resampling location, the scalar values of eight neighboring voxels are weighted accordingto their distance to the actual location for which a data value is needed. After resampling,the scalar data value is mapped to optical properties via a lookup table, which yields anRGBA quadruplet that subsumes the corresponding emission and absorption coefficients forthis location. The solution of the volume rendering integral is then approximated via alphablending in either front-to-back or back-to-front order, where usually the former is used inray casting.

In this project, we just consider X-Ray and maximum intensity projection (MIP) volumerendering. And the scalar values are grey values.

2. Design outline

We follow that two main algorithms about X-Ray and MIP provided in section 2 toimplement X-Ray and MIP volume rendering, respectively, which is based on orthographicprojection. Rotation and scaling the image are implemented in this project.

2.1. Underlying theorems–Continuous forms. •X-Ray projectionIn order to get the intensity Ii,j of the image on the location(i, j), we should accumulate

(integrate) the volumetric function f(x, y) along the ray in the continuous forms.

Ii,j =

∫ L

0

f(Pi,j + t · ri,j)dt

•MIPTo find the maximum of f(x, y) along the ray and write it to image location(i, j), we

employ following formula.

Ii,j = max(f(Pi,j + t · ri,j))

2.2. Underlying theorems–Discrete forms. Since volumetric integrals that cannot besolved in closed form (i.e. analytically) and therefore must be approximated by discrete rays.•X-Ray projection

1

Page 2: TAO Fayan_X-Ray and MIP volume rendering

2 FAYAN TAO (1509853F-II20-0019)

Ii,j =

L/4t∑k=0

f(Pi,j + k · 4k · ri,j) · 4t

Sample the volumetric function f(x, y) at equi-spaced distances 4t along the ray accu-mulate the samples and write the resulting intensity Ii,j to the image at location (i, j).•MIP

Ii,j = max(f(Pi,j + k · 4k · ri,j))(0 ≤ k ≤ L/4 k)

Find the maximum of f(x, y) along the ray and write it to image location(i, j).

2.3. Trilinear interpolation. As the ray sample points do not always fall onto the knowngrid points, in fact, most often they fall somewhere inbetween. So we need to estimate thevalues of the ray samples from the existing grid points. In this project, we choose trilinearinterpolation to calculate related values of samples.

2.4. Volume bounding box. In order to approximate the volume rendering integral byusing a volume bounding box, which has the front-to-back order, we limit volume data inthe volume bounding box. The detailed key code of this part is shown in the followingsection 2.

2.5. Scaling. We try to control the image size by changing 4i and 4j, where 4i = HNi−1 ,

4j = WNj−1 , (0 ≤ i < Ni, 0 ≤ j < Nj); W,H is the screen width and hight in world

coordinates; Ni, Nj is the image dimensions in pixels.We set a variable k, let k · 4i, k · 4j as the new value of 4i and 4j, respectively.if 0 < k < 1, then the image will be enlarged, while k > 1, the image will become small.Please refer to X-Ray Rendering Algorithm and MIP Rendering Algorithm in section 2

for a better understanding of 4i and 4j.

2.6. Rotation. A new position of the image plane can be defined in terms of three rotationangle θ, α, β with respect to x, y, z axes and X, Y andZ rotation matrix.

X =

1 0 00 cosθ sinθ0 −sinθ cosθ

, Y =

cosα 0 sinα0 1 0

−sinα 0 cosα

, Z =

cosβ sinβ 0−sinβ cosβ 0

0 0 1

Assuming the original view vector is u = [0, 0, 1], then the new view vector new u becomes:

new u = u ·X · Y · ZIn order to implement the function of rotation, we try to rotate the view direction vector

ray by means of rotation matrix X, Y andZ with rotation angle θ, α, β, respectively.In this project, we also use another way to rotate the image at any angle. The main idea

is to make the volume cube fixed, and rotate the view direction ray at any angle. the startpoint(eye) of the ray is controlled by mouse. We regard the point that mouse point to inthe image plane as the start point of the ray. The ray always pointing to the center (p0) ofcube. In order to get the height and width of image plane, we compute the length of eachbody diagonal’s projection of that cube(bounding box), then choose the largest two as theheight and width. Besides, to get the orthonormal vector v and u on the image plane, wechoose two points c and d on cube, find two parallel vectors of ray (n1 and n2), where run

Page 3: TAO Fayan_X-Ray and MIP volume rendering

X-RAY AND MIP VOLUME RENDERING 3

through two points m and n on image plane and two points c and d on cube. In this case,v = (eye.x−m.x, eye.y −m.y, eye.z −m.z), u = (eye.x− n.x, eye.y − n.y, eye.z − n.z).

This part is shown as following codes.

Page 4: TAO Fayan_X-Ray and MIP volume rendering

4 FAYAN TAO (1509853F-II20-0019)

1 // f o r the menu ”XRay” to d i sp l ay XRay

2 i n t CVolumeRender : : XRay( f l o a t s t epS i z e )

3 {4 // eye i s the s t a r t po int o f ray on image plane

5 th i s−>s t epS i z e = s t epS i z e ;

6 th i s−>ray = th i s−>pointO − th i s−>eye ;

7 f l o a t mRay = th i s−>ray . Magnitude ( ) ;

8 th i s−>ray . Normalize ( ) ;

9

10 th i s−>IntersectRaywithVolumeBoundingBox ( th i s−>eye ) ;

11 // vec to r c , d i s p a r a l l e l to ray

12 f l o a t xc , yc , zc ;

13 xc = th i s−>eye .X( ) − th i s−>pointO .X( ) + th i s−>voxelWidth ;

14 yc = th i s−>eye .Y( ) − th i s−>pointO .Y( ) + 0 ;

15 zc = th i s−>eye . Z ( ) − th i s−>pointO .Z( ) + th i s−>voxelDepth ;

16 Vector3 c ( xc , yc , zc ) ;

17 f l o a t xd , yd , zd ;

18 xd = th i s−>eye .X( ) − th i s−>pointO .X( ) + 0 ;

19 yd = th i s−>eye .Y( ) − th i s−>pointO .Y( ) + 0 ;

20 zd = th i s−>eye . Z ( ) − th i s−>pointO .Z( ) + th i s−>voxelDepth ;

21 Vector3 d(xd , yd , zd ) ;

22 // u , v are on the image plane , and u , v , ray are orthnormal image plane ve c t o r s

23 Vector3 u , v ;

24 u = th i s−>eye − c ;

25 v = th i s−>eye − d ;

26 // four body d iagona l s on cube : dig1 , dig2 , dig3 , d ig4 ; e i gh t po in t s on cube :

27 //v00 , v100 , v101 , v001 , v010 , v110 , v111 , v011//

28 Vector3 dig1 , dig2 , dig3 , d ig4 ;

29 Vector3 v000 (0 , 0 , 0 ) ;

30 Vector3 v100 ( th i s−>voxelWidth , 0 , 0 ) ;

31 Vector3 v101 ( th i s−>voxelWidth , 0 , th i s−>voxelDepth ) ;

32 Vector3 v001 (0 , 0 , th i s−>voxelDepth ) ;

33 Vector3 v010 (0 , th i s−>voxelHeigth , 0 ) ;

34 Vector3 v110 ( th i s−>voxelWidth , th i s−>voxelHeigth , 0 ) ;

35 Vector3 v111 ( th i s−>voxelWidth , th i s−>voxelHeigth , th i s−>voxelDepth ) ;

36 Vector3 v011 (0 , th i s−>voxelHeigth , th i s−>voxelDepth ) ;

37 dig1 = v111 − v000 ;

38 dig2 = v011 − v100 ;

39 dig3 = v010 − v101 ;

40 dig4 = v110 − v001 ;

41 // the l ength o f each body d iagona l //

42 f l o a t mDig1 = dig1 . Magnitude ( ) ;

43 f l o a t mDig2 = dig2 . Magnitude ( ) ;

44 f l o a t mDig3 = dig3 . Magnitude ( ) ;

45 f l o a t mDig4 = dig4 . Magnitude ( ) ;

46 // compute the p r o j e c t i o n l ength o f each body d iagona l on image plane //

47 f l o a t r1 = fabs ( th i s−>ray∗dig1 ) / ( dig1 . Magnitude ( )∗ th i s−>ray . Magnitude ( ) ) ;

48 f l o a t r2 = fabs ( th i s−>ray∗dig2 ) / ( dig2 . Magnitude ( )∗ th i s−>ray . Magnitude ( ) ) ;

49 f l o a t r3 = fabs ( th i s−>ray∗dig3 ) / ( dig3 . Magnitude ( )∗ th i s−>ray . Magnitude ( ) ) ;

50 f l o a t r4 = fabs ( th i s−>ray∗dig4 ) / ( dig4 . Magnitude ( )∗ th i s−>ray . Magnitude ( ) ) ;

51 f l o a t ang1 = acos ( r1 ) ;

52 f l o a t ang2 = acos ( r2 ) ;

53 f l o a t ang3 = acos ( r3 ) ;

54 f l o a t ang4 = acos ( r4 ) ;

55 f l o a t l ength1 = dig1 . Magnitude ( )∗ cos (PI / 2 − ang1 ) ;

56 f l o a t l ength2 = dig2 . Magnitude ( )∗ cos (PI / 2 − ang2 ) ;

57 f l o a t l ength3 = dig3 . Magnitude ( )∗ cos (PI / 2 − ang3 ) ;

58 f l o a t l ength4 = dig4 . Magnitude ( )∗ cos (PI / 2 − ang4 ) ;

59 f l o a t lengthA [ 4 ] = { l ength1 , l ength2 , l ength3 , l ength4 } ;60 std : : s o r t ( lengthA , lengthA + 4 ) ;

61 // the he ight and width o f image plane //

62 th i s−>screenWidth = lengthA [ 2 ] + 1 ;

63 th i s−>sc reenHe ight = lengthA [ 3 ] + 1 ;

64 th i s−>I n i t S c r e en (&CVolumeRender : : xrayLoop ) ;

65 re turn 0 ;

66

67 }

Page 5: TAO Fayan_X-Ray and MIP volume rendering

X-RAY AND MIP VOLUME RENDERING 5

3. Algorithms and key code fragments

In this section, we will show details about X-Ray and MIP Rending Algorithms. Besides,we will also provide the related key codes fragments.

3.1. X-Ray and MIP Rendering Algorithms. Following two tables shows algorithmsabout X-Ray and MIP volume rendering.

X-Ray Rendering AlgorithmRenderXRay(volume V, int stepSize, Image I)ray = v×u

|v×u| ; \∗ for orthographic projection ∗\\ ∗ ray: the view direction vector; v, uray: orthonormal image plane vectors ∗\4i = H

Ni−1 , 4j = WNj−1 (0 ≤ i < Ni, 0 ≤ j < Nj);

\ ∗W,H: screen width, hight in world coordinates; Ni, Nj: image dimensions in pixels ∗\for each image pixel(i, j)\∗ scan the image row by row, column by column: ∗\P (i, j) = P (0, 0) + i · v · 4i+ j · u · 4j;\ ∗ P (i, j): Location of image pixel(i, j) in the world space, which is a point on the ray direction ∗\\ ∗ P (0, 0): image origin in world space ∗\sum = 0;IntersectRayWithV olumeBoundingBox(V, ray, t front, t back);for(t = t front; t <= t back; t+ = stepSize)sampleLoc = P (i, j) + t · ray;intV al = Interpolate(V, sampleLoc);sum+ = intV al · stepSize;I(i, j) = sum;NormalizeImage(I);

Page 6: TAO Fayan_X-Ray and MIP volume rendering

6 FAYAN TAO (1509853F-II20-0019)

MIP Rendering AlgorithmRenderMIP(volume V, int stepSize, Image I)ray = v×u

|v×u| ; \∗ for orthographic projection ∗\\ ∗ ray: the view direction vector; v, uray: orthonormal image plane vectors ∗\4i = H

Ni−1 , 4j = WNj−1 (0 ≤ i < Ni, 0 ≤ j < Nj);

\ ∗W,H: screen width, hight in world coordinates; Ni, Nj: image dimensions in pixels ∗\for each image pixel(i, j)\∗ scan the image row by row, column by column: ∗\P (i, j) = P (0, 0) + i · v · 4i+ j · u · 4j;\ ∗ P (i, j): Location of image pixel(i, j) in the world space, which is a point on the ray direction ∗\\ ∗ P (0, 0): image origin in world space ∗\max = 0;IntersectRayWithV olumeBoundingBox(V, ray, t front, t back);for(t = t front; t <= t back; t+ = stepSize)sampleLoc = P (i, j) + t · ray;intV al = Interpolate(V, sampleLoc);if(intV al > max)max = intV al; sum+ = intV al · stepSize;I(i, j) = max;

3.2. Key code fragments. Now, we will show the key code for setting volume boundingbox, trilinear interpolation, scaling and rotation.

code for volume bounding box:

1 //p i s the s t a r t po int o f ray

2 void CVolumeRender : : IntersectRaywithVolumeBoundingBox ( Vector3 p)

3 {4 f l o a t bbx [ 2 ] , bby [ 2 ] , bbz [ 2 ] ;

5

6 bbx [ 1 ] = th i s−>voxelWidth ;

7 bby [ 1 ] = th i s−>voxe lHe igth ;

8 bbz [ 1 ] = th i s−>voxelDepth ;

9

10 bbx [ 0 ] = 0 ;

11 bby [ 0 ] = 0 ;

12 bbz [ 0 ] = 0 ;

13

14 f l o a t bbx0 , bbx1 , bby0 , bby1 , bbz0 , bbz1 ; // bounding box

15 f l o a t dev ;

16 f l o a t t1 , t2 , mint , maxt ;

17

18 t f r o n t = 0 .0 f ;

19 t back = 1000.0 f ;

20 dev = 0 .0 f ;

Page 7: TAO Fayan_X-Ray and MIP volume rendering

X-RAY AND MIP VOLUME RENDERING 7

1 i n t useBoundingBox = 1 ;

2 i f ( useBoundingBox )

3 {4 bbx0 = bbx [ 0 ] + dev ; bbx1 = bbx [ 1 ] − dev ;

5 bby0 = bby [ 0 ] + dev ; bby1 = bby [ 1 ] − dev ;

6 bbz0 = bbz [ 0 ] + dev ; bbz1 = bbz [ 1 ] − dev ;

7

8 }9 e l s e

10 {11 bbx0 = 0 + dev ; bbx1 = th i s−>voxelWidth − 1 − dev ;

12 bby0 = 0 + dev ; bby1 = th i s−>voxe lHe igth − 1 − dev ;

13 bbz0 = 0 + dev ; bbz1 = th i s−>voxelDepth − 1 − dev ;

14 }15

16 // i f p i s ou t s id e box , we w i l l not con s id e r i t

17 i f ( f abs ( ray .X( ) ) <= 1e−5)18 {19 i f (p . Z()<bbx0 && p .Z()>bbx1 )

20 {21 re turn ;

22 }23 }24 i f ( f abs ( ray .Y( ) ) <= 1e−5)25 {26 i f (p .Y()<bby0 && p .Y()>bby1 )

27 {28 re turn ;

29 }30 }31 i f ( f abs ( ray . Z ( ) ) <= 1e−5)32 {33 i f (p . Z()<bbz0 && p .Z()>bbz1 )

34 {35 re turn ;

36 }37

38 }39

40

41 // con s id e r X value

42 i f ( f abs ( ray .X( ) ) > 1e−5)43 { // i n t e r s e c t with bbx

44 t1 = (bbx0 − p . Z ( ) ) / ray .X( ) ;

45 t2 = (bbx1 − p .Y( ) ) / ray .X( ) ;

46 mint = std : : min ( t1 , t2 ) ;

47 maxt = std : : max( t1 , t2 ) ;

48 t f r o n t = std : : max(mint , t f r o n t ) ;

49 t back = std : : min (maxt , t back ) ;

50 }51 // con s id e r Y value

52 i f ( f abs ( ray .Y( ) ) > 1e−5)53 { // i n t e r s e c t with bby

54 t1 = (bby0 − p .Y( ) ) / ray .Y( ) ;

55 t2 = (bby1 − p .Y( ) ) / ray .Y( ) ;

56 mint = std : : min ( t1 , t2 ) ;

57 maxt = std : : max( t1 , t2 ) ;

58 t f r o n t = std : : max(mint , t f r o n t ) ;

59 t back = std : : min (maxt , t back ) ;

60 }61 // con s id e r Z value

62 i f ( f abs ( ray . Z ( ) ) > 1e−5)63 { // i n t e r s e c g t with bbz

64 t1 = ( bbz0 − p . Z ( ) ) / ray . Z ( ) ;

65 t2 = ( bbz1 − p . Z ( ) ) / ray . Z ( ) ;

66 mint = std : : min ( t1 , t2 ) ;

67 maxt = std : : max( t1 , t2 ) ;

68 t f r o n t = std : : max(mint , t f r o n t ) ;

69 t back = std : : min (maxt , t back ) ;

70 }71 }

Page 8: TAO Fayan_X-Ray and MIP volume rendering

8 FAYAN TAO (1509853F-II20-0019)

•Code for Trilinear Interpolation

1

2 i n t CVolumeRender : : Tr iL inear ( f l o a t x , f l o a t y , f l o a t z )

3 // (x , y , z ) i s the l o c a t i o n o f a ray sample po int .

4 {5 f l o a t u , v , w;

6 u = x − ( i n t ) x ;

7 v = y − ( i n t ) y ;

8 w = z − ( i n t ) ;

9 i f ( 0 . 0 f == u && 0.0 f == v && 0.0 f == w)

10 {11 re turn th i s−>GetVoxelVal ( x0 , y0 , z0 ) ;

12 }13

14 // f i nd the e i gh t ne ighbor ing samples o f (x , y , z )//

15 i n t p000 , p001 , p011 , p010 ;

16 i n t p100 , p101 , p111 , p110 ;

17

18 // get voxe l va lue o f each ne ighbor ing sample //

19 p100 = th i s−>GetVoxelVal ( x0 , y0 , z0 ) ;

20 p101 = th i s−>GetVoxelVal ( x0 + 1 , y0 , z0 ) ;

21 p111 = th i s−>GetVoxelVal ( x0 + 1 , y0 + 1 , z0 ) ;

22 p110 = th i s−>GetVoxelVal ( x0 , y0 + 1 , z0 ) ;

23

24 p000 = th i s−>GetVoxelVal ( x0 , y0 , z0 + 1 ) ;

25 p001 = th i s−>GetVoxelVal ( x0 + 1 , y0 , z0 + 1 ) ;

26 p011 = th i s−>GetVoxelVal ( x0 + 1 , y0 + 1 , z0 + 1 ) ;

27 p010 = th i s−>GetVoxelVal ( x0 , y0 + 1 , z0 + 1 ) ;

28

29 // get voxe l va lue o f sample po int by us ing f o l l ow i n g formula //

30 i n t intVal = (1 − w) ∗ ( (1 − v ) ∗ (u ∗ p001 + (1 − u) ∗ p000 ) +

31 v ∗ (u ∗ p011 + (1 − u) ∗ p010 ) ) +w ∗ ( (1 − v ) ∗ (u ∗ p101 + (1 − u) ∗ p100 )

32 + v ∗ (u ∗ p111 + (1 − u) ∗ p110 ) ) ;

33

34 re turn intVal ;

35 }36

37 // func t i on f o r g e t t i n g voxe l va lue o f sample po int to the po s i t i o n (x , y , z )//

38 i n t CVolumeRender : : GetVoxelVal ( i n t x , i n t y , i n t z )

39 {40 i n t width = th i s−>voxelWidth ;

41 i n t he ight = th i s−>voxe lHe igth ;

42 i f (x<0 | |y<0 | | z<0 | |x>width −1 | |y>height −1 | | z>th i s−>voxelDepth−1)43 {44 re turn 0 ;

45 }46 e l s e

47 {48 re turn th i s−>voxelData [ z∗ he ight ∗width + y∗width + x ] ;

49 }50 }

•Code for Scaling

Page 9: TAO Fayan_X-Ray and MIP volume rendering

X-RAY AND MIP VOLUME RENDERING 9

1

2 //// s c a l i n g : xxrayLoop ( ) f o r XRay . ////

3 // We s e t a va r i ab l e s c a l i n gk : the image w i l l be en l a rg e when s c a l i n gk i s between 0 and 1//

4 //and the image w i l l become sma l l e r when s c a l i n gk i s l a r g e r than 1 .//

5

6 // f o r each p i x e l in image plane , us ing volume bounding box to do volume render ing //

7 i n t CVolumeRender : : xxrayLoop ( i n t x , i n t y )

8 {9 f l o a t new x = x ∗ th i s−>s c a l i n gk ∗ d e l t a I ∗ o r i v [ 0 ] + y ∗ th i s−>s c a l i n gk

10 ∗ de l taJ ∗ o r i u [ 0 ] ;

11 f l o a t new y = x ∗ th i s−>s c a l i n gk ∗ d e l t a I ∗ o r i v [ 1 ] + y ∗ th i s−>s c a l i n gk

12 ∗ de l taJ ∗ o r i u [ 1 ] ;

13 f l o a t new z = x ∗ th i s−>s c a l i n gk ∗ d e l t a I ∗ o r i v [ 2 ] + y ∗ th i s−>s c a l i n gk

14 ∗ de l taJ ∗ o r i u [ 2 ] ;

15

16 //// the value o f l a y e r r ep r e s en t s the number o f voxe l va lue on the ray //

17 // from f r on t to back on bounding box .//

18 f l o a t l a y e r = (1 . 0 f / ( th i s−>voxelDepth / th i s−>s t epS i z e ) ) ;

19 f l o a t sum = 0.0 f ;

20 f o r ( f l o a t t = th i s−>t f r o n t ; t < th i s−>t back ; t += 15 . 0 ) // t += s t epS i z e

21 {22 Vector3 temp = th i s−>ray ∗ t ;

23 temp . Set ( temp .X( ) + new x , temp .Y( ) + new y , temp .Z( ) + new z ) ;

24 sum += th i s−>TriL inear ( temp .X( ) , temp .Y( ) , temp .Z ( ) ) ;

25 }26

27 // Here , ”sum ∗ l a y e r ” i s to make the value in each p i x e l between 0 and 255 . //

28 th i s−>s c r e en [ y∗ th i s−>voxelWidth + x ] = sum ∗ l a y e r ;

29 re turn 0 ;

30 }

•Code for Rotation

Page 10: TAO Fayan_X-Ray and MIP volume rendering

10 FAYAN TAO (1509853F-II20-0019)

1

2

3

4 // way2 : r o t a t i on f o r MIP by us ing r o t a t i on matrix //

5 i n t CVolumeRender : : MIPRotate ( Vector3 eye , f l o a t xDeg , f l o a t yDeg , f l o a t zDeg )

6 {7 // //” eye ” i s the s t a r t po int o f ray in the image plane , n=(0 ,0 ,1) ,

8 // n and ray i s perpend icu lar , n i s a l s o pe rpend i cu la r with image plane . //

9 //That i s to say , n i s pe rpend i cu l a r with vec to r o r i v and o r i u . //

10 // ray , o r i v , o r i u are orthonormal image plane ve c t o r s . //

11 th i s−>eye = eye ;

12 Vector3 o r i v , o r i u ; //

13 th i s−>ray = th i s−>pointO − th i s−>eye ;

14 o r i v . CrossProduct ( th i s−>ray , th i s−>n , o r i v ) ;

15 o r i u . CrossProduct ( th i s−>ray , th i s−>o r i v , o r i u ) ;

16 th i s−>rotateMatr ix . RotateX (xDeg ) ; // r o t a t i on with x ax i s

17 th i s−>rotateMatr ix . RotateY (yDeg ) ; // r o t a t i on with y ax i s

18 th i s−>rotateMatr ix . RotateZ ( zDeg ) ; // r o t a t i on with z ax i s

19

20 // get the new eye po s i t i o n a f t e r r o t a t i on with x−degree , y−degree and z−degree . //21 th i s−>eye = th i s−>eye∗ th i s−>rotateMatr ix ∗ th i s−>rotateMatr ix . RotateY (yDeg )

22 ∗ th i s−>rotateMatr ix . RotateZ ( zDeg ) ;

23

24 th i s−>ray . Normalize ( ) ;

25 th i s−>IntersectRaywithVolumeBoundingBox ( th i s−>eye ) ;

26

27 // make the image s i z e with 512 width and 512 he ight //

28 th i s−>screenWidth = 512 ;

29 th i s−>sc reenHe ight = 512 ;

30 th i s−>I n i t S c r e en (&CVolumeRender : : mipLoop ) ;

31 re turn 0 ;

32 }

4. Simple guideline on using program

When the program is compiled successfully, we will see the main window, which has a pop-up menu with ”Read Volume File”, ”X-Ray” and ”MIP”. Please click MIDDLE buttonof mouse to choose each one.

”Read Volume File” : This button provides us to choose a volume file, after selecting a file, the mainwindow will show the original image of that volume file.

”X-Ray” : After reading a file, choosing this button will allow us to observe the rotation of X-ray volume render. What we have to do is moving mouse by clicking LEFT button ,then we will see different images from different perspectives.

”MIP” : After reading a file, choosing this button will allow us to observe the rotation of MIPvolume render. When we move mouse by clicking RIGHT button , various imagesfrom different viewing angles will be shown. (Notes: As the algorithm I designed inthis rotation part is not so well, so you had better choose those points on the top-leftin the main window, otherwise, the result may be not so good.)

”+” and ”-” : Zoom out and zoom in for MIP volume rendering. We have to combine this functionwith the menu ”MIP”. That is to say, when we click the menu button ”MIP”, wecan use ”+” and ”-” to control the size of image.

Page 11: TAO Fayan_X-Ray and MIP volume rendering

X-RAY AND MIP VOLUME RENDERING 11

”l” and ”s” : Make the image larger and smaller for X-Ray volume rendering. This function isrelated to the menu ”X-Ray”. If we choose the menu button ”X-Ray”, we can use”l” and ”s” to enlarge or shrink the image.

”up, down, left, right” : rotate image plane with X and Y axis. These four keyboard keys are only usedto rotate image plane rather than image itself. The key ”up and down” are usedto rotate image plane with X axis, while key ”left and right” are used to rotateimage plane with Y axis.

5. Experimental results

Here, I show the related experimental results, including original images, X-Ray and MIPvolume rendering images.

6. Feelings about this project

I tried to use linear interpolation to scale the image, but failed. I think the idea isexecutable, but I did not find out faults for my following source code. So I choose to turnto change 4i and 4j to change image size.

1 // I plan to use t h i s part to s c a l e the image , but f a i l e d . so I choose change dethaI and dethaJ //

2 i n t CVolumeRender : : B i l i n e a r ( f l o a t x , f l o a t y )

3 { // (x , y ) i s the po int l o c a t i o n in image plane a f t e r s c a l i n g //

4 i n t i = ( i n t ) x ;

5 i n t j = ( i n t ) y ;

6 f l o a t u = x − i , v = y − j ;

7 re turn (1 − u )∗ (1 − v )∗ th i s−>GetScreenVal ( i , j ) + (1 − u)∗v∗ th i s−>GetScreenVal ( i , j + 1) +

8 u∗(1 − v )∗ th i s−>GetScreenVal ( i + 1 , j ) + u∗v∗ th i s−>GetScreenVal ( i + 1 , j + 1 ) ;

9 }

For the interpolation, I feel that it will make the edge becomes rough and fuzzy.In deed, After completing this project, I have a better knowledge on OpenGL and volume

rendering. Though it is not easy for me to start especially at the beginning. As I am notfamiliar with C + +, even though I know those underlying mathematics of those algorithms,I cannot implement it by C + + in a short time. Thanks to my classmates Zhang Qiaoyang,Lin Jiaming, Lu junyi and Chen Yuqing who are familiar with C++, I turn to them quiteoften, so that I am able to complete this project. However, there are still some drawbacksin the program, I will try to solve them in the following days.

Many thanks for Dr. Wong giving such fantastic lectures. I feel that OpenGL is a quitepowerful and useful tool. I want to learn more about it.

References

[1] Hadwiger M, Ljung P, Salama C R, et al. Advanced illumination techniques for GPU volume raycast-ing[C]//ACM Siggraph Asia 2008 Courses. ACM, 2008: 1.

[2] https:www.opengl.org/discussion boards/showthread.php/191078-Volume-Rendering-with-3D-Textures

[3] http:cg.alexandra.dk/?p = 107[4] http:graphicsrunner.blogspot.com/2009/01/volume-rendering-102-transfer-functions.html

Page 12: TAO Fayan_X-Ray and MIP volume rendering

12 FAYAN TAO (1509853F-II20-0019)

(a) ctHead

(b) engine

(c) footComplete

Figure 1. Original Figures

Page 13: TAO Fayan_X-Ray and MIP volume rendering

X-RAY AND MIP VOLUME RENDERING 13

(a) smoothSphere (b) softCube

Figure 2. Original Figures

(a) ctHead

(b) ctHead

(c) ctHead

Figure 3. MIP Figures (rotation)

Page 14: TAO Fayan_X-Ray and MIP volume rendering

14 FAYAN TAO (1509853F-II20-0019)

(a) ctHead.a

(b) ctHead.b

(c) ctHead.c

Figure 4. X-Ray Figures(rotation)

Page 15: TAO Fayan_X-Ray and MIP volume rendering

X-RAY AND MIP VOLUME RENDERING 15

(a) engine.a

(b) engine.b

(c) engine.c

Figure 5. MIP Figures (rotation)

Page 16: TAO Fayan_X-Ray and MIP volume rendering

16 FAYAN TAO (1509853F-II20-0019)

(a) engine.a

(b) engine.b

(c) engine.c

Figure 6. X-Ray Figures (rotation)

Page 17: TAO Fayan_X-Ray and MIP volume rendering

X-RAY AND MIP VOLUME RENDERING 17

(a) footComplete.a

(b) footComplete.b

(c) footComplete.c

Figure 7. MIP Figures (rotation)

Page 18: TAO Fayan_X-Ray and MIP volume rendering

18 FAYAN TAO (1509853F-II20-0019)

(a) footComplete.a

(b) footComplete.b

(c) footComplete.c

Figure 8. X-Ray Figures (rotation)

Page 19: TAO Fayan_X-Ray and MIP volume rendering

X-RAY AND MIP VOLUME RENDERING 19

(a) smoothSphere.a

(b) smoothSphere.b

(c) smoothSphere.c

Figure 9. MIP Figures (rotation)

Page 20: TAO Fayan_X-Ray and MIP volume rendering

20 FAYAN TAO (1509853F-II20-0019)

(a) smoothSphere.a

(b) smoothSphere.b

(c) smoothSphere.c

Figure 10. X-Ray Figures (rotation)

Page 21: TAO Fayan_X-Ray and MIP volume rendering

X-RAY AND MIP VOLUME RENDERING 21

(a) softCube.a

(b) softCube.b

(c) softCube.c

Figure 11. MIP Figures (rotation)

Page 22: TAO Fayan_X-Ray and MIP volume rendering

22 FAYAN TAO (1509853F-II20-0019)

(a) softCube.a

(b) softCube.b

(c) softCube.c

Figure 12. X-Ray Figures (rotation)