コード例 #1
0
ファイル: SurfaceProp.cs プロジェクト: bangush/server-1
        private void CreateSurfaceRendering()
        {
            _contourFilter = new vtkContourFilter();
            _contourFilter.SetInput(_volumeGraphic.GetImageData());
            _contourFilter.SetValue(0, _volumeGraphic.GetRescaledLevel());

            vtkPolyDataNormals normals = new vtkPolyDataNormals();

            normals.SetInputConnection(_contourFilter.GetOutputPort());
            normals.SetFeatureAngle(60.0);

            vtkStripper stripper = new vtkStripper();

            stripper.SetInputConnection(normals.GetOutputPort());

            vtkPolyDataMapper mapper = new vtkPolyDataMapper();

            mapper.SetInputConnection(stripper.GetOutputPort());
            mapper.ScalarVisibilityOff();

            _vtkActor = new vtkActor();
            _vtkActor.SetMapper(mapper);
            _vtkActor.GetProperty().SetSpecular(.3);
            _vtkActor.GetProperty().SetSpecularPower(20);
            ApplySetting("Opacity");
            ApplySetting("Level");
        }
コード例 #2
0
        public static vtkPolyData MarchingCubeImageData(vtkImageData imageData, double ISO)
        {
            // extract the skin
            vtkMarchingCubes _skinExtractor = new vtkMarchingCubes();

            _skinExtractor.SetInput(imageData);
            _skinExtractor.Update();
            Console.WriteLine("Extractor.Update(); Done");

            //_skinExtractor.SetValue(0, 155);
            _skinExtractor.SetValue(0, ISO);
            _skinExtractor.Update();

            vtkStripper _skinStripper = new vtkStripper();

            _skinStripper.SetInput(_skinExtractor.GetOutput());
            _skinStripper.Update();
            Console.WriteLine("Stripper.Update(); Done");

            vtkPolyData ret = _skinStripper.GetOutput();

            return(ret);
        }
コード例 #3
0
ファイル: SurfaceProp.cs プロジェクト: m-berkani/ClearCanvas
		private void CreateSurfaceRendering()
		{
			_contourFilter = new vtkContourFilter();
			_contourFilter.SetInput(_volumeGraphic.GetImageData());
			_contourFilter.SetValue(0, _volumeGraphic.GetRescaledLevel());

			vtkPolyDataNormals normals = new vtkPolyDataNormals();
			normals.SetInputConnection(_contourFilter.GetOutputPort());
			normals.SetFeatureAngle(60.0);

			vtkStripper stripper = new vtkStripper();
			stripper.SetInputConnection(normals.GetOutputPort());

			vtkPolyDataMapper mapper = new vtkPolyDataMapper();
			mapper.SetInputConnection(stripper.GetOutputPort());
			mapper.ScalarVisibilityOff();

			_vtkActor = new vtkActor();
			_vtkActor.SetMapper(mapper);
			_vtkActor.GetProperty().SetSpecular(.3);
			_vtkActor.GetProperty().SetSpecularPower(20);
			ApplySetting("Opacity");
			ApplySetting("Level");
		}
コード例 #4
0
        int build3DViewFull()
        {
            Kitware.VTK.RenderWindowControl rw = new Kitware.VTK.RenderWindowControl();

            vtkRenderWindow _renwin = rw.RenderWindow;
            vtkRenderer     _render = _renwin.GetRenderers().GetFirstRenderer();

            _renwin.AddRenderer(_render);

            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

            iren.SetRenderWindow(_renwin);

            // 新建文件读取对象,常见的有vtkBMPReader、vtkDICOMImageReader、vtkJPEGReader等
            vtkJPEGReader jpegReader = new vtkJPEGReader();

            // 不同的reader需要设置的参数是不同的 因此本例仅适合jpegreader
            jpegReader.SetFilePrefix("C:/Users/DawnWind/Desktop/000/"); // 要打开的路径
            jpegReader.SetFilePattern("%s%d.jpg");                      // 图片文件名格式,此处为 0.jpg 1.jpg ...
            jpegReader.SetDataByteOrderToLittleEndian();
            jpegReader.SetDataSpacing(1, 1, 1.4);                       // 设置图片中像素比,我理解得不清楚,具体请百度之
            jpegReader.SetFileNameSliceSpacing(1);

            jpegReader.SetDataExtent(0, 209, 0, 209, 0, 29);
            // 这里因为在000文件夹里面有0.jpg ~ 29.jpg,所以设置为 0,29
            // 每张图片的长宽为210 * 210 因此设置为0,209

            jpegReader.Update();
            // update这里要注意一下,对于VTK在默认情况下是在最后操作时候才一次性刷新
            // 也就是说如果没有自动刷新的话,在一些中间过程中是无法获得到数据的,因为没update进去

            vtkContourFilter skinExtractor = new vtkContourFilter();

            skinExtractor.SetInputConnection(jpegReader.GetOutputPort());
            skinExtractor.SetValue(200, 100);    //值越大,保留的部分越少。

            //重新计算法向量
            vtkPolyDataNormals skinNormals = new vtkPolyDataNormals();

            skinNormals.SetInputConnection(skinExtractor.GetOutputPort());
            skinNormals.SetFeatureAngle(60.0);
            //Specify the angle that defines a sharp edge.
            //If the difference in angle across neighboring polygons is greater than this value,
            //the shared edge is considered "sharp".


            //create triangle strips and/or poly-lines 为了更快的显示速度
            vtkStripper skinStripper = new vtkStripper();

            skinStripper.SetInputConnection(skinNormals.GetOutputPort());

            vtkPolyDataMapper skinMapper = new vtkPainterPolyDataMapper();

            skinMapper.SetInputConnection(skinStripper.GetOutputPort());
            skinMapper.ScalarVisibilityOff();    //这样不会带颜色



            vtkActor skin = new vtkActor();

            skin.SetMapper(skinMapper);

            // An outline provides context around the data.
            // 一个围绕在物体的立体框,可以先忽略

            /*
             * vtkOutlineFilter> outlineData =
             *  vtkOutlineFilter>::New();
             * outlineData.SetInputConnection(dicomReader.GetOutputPort());
             *
             * vtkPolyDataMapper> mapOutline =
             *  vtkPolyDataMapper>::New();
             * mapOutline.SetInputConnection(outlineData.GetOutputPort());
             *
             * vtkActor> outline =
             *  vtkActor>::New();
             * outline.SetMapper(mapOutline);
             * outline.GetProperty().SetColor(0,0,0);
             *
             * aRenderer.AddActor(outline);
             */
            // It is convenient to create an initial view of the data. The FocalPoint
            // and Position form a vector direction. Later on (ResetCamera() method)
            // this vector is used to position the camera to look at the data in
            // this direction.
            vtkCamera aCamera = new vtkCamera();

            aCamera.SetViewUp(0, 0, -1);
            aCamera.SetPosition(0, 1, 0);
            aCamera.SetFocalPoint(0, 0, 0);
            aCamera.ComputeViewPlaneNormal();
            aCamera.Azimuth(30.0);
            aCamera.Elevation(30.0);

            // Actors are added to the renderer. An initial camera view is created.
            // The Dolly() method moves the camera towards the FocalPoint,
            // thereby enlarging the image.
            _render.AddActor(skin);
            _render.SetActiveCamera(aCamera);
            _render.ResetCamera();
            aCamera.Dolly(1.5);

            // Set a background color for the renderer and set the size of the
            // render window (expressed in pixels).
            _render.SetBackground(.2, .3, .4);
            _renwin.SetSize(640, 480);

            // Note that when camera movement occurs (as it does in the Dolly()
            // method), the clipping planes often need adjusting. Clipping planes
            // consist of two planes: near and far along the view direction. The
            // near plane clips out objects in front of the plane; the far plane
            // clips out objects behind the plane. This way only what is drawn
            // between the planes is actually rendered.
            _render.ResetCameraClippingRange();

            // Initialize the event loop and then start it.
            iren.Initialize();
            iren.Start();
            return(0);
        }
コード例 #5
0
ファイル: CapClip.cs プロジェクト: wangsen53/vtk-examples
        private void CapClip(string filePath)
        {
            // PolyData to process
            vtkPolyData polyData;

            if (filePath != null)
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(filePath);
                reader.Update();
                polyData = reader.GetOutput();
            }
            else
            {
                // Create a sphere
                vtkSphereSource sphereSource = vtkSphereSource.New();
                sphereSource.SetThetaResolution(20);
                sphereSource.SetPhiResolution(11);

                vtkPlane plane = vtkPlane.New();
                plane.SetOrigin(0, 0, 0);
                plane.SetNormal(1.0, -1.0, -1.0);

                vtkClipPolyData clipper = vtkClipPolyData.New();
                clipper.SetInputConnection(sphereSource.GetOutputPort());
                clipper.SetClipFunction(plane);
                clipper.SetValue(0);
                clipper.Update();

                polyData = clipper.GetOutput();
            }

            vtkDataSetMapper clipMapper = vtkDataSetMapper.New();

#if VTK_MAJOR_VERSION_5
            clipMapper.SetInput(polyData);
#else
            clipMapper.SetInputData(polyData);
#endif

            vtkActor clipActor = vtkActor.New();
            clipActor.SetMapper(clipMapper);
            clipActor.GetProperty().SetColor(1.0000, 0.3882, 0.2784);
            clipActor.GetProperty().SetInterpolationToFlat();

            // Now extract feature edges
            vtkFeatureEdges boundaryEdges = vtkFeatureEdges.New();
#if VTK_MAJOR_VERSION_5
            boundaryEdges.SetInput(polyData);
#else
            boundaryEdges.SetInputData(polyData);
#endif
            boundaryEdges.BoundaryEdgesOn();
            boundaryEdges.FeatureEdgesOff();
            boundaryEdges.NonManifoldEdgesOff();
            boundaryEdges.ManifoldEdgesOff();

            vtkStripper boundaryStrips = vtkStripper.New();
            boundaryStrips.SetInputConnection(boundaryEdges.GetOutputPort());
            boundaryStrips.Update();

            // Change the polylines into polygons
            vtkPolyData boundaryPoly = vtkPolyData.New();
            boundaryPoly.SetPoints(boundaryStrips.GetOutput().GetPoints());
            boundaryPoly.SetPolys(boundaryStrips.GetOutput().GetLines());

            vtkPolyDataMapper boundaryMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            boundaryMapper.SetInput(boundaryPoly);
#else
            boundaryMapper.SetInputData(boundaryPoly);
#endif

            vtkActor boundaryActor = vtkActor.New();
            boundaryActor.SetMapper(boundaryMapper);
            boundaryActor.GetProperty().SetColor(0.8900, 0.8100, 0.3400);
            // 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(clipActor);
            renderer.AddActor(boundaryActor);
            // Generate an interesting view
            //
            renderer.ResetCamera();
            renderer.GetActiveCamera().Azimuth(30);
            renderer.GetActiveCamera().Elevation(30);
            renderer.GetActiveCamera().Dolly(1.2);
            renderer.ResetCameraClippingRange();
        }