• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            OpenCASCADE General Transformation

            Posted on 2015-01-22 20:30 eryar 閱讀(5871) 評論(1)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            OpenCASCADE General Transformation

            eryar@163.com

            Abstract. OpenCASCADE provides a general transformation class: gp_GTrsf. It can be a transformation from gp, an affinity, or you can define your own transformation giving the matrix of transformation. The general transformation contains the vectorial part of the transformation and the translation part. A GTrsf transformation is only applicable to coordinates. Be careful if you apply such a transformation to all points of a geometric object, as this can change the nature of the object and thus render it incoherent. Typically a circle is transformed into an ellipse by an affinity transformation. To avoid modifying the nature of an object, use a gp_Trsf transformation instead, as objects of this class respect the nature of geometric objects.

            Key Words. OpenCASCADE, Transformation, Affinity Transformation

            1. Introduction

            仿射變換(Affinity Transformation)是指線性變換后接著平移。因此,仿射變換的集合是線性變換的超集,任何線性變換都是仿射變換,但不是所有的仿射變換都是線性變換。

            仿射變換的定義如下:在空間直角坐標系下,點(x,y,z)與點(x’, y’,z’)之間的變換

            wps_clip_image-2056

            稱為仿射變換。如果采用特殊的齊次坐標來表達,仿射變換也可用下列形式:

            wps_clip_image-15105

            空間仿射變換是把平面變換到平面,直線變換到直線。兩個平行平面的像也是平行的。共線三點的的簡單比是不變量。平行六面體的體積是權(quán)為1的相對不變量。

            OpenCASCADE的TKMath庫中提供了這上仿射變換類gp_GTrsf,它能執(zhí)行比gp_Trsf更通用的變換。對于TopoDS_Shape,OpenCASCADE分別提供了如下兩個類進行變換:

            v BRepBuilderAPI_GTransform

            v BRepBuilderAPI_Transform

            本文在OpenCASCADE Draw Test Harness中給出這兩個類實現(xiàn)變換的結(jié)果。如果不想改變幾何的特性,只想改變模型的位置或朝向,建議采用BRepBuilderAPI_Transform。

            2.BRepBuilderAPI_Transform

            OpenCASCADE中使用算法BRepBuilderAPI_Transform來實現(xiàn):平移、旋轉(zhuǎn)、縮放及鏡像變換。在Draw Test Harness中實現(xiàn)的函數(shù)代碼如下所示:

            static Standard_Integer transform(Draw_Interpretor& di,Standard_Integer n,const char** a)
            {
              
            if (n <= 1return 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 < 3return 1;
                  TopoDS_Shape SL 
            = DBRep::Get(a[n-1]);
                  
            if (SL.IsNull()) return 0;
                  T 
            = SL.Location().Transformation();
                  last 
            = n-1;
                }
                
            else if (!strcmp(aName,"translate")) {
                  
            if (n < 5return 1;
                  T.SetTranslation(gp_Vec(Draw::Atof(a[n
            -3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1])));
                  last 
            = n-3;
                }
                
            else if (!strcmp(aName,"rotate")) {
                  
            if (n < 9return 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 
            = n-7;
                }
                
            else if (!strcmp(aName,"mirror")) {
                  
            if (n < 8return 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 
            = n-6;
                }
                
            else if (!strcmp(aName,"scale")) {
                  
            if (n < 6return 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 
            = n-4;
                }
              }

              
            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())
                    di 
            << a[i] << " is not a valid shape\n";
                  
            else
                    DBRep::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()) {
                    di 
            << a[i] << " is not a valid shape\n";
                  }
                  
            else {
                    trf.Perform(S);
                    
            if (!trf.IsDone())
                      
            return 1;
                    DBRep::Set(a[i],trf.Shape());
                  }
                }
              }
              
            return 0;
            }

            下面給出應(yīng)用Tcl腳本來實現(xiàn)這些變換的例子:

            # make rotated copies of a sphere in between two cylinders
            # create a file source toto.tcl
            # toto.tcl code:

            pload ALL

            #create a sphere
            psphere s 3
            ttranslate s 
            25 0 12.

            for {set i 0} {$i < 360} {incr i 20} {
                copy s s
            $i
                trotate s
            $i 0 0 0 0 0 1 $i
                
                vdisplay s
            $i
            }
            # create two cylinders
            pcylinder c1 30 5
            copy c1 c2
            ttranslate c2 
            0 0 20
            vdisplay c1 c2 s

            腳本運行效果如下圖所示:

            wps_clip_image-18963

            Figure 2.1 Transform Tcl demo

            從Draw中實現(xiàn)的函數(shù)來看,移動、旋轉(zhuǎn)及縮放變換都是使用類

            BRepBuilderAPI_Transformation來實現(xiàn)。Tcl腳本中先創(chuàng)建出一個球體,再平移后,復制13份,最后又創(chuàng)建出兩個圓柱體。如果要對TopoDS_Shape進行變換且不改變其中的幾何性質(zhì),建議都使用這個類來完成。

            3.BRepBuilderAPI_GTransform

            在OpenCASCADE也可使用仿射變換BRepBuilderAPI_GTransform來對形狀實現(xiàn)上述變換操作,還可提供變形的變換,因此仿射變換是更一般的變換方法。在Draw中實現(xiàn)的函數(shù)代碼如下所示:

            ///=======================================================================
            // gtransform
            //=======================================================================
            static Standard_Integer deform(Draw_Interpretor& di,Standard_Integer n,const char** a)
            {
              
            if (n <= 1return 1;
              
              Standard_Integer last 
            = n;
              
              gp_Trsf T;
              gp_GTrsf GT(T);
              
            //  gp_Mat rot(Draw::Atof(a[last-3]),0,0,0,Draw::Atof(a[last-2]),0,0,0,Draw::Atof(a[last-1]));
              gp_Mat rot(Draw::Atof(a[3]),0,0,0,Draw::Atof(a[4]),0,0,0,Draw::Atof(a[5]));
              GT.SetVectorialPart(rot);
              last 
            -= 3;
              BRepBuilderAPI_GTransform gtrf(GT);
              BRepBuilderAPI_NurbsConvert nbscv;
              
            //  for (Standard_Integer i = 1; i < last; i++) {
              
            //    TopoDS_Shape S = DBRep::Get(a[i]);
              TopoDS_Shape S = DBRep::Get(a[2]);    
              
            if (S.IsNull()) {
                
            //cout << a[2] << " is not a valid shape" << endl;
                di << a[2<< " is not a valid shape" << "\n";
              }
              
            else {
                gtrf.Perform(S);
                
            if (gtrf.IsDone()){
                  DBRep::Set(a[
            1],gtrf.Shape());
                }
                
            else {
                  
            return 1;
                }
              }
              
              
            return 0;
            }

            根據(jù)仿射變換的定義,給定一個球面的數(shù)學表達式:

            wps_clip_image-14741

            應(yīng)用如下的仿射變換,將會得到一個橢球面:

            wps_clip_image-5848

            由變換公式解得:

            wps_clip_image-13797

            將它代入球面方程得到:

            wps_clip_image-17839

            在Draw中使用BRepBuilderAPI_GTransform變換得到如下圖所示:

            wps_clip_image-23346

            Figure 3.1 Shape Deformation

            關(guān)于仿射變換有個重要定理:一般仿射變換是正交變換、沿著三個互相正交方向的壓縮或放大和平移這三者的乘積。上述命令的實現(xiàn)代碼就是設(shè)置了仿射矩陣中的a,b和c值,從而達到對模型變形的效果。

            4.Conclusion

            在三維建模軟件中經(jīng)常需要對模型的位置和其朝向進行變換,如果不想改變模型中的幾何特性,在OpenCASCADE中建議使用類BRepBuilderAPI_Transform來實現(xiàn)。如果需要對模型進行更通用的變換即仿射變換,可以使用類BRepBuilderAPI_GTransform來實現(xiàn)。使用此類后,會改變模型中的幾何特性,必須謹慎使用。

            5. References

            1. OpenCASCADE, OpenCASCADE Draw Test Harness User Guide, 2014

            2. 蘇步表, 華宣積. 應(yīng)用幾何教程. 復旦大學出版社. 2012

            3. Fletcher Dunn. 3D Math Primer for Graphics and Game Development. Wordware. 2002

             

            Feedback

            # re: OpenCASCADE General Transformation  回復  更多評論   

            2015-01-27 15:25 by 黑皮甘蔗
            好久沒用過C++語言了,都忘記了
            国产精品久久久久免费a∨| 久久精品国产亚洲av麻豆小说| 91精品国产高清91久久久久久| 国产午夜免费高清久久影院| 久久99热国产这有精品| 少妇被又大又粗又爽毛片久久黑人| 久久人妻AV中文字幕| jizzjizz国产精品久久| 久久国产乱子伦精品免费午夜| 国产精品久久久久久久人人看 | 国产一区二区三区久久精品| 精品久久久久久无码中文字幕| 久久亚洲AV无码精品色午夜| 色偷偷888欧美精品久久久| 97香蕉久久夜色精品国产| 久久亚洲精品视频| 久久久免费精品re6| 麻豆久久| 久久精品国产一区二区三区不卡| 热久久视久久精品18| 亚洲国产精品久久久久久| 久久夜色精品国产噜噜噜亚洲AV| 久久久不卡国产精品一区二区| 久久婷婷国产综合精品| 2021国内久久精品| 一级做a爱片久久毛片| 69久久精品无码一区二区| 伊人久久精品无码二区麻豆| 久久亚洲中文字幕精品一区四| 久久96国产精品久久久| 国产Av激情久久无码天堂| 综合网日日天干夜夜久久 | 中文字幕精品久久久久人妻| 亚洲欧美精品伊人久久| 久久久国产乱子伦精品作者| 久久亚洲精品国产精品| 久久午夜夜伦鲁鲁片免费无码影视| 久久综合伊人77777麻豆| 久久婷婷五月综合色99啪ak| 欧美一级久久久久久久大| 日本亚洲色大成网站WWW久久|