/** * 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; import java.util.List; /** * * @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; } }