Esempio n. 1
0
        public void UpdatePosition(double[] endPoint, double[] startPoint)
        {
            double[] normalizedX = new double[3];
            double[] normalizedY = new double[3];
            double[] normalizedZ = new double[3];

            // The X axis is a vector from start to end
            Subtract(endPoint, startPoint, normalizedX);

            double length =
                Math.Sqrt(normalizedX[0] * normalizedX[0] + normalizedX[1] * normalizedX[1] + normalizedX[2] * normalizedX[2]);

            //Console.WriteLine(@"length = " + length);

            normalizedX = VTKUtil.Normalize(normalizedX);

            // The Z axis is an arbitrary vecotr cross X
            double[] arbitrary = new double[3];
            arbitrary[0] = vtkMath.Random(-10, 10);
            arbitrary[1] = vtkMath.Random(-10, 10);
            arbitrary[2] = vtkMath.Random(-10, 10);
            arbitrary    = VTKUtil.Normalize(arbitrary);
            // TODO FIX ME

            normalizedZ = VTKUtil.Cross(normalizedX, arbitrary);
            //vtkMath.Cross(VTKUtil.ConvertIntPtr(normalizedX), VTKUtil.ConvertIntPtr(arbitrary), VTKUtil.ConvertIntPtr(normalizedZ));
            //vtkMath.Normalize(VTKUtil.ConvertIntPtr(normalizedZ));

            // The Y axis is Z cross X

            // TODO FIX ME
            //vtkMath.Cross(VTKUtil.ConvertIntPtr(normalizedZ), VTKUtil.ConvertIntPtr(normalizedX), VTKUtil.ConvertIntPtr(normalizedY));
            normalizedY = VTKUtil.Cross(normalizedX, normalizedZ);

            vtkMatrix4x4 matrix = vtkMatrix4x4.New();

            // Create the direction cosine matrix
            matrix.Identity();
            for (int i = 0; i < 3; i++)
            {
                matrix.SetElement(i, 0, normalizedX[i]);
                matrix.SetElement(i, 1, normalizedY[i]);
                matrix.SetElement(i, 2, normalizedZ[i]);
            }

            //Console.WriteLine(matrix);

            // Apply the transforms
            vtkTransform transform = vtkTransform.New();

            transform.Translate(VTKUtil.ConvertIntPtr(startPoint));
            transform.Concatenate(matrix);

            //length = 500;
            transform.Scale(length, length, length);

            // Transform the polydata
            //vtkTransformPolyDataFilter transformPD = new vtkTransformPolyDataFilter();
            //transformPD.SetTransform(transform);
            //transformPD.SetInputConnection(_arrowSource.GetOutputPort());

            _arrowSource.SetTipRadius(0.25);
            _arrowSource.SetTipLength(0.7);
            _arrowSource.Update();
            _mapper.SetInput(_arrowSource.GetOutput());
            _arrowActor.SetUserMatrix(transform.GetMatrix());
            _arrowActor.GetProperty().ShadingOn();
            _arrowActor.GetProperty().SetAmbient(0.7);
            _arrowActor.GetProperty().SetOpacity(0.4);
            _arrowActor.SetMapper(_mapper);
        }