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.povray;
020:
021: import java.math.*;
022: import java.util.*;
023:
024: import org.homedns.dade.jcgrid.*;
025:
026: public class POVWorkRequest extends WorkRequest {
027: private static final long serialVersionUID = 2L;
028:
029: private String iniFileName;
030: private int width;
031: private int height;
032: private int startCol;
033: private int endCol;
034: private int startRow;
035: private int endRow;
036:
037: private boolean animationEnabled;
038: private int frame;
039:
040: public POVWorkRequest(String name, int id, String iniName, int w,
041: int h, int sc, int ec, int sr, int er) {
042: super (name, id);
043:
044: iniFileName = iniName;
045: width = w;
046: height = h;
047: startCol = sc;
048: endCol = ec;
049: startRow = sr;
050: endRow = er;
051:
052: animationEnabled = false;
053: frame = 0;
054: }
055:
056: public int fragmentPerFrame(int wStep, int hStep) {
057: int col = endCol - startCol + 1;
058: int row = endRow - startRow + 1;
059:
060: int wCount = col / wStep;
061: if (col % wStep != 0)
062: wCount++;
063: int hCount = row / hStep;
064: if (row % hStep != 0)
065: hCount++;
066:
067: return wCount * hCount;
068: }
069:
070: public POVWorkRequest[] split(int wStep, int hStep) {
071: return this .split(0, wStep, hStep);
072: }
073:
074: public POVWorkRequest[] split(int RIDBase, int wStep, int hStep) {
075: int col = endCol - startCol + 1;
076: int row = endRow - startRow + 1;
077:
078: int wCount = col / wStep;
079: if (col % wStep != 0)
080: wCount++;
081: int hCount = row / hStep;
082: if (row % hStep != 0)
083: hCount++;
084:
085: int count = wCount * hCount;
086:
087: POVWorkRequest[] res = new POVWorkRequest[count];
088:
089: int i = 0;
090: for (int h = 0; h < hCount; h++) {
091: int fh;
092: if (h == hCount - 1) {
093: fh = row - h * hStep - 1;
094: } else
095: fh = hStep - 1;
096:
097: for (int w = 0; w < wCount; w++) {
098: int fw;
099: if (w == wCount - 1) {
100: fw = col - w * wStep - 1;
101: } else
102: fw = wStep - 1;
103:
104: res[i] = new POVWorkRequest(super .getSessionName(),
105: RIDBase + 1 + i, iniFileName, width, height, w
106: * wStep + startCol, w * wStep
107: + startCol + fw, h * hStep + startRow,
108: h * hStep + startRow + fh);
109: if (animationEnabled) {
110: res[i].setAnimationEnabled(true);
111: res[i].setFrame(frame);
112: }
113:
114: i++;
115: }
116: }
117:
118: return res;
119: }
120:
121: public POVWorkRequest[] split(int startFrame, int endFrame,
122: int wStep, int hStep) {
123: return this .split(0, startFrame, endFrame, wStep, hStep);
124: }
125:
126: public POVWorkRequest[] split(int RIDBase, int startFrame,
127: int endFrame, int wStep, int hStep) {
128: this .setAnimationEnabled(true);
129:
130: Vector v = new Vector();
131: for (frame = startFrame; frame <= endFrame; frame++) {
132: POVWorkRequest[] reqs = this .split(RIDBase, wStep, hStep);
133: RIDBase += reqs.length;
134: v.addAll(Arrays.asList(reqs));
135: }
136:
137: // While waiting for Java 1.5...
138:
139: POVWorkRequest[] reqs = new POVWorkRequest[v.size()];
140: int j = 0;
141: for (Iterator i = v.iterator(); i.hasNext();)
142: reqs[j++] = (POVWorkRequest) i.next();
143:
144: return reqs;
145: }
146:
147: public String getINIFileName() {
148: return iniFileName;
149: }
150:
151: public int getWidth() {
152: return width;
153: }
154:
155: public int getHeight() {
156: return height;
157: }
158:
159: public int getStartCol() {
160: return startCol;
161: }
162:
163: public int getEndCol() {
164: return endCol;
165: }
166:
167: public int getStartRow() {
168: return startRow;
169: }
170:
171: public int getEndRow() {
172: return endRow;
173: }
174:
175: public void setAnimationEnabled(boolean v) {
176: animationEnabled = v;
177: }
178:
179: public boolean isAnimationEnabled() {
180: return animationEnabled;
181: }
182:
183: public void setFrame(int f) {
184: frame = f;
185: }
186:
187: public int getFrame() {
188: return frame;
189: }
190: }
|