Package com.sun.j3d.utils.picking

Source Code of com.sun.j3d.utils.picking.PickTool

/*      */ package com.sun.j3d.utils.picking;
/*      */
/*      */ import com.sun.j3d.internal.UtilFreelistManager;
/*      */ import com.sun.j3d.internal.UtilMemoryFreelist;
/*      */ import java.util.ArrayList;
/*      */ import javax.media.j3d.Bounds;
/*      */ import javax.media.j3d.BranchGroup;
/*      */ import javax.media.j3d.CompressedGeometry;
/*      */ import javax.media.j3d.Geometry;
/*      */ import javax.media.j3d.GeometryArray;
/*      */ import javax.media.j3d.IndexedGeometryArray;
/*      */ import javax.media.j3d.Locale;
/*      */ import javax.media.j3d.Morph;
/*      */ import javax.media.j3d.Node;
/*      */ import javax.media.j3d.PickBounds;
/*      */ import javax.media.j3d.PickConeRay;
/*      */ import javax.media.j3d.PickConeSegment;
/*      */ import javax.media.j3d.PickCylinderRay;
/*      */ import javax.media.j3d.PickCylinderSegment;
/*      */ import javax.media.j3d.PickRay;
/*      */ import javax.media.j3d.PickSegment;
/*      */ import javax.media.j3d.PickShape;
/*      */ import javax.media.j3d.SceneGraphPath;
/*      */ import javax.media.j3d.Shape3D;
/*      */ import javax.vecmath.Point3d;
/*      */ import javax.vecmath.Vector3d;
/*      */
/*      */ public class PickTool
/*      */ {
/*  123 */   private final boolean debug = true;
/*  124 */   protected boolean userDefineShape = false;
/*      */   PickShape pickShape;
/*  129 */   BranchGroup pickRootBG = null;
/*      */
/*  131 */   Locale pickRootL = null;
/*      */
/*  136 */   Point3d start = null;
/*      */
/*  139 */   int mode = 512;
/*      */   public static final int BOUNDS = 512;
/*      */   public static final int GEOMETRY = 256;
/*      */   public static final int GEOMETRY_INTERSECT_INFO = 1024;
/*      */   public static final int INTERSECT_TEST = 4097;
/*      */   public static final int INTERSECT_COORD = 4098;
/*      */   public static final int INTERSECT_FULL = 4100;
/*      */
/*      */   public PickTool(BranchGroup b)
/*      */   {
/*  189 */     this.pickRootBG = b;
/*      */   }
/*      */
/*      */   public BranchGroup getBranchGroup()
/*      */   {
/*  196 */     return this.pickRootBG;
/*      */   }
/*      */
/*      */   public PickTool(Locale l)
/*      */   {
/*  203 */     this.pickRootL = l;
/*      */   }
/*      */
/*      */   public Locale setBranchGroup(Locale l)
/*      */   {
/*  211 */     return this.pickRootL;
/*      */   }
/*      */
/*      */   public static void setCapabilities(Node node, int level)
/*      */   {
/*  236 */     if ((node instanceof Morph)) {
/*  237 */       Morph morph = (Morph)node;
/*  238 */       switch (level)
/*      */       {
/*      */       case 4098:
/*      */       case 4100:
/*  242 */         morph.setCapability(12);
/*      */       case 4097:
/*  245 */         break;
/*      */       case 4099:
/*      */       default:
/*  247 */         throw new IllegalArgumentException("Improper level");
/*      */       }
/*  249 */       double[] weights = morph.getWeights();
/*  250 */       for (int i = 0; i < weights.length; i++) {
/*  251 */         GeometryArray ga = morph.getGeometryArray(i);
/*  252 */         setCapabilities(ga, level);
/*      */       }
/*  254 */     } else if ((node instanceof Shape3D)) {
/*  255 */       Shape3D shape = (Shape3D)node;
/*  256 */       switch (level)
/*      */       {
/*      */       case 4098:
/*      */       case 4100:
/*  260 */         shape.setCapability(12);
/*      */       case 4097:
/*  263 */         break;
/*      */       case 4099:
/*      */       default:
/*  265 */         throw new IllegalArgumentException("Improper level");
/*      */       }
/*  267 */       for (int i = 0; i < shape.numGeometries(); i++) {
/*  268 */         Geometry geo = shape.getGeometry(i);
/*  269 */         if ((geo instanceof GeometryArray))
/*  270 */           setCapabilities((GeometryArray)geo, level);
/*  271 */         else if ((geo instanceof CompressedGeometry))
/*  272 */           setCapabilities((CompressedGeometry)geo, level);
/*      */       }
/*      */     }
/*      */     else {
/*  276 */       throw new IllegalArgumentException("Improper node type");
/*      */     }
/*      */   }
/*      */
/*      */   private static void setCapabilities(GeometryArray ga, int level) {
/*  281 */     switch (level) {
/*      */     case 4100:
/*  283 */       ga.setCapability(2);
/*  284 */       ga.setCapability(4);
/*  285 */       ga.setCapability(6);
/*      */     case 4098:
/*  288 */       ga.setCapability(8);
/*  289 */       ga.setCapability(17);
/*  290 */       ga.setCapability(0);
/*      */     case 4097:
/*  293 */       ga.setCapability(18);
/*      */     case 4099:
/*      */     }
/*  296 */     if ((ga instanceof IndexedGeometryArray))
/*  297 */       setCapabilities((IndexedGeometryArray)ga, level);
/*      */   }
/*      */
/*      */   private static void setCapabilities(IndexedGeometryArray iga, int level)
/*      */   {
/*  302 */     switch (level) {
/*      */     case 4100:
/*  304 */       iga.setCapability(11);
/*  305 */       iga.setCapability(13);
/*  306 */       iga.setCapability(15);
/*      */     case 4098:
/*  309 */       iga.setCapability(9);
/*      */     case 4097:
/*      */     case 4099:
/*      */     }
/*      */   }
/*      */
/*      */   private static void setCapabilities(CompressedGeometry cg, int level)
/*      */   {
/*  317 */     switch (level)
/*      */     {
/*      */     case 4098:
/*      */     case 4100:
/*  321 */       cg.setCapability(2);
/*      */     case 4097:
/*  324 */       cg.setCapability(18);
/*      */     case 4099:
/*      */     }
/*      */   }
/*      */
/*      */   public void setShape(PickShape ps, Point3d startPt)
/*      */   {
/*  336 */     this.pickShape = ps;
/*  337 */     this.start = startPt;
/*  338 */     this.userDefineShape = (ps != null);
/*      */   }
/*      */
/*      */   public void setShapeBounds(Bounds bounds, Point3d startPt)
/*      */   {
/*  346 */     this.pickShape = new PickBounds(bounds);
/*  347 */     this.start = startPt;
/*  348 */     this.userDefineShape = true;
/*      */   }
/*      */
/*      */   public void setMode(int mode)
/*      */   {
/*  356 */     if ((mode != 512) && (mode != 256) && (mode != 1024))
/*      */     {
/*  358 */       throw new IllegalArgumentException();
/*      */     }
/*  360 */     this.mode = mode;
/*      */   }
/*      */
/*      */   public int getMode()
/*      */   {
/*  366 */     return this.mode;
/*      */   }
/*      */
/*      */   public void setShapeRay(Point3d start, Vector3d dir)
/*      */   {
/*  374 */     this.pickShape = new PickRay(start, dir);
/*  375 */     this.start = start;
/*  376 */     this.userDefineShape = true;
/*      */   }
/*      */
/*      */   public void setShapeSegment(Point3d start, Point3d end)
/*      */   {
/*  384 */     this.pickShape = new PickSegment(start, end);
/*  385 */     this.start = start;
/*  386 */     this.userDefineShape = true;
/*      */   }
/*      */
/*      */   public void setShapeCylinderSegment(Point3d start, Point3d end, double radius)
/*      */   {
/*  396 */     this.pickShape = new PickCylinderSegment(start, end, radius);
/*      */
/*  398 */     this.start = start;
/*  399 */     this.userDefineShape = true;
/*      */   }
/*      */
/*      */   public void setShapeCylinderRay(Point3d start, Vector3d dir, double radius)
/*      */   {
/*  409 */     this.pickShape = new PickCylinderRay(start, dir, radius);
/*  410 */     this.start = start;
/*  411 */     this.userDefineShape = true;
/*      */   }
/*      */
/*      */   public void setShapeConeSegment(Point3d start, Point3d end, double angle)
/*      */   {
/*  421 */     this.pickShape = new PickConeSegment(start, end, angle);
/*  422 */     this.start = start;
/*  423 */     this.userDefineShape = true;
/*      */   }
/*      */
/*      */   public void setShapeConeRay(Point3d start, Vector3d dir, double angle)
/*      */   {
/*  433 */     this.pickShape = new PickConeRay(start, dir, angle);
/*  434 */     this.start = start;
/*  435 */     this.userDefineShape = true;
/*      */   }
/*      */
/*      */   public PickShape getPickShape()
/*      */   {
/*  440 */     return this.pickShape;
/*      */   }
/*      */
/*      */   public Point3d getStartPosition()
/*      */   {
/*  445 */     return this.start;
/*      */   }
/*      */
/*      */   public PickResult[] pickAll()
/*      */   {
/*  454 */     PickResult[] retval = null;
/*  455 */     switch (this.mode) {
/*      */     case 512:
/*  457 */       retval = pickAll(this.pickShape);
/*  458 */       break;
/*      */     case 256:
/*  460 */       retval = pickGeomAll(this.pickShape);
/*  461 */       break;
/*      */     case 1024:
/*  463 */       retval = pickGeomAllIntersect(this.pickShape);
/*  464 */       break;
/*      */     default:
/*  466 */       throw new InternalError("Invalid pick mode");
/*      */     }
/*  468 */     return retval;
/*      */   }
/*      */
/*      */   public PickResult pickAny()
/*      */   {
/*  477 */     PickResult retval = null;
/*  478 */     switch (this.mode) {
/*      */     case 512:
/*  480 */       retval = pickAny(this.pickShape);
/*  481 */       break;
/*      */     case 256:
/*  483 */       retval = pickGeomAny(this.pickShape);
/*  484 */       break;
/*      */     case 1024:
/*  486 */       retval = pickGeomAnyIntersect(this.pickShape);
/*  487 */       break;
/*      */     default:
/*  489 */       throw new InternalError("Invalid pick mode");
/*      */     }
/*  491 */     return retval;
/*      */   }
/*      */
/*      */   public PickResult[] pickAllSorted()
/*      */   {
/*  503 */     PickResult[] retval = null;
/*      */
/*  507 */     switch (this.mode)
/*      */     {
/*      */     case 512:
/*  510 */       retval = pickAllSorted(this.pickShape);
/*  511 */       break;
/*      */     case 256:
/*  522 */       retval = pickGeomAllSorted(this.pickShape);
/*      */
/*  524 */       break;
/*      */     case 1024:
/*  528 */       retval = pickGeomAllSortedIntersect(this.pickShape);
/*  529 */       break;
/*      */     default:
/*  531 */       throw new InternalError("Invalid pick mode");
/*      */     }
/*  533 */     return retval;
/*      */   }
/*      */
/*      */   public PickResult pickClosest()
/*      */   {
/*  545 */     PickResult retval = null;
/*  546 */     switch (this.mode) {
/*      */     case 512:
/*  548 */       retval = pickClosest(this.pickShape);
/*  549 */       break;
/*      */     case 256:
/*  560 */       retval = pickGeomClosest(this.pickShape);
/*      */
/*  562 */       break;
/*      */     case 1024:
/*  566 */       retval = pickGeomClosestIntersect(this.pickShape);
/*  567 */       break;
/*      */     default:
/*  569 */       throw new InternalError("Invalid pick mode");
/*      */     }
/*  571 */     return retval;
/*      */   }
/*      */
/*      */   private PickResult[] pickAll(PickShape pickShape) {
/*  575 */     PickResult[] pr = null;
/*  576 */     SceneGraphPath[] sgp = null;
/*      */
/*  578 */     if (this.pickRootBG != null)
/*  579 */       sgp = this.pickRootBG.pickAll(pickShape);
/*  580 */     else if (this.pickRootL != null) {
/*  581 */       sgp = this.pickRootL.pickAll(pickShape);
/*      */     }
/*  583 */     if (sgp == null) return null;
/*      */
/*  586 */     pr = new PickResult[sgp.length];
/*  587 */     for (int i = 0; i < sgp.length; i++) {
/*  588 */       pr[i] = new PickResult(sgp[i], pickShape);
/*      */     }
/*  590 */     return pr;
/*      */   }
/*      */
/*      */   private PickResult[] pickAllSorted(PickShape pickShape) {
/*  594 */     PickResult[] pr = null;
/*  595 */     SceneGraphPath[] sgp = null;
/*      */
/*  597 */     if (this.pickRootBG != null)
/*  598 */       sgp = this.pickRootBG.pickAllSorted(pickShape);
/*  599 */     else if (this.pickRootL != null) {
/*  600 */       sgp = this.pickRootL.pickAllSorted(pickShape);
/*      */     }
/*  602 */     if (sgp == null) return null;
/*      */
/*  605 */     pr = new PickResult[sgp.length];
/*  606 */     for (int i = 0; i < sgp.length; i++) {
/*  607 */       pr[i] = new PickResult(sgp[i], pickShape);
/*      */     }
/*  609 */     return pr;
/*      */   }
/*      */
/*      */   private PickResult pickAny(PickShape pickShape) {
/*  613 */     PickResult pr = null;
/*  614 */     SceneGraphPath sgp = null;
/*      */
/*  616 */     if (this.pickRootBG != null)
/*  617 */       sgp = this.pickRootBG.pickAny(pickShape);
/*  618 */     else if (this.pickRootL != null) {
/*  619 */       sgp = this.pickRootL.pickAny(pickShape);
/*      */     }
/*  621 */     if (sgp == null) return null;
/*      */
/*  624 */     pr = new PickResult(sgp, pickShape);
/*  625 */     return pr;
/*      */   }
/*      */
/*      */   private PickResult pickClosest(PickShape pickShape) {
/*  629 */     PickResult pr = null;
/*  630 */     SceneGraphPath sgp = null;
/*      */
/*  632 */     if (this.pickRootBG != null)
/*  633 */       sgp = this.pickRootBG.pickClosest(pickShape);
/*  634 */     else if (this.pickRootL != null) {
/*  635 */       sgp = this.pickRootL.pickClosest(pickShape);
/*      */     }
/*  637 */     if (sgp == null) return null;
/*      */
/*  640 */     pr = new PickResult(sgp, pickShape);
/*  641 */     return pr;
/*      */   }
/*      */
/*      */   private PickResult[] pickGeomAll(PickShape pickShape)
/*      */   {
/*  649 */     SceneGraphPath[] sgp = null;
/*  650 */     Node[] obj = null;
/*  651 */     int cnt = 0;
/*      */
/*  654 */     if (this.pickRootBG != null)
/*  655 */       sgp = this.pickRootBG.pickAll(pickShape);
/*  656 */     else if (this.pickRootL != null) {
/*  657 */       sgp = this.pickRootL.pickAll(pickShape);
/*      */     }
/*  659 */     if (sgp == null) return null;
/*      */
/*  662 */     boolean[] found = new boolean[sgp.length];
/*      */
/*  664 */     obj = new Node[sgp.length];
/*  665 */     PickResult[] pr = new PickResult[sgp.length];
/*  666 */     for (int i = 0; i < sgp.length; i++) {
/*  667 */       obj[i] = sgp[i].getObject();
/*  668 */       pr[i] = new PickResult(sgp[i], pickShape);
/*      */
/*  670 */       if ((obj[i] instanceof Shape3D))
/*  671 */         found[i] = ((Shape3D)obj[i]).intersect(sgp[i], pickShape);
/*  672 */       else if ((obj[i] instanceof Morph)) {
/*  673 */         found[i] = ((Morph)obj[i]).intersect(sgp[i], pickShape);
/*      */       }
/*  675 */       if (found[i] == 1) cnt++;
/*      */     }
/*      */
/*  678 */     if (cnt == 0) return null;
/*      */
/*  680 */     PickResult[] newpr = new PickResult[cnt];
/*  681 */     cnt = 0;
/*  682 */     for (i = 0; i < sgp.length; i++) {
/*  683 */       if (found[i] == 1) {
/*  684 */         pr[(cnt++)] = pr[i];
/*      */       }
/*      */     }
/*  687 */     return pr;
/*      */   }
/*      */
/*      */   private PickResult[] pickGeomAllSorted(PickShape pickShape) {
/*  691 */     SceneGraphPath[] sgp = null;
/*  692 */     Node[] obj = null;
/*  693 */     int cnt = 0;
/*  694 */     double[] dist = new double[1];
/*      */
/*  697 */     if (this.pickRootBG != null)
/*  698 */       sgp = this.pickRootBG.pickAll(pickShape);
/*  699 */     else if (this.pickRootL != null) {
/*  700 */       sgp = this.pickRootL.pickAll(pickShape);
/*      */     }
/*  702 */     if (sgp == null) return null;
/*      */
/*  709 */     boolean[] found = new boolean[sgp.length];
/*  710 */     double[] distArr = new double[sgp.length];
/*  711 */     obj = new Node[sgp.length];
/*  712 */     PickResult[] pr = new PickResult[sgp.length];
/*      */
/*  714 */     for (int i = 0; i < sgp.length; i++) {
/*  715 */       obj[i] = sgp[i].getObject();
/*  716 */       pr[i] = new PickResult(sgp[i], pickShape);
/*  717 */       if ((obj[i] instanceof Shape3D)) {
/*  718 */         found[i] = ((Shape3D)obj[i]).intersect(sgp[i], pickShape, dist);
/*      */
/*  720 */         distArr[i] = dist[0];
/*  721 */       } else if ((obj[i] instanceof Morph)) {
/*  722 */         found[i] = ((Morph)obj[i]).intersect(sgp[i], pickShape, dist);
/*      */
/*  724 */         distArr[i] = dist[0];
/*      */       }
/*  726 */       if (found[i] == 1) cnt++;
/*      */     }
/*  728 */     if (cnt == 0) return null;
/*      */
/*  730 */     PickResult[] npr = new PickResult[cnt];
/*  731 */     double[] distance = new double[cnt];
/*  732 */     cnt = 0;
/*  733 */     for (i = 0; i < sgp.length; i++) {
/*  734 */       if (found[i] == 1) {
/*  735 */         distance[cnt] = distArr[i];
/*  736 */         npr[(cnt++)] = pr[i];
/*      */       }
/*      */     }
/*  739 */     if (cnt > 1) {
/*  740 */       return sortPickResults(npr, distance);
/*      */     }
/*  742 */     return npr;
/*      */   }
/*      */
/*      */   private PickResult pickGeomAny(PickShape pickShape)
/*      */   {
/*  747 */     Node obj = null;
/*      */
/*  749 */     SceneGraphPath[] sgpa = null;
/*      */
/*  751 */     if (this.pickRootBG != null)
/*  752 */       sgpa = this.pickRootBG.pickAll(pickShape);
/*  753 */     else if (this.pickRootL != null) {
/*  754 */       sgpa = this.pickRootL.pickAll(pickShape);
/*      */     }
/*      */
/*  757 */     if (sgpa == null) return null;
/*      */
/*  759 */     for (int i = 0; i < sgpa.length; i++) {
/*  760 */       obj = sgpa[i].getObject();
/*  761 */       PickResult pr = new PickResult(sgpa[i], pickShape);
/*  762 */       if ((obj instanceof Shape3D)) {
/*  763 */         if (((Shape3D)obj).intersect(sgpa[i], pickShape))
/*  764 */           return pr;
/*      */       }
/*  766 */       else if (((obj instanceof Morph)) &&
/*  767 */         (((Morph)obj).intersect(sgpa[i], pickShape))) {
/*  768 */         return pr;
/*      */       }
/*      */
/*      */     }
/*      */
/*  773 */     return null;
/*      */   }
/*      */
/*      */   private PickResult pickGeomClosest(PickShape pickShape)
/*      */   {
/*  778 */     PickResult[] pr = pickGeomAllSorted(pickShape);
/*  779 */     if (pr == null) {
/*  780 */       return null;
/*      */     }
/*  782 */     return pr[0];
/*      */   }
/*      */
/*      */   private PickResult[] pickGeomAllIntersect(PickShape pickShape)
/*      */   {
/*  791 */     SceneGraphPath[] sgp = null;
/*  792 */     Node[] obj = null;
/*  793 */     int cnt = 0;
/*      */
/*  796 */     if (this.pickRootBG != null)
/*  797 */       sgp = this.pickRootBG.pickAll(pickShape);
/*  798 */     else if (this.pickRootL != null) {
/*  799 */       sgp = this.pickRootL.pickAll(pickShape);
/*      */     }
/*  801 */     if (sgp == null) return null;
/*      */
/*  804 */     boolean[] found = new boolean[sgp.length];
/*      */
/*  806 */     PickResult[] pr = new PickResult[sgp.length];
/*  807 */     for (int i = 0; i < sgp.length; i++) {
/*  808 */       pr[i] = new PickResult(sgp[i], pickShape);
/*  809 */       if (pr[i].numIntersections() > 0) {
/*  810 */         found[i] = true;
/*  811 */         cnt++;
/*      */       }
/*      */     }
/*      */
/*  815 */     if (cnt == 0) return null;
/*      */
/*  817 */     PickResult[] newpr = new PickResult[cnt];
/*  818 */     cnt = 0;
/*  819 */     for (i = 0; i < sgp.length; i++) {
/*  820 */       if (found[i] == 1) {
/*  821 */         pr[(cnt++)] = pr[i];
/*      */       }
/*      */     }
/*  824 */     return pr;
/*      */   }
/*      */
/*      */   private PickResult[] pickGeomAllSortedIntersect(PickShape pickShape) {
/*  828 */     SceneGraphPath[] sgp = null;
/*  829 */     Node[] obj = null;
/*  830 */     int cnt = 0;
/*  831 */     double[] dist = new double[1];
/*      */
/*  834 */     if (this.pickRootBG != null)
/*  835 */       sgp = this.pickRootBG.pickAll(pickShape);
/*  836 */     else if (this.pickRootL != null) {
/*  837 */       sgp = this.pickRootL.pickAll(pickShape);
/*      */     }
/*  839 */     if (sgp == null) return null;
/*      */
/*  847 */     boolean[] found = new boolean[sgp.length];
/*  848 */     double[] distArr = new double[sgp.length];
/*      */
/*  850 */     PickResult[] pr = new PickResult[sgp.length];
/*  851 */     for (int i = 0; i < sgp.length; i++)
/*      */     {
/*  853 */       pr[i] = getPickResult(sgp[i], pickShape);
/*  854 */       int numIntersection = pr[i].numIntersections();
/*  855 */       if (numIntersection > 0)
/*      */       {
/*  857 */         found[i] = true;
/*      */
/*  862 */         boolean needToSwap = false;
/*  863 */         double minDist = pr[i].getIntersection(0).getDistance();
/*  864 */         int minIndex = 0;
/*  865 */         for (int j = 1; j < numIntersection; j++)
/*      */         {
/*  868 */           double tempDist = pr[i].getIntersection(j).getDistance();
/*  869 */           if (minDist > tempDist) {
/*  870 */             minDist = tempDist;
/*  871 */             minIndex = j;
/*  872 */             needToSwap = true;
/*      */           }
/*      */
/*      */         }
/*      */
/*  877 */         if (needToSwap)
/*      */         {
/*  879 */           PickIntersection pi0 = pr[i].getIntersection(0);
/*  880 */           PickIntersection piMin = pr[i].getIntersection(minIndex);
/*  881 */           pr[i].intersections.set(0, piMin);
/*  882 */           pr[i].intersections.set(minIndex, pi0);
/*      */         }
/*      */
/*  885 */         distArr[i] = pr[i].getIntersection(0).getDistance();
/*  886 */         cnt++;
/*      */       }
/*      */
/*      */     }
/*      */
/*  895 */     if (cnt == 0) return null;
/*      */
/*  897 */     PickResult[] npr = new PickResult[cnt];
/*  898 */     double[] distance = new double[cnt];
/*  899 */     cnt = 0;
/*  900 */     for (i = 0; i < sgp.length; i++) {
/*  901 */       if (found[i] == 1) {
/*  902 */         distance[cnt] = distArr[i];
/*  903 */         npr[(cnt++)] = pr[i];
/*      */       }
/*      */     }
/*      */
/*  907 */     if (cnt > 1) {
/*  908 */       return sortPickResults(npr, distance);
/*      */     }
/*  910 */     return npr;
/*      */   }
/*      */
/*      */   private PickResult pickGeomClosestIntersect(PickShape pickShape)
/*      */   {
/*  915 */     PickResult[] pr = pickGeomAllSortedIntersect(pickShape);
/*      */
/*  924 */     if (pr == null) {
/*  925 */       return null;
/*      */     }
/*  927 */     for (int i = 1; i < pr.length; i++) {
/*  928 */       freePickResult(pr[i]);
/*      */     }
/*  930 */     return pr[0];
/*      */   }
/*      */
/*      */   private PickResult pickGeomAnyIntersect(PickShape pickShape) {
/*  934 */     Node obj = null;
/*      */
/*  936 */     SceneGraphPath[] sgpa = null;
/*      */
/*  938 */     if (this.pickRootBG != null)
/*  939 */       sgpa = this.pickRootBG.pickAll(pickShape);
/*  940 */     else if (this.pickRootL != null) {
/*  941 */       sgpa = this.pickRootL.pickAll(pickShape);
/*      */     }
/*  943 */     if (sgpa == null) return null;
/*  944 */     for (int i = 0; i < sgpa.length; i++) {
/*  945 */       PickResult pr = new PickResult(sgpa[i], pickShape);
/*  946 */       pr.setFirstIntersectOnly(true);
/*  947 */       if (pr.numIntersections() > 0) {
/*  948 */         return pr;
/*      */       }
/*      */     }
/*      */
/*  952 */     return null;
/*      */   }
/*      */
/*      */   private PickResult[] sortPickResults(PickResult[] pr, double[] dist)
/*      */   {
/*  959 */     int[] pos = new int[pr.length];
/*  960 */     PickResult[] prsorted = new PickResult[pr.length];
/*      */
/*  963 */     for (int i = 0; i < pr.length; i++) {
/*  964 */       pos[i] = i;
/*      */     }
/*      */
/*  967 */     quicksort(0, dist.length - 1, dist, pos);
/*      */
/*  970 */     for (int i = 0; i < pr.length; i++) {
/*  971 */       prsorted[i] = pr[pos[i]];
/*      */     }
/*  973 */     return prsorted;
/*      */   }
/*      */
/*      */   private final void quicksort(int l, int r, double[] dist, int[] pos)
/*      */   {
/*  981 */     int i = l;
/*  982 */     int j = r;
/*  983 */     double k = dist[((l + r) / 2)];
/*      */     do {
/*  985 */       while (dist[i] < k) i++;
/*  986 */       while (k < dist[j]) j--;
/*  987 */       if (i <= j) {
/*  988 */         double tmp = dist[i];
/*  989 */         dist[i] = dist[j];
/*  990 */         dist[j] = tmp;
/*      */
/*  992 */         int p = pos[i];
/*  993 */         pos[i] = pos[j];
/*  994 */         pos[j] = p;
/*  995 */         i++;
/*  996 */         j--;
/*      */       }
/*      */     }
/*  998 */     while (i <= j);
/*      */
/* 1000 */     if (l < j) quicksort(l, j, dist, pos);
/* 1001 */     if (l < r) quicksort(i, r, dist, pos);
/*      */   }
/*      */
/*      */   PickResult getPickResult(SceneGraphPath spg, PickShape ps)
/*      */   {
/* 1005 */     PickResult pr = (PickResult)UtilFreelistManager.pickResultFreelist.getObject();
/* 1006 */     if (pr == null) {
/* 1007 */       pr = new PickResult();
/*      */     }
/* 1009 */     pr.reset(spg, ps);
/* 1010 */     return pr;
/*      */   }
/*      */
/*      */   void freePickResult(PickResult pr) {
/* 1014 */     UtilFreelistManager.pickResultFreelist.add(pr);
/*      */   }
/*      */ }

/* Location:           Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name:     com.sun.j3d.utils.picking.PickTool
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of com.sun.j3d.utils.picking.PickTool

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.