【CGAL 】表面细化

cgla提供了四种细化方式,这是第一天测试结果,明天四种都测试完在更新这一块,这是其中一种细化方法

// 01frame includes
#include "cgalmethods.h"// VTK includes
#include <vtkSTLReader.h>
#include <vtkSmartPointer.h>// CGAL includes
#include <CGAL/Simple_cartesian.h>// CGAL includes
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
#include <CGAL/subdivision_method_3.h>
#include <CGAL/Timer.h>
#include <boost/lexical_cast.hpp>
#include <iostream>
#include <fstream>
void CGALMethods::CatmullClarkSubdivision(QString off_filename) {typedef CGAL::Simple_cartesian<double>         Kernel;typedef CGAL::Surface_mesh<Kernel::Point_3>    PolygonMesh;using namespace std;using namespace CGAL;namespace params = CGAL::parameters;PolygonMesh pmesh;std::ifstream in(off_filename.toLocal8Bit().data());if (in.fail()) {qWarning() << "Could not open input file ";return ;}in >> pmesh;Timer t;t.start();Subdivision_method_3::CatmullClark_subdivision(pmesh, params::number_of_iterations(1));std::ofstream out(off_filename.toLocal8Bit().data());out << pmesh;
}


完整代码

  • Source/05CGALThread/cgalthread.h
  • Source/05CGALThread/cgalthread.cpp
  • Source/05CGALThread/cgalthreadsubdivision.h
  • Source/05CGALThread/cgalthreadsubdivision.cpp
/** CGAL线程   操作基类* 仅有run函数在子线程,其余均在主线程
*/#ifndef CGALTHREAD_H
#define CGALTHREAD_H//01frame
#include "app.h"class CGALThread : public QThread {Q_OBJECTpublic:explicit CGALThread(QObject *parent = nullptr);virtual ~CGALThread() override;bool GetThreadResult() const;//获取结果protected:virtual void run() override;//线程void InitialResult();//初始化void SetResult(const bool result);//设置结果protected:bool result_;//执行结果
};#endif // CGALTHREAD_H
// 01frame includes
#include "cgalthread.h"CGALThread::CGALThread(QObject *parent) : QThread(parent) {this->InitialResult();
}CGALThread::~CGALThread() {}bool CGALThread::GetThreadResult() const {return this->result_;
}void CGALThread::run() {}void CGALThread::InitialResult() {this->result_ = false;
}void CGALThread::SetResult(const bool result) {result_ |= result;
}
/** CGAL 表面细分算法* */#ifndef CGALTHREADSUBDIVISIONMETHODS_H
#define CGALTHREADSUBDIVISIONMETHODS_H// 01frame includes
#include "app.h"// 05CGALThread includes
#include "cgalthread.h"// VTK includes
#include <vtkPolyData.h>class CGALThreadSubdivision : public CGALThread {Q_OBJECTpublic:explicit CGALThreadSubdivision(QObject *parent = nullptr);virtual ~CGALThreadSubdivision() override;void doWork();void SetSurface(const vtkSmartPointer<vtkPolyData> value);vtkSmartPointer<vtkPolyData> GetSurface();protected:virtual void run() override;private:void STL2OFF(QString off_filename);void OFF2STL(QString off_filename);void CatmullClarkSubdivision(QString off_filename);vtkPolyData *CustomReader(std::istream &infile);private:vtkSmartPointer<vtkPolyData> polydata_;};#endif // CGALSURFACESUBDIVISIONMETHODS_H
// 01frame includes
#include "cgalthreadsubdivision.h"// C++ includes
#include <string.h>
#include <fstream>
#include <iostream>// VTK includes
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkCellArray.h>
#include <vtkSmartPointer.h>// CGAL includes
#include <CGAL/Timer.h>
#include <CGAL/Surface_mesh.h>
#include <boost/lexical_cast.hpp>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/subdivision_method_3.h>
#include <CGAL/boost/graph/graph_traits_Surface_mesh.h>CGALThreadSubdivision::CGALThreadSubdivision(QObject *parent) :CGALThread(parent) {this->polydata_ = nullptr;
}CGALThreadSubdivision::~CGALThreadSubdivision() {}void CGALThreadSubdivision::doWork() {STL2OFF("STL2OFF.off");CatmullClarkSubdivision("STL2OFF.off");OFF2STL("STL2OFF.off");this->SetResult(true);
}void CGALThreadSubdivision::SetSurface(const vtkSmartPointer<vtkPolyData> value) {this->polydata_ = value;
}vtkSmartPointer<vtkPolyData> CGALThreadSubdivision::GetSurface() {return this->polydata_;
}void CGALThreadSubdivision::run() {this->InitialResult();this->doWork();
}void CGALThreadSubdivision::STL2OFF(QString off_filename) {qDebug();if (this->polydata_ == nullptr) {return;}if (off_filename.isEmpty()) {return;}double x[3];QFile file(off_filename);file.open(QIODevice::WriteOnly);file.close();if (file.open(QIODevice::ReadWrite | QIODevice::Text)) {QTextStream stream(&file);stream.seek(file.size());stream << "OFF" << "\n";stream << this->polydata_->GetNumberOfPoints() << " "<< this->polydata_->GetNumberOfCells() << " 0\n";for (int ww = 0; ww < this->polydata_->GetNumberOfPoints() ; ww++) {this->polydata_->GetPoint(ww, x);stream << x[0] << " " << x[1] << " " << x[2] << "\n";}for (int ww = 0; ww < this->polydata_->GetNumberOfCells() ; ww++) {stream << this->polydata_->GetCell(ww)->GetNumberOfPoints() << " ";for (int i = 0; i <this->polydata_->GetCell(ww)->GetNumberOfPoints(); i++) {stream << this->polydata_->GetCell(ww)->GetPointId(i) << " ";}stream << "\n";}file.close();}
}void CGALThreadSubdivision::OFF2STL(QString off_filename) {std::string inputFilename = off_filename.toLocal8Bit().data();std::ifstream fin(inputFilename.c_str());if (this->polydata_ == nullptr) {return;}this->polydata_ = vtkSmartPointer<vtkPolyData>::Take(CustomReader(fin));
}void CGALThreadSubdivision::CatmullClarkSubdivision(QString off_filename) {typedef CGAL::Simple_cartesian<double>         Kernel;typedef CGAL::Surface_mesh<Kernel::Point_3>    PolygonMesh;using namespace std;using namespace CGAL;namespace params = CGAL::parameters;PolygonMesh pmesh;std::ifstream in(off_filename.toLocal8Bit().data());if (in.fail()) {qWarning() << "Could not open input file ";return ;}in >> pmesh;Subdivision_method_3::CatmullClark_subdivision(pmesh, params::number_of_iterations(1));Timer t;t.start();Subdivision_method_3::CatmullClark_subdivision(pmesh, params::number_of_iterations(1));std::cerr << "Done (" << t.time() << " s)" << std::endl;std::ofstream out(off_filename.toLocal8Bit().data());out << pmesh;
}vtkPolyData *CGALThreadSubdivision::CustomReader(istream &infile) {qDebug();char buf[1000];infile.getline(buf, 1000);if (strcmp(buf, "off") == 0 || strcmp(buf, "OFF") == 0) {vtkIdType number_of_points, number_of_triangles, number_of_lines;infile >> number_of_points >> number_of_triangles >> number_of_lines;vtkSmartPointer<vtkPoints> points= vtkSmartPointer<vtkPoints>::New();points->SetNumberOfPoints(number_of_points);for (vtkIdType i = 0; i < number_of_points; i++) {double x, y, z;infile >> x >> y >> z;points->SetPoint(i, x, y, z);}vtkSmartPointer<vtkCellArray> polys= vtkSmartPointer<vtkCellArray>::New();int n;vtkIdType type;for (vtkIdType i = 0; i < number_of_triangles; i++) {infile >> n;polys->InsertNextCell(n);for (; n > 0; n--) {infile >> type;polys->InsertCellPoint(type);}}vtkPolyData *polydata = vtkPolyData::New();polydata->SetPoints(points);polydata->SetPolys(polys);return polydata;}vtkPolyData *polydata = vtkPolyData::New();return polydata;
}

【CGAL】表面细化相关推荐

  1. CGAL表面网格降采样

    CGAL表面网格降采样 1. CGAL Surface_mesh_simplification模块 2. 源为stl格式数据 1. CGAL Surface_mesh_simplification模块 ...

  2. 翻译:PlaneRCNN: 3D Plane Detection and Reconstruction from a Single Image

    图1.本文提出了一种深度神经网络结构PlaneRCNN,该结构检测平面区域,并从单个RGB图像重建分段平面深度图.从左到右,输入图像.分割的平面区域.估计的深度图和重建的平面. 摘要 本文提出了一种深 ...

  3. 学习OpenFOAM Tutorial snappyHexMesh

    OpenFOAM v8 SnappyHexMesh 一.SnappyHexMesh是什么? 二.使用SnappyHexMesh生成网格 1.snappyHexMesh的网格生成过程 2.使用Snapp ...

  4. 【OpenFOAM】snappyHexMesh

    个人学习记录. 原创内容请查看以下链接. 参考    网格划分篇-SnappyHexMesh (之一)    网格划分篇-SnappyHexMesh(之三) 个人经验 网格贴合 snap 中的一些迭代 ...

  5. Opengl-法线贴图(用来细化表面的表现表现的凹凸)

    我们通过这张图可以看出来,使用了法线贴图的物体表面更有细节更逼真,其实这就是发现贴图的作用,没什么钻牛角尖的. 其实表面没有凹凸的情况是因为我们把表面一直按照平整来做的,要想突出这个表面的凹凸就要用到 ...

  6. CGAL例程:地理信息系统----点云数据生成DSM、DTM、等高线和数据分类

    作者:西蒙·吉罗多 链接:CGAL 5.4 - Manual: GIS (Geographic Information System) 目录 1 概述 2 不规则三角形网数据表示:TIN 3 数字表面 ...

  7. CGAL笔记之单元格复合体和多面体篇—三维多面体曲面

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 CGAL笔记之单元格复合体和多面体篇-三维多面体曲面 1 介绍 2 定义 3 示例程序 3.1 第一个使用默认值的例子 3.2 顶点中 ...

  8. matlab 细化函数,MATLAB图像处理工具箱函数(细化篇).doc

    MATLAB图像处理工具箱函数(细化篇) 第3章 MATLAB数字图像处理工具箱 3.1 MATLAB图像预处理 3.1.1 图像处理的基本操作 1. 读入并显示一幅图像 clear %清除所有的工作 ...

  9. CGAL 4.11 官方文档 软件包概述 ——胞腔复形与多面体类

    原文链接:https://doc.cgal.org/latest/Manual/packages.html 译文首发:http://blog.csdn.net/duzixi Cell Complexe ...

最新文章

  1. 仿微信的网络聊天室项目开发【完整源码讲解,Java一年工作经验面试题
  2. C语言素数筛选法(prime seive) 算法(附完整源码)
  3. 指针数组和数组指针——兄弟你的括号呢?
  4. SAP CRM WebClient UI incident - how is sales area saved
  5. 命中率_三分命中率暴涨19%!卡皇进化已无弱项,顶级3D练成何须布拉
  6. day7 地址 名片管理系统
  7. 由于找不到appvisvsubsystems32.dll_终于熬到孩子上幼儿园,宝妈却找不到工作了,背后原因让人心酸...
  8. windows电脑上一些软件如画图/记事本变成了英文
  9. 创意简单html游戏,创意绝佳趣味慢慢的网页互动小游戏
  10. Qt Design studio使用
  11. HTML编辑器UEditor的简单使用
  12. 基于微信小程序的图书馆管理系统设计与实现(论文+程序设计源码+数据库文件)
  13. 大部分人都容易焦虑,那么应该如何对待焦虑呢?
  14. 从 jsonpath 和 xpath 到 SPL
  15. cv2.error: OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-1y7gm6kn\opencv\modul
  16. 锤子T1(Smartisan T1 4G)版刷成3G版,即sm705运行sm701的CM11 Android 4.4.4ROM
  17. HIT信息安全概论复习:1~10
  18. python opencv调用摄像头并追踪移动物体,浅析Python+OpenCV使用摄像头追踪人脸面部血液变化实现脉搏评估...
  19. 解决Kubernetes的flannel pod出现Init:RunContainerError问题
  20. (三)AsyncTask

热门文章

  1. 关于解压 tar.gz的问题
  2. 一步步教你做“锅打灰太狼”
  3. 第3.7章:StarRocks数据导入--Broker Load
  4. 使用循环语句判断月份是31天还是30天?
  5. ​Excel如何转换成Word文档?教你如何实现转换
  6. 2023年租房投影仪推荐,出租屋投影仪值得买吗?又该怎么选择?
  7. java使用poi操作excel,写入excel数据并下载
  8. STM32单片机擦除片内Flash超时报错问题排查
  9. 11个超好用的SVG编辑工具
  10. 一个https域名访问多种服务器