Package bs.bs2d.slicer

Source Code of bs.bs2d.slicer.PrintObject

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package bs.bs2d.slicer;

import bs.bs2d.geom.AreaSet;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.util.AffineTransformation;
import java.util.Arrays;
import javax.vecmath.Point2d;
import javax.vecmath.Vector2d;

/**
*
* @author Djen
*/
public class PrintObject{
   
    private AreaSet areaSet;
    private double[] densities;
    private Point2d position;
    private double height;
   
    /**
     * Number of layers
     */
    int layers = 0;
   
    /**
     *
     * @param areaSet the geometry discribing the object
     * @param densities the infill densities for the seperate infill areas from
     * lowest to highest.
     * @param position coordinates of the center of the object on the print bed
     * @param height height of the object
     */
    public PrintObject(AreaSet areaSet, double[] densities, Point2d position, double height) {
        this.areaSet = areaSet;//.copy();
        this.densities = densities;
       
        if(densities.length != areaSet.getResolution())
            throw new IllegalArgumentException("Densities not defined!");
       
        this.position = position;
        this.height = height;
       
//        updateAreaSet();
    }

    public PrintObject(AreaSet areaSet, double[] densities, double height) {
        this(areaSet, densities, new Point2d(), height);
    }
   
    public PrintObject(AreaSet areaSet, double height){
        this(areaSet, new double[areaSet.getResolution()], new Point2d(), height);
    }
   
    public PrintObject(PrintObject obj, Point2d position){
        this(obj.areaSet,
             Arrays.copyOf(obj.densities, obj.densities.length),
             position,
             obj.height);
    }
   
    public AreaSet getAreaSet() {
        return areaSet;
    }

    public double[] getDensities() {
        return densities;
    }
   
    public double getDensity(int area){
        if(densities == null || area < 0 || area >= densities.length){
            return Double.NaN;
        } else {
            return densities[area];
        }
    }

    public void setDensities(double[] densities) {
        if(areaSet.getResolution() != densities.length)
            throw new RuntimeException("Number of density values must match number of subareas!");
        this.densities = densities;
    }

    public void setDensity(double density){
        setDensities(new double[]{density});
    }
   
    public Point2d getPosition() {
        return position;
    }
   
    public double getX(){
        return this.position.x;
    }
   
    public double getY(){
        return this.position.y;
    }
   
    public void setPosition(double x, double y) {
        setPosition(new Point2d(x, y));
    }

    public void setPosition(Point2d position) {
        this.position = position;
//        updateAreaSet();
    }
   
    @Deprecated
    private void updateAreaSet(){
       
       
//        if(dx != 0 || dy != 0)
//            areaSet = areaSet.getTranslated(dx, dy);
    }
   
    public AffineTransformation getTranslate(){
        Coordinate c = areaSet.getEnvelope().centre();
        double dx = position.x - c.x;
        double dy = position.y - c.y;
        return AffineTransformation.translationInstance(dx, dy);
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    /**
     * Creates a print object with identical shell but uniformn infill. Infill
     * density defaults to 0 and needs to be set seperately.
     * @return a new print object identical to this one but with no subareas
     */
    public PrintObject getUniform(){
        return new PrintObject(areaSet.createSingularAreaSet(), new double[1], position, height);
    }
}
TOP

Related Classes of bs.bs2d.slicer.PrintObject

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.