Ejemplo n.º 1
0
 public override bool Read(string fileName, IMonitor mon = null)
 {
     try
     {
         unitList.Clear();
         vtkSTLReader      reader = vtkSTLReader.New();
         vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
         reader.SetFileName(fileName);
         mapper.SetInputConnection(reader.GetOutputPort());
         StlUnit unit = new StlUnit("Stl." + Path.GetFileNameWithoutExtension(fileName));
         unit.Actor.SetMapper(mapper);
         unitList.Add(unit);
         reader.Dispose();
         mapper.Dispose();
         return(true);
     }
     catch (Exception e)
     {
         if (mon != null)
         {
             mon.ErrorLine(e.Message);
         }
         return(false);
     }
 }
Ejemplo n.º 2
0
        private void ReadSTL()
        {
            // 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();
            string       filePath = System.IO.Path.Combine(root, @"Data\42400-IDGH.stl");
            vtkSTLReader reader   = vtkSTLReader.New();

            reader.SetFileName(filePath);
            reader.Update();
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(reader.GetOutputPort());

            vtkActor actor = vtkActor.New();

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

            // set background color
            renderer.SetBackground(0.2, 0.3, 0.4);
            // add our actor to the renderer
            renderer.AddActor(actor);
        }
Ejemplo n.º 3
0
        private void ReadStlFileDraw()
        {
            vtkSTLReader stlReader = vtkSTLReader.New();

            //stlReader.SetFileName(@"..\..\Data\anchor_hook.stl");
            stlReader.SetFileName(@"..\..\Data\42400-IDGH.stl");
            vtkShrinkPolyData shrink = vtkShrinkPolyData.New();

            shrink.SetInputConnection(stlReader.GetOutputPort());
            shrink.SetShrinkFactor(0.85);

            vtkPolyDataMapper stlMapper = vtkPolyDataMapper.New();

            //stlMapper.SetInputConnection(stlReader.GetOutputPort());
            stlMapper.SetInputConnection(shrink.GetOutputPort());

            vtkLODActor stlActor = vtkLODActor.New();

            stlActor.SetMapper(stlMapper);
            stlActor.GetProperty().SetColor((float)Color.Orange.R / 256, (float)Color.Orange.G / 256, (float)Color.Orange.B / 256);  //设置actor的颜色

            vtkRenderer     stlRender = vtkRenderer.New();
            vtkRenderWindow renWin    = myRenderWindowControl.RenderWindow;

            renWin.AddRenderer(stlRender);

            stlRender.AddActor(stlActor);
            stlRender.SetBackground(1.0, 1.0, 1.0);
        }
Ejemplo n.º 4
0
        static private void init()
        {
            vtkSTLReader rdr = vtkSTLReader.New();

            rdr.SetFileName("BODY-EXTRUDEUR-WADE.stl");



            // Créer une géométrie sphérique

            /*vtkSphereSource sphere = vtkSphereSource.New();
             * sphere.SetRadius(1.0);
             * sphere.SetThetaResolution(18);
             * sphere.SetPhiResolution(18);*/

            // Transforme la géométrie en primitives graphiques (OpenGL dans notre cas)
            vtkPolyDataMapper map = vtkPolyDataMapper.New();

            map.SetInput(rdr.GetOutput());

            // L'acteur représente l'entitée géométrique.
            // Il permet de définir sa position, son orientation, sa couleur, etc.
            vtkActor aSphere = new vtkActor();

            aSphere.SetMapper(map);
            aSphere.GetProperty().SetColor(0.8, 0.8, 0.8); // color blue

            // Nous créons un renderer qui va faire le rendu de notre entitée.
            vtkRenderer ren1 = vtkRenderer.New();

            ren1.AddActor(aSphere);
            ren1.SetBackground(1, 1, 1); // background color white

            // Nous créons une fenêtre de rendu
            vtkRenderWindow renWin = vtkRenderWindow.New();

            renWin.AddRenderer(ren1);
            renWin.SetSize(300, 300);

            // Nous créons un interactor qui permet de bouger la caméra.
            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

            iren.SetRenderWindow(renWin);

            // Nous lançons le rendu et l'interaction
            renWin.Render();
            iren.Start();


            ////// CLEANUP ///////
            rdr.Dispose();
            map.Dispose();
            aSphere.Dispose();
            ren1.Dispose();
            renWin.Dispose();
            iren.Dispose();
        }
Ejemplo n.º 5
0
        static public vtkProp3D genSTLActor(CompontData data, vtkProperty pro)
        {
            if (data.restriction != null)
            {
                return(genActorByRestriction(data, pro));
            }
            vtkSTLReader reader = vtkSTLReader.New();

            reader.SetFileName(data.param_str);
            reader.Update();
            return(genUserActor(data, reader.GetOutputPort(), pro));
        }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            vtkSTLReader reader = vtkSTLReader.New();
            string       path   = @"d:\Staz\projekt2\Projekt2\Projekt2\fibula.stl";

            reader.SetFileName(path);
            vtkPolyDataMapper Mapper = vtkPolyDataMapper.New();

            Mapper.SetInputConnection(reader.GetOutputPort());
            vtkActor Actor = vtkActor.New();

            Actor.SetMapper(Mapper);
            renderer.AddActor(Actor);
            reader.SetFileName(path);
            vtkPolyDataMapper Mapperinscription = vtkPolyDataMapper.New();

            Mapperinscription.SetInputConnection(reader.GetOutputPort());

            renderer.ResetCamera();
            renderWindow.GetInteractor().Render();
        }
Ejemplo n.º 7
0
        public static double CalculateVolumeFromStl(string fileName)
        {
            vtkSTLReader reader = vtkSTLReader.New();

            reader.SetFileName(fileName);
            vtkMassProperties property = vtkMassProperties.New();

            property.SetInputConnection(reader.GetOutputPort());
            property.Update();
            double volume = property.GetVolume();

            property.Dispose();
            reader.Dispose();
            return(volume);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 读取STL文件
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        vtkActor ReadStlFile(string fileName)
        {// 读取stl模型
            vtkSTLReader stlReader = vtkSTLReader.New();

            stlReader.SetFileName(fileName);
            stlReader.Update();

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(stlReader.GetOutputPort());

            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            return(actor);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Charge le ficheir STL fourni en parametre.
        /// Si un STL est déjà chargé, on le décharge avant.
        /// </summary>
        /// <param name="filePath"></param>
        public void load(String filePath)
        {
            //décharge les objets existants
            this.destroy();

            _stlReader = vtkSTLReader.New();
            _stlReader.SetFileName(filePath);

            createVolumeObjects();
            createEdgeObjects();

            if (ShowVolume)
            {
                _renderer.AddActor(this._volumeActor);
            }

            if (ShowEdges)
            {
                _renderer.AddActor(this._edgeActor);
            }

            Render();
        }