Skip to content

Commit

Permalink
MD-447
Browse files Browse the repository at this point in the history
  • Loading branch information
rossetantoine committed Jun 25, 2013
1 parent 5346994 commit 6ce51be
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 71 deletions.
1 change: 1 addition & 0 deletions DCMView.m
Expand Up @@ -9533,6 +9533,7 @@ - (void) drawRect:(NSRect)aRect withContext:(NSOpenGLContext *)ctx

// Swap buffer to screen
[ctx flushBuffer];

// [NSOpenGLContext clearCurrentContext];

drawingFrameRect = [self convertRectToBacking: [self frame]];
Expand Down
2 changes: 2 additions & 0 deletions ITKBrushROIFilter.mm
Expand Up @@ -144,6 +144,8 @@ - (void) erode:(ROI*)aROI withStructuringElementRadius:(int)structuringElementRa

memcpy(buff, dstBuf.data, bufferWidth*bufferHeight);
free( dstBuf.data);

[aROI textureBufferHasChanged];

}
// else
Expand Down
4 changes: 2 additions & 2 deletions ROI.h
Expand Up @@ -62,7 +62,7 @@ enum

@interface ROI : NSObject <NSCoding, NSCopying>
{
NSLock *roiLock;
NSRecursiveLock *roiLock;

int textureWidth, textureHeight;

Expand Down Expand Up @@ -359,7 +359,7 @@ enum

/** Delete texture */
- (void) deleteTexture:(NSOpenGLContext*) c;

- (void) textureBufferHasChanged;

/** Set cab resize layer */
- (void) setCanResizeLayer:(BOOL)boo;
Expand Down
130 changes: 61 additions & 69 deletions ROI.m
Expand Up @@ -1067,19 +1067,23 @@ - (NSData*) data

- (void) deleteTexture:(NSOpenGLContext*) c
{
NSUInteger index = [ctxArray indexOfObjectIdenticalTo: c];

if( c && index != NSNotFound)
{
GLuint t = [[textArray objectAtIndex: index] intValue];
CGLContextObj cgl_ctx = [c CGLContextObj];

if( t)
(*cgl_ctx->disp.delete_textures)(cgl_ctx->rend, 1, &t);

[ctxArray removeObjectAtIndex: index];
[textArray removeObjectAtIndex: index];
}
NSUInteger index;
do
{
index = [ctxArray indexOfObjectIdenticalTo: c];

if( c && index != NSNotFound)
{
GLuint t = [[textArray objectAtIndex: index] intValue];
CGLContextObj cgl_ctx = [c CGLContextObj];

if( t)
(*cgl_ctx->disp.delete_textures)(cgl_ctx->rend, 1, &t);

[ctxArray removeObjectAtIndex: index];
[textArray removeObjectAtIndex: index];
}
} while( index != NSNotFound);
}

- (void) dealloc
Expand Down Expand Up @@ -1110,7 +1114,7 @@ - (void) dealloc
[textArray release];

if (textureBuffer) free(textureBuffer);
if( textureBufferSelected) free( textureBufferSelected);
[self textureBufferHasChanged];

[uniqueID release];
[points release];
Expand Down Expand Up @@ -1240,9 +1244,7 @@ - (void) setOriginAndSpacing :(float) ipixelSpacingx :(float) ipixelSpacingy :(N
free( textureBuffer);
textureBuffer = newBuffer;

if( textureBufferSelected) {
free( textureBufferSelected); textureBufferSelected = nil;
}
[self textureBufferHasChanged];
}
else
{
Expand Down Expand Up @@ -2442,9 +2444,7 @@ - (BOOL)mouseRoiDownIn:(NSPoint)pt :(int)slice :(float)scale
textureBuffer = malloc(textureWidth*textureHeight*sizeof(unsigned char));
memset (textureBuffer, 0, textureHeight*textureWidth);

if( textureBufferSelected){
free( textureBufferSelected); textureBufferSelected = nil;
}
[self textureBufferHasChanged];

mode = ROI_drawing;
}
Expand Down Expand Up @@ -2913,8 +2913,15 @@ - (void) mergeWithTexture: (ROI*) r

[self reduceTextureIfPossible];

if( textureBufferSelected){
free( textureBufferSelected); textureBufferSelected = nil;
[self textureBufferHasChanged];
}

- (void) textureBufferHasChanged
{
if( textureBufferSelected)
{
free( textureBufferSelected);
textureBufferSelected = nil;
}
}

Expand Down Expand Up @@ -3023,9 +3030,7 @@ - (BOOL) reduceTextureIfPossible
textureDownRightCornerX = textureUpLeftCornerX + textureWidth-1;
textureDownRightCornerY = textureUpLeftCornerY + textureHeight-1;

if( textureBufferSelected){
free( textureBufferSelected); textureBufferSelected = nil;
}
[self textureBufferHasChanged];
}

return NO; // means the ROI is NOT empty;
Expand Down Expand Up @@ -3081,7 +3086,8 @@ - (BOOL) mouseRoiDragged:(NSPoint) pt :(unsigned int) modifier :(float) scale
{
case ROI_selectedModify:
case ROI_drawing:


{
thickness = ROIRegionThickness;

if (textureUpLeftCornerX > pt.x-thickness)
Expand Down Expand Up @@ -3115,19 +3121,16 @@ - (BOOL) mouseRoiDragged:(NSPoint) pt :(unsigned int) modifier :(float) scale
if (textureBuffer!=NULL)
{
tempTextureBuffer = malloc( oldTextureHeight*oldTextureWidth*sizeof(unsigned char));

for( long i = 0; i < oldTextureWidth*oldTextureHeight;i++) tempTextureBuffer[i]=textureBuffer[i];
memcpy( tempTextureBuffer, textureBuffer, oldTextureWidth*oldTextureHeight);
free(textureBuffer);
textureBuffer = nil;

if( textureBufferSelected){
free( textureBufferSelected); textureBufferSelected = nil;
}
[self textureBufferHasChanged];
}

// new width and height
textureWidth=((textureDownRightCornerX-textureUpLeftCornerX))+1;
textureHeight=((textureDownRightCornerY-textureUpLeftCornerY))+1;
textureWidth = (textureDownRightCornerX-textureUpLeftCornerX) + 1;
textureHeight = (textureDownRightCornerY-textureUpLeftCornerY) + 1;

// if( textureWidth%4) {textureWidth /=4; textureWidth *=4; textureWidth +=4;}
// if( textureHeight%4) {textureHeight /=4; textureHeight *=4; textureHeight += 4;}
Expand All @@ -3143,13 +3146,11 @@ - (BOOL) mouseRoiDragged:(NSPoint) pt :(unsigned int) modifier :(float) scale
textureHeight=oldTextureHeight;

// new texture buffer
textureBuffer = malloc(textureWidth*textureHeight*sizeof(unsigned char));

if (textureBuffer!=NULL)
textureBuffer = calloc( textureWidth * textureHeight, sizeof(unsigned char));
if( textureBuffer)
{
// copy temp buffer to the new buffer
for( long i = 0; i < textureWidth*textureHeight;i++) textureBuffer[i]=0;


if (textureGrowDownX && textureGrowDownY)
{
for( long j=0; j<oldTextureHeight; j++ )
Expand Down Expand Up @@ -3189,9 +3190,9 @@ - (BOOL) mouseRoiDragged:(NSPoint) pt :(unsigned int) modifier :(float) scale
oldTextureWidth = textureWidth;
oldTextureHeight = textureHeight;

unsigned char val;
unsigned char val;

if (![curView eraserFlag]) val = 0xFF;
if( ![curView eraserFlag]) val = 0xFF;
else val = 0x00;

if( modifier & NSCommandKeyMask && !(modifier & NSShiftKeyMask))
Expand All @@ -3200,13 +3201,13 @@ - (BOOL) mouseRoiDragged:(NSPoint) pt :(unsigned int) modifier :(float) scale
else val = 0xFF;
}

long size, *xPoints, *yPoints;
long size, *xPoints, *yPoints;

if( previousPoint.x == -1000 && previousPoint.y == -1000) previousPoint = pt;

int intThickness = thickness;

unsigned char *brush = calloc( intThickness*2*intThickness*2, sizeof( unsigned char));
unsigned char *brush = calloc( intThickness*2*intThickness*2, sizeof( unsigned char));

[ROI fillCircle: brush :intThickness*2 :0xFF];

Expand All @@ -3217,12 +3218,13 @@ - (BOOL) mouseRoiDragged:(NSPoint) pt :(unsigned int) modifier :(float) scale
&xPoints,
&yPoints);

for( long x = 0 ; x < size; x++ ) {
for( long x = 0 ; x < size; x++)
{
long xx = xPoints[ x];
long yy = yPoints[ x];

for ( long j =- intThickness; j < intThickness; j++ ) {
for ( long i =- intThickness; i < intThickness; i++ ) {
for( long j =- intThickness; j < intThickness; j++ ) {
for( long i =- intThickness; i < intThickness; i++ ) {

if( xx+j > textureUpLeftCornerX && xx+j < textureDownRightCornerX)
{
Expand All @@ -3248,16 +3250,15 @@ - (BOOL) mouseRoiDragged:(NSPoint) pt :(unsigned int) modifier :(float) scale
rtotal = -1;
Brtotal = -1;

if( textureBufferSelected){
free( textureBufferSelected); textureBufferSelected = nil;
}
[self textureBufferHasChanged];
}
break;

case ROI_selected:
action = NO;
break;
}
}
}
else if( type == tOval || type == tROI)
{
switch( mode)
Expand Down Expand Up @@ -4022,14 +4023,12 @@ - (void) setTexture: (unsigned char*) t width: (int) w height:(int) h
textureWidth = w;
textureHeight = h;

if( textureBufferSelected){
free( textureBufferSelected); textureBufferSelected = nil;
}
[self textureBufferHasChanged];
}

- (void) drawROIWithScaleValue:(float)scaleValue offsetX:(float)offsetx offsetY:(float)offsety pixelSpacingX:(float)spacingX pixelSpacingY:(float)spacingY highlightIfSelected:(BOOL)highlightIfSelected thickness:(float)thick prepareTextualData:(BOOL) prepareTextualData;
{
if( roiLock == nil) roiLock = [[NSLock alloc] init];
if( roiLock == nil) roiLock = [[NSRecursiveLock alloc] init];

if( curView == nil && prepareTextualData == YES) {NSLog(@"curView == nil! We will not draw this ROI..."); return;}

Expand Down Expand Up @@ -4175,8 +4174,6 @@ - (void) drawROIWithScaleValue:(float)scaleValue offsetX:(float)offsetx offsetY:
{
glDisable(GL_POLYGON_SMOOTH);

[self deleteTexture: currentContext];

if( highlightIfSelected)
{
switch( mode)
Expand All @@ -4202,7 +4199,6 @@ - (void) drawROIWithScaleValue:(float)scaleValue offsetX:(float)offsetx offsetY:
unsigned char* newBufferCopy = malloc( newWidth*newHeight);
memcpy( newBufferCopy, textureBufferSelected, newWidth*newHeight);


{
// input buffer
unsigned char *buff = textureBufferSelected;
Expand Down Expand Up @@ -4245,9 +4241,6 @@ - (void) drawROIWithScaleValue:(float)scaleValue offsetX:(float)offsetx offsetY:
glPixelStorei (GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
glTexParameteri (GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_CACHED_APPLE);

[ctxArray addObject: currentContext];
[textArray addObject: [NSNumber numberWithInt: textureName]];

glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Expand Down Expand Up @@ -4284,12 +4277,15 @@ - (void) drawROIWithScaleValue:(float)scaleValue offsetX:(float)offsetx offsetY:
glTexCoord2f (newWidth, newHeight); // draw lower right in world coordinates
glVertex3d (screenXDr, screenYDr, 0.0);
glEnd();

glDeleteTextures( 1, &textureName);

glDisable(GL_TEXTURE_RECTANGLE_EXT);
}
break;
}
}

GLuint textureName = 0;

glEnable(GL_TEXTURE_RECTANGLE_EXT);
Expand All @@ -4300,9 +4296,6 @@ - (void) drawROIWithScaleValue:(float)scaleValue offsetX:(float)offsetx offsetY:
glPixelStorei (GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
glTexParameteri (GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_CACHED_APPLE);

[ctxArray addObject: currentContext];
[textArray addObject: [NSNumber numberWithInt: textureName]];

glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Expand Down Expand Up @@ -4341,6 +4334,9 @@ - (void) drawROIWithScaleValue:(float)scaleValue offsetX:(float)offsetx offsetY:
glEnd();

glDisable(GL_TEXTURE_RECTANGLE_EXT);

glDeleteTextures( 1, &textureName);

glEnable(GL_POLYGON_SMOOTH);

switch( mode)
Expand Down Expand Up @@ -6553,9 +6549,7 @@ - (void) addMarginToBuffer: (int) margin
textureUpLeftCornerX -= margin;
textureUpLeftCornerY -= margin;

if( textureBufferSelected){
free( textureBufferSelected); textureBufferSelected = nil;
}
[self textureBufferHasChanged];
}

// Calcium Scoring
Expand Down Expand Up @@ -6676,9 +6670,7 @@ - (GLuint) loadLayerImageTexture;

if(textureBuffer) free(textureBuffer);

if( textureBufferSelected){
free( textureBufferSelected); textureBufferSelected = nil;
}
[self textureBufferHasChanged];

if(spp == 1)
{
Expand Down

0 comments on commit 6ce51be

Please sign in to comment.