~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to xs/src/Flow.cpp

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "Flow.hpp"
 
2
#include <cmath>
 
3
 
 
4
namespace Slic3r {
 
5
 
 
6
Flow
 
7
Flow::new_from_config_width(FlowRole role, const ConfigOptionFloatOrPercent &width, float nozzle_diameter, float height, float bridge_flow_ratio) {
 
8
    // we need layer height unless it's a bridge
 
9
    if (height <= 0 && bridge_flow_ratio == 0) CONFESS("Invalid flow height supplied to new_from_config_width()");
 
10
    
 
11
    float w;
 
12
    // use automatic extrusion width if user left 0 or we need a bridge flow
 
13
    if ((!width.percent && width.value == 0) || bridge_flow_ratio > 0) {
 
14
        w = Flow::_width(role, nozzle_diameter, height, bridge_flow_ratio);
 
15
    } else {
 
16
        w = width.get_abs_value(height);
 
17
    }
 
18
    
 
19
    Flow flow(w, Flow::_spacing(w, nozzle_diameter, height, bridge_flow_ratio), nozzle_diameter);
 
20
    if (bridge_flow_ratio > 0) flow.bridge = true;
 
21
    return flow;
 
22
}
 
23
 
 
24
Flow
 
25
Flow::new_from_spacing(float spacing, float nozzle_diameter, float height, bool bridge) {
 
26
    // we need layer height unless it's a bridge
 
27
    if (height <= 0 && !bridge) CONFESS("Invalid flow height supplied to new_from_spacing()");
 
28
 
 
29
    float w = Flow::_width_from_spacing(spacing, nozzle_diameter, height, bridge);
 
30
    Flow flow(w, spacing, nozzle_diameter);
 
31
    flow.bridge = bridge;
 
32
    return flow;
 
33
}
 
34
 
 
35
double
 
36
Flow::mm3_per_mm(float h) {
 
37
    if (this->bridge) {
 
38
        return (this->width * this->width) * PI/4.0;
 
39
    } else if (this->width >= (this->nozzle_diameter + h)) {
 
40
        // rectangle with semicircles at the ends
 
41
        return this->width * h + (h*h) / 4.0 * (PI-4.0);
 
42
    } else {
 
43
        // rectangle with shrunk semicircles at the ends
 
44
        return this->nozzle_diameter * h * (1 - PI/4.0) + h * this->width * PI/4.0;
 
45
    }
 
46
}
 
47
 
 
48
float
 
49
Flow::_width(FlowRole role, float nozzle_diameter, float height, float bridge_flow_ratio) {
 
50
    if (bridge_flow_ratio > 0) {
 
51
        return sqrt(bridge_flow_ratio * (nozzle_diameter*nozzle_diameter));
 
52
    }
 
53
    
 
54
    // here we calculate a sane default by matching the flow speed (at the nozzle) and the feed rate
 
55
    float volume = (nozzle_diameter*nozzle_diameter) * PI/4.0;
 
56
    float shape_threshold = nozzle_diameter * height + (height*height) * PI/4.0;
 
57
    float width;
 
58
    if (volume >= shape_threshold) {
 
59
        // rectangle with semicircles at the ends
 
60
        width = ((nozzle_diameter*nozzle_diameter) * PI + (height*height) * (4.0 - PI)) / (4.0 * height);
 
61
    } else {
 
62
        // rectangle with squished semicircles at the ends
 
63
        width = nozzle_diameter * (nozzle_diameter/height - 4.0/PI + 1);
 
64
    }
 
65
    
 
66
    float min = nozzle_diameter * 1.05;
 
67
    float max = -1;
 
68
    if (role == frPerimeter || role == frSupportMaterial) {
 
69
        min = max = nozzle_diameter;
 
70
    } else if (role != frInfill) {
 
71
        // do not limit width for sparse infill so that we use full native flow for it
 
72
        max = nozzle_diameter * 1.7;
 
73
    }
 
74
    if (max != -1 && width > max) width = max;
 
75
    if (width < min) width = min;
 
76
    
 
77
    return width;
 
78
}
 
79
 
 
80
 
 
81
float
 
82
Flow::_width_from_spacing(float spacing, float nozzle_diameter, float height, bool bridge) {
 
83
    if (bridge) {
 
84
        return spacing - BRIDGE_EXTRA_SPACING;
 
85
    }
 
86
    
 
87
    float w_threshold = height + nozzle_diameter;
 
88
    float s_threshold = w_threshold - OVERLAP_FACTOR * (w_threshold - (w_threshold - height * (1 - PI/4.0)));
 
89
    
 
90
    if (spacing >= s_threshold) {
 
91
        // rectangle with semicircles at the ends
 
92
        return spacing + OVERLAP_FACTOR * height * (1 - PI/4.0);
 
93
    } else {
 
94
        // rectangle with shrunk semicircles at the ends
 
95
        return (spacing + nozzle_diameter * OVERLAP_FACTOR * (PI/4.0 - 1)) / (1 + OVERLAP_FACTOR * (PI/4.0 - 1));
 
96
    }
 
97
}
 
98
 
 
99
float
 
100
Flow::_spacing(float width, float nozzle_diameter, float height, float bridge_flow_ratio) {
 
101
    if (bridge_flow_ratio > 0) {
 
102
        return width + BRIDGE_EXTRA_SPACING;
 
103
    }
 
104
    
 
105
    float min_flow_spacing;
 
106
    if (width >= (nozzle_diameter + height)) {
 
107
        // rectangle with semicircles at the ends
 
108
        min_flow_spacing = width - height * (1 - PI/4.0);
 
109
    } else {
 
110
        // rectangle with shrunk semicircles at the ends
 
111
        min_flow_spacing = nozzle_diameter * (1 - PI/4.0) + width * PI/4.0;
 
112
    }
 
113
    return width - OVERLAP_FACTOR * (width - min_flow_spacing);
 
114
}
 
115
 
 
116
#ifdef SLIC3RXS
 
117
REGISTER_CLASS(Flow, "Flow");
 
118
#endif
 
119
 
 
120
}