org.jmol.shape.Mesh Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmol Show documentation
Show all versions of jmol Show documentation
Jmol: an open-source Java viewer for chemical structures in 3D
/* $RCSfile$
* $Author: hansonr $
* $Date: 2007-04-24 20:49:07 -0500 (Tue, 24 Apr 2007) $
* $Revision: 7483 $
*
* Copyright (C) 2005 Miguel, The Jmol Development Team
*
* Contact: [email protected], [email protected]
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jmol.shape;
import java.util.BitSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import org.jmol.script.Token;
import org.jmol.util.ArrayUtil;
import org.jmol.util.BitSetUtil;
import org.jmol.util.Escape;
import org.jmol.util.Measure;
import org.jmol.util.MeshSurface;
import org.jmol.util.Quaternion;
import org.jmol.api.JmolRendererInterface;
import org.jmol.api.SymmetryInterface;
import org.jmol.g3d.Graphics3D;
//import javax.vecmath.Matrix3f;
import javax.vecmath.Matrix3f;
import javax.vecmath.Matrix4f;
import javax.vecmath.Point3f;
import javax.vecmath.Point4f;
import javax.vecmath.Tuple3f;
import javax.vecmath.Vector3f;
public class Mesh extends MeshSurface {
public final static String PREVIOUS_MESH_ID = "+PREVIOUS_MESH+";
public String[] title;
public short meshColix;
public short[] normixes;
public List lineData;
public String thisID;
public boolean isValid = true;
public String scriptCommand;
public String colorCommand;
public Point3f lattice;
public boolean visible = true;
public int lighting = Token.frontlit;
public float scale = 1;
public boolean haveXyPoints;
public int diameter;
public float width;
public Point3f ptCenter = new Point3f(0,0,0);
public Mesh linkedMesh; //for lcaoOrbitals
public Map vertexColorMap;
public int color;
public SymmetryInterface unitCell;
public float scale3d = 0;
public int index;
public int atomIndex = -1;
public int modelIndex = -1; // for Isosurface and Draw
public int visibilityFlags;
public boolean insideOut;
public int checkByteCount;
public void setVisibilityFlags(int n) {
visibilityFlags = n;//set to 1 in mps
}
public boolean showContourLines = false;
public boolean showPoints = false;
public boolean drawTriangles = false;
public boolean fillTriangles = true;
public boolean showTriangles = false; //as distinct entitities
public boolean frontOnly = false;
public boolean isTwoSided = true;
public boolean havePlanarContours = false;
/**
*
* @param thisID
* @param g3d IGNORED
* @param colix
* @param index
*/
public Mesh(String thisID, JmolRendererInterface g3d, short colix, int index) {
if (PREVIOUS_MESH_ID.equals(thisID))
thisID = null;
this.thisID = thisID;
this.colix = colix;
this.index = index;
//System.out.println("Mesh " + this + " constructed");
}
//public void finalize() {
// System.out.println("Mesh " + this + " finalized");
//}
public void clear(String meshType) {
altVertices = null;
bsDisplay = null;
bsSlabDisplay = null;
bsSlabGhost = null;
cappingObject = null;
colix = Graphics3D.GOLD;
colorDensity = false;
connections = null;
diameter = 0;
drawTriangles = false;
fillTriangles = true;
frontOnly = false;
havePlanarContours = false;
haveXyPoints = false;
isTriangleSet = false;
isTwoSided = false;
lattice = null;
mat4 = null;
normixes = null;
scale3d = 0;
polygonIndexes = null;
scale = 1;
showContourLines = false;
showPoints = false;
showTriangles = false; //as distinct entities
slabbingObject = null;
slabOptions = null;
title = null;
unitCell = null;
vertexCount0 = polygonCount0 = vertexCount = polygonCount = 0;
vertices = null;
spanningVectors = null;
this.meshType = meshType;
}
private BitSet bsTemp;
public void initialize(int lighting, Point3f[] vertices, Point4f plane) {
if (vertices == null)
vertices = this.vertices;
Vector3f[] normals = getNormals(vertices, plane);
setNormixes(normals);
this.lighting = Token.frontlit;
if (insideOut)
invertNormixes();
setLighting(lighting);
}
public void setNormixes(Vector3f[] normals) {
normixes = new short[normixCount];
if (bsTemp == null)
bsTemp = new BitSet();
if (haveXyPoints)
for (int i = normixCount; --i >= 0;)
normixes[i] = Graphics3D.NORMIX_NULL;
else
for (int i = normixCount; --i >= 0;)
normixes[i] = Graphics3D.getNormix(normals[i], bsTemp);
}
public Vector3f[] getNormals(Point3f[] vertices, Point4f plane) {
normixCount = (isTriangleSet ? polygonCount : vertexCount);
Vector3f[] normals = new Vector3f[normixCount];
for (int i = normixCount; --i >= 0;)
normals[i] = new Vector3f();
if (plane == null) {
sumVertexNormals(vertices, normals);
}else {
Vector3f normal = new Vector3f(plane.x, plane.y, plane.z);
for (int i = normixCount; --i >= 0;)
normals[i] = normal;
}
if (!isTriangleSet)
for (int i = normixCount; --i >= 0;)
normals[i].normalize();
return normals;
}
public void setLighting(int lighting) {
isTwoSided = (lighting == Token.fullylit);
if (lighting == this.lighting)
return;
flipLighting(this.lighting);
flipLighting(this.lighting = lighting);
}
private void flipLighting(int lighting) {
if (lighting == Token.fullylit)
for (int i = normixCount; --i >= 0;)
normixes[i] = (short)~normixes[i];
else if ((lighting == Token.frontlit) == insideOut)
invertNormixes();
}
private void invertNormixes() {
for (int i = normixCount; --i >= 0;)
normixes[i] = Graphics3D.getInverseNormix(normixes[i]);
}
public void setTranslucent(boolean isTranslucent, float iLevel) {
colix = Graphics3D.getColixTranslucent(colix, isTranslucent, iLevel);
}
public final Vector3f vAB = new Vector3f();
public final Vector3f vAC = new Vector3f();
public final Vector3f vTemp = new Vector3f();
//public Vector data1;
//public Vector data2;
public List