当前位置:网站首页>Source code reading | the process of reading text format STL by openmesh
Source code reading | the process of reading text format STL by openmesh
2022-06-24 22:44:00 【CSU kayah】
bool
_STLReader_::
read_stla(std::istream& _in, BaseImporter& _bi, Options& _opt) const
{// The data flow is from _in To _bi in
unsigned int i;
OpenMesh::Vec3f v;// Store the three-dimensional coordinates of a single vertex vector Containers
OpenMesh::Vec3f n;// Storage of single normal three-dimensional coordinates vector Containers
BaseImporter::VHandles vhandles;// Storing a triangular patch 3 Handles to vertices
CmpVec comp(eps_);// Used to compare whether vertices coincide ,eps_ Is a very small constant
std::map<Vec3f, VertexHandle, CmpVec> vMap(comp);// A collection container of vertex handles that maps vertex coordinate containers
std::map<Vec3f, VertexHandle, CmpVec>::iterator vMapIt;// The iterator of the previous row collection container
std::string line;// Store the single line content in the input stream
std::string garbage;// Obsolete string
std::stringstream strstream;// Extract strings one by one from a single line
bool facet_normal(false);// Identifies whether a triangular patch has a normal
while( _in && !_in.eof() ) {//while A loop is the real implementation of a read
// Get one line Get a line to line
std::getline(_in, line);
if ( _in.bad() ){// If there is a fatal error
omerr() << " Warning! Could not read stream properly!\n";
return false;
}
// Trim Both leading and trailing spaces Delete the spaces before and after
trimStdString(line);
// Normal found?
if (line.find("facet normal") != std::string::npos) {
strstream.str(line);
strstream.clear();
// facet The string is discarded
strstream >> garbage;
// normal The string is discarded
strstream >> garbage;
strstream >> n[0];// Read in the three-dimensional coordinates of the normal direction of the patch in turn
strstream >> n[1];
strstream >> n[2];
facet_normal = true;
}
// Detected a triangle The three-dimensional coordinates of a triangular patch are expressed in outer loop At the beginning
if ( (line.find("outer") != std::string::npos) || (line.find("OUTER") != std::string::npos ) ) {
vhandles.clear();// Clear the vertex handle of the previous patch
for (i=0; i<3; ++i) {// Read in three vertices in turn
// Get one vertex
std::getline(_in, line);
trimStdString(line);// line The format is similar --vertex 0 0 0
strstream.str(line);
strstream.clear();
strstream >> garbage;// lose vertex
strstream >> v[0];// Store the three-dimensional coordinates of the current vertex in turn
strstream >> v[1];
strstream >> v[2];
// has vector been referenced before? Judge that the vertex is at vMap Whether it has been stored in
if ((vMapIt=vMap.find(v)) == vMap.end()) stay vMap I can't find
{
// No : add vertex and remember idx/vector mapping
VertexHandle handle = _bi.add_vertex(v);// The key , Add the coordinate vector of the vertex to _bi in
vhandles.push_back(handle);// Only this sentence else Also in the block
vMap[v] = handle;
}
else
// Yes : get index from map
vhandles.push_back(vMapIt->second);
}
// Add face only if it is not degenerated Judge whether a face degenerates
if ((vhandles[0] != vhandles[1]) &&
(vhandles[0] != vhandles[2]) &&
(vhandles[1] != vhandles[2])) { // Any two of the three vertices of the face coincide, indicating that the face degenerates
FaceHandle fh = _bi.add_face(vhandles);// Add non degenerate faces to _bi in , Note that the face here is referred to by the handle of its three vertices
// set the normal if requested
// If there is a normal , Set normal information for it
// if a normal was requested but could not be found we unset the option
if (facet_normal) {
if (fh.is_valid() && _opt.face_has_normal())
_bi.set_normal(fh, n);
} else
_opt -= Options::FaceNormal;
}
facet_normal = false;
}
}
return true;
}Reference documents
边栏推荐
- Rip protocol of dynamic routing protocol
- Learn more about the practical application of sentinel
- STP spanning tree protocol Foundation
- Cross border e-commerce, early entry and early benefit
- 详细了解关于sentinel的实际应用
- Genesis公链与美国一众加密投资者齐聚Consensus 2022
- [QT] QT event handling
- 中国SSD行业企业势力全景图
- In the multi network card environment, the service IP registered by Nacos is incorrect, resulting in inaccessible services
- Fanuc robot_ Introduction to Karel programming (1)
猜你喜欢

The usage difference between isempty and isblank is so different that so many people can't answer it

Database transaction Transanction

CDN principle

Chapter 10 project communication management

Annotation

详细了解Redis的八种数据类型及应用场景分析

AQS source code analysis

ThreadLocal memory leak

Uncover the secret of station B. is it true that programmers wear women's clothes and knock code more efficiently?

2022-06-10 work record --js- obtain the date n days after a certain date
随机推荐
Online filing process
Cache control of HTTP
Common voting governance in Dao
Description of transparent transmission function before master and slave of kt6368a Bluetooth chip, 2.4G frequency hopping automatic connection
Based on the codeless platform, users deeply participated in the construction, and digital data + Nanjing Fiberglass Institute jointly built a national smart laboratory solution
See how sparksql supports enterprise data warehouse
Docker installs MySQL 8.0. Detailed steps
Cross border e-commerce, early entry and early benefit
使用Aggregated APIServer扩展你的kubernetes API
Technology Review: what is the evolution route of container technology? What imagination space is there in the future?
源码阅读 | OpenMesh读取文本格式stl的过程
The ktp900f mobile download program of the fail safe mobile panel prompts that the download cannot be performed, and the target device is running or not in the transmission mode
O (n) complexity hand tear sorting interview questions | an article will help you understand counting sorting
Panorama of enterprise power in China SSD industry
Embedded development: tips and tricks -- clean jump from boot loader to application code
cat写多行内容到文件
img2pdf
nuScenes——数据集配置过程中遇到图像文件缺失或大小为0时的补救方法
Short video mall system, how does scroll view adapt to the remaining height of the page
【个人实验报告】