//------------------------------------------------------------------------------ // create private void create() { int u; int v; _point = new Vectors[_n][]; for (v = 0; v < _n; v++) { _point[v] = new Vectors[_m]; for (u = 0; u < _m; u++) { _point[v][u] = new Vectors((double)u / (double)(_m - 1) - 0.5, (double)v / (double)(_n - 1) - 0.5, 0.0); } } _patch = new Patch3D[_n - 1][]; for (v = 0; v < _n - 1; v++) { _patch[v] = new Patch3D[_m - 1]; for (u = 0; u < _m - 1; u++) { _patch[v][u] = new Patch3D(u, v, _tiles); } } }
//------------------------------------------------------------------------------ // copy private void copy(Patch3D patch3D) { _u = patch3D._u; _v = patch3D._v; _valid = patch3D._valid; _tiles = patch3D._tiles; for (int i = 0; i < C.CONST.ORDER; i++) { for (int j = 0; j < C.CONST.ORDER; j++) { _matrix[i][j] = patch3D._matrix[i][j]; } } create(); for (int v = 0; v < (_tiles + 1); v++) { for (int u = 0; u < (_tiles + 1); u++) { _vertex[v][u] = patch3D._vertex[v][u]; _normal[v][u] = patch3D._normal[v][u]; } } }
//------------------------------------------------------------------------------ // copy constructor public Patch3D(Patch3D patch3D) { copy(patch3D); }
//------------------------------------------------------------------------------ // remove public void remove() { if (_u > 0 && _u < _m - 1 && _v > 0 && _v < _n - 1 && _m > 2 && _n > 2) { int u; int v; // copy old z int nOld = _n; Vectors[][] pointOld = _point; for (v = 0; v < _n; v++) { pointOld[v] = _point[v]; for (u = 0; u < _m; u++) { pointOld[v][u] = _point[v][u]; } } for (v = 0; v < _n - 1; v++) { for (u = 0; u < _m - 1; u++) { _patch[v][u] = null; } _patch[v] = null; } _patch = null; _m--; _n--; // create new z _point = new Vectors[_n][]; for (v = 0; v < _n; v++) { _point[v] = new Vectors[_m]; for (u = 0; u < _m; u++) { if (v < _v) { if (u < _u) { _point[v][u] = pointOld[v][u]; } else { _point[v][u] = pointOld[v][u + 1]; } } else { if (u < _u) { _point[v][u] = pointOld[v + 1][u]; } else { _point[v][u] = pointOld[v + 1][u + 1]; } } } } _patch = new Patch3D[_n - 1][]; for (v = 0; v < _n - 1; v++) { _patch[v] = new Patch3D[_m - 1]; for (u = 0; u < _m - 1; u++) { _patch[v][u] = new Patch3D(u, v, _tiles); } } // erase old z for (v = 0; v < nOld; v++) { pointOld[v] = null; } pointOld = null; _u--; _v--; } }
//------------------------------------------------------------------------------ // insert public void insert() { if (_u < _m - 1 && _v < _n - 1) { int u; int v; // copy old z int nOld = _n; Vectors[][] pointOld = _point; for (v = 0; v < _n; v++) { pointOld[v] = _point[v]; for (u = 0; u < _m; u++) { pointOld[v][u] = _point[v][u]; } } _m++; _n++; // create new z _point = new Vectors[_n][]; for (v = 0; v < _n; v++) { _point[v] = new Vectors[_m]; for (u = 0; u < _m; u++) { if (v <= _v) { if (u <= _u) { _point[v][u] = pointOld[v][u]; } else if (u == _u + 1) { _point[v][u] = 0.5d * (pointOld[v][u - 1] + pointOld[v][u]); } else { _point[v][u] = pointOld[v][u - 1]; } } else if (v == _v + 1) { if (u <= _u) { _point[v][u] = 0.5d * (pointOld[v - 1][u] + pointOld[v][u]); } else if (u == _u + 1) { _point[v][u] = 0.25d * (pointOld[v - 1][u - 1] + pointOld[v - 1][u] + pointOld[v][u - 1] + pointOld[v][u]); } else { _point[v][u] = 0.5d * (pointOld[v - 1][u - 1] + pointOld[v][u - 1]); } } else { if (u <= _u) { _point[v][u] = pointOld[v - 1][u]; } else if (u == _u + 1) { _point[v][u] = 0.5d * (pointOld[v - 1][u - 1] + pointOld[v - 1][u]); } else { _point[v][u] = pointOld[v - 1][u - 1]; } } } } // erase patch for (v = 0; v < _n - 2; v++) { for (u = 0; u < _m - 2; u++) { _patch[v][u] = null; } _patch[v] = null; } _patch = null; // create patch _patch = new Patch3D[_n - 1][]; for (v = 0; v < _n - 1; v++) { _patch[v] = new Patch3D[_m - 1]; for (u = 0; u < _m - 1; u++) { _patch[v][u] = new Patch3D(u, v, _tiles); } } // erase old z for (v = 0; v < nOld; v++) { pointOld[v] = null; } pointOld = null; _u++; _v++; } }