Esempio n. 1
0
        private void PlatonicSolid()
        {
            vtkPlatonicSolidSource platonicSolidSource = vtkPlatonicSolidSource.New();

            platonicSolidSource.SetSolidTypeToOctahedron();

            // Each face has a different cell scalar
            vtkLookupTable lut = vtkLookupTable.New();

            lut.SetNumberOfTableValues(8);
            lut.SetTableRange(0.0, 7.0);
            lut.Build();
            lut.SetTableValue(0, 0, 0, 0, 1);
            lut.SetTableValue(1, 0, 0, 1, 1);
            lut.SetTableValue(2, 0, 1, 0, 1);
            lut.SetTableValue(3, 0, 1, 1, 1);
            lut.SetTableValue(4, 1, 0, 0, 1);
            lut.SetTableValue(5, 1, 0, 1, 1);
            lut.SetTableValue(6, 1, 1, 0, 1);
            lut.SetTableValue(7, 1, 1, 1, 1);

            // Visualize
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(platonicSolidSource.GetOutputPort());
            mapper.SetLookupTable(lut);
            mapper.SetScalarRange(0, 7);

            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);


            RenderAddActor(actor);
        }
Esempio n. 2
0
        public void ExtractEdgesVTKBuilderWithoutRunning(ref vtkActor actor, ref vtkPoints points, ref vtkCellArray polys,
                                                         ref vtkFloatArray scalars, ref vtkLookupTable Luk)
        {
            int pointsNum = 0;

            TowerModelInstance.VTKDrawModel(ref points, ref polys, ref scalars, ref pointsNum, paras);

            vtkPolyData profile = vtkPolyData.New();

            profile.SetPoints(points);
            profile.SetPolys(polys);

            vtkExtractEdges ExtProfile = new vtkExtractEdges();


            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            if (paras.RotateAngle == 0)
            {
                profile.GetCellData().SetScalars(scalars);
                ExtProfile.SetInput(profile);
                mapper.SetInputConnection(ExtProfile.GetOutputPort());
            }
            else
            {
                vtkRotationalExtrusionFilter refilter = vtkRotationalExtrusionFilter.New();
                profile.Update();
                profile.GetCellData().SetScalars(scalars);
                //profile.GetPointData().SetScalars(scalars);
                ExtProfile.SetInput(profile);

                refilter.SetInputConnection(ExtProfile.GetOutputPort());
                refilter.SetResolution(50);
                refilter.SetAngle(paras.RotateAngle);
                refilter.SetTranslation(0);
                refilter.SetDeltaRadius(0);

                mapper.SetInputConnection(refilter.GetOutputPort());
            }
            mapper.SetScalarRange(0, 5);
            mapper.SetLookupTable(Luk);
            actor.SetMapper(mapper);

            Luk.SetNumberOfTableValues(7);
            Luk.SetTableValue(0, 0, 1, 0, 1);   //
            Luk.SetTableValue(1, 0, 0, 0.8, 1); //inner surface
            Luk.SetTableValue(2, 0, 1, 0, 1);   //
            Luk.SetTableValue(3, 0, 0, 1, 1);
            Luk.SetTableValue(4, 0, 0, 0.8, 1); //insider
            Luk.SetTableValue(5, 0, 0.8, 0, 1); //outer surface
            Luk.Build();
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVfieldToUGrid(String [] argv)
    {
        //Prefix Content is: ""

          // Read a field representing unstructured grid and display it (similar to blow.tcl)[]
          // create a reader and write out field daya[]
          reader = new vtkUnstructuredGridReader();
          reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/blow.vtk");
          reader.SetScalarsName((string)"thickness9");
          reader.SetVectorsName((string)"displacement9");
          ds2do = new vtkDataSetToDataObjectFilter();
          ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          // we must be able to write here[]
          try
          {
         channel = new StreamWriter("UGridField.vtk");
          tryCatchError = "NOERROR";
          }
          catch(Exception)
          {tryCatchError = "ERROR";}

          if (tryCatchError.Equals("NOERROR"))
          {
          channel.Close();
          write = new vtkDataObjectWriter();
          write.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort());
          write.SetFileName((string)"UGridField.vtk");
          write.Write();
          // Read the field and convert to unstructured grid.[]
          dor = new vtkDataObjectReader();
          dor.SetFileName((string)"UGridField.vtk");
          do2ds = new vtkDataObjectToDataSetFilter();
          do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort());
          do2ds.SetDataSetTypeToUnstructuredGrid();
          do2ds.SetPointComponent((int)0,(string)"Points",(int)0);
          do2ds.SetPointComponent((int)1,(string)"Points",(int)1);
          do2ds.SetPointComponent((int)2,(string)"Points",(int)2);
          do2ds.SetCellTypeComponent((string)"CellTypes",(int)0);
          do2ds.SetCellConnectivityComponent((string)"Cells",(int)0);
          fd2ad = new vtkFieldDataToAttributeDataFilter();
          fd2ad.SetInput((vtkDataObject)do2ds.GetUnstructuredGridOutput());
          fd2ad.SetInputFieldToDataObjectField();
          fd2ad.SetOutputAttributeDataToPointData();
          fd2ad.SetVectorComponent((int)0,(string)"displacement9",(int)0);
          fd2ad.SetVectorComponent((int)1,(string)"displacement9",(int)1);
          fd2ad.SetVectorComponent((int)2,(string)"displacement9",(int)2);
          fd2ad.SetScalarComponent((int)0,(string)"thickness9",(int)0);
          // Now start visualizing[]
          warp = new vtkWarpVector();
          warp.SetInput((vtkDataObject)fd2ad.GetUnstructuredGridOutput());
          // extract mold from mesh using connectivity[]
          connect = new vtkConnectivityFilter();
          connect.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort());
          connect.SetExtractionModeToSpecifiedRegions();
          connect.AddSpecifiedRegion((int)0);
          connect.AddSpecifiedRegion((int)1);
          moldMapper = new vtkDataSetMapper();
          moldMapper.SetInputConnection((vtkAlgorithmOutput)connect.GetOutputPort());
          moldMapper.ScalarVisibilityOff();
          moldActor = new vtkActor();
          moldActor.SetMapper((vtkMapper)moldMapper);
          moldActor.GetProperty().SetColor((double).2,(double).2,(double).2);
          moldActor.GetProperty().SetRepresentationToWireframe();
          // extract parison from mesh using connectivity[]
          connect2 = new vtkConnectivityFilter();
          connect2.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort());
          connect2.SetExtractionModeToSpecifiedRegions();
          connect2.AddSpecifiedRegion((int)2);
          parison = new vtkGeometryFilter();
          parison.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort());
          normals2 = new vtkPolyDataNormals();
          normals2.SetInputConnection((vtkAlgorithmOutput)parison.GetOutputPort());
          normals2.SetFeatureAngle((double)60);
          lut = new vtkLookupTable();
          lut.SetHueRange((double)0.0,(double)0.66667);
          parisonMapper = vtkPolyDataMapper.New();
          parisonMapper.SetInputConnection((vtkAlgorithmOutput)normals2.GetOutputPort());
          parisonMapper.SetLookupTable((vtkScalarsToColors)lut);
          parisonMapper.SetScalarRange((double)0.12,(double)1.0);
          parisonActor = new vtkActor();
          parisonActor.SetMapper((vtkMapper)parisonMapper);
          cf = new vtkContourFilter();
          cf.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort());
          cf.SetValue((int)0,(double).5);
          contourMapper = vtkPolyDataMapper.New();
          contourMapper.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort());
          contours = new vtkActor();
          contours.SetMapper((vtkMapper)contourMapper);
          // Create graphics stuff[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          // Add the actors to the renderer, set the background and size[]
          ren1.AddActor((vtkProp)moldActor);
          ren1.AddActor((vtkProp)parisonActor);
          ren1.AddActor((vtkProp)contours);
          ren1.ResetCamera();
          ren1.GetActiveCamera().Azimuth((double)60);
          ren1.GetActiveCamera().Roll((double)-90);
          ren1.GetActiveCamera().Dolly((double)2);
          ren1.ResetCameraClippingRange();
          ren1.SetBackground((double)1,(double)1,(double)1);
          renWin.SetSize((int)375,(int)200);
          iren.Initialize();
        }

          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Esempio n. 4
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTenEllip(String [] argv)
    {
        //Prefix Content is: ""

          // create tensor ellipsoids[]
          // Create the RenderWindow, Renderer and interactive renderer[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.SetMultiSamples(0);
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          //[]
          // Create tensor ellipsoids[]
          //[]
          // generate tensors[]
          ptLoad = new vtkPointLoad();
          ptLoad.SetLoadValue((double)100.0);
          ptLoad.SetSampleDimensions((int)6,(int)6,(int)6);
          ptLoad.ComputeEffectiveStressOn();
          ptLoad.SetModelBounds((double)-10,(double)10,(double)-10,(double)10,(double)-10,(double)10);
          // extract plane of data[]
          plane = new vtkImageDataGeometryFilter();
          plane.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          plane.SetExtent((int)2,(int)2,(int)0,(int)99,(int)0,(int)99);
          // Generate ellipsoids[]
          sphere = new vtkSphereSource();
          sphere.SetThetaResolution((int)8);
          sphere.SetPhiResolution((int)8);
          ellipsoids = new vtkTensorGlyph();
          ellipsoids.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          ellipsoids.SetSourceConnection((vtkAlgorithmOutput)sphere.GetOutputPort());
          ellipsoids.SetScaleFactor((double)10);
          ellipsoids.ClampScalingOn();
          ellipNormals = new vtkPolyDataNormals();
          ellipNormals.SetInputConnection((vtkAlgorithmOutput)ellipsoids.GetOutputPort());
          // Map contour[]
          lut = new vtkLogLookupTable();
          lut.SetHueRange((double).6667,(double)0.0);
          ellipMapper = vtkPolyDataMapper.New();
          ellipMapper.SetInputConnection((vtkAlgorithmOutput)ellipNormals.GetOutputPort());
          ellipMapper.SetLookupTable((vtkScalarsToColors)lut);
          plane.Update();
          //force update for scalar range[]
          ellipMapper.SetScalarRange((double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)plane.GetOutput()).GetScalarRange()[1]);
          ellipActor = new vtkActor();
          ellipActor.SetMapper((vtkMapper)ellipMapper);
          //[]
          // Create outline around data[]
          //[]
          outline = new vtkOutlineFilter();
          outline.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          outlineMapper = vtkPolyDataMapper.New();
          outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outlineMapper);
          outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0);
          //[]
          // Create cone indicating application of load[]
          //[]
          coneSrc = new vtkConeSource();
          coneSrc.SetRadius((double).5);
          coneSrc.SetHeight((double)2);
          coneMap = vtkPolyDataMapper.New();
          coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort());
          coneActor = new vtkActor();
          coneActor.SetMapper((vtkMapper)coneMap);
          coneActor.SetPosition((double)0,(double)0,(double)11);
          coneActor.RotateY((double)90);
          coneActor.GetProperty().SetColor((double)1,(double)0,(double)0);
          camera = new vtkCamera();
          camera.SetFocalPoint((double)0.113766,(double)-1.13665,(double)-1.01919);
          camera.SetPosition((double)-29.4886,(double)-63.1488,(double)26.5807);
          camera.SetViewAngle((double)24.4617);
          camera.SetViewUp((double)0.17138,(double)0.331163,(double)0.927879);
          camera.SetClippingRange((double)1,(double)100);
          ren1.AddActor((vtkProp)ellipActor);
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)coneActor);
          ren1.SetBackground((double)1.0,(double)1.0,(double)1.0);
          ren1.SetActiveCamera((vtkCamera)camera);
          renWin.SetSize((int)400,(int)400);
          renWin.Render();
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // OBJECT
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Initializes a new instance of the <see cref="TextDocumentItemViewModel"/> class.
        /// </summary>
        public VTKDocumentItemViewModel(VTKDataModel dataModel)
        {
            this.Title = string.Format("VTK Doc {0}", counter++);
            this.Text = string.Format("Dynamically created at {0}", DateTime.Now);
            this.Description = "VTK document";
            this.vtkData = dataModel;

            this.CellAttributeArrayNames = new ObservableCollection<string>();
            this.CellAttributeArrayNames.Add(this.vtkData.CellIdsArrayName);
            this.CellAttributeArrayNames.Add(this.vtkData.CellTypeArrayName);
            this.cellColorArrayName = this.CellAttributeArrayNames[0];
            this.cellColorMapSpaceModel = ColorSpaceModel.HSV;

            // create a VTK output control and make the forms host point to it
            rwc = new RenderWindowControl();
            wfh = new WindowsFormsHost();
            wfh.Child = rwc;
            rwc.CreateGraphics();
            rwc.RenderWindow.SetCurrentCursor(9);

            vtkInteractorStyleSwitch istyle = vtkInteractorStyleSwitch.New();
            rwc.RenderWindow.GetInteractor().SetInteractorStyle(istyle);
            rwc.RenderWindow.GetInteractor().SetPicker(vtkCellPicker.New());
            (istyle).SetCurrentStyleToTrackballCamera();

            rwc.RenderWindow.GetInteractor().LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(leftMouseDown);

            // set up basic viewing
            ren = rwc.RenderWindow.GetRenderers().GetFirstRenderer();
            vtkCamera camera = ren.GetActiveCamera();

            // background color
            ren.SetBackground(0.1, 0.1, 0.1);

            vtkSphereSource sph = vtkSphereSource.New();
            sph.SetThetaResolution(16);
            sph.SetPhiResolution(16);
            sph.SetRadius(0.02);

            vtkGlyph3D glyp = vtkGlyph3D.New();
            glyp.SetSourceConnection(sph.GetOutputPort(0));
            glyp.SetInputConnection(this.vtkData.OutputPort);
            glyp.ScalingOff();
            glyp.OrientOff();

            ctf = vtkColorTransferFunction.New();
            ctf_min_color = System.Windows.Media.Color.FromRgb(0, 128, 255);
            ctf_max_color = System.Windows.Media.Color.FromRgb(64, 255, 64);
            this.BuildCTF();

            //lut.SetValueRange(0.5, 1.0);
            //lut.SetSaturationRange(0.1, 1.0);
            //lut.SetHueRange(0.4, 0.6);
            //lut.SetAlphaRange(0.2, 1.0);
            //lut.SetRampToLinear();
            //lut.Build();

            mapper = vtkPolyDataMapper.New();
            mapper.SetInputConnection(glyp.GetOutputPort());
            mapper.SetLookupTable(ctf);
            mapper.ScalarVisibilityOn();
            mapper.SetScalarModeToUsePointFieldData();
            mapper.SelectColorArray(this.cellColorArrayName);
            // scalar range doens't affect anything when using a ctf (instead of a lut)
            // mapper.SetScalarRange(0, this.vtkData.NumPoints - 1);

            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);
            //actor.GetProperty().SetRepresentationToWireframe();
            actor.GetProperty().SetRepresentationToSurface();
            rwc.RenderWindow.GetRenderers().GetFirstRenderer().AddViewProp(actor);
            ren.ResetCamera();
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestMultiBlockStreamer(String [] argv)
    {
        //Prefix Content is: ""

          // we need to use composite data pipeline with multiblock datasets[]
          alg = new vtkAlgorithm();
          pip = new vtkCompositeDataPipeline();
          vtkAlgorithm.SetDefaultExecutivePrototype((vtkExecutive)pip);
          //skipping Delete pip
          Ren1 = vtkRenderer.New();
          Ren1.SetBackground((double)0.33,(double)0.35,(double)0.43);

          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)Ren1);

          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);

          Plot3D0 = new vtkPLOT3DReader();
          Plot3D0.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin");
          Plot3D0.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin");
          Plot3D0.SetBinaryFile((int)1);
          Plot3D0.SetMultiGrid((int)0);
          Plot3D0.SetHasByteCount((int)0);
          Plot3D0.SetIBlanking((int)0);
          Plot3D0.SetTwoDimensionalGeometry((int)0);
          Plot3D0.SetForceRead((int)0);
          Plot3D0.SetByteOrder((int)0);

          Geometry5 = new vtkStructuredGridOutlineFilter();
          Geometry5.SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort());

          Mapper5 = vtkPolyDataMapper.New();
          Mapper5.SetInputConnection((vtkAlgorithmOutput)Geometry5.GetOutputPort());
          Mapper5.SetImmediateModeRendering((int)1);
          Mapper5.UseLookupTableScalarRangeOn();
          Mapper5.SetScalarVisibility((int)0);
          Mapper5.SetScalarModeToDefault();

          Actor5 = new vtkActor();
          Actor5.SetMapper((vtkMapper)Mapper5);
          Actor5.GetProperty().SetRepresentationToSurface();
          Actor5.GetProperty().SetInterpolationToGouraud();
          Actor5.GetProperty().SetAmbient((double)0.15);
          Actor5.GetProperty().SetDiffuse((double)0.85);
          Actor5.GetProperty().SetSpecular((double)0.1);
          Actor5.GetProperty().SetSpecularPower((double)100);
          Actor5.GetProperty().SetSpecularColor((double)1,(double)1,(double)1);

          Actor5.GetProperty().SetColor((double)1,(double)1,(double)1);
          Ren1.AddActor((vtkProp)Actor5);

          ExtractGrid[0] = new vtkExtractGrid();
          ExtractGrid[0].SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort());
          ExtractGrid[0].SetVOI((int)0,(int)14,(int)0,(int)32,(int)0,(int)24);
          ExtractGrid[0].SetSampleRate((int)1,(int)1,(int)1);
          ExtractGrid[0].SetIncludeBoundary((int)0);

          ExtractGrid[1] = new vtkExtractGrid();
          ExtractGrid[1].SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort());
          ExtractGrid[1].SetVOI((int)14,(int)29,(int)0,(int)32,(int)0,(int)24);
          ExtractGrid[1].SetSampleRate((int)1,(int)1,(int)1);
          ExtractGrid[1].SetIncludeBoundary((int)0);

          ExtractGrid[2] = new vtkExtractGrid();
          ExtractGrid[2].SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort());
          ExtractGrid[2].SetVOI((int)29,(int)56,(int)0,(int)32,(int)0,(int)24);
          ExtractGrid[2].SetSampleRate((int)1,(int)1,(int)1);
          ExtractGrid[2].SetIncludeBoundary((int)0);

          LineSourceWidget0 = new vtkLineSource();
          LineSourceWidget0.SetPoint1((double)3.05638,(double)-3.00497,(double)28.2211);
          LineSourceWidget0.SetPoint2((double)3.05638,(double)3.95916,(double)28.2211);
          LineSourceWidget0.SetResolution((int)20);

          mbds = new vtkMultiBlockDataSet();
          mbds.SetNumberOfBlocks((uint)3);
          i = 0;
          while((i) < 3)
        {
          ExtractGrid[i].Update();
          sg[i] = vtkStructuredGrid.New();
          sg[i].ShallowCopy(ExtractGrid[i].GetOutput());
          mbds.SetBlock((uint)i, sg[i]);
          //skipping Delete sg[i]
          i = i + 1;
        }

          Stream0 = new vtkStreamTracer();
          Stream0.SetInput((vtkDataObject)mbds);
          Stream0.SetSource((vtkDataSet)LineSourceWidget0.GetOutput());
          Stream0.SetIntegrationStepUnit(2);
          Stream0.SetMaximumPropagation((double)20);
          Stream0.SetInitialIntegrationStep((double)0.5);
          Stream0.SetIntegrationDirection((int)0);
          Stream0.SetIntegratorType((int)0);
          Stream0.SetMaximumNumberOfSteps((int)2000);
          Stream0.SetTerminalSpeed((double)1e-12);

          //skipping Delete mbds

          aa = new vtkAssignAttribute();
          aa.SetInputConnection((vtkAlgorithmOutput)Stream0.GetOutputPort());
          aa.Assign((string)"Normals",(string)"NORMALS",(string)"POINT_DATA");

          Ribbon0 = new vtkRibbonFilter();
          Ribbon0.SetInputConnection((vtkAlgorithmOutput)aa.GetOutputPort());
          Ribbon0.SetWidth((double)0.1);
          Ribbon0.SetAngle((double)0);
          Ribbon0.SetDefaultNormal((double)0,(double)0,(double)1);
          Ribbon0.SetVaryWidth((int)0);

          LookupTable1 = new vtkLookupTable();
          LookupTable1.SetNumberOfTableValues((int)256);
          LookupTable1.SetHueRange((double)0,(double)0.66667);
          LookupTable1.SetSaturationRange((double)1,(double)1);
          LookupTable1.SetValueRange((double)1,(double)1);
          LookupTable1.SetTableRange((double)0.197813,(double)0.710419);
          LookupTable1.SetVectorComponent((int)0);
          LookupTable1.Build();

          Mapper10 = vtkPolyDataMapper.New();
          Mapper10.SetInputConnection((vtkAlgorithmOutput)Ribbon0.GetOutputPort());
          Mapper10.SetImmediateModeRendering((int)1);
          Mapper10.UseLookupTableScalarRangeOn();
          Mapper10.SetScalarVisibility((int)1);
          Mapper10.SetScalarModeToUsePointFieldData();
          Mapper10.SelectColorArray((string)"Density");
          Mapper10.SetLookupTable((vtkScalarsToColors)LookupTable1);

          Actor10 = new vtkActor();
          Actor10.SetMapper((vtkMapper)Mapper10);
          Actor10.GetProperty().SetRepresentationToSurface();
          Actor10.GetProperty().SetInterpolationToGouraud();
          Actor10.GetProperty().SetAmbient((double)0.15);
          Actor10.GetProperty().SetDiffuse((double)0.85);
          Actor10.GetProperty().SetSpecular((double)0);
          Actor10.GetProperty().SetSpecularPower((double)1);
          Actor10.GetProperty().SetSpecularColor((double)1,(double)1,(double)1);
          Ren1.AddActor((vtkProp)Actor10);

          // enable user interface interactor[]
          iren.Initialize();
          // prevent the tk window from showing up then start the event loop[]
          vtkAlgorithm.SetDefaultExecutivePrototype(null);
          //skipping Delete alg

        //deleteAllVTKObjects();
    }
Esempio n. 7
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVHyper(String [] argv)
    {
        //Prefix Content is: ""

          // Create the RenderWindow, Renderer and interactive renderer[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          VTK_INTEGRATE_BOTH_DIRECTIONS = 2;
          //[]
          // generate tensors[]
          ptLoad = new vtkPointLoad();
          ptLoad.SetLoadValue((double)100.0);
          ptLoad.SetSampleDimensions((int)20,(int)20,(int)20);
          ptLoad.ComputeEffectiveStressOn();
          ptLoad.SetModelBounds((double)-10,(double)10,(double)-10,(double)10,(double)-10,(double)10);
          //[]
          // If the current directory is writable, then test the witers[]
          //[]
          try
          {
         channel = new StreamWriter("test.tmp");
          tryCatchError = "NOERROR";
          }
          catch(Exception)
          {tryCatchError = "ERROR";}

        if(tryCatchError.Equals("NOERROR"))
          {
          channel.Close();
          File.Delete("test.tmp");
          wSP = new vtkDataSetWriter();
          wSP.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          wSP.SetFileName((string)"wSP.vtk");
          wSP.SetTensorsName((string)"pointload");
          wSP.SetScalarsName((string)"effective_stress");
          wSP.Write();
          rSP = new vtkDataSetReader();
          rSP.SetFileName((string)"wSP.vtk");
          rSP.SetTensorsName((string)"pointload");
          rSP.SetScalarsName((string)"effective_stress");
          rSP.Update();
          input = rSP.GetOutput();
          File.Delete("wSP.vtk");
        }
          else
        {
          input = ptLoad.GetOutput();
        }

          // Generate hyperstreamlines[]
          s1 = new vtkHyperStreamline();
          s1.SetInputData((vtkDataObject)input);
          s1.SetStartPosition((double)9,(double)9,(double)-9);
          s1.IntegrateMinorEigenvector();
          s1.SetMaximumPropagationDistance((double)18.0);
          s1.SetIntegrationStepLength((double)0.1);
          s1.SetStepLength((double)0.01);
          s1.SetRadius((double)0.25);
          s1.SetNumberOfSides((int)18);
          s1.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s1.Update();
          // Map hyperstreamlines[]
          lut = new vtkLogLookupTable();
          lut.SetHueRange((double).6667,(double)0.0);
          s1Mapper = vtkPolyDataMapper.New();
          s1Mapper.SetInputConnection((vtkAlgorithmOutput)s1.GetOutputPort());
          s1Mapper.SetLookupTable((vtkScalarsToColors)lut);
          ptLoad.Update();
          //force update for scalar range[]
          s1Mapper.SetScalarRange((double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[1]);
          s1Actor = new vtkActor();
          s1Actor.SetMapper((vtkMapper)s1Mapper);
          s2 = new vtkHyperStreamline();
          s2.SetInputData((vtkDataObject)input);
          s2.SetStartPosition((double)-9,(double)-9,(double)-9);
          s2.IntegrateMinorEigenvector();
          s2.SetMaximumPropagationDistance((double)18.0);
          s2.SetIntegrationStepLength((double)0.1);
          s2.SetStepLength((double)0.01);
          s2.SetRadius((double)0.25);
          s2.SetNumberOfSides((int)18);
          s2.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s2.Update();
          s2Mapper = vtkPolyDataMapper.New();
          s2Mapper.SetInputConnection((vtkAlgorithmOutput)s2.GetOutputPort());
          s2Mapper.SetLookupTable((vtkScalarsToColors)lut);
          s2Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0],(double)((vtkDataSet)input).GetScalarRange()[1]);
          s2Actor = new vtkActor();
          s2Actor.SetMapper((vtkMapper)s2Mapper);
          s3 = new vtkHyperStreamline();
          s3.SetInputData((vtkDataObject)input);
          s3.SetStartPosition((double)9,(double)-9,(double)-9);
          s3.IntegrateMinorEigenvector();
          s3.SetMaximumPropagationDistance((double)18.0);
          s3.SetIntegrationStepLength((double)0.1);
          s3.SetStepLength((double)0.01);
          s3.SetRadius((double)0.25);
          s3.SetNumberOfSides((int)18);
          s3.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s3.Update();
          s3Mapper = vtkPolyDataMapper.New();
          s3Mapper.SetInputConnection((vtkAlgorithmOutput)s3.GetOutputPort());
          s3Mapper.SetLookupTable((vtkScalarsToColors)lut);
          s3Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0],
          (double)((vtkDataSet)input).GetScalarRange()[1]);
          s3Actor = new vtkActor();
          s3Actor.SetMapper((vtkMapper)s3Mapper);
          s4 = new vtkHyperStreamline();
          s4.SetInputData((vtkDataObject)input);
          s4.SetStartPosition((double)-9,(double)9,(double)-9);
          s4.IntegrateMinorEigenvector();
          s4.SetMaximumPropagationDistance((double)18.0);
          s4.SetIntegrationStepLength((double)0.1);
          s4.SetStepLength((double)0.01);
          s4.SetRadius((double)0.25);
          s4.SetNumberOfSides((int)18);
          s4.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s4.Update();
          s4Mapper = vtkPolyDataMapper.New();
          s4Mapper.SetInputConnection((vtkAlgorithmOutput)s4.GetOutputPort());
          s4Mapper.SetLookupTable((vtkScalarsToColors)lut);
          s4Mapper.SetScalarRange((double)((vtkDataSet)input).GetScalarRange()[0],(double)((vtkDataSet)input).GetScalarRange()[1]);
          s4Actor = new vtkActor();
          s4Actor.SetMapper((vtkMapper)s4Mapper);
          // plane for context[]
          //[]
          g = new vtkImageDataGeometryFilter();
          g.SetInputData((vtkDataObject)input);
          g.SetExtent((int)0,(int)100,(int)0,(int)100,(int)0,(int)0);
          g.Update();
          //for scalar range[]
          gm = vtkPolyDataMapper.New();
          gm.SetInputConnection((vtkAlgorithmOutput)g.GetOutputPort());
          gm.SetScalarRange((double)((vtkDataSet)g.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)g.GetOutput()).GetScalarRange()[1]);
          ga = new vtkActor();
          ga.SetMapper((vtkMapper)gm);
          // Create outline around data[]
          //[]
          outline = new vtkOutlineFilter();
          outline.SetInputData((vtkDataObject)input);
          outlineMapper = vtkPolyDataMapper.New();
          outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outlineMapper);
          outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0);
          // Create cone indicating application of load[]
          //[]
          coneSrc = new vtkConeSource();
          coneSrc.SetRadius((double).5);
          coneSrc.SetHeight((double)2);
          coneMap = vtkPolyDataMapper.New();
          coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort());
          coneActor = new vtkActor();
          coneActor.SetMapper((vtkMapper)coneMap);
          coneActor.SetPosition((double)0,(double)0,(double)11);
          coneActor.RotateY((double)90);
          coneActor.GetProperty().SetColor((double)1,(double)0,(double)0);
          camera = new vtkCamera();
          camera.SetFocalPoint((double)0.113766,(double)-1.13665,(double)-1.01919);
          camera.SetPosition((double)-29.4886,(double)-63.1488,(double)26.5807);
          camera.SetViewAngle((double)24.4617);
          camera.SetViewUp((double)0.17138,(double)0.331163,(double)0.927879);
          camera.SetClippingRange((double)1,(double)100);
          ren1.AddActor((vtkProp)s1Actor);
          ren1.AddActor((vtkProp)s2Actor);
          ren1.AddActor((vtkProp)s3Actor);
          ren1.AddActor((vtkProp)s4Actor);
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)coneActor);
          ren1.AddActor((vtkProp)ga);
          ren1.SetBackground((double)1.0,(double)1.0,(double)1.0);
          ren1.SetActiveCamera((vtkCamera)camera);
          renWin.SetSize((int)300,(int)300);
          renWin.Render();
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Esempio n. 8
0
        //Parameters for building a model

        private void BasicVTKBuilder(ref vtkActor actor, ref vtkPoints points, ref vtkCellArray polys,
                                     ref vtkFloatArray scalars, ref vtkLookupTable Luk, ref vtkActor2D actor2D)
        {
            int pointsNum = 0;

            TowerModelInstance.VTKDrawModel(ref points, ref polys, ref scalars, ref pointsNum, paras);

            vtkPolyData profile = vtkPolyData.New();

            profile.SetPoints(points);
            profile.SetPolys(polys);

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            if (paras.RotateAngle == 0)
            {
                profile.GetCellData().SetScalars(scalars);
                mapper.SetInput(profile);
            }
            else
            {
                vtkRotationalExtrusionFilter refilter = vtkRotationalExtrusionFilter.New();
                profile.Update();
                profile.GetCellData().SetScalars(scalars);
                //profile.GetPointData().SetScalars(scalars);
                refilter.SetInput(profile);
                refilter.SetResolution(50);
                refilter.SetAngle(paras.RotateAngle);
                refilter.SetTranslation(0);
                refilter.SetDeltaRadius(0);

                mapper.SetInputConnection(refilter.GetOutputPort());
            }

            mapper.SetScalarRange(TowerModelInstance.GetColorGenColorTableMinvalue(),
                                  TowerModelInstance.GetColorGenColorTableMaxValue());
            actor.SetMapper(mapper);

            // This text property is for scalarBar
            vtkTextProperty textProperty = vtkTextProperty.New();

            //textProperty.SetFontFamilyToCourier();
            //textProperty.SetColor(1.0, 1.0, 0.5);
            textProperty.SetFontSize(10);

            vtkScalarBarActor scalarBar = vtkScalarBarActor.New();

            scalarBar.SetLookupTable(mapper.GetLookupTable());
            scalarBar.SetTitle("Color Table");
            scalarBar.SetNumberOfLabels(TowerModelInstance.GetColorGenColorTableSize());
            scalarBar.SetTitleTextProperty(textProperty);
            scalarBar.SetLabelTextProperty(textProperty);
            scalarBar.SetWidth(0.07);
            scalarBar.SetHeight(0.6);
            //scalarBar.SetDrawFrame(1);

            vtkLookupTable hueLut = vtkLookupTable.New();

            hueLut.SetTableRange(TowerModelInstance.GetColorGenColorTableMinvalue(),
                                 TowerModelInstance.GetColorGenColorTableMaxValue());
            hueLut.SetHueRange(0.667, 0);
            hueLut.SetSaturationRange(1, 1);
            hueLut.SetValueRange(1, 1);
            hueLut.SetNumberOfTableValues(TowerModelInstance.GetColorGenColorTableSize());
            hueLut.Build();

            mapper.SetLookupTable(hueLut);
            scalarBar.SetLookupTable(hueLut);

            // The actor links the data pipeline to the rendering subsystem
            actor2D = scalarBar;
            //actor.GetProperty().SetColor(0.388, 0.388, 0.388);
        }
        private void RenderXYZColor()
        {
            FileStream   fs = null;
            StreamReader sr = null;
            String       sLineBuffer;

            String[]  sXYZ;
            char[]    chDelimiter = new char[] { ' ', '\t', ';' };
            double[]  xyz         = new double[3];
            double[]  rgb         = new double[3];
            vtkPoints points      = vtkPoints.New();
            vtkPoints colors      = vtkPoints.New();
            int       cnt         = 0;

            try
            {
                // in case file must be open in another application too use "FileShare.ReadWrite"
                fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                sr = new StreamReader(fs);

                vtkDoubleArray colorScalor = new vtkDoubleArray();
                int            n           = 1;
                while (!sr.EndOfStream)
                {
                    sLineBuffer = sr.ReadLine();
                    cnt++;
                    sXYZ = sLineBuffer.Split(chDelimiter, StringSplitOptions.RemoveEmptyEntries);
                    if (sXYZ == null || sXYZ.Length != 6)
                    {
                        MessageBox.Show("data seems to be in wrong format at line " + cnt, "Format Exception", MessageBoxButtons.OK);
                        return;
                    }
                    xyz[0] = double.Parse(sXYZ[0], CultureInfo.InvariantCulture) * 11100;
                    xyz[1] = double.Parse(sXYZ[1], CultureInfo.InvariantCulture) * 11100;
                    xyz[2] = double.Parse(sXYZ[2], CultureInfo.InvariantCulture);

                    rgb[0] = double.Parse(sXYZ[0], CultureInfo.InvariantCulture);
                    rgb[1] = double.Parse(sXYZ[1], CultureInfo.InvariantCulture);
                    rgb[2] = double.Parse(sXYZ[2], CultureInfo.InvariantCulture);

                    points.InsertNextPoint(xyz[0], xyz[1], xyz[2]);
                    colors.InsertNextPoint(rgb[0], rgb[1], rgb[2]);
                    colorScalor.InsertNextTuple1(n++);
                }
                vtkPolyData polydata = vtkPolyData.New();
                polydata.SetPoints(points);
                polydata.GetPointData().SetScalars(colorScalor); //设置点的Scalar(标量)属性

                vtkVertexGlyphFilter glyphFilter = vtkVertexGlyphFilter.New();
                glyphFilter.SetInputConnection(polydata.GetProducerPort());

                vtkLookupTable lookupTable = new vtkLookupTable();
                lookupTable.SetNumberOfColors(n);
                // SetSetTableValue(vtkIdType  indx, double r, double g, double  b, double a);
                Random random = new Random();
                for (int i = 0; i < n; i++)
                {
                    double[] tmp = colors.GetPoint(i);
                    double   r   = tmp[0];
                    double   g   = tmp[1];
                    double   b   = tmp[2];
                    lookupTable.SetTableValue(i, r, g, b, 1);
                }

                // Visualize
                vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
                mapper.SetInputConnection(glyphFilter.GetOutputPort());
                mapper.SetLookupTable(lookupTable);
                mapper.SetScalarRange(1, n);

                vtkActor actor = vtkActor.New();
                actor.SetMapper(mapper);
                actor.GetProperty().SetPointSize(1);
                //actor.GetProperty().SetColor(1, 0.5, 0);
                // add our actor to the renderer
                m_Renderer.AddActor(actor);
                imgPropList.Add(actor);

                m_Renderer.ResetCamera();

                //Rerender the screen
                m_RenderWindow.Render();
                m_Renderer.Render();
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message, "IOException", MessageBoxButtons.OK);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                    sr.Dispose();
                    sr = null;
                }
            }
        }
Esempio n. 10
0
        private void FilledContours(string filePath, int numberOfContours)
        {
            // Read the file
            vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();

            reader.SetFileName(filePath);
            reader.Update(); // Update so that we can get the scalar range

            double[] scalarRange = reader.GetOutput().GetPointData().GetScalars().GetRange();

            vtkAppendPolyData appendFilledContours = vtkAppendPolyData.New();

            double delta = (scalarRange[1] - scalarRange[0]) / (numberOfContours - 1);

            // Keep the clippers alive
            List <vtkClipPolyData> clippersLo = new List <vtkClipPolyData>();
            List <vtkClipPolyData> clippersHi = new List <vtkClipPolyData>();

            for (int i = 0; i < numberOfContours; i++)
            {
                double valueLo = scalarRange[0] + i * delta;
                double valueHi = scalarRange[0] + (i + 1) * delta;

                clippersLo.Add(vtkClipPolyData.New());
                clippersLo[i].SetValue(valueLo);
                if (i == 0)
                {
                    clippersLo[i].SetInputConnection(reader.GetOutputPort());
                }
                else
                {
                    clippersLo[i].SetInputConnection(clippersHi[i - 1].GetOutputPort(1));
                }
                clippersLo[i].InsideOutOff();
                clippersLo[i].Update();

                clippersHi.Add(vtkClipPolyData.New());
                clippersHi[i].SetValue(valueHi);
                clippersHi[i].SetInputConnection(clippersLo[i].GetOutputPort());
                clippersHi[i].GenerateClippedOutputOn();
                clippersHi[i].InsideOutOn();
                clippersHi[i].Update();
                if (clippersHi[i].GetOutput().GetNumberOfCells() == 0)
                {
                    continue;
                }

                vtkFloatArray cd = vtkFloatArray.New();
                cd.SetNumberOfComponents(1);
                cd.SetNumberOfTuples(clippersHi[i].GetOutput().GetNumberOfCells());
                cd.FillComponent(0, valueLo);

                clippersHi[i].GetOutput().GetCellData().SetScalars(cd);
                appendFilledContours.AddInputConnection(clippersHi[i].GetOutputPort());
            }

            vtkCleanPolyData filledContours = vtkCleanPolyData.New();

            filledContours.SetInputConnection(appendFilledContours.GetOutputPort());

            vtkLookupTable lut = vtkLookupTable.New();

            lut.SetNumberOfTableValues(numberOfContours + 1);
            lut.Build();
            vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New();

            contourMapper.SetInputConnection(filledContours.GetOutputPort());
            contourMapper.SetScalarRange(scalarRange[0], scalarRange[1]);
            contourMapper.SetScalarModeToUseCellData();
            contourMapper.SetLookupTable(lut);

            vtkActor contourActor = vtkActor.New();

            contourActor.SetMapper(contourMapper);
            contourActor.GetProperty().SetInterpolationToFlat();

            vtkContourFilter contours = vtkContourFilter.New();

            contours.SetInputConnection(filledContours.GetOutputPort());
            contours.GenerateValues(numberOfContours, scalarRange[0], scalarRange[1]);

            vtkPolyDataMapper contourLineMapperer = vtkPolyDataMapper.New();

            contourLineMapperer.SetInputConnection(contours.GetOutputPort());
            contourLineMapperer.SetScalarRange(scalarRange[0], scalarRange[1]);
            contourLineMapperer.ScalarVisibilityOff();

            vtkActor contourLineActor = vtkActor.New();

            contourLineActor.SetMapper(contourLineMapperer);
            contourLineActor.GetProperty().SetLineWidth(2);

            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();

            // set background color
            renderer.SetBackground(.2, .3, .4);
            // add our actor to the renderer
            renderer.AddActor(contourActor);
            renderer.AddActor(contourLineActor);
        }
Esempio n. 11
0
        private void DrawRainBow()
        {
            //# First create pipeline a simple pipeline that reads a structure grid
            //# and then extracts a plane from the grid. The plane will be colored
            //# differently by using different lookup tables.
            //#
            //# Note: the Update method is manually invoked because it causes the
            //# reader to read; later on we use the output of the reader to set
            //# a range for the scalar values.
            vtkMultiBlockPLOT3DReader pl3d = vtkMultiBlockPLOT3DReader.New();

            pl3d.SetXYZFileName(@"..\..\Data\combxyz.bin");
            pl3d.SetQFileName(@"..\..\Data\combq.bin");
            pl3d.SetScalarFunctionNumber(100);
            pl3d.SetVectorFunctionNumber(202);
            pl3d.Update();
            vtkDataObject pl3d_output = pl3d.GetOutput().GetBlock(0);

            vtkStructuredGridGeometryFilter planeFilter = vtkStructuredGridGeometryFilter.New();

            planeFilter.SetInputData(pl3d_output);
            planeFilter.SetExtent(1, 100, 1, 100, 7, 7);
            vtkLookupTable    lut         = vtkLookupTable.New();
            vtkPolyDataMapper planeMapper = vtkPolyDataMapper.New();

            planeMapper.SetLookupTable(lut);
            planeMapper.SetInputConnection(planeFilter.GetOutputPort());
            //planeMapper.SetScalarRange(pl3d_output.)
            vtkActor planeActor = vtkActor.New();

            planeActor.SetMapper(planeMapper);

            //this creates an outline around the data
            vtkStructuredGridOutlineFilter outlineFilter = vtkStructuredGridOutlineFilter.New();

            outlineFilter.SetInputData(pl3d_output);
            vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New();

            outlineMapper.SetInputConnection(outlineFilter.GetOutputPort());
            vtkActor outlineActor = vtkActor.New();

            outlineActor.SetMapper(outlineMapper);

            //Much of the following is commented out. To try different lookup tables.
            //This create a black to white lut
            //lut.SetHueRange(0, 0);
            //lut.SetSaturationRange(0, 0);
            //lut.SetValueRange(0.2, 1.0);

            //This creates a red to blue lut
            //lut.SetHueRange(0.0, 0.677);

            //This creates a blue to red lue
            lut.SetHueRange(0.667, 0.0);

            //This creates a weird effect. the Build() method cause lookup
            //table to allocate memory and create a table based on the correct
            //hue, saturatioin, value, and alpha range. Here we then
            //manully overwrite the value generated by the Build() method.
            lut.SetNumberOfColors(256);
            lut.Build();
            for (int i = 0; i < 16; i++)
            {
                lut.SetTableValue(i * 16, (float)Color.Red.R / 256, (float)Color.Red.G / 256, (float)Color.Red.B / 256, 1);
                lut.SetTableValue(i * 16 + 1, (float)Color.Green.R / 256, (float)Color.Green.G / 256, (float)Color.Green.B / 256, 1);
                lut.SetTableValue(i * 16 + 2, (float)Color.Blue.R / 256, (float)Color.Blue.G / 256, (float)Color.Blue.B / 256, 1);
                lut.SetTableValue(i * 16 + 3, (float)Color.Black.R / 256, (float)Color.Black.G / 256, (float)Color.Black.B / 256, 1);
            }


            //Create the renderwindow, the render and both actors
            vtkRenderer     ren    = vtkRenderer.New();
            vtkRenderWindow renWin = myRenderWindowControl.RenderWindow;

            renWin.AddRenderer(ren);

            //Add the actors to the renderer, set the backgroud
            ren.AddActor(outlineActor);
            ren.AddActor(planeActor);

            ren.SetBackground(0.1, 0.2, 0.4);
            ren.TwoSidedLightingOff();
        }
Esempio n. 12
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVHyperScalarBar(String [] argv)
    {
        //Prefix Content is: ""

          // Test the scalar bar actor using a logarithmic lookup table[]
          //[]
          VTK_INTEGRATE_BOTH_DIRECTIONS = 2;
          //[]
          // generate tensors[]
          ptLoad = new vtkPointLoad();
          ptLoad.SetLoadValue((double)100.0);
          ptLoad.SetSampleDimensions((int)20,(int)20,(int)20);
          ptLoad.ComputeEffectiveStressOn();
          ptLoad.SetModelBounds((double)-10,(double)10,(double)-10,(double)10,(double)-10,(double)10);
          // Generate hyperstreamlines[]
          s1 = new vtkHyperStreamline();
          s1.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          s1.SetStartPosition((double)9,(double)9,(double)-9);
          s1.IntegrateMinorEigenvector();
          s1.SetMaximumPropagationDistance((double)18.0);
          s1.SetIntegrationStepLength((double)0.1);
          s1.SetStepLength((double)0.01);
          s1.SetRadius((double)0.25);
          s1.SetNumberOfSides((int)18);
          s1.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s1.Update();
          // Map hyperstreamlines[]
          lut = new vtkLogLookupTable();
          lut.SetHueRange((double).6667,(double)0.0);
          scalarBar = new vtkScalarBarActor();
          scalarBar.SetLookupTable((vtkScalarsToColors)lut);
          scalarBar.SetTitle((string)"Stress");
          scalarBar.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport();
          scalarBar.GetPositionCoordinate().SetValue((double)0.1,(double)0.05);
          scalarBar.SetOrientationToVertical();
          scalarBar.SetWidth((double)0.1);
          scalarBar.SetHeight((double)0.9);
          scalarBar.SetPosition((double)0.01,(double)0.1);
          scalarBar.SetLabelFormat((string)"%-#6.3f");
          scalarBar.GetLabelTextProperty().SetColor((double)1,(double)0,(double)0);
          scalarBar.GetTitleTextProperty().SetColor((double)1,(double)0,(double)0);
          s1Mapper = vtkPolyDataMapper.New();
          s1Mapper.SetInputConnection((vtkAlgorithmOutput)s1.GetOutputPort());
          s1Mapper.SetLookupTable((vtkScalarsToColors)lut);
          ptLoad.Update();
          //force update for scalar range[]
          s1Mapper.SetScalarRange((double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[1]);
          s1Actor = new vtkActor();
          s1Actor.SetMapper((vtkMapper)s1Mapper);
          s2 = new vtkHyperStreamline();
          s2.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          s2.SetStartPosition((double)-9,(double)-9,(double)-9);
          s2.IntegrateMinorEigenvector();
          s2.SetMaximumPropagationDistance((double)18.0);
          s2.SetIntegrationStepLength((double)0.1);
          s2.SetStepLength((double)0.01);
          s2.SetRadius((double)0.25);
          s2.SetNumberOfSides((int)18);
          s2.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s2.Update();
          s2Mapper = vtkPolyDataMapper.New();
          s2Mapper.SetInputConnection((vtkAlgorithmOutput)s2.GetOutputPort());
          s2Mapper.SetLookupTable((vtkScalarsToColors)lut);
          s2Mapper.SetScalarRange((double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[1]);
          s2Actor = new vtkActor();
          s2Actor.SetMapper((vtkMapper)s2Mapper);
          s3 = new vtkHyperStreamline();
          s3.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          s3.SetStartPosition((double)9,(double)-9,(double)-9);
          s3.IntegrateMinorEigenvector();
          s3.SetMaximumPropagationDistance((double)18.0);
          s3.SetIntegrationStepLength((double)0.1);
          s3.SetStepLength((double)0.01);
          s3.SetRadius((double)0.25);
          s3.SetNumberOfSides((int)18);
          s3.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s3.Update();
          s3Mapper = vtkPolyDataMapper.New();
          s3Mapper.SetInputConnection((vtkAlgorithmOutput)s3.GetOutputPort());
          s3Mapper.SetLookupTable((vtkScalarsToColors)lut);
          s3Mapper.SetScalarRange((double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[1]);
          s3Actor = new vtkActor();
          s3Actor.SetMapper((vtkMapper)s3Mapper);
          s4 = new vtkHyperStreamline();
          s4.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          s4.SetStartPosition((double)-9,(double)9,(double)-9);
          s4.IntegrateMinorEigenvector();
          s4.SetMaximumPropagationDistance((double)18.0);
          s4.SetIntegrationStepLength((double)0.1);
          s4.SetStepLength((double)0.01);
          s4.SetRadius((double)0.25);
          s4.SetNumberOfSides((int)18);
          s4.SetIntegrationDirection((int)VTK_INTEGRATE_BOTH_DIRECTIONS);
          s4.Update();
          s4Mapper = vtkPolyDataMapper.New();
          s4Mapper.SetInputConnection((vtkAlgorithmOutput)s4.GetOutputPort());
          s4Mapper.SetLookupTable((vtkScalarsToColors)lut);
          s4Mapper.SetScalarRange((double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)ptLoad.GetOutput()).GetScalarRange()[1]);
          s4Actor = new vtkActor();
          s4Actor.SetMapper((vtkMapper)s4Mapper);
          // plane for context[]
          //[]
          g = new vtkImageDataGeometryFilter();
          g.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          g.SetExtent((int)0,(int)100,(int)0,(int)100,(int)0,(int)0);
          g.Update();
          //for scalar range[]
          gm = vtkPolyDataMapper.New();
          gm.SetInputConnection((vtkAlgorithmOutput)g.GetOutputPort());
          gm.SetScalarRange((double)((vtkImageDataGeometryFilter)g).GetOutput().GetScalarRange()[0], (double)((vtkImageDataGeometryFilter)g).GetOutput().GetScalarRange()[1]);
          ga = new vtkActor();
          ga.SetMapper((vtkMapper)gm);
          // Create outline around data[]
          //[]
          outline = new vtkOutlineFilter();
          outline.SetInputConnection((vtkAlgorithmOutput)ptLoad.GetOutputPort());
          outlineMapper = vtkPolyDataMapper.New();
          outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outlineMapper);
          outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0);
          // Create cone indicating application of load[]
          //[]
          coneSrc = new vtkConeSource();
          coneSrc.SetRadius((double).5);
          coneSrc.SetHeight((double)2);
          coneMap = vtkPolyDataMapper.New();
          coneMap.SetInputConnection((vtkAlgorithmOutput)coneSrc.GetOutputPort());
          coneActor = new vtkActor();
          coneActor.SetMapper((vtkMapper)coneMap);
          coneActor.SetPosition((double)0,(double)0,(double)11);
          coneActor.RotateY((double)90);
          coneActor.GetProperty().SetColor((double)1,(double)0,(double)0);
          // Create the rendering infrastructure[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          camera = new vtkCamera();
          camera.SetFocalPoint((double)0.113766,(double)-1.13665,(double)-1.01919);
          camera.SetPosition((double)-29.4886,(double)-63.1488,(double)26.5807);
          camera.SetViewAngle((double)24.4617);
          camera.SetViewUp((double)0.17138,(double)0.331163,(double)0.927879);
          camera.SetClippingRange((double)1,(double)100);
          ren1.AddActor2D((vtkProp)scalarBar);
          ren1.AddActor((vtkProp)s1Actor);
          ren1.AddActor((vtkProp)s2Actor);
          ren1.AddActor((vtkProp)s3Actor);
          ren1.AddActor((vtkProp)s4Actor);
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)coneActor);
          ren1.AddActor((vtkProp)ga);
          ren1.SetBackground((double)1.0,(double)1.0,(double)1.0);
          ren1.SetActiveCamera((vtkCamera)camera);
          renWin.SetSize((int)300,(int)300);
          renWin.Render();
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }