Skip to content

Commit

Permalink
Gantry Tilt plugin
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/osirixplugins/code@178 bdd3870d-6ba2-4b59-8605-1de7af000970
  • Loading branch information
rossetantoine committed Nov 22, 2011
1 parent 9fdf866 commit 507c930
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 73 deletions.
149 changes: 77 additions & 72 deletions GantryTiltCorrection/GantryTiltCorrection.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @implementation GantryTiltCorrection
- (long) filterImage:(NSString*) menuName
{
DCMPix *curPix;
BOOL OK = YES;

curPix = [[viewerController pixList] objectAtIndex: 0];

Expand Down Expand Up @@ -51,81 +52,85 @@ - (long) filterImage:(NSString*) menuName
if( equal == NO)
{
NSRunInformationalAlertPanel( NSLocalizedString(@"Error!", nil), NSLocalizedString(@"These slices have not the same orientation. Gantry Tilt Correction cannot be applied to this dataset.", nil), NSLocalizedString(@"OK", nil), 0L, 0L);
return 0;
OK = NO;
break;
}
}

for( DCMPix *p in pixList)
{
float o[ 9];
float xyz[ 3];

[p orientation: o];
xyz[ 0] = [p originX]; xyz[ 1] = [p originY]; xyz[ 2] = [p originZ];

float vectorModel[ 9], vectorSensor[ 9];

[p orientation: vectorSensor];
[curPix orientation: vectorModel];

double length;

// --
matrix[ 9] = xyz[ 0] - origin[ 0];
matrix[ 10] = xyz[ 1] - origin[ 1];
matrix[ 11] = xyz[ 2] - origin[ 2];
// --

matrix[ 0] = vectorSensor[ 0] * vectorModel[ 0] + vectorSensor[ 1] * vectorModel[ 1] + vectorSensor[ 2] * vectorModel[ 2];
matrix[ 1] = vectorSensor[ 0] * vectorModel[ 3] + vectorSensor[ 1] * vectorModel[ 4] + vectorSensor[ 2] * vectorModel[ 5];
matrix[ 2] = vectorSensor[ 0] * vectorModel[ 6] + vectorSensor[ 1] * vectorModel[ 7] + vectorSensor[ 2] * vectorModel[ 8];

length = sqrt(matrix[0]*matrix[0] + matrix[1]*matrix[1] + matrix[2]*matrix[2]);

matrix[0] = matrix[ 0] / length;
matrix[1] = matrix[ 1] / length;
matrix[2] = matrix[ 2] / length;

// --

matrix[ 3] = vectorSensor[ 3] * vectorModel[ 0] + vectorSensor[ 4] * vectorModel[ 1] + vectorSensor[ 5] * vectorModel[ 2];
matrix[ 4] = vectorSensor[ 3] * vectorModel[ 3] + vectorSensor[ 4] * vectorModel[ 4] + vectorSensor[ 5] * vectorModel[ 5];
matrix[ 5] = vectorSensor[ 3] * vectorModel[ 6] + vectorSensor[ 4] * vectorModel[ 7] + vectorSensor[ 5] * vectorModel[ 8];

length = sqrt(matrix[3]*matrix[3] + matrix[4]*matrix[4] + matrix[5]*matrix[5]);

matrix[3] = matrix[ 3] / length;
matrix[4] = matrix[ 4] / length;
matrix[5] = matrix[ 5] / length;

// --

matrix[6] = matrix[1]*matrix[5] - matrix[2]*matrix[4];
matrix[7] = matrix[2]*matrix[3] - matrix[0]*matrix[5];
matrix[8] = matrix[0]*matrix[4] - matrix[1]*matrix[3];

length = sqrt(matrix[6]*matrix[6] + matrix[7]*matrix[7] + matrix[8]*matrix[8]);

matrix[6] = matrix[ 6] / length;
matrix[7] = matrix[ 7] / length;
matrix[8] = matrix[ 8] / length;

long size;

float *resultBuff = [ITKTransform reorient2Dimage: matrix firstObject: curPix firstObjectOriginal: p length: &size];
memcpy( [p fImage] , resultBuff, size);
free( resultBuff);

xyz[ 0] = origin[ 0];
xyz[ 1] = origin[ 1];
[p setOrigin: xyz];
}

for( DCMPix *p in pixList)
{
[p setOrientationDouble: matrix];
[p setSliceInterval: 0];
}
if( OK)
{
for( DCMPix *p in pixList)
{
float o[ 9];
float xyz[ 3];

[p orientation: o];
xyz[ 0] = [p originX]; xyz[ 1] = [p originY]; xyz[ 2] = [p originZ];

float vectorModel[ 9], vectorSensor[ 9];

[p orientation: vectorSensor];
[curPix orientation: vectorModel];

double length;

// --
matrix[ 9] = xyz[ 0] - origin[ 0];
matrix[ 10] = xyz[ 1] - origin[ 1];
matrix[ 11] = xyz[ 2] - origin[ 2];
// --

matrix[ 0] = vectorSensor[ 0] * vectorModel[ 0] + vectorSensor[ 1] * vectorModel[ 1] + vectorSensor[ 2] * vectorModel[ 2];
matrix[ 1] = vectorSensor[ 0] * vectorModel[ 3] + vectorSensor[ 1] * vectorModel[ 4] + vectorSensor[ 2] * vectorModel[ 5];
matrix[ 2] = vectorSensor[ 0] * vectorModel[ 6] + vectorSensor[ 1] * vectorModel[ 7] + vectorSensor[ 2] * vectorModel[ 8];

length = sqrt(matrix[0]*matrix[0] + matrix[1]*matrix[1] + matrix[2]*matrix[2]);

matrix[0] = matrix[ 0] / length;
matrix[1] = matrix[ 1] / length;
matrix[2] = matrix[ 2] / length;

// --

matrix[ 3] = vectorSensor[ 3] * vectorModel[ 0] + vectorSensor[ 4] * vectorModel[ 1] + vectorSensor[ 5] * vectorModel[ 2];
matrix[ 4] = vectorSensor[ 3] * vectorModel[ 3] + vectorSensor[ 4] * vectorModel[ 4] + vectorSensor[ 5] * vectorModel[ 5];
matrix[ 5] = vectorSensor[ 3] * vectorModel[ 6] + vectorSensor[ 4] * vectorModel[ 7] + vectorSensor[ 5] * vectorModel[ 8];

length = sqrt(matrix[3]*matrix[3] + matrix[4]*matrix[4] + matrix[5]*matrix[5]);

matrix[3] = matrix[ 3] / length;
matrix[4] = matrix[ 4] / length;
matrix[5] = matrix[ 5] / length;

// --

matrix[6] = matrix[1]*matrix[5] - matrix[2]*matrix[4];
matrix[7] = matrix[2]*matrix[3] - matrix[0]*matrix[5];
matrix[8] = matrix[0]*matrix[4] - matrix[1]*matrix[3];

length = sqrt(matrix[6]*matrix[6] + matrix[7]*matrix[7] + matrix[8]*matrix[8]);

matrix[6] = matrix[ 6] / length;
matrix[7] = matrix[ 7] / length;
matrix[8] = matrix[ 8] / length;

long size;

float *resultBuff = [ITKTransform reorient2Dimage: matrix firstObject: curPix firstObjectOriginal: p length: &size];
memcpy( [p fImage] , resultBuff, size);
free( resultBuff);

xyz[ 0] = origin[ 0];
xyz[ 1] = origin[ 1];
[p setOrigin: xyz];
}

for( DCMPix *p in pixList)
{
[p setOrientationDouble: matrix];
[p setSliceInterval: 0];
}
}
[viewerController endWaitWindow: w];

// We modified the view: OsiriX please update the display!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
);
GCC_C_LANGUAGE_STANDARD = c99;
MACOSX_DEPLOYMENT_TARGET = 10.5;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.6.sdk";
};
name = Development;
};
Expand Down

0 comments on commit 507c930

Please sign in to comment.