日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > 循环神经网络 >内容正文

循环神经网络

【matlab教程】20、简单网格细分

發布時間:2023/12/20 循环神经网络 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【matlab教程】20、简单网格细分 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題

matlab處理網格時,有時需要將網格細分
思路參考:https://hanspond.github.io/2018/11/27/%E7%AE%80%E5%8D%95%E7%BD%91%E6%A0%BC%E7%BB%86%E5%88%86%201to4%20Mesh%20Subdivision/index.html

將每一個面的每一條邊取中點并連接,形成新的三角形,原來一個面細分成四個面
原博主的代碼只適合封閉曲面的細分,如果曲面是不封閉的,則拓撲結構會亂,如:
代碼:

%% created by H_P 20181119: subdivide mesh into 4 smaller meshes in a simple mannerfunction [ Divided_faces, Divided_vertices ] = sub_test( faces, vertices ) %SUB_TEST 此處顯示有關此函數的摘要 % 此處顯示詳細說明mesh_length_Large=length(faces); Divided_faces=1:mesh_length_Large*4*3; Divided_faces=(reshape(Divided_faces,[3,mesh_length_Large*4]))'; Divided_vertices=repelem(vertices,4,1);for n_for=1:mesh_length_Largev1=faces(n_for,1);v2=faces(n_for,2);v3=faces(n_for,3);new_1=(vertices(v1,:)+vertices(v2,:))/2;new_2=(vertices(v3,:)+vertices(v2,:))/2;new_3=(vertices(v1,:)+vertices(v3,:))/2;Divided_vertices((n_for-1)*12+2,:)= new_1;Divided_vertices((n_for-1)*12+3,:)= new_3;Divided_vertices((n_for-1)*12+4,:)= new_1;Divided_vertices((n_for-1)*12+6,:)= new_2;Divided_vertices((n_for-1)*12+7,:)= new_2;Divided_vertices((n_for-1)*12+8,:)= new_3;Divided_vertices((n_for-1)*12+10,:)= new_1;Divided_vertices((n_for-1)*12+11,:)= new_2;Divided_vertices((n_for-1)*12+12,:)= new_3; end end

調用:

>> [v,f]=read_obj('test.obj'); >> [ Divided_faces, Divided_vertices ] = sub_test( f', v'); >> writeOBJ('test_sub.obj',Divided_vertices,Divided_faces);

結果:
細分前:

細分后:

解決

我將代碼改進了一下,將分割條件改為網格面積大于閾值就分割,否則不分割
代碼:

function [ divided_vertices ,divided_faces ] = subdivide_mesh01( vertices,faces ,threshold ) %SUBDIVIDE_MESH 將曲面簡單細分為1to4 % 輸入: % vertices:細分前的點集n*3 % faces:細分前的面集m*3 % threshold:網格面積小于這個就細分 % 輸出: % divided_vertices:細分后的點集 % divided_faces:細分后的面集 tic%403秒 size_faces=size(faces,1); delete_flag=[]; for m=1:size_facesinx1=faces(m,1);inx2=faces(m,2);inx3=faces(m,3);v1=vertices(inx1,:);v2=vertices(inx2,:);v3=vertices(inx3,:);s=my_area(v1,v2,v3);if s>thresholddelete_flag=[delete_flag;m];%細分new1=(v1+v2)/2;new2=(v2+v3)/2;new3=(v3+v1)/2;[inx_new1,vertices]=my_index(new1,vertices);[inx_new2,vertices]=my_index(new2,vertices);[inx_new3,vertices]=my_index(new3,vertices);faces_temp=[inx3,inx_new2,inx_new3;inx_new1,inx_new2,inx_new3;inx_new1,inx_new2,inx2;inx_new3,inx_new1,inx1];faces=[faces;faces_temp];endend toc faces(delete_flag,:)=[];%刪除細分過后的原始面 divided_vertices=vertices; divided_faces=faces;endfunction [dist]=my_dist(v1,v2) %輸入兩個點,得到它們之間的距離 dist=power( (v1-v2)*((v1-v2)'),1/2); endfunction [area]=my_area(v1,v2,v3) %輸入三個點,得到由它們構成的三角形的面集a=my_dist(v1,v2);b=my_dist(v2,v3);c=my_dist(v1,v3);p=(a+b+c)/2;area=power(p*(p-a)*(p-b)*(p-c),1/2); endfunction [inx,vertices]=my_index(v,vertices) %輸入一個點,返回該點在點集中的索引行 %如果該點存在,返回索引行,如果該點不存在,插入該點,返回索引行 mem = ismember(vertices,v,'rows'); inx=find(mem==1); if isempty(inx)%如果inx為空vertices=[vertices;v];inx=size(vertices,1); end end

調用:

>> [ divided_vertices ,divided_faces ] = subdivide_mesh01( v',f' ,0.06 ); 時間已過 4.625456 秒。 >> writeOBJ('test_sub02.obj',divided_vertices,divided_faces);

結果:
細分前:

細分后:

優化

將元素運算換成矩陣運算,見文章
【matlab教程】21、matlab優化一:將對單個元素的操作轉換成矩陣之間的運算

總結

以上是生活随笔為你收集整理的【matlab教程】20、简单网格细分的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。