Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hi
- I have a view (holderview) which I add to it a uiimageview as following
- holderView=[[UIView alloc] init];
- //[holderView setFrame:[self.view frame]];
- holderView.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height );
- if(imageview.image!=nil)
- {
- imageview.image=nil;
- [imageview.image release];
- }
- imageview = [[UIImageView alloc] init];
- imageview.frame=CGRectMake(0,0,holderView.frame.size.width,holderView.frame.size.height );
- [imageview setImage:cppobject->OutputImage];
- imageview.contentMode = UIViewContentModeScaleAspectFit;
- [holderView addSubview:imageview];
- holderView.contentMode = UIViewContentModeScaleAspectFit ;
- UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
- [pinchRecognizer setDelegate:self];
- [holderView addGestureRecognizer:pinchRecognizer];
- [pinchRecognizer release];
- UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
- [rotationRecognizer setDelegate:self];
- [holderView addGestureRecognizer:rotationRecognizer];
- [rotationRecognizer release];
- panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
- [panRecognizer setMinimumNumberOfTouches:1];
- [panRecognizer setMaximumNumberOfTouches:1];
- [panRecognizer setDelegate:self];
- [holderView addGestureRecognizer:panRecognizer];
- /* the function for gesture */
- then I add another uiview to draw a line on it
- DrawLine = [[MeasuringLayer alloc] init];
- DrawLine.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height );
- DrawLine.opaque = NO;
- DrawLine.backgroundColor = [UIColor clearColor];
- DrawLine.tag = 202 ;
- pinchRecognizerMeasure = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(MeasureAndDraw:)];
- [pinchRecognizerMeasure setDelegate:self];
- [DrawLine addGestureRecognizer:pinchRecognizerMeasure];
- [pinchRecognizerMeasure release];
- /*For keeping window Width and Level*/
- panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
- [panRecognizer setMinimumNumberOfTouches:1];
- [panRecognizer setMaximumNumberOfTouches:1];
- [panRecognizer setDelegate:self];
- [DrawLine addGestureRecognizer:panRecognizer];
- [self.view addSubview: DrawLine];
- my problem is that I want to draw a line and get it its actual size I work with DICOM
- I use the following code to get the distance , it work well with 90, 180, 270,0 angle rotation but it fail with other angels
- - (void) DisplayDistance {
- for (UIView *subview in [DrawLine subviews])
- {
- if (subview.tag==203)
- {
- [subview removeFromSuperview];
- }
- }
- CGFloat Width , Height , ScaleFactor ,radians ;
- for (UIView *subview in [self.view subviews])
- {
- if (subview.tag==101)
- {
- if ([subview isEqual:holderView]) {
- NSLog(@"holder view is pointing correctly");
- }else {
- NSLog(@"holder view is not pointing correctly");
- }
- Width = subview.frame.size.width ;
- Height = subview.frame.size.height ;
- Origin = subview.frame.origin ;
- ScaleFactor = subview.contentScaleFactor ;
- radians = atan2f(subview.transform.b, subview.transform.a);
- NSLog(@" Angel ---------->%f",(radians *180 / M_PI)) ;
- }
- }
- /*Zooming Area */
- CGFloat ZoomX =Width / (float ) cppobject->Width ;
- NSLog(@"ZoomX %f",ZoomX);
- NSLog(@"Width form %f ", Width);
- NSLog(@"Width width %f", (float ) cppobject->Width );
- CGFloat ZoomY = Height / (float ) cppobject->Height ;
- NSLog(@"Width form %f", Height );
- NSLog(@"Width width %f", (float ) cppobject->Height );
- NSLog(@"ZoomY %f",ZoomY);
- CGFloat minimmum ;
- if (ZoomX > ZoomY ) {
- minimmum = ZoomY;
- }
- else {
- minimmum = ZoomX;
- }
- /**/
- CGPoint outTL = [self RotatePoint:CGPointMake(0, 0) WithAngle:radians];
- CGPoint outTR = [self RotatePoint:CGPointMake((CGFloat) Width , 0) WithAngle:radians];
- CGPoint outBL = [self RotatePoint:CGPointMake(0,(CGFloat) Height ) WithAngle:radians];
- CGPoint outBR = [self RotatePoint:CGPointMake((CGFloat) Width ,(CGFloat) Height ) WithAngle:radians];
- NSLog(@" Width %f",(CGFloat) cppobject->Width ) ;
- NSLog(@" HEight %f",(CGFloat) cppobject->Height ) ;
- CGFloat temp1 = MIN(outTL.x ,outTR.x) ;
- CGFloat temp2 =MIN( outBL.x,outBR.x );
- CGFloat xtrans = MIN(temp1,temp2) ;
- temp1 =MIN( outTL.y,outTR.y );
- temp2 =MIN( outBL.y,outBR.y );
- CGFloat ytrans = MIN(temp1,temp2) ;
- NSLog(@"minimmum %f",minimmum);
- CGPoint BitmapStart , BitmapEnd ;
- ////////////// Zooming
- BitmapStart = CGPointMake( ( ( ( DrawLine.startPoint.x * ScaleFactor ) - Origin.x ) / minimmum ) , ( ( ( DrawLine.startPoint.y * ScaleFactor ) - Origin.y ) / minimmum ) ) ;
- ///////////////// Rotation
- BitmapStart = [self RotatePoint:BitmapStart WithAngle:radians];
- /////////////// Translation
- BitmapStart.x = BitmapStart.x - xtrans ;
- BitmapStart.y =BitmapStart.y - ytrans ;
- /*CGAffineTransform tr_BitmapStart = CGAffineTransformMakeRotation(radians);
- BitmapStart= CGPointApplyAffineTransform(BitmapStart, tr_BitmapStart );*/
- BitmapEnd = CGPointMake( ( ( ( DrawLine.endPoint.x * ScaleFactor ) - Origin.x ) / minimmum ) , ( ( ( DrawLine.endPoint.y * ScaleFactor) - Origin.y ) / minimmum ) ) ;
- NSLog(@"BitmapEnd Before %f , %f", BitmapEnd.x ,BitmapEnd.y );
- BitmapEnd = [self RotatePoint:BitmapEnd WithAngle:radians];
- NSLog(@"BitmapEnd Before %f , %f", BitmapEnd.x ,BitmapEnd.y );
- /////////////// Translation
- BitmapEnd.x = BitmapEnd.x - xtrans ;
- BitmapEnd.y =BitmapEnd.y - ytrans ;
- NSLog(@"BitmapEnd Before %f , %f", BitmapEnd.x ,BitmapEnd.y );
- //CGAffineTransform tr_BitmapEnd = CGAffineTransformMakeRotation(radians); BitmapEnd= CGPointApplyAffineTransform(BitmapEnd, tr_BitmapEnd );
- NSLog(@"BitmapEnd After Rotation %f", BitmapEnd );
- UILabel *Distance = [[UILabel alloc] initWithFrame:CGRectMake(DrawLine.endPoint.x, DrawLine.endPoint.y ,100, 20)];
- Distance.layer.cornerRadius=10;
- Distance.tag = 203 ;
- Distance.backgroundColor =[UIColor greenColor];
- Distance.textColor =[UIColor blackColor];
- //holderView.bounds.size.width ;
- //holderView.bounds.size.height ;
- CGFloat part1 =pow( ( ( ( BitmapEnd.x /** holderView.contentScaleFactor */ ) - ( BitmapStart.x /** holderView.contentScaleFactor*/ ) ) * cppobject->PixelSpacing.x ) , 2 ) ;
- NSLog(@"part1 %f",part1);
- CGFloat part2 =pow( ( ( ( BitmapEnd.y /** holderView.contentScaleFactor */ ) - ( BitmapStart.y /** holderView.contentScaleFactor*/ ) ) * cppobject->PixelSpacing.y ) , 2 ) ;
- NSLog(@"part2 %f",part2);
- CGFloat Result = sqrt( (part1 + part2) ) /10;
- NSLog(@"Result %f",Result);
- Distance.text= [NSString stringWithFormat: @"%.2f Cm", Result ];
- [DrawLine addSubview: Distance] ;
- /*CGPoint StartPointConversion = [DrawLine convertPoint:DrawLine.startPoint toView:imageview.superview ];
- CGPoint EndPointConversion = [DrawLine convertPoint:DrawLine.endPoint toView:imageview.superview ];
- NSLog(@" Begin X %f , Begin Y %f" ,StartPointConversion.x , StartPointConversion.y ) ;
- NSLog(@" End X %f , End Y %f" ,EndPointConversion.x , EndPointConversion.y ) ;
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement