コード例 #1
0
ファイル: VTKRoot.cs プロジェクト: sebastianbk/VtkUnity
    public void CreateGameObject(VTKNode node)
    {
        string gameObjectName = VTK.GetGameObjectName(node);

        Debug.Log("Create gameobject " + gameObjectName);

        if (node.filter.outputType == VTK.DataType.PolyData)
        {
            //Create gameobject
            VtkToUnity vtu = new VtkToUnity(node.filter.vtkFilter.GetOutputPort(),
                                            VTK.GetGameObjectName(node));
            vtu.go.transform.parent = gameObject.transform;
            vtu.ColorBy(Color.magenta);
            vtu.Update();

            gameObjects.Add(vtu.go.name, vtu);

            if (node.filter.outputType == VTK.DataType.PolyData)
            {
                //Add mesh for controller support
                GameObject   go = FindGameObject(gameObjectName);
                MeshCollider mc = go.AddComponent <MeshCollider>();
                mc.isTrigger = true;
                ControllerGameObject cg = go.AddComponent <ControllerGameObject>();
                cg.node = node;
                cg.Initialize();
            }
        }
    }
コード例 #2
0
    public void Set(string key, VtkToUnity value)
    {
        if(ContainsKey(key))
        {
            int index = keys.IndexOf(key);

            values[index] = value;
        }
    }
コード例 #3
0
    public void Set(string key, VtkToUnity value)
    {
        if (ContainsKey(key))
        {
            int index = keys.IndexOf(key);

            values[index] = value;
        }
    }
コード例 #4
0
    void Start()
    {
        string filepath = System.IO.Path.Combine(Application.streamingAssetsPath, "Vtk-Data/Box.vtp");         //Application.dataPath + "/" + "Vtk-Data/Box.vtp";

        //filepath = filepath.Replace("/", "\\");
        Kitware.VTK.vtkXMLPolyDataReader reader = Kitware.VTK.vtkXMLPolyDataReader.New();
        if (reader.CanReadFile(filepath) == 0)
        {
            Debug.Log(filepath + " could not be loaded by Vtk!");
            return;
        }
        reader.SetFileName(filepath);
        reader.Update();

        VtkToUnity vtkToUnity = new VtkToUnity(reader.GetOutputPort(), "Vtk-Data/Box.vtp");

        vtkToUnity.ColorBy("Elevation", VtkToUnity.VtkColorType.POINT_DATA);
        vtkToUnity.SetLut(VtkToUnity.LutPreset.BLUE_RED);
        //vtkToUnity.ColorBy(Color.red);
        vtkToUnity.Update();
        vtkToUnity.go.transform.Translate(-2f, 0f, 0f);

        Kitware.VTK.vtkContourFilter contours = Kitware.VTK.vtkContourFilter.New();
        contours.SetInputConnection(vtkToUnity.triangleFilter.GetOutputPort());
        contours.SetInputArrayToProcess(0, 0, 0, (int)Kitware.VTK.vtkDataObject.FieldAssociations.FIELD_ASSOCIATION_POINTS, "Elevation");
        for (int i = 0; i < 10; ++i)
        {
            contours.SetValue(i, i / 10.0);
        }
        contours.ComputeScalarsOn();
        VtkToUnity vtkToUnityContours = new VtkToUnity(contours.GetOutputPort(), "Contours");

        vtkToUnityContours.ColorBy("Elevation", VtkToUnity.VtkColorType.POINT_DATA);
        vtkToUnityContours.SetLut(VtkToUnity.LutPreset.BLUE_RED);
        //vtkToUnityContours.ColorBy(Color.red);
        vtkToUnityContours.Update();
        vtkToUnityContours.go.transform.Translate(-4f, 0f, 0f);

        // Points
        filepath = System.IO.Path.Combine(Application.streamingAssetsPath, "Vtk-Data/Points.vtp");
        if (reader.CanReadFile(filepath) == 0)
        {
            Debug.Log(filepath + " could not be loaded by Vtk!");
            return;
        }
        reader.SetFileName(filepath);
        reader.Update();

        VtkToUnity vtkToUnityPoints = new VtkToUnity(reader.GetOutputPort(), "Vtk-Data/Points.vtp");

        vtkToUnityPoints.ColorBy("Elevation", VtkToUnity.VtkColorType.POINT_DATA);
        vtkToUnityPoints.SetLut(VtkToUnity.LutPreset.RED_BLUE);
        //vtkToUnityPoints.ColorBy(Color.red);
        vtkToUnityPoints.Update();
        vtkToUnityPoints.go.transform.Translate(2f, 0f, 0f);
    }
コード例 #5
0
    void Start()
    {
        SphereSource = Kitware.VTK.vtkSphereSource.New();
        SphereSource.SetRadius(1);
        SphereSource.Update();

        vtkToUnity = new VtkToUnity(SphereSource.GetOutputPort(), "VTK Sphere Source");
        vtkToUnity.ColorBy(Color.grey);
        vtkToUnity.Update();
    }
コード例 #6
0
    public bool TryGetValue(string key, out VtkToUnity vtkToUnity)
    {
        if (ContainsKey (key))
        {
            vtkToUnity = values [keys.IndexOf (key)];
            return true;
        }

        vtkToUnity = null;
        return false;
    }
コード例 #7
0
    public bool TryGetValue(string key, out VtkToUnity vtkToUnity)
    {
        if (ContainsKey(key))
        {
            vtkToUnity = values [keys.IndexOf(key)];
            return(true);
        }

        vtkToUnity = null;
        return(false);
    }
コード例 #8
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        VtkToUnity myScript = (VtkToUnity)target;

        if (GUILayout.Button("VTK Polydata to Unity mesh"))
        {
            myScript.PolyDataToMesh();
        }
    }
コード例 #9
0
    void Generate()
    {
        if (SphereSource == null)
        {
            SphereSource = Kitware.VTK.vtkSphereSource.New();
        }
        if (vtkToUnity == null)
        {
            vtkToUnity = new VtkToUnity(SphereSource.GetOutputPort(), "VTK Run In Editor");
            vtkToUnity.ColorBy(Color.green);
        }
        SphereSource.SetPhiResolution(resolution);
        SphereSource.SetThetaResolution(resolution);
        SphereSource.SetRadius(1);
        SphereSource.Update();

        vtkToUnity.Update();
    }
コード例 #10
0
 public void Add(string key, VtkToUnity value)
 {
     keys.Add (key);
     values.Add (value);
 }
コード例 #11
0
ファイル: VTKRoot.cs プロジェクト: rfrister/VtkUnity
    public void CreateGameObject(VTKNode node)
    {
        string gameObjectName = VTK.GetGameObjectName(node);
        Debug.Log ("Create gameobject " + gameObjectName);

        if(node.filter.outputType == VTK.DataType.PolyData)
        {
            //Create gameobject
            VtkToUnity vtu = new VtkToUnity(node.filter.vtkFilter.GetOutputPort(),
                VTK.GetGameObjectName (node));
            vtu.go.transform.parent = gameObject.transform;
            vtu.ColorBy (Color.magenta);
            vtu.Update ();

            gameObjects.Add(vtu.go.name, vtu);

            if(node.filter.outputType == VTK.DataType.PolyData)
            {
                //Add mesh for controller support
                GameObject go = FindGameObject(gameObjectName);
                MeshCollider mc = go.AddComponent<MeshCollider>();
                mc.isTrigger = true;
                ControllerGameObject cg = go.AddComponent<ControllerGameObject>();
                cg.node = node;
                cg.Initialize();
            }
        }
    }
コード例 #12
0
 void Reset()
 {
     DestroyImmediate(vtkToUnity.go);
     vtkToUnity = null;
 }
コード例 #13
0
 public void Add(string key, VtkToUnity value)
 {
     keys.Add(key);
     values.Add(value);
 }