Exemple #1
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);
        }
            /// <summary>
            /// Return a list of 3 values, respectively: Volume, Surface and compactness
            /// </summary>
            /// <returns></returns>
            private double[] ComputeVolSurfComp()
            {
                vtkTriangleFilter TriangleFilter = vtkTriangleFilter.New();
                TriangleFilter.SetInputConnection(ContourObject);
                vtkMassProperties MassProperties = new vtkMassProperties();
                MassProperties.SetInputConnection(TriangleFilter.GetOutputPort());

                double Volume = MassProperties.GetVolume();
                double Surface = MassProperties.GetSurfaceArea();
                double Compactness = MassProperties.GetNormalizedShapeIndex();
                double[] Res = new double[3];
                Res[0] = Volume;
                Res[1] = Surface;
                Res[2] = Compactness;

                return Res;
            }
 private double ComputeHullRatio(double ObjectVolume)
 {
     vtkTriangleFilter TriangleFilter = vtkTriangleFilter.New();
     TriangleFilter.SetInputConnection(hullFilter.GetOutputPort());
     vtkMassProperties MassProperties = new vtkMassProperties();
     MassProperties.SetInputConnection(TriangleFilter.GetOutputPort());
     return MassProperties.GetVolume() / ObjectVolume;
 }