←Select platform

Calibrate Method

Summary
Sets the ruler calibration scale.
Syntax
C#
Objective-C
C++/CLI
Java
Python
- (void)calibrate:(LeadLengthD)sourceLength sourceUnit:(LTAnnUnit)sourceUnit destinationLength:(LeadLengthD)destinationLength destinationUnit:(LTAnnUnit)destinationUnit NS_SWIFT_NAME(calibrate(sourceLength:sourceUnit:destinationLength:destinationUnit:)); 
public void calibrate( 
   LeadLengthD sourceLength, 
   AnnUnit sourceUnit, 
   LeadLengthD destinationLength, 
   AnnUnit destinationUnit 
) 

Parameters

sourceLength
Known source length value

sourceUnit
Units of  sourceLength

destinationLength
What the destination length must be

destinationUnit
Units of  destinationUnit

Remarks

This method will use the parameters to calculate a new value for CalibrationScale. This value is used afterwards by all the existing ruler and new ruler objects created in this container.

The value of destinationUnit is set into CalibrationUnit and will be used as the default unit for all new ruler objects created in this container after this method has been called.

Calibrating a ruler means assigning a specific length to it. For example, on a digital X-ray of a hand, you may draw an annotation ruler object along one of the fingers. You know that this distance is supposed to be exactly 6.5 cm. Using the new calibration functionality you can calibrate this ruler, all existing rulers, and all newly created rulers so that they would precisely measure this distance to be 6.5 cm. This is accomplished by first drawing a ruler on the container till it matches exactly the length of the finger - ignoring the values shown - then using Calibrate as shown in the example.

Use AnnPolyRulerObject.Calibrate to set individual calibration values for a single ruler.

Example

This example will draw a ruler with a length that is assumed is 6.5cm, it then uses Calibrate to set the mapper calibration scale.

C#
Java
using Leadtools.Annotations.Engine; 
 
public void AnnContainerMapper_Calibrate() 
{ 
 
   // Add a ruler with a length of 1 inch to the container 
   AnnContainer container = new AnnContainer(); 
 
   double inch = 720; 
   AnnPolyRulerObject rulerObj = new AnnPolyRulerObject(); 
   rulerObj.Points.Add(LeadPointD.Create(1 * inch, 1 * inch)); 
   rulerObj.Points.Add(LeadPointD.Create(2 * inch, 1 * inch)); 
   rulerObj.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("Red"), LeadLengthD.Create(1)); 
   rulerObj.ShowGauge = true; 
   rulerObj.ShowTickMarks = true; 
   rulerObj.MeasurementUnit = AnnUnit.Inch; 
   container.Children.Add(rulerObj); 
 
   // Show the ruler 
   Debug.WriteLine("Ruler to calibrate, length is 1 inch"); 
 
   // Get the length of the ruler 
   LeadPointD point1 = rulerObj.Points[0]; 
   LeadPointD point2 = rulerObj.Points[1]; 
   double length = Math.Sqrt(Math.Pow(Math.Abs(point2.X - point1.X), 2) + Math.Pow(Math.Abs(point2.Y - point1.Y), 2)); 
 
   // Calibrate the container mapper 
   container.Mapper.Calibrate( 
      LeadLengthD.Create(length),   // Source length 
      AnnUnit.Unit,                       // Source unit (container units) 
      LeadLengthD.Create(6.5),      // Destination length 
      AnnUnit.Centimeter);                // Destination unit  
 
   // Use the Centimeters as the measurement unit in the ruler 
   rulerObj.MeasurementUnit = AnnUnit.Centimeter; 
 
   // Now rulerObj should show 6.5 Centimeter as its length 
   Debug.WriteLine("Calibrated, length is 6.5 cm"); 
} 
 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.Test; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.annotations.engine.*; 
 
 
public void annContainerMapperCalibrateExample() { 
 
   // Add a ruler with a length of 1 inch to the container 
   AnnContainer container = new AnnContainer(); 
 
   double inch = 720; 
   AnnPolyRulerObject rulerObj = new AnnPolyRulerObject(); 
   rulerObj.getPoints().add(LeadPointD.create(1 * inch, 1 * inch)); 
   rulerObj.getPoints().add(LeadPointD.create(2 * inch, 1 * inch)); 
   rulerObj.setStroke(AnnStroke.create(AnnSolidColorBrush.create("Red"), LeadLengthD.create(1))); 
   rulerObj.setShowGauge(true); 
   rulerObj.setShowTickMarks(true); 
   rulerObj.setMeasurementUnit(AnnUnit.INCH); 
   container.getChildren().add(rulerObj); 
 
   assertTrue("Guage is not correctly set", rulerObj.getShowGauge() == true); 
   assertTrue("Tick marks are not correctly set", rulerObj.getShowTickMarks() == true); 
   assertTrue("Measurement unit is not set to inch", rulerObj.getMeasurementUnit() == AnnUnit.INCH); 
 
   // Show the ruler 
   System.out.println("Ruler to calibrate, length is 1 inch"); 
 
   // Get the length of the ruler 
   LeadPointD point1 = rulerObj.getPoints().get(0); 
   LeadPointD point2 = rulerObj.getPoints().get(1); 
   double length = Math.sqrt(Math.pow(Math.abs(point2.getX() - point1.getX()), 2) 
         + Math.pow(Math.abs(point2.getY() - point1.getY()), 2)); 
 
   // Calibrate the container mapper 
   container.getMapper().calibrate( 
         LeadLengthD.create(length), // Source length 
         AnnUnit.UNIT, // Source unit (container units) 
         LeadLengthD.create(6.5), // Destination length 
         AnnUnit.CENTIMETER); // Destination unit 
 
   // Use the Centimeters as the measurement unit in the ruler 
   rulerObj.setMeasurementUnit(AnnUnit.CENTIMETER); 
   assertTrue("Measurement unit incorrectly set", rulerObj.getMeasurementUnit() == AnnUnit.CENTIMETER); 
 
   // Now rulerObj should show 6.5 Centimeter as its length 
   assertTrue("Length differs from expected 6.5cm", rulerObj.getPoints().size() == 2); 
   System.out.println("Calibrated, length is 6.5 cm"); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Annotations.Engine Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.