public override sealed void InitializeSceneGraph(vtkRenderer vtkRenderer)
        {
            if (Disposed)
            {
                return;
            }

            var rootProp = ModelRootProp;
            var origin   = Owner.Origin ?? Vector3D.Null;

            rootProp.SetPosition(origin.X, origin.Y, origin.Z);

            // preinitialize the prop transform matrix
            using (var userMatrix = new vtkMatrix4x4())
                rootProp.SetUserMatrix(userMatrix);

            vtkRenderer.AddViewProp(rootProp);

            using (var renderWindow = vtkRenderer.GetRenderWindow())
            {
                var cameraDistance = GetNominalCameraDistance();
                var clientSize     = renderWindow.GetSize();
                var camera         = AddNewVtkObject <vtkCamera>();
                camera.ParallelProjectionOn();
                camera.SetParallelScale(0.5 * clientSize[1]);
                camera.SetPosition(0, 0, cameraDistance);
                camera.SetFocalPoint(0, 0, 0);
                camera.SetClippingRange(10, 2 * cameraDistance);
                camera.ComputeViewPlaneNormal();
                camera.SetViewUp(0, 1, 0);
                vtkRenderer.SetActiveCamera(camera);
            }
        }
        public override sealed void UpdateSceneGraph(vtkRenderer vtkRenderer)
        {
            if (Disposed)
            {
                return;
            }

            vtkRenderer.SetBackground(VtkHelper.ConvertToVtkColor(_backgroundColor));

            uint mTime;

            using (var camera = vtkRenderer.GetActiveCamera())
                using (var vtkRenderWindow = vtkRenderer.GetRenderWindow())
                {
                    var clientSize = vtkRenderWindow.GetSize2();
                    var scale      = ViewPortSpatialTransform.Scale;
                    if (FloatComparer.AreEqual(0, scale))
                    {
                        scale = 1;
                    }

                    camera.SetParallelScale(0.5 * clientSize.Height / scale);

                    var cameraDistance = GetNominalCameraDistance();
                    var pos            = ViewPortSpatialTransform.ConvertToSource(new PointF(clientSize.Width / 2f, clientSize.Height / 2f));
                    camera.SetPosition(pos.X, pos.Y, cameraDistance);
                    camera.SetFocalPoint(pos.X, pos.Y, 0);
                    camera.SetClippingRange(10, 2 * cameraDistance);
                    camera.ComputeViewPlaneNormal();

                    var up = ViewPortSpatialTransform.ConvertToSource(new SizeF(0, -1));
                    camera.SetViewUp(up.Width, up.Height, 0);

                    mTime = camera.GetMTime();
                }

            var rootProp = ModelRootProp;

            using (var vtkTransform = rootProp.GetUserMatrix())
            {
                var modelCumulativeTransform = GetModelCumulativeTransform();
                vtkTransform.SetElements(modelCumulativeTransform);
            }

            UpdateModelRootProp(rootProp);

            var propMTime = rootProp.GetMTime();

            if (mTime < propMTime)
            {
                mTime = propMTime;
            }

            if (_lastMTime < mTime)
            {
                _lastMTime = mTime;
                Modified();
            }
        }
Example #3
0
 public void Render()
 {
     try
     {
         _renderer.GetRenderWindow().Render();
     }
     catch (Exception)
     {
     }
 }
Example #4
0
        public void SetTopMost()
        {
            vtkRenderer _aRender = _rendererPackage.Renderer;

            if (_aRender.GetLayer() > 0)
            {
                return;
            }

            if (_aRender.GetRenderWindow().GetRenderers().GetNumberOfItems() == 1)
            {
                vtkRenderer ren1 = vtkRenderer.New(); // 2d actor
                ren1.SetLayer(1);                     // top layer
                ren1.InteractiveOff();

                _aRender.SetLayer(0);
                _aRender.GetRenderWindow().SetNumberOfLayers(2);
                _aRender.GetRenderWindow().AddRenderer(ren1);

                //ren1.SetActiveCamera(_aRender.GetActiveCamera());

                //new SpherePackage(ren1, new double[] { 0, 0, 0 }, 600).SetOpacity(0.01f);

                _aRender.SetActiveCamera(ren1.GetActiveCamera());

                _aRender.RemoveActor(Actor);
                ren1.AddActor(Actor);

                _aRender.InteractiveOn();
            }
            else
            {
                for (int i = 0; i < _aRender.GetRenderWindow().GetRenderers().GetNumberOfItems(); ++i)
                {
                    int layer = vtkRenderer.SafeDownCast(_aRender.GetRenderWindow().GetRenderers().GetItemAsObject(i)).GetLayer();

                    if (layer == 1)
                    {
                        vtkRenderer.SafeDownCast(_aRender.GetRenderWindow().GetRenderers().GetItemAsObject(i)).AddActor(Actor);
                    }
                    else
                    {
                        vtkRenderer.SafeDownCast(_aRender.GetRenderWindow().GetRenderers().GetItemAsObject(i)).RemoveActor(Actor);
                    }
                }
            }
        }