コード例 #1
0
ファイル: CellPackLoader.cs プロジェクト: pmindek/cellVIEWcut
    public static void AddCurveIngredients(JSONNode ingredientDictionary, params string[] pathElements)
    {
        var name      = ingredientDictionary["name"];
        var path      = MyUtility.GetUrlPath(pathElements.ToList(), name);
        var numCurves = ingredientDictionary["nbCurve"].AsInt;
        var pdbName   = ingredientDictionary["source"]["pdb"].Value.Replace(".pdb", "");

        SceneManager.Get.AddCurveIngredient(path, pdbName);

        for (int i = 0; i < numCurves; i++)
        {
            //if (i < nCurve-10) continue;
            var controlPoints = new List <Vector4>();
            if (ingredientDictionary["curve" + i.ToString()].Count < 4)
            {
                continue;
            }

            for (int k = 0; k < ingredientDictionary["curve" + i.ToString()].Count; k++)
            {
                var p = ingredientDictionary["curve" + i.ToString()][k];
                controlPoints.Add(new Vector4(-p[0].AsFloat, p[1].AsFloat, p[2].AsFloat, 1));
            }

            SceneManager.Get.AddCurveIntance(path, controlPoints);
            //break;
        }

        Debug.Log("*****");
        Debug.Log("Added curve ingredient: " + path);
        Debug.Log("Num curves: " + numCurves);
    }
コード例 #2
0
ファイル: CellPackLoader.cs プロジェクト: pmindek/cellVIEWcut
    public static void AddProteinIngredient(JSONNode ingredientDictionary, params string[] pathElements)
    {
        var name    = ingredientDictionary["name"];
        var path    = MyUtility.GetUrlPath(pathElements.ToList(), name);
        var biomt   = (bool)ingredientDictionary["source"]["biomt"].AsBool;
        var center  = (bool)ingredientDictionary["source"]["transform"]["center"].AsBool;
        var pdbName = ingredientDictionary["source"]["pdb"].Value.Replace(".pdb", "");

        List <Vector4>   atomSpheres;
        List <Matrix4x4> biomtTransforms     = new List <Matrix4x4>();
        Vector3          biomtCenter         = Vector3.zero;
        bool             containsACarbonOnly = false;
        bool             oneLOD = false;

        if ((pdbName == "") || (pdbName == "null") || (pdbName == "None") || pdbName.StartsWith("EMDB"))
        {
            return;

            ////check for sphere file//information in the file. if not in file is it on disk ? on repo ?
            ////possibly read the actuall recipe definition ?
            ////check if bin exist
            //var filePath = PdbLoader.DefaultPdbDirectory + ingredientDictionary["name"] + ".bin";
            //if (File.Exists(filePath)){
            //	atomSpheres = new List<Vector4>();
            //	var points = MyUtility.ReadBytesAsFloats(filePath);
            //	for (var i = 0; i < points.Length; i += 4) {
            //		var currentAtom = new Vector4 (points [i], points [i + 1], points [i + 2], points [i + 3]);
            //		atomSpheres.Add (currentAtom);
            //	}
            //	containsACarbonOnly = true;
            //	oneLOD = true;
            //}
            //else if (ingredientDictionary ["radii"] != null) {
            //	atomSpheres = MyUtility.gatherSphereTree(ingredientDictionary)[0];
            //	Debug.Log ("nbprim "+atomSpheres.Count.ToString());//one sphere
            //	oneLOD = true;
            //} else {
            //	float radius = 30.0f;
            //	if (name.Contains("dLDL"))
            //		radius = 108.08f;//or use the mesh? or make sphere from the mesh ?
            //	if (name.Contains("iLDL"))
            //		radius = 105.41f;//or use the mesh? or make sphere from the mesh ?
            //	atomSpheres = new List<Vector4>();
            //	atomSpheres.Add (new Vector4(0,0,0,radius));
            //	//No LOD since only one sphere
            //	oneLOD = true;
            //}
        }
        else
        {
            //if (pdbName.StartsWith("EMDB")) return;
            //if (pdbName.Contains("1PI7_1vpu_biounit")) return;//??
            // Load atom set from pdb file
            var atomSet = PdbLoader.LoadAtomSet(pdbName);

            // If the set is empty return
            if (atomSet.Count == 0)
            {
                return;
            }

            atomSpheres         = AtomHelper.GetAtomSpheres(atomSet);
            containsACarbonOnly = AtomHelper.ContainsCarbonAlphaOnly(atomSet);
        }
        var centerPosition = AtomHelper.ComputeBounds(atomSpheres).center;

        // Center atoms
        AtomHelper.OffsetSpheres(ref atomSpheres, centerPosition);

        // Compute bounds
        var bounds = AtomHelper.ComputeBounds(atomSpheres);

        biomtTransforms = biomt ? PdbLoader.LoadBiomtTransforms(pdbName) : new List <Matrix4x4>();
        biomtCenter     = AtomHelper.GetBiomtCenter(biomtTransforms, centerPosition);

        //if (!pdbName.Contains("1TWT_1TWV")) return;

        // Disable biomts until loading problem is resolved
        //if (!biomt) return;


        // Get ingredient color
        // TODO: Move color palette code into dedicated function
        var cid = ColorPaletteGenerator.GetRandomUniqFromSample(current_color, usedColors[current_color]);

        usedColors[current_color].Add(cid);
        var sample = ColorPaletteGenerator.colorSamples[cid];
        var c      = ColorPaletteGenerator.lab2rgb(sample) / 255.0f;
        var color  = new Color(c[0], c[1], c[2]);

        // Define cluster decimation levels
        var clusterLevels = (containsACarbonOnly)
                ? new List <float>()
        {
            0.85f, 0.25f, 0.1f
        }
            : new List <float>()
        {
            0.15f, 0.10f, 0.05f
        };

        if (oneLOD)
        {
            clusterLevels = new List <float> ()
            {
                1, 1, 1
            }
        }
        ;
        // Add ingredient type
        //SceneManager.Instance.AddIngredient(name, bounds, atomSpheres, color);

        SceneManager.Get.AddProteinIngredient(path, bounds, atomSpheres, color, clusterLevels, oneLOD);
        int instanceCount = 0;

        for (int k = 0; k < ingredientDictionary["results"].Count; k++)
        {
            var p = ingredientDictionary["results"][k][0];
            var r = ingredientDictionary["results"][k][1];

            var position = new Vector3(-p[0].AsFloat, p[1].AsFloat, p[2].AsFloat);
            var rotation = new Quaternion(r[0].AsFloat, r[1].AsFloat, r[2].AsFloat, r[3].AsFloat);

            var mat   = MyUtility.quaternion_matrix(rotation);
            var euler = MyUtility.euler_from_matrix(mat);
            rotation = MyUtility.MayaRotationToUnity(euler);

            if (!biomt)
            {
                // Find centered position
                if (!center)
                {
                    position += MyUtility.QuaternionTransform(rotation, centerPosition);
                }
                SceneManager.Get.AddProteinInstance(path, position, rotation);
                instanceCount++;
            }
            else
            {
                foreach (var transform in biomtTransforms)
                {
                    var biomteuler = MyUtility.euler_from_matrix(transform);
                    var rotBiomt   = MyUtility.MayaRotationToUnity(biomteuler);
                    var offset     = MyUtility.QuaternionTransform(rotBiomt, centerPosition);               //Helper.RotationMatrixToQuaternion(matBiomt), GetCenter());
                    var posBiomt   = new Vector3(-transform.m03, transform.m13, transform.m23) + offset - biomtCenter;

                    var biomtOffset      = MyUtility.RotationMatrixToQuaternion(transform) * centerPosition;
                    var biomtInstanceRot = rotation * rotBiomt;                    //Helper.RotationMatrixToQuaternion(transform);
                    var biomtInstancePos = rotation * posBiomt + position;

                    SceneManager.Get.AddProteinInstance(path, biomtInstancePos, biomtInstanceRot);
                    instanceCount++;
                }
            }
        }

        SceneManager.Get.AddIngredientProperties(atomSpheres.Count, instanceCount);

        Debug.Log("*****");
        Debug.Log("Added ingredient: " + path);

        //if (isCarbonAlphaOnly) Debug.Log("Alpha-carbons only");
        //Debug.Log("Pdb name: " + pdbName + " *** " + "Num atoms: " + atomSet.Count + " *** " + "Num instances: " + instanceCount + " *** " + "Total atom count: " + atomSet.Count * instanceCount);
    }