//This file is part of SECONDO. //Copyright (C) 2004, University in Hagen, Department of Computer Science, //Database Systems for New Applications. //SECONDO is free software; you can redistribute it and/or modify //it under the terms of the GNU General Public License as published by //the Free Software Foundation; either version 2 of the License, or //(at your option) any later version. //SECONDO 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 General Public License for more details. //You should have received a copy of the GNU General Public License //along with SECONDO; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package viewer.fuzzy2d; import java.awt.*; import java.awt.image.*; import viewer.viewer3d.graphic3d.*; // we need 3D-points lines and triangles import gui.idmanager.*; import viewer.viewer3d.objects.*; public class FuzzyImage extends BufferedImage{ /** create a new fuzzy images with specific size */ public FuzzyImage(int width, int height){ super(width,height,TYPE_INT_RGB); this.width = width; this.height = height; ZBuffer = new double[width][height]; BB.setTo(0,0,width,height); } /** keep proportions while resize of objects ? */ public void setProportional(boolean p){ proportional = p; } /** adds a Point to this Image */ public void add(Point3D P){ if(P!=null) { Points.append(P); transformAndInsert(P); } } /** adds a set of points to this image */ public void add(Point3D[] Pts){ if(Pts!=null) for(int i=0;i=0 && y>=0 && x=ZBuffer[x][y]){ ZBuffer[x][y] = z; setRGB(x,y,Colorvalue); } } /** paint all containing points */ private void paintPoints(){ Point3D P; for(int i=0;i1) then Min (Max) id returned */ private int getColor(Color Min,Color Max,double delta){ int r1 = Min.getRed(); int g1 = Min.getGreen(); int b1 = Min.getBlue(); int r2 = Max.getRed(); int g2 = Max.getGreen(); int b2 = Max.getBlue(); double r,g,b; if(delta<=0){ r=r1; g=g1; b=b1; } else if(delta>=1){ r=r2; g=g2; b=b2; } else{ r = r1 + delta*(r2-r1); g = g1 + delta*(g2-g1); b = b1 + delta*(b2-b1); } return (int) 4278190080L + // Alpha-Value (int) r * 65536 + (int) g * 256 + (int) b; } /** computes a linear approximation beween Min and Max * if delta<0 (delta>1) then Min (Max) is returned */ private double getZ(double Min,double Max, double delta){ if(delta<=0) return Min; if(delta>=1) return Max; return Min+delta*(Max-Min); } /** paints all containing segments */ private void paintLines(){ for(int i=0;i Math.abs(x2-x1) ) { // a steep line if(y2P3 actX1 = (int)(x1 + delta1*(x3-x1)); actZ1 = z1 + delta1*(z3-z1); actR1 = (int)(r1 + delta1*(r3-r1)); actG1 = (int)(g1 + delta1*(g3-g1)); actB1 = (int)(b1 + delta1*(b3-b1)); if(actY<=y2){ // on line P1->P2 delta2 = ((double)(actY-y1))/((double)(y2-y1)); actX2 = (int)(x1+delta2*(x2-x1)); actZ2 = z1+delta2*(z2-z1); actR2 = (int)(r1+delta2*(r2-r1)); actG2 = (int)(g1+delta2*(g2-g1)); actB2 = (int)(b1+delta2*(b2-b1)); } else{ // on Line P2->P3 delta2 = ((double)(actY-y2))/((double)(y3-y2)); actX2 = (int)( x2+delta2*(x3-x2)); actZ2 = z2+delta2*(z3-z2); actR2 = (int)(r2+delta2*(r3-r2)); actG2 = (int)(g2+delta2*(g3-g2)); actB2 = (int)(b2+delta2*(b3-b2)); } paintHorizontalLine(actY, actX1,actZ1,actR1,actG1,actB1, actX2,actZ2,actR2,actG2,actB2); } if(border){ Point3DSimple P1_1 = P1.duplicate(); P1_1.setR(0);P1_1.setG(0);P1_1.setB(0); Point3DSimple P2_1 = P2.duplicate(); P2_1.setR(0);P2_1.setG(0);P2_1.setB(0); Point3DSimple P3_1 = P3.duplicate(); P3_1.setR(0);P3_1.setG(0);P3_1.setB(0); paintSingleLine(new Line3D(P1_1,P2_1)); paintSingleLine(new Line3D(P1_1,P3_1)); paintSingleLine(new Line3D(P2_1,P3_1)); } } /** paints a horizontal Line */ private void paintHorizontalLine(int y,int x1,double z1,int r1,int g1,int b1, int x2,double z2,int r2,int g2,int b2){ if(x2==x1) return; if(x2WorldRatio) WorldWidth = WorldHeight*ScreenRatio; maxY = minY + WorldHeight; maxX = minX + WorldWidth; } BB.setTo(minX,minY,maxX,maxY); transformObjects(); } /** returns the current bounding box */ public BoundingBox2D getBoundingBox(){ return BB; } /** set the BoundingBox of the World ingnoring the z-values */ public void setBoundingBox(BoundingBox3D BB3){ BB.readFrom(BB3); setBoundingBox(BB); // to ensure a minimum size } /** converts all Objects from given World-Bounding-Box BB to the Screen */ private void transformObjects(){ TransformedPoints.empty(); TransformedLines.empty(); TransformedTriangles.empty(); for(int i=0;i