メッシュ生成用stl ファイルの...
TRANSCRIPT
![Page 1: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/1.jpg)
メッシュ生成用STL ファイルの自前での作成方法について
一関高専・若嶋振一郎([email protected])
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 1
事例報告
※ 「自前で」とありますが、サーフェスをメッシュ分割するアルゴリズム(Delaunay分割など)については含んでいません。STLの記述についてのお話です。
![Page 2: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/2.jpg)
OpenFOAMにおけるメッシュ生成方法
1. まずはともあれ“blockMesh”コマンドを使いこなそう!• 最近multi gradingを搭載したので使いやすくなりました
• 派生として“extBlockMesh”・・・メッシュスムージング+Objファイルへのプロジェクション機能
2. 市販・フリーメッシャーから出力もしくはネイティブフォーマットを変換• ICEM CFD
• Pointwise/gridgen
• Netgen
• enGrid
:
3. フリー3D-CAD(アカデミック)>STL出力>sHM/cfMesh• STLファイルの品質が重要
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 2
![Page 3: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/3.jpg)
STLファイルとは?
STL=“Stereolithography ”
三次元形状を小さな三角形の集合体(ポリゴン)として表現•色やトポロジーデータなどは表現不可• カーブ形状などの表現不可(微小三角形平面で近似)
→ 曲面(曲率半径大)では十分な解像度の三角形を出力する•データ構造が簡単で3Dプリンタ用データなどによく用いられるASCII形式・・・・可読性あり、データ量多、読み込み遅
Binary形式・・・可読性なし、データ量少、読み込み早
たいていの3D-CAD・CGには出力機能あり
OpenFOAMではsHMやcfMeshのメッシュ生成用データとして利用
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 3
![Page 4: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/4.jpg)
STLファイルの例
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 4
3Dモデル STL形式出力 STLファイルの中身(ASCII)
solid Part1facet normal -5.000000e-001 8.660254e-001 0.000000e+000
outer loopvertex 0.000000e+000 8.660254e+000 5.000000e+000vertex 5.000000e+000 1.154701e+001 5.000000e+000vertex 0.000000e+000 8.660254e+000 -1.734723e-015
endloopendfacet
:
facet normal 0.000000e+000 0.000000e+000 -1.000000e+000outer loop
vertex 1.000000e+001 2.886751e+000 0.000000e+000vertex 5.000000e+000 1.154701e+001 0.000000e+000vertex 1.000000e+001 8.660254e+000 0.000000e+000
endloopendfacet
endsolid
1個1個の三角形パッチはFacetと呼ばれる
1つの物体はsolidと呼ばれる
![Page 5: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/5.jpg)
STLファイルの基本構造(ASCII形式)
solid NAME
facet normal nx ny nz
outer loop
vertex v0x v0y v0z
vertex v1x v1y v1z
vertex v2x v2y v1z
endloop
endfacet
:
endsolid
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 5
solid ブロック名
三角形(facet)の単位法線ベクトル(表)
三角形(facet)を形成する3つの点の座標※右ねじ回りに指定※法線ベクトルや座標はe表記法(例:1.000000e+01 )で表記※改行コードはCR+LFが無難?
(nx ny nz)
(v0x v0y v0z)
(v1x v1y v1z)(v2x v2y v2z)
![Page 6: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/6.jpg)
STLファイルの基本構造(BINARY形式)
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 6
参考:http://www.fabbers.com/tech/STL_Format
ヘッダー部(任意文字列)facetの数
facetの数分だけのデータを繰り返す
- facetの単位法線ベクトル3成分-節点1の座標3成分-節点2の座標3成分-節点3の座標3成分- 2byte分の追加データ(通常は0埋め)
この部分に色情報を埋め込んだcolor STL 形式というものもある。
![Page 7: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/7.jpg)
CFD(OpenFOAM)用に用いるSTLファイルの注意点
単位系STLファイルで用いる数値は単位系が記述されていないので、[mm]なのか[m]なのか[inch]なのか、間違いやすいため注意が必要です
三角形ポリゴンで囲まれた空間の表面・裏面の統一
三角形パッチの節点の並び方(右ねじ)と、法線の指定の仕方に矛盾があると、メッシュ生成ができないことがあります(反転ポリゴン)
三角形ポリゴン同士の干渉・不整合・低品質あるポリゴンが他のポリゴンとクロスしている場合(ポリゴンの交差)
あるポリゴンの節点が他のポリゴンの節点と同じ値を持つ場合(ポリゴンの重複)
ポリゴンによって空間が閉じられていない場合(ポリゴンの欠落)
ポリゴン座標データに同じものが入っている(点ポリゴン、線ポリゴン)
微小・鋭角三角形
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 7
目視での確認・修正は非常に困難(とくに複雑形状になればなるほど)
3D-CAD/modelerソフトで再作成(ヒーリングツール)
修正ツールを利用
![Page 8: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/8.jpg)
STLファイルの修正ツール
• MeshLab( http://meshlab.sourceforge.net/ )
• MeshMagic( http://www.nchsoftware.com/meshmagic3d/ )
• MiniMagics(http://www.vector.co.jp/soft/winnt/business/se453733.html)
・・・非OSSで要登録。エラーチェック機能のみ?
• netfabb basic(http://www.3ds.co.jp/netfabb/index.htm)
• OpenSTL(http://sourceforge.net/projects/openstl/)
・・・Viewer機能のみ? など
※有償Softwareは高機能な分、高価(O(10~100)万円)
※ OpenFOAMにもSTL関係のUtility(surface mesh tools)が存在
→ http://cfd.direct/openfoam/user-guide/standard-utilities/
surfaceCheck, surfaceClean, surfaceMeshConvert , ……….
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 8
AppendixにMeshLabを用いた例を追記していますので、ご参照ください。
![Page 9: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/9.jpg)
STLファイルの作成法(python)
• 構造が分かれば,ASCIIでファイルを作成を作成可能
• pythonでのSTL出力パッケージが多数存在• pythonでの点列計算→STL出力→sHM/cfMesh→OpenFOAM solverの自動化
• https://github.com/telefab/ImageExtruder/blob/master/photomaton/stl_writer.py
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 9
#!/usr/bin/env python# coding:utf-8# Purpose: Export 3D objects, build of faces with 3 or 4 vertices, as ASCII or Binary STL file.# License: MIT License# http://code.activestate.com/recipes/578246/
import struct
ASCII_FACET = """facet normal 0 0 0outer loopvertex {face[0][0]:.4f} {face[0][1]:.4f} {face[0][2]:.4f}vertex {face[1][0]:.4f} {face[1][1]:.4f} {face[1][2]:.4f}vertex {face[2][0]:.4f} {face[2][1]:.4f} {face[2][2]:.4f}endloopendfacet"""BINARY_HEADER ="80sI"BINARY_FACET = "12fH"
facetのNormal Vectorを別に計算する必要があるためそのあたりも追記して改造したサンプルを公開します(@勉強会HP?)
![Page 10: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/10.jpg)
(cont.)
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 10
class ASCIISTLWriter:""" Export 3D objects build of 3 or 4 vertices as ASCII
STL file."""def __init__(self, stream):
self.fp = streamself._write_header()
def _write_header(self):self.fp.write("solid python¥n")
def close(self):self.fp.write("endsolid python¥n")
def _write(self, face):self.fp.write(ASCII_FACET.format(face=face))
def _split(self, face):p1, p2, p3, p4 = facereturn (p1, p2, p3), (p3, p4, p1)
def add_face(self, face):""" Add one face with 3 or 4 vertices. """if len(face) == 4:
face1, face2 = self._split(face)self._write(face1)self._write(face2)
elif len(face) == 3:self._write(face)
else:raise ValueError('only 3 or 4 vertices for each face')
def add_faces(self, faces):""" Add many faces. """for face in faces:
self.add_face(face)
入出力ストリームの初期化(ファイルストリーム)
ヘッダー出力(solid名は決め打ち)
STLファイル終了
Facetデータ出力
四角形を三角形に分割
facet追加
Facet複数追加
![Page 11: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/11.jpg)
(cont.)
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 11
class BinarySTLWriter(ASCIISTLWriter):"""Export 3D objects build of 3 or 4 vertices as binary STL file."""def __init__(self, stream):
self.counter = 0super(Binary_STL_Writer, self).__init__(stream)
def close(self):self._write_header()
def _write_header(self):self.fp.seek(0)self.fp.write(struct.pack(BINARY_HEADER, b'Python Binary STL Writer', self.counter))
def _write(self, face):self.counter += 1data = [0., 0., 0.,face[0][0], face[0][1], face[0][2],face[1][0], face[1][1], face[1][2],face[2][0], face[2][1], face[2][2],0]self.fp.write(struct.pack(BINARY_FACET, *data))
入出力ストリームの初期化(ファイルストリーム)
ヘッダー出力
STLファイル終了
Facetデータ出力
![Page 12: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/12.jpg)
Appendix: MeshLabによるSTLデータ修正
• 公開3D STLデータの例 Honda NSX Consept( http://www.honda-3d.com/ )
• nsx_concept_LOW.stl
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 12
SolidWorksでは読み込めますが(パッと見OK),これをそのままsHMに使うとエラーになります。
![Page 13: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/13.jpg)
Close Holes
• Filters → Remeshing,simpl・・・→ Close Holes
• 欠落したfaceを再構成
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 13
修正後
欠損したface
修正前
faceの修正
![Page 14: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/14.jpg)
Mesh reduction
• Filters → Remeshing,simpl・・・→ QuadricEdgeCollapseDecimation
• Target number of facesを修正(もしくはpercentage of reduction)
• Preserve boundary of the meshにチェックをいれる
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 14
オリジナル: 約21万faces 修正後: 10万faces
![Page 15: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/15.jpg)
Mesh subdivision
• Filters → Remeshing,simpl・・・→ Subdivision Surfaces: midpoint
• Face edgeの中点を使ってメッシュを細分化
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 15
Iteration 3回後
![Page 16: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/16.jpg)
Mesh smoothing
• Filters → Smoothing,Fairing・・・→ Laplacian smooth (surface preserving)
• ラプラス方程式を用いたメッシュスムージング
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 16
Iteration 10回後
![Page 17: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/17.jpg)
そのほかの修正コマンド
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 17
Non manifoldなメッシュの除去• Filters -> Cleaning and Repairing -> Remove Non Manifold Faces
• Filters -> Cleaning and Repairing -> Remove Non Manifold Vertices
法線ベクトルの裏表の整列• Filters->Normals, Curvatures and Orientation->Re-Orient All Faces Coherently
メッシュの粗粒化(形状変更を伴うことが多い)• Filters -> Rendering, simplification and reconstruction -> Quadric Edge Collapse
Decimation
![Page 18: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/18.jpg)
Manifold conditions
① Each edge is incident to only one or two faces
② The faces incident to a vertex form a closed or an open fan
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 18
このようなメッシュ(黄色)は”Non-Manifold mesh”となり,しばしばエラーになります.
From http://www.cs.mtu.edu/~shene/COURSES/cs3621/SLIDES/Mesh.pdf
![Page 19: メッシュ生成用STL ファイルの 自前での作成方法についてhirose/ockitatohoku/ref/wakashimasensei-text-6.pdf · STLファイルとは? STL=“Stereolithography”](https://reader030.vdocuments.net/reader030/viewer/2022040720/5e03d74ee24119047234a3f1/html5/thumbnails/19.jpg)
参考文献/URL
− http://www-bl20.spring8.or.jp/~sp8ct/tmp/stl.pdf
− http://www.fabbers.com/tech/STL_Format
− http://www.hiramine.com/programming/3dmodelfileformat/stlfileformat.html
− https://ja.wikipedia.org/wiki/Standard_Triangulated_Language
2015/11/14 第6回OpenCAE初歩情報交換会@北東北 19
次回は、STLファイルを使ってsHMもしくはcfMeshによるメッシュ生成や境界生成(autoPatchコマンドなど)のまとめについてお話しする予定です。