【OpenMesh】標準属性の使用
6248 ワード
この例では、標準属性 を追加する方法標準属性の値 を取得および設定する方法
前述したように、プロパティを使用してグリッドエンティティにデータをバインドできます.OpenMeshは一連の標準属性を提供する.カスタムプロパティとは異なり、標準プロパティには特定の機能と異なるインタフェースがあります.これがこのガイドで説明します.
次の表には、可能なすべての標準属性と、これらの属性を使用するのに適したエンティティを示します.
Vertex
Face
Edge
Halfedge
Color
X
X
X
Normal
X
X
X
Position
X
Status
X
X
X
X
TexCoord
X
X
エンティティに標準属性を追加するには、request_などの適切なリクエストメソッドのみを使用します.face_normals().唯一の例外はpositionです.永続的に使用可能であるため、追加できません.削除できません.
例では頂点法ベクトルをメッシュオブジェクト に追加する.ファイル をロードファイルが頂点normalを提供するかどうかを確認し、そうでなければ を計算します.頂点法ベクトルの方向に沿って各頂点の単位長 を移動する.印刷結果位置std::cout 頂点法ベクトルのメッシュへの追加を開始します.
しかし、標準プロパティを使用してより多くのことをすることができます.メッシュに頂点ベクトルがあるかどうかを確認できます
上記の表のように、OpenMesh::Concepts::KernelT: request_edge_status() request_edge_colors() request_face_colors() request_face_normals() request_face_status() request_face_texture_index() request_halfedge_status() request_halfedge_normals() request_halfedge_texcoords1D() request_halfedge_texcoords2D() request_halfedge_texcoords3D() request_vertex_colors() request_vertex_normals() request_vertex_status() request_vertex_texcoords1D() request_vertex_texcoords2D() request_vertex_texcoords3D()
追加したプロパティは、次の関数で解放できます. release_edge_status() release_edge_colors() release_face_colors() release_face_normals() release_face_status() release_face_texture_index() release_halfedge_status() release_halfedge_normals() release_halfedge_texcoords1D() release_halfedge_texcoords2D() release_halfedge_texcoords3D() release_vertex_colors() release_vertex_normals() release_vertex_status() release_vertex_texcoords1D() release_vertex_texcoords2D() release_vertex_texcoords3D()
属性の存在は、次の関数でテストできます. has_edge_status() has_edge_colors() has_face_colors() has_face_normals() has_face_status() has_face_texture_index() has_halfedge_status() has_halfedge_normals() has_halfedge_texcoords1D() has_halfedge_texcoords2D() has_halfedge_texcoords3D() has_vertex_colors() has_vertex_normals() has_vertex_status() has_vertex_texcoords1D() has_vertex_texcoords2D() has_vertex_texcoords3D()
プロパティが要求されるとtrueが返されます.
このステータスプロパティは、ジオメトリ要素が選択されているか削除されているかをマークするために使用します.
標準プロパティを追加および削除する方法を知っていますが、どのようにアクセスしますか?グリッドオブジェクトが再び必要です.カスタム属性とは異なり、アクセス属性はグリッドメンバー関数property()を使用し、標準属性ごとにgetメソッドとsetメソッドをグリッドに提供します.以前のガイドでは,getとset法を用いて,頂点位置の新しいアドレスを計算した.ここでは、頂点法ベクトルに沿って単位長の距離を移動します.
add/remove/access標準プロパティの方法を知っているので、より深刻な問題があります.属性のデータ型は何ですか?この中にはもっと秘密がありますか?次のガイドは答えを出します.
完全なコード:
前述したように、プロパティを使用してグリッドエンティティにデータをバインドできます.OpenMeshは一連の標準属性を提供する.カスタムプロパティとは異なり、標準プロパティには特定の機能と異なるインタフェースがあります.これがこのガイドで説明します.
次の表には、可能なすべての標準属性と、これらの属性を使用するのに適したエンティティを示します.
Vertex
Face
Edge
Halfedge
Color
X
X
X
Normal
X
X
X
Position
X
Status
X
X
X
X
TexCoord
X
X
エンティティに標準属性を追加するには、request_などの適切なリクエストメソッドのみを使用します.face_normals().唯一の例外はpositionです.永続的に使用可能であるため、追加できません.削除できません.
例では
mesh.request_vertex_normals();
同様の方法で他の属性を要求することができます.たとえば、フェースの法線ベクトル:mesh.request_face_normals();
頂点ベクトルを計算するためにこれらの値が必要です.update_を使用します.normal()は、ファイルがこれらを提供していない場合です.しかし、標準プロパティを使用してより多くのことをすることができます.メッシュに頂点ベクトルがあるかどうかを確認できます
if (!mesh.has_vertex_normals())
{
std::cerr << "ERROR: Standard vertex property 'Normals' not available!
";
return 1;
}
使用が完了したら削除します.mesh.release_vertex_normals();
しかし、もしプログラムの頂点状態が2回要求されたらどうなりますか?1回目のリリースでは実際の作業は行われませんでしたが、2回目のリリースでは削除されました.標準属性には参照カウントがあり、リクエストごとにカウントが1増加し、リリースごとにカウントが1減少します.カウンタが0に減少すると、このプロパティはメモリから削除されます.上記の表のように、OpenMesh::Concepts::KernelT:
追加したプロパティは、次の関数で解放できます.
属性の存在は、次の関数でテストできます.
プロパティが要求されるとtrueが返されます.
このステータスプロパティは、ジオメトリ要素が選択されているか削除されているかをマークするために使用します.
標準プロパティを追加および削除する方法を知っていますが、どのようにアクセスしますか?グリッドオブジェクトが再び必要です.カスタム属性とは異なり、アクセス属性はグリッドメンバー関数property()を使用し、標準属性ごとにgetメソッドとsetメソッドをグリッドに提供します.以前のガイドでは,getとset法を用いて,頂点位置の新しいアドレスを計算した.ここでは、頂点法ベクトルに沿って単位長の距離を移動します.
for (MyMesh::VertexIter v_it = mesh.vertices_begin();
v_it != mesh.vertices_end(); ++v_it)
{
mesh.set_point( v_it, mesh.point(v_it)+mesh.normal(v_it) );
}
getメソッドは、エンティティハンドルに入力され、所望の属性値を返します.setメソッドでは、追加されたパラメータが属性に新しい値を渡す必要があります.テーブルに基づいて、各get/setメソッドが各エンティティに適用されるわけではありません.たとえば、1つの面には通常テクスチャ座標がありません.そのためmesh.texcoord 2 D(_face_handle)を呼び出すとエラーが発生します.add/remove/access標準プロパティの方法を知っているので、より深刻な問題があります.属性のデータ型は何ですか?この中にはもっと秘密がありますか?次のガイドは答えを出します.
完全なコード:
#include <iostream>
// --------------------
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
typedef OpenMesh::TriMesh_ArrayKernelT<> MyMesh;
int main(int argc, char **argv)
{
MyMesh mesh;
if (argc!=2)
{
std::cerr << "Usage: " << argv[0] << " <input>
";
return 1;
}
// request vertex normals, so the mesh reader can use normal information
// if available
mesh.request_vertex_normals();
// assure we have vertex normals
if (!mesh.has_vertex_normals())
{
std::cerr << "ERROR: Standard vertex property 'Normals' not available!
";
return 1;
}
OpenMesh::IO::Options opt;
if ( ! OpenMesh::IO::read_mesh(mesh,argv[1], opt))
{
std::cerr << "Error loading mesh from file " << argv[1] << std::endl;
return 1;
}
// If the file did not provide vertex normals, then calculate them
if ( !opt.check( OpenMesh::IO::Options::VertexNormal ) )
{
// we need face normals to update the vertex normals
mesh.request_face_normals();
// let the mesh update the normals
mesh.update_normals();
// dispose the face normals, as we don't need them anymore
mesh.release_face_normals();
}
// move all vertices one unit length along it's normal direction
for (MyMesh::VertexIter v_it = mesh.vertices_begin();
v_it != mesh.vertices_end(); ++v_it)
{
std::cout << "Vertex #" << v_it << ": " << mesh.point( v_it );
mesh.set_point( v_it, mesh.point(v_it)+mesh.normal(v_it) );
std::cout << " moved to " << mesh.point( v_it ) << std::endl;
}
// don't need the normals anymore? Remove them!
mesh.release_vertex_normals();
// just check if it really works
if (mesh.has_vertex_normals())
{
std::cerr << "Ouch! ERROR! Shouldn't have any vertex normals anymore!
";
return 1;
}
return 0;
}