Esempio n. 1
0
 public CTwoPoints(CPoint3D first, CPoint3D second)
 {
     m_first = new CPoint3D(first.Point);
     m_second = new CPoint3D(second.Point);
 }
        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);
            }
        }