Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 package edu.tum.cs.vis.model.util;
00009
00010 import java.io.Serializable;
00011
00012 import javax.vecmath.Vector3f;
00013
00014 import processing.core.PGraphics;
00015
00022 public abstract class DrawObject implements Serializable {
00026 private static final long serialVersionUID = -1917773602783043823L;
00027
00037 public static float[][] MatrixMultiply(float mat1[][], float mat2[][]) {
00038 int x = mat1.length;
00039 int y = mat2.length;
00040 float result[][] = new float[x][y];
00041
00042 for (int i = 0; i < x; i++) {
00043 for (int j = 0; j < y - 1; j++) {
00044 for (int k = 0; k < y; k++) {
00045
00046 result[i][j] += mat1[i][k] * mat2[k][j];
00047 }
00048 }
00049 }
00050
00051 return result;
00052 }
00053
00057 protected Vertex position[];
00058
00062 protected Appearance appearance;
00063
00070 public DrawObject(final int numberOfEdges) {
00071 position = new Vertex[numberOfEdges];
00072 }
00073
00082 protected void applyColor(PGraphics g, DrawSettings drawSettings) {
00083 if (appearance == null) {
00084
00085 g.noStroke();
00086 g.noFill();
00087 if (drawSettings == null || drawSettings.drawType == DrawType.FILL) {
00088 if (drawSettings != null && drawSettings.getOverrideColor() != null)
00089 g.fill(drawSettings.getOverrideColor().getRed(), drawSettings
00090 .getOverrideColor().getGreen(), drawSettings.getOverrideColor()
00091 .getBlue(), drawSettings.getOverrideColor().getAlpha());
00092 else
00093 g.fill(200, 200, 200);
00094 } else {
00095 if (drawSettings.getOverrideColor() != null)
00096 g.stroke(drawSettings.getOverrideColor().getRed(), drawSettings
00097 .getOverrideColor().getGreen(), drawSettings.getOverrideColor()
00098 .getBlue(), drawSettings.getOverrideColor().getAlpha());
00099 else
00100 g.stroke(200, 200, 200);
00101 g.strokeWeight(drawSettings.getLineWidth());
00102 }
00103 return;
00104 }
00105 if (appearance.getColorLine() != null) {
00106 if (drawSettings != null && drawSettings.getOverrideColor() != null)
00107 g.stroke(drawSettings.getOverrideColor().getRed(), drawSettings.getOverrideColor()
00108 .getGreen(), drawSettings.getOverrideColor().getBlue(), drawSettings
00109 .getOverrideColor().getAlpha());
00110 else
00111 g.stroke(appearance.getColorLine().getRed(), appearance.getColorLine().getGreen(),
00112 appearance.getColorLine().getBlue(), appearance.getColorLine().getAlpha());
00113 g.strokeWeight(appearance.getStrokeWeight());
00114 } else {
00115 g.noStroke();
00116 }
00117
00118 if (drawSettings == null || drawSettings.drawType == DrawType.FILL) {
00119 if (drawSettings != null && drawSettings.getOverrideColor() != null)
00120 g.fill(drawSettings.getOverrideColor().getRed(), drawSettings.getOverrideColor()
00121 .getGreen(), drawSettings.getOverrideColor().getBlue(), drawSettings
00122 .getOverrideColor().getAlpha());
00123 else if (appearance.getImageReference() == null) {
00124 if (appearance.getColorFill() != null) {
00125 g.fill(appearance.getColorFill().getRed(),
00126 appearance.getColorFill().getGreen(), appearance.getColorFill()
00127 .getBlue(), appearance.getColorFill().getAlpha() == 0 ? 255
00128 : appearance.getColorFill().getAlpha());
00129 } else {
00130 g.noFill();
00131 }
00132 } else {
00133
00134
00135 g.fill(255, 255, 255, 0);
00136 }
00137 } else {
00138 if (drawSettings != null && drawSettings.getOverrideColor() != null)
00139 g.stroke(drawSettings.getOverrideColor().getRed(), drawSettings.getOverrideColor()
00140 .getGreen(), drawSettings.getOverrideColor().getBlue(), drawSettings
00141 .getOverrideColor().getAlpha());
00142 else if (appearance.getColorFill() != null) {
00143 g.stroke(appearance.getColorFill().getRed(), appearance.getColorFill().getGreen(),
00144 appearance.getColorFill().getBlue(),
00145 appearance.getColorFill().getAlpha() == 0 ? 255 : appearance.getColorFill()
00146 .getAlpha());
00147 } else
00148 g.stroke(255, 255, 255);
00149 g.strokeWeight(drawSettings.getLineWidth());
00150 }
00151 }
00152
00153 @Override
00154 public boolean equals(Object o) {
00155 if (o == this) {
00156 return true;
00157 }
00158 if (!(o instanceof DrawObject)) {
00159 return false;
00160 }
00161
00162 DrawObject t = (DrawObject) o;
00163 if (t.position.length != t.position.length)
00164 return false;
00165 int cnt = 0;
00166 int maxCnt = position.length;
00167 for (int k = 0; k < maxCnt; k++) {
00168 for (int l = 0; l < maxCnt; l++) {
00169 if (t.position[k].equals(position[l]))
00170 cnt++;
00171 }
00172 }
00173 return (cnt == maxCnt);
00174 }
00175
00179 public Appearance getAppearance() {
00180 return appearance;
00181 }
00182
00186 public Vertex[] getPosition() {
00187 return position;
00188 }
00189
00196 public void scale(float factor) {
00197 for (int v = 0; v < position.length; v++) {
00198 position[v].x *= factor;
00199 position[v].y *= factor;
00200 position[v].z *= factor;
00201 }
00202 updateCentroid();
00203 }
00204
00209 public void setAppearance(Appearance appearance) {
00210 this.appearance = appearance;
00211 }
00212
00219 public void setPosition(Vertex[] position) {
00220 this.position = position;
00221 updateCentroid();
00222 }
00223
00230 public void transform(float[][] matrix) {
00231 for (int v = 0; v < position.length; v++) {
00232 float[] newPos = new float[4];
00233 for (int row = 0; row < 4; row++) {
00234 newPos[row] = position[v].x * matrix[row][0] + position[v].y * matrix[row][1]
00235 + position[v].z * matrix[row][2] + matrix[row][3];
00236 }
00237 position[v].x = newPos[0] / newPos[3];
00238 position[v].y = newPos[1] / newPos[3];
00239 position[v].z = newPos[2] / newPos[3];
00240 }
00241 updateCentroid();
00242 }
00243
00249 public void updateCentroid() {
00250
00251
00252
00253 }
00254
00261 public Vector3f[] getEdges() {
00262 Vector3f e[] = new Vector3f[3];
00263
00264 for (int j = 0; j < position.length; j++) {
00265 e[j] = new Vector3f(position[(j + 2) % position.length]);
00266 e[j].sub(position[(j + 1) % position.length]);
00267 }
00268 return e;
00269 }
00270
00271 }