Ejemplo n.º 1
0
    /// <summary>
    /// 初始化帧到第一帧
    /// </summary>
    private void modelInitReloadALLFrame()
    {
        GlobalVariableBackground.Instance.conManager.WriteLog("帧初始化开始");
        if (vtkAllFrame.listFrame.Count == 0)
        {
            return;
        }
        lastIndex = 0;
        GlobalVariableBackground.Instance.FrameAllIndex = 0;
        //vtkAllFrame.ClearListFrame();
        //vtkAllFrame.listFrame =new List<VTK_Frame>();
        for (int i = 0; i < GlobalVariableBackground.Instance.modelCacheCount; i++)
        {
            modelFrameManager modelFrameManager = transform.GetChild(i).GetComponent <modelFrameManager>();
            if (modelFrameManager == null)
            {
                transform.GetChild(i).gameObject.AddComponent <modelFrameManager>();
                modelFrameManager.vtkframe   = new VTK_Frame();
                modelFrameManager.isCollider = vtkAllFrame.loadFile.dataType == Enums.DataType.Default;
            }
            else
            {
                if (modelFrameManager.isCutModelGO)
                {
                    //transform.GetChild(i) 里面含有切割生成的对象
                    continue;
                }
            }
            VTK_Frame vtkframe = modelFrameManager.vtkframe;
            vtkframe.go = transform.GetChild(i).gameObject;

            //vtkAllFrame.listFrame.Add(vtkframe);
            Others.ThreadLoadFilePack pack = new Others.ThreadLoadFilePack();

            //填充 线程数据包-》单帧
            pack.vtkFrame = vtkframe;

            pack.vtkAllFrame = vtkAllFrame;

            DirectoryInfo folder = new DirectoryInfo(vtkAllFrame.loadFile.FileDir);
            FileInfo[]    fileinfoArray;
            fileinfoArray = folder.GetFiles("*.qf");

            Array.Sort(fileinfoArray, new FileNameSort());

            //填充 线程数据包-》单一文件
            pack.fileAddres = fileinfoArray[i];
            //
            vtkframe.selfFrameIndex = i;

            VTKCManager m = new VTKCManager();
            vtkframe.timeStartLession = DateTime.Now;
            ThreadPool.QueueUserWorkItem(new WaitCallback(m.DisposeData), pack as object);
        }
        //GlobalVariableBackground.Instance.conManager.WriteLog("帧初始化任务分发完毕");
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 获取文件列表
    /// </summary>
    public void VTKGetFileList(Structure_LoadFile structure_loadFile)
    {
        if (structure_loadFile.FileDir == null)
        {
            return;
        }

        List <Others.MaxAndMin> listm = new List <Others.MaxAndMin>();

        if (structure_loadFile.dataType == Enums.DataType.Default)
        {
            StreamReader sr;
            string       file_name = structure_loadFile.FileDir + @"\Arr.mm";
            sr = File.OpenText(file_name);
            string strAboutAttMaxMin = sr.ReadLine();
            sr.Close();
            sr.Dispose();

            string[]         strTempArray = strAboutAttMaxMin.Trim().Split(' ');
            Others.MaxAndMin mn;
            for (int i = 0; i < strTempArray.Length;)
            {
                mn            = new Others.MaxAndMin();
                mn.Attname    = strTempArray[i++];
                mn.Dimension  = Convert.ToInt32(strTempArray[i++]);
                mn.isPointAtt = strTempArray[i++].Contains("point");
                mn.Min        = Convert.ToSingle(strTempArray[i++]);
                mn.Max        = Convert.ToSingle(strTempArray[i++]);
                listm.Add(mn);
            }
        }
        structure_loadFile.name = GetSameName(structure_loadFile.FileDir);

        string extensionName = "*.qf";

        //switch (structure_loadFile.fileType)
        //{
        //    case Enums.FileType.Tecplot:
        //        extensionName = "*.dat";
        //        break;
        //    case Enums.FileType.VTK:
        //        extensionName = "*.vtk";
        //        break;
        //    default:
        //        break;
        //}

        //创建所有帧对象
        VTK_AllFrame AllFrame = new VTK_AllFrame();

        AllFrame.point_MaxAndMin = listm;

        AllFrame.modelState = new Others.ModelState();
        int pointAttIndex = 0;
        int cellAttIndex  = 0;

        for (int i = 0; i < listm.Count; i++)
        {
            if (listm[i].Dimension == 1)
            {
                AllFrame.modelState.isUsecolor = true;
                AllFrame.modelState.isPointAtt = listm[i].isPointAtt;
                if (listm[i].isPointAtt)
                {
                    AllFrame.modelState.attIndex = pointAttIndex;
                }
                else
                {
                    AllFrame.modelState.attIndex = cellAttIndex;
                }
                AllFrame.modelState.maxminIndex = i;
                break;
            }
            else
            {
                if (listm[i].isPointAtt)
                {
                    pointAttIndex++;
                }
                else
                {
                    cellAttIndex++;
                }
            }
        }

        AllFrame.listFrame = new List <VTK_Frame>();

        AllFrame.name = structure_loadFile.name;

        //创建 场景中的 数据模型载体
        GameObject newNodel = new GameObject();

        newNodel.name             = structure_loadFile.name;
        newNodel.transform.parent = transform;
        //挂上 功能脚本
        modelGameObject modelgo = newNodel.AddComponent <modelGameObject>();

        modelgo.vtkAllFrame = AllFrame;
        AllFrame.loadFile   = structure_loadFile;


        DirectoryInfo folder = new DirectoryInfo(structure_loadFile.FileDir);

        FileInfo[] fileinfoArray = folder.GetFiles(extensionName);
        Array.Sort(fileinfoArray, new FileNameSort());

        AllFrame.FileCount = fileinfoArray.Length;

        GlobalVariableBackground.Instance.FrameALLCount = fileinfoArray.Length;

        //加载指定缓存数量的模型数据
        for (int i = 0; i < GlobalVariableBackground.Instance.modelCacheCount; i++)
        {
            GameObject goModelFrame;
            //生成 线程数据包
            goModelFrame = GameObject.Instantiate(GlobalVariableBackground.Instance.modelPerfab);

            goModelFrame.transform.parent = newNodel.transform;

            modelFrameManager modelManager = goModelFrame.AddComponent <modelFrameManager>();
            goModelFrame.AddComponent <ClickGameObjectEvent>();
            modelManager.modelState = AllFrame.modelState;

            Others.ThreadLoadFilePack pack = new Others.ThreadLoadFilePack();

            //pack.strAboutArrMAxMin = strAboutAttMaxMin;

            //创建 单帧
            VTK_Frame frame = new VTK_Frame();
            frame.point_MaxAndMin = AllFrame.point_MaxAndMin;
            modelManager.vtkframe = frame;
            frame.go = goModelFrame;
            modelManager.isCollider = structure_loadFile.dataType == Enums.DataType.Default;
            pack.vtkAllFrame        = AllFrame;
            //填充 线程数据包-》单帧
            pack.vtkFrame = frame;
            //填充 线程数据包-》单一文件
            pack.fileAddres = fileinfoArray[i];
            int fileIndex = i;

            AllFrame.listFrame.Add(frame);

            goModelFrame.name    = AllFrame.name + "#" + fileIndex;
            frame.selfFrameIndex = fileIndex;

            VTKCManager m = new VTKCManager();
            frame.timeStartLession = DateTime.Now;
            m.DisposeData(pack);

            //Thread t = new Thread(m.DisposeData);
            //t.IsBackground = true;
            //t.Start(pack);

            //ThreadPool.QueueUserWorkItem(new WaitCallback(m.DisposeData), pack as object);
        }
        folder        = null;
        fileinfoArray = null;
    }
Ejemplo n.º 3
0
    public void loadQFFile(string fileAddress, VTK_Frame frame)
    {
        FileStream   fs              = new FileStream(fileAddress, FileMode.Open, FileAccess.Read);
        BinaryReader br              = new BinaryReader(fs);
        int          meshCount       = 0;
        int          pointArrayCount = 0;
        int          cellArrayCount  = 0;
        int          NameLength      = 0;
        int          tempCount       = 0;

        frame.minX = br.ReadSingle();
        frame.maxX = br.ReadSingle();

        frame.minZ = br.ReadSingle();
        frame.maxZ = br.ReadSingle();

        frame.minY = br.ReadSingle();
        frame.maxY = br.ReadSingle();

        //meshCount
        br.ReadChars(10);
        meshCount = br.ReadInt32();


        Thread t = new Thread(frame.MeshClear);

        t.IsBackground = true;
        t.Start();

        //frame.MeshClear();
        frame.meshArray = new CLoadTest.VTKMesh[meshCount];

        //pointArrayCount
        br.ReadChars(16);
        pointArrayCount = br.ReadInt32();

        //cellArrayCount
        br.ReadChars(15);
        cellArrayCount = br.ReadInt32();

        if (frame.pointAttType == null)
        {
            frame.pointAttType = new CLoadTest.AttributType();
        }

        if (frame.pointAttType.listAttName == null)
        {
            frame.pointAttType.listAttName  = new List <string>();
            frame.pointAttType.listAttCount = new List <int>();
        }
        else
        {
            frame.pointAttType.listAttName.Clear();
            frame.pointAttType.listAttCount.Clear();
        }

        for (int i = 0; i < pointArrayCount; i++)
        {
            NameLength = br.ReadInt32();

            frame.pointAttType.listAttName.Add(new string(br.ReadChars(NameLength)));
            frame.pointAttType.listAttCount.Add(br.ReadInt32());
        }

        if (frame.CellAttType == null)
        {
            frame.CellAttType = new CLoadTest.AttributType();
        }

        if (frame.CellAttType.listAttName == null)
        {
            frame.CellAttType.listAttName  = new List <string>();
            frame.CellAttType.listAttCount = new List <int>();
        }
        else
        {
            frame.CellAttType.listAttName.Clear();
            frame.CellAttType.listAttCount.Clear();
        }

        for (int i = 0; i < cellArrayCount; i++)
        {
            NameLength = br.ReadInt32();

            frame.CellAttType.listAttName.Add(new string(br.ReadChars(NameLength)));
            frame.CellAttType.listAttCount.Add(br.ReadInt32());
        }

        int pointCount = 0;
        int cellCount  = 0;

        for (int i = 0; i < meshCount; i++)
        {
            //mesh
            br.ReadChars(5);
            tempCount = br.ReadInt32();
            CLoadTest.VTKMesh vtkMesh = new CLoadTest.VTKMesh();
            frame.meshArray[tempCount] = vtkMesh;
            vtkMesh.meshIndex          = tempCount;
            //pointCount
            br.ReadChars(11);
            pointCount         = br.ReadInt32();
            vtkMesh.pointArray = new CLoadTest.Point_Out[pointCount];
            vtkMesh.vec3Array  = new Vector3[pointCount];
            for (int j = 0; j < pointCount; j++)
            {
                CLoadTest.Point_Out point = new CLoadTest.Point_Out();
                vtkMesh.pointArray[j] = point;
                Vector3 vec3 = new Vector3();

                vec3.x = br.ReadSingle();

                vec3.z = br.ReadSingle();

                vec3.y = br.ReadSingle();

                vtkMesh.vec3Array[j] = vec3;

                //point.color = br.ReadSingle();
                br.ReadSingle();
                point.number   = br.ReadInt32();
                point.attArray = new CLoadTest.Attribut[pointArrayCount];
                for (int k = 0; k < pointArrayCount; k++)
                {
                    CLoadTest.Attribut att = new CLoadTest.Attribut();
                    point.attArray[k] = att;

                    att.arrayData = new float[frame.pointAttType.listAttCount[k]];
                    for (int m = 0; m < frame.pointAttType.listAttCount[k]; m++)
                    {
                        att.arrayData[m] = br.ReadSingle();
                    }
                }
            }

            //cellCount
            br.ReadChars(10);
            cellCount         = br.ReadInt32();
            vtkMesh.cellArray = new CLoadTest.Cell_Out[cellCount];
            vtkMesh.triArray  = new int[cellCount * 3];
            //vtkMesh.listTri = new List<int>();
            for (int j = 0; j < cellCount; j++)
            {
                CLoadTest.Cell_Out cell = new CLoadTest.Cell_Out();
                vtkMesh.cellArray[j] = cell;
                //cell.index_1 = br.ReadInt32();
                //cell.index_2 = br.ReadInt32();
                //cell.index_3 = br.ReadInt32();

                vtkMesh.triArray[j * 3 + 2] = br.ReadInt32();
                vtkMesh.triArray[j * 3 + 1] = br.ReadInt32();
                vtkMesh.triArray[j * 3]     = br.ReadInt32();
                //vtkMesh.listTri.Add(br.ReadInt32());
                //vtkMesh.listTri.Add(br.ReadInt32());
                //vtkMesh.listTri.Add(br.ReadInt32());

                cell.number   = br.ReadInt32();
                cell.attArray = new CLoadTest.Attribut[cellArrayCount];
                for (int k = 0; k < cellArrayCount; k++)
                {
                    CLoadTest.Attribut att = new CLoadTest.Attribut();
                    cell.attArray[k] = att;

                    att.arrayData = new float[frame.CellAttType.listAttCount[k]];
                    for (int m = 0; m < frame.CellAttType.listAttCount[k]; m++)
                    {
                        att.arrayData[m] = br.ReadSingle();
                    }
                }
            }

            for (int j = 0; j < vtkMesh.pointArray.Length; j++)
            {
                if (vtkMesh.pointArray[j] == null)
                {
                    Debug.Log("读数据阶段 vtkMesh.pointArray[" + j + "] is null");
                }
            }
        }
        br.Close();
        fs.Close();
    }
Ejemplo n.º 4
0
    private void modelInitReloadAllFrameByIndex(int indexFrame)
    {
        int min, max = 0;
        int half = GlobalVariableBackground.Instance.modelCacheCount / 2;

        if (indexFrame - half < 0)
        {
            min = 0;
            max = GlobalVariableBackground.Instance.modelCacheCount - 1;
        }
        else if (indexFrame + half > vtkAllFrame.FileCount)
        {
            min = vtkAllFrame.FileCount - 1 - GlobalVariableBackground.Instance.modelCacheCount;
            max = vtkAllFrame.FileCount - 1;
        }
        else
        {
            min = indexFrame - half;
            max = indexFrame + half;
        }
        for (int i = min; i <= max; i++)
        {
            int childIndex = i % GlobalVariableBackground.Instance.modelCacheCount;
            modelFrameManager modelFrameManager = transform.GetChild(childIndex).GetComponent <modelFrameManager>();
            if (modelFrameManager == null)
            {
                transform.GetChild(childIndex).gameObject.AddComponent <modelFrameManager>();
                modelFrameManager.vtkframe   = new VTK_Frame();
                modelFrameManager.isCollider = vtkAllFrame.loadFile.dataType == Enums.DataType.Default;
            }
            else
            {
                if (modelFrameManager.isCutModelGO)
                {
                    //transform.GetChild(i) 里面含有切割生成的对象
                    continue;
                }
            }
            VTK_Frame vtkframe = modelFrameManager.vtkframe;
            vtkframe.go = transform.GetChild(childIndex).gameObject;
            Others.ThreadLoadFilePack pack = new Others.ThreadLoadFilePack();
            pack.vtkFrame    = vtkframe;
            pack.vtkAllFrame = vtkAllFrame;
            DirectoryInfo folder = new DirectoryInfo(vtkAllFrame.loadFile.FileDir);
            FileInfo[]    fileinfoArray;
            fileinfoArray = folder.GetFiles("*.qf");

            Array.Sort(fileinfoArray, new FileNameSort());

            //填充 线程数据包-》单一文件
            pack.fileAddres         = fileinfoArray[i];
            vtkframe.selfFrameIndex = i;
            VTKCManager m = new VTKCManager();
            vtkframe.timeStartLession = DateTime.Now;

            if (vtkAllFrame.modelState.isSmooth && vtkAllFrame.loadFile.dataType == Enums.DataType.Water)
            {
                Others.ThreadSmoothModePack packsm = new Others.ThreadSmoothModePack();
                packsm.fileAddres  = pack.fileAddres;
                packsm.smoothCount = 20;
                packsm.vtkAllFrame = pack.vtkAllFrame;
                packsm.vtkFrame    = pack.vtkFrame;
                m.SmoothDispose(packsm);
                //ThreadPool.QueueUserWorkItem(new WaitCallback(m.SmoothDispose), packsm as object);
                //Thread t = new Thread(m.SmoothDispose);
                //t.IsBackground = true;
                //t.Start(packsm);
            }
            else
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(m.DisposeData), pack as object);
            }
        }
    }
Ejemplo n.º 5
0
    private void ConManager_CutModel()
    {
        float[]    plane16 = new float[16];
        GameObject plane   = GlobalVariableBackground.Instance.CutKnife;
        Matrix4x4  mat     = plane.transform.localToWorldMatrix;

        plane16[0] = mat.m00;
        plane16[1] = mat.m01;
        plane16[2] = mat.m02;
        plane16[3] = mat.m03;

        plane16[4] = mat.m10;
        plane16[5] = mat.m11;
        plane16[6] = mat.m12;
        plane16[7] = mat.m13;

        plane16[8]  = mat.m20;
        plane16[9]  = mat.m21;
        plane16[10] = mat.m22;
        plane16[11] = mat.m23;

        plane16[12] = mat.m30;
        plane16[13] = mat.m31;
        plane16[14] = mat.m32;
        plane16[15] = mat.m33;

        float[] model16 = new float[16];

        mat = transform.localToWorldMatrix;

        model16[0] = mat.m00;
        model16[1] = mat.m01;
        model16[2] = mat.m02;
        model16[3] = mat.m03;

        model16[4] = mat.m10;
        model16[5] = mat.m11;
        model16[6] = mat.m12;
        model16[7] = mat.m13;

        model16[8]  = mat.m20;
        model16[9]  = mat.m21;
        model16[10] = mat.m22;
        model16[11] = mat.m23;

        model16[12] = mat.m30;
        model16[13] = mat.m31;
        model16[14] = mat.m32;
        model16[15] = mat.m33;

        string            NewName = name + "&CutModel";
        GameObject        newNodel;
        modelFrameManager modelChild;
        Transform         t = transform.Find(NewName);

        if (t == null)
        {
            newNodel = GameObject.Instantiate(GlobalVariableBackground.Instance.modelPerfab);
            newNodel.transform.parent = transform;
            newNodel.name             = NewName;

            newNodel.transform.localPosition = Vector3.zero;
            newNodel.transform.localRotation = new Quaternion(0, 0, 0, 1);
            newNodel.transform.localScale    = Vector3.one;

            modelChild = newNodel.AddComponent <modelFrameManager>();
            modelChild.isCutModelGO = true;
            modelChild.modelState   = vtkAllFrame.modelState;
        }
        else
        {
            newNodel   = t.gameObject;
            modelChild = newNodel.GetComponent <modelFrameManager>();
        }
        VTK_Frame frame = new VTK_Frame();

        modelChild.vtkframe   = frame;
        frame.point_MaxAndMin = vtkAllFrame.point_MaxAndMin;
        frame.go = newNodel;
        modelChild.isCollider = vtkAllFrame.loadFile.dataType == Enums.DataType.Default;

        Others.ThreadCutModelPack pack = new Others.ThreadCutModelPack();

        pack.model16 = model16;
        pack.plane16 = plane16;

        //填充 线程数据包-》单帧
        pack.vtkAllFrame = vtkAllFrame;
        pack.vtkFrame    = frame;
        DirectoryInfo folder = new DirectoryInfo(vtkAllFrame.loadFile.FileDir);


        FileInfo[] fileinfoArray;
        fileinfoArray = folder.GetFiles("*.qf");

        Array.Sort(fileinfoArray, new FileNameSort());

        //填充 线程数据包-》单一文件
        pack.fileAddres = fileinfoArray[GlobalVariableBackground.Instance.FrameAllIndex];

        //
        frame.selfFrameIndex   = GlobalVariableBackground.Instance.FrameAllIndex;
        frame.timeStartLession = System.DateTime.Now;
        VTKCManager m = new VTKCManager();

        //m.CutModelDispose(pack);
        ThreadPool.QueueUserWorkItem(new WaitCallback(m.CutModelDispose), pack as object);
    }