博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
perform_faces_reorientation
阅读量:4042 次
发布时间:2019-05-24

本文共 2777 字,大约阅读时间需要 9 分钟。

function faces = perform_faces_reorientation(vertex,faces, options)% perform_faces_reorientation - reorient the faces with respect to the center of the mesh%%   faces = perform_faces_reorientation(vertex,faces, options);%% try to find a consistant reorientation for faces of a mesh.%%   if options.method = 'fast', then use a fast non accurate method%   if options.method = 'slow', then use a slow exact method%%   Copyright (c) 2007 Gabriel Peyreoptions.null = 0;method = getoptions(options, 'method', 'fast');verb = getoptions(options, 'verb', 1);[vertex,faces] = check_face_vertex(vertex,faces);n = size(vertex,2);m = size(faces,2);if strcmp(method, 'fast')    % compute the center of mass of the mesh    G = mean(vertex,2);    % center of faces    Cf = (vertex(:,faces(1,:)) + vertex(:,faces(2,:)) + vertex(:,faces(3,:)))/3;    Cf = Cf - repmat(G,[1 m]);    % normal to the faces    V1 = vertex(:,faces(2,:))-vertex(:,faces(1,:));    V2 = vertex(:,faces(3,:))-vertex(:,faces(1,:));    N = [V1(2,:).*V2(3,:) - V1(3,:).*V2(2,:) ; ...        -V1(1,:).*V2(3,:) + V1(3,:).*V2(1,:) ; ...        V1(1,:).*V2(2,:) - V1(2,:).*V2(1,:) ];    % dot product    s = sign(sum(N.*Cf));    % reverse faces    I = find(s>0);    faces(:,I) = faces(3:-1:1,I);    returnendoptions.method = 'fast';faces = perform_faces_reorientation(vertex,faces, options);fring = compute_face_ring(faces);tag = zeros(m,1)-1;heap = 1;for i=1:m    if m>100 & verb==1        progressbar(i,m);    end    if isempty(heap)        I = find(tag==-1);         if isempty(I)            error('Problem');        end        heap = I(1);    end    f = heap(end); heap(end) = [];    if tag(f)==1        warning('Problem');    end    tag(f) = 1;    % computed    fr = fring{f};    fr = fr(tag(fr)==-1);    tag(fr)=0;    heap = [heap fr];    for k=fr(:)'        % see if re-orientation is needed        if check_orientation(faces(:,k), faces(:,f))==1            faces(1:2,k) = faces(2:-1:1,k);        end    endendif not(isempty(heap)) || not(isempty(find(tag<1)))    warning('Problem');end% try to see if face are facing in the correct direction[normal,normalf] = compute_normal(vertex,faces);a = mean(vertex,2);a = repmat(a, [1 n]);dp = sign(sum(normal.*a,1));if sum(dp>0)
<0)%这里改成大于了, 原本是小于,seamanj 27/10/2016 faces(1:2,:) = faces(2:-1:1,:);end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function o = check_orientation(f1,f2)i1 = 0; j1 = 0;for i=1:3 for j=1:3 if f1(i)==f2(j) i1 = i; j1 = j; break; end end if i1~=0 break; endendif i1==0 error('Problem.');endia = mod(i1,3)+1;ja = mod(j1,3)+1;ib = mod(i1-2,3)+1;jb = mod(j1-2,3)+1;if f1(ia)==f2(ja) || f1(ib)==f2(jb) o=1;else o = -1;end

转载地址:http://tvxdi.baihongyu.com/

你可能感兴趣的文章
让我做你的下一行Code
查看>>
浅析:setsockopt()改善程序的健壮性
查看>>
关于对象赋值及返回临时对象过程中的构造与析构
查看>>
VS 2005 CRT函数的安全性增强版本
查看>>
SQL 多表联合查询
查看>>
Visual Studio 2010:C++0x新特性
查看>>
drwtsn32.exe和adplus.vbs进行dump文件抓取
查看>>
cppcheck c++静态代码检查
查看>>
在C++中使用Lua
查看>>
一些socket的编程经验
查看>>
socket编程中select的使用
查看>>
关于AIS编码解码的两个小问题
查看>>
GitHub 万星推荐:黑客成长技术清单
查看>>
可以在线C++编译的工具站点
查看>>
关于无人驾驶的过去、现在以及未来,看这篇文章就够了!
查看>>
所谓的进步和提升,就是完成认知升级
查看>>
昨夜今晨最大八卦终于坐实——人类首次直接探测到了引力波
查看>>
为什么读了很多书,却学不到什么东西?
查看>>
长文干货:如何轻松应对工作中最棘手的13种场景?
查看>>
如何用好碎片化时间,让思维更有效率?
查看>>