public static vtk.vtkTransform ToVTKTransformation(this Matrix3D matrix3D)
        {
            double[] matData = new double[16];

            matData[0] = matrix3D.M11;
            matData[1] = matrix3D.M21;
            matData[2] = matrix3D.M31;
            matData[3] = matrix3D.OffsetX;

            matData[4] = matrix3D.M12;
            matData[5] = matrix3D.M22;
            matData[6] = matrix3D.M32;
            matData[7] = matrix3D.OffsetY;

            matData[8] = matrix3D.M13;
            matData[9] = matrix3D.M23;
            matData[10] = matrix3D.M33;
            matData[11] = matrix3D.OffsetZ;

            matData[12] = matrix3D.M14;
            matData[13] = matrix3D.M24;
            matData[14] = matrix3D.M34;
            matData[15] = matrix3D.M44;

            // Set the vtkTransform with a double[16]
            vtk.vtkTransform vtkTransform = new vtk.vtkTransform();
            vtkTransform.SetMatrix(matData);

            return vtkTransform;
        }
Esempio n. 2
0
 static void myCallback(vtk.vtkObject caller, uint eventId,
                        object clientData, IntPtr callData)
 {
     System.Diagnostics.Debug.WriteLine("Callback has been called.");
     vtk.vtkBoxWidget boxWidget = vtk.vtkBoxWidget.SafeDownCast(caller);
     if (null != boxWidget)
     {
         using (vtk.vtkTransform t = new vtk.vtkTransform())
         {
             boxWidget.GetTransform(t);
             boxWidget.GetProp3D().SetUserTransform(t);
         }
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("Caller is not a box widget.");
     }
 }
        protected void ScaleModel(CModelNode node, CPoint3D ptScaleCenter, Vector3D scaleDirection, double dScale)
        {
            try
            {
                double dScaleFactor = dScale;
                if (dScale < 0) dScaleFactor = 0;
                if (dScale > 1) dScaleFactor = 1;

                // Scale the segment, because the dProgress is inside the range
                vtk.vtkTransform transform = new vtk.vtkTransform();
                transform.Translate(ptScaleCenter.X, ptScaleCenter.Y, ptScaleCenter.Z);

                // Calculate a scale transform along with the given scaleDirection
                double nx = scaleDirection.X;
                double ny = scaleDirection.Y;
                double nz = scaleDirection.Z;

                double dFactorTemp = (dScaleFactor - 1);

                vtk.vtkTransform scaleTransform = new vtk.vtkTransform();
                vtk.vtkMatrix4x4 scaleMatrix = scaleTransform.GetMatrix();
                scaleMatrix.SetElement(0, 0, 1 + dFactorTemp * nx * nx);
                scaleMatrix.SetElement(0, 1, dFactorTemp * nx * ny);
                scaleMatrix.SetElement(0, 2, dFactorTemp * nx * nz);

                scaleMatrix.SetElement(1, 0, dFactorTemp * nx * ny);
                scaleMatrix.SetElement(1, 1, 1 + dFactorTemp * ny * ny);
                scaleMatrix.SetElement(1, 2, dFactorTemp * ny * nz);

                scaleMatrix.SetElement(2, 0, dFactorTemp * nx * nz);
                scaleMatrix.SetElement(2, 1, dFactorTemp * ny * nz);
                scaleMatrix.SetElement(2, 2, 1 + dFactorTemp * nz * nz);

                // Mutliply the scale transform
                vtk.vtkMatrix4x4 scaleMatrix2 = new vtk.vtkMatrix4x4();
                vtk.vtkMatrix4x4.Multiply4x4(transform.GetMatrix(), scaleMatrix, scaleMatrix2);
                transform.SetMatrix(scaleMatrix2);

                transform.Translate(-ptScaleCenter.X, -ptScaleCenter.Y, -ptScaleCenter.Z);

                // Update  the node
                node.PokeMatrix(transform);

                // Pay attention to the dScaleFactor is 0, we must make it invisible.
                if (Math.Abs(dScaleFactor) < 1e-6)
                {
                    node.Visibility = false;
                }
            }
            catch(Exception ex)
            {
                string errMsg = ex.Message + "\n" + ex.StackTrace;
                vtk.vtkOutputWindow.GetInstance().DisplayErrorText(errMsg);
            }
        }
Esempio n. 4
0
        public virtual void ReadFromXMLNode(XmlNode node)
        {
            // Read the origin node
            XmlNode originNode = node.SelectSingleNode(ModelXMLDefinition.pipeUCSOrigin);
            CPoint3D origin = CPoint3DSerializer.ReadPoint(originNode);

            // Read the x axis
            XmlNode xAxisNode = node.SelectSingleNode(ModelXMLDefinition.pipeUCSXAxis);
            CPoint3D xAxis = CPoint3DSerializer.ReadPoint(xAxisNode);

            // Read the x axis
            XmlNode yAxisNode = node.SelectSingleNode(ModelXMLDefinition.pipeUCSYAxis);
            CPoint3D yAxis = CPoint3DSerializer.ReadPoint(yAxisNode); ;

            // Calculate the UCS
            Vector3D vecX = new Vector3D(xAxis.X, xAxis.Y, xAxis.Z);
            vecX.Normalize();

            Vector3D vecY = new Vector3D(yAxis.X, yAxis.Y, yAxis.Z);
            vecY.Normalize();

            // Get the z axis
            Vector3D vecZ = Vector3D.CrossProduct(vecX, vecY);

            // Recalculate the y axis since yaxis may not be preh to xaxis.
            vecY = Vector3D.CrossProduct(vecZ, vecX);

            // Create matrix3d representation
            m_matrix3d = new Matrix3D(vecX.X, vecX.Y, vecX.Z, 0,
                                      vecY.X, vecY.Y, vecY.Z, 0,
                                      vecZ.X, vecZ.Y, vecZ.Z, 0,
                                      origin.X, origin.Y, origin.Z, 1.0);

            m_matrix3dInvert = new Matrix3D(vecX.X, vecX.Y, vecX.Z, 0,
                                            vecY.X, vecY.Y, vecY.Z, 0,
                                            vecZ.X, vecZ.Y, vecZ.Z, 0,
                                            origin.X, origin.Y, origin.Z, 1.0);
            m_matrix3dInvert.Invert();

            // Set transform
            m_tranform = m_matrix3d.ToVTKTransformation();
            m_tranformInvert.DeepCopy(m_tranform);
            m_tranformInvert.Inverse();
        }