Beispiel #1
0
        /// <summary>
        /// blend two volumes
        /// </summary>
        /// <param name="bVolume">volume to blend with</param>
        /// <param name="bPosition">position parameter to sample blending at (normalized 0-1)</param>
        /// <returns>blended volume</returns>
        public DendroVolume Blend(DendroVolume bVolume, double bPosition, double bEnd)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            if (bPosition < 0)
            {
                bPosition = 0;
            }
            if (bPosition > 1)
            {
                bPosition = 1;
            }

            if (bEnd < 1)
            {
                bEnd = 1;
            }

            bPosition = 1 - bPosition;

            DendroVolume blend = new DendroVolume(this);

            // pinvoke smoothing function
            DendroBlend(blend.Grid, bVolume.Grid, bPosition, bEnd);

            blend.UpdateDisplay();

            return(blend);
        }
Beispiel #2
0
        /// <summary>
        /// blend two volumes using a mask
        /// </summary>
        /// <param name="bVolume">volume to blend with</param>
        /// <param name="bPosition">position parameter to sample blending at (normalized 0-1)</param>
        /// <param name="vMask">mask for blending operation</param>
        /// <returns>blended volume</returns>
        public DendroVolume Blend(DendroVolume bVolume, double bPosition, double bEnd, DendroMask vMask)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            if (bPosition < 0)
            {
                bPosition = 0;
            }
            if (bPosition > 1)
            {
                bPosition = 1;
            }

            if (bEnd < 1)
            {
                bEnd = 1;
            }

            bPosition = 1 - bPosition;

            DendroVolume blend = new DendroVolume(this);

            // pinvoke smoothing function with mask
            DendroBlendMask(blend.Grid, bVolume.Grid, bPosition, bEnd, vMask.Volume.Grid, vMask.Min, vMask.Max, vMask.Invert);

            blend.UpdateDisplay();

            return(blend);
        }
Beispiel #3
0
        /// <summary>
        /// apply smoothing to a volume
        /// </summary>
        /// <param name="sWidth">(optional) width of the mean-value filter is 2*width+1 voxels</param>
        /// <param name="sType">0 - gaussian, 1 - laplacian, 2 - mean, 3 - median</param>
        /// <param name="sIterations">number of smoothing operations to perform</param>
        /// <returns>smoothed volume</returns>
        public DendroVolume Smooth(int sType, int sIterations, int sWidth = 1)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            if (sType < 0 || sType > 3)
            {
                sType = 1;
            }

            if (sWidth < 1)
            {
                sWidth = 1;
            }

            if (sIterations < 1)
            {
                sIterations = 1;
            }

            DendroVolume smooth = new DendroVolume(this);

            // pinvoke smoothing function
            DendroSmooth(smooth.Grid, sType, sIterations, sWidth);

            smooth.UpdateDisplay();

            return(smooth);
        }
Beispiel #4
0
        /// <summary>
        /// apply smoothing to a volume
        /// </summary>
        /// <param name="sWidth">(optional) width of the mean-value filter is 2*width+1 voxels</param>
        /// <param name="sType">0 - gaussian, 1 - laplacian, 2 - mean, 3 - median</param>
        /// <param name="sIterations">number of smoothing operations to perform</param>
        /// <param name="vMask">mask for smoothing operation</param>
        /// <returns>smoothed volume</returns>
        public DendroVolume Smooth(int sType, int sIterations, DendroMask vMask, int sWidth = 1)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            if (sType < 0 || sType > 3)
            {
                sType = 1;
            }

            if (sWidth < 1)
            {
                sWidth = 1;
            }

            if (sIterations < 1)
            {
                sIterations = 1;
            }

            DendroVolume smooth = new DendroVolume(this);

            // pinvoke smoothing function with mask
            DendroSmoothMask(smooth.Grid, sType, sIterations, sWidth, vMask.Volume.Grid, vMask.Min, vMask.Max, vMask.Invert);

            smooth.UpdateDisplay();

            return(smooth);
        }
Beispiel #5
0
        /// <summary>
        /// apply an offset to the volume
        /// </summary>
        /// <param name="amount">amount to offset volume</param>
        /// <returns>offset volume</returns>
        public DendroVolume Offset(double amount)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            DendroVolume offset = new DendroVolume(this);

            // pinvoke offset function
            DendroOffset(offset.Grid, amount);

            offset.UpdateDisplay();

            return(offset);
        }
Beispiel #6
0
        /// <summary>
        /// apply an offset to the volume with a mask
        /// </summary>
        /// <param name="amount">amount to offset volume</param>
        /// <param name="vMask">mask for offset operation</param>
        /// <returns>offset volume</returns>
        public DendroVolume Offset(double amount, DendroMask vMask)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            DendroVolume offset = new DendroVolume(this);

            // pinvoke offset function with mask
            DendroOffsetMask(offset.Grid, amount, vMask.Volume.Grid, vMask.Min, vMask.Max, vMask.Invert);

            offset.UpdateDisplay();

            return(offset);
        }
Beispiel #7
0
        /// <summary>
        /// compute a boolean union of a volume
        /// </summary>
        /// <param name="vUnion">volume to union</param>
        /// <returns>new volume with the resulting union</returns>
        public DendroVolume BooleanUnion(DendroVolume vUnion)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            if (!vUnion.IsValid)
            {
                return(new DendroVolume(this));
            }

            DendroVolume csg = new DendroVolume(this);

            // pinvoke union function
            DendroUnion(csg.Grid, vUnion.Grid);
            csg.UpdateDisplay();

            return(csg);
        }
Beispiel #8
0
        /// <summary>
        /// compute a boolean intersection of a volume
        /// </summary>
        /// <param name="vIntersect">volume to intersect</param>
        /// <returns>new volume with the resulting intersection</returns>
        public DendroVolume BooleanIntersection(DendroVolume vIntersect)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            if (!vIntersect.IsValid)
            {
                return(new DendroVolume(this));
            }

            DendroVolume csg = new DendroVolume(this);

            // pinvoke intersection function
            DendroIntersection(csg.Grid, vIntersect.Grid);
            csg.UpdateDisplay();

            return(csg);
        }
Beispiel #9
0
        /// <summary>
        /// compute a boolean difference of a volume
        /// </summary>
        /// <param name="vSubract">volume to subtract with</param>
        /// <returns>new volume with the resulting difference</returns>
        public DendroVolume BooleanDifference(DendroVolume vSubract)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            if (!vSubract.IsValid)
            {
                return(new DendroVolume(this));
            }

            DendroVolume csg = new DendroVolume(this);

            // pinvoke difference function
            DendroDifference(csg.Grid, vSubract.Grid);
            csg.UpdateDisplay();

            return(csg);
        }
Beispiel #10
0
        /// <summary>
        /// compute a boolean union of a set of volumes
        /// </summary>
        /// <param name="vUnion">list of volumes to union</param>
        /// <returns>new volume with the resulting union</returns>
        public DendroVolume BooleanUnion(List <DendroVolume> vUnion)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            DendroVolume csg = new DendroVolume(this);

            foreach (DendroVolume union in vUnion)
            {
                // pinvoke union function
                if (union.IsValid)
                {
                    DendroUnion(csg.Grid, union.Grid);
                }
            }

            csg.UpdateDisplay();

            return(csg);
        }
Beispiel #11
0
        /// <summary>
        /// compute a boolean intersection of a set of volumes
        /// </summary>
        /// <param name="vIntersect">list of volumes to intersect</param>
        /// <returns>new volume with the resulting intersection</returns>
        public DendroVolume BooleanIntersection(List <DendroVolume> vIntersect)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            DendroVolume csg = new DendroVolume(this);

            foreach (DendroVolume intersect in vIntersect)
            {
                // pinvoke intersection function
                if (intersect.IsValid)
                {
                    DendroIntersection(csg.Grid, intersect.Grid);
                }
            }

            csg.UpdateDisplay();

            return(csg);
        }
Beispiel #12
0
        /// <summary>
        /// compute a boolean difference of a set of volumes
        /// </summary>
        /// <param name="vSubtract">list of volumes to subtract with</param>
        /// <returns>new volume with the resulting difference</returns>
        public DendroVolume BooleanDifference(List <DendroVolume> vSubtract)
        {
            if (!this.IsValid)
            {
                return(new DendroVolume());
            }

            DendroVolume csg = new DendroVolume(this);

            foreach (DendroVolume subtract in vSubtract)
            {
                // pinvoke difference function
                if (subtract.IsValid)
                {
                    DendroDifference(csg.Grid, subtract.Grid);
                }
            }

            csg.UpdateDisplay();

            return(csg);
        }
Beispiel #13
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DendroVolume   mVolume   = new DendroVolume();
            DendroSettings vSettings = new DendroSettings();

            if (!DA.GetData(0, ref mVolume))
            {
                return;
            }
            if (!DA.GetData(1, ref vSettings))
            {
                return;
            }

            if (!mVolume.IsValid)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Volume is not valid");
                return;
            }

            mVolume.UpdateDisplay(vSettings);

            DA.SetData(0, mVolume.Display);
        }