[brlcad-commits] SF.net SVN: brlcad:[33878] jbrlcad/trunk/src/org/brlcad
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <joh...@us...> - 2009-02-23 17:43:12
|
Revision: 33878 http://brlcad.svn.sourceforge.net/brlcad/?rev=33878&view=rev Author: johnranderson Date: 2009-02-23 17:43:09 +0000 (Mon, 23 Feb 2009) Log Message: ----------- More bug fixes Modified Paths: -------------- jbrlcad/trunk/src/org/brlcad/geometry/OverlapHandler.java jbrlcad/trunk/src/org/brlcad/geometry/Partition.java jbrlcad/trunk/src/org/brlcad/geometry/SimpleOverlapHandler.java jbrlcad/trunk/src/org/brlcad/samples/rt.java jbrlcad/trunk/src/org/brlcad/shading/Material.java jbrlcad/trunk/src/org/brlcad/shading/NormalShader.java jbrlcad/trunk/src/org/brlcad/shading/Phong.java jbrlcad/trunk/src/org/brlcad/shading/Shader.java Modified: jbrlcad/trunk/src/org/brlcad/geometry/OverlapHandler.java =================================================================== --- jbrlcad/trunk/src/org/brlcad/geometry/OverlapHandler.java 2009-02-23 17:39:05 UTC (rev 33877) +++ jbrlcad/trunk/src/org/brlcad/geometry/OverlapHandler.java 2009-02-23 17:43:09 UTC (rev 33878) @@ -17,5 +17,17 @@ * @return A SortedSet of Partitions with no overlaps */ public SortedSet<Partition> handleOverlaps( SortedSet<Partition> parts, Ray ray ); + + /** + * Set this OverlapHandler to be quite (do not report overlaps) + * @param quiet boolean value (true means do not report) + */ + public void setQuiet( boolean quiet ); + + /** + * Get the quiet value for this OverlapHandler. True means do not report overlaps + * @return the boolean quiet value + */ + public boolean isQuiet(); } Modified: jbrlcad/trunk/src/org/brlcad/geometry/Partition.java =================================================================== --- jbrlcad/trunk/src/org/brlcad/geometry/Partition.java 2009-02-23 17:39:05 UTC (rev 33877) +++ jbrlcad/trunk/src/org/brlcad/geometry/Partition.java 2009-02-23 17:43:09 UTC (rev 33878) @@ -22,10 +22,10 @@ private static final Logger logger = Logger.getLogger(Partition.class.getName()); private Hit in_hit; - private boolean flipInNormal; + private boolean flipInNormal = false; private float inObliquity; private Hit out_hit; - private boolean flipOutNormal; + private boolean flipOutNormal = false; private float outObliquity; private String fromRegion; private double los; @@ -67,6 +67,14 @@ this.regionID = part.regionID; } + private void reverseInHitNormal() { + this.flipInNormal = !this.flipInNormal; + } + + private void reverseOutHitNormal() { + this.flipOutNormal = !this.flipOutNormal; + } + public int getRegionID() { return this.regionID; } @@ -182,14 +190,14 @@ public void setInHit(Hit hit, boolean flip) { this.in_hit = hit; if (flip) { - this.flipInNormal = !this.flipInNormal; + this.reverseInHitNormal(); } } public void setOutHit(Hit hit, boolean flip) { this.out_hit = hit; if (flip) { - this.flipOutNormal = !this.flipOutNormal; + this.reverseOutHitNormal(); } } @@ -249,6 +257,8 @@ Hit outHit; float inObliquity; float outObliquity; + boolean inflip1 = part1.isFlipInNormal(); + boolean outflip1 = part1.isFlipOutNormal(); logger.log(Level.FINEST, "Starting seg: <" + inDist1 + " - " + outDist1 + ">"); @@ -259,6 +269,10 @@ double outDist2 = part2.out_hit.getHit_dist(); float inObliquity2 = part2.getInObliquity(); float outObliquity2 = part2.getOutObliquity(); + boolean inflip2 = part2.isFlipInNormal(); + boolean outflip2 = part2.isFlipOutNormal(); + boolean inflip; + boolean outflip; logger.log(Level.FINEST, "intersect seg: <" + inDist2 + " - " + outDist2 + ">"); @@ -271,25 +285,33 @@ outHit = part2.out_hit; inObliquity = inObliquity2; outObliquity = outObliquity2; + inflip = inflip2; + outflip = outflip2; } else if (inDist2 > inDist1) { inHit = part2.in_hit; outHit = part1.out_hit; inObliquity = inObliquity2; outObliquity = outObliquity1; + inflip = inflip2; + outflip = outflip1; } else if (outDist2 < outDist1) { inHit = part1.in_hit; outHit = part2.out_hit; inObliquity = inObliquity1; outObliquity = outObliquity2; + inflip = inflip1; + outflip = outflip2; } else { inHit = part1.in_hit; outHit = part1.out_hit; inObliquity = inObliquity1; outObliquity = outObliquity1; + inflip = inflip1; + outflip = outflip1; } if (inHit != null && outHit != null) { if (inHit.getHit_dist() < outHit.getHit_dist()) { - parts.add(new Partition(inHit, false, outHit, false, + parts.add(new Partition(inHit, inflip, outHit, outflip, inObliquity, outObliquity, part1.fromRegion, part1.regionID)); } } Modified: jbrlcad/trunk/src/org/brlcad/geometry/SimpleOverlapHandler.java =================================================================== --- jbrlcad/trunk/src/org/brlcad/geometry/SimpleOverlapHandler.java 2009-02-23 17:39:05 UTC (rev 33877) +++ jbrlcad/trunk/src/org/brlcad/geometry/SimpleOverlapHandler.java 2009-02-23 17:43:09 UTC (rev 33878) @@ -11,6 +11,7 @@ public class SimpleOverlapHandler implements OverlapHandler { + private boolean quiet = false; /** * Method to reconcile overlaps along a ray trace. @@ -41,7 +42,7 @@ if( part2.getOutHit().getHit_dist() < part1.getOutHit().getHit_dist() ) { // part2 is entirely inside part1 (delete it) - if( !part1.getFromRegion().equals(part2.getFromRegion()) ) + if( !quiet && !part1.getFromRegion().equals(part2.getFromRegion()) ) { System.err.println( "OVERLAP on Ray: " + ray + "\n\t" + part1 + "\n\t" + part2 ); } @@ -54,16 +55,16 @@ { // not really an overlap, but handle it part1.setOutHit( part2.getOutHit(), false ); - part1.setFlipOutNormal( part2.isFlipOutNormal() ); iter.remove(); continue; } else { // two different regions, select part1 - System.err.println( "OVERLAP on Ray: " + ray + "\n\t" + part1 + "\n\t" + part2 ); - part2.setInHit( part1.getOutHit(), false ); - part2.setFlipInNormal( !part1.isFlipOutNormal() ); + if( !quiet ) { + System.err.println("OVERLAP on Ray: " + ray + "\n\t" + part1 + "\n\t" + part2); + } + part2.setInHit( part1.getOutHit(), true ); } } } @@ -73,6 +74,14 @@ } return parts; } + + public void setQuiet(boolean quiet) { + this.quiet = quiet; + } + + public boolean isQuiet() { + return this.quiet; + } } Modified: jbrlcad/trunk/src/org/brlcad/samples/rt.java =================================================================== --- jbrlcad/trunk/src/org/brlcad/samples/rt.java 2009-02-23 17:39:05 UTC (rev 33877) +++ jbrlcad/trunk/src/org/brlcad/samples/rt.java 2009-02-23 17:43:09 UTC (rev 33878) @@ -28,6 +28,7 @@ import org.brlcad.geometry.DbException; import org.brlcad.geometry.DbNameNotFoundException; import org.brlcad.geometry.DbObject; +import org.brlcad.geometry.OverlapHandler; import org.brlcad.geometry.Partition; import org.brlcad.geometry.SimpleOverlapHandler; import org.brlcad.numerics.BoundingBox; @@ -61,6 +62,7 @@ String dbFileName = null; String[] tlos = null; int fbPort = -1; + boolean reportOverlaps = true; if (args.length < 2) { System.err.println(usage); @@ -88,6 +90,10 @@ } else if( "-e".equals(arg)) { argNo++; el = Amount.valueOf(Double.valueOf(args[argNo]), NonSI.DEGREE_ANGLE); + } else if( "-r".equals(arg)) { + reportOverlaps = true; + } else if( "-R".equals(arg)) { + reportOverlaps = false; } else { endOfOptions = true; continue; @@ -170,11 +176,13 @@ colorTable = new ColorTable(colortab); } } + OverlapHandler oh = new SimpleOverlapHandler(); + oh.setQuiet(!reportOverlaps); ExecutorService executor = Executors.newFixedThreadPool(cpus); Object lock = new Object(); for( int row = 0 ; row < size ; row++ ) { executor.submit(new RowTask(row, size, gridStart, xDir, yDir, rayDir, - delta, lights, backGround, prepped, colorTable, buffer, fbOs, lock)); + delta, lights, oh, backGround, prepped, colorTable, buffer, fbOs, lock)); } executor.shutdown(); while( !executor.awaitTermination(10, TimeUnit.SECONDS)); @@ -223,9 +231,10 @@ private PreppedDb prepped; private final Object lock; private OutputStream fbOs; + private OverlapHandler oh; public RowTask(int row, int size, Point gridStart, Vector3 xDir, Vector3 yDir, Vector3 rayDir, - double delta, Set<Light> lights, Color backGround, PreppedDb prepped, + double delta, Set<Light> lights, OverlapHandler oh, Color backGround, PreppedDb prepped, ColorTable colorTable, ByteBuffer buffer, OutputStream fbOs, Object lock) { this.row = row; this.size = size; @@ -235,6 +244,7 @@ this.rayDir = rayDir; this.delta = delta; this.lights = lights; + this.oh = oh; this.backGround = backGround; this.buffer = buffer; this.prepped = prepped; @@ -250,9 +260,9 @@ start.join(delta * row, yDir); start.join(delta * col, xDir); Ray ray = new Ray(start, rayDir); - Shader shader = new Phong(start, lights); -// Shader shader = new NormalShader(start); - SortedSet<Partition> parts = prepped.shootRay(ray, new SimpleOverlapHandler()); + Shader shader = new Phong(lights); +// Shader shader = new NormalShader(); + SortedSet<Partition> parts = prepped.shootRay(ray, oh); Color color = null; if (parts.size() > 0) { Partition first = parts.first(); @@ -261,7 +271,7 @@ Color matColor = colorTable.getColor(first.getRegionID()); // System.out.println( "Setting color of " + first.getFromRegion() + " to " + matColor); } - color = shader.shade(first.getInHit(), material); + color = shader.shade(first, material, start); } else { color = backGround; } Modified: jbrlcad/trunk/src/org/brlcad/shading/Material.java =================================================================== --- jbrlcad/trunk/src/org/brlcad/shading/Material.java 2009-02-23 17:39:05 UTC (rev 33877) +++ jbrlcad/trunk/src/org/brlcad/shading/Material.java 2009-02-23 17:43:09 UTC (rev 33878) @@ -25,7 +25,7 @@ this.color = new Color(color.getRGB()); this.ks = 0.7; this.kd = 0.2; - this.ka = 0.5; + this.ka = 1.0; this.alpha = 10; } Modified: jbrlcad/trunk/src/org/brlcad/shading/NormalShader.java =================================================================== --- jbrlcad/trunk/src/org/brlcad/shading/NormalShader.java 2009-02-23 17:39:05 UTC (rev 33877) +++ jbrlcad/trunk/src/org/brlcad/shading/NormalShader.java 2009-02-23 17:43:09 UTC (rev 33878) @@ -6,7 +6,7 @@ package org.brlcad.shading; import java.awt.Color; -import org.brlcad.geometry.Hit; +import org.brlcad.geometry.Partition; import org.brlcad.numerics.Point; import org.brlcad.numerics.Vector3; @@ -16,18 +16,16 @@ */ public class NormalShader implements Shader { - private Point eye_pt; - - public NormalShader( Point eye_pt ) { - this.eye_pt = new Point( eye_pt ); + public NormalShader() { } - public Color shade(Hit hit, Material mat) { - Vector3 toEye = Vector3.minus(eye_pt, hit.getHit_pt()); + public Color shade(Partition part, Material mat, Point eye_pt) { + Point hit_pt = part.getInHit().getHit_pt(); + Vector3 hit_norm = part.getInHitNormal(); + Vector3 toEye = Vector3.minus(eye_pt, hit_pt); toEye.normalize(); - Vector3 norm = hit.getHit_normal(); - float dot = (float) norm.dotProduct(toEye); + float dot = (float) hit_norm.dotProduct(toEye); if( dot < 0.0 ) { dot = 0.0f; } Modified: jbrlcad/trunk/src/org/brlcad/shading/Phong.java =================================================================== --- jbrlcad/trunk/src/org/brlcad/shading/Phong.java 2009-02-23 17:39:05 UTC (rev 33877) +++ jbrlcad/trunk/src/org/brlcad/shading/Phong.java 2009-02-23 17:43:09 UTC (rev 33878) @@ -8,7 +8,7 @@ import java.awt.Color; import java.util.HashSet; import java.util.Set; -import org.brlcad.geometry.Hit; +import org.brlcad.geometry.Partition; import org.brlcad.numerics.Point; import org.brlcad.numerics.Vector3; @@ -17,29 +17,28 @@ * @author jra */ public class Phong implements Shader { - private static final Material defaultMaterial = new Material("default", new Color(55, 55, 55)); - private Point eye_pt; + private static final Material defaultMaterial = new Material("default", new Color(200, 200, 200)); private Set<Light> lights; private double ambientIntensity = 0.7; - public Phong( Point eye_pt ) { - this.eye_pt = new Point( eye_pt ); + public Phong() { this.lights = new HashSet<Light>(); } - public Phong( Point eye_pt, Set<Light> lights ) { - this.eye_pt = new Point( eye_pt ); + public Phong( Set<Light> lights ) { this.lights = new HashSet<Light>(); this.lights.addAll(lights); } - public Color shade( Hit hit, Material mat ) { - Vector3 toEye = Vector3.minus(eye_pt, hit.getHit_pt()); + public Color shade( Partition part, Material mat, Point eye_pt ) { + Vector3 toEye = Vector3.minus(eye_pt, part.getInHit().getHit_pt()); toEye.normalize(); if( mat == null ) { mat = defaultMaterial; } - double scale = -hit.getRayData().getTheRay().getDirection().dotProduct(hit.getHit_normal()); + Point hit_pt = part.getInHit().getHit_pt(); + Vector3 hit_normal = part.getInHitNormal(); + double scale = -part.getInHit().getRayData().getTheRay().getDirection().dotProduct(hit_normal); if( scale < 0.0 ) { scale = 0.0; } @@ -49,27 +48,35 @@ scale *= ambientIntensity; Color color = scale(mat.getColor(), (float)(mat.getKa()*scale)); for( Light light : lights ) { - Vector3 toLight = Vector3.minus(light.getLocation(), hit.getHit_pt()); + Vector3 toLight = Vector3.minus(light.getLocation(), hit_pt); toLight.normalize(); - double cosine = toLight.dotProduct(hit.getHit_normal()); + double cosine = toLight.dotProduct(hit_normal); if( cosine < 0.0 ) { continue; } else if( cosine > 1.0 ) { cosine = 1.0; } color = add( color, scale(light.getDiffuse(), (float)(3.0*mat.getKd()*cosine/lights.size())) ); - Vector3 reflected = Vector3.scale(hit.getHit_normal(), 2.0*cosine); + Vector3 reflected = Vector3.scale(hit_normal, 2.0*cosine); reflected.minus(toLight); reflected.normalize(); cosine = reflected.dotProduct(toEye); - double spec = Math.pow(cosine, mat.getAlpha()); - color = add( color, scale(light.getSpecular(), (float)(mat.getKs()*spec))); + if( cosine > 1.0 ) { + cosine = 1.0; + } + if( cosine > 0.0 ) { + double spec = Math.pow(cosine, mat.getAlpha()); + color = add(color, scale(light.getSpecular(), (float) (mat.getKs() * spec))); + } } float[] rgb = color.getRGBColorComponents(null); for (int i = 0; i < 3; i++) { if (rgb[i] > 1.0) { rgb[i] = 1.0f; } + if( rgb[i] < 0.0 ) { + rgb[i] = 0.0f; + } } return new Color(rgb[0], rgb[1], rgb[2]); } @@ -110,20 +117,6 @@ } /** - * @return the eye_pt - */ - public Point getEye_pt() { - return eye_pt; - } - - /** - * @param eye_pt the eye_pt to set - */ - public void setEye_pt(Point eye_pt) { - this.eye_pt = eye_pt; - } - - /** * @return the lights */ public Set<Light> getLights() { Modified: jbrlcad/trunk/src/org/brlcad/shading/Shader.java =================================================================== --- jbrlcad/trunk/src/org/brlcad/shading/Shader.java 2009-02-23 17:39:05 UTC (rev 33877) +++ jbrlcad/trunk/src/org/brlcad/shading/Shader.java 2009-02-23 17:43:09 UTC (rev 33878) @@ -6,12 +6,13 @@ package org.brlcad.shading; import java.awt.Color; -import org.brlcad.geometry.Hit; +import org.brlcad.geometry.Partition; +import org.brlcad.numerics.Point; /** * * @author jra */ public interface Shader { - public Color shade( Hit hit, Material mat ); + public Color shade( Partition part, Material mat, Point eye_pt ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |