[Scopeapp-cvs]scopeapp/src TracePath.h,NONE,1.1 TracePath.m,NONE,1.1 TraceView.h,1.5,1.6 TraceView.m
Status: Alpha
Brought to you by:
narge
From: <sco...@li...> - 2003-01-10 10:49:30
|
Update of /cvsroot/scopeapp/scopeapp/src In directory sc8-pr-cvs1:/tmp/cvs-serv12628/src Modified Files: TraceView.h TraceView.m ScopeView.m XYPlotView.m Added Files: TracePath.h TracePath.m Log Message: Replace NSBezierCurve with TracePath to allow alternative methods of drawing. Currently draws one segment at a time, to work around Quartz performance issue. --- NEW FILE: TracePath.h --- // // TracePath.h // MacCRO X // // Created by Philip Derrin on Fri Jan 10 2003. // Copyright (c) 2003 Philip Derrin. // // This file is part of MacCRO X. // // MacCRO X is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // MacCRO X is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with MacCRO X; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // $Header: /cvsroot/scopeapp/scopeapp/src/TracePath.h,v 1.1 2003/01/10 10:49:27 narge Exp $ // #import <Foundation/Foundation.h> // TracePath is intended to replace NSBezierPath for drawing large numbers // of connected straight line segments. It is significantly faster than // NSBezierPath, at the expense of not using high-quality joins between // segments or drawing overlapping lines correctly (especially when // transparent). It does this by drawing line segments one at a time, rather // than all in one large path. @interface TracePath : NSObject { NSPoint* myPoints; // an array of NSPoints int myPointsAllocated; // the current size of the array int myPointsStored; // the number of points stored in the array } - init; - removeAllPoints; - addPoint: (NSPoint) newPoint; - stroke; @end // vim:syn=objc:nocin:si: --- NEW FILE: TracePath.m --- // // TracePath.m // MacCRO X // // Created by Philip Derrin on Fri Jan 10 2003. // Copyright (c) 2003 Philip Derrin. // // This file is part of MacCRO X. // // MacCRO X is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // MacCRO X is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with MacCRO X; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // $Header: /cvsroot/scopeapp/scopeapp/src/TracePath.m,v 1.1 2003/01/10 10:49:27 narge Exp $ // #import <AppKit/AppKit.h> #import "TracePath.h" @implementation TracePath - init { self = [super init]; if(self != nil) { myPointsStored = 0; myPointsAllocated = 4; myPoints = malloc(sizeof(NSPoint) * myPointsAllocated); } return self; } -(void) dealloc { free(myPoints); } - removeAllPoints { // don't bother to reallocate array; chances are it'll just fill up // to the same size next time it's used myPointsStored = 0; return self; } - addPoint: (NSPoint) newPoint { if(myPointsStored == myPointsAllocated) { myPointsAllocated *= 2; myPoints = realloc(myPoints, sizeof(NSPoint) * myPointsAllocated); } myPoints[myPointsStored] = newPoint; myPointsStored++; return self; } - stroke { int i; NSBezierPath* path = [[NSBezierPath alloc] init]; // FIXME: I tried using CoreGraphics directly to do this, but // it took "line width = 0" literally and drew nothing, rather // than drawing the thinnest possible line as Cocoa does. [path setLineWidth: 0.0]; [path setLineCapStyle: NSButtLineCapStyle]; for(i=0; i<myPointsStored-1; i++) { [path removeAllPoints]; [path moveToPoint: myPoints[i]]; [path lineToPoint: myPoints[i+1]]; [path stroke]; } [path release]; return self; } @end // vim:syn=objc:nocin:si: Index: TraceView.h =================================================================== RCS file: /cvsroot/scopeapp/scopeapp/src/TraceView.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TraceView.h 9 Jan 2003 04:44:59 -0000 1.5 --- TraceView.h 10 Jan 2003 10:49:27 -0000 1.6 *************** *** 27,30 **** --- 27,31 ---- #import <AppKit/AppKit.h> #import "InputSampler.h" + #import "TracePath.h" @interface TraceView : NSView <InputHandler> { *************** *** 50,54 **** // drawing thread stuff NSLock* myDisplayLock; // lock for access to the Bezier Paths ! NSBezierPath* myBezierPaths[2]; NSConditionLock* myDrawThreadState; // semaphore to start & stop the drawing thread BOOL myDisplayIsFrozen; --- 51,55 ---- // drawing thread stuff NSLock* myDisplayLock; // lock for access to the Bezier Paths ! TracePath* myTracePaths[2]; NSConditionLock* myDrawThreadState; // semaphore to start & stop the drawing thread BOOL myDisplayIsFrozen; Index: TraceView.m =================================================================== RCS file: /cvsroot/scopeapp/scopeapp/src/TraceView.m,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TraceView.m 9 Jan 2003 04:44:59 -0000 1.8 --- TraceView.m 10 Jan 2003 10:49:27 -0000 1.9 *************** *** 52,59 **** - (void)awakeFromNib { ! myBezierPaths[0] = [[NSBezierPath alloc] init]; ! [myBezierPaths[0] setLineWidth: 0.0]; ! myBezierPaths[1] = [[NSBezierPath alloc] init]; ! [myBezierPaths[1] setLineWidth: 0.0]; myDisplayIsFrozen = NO; --- 52,57 ---- - (void)awakeFromNib { ! myTracePaths[0] = [[TracePath alloc] init]; ! myTracePaths[1] = [[TracePath alloc] init]; myDisplayIsFrozen = NO; *************** *** 84,89 **** } ! [myBezierPaths[0] release]; ! [myBezierPaths[1] release]; [myDataLock release]; [myDisplayLock release]; --- 82,87 ---- } ! [myTracePaths[0] release]; ! [myTracePaths[1] release]; [myDataLock release]; [myDisplayLock release]; *************** *** 107,110 **** --- 105,110 ---- NSColor* foreColor; NSRect bounds = [self bounds]; + NSGraphicsContext* context; + BOOL wasAntiAliased; NSAffineTransform* scaling = *************** *** 130,146 **** #endif // draw trace A foreColor = [NSColor blackColor]; [foreColor set]; ! [myBezierPaths[0] stroke]; // draw trace B foreColor = [NSColor redColor]; [foreColor set]; ! [myBezierPaths[1] stroke]; #ifdef DEBUG_CODE time = -[startTime timeIntervalSinceNow]; ! fprintf(stderr, "%lf\n", time); #endif --- 130,154 ---- #endif + // turn off anti-aliasing if necessary + context = [NSGraphicsContext currentContext]; + wasAntiAliased = [context shouldAntialias]; + [context setShouldAntialias: YES]; // FIXME put this in prefs panel + // draw trace A foreColor = [NSColor blackColor]; [foreColor set]; ! [myTracePaths[0] stroke]; // draw trace B foreColor = [NSColor redColor]; [foreColor set]; ! [myTracePaths[1] stroke]; ! ! // restore antialiasing ! [context setShouldAntialias: wasAntiAliased]; #ifdef DEBUG_CODE time = -[startTime timeIntervalSinceNow]; ! fprintf(stderr, "%d %lf\n", myDataWanted[0], time); #endif Index: ScopeView.m =================================================================== RCS file: /cvsroot/scopeapp/scopeapp/src/ScopeView.m,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ScopeView.m 9 Jan 2003 04:44:59 -0000 1.15 --- ScopeView.m 10 Jan 2003 10:49:27 -0000 1.16 *************** *** 254,258 **** { [myDisplayLock lock]; ! [myBezierPaths[1] removeAllPoints]; [myDisplayLock unlock]; return self; --- 254,258 ---- { [myDisplayLock lock]; ! [myTracePaths[1] removeAllPoints]; [myDisplayLock unlock]; return self; *************** *** 293,301 **** [myDisplayLock lock]; ! [myBezierPaths[inTrace] removeAllPoints]; curX = 0; curY = 0.5 + (curValue * theScaleFactor) + myYOffsets[inTrace]; ! [myBezierPaths[inTrace] moveToPoint: NSMakePoint(curX, curY)]; switch(traceMode) { --- 293,301 ---- [myDisplayLock lock]; ! [myTracePaths[inTrace] removeAllPoints]; curX = 0; curY = 0.5 + (curValue * theScaleFactor) + myYOffsets[inTrace]; ! [myTracePaths[inTrace] addPoint: NSMakePoint(curX, curY)]; switch(traceMode) { *************** *** 305,309 **** curValue = myDisplayData[0][curSample]; curY = 0.5 + (curValue * theScaleFactor) + myYOffsets[inTrace]; ! [myBezierPaths[inTrace] lineToPoint: NSMakePoint(curX, curY)]; } break; --- 305,309 ---- curValue = myDisplayData[0][curSample]; curY = 0.5 + (curValue * theScaleFactor) + myYOffsets[inTrace]; ! [myTracePaths[inTrace] addPoint: NSMakePoint(curX, curY)]; } break; *************** *** 313,317 **** curValue = myDisplayData[1][curSample]; curY = 0.5 + (curValue * theScaleFactor) + myYOffsets[inTrace]; ! [myBezierPaths[inTrace] lineToPoint: NSMakePoint(curX, curY)]; } break; --- 313,317 ---- curValue = myDisplayData[1][curSample]; curY = 0.5 + (curValue * theScaleFactor) + myYOffsets[inTrace]; ! [myTracePaths[inTrace] addPoint: NSMakePoint(curX, curY)]; } break; *************** *** 322,326 **** myDisplayData[1][curSample]); curY = 0.5 + (curValue * theScaleFactor) + myYOffsets[inTrace]; ! [myBezierPaths[inTrace] lineToPoint: NSMakePoint(curX, curY)]; } break; --- 322,326 ---- myDisplayData[1][curSample]); curY = 0.5 + (curValue * theScaleFactor) + myYOffsets[inTrace]; ! [myTracePaths[inTrace] addPoint: NSMakePoint(curX, curY)]; } break; *************** *** 331,335 **** myDisplayData[1][curSample]); curY = 0.5 + (curValue * theScaleFactor) + myYOffsets[inTrace]; ! [myBezierPaths[inTrace] lineToPoint: NSMakePoint(curX, curY)]; } break; --- 331,335 ---- myDisplayData[1][curSample]); curY = 0.5 + (curValue * theScaleFactor) + myYOffsets[inTrace]; ! [myTracePaths[inTrace] addPoint: NSMakePoint(curX, curY)]; } break; Index: XYPlotView.m =================================================================== RCS file: /cvsroot/scopeapp/scopeapp/src/XYPlotView.m,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** XYPlotView.m 9 Jan 2003 04:44:59 -0000 1.8 --- XYPlotView.m 10 Jan 2003 10:49:27 -0000 1.9 *************** *** 91,95 **** { [myDisplayLock lock]; ! [myBezierPaths[1] removeAllPoints]; [myDisplayLock unlock]; return self; --- 91,95 ---- { [myDisplayLock lock]; ! [myTracePaths[1] removeAllPoints]; [myDisplayLock unlock]; return self; *************** *** 100,108 **** [myDisplayLock lock]; ! [myBezierPaths[0] removeAllPoints]; curX = 0.5 + (myDisplayData[0][0] * theScaleFactor[0]); curY = 0.5 + (myDisplayData[1][0] * theScaleFactor[0]); ! [myBezierPaths[0] moveToPoint: NSMakePoint(curX, curY)]; for(curSample = 0; --- 100,108 ---- [myDisplayLock lock]; ! [myTracePaths[0] removeAllPoints]; curX = 0.5 + (myDisplayData[0][0] * theScaleFactor[0]); curY = 0.5 + (myDisplayData[1][0] * theScaleFactor[0]); ! [myTracePaths[0] addPoint: NSMakePoint(curX, curY)]; for(curSample = 0; *************** *** 112,116 **** curX = 0.5 + (myDisplayData[0][curSample] * theScaleFactor[0]); curY = 0.5 + (myDisplayData[1][curSample] * theScaleFactor[0]); ! [myBezierPaths[0] lineToPoint: NSMakePoint(curX, curY)]; } --- 112,116 ---- curX = 0.5 + (myDisplayData[0][curSample] * theScaleFactor[0]); curY = 0.5 + (myDisplayData[1][curSample] * theScaleFactor[0]); ! [myTracePaths[0] addPoint: NSMakePoint(curX, curY)]; } |