Exemple #1
0
 /// <summary>
 /// 外積を求める
 /// </summary>
 /// <param name="v2"></param>
 /// <returns>外積ベクトル</returns>
 public Vec3 Cross(Vec3 v2)
 {
     Vec3 v;
     v.X = Y * v2.Z - Z * v2.Y;
     v.Y = Z * v2.X - X * v2.Z;
     v.Z = X * v2.Y - Y * v2.X;
     return v;
 }
        public MarchingCubes(PARData data)
        {
            // 以下プロパティアクセスによるパフォーマンス低下を避けるためのコード
            _sizeX = data.SizeX;
            _sizeY = data.SizeY;
            _sizeZ = data.SizeZ;
            _sizeXY = _sizeX * _sizeY;
            var stepX = data.StepX;
            var stepY = data.StepY;
            var stepZ = data.StepZ;
            var startX = data.StartX;
            var startY = data.StartY;
            var startZ = data.StartZ;
            var rawData = data.RawData;

            _verticesBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Vertex)) * _sizeX * _sizeY * _sizeZ);
            GC.AddMemoryPressure(Marshal.SizeOf(typeof(Vertex)) * _sizeX * _sizeY * _sizeZ);

            // unsafeを用いることによりパフォーマンス向上
            unsafe {
                var vptr = (Vertex*)_verticesBuffer.ToPointer();
                var ptr = (float*)rawData.ToPointer();
                for (var z = 0; z < _sizeZ; z++) {
                    for (var y = 0; y < _sizeY; y++) {
                        for (var x = 0; x < _sizeX; x++) {
                            vptr->Point = new Vec3 (
                                startX + stepX * x,
                                startY + stepY * y,
                                startZ + stepZ * z
                            );
                            vptr->Value = *ptr;
                            vptr++;
                            ptr++;
                        }
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// 内積を求める
 /// </summary>
 /// <param name="v"></param>
 /// <returns>内積の値</returns>
 public float Dot(Vec3 v)
 {
     return X * v.X + Y * v.Y + Z * v.Z;
 }
 public Triangle(Vec3 v1, Vec3 v2, Vec3 v3)
 {
     Vertex1 = v1;
     Vertex2 = v2;
     Vertex3 = v3;
 }