//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.*; import tools.Reporter; public class FRegion3D implements Object3D{ public Triangle3DVector getTriangles(){ return Triangles;} public Line3DVector getLines(){ return null;} 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 ID getID(){return myID;}; /** check if the type from SO is a FRegion */ 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("fregion")); } /** 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(); boolean ok = readFromListExpr(LE.second()); return ok; } /** read this FRegion from a ListExpr * @return true if LE is a valid Representaion of a FRegion */ public boolean readFromListExpr(ListExpr LE){ ScaleFactor = 1.0; SingleTriangles = new Vector(); Triangles = new Triangle3DVector(); 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 triangle_list = LE.second(); SingleTriangle T; boolean ok = true; while( !triangle_list.isEmpty() & ok) { T = new SingleTriangle(); if(T.readFromListExpr(triangle_list.first())){ SingleTriangles.add(T); triangle_list=triangle_list.rest(); } else{ ok = false; } } computeTriangles3D(); return ok; } private void computeTriangles3D(){ Triangles = new Triangle3DVector(); SingleTriangle ST; Triangle3D T3D; Point3DSimple P3D1,P3D2,P3D3; BoundingBox3D BB2 = new BoundingBox3D(); int z1,z2,z3; double minx,miny,minz; double maxx,maxy,maxz; for (int i=0;i0) && (BC*CA)>0; } private class SingleTriangle{ SingleFPoint P1,P2,P3; public boolean readFromListExpr(ListExpr LE){ if(LE.listLength()!=3) return false; SingleFPoint tmpP1 = new SingleFPoint(); SingleFPoint tmpP2 = new SingleFPoint(); SingleFPoint tmpP3 = new SingleFPoint(); boolean ok = tmpP1.readFromListExpr(LE.first(),false); if(!ok) Reporter.writeError("Error reading :"+LE.first().writeListExprToString()); else{ ok = tmpP2.readFromListExpr(LE.second(),false); if(!ok) Reporter.writeError("Error reading :"+LE.second().writeListExprToString()); else { ok = tmpP3.readFromListExpr(LE.third(),false); if(!ok) Reporter.writeError("error reading :"+LE.third().writeListExprToString()); } } if(ok){ this.P1 = tmpP1; this.P2 = tmpP2; this.P3 = tmpP3; } return ok; } } }