Locations Section of OpenCascade BRep
Locations Section of OpenCascade BRep
eryar@163.com
摘要Abstract:本文結(jié)合OpenCascade的BRep格式描述文檔和源程序,對BRep格式進(jìn)行分析,詳細(xì)說明BRep的數(shù)據(jù)組織形式。本文主要通過對BRep文件中的Locations部分的讀寫代碼進(jìn)行分析,來完全理解OpenCascade中的Location部分。?
關(guān)鍵字Key Words:OpenCascade, BRep Format, Location, Location Set?
一、引言 Introduction
為了跟蹤拓樸體的位置(Shape Location),每個形狀都有一個局部坐標(biāo)系。局部坐標(biāo)系可以通過如下兩種方式來表示:?
l 一個右手法則表示的三個互相垂直的向量,對應(yīng)的類是gp_Ax2;?
l 一個相對于世界坐標(biāo)系的變換(the transformation of coordinates between local and global references frames),對應(yīng)的類是gp_Trsf;?
類TopLoc_Location表示了初等矩陣經(jīng)過一系列變換后得到的坐標(biāo)系,保存累積變換后的結(jié)果避免了矩陣變換的重新計算。?
二、<locations>部分 Section <locations>
示例:?
BNF 定義:?
詳細(xì)說明:?
<location data 1>定義了3X4的矩陣Q,描述了三維空間的線性變換,并滿足如下約定:?
矩陣Q是線性變換矩陣,它可以通過矩陣乘法將一個點(x, y, z)變換成另外一點(u, v, w):?
Q也可能是以下基本變換矩陣的組合:?
1) 平移變換矩陣:?
2) 繞任意軸旋轉(zhuǎn)的變換矩陣,軸的方向為D(Dx, Dy, Dz),旋轉(zhuǎn)角度ψ:?
3) 縮放變換矩陣:?
4) 中心對稱變換矩陣:?
5) 軸對稱變換矩陣:?
6) 平面對稱變換矩陣:?
<location data 2>解釋為組合變換的冪。<location data 2>是整數(shù)對li, pi的序列。這個序列將被解釋為:?
Lli是<location record>部分的變換矩陣。?
三、示例程序
通過分析Location數(shù)據(jù)輸出和讀取的程序,可以完全理解Location類的作用。Location的輸出與讀取都是通過類TopTools_LocationSet來實現(xiàn)的。調(diào)試跟蹤其代碼,可以理解其具體實現(xiàn)了。?
3.1 輸出位置數(shù)據(jù) Output Location data
將Location中的數(shù)據(jù)輸出有兩種方式,一種是在Debug模式下,可以輸出到屏幕顯示;一種是輸出到文件。輸出到文件還可以被讀取。示例程序如下所示:?
1 /*2 * Copyright (c) 2013 eryar All Rights Reserved.3 *4 * File : Main.cpp5 * Author : eryar@163.com6 * Date : 2013-11-16 20:087 * Version : 1.0v8 *9 * Description : Keeping track of shape location. 10 * The TopLoc_Location class represents a marker composed of 11 * references to elementary markers. The resulting cumulative 12 * transformation is stored in order to avoid recalculating the 13 * sum of the transformations for the whole list. 14 */ 15 16 #define WNT 17 #include <gp_Trsf.hxx> 18 #include <TopLoc_Location.hxx> 19 #include <TopTools_LocationSet.hxx> 20 21 #pragma comment(lib, "TKernel.lib") 22 #pragma comment(lib, "TKMath.lib") 23 #pragma comment(lib, "TKBRep.lib") 24 25 int main(void) 26 { 27 ofstream dumpFile("LocationTest.txt"); 28 29 TopTools_LocationSet locationSet; 30 31 // 1. Null transformation, identity matrix. 32 gp_Trsf trsfNull; 33 TopLoc_Location locationNull(trsfNull); 34 35 locationSet.Add(locationNull); 36 locationSet.Add(locationNull.Powered(2)); 37 38 // 2. Translate transformation. 39 gp_Trsf trsfTranslate; 40 trsfTranslate.SetTranslation(gp_Vec(100, 200, 0)); 41 TopLoc_Location locationTranslate(trsfTranslate); 42 43 locationSet.Add(locationTranslate); 44 locationSet.Add(locationTranslate.Powered(3)); 45 46 // 3. Rotate transformation. 47 gp_Trsf trsfRotate; 48 trsfRotate.SetRotation(gp::OX(), M_PI_2); 49 TopLoc_Location locationRotate(trsfRotate); 50 51 locationSet.Add(locationRotate); 52 locationSet.Add(locationRotate.Powered(6)); 53 54 // dump the location set and write to file. 55 locationSet.Dump(std::cout); 56 locationSet.Write(dumpFile); 57 58 return 0; 59 }Debug模式下屏幕上輸出結(jié)果為:
1 2 3 4 -------5 Dump of 6 Locations6 -------7 8 1 :9 Elementary location 10 ( 1 0 0 0 ) 11 ( 0 1 0 0 ) 12 ( 0 0 1 0 ) 13 2 : 14 Complex : L1^2 15 ( 1 0 0 0 ) 16 ( 0 1 0 0 ) 17 ( 0 0 1 0 ) 18 3 : 19 Elementary location 20 ( 1 0 0 100 ) 21 ( 0 1 0 200 ) 22 ( 0 0 1 0 ) 23 4 : 24 Complex : L3^3 25 ( 1 0 0 300 ) 26 ( 0 1 0 600 ) 27 ( 0 0 1 0 ) 28 5 : 29 Elementary location 30 ( 1 0 0 0 ) 31 ( 0 1.11022e-016 -1 0 ) 32 ( 0 1 1.11022e-016 0 ) 33 6 : 34 Complex : L5^6 35 ( 1 0 0 0 ) 36 ( 0 -1 -6.66134e-016 0 ) 37 ( 0 6.66134e-016 -1 0 ) 38 Press any key to continue . . .輸出到文件中的內(nèi)容為:
1 Locations 62 13 1 0 0 0 4 0 1 0 0 5 0 0 1 0 6 2 1 2 07 18 1 0 0 100 9 0 1 0 200 10 0 0 1 0 11 2 3 3 0 12 1 13 1 0 0 0 14 0 1.11022302462516e-016 -1 0 15 0 1 1.11022302462516e-016 0 16 2 5 6 0從輸出結(jié)果可以看出,輸出到文件中的內(nèi)容與BRep文件中的內(nèi)容一致。Location有兩種類型,當(dāng)類型為1時,即是一個初等變換矩陣(Elementary location);當(dāng)類型為2時,是一個復(fù)合變換(Complex),即在初等變換矩陣的基礎(chǔ)上做的一些變換操作。?
3.2 讀取位置數(shù)據(jù) Input Location data
讀取<locations>部分的類為TopTools_LocationSet,程序代碼如下所示:
1 //=======================================================================2 //function : Read3 //purpose : 4 //=======================================================================5 6 void TopTools_LocationSet::Read(Standard_IStream& IS)7 {8 myMap.Clear();9 10 char buffer[255]; 11 Standard_Integer l1,p; 12 13 IS >> buffer; 14 if (strcmp(buffer,"Locations")) { 15 cout << "Not a location table "<<endl; 16 return; 17 } 18 19 Standard_Integer i, nbLoc; 20 IS >> nbLoc; 21 22 TopLoc_Location L; 23 gp_Trsf T; 24 25 //OCC19559 26 Message_ProgressSentry PS(GetProgress(), "Locations", 0, nbLoc, 1); 27 for (i = 1; i <= nbLoc&& PS.More(); i++, PS.Next()) { 28 if ( !GetProgress().IsNull() ) 29 GetProgress()->Show(); 30 31 Standard_Integer typLoc; 32 IS >> typLoc; 33 34 if (typLoc == 1) { 35 ReadTrsf(T,IS); 36 L = T; 37 } 38 39 else if (typLoc == 2) { 40 L = TopLoc_Location(); 41 IS >> l1; 42 while (l1 != 0) { 43 IS >> p; 44 TopLoc_Location L1 = myMap(l1); 45 L = L1.Powered(p) *L; 46 IS >> l1; 47 } 48 } 49 50 if (!L.IsIdentity()) myMap.Add(L); 51 } 52 }從讀取Location部分的代碼可以看出,分兩情況來處理。一種是初等變換矩陣,類型值為1,直接讀取矩陣數(shù)據(jù);一種是復(fù)合變換,類型值為2,它是在初等變換矩陣的基礎(chǔ)上通過Power來實現(xiàn)的復(fù)合變換。BRep中記錄復(fù)合變換的數(shù)據(jù)為初等變換矩陣的編號及其冪次。通過編號Map得出其對應(yīng)的初等變換矩陣。結(jié)合讀取Location的代碼,對BRep中Location部分的數(shù)據(jù)有了清晰認(rèn)識。?
四、結(jié)論
通過對OpenCascade中BRep文件中的Locations部分的數(shù)據(jù)的輸出與讀取,理解其實現(xiàn)。即對Location分為兩種類型:?
1. 初等變換矩陣:存儲數(shù)據(jù)為3X4變換矩陣;?
2. 復(fù)合變換:存儲數(shù)據(jù)為初等變換矩陣的編號及其冪次。?
?
PDF Version: Location Section of BRep File
轉(zhuǎn)載于:https://www.cnblogs.com/opencascade/p/3446718.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的Locations Section of OpenCascade BRep的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Eclipse/Myeclipse生成s
- 下一篇: NO.106 需求的状态、研发阶段及注意