/** * Gets the parameters from this PickSegment. * * @param start the Point3d object into which the start point will be copied. * @param end the Point3d object into which the end point will be copied. */ public void get(Point3d start, Point3d end) { start.x = this.start.x; start.y = this.start.y; start.z = this.start.z; end.x = this.end.x; end.y = this.end.y; end.z = this.end.z; }
private Point3d getEffectiveCoordinates(IAtomContainer atomContainer, int[] atomIndices) { Point3d ret = new Point3d(0, 0, 0); for (int i : atomIndices) { Point3d coord = atomContainer.getAtom(i).getPoint3d(); ret.x += coord.x; ret.y += coord.y; ret.z += coord.z; } ret.x /= atomIndices.length; ret.y /= atomIndices.length; ret.z /= atomIndices.length; return ret; }
private Point3d getEffectiveCoordinates(IAtomContainer atomContainer, List<Integer> atomIndices) { Point3d ret = new Point3d(0, 0, 0); for (Object atomIndice : atomIndices) { int atomIndex = (Integer) atomIndice; Point3d coord = atomContainer.getAtom(atomIndex).getPoint3d(); ret.x += coord.x; ret.y += coord.y; ret.z += coord.z; } ret.x /= atomIndices.size(); ret.y /= atomIndices.size(); ret.z /= atomIndices.size(); return ret; }
public Point3d calcCenterOfRotation() { List<Integer> line = getLongestLayerLine(); // can't determine center of rotation if there are only 2 points // TODO does this ever happen?? if (line.size() < 3) { return subunits.getCentroid(); } Point3d centerOfRotation = new Point3d(); List<Point3d> centers = subunits.getOriginalCenters(); // calculate helix mid points for each set of 3 adjacent subunits for (int i = 0; i < line.size() - 2; i++) { Point3d p1 = new Point3d(centers.get(line.get(i))); Point3d p2 = new Point3d(centers.get(line.get(i + 1))); Point3d p3 = new Point3d(centers.get(line.get(i + 2))); transformationMatrix.transform(p1); transformationMatrix.transform(p2); transformationMatrix.transform(p3); centerOfRotation.add(getMidPoint(p1, p2, p3)); } // average over all midpoints to find best center of rotation centerOfRotation.scale(1 / (line.size() - 2)); // since helix is aligned along the y-axis, with an origin at y = 0, place the center of // rotation there centerOfRotation.y = 0; // transform center of rotation to the original coordinate frame reverseTransformationMatrix.transform(centerOfRotation); // System.out.println("center of rotation: " + centerOfRotation); return centerOfRotation; }
@Override void update() { int newEditId; if ((newEditId = volume.update()) != volumeEditId) { for (int i = 0; i < 6; i++) { boxLine[i].setCoordinates(0, volume.facePoints[i], 0, 4); boxLine[i].setCoordinate(4, volume.facePoints[i][0]); imageQuad[i].setCoordinates(0, volume.facePoints[i], 0, 4); } faceCenter[PLUS_X].set(volume.maxCoord.x, 0.0, 0.0); faceCenter[PLUS_Y].set(0.0, volume.maxCoord.y, 0.0); faceCenter[PLUS_Z].set(0.0, 0.0, volume.maxCoord.z); faceCenter[MINUS_X].set(volume.minCoord.x, 0.0, 0.0); faceCenter[MINUS_Y].set(0.0, volume.minCoord.y, 0.0); faceCenter[MINUS_Z].set(0.0, 0.0, volume.minCoord.z); volCenter.x = (volume.maxCoord.x + volume.minCoord.x) / 2; volCenter.y = (volume.maxCoord.y + volume.minCoord.y) / 2; volCenter.z = (volume.maxCoord.z + volume.minCoord.z) / 2; volumeEditId = newEditId; } eyePtChanged(); for (int i = 0; i < 6; i++) { if (boxAttr[i].getValue() == true) { boxSwitch[i].setWhichChild(Switch.CHILD_ALL); } else { boxSwitch[i].setWhichChild(Switch.CHILD_NONE); } String curImageFile = imageAttr[i].getValue(); if (curImageFile != imageFile[i]) { imageFile[i] = curImageFile; if (imageFile[i].length() > 0) { try { URL imageURL = new URL(context.getCodeBase().toString() + imageFile[i]); imageTexture[i] = new TextureLoader(imageURL, null).getTexture(); } catch (Exception e) { System.err.println("Error " + e + " loading image:" + imageFile[i] + "."); } } imageAppearance[i].setTexture(imageTexture[i]); if (imageTexture[i] != null) { imageSwitch[i].setWhichChild(Switch.CHILD_ALL); } else { imageSwitch[i].setWhichChild(Switch.CHILD_NONE); } } } }
public static void transformMesh(final TopLoc_Location loc, double[] src, float[] dst) { double[] matrix = new double[16]; loc.transformation().getValues(matrix); Matrix4d m4d = new Matrix4d(matrix); Point3d p3d = new Point3d(); for (int i = 0; i < src.length; i += 3) { p3d.x = src[i + 0]; p3d.y = src[i + 1]; p3d.z = src[i + 2]; m4d.transform(p3d); dst[i + 0] = (float) p3d.x; dst[i + 1] = (float) p3d.y; dst[i + 2] = (float) p3d.z; } }
// Note we set teh locations values up, but process does the work, in case teh world changes // without us moving (a door opens) public void locationUpdated(Quat4f rot, Vector3f trans) { // only update if new things have happened if (!prevRot.epsilonEquals(rot, 0.0001f) || !prevTrans.epsilonEquals(trans, 0.005f)) { // set head point currentAvartarHeadPoint.set(trans); currentAvartarHeadPoint.y += avatarCollisionInfo.getCameraAbovePelvisHeight(); tempRotTransform.set(rot); currentCameraMaxVector.set(0, 0, 1); // use a normal tempRotTransform.transform(currentCameraMaxVector); // set max camera vector currentCameraMaxVector.scale(TRAIL_MAX_DIST); // recall for next iter prevRot.set(rot); prevTrans.set(trans); } }
// called on the parent object // Should be synchronized so that the user thread does not modify the // OrientedShape3D params while computing the transform synchronized void updateOrientedTransform(Canvas3D canvas, int viewIndex) { double angle = 0.0; double sign; boolean status; Transform3D orientedxform = getOrientedTransform(viewIndex); // get viewplatforms's location in virutal world if (mode == OrientedShape3D.ROTATE_ABOUT_AXIS) { // rotate about axis canvas.getCenterEyeInImagePlate(viewPosition); canvas.getImagePlateToVworld(xform); // xform is imagePlateToLocal xform.transform(viewPosition); // get billboard's transform xform.set(getCurrentLocalToVworld()); xform.invert(); // xform is now vWorldToLocal // transform the eye position into the billboard's coordinate system xform.transform(viewPosition); // eyeVec is a vector from the local origin to the eye pt in local eyeVec.set(viewPosition); eyeVec.normalize(); // project the eye into the rotation plane status = projectToPlane(eyeVec, nAxis); if (status) { // project the z axis into the rotation plane zAxis.x = 0.0; zAxis.y = 0.0; zAxis.z = 1.0; status = projectToPlane(zAxis, nAxis); } if (status) { // compute the sign of the angle by checking if the cross product // of the two vectors is in the same direction as the normal axis vector.cross(eyeVec, zAxis); if (vector.dot(nAxis) > 0.0) { sign = 1.0; } else { sign = -1.0; } // compute the angle between the projected eye vector and the // projected z double dot = eyeVec.dot(zAxis); if (dot > 1.0f) { dot = 1.0f; } else if (dot < -1.0f) { dot = -1.0f; } angle = sign * Math.acos(dot); // use -angle because xform is to *undo* rotation by angle aa.x = nAxis.x; aa.y = nAxis.y; aa.z = nAxis.z; aa.angle = -angle; orientedxform.set(aa); } else { orientedxform.setIdentity(); } } else if (mode == OrientedShape3D.ROTATE_ABOUT_POINT) { // rotate about point // Need to rotate Z axis to point to eye, and Y axis to be // parallel to view platform Y axis, rotating around rotation pt // get the eye point canvas.getCenterEyeInImagePlate(viewPosition); // derive the yUp point yUpPoint.set(viewPosition); yUpPoint.y += 0.01; // one cm in Physical space // transform the points to the Billboard's space canvas.getImagePlateToVworld(xform); // xform is ImagePlateToVworld xform.transform(viewPosition); xform.transform(yUpPoint); // get billboard's transform xform.set(getCurrentLocalToVworld()); xform.invert(); // xform is vWorldToLocal // transfom points to local coord sys xform.transform(viewPosition); xform.transform(yUpPoint); // Make a vector from viewPostion to 0,0,0 in the BB coord sys eyeVec.set(viewPosition); eyeVec.normalize(); // create a yUp vector yUp.set(yUpPoint); yUp.sub(viewPosition); yUp.normalize(); // find the plane to rotate z zAxis.x = 0.0; zAxis.y = 0.0; zAxis.z = 1.0; // rotation axis is cross product of eyeVec and zAxis vector.cross(eyeVec, zAxis); // vector is cross product // if cross product is non-zero, vector is rotation axis and // rotation angle is acos(eyeVec.dot(zAxis))); double length = vector.length(); if (length > 0.0001) { double dot = eyeVec.dot(zAxis); if (dot > 1.0f) { dot = 1.0f; } else if (dot < -1.0f) { dot = -1.0f; } angle = Math.acos(dot); aa.x = vector.x; aa.y = vector.y; aa.z = vector.z; aa.angle = -angle; zRotate.set(aa); } else { // no rotation needed, set to identity (scale = 1.0) zRotate.set(1.0); } // Transform the yAxis by zRotate yAxis.x = 0.0; yAxis.y = 1.0; yAxis.z = 0.0; zRotate.transform(yAxis); // project the yAxis onto the plane perp to the eyeVec status = projectToPlane(yAxis, eyeVec); if (status) { // project the yUp onto the plane perp to the eyeVec status = projectToPlane(yUp, eyeVec); } if (status) { // rotation angle is acos(yUp.dot(yAxis)); double dot = yUp.dot(yAxis); // Fix numerical error, otherwise acos return NULL if (dot > 1.0f) { dot = 1.0f; } else if (dot < -1.0f) { dot = -1.0f; } angle = Math.acos(dot); // check the sign by looking a the cross product vs the eyeVec vector.cross(yUp, yAxis); // vector is cross product if (eyeVec.dot(vector) < 0) { angle *= -1; } aa.x = eyeVec.x; aa.y = eyeVec.y; aa.z = eyeVec.z; aa.angle = -angle; xform.set(aa); // xform is now yRotate // rotate around the rotation point vector.x = rotationPoint.x; vector.y = rotationPoint.y; vector.z = rotationPoint.z; // vector to translate to RP orientedxform.set(vector); // translate to RP orientedxform.mul(xform); // yRotate orientedxform.mul(zRotate); // zRotate vector.scale(-1.0); // vector to translate back xform.set(vector); // xform to translate back orientedxform.mul(xform); // translate back } else { orientedxform.setIdentity(); } } // Scale invariant computation if (constantScale) { // Back Xform a unit vector to local world coords canvas.getInverseVworldProjection(left_xform, right_xform); // the two endpts of the vector have to be transformed // individually because the Xform is not affine im_vec[0].set(0.0, 0.0, 0.0, 1.0); im_vec[1].set(1.0, 0.0, 0.0, 1.0); left_xform.transform(im_vec[0]); left_xform.transform(im_vec[1]); left_xform.set(getCurrentLocalToVworld()); left_xform.invert(); left_xform.transform(im_vec[0]); left_xform.transform(im_vec[1]); lvec.set(im_vec[1]); lvec.sub(im_vec[0]); // We simply need the direction of this vector lvec.normalize(); im_vec[0].set(0.0, 0.0, 0.0, 1.0); im_vec[1].set(lvec); im_vec[1].w = 1.0; // Forward Xfrom to clip coords left_xform.set(getCurrentLocalToVworld()); left_xform.transform(im_vec[0]); left_xform.transform(im_vec[1]); canvas.getVworldProjection(left_xform, right_xform); left_xform.transform(im_vec[0]); left_xform.transform(im_vec[1]); // Perspective division im_vec[0].x /= im_vec[0].w; im_vec[0].y /= im_vec[0].w; im_vec[0].z /= im_vec[0].w; im_vec[1].x /= im_vec[1].w; im_vec[1].y /= im_vec[1].w; im_vec[1].z /= im_vec[1].w; lvec.set(im_vec[1]); lvec.sub(im_vec[0]); // Use the length of this vector to determine the scaling // factor double scale = 1 / lvec.length(); // Convert to meters scale *= scaleFactor * canvas.getPhysicalWidth() / 2; // Scale object so that it appears the same size scaleXform.setScale(scale); orientedxform.mul(scaleXform); } }
/** * Places the value of the "home" center around which the View rotates into the Point3d. The * default center is (0, 0, 0). * * @param homeCenter The Point3d * @since Version 1.1 */ public void getHomeRotationCenter(Point3d homeCenter) { homeCenter.x = homeRotCenter.x; homeCenter.y = homeRotCenter.y; homeCenter.z = homeRotCenter.z; }
/** * Procedure required by the CDOInterface. This function is only supposed to be called by the JCFL * library */ public void setObjectProperty(String objectType, String propertyType, String propertyValue) { logger.debug("objectType: " + objectType); logger.debug("propType: " + propertyType); logger.debug("property: " + propertyValue); if (objectType == null) { logger.error("Cannot add property for null object"); return; } if (propertyType == null) { logger.error("Cannot add property for null property type"); return; } if (propertyValue == null) { logger.warn("Will not add null property"); return; } if (objectType.equals("Molecule")) { if (propertyType.equals("id")) { currentMolecule.setID(propertyValue); } else if (propertyType.equals("inchi")) { currentMolecule.setProperty("iupac.nist.chemical.identifier", propertyValue); } } else if (objectType.equals("PseudoAtom")) { if (propertyType.equals("label")) { if (!(currentAtom instanceof IPseudoAtom)) { currentAtom = builder.newPseudoAtom(currentAtom); } ((IPseudoAtom) currentAtom).setLabel(propertyValue); } } else if (objectType.equals("Atom")) { if (propertyType.equals("type")) { if (propertyValue.equals("R") && !(currentAtom instanceof IPseudoAtom)) { currentAtom = builder.newPseudoAtom(currentAtom); } currentAtom.setSymbol(propertyValue); } else if (propertyType.equals("x2")) { Point2d coord = currentAtom.getPoint2d(); if (coord == null) coord = new Point2d(); coord.x = Double.parseDouble(propertyValue); currentAtom.setPoint2d(coord); } else if (propertyType.equals("y2")) { Point2d coord = currentAtom.getPoint2d(); if (coord == null) coord = new Point2d(); coord.y = Double.parseDouble(propertyValue); currentAtom.setPoint2d(coord); } else if (propertyType.equals("x3")) { Point3d coord = currentAtom.getPoint3d(); if (coord == null) coord = new Point3d(); coord.x = Double.parseDouble(propertyValue); currentAtom.setPoint3d(coord); } else if (propertyType.equals("y3")) { Point3d coord = currentAtom.getPoint3d(); if (coord == null) coord = new Point3d(); coord.y = Double.parseDouble(propertyValue); currentAtom.setPoint3d(coord); } else if (propertyType.equals("z3")) { Point3d coord = currentAtom.getPoint3d(); if (coord == null) coord = new Point3d(); coord.z = Double.parseDouble(propertyValue); currentAtom.setPoint3d(coord); } else if (propertyType.equals("xFract")) { Point3d coord = currentAtom.getFractionalPoint3d(); if (coord == null) coord = new Point3d(); coord.x = Double.parseDouble(propertyValue); currentAtom.setFractionalPoint3d(coord); } else if (propertyType.equals("yFract")) { Point3d coord = currentAtom.getFractionalPoint3d(); if (coord == null) coord = new Point3d(); coord.y = Double.parseDouble(propertyValue); currentAtom.setFractionalPoint3d(coord); } else if (propertyType.equals("zFract")) { Point3d coord = currentAtom.getFractionalPoint3d(); if (coord == null) coord = new Point3d(); coord.z = Double.parseDouble(propertyValue); currentAtom.setFractionalPoint3d(coord); } else if (propertyType.equals("formalCharge")) { currentAtom.setFormalCharge(Integer.parseInt(propertyValue)); } else if (propertyType.equals("charge") || propertyType.equals("partialCharge")) { currentAtom.setCharge(Double.parseDouble(propertyValue)); } else if (propertyType.equals("hydrogenCount")) { currentAtom.setHydrogenCount(Integer.parseInt(propertyValue)); } else if (propertyType.equals("dictRef")) { currentAtom.setProperty("org.openscience.cdk.dict", propertyValue); } else if (propertyType.equals("atomicNumber")) { currentAtom.setAtomicNumber(Integer.parseInt(propertyValue)); } else if (propertyType.equals("massNumber")) { currentAtom.setMassNumber((int) Double.parseDouble(propertyValue)); } else if (propertyType.equals("id")) { logger.debug("id: ", propertyValue); currentAtom.setID(propertyValue); atomEnumeration.put(propertyValue, numberOfAtoms); } } else if (objectType.equals("Bond")) { if (propertyType.equals("atom1")) { bond_a1 = Integer.parseInt(propertyValue); } else if (propertyType.equals("atom2")) { bond_a2 = Integer.parseInt(propertyValue); } else if (propertyType.equals("id")) { logger.debug("id: " + propertyValue); bond_id = propertyValue; } else if (propertyType.equals("order")) { try { Double order = Double.parseDouble(propertyValue); if (order == 1.0) { bond_order = IBond.Order.SINGLE; } else if (order == 2.0) { bond_order = IBond.Order.DOUBLE; } else if (order == 3.0) { bond_order = IBond.Order.TRIPLE; } else if (order == 4.0) { bond_order = IBond.Order.QUADRUPLE; } else { bond_order = IBond.Order.SINGLE; } } catch (Exception e) { logger.error("Cannot convert to double: " + propertyValue); bond_order = IBond.Order.SINGLE; } } else if (propertyType.equals("stereo")) { if (propertyValue.equals("H")) { bond_stereo = CDKConstants.STEREO_BOND_DOWN; } else if (propertyValue.equals("W")) { bond_stereo = CDKConstants.STEREO_BOND_UP; } } } logger.debug("Object property set..."); }
@Override boolean intersect( PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, GeometryRetained geom, int geomIndex) { Point3d pnts[] = new Point3d[4]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; int[] vtxIndexArr = new int[4]; int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? initialVertexIndex : initialCoordIndex); pnts[0] = new Point3d(); pnts[1] = new Point3d(); pnts[2] = new Point3d(); pnts[3] = new Point3d(); switch (pickShape.getPickType()) { case PickShape.PICKRAY: PickRay pickRay = (PickRay) pickShape; while (i < validVertexCount) { for (int j = 0; j < 4; j++) { vtxIndexArr[j] = i; getVertexData(i++, pnts[j]); } if (intersectRay(pnts, pickRay, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; x = iPnt.x; y = iPnt.y; z = iPnt.z; if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } if ((flags & PickInfo.ALL_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } } break; case PickShape.PICKSEGMENT: PickSegment pickSegment = (PickSegment) pickShape; while (i < validVertexCount) { for (int j = 0; j < 4; j++) { vtxIndexArr[j] = i; getVertexData(i++, pnts[j]); } if (intersectSegment(pnts, pickSegment.start, pickSegment.end, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; x = iPnt.x; y = iPnt.y; z = iPnt.z; if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } if ((flags & PickInfo.ALL_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } } break; case PickShape.PICKBOUNDINGBOX: BoundingBox bbox = (BoundingBox) ((PickBounds) pickShape).bounds; while (i < validVertexCount) { for (int j = 0; j < 4; j++) { vtxIndexArr[j] = i; getVertexData(i++, pnts[j]); } if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; x = iPnt.x; y = iPnt.y; z = iPnt.z; if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } if ((flags & PickInfo.ALL_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } } break; case PickShape.PICKBOUNDINGSPHERE: BoundingSphere bsphere = (BoundingSphere) ((PickBounds) pickShape).bounds; while (i < validVertexCount) { for (int j = 0; j < 4; j++) { vtxIndexArr[j] = i; getVertexData(i++, pnts[j]); } if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; x = iPnt.x; y = iPnt.y; z = iPnt.z; if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } if ((flags & PickInfo.ALL_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } } break; case PickShape.PICKBOUNDINGPOLYTOPE: BoundingPolytope bpolytope = (BoundingPolytope) ((PickBounds) pickShape).bounds; while (i < validVertexCount) { for (int j = 0; j < 4; j++) { vtxIndexArr[j] = i; getVertexData(i++, pnts[j]); } if (intersectBoundingPolytope(pnts, bpolytope, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; x = iPnt.x; y = iPnt.y; z = iPnt.z; if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } if ((flags & PickInfo.ALL_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } } break; case PickShape.PICKCYLINDER: PickCylinder pickCylinder = (PickCylinder) pickShape; while (i < validVertexCount) { for (int j = 0; j < 4; j++) { vtxIndexArr[j] = i; getVertexData(i++, pnts[j]); } if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; x = iPnt.x; y = iPnt.y; z = iPnt.z; if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } if ((flags & PickInfo.ALL_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } } break; case PickShape.PICKCONE: PickCone pickCone = (PickCone) pickShape; while (i < validVertexCount) { for (int j = 0; j < 4; j++) { vtxIndexArr[j] = i; getVertexData(i++, pnts[j]); } if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; x = iPnt.x; y = iPnt.y; z = iPnt.z; if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } if ((flags & PickInfo.ALL_GEOM_INFO) != 0) { storeInterestData(pickInfo, flags, geom, geomIndex, vtxIndexArr, iPnt, sdist[0]); } } } break; case PickShape.PICKPOINT: // Should not happen since API already check for this throw new IllegalArgumentException(J3dI18N.getString("QuadArrayRetained0")); default: throw new RuntimeException("PickShape not supported for intersection "); } if (minDist < Double.MAX_VALUE) { iPnt.x = x; iPnt.y = y; iPnt.z = z; return true; } return false; }
public Annotations(View view, Context context, Volume vol) { super(view, context, vol); viewPtAttr = (CoordAttr) context.getAttr("Vol Ref Pt"); perspectiveAttr = (ToggleAttr) context.getAttr("Perspective"); boxAttr[PLUS_X] = (ToggleAttr) context.getAttr("Plus X Box"); boxAttr[PLUS_Y] = (ToggleAttr) context.getAttr("Plus Y Box"); boxAttr[PLUS_Z] = (ToggleAttr) context.getAttr("Plus Z Box"); boxAttr[MINUS_X] = (ToggleAttr) context.getAttr("Minus X Box"); boxAttr[MINUS_Y] = (ToggleAttr) context.getAttr("Minus Y Box"); boxAttr[MINUS_Z] = (ToggleAttr) context.getAttr("Minus Z Box"); imageAttr[PLUS_X] = (StringAttr) context.getAttr("Plus X Image"); imageAttr[PLUS_Y] = (StringAttr) context.getAttr("Plus Y Image"); imageAttr[PLUS_Z] = (StringAttr) context.getAttr("Plus Z Image"); imageAttr[MINUS_X] = (StringAttr) context.getAttr("Minus X Image"); imageAttr[MINUS_Y] = (StringAttr) context.getAttr("Minus Y Image"); imageAttr[MINUS_Z] = (StringAttr) context.getAttr("Minus Z Image"); volume = vol; frontRoot = new BranchGroup(); frontRoot.setCapability(BranchGroup.ALLOW_DETACH); frontRoot.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ); backRoot = new BranchGroup(); backRoot.setCapability(BranchGroup.ALLOW_DETACH); backRoot.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ); int stripLength[] = new int[1]; stripLength[0] = 5; ColoringAttributes ca = new ColoringAttributes(1.0f, 0.0f, 0.0f, ColoringAttributes.SHADE_FLAT); Appearance boxAppearance = new Appearance(); boxAppearance.setColoringAttributes(ca); TexCoord2f[] texCoords = new TexCoord2f[4]; texCoords[0] = new TexCoord2f(0.0f, 0.0f); texCoords[1] = new TexCoord2f(1.0f, 0.0f); texCoords[2] = new TexCoord2f(1.0f, 1.0f); texCoords[3] = new TexCoord2f(0.0f, 1.0f); TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.0f); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(PolygonAttributes.CULL_NONE); RenderingAttributes ra = new RenderingAttributes(); ra.setDepthBufferEnable(false); for (int i = 0; i < 6; i++) { faceGroup[i] = new SharedGroup(); frontAnnotations.addChild(new Link(faceGroup[i])); backAnnotations.addChild(new Link(faceGroup[i])); boxLine[i] = new LineStripArray(5, GeometryArray.COORDINATES, stripLength); boxLine[i].setCoordinates(0, volume.facePoints[i], 0, 4); boxLine[i].setCoordinate(4, volume.facePoints[i][0]); boxLine[i].setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); Shape3D box = new Shape3D(boxLine[i], boxAppearance); boxSwitch[i] = new Switch(); boxSwitch[i].setCapability(Switch.ALLOW_SWITCH_WRITE); boxSwitch[i].addChild(box); if (boxAttr[i].getValue() == true) { boxSwitch[i].setWhichChild(Switch.CHILD_ALL); } else { boxSwitch[i].setWhichChild(Switch.CHILD_NONE); } faceGroup[i].addChild(boxSwitch[i]); imageQuad[i] = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2); imageQuad[i].setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); imageQuad[i].setCoordinates(0, volume.facePoints[i], 0, 4); imageQuad[i].setTextureCoordinates(0, 0, texCoords, 0, 4); imageAppearance[i] = new Appearance(); imageAppearance[i].setTransparencyAttributes(ta); imageAppearance[i].setPolygonAttributes(pa); imageAppearance[i].setRenderingAttributes(ra); imageAppearance[i].setTextureAttributes(texAttr); imageAppearance[i].setCapability(Appearance.ALLOW_TEXTURE_WRITE); imageSwitch[i] = new Switch(); imageSwitch[i].setCapability(Switch.ALLOW_SWITCH_WRITE); imageFile[i] = imageAttr[i].getValue(); if (imageFile[i].length() > 0) { try { URL imageURL = new URL(context.getCodeBase().toString() + imageFile[i]); imageTexture[i] = new TextureLoader(imageURL, null).getTexture(); } catch (Exception e) { System.err.println("Error " + e + " loading image:" + imageFile[i] + "."); } } imageAppearance[i].setTexture(imageTexture[i]); if (imageTexture[i] != null) { imageSwitch[i].setWhichChild(Switch.CHILD_ALL); } else { imageSwitch[i].setWhichChild(Switch.CHILD_NONE); } Shape3D imageShape = new Shape3D(imageQuad[i], imageAppearance[i]); imageSwitch[i].addChild(imageShape); faceGroup[i].addChild(imageSwitch[i]); } frontAnnotations.setCapability(Switch.ALLOW_SWITCH_WRITE); backAnnotations.setCapability(Switch.ALLOW_SWITCH_WRITE); faceNormal[PLUS_X] = new Vector3d(1.0, 0.0, 0.0); faceCenter[PLUS_X] = new Point3d(volume.maxCoord.x, 0.0, 0.0); faceNormal[PLUS_Y] = new Vector3d(0.0, 1.0, 0.0); faceCenter[PLUS_Y] = new Point3d(0.0, volume.maxCoord.y, 0.0); faceNormal[PLUS_Z] = new Vector3d(0.0, 0.0, 1.0); faceCenter[PLUS_Z] = new Point3d(0.0, 0.0, volume.maxCoord.z); faceNormal[MINUS_X] = new Vector3d(-1.0, 0.0, 0.0); faceCenter[MINUS_X] = new Point3d(volume.minCoord.x, 0.0, 0.0); faceNormal[MINUS_Y] = new Vector3d(0.0, -1.0, 0.0); faceCenter[MINUS_Y] = new Point3d(0.0, volume.minCoord.y, 0.0); faceNormal[MINUS_Z] = new Vector3d(0.0, 0.0, -1.0); faceCenter[MINUS_Z] = new Point3d(0.0, 0.0, volume.minCoord.z); volCenter.x = (volume.maxCoord.x + volume.minCoord.x) / 2; volCenter.y = (volume.maxCoord.y + volume.minCoord.y) / 2; volCenter.z = (volume.maxCoord.z + volume.minCoord.z) / 2; frontRoot.addChild(frontAnnotations); backRoot.addChild(backAnnotations); }