小知识补充:
在知道CuraEngine的工作原理之前,需要先知道STL格式的含义。.stl 文件是在计算机图形应用系统中,用于表示三角形网格的一种文件格式。它的文件格式非常简单,应用很广泛。STL是最多快速原型系统所应用的标准文件类型。STL是用三角网格来表现3D CAD模型。Stl文件中存放的是无数个空间三角面的位置信息(空间中,每个三角面的确定是通过它三个定点的坐标来的)。所以,我们如果要对一个3d模型进行切割,实际上就是用一个平面来和无数小三角形做相交,得到很多条交线,我们把这些交线连接起来就得到了切平面。
   CuraEngine基本工作流程
   笔者一开始就选择了Cura作为研究对象,有两个原因:一是slice3R的切片速度明显不如Cura,二是,Cura的切片引擎使用的是C++…这是笔者所钟爱的开发语言。虽然Cura的界面是用Python语言写的,但这不影响底层切片软件引擎的使用。
下面是CuraEngine的github上关于Cura项目的介绍和描述。
(https://github.com/Ultimaker/CuraEngine)
1.1    总流程
The Cura Engine is structured as mainly .hfiles. This is not standard for an C++ project. However, using less cpp filesmakes the optimizer work harder and removes linking error issues. It's partialya result of lazyness but also for optimalizations.
The .h files contain different steps calledfrom the main.cpp file. The main.cpp file contains the global slicing logic.
The slicing process follows the followingglobal steps:
Load 3D model
Analize and fix 3D model
Slice 3D model into 2D layers
Build LayerParts from sliced layers
Generate Insets
Generate up/down skins areas
Generate sparse infill areas
Generate GCode for each layer
Each step has more logic in it. But this isa general overview. All data for the engine is stored in the"SliceDataStorage". It's important to remember that only the data fromthe previous step is valid.
Coordinates are stored in 64bit integers asmicrons in the code. So if you see a value of 1000 then this mean 1mm ofdistance. This is because Clipper works on 64bit integers and microns give ahigh enough resolution without limiting the size too much. Note that there aresome bits and pieces of code that need to be careful about 64bit overflows,especially calculating lengths sqrt(x*x+y*y) can cause overflows.

下面我把自己理解的意思说一下,英文烂,勿喷。
首先,Cura不是一个标准的C++工程,他大部分的函数都是在.h文件中实现的,这样做,使得在编译过程中优化出现了很多的错误,这主要是由于懒的原因….(..请跳过)。
切片程序的主要过程如下:
         i.             导入3D模型(STL,OBJ等等)。
        ii.             分析并修复3D模型(源码里面貌似木有这一步…)。
       iii.             将3D模型切割成2D层。
       iv.             用上一步得到的2D图层形成LayerParts(他们自己的叫法),因为一层里面,很有可能有很多个不同的多边形,比如桌子,他的四个角,切出来后是四个圆形,上一步中只是得到了四个圆形,而没有确定这四个圆形是属于同一层的。
        v.             进一步确定LayerParts中,各个part间的关系,比如得到了两个圆,大圆套小圆,我们就需要确认,小圆是空心的,而大圆和小圆形成的圆环是实心的。
       vi.             将需要实心打印的部分标记出来(100%填充)。
      vii.             将需要空心打印的地方打印出来(部分填充)。
     viii.             根据生成的LayerParts生成每一层的G-code。
上述的每一步都有更多的逻辑关系在里面,但这只是一个工作的大概流程。切割引擎所有的数据都存放在一个叫SliceDataStorage的类里面。记住,上述的每一步都是基于前一步的数据来进行的。这里严格按照上述的流程来处理3D模型生成G-code。另外,在代码里面,坐标是用64位整数的形式存在的,比如,你在代码中看到的1000,他实际代表了1mm。这样做是因为Clipper使用了64为整数来表示距离。

1.2    源码中几个重要的类  1.    OptimizedModel
The OptimizedModel is a 3D model storedwith vertex<->face relations. This gives touching face relations whichare used later on to slice into layers faster.

OptimizedModel也是一个3D模型,只是他是对一开始导入的模型进行的优化,去除了3D模型中多余的数据,同时确立了3D模型中每个三角面之间的拓扑关系。这是整个软件最为核心的一部分之一。他为后面一步进行切割做好了准备,没有他slice无法进行。

2.   Slicer
While usually the whole GCode generationprocess is called Slicing. The slicer in the CuraEngine is the piece of codethat generates layers. Each layer has closed 2D polygons. These polygons aregenerated in a 2 step process. First all triangles are cut into lines perlayer, for each layer a "line segment" is added to that layer. Nextall these line-segments are connected to eachother to make Polygons. Thevertex<->face relations of the OptimizedModel help to make this processfast, as there is a huge chance that 2 connecting faces also make 2 connectingline-segments. This code also fixes up small holes in the 3D model, so yourmodel doesn't need to be perfect Manifold. It also accounts for incorrectnormals, so it can flip around line-segments to fit end-to-end.
After the Slicer we have closed Polygonswhich can be used in Clipper, as Clipper can only opperate on closed 2Dpolygons.

我们通常都把由3D模型生成G-code的过程叫做slicing.在CuraEngine中,Slicer只是数量很小的一部分代码,用于生成layers。每个layer都有闭合的2D多边形。这些多边形的形成有两步。
l  第一步,用一个切割平面同所有三角形做相交运算,得到和这个平面相交的线段就是属于这个layer的,这些切割后得到的线段称之为”linesegment”。此时,layer里面只是有一些零散的线段。
l  第二步,将这些linesegment连起来,形成封闭的多边形。
由于OptimizedModel已经将各个相邻三角形之间的关系确立好了,这里的slice速度变得很快。在进行完slice之后,我们就得到了封闭的多边形曲线,这些曲线,要交给Clipper库来进行下一步的处理。Clipper库只能用于处理2D的封闭多边形模型。(Clipper的用途请google)。

3. LayerParts
An important concept to grasp is theLayerParts. LayerParts are seperate parts inside a single layer. For example,if you have a cube. Then each layer has a single LayerPart. However, if youhave a table, then the layers which build the legs have a LayerPart per leg,and thus there will be 4 LayerParts. A LayerPart is a seperated area inside asingle layer which does not touch any other LayerParts. Most operations run onLayerParts as it reduces the amount of data to process. During GCode generationhandling each LayerPart as an own step makes sure you never travel betweenLayerParts and thus reducing the amount of external travel. LayerParts are generatedafter the Slicer step.
To generate the LayerParts Clipper is used.A Clipper union with extended results gives a list of Polygons with holes inthem. Each polygon is a LayerPart, and the holes are added to this LayerPart.

LayerParts是需要掌握的一个重要概念。LayerParts是一个单独的layer中的一部分。比如,切割一个正方体,我们只会得到一个LayerPart,但是,如果切割一个桌子,这个桌子有四个脚,我们就会得到四个切面,也就是四个LayerPart,我们把这在同一平面的四个LayerPart称为layer。在生成G-code的过程中,都是对每个LayerPart单独操作,避免了打印机在两个LayerPart之间打印多余的东西。同时也减少了喷头运动的距离。为了生成LayerPart,我们要使用到Clipper库。

4.Up/Down skin
The skin code generates the fully filledareas, it does this with some heavy boolean Clipper action. The skin step usesdata from different layers to get the job done. Check the code for details. Thesparse infill area code is almost the same as the skin code. With thedifference that it keeps the other areas and uses different offsets.
Note that these steps generate the areas,not the actual infill lines. The infill line paths are generated later on. Sothe result of this step are list of Polygons which are the areas that need tobe filled.
这部分的功能是确定模型中,需要完全被填充的部位,这里大量使用了Clipper库里面的布尔运算。如果自己看Cura的代码会发现,这里的skin(完全填充)和sparse fill(稀疏填充)的代码是几乎一样的,只是设置了不同的填充比例而已。注意,这一步只是标记了需要填充的区域,真正的填充操作是在下面一步生成G-code的过程中进行。

5. G-code 生成器
The GCode generation is quite a large bitof code. As a lot is going on here. Important bits here are:
PathOrderOptimizer: This piece of codeneeds to solve a TravelingSalesmanProblem. Given a list of polygons/lines ittries to find the best order in which to print them. It currently does this byfinding the closest next polygon to print.
Infill: This code generates a group oflines from an area. This is the code that generates the actuall infill pattern.There is also a concentric infill function, which is currently not used.
Comb: The combing code is the code thattries to avoid holes when moving around the head without printing. This codealso detects when it fails. The final GCode generator uses the combing codewhile generating the final GCode. So they interact closely.
GCodeExport: The GCode export is a 2 stepprocess. First it collects all the paths for a layer that it needs to print,this includes all moves, prints, extrusion widths. And then it generates thefinal GCode. This is the only piece of code that has knowledge about GCode, andto generate a different flavor of GCode it will be the only piece that needsadjustment. All volumatric calculations also happen here.

G-code生成器有非常多的代码,这里给出他主要的几个点:
l  PathOrderOptimizer:这部分代码是路径优化代码,计算最优路径。提供很多歌多边形,然后找到最好的顺序和最好的路径来走完他们。比如,你打印完这一个LayerPart后,你需要找到下一个离他最近的LayerPart多边形来打印
l  Infill :这部分代码会在一个区域里生成一组线。
l  Comb:这部分的代码,是为了避免在打印机不喷丝时移动喷头而不会同打印好的层发生接触从而产生一些不好的洞。
l  GCodeExport:导出G-code分为两个步骤,首先,他将需要打印的那一层(layer,不是LayerPart)的所有路径收集起来,包括移动,打印,挤出宽度等。然后生成最终的G-code。只有这一部分的代码是和G-code直接相关的。要生成不同的G-code,只需要在这里做少量的调整即可。另外,对模型体积的计算,也是在这一步中计算出来的。

CuraEngine相关推荐

  1. cura-engine学习(1)

    cura-engine为开源3D打印软件cura的核心引擎代码,详细介绍参看github主页.现在学习的是一个简单版的https://github.com/repetier/CuraEngine,最新 ...

  2. curaengine linux编译,Cura源码在Ubuntu15.04上编译脚本(成功)

    Cura是著名的3D打印切片和控制软件.新的版本采用Qt和Python进行了重构,界面变化也非常大,目前还在开发中,运行问题还有不少.这里介绍如何从源代码进行Cura的编译,可以抢先体验新版的界面设计 ...

  3. 3D 打印切片软件 CuraEngine 介绍

    Scientists study the world as it is, engineers create the world that never has been. 跳至正文 首页 ← Mac下各 ...

  4. 3D打印切片软件CuraEngine介绍 windows版本

    不再更新CuraEngine博文,ustc博客也已经注销.博客中图片无法显示的话,请转 http://www.wrighteaglehardware.tk/ . 最新进展可加群 187233472 讨 ...

  5. curaengine linux编译,CuraEngine开源程序解读

    8种机械键盘轴体对比 本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选? mesh mesh中主要定义了关于三角形网格三个类和这三个类的一些成员函数,分别是MeshVertex,MeshFace ...

  6. python语言程序设计基础第二版第六章答案-python语言程序设计基础(第二版)第五章答案随笔...

    模板模式与策略模式/template模式与strategy模式/行为型模式 模板模式 模版模式,又被称为模版方法模式,它可以将工作流程进行封装,并且对外提供了个性化的控制,但主流程外界不能修改,也就是 ...

  7. python语言程序设计基础第二版答案-python语言程序设计基础(第二版)第五章答案随笔...

    模板模式与策略模式/template模式与strategy模式/行为型模式 模板模式 模版模式,又被称为模版方法模式,它可以将工作流程进行封装,并且对外提供了个性化的控制,但主流程外界不能修改,也就是 ...

  8. 3D打印开源切片软件Cura配置步骤

    3D打印开源切片软件Cura配置步骤 Cura ==== Read this, it's important! =========================== If you are readi ...

  9. 3D打印开源软件Cura分析(1) 【转】

    http://www.sohu.com/a/236241465_100000368 Cura是Ultimaker公司开发的3D打印开源软件,在所有的3D打印开源软件中应属上乘之作,很有研究的价值.国内 ...

  10. CNC+CRC/SoftPLC/OpenCASCADE/CAD/CAM 开源项目汇总

    先来看看B站的视频 https://www.bilibili.com/video/BV1Bt4y1y74P CRC/CNC Cutter Radius Compensation for Milling ...

最新文章

  1. Win10用Windows照片查看程序打开图片+更改注册表后导致Win10任务栏Adobe PDF阅读器图标显示异常
  2. MySQL.. ERROR! The server quit without updating PID file问题解决
  3. JAVA大数据-Week4-DAY3
  4. 学点PYTHON基础的东东--数据结构,算法,设计模式---观察者模式
  5. 在linux中安装字体
  6. PMP培训一般是多久?怎么收费?
  7. HBase 下载地址
  8. 服务器网卡驱动装好后本地连接显示,系统装好后网卡驱动也装好了,可是没有本地连接,怎么弄...
  9. XTUOJ-1277-Triangle
  10. PS 如何制作WIN7的玻璃化透明窗口效果
  11. Git 使用tag标签
  12. Java——反射(reflection)详解
  13. 不想在网易博客写技术文章了
  14. 小米智能家居硬件的发展进程盘点
  15. Selenium自动化测试框架基础操作
  16. [英语语法]句法之定语从句
  17. 三星 android 模拟器下载地址,GalaxyOfWar电脑版下载 安卓模拟器图文安装教程
  18. 静态链接库(Lib) 与 动态链接库(DLL)
  19. html5发展现状调查问卷,《小班语言发展现状调查问卷分析报告》
  20. Solr(1):Solr概述

热门文章

  1. 文件上传解析器MultipartResolver
  2. 从学校,到字节跳动,追忆似水流年
  3. math_数集(数集符号)/算数运算中英文对照
  4. 服务器系统照片备份,利用云服务器备份照片
  5. MQTT(Message Queuing Telemetry Transport,消息队列遥测传输)
  6. 档案重要吗有什么作用(转载记录避免以后麻烦)
  7. DTAS棣拓三维公差分析软件容差分析软件蒙特卡洛法:DTAS Talk尺寸联盟参与公益课
  8. 谷歌字体连接超时解决方案
  9. 设计手机APP界面的感想
  10. 几组数据的相关性python_几的笔顺 笔画数:2 拼音:jī,jǐ 部首:几 - 智慧山