/// <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> /// 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); }
/// <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(); string filepath = ""; bool isWrite = false; if (!DA.GetData(0, ref volume)) { return; } if (!DA.GetData(1, ref filepath)) { return; } if (!DA.GetData(2, ref isWrite)) { return; } if (isWrite) { bool success = volume.Write(filepath); if (!success) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Write failed. Make sure you supplied a path plus filename with the extension *.vdb"); return; } } }
/// <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); }
/// <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) { List <DendroVolume> vUnion = new List <DendroVolume> (); if (!DA.GetDataList(0, vUnion)) { return; } if (vUnion.Count < 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Need to supply a value"); return; } DendroVolume csg = new DendroVolume(); if (vUnion.Count == 1) { csg = new DendroVolume(vUnion[0]); } else { csg = vUnion[0].BooleanUnion(vUnion); } if (!csg.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "CSG failed. Make sure all supplied volumes are valid"); return; } DA.SetData(0, new VolumeGOO(csg)); }
/// <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) { string filepath = ""; bool isRead = false; if (!DA.GetData(0, ref filepath)) { return; } if (!DA.GetData(1, ref isRead)) { return; } DendroVolume volume = new DendroVolume(); if (isRead) { volume = new DendroVolume(filepath); if (!volume.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Read failed. Make sure you supplied valid *.VDB file. If file wasn't output from Dendro, make sure your source outputs volume as a float grid"); return; } } DA.SetData(0, new VolumeGOO(volume)); }
/// <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); }
/// <summary> /// volume constructor /// </summary> /// <param name="vCopy">volume to copy from</param> public DendroMask(DendroVolume vCopy) { this.Volume = new DendroVolume(vCopy); this.Min = 0; this.Max = 0; this.Invert = false; }
/// <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> /// 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> /// 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> /// 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); }
/// <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> /// copy constructor /// </summary> /// <param name="vCopy">volume to copy from</param> public DendroVolume(DendroVolume vCopy) { if (vCopy.IsValid) { this.Grid = vCopy.DuplicateGrid(); this.Display = vCopy.Display.DuplicateMesh(); this.IsValid = true; } else { // pinvoke grid creation this.Grid = DendroCreate(); this.Display = new Mesh(); // volume is empty, so it is invalid this.IsValid = false; } }
/// <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); }
/// <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); }
/// <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); }
/// <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> /// 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) { List <Curve> vCurves = new List <Curve> (); List <double> vRadius = new List <double> (); DendroSettings vSettings = new DendroSettings(); if (!DA.GetDataList(0, vCurves)) { return; } if (!DA.GetDataList(1, vRadius)) { return; } if (!DA.GetData(2, ref vSettings)) { return; } double minRadius = vSettings.VoxelSize / 0.6667; foreach (double radius in vRadius) { if (radius <= minRadius) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Radius must be at least 33% larger than voxel size. This will compute but no volume will be created."); } } DendroVolume volume = new DendroVolume(vCurves, vRadius, vSettings); if (!volume.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Conversion failed. Make sure you supplied valid radius values or valid settings"); return; } DA.SetData(0, new VolumeGOO(volume)); }
/// <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); }
/// <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); }
/// <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); }
/// <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 vBase = new DendroVolume(); List <DendroVolume> vIntersect = new List <DendroVolume> (); if (!DA.GetData(0, ref vBase)) { return; } if (!DA.GetDataList(1, vIntersect)) { return; } DendroVolume csg = vBase.BooleanIntersection(vIntersect); if (!csg.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "CSG failed. Make sure all supplied volumes are valid"); return; } DA.SetData(0, new VolumeGOO(csg)); }
/// <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) { Mesh vMesh = new Mesh(); DendroSettings vSettings = new DendroSettings(); if (!DA.GetData(0, ref vMesh)) { return; } if (!DA.GetData(1, ref vSettings)) { return; } DendroVolume volume = new DendroVolume(vMesh, vSettings); if (!volume.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Conversion failed. Make sure you supplied a valid mesh and correct settings"); return; } DA.SetData(0, new VolumeGOO(volume)); }
/// <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); }