Exemplo n.º 1
0
 public void setViewerG3dFrame(/*Viewer viewer,*/ NuGraphics3D g3d, Frame frame)
 {
     //this.viewer = viewer;
     this.g3d   = g3d;
     this.frame = frame;
     initShape();
 }
Exemplo n.º 2
0
 public void setViewerFrameRenderer(/*Viewer viewer,*/ FrameRenderer frameRenderer, NuGraphics3D g3d)
 {
     //this.viewer = viewer;
     this.frameRenderer = frameRenderer;
     this.g3d           = g3d;
     initRenderer();
 }
Exemplo n.º 3
0
 public virtual ShapeRenderer getRenderer(int refShape, NuGraphics3D g3d)
 {
     if (renderers[refShape] == null)
     {
         renderers[refShape] = allocateRenderer(refShape, g3d);
     }
     return(renderers[refShape]);
 }
Exemplo n.º 4
0
 //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
 public virtual void render(NuGraphics3D g3d, ref System.Drawing.Rectangle rectClip, Frame frame, int displayModelIndex, Shape shape)
 {
     this.g3d               = g3d;
     this.rectClip          = rectClip;
     this.frame             = frame;
     this.displayModelIndex = displayModelIndex;
     this.shape             = shape;
     render();
 }
Exemplo n.º 5
0
        private static int allocateColix(int argb)
        {
            lock (typeof(Colix))
            {
                // double-check to make sure that someone else did not allocate
                // something of the same color while we were waiting for the lock
                if ((argb & unchecked ((int)0xFF000000)) != unchecked ((int)0xFF000000))
                {
                    throw new System.IndexOutOfRangeException();
                }
                for (int i = colixMax; --i >= NuGraphics3D.SPECIAL_COLIX_MAX;)
                {
                    if (argb == argbs[i])
                    {
                        return((short)i);
                    }
                }
                if (colixMax == argbs.Length)
                {
                    int   oldSize = argbs.Length;
                    int   newSize = oldSize * 2;
                    int[] t0      = new int[newSize];
                    Array.Copy(argbs, 0, t0, 0, oldSize);
                    argbs = t0;

                    if (argbsGreyscale != null)
                    {
                        t0 = new int[newSize];
                        Array.Copy(argbsGreyscale, 0, t0, 0, oldSize);
                        argbsGreyscale = t0;
                    }

                    int[][] t2 = new int[newSize][];
                    Array.Copy(ashades, 0, t2, 0, oldSize);
                    ashades = t2;

                    if (ashadesGreyscale != null)
                    {
                        t2 = new int[newSize][];
                        Array.Copy(ashadesGreyscale, 0, t2, 0, oldSize);
                        ashadesGreyscale = t2;
                    }
                }
                argbs[colixMax] = argb;
                if (argbsGreyscale != null)
                {
                    argbsGreyscale[colixMax] = NuGraphics3D.calcGreyscaleRgbFromRgb(argb);
                }
                colixHash.put(argb, colixMax);
                return(colixMax++);
            }
        }
Exemplo n.º 6
0
 private static void  calcArgbsGreyscale()
 {
     lock (typeof(Colix))
     {
         if (argbsGreyscale == null)
         {
             argbsGreyscale = new int[argbs.Length];
             for (int i = argbsGreyscale.Length; --i >= 0;)
             {
                 argbsGreyscale[i] = NuGraphics3D.calcGreyscaleRgbFromRgb(argbs[i]);
             }
         }
     }
 }
Exemplo n.º 7
0
        public virtual ShapeRenderer allocateRenderer(int refShape, NuGraphics3D g3d)
        {
            string classBase = JmolConstants.shapeClassBases[refShape] + "Renderer";
            string className = "Org.Jmol.Viewer." + classBase;

            try
            {
                //UPGRADE_TODO: The differences in the format  of parameters for method 'java.lang.Class.forName'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                System.Type   shapeClass = System.Type.GetType(className);
                ShapeRenderer renderer   = (ShapeRenderer)System.Activator.CreateInstance(shapeClass);
                renderer.setViewerFrameRenderer(/*viewer, */ this, g3d);
                return(renderer);
            }
            catch (System.Exception e)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                System.Console.Out.WriteLine("Could not instantiate renderer:" + classBase + "\n" + e);
                SupportClass.WriteStackTrace(e, Console.Error);
            }
            return(null);
        }
Exemplo n.º 8
0
        //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
        public virtual void render(NuGraphics3D g3d, ref System.Drawing.Rectangle rectClip, Frame frame, int displayModelIndex, int shapeType)
        {
            if (frame == null || frame.atomCount <= 0)
            {
                return;
            }

            //viewer.calcTransformMatrices();

            //for (int i = 0; i < JmolConstants.SHAPE_MAX; ++i)
            //{
            Shape shape = frame.shapes[shapeType /*i*/];

            //if (shape == null)
            //    continue;
            if (shape != null)
            {
                getRenderer(shapeType /*i*/, g3d).render(g3d, ref rectClip, frame, displayModelIndex, shape);
            }
            //}

            g3d.Flush();
        }
Exemplo n.º 9
0
        public static int[] getShades(int rgb, bool greyScale)
        {
            int[] shades = new int[shadeMax];

            int red = (rgb >> 16) & 0xFF;
            int grn = (rgb >> 8) & 0xFF;
            int blu = rgb & 0xFF;

            float ambientRange = 1 - ambientFraction;

            shades[shadeNormal] = Shade3D.rgb(red, grn, blu);
            for (int i = 0; i < shadeNormal; ++i)
            {
                float fraction = ambientFraction + ambientRange * i / shadeNormal;
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                shades[i] = Shade3D.rgb((int)(red * fraction + 0.5f), (int)(grn * fraction + 0.5f), (int)(blu * fraction + 0.5f));
            }

            int   nSteps   = shadeMax - shadeNormal - 1;
            float redRange = (255 - red) * intenseFraction;
            float grnRange = (255 - grn) * intenseFraction;
            float bluRange = (255 - blu) * intenseFraction;

            for (int i = 1; i <= nSteps; ++i)
            {
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                shades[shadeNormal + i] = Shade3D.rgb(red + (int)(redRange * i / nSteps + 0.5f), grn + (int)(grnRange * i / nSteps + 0.5f), blu + (int)(bluRange * i / nSteps + 0.5f));
            }
            if (greyScale)
            {
                for (int i = shadeMax; --i >= 0;)
                {
                    shades[i] = NuGraphics3D.calcGreyscaleRgbFromRgb(shades[i]);
                }
            }
            return(shades);
        }
Exemplo n.º 10
0
        public /*Chem*/ Frame(Org.OpenScience.CDK.Interfaces.IChemFile chemFile, Device graphicsDevice)
        {
            shapes             = new Shape[JmolConstants.SHAPE_MAX];
            this.g3d           = new NuGraphics3D(graphicsDevice);
            this.frameRenderer = new FrameRenderer();

            for (int i = MAX_BONDS_LENGTH_TO_CACHE; --i > 0;)  // .GT. 0
            {
                freeBonds[i] = new Bond[MAX_NUM_TO_CACHE][];
            }

            // convert to jmol native
            mmset = new Mmset(this);

            // set properties
            mmset.ModelSetProperties = new System.Collections.Specialized.NameValueCollection();

            // init build
            currentModelIndex          = -1;
            currentModel               = null;
            currentChainID             = '\uFFFF';
            currentChain               = null;
            currentGroupSequenceNumber = -1;
            currentGroupInsertionCode  = '\uFFFF';

            int atomCountEstimate = 0;

            for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++)
            {
                for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++)
                {
                    Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model];
                    for (int atomC = 0; atomC < chemModel.SetOfMolecules.AtomContainerCount; atomC++)
                    {
                        atomCountEstimate += chemModel.SetOfMolecules.AtomContainers[atomC].AtomCount;
                    }
                }
            }

            if (atomCountEstimate <= 0)
            {
                atomCountEstimate = ATOM_GROWTH_INCREMENT;
            }
            atoms = new Atom[atomCountEstimate];
            bonds = new Bond[2 * atomCountEstimate];
            htAtomMap.Clear();

            // translate IChemSequence[] into Model[]
            mmset.ModelCount = chemFile.ChemSequenceCount;
            for (int seq = 0; seq < chemFile.ChemSequenceCount; ++seq)
            {
                int    modelNumber = seq + 1;
                string modelName   = modelNumber.ToString();
                NameValueCollection modelProperties = new NameValueCollection();    // FIXME: Loading property values
                mmset.setModelNameNumberProperties(seq, modelName, modelNumber, modelProperties);
            }

            // translate Atoms
            Dictionary <Org.OpenScience.CDK.Interfaces.IAtom, Atom> atomsList = new Dictionary <Org.OpenScience.CDK.Interfaces.IAtom, Atom>();

            //try
            //{
            for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++)
            {
                for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++)
                {
                    Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model];
                    for (int atomC = 0; atomC < chemModel.SetOfMolecules.AtomContainerCount; atomC++)
                    {
                        for (int atomIdx = 0; atomIdx < chemModel.SetOfMolecules.AtomContainers[atomC].AtomCount; atomIdx++)
                        {
                            Org.OpenScience.CDK.Interfaces.IAtom atom = chemModel.SetOfMolecules.AtomContainers[atomC].Atoms[atomIdx];

                            sbyte elementNumber = (sbyte)atom.AtomicNumber;
                            if (elementNumber <= 0)
                            {
                                elementNumber = JmolConstants.elementNumberFromSymbol(atom.Symbol);
                            }
                            char alternateLocation = '\0';

                            int  sequenceNumber     = int.MinValue;
                            char groupInsertionCode = '\0';

                            string atomName   = null;
                            string group3Name = null;
                            char   chainID    = '\0';
                            if (atom is PDBAtom)
                            {
                                PDBAtom pdbAtom = (PDBAtom)atom;
                                if (pdbAtom.ResSeq != null && pdbAtom.ResSeq.Length > 0)
                                {
                                    sequenceNumber = int.Parse(pdbAtom.ResSeq);
                                }
                                if (pdbAtom.ICode != null && pdbAtom.ICode.Length > 0)
                                {
                                    groupInsertionCode = pdbAtom.ICode[0];
                                }

                                atomName   = pdbAtom.Name;
                                group3Name = pdbAtom.ResName;
                                if (pdbAtom.ChainID != null && pdbAtom.ChainID.Length >= 1)
                                {
                                    chainID = pdbAtom.ChainID[0];
                                }
                            }
                            else
                            {
                                atomName = atom.AtomTypeName;
                            }

                            atomsList[atom] = AddAtom(model, atom, elementNumber, atomName, atom.getFormalCharge(),
                                                      (float)atom.getCharge(), 100, float.NaN, (float)atom.X3d, (float)atom.Y3d,
                                                      (float)atom.Z3d, false, int.MinValue, chainID, group3Name, sequenceNumber,
                                                      groupInsertionCode, float.NaN, float.NaN, float.NaN, alternateLocation, null);
                        }
                    }
                }
            }
            //}
            //catch (Exception e)
            //{
            //    throw new ApplicationException("Problem translating atoms", e);
            //}

            fileHasHbonds = false;

            // translate bonds
            try
            {
                for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++)
                {
                    for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++)
                    {
                        Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model];

                        for (int atomC = 0; atomC < chemModel.SetOfMolecules.AtomContainerCount; atomC++)
                        {
                            for (int bondIdx = 0; bondIdx < chemModel.SetOfMolecules.AtomContainers[atomC].Bonds.Length; bondIdx++)
                            {
                                Org.OpenScience.CDK.Interfaces.IBond   bond     = chemModel.SetOfMolecules.AtomContainers[atomC].Bonds[bondIdx];
                                Org.OpenScience.CDK.Interfaces.IAtom[] cdkAtoms = bond.getAtoms();
                                // locate translated atoms
                                Atom atom1, atom2;
                                atomsList.TryGetValue(cdkAtoms[0], out atom1);
                                atomsList.TryGetValue(cdkAtoms[1], out atom2);
                                bondAtoms(atom1, atom2, (int)bond.Order);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new ApplicationException("Problem translating bonds", e);
            }
            atomsList.Clear();

            // translate structures of PDBPolymer only
            for (int seq = 0; seq < chemFile.ChemSequenceCount; seq++)
            {
                for (int model = 0; model < chemFile.ChemSequences[seq].ChemModelCount; model++)
                {
                    Org.OpenScience.CDK.Interfaces.IChemModel chemModel = chemFile.ChemSequences[seq].ChemModels[model];

                    foreach (Org.OpenScience.CDK.Interfaces.IMolecule molecule in chemModel.SetOfMolecules.Molecules)
                    {
                        if (molecule is PDBPolymer)
                        {
                            PDBPolymer pdbPolymer = (PDBPolymer)molecule;
                            if (pdbPolymer.Structures != null && pdbPolymer.Structures.Count > 0)
                            {
                                structuresDefined = true;
                                foreach (PDBStructure pdbStruct in pdbPolymer.Structures)
                                {
                                    structuresDefined = true;
                                    mmset.defineStructure(pdbStruct.StructureType, pdbStruct.StartChainID,
                                                          pdbStruct.StartSequenceNumber, pdbStruct.StartInsertionCode,
                                                          pdbStruct.EndChainID, pdbStruct.EndSequenceNumber, pdbStruct.EndInsertionCode);
                                }
                            }
                        }
                    }
                }
            }
            autoBond(null, null);

            // build groups
            FinalizeGroupBuild();
            BuildPolymers();
            Freeze();

            finalizeBuild();

            // create ribbon shapes
            try
            {
                setShapeSize(JmolConstants.SHAPE_RIBBONS, -1, new BitArray(0));
                setShapeSize(JmolConstants.SHAPE_CARTOON, -1, new BitArray(0));
            }
            catch (Exception) { }
        }
Exemplo n.º 11
0
 public Cylinder3D(NuGraphics3D g3d)
 {
     this.g3d = g3d;
 }