public void UpdatePosition_OLD(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 = vtkMath.Norm(VTKUtil.ConvertIntPtr(normalizedX)); vtkMath.Normalize(VTKUtil.ConvertIntPtr(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); // TODO FIX ME 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)); 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]); } // 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.Update(); _mapper.SetInput(_arrowSource.GetOutput()); _arrowActor.SetUserMatrix(transform.GetMatrix()); _arrowActor.SetMapper(_mapper); }
public void SetScale() { vtkTransform.Scale(scaleX, scaleY, scaleZ); }
private void OrientedArrow() { //Create an arrow. vtkArrowSource arrowSource = vtkArrowSource.New(); // Generate a random start and end point vtkMath.RandomSeed(8775070); double[] startPoint = new double[] { vtkMath.Random(-10, 10), vtkMath.Random(-10, 10), vtkMath.Random(-10, 10) }; double[] endPoint = new double[] { vtkMath.Random(-10, 10), vtkMath.Random(-10, 10), vtkMath.Random(-10, 10) }; // Compute a basis 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 myMath.Subtract(endPoint, startPoint, ref normalizedX); double length = myMath.Norm(normalizedX); myMath.Normalize(ref normalizedX); // The Z axis is an arbitrary vector cross X double[] arbitrary = new double[] { vtkMath.Random(-10, 10), vtkMath.Random(-10, 10), vtkMath.Random(-10, 10) }; myMath.Cross(normalizedX, arbitrary, ref normalizedZ); myMath.Normalize(ref normalizedZ); // The Y axis is Z cross X myMath.Cross(normalizedZ, normalizedX, ref normalizedY); 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]); } // Apply the transforms vtkTransform transform = vtkTransform.New(); transform.Translate(startPoint[0], startPoint[1], startPoint[2]); transform.Concatenate(matrix); transform.Scale(length, length, length); //Create a mapper and actor for the arrow vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); vtkActor actor = vtkActor.New(); #if USER_MATRIX mapper.SetInputConnection(arrowSource.GetOutputPort()); actor.SetUserMatrix(transform.GetMatrix()); #else // Transform the polydata vtkTransformPolyDataFilter transformPD = vtkTransformPolyDataFilter.New(); transformPD.SetTransform(transform); transformPD.SetInputConnection(arrowSource.GetOutputPort()); mapper.SetInputConnection(transformPD.GetOutputPort()); #endif actor.SetMapper(mapper); // Create spheres for start and end point vtkSphereSource sphereStartSource = vtkSphereSource.New(); sphereStartSource.SetCenter(startPoint[0], startPoint[1], startPoint[2]); vtkPolyDataMapper sphereStartMapper = vtkPolyDataMapper.New(); sphereStartMapper.SetInputConnection(sphereStartSource.GetOutputPort()); vtkActor sphereStart = vtkActor.New(); sphereStart.SetMapper(sphereStartMapper); sphereStart.GetProperty().SetColor(1.0, 1.0, .3); vtkSphereSource sphereEndSource = vtkSphereSource.New(); sphereEndSource.SetCenter(endPoint[0], endPoint[1], endPoint[2]); vtkPolyDataMapper sphereEndMapper = vtkPolyDataMapper.New(); sphereEndMapper.SetInputConnection(sphereEndSource.GetOutputPort()); vtkActor sphereEnd = vtkActor.New(); sphereEnd.SetMapper(sphereEndMapper); sphereEnd.GetProperty().SetColor(1.0, .3, .3); vtkRenderWindow renderWindow = myRenderWindowControl.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(0.2, 0.3, 0.4); renderer.AddActor(actor); renderer.AddActor(sphereStart); renderer.AddActor(sphereEnd); renderer.ResetCamera(); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVprobeComb(String [] argv) { //Prefix Content is: "" // create planes[] // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.SetMultiSamples(0); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // create pipeline[] //[] pl3d = new vtkMultiBlockPLOT3DReader(); pl3d.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin"); pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin"); pl3d.SetScalarFunctionNumber((int)100); pl3d.SetVectorFunctionNumber((int)202); pl3d.Update(); plane = new vtkPlaneSource(); plane.SetResolution((int)50, (int)50); transP1 = new vtkTransform(); transP1.Translate((double)3.7, (double)0.0, (double)28.37); transP1.Scale((double)5, (double)5, (double)5); transP1.RotateY((double)90); tpd1 = new vtkTransformPolyDataFilter(); tpd1.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd1.SetTransform((vtkAbstractTransform)transP1); outTpd1 = new vtkOutlineFilter(); outTpd1.SetInputConnection((vtkAlgorithmOutput)tpd1.GetOutputPort()); mapTpd1 = vtkPolyDataMapper.New(); mapTpd1.SetInputConnection((vtkAlgorithmOutput)outTpd1.GetOutputPort()); tpd1Actor = new vtkActor(); tpd1Actor.SetMapper((vtkMapper)mapTpd1); tpd1Actor.GetProperty().SetColor((double)0, (double)0, (double)0); transP2 = new vtkTransform(); transP2.Translate((double)9.2, (double)0.0, (double)31.20); transP2.Scale((double)5, (double)5, (double)5); transP2.RotateY((double)90); tpd2 = new vtkTransformPolyDataFilter(); tpd2.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd2.SetTransform((vtkAbstractTransform)transP2); outTpd2 = new vtkOutlineFilter(); outTpd2.SetInputConnection((vtkAlgorithmOutput)tpd2.GetOutputPort()); mapTpd2 = vtkPolyDataMapper.New(); mapTpd2.SetInputConnection((vtkAlgorithmOutput)outTpd2.GetOutputPort()); tpd2Actor = new vtkActor(); tpd2Actor.SetMapper((vtkMapper)mapTpd2); tpd2Actor.GetProperty().SetColor((double)0, (double)0, (double)0); transP3 = new vtkTransform(); transP3.Translate((double)13.27, (double)0.0, (double)33.30); transP3.Scale((double)5, (double)5, (double)5); transP3.RotateY((double)90); tpd3 = new vtkTransformPolyDataFilter(); tpd3.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd3.SetTransform((vtkAbstractTransform)transP3); outTpd3 = new vtkOutlineFilter(); outTpd3.SetInputConnection((vtkAlgorithmOutput)tpd3.GetOutputPort()); mapTpd3 = vtkPolyDataMapper.New(); mapTpd3.SetInputConnection((vtkAlgorithmOutput)outTpd3.GetOutputPort()); tpd3Actor = new vtkActor(); tpd3Actor.SetMapper((vtkMapper)mapTpd3); tpd3Actor.GetProperty().SetColor((double)0, (double)0, (double)0); appendF = new vtkAppendPolyData(); appendF.AddInputConnection(tpd1.GetOutputPort()); appendF.AddInputConnection(tpd2.GetOutputPort()); appendF.AddInputConnection(tpd3.GetOutputPort()); probe = new vtkProbeFilter(); probe.SetInputConnection((vtkAlgorithmOutput)appendF.GetOutputPort()); probe.SetSourceData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); contour = new vtkContourFilter(); contour.SetInputConnection((vtkAlgorithmOutput)probe.GetOutputPort()); contour.GenerateValues((int)50, (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]); contourMapper = vtkPolyDataMapper.New(); contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort()); contourMapper.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)contourMapper); outline = new vtkStructuredGridOutlineFilter(); outline.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0)); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0, (double)0, (double)0); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)tpd1Actor); ren1.AddActor((vtkProp)tpd2Actor); ren1.AddActor((vtkProp)tpd3Actor); ren1.SetBackground((double)1, (double)1, (double)1); renWin.SetSize((int)400, (int)400); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.95297, (double)50); cam1.SetFocalPoint((double)8.88908, (double)0.595038, (double)29.3342); cam1.SetPosition((double)-12.3332, (double)31.7479, (double)41.2387); cam1.SetViewUp((double)0.060772, (double)-0.319905, (double)0.945498); iren.Initialize(); // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }
private void WeightedTransformFilter() { // Use a sphere as a basis of the shape vtkSphereSource sphere = vtkSphereSource.New(); sphere.SetPhiResolution(40); sphere.SetThetaResolution(40); sphere.Update(); vtkPolyData sphereData = sphere.GetOutput(); // Create a data array to hold the weighting coefficients vtkFloatArray tfarray = vtkFloatArray.New(); int npoints = sphereData.GetNumberOfPoints(); tfarray.SetNumberOfComponents(2); tfarray.SetNumberOfTuples(npoints); // Parameterize the sphere along the z axis, and fill the weights // with (1.0-a, a) to linearly interpolate across the shape IntPtr pPoint = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * 3); double[] point = new double[3]; for (int i = 0; i < npoints; i++) { sphereData.GetPoint(i, pPoint); Marshal.Copy(pPoint, point, 0, 3); double x = point[0]; double y = point[1]; double z = point[2]; double zn = z + 0.5; double zn1 = 1.0 - zn; if (zn > 1.0) { zn = 1.0; } if (zn1 < 0.0) { zn1 = 0.0; } tfarray.SetComponent(i, 0, zn1); tfarray.SetComponent(i, 1, zn); } Marshal.FreeHGlobal(pPoint); // Create field data to hold the array, and bind it to the sphere vtkFieldData fd = vtkFieldData.New(); tfarray.SetName("weights"); sphereData.GetPointData().AddArray(tfarray); // Use an ordinary transform to stretch the shape vtkTransform stretch = vtkTransform.New(); stretch.Scale(1, 1, 3.2); vtkTransformFilter stretchFilter = vtkTransformFilter.New(); stretchFilter.SetInputConnection(sphereData.GetProducerPort()); stretchFilter.SetTransform(stretch); // Now, for the weighted transform stuff vtkWeightedTransformFilter weightedTrans = vtkWeightedTransformFilter.New(); // Create two transforms to interpolate between vtkTransform identity = vtkTransform.New(); identity.Identity(); vtkTransform rotated = vtkTransform.New(); double rotatedAngle = 45; rotated.RotateX(rotatedAngle); weightedTrans.SetNumberOfTransforms(2); weightedTrans.SetTransform(identity, 0); weightedTrans.SetTransform(rotated, 1); // which data array should the filter use ? weightedTrans.SetWeightArray("weights"); weightedTrans.SetInputConnection(stretchFilter.GetOutputPort()); vtkPolyDataMapper weightedTransMapper = vtkPolyDataMapper.New(); weightedTransMapper.SetInputConnection(weightedTrans.GetOutputPort()); vtkActor weightedTransActor = vtkActor.New(); weightedTransActor.SetMapper(weightedTransMapper); weightedTransActor.GetProperty().SetDiffuseColor(0.8, 0.8, 0.1); weightedTransActor.GetProperty().SetRepresentationToSurface(); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.2, 0.3, 0.4); // add our actor to the renderer renderer.AddActor(weightedTransActor); renderer.ResetCamera(); renderer.GetActiveCamera().Azimuth(90); renderer.GetActiveCamera().Dolly(1); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVprobeComb(String [] argv) { //Prefix Content is: "" // create planes[] // Create the RenderWindow, Renderer and both Actors[] //[] ren1 = vtkRenderer.New(); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); // create pipeline[] //[] pl3d = new vtkPLOT3DReader(); pl3d.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin"); pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin"); pl3d.SetScalarFunctionNumber((int)100); pl3d.SetVectorFunctionNumber((int)202); pl3d.Update(); plane = new vtkPlaneSource(); plane.SetResolution((int)50,(int)50); transP1 = new vtkTransform(); transP1.Translate((double)3.7,(double)0.0,(double)28.37); transP1.Scale((double)5,(double)5,(double)5); transP1.RotateY((double)90); tpd1 = new vtkTransformPolyDataFilter(); tpd1.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd1.SetTransform((vtkAbstractTransform)transP1); outTpd1 = new vtkOutlineFilter(); outTpd1.SetInputConnection((vtkAlgorithmOutput)tpd1.GetOutputPort()); mapTpd1 = vtkPolyDataMapper.New(); mapTpd1.SetInputConnection((vtkAlgorithmOutput)outTpd1.GetOutputPort()); tpd1Actor = new vtkActor(); tpd1Actor.SetMapper((vtkMapper)mapTpd1); tpd1Actor.GetProperty().SetColor((double)0,(double)0,(double)0); transP2 = new vtkTransform(); transP2.Translate((double)9.2,(double)0.0,(double)31.20); transP2.Scale((double)5,(double)5,(double)5); transP2.RotateY((double)90); tpd2 = new vtkTransformPolyDataFilter(); tpd2.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd2.SetTransform((vtkAbstractTransform)transP2); outTpd2 = new vtkOutlineFilter(); outTpd2.SetInputConnection((vtkAlgorithmOutput)tpd2.GetOutputPort()); mapTpd2 = vtkPolyDataMapper.New(); mapTpd2.SetInputConnection((vtkAlgorithmOutput)outTpd2.GetOutputPort()); tpd2Actor = new vtkActor(); tpd2Actor.SetMapper((vtkMapper)mapTpd2); tpd2Actor.GetProperty().SetColor((double)0,(double)0,(double)0); transP3 = new vtkTransform(); transP3.Translate((double)13.27,(double)0.0,(double)33.30); transP3.Scale((double)5,(double)5,(double)5); transP3.RotateY((double)90); tpd3 = new vtkTransformPolyDataFilter(); tpd3.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort()); tpd3.SetTransform((vtkAbstractTransform)transP3); outTpd3 = new vtkOutlineFilter(); outTpd3.SetInputConnection((vtkAlgorithmOutput)tpd3.GetOutputPort()); mapTpd3 = vtkPolyDataMapper.New(); mapTpd3.SetInputConnection((vtkAlgorithmOutput)outTpd3.GetOutputPort()); tpd3Actor = new vtkActor(); tpd3Actor.SetMapper((vtkMapper)mapTpd3); tpd3Actor.GetProperty().SetColor((double)0,(double)0,(double)0); appendF = new vtkAppendPolyData(); appendF.AddInput((vtkPolyData)tpd1.GetOutput()); appendF.AddInput((vtkPolyData)tpd2.GetOutput()); appendF.AddInput((vtkPolyData)tpd3.GetOutput()); probe = new vtkProbeFilter(); probe.SetInputConnection((vtkAlgorithmOutput)appendF.GetOutputPort()); probe.SetSource((vtkDataObject)pl3d.GetOutput()); contour = new vtkContourFilter(); contour.SetInputConnection((vtkAlgorithmOutput)probe.GetOutputPort()); contour.GenerateValues((int)50,(double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[1]); contourMapper = vtkPolyDataMapper.New(); contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort()); contourMapper.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[1]); planeActor = new vtkActor(); planeActor.SetMapper((vtkMapper)contourMapper); outline = new vtkStructuredGridOutlineFilter(); outline.SetInputConnection((vtkAlgorithmOutput)pl3d.GetOutputPort()); outlineMapper = vtkPolyDataMapper.New(); outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort()); outlineActor = new vtkActor(); outlineActor.SetMapper((vtkMapper)outlineMapper); outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0); ren1.AddActor((vtkProp)outlineActor); ren1.AddActor((vtkProp)planeActor); ren1.AddActor((vtkProp)tpd1Actor); ren1.AddActor((vtkProp)tpd2Actor); ren1.AddActor((vtkProp)tpd3Actor); ren1.SetBackground((double)1,(double)1,(double)1); renWin.SetSize((int)400,(int)400); cam1 = ren1.GetActiveCamera(); cam1.SetClippingRange((double)3.95297,(double)50); cam1.SetFocalPoint((double)8.88908,(double)0.595038,(double)29.3342); cam1.SetPosition((double)-12.3332,(double)31.7479,(double)41.2387); cam1.SetViewUp((double)0.060772,(double)-0.319905,(double)0.945498); iren.Initialize(); // prevent the tk window from showing up then start the event loop[] //deleteAllVTKObjects(); }