public void GeneratePointPressed()
    {
        string[] newRecord = new string[createdRecordAttributes.Count];
        for (int i = 0; i < createdRecordAttributes.Count; i++)
        {
            newRecord[i] = createdRecordAttributes[i].AttributeValue.text;
        }
        GameObject newNode    = NodeHandler.Graphcontroller.GenerateNode();
        NodePhysX  nodeScript = newNode.GetComponent <NodePhysX>();

        // Debug.Log("found script: " + nodeScript.name);

        // adds the next record from persistantdata loaded data file
        nodeScript.setDataPoint(DataTypes.ADDED_DATA, NodeHandler.Persistantdata.MinMaxData, newRecord,
                                NodeHandler.Persistantdata.DatasetNames, NodeHandler.Persistantdata.Types, NodeHandler.DataCluster, NodeHandler);
        NodeHandler.AddedDataPointsCoordinator.OriginType = DataTypes.ADDED_DATA;
        NodeHandler.AddedDataPointsCoordinator.Records.Add(newNode);
        if (NodeHandler.ClusteringOn) // if in cluster, inform cluster
        {
            NodeHandler.DataCluster.PointsTotal++;
        }

        string newID = "Generated_" + (NodeHandler.AddedDataPointsCoordinator.Count + 1);

        foreach (CreateAttributeItemController controller in createdRecordAttributes)
        {
            if (controller.AttributeType.Contains(DataTypes.ID))
            {
                controller.AttributeValue.text = newID;
            }
        }
        RandomizeAllAttributeValues();
        AddSimulatedToList(newRecord, newNode);
        GeneratedCountText.text = NodeHandler.AddedDataPointsCoordinator.Count.ToString();
    }
示例#2
0
    public void GeneFindAssociations()
    {
        //   Debug.Log("Finding gene to record associations " + ID + " " + _associations.Count);
        if (ID != null && _associations != null)
        {
            // create new list (also prevents repeat search)
            List <string[]> matches;

            // if associations has a match for this record, search all other datapoints
            if (_associations.TryGetValue(ID.ToLower(), out matches))
            {
                //     Debug.Log("Found match in associations");
                // check each record for a match
                foreach (GameObject record in _nodeHandler.DataPointsCoordinator.Records)
                {
                    NodePhysX dataPoint = record.GetComponent <NodePhysX>();
                    // check all found associations to this point for match to checked record
                    foreach (string[] match in matches)
                    {
                        // if current check record is a match to association
                        if (match[1].ToLower() == "pd" && match[0].ToLower() == dataPoint.ID.ToLower())
                        {
                            Debug.Log("Found gene to record match " + match[0].ToLower() + " : " + dataPoint.ID.ToLower());

                            // make sure link doesn't alread exist
                            bool exists = false;
                            foreach (GameObject linkToGene in dataPoint.LinksToGenes)
                            {
                                Link assLink = linkToGene.GetComponent <Link>();
                                if (assLink.source == gameObject && assLink.target == record)
                                {
                                    exists = true;
                                }
                                if (assLink.target == gameObject && assLink.source == record)
                                {
                                    exists = true;
                                }
                            }

                            // if it doesn't exist, make a new one
                            if (!exists)
                            {
                                GameObject newLink = Instantiate(LinkPrefab, new Vector3(0, 0, 0), Quaternion.identity);
                                Link       linkScr = newLink.GetComponent <Link>();
                                linkScr.source    = record;
                                linkScr.target    = gameObject;
                                linkScr.lineColor = Color.green;
                                dataPoint.LinksToGenes.Add(newLink);
                                linkCount.text = (int.Parse(linkCount.text) + 1).ToString();
                                GeneAssociatedRecords++;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
        public void DestroyDataPoint(GameObject record)
        {
            if (!Records.Contains(record))
            {
                Debug.Log("Record not found");
                return;
            }
            _records.Remove(record);
            // destroy any cluster links
            NodePhysX recordScript = record.GetComponent <NodePhysX>();

            recordScript.DestroyCentroidLinks();
            recordScript.DestroyAssociationLinks();
            recordScript.DestroyGeneLinks();

            // destroy the record
            UnityEngine.Object.Destroy(record);
        }
        public void DestroyDataPoint(int index)
        {
            if (index >= Count)
            {
                Debug.Log("index greater than records count");
                return;
            }
            GameObject removeRecord = _records[index];

            _records.RemoveAt(index);

            // destroy any cluster links
            NodePhysX recordScript = removeRecord.GetComponent <NodePhysX>();

            recordScript.DestroyCentroidLinks();
            recordScript.DestroyAssociationLinks();
            recordScript.DestroyGeneLinks();

            // destroy the record
            UnityEngine.Object.Destroy(removeRecord);
        }
示例#5
0
    public void DestroyGeneLinks()
    {
        foreach (GameObject geneLink in LinksToGenes)
        {
            Link      gLink           = geneLink.GetComponent <Link>();
            NodePhysX gLinkTargetGene = gLink.target.GetComponent <NodePhysX>();
            // Debug.Log("Destroying gene link " + ID);
            // Debug.Log("Target gene count " + gLinkTargetGene.GeneAssociatedRecords.ToString());
            gLinkTargetGene.GeneAssociatedRecords--;
            if (gLinkTargetGene.GeneAssociatedRecords == 0)
            {
                //   Debug.Log("Destroying gene " + gLinkTargetGene.ID);
                Destroy(gLinkTargetGene.gameObject);
                _nodeHandler.GenePointsCoordinator.Records.Remove(gLinkTargetGene.gameObject);
                geneCount.text = (int.Parse(geneCount.text) - 1).ToString();
            }

            Destroy(geneLink);
            linkCount.text = (int.Parse(linkCount.text) - 1).ToString();
        }
        LinksToGenes = new List <GameObject>();
    }
    public void UpdateLinks()
    {
        ///<summary>
        /// The purpose of this function is to add, destroy, and hide links as necessary by iterating through the nodes list and checking the status of each node.
        /// Thought about creating a bunch of "status lists", but that would simply result in a ton of linear searches anyway.
        /// </summary>

        foreach (GraphNodeType node in nodes)
        {
            GameObject nodeObj = node.getObject();
            // Is the object flagged for deletion?
            NodePhysX nodeInfo = nodeObj.GetComponent <NodePhysX>();
            if (nodeInfo.delete)
            {
                print("Destroying " + node.name);
                nodes.Remove(node);
                Destroy(node);
            }
            else if (nodeInfo.hide)
            {
                // Hide the mesh+collider
                print("Hiding " + node.name);
                nodeObj.SetActive(false);
                nodeInfo.hide = false;
            }

            else if (nodeInfo.unHide && nodeObj.activeSelf == false)
            {
                // Hide the mesh+collider
                print("Un-Hiding " + node.name);
                nodeObj.SetActive(true);
                nodeInfo.unHide = false;
                // re-create the link
                CreateLink(nodeObj, nodeInfo.root);
            }
        }
        // After we're all done, remove the links.
        ScrubLinks();
    }
        public bool DestroyLastDataPoint()
        {
            if (_records.Count == 0)
            {
                return(false);
            }

            GameObject removeRecord = _records[Count - 1];

            _records.RemoveAt(Count - 1);

            // destroy any cluster links
            NodePhysX recordScript = removeRecord.GetComponent <NodePhysX>();

            recordScript.DestroyCentroidLinks();
            recordScript.DestroyAssociationLinks();
            recordScript.DestroyGeneLinks();

            // destroy the record
            UnityEngine.Object.Destroy(removeRecord);
            return(true);
        }
示例#8
0
    void doRayCast()
    {
        PointerEventData     pointer    = new PointerEventData(EventSystem.current);
        List <RaycastResult> targetsHit = GetRaycastTargets(pointer);

        if (targetsHit.Count > 0)
        {
            _targetSelected = targetsHit[0].gameObject;

            if (Input.GetKeyDown("space") || Input.GetMouseButtonDown(0))
            {
                if (_targetSelected.GetComponent <IPointerClickHandler>() != null)
                {
                    _targetSelected.GetComponent <IPointerClickHandler>().OnPointerClick(pointer);
                }

                else if (_targetSelected.GetComponentInParent <IPointerClickHandler>() != null)
                {
                    _targetSelected.GetComponentInParent <IPointerClickHandler>().OnPointerClick(pointer);
                }
            }
        }
        Ray        ray = vrcam.ScreenPointToRay(pointer.position);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            if (hit.collider.tag == "node")
            {
                NodePhysX nodescript = hit.collider.GetComponentInParent <NodePhysX>();
                if (nodescript != null)
                {
                    LayoutPanel.GetComponent <DatapointInfoPanelScript>().SetValues(nodescript.RecordValues);
                }
            }
        }
    }
示例#9
0
    public void UpdateDataDataAssociations()
    {
        // check to see if associations need to be found
        if (ID != null && _associations != null)
        {
            // create new list (also prevents repeat search)
            List <string[]> matches;

            // if associations has a match for this record, search all other datapoints
            if (_associations.TryGetValue(ID, out matches))
            {
                // check each record for a match
                foreach (GameObject record in _nodeHandler.DataPointsCoordinator.Records)
                {
                    NodePhysX dataPoint = record.GetComponent <NodePhysX>();
                    // check all found associations to this point for match to checked record
                    foreach (string[] match in matches)
                    {
                        // if current check record is a match to association
                        if (match[0].ToLower() == dataPoint.ID.ToLower())
                        {
                            // make sure link doesn't alread exist
                            bool exists = false;
                            foreach (GameObject linkToAssociation in LinksToAssociations)
                            {
                                Link assLink = linkToAssociation.GetComponent <Link>();
                                if (assLink.source == gameObject && assLink.target == record)
                                {
                                    exists = true;
                                }
                                if (assLink.target == gameObject && assLink.source == record)
                                {
                                    exists = true;
                                }
                            }

                            // if it doesn't exist, make a new one
                            if (!exists)
                            {
                                GameObject newLink = Instantiate(LinkPrefab, new Vector3(0, 0, 0), Quaternion.identity);
                                Link       linkScr = newLink.GetComponent <Link>();
                                linkScr.source    = gameObject;
                                linkScr.target    = record;
                                linkScr.lineColor = Color.red;
                                LinksToAssociations.Add(newLink);
                                linkCount.text = (int.Parse(linkCount.text) + 1).ToString();


                                bool targetHasLink = false;

                                // check if target has this link already add if not
                                foreach (GameObject linkToAssociation in dataPoint.LinksToAssociations)
                                {
                                    Link assLink = linkToAssociation.GetComponent <Link>();
                                    if (assLink.source == gameObject && assLink.target == record)
                                    {
                                        targetHasLink = true;
                                    }
                                    if (assLink.target == gameObject && assLink.source == record)
                                    {
                                        targetHasLink = true;
                                    }
                                }
                                if (!targetHasLink)
                                {
                                    dataPoint.LinksToAssociations.Add(newLink);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
示例#10
0
    public void UpdateDataGeneAssociations()
    {
        if (ID != null && _associations != null)
        {
            List <string[]> matches;

            // see if associations exist for this datapoint
            if (_associations.TryGetValue(ID, out matches))
            {
                bool          foundAssociatedGene = false;
                List <string> foundGeneIds        = new List <string>();
                // check all gene records to see if exists already
                foreach (GameObject geneRecordObject in _nodeHandler.GenePointsCoordinator.Records)
                {
                    NodePhysX genePoint = geneRecordObject.GetComponent <NodePhysX>();
                    //     Debug.Log("Existing gene id " + genePoint.ID);

                    // check if check gene is in this association's matches
                    foreach (string[] match in matches)
                    {
                        // if current check gene is a match to association
                        if (genePoint.ID.ToLower() == match[0].ToLower())
                        {
                            foundGeneIds.Add(genePoint.ID.ToLower());
                            foundAssociatedGene = true;
                            bool exists = false;
                            // check if link already exists in this point
                            foreach (GameObject geneLink in LinksToGenes)
                            {
                                Link assLink = geneLink.GetComponent <Link>();
                                if (assLink.source == gameObject && assLink.target == geneRecordObject)
                                {
                                    exists = true;
                                }
                                if (assLink.target == gameObject && assLink.source == geneRecordObject)
                                {
                                    exists = true;
                                }
                            }
                            if (!exists)
                            {
                                GameObject newLink = Instantiate(LinkPrefab, new Vector3(0, 0, 0), Quaternion.identity);
                                Link       linkScr = newLink.GetComponent <Link>();
                                linkScr.source    = gameObject;
                                linkScr.target    = geneRecordObject;
                                linkScr.lineColor = Color.green;
                                LinksToGenes.Add(newLink);
                                genePoint.GeneAssociatedRecords++;
                                linkCount.text = (int.Parse(linkCount.text) + 1).ToString();
                                break;
                            }
                        }
                    }
                }
                if (!foundAssociatedGene)
                {
                    foreach (string[] match in matches)
                    {
                        if (!foundGeneIds.Contains(match[0].ToLower()) && match[1] == "pd")
                        {
                            GameObject newGeneObject = graphControl.GenerateNode();
                            NodePhysX  newGeneScript = newGeneObject.GetComponent <NodePhysX>();
                            newGeneScript.OriginType = DataTypes.GENE;
                            GameObject newLink = Instantiate(LinkPrefab, new Vector3(0, 0, 0), Quaternion.identity);
                            Link       linkScr = newLink.GetComponent <Link>();

                            linkScr.source    = gameObject;
                            linkScr.target    = newGeneObject;
                            linkScr.lineColor = Color.green;
                            LinksToGenes.Add(newLink);
                            newGeneScript.LinksToGenes  = new List <GameObject>();
                            newGeneScript._originType   = DataTypes.GENE;
                            newGeneScript._associations = _associations;
                            newGeneScript._nodeHandler  = _nodeHandler;
                            newGeneScript.ID            = match[0].ToLower();
                            newGeneScript.GeneFindAssociations();
                            newGeneScript.GeneAssociatedRecords++;
                            _nodeHandler.GenePointsCoordinator.Records.Add(newGeneObject);
                            // Debug.Log("Count genepoints: " + _nodeHandler.GenePointsCoordinator.Count);
                            linkCount.text = (int.Parse(linkCount.text) + 1).ToString();
                            geneCount.text = (int.Parse(geneCount.text) + 1).ToString();
                            //Debug.Log(ID + " creating new gene and link to " + match[0].ToLower());
                        }
                    }
                }
            }
        }
    }
示例#11
0
    // Update file data points on toggle clicks.
    // This only updates records loaded from data file.
    void UpdateRenderFileDataPoints()
    {
        MinMaxAttributes = Persistantdata.MinMaxData;

        Debug.Log("Updating points in nodehandler");
        // if file data points rendering turned off, destroy all the points and links
        if (!RenderFileDataPoints && DataPointsCoordinator.Count > 0)
        {
            while (DataPointsCoordinator.DestroyLastDataPoint())
            {
                if (ClusteringOn) // if clustering, inform cluster
                {
                    DataCluster.PointsTotal--;
                }
            }
            CheckForRenderDataUpdate = false;
        }
        // if points to render is lower than points already rendered, destroy last point
        else if (RenderFileDataPoints && DataPointsCoordinator.Count > MaxRenderDatapoints)
        {
            DataPointsCoordinator.DestroyLastDataPoint();

            if (ClusteringOn) // if in cluster, inform cluster
            {
                DataCluster.PointsTotal--;
            }

            if (DataPointsCoordinator.Count <= MaxRenderDatapoints)
            {
                CheckForRenderDataUpdate = false;
            }
        }
        // if points rendered is below max, create a point
        else if (RenderFileDataPoints && DataPointsCoordinator.Count < MaxRenderDatapoints)
        {
            // if no more file records
            if (Persistantdata.RecordValues.Count <= DataPointsCoordinator.Count)
            {
                CheckForRenderDataUpdate = false;
            }

            // else add a new record
            else
            {
                GameObject newNode    = Graphcontroller.GenerateNode();
                NodePhysX  nodeScript = newNode.GetComponent <NodePhysX>();
                // Debug.Log("found script: " + nodeScript.name);

                // adds the next record from persistantdata loaded data file
                nodeScript.setDataPoint(DataTypes.FILE_DATA, MinMaxAttributes, Persistantdata.RecordValues[DataPointsCoordinator.Count],
                                        Persistantdata.DatasetNames, Persistantdata.Types, DataCluster, this);

                DataPointsCoordinator.Records.Add(newNode);

                if (ClusteringOn) // if in cluster, inform cluster
                {
                    DataCluster.PointsTotal++;
                }

                // Debug.Log("Rendered: " + DataPointsCoordinator.Count + " of " + RenderDatapointsCount);

                if (DataPointsCoordinator.Count >= MaxRenderDatapoints)
                {
                    CheckForRenderDataUpdate = false;
                }

                if (PPLinksActive)
                {
                    nodeScript.UpdateDataDataAssociations();
                }

                if (PGLinksActive)
                {
                    nodeScript.UpdateDataGeneAssociations();
                }
            }
        }
        // if no change needed, stop updating
        else
        {
            CheckForRenderDataUpdate = false;
        }
    }