예제 #1
1
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVPlot3DVectors(String [] argv)
    {
        //Prefix Content is: ""

        //[]
        // All Plot3D vector functions[]
        //[]
        // Create the RenderWindow, Renderer and both Actors[]
        //[]
        renWin = vtkRenderWindow.New();
        renWin.SetMultiSamples(0);
        ren1 = vtkRenderer.New();
        ren1.SetBackground((double).8, (double).8, (double).2);
        renWin.AddRenderer((vtkRenderer)ren1);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        vectorLabels    = "Velocity Vorticity Momentum Pressure_Gradient";
        vectorFunctions = "200 201 202 210";
        camera          = new vtkCamera();
        light           = new vtkLight();
        // All text actors will share the same text prop[]
        textProp = new vtkTextProperty();
        textProp.SetFontSize((int)10);
        textProp.SetFontFamilyToArial();
        textProp.SetColor((double).3, (double)1, (double)1);
        i = 0;
        foreach (string vectorFunction in vectorFunctions.Split(new char[] { ' ' }))
        {
            pl3d[getArrayIndex(vectorFunction)] = new vtkMultiBlockPLOT3DReader();
            pl3d[getArrayIndex(vectorFunction)].SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinxyz.bin");
            pl3d[getArrayIndex(vectorFunction)].SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinq.bin");
            pl3d[getArrayIndex(vectorFunction)].SetVectorFunctionNumber((int)(int)(getArrayIndex(vectorFunction)));
            pl3d[getArrayIndex(vectorFunction)].Update();
            plane[getArrayIndex(vectorFunction)] = new vtkStructuredGridGeometryFilter();
            plane[getArrayIndex(vectorFunction)].SetInputData((vtkDataSet)pl3d[getArrayIndex(vectorFunction)].GetOutput().GetBlock(0));
            plane[getArrayIndex(vectorFunction)].SetExtent((int)25, (int)25, (int)0, (int)100, (int)0, (int)100);
            hog[getArrayIndex(vectorFunction)] = new vtkHedgeHog();
            hog[getArrayIndex(vectorFunction)].SetInputConnection((vtkAlgorithmOutput)plane[getArrayIndex(vectorFunction)].GetOutputPort());
            maxnorm = ((vtkDataSet)pl3d[getArrayIndex(vectorFunction)].GetOutput().GetBlock(0)).GetPointData().GetVectors().GetMaxNorm();
            hog[getArrayIndex(vectorFunction)].SetScaleFactor((double)1.0 / maxnorm);
            mapper[getArrayIndex(vectorFunction)] = vtkPolyDataMapper.New();
            mapper[getArrayIndex(vectorFunction)].SetInputConnection((vtkAlgorithmOutput)hog[getArrayIndex(vectorFunction)].GetOutputPort());
            actor[getArrayIndex(vectorFunction)] = new vtkActor();
            actor[getArrayIndex(vectorFunction)].SetMapper((vtkMapper)mapper[getArrayIndex(vectorFunction)]);
            ren[getArrayIndex(vectorFunction)] = vtkRenderer.New();
            ren[getArrayIndex(vectorFunction)].SetBackground((double)0.5, (double).5, (double).5);
            ren[getArrayIndex(vectorFunction)].SetActiveCamera((vtkCamera)camera);
            ren[getArrayIndex(vectorFunction)].AddLight((vtkLight)light);
            renWin.AddRenderer(ren[getArrayIndex(vectorFunction)]);
            ren[getArrayIndex(vectorFunction)].AddActor((vtkProp)actor[getArrayIndex(vectorFunction)]);
            textMapper[getArrayIndex(vectorFunction)] = new vtkTextMapper();
            textMapper[getArrayIndex(vectorFunction)].SetInput(vectorLabels.Split(new char[] { ' ' })[i]);
            textMapper[getArrayIndex(vectorFunction)].SetTextProperty((vtkTextProperty)textProp);
            text[getArrayIndex(vectorFunction)] = new vtkActor2D();
            text[getArrayIndex(vectorFunction)].SetMapper((vtkMapper2D)textMapper[getArrayIndex(vectorFunction)]);
            text[getArrayIndex(vectorFunction)].SetPosition((double)2, (double)5);

            ren[getArrayIndex(vectorFunction)].AddActor2D((vtkProp)text[getArrayIndex(vectorFunction)]);


            i = i + 1;
        }
        //[]
        // now layout renderers[]
        column = 1;
        row    = 1;
        deltaX = 1.0 / 2.0;
        deltaY = 1.0 / 2.0;
        foreach (string vectorFunction in vectorFunctions.Split(new char[] { ' ' }))
        {
            ren[getArrayIndex(vectorFunction)].SetViewport((double)(column - 1) * deltaX + (deltaX * .05), (double)(row - 1) * deltaY + (deltaY * .05), (double)column * deltaX - (deltaX * .05), (double)row * deltaY - (deltaY * .05));
            column = column + 1;
            if ((column) > 2)
            {
                column = 1;
                row    = row + 1;
            }
        }
        camera.SetViewUp((double)1, (double)0, (double)0);
        camera.SetFocalPoint((double)0, (double)0, (double)0);
        camera.SetPosition((double).4, (double)-.5, (double)-.75);
        ren[200].ResetCamera();
        camera.Dolly((double)1.25);
        ren[200].ResetCameraClippingRange();
        ren[201].ResetCameraClippingRange();
        ren[202].ResetCameraClippingRange();
        ren[210].ResetCameraClippingRange();
        light.SetPosition(camera.GetPosition()[0], camera.GetPosition()[1], camera.GetPosition()[2]);
        light.SetFocalPoint(camera.GetFocalPoint()[0], camera.GetFocalPoint()[1], camera.GetFocalPoint()[2]);
        renWin.SetSize(350, 350);
        renWin.Render();
        iren.Initialize();
        // render the image[]
        //[]
        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }
예제 #2
0
        /*
         * In this function, first need to build the color table,
         * and then add the text
         */

        public void VTKInfoBuilder(ref vtkActor2D actor)
        {
            vtkActor2D    colorTextActor = new vtkActor2D();
            vtkTextMapper colorText      = new vtkTextMapper();

            colorTextActor.SetMapper(colorText);

            //Generate the string:
            string outPutChartString = "";

            outPutChartString += "[Model Details]\n";
            outPutChartString += "Phase: " + WorkSpaceInstance.Env.GetModelGeneratingPhase() + "\n";
            outPutChartString += "ModelType: " + WorkSpaceInstance.Env.GetModelTypeString() + "\n";
            outPutChartString += "Model Name: " + WorkSpaceInstance.Env.GetCurrentTowerModelName() + "\n";
            outPutChartString += "\n";
            outPutChartString += "Min: " + TowerModelInstance.GetColorGenColorTableMinvalue().ToString() +
                                 " Max: " + TowerModelInstance.GetColorGenColorTableMaxValue().ToString() +
                                 "\n";


            colorText.SetInput(outPutChartString);
            colorText.GetTextProperty().SetFontSize(12);
            colorText.GetTextProperty().SetFontFamilyToArial();
            //colorText.GetTextProperty().SetColor(225, 39, 39);

            colorTextActor.SetDisplayPosition(20, 50);
            actor = colorTextActor;
        }
예제 #3
0
        static void Main(string[] args)
        {
            // create a sphere source, mapper, and actor
            vtkSphereSource sphere = new vtkSphereSource();
            vtkPolyDataMapper sphereMapper = new vtkPolyDataMapper();
            sphereMapper.SetInputConnection(sphere.GetOutputPort());
            vtkPolyDataMapper.GlobalImmediateModeRenderingOn();
            vtkLODActor sphereActor = new vtkLODActor();
            sphereActor.SetMapper(sphereMapper);

            // create the spikes by glyphing the sphere with a cone.  Create the
            // mapper and actor for the glyphs.
            vtkConeSource cone = new vtkConeSource();
            vtkGlyph3D glyph = new vtkGlyph3D();
            glyph.SetInputConnection(sphere.GetOutputPort());
            glyph.SetSource(cone.GetOutput());
            glyph.SetVectorModeToUseNormal();
            glyph.SetScaleModeToScaleByVector();
            glyph.SetScaleFactor(0.25);
            vtkPolyDataMapper spikeMapper = new vtkPolyDataMapper();
            spikeMapper.SetInputConnection(glyph.GetOutputPort());
            vtkLODActor spikeActor = new vtkLODActor();
            spikeActor.SetMapper(spikeMapper);

            // Create a text mapper and actor to display the results of picking.
            vtkTextMapper textMapper = new vtkTextMapper();
            vtkTextProperty tprop = textMapper.GetTextProperty();
            tprop.SetFontFamilyToArial();
            tprop.SetFontSize(10);
            tprop.BoldOn();
            tprop.ShadowOn();
            tprop.SetColor(1, 0, 0);
            vtkActor2D textActor = new vtkActor2D();
            textActor.VisibilityOff();
            textActor.SetMapper(textMapper);

            // Create a cell picker.
            vtkCellPicker picker = new vtkCellPicker();

            PickData pd = new PickData();
            pd.textActor = textActor;
            pd.textMapper = textMapper;
            vtkDotNetCallback cb = new vtkDotNetCallback(pd.annotatePickCallback);
            // Now at the end of the pick event call the above function.
            picker.AddObserver((uint) EventIds.EndPickEvent, cb);

            // Create the Renderer, RenderWindow, etc. and set the Picker.
            vtkRenderer ren = new vtkRenderer();
            vtkRenderWindow renWin = new vtkRenderWindow();
            renWin.AddRenderer(ren);
            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
            iren.SetRenderWindow(renWin);
            iren.SetPicker(picker);

            // Add the actors to the renderer, set the background and size
            ren.AddActor2D(textActor);
            ren.AddActor(sphereActor);
            ren.AddActor(spikeActor);
            ren.SetBackground(1, 1, 1);
            renWin.SetSize(300, 300);

            // Get the camera and zoom in closer to the image.
            ren.ResetCamera();
            vtkCamera cam1 = ren.GetActiveCamera();
            cam1.Zoom(1.4);

            iren.Initialize();
            // Initially pick the cell at this location.
            picker.Pick(85, 126, 0, ren);
            renWin.Render();

            iren.Start();

            vtkWin32OpenGLRenderWindow win32win =
                vtkWin32OpenGLRenderWindow.SafeDownCast(renWin);
            if (null != win32win) win32win.Clean();
        }
예제 #4
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVPlot3DScalars(String[] argv)
    {
        //Prefix Content is: ""

        //[]
        // All Plot3D scalar functions[]
        //[]
        // Create the RenderWindow, Renderer and both Actors[]
        //[]
        renWin = vtkRenderWindow.New();
        renWin.SetMultiSamples(0);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        scalarLabels    = "Density Pressure Temperature Enthalpy Internal_Energy Kinetic_Energy Velocity_Magnitude Stagnation_Energy Entropy Swirl";
        scalarFunctions = "100 110 120 130 140 144 153 163 170 184";
        camera          = new vtkCamera();
        light           = new vtkLight();
        math            = new vtkMath();
        // All text actors will share the same text prop[]
        textProp = new vtkTextProperty();
        textProp.SetFontSize((int)10);
        textProp.SetFontFamilyToArial();
        textProp.SetColor((double)0, (double)0, (double)0);
        i = 0;
        foreach (string scalarFunction in scalarFunctions.Split(new char[] { ' ' }))
        {
            pl3d[getArrayIndex(scalarFunction)] = new vtkMultiBlockPLOT3DReader();
            pl3d[getArrayIndex(scalarFunction)].SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinxyz.bin");
            pl3d[getArrayIndex(scalarFunction)].SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinq.bin");
            pl3d[getArrayIndex(scalarFunction)].SetScalarFunctionNumber((int)(int)(Int32.Parse(scalarFunction)));
            pl3d[getArrayIndex(scalarFunction)].Update();

            plane[getArrayIndex(scalarFunction)] = new vtkStructuredGridGeometryFilter();
            plane[getArrayIndex(scalarFunction)].SetInputData((vtkDataSet)pl3d[getArrayIndex(scalarFunction)].GetOutput().GetBlock(0));
            plane[getArrayIndex(scalarFunction)].SetExtent((int)25, (int)25, (int)0, (int)100, (int)0, (int)100);

            mapper[getArrayIndex(scalarFunction)] = vtkPolyDataMapper.New();
            mapper[getArrayIndex(scalarFunction)].SetInputConnection((vtkAlgorithmOutput)plane[getArrayIndex(scalarFunction)].GetOutputPort());
            mapper[getArrayIndex(scalarFunction)].SetScalarRange((double)((vtkDataSet)pl3d[getArrayIndex(scalarFunction)].GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[0],
                                                                 (double)((vtkDataSet)pl3d[getArrayIndex(scalarFunction)].GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[1]);

            actor[getArrayIndex(scalarFunction)] = new vtkActor();
            actor[getArrayIndex(scalarFunction)].SetMapper((vtkMapper)mapper[getArrayIndex(scalarFunction)]);
            ren[getArrayIndex(scalarFunction)] = vtkRenderer.New();
            ren[getArrayIndex(scalarFunction)].SetBackground((double)0, (double)0, (double).5);
            ren[getArrayIndex(scalarFunction)].SetActiveCamera((vtkCamera)camera);
            ren[getArrayIndex(scalarFunction)].AddLight((vtkLight)light);
            renWin.AddRenderer(ren[getArrayIndex(scalarFunction)]);
            ren[getArrayIndex(scalarFunction)].SetBackground((double)vtkMath.Random((double).5, (double)1), (double)vtkMath.Random((double).5, (double)1), (double)vtkMath.Random((double).5, (double)1));
            ren[getArrayIndex(scalarFunction)].AddActor((vtkProp)actor[getArrayIndex(scalarFunction)]);

            textMapper[getArrayIndex(scalarFunction)] = new vtkTextMapper();
            textMapper[getArrayIndex(scalarFunction)].SetInput(scalarLabels.Split(new char[] { ' ' })[i]);
            textMapper[getArrayIndex(scalarFunction)].SetTextProperty((vtkTextProperty)textProp);

            text[getArrayIndex(scalarFunction)] = new vtkActor2D();
            text[getArrayIndex(scalarFunction)].SetMapper((vtkMapper2D)textMapper[getArrayIndex(scalarFunction)]);
            text[getArrayIndex(scalarFunction)].SetPosition((double)2, (double)3);

            ren[getArrayIndex(scalarFunction)].AddActor2D(text[getArrayIndex(scalarFunction)]);


            i = i + 1;
        }
        //[]
        // now layout renderers[]
        column = 1;
        row    = 1;
        deltaX = 1.0 / 5.0;
        deltaY = 1.0 / 2.0;
        foreach (string scalarFunction in scalarFunctions.Split(new char[] { ' ' }))
        {
            ren[getArrayIndex(scalarFunction)].SetViewport((double)(column - 1) * deltaX, (double)(row - 1) * deltaY, (double)column * deltaX, (double)row * deltaY);
            column = column + 1;
            if ((column) > 5)
            {
                column = 1;
                row    = row + 1;
            }
        }
        camera.SetViewUp((double)0, (double)1, (double)0);
        camera.SetFocalPoint((double)0, (double)0, (double)0);
        camera.SetPosition((double)1, (double)0, (double)0);
        ren[100].ResetCamera();
        camera.Dolly((double)1.25);
        ren[100].ResetCameraClippingRange();
        ren[110].ResetCameraClippingRange();
        ren[120].ResetCameraClippingRange();
        ren[130].ResetCameraClippingRange();
        ren[140].ResetCameraClippingRange();
        ren[144].ResetCameraClippingRange();
        ren[153].ResetCameraClippingRange();
        ren[163].ResetCameraClippingRange();
        ren[170].ResetCameraClippingRange();
        ren[184].ResetCameraClippingRange();

        light.SetPosition(camera.GetPosition()[0], camera.GetPosition()[1], camera.GetPosition()[2]);
        light.SetFocalPoint(camera.GetFocalPoint()[0], camera.GetFocalPoint()[1], camera.GetFocalPoint()[2]);

        renWin.SetSize(600, 180);
        renWin.Render();
        iren.Initialize();
        // render the image[]
        //[]
        // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
        static void ReadSupport(string Spath)
        {
            vtkJPEGReader reader = vtkJPEGReader.New();

            reader.SetFileName(Spath);
            reader.Update();

            // Visualize
            _ImageViewer = vtkImageViewer2.New();
            _ImageViewer.SetInputConnection(reader.GetOutputPort());

            _SliceStatusMapper = vtkTextMapper.New();
            _SliceStatusMapper.SetInputConnection(reader.GetOutputPort());

            vtkActor2D sliceStatusActor = vtkActor2D.New();

            sliceStatusActor.SetMapper(_SliceStatusMapper);

            vtkRenderWindow renderWindow = vtkRenderWindow.New();

            //Display in full screen
            renderWindow.SetFullScreen(1);

            vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New();

            renderWindow.GetRenderers().InitTraversal();
            vtkRenderer ren;

            while ((ren = renderWindow.GetRenderers().GetNextItem()) != null)
            {
                renderWindow.AddRenderer(ren);
            }

            _ImageViewer.SetRenderWindow(renderWindow);
            _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor);
            _ImageViewer.SetSlice(_SupportSlice);

            iren = vtkRenderWindowInteractor.New();
            iren.SetRenderWindow(renderWindow);
            renderWindow.Render();
            _ColorLevel = 60;
            _ImageViewer.SetColorLevel(_BlackLevel);
            _ImageViewer.Render();
            Down(_period, 170);
            Backward(_period, 1);

            for (int i = 0; i < _SupportLayers; i++)
            {
                System.Threading.Thread.Sleep(_layertime); // delay
                Backward(_period, 1);
            }
            _ImageViewer.SetColorLevel(_BlackLevel);
            _ImageViewer.Render();
            Forward(_period, _MovedLayers);
            Console.WriteLine(_MovedLayers);

            if (reader != null)
            {
                reader.Dispose();
            }
            if (_ImageViewer != null)
            {
                _ImageViewer.Dispose();
            }
            if (_SliceStatusMapper != null)
            {
                _SliceStatusMapper.Dispose();
            }
            if (sliceStatusActor != null)
            {
                sliceStatusActor.Dispose();
            }
            if (renderWindow != null)
            {
                renderWindow.Dispose();
            }
            if (interactorStyle != null)
            {
                interactorStyle.Dispose();
            }
            if (ren != null)
            {
                ren.Dispose();
            }
            if (iren != null)
            {
                iren.Dispose();
            }
        }
        static void PrintImage(string Ipath)
        {
            vtkDICOMImageReader reader = vtkDICOMImageReader.New();

            reader.SetDirectoryName(Ipath);
            reader.Update();
            X = reader.GetWidth();
            Y = reader.GetHeight();
            Z = reader.GetPixelSpacing();
            Console.WriteLine(X * Z[0]);
            Console.WriteLine(Y * Z[1]);
            Console.WriteLine(Z[2]);

            // Visualize
            _ImageViewer = vtkImageViewer2.New();
            _ImageViewer.SetInputConnection(reader.GetOutputPort());

            // Get range of slices (min is the first index, max is the last index)
            _ImageViewer.GetSliceRange(ref _MinSlice, ref _MaxSlice);
            Console.WriteLine(_MinSlice);
            Console.WriteLine(_MaxSlice);

            _SliceStatusMapper = vtkTextMapper.New();
            _SliceStatusMapper.SetInputConnection(reader.GetOutputPort());

            vtkActor2D sliceStatusActor = vtkActor2D.New();

            sliceStatusActor.SetMapper(_SliceStatusMapper);

            vtkRenderWindow renderWindow = vtkRenderWindow.New();

            //Display in full screen
            renderWindow.SetFullScreen(1);

            vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New();

            renderWindow.GetRenderers().InitTraversal();
            vtkRenderer ren;

            while ((ren = renderWindow.GetRenderers().GetNextItem()) != null)
            {
                renderWindow.AddRenderer(ren);
            }

            _ImageViewer.SetRenderWindow(renderWindow);
            _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor);
            _ImageViewer.SetSlice(_Slice);
            _ColorLevel = 500;
            _ImageViewer.SetColorLevel(_BlackLevel);
            _ImageViewer.Render();
            Down(_period, 62);
            Backward(_period, 1);

            _ImageViewer.SetColorLevel(_ColorLevel);
            _ImageViewer.Render();
            System.Threading.Thread.Sleep(_layertime);  // delay

            iren = vtkRenderWindowInteractor.New();
            iren.SetRenderWindow(renderWindow);
            renderWindow.Render();

            //Start Timer
            InitTimer();
            iren.Start();

            if (reader != null)
            {
                reader.Dispose();
            }
            if (_ImageViewer != null)
            {
                _ImageViewer.Dispose();
            }
            if (_SliceStatusMapper != null)
            {
                _SliceStatusMapper.Dispose();
            }
            if (sliceStatusActor != null)
            {
                sliceStatusActor.Dispose();
            }
            if (renderWindow != null)
            {
                renderWindow.Dispose();
            }
            if (interactorStyle != null)
            {
                interactorStyle.Dispose();
            }
            if (ren != null)
            {
                ren.Dispose();
            }
            if (iren != null)
            {
                iren.Dispose();
            }
        }
예제 #7
0
        private void Subdivision(string filePath)
        {
            vtkPolyData originalMesh;

            if (filePath != null)
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(filePath);
                // Subdivision filters only work on triangles
                vtkTriangleFilter triangles = vtkTriangleFilter.New();
                triangles.SetInputConnection(reader.GetOutputPort());
                triangles.Update();
                originalMesh = triangles.GetOutput();
            }
            else
            {
                vtkSphereSource sphereSource = vtkSphereSource.New();
                sphereSource.Update();
                originalMesh = sphereSource.GetOutput();
            }
            Debug.WriteLine("Before subdivision");
            Debug.WriteLine("    There are " + originalMesh.GetNumberOfPoints()
                            + " points.");
            Debug.WriteLine("    There are " + originalMesh.GetNumberOfPolys()
                            + " triangles.");

            int numberOfViewports = 3;

            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;

            this.Size  = new System.Drawing.Size(200 * numberOfViewports + 12, 252);
            this.Text += " - Subdivision";
            Random rnd = new Random(2);
            int    numberOfSubdivisions = 2;

            // Create one text property for all
            vtkTextProperty textProperty = vtkTextProperty.New();

            textProperty.SetFontSize(14);
            textProperty.SetJustificationToCentered();

            for (int i = 0; i < numberOfViewports; i++)
            {
                // Note: Here we create a superclass pointer (vtkPolyDataAlgorithm) so that we can easily instantiate different
                // types of subdivision filters. Typically you would not want to do this, but rather create the pointer to be the type
                // filter you will actually use, e.g.
                // <vtkLinearSubdivisionFilter>  subdivisionFilter = <vtkLinearSubdivisionFilter>.New();
                vtkPolyDataAlgorithm subdivisionFilter;
                switch (i)
                {
                case 0:
                    subdivisionFilter = vtkLinearSubdivisionFilter.New();
                    ((vtkLinearSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions);
                    break;

                case 1:
                    subdivisionFilter = vtkLoopSubdivisionFilter.New();
                    ((vtkLoopSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions);
                    break;

                case 2:
                    subdivisionFilter = vtkButterflySubdivisionFilter.New();
                    ((vtkButterflySubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions);
                    break;

                default:
                    subdivisionFilter = vtkLinearSubdivisionFilter.New();
                    ((vtkLinearSubdivisionFilter)subdivisionFilter).SetNumberOfSubdivisions(numberOfSubdivisions);
                    break;
                }
#if VTK_MAJOR_VERSION_5
                subdivisionFilter.SetInputConnection(originalMesh.GetProducerPort());
#else
                subdivisionFilter.SetInputData(originalMesh);
#endif
                subdivisionFilter.Update();
                vtkRenderer renderer = vtkRenderer.New();
                renderWindow.AddRenderer(renderer);
                renderer.SetViewport((float)i / numberOfViewports, 0, (float)(i + 1) / numberOfViewports, 1);
                renderer.SetBackground(.2 + rnd.NextDouble() / 8, .3 + rnd.NextDouble() / 8, .4 + rnd.NextDouble() / 8);

                vtkTextMapper textMapper = vtkTextMapper.New();
                vtkActor2D    textActor  = vtkActor2D.New();
                textMapper.SetInput(subdivisionFilter.GetClassName());
                textMapper.SetTextProperty(textProperty);

                textActor.SetMapper(textMapper);
                textActor.SetPosition(100, 16);

                //Create a mapper and actor
                vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
                mapper.SetInputConnection(subdivisionFilter.GetOutputPort());
                vtkActor actor = vtkActor.New();
                actor.SetMapper(mapper);
                renderer.AddActor(actor);
                renderer.AddActor(textActor);
                renderer.ResetCamera();
            }
            renderWindow.Render();
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVPlot3DVectors(String [] argv)
    {
        //Prefix Content is: ""

          //[]
          // All Plot3D vector functions[]
          //[]
          // Create the RenderWindow, Renderer and both Actors[]
          //[]
          renWin = vtkRenderWindow.New();
          ren1 = vtkRenderer.New();
          ren1.SetBackground((double).8,(double).8,(double).2);
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          vectorLabels = "Velocity Vorticity Momentum Pressure_Gradient";
          vectorFunctions = "200 201 202 210";
          camera = new vtkCamera();
          light = new vtkLight();
          // All text actors will share the same text prop[]
          textProp = new vtkTextProperty();
          textProp.SetFontSize((int)10);
          textProp.SetFontFamilyToArial();
          textProp.SetColor((double).3,(double)1,(double)1);
          i = 0;
          foreach (string vectorFunction in vectorFunctions.Split(new char[]{' '}))
          {
          pl3d[getArrayIndex(vectorFunction)] = new vtkPLOT3DReader();
          pl3d[getArrayIndex(vectorFunction)].SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinxyz.bin");
          pl3d[getArrayIndex(vectorFunction)].SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinq.bin");
          pl3d[getArrayIndex(vectorFunction)].SetVectorFunctionNumber((int)(int)(getArrayIndex(vectorFunction)));
          pl3d[getArrayIndex(vectorFunction)].Update();
          plane[getArrayIndex(vectorFunction)] = new vtkStructuredGridGeometryFilter();
          plane[getArrayIndex(vectorFunction)].SetInputConnection((vtkAlgorithmOutput)pl3d[getArrayIndex(vectorFunction)].GetOutputPort());
          plane[getArrayIndex(vectorFunction)].SetExtent((int)25,(int)25,(int)0,(int)100,(int)0,(int)100);
          hog[getArrayIndex(vectorFunction)] = new vtkHedgeHog();
          hog[getArrayIndex(vectorFunction)].SetInputConnection((vtkAlgorithmOutput)plane[getArrayIndex(vectorFunction)].GetOutputPort());
          maxnorm = pl3d[getArrayIndex(vectorFunction)].GetOutput().GetPointData().GetVectors().GetMaxNorm();
          hog[getArrayIndex(vectorFunction)].SetScaleFactor((double)1.0/maxnorm);
          mapper[getArrayIndex(vectorFunction)] = vtkPolyDataMapper.New();
          mapper[getArrayIndex(vectorFunction)].SetInputConnection((vtkAlgorithmOutput)hog[getArrayIndex(vectorFunction)].GetOutputPort());
          actor[getArrayIndex(vectorFunction)] = new vtkActor();
          actor[getArrayIndex(vectorFunction)].SetMapper((vtkMapper)mapper[getArrayIndex(vectorFunction)]);
          ren[getArrayIndex(vectorFunction)] = vtkRenderer.New();
          ren[getArrayIndex(vectorFunction)].SetBackground((double)0.5,(double).5,(double).5);
          ren[getArrayIndex(vectorFunction)].SetActiveCamera((vtkCamera)camera);
          ren[getArrayIndex(vectorFunction)].AddLight((vtkLight)light);
          renWin.AddRenderer(ren[getArrayIndex(vectorFunction)]);
          ren[getArrayIndex(vectorFunction)].AddActor((vtkProp)actor[getArrayIndex(vectorFunction)]);
          textMapper[getArrayIndex(vectorFunction)] = new vtkTextMapper();
          textMapper[getArrayIndex(vectorFunction)].SetInput(vectorLabels.Split(new char[] { ' ' })[i]);
          textMapper[getArrayIndex(vectorFunction)].SetTextProperty((vtkTextProperty)textProp);
          text[getArrayIndex(vectorFunction)] = new vtkActor2D();
          text[getArrayIndex(vectorFunction)].SetMapper((vtkMapper2D)textMapper[getArrayIndex(vectorFunction)]);
          text[getArrayIndex(vectorFunction)].SetPosition((double)2,(double)5);

          ren[getArrayIndex(vectorFunction)].AddActor2D((vtkProp)text[getArrayIndex(vectorFunction)]);

          i = i + 1;

          }
          //[]
          // now layout renderers[]
          column = 1;
          row = 1;
          deltaX = 1.0/2.0;
          deltaY = 1.0/2.0;
          foreach (string vectorFunction in vectorFunctions.Split(new char[]{' '}))
          {
          ren[getArrayIndex(vectorFunction)].SetViewport((double)(column - 1) * deltaX + (deltaX * .05), (double)(row - 1) * deltaY + (deltaY * .05), (double)column * deltaX - (deltaX * .05), (double)row * deltaY - (deltaY * .05));
          column = column + 1;
          if ((column) > 2)
        {
          column = 1;
          row = row + 1;
        }

          }
          camera.SetViewUp((double)1,(double)0,(double)0);
          camera.SetFocalPoint((double)0,(double)0,(double)0);
          camera.SetPosition((double).4,(double)-.5,(double)-.75);
          ren[200].ResetCamera();
          camera.Dolly((double)1.25);
          ren[200].ResetCameraClippingRange();
          ren[201].ResetCameraClippingRange();
          ren[202].ResetCameraClippingRange();
          ren[210].ResetCameraClippingRange();
          light.SetPosition(camera.GetPosition()[0],camera.GetPosition()[1],camera.GetPosition()[2]);
          light.SetFocalPoint(camera.GetFocalPoint()[0],camera.GetFocalPoint()[1],camera.GetFocalPoint()[2]);
          renWin.SetSize(350,350);
          renWin.Render();
          iren.Initialize();
          // render the image[]
          //[]
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
 ///<summary> A Set Method for Static Variables </summary>
 public static void SettextMapper(vtkTextMapper[] toSet)
 {
     textMapper = toSet;
 }
예제 #10
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVPlot3DScalars(String[] argv)
    {
        //Prefix Content is: ""

        //[]
        // All Plot3D scalar functions[]
        //[]
        // Create the RenderWindow, Renderer and both Actors[]
        //[]
        renWin = vtkRenderWindow.New();
        renWin.SetMultiSamples(0);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        scalarLabels = "Density Pressure Temperature Enthalpy Internal_Energy Kinetic_Energy Velocity_Magnitude Stagnation_Energy Entropy Swirl";
        scalarFunctions = "100 110 120 130 140 144 153 163 170 184";
        camera = new vtkCamera();
        light = new vtkLight();
        math = new vtkMath();
        // All text actors will share the same text prop[]
        textProp = new vtkTextProperty();
        textProp.SetFontSize((int)10);
        textProp.SetFontFamilyToArial();
        textProp.SetColor((double)0, (double)0, (double)0);
        i = 0;
        foreach (string scalarFunction in scalarFunctions.Split(new char[] { ' ' }))
        {
            pl3d[getArrayIndex(scalarFunction)] = new vtkMultiBlockPLOT3DReader();
            pl3d[getArrayIndex(scalarFunction)].SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinxyz.bin");
            pl3d[getArrayIndex(scalarFunction)].SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/bluntfinq.bin");
            pl3d[getArrayIndex(scalarFunction)].SetScalarFunctionNumber((int)(int)(Int32.Parse(scalarFunction)));
            pl3d[getArrayIndex(scalarFunction)].Update();

            plane[getArrayIndex(scalarFunction)] = new vtkStructuredGridGeometryFilter();
            plane[getArrayIndex(scalarFunction)].SetInputData((vtkDataSet)pl3d[getArrayIndex(scalarFunction)].GetOutput().GetBlock(0));
            plane[getArrayIndex(scalarFunction)].SetExtent((int)25, (int)25, (int)0, (int)100, (int)0, (int)100);

            mapper[getArrayIndex(scalarFunction)] = vtkPolyDataMapper.New();
            mapper[getArrayIndex(scalarFunction)].SetInputConnection((vtkAlgorithmOutput)plane[getArrayIndex(scalarFunction)].GetOutputPort());
            mapper[getArrayIndex(scalarFunction)].SetScalarRange((double)((vtkDataSet)pl3d[getArrayIndex(scalarFunction)].GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[0],
                (double)((vtkDataSet)pl3d[getArrayIndex(scalarFunction)].GetOutput().GetBlock(0)).GetPointData().GetScalars().GetRange()[1]);

            actor[getArrayIndex(scalarFunction)] = new vtkActor();
            actor[getArrayIndex(scalarFunction)].SetMapper((vtkMapper)mapper[getArrayIndex(scalarFunction)]);
            ren[getArrayIndex(scalarFunction)] = vtkRenderer.New();
            ren[getArrayIndex(scalarFunction)].SetBackground((double)0, (double)0, (double).5);
            ren[getArrayIndex(scalarFunction)].SetActiveCamera((vtkCamera)camera);
            ren[getArrayIndex(scalarFunction)].AddLight((vtkLight)light);
            renWin.AddRenderer(ren[getArrayIndex(scalarFunction)]);
            ren[getArrayIndex(scalarFunction)].SetBackground((double)vtkMath.Random((double).5, (double)1), (double)vtkMath.Random((double).5, (double)1), (double)vtkMath.Random((double).5, (double)1));
            ren[getArrayIndex(scalarFunction)].AddActor((vtkProp)actor[getArrayIndex(scalarFunction)]);

            textMapper[getArrayIndex(scalarFunction)] = new vtkTextMapper();
            textMapper[getArrayIndex(scalarFunction)].SetInput(scalarLabels.Split(new char[] { ' ' })[i]);
            textMapper[getArrayIndex(scalarFunction)].SetTextProperty((vtkTextProperty)textProp);

            text[getArrayIndex(scalarFunction)] = new vtkActor2D();
            text[getArrayIndex(scalarFunction)].SetMapper((vtkMapper2D)textMapper[getArrayIndex(scalarFunction)]);
            text[getArrayIndex(scalarFunction)].SetPosition((double)2, (double)3);

            ren[getArrayIndex(scalarFunction)].AddActor2D(text[getArrayIndex(scalarFunction)]);

            i = i + 1;

        }
        //[]
        // now layout renderers[]
        column = 1;
        row = 1;
        deltaX = 1.0 / 5.0;
        deltaY = 1.0 / 2.0;
        foreach (string scalarFunction in scalarFunctions.Split(new char[] { ' ' }))
        {
            ren[getArrayIndex(scalarFunction)].SetViewport((double)(column - 1) * deltaX, (double)(row - 1) * deltaY, (double)column * deltaX, (double)row * deltaY);
            column = column + 1;
            if ((column) > 5)
            {
                column = 1;
                row = row + 1;
            }
        }
        camera.SetViewUp((double)0, (double)1, (double)0);
        camera.SetFocalPoint((double)0, (double)0, (double)0);
        camera.SetPosition((double)1, (double)0, (double)0);
        ren[100].ResetCamera();
        camera.Dolly((double)1.25);
        ren[100].ResetCameraClippingRange();
        ren[110].ResetCameraClippingRange();
        ren[120].ResetCameraClippingRange();
        ren[130].ResetCameraClippingRange();
        ren[140].ResetCameraClippingRange();
        ren[144].ResetCameraClippingRange();
        ren[153].ResetCameraClippingRange();
        ren[163].ResetCameraClippingRange();
        ren[170].ResetCameraClippingRange();
        ren[184].ResetCameraClippingRange();

        light.SetPosition(camera.GetPosition()[0], camera.GetPosition()[1], camera.GetPosition()[2]);
        light.SetFocalPoint(camera.GetFocalPoint()[0], camera.GetFocalPoint()[1], camera.GetFocalPoint()[2]);

        renWin.SetSize(600, 180);
        renWin.Render();
        iren.Initialize();
        // render the image[]
        //[]
        // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
예제 #11
0
        private void ReadDICOMSeries()
        {
            // Path to vtk data must be set as an environment variable
            // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0"
            vtkTesting test = vtkTesting.New();
            string     root = test.GetDataRoot();
            // Read all the DICOM files in the specified directory.
            // Caution: folder "DicomTestImages" don't exists by default in the standard vtk data folder
            // sample data are available at http://www.vtk.org/Wiki/images/1/12/VTK_Examples_StandardFormats_Input_DicomTestImages.zip

            //string folder = Path.Combine(root, @"Data\DicomTestImages");
            string folder = @"provaDicom/" + studyUID;

            Console.WriteLine(folder);
            vtkDICOMImageReader reader = vtkDICOMImageReader.New();

            reader.SetDirectoryName(folder);
            reader.Update();
            // Visualize
            _ImageViewer = vtkImageViewer2.New();
            _ImageViewer.SetInputConnection(reader.GetOutputPort());
            // get range of slices (min is the first index, max is the last index)
            _ImageViewer.GetSliceRange(ref _MinSlice, ref _MaxSlice);
            Debug.WriteLine("slices range from : " + _MinSlice.ToString() + " to " + _MaxSlice.ToString());

            // slice status message
            vtkTextProperty sliceTextProp = vtkTextProperty.New();

            sliceTextProp.SetFontFamilyToCourier();
            sliceTextProp.SetFontSize(20);
            sliceTextProp.SetVerticalJustificationToBottom();
            sliceTextProp.SetJustificationToLeft();

            _SliceStatusMapper = vtkTextMapper.New();
            _SliceStatusMapper.SetInput("Slice No " + (_Slice + 1).ToString() + "/" + (_MaxSlice + 1).ToString());
            _SliceStatusMapper.SetTextProperty(sliceTextProp);

            vtkActor2D sliceStatusActor = vtkActor2D.New();

            sliceStatusActor.SetMapper(_SliceStatusMapper);
            sliceStatusActor.SetPosition(15, 10);
            // usage hint message
            vtkTextProperty usageTextProp = vtkTextProperty.New();

            usageTextProp.SetFontFamilyToCourier();
            usageTextProp.SetFontSize(14);
            usageTextProp.SetVerticalJustificationToTop();
            usageTextProp.SetJustificationToLeft();

            vtkTextMapper usageTextMapper = vtkTextMapper.New();

            usageTextMapper.SetInput("Slice with mouse wheel\nor Up/Down-Key");
            usageTextMapper.SetTextProperty(usageTextProp);

            vtkActor2D usageTextActor = vtkActor2D.New();

            usageTextActor.SetMapper(usageTextMapper);
            usageTextActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay();
            usageTextActor.GetPositionCoordinate().SetValue(0.05, 0.95);

            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;

            vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New();

            // NOTA:non funziona la rotellina del mouse per cambiare slice <--------------------------------------
            // l'errore è causato dalla funzione DicomCFindRequest(della sorgente di FellowOak)
            //in QueryFellowOak.cs, in particolare dal costruttore
            // DicomCFindRequest(DicomQueryRetrieveLevel level)

            // interactorStyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt);
            //  interactorStyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt);

            renderWindow.GetInteractor().SetInteractorStyle(interactorStyle);
            renderWindow.GetRenderers().InitTraversal();
            vtkRenderer ren;

            while ((ren = renderWindow.GetRenderers().GetNextItem()) != null)
            {
                ren.SetBackground(0.0, 0.0, 0.0);
            }

            _ImageViewer.SetRenderWindow(renderWindow);
            _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor);
            _ImageViewer.GetRenderer().AddActor2D(usageTextActor);
            _ImageViewer.SetSlice(_MinSlice);
            _ImageViewer.Render();
        }
        private void ReadDICOMSeries()
        {
            // Path to vtk data must be set as an environment variable
             // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0"
             vtkTesting test = vtkTesting.New();
             string root = test.GetDataRoot();
             // Read all the DICOM files in the specified directory.
             // Caution: folder "DicomTestImages" don't exists by default in the standard vtk data folder
             // sample data are available at http://www.vtk.org/Wiki/images/1/12/VTK_Examples_StandardFormats_Input_DicomTestImages.zip
             string folder = Path.Combine(root, @"Data\DicomTestImages");
             vtkDICOMImageReader reader = vtkDICOMImageReader.New();
             reader.SetDirectoryName(folder);
             reader.Update();
             // Visualize
             _ImageViewer = vtkImageViewer2.New();
             _ImageViewer.SetInputConnection(reader.GetOutputPort());
             // get range of slices (min is the first index, max is the last index)
             _ImageViewer.GetSliceRange(ref _MinSlice, ref _MaxSlice);
             Debug.WriteLine("slices range from : " + _MinSlice.ToString() + " to " + _MaxSlice.ToString());

             // slice status message
             vtkTextProperty sliceTextProp = vtkTextProperty.New();
             sliceTextProp.SetFontFamilyToCourier();
             sliceTextProp.SetFontSize(20);
             sliceTextProp.SetVerticalJustificationToBottom();
             sliceTextProp.SetJustificationToLeft();

             _SliceStatusMapper = vtkTextMapper.New();
             _SliceStatusMapper.SetInput("Slice No " + ( _Slice + 1 ).ToString() + "/" + ( _MaxSlice + 1 ).ToString());
             _SliceStatusMapper.SetTextProperty(sliceTextProp);

             vtkActor2D sliceStatusActor = vtkActor2D.New();
             sliceStatusActor.SetMapper(_SliceStatusMapper);
             sliceStatusActor.SetPosition(15, 10);

             // usage hint message
             vtkTextProperty usageTextProp = vtkTextProperty.New();
             usageTextProp.SetFontFamilyToCourier();
             usageTextProp.SetFontSize(14);
             usageTextProp.SetVerticalJustificationToTop();
             usageTextProp.SetJustificationToLeft();

             vtkTextMapper usageTextMapper = vtkTextMapper.New();
             usageTextMapper.SetInput("Slice with mouse wheel\nor Up/Down-Key");
             usageTextMapper.SetTextProperty(usageTextProp);

             vtkActor2D usageTextActor = vtkActor2D.New();
             usageTextActor.SetMapper(usageTextMapper);
             usageTextActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay();
             usageTextActor.GetPositionCoordinate().SetValue(0.05, 0.95);

             vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;

             vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New();
             interactorStyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt);
             interactorStyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt);

             renderWindow.GetInteractor().SetInteractorStyle(interactorStyle);
             renderWindow.GetRenderers().InitTraversal();
             vtkRenderer ren;
             while(( ren = renderWindow.GetRenderers().GetNextItem() ) != null)
            ren.SetBackground(0.0, 0.0, 0.0);

             _ImageViewer.SetRenderWindow(renderWindow);
             _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor);
             _ImageViewer.GetRenderer().AddActor2D(usageTextActor);
             _ImageViewer.SetSlice(_MinSlice);
             _ImageViewer.Render();
        }