.. role:: code :class: code Constructing a Deformable Body =============================== .. _Constructing_a_Deformable_Body_: .. версия ядра: 118061 Construction of a deformable body is performed by a user in several sequential steps, each of which is implemented by a separate function. The goal is to obtain the body result in which the selected faces of the initial body solid are replaced with deformable faces. 1. At the first step, the faces are prepared for deformation: a parameter object of type :code:`NurbsValues` is created and one of the functions :code:`ModifiedNurbsItem` is called, either the variant with an array of faces **faces** or the variant with a single face **face**. As a result, the body **result** is obtained, in which the specified faces of the initial body **solid** are replaced with NURBS-surfaces suitable for further modification. 2. If necessary, for a selected face **face** of the body **result** the function :code:`GetControlSurface` is called and a copy of the base NURBS-surface of the face **face** is obtained, which can be modified independently of the body. 3. If the shape of a face is to be controlled through its control points, the function :code:`FaceControlPoints` is called for the face **face** to obtain the matrix of control points and their weights. The user changes the coordinates of the control points and/or their weights according to the required deformation. 4. After the modifications have been made, the deformation is applied to the body using one of the functions :code:`NurbsModification`. In the variant with a surface, the modified surface **faceSurface** and the fixed points are passed. In the variant with control points, the modified control points, the weights and the fixed points are passed. In both cases, the output is the modified body **result** with a changed shape of the selected face. The function .. code-block:: cpp MbResultType ModifiedNurbsItem( MbSolid & solid, MbeCopyMode sameShell, const NurbsValues & p, const RPArray & faces, const MbSNameMaker & names, MbSolid *& result ) replaces the selected faces of the **solid** with deformable faces for further editing. The input parameters of the function are: - **solid** -- the initial solid; - **sameShell** -- the mode of copying of the initial solid; - **p** -- an object containing transformation parameters; - **faces** -- the faces of the solid to be replaced; - **names** -- a name maker of the operation. The output parameter of the function is the constructed solid **result**. If successful, the function returns :code:`rt_Success`; otherwise it returns an error code from the enumeration :ref:`MbResultType ` (see *mb_operation_result.h*). The function is declared in the file *action_direct.h*. When the object **p** with modification parameters is created, the following constructor of parameters is used (see *op_shell_parameter.h*): - **ud, vd** -- the order of the NURBS copy in the *u*- and *v*-directions; - **uc, vc** -- the number of control points in the *u*- and *v*-directions; - **umin, umax, vmin, vmax** -- parameter ranges in *u* and *v* for deforming the face; - **uapprox, vapprox** -- flags that allow an approximating surface to be constructed instead of an exact one. .. code-block:: cpp NurbsValues( size_t ud, size_t uc, double umin, double umax, bool uapprox, size_t vd, size_t vc, double vmin, double vmax, bool vapprox ) : uParameters( ud, uc, umin, umax, uapprox ) , vParameters( vd, vc, vmin, vmax, vapprox ) {} The object **p** stores two sets of parameters of type :code:`MbNurbsParameters`: **uParameters** and **vParameters**. The parameters **ud**, **uc**, **umin**, **umax**, **uapprox** define the fields of **uParameters**, and the parameters **vd**, **vc**, **vmin**, **vmax**, **vapprox** define the fields of **vParameters**. The considered function copies the solid **solid** (depending on the parameter **sameShell**) and prepares the copy of the solid for further deformation of the specified faces of the initial solid. The parameter **solid** contains the initial solid in which the specified faces will be replaced with deformable faces based on NURBS-surfaces. The parameter **sameShell** controls the transfer of faces, edges and vertices from the initial solid **solid** to the constructed solid **result** and can take one of four values: - *cm_Same* = 0 (the solid is not copied); - *cm_KeepHistory* (the initial shell and its copy share base surfaces, vertices and faces that are not changed by the operation); - *cm_KeepSurface* (the initial solid and its copy share base surfaces); - *cm_Copy* (the initial solid and its copy do not share any data). The enumeration :code:`MbeCopyMode` is declared in the file *mb_enum.h* and is described in detail in :ref:`Copying a Set of Faces MbFaceShell `. The parameter **faces** contains the set of faces of the solid **solid** that will be replaced with deformable faces based on NURBS-surfaces in the constructed solid **result**. The parameter **names** is used for naming new faces, edges and vertices and for versioning of the operation. The function .. code-block:: cpp MbResultType ModifiedNurbsItem( MbSolid & solid, MbeCopyMode sameShell, const NurbsValues & params, const MbFace & face, const MbSNameMaker & names, MbSolid *& result ) replaces a single face of the solid with a deformable face for further editing. This function differs from the one described above only in the fourth parameter, which contains not a set of faces but a single face **face** to be replaced. The function is declared in the file *action_direct.h*. The constructed body **result** may look similar to the original body **solid**, but unlike the original body it has NURBS surfaces available for modification. Fig. 1 shows an initial cylindrical solid **solid** whose side face is a cylinder :code:`MbCylinderSurface` and the solid **result** with a side face based on a NURBS-surface. The control points of the NURBS-surface are also shown in Figure. .. figure:: ../../pictures/M.6.3.2.png :width: 18cm :align: center Fig. 1 The functions :code:`ModifiedNurbsItem`\() add to the history of the constructed solid the builder :code:`MbModifiedNurbsItem`, which contains all data required to perform the operation. The builder :code:`MbModifiedNurbsItem` is declared in the file *cr_modified_nurbs_.h*. The function .. code-block:: cpp MbSurface * GetControlSurface( const MbFace & face ) creates a deformable NURBS-surface of the face **face** for further editing. The input parameter of the function is the initial face **face**. The function is declared in the file *action_direct.h*. The function returns a non-null pointer to a surface if the face **face** is based on a NURBS-surface. This requirement is satisfied after successful execution of the functions :code:`ModifiedNurbsItem`\(). The function returns a pointer to a copy of the base surface of the face **face**, not to the base surface of the face itself. The control points and their weights of the returned surface can then be modified. The function .. code-block:: cpp MbResultType FaceControlPoints( const MbFace & face, Array2 & controlPoints, Array2 & result ) returns the set of control points of the surface of a face and the set of their weights. The input parameter of the function is the initial face **face**. The output parameters of the function are: - **controlPoints** -- the control points of the face; - **result** -- the weights of the control points. The function is declared in the file *action_direct.h*. The function returns :code:`rt_Success` if the face **face** is based on a NURBS-surface; otherwise it returns an error code from the enumeration :ref:`MbResultType ` (see *mb_operation_result.h*). By changing the positions of the control points **controlPoints** and changing the weights in **result**, one can change the shape of the surface. The considered function should be used after successful execution of the functions :code:`ModifiedNurbsItem`\() described above. The control points **controlPoints** are passed as a rectangular matrix whose rows correspond to the first parameter of the NURBS-surface and whose columns correspond to the second parameter of the NURBS-surface. That is, the points lying in one row of the rectangular matrix **controlPoints** are arranged along a coordinate line of the surface with a fixed second parameter of the NURBS-surface, and the points lying in one column of the rectangular matrix **controlPoints** are arranged along a coordinate line of the surface with a fixed first parameter of the NURBS-surface. In Fig. 2 the control points are shown against the background of the coordinate lines of the surface. .. figure:: ../../pictures/M.6.3.4.png :width: 15cm :align: center Fig. 2 The rectangular matrix **result** of weights corresponds to the rectangular matrix of control points **controlPoints**. Fig. 3 shows the face **face** and the control points **controlPoints** of its surface leftward and the edited control points **controlPoints** for subsequent modification of the face **face** on the right. .. figure:: ../../pictures/M.6.3.5.png :width: 18cm :align: center Fig. 3 The function .. code-block:: cpp MbResultType NurbsModification( MbSolid & solid, MbeCopyMode sameShell, MbFace * face, MbSurface & faceSurface, Array2 & fixedPoints, const MbSNameMaker & names, MbSolid *& result ) deforms the specified face of the initial solid by substituting the given surface into the modified face. The input parameters of the function are: - **solid** -- the initial solid; - **sameShell** -- the mode of copying of the initial solid; - **face** -- the face of the solid to be modified; - **faceSurface** -- the new NURBS-surface of the face; - **fixedPoints** -- the fixed points (if the **fixedPoints** pointer is equal to *nullptr*, all control points are considered movable); - **names** -- a name maker of the operation. The output parameter of the function is the constructed modified solid **result**. If successful, the function returns :code:`rt_Success`; otherwise it returns an error code from the enumeration :ref:`MbResultType ` (see *mb_operation_result.h*). The function is declared in the file *action_direct.h*. The considered function copies the solid **solid** and substitutes the given surface **faceSurface** into the copy of the face **face** of the solid **solid**. The enumeration :code:`MbeCopyMode` is described in detail in :ref:`Copying a Set of Faces MbFaceShell `. The surface **faceSurface** must be a NURBS-surface. The parameter **fixedPoints** is a rectangular matrix whose rows and columns correspond to the rows and columns of the matrix of control points of the NURBS-surface **faceSurface**. The elements of the matrix with the value *true* define fixed control points of the NURBS-surface. The function .. code-block:: cpp MbResultType NurbsModification( MbSolid & solid, MbeCopyMode sameShell, MbFace * face, const Array2 & controlPoints, const Array2 & weights, Array2 * fixedPoints, const MbSNameMaker & names, MbSolid *& result ) deforms the specified face of the initial solid using the given control points and their weights. The input parameters of the function are: - **solid** -- the initial solid; - **sameShell** -- the mode of copying of the initial solid; - **face** -- the face of the solid to be modified; - **controlPoints** -- the given control points of the face to be modified; - **weights** -- the weights of the control points; - **fixedPoints** -- the fixed points (if the **fixedPoints** pointer is equal to *nullptr*, all control points are considered movable); - **names** -- a name maker of the operation. The output parameter of the function is the constructed solid **result**. If successful, the function returns :code:`rt_Success`; otherwise it returns an error code from the enumeration :ref:`MbResultType ` (see *mb_operation_result.h*). The function is declared in the file *action_direct.h*. The considered function should be used after successful execution of the functions :code:`ModifiedNurbsItem`\(), :code:`GetControlSurface`\() and :code:`FaceControlPoints`\() described above. The functions :code:`ModifiedNurbsItem`\() prepare the faces for modification. Fig. 4 shows an initial cylindrical solid **solid** whose side face is based on a NURBS-surface and whose control points are to be modified. Also Fig. 4 shows the solid **result** with a modified side face; the control points **controlPoints** of this face are shown in the figure. .. figure:: ../../pictures/M.6.3.7.png :width: 18cm :align: center Fig. 4 The functions :code:`NurbsModification`\() add to the history of the constructed solid the builder :code:`MbNurbsModification`, which contains all data required to perform the operation. The builder :code:`MbNurbsModification` is declared in the file *cr_modified_nurbs_.h*.