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; }
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); } }