001: /*
002: Copyright (C) 2004 David Bucciarelli (davibu@interfree.it)
003:
004: This program is free software; you can redistribute it and/or
005: modify it under the terms of the GNU General Public License
006: as published by the Free Software Foundation; either version 2
007: of the License, or (at your option) any later version.
008:
009: This program is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: GNU General Public License for more details.
013:
014: You should have received a copy of the GNU General Public License
015: along with this program; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: */
018:
019: package org.homedns.dade.jcgrid.worker.impl.mandel;
020:
021: import java.math.*;
022:
023: import org.homedns.dade.jcgrid.*;
024:
025: public class MandelWorkRequest extends WorkRequest {
026: private static final long serialVersionUID = 1L;
027:
028: private short maxIter;
029:
030: private double xOrig;
031: private double yOrig;
032:
033: private double dx;
034: private double dy;
035:
036: private int xOffset;
037: private int yOffset;
038:
039: private int xStep;
040: private int yStep;
041:
042: public MandelWorkRequest(String nameVal, int idVal,
043: short maxIterVal, double xOrigVal, double yOrigVal,
044: double dxVal, double dyVal, int xStepVal, int yStepVal) {
045: super (nameVal, idVal);
046:
047: maxIter = maxIterVal;
048:
049: xOrig = xOrigVal;
050: yOrig = yOrigVal;
051:
052: dx = dxVal;
053: dy = dyVal;
054:
055: xStep = xStepVal;
056: yStep = yStepVal;
057: }
058:
059: public int fragmentPerFrame() {
060: int xCount = (int) Math.ceil(xStep
061: / (double) MandelConfig.MANDELGRID_FRAG_SIZE);
062: int yCount = (int) Math.ceil(yStep
063: / (double) MandelConfig.MANDELGRID_FRAG_SIZE);
064:
065: return xCount * yCount;
066: }
067:
068: public MandelWorkRequest[] split() {
069: int xCount = (int) Math.ceil(xStep
070: / (double) MandelConfig.MANDELGRID_FRAG_SIZE);
071: int yCount = (int) Math.ceil(yStep
072: / (double) MandelConfig.MANDELGRID_FRAG_SIZE);
073: int count = xCount * yCount;
074:
075: MandelWorkRequest[] mfs = new MandelWorkRequest[count];
076:
077: int i = 0;
078: for (int y = 0; y < yCount; y++) {
079: int fh;
080: if (y == yCount - 1) {
081: fh = yStep - y * MandelConfig.MANDELGRID_FRAG_SIZE;
082: } else
083: fh = MandelConfig.MANDELGRID_FRAG_SIZE;
084:
085: for (int x = 0; x < xCount; x++) {
086: int fw;
087: if (x == xCount - 1) {
088: fw = xStep - x * MandelConfig.MANDELGRID_FRAG_SIZE;
089: } else
090: fw = MandelConfig.MANDELGRID_FRAG_SIZE;
091:
092: MandelWorkRequest mf = new MandelWorkRequest(this
093: .getSessionName(), i, maxIter, xOrig + dx * x
094: * MandelConfig.MANDELGRID_FRAG_SIZE, yOrig + dy
095: * y * MandelConfig.MANDELGRID_FRAG_SIZE, dx,
096: dy, fw, fh);
097: mf.setXOffset(x * MandelConfig.MANDELGRID_FRAG_SIZE);
098: mf.setYOffset(y * MandelConfig.MANDELGRID_FRAG_SIZE);
099:
100: mfs[i++] = mf;
101: }
102: }
103:
104: return mfs;
105: }
106:
107: public String toString() {
108: return "MandelWorkRequest[" + maxIter + "," + xOrig + ","
109: + yOrig + "," + dx + "," + dy + "," + xOffset + ","
110: + yOffset + "," + xStep + "," + yStep + "]";
111: }
112:
113: //------------------------------- Get & Set --------------------------------
114:
115: public void setMaxIter(short i) {
116: maxIter = i;
117: }
118:
119: public short getMaxIter() {
120: return maxIter;
121: }
122:
123: public void setXOrig(double xo) {
124: xOrig = xo;
125: }
126:
127: public double getXOrig() {
128: return xOrig;
129: }
130:
131: public void setYOrig(double yo) {
132: yOrig = yo;
133: }
134:
135: public double getYOrig() {
136: return yOrig;
137: }
138:
139: public void setDX(double d) {
140: dx = d;
141: }
142:
143: public double getDX() {
144: return dx;
145: }
146:
147: public void setDY(double d) {
148: dy = d;
149: }
150:
151: public double getDY() {
152: return dy;
153: }
154:
155: public void setXStep(int xs) {
156: xStep = xs;
157: }
158:
159: public int getXStep() {
160: return xStep;
161: }
162:
163: public void setYStep(int ys) {
164: yStep = ys;
165: }
166:
167: public int getYStep() {
168: return yStep;
169: }
170:
171: public void setXOffset(int xo) {
172: xOffset = xo;
173: }
174:
175: public int getXOffset() {
176: return xOffset;
177: }
178:
179: public void setYOffset(int yo) {
180: yOffset = yo;
181: }
182:
183: public int getYOffset() {
184: return yOffset;
185: }
186: }
|