//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.viewer3d.objects; import sj.lang.ListExpr; import viewer.viewer3d.graphic3d.*; import java.util.Vector; import gui.idmanager.*; import gui.SecondoObject; import java.awt.*; public class FLine3D implements Object3D{ public Triangle3DVector getTriangles(){ return null;} public Line3DVector getLines(){ return Lines;} public Point3DVector getPoints(){return null;} /** get red-part by given membership-value */ private int getR(double delta){ return (int)( (double)(minR) + delta*( (double) (maxR-minR))); } /** get green-part by given membership-value */ private int getG(double delta){ return (int)( (double)(minG) + delta*( (double) (maxG-minG))); } /** get blue-part by given membership-value */ private int getB(double delta){ return (int)( (double)(minB) + delta*( (double) (maxB-minB))); } public String toString(){return Name;} /** check if the type from SO is a FLine */ public boolean checkType(SecondoObject SO){ ListExpr LE = SO.toListExpr(); if(LE.listLength()!=2) return false; else return (LE.first().isAtom() && LE.first().atomType()==ListExpr.SYMBOL_ATOM && LE.first().symbolValue().equals("fline")); } /** read the value of this FLine from SO */ public boolean readFromSecondoObject(SecondoObject SO){ ListExpr LE = SO.toListExpr(); if(LE.listLength()!=2) return false; if (!checkType(SO)) return false; Name = SO.getName(); myID = SO.getID(); return readFromListExpr(LE.second()); } /** read this FLine from a ListExpr * @return true if LE is a valid Representation of a FLine * all valid Segments of this List are inserted */ private boolean readFromListExpr(ListExpr LE){ ScaleFactor = 1.0; SingleSegments = new Vector(); Lines = new Line3DVector(); if(LE==null) return false; if(LE.listLength()!=2) return false; ListExpr SFList = LE.first(); if( !( SFList.isAtom() && (SFList.atomType()==ListExpr.INT_ATOM || SFList.atomType()==ListExpr.REAL_ATOM))) return false; double z= SFList.atomType()==ListExpr.INT_ATOM ? SFList.intValue() : SFList.realValue(); if(z<=0) return false; this.ScaleFactor = z; ListExpr Segments = LE.second(); SingleSegment S; boolean ok = true; while( !Segments.isEmpty() & ok) { S = new SingleSegment(); if(S.readFromListExpr(Segments.first())){ SingleSegments.add(S); Segments=Segments.rest(); } else ok = false; } computeLine3Ds(); return ok; } private void computeLine3Ds(){ Lines = new Line3DVector(); SingleSegment SS; Line3D L3D; Point3DSimple P3D1,P3D2; BB.set(0,0,0,0,0,0); double minx,miny,minz,maxx,maxy,maxz; BoundingBox3D BB2 = new BoundingBox3D(); for (int i=0;ix & P2x>x) ) // left or right from (xy) return false; if( (P1yy & P2y>y) ) // above or under (xy) return false; // algorithm from http://astronomy.swin.edu.au/~pbourke/geometry/pointline d2 = (P2x-P1x)*(P2x-P1x) + (P2y-P1y)*(P2y-P1y); // distance between P1 and P1 double u = ((x-P1x)*(P2x-P1x) + (y-P1y)*(P2y-P1y))/d2; // compute the point of intersection double x4 = P1x+u*(P2x-P1x); double y4 = P1y+u*(P2y-P1y); double dist2 = (x4-x)*(x4-x) + (y4-y)*(y4-y); if (dist2