Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/osirix/code/osirix@10251 4e9e6e3d-4551-47eb-9dbe-a6127f9400a1
  • Loading branch information
rossetantoine committed Aug 10, 2012
1 parent 8712f0e commit be240fd
Show file tree
Hide file tree
Showing 12 changed files with 3,326 additions and 3,333 deletions.
230 changes: 100 additions & 130 deletions Binaries/English.lproj/CPR.xib

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions CPRController.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ typedef NSInteger CPRExportRotationSpan;
NSColor *curvedPathColor;
BOOL curvedPathCreationMode;

// Fly Assistant and CurvedPath simplification
FlyAssistant * assistant;
NSMutableArray * centerline;
NSMutableArray * delationCost;
NSMutableArray * nodeRemovalCost;
NSMutableArray * delHistory;
NSMutableArray * delNodes;
IBOutlet NSSlider *pathSimplificationSlider;

// Blending
DCMView *blendedMprView1, *blendedMprView2, *blendedMprView3;
Expand Down Expand Up @@ -255,9 +257,11 @@ typedef NSInteger CPRExportRotationSpan;
- (void) loadBezierPathFromFile:(NSString*) f;
- (NSDictionary*)exportDCMImage16bitWithWidth:(NSUInteger)width height:(NSUInteger)height fullDepth:(BOOL)fullDepth withDicomExport:(DICOMExport *)dicomExport; // dicomExport can be nil
- (void) setupToolbar;
- (IBAction)removeNode:(id)sender;
- (IBAction)undoLastNodeRemoval:(id)sender;
- (void)removeNode;
- (void)undoLastNodeRemoval;
- (void)updateCurvedPathCost;
- (void)resetSlider;
- (IBAction)runFlyAssistant:(id)sender;
- (IBAction)onSliderMove:(id)sender;
- (float) costFunction:(NSUInteger)index;
- (IBAction)openSimplifyPath:(id)sender;
@end
119 changes: 69 additions & 50 deletions CPRController.m
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ - (id)initWithDCMPixList:(NSMutableArray*)pix filesList:(NSMutableArray*)files v
assistant = [[FlyAssistant alloc] initWithVolume:(float*)[volume bytes] WidthDimension:dim Spacing:spacing ResampleVoxelSize:resamplesize];
[assistant setCenterlineResampleStepLength:3.0];
centerline = [[NSMutableArray alloc] init];
delationCost = [[NSMutableArray alloc] init];
nodeRemovalCost = [[NSMutableArray alloc] init];
delHistory = [[NSMutableArray alloc] init];
delNodes = [[NSMutableArray alloc] init];
curvedPath = [[CPRCurvedPath alloc] init];
Expand Down Expand Up @@ -390,7 +390,10 @@ - (id)initWithDCMPixList:(NSMutableArray*)pix filesList:(NSMutableArray*)files v

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(CloseViewerNotification:) name:OsirixCloseViewerNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(changeWLWW:) name: OsirixChangeWLWWNotification object: nil];


[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(updateCurvedPathCost) name:OsirixUpdateCurvedPathCostNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(resetSlider) name:OsirixDeletedCurvedPathNotification object: nil];

[shadingCheck setAction:@selector(switchShading:)];
[shadingCheck setTarget:self];

Expand Down Expand Up @@ -658,7 +661,7 @@ - (void) dealloc

[assistant release];
[centerline release];
[delationCost release];
[nodeRemovalCost release];
[delHistory release];
[delNodes release];

Expand Down Expand Up @@ -1134,18 +1137,9 @@ - (void) assistedCurvedPath:(NSNotification*) note

self.curvedPath = newCP;

[delationCost removeAllObjects];
NSUInteger pathSize = [[curvedPath nodes] count];
for (NSUInteger i = 0 ; i < pathSize; ++i)
{
[delationCost addObject:[NSNumber numberWithFloat:[self costFunction:i]]];
}
[self updateCurvedPathCost];
[pathSimplificationSlider setDoubleValue:[pathSimplificationSlider maxValue]];

if (pathSize != [delationCost count]) {
NSLog(@"Trouble.");
} else {
NSLog(@"No trouble.");
}
mprView1.curvedPath = curvedPath;
mprView2.curvedPath = curvedPath;
mprView3.curvedPath = curvedPath;
Expand Down Expand Up @@ -4542,13 +4536,6 @@ - (float) costFunction:(NSUInteger)index
if (index == 0 || index == [[curvedPath nodes] count] - 1)
{
cost = MAXFLOAT;
// N3Vector next = [[[curvedPath nodes] objectAtIndex:index+1] N3VectorValue];
// cost = (cur.x - next.x) * (cur.x - next.x) + (cur.y - next.y) * (cur.y - next.y) + (cur.z - next.z) * (cur.z - next.z);
// }
// else if (index == [[curvedPath nodes] count] - 1)
// {
// N3Vector prev = [[[curvedPath nodes] objectAtIndex:index-1] N3VectorValue];
// cost = (cur.x - prev.x) * (cur.x - prev.x) + (cur.y - prev.y) * (cur.y - prev.y) + (cur.z - prev.z) * (cur.z - prev.z);
}
else
{
Expand All @@ -4562,9 +4549,9 @@ - (float) costFunction:(NSUInteger)index
return cost;
}

- (IBAction)removeNode:(id)sender
- (void)removeNode
{
NSUInteger delCount = [delationCost count];
NSUInteger delCount = [nodeRemovalCost count];

if (delCount > 3) // prevents the removal of too many points: CPR view is shown with at least 3 points.
{
Expand All @@ -4573,29 +4560,29 @@ - (IBAction)removeNode:(id)sender
// Find the index of the node that lowers the delation cost
for (NSUInteger i = 0; i < delCount; ++i)
{
if (cost > [[delationCost objectAtIndex:i] floatValue])
if (cost > [[nodeRemovalCost objectAtIndex:i] floatValue])
{
index = i;
cost = [[delationCost objectAtIndex:i] floatValue];
cost = [[nodeRemovalCost objectAtIndex:i] floatValue];
}
}

// Remove the node
N3Vector node = [[[curvedPath nodes] objectAtIndex:index] N3VectorValue];
[self.curvedPath removeNodeAtIndex:index];
[delationCost removeObjectAtIndex:index];
[nodeRemovalCost removeObjectAtIndex:index];
[delHistory addObject:[NSNumber numberWithUnsignedInteger:index]];
[delNodes addObject:[NSValue valueWithN3Vector:node]];

// Update the cost list
if (index > 0)
{
[delationCost replaceObjectAtIndex:index-1 withObject:[NSNumber numberWithFloat:[self costFunction:index-1]]];
[nodeRemovalCost replaceObjectAtIndex:index-1 withObject:[NSNumber numberWithFloat:[self costFunction:index-1]]];
}

if (index < delCount - 1)
{
[delationCost replaceObjectAtIndex:index withObject:[NSNumber numberWithFloat:[self costFunction:index]]];
[nodeRemovalCost replaceObjectAtIndex:index withObject:[NSNumber numberWithFloat:[self costFunction:index]]];
}

// Update the curved path on all views
Expand All @@ -4609,7 +4596,7 @@ - (IBAction)removeNode:(id)sender
}
}

- (IBAction)undoLastNodeRemoval:(id)sender
- (void)undoLastNodeRemoval
{
if ([delHistory count] > 0)
{
Expand All @@ -4620,16 +4607,16 @@ - (IBAction)undoLastNodeRemoval:(id)sender
[delNodes removeLastObject];
// Update the cost list
// the index in delHistory and delationCost do not include first and last two indexes of centerline (can't remoce first and last points)
[delationCost insertObject:[NSNumber numberWithFloat:[self costFunction:index]] atIndex:index];
[nodeRemovalCost insertObject:[NSNumber numberWithFloat:[self costFunction:index]] atIndex:index];

if (index > 0)
{
[delationCost replaceObjectAtIndex:index-1 withObject:[NSNumber numberWithFloat:[self costFunction:index-1]]];
[nodeRemovalCost replaceObjectAtIndex:index-1 withObject:[NSNumber numberWithFloat:[self costFunction:index-1]]];
}

if (index < [delationCost count] - 1)
if (index < [nodeRemovalCost count] - 1)
{
[delationCost replaceObjectAtIndex:index+1 withObject:[NSNumber numberWithFloat:[self costFunction:index+1]]];
[nodeRemovalCost replaceObjectAtIndex:index+1 withObject:[NSNumber numberWithFloat:[self costFunction:index+1]]];
}

// Update the curved path on all views
Expand All @@ -4643,6 +4630,24 @@ - (IBAction)undoLastNodeRemoval:(id)sender
}
}

- (void) updateCurvedPathCost
{
[nodeRemovalCost removeAllObjects];
NSUInteger pathSize = [[curvedPath nodes] count];
for (NSUInteger i = 0; i < pathSize ; ++i)
{
[nodeRemovalCost addObject:[NSNumber numberWithFloat:[self costFunction:i]]];
}
}

- (void) resetSlider
{
[nodeRemovalCost removeAllObjects];
[delNodes removeAllObjects];
[delHistory removeAllObjects];
[pathSimplificationSlider setDoubleValue:[pathSimplificationSlider maxValue]];
}

#pragma mark CPRViewDelegate Methods

- (NSMutableArray *)_delegateCurveViewDebugging
Expand Down Expand Up @@ -4846,28 +4851,42 @@ - (void)CPRView:(CPRMPRDCMView*) CPRMPRDCMView setCrossCenter:(N3Vector)crossCen

- (IBAction)runFlyAssistant:(id)sender;
{
if ([curvedPath.nodes count] > 1) {
if( [curvedPath.nodes count] > 1 && [curvedPath.nodes count] <= 5)
[self assistedCurvedPath:nil];
}
else
NSRunAlertPanel(NSLocalizedString(@"Path Assistant error", nil), NSLocalizedString(@"Path Assistant can not find a path with at least two points. Use the Curved Path tool to define at least two points.", nil), NSLocalizedString(@"OK", nil), nil, nil);
NSRunAlertPanel(NSLocalizedString(@"Path Assistant error", nil), NSLocalizedString(@"Path Assistant requires at least 2 points, and no more than 5 points. Use the Curved Path tool to define at least two points.", nil), NSLocalizedString(@"OK", nil), nil, nil);

[self willChangeValueForKey: @"onSliderEnabled"];
[self didChangeValueForKey: @"onSliderEnabled"];
}

- (BOOL) onSliderEnabled
{
if ([centerline count] && [[curvedPath nodes] count] > 2)
return YES;
else
return NO;
}

//- (IBAction)switchPathAssistantMode:(id)sender;
//{
// assistantPathMode = !assistantPathMode;
// mprView1.pathAssistantMode = assistantPathMode;
// mprView2.pathAssistantMode = assistantPathMode;
// mprView3.pathAssistantMode = assistantPathMode;
// if (assistantPathMode) {
// NSLog(@"Path Assistant enabled.");
// }
// else
// NSLog(@"Path Assistant disabled.");
//}

- (IBAction)openSimplifyPath:(id)sender {
- (IBAction)onSliderMove:(id)sender
{
if ([centerline count] && [[curvedPath nodes] count] > 2)
{
int targetValue = ([centerline count] - 3) * [pathSimplificationSlider floatValue] / 100 + 3;
while ([[curvedPath nodes] count] != targetValue)
{
if (targetValue < [[curvedPath nodes] count])
{
[self removeNode];
}
else
{
[self undoLastNodeRemoval];
}
}
}
[self willChangeValueForKey: @"onSliderEnabled"];
[self didChangeValueForKey: @"onSliderEnabled"];
}

- (void)CPRViewDidEditAssistedCurvedPath:(id)CPRMPRDCMView
Expand Down
Loading

0 comments on commit be240fd

Please sign in to comment.