Operators |
read_object_model_3d — Read a 3D object model from a file.
read_object_model_3d( : : FileName, Scale, GenParamName, GenParamValue : ObjectModel3D, Status)
The operator read_object_model_3d reads a 3D object model from the file FileName and returns a 3D object model handle in ObjectModel3D.
The operator supports the following file formats:
HALCON format for 3D object model. Files with this format can be written by write_object_model_3d. The default file extension for this format is 'om3'.
AUTOCAD format. See below for details about reading this file format. The default file extension for this format is 'dxf'.
Object File Format. This is a simple ASCII-based format that can hold 3D points and polygons. The binary OFF format is not supported. The default file extension for this format is 'off'.
Polygon File Format (also Stanford Triangle Format). This is a simple format that can hold 3D points, point normals, polygons, color information and point-based extended attributes. HALCON supports both the ASCII and the binary version of the format. If the file to be read contains unsupported information, the additional data is ignored for ASCII files and only the supported data is read. For binary versions of the format, an error is returned in this case and no object model is returned. The default file extension for this format is 'ply'.
OBJ file format, also 'Wavefront OBJ-Format'. This is an ASCII-based format that can hold 3D points, polygons, normals, texture coordinates, materials and other information. HALCON supports points ('v'-lines) and polygonal faces ('f'-lines). Other entities are ignored. The default file extension for this format is 'obj'.
STL file format, also 'Stereolithography format', 'SurfaceTesselationLanguage ', 'StandardTriangulationLanguage', and 'StandardTesselationLanguage'. This format stores triangles and triangle normals. However, as triangle normals are not supported by HALCON 3D object models, only triangles are read while the triangle normals are ignored. Normals are recomputed from the triangles if required. HALCON reads both the ASCII and the binary version of this format. If 'stl' is set, HALCON will autodetect the type. Setting the type to 'stl_binary' or 'stl_ascii' will enforce the corresponding format. The default file extension for this format is 'stl'.
When reading a DXF file, the output parameter Status contains information about the number of 3D faces that were read and, if necessary, warnings that parts of the DXF file could not be interpreted.
The parameter Scale defines the scale of the file. For example, if the parameter is set to 'mm' , all units in the file are assumed to have the unit 'mm' and are transformed into the usual HALCON-internal unit 'm' by multiplication with 1e-3. A value of '100 mm' thus becomes '0.1 m' . Alternatively, a scaling factor can be passed to Scale, which is multiplied with all coordinate values found in the file. The relation of units to scaling factors is given in the following table:
Unit | Scaling factor |
---|---|
m | 1 |
dm | 0.1 |
cm | 0.01 |
mm | 0.001 |
µm, microns | 1e-6 |
nm | 1e-9 |
km | 1000 |
in | 0.0254 |
ft | 0.3048 |
yd | 0.9144 |
Note that the parameter Scale is ignored for files of type 'om3' , i.e., om3-files are always read without any scale changes. For changing the scale manually after reading a 3D object model, use affine_trans_object_model_3d.
A set of additional optional parameters can be set. The names and values of the parameters are passed in GenParamName and GenParamValue, respectively. Some of the optional parameters can only be set for a certain file type. The following values for GenParamName are possible:
Forces a file type. If this parameter is not set, the operator read_object_model_3d tries to auto-detect the file type using the file ending and the file header. If the parameter is set, the given file is interpreted as this file format.
Value list: 'om3' , 'dxf' , 'off' , 'ply' , 'obj' , 'stl'
Convert all faces to triangles. If this parameter is set to 'true' , all faces read from the file are converted to triangles.
Value list: 'true' , 'false'
Default value: 'false'
Valid for formats: 'dxf' , 'ply' , 'off' , 'obj'
Invert normals and face orientations. If this parameter is set to 'true' , the orientation of all normals and faces is inverted.
Value list: 'true' , 'false'
Default value: 'false'
Valid for formats: 'dxf' , 'ply' , 'off' , 'obj' , 'stl'
DXF-specific parameters (see below).
Valid for formats: 'dxf'
Creates for the read 3D object model a mapping that assigns an image coordinate to each read 3D point, as in xyz_to_object_model_3d. It is assumed that the read file contains the 3D points row-wise. The passed value is used as width of the image. The height of the image is computed automatically. If this parameter is set, the read 3D object model can be projected by object_model_3d_to_xyz using the method 'from_xyz_map' . Only one of the two parameters 'xyz_map_width' and 'xyz_map_height' can be set.
Assertion: 'xyz_map_width' > 0 Default value: -1
Valid for formats: 'ply' , 'off' , 'obj'
As 'xyz_map_width' , but assuming that the 3D points are aligned column-wise. The width of the image is computed automatically. Only one of the two parameters 'xyz_map_width' and 'xyz_map_height' can be set.
Assertion: 'xyz_map_height' > 0 Default value: -1
Valid for formats: 'ply' , 'off' , 'obj'
The operator read_object_model_3d supports the following DXF entities:
POLYLINE
Polyface meshes (Polyline flag 64)
3D Polylines (Polyline flag 8,9)
2D Polylines (Polyline flag 0)
LWPOLYLINE
2D Polylines
3DFACE
LINE
CIRCLE
ARC
SOLID
BLOCK
INSERT
The two-dimensional linear DXF entities LINE, CIRCLE and ARC are not interpreted as faces. Only if these elements are extruded, the resulting faces are inserted in the 3D object model. All elements that represent no faces but lines are added as 3D lines to the 3D object model.
The curved surface of extruded DXF entities of the type CIRCLE and ARC is approximated by planar faces. The accuracy of this approximation can be controlled with the two generic parameters 'min_num_points' and 'max_approx_error' . The parameter 'min_num_points' defines the minimum number of sampling points that are used for the approximation of the DXF element CIRCLE or ARC. Note that the parameter 'min_num_points' always refers to the full circle, even for ARCs, i.e., if 'min_num_points' is set to 50 and a DXF entity of the type ARC is read that represents a semi-circle, this semi-circle is approximated by at least 25 sampling points. The parameter 'max_approx_error' defines the maximum deviation of the XLD contour from the ideal circle. The determination of this deviation is carried out in the units used in the DXF file. For the determination of the accuracy of the approximation both criteria are evaluated. Then, the criterion that leads to the more accurate approximation is used.
Internally, the following default values are used for the generic parameters:
'min_num_points' = 20
'max_approx_error' = 0.25
To achieve a more accurate approximation, either the value for 'min_num_points' must be increased or the value for 'max_approx_error' must be decreased.
One possible way to create a suitable DXF file is to create a 3D model of the object with the CAD program AutoCAD. Ensure that the surface of the object is modeled, not only its edges. Lines that, e.g., define object edges, will not be used by HALCON, because they do not define the surface of the object. Once the modeling is completed, you can store the model in DWG format. To convert the DWG file into a DXF file that is suitable for HALCON's 3D matching, carry out the following steps:
Export the 3D CAD model to a 3DS file using the 3dsout command of AutoCAD. This will triangulate the object's surface, i.e., the model will only consist of planes. (Users of AutoCAD 2007 or newer versions can download this command utility from Autodesk's web site.)
Open a new empty sheet in AutoCAD.
Import the 3DS file into this empty sheet with the 3dsin command of AutoCAD.
Save the object into a DXF R12 file.
Users of other CAD programs should ensure that the surface of the 3D model is triangulated before it is exported into the DXF file. If the CAD program is not able to carry out the triangulation, it is often possible to save the 3D model in the proprietary format of the CAD program and to convert it into a suitable DXF file by using a CAD file format converter that is able to perform the triangulation.
Note that if a 3D object model is no longer needed or should be overwritten, the memory has to be freed first by calling the operator clear_object_model_3d.
This operator returns a handle. Note that the state of an instance of this handle type may be changed by specific operators even though the handle is used as an input parameter by those operators.
Filename of the file to be read.
File extension: .off, .ply, .dxf, .om3, .obj, .stl
Scale of the data in the file.
Default value: 'm'
Suggested values: 'm' , 'cm' , 'mm' , 'microns' , 'µm' , 'microns' , 'nm' , 'km' , 'in' , 'ft' , 'yd' , 1.0, 0.01, 0.001, 1.0e-6, 0.0254, 0.3048, 0.9144
Names of the generic parameters.
Default value: []
List of values: 'convert_to_triangles' , 'file_type' , 'invert_normals' , 'max_approx_error' , 'min_num_points' , 'xyz_map_height' , 'xyz_map_width'
Values of the generic parameters.
Default value: []
Suggested values: 'true' , 'false' , 1, 0, 'om3' , 'off' , 'ply' , 'dxf' , 'obj' , 'stl' , 'stl_binary' , 'stl_ascii'
Handle of the 3D object model.
Status information.
The operator read_object_model_3d returns the value 2 (H_MSG_TRUE) if the given parameters are correct, the file can be read, and the file is valid. If the file format is unknown or cannot be determined, the error 9512 is raised. If the file is invalid, the error 9510 is raised. If necessary, an exception will be raised.
affine_trans_object_model_3d, object_model_3d_to_xyz, prepare_object_model_3d
write_object_model_3d, clear_object_model_3d
3D Metrology
Operators |