/// <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) { double bandwidth = 5.0; double voxelSize = 1.0; double isoValue = 0.0; double adaptivity = 0.1; if (!DA.GetData(0, ref voxelSize)) { return; } if (!DA.GetData(1, ref bandwidth)) { return; } if (!DA.GetData(2, ref isoValue)) { return; } if (!DA.GetData(3, ref adaptivity)) { return; } DendroSettings vs = new DendroSettings(); vs.Adaptivity = adaptivity; vs.Bandwidth = bandwidth; vs.IsoValue = isoValue; vs.VoxelSize = voxelSize; DA.SetData(0, new SettingsGOO(vs)); }
/// <summary> /// copy constructor /// </summary> /// <param name="ds">settings to copy from</param> public DendroSettings(DendroSettings ds) { this.mAdaptivity = ds.Adaptivity; this.mBandwidth = ds.Bandwidth; this.mIsovalue = ds.IsoValue; this.mVoxelSize = ds.VoxelSize; }
/// <summary> /// curve constructor /// </summary> /// <remark>must supply a single radius value or a list of radii equal to the number of curves supplied</remark> /// <param name="vCurves">curves to build volume from</param> /// <param name="vRadius">radius values for each curve</param> /// <param name="vSettings">voxelization settings to be used</param> public DendroVolume(List <Curve> vCurves, List <double> vRadius, DendroSettings vSettings) { // pinvoke grid creation this.Grid = DendroCreate(); this.Display = new Mesh(); this.IsValid = this.CreateFromCurves(vCurves, vRadius, vSettings); }
/// <summary> /// mesh constructor /// </summary> /// <param name="vMesh">mesh to build volume from</param> /// <param name="vSettings">voxelization settings to be used</param> public DendroVolume(Mesh vMesh, DendroSettings vSettings) { // pinvoke grid creation this.Grid = DendroCreate(); this.Display = new Mesh(); this.IsValid = this.CreateFromMesh(vMesh, vSettings); }
/// <summary> /// build a volume from a supplied list of points /// </summary> /// <remark>must supply a single radius value or a list of radii equal to the number of points supplied</remark> /// <param name="vPoints">point set to build volume from</param> /// <param name="vRadius">radius values for each point</param> /// <param name="vSettings">voxelization settings to be used</param> /// <returns>boolean value for whether volume was built successfully</returns> public bool CreateFromPoints(List <Point3d> vPoints, List <double> vRadius, DendroSettings vSettings) { // there were no points/radius supplied so exit if (vPoints.Count == 0 || vRadius.Count == 0) { return(false); } // check for invalid voxelsize settings if (vSettings.VoxelSize < 0.01) { vSettings.VoxelSize = 0.01; } // check for invalid bandwidth settings if (vSettings.Bandwidth < 1) { vSettings.Bandwidth = 1; } // if one or equal radius values were supplied then build volume if (vPoints.Count == vRadius.Count || vRadius.Count == 1) { // create point array from point3d list so we can pass to c++ double[] points = new double[vPoints.Count * 3]; int i = 0; foreach (Point3d pt in vPoints) { points[i] = pt.X; points[i + 1] = pt.Y; points[i + 2] = pt.Z; i += 3; } // create radius array from list so we can pass to c++ double[] radius = vRadius.ToArray(); // pinvoke build volume from points this.IsValid = DendroFromPoints(this.Grid, points, points.Length, radius, radius.Length, vSettings.VoxelSize, vSettings.Bandwidth); if (!this.IsValid) { return(false); } this.UpdateDisplay(); } else { return(false); } return(true); }
/// <summary> /// build a volume from a supplied list of curves /// </summary> /// <remark>must supply a single radius value or a list of radii equal to the number of curves supplied</remark> /// <param name="vCurves">curves to build volume from</param> /// <param name="vRadius">radius values for each curve</param> /// <param name="vSettings">voxelization settings to be used</param> /// <returns>boolean value for whether volume was built successfully</returns> public bool CreateFromCurves(List <Curve> vCurves, List <double> vRadius, DendroSettings vSettings) { // there were no curves/radius supplied so exit if (vCurves.Count == 0 || vRadius.Count == 0) { return(false); } // check for invalid voxelsize settings if (vSettings.VoxelSize < 0.01) { vSettings.VoxelSize = 0.01; } // check for invalid bandwidth settings if (vSettings.Bandwidth < 1) { vSettings.Bandwidth = 1; } // find out if we were supplied a single radius value or multiple values int method = GetCurveSolverMethod(vCurves.Count, vRadius.Count); bool validInput = false; List <double> rValues = new List <double> (); List <Point3d> vPoints = new List <Point3d> (); switch (method) { // only a single radius was supplied case 1: validInput = ResolveSingleRadius(vCurves, vRadius[0], out vPoints, out rValues); break; // multiple radius values were supplied case 2: validInput = ResolveMultipleRadius(vCurves, vRadius, out vPoints, out rValues); break; default: validInput = false; break; } // supplied values were not valid so exit if (!validInput) { return(false); } // return results from point to volume function return(this.CreateFromPoints(vPoints, rValues, vSettings)); }
/// <summary> /// update the mesh representation of the volume using voxel settings /// </summary> /// <param name="vSettings">settings for meshing volume</param> public void UpdateDisplay(DendroSettings vSettings) { // pinvoke mesh update DendroToMeshSettings(this.Grid, vSettings.IsoValue, vSettings.Adaptivity); // get update vertex and face arrays float[] vertices = this.GetMeshVertices(); int[] faces = this.GetMeshFaces(); this.Display = this.ConstructMesh(vertices, faces); // flip and rebuild this.Display.Normals.ComputeNormals(); this.Display.UnifyNormals(); this.Display.Flip(true, true, true); }
/// <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> /// build a volume from a mesh input /// </summary> /// <param name="vMesh">mesh to build volume from</param> /// <param name="vSettings">voxelization settings to be used</param> /// <returns>boolean value for whether volume was built successfully</returns> public bool CreateFromMesh(Mesh vMesh, DendroSettings vSettings) { if (!vMesh.IsValid) { return(false); } // check for invalid voxelsize settings if (vSettings.VoxelSize < 0.01) { vSettings.VoxelSize = 0.01; } // check for invalid bandwidth settings if (vSettings.Bandwidth < 1) { vSettings.Bandwidth = 1; } // create flattened vertex and face arrays from input mesh float[] vertices = vMesh.Vertices.ToFloatArray(); int[] faces = vMesh.Faces.ToIntArray(true); // pinvoke build volume from mesh this.IsValid = DendroFromMesh(this.Grid, vertices, vertices.Length, faces, faces.Length, vSettings.VoxelSize, vSettings.Bandwidth); if (!this.IsValid) { return(false); } // use input mesh for the visualization mesh (saves us from computing it in c++) this.Display = vMesh.DuplicateMesh(); return(true); }
/// <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); }
/// <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)); }