Newer
Older
/**
* This file is part of VisiCut.
* Copyright (C) 2011 Thomas Oster <thomas.oster@rwth-aachen.de>
* RWTH Aachen University - 52062 Aachen, Germany
*
* VisiCut is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VisiCut 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with VisiCut. If not, see <http://www.gnu.org/licenses/>.
**/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.t_oster.liblasercut;
import com.t_oster.liblasercut.platform.Point;
import java.util.LinkedList;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
*
* @author Thomas Oster <thomas.oster@rwth-aachen.de>
*/
public class Raster3dPart {
private LaserProperty curProp;
private List<GreyscaleRaster> images = new LinkedList<GreyscaleRaster>();
private List<LaserProperty> properties = new LinkedList<LaserProperty>();
private List<Point> starts = new LinkedList<Point>();
public Raster3dPart(LaserProperty initialLaserProperty) {
this.curProp = initialLaserProperty;
}
public void setCurrentLaserProperty(LaserProperty eng) {
this.curProp = eng;
}
public LaserProperty getCurrentLaserProperty() {
return this.curProp;
}
/**
* Adds the given Image to this RasterPart
* The Image must be in sRGB Format. The grey value of every pixel
* is mapped to the LaserPower (scaled to the LaserPower in the
* current engraving property)
* @param img
*/
public void addImage(GreyscaleRaster img, Point start) {
this.addImage(img, curProp, start);
}
public void addImage(GreyscaleRaster img, LaserProperty prop, Point start) {
this.images.add(img);
this.properties.add(prop);
this.starts.add(start);
}
/**
* Returns the number of Rasters, this rasterpart contains
* @return
*/
public int getRasterCount() {
return this.images.size();
}
/**
* Returns the full width of the complete raster Part
* @return
*/
public int getWidth() {
int minx = 0;
int maxx = 0;
for (int i = 0; i < this.getRasterCount(); i++) {
Point start = this.getRasterStart(i);
minx = Math.min(minx, start.x);
maxx = Math.max(maxx, start.x + this.getRasterWidth(i));
}
return maxx - minx;
}
/**
* Returns the full height of the complete raster Part
* @return
*/
public int getHeight() {
int miny = 0;
int maxy = 0;
for (int i = 0; i < this.getRasterCount(); i++) {
Point start = this.getRasterStart(i);
miny = Math.min(miny, start.y);
maxy = Math.max(maxy, start.y + this.getRasterHeight(i));
}
return maxy - miny;
}
/**
* Returns the upper left point of the given raster
* @param raster the raster which upper left corner is to determine
* @return
*/
public Point getRasterStart(int raster) {
return this.starts.get(raster);
}
/**
* Returns one line of the given rasterpart
* every byte represents one pixel and the value corresponds to
* the raster power
* @param raster
* @param line
* @return
*/
public List<Byte> getRasterLine(int raster, int line) {
GreyscaleRaster img = this.images.get(raster);
List<Byte> result = new LinkedList<Byte>();
for (int x = 0; x < img.getWidth(); x++) {
//TOTEST: Black white (byte converssion)
result.add((byte) img.getGreyScale(x, line));
}
return result;
}
public int getRasterWidth(int raster) {
return this.images.get(raster).getWidth();
}
public int getRasterHeight(int raster) {
return this.images.get(raster).getHeight();
}
public LaserProperty getLaserProperty(int raster) {
return this.properties.get(raster);
}
public GreyscaleRaster[] getImages() {
return this.images.toArray(new GreyscaleRaster[0]);
}
public LaserProperty[] getPropertys() {
return this.properties.toArray(new LaserProperty[0]);
}
public List<Byte> getInvertedRasterLine(int raster, int line) {
GreyscaleRaster img = this.images.get(raster);
List<Byte> result = new LinkedList<Byte>();
for (int x = 0; x < img.getWidth(); x++) {
//TOTEST: Black white (byte converssion)
result.add((byte) (255 - img.getGreyScale(x, line)));
}
return result;
}
}