Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 package edu.tum.cs.vis.model.util;
00010
00011 import java.io.Serializable;
00012
00013 import processing.core.PGraphics;
00014
00021 public abstract class DrawObject implements Serializable {
00025 private static final long serialVersionUID = -1917773602783043823L;
00026
00030 protected Vertex position[];
00031
00035 protected Appearance appearance;
00036
00043 public DrawObject(final int numberOfEdges) {
00044 position = new Vertex[numberOfEdges];
00045 }
00046
00056 public static float[][] MatrixMultiply(float mat1[][], float mat2[][]) {
00057 int x = mat1.length;
00058 int y = mat2.length;
00059 float result[][] = new float[x][y];
00060
00061 for (int i = 0; i < x; i++) {
00062 for (int j = 0; j < y - 1; j++) {
00063 for (int k = 0; k < y; k++) {
00064
00065 result[i][j] += mat1[i][k] * mat2[k][j];
00066 }
00067 }
00068 }
00069
00070 return result;
00071 }
00072
00081 protected void applyColor(PGraphics g, DrawSettings drawSettings) {
00082 if (appearance == null) {
00083 g.noStroke();
00084 g.noFill();
00085 if (drawSettings == null || drawSettings.drawType == DrawType.FILL) {
00086 if (drawSettings != null && drawSettings.getOverrideColor() != null)
00087 g.fill(drawSettings.getOverrideColor().getRed(), drawSettings
00088 .getOverrideColor().getGreen(), drawSettings.getOverrideColor()
00089 .getBlue(), drawSettings.getOverrideColor().getAlpha());
00090 else
00091 g.fill(200, 200, 200);
00092 } else {
00093 if (drawSettings.getOverrideColor() != null)
00094 g.stroke(drawSettings.getOverrideColor().getRed(), drawSettings
00095 .getOverrideColor().getGreen(), drawSettings.getOverrideColor()
00096 .getBlue(), drawSettings.getOverrideColor().getAlpha());
00097 else
00098 g.stroke(200, 200, 200);
00099 g.strokeWeight(drawSettings.getLineWidth());
00100 }
00101 return;
00102 }
00103 if (appearance.getColorLine() != null) {
00104 if (drawSettings != null && drawSettings.getOverrideColor() != null)
00105 g.stroke(drawSettings.getOverrideColor().getRed(), drawSettings.getOverrideColor()
00106 .getGreen(), drawSettings.getOverrideColor().getBlue(), drawSettings
00107 .getOverrideColor().getAlpha());
00108 else
00109 g.stroke(appearance.getColorLine().getRed(), appearance.getColorLine().getGreen(),
00110 appearance.getColorLine().getBlue(), appearance.getColorLine().getAlpha());
00111 g.strokeWeight(appearance.getStrokeWeight());
00112 } else {
00113 g.noStroke();
00114 }
00115
00116 if (drawSettings == null || drawSettings.drawType == DrawType.FILL) {
00117 if (drawSettings != null && drawSettings.getOverrideColor() != null)
00118 g.fill(drawSettings.getOverrideColor().getRed(), drawSettings.getOverrideColor()
00119 .getGreen(), drawSettings.getOverrideColor().getBlue(), drawSettings
00120 .getOverrideColor().getAlpha());
00121 else if (appearance == null || appearance.getImageReference() == null) {
00122 if (appearance != null && appearance.getColorFill() != null) {
00123 g.fill(appearance.getColorFill().getRed(),
00124 appearance.getColorFill().getGreen(), appearance.getColorFill()
00125 .getBlue(), appearance.getColorFill().getAlpha() == 0 ? 255
00126 : appearance.getColorFill().getAlpha());
00127 } else {
00128 g.noFill();
00129 }
00130 } else {
00131
00132
00133 g.fill(255, 255, 255, 0);
00134 }
00135 } else {
00136 if (drawSettings != null && drawSettings.getOverrideColor() != null)
00137 g.stroke(drawSettings.getOverrideColor().getRed(), drawSettings.getOverrideColor()
00138 .getGreen(), drawSettings.getOverrideColor().getBlue(), drawSettings
00139 .getOverrideColor().getAlpha());
00140 else if (appearance.getColorFill() != null) {
00141 g.stroke(appearance.getColorFill().getRed(), appearance.getColorFill().getGreen(),
00142 appearance.getColorFill().getBlue(),
00143 appearance.getColorFill().getAlpha() == 0 ? 255 : appearance.getColorFill()
00144 .getAlpha());
00145 } else
00146 g.stroke(255, 255, 255);
00147 g.strokeWeight(drawSettings.getLineWidth());
00148 }
00149 }
00150
00151 @Override
00152 public boolean equals(Object o) {
00153 if (o == this) {
00154 return true;
00155 }
00156 if (!(o instanceof DrawObject)) {
00157 return false;
00158 }
00159
00160 DrawObject t = (DrawObject) o;
00161 if (t.position.length != t.position.length)
00162 return false;
00163 int cnt = 0;
00164 int maxCnt = position.length;
00165 for (int k = 0; k < maxCnt; k++) {
00166 for (int l = 0; l < maxCnt; l++) {
00167 if (t.position[k].equals(position[l]))
00168 cnt++;
00169 }
00170 }
00171 return (cnt == maxCnt);
00172 }
00173
00177 public Appearance getAppearance() {
00178 return appearance;
00179 }
00180
00184 public Vertex[] getPosition() {
00185 return position;
00186 }
00187
00194 public void scale(float factor) {
00195 for (int v = 0; v < position.length; v++) {
00196 position[v].x *= factor;
00197 position[v].y *= factor;
00198 position[v].z *= factor;
00199 }
00200 updateCentroid();
00201 }
00202
00207 public void setAppearance(Appearance appearance) {
00208 this.appearance = appearance;
00209 }
00210
00217 public void setPosition(Vertex[] position) {
00218 this.position = position;
00219 updateCentroid();
00220 }
00221
00228 public void transform(float[][] matrix) {
00229 for (int v = 0; v < position.length; v++) {
00230 float[] newPos = new float[4];
00231 for (int row = 0; row < 4; row++) {
00232 newPos[row] = position[v].x * matrix[row][0] + position[v].y * matrix[row][1]
00233 + position[v].z * matrix[row][2] + matrix[row][3];
00234 }
00235 position[v].x = newPos[0] / newPos[3];
00236 position[v].y = newPos[1] / newPos[3];
00237 position[v].z = newPos[2] / newPos[3];
00238 }
00239 updateCentroid();
00240 }
00241
00247 public void updateCentroid() {
00248
00249
00250
00251 }
00252
00259 public Edge[] getEdges() {
00260 Edge[] e = new Edge[3];
00261 for (int j = 0; j < position.length; j++) {
00262 e[j] = new Edge(position[(j + 2) % position.length],
00263 position[(j + 1) % position.length]);
00264 }
00265 return e;
00266 }
00267 }