Vertex.java
Go to the documentation of this file.
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 import java.util.Collection;
00012 import java.util.HashSet;
00013 import java.util.Set;
00014 
00015 import javax.vecmath.Point3f;
00016 import javax.vecmath.Tuple3f;
00017 import javax.vecmath.Vector3f;
00018 
00027 public class Vertex extends Point3f {
00028 
00032         private static final long       serialVersionUID        = 4454667509075960402L;
00033 
00037         private Vector3f                        normalVector            = new Vector3f();
00038 
00042         private float                           pointarea                       = 0f;
00043 
00047         public Color                            color;
00048 
00052         public Color                            overrideColor           = null;
00053 
00057         private final Set<Vertex>       neighbors                       = new HashSet<Vertex>();
00058 
00069         public Vertex(float x, float y, float z) {
00070                 super(x, y, z);
00071         }
00072 
00079         public Vertex(Tuple3f p) {
00080                 super(p);
00081         }
00082 
00091         public Vertex(Tuple3f p, Vector3f norm) {
00092                 super(p);
00093                 this.normalVector = (Vector3f) norm.clone();
00094         }
00095 
00096         @Override
00097         public Object clone() {
00098                 Vertex v = new Vertex(this);
00099                 v.normalVector = (Vector3f) normalVector.clone();
00100                 v.color = color == null ? null : new Color(color.getRed(), color.getGreen(),
00101                                 color.getBlue(), color.getAlpha());
00102                 v.overrideColor = overrideColor == null ? null : new Color(overrideColor.getRed(),
00103                                 overrideColor.getGreen(), overrideColor.getBlue(), overrideColor.getAlpha());
00104                 return v;
00105         }
00106 
00107         @Override
00108         public boolean equals(Object o) {
00109                 if (o == this) {
00110                         return true;
00111                 }
00112 
00113                 return false;
00114         }
00115 
00123         public boolean sameCoordinates(Point3f p) {
00124                 return (p.x == x && p.y == y && p.z == z);
00125         }
00126 
00132         public Vector3f getNormalVector() {
00133                 return normalVector;
00134         }
00135 
00141         public float getPointarea() {
00142                 return pointarea;
00143         }
00144 
00145         @Override
00146         public int hashCode() {
00147                 return Float.valueOf(x).hashCode() ^ Float.valueOf(y).hashCode()
00148                                 ^ Float.valueOf(z).hashCode() ^ Double.valueOf(pointarea).hashCode()
00149                                 ^ normalVector.hashCode();
00150         }
00151 
00158         public void setNormalVector(Vector3f normalVector) {
00159                 this.normalVector = normalVector;
00160         }
00161 
00168         public void setPointarea(float pointarea) {
00169 
00170                 this.pointarea = pointarea;
00171         }
00172 
00179         public void transform(float[][] matrix) {
00180 
00181                 float[] newPos = new float[4];
00182                 for (int row = 0; row < 4; row++) {
00183                         newPos[row] = x * matrix[row][0] + y * matrix[row][1] + z * matrix[row][2]
00184                                         + matrix[row][3];
00185                 }
00186                 x = newPos[0] / newPos[3];
00187                 y = newPos[1] / newPos[3];
00188                 z = newPos[2] / newPos[3];
00189         }
00190 
00194         public Set<Vertex> getNeighbors() {
00195                 return neighbors;
00196         }
00197 
00205         public void addNeighbor(Vertex v) {
00206                 if (v == this)
00207                         return;
00208                 synchronized (neighbors) {
00209                         neighbors.add(v);
00210                 }
00211         }
00212 
00220         public void addNeighbor(Collection<Vertex> neig) {
00221                 synchronized (neighbors) {
00222                         synchronized (neig) {
00223                                 neighbors.addAll(neig);
00224                         }
00225                         // make sure we didn't add ourself as neighbor
00226                         if (neighbors.contains(this))
00227                                 neighbors.remove(this);
00228                 }
00229         }
00230 
00238         public void addNeighbor(Vertex[] neig) {
00239                 synchronized (neighbors) {
00240                         synchronized (neig) {
00241                                 for (Vertex v : neig) {
00242                                         if (v == this)
00243                                                 continue;
00244                                         neighbors.add(v);
00245                                 }
00246                         }
00247                 }
00248         }
00249 
00250 }


knowrob_cad_parser
Author(s): Stefan Profanter
autogenerated on Sat Dec 28 2013 17:09:45