[brlcad-commits] SF.net SVN: brlcad:[33162] jbrlcad/trunk
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <joh...@us...> - 2008-11-13 00:44:25
|
Revision: 33162 http://brlcad.svn.sourceforge.net/brlcad/?rev=33162&view=rev Author: johnranderson Date: 2008-11-13 00:44:13 +0000 (Thu, 13 Nov 2008) Log Message: ----------- Refactored package names (they all start with "org.brlcad" now) Added Paths: ----------- jbrlcad/trunk/src/org/ jbrlcad/trunk/src/org/brlcad/ jbrlcad/trunk/src/org/brlcad/geometry/ jbrlcad/trunk/src/org/brlcad/geometry/Arb8.java jbrlcad/trunk/src/org/brlcad/geometry/BadGeometryException.java jbrlcad/trunk/src/org/brlcad/geometry/Bot.java jbrlcad/trunk/src/org/brlcad/geometry/BotPiece.java jbrlcad/trunk/src/org/brlcad/geometry/BrlcadDb.java jbrlcad/trunk/src/org/brlcad/geometry/Combination.java jbrlcad/trunk/src/org/brlcad/geometry/DbException.java jbrlcad/trunk/src/org/brlcad/geometry/DbExternal.java jbrlcad/trunk/src/org/brlcad/geometry/DbNameNotFoundException.java jbrlcad/trunk/src/org/brlcad/geometry/DbObject.java jbrlcad/trunk/src/org/brlcad/geometry/Ellipsoid.java jbrlcad/trunk/src/org/brlcad/geometry/Face.java jbrlcad/trunk/src/org/brlcad/geometry/Hit.java jbrlcad/trunk/src/org/brlcad/geometry/Operator.java jbrlcad/trunk/src/org/brlcad/geometry/OverlapHandler.java jbrlcad/trunk/src/org/brlcad/geometry/Partition.java jbrlcad/trunk/src/org/brlcad/geometry/Segment.java jbrlcad/trunk/src/org/brlcad/geometry/SimpleOverlapHandler.java jbrlcad/trunk/src/org/brlcad/geometry/Tree.java jbrlcad/trunk/src/org/brlcad/numerics/ jbrlcad/trunk/src/org/brlcad/numerics/BoundingBox.java jbrlcad/trunk/src/org/brlcad/numerics/Matrix.java jbrlcad/trunk/src/org/brlcad/numerics/Plane3D.java jbrlcad/trunk/src/org/brlcad/numerics/Point.java jbrlcad/trunk/src/org/brlcad/numerics/Quaternion.java jbrlcad/trunk/src/org/brlcad/numerics/Ray.java jbrlcad/trunk/src/org/brlcad/numerics/Tolerance.java jbrlcad/trunk/src/org/brlcad/numerics/Vector3.java jbrlcad/trunk/src/org/brlcad/preppedGeometry/ jbrlcad/trunk/src/org/brlcad/preppedGeometry/PreppedArb8.java jbrlcad/trunk/src/org/brlcad/preppedGeometry/PreppedBot.java jbrlcad/trunk/src/org/brlcad/preppedGeometry/PreppedCombination.java jbrlcad/trunk/src/org/brlcad/preppedGeometry/PreppedEllipsoid.java jbrlcad/trunk/src/org/brlcad/preppedGeometry/PreppedObject.java jbrlcad/trunk/src/org/brlcad/preppedGeometry/PreppedObjectPiece.java jbrlcad/trunk/src/org/brlcad/preppedGeometry/PreppedTriangle.java jbrlcad/trunk/src/org/brlcad/samples/ jbrlcad/trunk/src/org/brlcad/samples/BrlcadJava.java jbrlcad/trunk/src/org/brlcad/samples/GetRegionMap.java jbrlcad/trunk/src/org/brlcad/spacePartition/ jbrlcad/trunk/src/org/brlcad/spacePartition/BoxNode.java jbrlcad/trunk/src/org/brlcad/spacePartition/CutNode.java jbrlcad/trunk/src/org/brlcad/spacePartition/Node.java jbrlcad/trunk/src/org/brlcad/spacePartition/PreppedDb.java jbrlcad/trunk/src/org/brlcad/spacePartition/RayData.java Removed Paths: ------------- jbrlcad/trunk/src/geometry/Arb8.java jbrlcad/trunk/src/geometry/BadGeometryException.java jbrlcad/trunk/src/geometry/Bot.java jbrlcad/trunk/src/geometry/BotPiece.java jbrlcad/trunk/src/geometry/BrlcadDb.java jbrlcad/trunk/src/geometry/Combination.java jbrlcad/trunk/src/geometry/DbException.java jbrlcad/trunk/src/geometry/DbExternal.java jbrlcad/trunk/src/geometry/DbNameNotFoundException.java jbrlcad/trunk/src/geometry/DbObject.java jbrlcad/trunk/src/geometry/Ellipsoid.java jbrlcad/trunk/src/geometry/Face.java jbrlcad/trunk/src/geometry/Hit.java jbrlcad/trunk/src/geometry/Operator.java jbrlcad/trunk/src/geometry/OverlapHandler.java jbrlcad/trunk/src/geometry/Partition.java jbrlcad/trunk/src/geometry/Segment.java jbrlcad/trunk/src/geometry/SimpleOverlapHandler.java jbrlcad/trunk/src/geometry/Tree.java jbrlcad/trunk/src/numerics/BoundingBox.java jbrlcad/trunk/src/numerics/Matrix.java jbrlcad/trunk/src/numerics/Plane3D.java jbrlcad/trunk/src/numerics/Point.java jbrlcad/trunk/src/numerics/Quaternion.java jbrlcad/trunk/src/numerics/Ray.java jbrlcad/trunk/src/numerics/Tolerance.java jbrlcad/trunk/src/numerics/Vector3.java jbrlcad/trunk/src/preppedGeometry/PreppedArb8.java jbrlcad/trunk/src/preppedGeometry/PreppedBot.java jbrlcad/trunk/src/preppedGeometry/PreppedCombination.java jbrlcad/trunk/src/preppedGeometry/PreppedEllipsoid.java jbrlcad/trunk/src/preppedGeometry/PreppedObject.java jbrlcad/trunk/src/preppedGeometry/PreppedObjectPiece.java jbrlcad/trunk/src/preppedGeometry/PreppedTriangle.java jbrlcad/trunk/src/samples/BrlcadJava.java jbrlcad/trunk/src/samples/GetRegionMap.java jbrlcad/trunk/src/spacePartition/BoxNode.java jbrlcad/trunk/src/spacePartition/CutNode.java jbrlcad/trunk/src/spacePartition/Node.java jbrlcad/trunk/src/spacePartition/PreppedDb.java jbrlcad/trunk/src/spacePartition/RayData.java Property Changed: ---------------- jbrlcad/trunk/ Property changes on: jbrlcad/trunk ___________________________________________________________________ Added: svn:ignore + dist build Deleted: jbrlcad/trunk/src/geometry/Arb8.java =================================================================== --- jbrlcad/trunk/src/geometry/Arb8.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/Arb8.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,96 +0,0 @@ -package geometry; -/** - * Arb8 - based on the BRL-CAD ARB8 - * - */ - - - -import preppedGeometry.PreppedArb8; -import preppedGeometry.PreppedCombination; -import numerics.Point; -import spacePartition.PreppedDb; -import numerics.Matrix; - -public class Arb8 extends DbObject -{ - // the arb vertices - private Point[] points; - - // the major and minor types for an Arb8 - public static final byte majorType = 1; - public static final byte minorType = 4; - - /** - * Constructor - * @param dbExt The DbExternal object representing an arb8 - * @throws DbException - */ - public Arb8( DbExternal dbExt ) throws DbException - { - super( dbExt ); - - if( dbExt.getMajorType() != Arb8.majorType || dbExt.getMinorType() != Arb8.minorType ) - { - throw new DbException( "Attempted to import an Arb8, but external is " + - " major type: " + dbExt.getMajorType() + - " minor type: " + dbExt.getMinorType() ); - } - - this.points = new Point[8]; - - // get the body bytes from the DbExternal object - byte[] body = dbExt.getBody(); - - int pointer = 0; - for( int i=0 ; i<8 ; i++ ) - { - this.points[i] = new Point(); - this.points[i].setX( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.points[i].setY( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.points[i].setZ( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - } - } - - /** - * Get a vertex of this ARB8 - * @param i The index of the desired vertex - * @return The vertex corresponding to the specified index - */ - public Point getVertex( int i ) - { - return this.points[i]; - } - - /** - * Prep this Arb8 for ray tracing - * @param reg The region containing this Arb8 (or null) - * @param preppedDb The PreppedDb that contains this Arb8 - * @param matrix The transformation matrix to be applied to this Arb8 - */ - public PreppedArb8 prep( PreppedCombination reg, PreppedDb preppedDb, Matrix matrix) throws BadGeometryException - { - PreppedArb8 prepped = new PreppedArb8( this, matrix ); - preppedDb.addPreppedObjectToInitialBox( prepped ); - if( reg != null ) - { - prepped.addRegion( reg ); - } - return prepped; - } - - public String toString() - { - StringBuffer sb = new StringBuffer(); - sb.append("arb8:\n"); - for( int i=0 ; i<8 ; i++ ) - { - sb.append( "\tpt["+i+"] = " + this.points[i] + "\n" ); - } - return sb.toString(); - } -} - Deleted: jbrlcad/trunk/src/geometry/BadGeometryException.java =================================================================== --- jbrlcad/trunk/src/geometry/BadGeometryException.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/BadGeometryException.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,16 +0,0 @@ -package geometry; -/** - * BadGeometryException.java - * - * @author Created by Omnicore CodeGuide - */ - - -public class BadGeometryException extends Exception -{ - public BadGeometryException( String msg ) - { - super( msg ); - } -} - Deleted: jbrlcad/trunk/src/geometry/Bot.java =================================================================== --- jbrlcad/trunk/src/geometry/Bot.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/Bot.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,453 +0,0 @@ -package geometry; -/** - * A Bot (Bag of triangles) object. Based on the BRL-CAD BOT - */ - - - -import java.util.BitSet; -import java.util.Iterator; - -import preppedGeometry.PreppedBot; -import preppedGeometry.PreppedCombination; -import preppedGeometry.PreppedTriangle; - -import numerics.Matrix; -import numerics.Point; -import numerics.Vector3; -import spacePartition.PreppedDb; - -public class Bot extends DbObject -{ - private Orientation orientation; - private Mode mode; - private byte flags; - - // Array of vertices used in this Bot - private Point[] points; - - // Array of faces in this Bot (each face has indices into the above array of vertices) - private Face[] faces; - - // Mode for each face, only used for PLATE or PLATE_NOCOS mode, if bit is set for - // a face, then its thickness is appended to a shotline at the hit point. Otherwise, - // the thicknes is centered about the shotline. - private BitSet faceMode; - - // Thickness of each face (only used for PLATE or PLATE_NOCOS mode) - private double[] thickness; - - // Array of vertex normals (optional) - private Vector3[] normals; - - // Array of face normals (each face has indices into the normals array, one-to-one - // correspondence with faces array) - private Face[] faceNormals; - - // the major and minor types for a Bot - public static final byte majorType = 1; - public static final byte minorType = 30; - - /** - * The possible orientations for the faces of a Bot - * - */ - public enum Orientation { - UNORIENTED( "unoriented"), - COUNTER_CLOCKWISE( "counter-clockwise"), - CLOCKWISE( "clockwise"); - - private final String humanReadable; - - Orientation( String hrs ) - { - this.humanReadable = hrs; - } - - public String toString() - { - return this.humanReadable; - } - } - - /** - * The possible modes for a Bot - * - */ - public enum Mode - { - SURFACE( "Surface"), - SOLID( "Solid"), - PLATE( "Plate"), - PLATE_NOCOS( "Plate (Defined LOS)"); - - private final String humanReadable; - - Mode( String hrs) - { - this.humanReadable = hrs; - } - - public String toString() - { - return this.humanReadable; - } - } - - // flags - public static final byte HAS_SURFACE_NORMALS = 0x1; - public static final byte USE_SURFACE_NORMALS = 0x2; - public static final byte USE_FLOATS = 0x4; - - /** - * Constructor - builds a Bot from the body of a dbExt - * @param dbExt - * @throws DbException - */ - public Bot( DbExternal dbExt ) throws DbException - { - super( dbExt ); - - if( dbExt.getMajorType() != Bot.majorType || dbExt.getMinorType() != Bot.minorType ) - { - throw new DbException( "Attempted to import an Arb8, but external is " + - " major type: " + dbExt.getMajorType() + - " minor type: " + dbExt.getMinorType() ); - } - - // get the body bytes from the DbExternal object - byte[] body = dbExt.getBody(); - - int pointer = 0; - - int numVertices = (int)BrlcadDb.getLong( body, pointer, 4 ); - System.out.println( "numVertices = " + numVertices ); - pointer += 4; - int numFaces = (int)BrlcadDb.getLong( body, pointer, 4 ); - System.out.println( "numFaces = " + numFaces ); - pointer += 4; - int tmp = body[pointer++]; - switch( tmp ) { - case 1: - this.orientation = Bot.Orientation.UNORIENTED; - break; - case 2: - this.orientation = Bot.Orientation.COUNTER_CLOCKWISE; - break; - case 3: - this.orientation = Bot.Orientation.CLOCKWISE; - break; - default: - throw new DbException( "Bot has invalid orientation: " + tmp); - } - - tmp = body[pointer++]; - switch( tmp ) { - case 1: - this.mode = Mode.SURFACE; - break; - case 2: - this.mode = Mode.SOLID; - break; - case 3: - this.mode = Mode.PLATE; - break; - case 4: - this.mode = Mode.PLATE_NOCOS; - break; - default: - throw new DbException( "Bot has invalid mode: " + tmp); - } - - this.flags = body[pointer++]; - this.points = new Point[numVertices]; - for( int i=0 ; i<numVertices ; i++ ) - { - double x = BrlcadDb.getDouble( body, pointer ); - pointer += 8; - double y = BrlcadDb.getDouble( body, pointer ); - pointer += 8; - double z = BrlcadDb.getDouble( body, pointer ); - pointer += 8; - points[i] = new Point( x, y, z ); - } - this.faces = new Face[numFaces]; - for( int i=0 ; i<numFaces ; i++ ) - { - int v1 = (int)BrlcadDb.getLong( body, pointer, 4 ); - pointer += 4; - int v2 = (int)BrlcadDb.getLong( body, pointer, 4 ); - pointer += 4; - int v3 = (int)BrlcadDb.getLong( body, pointer, 4 ); - pointer += 4; - faces[i] = new Face( v1, v2, v3 ); - } - - if( this.mode == Bot.Mode.PLATE || this.mode == Bot.Mode.PLATE_NOCOS ) - { - this.thickness = new double[numFaces]; - for( int i=0 ; i<numFaces ; i++ ) - { - this.thickness[i] = BrlcadDb.getDouble( body, pointer ); - pointer += 8; - } - - this.faceMode = BrlcadDb.getBitSet( body, pointer ); - if( this.faceMode == null ) - { - throw new DbException( "Bad face mode bit vector in database file for " + - this.getName() ); - } - pointer += this.faceMode.size() / 8; - } - - if( (this.flags & Bot.HAS_SURFACE_NORMALS) != 0 ) - { - int numNormals = (int)BrlcadDb.getLong( body, pointer, 4 ); - pointer += 4; - int numFaceNormals = (int)BrlcadDb.getLong( body, pointer, 4 ); - pointer += 4; - - if( numNormals > 0 ) - { - this.normals = new Vector3[numNormals]; - for( int i=0 ; i<numNormals ; i++ ) - { - double x = BrlcadDb.getDouble( body, pointer ); - pointer += 8; - double y = BrlcadDb.getDouble( body, pointer ); - pointer += 8; - double z = BrlcadDb.getDouble( body, pointer ); - pointer += 8; - normals[i] = new Vector3( x, y, z ); - } - } - if( numFaceNormals > 0 ) - { - this.faceNormals = new Face[numFaceNormals]; - for( int i=0 ; i<numFaceNormals ; i++ ) - { - int v1 = (int)BrlcadDb.getLong( body, pointer, 4 ); - pointer += 4; - int v2 = (int)BrlcadDb.getLong( body, pointer, 4 ); - pointer += 4; - int v3 = (int)BrlcadDb.getLong( body, pointer, 4 ); - pointer += 4; - this.faceNormals[i] = new Face( v1, v2, v3 ); - } - } - } - } - - public Point getVertex( int i ) - { - return this.points[i]; - } - - public Face getFace( int i ) - { - return this.faces[i]; - } - - public boolean hasVertexNormals() - { - return (this.flags & Bot.HAS_SURFACE_NORMALS) != 0; - } - - public boolean useVertexNormals() - { - return (this.flags & Bot.USE_SURFACE_NORMALS) != 0; - } - - public Vector3 getVertexNormal( int faceNumber, int vertexNumber ) - { - return this.normals[this.faceNormals[faceNumber].v[vertexNumber]]; - } - - public boolean isCCW() - { - return this.orientation == Bot.Orientation.COUNTER_CLOCKWISE; - } - - public boolean isCW() - { - return this.orientation == Bot.Orientation.CLOCKWISE; - } - - public boolean isUnOriented() - { - return this.orientation == Bot.Orientation.UNORIENTED; - } - - public int getFaceCount() - { - return this.faces.length; - } - - public boolean isSurface() - { - return this.mode == Bot.Mode.SURFACE; - } - - public boolean isPlate() - { - return this.mode == Bot.Mode.PLATE; - } - - public boolean isPlateNoCos() - { - return this.mode == Bot.Mode.PLATE_NOCOS; - } - - public double getFaceThickness( int faceNumber ) - { - return this.thickness[faceNumber]; - } - - public boolean isFaceThicknessAppendedtoHit( int faceNumber ) - { - return this.faceMode.get( faceNumber ); - } - - public String getOrientationString() - { - return this.orientation.toString(); - } - - public String getModeString() - { - return this.mode.toString(); - } - - public String getFlagsString() - { - StringBuffer sb = new StringBuffer(); - - if( (this.flags & Bot.HAS_SURFACE_NORMALS) != 0 ) - { - sb.append( "has surface normals" ); - } - if( (this.flags & Bot.USE_SURFACE_NORMALS) != 0) - { - if( sb.length() > 0 ) - { - sb.append( " and use surface normals" ); - } - else - { - sb.append( "use surface normals" ); - } - } - if( (this.flags & Bot.USE_FLOATS) != 0 ) - { - if( sb.length() > 0 ) - { - sb.append( " and use floats in prepped version" ); - } - else - { - sb.append( "use floats in prepped version" ); - } - } - - return sb.toString(); - } - - public String toString() - { - StringBuffer sb = new StringBuffer(); - sb.append( this.getName() + " BOT:\n" ); - sb.append( "Orientation: " + this.getOrientationString() ); - sb.append( ", mode: " + this.getModeString() ); - sb.append( ", flags: " + this.getFlagsString() + "\n" ); - sb.append( this.points.length + " vertices, " + this.faces.length + " faces" ); - - sb.append( "\nPoints:\n" ); - for( int i=0 ; i<this.points.length ; i++ ) - { - sb.append( "\t" + i + " " + this.points[i] + "\n" ); - } - - sb.append( "Faces:\n" ); - for( int i=0 ; i<this.faces.length ; i++ ) - { - sb.append( "\t" + i + " " + this.faces[i] + "\n" ); - } - - if( this.mode == Bot.Mode.PLATE || this.mode == Bot.Mode.PLATE_NOCOS ) - { - sb.append( "Face thickness:\n" ); - for( int i=0 ; i<this.thickness.length ; i++ ) - { - sb.append( "\t" + i + " " + this.thickness[i] + "\n" ); - } - sb.append( "Face mode: " + this.faceMode + "\n" ); - } - - if( (this.flags & Bot.HAS_SURFACE_NORMALS) != 0 ) - { - sb.append( "Normals:\n" ); - for( int i=0 ; i<this.normals.length ; i++ ) - { - sb.append( "\t" + i + " " + this.normals[i] + "\n" ); - } - } - - return sb.toString(); - } - - /** - * Prep this Bot - * @param reg The region that this Bot belongs to (may be null) - * @param preppedDb The PreppedDb that this Bot belongs to - * @param matrix The transformation matrix to apply to this Bot - * @return A PreppedBot - */ - public PreppedBot prep( PreppedCombination reg, PreppedDb preppedDb, Matrix matrix) - { - PreppedBot prepped = new PreppedBot( this, matrix ); - if( prepped.getTriangleCount() >= BrlcadDb.BOT_MINFACES ) - { - // use pieces - BotPiece pbp = null; - int triCount = 0; - Iterator<PreppedTriangle> iter = prepped.getTriangles().iterator(); - - while( iter.hasNext() ) - { - if( triCount == 0 ) - { - if( pbp != null ) - { - preppedDb.addPreppedObjectPieceToInitialBox( pbp ); - pbp = null; - } - pbp = new BotPiece( this.name, prepped ); - } - PreppedTriangle pt = iter.next(); - pbp.addTriangle( pt ); - if( triCount++ >= BrlcadDb.BOT_FACES_PER_PIECE ) - { - triCount = 0; - } - } - - if( pbp != null ) - { - preppedDb.addPreppedObjectPieceToInitialBox( pbp ); - } - } - else - { - preppedDb.addPreppedObjectToInitialBox( prepped ); - } - - if( reg != null ) - { - // add the region to this objects list of regions - prepped.addRegion( reg ); - } - return prepped; - } -} - Deleted: jbrlcad/trunk/src/geometry/BotPiece.java =================================================================== --- jbrlcad/trunk/src/geometry/BotPiece.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/BotPiece.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,70 +0,0 @@ -package geometry; -/** - * Represents a single "piece" of Bot (some number of triangles from a - * single Bot - * @see PreppedTriangle - */ - - - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -import preppedGeometry.PreppedBot; -import preppedGeometry.PreppedObjectPiece; -import preppedGeometry.PreppedTriangle; - -import numerics.Ray; -import spacePartition.RayData; - -public class BotPiece extends PreppedObjectPiece -{ - // The PreppedTriangles in this piece - private List<PreppedTriangle> triangles; - - /** - * Constructor (builds an empty piece) - * @param botName The name of the Bot - * @param pBot The Prepped verion of the Bot - */ - public BotPiece( String botName, PreppedBot pBot ) - { - super( botName, pBot ); - this.triangles = new ArrayList<PreppedTriangle>(); - } - - /** - * Add a PreppedTriangle to this BotPiece - * @param tri The PreppedTriangle to add - * @see PreppedTriangle - */ - public void addTriangle( PreppedTriangle tri ) - { - this.triangles.add( tri ); - this.boundingBox.extend( tri.getBoundingBox() ); - } - - /** - * Shoot a ray at this BotPiece - * @param ray The ray to shoot - * @param rayData The RayData to use for the shot - * @return A Set of Hit objects (one for each PreppedTriangle that the ray intersects) - */ - public Set<Hit> shoot( Ray ray, RayData rayData ) - { - Set<Hit> hits = new TreeSet<Hit>(); - for( PreppedTriangle ptri:this.triangles ) - { - Hit hit = ptri.shoot( ray, rayData ); - if( hit != null ) - { - hits.add( hit ); - } - } - - return hits; - } -} - Deleted: jbrlcad/trunk/src/geometry/BrlcadDb.java =================================================================== --- jbrlcad/trunk/src/geometry/BrlcadDb.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/BrlcadDb.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,464 +0,0 @@ -package geometry; -/** - * This class holds a BRL-CAD database and provides interfaces to its contents - * - * @author Created by Omnicore CodeGuide - */ - - -import java.io.FileNotFoundException; -import java.io.RandomAccessFile; -import java.util.Map; -import java.util.HashMap; -import java.io.IOException; -import java.io.EOFException; -import numerics.Tolerance; -import java.util.BitSet; -import java.util.Set; -import java.util.TreeSet; - -public class BrlcadDb -{ - /** Name of the BRL-CAD db file */ - private String dbFileName; - - /** The title of this BRL-CAD db */ - private String title; - - /** The RandomAccessFile object associated with this BRL-CAD db */ - private RandomAccessFile dbInput; - - /** Directory of BRL-CAD object names and their offset into the BRL-CAD db */ - private Map < String, Long > directory; - - /** Magic number (byte) at the start of the BRL-CAD db file */ - public static final byte DB5HDR_MAGIC1 = 'v'; - - /** Magic number (byte) at the end of each object in the BRL-CAD database */ - public static final byte DB5HDR_MAGIC2 = '5'; - - /** default tolerance */ - public static final double DEFAULT_TOL_DIST = 0.005; - public static final double DEFAULT_TOL_PERP = 1.0e-6; - public static Tolerance tolerance = new Tolerance( DEFAULT_TOL_DIST, DEFAULT_TOL_PERP );; - - /** minimum number of faces to trigger use of pieces */ - public static int BOT_MINFACES = 32; - - /** number of triangles per Bot piece */ - public static int BOT_FACES_PER_PIECE = 4; - - /** - * Constructor - * - * @param dbFileName Name of the BRL-CAD DB file - * - * @exception FileNotFoundException - * @exception IOException - * @exception DbException - * - */ - public BrlcadDb ( String dbFileName ) throws FileNotFoundException, IOException, DbException - { - this.dbFileName = dbFileName; - this.dbInput = new RandomAccessFile( this.dbFileName, "r" ); - this.scan(); - } - - /** - * Sets Tolerance - * - * @param Tolerance a Tolerance - */ - public static void setTolerance(Tolerance tolerance) - { - BrlcadDb.tolerance = tolerance; - } - - /** - * Returns Tolerance - * - * @return a Tolerance - */ - public static Tolerance getTolerance() - { - return tolerance; - } - - /** - * Get the RandomAccesFile object asociated with this BRL-CAD database - * - * @return a RandomAccessFile - * - */ - public RandomAccessFile getRAM() - { - return this.dbInput; - } - - /** - * Scan the BRL-CAD database, constructing the directory and extracting the title - * - * @exception IOException - * @exception DbException - * - */ - private void scan() throws IOException, DbException - { - // this will hold the 8 byte header at the start of the file - byte fileHeader[] = new byte[8]; - - // create a new directory - this.directory = new HashMap < String, Long > (); - try - { - // make sure we start at the start - this.dbInput.seek( 0L ); - - // read the file header - this.dbInput.readFully( fileHeader ); - - // verify the file header - if( !this.fileHeaderIsValid( fileHeader ) ) - { - throw new IOException( "Invalid file header" ); - } - - // scan the rest of the file by importing DbExternal objects - Long offset; - while( true ) - { - offset = this.dbInput.getFilePointer(); - DbExternal dbExt = new DbExternal( this, offset ); - - // if this object has a name, add it to the directory - String name = dbExt.getName(); - if( name != null ) - { - if( this.directory.get( name ) != null ) - { - System.err.println( "Duplicate name (" + name + ") ignored" ); - } - else - { -// System.out.println( name + ": " + offset -// + "; major " + dbExt.getMajorType() -// + "; minor " + dbExt.getMinorType()); - this.directory.put( name, offset ); - } - } - } - } - catch( EOFException e ) - { - // we reached the end of the file - - // get the title from this database - try - { - DbObject global = this.getInternal( "_GLOBAL" ); - this.title = global.getAttribute( "title" ); - } - catch( Exception e1 ) - { - throw new DbException( "Db has no GLOBAL object " + e1); - } - System.err.println( "Completed scan, " + - this.directory.size() + - " objects" + - ", title = " + this.title); - return; - } - - } - - /** - * Get the DbObject that has the specified name - * - * @param name The name of the desired object - * - * @return a DbObject - * - * @exception IOException - * @exception DbException - * @exception DbNameNotFoundException - * - */ - public DbObject getInternal( String name ) throws IOException, DbException, DbNameNotFoundException - { - // Lookup this name in the directory - Long offset = this.directory.get( name ); - - if( offset == null ) - { - // no such object - throw new DbNameNotFoundException( "Error: " + name + " not found" ); - } - - // Read the object in external form - DbExternal dbExt = new DbExternal( this, offset ); - - // Import this object into its internal form (this will usually be a subclass of DbObject) - DbObject dbObj = this.importObj( dbExt ); - return dbObj; - } - - /** - * Import a DbExternal object into its internal form - * - * @param dbExt a DbExternal object - * - * @return a dbObject or, more likely, a subclass of DbObject - */ - private DbObject importObj(DbExternal dbExt) throws DbException - { - switch( dbExt.getMajorType() ) - { - case 0: - throw new DbException( "Illegal major type number (0)" ); - case 1: - switch( dbExt.getMinorType() ) - { - case Ellipsoid.minorType: - return new Ellipsoid( dbExt ); - case Arb8.minorType: - return new Arb8( dbExt ); - case Bot.minorType: - return new Bot( dbExt ); - case Combination.minorType: - return new Combination( dbExt ); - default: - throw new DbException( "Unrecognized minor type (" + - dbExt.getMinorType() + ")" ); - } - case 2: - return new DbObject( dbExt ); - - default: - throw new DbException( "Unrecognized major type (" + - dbExt.getMajorType() + ")" ); - } - } - - /** - * Get the description of an object with the specified name - * - * @param name a String - * - * @return a description of the specified object - * - * @exception DbException - * @exception IOException - * @exception DbNameNotFoundException - * - */ - public String describe( String name ) throws DbException, IOException, DbNameNotFoundException - { - DbObject obj = this.getInternal( name ); - return obj.toString(); - } - - /** - * Read an unsigned integral number from the database using the specified number of bytes - * - * @param numBytes the number of bytes to read (must be 1, 2, 4, or 8) - * - * @return a long - * - * @exception IOException - * - */ - public long getUnsignedLong( int numBytes ) throws IOException - { - long longNum; - - switch( numBytes ) - { - case 1: - return (long)this.dbInput.readUnsignedByte(); - case 2: - return (long)this.dbInput.readUnsignedShort(); - case 4: - byte[] bytes = new byte[4]; - this.dbInput.readFully( bytes ); - longNum = (long)(bytes[0] & 0xff); - for( int i=1 ; i<4 ; i++ ) - { - longNum = longNum << 8; - longNum |= (long)(bytes[i] & 0xff); - } - return longNum; - case 8: - longNum = this.dbInput.readLong(); - if( longNum < 0 ) - { - throw new IOException( "Database contains an unsigned long that we cannot read in Java!!"); - } - return longNum; - default: - throw new IOException( "BrlcadDb.getLong(): Illegal length (" + numBytes + - ")" ); - } - } - - /** - * Read a signed integral number from the database using the specified number of bytes - * - * @param numBytes The number of bytes to read - * - * @return a long - * - * @exception IOException - * - */ - public long getLong( int numBytes ) throws IOException - { - switch( numBytes ) - { - case 1: - return (long)this.dbInput.readByte(); - case 2: - return (long)this.dbInput.readShort(); - case 4: - return (long)this.dbInput.readInt(); - case 8: - return this.dbInput.readLong(); - default: - throw new IOException( "BrlcadDb.getLong(): Illegal length (" + numBytes + - ")" ); - } - } - - /** - * Extract a long value using bytes from the provided input array - * - * @param bytes The array containing the bytes - * @param pointer The location in the above array to start converting - * @param length The number of bytes to convert - * @return A long - */ - public static long getLong( byte[] bytes, int pointer, int length ) - { - long longBytes = (long)(bytes[pointer] & 0xff); - for( int i=1 ; i<length ; i++ ) - { - longBytes = longBytes << 8; - longBytes |= ((long)bytes[pointer+i] & 0xff); - } - - return longBytes; - } - - /** - * Extract a double value using 8 bytes from the provided input array starting with the - * array element at index "pointer" - * - * @param bytes a byte[] - * @param pointer the starting index in the above array - * - * @return a double - * - */ - public static double getDouble( byte[] bytes, int pointer ) - { - long longBytes = (long)(bytes[pointer] & 0xff); - for( int i=1 ; i<8 ; i++ ) - { - longBytes = longBytes << 8; - longBytes |= ((long)bytes[pointer+i] & 0xff); - } - return Double.longBitsToDouble( longBytes ); - } - - /** - * Extract a BitSet from an input array of bytes. The end of the BitSet is - * the first 0 value byte after the staring point. - * @param bytes The array of bytes - * @param pointer The starting point of the BitSet in the above array - * @return A BitSet - */ - public static BitSet getBitSet( byte[] bytes, int pointer ) - { - BitSet bitset; - - // find start of bit vector - while( Character.isWhitespace(bytes[pointer]) ) - { - pointer++; - } - // count number of hex digits in bit vector - int index = pointer; - while( bytes[index] != 0 ) - { - index++; - } - int length = index - pointer; - if( length < 2 || (length % 2) != 0 ) - { - return null; - } - bitset = new BitSet( length * 4 ); - - // set the bits - int bitNum = length*4 - 1; - while( bytes[pointer] != 0 ) - { - byte mask = (byte)0x8; - byte b = Byte.decode( "0x" + (char)bytes[pointer] ); - for( int i=0 ; i<4 ; i++ ) - { - if( (b & mask) != 0 ) - { - bitset.set( bitNum, true ); - } - mask = (byte)(mask >> 1); - bitNum--; - } - pointer++; - } - return bitset; - } - - /** - * Method fileHeaderIsValid - * - * @param fileHeader a byte[] - * - * @return a boolean - */ - private boolean fileHeaderIsValid(byte[] h ) - { - if( h[0] != DB5HDR_MAGIC1 ) return false; - if( h[7] != DB5HDR_MAGIC2 ) return false; - return true; - } - - - /** - * Method getObjectNames - * - * @return Set of object names in the file in alphabetical order - */ - public Set<String> getObjectNames() { - return new TreeSet<String>(directory.keySet()); - } - - /** - * Method getDbExternal - * - * @param String which contains the name of the object to return - * - * @return DbExternal object for given name; null if it doesn't exist - */ - public DbExternal getDbExternal(String name) { - Long offset = this.directory.get( name ); - if( offset == null ) return null; - try { - return new DbExternal( this, offset ); - } catch (IOException ioe) { - return null; - } - } - - -} Deleted: jbrlcad/trunk/src/geometry/Combination.java =================================================================== --- jbrlcad/trunk/src/geometry/Combination.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/Combination.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,276 +0,0 @@ -package geometry; -/** - * Represents a BRL-CAD Combination - */ - - - -import java.util.Stack; -import numerics.Matrix; -import spacePartition.PreppedDb; -import numerics.BoundingBox; -import java.io.IOException; -import java.util.List; -import java.util.ArrayList; -import java.util.Iterator; - -import preppedGeometry.PreppedCombination; -import preppedGeometry.PreppedObject; - -public class Combination extends DbObject -{ - private int index; - private Tree tree; - - public static final byte majorType = 1; - public static final byte minorType = 31; - - private static final byte leaf = 1; - private static final byte union = 2; - private static final byte intersection = 3; - private static final byte subtraction = 4; - private static final byte xor = 5; - private static final byte not = 6; - - // minus one stored as differnt length ints (indexed by wid) - private static final long[] identMatrix = { 0377L, - 0177777L, - 037777777777L, - 01777777777777777777777L }; - - - public Combination( DbExternal dbExt ) throws DbException - { - super( dbExt ); - if( dbExt.getMajorType() != majorType ||dbExt.getMinorType() != minorType ) - { - throw new DbException( "Attempted to import combination, but external is " + - " major type: " + dbExt.getMajorType() + - " minor type: " + dbExt.getMinorType() ); - } - byte[] body = dbExt.getBody(); - int pointer = 0; - byte wid = body[0]; - pointer += 1; - int length = DbExternal.fieldLength[ wid ]; - int numMatrices = (int)BrlcadDb.getLong( body, pointer, length ); - pointer += length; - int numLeaves = (int)BrlcadDb.getLong( body, pointer, length ); - pointer += length; - int leafBytes = (int)BrlcadDb.getLong( body, pointer, length ); - pointer += length; - long rpnLength = BrlcadDb.getLong( body, pointer, length ); - pointer += length; - long maxStackDepth = BrlcadDb.getLong( body, pointer, length ); - pointer += length; - - Matrix[] matrices = new Matrix[numMatrices]; - // read the matrices - for( int i=0 ; i<numMatrices ; i++ ) - { - matrices[i] = new Matrix( 4, 4 ); - for( int row = 0 ; row < 4 ; row ++ ) - { - for( int col = 0 ; col < 4 ; col++ ) - { - matrices[i].set( row, col, BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - } - } - } - - // new pointer that starts at the RPN expresion - if( rpnLength == 0 ) - { - List<Tree> list1 = new ArrayList<Tree>(); - List<Tree> list2 = new ArrayList<Tree>(); - - // there is no RPN expresion, just union together all the leaves - for( int i=0 ; i<numLeaves ; i++ ) - { - int nameStart = pointer; - int nameEnd = pointer; - while( body[nameEnd] != (byte)0 ) - { - nameEnd++; - } - String name = new String( body, nameStart, nameEnd - nameStart ); - pointer = nameEnd + 1; - long matrixInd = BrlcadDb.getLong(body, pointer, length); - pointer += length; - Matrix mat = null; - if( matrixInd != identMatrix[wid] ) - { - mat = matrices[(int)matrixInd]; - } - Tree node = new Tree( name, mat ); - list1.add( node ); - } - - // make a balanced tree - while( true ) - { - Tree t1; - Tree t2; - - Iterator<Tree> iter = list1.iterator(); - while( iter.hasNext() ) - { - t1 = iter.next(); - if( iter.hasNext() ) - { - t2 = iter.next(); - list2.add( new Tree( t1, t2, Operator.UNION ) ); - } - else - { - list2.add( t1 ); - } - } - - if( list2.size() == 1 ) - { - this.tree = list2.get(0); - break; - } - list1 = list2; - list2= new ArrayList<Tree>(); - } - } - else - { - int tmpptr = pointer + leafBytes; - Stack<Tree> stack = new Stack<Tree>(); - Tree node = null; - Tree left = null; - Tree right = null; - for( int i=tmpptr ; i < tmpptr+rpnLength ; i++ ) - { - switch( body[i] ) - { - case leaf: - // get the leaf from the body array - int nameStart = pointer; - int nameEnd = pointer; - while( body[nameEnd] != (byte)0 ) - { - nameEnd++; - } - String name = new String( body, nameStart, nameEnd - nameStart ); - pointer = nameEnd + 1; - long matrixInd = BrlcadDb.getLong(body, pointer, length); - pointer += length; - Matrix mat = null; - if (matrixInd != identMatrix[wid]) - { - mat = matrices[(int) matrixInd]; - } - node = new Tree( name, mat ); - stack.push( node ); - break; - case union: - right = (Tree)stack.pop(); - left = (Tree)stack.pop(); - node = new Tree( left, right, Operator.UNION ); - stack.push( node ); - break; - case intersection: - right = (Tree)stack.pop(); - left = (Tree)stack.pop(); - node = new Tree( left, right, Operator.INTERSECTION ); - stack.push( node ); - break; - case subtraction: - right = (Tree)stack.pop(); - left = (Tree)stack.pop(); - node = new Tree( left, right, Operator.SUBTRACTION ); - stack.push( node ); - break; - case xor: - right = (Tree)stack.pop(); - left = (Tree)stack.pop(); - node = new Tree( left, right, Operator.XOR ); - stack.push( node ); - break; - case not: - right = (Tree)stack.pop(); - node = new Tree( null, right, Operator.NOT ); - stack.push( node ); - break; - default: - throw new DbException( "Unrecognized operator in RPN expression in external form of a Combination" ); - } - } - this.tree = (Tree)stack.pop(); - } - } - - /** - * Sets Index - * - * @param Index an int - */ - public void setIndex(int index) - { - this.index = index; - } - - /** - * Returns Index - * - * @return an int - */ - public int getIndex() - { - return index; - } - - /** - * Constructor - * @param reg The region that this Combination belongs to (or null) - * @param preppedDb The PreppedDb that this Combination belongs to - * @para matrix The transformation matrix to apply to this Combination - * @return A PreppedRegion or a PreppedCombination as appropriate - */ - public PreppedObject prep( PreppedCombination reg, PreppedDb preppedDb, Matrix matrix) throws BadGeometryException, DbException, IOException, DbNameNotFoundException - { - BoundingBox boundingBox = null; - PreppedCombination pc = null; - boolean isRegion = this.getAttribute( "region" ) != null; - if( isRegion && reg == null ) - { - pc = new PreppedCombination( this ); - boundingBox = this.tree.prep( pc, preppedDb, matrix ); - preppedDb.addPreppedRegion( pc ); - } - else - { - boundingBox = this.tree.prep( reg, preppedDb, matrix ); - pc = new PreppedCombination( this ); - } - pc.setBoundingBox( boundingBox ); - - return pc; - } - - /** - * Get the tree that belongs to this Combination - * @return The tree - */ - public Tree getTree() - { - return this.tree; - } - - /** - * Create a String representation of this Combination - * - * @return a String - * - */ - public String toString() - { - return super.toString() + " Combination:\n" + this.tree; - } -} - Deleted: jbrlcad/trunk/src/geometry/DbException.java =================================================================== --- jbrlcad/trunk/src/geometry/DbException.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/DbException.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,16 +0,0 @@ -package geometry; -/** - * DbException.java - * - * @author Created by Omnicore CodeGuide - */ - - -public class DbException extends Exception -{ - public DbException( String msg ) - { - super( msg ); - } -} - Deleted: jbrlcad/trunk/src/geometry/DbExternal.java =================================================================== --- jbrlcad/trunk/src/geometry/DbExternal.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/DbExternal.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,214 +0,0 @@ -package geometry; -/** - * This class contains the external form of a BRL-CAD object consisting of the object name, its offset - * into the BRL-CAD database file, its major type, its minor type , its total length (bytes) in the - * BRL-CAD database file, an array of bytes containing the body of the object and another array of bytes - * containing the attributes of the object. - * - * @author Created by Omnicore CodeGuide - */ - -import java.io.IOException; -import java.io.RandomAccessFile; - -public class DbExternal -{ - // this object's name - private String name; - - // offset into the BRL-CAD database file for this object - private long offset; - - // major type of this object - private byte majorType; - - // minor type of this object - private byte minorType; - - // number of bytes used by this object in the database file - private long objectLength; - - // the attributes associated with this object - private byte[] attributes; - - // the body of the object - private byte[] body; - - // some masks - private static final byte DLI_MASK = 03; - private static final byte OBJECT_WID_MASK = (byte)0xc0; - private static final byte NAME_PRESENT = 0x20; - private static final byte NAME_WID_MASK = 0x18; - private static final byte AFLAGS_PRESENT = 0x20; - private static final byte AFLAGS_WID_MASK = (byte)0xc0; - private static final byte BFLAGS_PRESENT = 0x20; - private static final byte BFLAGS_WID_MASK = (byte)0xc0; - - // number of bytes used to represent different values in the byte arrays - public static final int[] fieldLength = { 1, 2, 4, 8 }; - - /** - * Construct a DbExternal by reading bytes from the specified BrlcadDb object starting at the specified offset - * - * @param db a BrlcadDb - * @param offset a long - * - * @exception IOException - * - */ - public DbExternal( BrlcadDb db, long offset ) throws IOException - { - // remember our offset - this.offset = offset; - - // get the RandomAccessFile - RandomAccessFile dbInput = db.getRAM(); - - // seek to the specified offset - dbInput.seek( offset ); - - // storage for the header - byte header[] = new byte[6]; - - // a counter of the number of bytes read so far - int used = 0; - - // read the object header - dbInput.readFully( header ); - - // check the first byte in the header - if( header[0] != BrlcadDb.DB5HDR_MAGIC1 ) - { - throw new IOException( "Bad magic number in object header" ); - } - - // get the major and minor types - this.majorType = header[4]; - this.minorType = header[5]; - - // the header was 6 bytes long - used += 6; - - // get the index into the fieldLength array for the object length - int objectWidIndex = (byte)(header[1] & OBJECT_WID_MASK) >> 6; - - // get the number of bytes used to store the object length - int objectLengthWidth = fieldLength[objectWidIndex]; - - // read the object length - this.objectLength = db.getUnsignedLong( objectLengthWidth ); - - // add the number of bytes read to our used count - used += objectLengthWidth; - - // the object length is specified in 8 byte chunks, so multiply by 8 to get bytes - this.objectLength = this.objectLength << 3; - - // check if we have a name - if( (header[1] & NAME_PRESENT) != 0 ) - { - // get the index into the fieldLength array for the name length - int nameWidIndex = (byte)(header[1] & NAME_WID_MASK) >> 3; - // get the number of bytes used to store the name length - int nameLengthWidth = fieldLength[nameWidIndex]; - // read the name length - int nameLength = (int)db.getUnsignedLong( nameLengthWidth ); - // update our used count - used += nameLengthWidth; - // create an array of bytes to hold the actual name - byte nameBytes[] = new byte[nameLength]; - // read the name - dbInput.readFully( nameBytes ); - // update our used count - used += nameLength; - // convert name bytes into a String and save it - this.name = new String( nameBytes ); - // eliminate trailing null - this.name = this.name.substring( 0, this.name.length() - 1 ); - } - - // check if we have attributes - if( (header[2] & AFLAGS_PRESENT) != 0 ) - { - // get the index into the fieldLength array for the attributes length - int attWidIndex = (byte)(header[2] & AFLAGS_WID_MASK) >> 6; - // get the number of bytes used to store the attribute length - int attLengthWidth = fieldLength[attWidIndex]; - // read the attribute length - int attLength = (int)db.getUnsignedLong( attLengthWidth ); - // update our used count - used += attLengthWidth; - // create an array of bytes to hold the actual array of bytes for attributes - this.attributes = new byte[attLength]; - // read the attribute bytes - dbInput.readFully( this.attributes ); - // update our used count - used += attLength; - } - - // check if we have a body - if( (header[3] & BFLAGS_PRESENT) != 0 ) - { - // get the index into the fieldLength array for the body length - int bodyWidIndex = (byte)(header[3] & BFLAGS_WID_MASK) >> 6; - // get the number of bytes used to store the body length - int bodyLengthWidth = fieldLength[bodyWidIndex]; - // read the body length - int bodyLength = (int)db.getUnsignedLong( bodyLengthWidth ); - // update our used count - used += bodyLengthWidth; - // create an array of bytes to hold the actual array of bytes for the body - this.body = new byte[bodyLength]; - // read the body - dbInput.readFully( this.body ); - // update our used count - used += bodyLength; - } -// The dli bits indicate what type of object we are reading, -// but since all objects are the same format, we really don't need -// to pay any attention to them. -// byte dli = (byte)(header[1] & DLI_MASK); -// if( dli == 0x1 ) -// { -// } -// else if( dli == 0x0 ) -// { -// } - - // skip over unused bytes (except for the last one) - dbInput.skipBytes( (int)(objectLength - used - 1) ); - // read the last byte in this object - byte lastByte = dbInput.readByte(); - // verify the last byte - if( lastByte != BrlcadDb.DB5HDR_MAGIC2 ) - { - throw new IOException( "Corrupted file (bad magic2)" ); - } - } - - public String getName() - { - return this.name; - } - - public byte getMajorType() - { - return this.majorType; - } - - public byte getMinorType() - { - return this.minorType; - } - - public byte[] getBody() - { - return this.body; - } - - public byte[] getAttributes() - { - return this.attributes; - } -} - Deleted: jbrlcad/trunk/src/geometry/DbNameNotFoundException.java =================================================================== --- jbrlcad/trunk/src/geometry/DbNameNotFoundException.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/DbNameNotFoundException.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,16 +0,0 @@ -package geometry; -/** - * DbNameNotFoundException.java - * - * @author Created by Omnicore CodeGuide - */ - - -public class DbNameNotFoundException extends Exception -{ - public DbNameNotFoundException( String msg ) - { - super( msg ); - } -} - Deleted: jbrlcad/trunk/src/geometry/DbObject.java =================================================================== --- jbrlcad/trunk/src/geometry/DbObject.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/DbObject.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,145 +0,0 @@ -package geometry; -/** - * This class is the base class for most of the BRL-CAD objects. It is only used directly for objects - * that are "attribute-only" objects (such as the "GLOBAL" object). - * - * @author Created by Omnicore CodeGuide - */ - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import preppedGeometry.PreppedCombination; -import preppedGeometry.PreppedObject; - -import numerics.Matrix; -import spacePartition.PreppedDb; - -public class DbObject -{ - /** the name of this object */ - String name; - - /** a map of atributes associated with this object */ - Map < String, String > attributes; - - /** - * Construct a DbObject from the specified DbExternal object - * - * @param dbExt a DbExternal - * - */ - protected DbObject( DbExternal dbExt ) - { - // get the object name - this.name = new String( dbExt.getName() ); - - // create an empty map of attributes - this.attributes = new HashMap <String, String>(); - - // Get the attibute bytes from the external object - byte[] attrBytes = dbExt.getAttributes(); - if( attrBytes == null ) - { - return; - } - - // Create buffers to hold the attribute names and values as we proces them - StringBuffer attrName = new StringBuffer(); - StringBuffer attrValue = new StringBuffer(); - - // process the entire array of bytes - int i=0; - while( attrBytes[i] != (byte)0 ) // a zero byte signls the end of the array - { - // reset the buffers - attrName.setLength( 0 ); - attrValue.setLength( 0 ); - - // read the attribute name (ends with a zero byte) - while( attrBytes[i] != (byte)0 ) - { - attrName.append( (char)attrBytes[i] ); - i++; - } - i++; - - // read the attibute vale (ends with a zero byte) - while( attrBytes[i] != (byte)0 ) - { - attrValue.append( (char)attrBytes[i] ); - i++; - } - i++; - - // if we have something meaningful, save it in the atributes map - if( attrName.length() > 0 && attrValue.length() > 0 ) - { - this.attributes.put( attrName.toString(), attrValue.toString() ); - } - } - } - - /** - * Method toString - * - * @return a String - * - */ - public String toString() - { - StringBuffer desc = new StringBuffer(); - desc.append( this.name + ":\n" ); - Set <String> keys = this.attributes.keySet(); - for( String key:keys ) - { - desc.append( "\t" + key + " = " + this.attributes.get( key ) + "\n" ); - } - return desc.toString(); - } - - /** - * Get the attribute value corresponding to the specified name (or null if - * there is no value fo rthe specified name) - * - * @param attrName the attribute name (a String) - * - * @return the attribute value (a String) - * - */ - public String getAttribute( String attrName ) - { - return this.attributes.get( attrName ); - } - - /** - * Get all attribute values for this object - * - * @return attribute values (Map<String, String>) - * - */ - public Map<String, String> getAttributes() - { - return new HashMap<String, String>(this.attributes); - } - - /** - * Method getName - * - * @return a String - * - */ - public String getName() - { - return this.name; - } - - public PreppedObject prep( PreppedCombination reg, PreppedDb preppedDb, Matrix matrix) throws BadGeometryException, DbException, IOException, DbNameNotFoundException - { - System.out.println( "DbObject.prep()" ); - return null; - } -} - Deleted: jbrlcad/trunk/src/geometry/Ellipsoid.java =================================================================== --- jbrlcad/trunk/src/geometry/Ellipsoid.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/Ellipsoid.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,187 +0,0 @@ -package geometry; -/** - * This class provides a representation of a BRL-CAD ellipsoid - * - * @author Created by Omnicore CodeGuide - */ - -import preppedGeometry.PreppedCombination; -import preppedGeometry.PreppedEllipsoid; -import numerics.Matrix; -import numerics.Point; -import numerics.Vector3; -import spacePartition.PreppedDb; - -public class Ellipsoid extends DbObject -{ - // geometry of the ellipsoid - private Point center; - private Vector3 a; - private Vector3 b; - private Vector3 c; - - // the major and minor types for an Ellipsoid - public static final byte majorType = 1; - public static final byte minorType = 3; - - /** - * Constructs an Ellipsoid object using a DbExternal object - * - * @param dbExt a DbExternal - * - * @exception DbException - * - */ - public Ellipsoid( DbExternal dbExt ) throws DbException - { - super( dbExt ); - - if( dbExt.getMajorType() != Ellipsoid.majorType || dbExt.getMinorType() != Ellipsoid.minorType ) - { - throw new DbException( "Attempted to import an Ellipsoid, but external is " + - " major type: " + dbExt.getMajorType() + - " minor type: " + dbExt.getMinorType() ); - } - - // create the geometry data objects - this.center = new Point(); - this.a = new Vector3(); - this.b = new Vector3(); - this.c = new Vector3(); - - // get the body bytes from the DbExternal object - byte[] body = dbExt.getBody(); - - // parse the body for the geometry data - int pointer = 0; - this.center.setX( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.center.setY( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.center.setZ( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.a.setX( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.a.setY( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.a.setZ( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.b.setX( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.b.setY( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.b.setZ( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.c.setX( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.c.setY( BrlcadDb.getDouble( body, pointer ) ); - pointer += 8; - this.c.setZ( BrlcadDb.getDouble( body, pointer ) ); - } - - /** - * Sets Center - * - * @param Center a Point - */ - public void setCenter(Point center) - { - this.center = center; - } - - /** - * Returns Center - * - * @return a Point - */ - public Point getCenter() - { - return center; - } - - /** - * Sets A - * - * @param A a Vector3 - */ - public void setA(Vector3 a) - { - this.a = a; - } - - /** - * Returns A - * - * @return a Vector3 - */ - public Vector3 getA() - { - return a; - } - - /** - * Sets B - * - * @param B a Vector3 - */ - public void setB(Vector3 b) - { - this.b = b; - } - - /** - * Returns B - * - * @return a Vector3 - */ - public Vector3 getB() - { - return b; - } - - /** - * Sets C - * - * @param C a Vector3 - */ - public void setC(Vector3 c) - { - this.c = c; - } - - /** - * Returns C - * - * @return a Vector3 - */ - public Vector3 getC() - { - return c; - } - - public PreppedEllipsoid prep( PreppedCombination reg, PreppedDb preppedDb, Matrix matrix) throws BadGeometryException - { - PreppedEllipsoid prepped = new PreppedEllipsoid( this, matrix ); - preppedDb.addPreppedObjectToInitialBox( prepped ); - if( reg != null ) - { - prepped.addRegion( reg ); - } - return prepped; - } - - /** - * Create a String representation of this Ellipsoid - * - * @return a String - * - */ - public String toString() - { - return super.toString() + " Ellipsoid, V=" + this.center + - ", a=" + this.a + - ", b=" + this.b + - ", c=" + this.c; - } -} - Deleted: jbrlcad/trunk/src/geometry/Face.java =================================================================== --- jbrlcad/trunk/src/geometry/Face.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/Face.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,33 +0,0 @@ -package geometry; -/** - * A simple containiner class for the indices of a triangular face - */ - - -public class Face -{ - /** - * Array of indices. These are indices into an array of vertices - */ - public final int[] v; - - /** - * Constructor - * @param i1 index of first vertex - * @param i2 index of second vertex - * @param i3 index of third vertex - */ - public Face( int i1, int i2, int i3 ) - { - this.v = new int[3]; - this.v[0] = i1; - this.v[1] = i2; - this.v[2] = i3; - } - - public String toString() - { - return "(" + v[0] + ", " + v[1] + ", " + v[2] + ")"; - } -} - Deleted: jbrlcad/trunk/src/geometry/Hit.java =================================================================== --- jbrlcad/trunk/src/geometry/Hit.java 2008-11-12 23:58:20 UTC (rev 33161) +++ jbrlcad/trunk/src/geometry/Hit.java 2008-11-13 00:44:13 UTC (rev 33162) @@ -1,201 +0,0 @@ -package geometry; -/** - * Hit.java - * - * @author Created by Omnicore CodeGuide - */ - - - -import numerics.Point; -import numerics.Vector3; -import spacePartition.RayData; - -public class Hit implements Comparable -{ - - private double hit_dist; - private Point hit_pt; - private Vector3 hit_normal; - private int hit_surfno; - private RayData rayData; - - public Hit( double dist, Point pt, Vector3 norm, int surfno, RayData rayData ) - { - this.hit_dist = dist; - this.hit_pt = pt; - this.hit_normal = norm; - this.hit_surfno = surfno; - this.rayData = rayData; - } - - /** - * Sets Hit_dist - * - * @param Hit_dist a double - */ - public void setHit_dist(double hit_dist) - { - this.hit_dist = hit_dist; - } - - /** - * Returns Hit_dist - * - * @return a double - */ - public double getHit_dist() - { - return hit_dist; - } - - /** - * Sets Hit_pt - * - * @param Hit_pt a Point - */ - public void setHit_pt(Point hit_pt) - { - this.hit_pt = hit_pt; - } - - /** - * Returns Hit_pt - * - * @return a Point - */ - public Point getHit_pt() - { - return hit_pt; - } - - /** - * Sets Hit_normal - * - * @param Hit_normal a Vector3 - */ - public void setHit_normal(Vector3 hit_normal) - { - this.hit_normal = hit_normal; - } - - /** - * Returns Hit_normal - * - * @return a Vector3 - */ - public Vector3 getHit_normal() - { - return hit_normal; - } - - /** - * Sets Hit_surfno - * - * @param Hit_surfno an int - */ - public void setHit_surfno(int hit_surfno) - { - this.hit_surfno = hit_surfno; - } - - /** - * Returns Hit_surfno - * - * @return an int - */ - public int getHit_surfno() - { - return hit_surfno; - } - - public String toString() - { - return "Hit: dist_pt=" + hit_dist + - ", point=" + hit_pt + - ", norm=" + hit_normal + - ", surf=" + hit_surfno; - } - public ... [truncated message content] |