📄 parametricbicubicpatch.java
字号:
//===========================================================================//=-------------------------------------------------------------------------=//= References: =//= [WAYN1990] Knapp Wayne. "Ray with Bicubic Patch Intersection Problem", =//= Ray Tracing News, volume 3, number 3, july 13 1990. =//= available at =//= http://jedi.ks.uiuc.edu/~johns/raytracer/rtn/rtnv3n3.html#art19 =//= [FOLE1992] Foley, vanDam, Feiner, Hughes. "Computer Graphics, princi- =//= ples and practice" - second edition, Addison Wesley, 1992. =//=-------------------------------------------------------------------------=//= Module history: =//= - April 27 2006 - Gina Chiquillo / David Camello: Original base version =//= - April 28 2006 - Gina Chiquillo / Oscar Chavarro: quality check =//===========================================================================package vsdk.toolkit.environment.geometry;import java.util.ArrayList;import vsdk.toolkit.common.Matrix4x4;import vsdk.toolkit.common.Vector3D;import vsdk.toolkit.common.Ray;import vsdk.toolkit.environment.geometry.Geometry;public class ParametricBiCubicPatch extends Surface { /// Check the general attribute description in superclass Entity. public static final long serialVersionUID = 20060502L; public Matrix4x4 Gx_MATRIX = new Matrix4x4(); public Matrix4x4 Gy_MATRIX = new Matrix4x4(); public Matrix4x4 Gz_MATRIX = new Matrix4x4(); private Matrix4x4 S_MATRIX; private Matrix4x4 Tt_MATRIX; private Matrix4x4 S_MATRIX_DS; private Matrix4x4 Tt_MATRIX_DT; private Matrix4x4 M_MATRIX; private Matrix4x4 Mt_MATRIX; private Matrix4x4 M_Gx_Mt_MATRIX; private Matrix4x4 M_Gy_Mt_MATRIX; private Matrix4x4 M_Gz_Mt_MATRIX; public static final int FERGUSON = 7; /// Note that the contourCurve must have 4 points with its respective /// control parameters. public ParametricCurve contourCurve; private Vector3D controlMeshPoints[][]; public int type; // Number of steps for curve approximation private static final int INITIAL_APPROXIMATION_STEPS = 12; private int approximationSteps; public ParametricBiCubicPatch() { approximationSteps = INITIAL_APPROXIMATION_STEPS; this.type = ParametricCurve.HERMITE; contourCurve = null; S_MATRIX = null; Tt_MATRIX = null; S_MATRIX_DS = null; Tt_MATRIX_DT = null; M_MATRIX = null; Mt_MATRIX = null; M_Gx_Mt_MATRIX = null; M_Gy_Mt_MATRIX = null; M_Gz_Mt_MATRIX = null; } /** Given a contour curve, this constructor builds a corresponding FERGUSON type patch. PRE: Contour curve must has at least 4 control points. The first 4 control points (the only one used) must be of type HERMITE. Note that a Ferguson patch is an Hermite patch with zero valued twist vectors. */ public void buildFergusonPatch(ParametricCurve curve) { this.contourCurve = curve; approximationSteps = INITIAL_APPROXIMATION_STEPS; this.type = FERGUSON; calculateMatrices(); } public void buildBezierPatch(Vector3D controlMeshPoints[][]) { this.controlMeshPoints = controlMeshPoints; approximationSteps = INITIAL_APPROXIMATION_STEPS; this.type = ParametricCurve.BEZIER; calculateMatrices(); } /** PRE: Some of the "build*Patch" methods should be called before calling this method. */ private void calculateMatrices() { //- Build matrices M, Gx, Gy, Gz and Mt --------------------------- if ( this.type == ParametricCurve.BEZIER ) { buildGeometryMatricesXYZ_Bezier(); M_MATRIX = ParametricCurve.BEZIER_MATRIX; } else if ( this.type == ParametricCurve.HERMITE ) { buildGeometryMatricesXYZ_Hermite(); M_MATRIX = ParametricCurve.HERMITE_MATRIX; } else if ( this.type == ParametricBiCubicPatch.FERGUSON ) { buildGeometryMatricesXYZ_Ferguson(); M_MATRIX = ParametricCurve.HERMITE_MATRIX; } Mt_MATRIX = new Matrix4x4(M_MATRIX); Mt_MATRIX.transpose(); M_Gx_Mt_MATRIX = M_MATRIX.multiply(Gx_MATRIX).multiply(Mt_MATRIX); M_Gy_Mt_MATRIX = M_MATRIX.multiply(Gy_MATRIX).multiply(Mt_MATRIX); M_Gz_Mt_MATRIX = M_MATRIX.multiply(Gz_MATRIX).multiply(Mt_MATRIX); S_MATRIX = new Matrix4x4(); Tt_MATRIX = new Matrix4x4(); S_MATRIX_DS = new Matrix4x4(); Tt_MATRIX_DT = new Matrix4x4(); } public int getApproximationSteps() { return approximationSteps; } public void setApproximationSteps(int n) { approximationSteps = n; } public int getType() { return type; } public void setType(int type) { type = type; } private void buildGeometryMatricesXYZ_Bezier() { double[][] mx = new double[4][4]; double[][] my = new double[4][4]; double[][] mz = new double[4][4]; int i; int j; for ( i = 0; i < 4; i++ ) { for ( j = 0; j < 4; j++ ) { Vector3D vp = controlMeshPoints[i][j]; mx[i][j] = vp.x; my[i][j] = vp.y; mz[i][j] = vp.z; } } Gx_MATRIX.M = mx; Gy_MATRIX.M = my; Gz_MATRIX.M = mz; //printGeometryMatrices(); } private void buildGeometryMatricesXYZ_Hermite() { double[][] mx = new double[4][4]; double[][] my = new double[4][4]; double[][] mz = new double[4][4]; /* The upper-left 2x2 matrix portion of Gh contains the x coordinates of the four corners of the patch. The upper-right and lower-left 2x2 matrix portion of Gh contains the x coordiates of the tangent vectors four corners of the patch. */ int p = 0; int i = 0; for (int j = 0; j < 2; j++) { Vector3D[] vp = contourCurve.getPoint(p); mx[i][j] = vp[0].x; my[i][j] = vp[0].y; mz[i][j] = vp[0].z; mx[i][j + 2] = vp[2 - j].x; my[i][j + 2] = vp[2 - j].y; mz[i][j + 2] = vp[2 - j].z; mx[i + 2][j] = vp[1 + j].x; my[i + 2][j] = vp[1 + j].y; mz[i + 2][j] = vp[1 + j].z; Vector3D vn = new Vector3D(0, 0, 0); mx[i + 2][j + 2] = vn.x; my[i + 2][j + 2] = vn.y; mz[i + 2][j + 2] = vn.z; p++; } p = 2; i = 1; for (int j = 0; j < 2; j++) { Vector3D[] vp = contourCurve.getPoint(p); mx[i][j] = vp[0].x; my[i][j] = vp[0].y; mz[i][j] = vp[0].z; mx[i][j + 2] = vp[j + 1].x; my[i][j + 2] = vp[j + 1].y; mz[i][j + 2] = vp[j + 1].z; mx[i + 2][j] = vp[2 - j].x; my[i + 2][j] = vp[2 - j].y; mz[i + 2][j] = vp[2 - j].z; Vector3D vn = new Vector3D(0, 0, 0); mx[i + 2][j + 2] = vn.x; my[i + 2][j + 2] = vn.y; mz[i + 2][j + 2] = vn.z; p++; } Gx_MATRIX.M = mx; Gy_MATRIX.M = my; Gz_MATRIX.M = mz; } private void printGeometryMatrices() { double[][] mx = Gx_MATRIX.M; double[][] my = Gy_MATRIX.M; double[][] mz = Gz_MATRIX.M; System.out.printf("[ <%.2f, %.2f, %.2f> | <%.2f, %.2f, %.2f> | " + "<%.2f, %.2f, %.2f> | <%.2f, %.2f, %.2f> ]\n", mx[0][0], my[0][0], mz[0][0], mx[0][1], my[0][1], mz[0][1], mx[0][2], my[0][2], mz[0][2], mx[0][3], my[0][3], mz[0][3] ); System.out.printf("[ <%.2f, %.2f, %.2f> | <%.2f, %.2f, %.2f> | " + "<%.2f, %.2f, %.2f> | <%.2f, %.2f, %.2f> ]\n", mx[1][0], my[1][0], mz[1][0], mx[1][1], my[1][1], mz[1][1], mx[1][2], my[1][2], mz[1][2], mx[1][3], my[1][3], mz[1][3] ); System.out.printf("[ <%.2f, %.2f, %.2f> | <%.2f, %.2f, %.2f> | " + "<%.2f, %.2f, %.2f> | <%.2f, %.2f, %.2f> ]\n", mx[2][0], my[2][0], mz[2][0], mx[2][1], my[2][1], mz[2][1], mx[2][2], my[2][2], mz[2][2], mx[2][3], my[2][3], mz[2][3] ); System.out.printf("[ <%.2f, %.2f, %.2f> | <%.2f, %.2f, %.2f> | " + "<%.2f, %.2f, %.2f> | <%.2f, %.2f, %.2f> ]\n", mx[3][0], my[3][0], mz[3][0], mx[3][1], my[3][1], mz[3][1], mx[3][2], my[3][2], mz[3][2], mx[3][3], my[3][3], mz[3][3] ); } /** @todo verify that current contour curve have at least 4 control points and that first 4 control points are of type HERMITE. */ private void buildGeometryMatricesXYZ_Ferguson() { double[][] mx = new double[4][4]; double[][] my = new double[4][4]; double[][] mz = new double[4][4]; Vector3D[] vp00 = contourCurve.getPoint(0); Vector3D[] vp10 = contourCurve.getPoint(1); Vector3D[] vp11 = contourCurve.getPoint(2); Vector3D[] vp01 = contourCurve.getPoint(3); // Positions with respect to contour curve mx[0][0] = vp00[0].x; my[0][0] = vp00[0].y;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -