Clear Filters
Clear Filters

patchの表面カラ​ーにテクスチャを割り​当てることはできます​か?

9 views (last 30 days)
Fumiya Watanabe
Fumiya Watanabe on 24 Nov 2016
Answered: michio on 25 Nov 2016
patchを利用して多角形を表示する際に,表面カラーにテクスチャを割り当てる方法はありますか?
3Dモデルのポリゴンデータをpatchを利用して可視化しようと考えています.現在,下記のデータを読み込むことができています.
  • モデルに定義されているすべての頂点の座標
  • ひとつのポリゴンに含まれる頂点の集合
  • 各頂点のUV座標(モデル内の各頂点がテクスチャ上のどの画素を指すかを表す座標)
今のところ,モデルに定義されているすべての頂点の座標から,patch関数を利用してポリゴンを表示しています. この状態で,モデルの形状自体は正しく表示されるような状況となっています.
現在,テクスチャデータから色情報を読み取って,ポリゴンの表面カラーを設定しようとしています. 具体的には,以下の手順で行っています.
  1. 画像データ読み込み
  2. モデルの各頂点に対し,UV座標を元に,読み取った画像データの位置に対応する色を取得し,それを頂点の色データとする.
  3. patchのプロパティであるFaceVertexCDataに3で読み取った色データを適用
上記の手順を実行しますと,patchのプロパティFaceColorがinterpに設定されている場合,FaceVertexCDataで設定されている各頂点の色データに対して線形で補間されるように面の色が表示されます. しかしながら,ポリゴンの頂点の密度が粗い場合,テクスチャ画像の様子を再現することができません.
本来は,ポリゴンの頂点に定義されたUV座標に対応する画像の一部分を「切り抜いて貼り付ける」ようなマッピングができればよいのですが,patchでは単に面の色が単一の色(flat)もしくはグラデーション的に変わるような設定(interp)しかできないようでした.
patchに対して上記のようなテクスチャマッピングをする方法,もしくは何か代案などはありませんでしょうか?
代替策としてsurfaceを利用することが考えられますが,複雑なポリゴンでは重ね合わせる数が多くなり,動作が重くなることを危惧しております.
  1 Comment
KSSV
KSSV on 24 Nov 2016
Translation:
Is there a way to assign a texture to the surface color when displaying polygons using patch?
We are planning to visualize polygon data of 3D model using patch. Currently, you can read the following data.
The coordinates of all the vertices defined in the model The set of vertices included in one polygon UV coordinates of each vertex (coordinates representing which pixel on the texture each vertex in the model points to) For now, polygons are displayed using the patch function from the coordinates of all the vertices defined in the model. In this state, the shape of the model itself is displayed correctly.
Currently, we are trying to set the surface color of the polygon by reading the color information from the texture data. Specifically, it is done by the following procedure.
Read image data For each vertex of the model, the color corresponding to the position of the read image data is acquired based on the UV coordinates, and this is taken as the color data of the vertex. Apply color data read by 3 to FaceVertexCData which is a property of patch If you execute the above procedure, if the property FaceColor of patch is set to interp, the face color is displayed so that it is linearly interpolated for the color data of each vertex set by FaceVertexCData . However, if the vertex density of the polygon is coarse, it is not possible to reproduce the appearance of the texture image.
Originally it suffices to create a mapping such as "cut out and paste" a part of the image corresponding to the UV coordinates defined at the apex of the polygon, but in patch it is merely the case that the face color is a single color It seemed that it was only possible to set a gradation-like setting (interp).
Is there any way to do texture mapping like above for patch, or any alternative?
As an alternative, it is conceivable to use surface, but with complicated polygons, the number of overlapping is increased, and we are worried about the heavy operation

Sign in to comment.

Accepted Answer

michio
michio on 25 Nov 2016
詳細に記載頂きありがとうございます。
おっしゃる通り patch オブジェクトでは、全体の色、もしくは面毎/頂点毎の色指定にのみ対応しており、ポリゴンの頂点の密度が粗い場合、テクスチャ画像の再現は難しいですね。個人的にはsurface オブジェクトの利用をおすすめします。
すでにご覧になられたかとは思いますが、こちらのエントリーも参考にしてください。 Is it possible to perform texture mapping within MATLAB?

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!