public static Dictionary <string, object> CurveSinusoidalPointsWithVoxel( Autodesk.DesignScript.Geometry.Curve _Curve, VoxelImage Voxel, double WaveLength = 5.0, double Amplitude = 1.0, double Resolution = 2.0) { VoxelChannel _VoxelChannel = Voxel.GetChannel(VoxelImageLayout.SHAPECHANNEL); double n = (_Curve.Length / WaveLength) * 4 * Resolution; double _Span = _Curve.Length / n; List <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); List <double> ks = new List <double>(); for (int i = 0; i < n; i++) { Autodesk.DesignScript.Geometry.Plane pl = _Curve.PlaneAtParameter(_Curve.ParameterAtSegmentLength(i * _Span)); Autodesk.DesignScript.Geometry.Point p = _Curve.PointAtSegmentLength(i * _Span); double FieldValue = V2GVoxel.GetVoxelFieldValue(_VoxelChannel, p.X, p.Y, p.Z); double k = FieldValue * Amplitude * Math.Sin(i * _Span * Math.PI * 2 / WaveLength + Math.PI * 2); points.Add((Autodesk.DesignScript.Geometry.Point)p.Translate(pl.YAxis, k)); ks.Add(k); } return(new Dictionary <string, object> { { "Points", points }, { "k", ks } }); }
public bool Save(string file, IVoxelChannel _c) { VoxelChannel c = (VoxelChannel)_c; c.SaveToFile(file); return(true); }
public IVoxelChannel Load(string file) { VoxelChannel vc = new VoxelChannel(Constants.RegionSize, Constants.RegionSize, 256); vc.LoadFromFile(file); return(vc); }
/// <summary> /// Get the interpolated value of a voxel field at a given Point3d. /// </summary> /// <param name="vc"></param> /// <param name="p"></param> /// <returns></returns> public static double GetVoxelFieldValue(VoxelChannel vc, V2GPoint p) { double res = 0.0; if (vc.GetDataAtPointTriL(new CVector(p.X, p.Y, p.Z), out res)) { return(res); } return(0.0); }
/// <summary> /// Get the interpolated value of a voxel field at a given point with coordinates. /// </summary> /// <param name="vc"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <returns></returns> public static double GetVoxelFieldValue(VoxelChannel vc, double x, double y, double z) { double res = 0.0; if (vc.GetDataAtPointTriL(new CVector(x, y, z), out res)) { return(res); } return(0.0); }
public static Dictionary <string, object> VoxelChannels(VoxelImage v) { VoxelChannel ShapeChannel = v.GetChannel(VoxelImageLayout.SHAPECHANNEL); VoxelChannel MaterialRatioChannel = v.GetChannel(VoxelImageLayout.MATERIALRATIOCHANNEL); return(new Dictionary <string, object> { { "Shape", ShapeChannel }, { "Material Ratio", MaterialRatioChannel } }); }
/// <summary> /// Calculate voxel point properties. /// </summary> /// <param name="_Voxel"></param> public void SetPropertiesWith(VoxelImage _Voxel) { double delta = 0.000001; VoxelImage v = _Voxel as VoxelImage; VoxelChannel vc = v.GetChannel(VoxelImageLayout.SHAPECHANNEL) as VoxelChannel; V2GPoint x0 = this.Position - V2GPoint.XAxis * delta; V2GPoint x1 = this.Position + V2GPoint.XAxis * delta; V2GPoint y0 = this.Position - V2GPoint.YAxis * delta; V2GPoint y1 = this.Position + V2GPoint.YAxis * delta; V2GPoint z0 = this.Position - V2GPoint.ZAxis * delta; V2GPoint z1 = this.Position + V2GPoint.ZAxis * delta; double x = V2GVoxel.GetVoxelFieldValue(vc, x1) - V2GVoxel.GetVoxelFieldValue(vc, x0); double y = V2GVoxel.GetVoxelFieldValue(vc, y1) - V2GVoxel.GetVoxelFieldValue(vc, y0); double z = V2GVoxel.GetVoxelFieldValue(vc, z1) - V2GVoxel.GetVoxelFieldValue(vc, z0); V2GPoint UnitVector = new V2GPoint(x, y, z); UnitVector.Normalize(); double fieldValue = V2GVoxel.GetVoxelFieldValue(vc, this.Position); V2GPoint RealVector = UnitVector * fieldValue; V2GPoint UnitVectorProjected = new V2GPoint(RealVector.X, RealVector.Y, 0); V2GPoint UnitVectorPerpendicularProjected = V2GPoint.CrossProduct(UnitVectorProjected, V2GPoint.ZAxis); UnitVectorProjected.Normalize(); UnitVectorPerpendicularProjected.Normalize(); this.ContourVector3d = UnitVector; this.ContourVector = UnitVectorPerpendicularProjected; this.GradientVector = UnitVectorProjected; this.FieldValue = fieldValue; }
/// <summary> /// Get field value of a VoxelChannel at a given point. /// </summary> /// <param name="vc"></param> /// <param name="p"></param> /// <returns name="Value"></returns> public static double VoxelChannelValueAtPoint(VoxelChannel vc, Autodesk.DesignScript.Geometry.Point p) { return(V2GVoxel.GetVoxelFieldValue(vc, p.X, p.Y, p.Z)); }