Beispiel #1
0
        public static void ApplyMatrixTransform(TransformMatrix transformMat, matrix m)
        {
            var transform = transformMat.transform;
            var values = m.Values;
            var mat = new Matrix4(
                (float)values[0], (float)values[1], (float)values[2], (float)values[3],
                (float)values[4], (float)values[5], (float)values[6], (float)values[7],
                (float)values[8], (float)values[9], (float)values[10], (float)values[11],
                (float)values[12], (float)values[13], (float)values[14], (float)values[15]
            );
            mat.Transpose();
            transformMat.matrix *= mat;

            var translation = mat.ExtractTranslation();
            transform.Translation += translation;

            if (translation != Vector3.Zero)
                transform.Flags |= (int)Transform.TransformFlags.HasTranslation;

            var rotation = mat.ExtractRotation();
            transform.Rotation *= rotation;

            if (rotation != Quaternion.Identity)
                transform.Flags |= (int)Transform.TransformFlags.HasRotation;

            var scale = mat.ExtractScale();
            transform.ScaleShear[0, 0] *= scale[0];
            transform.ScaleShear[1, 1] *= scale[1];
            transform.ScaleShear[2, 2] *= scale[2];

            if (transform.ScaleShear != Matrix3.Identity)
                transform.Flags |= (int)Transform.TransformFlags.HasScaleShear;
        }
Beispiel #2
0
        public static void ApplyRotation(TransformMatrix transformMat, rotate rotation)
        {
            var transform = transformMat.transform;
            transform.Flags |= (int)Transform.TransformFlags.HasRotation;
            var axis = new Vector3((float)rotation.Values[0], (float)rotation.Values[1], (float)rotation.Values[2]);
            // TODO: rad -> deg?
            var quat = Quaternion.FromAxisAngle(axis, (float)rotation.Values[3]);
            transform.Rotation *= quat;

            transformMat.matrix *= Matrix4.CreateFromAxisAngle(axis, (float)rotation.Values[3]);
        }
Beispiel #3
0
        public static void ApplyTranslation(TransformMatrix transformMat, TargetableFloat3 translation)
        {
            var transform = transformMat.transform;
            transform.Flags |= (int)Transform.TransformFlags.HasTranslation;
            transform.Translation.X += (float)translation.Values[0];
            transform.Translation.Y += (float)translation.Values[1];
            transform.Translation.Z += (float)translation.Values[2];

            transformMat.matrix *= Matrix4.CreateTranslation(
                (float)translation.Values[0],
                (float)translation.Values[1],
                (float)translation.Values[2]
            );
        }
Beispiel #4
0
        public static void ApplyScale(TransformMatrix transformMat, TargetableFloat3 scale)
        {
            var transform = transformMat.transform;
            transform.Flags |= (int)Transform.TransformFlags.HasScaleShear;
            transform.ScaleShear[0, 0] *= (float)scale.Values[0];
            transform.ScaleShear[1, 1] *= (float)scale.Values[1];
            transform.ScaleShear[2, 2] *= (float)scale.Values[2];

            transformMat.matrix *= Matrix4.CreateScale(
                (float)scale.Values[0],
                (float)scale.Values[1],
                (float)scale.Values[2]
            );
        }
            public void Execute(int i)
            {
                float2 position = positions[i].Value;
                float2 heading  = math.normalize(headings[i].Value);

                matrices[i] = new TransformMatrix
                {
                    Value = new float4x4
                    {
                        m0 = new float4(heading.y, 0.0f, -heading.x, 0.0f),
                        m1 = new float4(0.0f, 1.0f, 0.0f, 0.0f),
                        m2 = new float4(heading.x, 0.0f, heading.y, 0.0f),
                        m3 = new float4(position.x, 0.0f, position.y, 1.0f)
                    }
                };
            }
Beispiel #6
0
        /***************************************************/

        public static NurbsSurface Transform(this NurbsSurface surface, TransformMatrix transform)
        {
            List <SurfaceTrim> innerTrims = surface.InnerTrims.Select(x => new SurfaceTrim(ITransform(x.Curve3d, transform), x.Curve2d)).ToList();

            List <SurfaceTrim> outerTrims = surface.OuterTrims.Select(x => new SurfaceTrim(ITransform(x.Curve3d, transform), x.Curve2d)).ToList();

            return(new NurbsSurface(
                       surface.ControlPoints.Select(x => Transform(x, transform)),
                       surface.Weights,
                       surface.UKnots,
                       surface.VKnots,
                       surface.UDegree,
                       surface.VDegree,
                       innerTrims,
                       outerTrims));
        }
Beispiel #7
0
        // mouse down message handler
        // input parameter
        // 1. mouse down location
        // 2. Viewport 3D
        // 3. the model index of the rect in the viewport
        public void OnMouseDown(System.Windows.Point pt, System.Windows.Controls.Viewport3D viewport3d, int nModelIndex)
        {
            if (nModelIndex == -1)
            {
                return;
            }
            System.Windows.Media.Media3D.MeshGeometry3D meshGeometry = Model3D.GetGeometry(viewport3d, nModelIndex);
            if (meshGeometry == null)
            {
                return;
            }

            System.Windows.Point pt1 = TransformMatrix.ScreenPtToViewportPt(pt, viewport3d);

            SetRect(pt1, pt1);
            UpdatePositions(meshGeometry);
        }
Beispiel #8
0
        /***************************************************/

        public static IEnumerable <IBHoMObject> FromRevit(this Wall wall, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            IEnumerable <IElement2D> result = null;

            switch (discipline)
            {
            case Discipline.Environmental:
                result = wall.EnvironmentPanelsFromRevit(settings, refObjects);
                break;

            case Discipline.Structural:
                result = wall.StructuralPanelsFromRevit(settings, refObjects);
                break;

            case Discipline.Facade:
                if (wall.CurtainGrid != null)
                {
                    result = new List <IElement2D> {
                        wall.CurtainWallFromRevit(settings, refObjects)
                    }
                }
                ;
                else
                {
                    result = new List <IElement2D> {
                        wall.FacadePanelFromRevit(settings, refObjects)
                    }
                };
                break;

            case Discipline.Architecture:
            case Discipline.Physical:
                result = new List <IElement2D> {
                    wall.WallFromRevit(settings, refObjects)
                };
                break;
            }

            if (result != null && transform?.IsIdentity == false)
            {
                TransformMatrix bHoMTransform = transform.FromRevit();
                result = result.Select(x => x.ITransform(bHoMTransform));
            }

            return(result?.Cast <IBHoMObject>().ToList());
        }
Beispiel #9
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static TransformMatrix Transpose(this TransformMatrix transform)
        {
            double[,] matrix    = transform.Matrix;
            double[,] transpose = new double[4, 4];

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    transpose[i, j] = matrix[j, i];
                }
            }

            return(new TransformMatrix {
                Matrix = transpose
            });
        }
Beispiel #10
0
        /***************************************************/

        public static TransformMatrix ProjectionMatrix(Plane plane, Vector vector = null)
        {
            Point x = new Point()
            {
                X = 1
            };
            Point y = new Point()
            {
                Y = 1
            };
            Point z = new Point()
            {
                Z = 1
            };

            vector = vector == null || vector.SquareLength() < Tolerance.Distance * Tolerance.Distance ? plane.Normal : vector;

            Vector refVector = (new Point()).ProjectAlong(plane, vector) - new Point();

            // Set plane to origin for projection
            plane = new Plane()
            {
                Normal = plane.Normal
            };

            // Compute the projection for three controlPoints defining the transformation
            x = x.ProjectAlong(plane, vector);
            y = y.ProjectAlong(plane, vector);
            z = z.ProjectAlong(plane, vector);

            TransformMatrix project = new TransformMatrix
            {
                Matrix = new double[, ]
                {
                    { x.X, y.X, z.X, 0 },
                    { x.Y, y.Y, z.Y, 0 },
                    { x.Z, y.Z, z.Z, 0 },
                    { 0, 0, 0, 1 }
                }
            };

            // Move the projection out from the origin to the original plane
            TransformMatrix move = TranslationMatrix(refVector);

            return(move * project);
        }
Beispiel #11
0
        public void Execute(int i)
        {
            var camera_target_id = cameras[i].target_id;
            var camera_mat       = camera_mats[i];

            for (int j = 0; j < targets.Length; j++)
            {
                if (camera_target_id == targets[j].id)
                {
                    // var new_camera_mat = math.mul(camera_mat.Value, target_mats[j].Value);//camera_mat.Value * target_mats[j].Value;
                    camera_mats[i] = new TransformMatrix {
                        Value = math.mul(camera_mat.Value, target_mats[j].Value)
                    };
                    return;
                }
            }
        }
Beispiel #12
0
        /***************************************************/

        public static TransformMatrix ScaleMatrix(Point refPoint, Vector scaleVector)
        {
            TransformMatrix move1 = TranslationMatrix(oM.Geometry.Point.Origin - refPoint);
            TransformMatrix move2 = TranslationMatrix(refPoint - oM.Geometry.Point.Origin);
            TransformMatrix scale = new TransformMatrix
            {
                Matrix = new double[, ]
                {
                    { scaleVector.X, 0, 0, 0 },
                    { 0, scaleVector.Y, 0, 0 },
                    { 0, 0, scaleVector.Z, 0 },
                    { 0, 0, 0, 1 }
                }
            };

            return(move2 * scale * move1);
        }
Beispiel #13
0
        /***************************************************/

        public static IBHoMObject FromRevit(this CurveElement curveElement, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            BH.oM.Adapters.Revit.Elements.IInstance result = null;
            switch (discipline)
            {
            default:
                result = curveElement.InstanceFromRevit(settings, refObjects);
                break;
            }

            if (result is BH.oM.Adapters.Revit.Elements.ModelInstance && transform?.IsIdentity == false)
            {
                TransformMatrix bHoMTransform = transform.FromRevit();
                result = result.Transform(bHoMTransform);
            }

            return(result);
        }
Beispiel #14
0
        void _textureControl_EditableTransformChanged(object sender, EventArgs e)
        {
            int currentIndex = _textureControl.selectedTransformIndex;
            int boneIndex    = _editableTransforms[currentIndex].boneIndex;

            //create new transform... needed edited part, allong with the part that leads up to it from the original parsed file
            TransformMatrix tm   = _textureControl.getEditedTransform() * _editableTransforms[currentIndex].StartingTransform;
            Transform       tfrm = tm.ToTransform();

            //remove the old one first
            if (_bones[boneIndex].hasTransform())
            {
                _bones[boneIndex].removeTransform();
            }

            //add edited
            _bones[boneIndex].addTransform(tfrm);
        }
        /// <summary>
        /// Draw a texture rotated around (x,y) blended with a diffuse texture.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="nw"></param>
        /// <param name="nh"></param>
        /// <param name="zrot"></param>
        /// <param name="uoff"></param>
        /// <param name="voff"></param>
        /// <param name="umax"></param>
        /// <param name="vmax"></param>
        /// <param name="color"></param>
        /// <param name="diffuseTextureNo"></param>
        /// <param name="uoffd"></param>
        /// <param name="voffd"></param>
        /// <param name="umaxd"></param>
        /// <param name="vmaxd"></param>
        public void Draw(float x, float y, float nw, float nh, float zrot, float uoff, float voff,
                         float umax, float vmax, uint color, int blendableTextureNo, float uoffd,
                         float voffd, float umaxd, float vmaxd, FontEngineBlendMode blendMode)
        {
            if (_textureNumber >= 0)
            {
                // Rotate around the x,y point of the specified rectangle; maintain aspect ratio (1.0f)
                TransformMatrix localTransform = new TransformMatrix();
                localTransform.SetZRotation(zrot, x, y, 1.0f);
                TransformMatrix finalTransform = GUIGraphicsContext.GetFinalTransform();
                localTransform = finalTransform.multiply(localTransform);

                DXNative.FontEngineDrawTexture2(_textureNumber, x, y, nw, nh, uoff, voff, umax, vmax,
                                                color, localTransform.Matrix,
                                                blendableTextureNo, uoffd, voffd, umaxd, vmaxd,
                                                blendMode);
            }
        }
Beispiel #16
0
        public static Spectator Spectator(Point location, Vector viewDirection, Polyline headOutline = null, double majorRadius = 0.11, double minorRadius = 0.078)
        {
            if (location.IsNull() || viewDirection.IsNull())
            {
                return(null);
            }
            if (headOutline == null)
            {
                //create basic elliptical head form
                List <Point> points = new List <Point>();
                double       theta  = 2 * Math.PI / 16;
                for (int i = 0; i <= 16; i++)
                {
                    double x = minorRadius * Math.Cos(theta * i);
                    double y = majorRadius * Math.Sin(theta * i);
                    points.Add(Geometry.Create.Point(x, y, 0));
                }
                headOutline = Geometry.Create.Polyline(points);
            }

            if (!headOutline.IsPlanar() || !headOutline.IsClosed())
            {
                Reflection.Compute.RecordError("The reference headOutline must be closed and planar.");
                return(null);
            }

            //create the head
            Head head = Humans.Create.Head(location, viewDirection);

            Spectator spectator = new Spectator()
            {
                Head = head
            };

            //local cartesian
            Cartesian local = spectator.Cartesian();

            //transform the reference head outline
            TransformMatrix transform = Geometry.Create.OrientationMatrixGlobalToLocal(local);

            spectator.HeadOutline = headOutline.Transform(transform);

            return(spectator);
        }
Beispiel #17
0
        public static void ApplyMatrixTransform(TransformMatrix transformMat, matrix m)
        {
            var transform = transformMat.transform;
            var values    = m.Values;
            var mat       = new Matrix4(
                (float)values[0], (float)values[1], (float)values[2], (float)values[3],
                (float)values[4], (float)values[5], (float)values[6], (float)values[7],
                (float)values[8], (float)values[9], (float)values[10], (float)values[11],
                (float)values[12], (float)values[13], (float)values[14], (float)values[15]
                );

            mat.Transpose();
            transformMat.matrix *= mat;

            var translation = mat.ExtractTranslation();

            transform.Translation += translation;

            if (translation != Vector3.Zero)
            {
                transform.Flags |= (int)Transform.TransformFlags.HasTranslation;
            }

            var rotation = mat.ExtractRotation();

            transform.Rotation *= rotation;

            if (rotation != Quaternion.Identity)
            {
                transform.Flags |= (int)Transform.TransformFlags.HasRotation;
            }

            var scale = mat.ExtractScale();

            transform.ScaleShear[0, 0] *= scale[0];
            transform.ScaleShear[1, 1] *= scale[1];
            transform.ScaleShear[2, 2] *= scale[2];

            if (transform.ScaleShear != Matrix3.Identity)
            {
                transform.Flags |= (int)Transform.TransformFlags.HasScaleShear;
            }
        }
Beispiel #18
0
        /***************************************************/

        public static ICurve Transform(this Circle curve, TransformMatrix transform)
        {
            if (Math.Abs(transform.Determinant() - 1) <= 1e-6 || transform.IsUniformScaling())
            {
                return new Circle
                       {
                           Centre = curve.Centre.Transform(transform),
                           Radius = (curve.StartPoint() - curve.Centre).Transform(transform).Length(),
                           Normal = curve.Normal.Transform(transform)
                       }
            }
            ;
            else
            {
                Reflection.Compute.RecordNote("Transformation is not rigid. Converting into NurbsCurve. May occure change in shape");

                return(curve.ToNurbsCurve().Transform(transform));
            }
        }
Beispiel #19
0
        /***************************************************/

        public static ICurve Transform(this Circle curve, TransformMatrix transform)
        {
            if (transform.IsRigidTransformation() || transform.IsUniformScaling())
            {
                return new Circle
                       {
                           Centre = curve.Centre.Transform(transform),
                           Radius = (curve.StartPoint() - curve.Centre).Transform(transform).Length(),
                           Normal = curve.Normal.Transform(transform)
                       }
            }
            ;
            else
            {
                Reflection.Compute.RecordNote("Transformation is not rigid or uniform. Converting into NurbsCurve. Change in shape may occur.");

                return(curve.ToNurbsCurve().Transform(transform));
            }
        }
Beispiel #20
0
        /***************************************************/

        public static IBHoMObject FromRevit(this MultiSegmentGrid grid, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            IElement1D result = null;

            switch (discipline)
            {
            default:
                result = grid.GridFromRevit(settings, refObjects);
                break;
            }

            if (result != null && transform?.IsIdentity == false)
            {
                TransformMatrix bHoMTransform = transform.FromRevit();
                result = result.ITransform(bHoMTransform);
            }

            return(result as IBHoMObject);
        }
Beispiel #21
0
        /***************************************************/
        /**** Public Methods - Curves                   ****/
        /***************************************************/

        public static ICurve Transform(this Arc curve, TransformMatrix transform)
        {
            if (Math.Abs(transform.Determinant() - 1) <= 1e-6 || transform.IsUniformScaling())
            {
                return new Arc
                       {
                           Radius           = (curve.StartPoint() - curve.CoordinateSystem.Origin).Transform(transform).Length(),
                           StartAngle       = curve.StartAngle,
                           EndAngle         = curve.EndAngle,
                           CoordinateSystem = curve.CoordinateSystem.Transform(transform)
                       }
            }
            ;
            else
            {
                Reflection.Compute.RecordNote("Transformation is not rigid. Converting into NurbsCurve. May occure change in shape");

                return(curve.ToNurbsCurve().Transform(transform));
            }
        }
Beispiel #22
0
        /// <summary>
        /// Transforms xCAD matrix to SOLIDWORKS transform data <see cref="IMathTransform.ArrayData"/>
        /// </summary>
        /// <param name="matrix">Matrix to transform</param>
        /// <returns>SOLIDWORKS transform data</returns>
        public static double[] ToMathTransformData(this TransformMatrix matrix)
        {
            var transX = matrix.M41;
            var transY = matrix.M42;
            var transZ = matrix.M43;

            var scaleX = new Vector(matrix.M11, matrix.M21, matrix.M31).GetLength();
            var scaleY = new Vector(matrix.M11, matrix.M21, matrix.M31).GetLength();
            var scaleZ = new Vector(matrix.M11, matrix.M21, matrix.M31).GetLength();

            return(new double[]
            {
                matrix.M11 / scaleX, matrix.M12 / scaleY, matrix.M13 / scaleZ,
                matrix.M21 / scaleX, matrix.M22 / scaleY, matrix.M23 / scaleZ,
                matrix.M31 / scaleX, matrix.M32 / scaleY, matrix.M33 / scaleZ,
                transX, transY, transZ,
                scaleX,
                0, 0, 0
            });
        }
Beispiel #23
0
        public static void HeadOutline(this Spectator spectator, Polyline newHeadOutline)
        {
            if (spectator == null || newHeadOutline.IsNull())
            {
                return;
            }

            if (!newHeadOutline.IsPlanar() || !newHeadOutline.IsClosed())
            {
                Reflection.Compute.RecordError("The reference headOutline must be closed and planar.");
                return;
            }
            //local cartesian
            Cartesian local = spectator.Cartesian();

            //transform the reference head outline
            TransformMatrix transform = Geometry.Create.OrientationMatrixGlobalToLocal(local);

            spectator.HeadOutline = newHeadOutline.Transform(transform);
        }
Beispiel #24
0
        /***************************************************/

        private static void TransformTier(ref TierProfile profile, TransformMatrix xTrans)
        {
            if (profile == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Cannot modify a null tier profile.");
                return;
            }

            if (xTrans == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Cannot modify a tier profile with a null transformation matrix.");
                return;
            }

            profile.FloorPoints           = profile.FloorPoints.Select(p => p.Transform(xTrans)).ToList();
            profile.EyePoints             = profile.EyePoints.Select(p => p.Transform(xTrans)).ToList();
            profile.Profile.ControlPoints = profile.FloorPoints;
            profile.FocalPoint            = profile.FocalPoint.Transform(xTrans);
            profile.SectionOrigin         = DefineTierOrigin(profile.FloorPoints);
        }
Beispiel #25
0
        /// <summary>
        /// 重写鼠标滚轮事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);

            if (e.Delta > 0)
            {
                scaleNum       = 1.5f;
                globalZoomNum *= 1.5f;
            }
            else
            {
                scaleNum       = 0.67f;
                globalZoomNum *= 0.67f;
            }
            MouseShape.HitRect = new RectangleF(MouseShape.MousePoint.X - 3.5f / globalZoomNum, MouseShape.MousePoint.Y - 3.5f / globalZoomNum, 7 / globalZoomNum, 7 / globalZoomNum);
            bGrp.Graphics.Clear(this.BackColor);
            bGrp.Graphics.Transform = TransformMatrix.ScaleByPoint(scaleNum, MouseShape.MousePoint);
            //GetDrawRegionRect();
            DrawShap();
        }
Beispiel #26
0
        public Vector Move(Vector move, Size screenSize)
        {
            if (CanvasBoundaries == null)
            {
                return(new Vector(0, 0));
            }
            Matrix m          = TransformMatrix;
            Point  tl         = TransformMatrix.Transform(new Point(CanvasBoundaries.Item1 - Margin, CanvasBoundaries.Item2 - Margin));
            Point  br         = TransformMatrix.Transform(new Point(CanvasBoundaries.Item3 + 150 + Margin, CanvasBoundaries.Item4 + 40 + Margin));
            Size   canvasSize = new Size(br.X - tl.X, br.Y - tl.Y);
            Size   minSize    = new Size(Math.Min(canvasSize.Width, screenSize.Width), Math.Min(screenSize.Height, canvasSize.Height));

            Vector res = new Vector();

            if (0 < tl.X + move.X)
            {
                DoMove(new Vector(res.X = -tl.X, 0));
            }
            else if (br.X + move.X < minSize.Width)
            {
                DoMove(new Vector(res.X = minSize.Width - br.X, 0));
            }
            else
            {
                DoMove(new Vector(res.X = move.X, 0));
            }
            if (0 < tl.Y + move.Y)
            {
                DoMove(new Vector(0, res.Y = -tl.Y));
            }
            else if (br.Y + move.Y < minSize.Height)
            {
                DoMove(new Vector(0, res.Y = minSize.Height - br.Y));
            }
            else
            {
                DoMove(new Vector(0, res.Y = move.Y));
            }
            UpdateControls(screenSize);
            return(res);
        }
Beispiel #27
0
        /***************************************************/

        public static ICurve Transform(this Ellipse curve, TransformMatrix transform)
        {
            if (transform.IsRigidTransformation() || transform.IsUniformScaling())
            {
                return new Ellipse
                       {
                           Centre  = curve.Centre.Transform(transform),
                           Axis1   = curve.Axis1.Transform(transform),
                           Axis2   = curve.Axis2.Transform(transform),
                           Radius1 = (curve.Axis1.Normalise() * curve.Radius1).Transform(transform).Length(),
                           Radius2 = (curve.Axis2.Normalise() * curve.Radius2).Transform(transform).Length(),
                       }
            }
            ;
            else
            {
                Reflection.Compute.RecordNote("Transformation is not rigid or uniform. Converting into NurbsCurve. Change in shape may occur.");

                return(curve.ToNurbsCurve().Transform(transform));
            }
        }
        private void DeleteFromRegistry(MaterialEffect mat, ModelMeshPart mesh, TransformMatrix worldMatrix)
        {
            for (var i = 0; i < Index; i++)
            {
                MaterialLibrary matLib = MaterialLib[i];
                //if (matLib.HasMaterial(mat))
                //{
                if (matLib.DeleteFromRegistry(mesh, worldMatrix))
                {
                    for (var j = i; j < Index - 1; j++)
                    {
                        //slide down one
                        MaterialLib[j] = MaterialLib[j + 1];
                    }
                    Index--;

                    break;
                }
                //}
            }
        }
Beispiel #29
0
        /***************************************************/

        public static ICurve Transform(this Ellipse curve, TransformMatrix transform)
        {
            if (Math.Abs(transform.Determinant() - 1) <= 1e-6 || transform.IsUniformScaling())
            {
                return new Ellipse
                       {
                           Centre  = curve.Centre.Transform(transform),
                           Axis1   = curve.Axis1.Transform(transform),
                           Axis2   = curve.Axis2.Transform(transform),
                           Radius1 = (curve.Axis1.Normalise() * curve.Radius1).Transform(transform).Length(),
                           Radius2 = (curve.Axis2.Normalise() * curve.Radius2).Transform(transform).Length(),
                       }
            }
            ;
            else
            {
                Reflection.Compute.RecordNote("Transformation is not rigid. Converting into NurbsCurve. May occure change in shape");

                return(curve.ToNurbsCurve().Transform(transform));
            }
        }
Beispiel #30
0
        public static IEnumerable <IBHoMObject> FromRevit(this Autodesk.Revit.DB.Plumbing.Pipe pipe, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            IEnumerable <IElement1D> result = null;

            switch (discipline)
            {
            case Discipline.Architecture:
            case Discipline.Physical:
            case Discipline.Environmental:
                result = new List <IElement1D>(pipe.PipeFromRevit(settings, refObjects));
                break;
            }

            if (result != null && transform?.IsIdentity == false)
            {
                TransformMatrix bHoMTransform = transform.FromRevit();
                result = result.Select(x => x.ITransform(bHoMTransform));
            }

            return(result?.Cast <IBHoMObject>().ToList());
        }
Beispiel #31
0
        public static IBHoMObject FromRevit(this Autodesk.Revit.DB.Electrical.Wire wire, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            IElement1D result = null;

            switch (discipline)
            {
            case Discipline.Architecture:
            case Discipline.Physical:
            case Discipline.Environmental:
                result = wire.WireFromRevit(settings, refObjects);
                break;
            }

            if (result != null && transform?.IsIdentity == false)
            {
                TransformMatrix bHoMTransform = transform.FromRevit();
                result = result.ITransform(bHoMTransform);
            }

            return(result as IBHoMObject);
        }
Beispiel #32
0
        /***************************************************/
        /**** Private Methods                           ****/
        /***************************************************/

        private static CompositeGeometry Extrude(List <ICurve> sectionCurves, TransformMatrix matrix, Vector tangent)
        {
            List <IGeometry> extrusions = new List <IGeometry>();

            List <PolyCurve> joined = BH.Engine.Geometry.Compute.IJoin(sectionCurves);

            for (int i = 0; i < joined.Count; i++)
            {
                ICurve curve = joined[i];
                curve = BH.Engine.Geometry.Modify.ITransform(curve, matrix);
                extrusions.Add(new Extrusion()
                {
                    Curve = curve, Direction = tangent
                });
            }

            return(new CompositeGeometry()
            {
                Elements = extrusions
            });
        }
Beispiel #33
0
        public Vector3 JumpToHelper()
        {
            object data = treeView1.SelectedNode.Tag;

            if (FrameResource.IsFrameType(data))
            {
                bool            fin     = false;
                TransformMatrix matrix  = (data as FrameObjectBase).Matrix;
                TreeNode        curNode = treeView1.SelectedNode;
                while (!fin)
                {
                    if (curNode.Parent == null)
                    {
                        fin = true;
                    }
                    else
                    {
                        FrameObjectBase parent = (curNode.Parent.Tag as FrameObjectBase);
                        curNode = curNode.Parent;
                        if (parent != null)
                        {
                            matrix += parent.Matrix;
                        }
                    }
                }
                return(matrix.Position);
            }

            if (data.GetType() == typeof(ResourceTypes.Collisions.Collision.Placement))
            {
                return((data as ResourceTypes.Collisions.Collision.Placement).Position);
            }

            if (data.GetType() == typeof(Rendering.Graphics.RenderJunction))
            {
                return((data as Rendering.Graphics.RenderJunction).Data.Position);
            }

            return(new Vector3(0, 0, 0));
        }
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static bool IsRigidTransformation(this TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsValid())
            {
                BH.Engine.Reflection.Compute.RecordError("The given TransformMatrix is not valid.");
                return(false);
            }

            double[,] rotation = new double[3, 3];
            for (int m = 0; m < 3; m++)
            {
                for (int n = 0; n < 3; n++)
                {
                    rotation[m, n] = transform.Matrix[m, n];
                }
            }

            double[,] transposed = rotation.Transpose();

            double[,] multiplied = new double[3, 3];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        multiplied[i, j] += rotation[i, k] * transposed[k, j];
                    }
                }
            }

            double[,] identity = new double[, ]
            {
                { 1, 0, 0 },
                { 0, 1, 0 },
                { 0, 0, 1 }
            };

            return(multiplied.IsEqual(identity, tolerance) && Math.Abs(1 - rotation.Determinant()) <= tolerance);
        }
Beispiel #35
0
        // selection
        public override void Select(ViewportRect rect, TransformMatrix matrix, Viewport3D viewport3d)
        {
            int nDotNo = GetDataNo();
            if (nDotNo == 0) return;

            double xMin = rect.XMin();
            double xMax = rect.XMax();
            double yMin = rect.YMin();
            double yMax = rect.YMax();

            for (int i = 0; i < nDotNo; i++)
            {
                ScatterPlotItem plotItem = Get(i);
                Point pt = matrix.VertexToViewportPt(new Point3D(plotItem.x, plotItem.y, plotItem.z),
                    viewport3d);

                if ((pt.X > xMin) && (pt.X < xMax) && (pt.Y > yMin) && (pt.Y < yMax))
                {
                    m_vertices[i].selected = true;
                }
                else
                {
                    m_vertices[i].selected = false;
                }
            }
        }
Beispiel #36
0
        public static TransformMatrix TransformFromNode(node node)
        {
            var transform = new TransformMatrix
            {
                matrix = Matrix4.Identity,
                transform = new Transform(),
                TransformSID = null
            };

            if (node.ItemsElementName != null)
            {
                for (int i = 0; i < node.ItemsElementName.Length; i++)
                {
                    var name = node.ItemsElementName[i];
                    var item = node.Items[i];

                    switch (name)
                    {
                        case ItemsChoiceType2.translate:
                            {
                                var translation = item as TargetableFloat3;
                                ApplyTranslation(transform, translation);
                                break;
                            }

                        case ItemsChoiceType2.rotate:
                            {
                                var rotation = item as rotate;
                                ApplyRotation(transform, rotation);
                                break;
                            }

                        case ItemsChoiceType2.scale:
                            {
                                var scale = item as TargetableFloat3;
                                ApplyScale(transform, scale);
                                break;
                            }

                        case ItemsChoiceType2.matrix:
                            {
                                var mat = item as matrix;
                                transform.TransformSID = mat.sid;
                                ApplyMatrixTransform(transform, mat);
                                break;
                            }
                    }
                }
            }

            return transform;
        }
Beispiel #37
0
 // select
 public virtual void Select(ViewportRect rect, TransformMatrix matrix, Viewport3D viewport3d)
 {
 }