Opencascade Shape Location
[Email protected]
Abstract. The Toploc package of Opencascade gives resources to handle 3D local coordinate systems called Locations. A location was a composition of elementary coordinate systems, each of which is called a Datum. The location keeps track of this composition. The paper would use the Draw Test harness to illustrate the location concept.
Key Words. Transformation, location, Local coordinate Systems
1.Introduction
For the various models in three-dimensional space, always want to be placed in the right place, and eventually form a factory model, a ship model, a building model, and so on. For the time being, all the geometry-related library implementations of model transformations are generally using matrix transformations. Some may only retain the resulting matrix data for the final transformation, while the Opencascade Topods_shape retains the location information. As can be seen from its documentation, the location retains a series of transformation combinations of the model transform and can track the transformation. How to understand the meaning of this location correctly? The following is illustrated with the draw Test harness.
2.Draw Test
The commands for transforming the model in the draw Test harness are: Ttranslate, trotate, Tmove, Reset, Tmirror, TScale. Where ttranslate, Trotate, Tmove, The reset command only adjusts the position of the model and does not deform the model, which is a rigid transformation. The following moves and rotates a box to see how the location in Topods_shape is changing. Enter the following command in the draw Test harness:
Ten - - Dump
You can see that the location of box is not available at this time:
Figure 2.1 Box Original
When you move the box in the X direction for a certain distance:
#00dump b
Figure 2.2 Location of the translation box
It is known that when the model is transformed, the location data is in the Topods_shape, and the translation part of the Transformation matrix (the 4th column data) has changed. Continue to move 10 along the x-axis:
#00dump b
Figure 2.3 Translate Box in X Direction
As shown in Figure 2.3, the current position of the model is obtained through two elementary transformations. The last complex transform is a composite of all the transformations described above. The model is then rotated 45 degrees around the y-axis:
#000010-dump
Figure 2.4 Rotate the Box
It is known that after the rotation transformation of the model has 4 location: three basic transformations and a composite transformation, composite transformation is the combination of all basic transformations.
With the above example, the concept of location in Opencascade can be clearly understood, although the processing is somewhat complex, and the location can be used to trace the model's transformation trajectory in detail. The benefit of this process is that the transformation of the model is recorded and can be conveniently returned to any moment in history; The downside is that the program is difficult to understand and requires additional memory to hold the data.
The following are all TCL scripts:
## test Topods_shape location.# Shing Liu ([email protected]) # 2016-09-06 22:50#pload All#InitializeBox BTen - -Vdisplay bvtrihedron VTDumpb#translate by x directionTtranslate bTen 0 0Vdisplay bDumpb#translate by x directionTtranslate bTen 0 0Vdisplay bDumpb#rotate by Y axisTrotate b0 0 0 0 1 0 $Vdisplay bDumpB
3.Draw Code
Each draw Test harness command makes it easy to find its implementation code, where the implementation code for the Model Transformation command is as follows:
//=======================================================================//Transform//=======================================================================StaticStandard_integer transform (draw_interpretor&, Standard_integer N,Const Char**a) { if(N <=1)return 1; GP_TRSF T; Standard_integer Last=N; Const Char* AName = a[0]; Standard_boolean Isbasic=Standard_false; if(!STRCMP (AName,"Reset")) { } Else{isbasic= (aname[0] =='b'); AName++; if(!STRCMP (AName,"Move")) { if(N <3)return 1; Topods_shape SL= Dbrep::get (a[n-1]); if(SL. IsNull ())return 0; T=SL. Location (). Transformation (); Last= N1; } Else if(!STRCMP (AName,"Translate")) { if(N <5)return 1; T.settranslation (Gp_vec (Draw::atof (a[n-3]), Draw::atof (a[n-2]), Draw::atof (a[n-1]))); Last= N3; } Else if(!STRCMP (AName,"Rotate")) { if(N <9)return 1; T.setrotation (Gp_ax1 (Gp_pnt (Draw::atof (a[n-7]), Draw::atof (a[n-6]), Draw::atof (a[n-5]), Gp_vec (Draw::atof (a[n-4]), Draw::atof (a[n-3]), Draw::atof (a[n-2])), Draw::atof (A[n-1]) * (M_PI/180.0)); Last= N7; } Else if(!STRCMP (AName,"Mirror")) { if(N <8)return 1; T.setmirror (Gp_ax2 (Gp_pnt (Draw::atof (a[n-6]), Draw::atof (a[n-5]), Draw::atof (a[n-4]), Gp_vec (Draw::atof (a[n-3]), Draw::atof (a[n-2]), Draw::atof (a[n-1])))); Last= N6; } Else if(!STRCMP (AName," Scale")) { if(N <6)return 1; T.setscale (Gp_pnt (Draw::atof (a[n-4]), Draw::atof (a[n-3]), Draw::atof (a[n-2]), Draw::atof (a[n-1])); Last= N4; } } if(T.form () = = Gp_identity | |isbasic) {toploc_location L (T); for(Standard_integer i =1; i < last; i++) {Topods_shape S=Dbrep::get (A[i]); if(S.isnull ()) {Std::cerr<<"Error:"<< A[i] <<"is not a valid shape\n"; return 1; } ElseDbrep::set (a[i],s.located (L)); } } Else{brepbuilderapi_transform TRF (T); for(Standard_integer i =1; i < last; i++) {Topods_shape S=Dbrep::get (A[i]); if(S.isnull ()) {Std::cerr<<"Error:"<< A[i] <<"is not a valid shape\n"; return 1; } Else{TRF. Perform (S); if(!TRF. IsDone ())return 1; Dbrep::set (A[I],TRF. Shape ()); } } } return 0;}
The transformation of the model is mainly done by using class Brepbuilderapi_transform.
4.Conclusion
With the above example, the concept of location in Opencascade can be clearly understood, although the processing is somewhat complex, and the location can be used to trace the model's transformation trajectory in detail. The benefit of this process is that the transformation of the model is recorded and can be conveniently returned to any moment in history; The downside is that the program is difficult to understand and requires additional memory to hold the data.
Understand the concept of location, also understand the Opencascade Brep file in a basic content, to facilitate the development of some conversion interface.
The application of matrix transformation in graphics can be referenced in the 3D Mathematical Fundamentals: Graphics and Game development.
5.References
1.Fletcher Dunn, Ian Parberry. 3D Math Primer for Graphics and Game development. Tsinghua University Press. 2005
2.OpenCASCADE Draw Test Harness User Guide.
PDF Version:opencascade Shape Location
Opencascade Shape Location