$search
00001 /******************************************************************************* 00002 * Copyright (c) 2012 Stefan Profanter. All rights reserved. This program and the accompanying 00003 * materials are made available under the terms of the GNU Public License v3.0 which accompanies 00004 * this distribution, and is available at http://www.gnu.org/licenses/gpl.html 00005 * 00006 * Contributors: Stefan Profanter - initial API and implementation, Year: 2012 00007 ******************************************************************************/ 00008 package edu.tum.cs.vis.model.util; 00009 00010 import java.awt.Color; 00011 00012 import javax.vecmath.Point3f; 00013 import javax.vecmath.Vector3f; 00014 00023 public class Vertex extends Point3f { 00024 00028 private static final long serialVersionUID = 4454667509075960402L; 00029 00033 private Vector3f normalVector = new Vector3f(); 00034 00038 private float pointarea = 0f; 00039 00043 public Color color; 00044 00048 public Color overrideColor = null; 00049 00060 public Vertex(float x, float y, float z) { 00061 super(x, y, z); 00062 } 00063 00070 public Vertex(Point3f p) { 00071 super(p); 00072 } 00073 00074 @Override 00075 public Object clone() { 00076 Vertex v = new Vertex(this); 00077 v.normalVector = (Vector3f) normalVector.clone(); 00078 v.color = color == null ? null : new Color(color.getRed(), color.getGreen(), 00079 color.getBlue(), color.getAlpha()); 00080 v.overrideColor = overrideColor == null ? null : new Color(overrideColor.getRed(), 00081 overrideColor.getGreen(), overrideColor.getBlue(), overrideColor.getAlpha()); 00082 return v; 00083 } 00084 00085 @Override 00086 public boolean equals(Object o) { 00087 if (o == this) { 00088 return true; 00089 } 00090 if (!(o instanceof Point3f)) { 00091 return false; 00092 } 00093 00094 Point3f p = (Point3f) o; 00095 Vertex v = (Vertex) o; 00096 return (sameCoordinates(p) && v.pointarea == pointarea && v.normalVector 00097 .equals(normalVector)); 00098 } 00099 00107 public boolean sameCoordinates(Point3f p) { 00108 return (p.x == x && p.y == y && p.z == z); 00109 } 00110 00116 public Vector3f getNormalVector() { 00117 return normalVector; 00118 } 00119 00125 public float getPointarea() { 00126 return pointarea; 00127 } 00128 00129 @Override 00130 public int hashCode() { 00131 return Float.valueOf(x).hashCode() ^ Float.valueOf(y).hashCode() 00132 ^ Float.valueOf(z).hashCode() ^ Double.valueOf(pointarea).hashCode() 00133 ^ normalVector.hashCode(); 00134 } 00135 00142 public void setNormalVector(Vector3f normalVector) { 00143 this.normalVector = normalVector; 00144 } 00145 00152 public void setPointarea(float pointarea) { 00153 00154 this.pointarea = pointarea; 00155 } 00156 00163 public void transform(float[][] matrix) { 00164 00165 float[] newPos = new float[4]; 00166 for (int row = 0; row < 4; row++) { 00167 newPos[row] = x * matrix[row][0] + y * matrix[row][1] + z * matrix[row][2] 00168 + matrix[row][3]; 00169 } 00170 x = newPos[0] / newPos[3]; 00171 y = newPos[1] / newPos[3]; 00172 z = newPos[2] / newPos[3]; 00173 } 00174 00175 }