⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vdpmsynthesizerviewerwidget.cc

📁 penMesh is a generic and efficient data structure for representing and manipulating polygonal meshes
💻 CC
📖 第 1 页 / 共 2 页
字号:
/*===========================================================================*\ *                                                                           * *                               OpenMesh                                    * *      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen      * *                           www.openmesh.org                                * *                                                                           * *---------------------------------------------------------------------------*  *                                                                           * *                                License                                    * *                                                                           * *  This library is free software; you can redistribute it and/or modify it  * *  under the terms of the GNU Library General Public License as published   * *  by the Free Software Foundation, version 2.                              * *                                                                           * *  This library is distributed in the hope that it will be useful, but      * *  WITHOUT ANY WARRANTY; without even the implied warranty of               * *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        * *  Library General Public License for more details.                         * *                                                                           * *  You should have received a copy of the GNU Library General Public        * *  License along with this library; if not, write to the Free Software      * *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                * *                                                                           *\*===========================================================================*///=============================================================================////  CLASS newClass - IMPLEMENTATION////=============================================================================//== INCLUDES =================================================================#ifdef _MSC_VER#  pragma warning(disable: 4267 4311)#endif#include <iostream>#include <fstream>#include <map>#include <qapplication.h>#include <qdatetime.h>#include <qfiledialog.h>#include <qdatastream.h>#ifndef WIN32#ifdef ARCH_DARWIN#  include <glut.h>#else#  include <GL/glut.h>#endif#endif#include <OpenMesh/Core/IO/MeshIO.hh>#include <OpenMesh/Core/IO/BinaryHelper.hh>#include <OpenMesh/Core/Utils/Endian.hh>#include <OpenMesh/Tools/Utils/Timer.hh>#include <OpenMesh/Apps/VDProgMesh/Synthesizer/VDPMSynthesizerViewerWidget.hh>//== NAMESPACES ===============================================================namespace OpenMesh {//== IMPLEMENTATION ========================================================== voidVDPMSynthesizerViewerWidget::draw_scene(const std::string &_draw_mode){  if (adaptive_mode_ == true)  {        adaptive_refinement();  }  MeshViewerWidget::draw_scene(_draw_mode);  }voidVDPMSynthesizerViewerWidget::adaptive_refinement(){  update_viewing_parameters();  VDPMMesh::HalfedgeHandle v0v1;  float fovy = viewing_parameters_.fovy();  float tolerance_square = viewing_parameters_.tolerance_square();  float	tan_value = tanf(fovy / 2.0f);	  kappa_square_ = 4.0f * tan_value * tan_value * tolerance_square;  //assert( !vfront_.end() );  for ( vfront_.begin(); !vfront_.end(); )  {    VHierarchyNodeHandle        node_handle   = vfront_.node_handle(),      parent_handle = vhierarchy_.parent_handle(node_handle);        if (vhierarchy_.is_leaf_node(node_handle) != true &&         qrefine(node_handle) == true)    {      force_vsplit(node_handle);          }    else if (vhierarchy_.is_root_node(node_handle) != true && 	     ecol_legal(parent_handle, v0v1) == true       && 	     qrefine(parent_handle) != true)    {      ecol(parent_handle, v0v1);    }    else    {      vfront_.next();    }  }  // free memories tagged as 'deleted'  mesh_.garbage_collection(false, true, true);   mesh_.update_face_normals();}boolVDPMSynthesizerViewerWidget::qrefine(VHierarchyNodeHandle _node_handle){  VHierarchyNode &node    = vhierarchy_.node(_node_handle);  Vec3f p       = mesh_.point(node.vertex_handle());    Vec3f eye_dir = p - viewing_parameters_.eye_pos();;  float	distance = eye_dir.length();  float	distance2 = distance * distance;  float	product_value = dot(eye_dir, node.normal());  if (outside_view_frustum(p, node.radius()) == true)    return	false;  if (oriented_away(node.sin_square(), distance2, product_value) == true)    return	false;  if (screen_space_error(node.mue_square(), 			 node.sigma_square(), 			 distance2, 			 product_value) == true)    return false;    return true;}void VDPMSynthesizerViewerWidget::force_vsplit(VHierarchyNodeHandle node_handle){  VDPMMesh::VertexHandle  vl, vr;  get_active_cuts(node_handle, vl, vr);  while (vl == vr)   {    force_vsplit(mesh_.vertex(vl).vhierarchy_node_handle());    get_active_cuts(node_handle, vl, vr);  }	  vsplit(node_handle, vl, vr);}voidVDPMSynthesizerViewerWidget::vsplit(VHierarchyNodeHandle _node_handle,        VDPMMesh::VertexHandle vl,        VDPMMesh::VertexHandle vr){  // refine  VHierarchyNodeHandle      lchild_handle = vhierarchy_.lchild_handle(_node_handle),    rchild_handle = vhierarchy_.rchild_handle(_node_handle);  VDPMMesh::VertexHandle  v0 = vhierarchy_.vertex_handle(lchild_handle);  VDPMMesh::VertexHandle  v1 = vhierarchy_.vertex_handle(rchild_handle);    mesh_.vertex_split(v0, v1, vl, vr);  mesh_.set_normal(v0, vhierarchy_.normal(lchild_handle));  mesh_.set_normal(v1, vhierarchy_.normal(rchild_handle));  mesh_.vertex(v0).set_vhierarchy_node_handle(lchild_handle);  mesh_.vertex(v1).set_vhierarchy_node_handle(rchild_handle);  mesh_.status(v0).set_deleted(false);  mesh_.status(v1).set_deleted(false);    vfront_.remove(_node_handle);  vfront_.add(lchild_handle);  vfront_.add(rchild_handle);  }void VDPMSynthesizerViewerWidget::ecol(VHierarchyNodeHandle _node_handle, const VDPMMesh::HalfedgeHandle& v0v1){  VHierarchyNodeHandle      lchild_handle = vhierarchy_.lchild_handle(_node_handle),    rchild_handle = vhierarchy_.rchild_handle(_node_handle);  VDPMMesh::VertexHandle  v0 = vhierarchy_.vertex_handle(lchild_handle);  VDPMMesh::VertexHandle  v1 = vhierarchy_.vertex_handle(rchild_handle);  // coarsen  mesh_.collapse(v0v1);  mesh_.set_normal(v1, vhierarchy_.normal(_node_handle));  mesh_.vertex(v0).set_vhierarchy_node_handle(lchild_handle);  mesh_.vertex(v1).set_vhierarchy_node_handle(_node_handle);  mesh_.status(v0).set_deleted(false);  mesh_.status(v1).set_deleted(false);  vfront_.add(_node_handle);  vfront_.remove(lchild_handle);  vfront_.remove(rchild_handle);}boolVDPMSynthesizerViewerWidget::ecol_legal(VHierarchyNodeHandle _parent_handle, VDPMMesh::HalfedgeHandle& v0v1){  VHierarchyNodeHandle    lchild_handle = vhierarchy_.lchild_handle(_parent_handle),    rchild_handle = vhierarchy_.rchild_handle(_parent_handle);  // test whether lchild & rchild present in the current vfront  if ( vfront_.is_active(lchild_handle) != true ||        vfront_.is_active(rchild_handle) != true)    return  false;    VDPMMesh::VertexHandle v0, v1;  v0 = vhierarchy_.vertex_handle(lchild_handle);  v1 = vhierarchy_.vertex_handle(rchild_handle);  v0v1 = mesh_.find_halfedge(v0, v1);    return  mesh_.is_collapse_ok(v0v1);}voidVDPMSynthesizerViewerWidget::get_active_cuts(const VHierarchyNodeHandle _node_handle, 		VDPMMesh::VertexHandle &vl, VDPMMesh::VertexHandle &vr){  VDPMMesh::VertexVertexIter  vv_it;  VHierarchyNodeHandle        nnode_handle;  VHierarchyNodeIndex    nnode_index,     fund_lcut_index = vhierarchy_.fund_lcut_index(_node_handle),    fund_rcut_index = vhierarchy_.fund_rcut_index(_node_handle);  vl = VDPMMesh::InvalidVertexHandle;  vr = VDPMMesh::InvalidVertexHandle;    for (vv_it=mesh_.vv_iter(vhierarchy_.vertex_handle(_node_handle));        vv_it; ++vv_it)  {    nnode_handle = mesh_.vertex(vv_it.handle()).vhierarchy_node_handle();    nnode_index = vhierarchy_.node_index(nnode_handle);    if (vl == VDPMMesh::InvalidVertexHandle && 	vhierarchy_.is_ancestor(nnode_index, fund_lcut_index) == true)      vl = vv_it.handle();    if (vr == VDPMMesh::InvalidVertexHandle && 	vhierarchy_.is_ancestor(nnode_index, fund_rcut_index) == true)      vr = vv_it.handle();    /*if (vl == VDPMMesh::InvalidVertexHandle && nnode_index.is_ancestor_index(fund_lcut_index) == true)      vl = vv_it.handle();    if (vr == VDPMMesh::InvalidVertexHandle && nnode_index.is_ancestor_index(fund_rcut_index) == true)      vr = vv_it.handle();*/    if (vl != VDPMMesh::InvalidVertexHandle && 	vr != VDPMMesh::InvalidVertexHandle)      break;  }}bool VDPMSynthesizerViewerWidget::outside_view_frustum(const Vec3f &pos, float radius){  #if 0  return     (frustum_plane_[0].signed_distance(pos) < -radius) ||

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -