Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Hi
  2.  
  3. I have a view (holderview) which I add to it a uiimageview  as following
  4.  
  5. holderView=[[UIView  alloc] init];
  6.     //[holderView setFrame:[self.view frame]];
  7.    
  8.     holderView.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height  );
  9.    
  10.     if(imageview.image!=nil)
  11.     {
  12.         imageview.image=nil;
  13.         [imageview.image release];
  14.     }
  15.    
  16.     imageview = [[UIImageView alloc] init];
  17.     imageview.frame=CGRectMake(0,0,holderView.frame.size.width,holderView.frame.size.height  );
  18.    
  19.     [imageview setImage:cppobject->OutputImage];
  20.     imageview.contentMode = UIViewContentModeScaleAspectFit;
  21.    
  22.     [holderView addSubview:imageview];
  23.     holderView.contentMode = UIViewContentModeScaleAspectFit ;
  24.    
  25.     UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
  26.     [pinchRecognizer setDelegate:self];
  27.     [holderView addGestureRecognizer:pinchRecognizer];
  28.     [pinchRecognizer release];
  29.    
  30.     UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
  31.     [rotationRecognizer setDelegate:self];
  32.     [holderView addGestureRecognizer:rotationRecognizer];
  33.     [rotationRecognizer release];
  34.    
  35.     panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
  36.     [panRecognizer setMinimumNumberOfTouches:1];
  37.     [panRecognizer setMaximumNumberOfTouches:1];
  38.     [panRecognizer setDelegate:self];
  39.     [holderView addGestureRecognizer:panRecognizer];
  40.    
  41.    
  42. /* the function for gesture */
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. then I add another uiview to draw a line on it
  50. DrawLine = [[MeasuringLayer alloc] init];
  51.        
  52.         DrawLine.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height  );
  53.        
  54.     DrawLine.opaque = NO;
  55.     DrawLine.backgroundColor = [UIColor clearColor];
  56.    
  57.     DrawLine.tag = 202 ;
  58.  
  59.    
  60.     pinchRecognizerMeasure = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(MeasureAndDraw:)];
  61.     [pinchRecognizerMeasure setDelegate:self];
  62.     [DrawLine addGestureRecognizer:pinchRecognizerMeasure];
  63.     [pinchRecognizerMeasure release];
  64.    
  65.    
  66.     /*For keeping window Width and Level*/
  67.    
  68.     panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
  69.     [panRecognizer setMinimumNumberOfTouches:1];
  70.     [panRecognizer setMaximumNumberOfTouches:1];
  71.     [panRecognizer setDelegate:self];
  72.     [DrawLine addGestureRecognizer:panRecognizer];
  73.    
  74.     [self.view addSubview: DrawLine];
  75.  
  76.  
  77.  
  78. my problem is that I want to draw a line and get it its actual size I work with DICOM
  79.  
  80. 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
  81.  
  82.  
  83. - (void) DisplayDistance {
  84.  
  85.      
  86.     for (UIView *subview in [DrawLine subviews])
  87.     {
  88.         if (subview.tag==203)
  89.         {
  90.             [subview removeFromSuperview];
  91.         }
  92.        
  93.          
  94.     }
  95.    
  96.     CGFloat Width ,  Height , ScaleFactor ,radians ;
  97.    
  98.     for (UIView *subview in [self.view subviews])
  99.     {
  100.         if (subview.tag==101)
  101.         {
  102.            
  103.            
  104.             if ([subview isEqual:holderView]) {
  105.                 NSLog(@"holder view is pointing correctly");
  106.             }else {
  107.                 NSLog(@"holder view is not pointing correctly");
  108.             }
  109.            
  110.            
  111.             Width = subview.frame.size.width ;
  112.             Height = subview.frame.size.height ;
  113.             Origin = subview.frame.origin ;
  114.            
  115.             ScaleFactor = subview.contentScaleFactor ;
  116.            
  117.            
  118.              radians = atan2f(subview.transform.b, subview.transform.a);
  119.            
  120.             NSLog(@"  Angel ---------->%f",(radians *180 / M_PI)) ;
  121.            
  122.            
  123.            
  124.            
  125.              
  126.         }
  127.  
  128.  
  129.     }
  130.    
  131.     /*Zooming Area */
  132.  
  133.     CGFloat ZoomX =Width / (float ) cppobject->Width  ;
  134.    
  135.     NSLog(@"ZoomX  %f",ZoomX);
  136.    
  137.     NSLog(@"Width form %f ", Width);
  138.     NSLog(@"Width width %f", (float )  cppobject->Width  );
  139.    
  140.     CGFloat ZoomY = Height / (float )  cppobject->Height  ;
  141.    
  142.     NSLog(@"Width form %f", Height );
  143.     NSLog(@"Width width %f", (float ) cppobject->Height  );
  144.    
  145.    
  146.     NSLog(@"ZoomY  %f",ZoomY);
  147.    
  148.     CGFloat minimmum ;
  149.    
  150.     if (ZoomX > ZoomY ) {
  151.         minimmum = ZoomY;
  152.     }
  153.     else {
  154.        
  155.     minimmum = ZoomX;
  156.        
  157.     }
  158.    
  159.     /**/
  160.    
  161.      
  162.     CGPoint outTL = [self RotatePoint:CGPointMake(0, 0) WithAngle:radians];
  163.     CGPoint outTR = [self RotatePoint:CGPointMake((CGFloat) Width  , 0) WithAngle:radians];
  164.     CGPoint outBL = [self RotatePoint:CGPointMake(0,(CGFloat) Height  ) WithAngle:radians];
  165.     CGPoint outBR = [self RotatePoint:CGPointMake((CGFloat) Width  ,(CGFloat) Height  ) WithAngle:radians];
  166.    
  167.     NSLog(@" Width %f",(CGFloat) cppobject->Width ) ;
  168.     NSLog(@" HEight %f",(CGFloat) cppobject->Height ) ;
  169.    
  170.    
  171.     CGFloat temp1 = MIN(outTL.x ,outTR.x) ;
  172.    
  173.     CGFloat temp2 =MIN( outBL.x,outBR.x );
  174.     CGFloat xtrans = MIN(temp1,temp2) ;
  175.    
  176.     temp1 =MIN( outTL.y,outTR.y );
  177.     temp2 =MIN( outBL.y,outBR.y );
  178.     CGFloat ytrans = MIN(temp1,temp2) ;
  179.    
  180.    
  181.    
  182.    
  183.    
  184.     NSLog(@"minimmum  %f",minimmum);
  185.    
  186.    
  187.    
  188.     CGPoint BitmapStart , BitmapEnd ;
  189.    
  190.    
  191.     ////////////// Zooming
  192.    
  193.     BitmapStart = CGPointMake(  ( ( ( DrawLine.startPoint.x * ScaleFactor ) - Origin.x ) / minimmum )  , ( ( ( DrawLine.startPoint.y * ScaleFactor ) - Origin.y ) / minimmum ) ) ;
  194.    
  195.     ///////////////// Rotation
  196.     BitmapStart = [self RotatePoint:BitmapStart WithAngle:radians];
  197.    
  198.     /////////////// Translation
  199.    
  200.     BitmapStart.x = BitmapStart.x - xtrans ;
  201.     BitmapStart.y =BitmapStart.y - ytrans ;
  202.    
  203.     /*CGAffineTransform tr_BitmapStart = CGAffineTransformMakeRotation(radians);
  204.    
  205.     BitmapStart= CGPointApplyAffineTransform(BitmapStart, tr_BitmapStart );*/
  206.    
  207.    
  208.     BitmapEnd = CGPointMake(  ( ( ( DrawLine.endPoint.x * ScaleFactor ) - Origin.x ) / minimmum )  , ( ( ( DrawLine.endPoint.y * ScaleFactor) - Origin.y ) / minimmum ) ) ;
  209.    
  210.    
  211.     NSLog(@"BitmapEnd Before %f , %f", BitmapEnd.x ,BitmapEnd.y );
  212.    
  213.    
  214.     BitmapEnd  = [self RotatePoint:BitmapEnd WithAngle:radians];
  215.    
  216.    
  217.         NSLog(@"BitmapEnd Before %f , %f", BitmapEnd.x ,BitmapEnd.y );
  218.    
  219.     /////////////// Translation
  220.    
  221.     BitmapEnd.x = BitmapEnd.x - xtrans ;
  222.     BitmapEnd.y =BitmapEnd.y - ytrans ;
  223.    
  224.         NSLog(@"BitmapEnd Before %f , %f", BitmapEnd.x ,BitmapEnd.y );
  225.    
  226.    
  227.     //CGAffineTransform tr_BitmapEnd = CGAffineTransformMakeRotation(radians); BitmapEnd= CGPointApplyAffineTransform(BitmapEnd, tr_BitmapEnd );
  228.    
  229.    
  230.     NSLog(@"BitmapEnd After Rotation %f", BitmapEnd );
  231.    
  232.    
  233.     UILabel *Distance = [[UILabel alloc] initWithFrame:CGRectMake(DrawLine.endPoint.x, DrawLine.endPoint.y ,100, 20)];
  234.    
  235.    
  236.    
  237.     Distance.layer.cornerRadius=10;
  238.    
  239.     Distance.tag = 203 ;
  240.    
  241.     Distance.backgroundColor  =[UIColor greenColor];
  242.     Distance.textColor =[UIColor blackColor];
  243.    
  244.     //holderView.bounds.size.width ;
  245.     //holderView.bounds.size.height  ;
  246.    
  247.    
  248.     CGFloat part1 =pow( ( ( ( BitmapEnd.x  /** holderView.contentScaleFactor */ ) - ( BitmapStart.x  /** holderView.contentScaleFactor*/  )  ) * cppobject->PixelSpacing.x ) , 2 ) ;
  249.    
  250.     NSLog(@"part1  %f",part1);
  251.    
  252.     CGFloat part2 =pow( ( ( ( BitmapEnd.y  /** holderView.contentScaleFactor */ ) - ( BitmapStart.y  /** holderView.contentScaleFactor*/  )  ) * cppobject->PixelSpacing.y ) , 2 ) ;
  253.    
  254.     NSLog(@"part2  %f",part2);
  255.    
  256.    
  257.     CGFloat Result = sqrt( (part1 + part2) ) /10;
  258.    
  259.     NSLog(@"Result  %f",Result);
  260.    
  261.    
  262.     Distance.text= [NSString stringWithFormat: @"%.2f Cm", Result ];
  263.    
  264.     [DrawLine addSubview: Distance] ;
  265.    
  266.     /*CGPoint StartPointConversion = [DrawLine convertPoint:DrawLine.startPoint toView:imageview.superview ];
  267.     CGPoint EndPointConversion = [DrawLine convertPoint:DrawLine.endPoint toView:imageview.superview ];
  268.        
  269.     NSLog(@" Begin X %f , Begin Y %f" ,StartPointConversion.x , StartPointConversion.y ) ;
  270.     NSLog(@" End X %f , End Y %f" ,EndPointConversion.x , EndPointConversion.y ) ;                        
  271.     */
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement