public void renderRopeSegment(short colix, short[] mads, int i, int monomerCount, Monomer[] monomers, Point3i[] leadMidpointScreens, bool[] isSpecials) { int iPrev1 = i - 1; if (iPrev1 < 0) iPrev1 = 0; int iNext1 = i + 1; if (iNext1 > monomerCount) iNext1 = monomerCount; int iNext2 = i + 2; if (iNext2 > monomerCount) iNext2 = monomerCount; int madThis, madBeg, madEnd; madThis = madBeg = madEnd = mads[i]; if (isSpecials != null) { if (!isSpecials[iPrev1]) madBeg = (mads[iPrev1] + madThis) / 2; if (!isSpecials[iNext1]) madEnd = (mads[iNext1] + madThis) / 2; } int diameterBeg = leadMidpointScreens[i].z;//viewer.scaleToScreen(leadMidpointScreens[i].z, madBeg); int diameterEnd = leadMidpointScreens[iNext1].z;//viewer.scaleToScreen(leadMidpointScreens[iNext1].z, madEnd); int diameterMid = monomers[i].LeadAtom.ScreenZ;//viewer.scaleToScreen(monomers[i].LeadAtom.ScreenZ, madThis); g3d.fillHermite(colix, monomers[i].Nucleic?4:7, diameterBeg, diameterMid, diameterEnd, leadMidpointScreens[iPrev1], leadMidpointScreens[i], leadMidpointScreens[iNext1], leadMidpointScreens[iNext2]); }
public virtual Point3i[] calcScreens(Point3f[] centers, Vector3f[] vectors, short[] mads, float offsetFraction) { // this basically does object->screen transformation?? Point3i[] screens = new Point3i[centers.Length];// viewer.allocTempScreens(centers.Length); if (offsetFraction == 0) { for (int i = centers.Length; --i >= 0; ) screens[i] = new Point3i((int)centers[i].x, (int)centers[i].y, (int)centers[i].z); //viewer.transformPoint(centers[i], screens[i]); } else { offsetFraction /= 1000; for (int i = centers.Length; --i >= 0; ) { pointT.set_Renamed(vectors[i]); float scale = mads[i] * offsetFraction; pointT.scaleAdd(scale, centers[i]); //if (float.IsNaN(pointT.x)) //{ // System.Console.Out.WriteLine(" vectors[" + i + "]=" + vectors[i] + " centers[" + i + "]=" + centers[i] + " mads[" + i + "]=" + mads[i] + " scale=" + scale + " --> " + pointT); //} //viewer.transformPoint(pointT, screens[i]); screens[i] = new Point3i((int)pointT.x, (int)pointT.y, (int)pointT.z); } } return screens; }
public virtual void calc1Screen(Point3f center, Vector3f vector, short mad, float offsetFraction, Point3i screen) { pointT.set_Renamed(vector); float scale = mad * offsetFraction; pointT.scaleAdd(scale, center); //viewer.transformPoint(pointT, screen); }
private void InitBlock() { ring6Screens[5] = new Point3i(); for (int i = 5; --i >= 0; ) { ring5Screens[i] = new Point3i(); ring6Screens[i] = new Point3i(); } }
public Point3i[] calcScreenLeadMidpoints(int monomerCount, Point3f[] leadMidpoints) { int count = monomerCount + 1; Point3i[] leadMidpointScreens = new Point3i[count];// null;// viewer.allocTempScreens(count); for (int i = count; --i >= 0; ) { leadMidpointScreens[i] = new Point3i((int)leadMidpoints[i].x, (int)leadMidpoints[i].y, (int)leadMidpoints[i].z); //viewer.transformPoint(leadMidpoints[i], leadMidpointScreens[i]); //g3d.fillSphereCentered(Graphics3D.CYAN, 15, leadMidpointScreens[i]); g3d.fillSphereCentered(0, 15, leadMidpointScreens[i]); } return leadMidpointScreens; }
public NuHermite3D(NuGraphics3D g3d) { this.g3d = g3d; for (int i = 16; --i >= 0; ) { pLeft[i] = new Point3i(); pRight[i] = new Point3i(); pTopLeft[i] = new Point3f(); pTopRight[i] = new Point3f(); pBotLeft[i] = new Point3f(); pBotRight[i] = new Point3f(); } triStripBuffer = new List<List<Vector3>>(); }
public virtual Point3i[] calcScreens(Point3f[] centers, Vector3f[] vectors, short[] mads, float offsetFraction) { int count = centers.Length; Point3i[] screens = new Point3i[count];// null;// viewer.allocTempScreens(count); if (offsetFraction == 0) { for (int i = count; --i >= 0; ) screens[i] = new Point3i((int)centers[i].x, (int)centers[i].y, (int)centers[i].z); // viewer.transformPoint(centers[i], screens[i]); } else { for (int i = count; --i >= 0; ) { pointT.set_Renamed(vectors[i]); //boolean isSpecial = isSpecials[i]; short mad = mads[i]; /* if (isSpecial && !lastWasSpecial) mad *= 2; */ /* short mad = isSpecial || i == 0 ? mads[i] : mads[i - 1]; if (i + 1 < count && isSpecial) { if (isSpecial && ! isSpecials[i + 1]) mad = mads[i]; } */ float scale = mad * offsetFraction; pointT.scaleAdd(scale, centers[i]); screens[i] = new Point3i((int)pointT.x, (int)pointT.y, (int)pointT.z); //viewer.transformPoint(pointT, screens[i]); } } return screens; }
public virtual void render2Strand(int monomerCount, Monomer[] monomers, short[] mads, short[] colixes, Point3i[] ribbonTopScreens, Point3i[] ribbonBottomScreens) { for (int i = monomerCount; --i >= 0; ) if (mads[i] > 0) render2StrandSegment(monomerCount, monomers[i], colixes[i], mads, ribbonTopScreens, ribbonBottomScreens, i); }
public virtual void render2StrandSegment(int monomerCount, Monomer monomer, short colix, short[] mads, Point3i[] ribbonTopScreens, Point3i[] ribbonBottomScreens, int i) { int iLast = monomerCount; int iPrev = i - 1; if (iPrev < 0) iPrev = 0; int iNext = i + 1; if (iNext > iLast) iNext = iLast; int iNext2 = i + 2; if (iNext2 > iLast) iNext2 = iLast; //colix = Graphics3D.inheritColix(colix, monomer.LeadAtom.colixAtom); g3d.drawHermite(true, ribbonBorder, colix, isNucleic?4:7, ribbonTopScreens[iPrev], ribbonTopScreens[i], ribbonTopScreens[iNext], ribbonTopScreens[iNext2], ribbonBottomScreens[iPrev], ribbonBottomScreens[i], ribbonBottomScreens[iNext], ribbonBottomScreens[iNext2]); }
public void fillTriangle(short colix, Point3i screenA, Point3i screenB, Point3i screenC) { fillTriangle(screenA, screenB, screenC); }
public void render2(bool fill, bool border, short colix, int tension, //top strand segment Point3i p0, Point3i p1, Point3i p2, Point3i p3, //bottom strand segment Point3i p4, Point3i p5, Point3i p6, Point3i p7) { if (!fill) { render2x(fill, colix, tension, p0, p1, p2, p3, p4, p5, p6, p7); return; } /* System.out.println("------------render2-------------"); System.out.println("p1=" + p1 + " p2=" + p2 + "\np3=" + p3 + " p4=" + p4); */ int x1 = p1.x, y1 = p1.y, z1 = p1.z; int x2 = p2.x, y2 = p2.y, z2 = p2.z; int xT1 = ((x2 - p0.x) * tension) / 8; int yT1 = ((y2 - p0.y) * tension) / 8; int zT1 = ((z2 - p0.z) * tension) / 8; int xT2 = ((p3.x - x1) * tension) / 8; int yT2 = ((p3.y - y1) * tension) / 8; int zT2 = ((p3.z - z1) * tension) / 8; set(pTopLeft[0], p1); set(pTopRight[0], p2); int x5 = p5.x, y5 = p5.y, z5 = p5.z; int x6 = p6.x, y6 = p6.y, z6 = p6.z; int xT5 = ((x6 - p4.x) * tension) / 8; int yT5 = ((y6 - p4.y) * tension) / 8; int zT5 = ((z6 - p4.z) * tension) / 8; int xT6 = ((p7.x - x5) * tension) / 8; int yT6 = ((p7.y - y5) * tension) / 8; int zT6 = ((p7.z - z5) * tension) / 8; set(pBotLeft[0], p5); set(pBotRight[0], p6); sLeft[0] = 0; sRight[0] = 1; needToFill[0] = true; sp = 0; do { Point3f a = pTopLeft[sp]; Point3f b = pTopRight[sp]; double dxTop = b.x - a.x; double dxTop2 = dxTop * dxTop; if (dxTop2 < 10) { double dyTop = b.y - a.y; double dyTop2 = dyTop * dyTop; if (dyTop2 < 10) { Point3f c = pBotLeft[sp]; Point3f d = pBotRight[sp]; double dxBot = d.x - c.x; double dxBot2 = dxBot * dxBot; if (dxBot2 < 8) { double dyBot = d.y - c.y; double dyBot2 = dyBot * dyBot; if (dyBot2 < 8) { if (border) { g3d.fillSphereCentered(colix, 3, a); g3d.fillSphereCentered(colix, 3, c); } if (needToFill[sp]) { //g3d.fillQuadrilateral(colix, a, b, d, c); // see if fits on end of any existing bool appended = false; for (int strip = 0; strip < triStripBuffer.Count; strip++) { int end2Idx = triStripBuffer[strip].Count - 2; if (triStripBuffer[strip][end2Idx].X == b.x && triStripBuffer[strip][end2Idx].Y == b.y && triStripBuffer[strip][end2Idx].Z == b.z && triStripBuffer[strip][end2Idx + 1].X == d.x && triStripBuffer[strip][end2Idx + 1].Y == d.y && triStripBuffer[strip][end2Idx + 1].Z == d.z) { // append to end triStripBuffer[strip].Add(new Vector3(a.x, a.y, a.z)); triStripBuffer[strip].Add(new Vector3(c.x, c.y, c.z)); appended = true; } } if (!appended) { List<Vector3> strip = new List<Vector3>(); triStripBuffer.Add(strip); strip.Add(new Vector3(b.x, b.y, b.z)); strip.Add(new Vector3(d.x, d.y, d.z)); strip.Add(new Vector3(a.x, a.y, a.z)); strip.Add(new Vector3(c.x, c.y, c.z)); } needToFill[sp] = false; } if (dxTop2 + dyTop2 < 2 && dxBot2 + dyBot2 < 2) { --sp; continue; } } } } } double s = (sLeft[sp] + sRight[sp]) / 2; double s2 = s * s; double s3 = s2 * s; double h1 = 2 * s3 - 3 * s2 + 1; double h2 = -2 * s3 + 3 * s2; double h3 = s3 - 2 * s2 + s; double h4 = s3 - s2; int spNext = sp + 1; Point3f pMidTop = pTopRight[spNext]; pMidTop.x = (float)(h1 * x1 + h2 * x2 + h3 * xT1 + h4 * xT2); pMidTop.y = (float)(h1 * y1 + h2 * y2 + h3 * yT1 + h4 * yT2); pMidTop.z = (float)(h1 * z1 + h2 * z2 + h3 * zT1 + h4 * zT2); Point3f pMidBot = pBotRight[spNext]; pMidBot.x = (float)(h1 * x5 + h2 * x6 + h3 * xT5 + h4 * xT6); pMidBot.y = (float)(h1 * y5 + h2 * y6 + h3 * yT5 + h4 * yT6); pMidBot.z = (float)(h1 * z5 + h2 * z6 + h3 * zT5 + h4 * zT6); pTopRight[spNext] = pTopRight[sp]; pTopRight[sp] = pMidTop; pBotRight[spNext] = pBotRight[sp]; pBotRight[sp] = pMidBot; sRight[spNext] = sRight[sp]; sRight[sp] = (float)s; needToFill[spNext] = needToFill[sp]; pTopLeft[spNext].set_Renamed(pMidTop); pBotLeft[spNext].set_Renamed(pMidBot); sLeft[spNext] = (float)s; ++sp; } while (sp >= 0); }
public void render(bool tFill, short colix, int tension, int diameterBeg, int diameterMid, int diameterEnd, Point3i p0, Point3i p1, Point3i p2, Point3i p3) { int x1 = p1.x, y1 = p1.y, z1 = p1.z; int x2 = p2.x, y2 = p2.y, z2 = p2.z; int xT1 = ((x2 - p0.x) * tension) / 8; int yT1 = ((y2 - p0.y) * tension) / 8; int zT1 = ((z2 - p0.z) * tension) / 8; int xT2 = ((p3.x - x1) * tension) / 8; int yT2 = ((p3.y - y1) * tension) / 8; int zT2 = ((p3.z - z1) * tension) / 8; sLeft[0] = 0; pLeft[0].set_Renamed(p1); sRight[0] = 1; pRight[0].set_Renamed(p2); sp = 0; int dDiameterFirstHalf = 0; int dDiameterSecondHalf = 0; if (tFill) { dDiameterFirstHalf = 2 * (diameterMid - diameterBeg); dDiameterSecondHalf = 2 * (diameterEnd - diameterMid); } else g3d.setColix(colix); do { Point3i a = pLeft[sp]; Point3i b = pRight[sp]; int dx = b.x - a.x; if (dx >= -1 && dx <= 1) { int dy = b.y - a.y; if (dy >= -1 && dy <= 1) { // mth 2003 10 13 // I tried drawing short cylinder segments here, // but drawing spheres was faster float _s = sLeft[sp]; if (tFill) { int d =(_s < 0.5f ? diameterBeg + (int)(dDiameterFirstHalf * _s) : diameterMid + (int)(dDiameterSecondHalf * (_s - 0.5f))); g3d.fillSphereCentered(colix, d, a); } //else // g3d.plotPixelClipped(a); } --sp; continue; } double s = (sLeft[sp] + sRight[sp]) / 2; double s2 = s * s; double s3 = s2 * s; double h1 = 2 * s3 - 3 * s2 + 1; double h2 = -2 * s3 + 3 * s2; double h3 = s3 - 2 * s2 + s; double h4 = s3 - s2; Point3i pMid = pRight[sp + 1]; pMid.x = (int)(h1 * x1 + h2 * x2 + h3 * xT1 + h4 * xT2); pMid.y = (int)(h1 * y1 + h2 * y2 + h3 * yT1 + h4 * yT2); pMid.z = (int)(h1 * z1 + h2 * z2 + h3 * zT1 + h4 * zT2); pRight[sp + 1] = pRight[sp]; sRight[sp + 1] = sRight[sp]; pRight[sp] = pMid; sRight[sp] = (float)s; ++sp; pLeft[sp].set_Renamed(pMid); sLeft[sp] = (float)s; } while (sp >= 0); }
public void drawLine(Point3i pointA, Point3i pointB) { currentSceneBuffer.lines.Add(new Vector3(pointA.x, pointA.y, pointA.z)); currentSceneBuffer.lines.Add(new Vector3(pointB.x, pointB.y, pointB.z)); }
static void set(Point3f p3f, Point3i p3i) { p3f.x = p3i.x; p3f.y = p3i.y; p3f.z = p3i.z; }
public void fillTriangle(Point3i screenA, Point3i screenB, Point3i screenC) { currentSceneBuffer.triangles.Add(new Vector3(screenA.x, screenA.y, screenA.z)); currentSceneBuffer.triangles.Add(new Vector3(screenB.x, screenB.y, screenB.z)); currentSceneBuffer.triangles.Add(new Vector3(screenC.x, screenC.y, screenC.z)); }
public void transformPoints(Point3f[] pointsAngstroms, Point3i[] pointsScreens) { //transformManager.transformPoints(pointsAngstroms.length, pointsAngstroms, pointsScreens); }
public void transformPoint(Point3f pointAngstroms, Vector3f vibrationVector, Point3i pointScreen) { //transformManager.transformPoint(pointAngstroms, vibrationVector, pointScreen); }
public void drawHermite(bool fill, bool border, short colix, int tension, Point3i s0, Point3i s1, Point3i s2, Point3i s3, Point3i s4, Point3i s5, Point3i s6, Point3i s7) { hermite3d.render2(fill, border, colix, tension, s0, s1, s2, s3, s4, s5, s6, s7); }
public void fillHermite(short colix, int tension, int diameterBeg, int diameterMid, int diameterEnd, Point3i s0, Point3i s1, Point3i s2, Point3i s3) { hermite3d.render(true, colix, tension, diameterBeg, diameterMid, diameterEnd, s0, s1, s2, s3); }
public void transformPoint(Point3f pointAngstroms, Point3i pointScreen) { //transformManager.transformPoint(pointAngstroms, pointScreen); }
void render2x(bool fill, short colix, int tension, //top strand segment Point3i p0, Point3i p1, Point3i p2, Point3i p3, //bottom strand segment Point3i p4, Point3i p5, Point3i p6, Point3i p7) { Point3i[] endPoints = { p2, p1, p6, p5 }; // stores all points for top+bottom strands of 1 segment List<Point3i> points = new List<Point3i>(10); int whichPoint = 0; int numTopStrandPoints = 2; //first and last points automatically included float numPointsPerSegment = 5.0f;//use 5 for mesh // could make it so you can set this from script command if (fill) numPointsPerSegment = 10.0f; float interval = (1.0f / numPointsPerSegment); float currentInt = 0.0f; int x1 = p1.x, y1 = p1.y, z1 = p1.z; int x2 = p2.x, y2 = p2.y, z2 = p2.z; int xT1 = ((x2 - p0.x) * tension) / 8; int yT1 = ((y2 - p0.y) * tension) / 8; int zT1 = ((z2 - p0.z) * tension) / 8; int xT2 = ((p3.x - x1) * tension) / 8; int yT2 = ((p3.y - y1) * tension) / 8; int zT2 = ((p3.z - z1) * tension) / 8; sLeft[0] = 0; pLeft[0].set_Renamed(p1); sRight[0] = 1; pRight[0].set_Renamed(p2); sp = 0; g3d.setColix(colix); // set colix here for entire routine for (int strands = 2; strands > 0; strands--) { if (strands == 1) { x1 = p5.x; y1 = p5.y; z1 = p5.z; x2 = p6.x; y2 = p6.y; z2 = p6.z; xT1 = ( (x2 - p4.x) * tension) / 8; yT1 = ( (y2 - p4.y) * tension) / 8; zT1 = ( (z2 - p4.z) * tension) / 8; xT2 = ( (p7.x - x1) * tension) / 8; yT2 = ( (p7.y - y1) * tension) / 8; zT2 = ( (p7.z - z1) * tension) / 8; sLeft[0] = 0; pLeft[0].set_Renamed(p5); sRight[0] = 1; pRight[0].set_Renamed(p6); sp = 0; } points.Add(endPoints[whichPoint++]); currentInt = interval; do { Point3i a = pLeft[sp]; Point3i b = pRight[sp]; int dx = b.x - a.x; int dy = b.y - a.y; int dist2 = dx * dx + dy * dy; if (dist2 <= 2) { // mth 2003 10 13 // I tried drawing short cylinder segments here, // but drawing spheres was faster float s = sLeft[sp]; g3d.fillSphereCentered(colix, 3, a); //draw outside edges of mesh if (s < 1.0f - currentInt) { //if first point over the interval Point3i temp = new Point3i(); temp.set_Renamed(a); points.Add(temp); //store it currentInt += interval; // increase to next interval if (strands == 2) { numTopStrandPoints++; } } --sp; } else { double s = (sLeft[sp] + sRight[sp]) / 2; double s2 = s * s; double s3 = s2 * s; double h1 = 2 * s3 - 3 * s2 + 1; double h2 = -2 * s3 + 3 * s2; double h3 = s3 - 2 * s2 + s; double h4 = s3 - s2; Point3i pMid = pRight[sp + 1]; pMid.x = (int)(h1 * x1 + h2 * x2 + h3 * xT1 + h4 * xT2); pMid.y = (int)(h1 * y1 + h2 * y2 + h3 * yT1 + h4 * yT2); pMid.z = (int)(h1 * z1 + h2 * z2 + h3 * zT1 + h4 * zT2); pRight[sp + 1] = pRight[sp]; sRight[sp + 1] = sRight[sp]; pRight[sp] = pMid; sRight[sp] = (float)s; ++sp; pLeft[sp].set_Renamed(pMid); sLeft[sp] = (float)s; } } while (sp >= 0); points.Add(endPoints[whichPoint++]); } //end of for loop - processed top and bottom strands int size = points.Count; if (fill) { //RIBBONS Point3i t1 = null; Point3i b1 = null; Point3i t2 = null; Point3i b2 = null; int top = 1; Vector3[] strip = new Vector3[numTopStrandPoints * 2]; int stIdx = 0; for (; top < numTopStrandPoints && (top + numTopStrandPoints) < size; top++) { t1 = points[top - 1]; b1 = points[numTopStrandPoints + (top - 1)]; strip[stIdx++] = new Vector3(t1.X, t1.y, t1.z); strip[stIdx++] = new Vector3(b1.x, b1.y, b1.z); } if ((numTopStrandPoints * 2) != size) { //BUG(DC09_MAY_2004): not sure why but //sometimes misses triangle at very start of segment //temp fix - will inestigate furture g3d.fillTriangle(p1, p5, t2); g3d.fillTriangle(b2, t2, p5); } g3d.FillTriangleStrip(strip); } else { //MESH for (int top = 0; top < numTopStrandPoints && (top + numTopStrandPoints) < size; top++) { g3d.drawLine(points[top], points[top + numTopStrandPoints]); } } }
public void freeTempScreens(Point3i[] tempScreens) { //tempManager.freeTempScreens(tempScreens); }
/// <summary> /// fills a solid sphere /// </summary> /// <param name="colix">the color index</param> /// <param name="diameter">pixel count</param> /// <param name="center">javax.vecmath.Point3i defining the center</param> public void fillSphereCentered(short colix, int diameter, Point3i center) { fillSphereCentered(colix, diameter, center.X, center.Y, center.Z); }