Exemplo n.º 1
0
            public static void OutputImageFromCurrentSence(vtk.vtkRenderWindow renderWin, string outputPath)
            {
                // Create a window to image filter
                using (vtk.vtkWindowToImageFilter filterImage = new vtk.vtkWindowToImageFilter())
                {
                    filterImage.SetInput(renderWin);

                    // PNG Writer
                    using (vtk.vtkPNGWriter pngWriter = new vtk.vtkPNGWriter())
                    {
                        pngWriter.SetFileName(outputPath);
                        pngWriter.SetInput(filterImage.GetOutput());
                        pngWriter.Write();
                    }
                }
            }
Exemplo n.º 2
0
            public void PokeMatrix(vtk.vtkTransform transform)
            {
                InitTraversal();
                for (int iIndex = 0; iIndex < GetNumberOfItems(); ++iIndex)
                {
                    vtk.vtkProp prop = GetNextProp();
                    if (prop == null) continue;

                    prop.PokeMatrix(transform.GetMatrix());
                }
            }
Exemplo n.º 3
0
            public virtual void UpdateCablePosition(vtk.vtkTransform transform)
            {
                if (m_twoPointsIndicator == null) return;

                bool bShowCabling = ApplicationOptions.Instance().ViewOptions.ShowCablingSystem;
                m_twoPointsIndicator.Impl.Actor.SetVisibility(bShowCabling ? 1 : 0);

                // Drive the cable graphics
                IList<CTwoPoints> pointsList = m_twoPointsIndicator.PointsList;

                // Clear the points
                pointsList.Clear();

                foreach (CCableSegment segment in CableSegments)
                {
                    CPoint3D ptStartPoint = segment.StartPoint;
                    if (segment.DriveStartPointAtRuntime)
                    {
                        ptStartPoint = new CPoint3D(transform.TransformDoublePoint(ptStartPoint.Point));
                    }

                    CPoint3D ptEndPoint = segment.EndPoint;
                    if (segment.DriveEndPointAtRuntime)
                    {
                        ptEndPoint = new CPoint3D(transform.TransformDoublePoint(ptEndPoint.Point));
                    }

                    pointsList.Add(new CTwoPoints(ptStartPoint, ptEndPoint));
                }

                // Update
                m_twoPointsIndicator.Impl.UpatePoints();
            }
Exemplo n.º 4
0
            public virtual void OnPipePosChanged(vtk.vtkTransform transform)
            {
                try
                {
                    // Apply the switch condition
                    CCableSwitchLength2StatesCondition condition = m_cableSwitchCondition as CCableSwitchLength2StatesCondition;
                    if (condition != null)
                    {
                        condition.CurrentPipeTransformation = transform;

                        if (ConditionCallback != null)
                        {
                            ConditionCallback(condition.eLengthEqual, transform);
                        }

                        m_cableSwitchCondition.Apply();
                    }

                    // Update the active cable state
                    if (m_activeCableState != null)
                    {
                        m_activeCableState.UpdateCablePosition(transform);
                    }
                }
                catch(Exception ex)
                {
                    string errMsg = ex.Message + "\n" + ex.StackTrace;
                    vtk.vtkOutputWindow.GetInstance().DisplayErrorText(errMsg);
                }
            }
Exemplo n.º 5
0
        void InitializeRenderWindow(vtk.vtkRenderWindow renWin)
        {
            CRendererManager renderManager = IApp.theApp.RendererManager as CRendererManager;
            if (renderManager == null) return;

            renderManager.ActiveRenderChanged += new CRendererManager.ActiveRenderChangedHandler(renderManager_ActiveRenderChanged);
            renderManager.RenderLayoutChanged += new CRendererManager.RenderLayoutChangedHandler(renderManager_RenderLayoutChanged);

            double[] clrBackground = ApplicationOptions.Instance().ViewOptions.BackgroundColor;

            // Add more arbitary lights to turn the scence a little bit bright
            vtk.vtkLightKit lightKit = new vtk.vtkLightKit();
            vtk.vtkLight sceneLight = new vtk.vtkLight();
            sceneLight.SetAmbientColor(1, 1, 1);
            sceneLight.SetDiffuseColor(1, 1, 1);
            sceneLight.SetFocalPoint(0, 0, 0);
            sceneLight.SetPosition(0, 0, 500000);
            sceneLight.SetLightTypeToSceneLight();
            sceneLight.SetIntensity(1);
            sceneLight.SwitchOn();

            // Background Renderer for the background image
            vtk.vtkRenderer backgroundRenderer = renderManager.BackgroundRenderer;
            backgroundRenderer.SetBackground(clrBackground);
            backgroundRenderer.SetLayer(0);
            renWin.AddRenderer(backgroundRenderer);
            LoadImageToRenderer(backgroundRenderer);

            // Main Renderer
            vtk.vtkRenderer mainRenderer = renderManager.MainRenderer;
            mainRenderer.SetBackground(clrBackground);
            mainRenderer.SetLayer(1);
            mainRenderer.AddLight(sceneLight);
            lightKit.AddLightsToRenderer(mainRenderer);
            renWin.AddRenderer(mainRenderer);

            // TopView Renderer
            vtk.vtkRenderer topViewRender = renderManager.TopViewRenderer;
            topViewRender.SetBackground(clrBackground);
            topViewRender.SetLayer(1);
            lightKit.AddLightsToRenderer(topViewRender);
            renWin.AddRenderer(topViewRender);

            // front Renderer
            vtk.vtkRenderer frontViewRenderer = renderManager.FrontViewRenderer;
            frontViewRenderer.SetBackground(clrBackground);
            frontViewRenderer.SetLayer(1);
            lightKit.AddLightsToRenderer(frontViewRenderer);
            renWin.AddRenderer(frontViewRenderer);

            // right Renderer
            vtk.vtkRenderer rightViewRenderer = renderManager.RightViewRenderer;
            rightViewRenderer.SetBackground(clrBackground);
            rightViewRenderer.SetLayer(1);
            lightKit.AddLightsToRenderer(rightViewRenderer);
            renWin.AddRenderer(rightViewRenderer);

            renWin.SetNumberOfLayers(2);

            // Set active rendere to main renderer
            renderManager.ActiveRenderer = mainRenderer;

            // Set up layout strategy
            CRenderersLayoutStrategy renderersLayoutStrategy = new CRenderersLayoutStrategy(renderManager);
            renderManager.RendererLayoutStrategy = renderersLayoutStrategy;
        }
Exemplo n.º 6
0
        private void LoadImageToRenderer(vtk.vtkRenderer renderer)
        {
            try
            {
                string backgroundImageFileName = ApplicationOptions.Instance().ViewOptions.BackgroundFileName;
                if (!string.IsNullOrEmpty(backgroundImageFileName))
                {
                    string backgroundImagePath = System.IO.Path.Combine(CFolderUtility.DataFolder(), ApplicationOptions.Instance().ViewOptions.BackgroundFileName);
                    //string backgroundImagePath = @"C:\sky4.jpg";
                    vtk.vtkJPEGReader jpegReader = new vtk.vtkJPEGReader();
                    if (jpegReader.CanReadFile(backgroundImagePath) != 0)
                    {
                        jpegReader.SetFileName(backgroundImagePath);
                        jpegReader.Update();

                        vtk.vtkImageData imageData = jpegReader.GetOutput();

                        vtk.vtkImageActor actor = new vtk.vtkImageActor();
                        actor.SetInput(imageData);

                        renderer.AddActor(actor);

                        double[] origin = imageData.GetOrigin();
                        double[] spacing = imageData.GetSpacing();
                        int[] extent = imageData.GetExtent();

                        vtk.vtkCamera camera = renderer.GetActiveCamera();
                        camera.ParallelProjectionOn();
                        double xc = origin[0] + 0.5 * (extent[0] + extent[1]) * spacing[0];
                        double yc = origin[1] + 0.5 * (extent[2] + extent[3]) * spacing[1];
                        //double xd = (extent[1] - extent[0] + 1)*spacing[0];
                        double yd = (extent[3] - extent[2] + 1) * spacing[1];
                        double d = camera.GetDistance();
                        camera.SetParallelScale(0.5 * yd);
                        camera.SetFocalPoint(xc, yc, 0.0);
                        camera.SetPosition(xc, yc, d);
                    }
                    jpegReader.Dispose();
                }
            }
            catch (Exception ex)
            {
                string errMsg = ex.Message + "\n" + ex.StackTrace;
                vtk.vtkOutputWindow.GetInstance().DisplayErrorText(errMsg);
            }
        }
Exemplo n.º 7
0
        private void UpdateRendererOutline(ref vtk.vtkActor2D outlineRendererActor, ref vtk.vtkPolyData polyData, vtk.vtkRenderer renderer)
        {
            try
            {

                if (outlineRendererActor == null)
                {
                    outlineRendererActor = new vtk.vtkActor2D();

                    polyData = new vtk.vtkPolyData();
                    polyData.Allocate(5, 0);

                    vtk.vtkIdList idList = new vtk.vtkIdList();
                    idList.SetNumberOfIds(5);

                    vtk.vtkPoints points = new vtk.vtkPoints();
                    idList.InsertId(0, points.InsertNextPoint(1, 1, 0));
                    idList.InsertId(1, points.InsertNextPoint(2, 1, 0));
                    idList.InsertId(2, points.InsertNextPoint(2, 2, 0));
                    idList.InsertId(3, points.InsertNextPoint(1, 2, 0));
                    idList.InsertId(4, idList.GetId(0));

                    polyData.SetPoints(points);
                    polyData.InsertNextCell(4, idList);

                    vtk.vtkCoordinate coordinate = new vtk.vtkCoordinate();
                    coordinate.SetCoordinateSystemToDisplay();
                    vtk.vtkPolyDataMapper2D mapper = new vtk.vtkPolyDataMapper2D();
                    mapper.SetInput(polyData);
                    mapper.SetTransformCoordinate(coordinate);

                    outlineRendererActor.SetMapper(mapper);
                    outlineRendererActor.SetPosition(0, 0);
                    outlineRendererActor.SetPosition2(1, 1);

                    renderer.AddActor(outlineRendererActor);
                }

                double[] vp = renderer.GetViewport();
                renderer.NormalizedDisplayToDisplay(ref vp[0], ref vp[1]);
                renderer.NormalizedDisplayToDisplay(ref vp[2], ref vp[3]);

                polyData.GetPoints().SetPoint(0, vp[0], vp[1], 0);
                polyData.GetPoints().SetPoint(1, vp[2], vp[1], 0);
                polyData.GetPoints().SetPoint(2, vp[2], vp[3], 0);
                polyData.GetPoints().SetPoint(3, vp[0], vp[3], 0);

                // Change Outline color and width
                double[] normalOutlineColor = ApplicationOptions.Instance().RendererLayoutOptions.NormalOutlineColor;
                float normalOutlineWidth = ApplicationOptions.Instance().RendererLayoutOptions.NormalOutlineLineWidth;

                if (renderer == IApp.theApp.RendererManager.ActiveRenderer)
                {
                    normalOutlineColor = ApplicationOptions.Instance().RendererLayoutOptions.ActiveOutlineColor;
                    normalOutlineWidth = ApplicationOptions.Instance().RendererLayoutOptions.ActiveOutlineLineWidth;
                }

                outlineRendererActor.GetProperty().SetColor(normalOutlineColor);
                outlineRendererActor.GetProperty().SetLineWidth(normalOutlineWidth);
            }
            catch (Exception ex)
            {
                string errMsg = ex.Message + "\n" + ex.StackTrace;
                vtk.vtkOutputWindow.GetInstance().DisplayErrorText(errMsg);
            }
        }
Exemplo n.º 8
0
 private void ShowHideProp(vtk.vtkProp prop, bool vis)
 {
     if (vis)
     {
         prop.VisibilityOn();
     }
     else
     {
         prop.VisibilityOff();
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// This function is a callback to renderwindow' render event
 /// </summary>
 /// <param name="caller"></param>
 /// <param name="eventId"></param>
 /// <param name="clientData"></param>
 /// <param name="callData"></param>
 public void OnRenderCallback(vtk.vtkObject caller, uint eventId, object clientData, IntPtr callData)
 {
     // Update the Video record
     if (IApp.theApp.VideoWriter.IsRecording)
     {
         IApp.theApp.VideoWriter.CaptureData();
     }
 }
Exemplo n.º 10
0
 private void SetDefaultView(vtk.vtkRenderer renderer, ViewOptions.ViewTypeEnum viewTypeEnum)
 {
     switch (viewTypeEnum)
     {
         case ViewOptions.ViewTypeEnum.eTopView:
             IApp.theApp.vtkControl.ShowTopView(renderer, CBoundingBoxUtil.GetBounds(renderer));
             break;
         case ViewOptions.ViewTypeEnum.eBottomView:
             IApp.theApp.vtkControl.ShowBottomView(renderer, CBoundingBoxUtil.GetBounds(renderer));
             break;
         case ViewOptions.ViewTypeEnum.eFrontView:
             IApp.theApp.vtkControl.ShowFrontView(renderer, CBoundingBoxUtil.GetBounds(renderer));
             break;
         case ViewOptions.ViewTypeEnum.eBackView:
             IApp.theApp.vtkControl.ShowBackView(renderer, CBoundingBoxUtil.GetBounds(renderer));
             break;
         case ViewOptions.ViewTypeEnum.eLeftView:
             IApp.theApp.vtkControl.ShowLeftView(renderer, CBoundingBoxUtil.GetBounds(renderer));
             break;
         case ViewOptions.ViewTypeEnum.eRightView:
             IApp.theApp.vtkControl.ShowRightView(renderer, CBoundingBoxUtil.GetBounds(renderer));
             break;
         case ViewOptions.ViewTypeEnum.eSWISO:
             IApp.theApp.vtkControl.ShowSWIsoMetricView(renderer, CBoundingBoxUtil.GetBounds(renderer));
             break;
         case ViewOptions.ViewTypeEnum.eSEISO:
             IApp.theApp.vtkControl.ShowSEIsoMetricView(renderer, CBoundingBoxUtil.GetBounds(renderer));
             break;
         case ViewOptions.ViewTypeEnum.eNWISO:
             IApp.theApp.vtkControl.ShowNWIsoMetricView(renderer, CBoundingBoxUtil.GetBounds(renderer));
             break;
         case ViewOptions.ViewTypeEnum.eNEISO:
             IApp.theApp.vtkControl.ShowNEIsoMetricView(renderer, CBoundingBoxUtil.GetBounds(renderer));
             break;
         default:
             break;
     }
 }
Exemplo n.º 11
0
 void renderManager_ActiveRenderChanged(vtk.vtkRenderer previousRender, vtk.vtkRenderer newRenderer)
 {
     UpdateRendererOutline();
 }