📄 canvasviewcache.java
字号:
* be cached - used by Canavs3D.getInverseVworldProjection(). */ private void computeFrustumPlanes(Transform3D ecToCc, Transform3D vpcToEc, Vector4d [] frustumPlanes, Point4d [] frustumPoints, Transform3D ccToVworld) { // Compute the inverse of the Vworld to Cc transform. This // gives us the Cc to Vworld transform. tMat2.mul(ecToCc, vpcToEc); ccToVworld.mul(tMat2, vworldToVpc); // System.err.println("ccToVworld = " + ccToVworld); try { ccToVworld.invert(); } catch (SingularMatrixException e) { ccToVworld.setIdentity(); // System.err.println("SingularMatrixException encountered when doing invert in computeFrustumPlanes"); } if((J3dDebug.devPhase) && (J3dDebug.canvasViewCache >= J3dDebug.LEVEL_2)) { Transform3D t = new Transform3D(); t.mul(ecToCc, vpcToEc); t.mul(vworldToVpc); System.err.println("\nvworldToCc = " + t); System.err.println("ccToVworld = " + ccToVworld); t.mul(ccToVworld); System.err.println("vworldToCc * ccToVworld = " + t); } // Transform the 8 corners of the viewing frustum into Vpc frustumPoints[0].set(-1.0, -1.0, 1.0, 1.0); // lower-left-front frustumPoints[1].set(-1.0, 1.0, 1.0, 1.0); // upper-left-front frustumPoints[2].set( 1.0, 1.0, 1.0, 1.0); // upper-right-front frustumPoints[3].set( 1.0, -1.0, 1.0, 1.0); // lower-right-front frustumPoints[4].set(-1.0, -1.0, -1.0, 1.0); // lower-left-back frustumPoints[5].set(-1.0, 1.0, -1.0, 1.0); // upper-left-back frustumPoints[6].set( 1.0, 1.0, -1.0, 1.0); // upper-right-back frustumPoints[7].set( 1.0, -1.0, -1.0, 1.0); // lower-right-back ccToVworld.get(tMatrix); int i; for (i = 0; i < frustumPoints.length; i++) { tMatrix.transform(frustumPoints[i]); double w_inv = 1.0 / frustumPoints[i].w; frustumPoints[i].x *= w_inv; frustumPoints[i].y *= w_inv; frustumPoints[i].z *= w_inv; } // Now compute the 6 plane equations // left computePlaneEq(frustumPoints[0], frustumPoints[4], frustumPoints[5], frustumPoints[1], frustumPlanes[0]); // right computePlaneEq(frustumPoints[3], frustumPoints[2], frustumPoints[6], frustumPoints[7], frustumPlanes[1]); // top computePlaneEq(frustumPoints[1], frustumPoints[5], frustumPoints[6], frustumPoints[2], frustumPlanes[2]); // bottom computePlaneEq(frustumPoints[0], frustumPoints[3], frustumPoints[7], frustumPoints[4], frustumPlanes[3]); // front computePlaneEq(frustumPoints[0], frustumPoints[1], frustumPoints[2], frustumPoints[3], frustumPlanes[4]); // back computePlaneEq(frustumPoints[4], frustumPoints[7], frustumPoints[6], frustumPoints[5], frustumPlanes[5]); //System.err.println("left plane = " + frustumPlanes[0]); //System.err.println("right plane = " + frustumPlanes[1]); //System.err.println("top plane = " + frustumPlanes[2]); //System.err.println("bottom plane = " + frustumPlanes[3]); //System.err.println("front plane = " + frustumPlanes[4]); //System.err.println("back plane = " + frustumPlanes[5]); } private void computePlaneEq(Point4d p1, Point4d p2, Point4d p3, Point4d p4, Vector4d planeEq) { tVec1.x = p3.x - p1.x; tVec1.y = p3.y - p1.y; tVec1.z = p3.z - p1.z; tVec2.x = p2.x - p1.x; tVec2.y = p2.y - p1.y; tVec2.z = p2.z - p1.z; tVec3.cross(tVec2, tVec1); tVec3.normalize(); planeEq.x = tVec3.x; planeEq.y = tVec3.y; planeEq.z = tVec3.z; planeEq.w = -(planeEq.x * p1.x + planeEq.y * p1.y + planeEq.z * p1.z); } // Get methods for returning derived data values. // Eventually, these get functions will cause some of the parameters // to be lazily evaluated. // // NOTE: in the case of Transform3D, and Tuple objects, a reference // to the actual derived data is returned. In these cases, the caller // must ensure that the returned data is not modified. // // NOTE: the snapshot and computeDerivedData methods are synchronized. // Callers of the following methods that can run asynchronously with // the renderer must call these methods and copy the data from within // a synchronized block on the canvas view cache object. int getCanvasX() { return canvasX; } int getCanvasY() { return canvasY; } int getCanvasWidth() { return canvasWidth; } int getCanvasHeight() { return canvasHeight; } double getPhysicalWindowWidth() { return physicalWindowWidth; } double getPhysicalWindowHeight() { return physicalWindowHeight; } boolean getUseStereo() { return useStereo; } Transform3D getLeftProjection() { return leftProjection; } Transform3D getRightProjection() { return rightProjection; } Transform3D getLeftVpcToEc() { return leftVpcToEc; } Transform3D getRightVpcToEc() { return rightVpcToEc; } Transform3D getLeftEcToVpc() { return leftEcToVpc; } Transform3D getRightEcToVpc() { return rightEcToVpc; } Transform3D getInfLeftProjection() { return infLeftProjection; } Transform3D getInfRightProjection() { return infLeftProjection; } Transform3D getInfLeftVpcToEc() { return infLeftVpcToEc; } Transform3D getInfRightVpcToEc() { return infRightVpcToEc; } Transform3D getInfLeftEcToVpc() { return infLeftEcToVpc; } Transform3D getInfgRightEcToVpc() { return infRightEcToVpc; } Transform3D getInfVworldToVpc() { return infVworldToVpc; } Transform3D getLeftCcToVworld() { return leftCcToVworld; } Transform3D getRightCcToVworld() { return rightCcToVworld; } Transform3D getImagePlateToVworld() { // XXXX: Document -- This will return the transform of left plate. return leftPlateToVworld; } Transform3D getLastVworldToImagePlate() { // XXXX: Document -- This will return the transform of left plate. return lastVworldToLeftPlate; } Transform3D getVworldToImagePlate() { // XXXX: Document -- This will return the transform of left plate. return vworldToLeftPlate; } Transform3D getVworldToTrackerBase() { return vworldToTrackerBase; } double getVworldToCoexistenceScale() { return vworldToCoexistenceScale; } double getInfVworldToCoexistenceScale() { return infVworldToCoexistenceScale; } Point3d getLeftEyeInImagePlate() { return leftEyeInImagePlate; } Point3d getRightEyeInImagePlate() { return rightEyeInImagePlate; } Point3d getCenterEyeInImagePlate() { return centerEyeInImagePlate; } Transform3D getHeadToVworld() { return headToVworld; } Transform3D getVpcToVworld() { return vpcToVworld; } Transform3D getVworldToVpc() { return vworldToVpc; } // Transform the specified X point in AWT window-relative coordinates // to image plate coordinates double getWindowXInImagePlate(double x) { double xScreen = x + (double)canvasX; return metersPerPixelX * xScreen; } // Transform the specified Y point in AWT window-relative coordinates // to image plate coordinates double getWindowYInImagePlate(double y) { double yScreen = y + (double)canvasY; return metersPerPixelY * ((double)(screenHeight - 1) - yScreen); } Vector4d[] getLeftFrustumPlanesInVworld() { return leftFrustumPlanes; } Vector4d[] getRightFrustumPlanesInVworld() { return rightFrustumPlanes; } void getPixelLocationInImagePlate(double x, double y, double z, Point3d imagePlatePoint) { double screenx = (x + canvasX)*metersPerPixelX; double screeny = (screenHeight - 1 - canvasY - y)*metersPerPixelY; if ((viewCache.projectionPolicy == View.PERSPECTIVE_PROJECTION) && (centerEyeInImagePlate.z != 0)) { double zScale = 1.0 - z/centerEyeInImagePlate.z; imagePlatePoint.x = (screenx - centerEyeInImagePlate.x)*zScale + centerEyeInImagePlate.x; imagePlatePoint.y = (screeny - centerEyeInImagePlate.y)*zScale + centerEyeInImagePlate.y; } else { imagePlatePoint.x = screenx; imagePlatePoint.y = screeny; } imagePlatePoint.z = z; } /** * Projects the specified point from image plate coordinates * into AWT pixel coordinates. */ void getPixelLocationFromImagePlate(Point3d imagePlatePoint, Point2d pixelLocation) { double screenX, screenY; if(viewCache.projectionPolicy == View.PERSPECTIVE_PROJECTION) { // get the vector from centerEyeInImagePlate to imagePlatePoint tVec1.sub(imagePlatePoint, centerEyeInImagePlate); // Scale this vector to make it end at the projection plane. // Scale is ratio : // eye->imagePlate Plane dist / eye->imagePlatePt dist // eye dist to plane is eyePos.z (eye is in +z space) // image->eye dist is -tVec1.z (image->eye is in -z dir) //System.err.println("eye dist = " + (centerEyeInImagePlate.z)); //System.err.println("image dist = " + (-tVec1.z)); if (tVec1.z != 0) { double zScale = centerEyeInImagePlate.z / (-tVec1.z); screenX = centerEyeInImagePlate.x + tVec1.x * zScale; screenY = centerEyeInImagePlate.y + tVec1.y * zScale; } else { screenX = imagePlatePoint.x; screenY = imagePlatePoint.y; } } else { screenX = imagePlatePoint.x; screenY = imagePlatePoint.y; } //System.err.println("screenX = " + screenX + " screenY = " + screenY); // Note: screenPt is in image plate coords, at z=0 // Transform from image plate coords to screen coords pixelLocation.x = (screenX / screenViewCache.metersPerPixelX) - canvasX; pixelLocation.y = screenViewCache.screenHeight - 1 - (screenY / screenViewCache.metersPerPixelY) - canvasY; //System.err.println("pixelLocation = " + pixelLocation); } /** * Constructs and initializes a CanvasViewCache object. * Note that the canvas, screen, screenCache, view, and * viewCache parameters are all fixed at construction time * and must be non-null. */ CanvasViewCache(Canvas3D canvas, ScreenViewCache screenViewCache, ViewCache viewCache) { this.canvas = canvas; this.screenViewCache = screenViewCache; this.viewCache = viewCache; // Set up the initial plane equations int i; for (i = 0; i < leftFrustumPlanes.length; i++) { leftFrustumPlanes[i] = new Vector4d(); rightFrustumPlanes[i] = new Vector4d(); } for (i = 0; i < leftFrustumPoints.length; i++) { leftFrustumPoints[i] = new Point4d(); rightFrustumPoints[i] = new Point4d(); } // canvas is null in Renderer copyOfCvCache if (canvas != null) { leftEyeInImagePlate.set(canvas.leftManualEyeInImagePlate); rightEyeInImagePlate.set(canvas.rightManualEyeInImagePlate); centerEyeInImagePlate.add(leftEyeInImagePlate, rightEyeInImagePlate); centerEyeInImagePlate.scale(0.5); } if((J3dDebug.devPhase) && (J3dDebug.canvasViewCache >= J3dDebug.LEVEL_1)) System.err.println("Constructed a CanvasViewCache"); } synchronized void setCanvas(Canvas3D c) { canvas = c; } synchronized void setScreenViewCache(ScreenViewCache svc) { screenViewCache = svc; } synchronized void setViewCache(ViewCache vc) { viewCache = vc; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -