/// <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); }
/// <summary> /// copy constructor /// </summary> /// <param name="mask">mask to copy from</param> public DendroMask(DendroMask mask) { this.Volume = new DendroVolume(mask.Volume); this.Min = mask.Min; this.Max = mask.Max; this.Invert = mask.Invert; }
/// <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 sVolume = new DendroVolume(); DendroMask vMask = new DendroMask(); int sType = 1; int sIterations = 1; int sWidth = 1; if (!DA.GetData(0, ref sVolume)) { return; } if (!DA.GetData(1, ref sWidth)) { return; } if (!DA.GetData(2, ref sType)) { return; } if (!DA.GetData(3, ref sIterations)) { return; } DA.GetData(4, ref vMask); if (vMask == null) { return; } DendroVolume smooth = new DendroVolume(); if (vMask.IsValid) { smooth = sVolume.Smooth(sType, sIterations, vMask, sWidth); } else { smooth = sVolume.Smooth(sType, sIterations, sWidth); } if (!smooth.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Smooth failed. Make sure all supplied volumes are valid"); return; } DA.SetData(0, new VolumeGOO(smooth)); }
/// <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 vBegin = new DendroVolume(); DendroVolume vEnd = new DendroVolume(); double vParam = 0.0; double vTime = 0.0; DendroMask vMask = new DendroMask(); if (!DA.GetData(0, ref vBegin)) { return; } if (!DA.GetData(1, ref vEnd)) { return; } if (!DA.GetData(2, ref vParam)) { return; } if (!DA.GetData(3, ref vTime)) { return; } DA.GetData(4, ref vMask); if (vMask == null) { return; } DendroVolume blend = new DendroVolume(); if (vMask.IsValid) { blend = vBegin.Blend(vEnd, vParam, vTime, vMask); } else { blend = vBegin.Blend(vEnd, vParam, vTime); } if (!blend.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Blend failed. Make sure all supplied volumes are valid"); return; } DA.SetData(0, new VolumeGOO(blend)); }
/// <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); }
/// <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 volume = new DendroVolume(); double min = 0.0; double max = 1.0; bool invert = false; if (!DA.GetData(0, ref volume)) { return; } if (!DA.GetData(1, ref min)) { return; } if (!DA.GetData(2, ref max)) { return; } if (!DA.GetData(3, ref invert)) { return; } if (max < min) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Max value must be larger than min value"); return; } DendroMask mask = new DendroMask(volume); mask.Invert = invert; mask.Min = min; mask.Max = max; if (!mask.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Mask creation failed. Is your volume volid?"); return; } DA.SetData(0, new MaskGOO(mask)); }
/// <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 volume = new DendroVolume(); DendroMask vMask = new DendroMask(); double oAmount = 0.0; if (!DA.GetData(0, ref volume)) { return; } if (!DA.GetData(1, ref oAmount)) { return; } DA.GetData(2, ref vMask); if (vMask == null) { return; } DendroVolume offset = new DendroVolume(); if (vMask.IsValid) { offset = volume.Offset(oAmount, vMask); } else { offset = volume.Offset(oAmount); } if (!offset.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Offset failed. Make sure all supplied volumes are valid"); return; } DA.SetData(0, new VolumeGOO(offset)); }
/// <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); }