DG Kernel (ActiveX) Documentation


Skip Navigation Links.
Start page
Quick Start
Search Page
Installation
What is new
Upgrading Native Apps
Licensing
Collapse ModelsModels
Collapse DG Kernel ControlsDG Kernel Controls
Collapse API ReferenceAPI Reference
Interface List
Vector Space
Collapse General GeometryGeneral Geometry
Collapse ModelModel
Collapse ViewView
Collapse General ComputingGeneral Computing
Collapse ViewsViews
Collapse Samples and TutorialsSamples and Tutorials
Collapse GraphicsGraphics
Collapse Math ObjectsMath Objects
Collapse DeprecatedDeprecated
Redistribution
Model Viewer
Open Source
Support
Skip Navigation Links Go to DGKC docs Search Documentation


Metrics2 C++ Sample

Metrics is an MFC dialogue based application, which demonstrates calculation of distances, and nearest points between two objects and usage of IMetrics.Dist method. Metrics2 is an enhanced version of Metrics sample. Metrics2 demonstrates additionally how case when there are many points which have the same distance to another object is handled. It also demonstrates usage of "Include Children" property in distance calculations.

Source code for Metrics sample is available in Samples\VC\Metrics2 folder of the installation directory. It is recommended to copy the folder to location outside of the installation folder.

Running the application  

The application expects the model to have at least two top level objects. Names of the first and the second objects are displayed on the right hand side of the form. The Calculate button calculates distances between the two objects and displays the result in 3D view.

By default pairs of nearest points are rendered connected with a red segment in 3D view. Check boxes in the Display group allow to turning on and off rendering shortest distances, nearest points and normals.

When "Find All" check box is on, all pairs of nearest points (at the same distances in this sample) are found and displayed. More.

"Include Children" check box forces the algorithm to consider children of both objects as single object with its parent. In the default Dist,glm model the cylinder is a child of the box object.

The Move Object control group allows changing position and orientation of either of the two objects. The movement is performed relative to the current location and orientation of the local frame of the object. Show check box displays or hides the local frame.

The "Is Closer Than" controls allow to determine whether the objects are closer than the distance specified in the edit box.

File menu allows loading new and saving the current model.

Implementation

All DG Kernel related functionality is implemented inside the MetricsDlg class. The DG Kernel related data is initialized inside InitModelInfo() method, which uses GetModel method of the DG Kernel control to obtain the root interface of the hierarchy. ISection interfaces, representing generic DG Kernel object, are obtained for the first two top level objects of the model with the help of IModel.GetEntity and stored in m_iEntityFrom and m_iEntityTo member variables.

Calculation of distance is performed in OnCalculate() handler, where IMetrics interfaces are queried from relevant ISection and IMetrics.Dist is called. The result of the calculation is listed by returned IRelation interface.

In this application the calculated nearest points are displayed in 3D view with line segments and points. To improve performance of rendering IRelation is converted once to a pointer list and stored in m_pairList member. This work is done by CompileNearestData method, where pairs of the relation are iterated through, correspondent elements of the each per object list are retrieved and converted to the actual type of IVertex.

The application uses ClientDraw event, requested in OnInitDialog(), to add custom drawing of shortest segments and other elements to the scene. The drawing is performed inside OnClientDraw handler. In the OnClientDraw method the coordinates of each vertex are obtained via IVertex.GetVertexCoord. When rendering of normals, is requested they are obtained with a IVertex.GetNormal call in DrawNormals().

Work related to the "Is Closer than" group of controls is done in OnCalculateCloserThan handler with the help of IMetrics.IsCloserThan method.

Note that movements of the current object are performed in OnMoveObject via IFrame2 rather than IFrame to make movements relative to the current axes.