/// <summary> /// Rotates volume along given axis. /// </summary> /// <param name="volume"></param> /// <param name="angles"></param> public static void RotateData(ref vtkImageData volume, double[] angles) { // Rotation along image center double[] center = volume.GetExtent().Divide(2); // Dimensions of rotated image int[] outExtent = volume.GetExtent().Multiply(1.1).Round().ToInt32(); // Rotation parameters var rotate = new vtkTransform(); rotate.Translate(center[1], center[3], center[5]); rotate.RotateX(angles[0]); rotate.RotateY(angles[1]); rotate.RotateZ(angles[2]); // z angle should be 0 rotate.Translate(-center[1], -center[3], -center[5]); // Perform rotation var slice = new vtkImageReslice(); slice.SetInput(volume); slice.SetResliceTransform(rotate); slice.SetInterpolationModeToCubic(); slice.SetOutputSpacing(volume.GetSpacing()[0], volume.GetSpacing()[1], volume.GetSpacing()[2]); slice.SetOutputOrigin(volume.GetOrigin()[0], volume.GetOrigin()[1], volume.GetOrigin()[2]); slice.SetOutputExtent(outExtent[0], outExtent[1], outExtent[2], outExtent[3], outExtent[4], outExtent[5]); }
/// <summary> /// Update the 2D visualization when the plane moved. /// </summary> /// <param name="plane">PlaneWidget which changed the coordinates.</param> public void PlaneMoved(vtkImagePlaneWidget plane) { vtkImageReslice reslice = vtkImageReslice.New(); vtkTransform transform = vtkTransform.New(); transform.PostMultiply(); //TODO wyznaczenie centrum okna double[] center = { 75, 100, 0 }; transform.Translate(-center[0], -center[1], -center[2]); transform.RotateZ(_orientation); transform.Translate(+center[0], +center[1], +center[2]); transform.Update(); reslice.SetInput(plane.GetResliceOutput()); reslice.SetResliceTransform(transform); reslice.Update(); // vtkImageData viewerInputData; viewerInputData = reslice.GetOutput(); _lastData = viewerInputData; _viewer.SetInput(viewerInputData); // //_viewer.SetInput(reslice.GetOutput()); UpdateViewer(); }
private void RotateImage(RotationOperation operation) { vtkImageReslice reslice = vtkImageReslice.New(); vtkTransform transform = vtkTransform.New(); transform.PostMultiply(); double[] center = { 75, 100, 0 }; transform.Translate(-center[0], -center[1], -center[2]); if (operation == RotationOperation.Forward) { transform.RotateZ(90); } else if (operation == RotationOperation.Back) { transform.RotateZ(-90); } transform.Translate(+center[0], +center[1], +center[2]); transform.Update(); reslice.SetInput(_viewer.GetInput()); reslice.SetResliceTransform(transform); reslice.Update(); _viewer.SetInput(reslice.GetOutput()); UpdateViewer(); }
//TODO public void DrawingModeRepaint() { if (_lastData == null) { return; } vtkImageReslice reslice = vtkImageReslice.New(); vtkTransform transform = vtkTransform.New(); transform.PostMultiply(); //TODO wyznaczenie centrum okna double[] center = { 75, 100, 0 }; transform.Translate(-center[0], -center[1], -center[2]); transform.RotateZ(_orientation); transform.Translate(+center[0], +center[1], +center[2]); transform.Update(); reslice.SetInput(_lastData); reslice.SetResliceTransform(transform); reslice.Update(); vtkImageData viewerInputData; if (!DrawingEnabled) { viewerInputData = reslice.GetOutput(); } else { var resliceOutput = reslice.GetOutput(); var sizeArray = resliceOutput.GetDimensions(); vtkImageCanvasSource2D imageCanvas = vtkImageCanvasSource2D.New(); imageCanvas.SetScalarTypeToUnsignedChar(); imageCanvas.SetExtent(0, sizeArray[0], 0, sizeArray[1], 0, 0); imageCanvas.DrawImage(0, 0, resliceOutput); DrawingUtils.Draw(imageCanvas, DrawingInfo); imageCanvas.Update(); viewerInputData = imageCanvas.GetOutput(); } _viewer.SetInput(viewerInputData); UpdateViewer(); }
public Cone(ARenderable parent) : base(parent) { Name = "Cone"; cone = vtkConeSource.New(); cone.SetAngle(10); cone.SetRadius(0.2); cone.SetHeight(0.5); cone.SetResolution(20); move = vtkTransform.New(); move.Translate(_random.NextDouble(), _random.NextDouble(), _random.NextDouble()); moveFilter = vtkTransformPolyDataFilter.New(); moveFilter.SetTransform(move); moveFilter.SetInputConnection(cone.GetOutputPort()); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(moveFilter.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); Actors = new ObservableCollection <vtkActor>(); Actors.Add(actor); }
public Sphere(ARenderable parent) : base(parent) { Name = "Sphere"; sphere = vtkSphereSource.New(); sphere.SetThetaResolution(8); sphere.SetPhiResolution(16); shrink = vtkShrinkPolyData.New(); shrink.SetInputConnection(sphere.GetOutputPort()); shrink.SetShrinkFactor(0.9); move = vtkTransform.New(); move.Translate(_random.NextDouble(), _random.NextDouble(), _random.NextDouble()); moveFilter = vtkTransformPolyDataFilter.New(); moveFilter.SetTransform(move); moveFilter.SetInputConnection(shrink.GetOutputPort()); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(moveFilter.GetOutputPort()); Actors = new ObservableCollection <vtkActor>(); // The actor links the data pipeline to the rendering subsystem vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.GetProperty().SetColor(1, 0, 0); Actors.Add(actor); }
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); }
static public vtkAlgorithmOutput genFrustumCone(double total_dis, double end_radius, double distance, bool is_reverse) { vtkConeSource cone = vtkConeSource.New(); cone.SetHeight(total_dis * 1.2); cone.SetRadius(end_radius * 1.2); cone.SetCenter(0, 0, total_dis * 0.4); cone.SetResolution(80); cone.SetDirection(0, 0, 1); cone.Update(); vtkPlane plane = vtkPlane.New(); plane.SetOrigin(0, 0, 0); plane.SetNormal(0, 0, 1); vtkClipPolyData clipPolyData = vtkClipPolyData.New(); clipPolyData.SetInputConnection(cone.GetOutputPort()); clipPolyData.SetClipFunction(plane); clipPolyData.GenerateClippedOutputOn(); clipPolyData.Update(); vtkPlane plane2 = vtkPlane.New(); plane2.SetOrigin(0, 0, distance); plane2.SetNormal(0, 0, -1); vtkClipPolyData clipPolyData2 = vtkClipPolyData.New(); clipPolyData2.SetInputConnection(clipPolyData.GetOutputPort()); clipPolyData2.SetClipFunction(plane2); clipPolyData2.GenerateClippedOutputOn(); clipPolyData2.Update(); if (is_reverse) { vtkTransform transform = vtkTransform.New(); transform.RotateWXYZ(180, 0, 1, 0); transform.Translate(0, 0, -distance); vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New(); transFilter.SetInputConnection(clipPolyData2.GetOutputPort()); transFilter.SetTransform(transform); //use vtkTransform (or maybe vtkLinearTransform) transFilter.Update(); return(transFilter.GetOutputPort()); } return(clipPolyData2.GetOutputPort()); }
/// <summary> /// 进行2D转换 /// </summary> /// <param name="polyData"></param> /// <param name="info"></param> /// <returns></returns> private static vtkPolyData Extrude2DSection(vtkPolyData polyData, ModelingBaseInfo info) { vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); vtkTransformFilter transFilter = vtkTransformFilter.New(); vtkTransform transform = vtkTransform.New(); transform.RotateX(-90); // 旋转到xoy面上 transform.RotateY(info.Angle); //顺时针为正逆时针为负 // transform.Translate(info.BaseCoordinate.X, info.BaseCoordinate.Y, info.BaseCoordinate.Z);//先旋转后平移 transform.Translate(info.BaseCoordinate.X, info.BaseCoordinate.Z, info.BaseCoordinate.Y); //先旋转后平移 transFilter.SetTransform(transform); transFilter.SetInput(polyData); return(transFilter.GetPolyDataOutput()); }
public void SetPosition(double[] position) { if (position == null) { return; } this.Position = position; vtkTransform transform = vtkTransform.New(); transform.Translate(position[0], position[1], position[2]); SetUserTransform(transform: transform); transform.Dispose(); }
private void Axes() { vtkSphereSource sphereSource = vtkSphereSource.New(); sphereSource.SetCenter(0.0, 0.0, 0.0); sphereSource.SetRadius(0.5); //create a mapper vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New(); sphereMapper.SetInputConnection(sphereSource.GetOutputPort()); // create an actor vtkActor sphereActor = vtkActor.New(); sphereActor.SetMapper(sphereMapper); // a renderer and render window vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); renderer.SetBackground(0.2, 0.3, 0.4); // add the actors to the scene renderer.AddActor(sphereActor); vtkAxesActor axes = vtkAxesActor.New(); // The axes are positioned with a user transform vtkTransform transform = vtkTransform.New(); transform.Translate(0.75, 0.0, 0.0); axes.SetUserTransform(transform); // properties of the axes labels can be set as follows // this sets the x axis label to red // axes.GetXAxisCaptionActor2D().GetCaptionTextProperty().SetColor(1,0,0); // the actual text of the axis label can be changed: // axes.SetXAxisLabelText("test"); renderer.AddActor(axes); // we need to call Render() for the whole renderWindow, // because vtkAxesActor uses an overlayed renderer for the axes label // in total we have now two renderer renderWindow.Render(); }
static public vtkProp3D genActor(List <GaussianCluster> data) { vtkProperty pro = new vtkProperty(); // 默认颜色 pro.SetColor(config.cone_color[0], config.cone_color[1], config.cone_color[2]); pro.SetOpacity(0.4); vtkAppendPolyData polydata = vtkAppendPolyData.New(); for (int i = 1; i < data.Count; i++) { var cluster = data[i]; System.Windows.Forms.MessageBox.Show("cluster.start_radius:" + cluster.start_radius.ToString() + "cluster.distance:" + cluster.distance.ToString() + "cluster.is_foucs:" + cluster.is_foucs.ToString() + "cluster.foucs_radius:" + cluster.foucs_radius.ToString()); vtkTransform transform = vtkTransform.New(); transform.Translate(cluster.coordinate.pos.x, cluster.coordinate.pos.y, cluster.coordinate.pos.z); transform.RotateWXYZ(cluster.coordinate.rotate_theta, cluster.coordinate.rotate_axis.x, cluster.coordinate.rotate_axis.y, cluster.coordinate.rotate_axis.z); vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New(); transFilter.SetInputConnection(combiFrustumCone(cluster.start_radius, 1, cluster.angle, true, 0.01)); transFilter.SetTransform(transform); transFilter.Update(); polydata.AddInputConnection(transFilter.GetOutputPort()); } vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(polydata.GetOutputPort()); mapper.ScalarVisibilityOff(); // The actor links the data pipeline to the rendering subsystem vtkActor actor = vtkActor.New(); actor.SetProperty(pro); actor.SetMapper(mapper); return(actor); }
/// <summary> /// 进行二维结构的转换 /// </summary> /// <param name="polyData"></param> /// <param name="info"></param> /// <returns></returns> private static vtkActor FormActor2D(vtkPolyData polyData, ModelingBaseInfo info) {// vtkActor actor = vtkActor.New(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); vtkTransformFilter transFilter = vtkTransformFilter.New(); vtkTransform transform = vtkTransform.New(); transform.RotateX(-90); // 旋转到xoy面上 transform.RotateY(info.Angle); //顺时针为正逆时针为负 transform.Translate(info.BaseCoordinate.X, info.BaseCoordinate.Y, info.BaseCoordinate.Z); //先旋转后平移 // transform.Translate(info.BaseCoordinate.X, info.BaseCoordinate.Z,info.BaseCoordinate.Y );//先旋转后平移 transFilter.SetTransform(transform); transFilter.SetInput(polyData); mapper.SetInputConnection(transFilter.GetOutputPort()); actor.SetMapper(mapper); return(actor); }
static public vtkAlgorithmOutput combiFrustumCone(double start_radius, double distance, double angle, bool is_foucs, double foucs_radius) { double tanArc = Math.Tan(Math.PI * angle / 180); double origin_dis = start_radius / tanArc; if (is_foucs) // 缩小 { double origin_foucs_dis = foucs_radius / tanArc; double fouce_dis = origin_dis - origin_foucs_dis; if (distance > fouce_dis) //缩小到焦点后放大 { vtkAppendPolyData polydata = vtkAppendPolyData.New(); polydata.AddInputConnection(genFrustumCone(origin_dis, start_radius, fouce_dis, false)); vtkTransform transform = vtkTransform.New(); transform.Translate(0, 0, fouce_dis); vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New(); origin_dis = origin_foucs_dis + distance - fouce_dis; transFilter.SetInputConnection(genFrustumCone(origin_dis, origin_dis * tanArc, distance - fouce_dis, true)); transFilter.SetTransform(transform); //use vtkTransform (or maybe vtkLinearTransform) transFilter.Update(); polydata.AddInputConnection(transFilter.GetOutputPort()); polydata.Update(); return(polydata.GetOutputPort()); } else { return(genFrustumCone(origin_dis, start_radius, distance, false)); } } else // 放大 { double total_dis = origin_dis + distance; double end_radius = total_dis * tanArc; return(genFrustumCone(total_dis, end_radius, distance, true)); } }
static public vtkProp3D genUserActor(CompontData data, vtkAlgorithmOutput vtkAlgorithmOutput, vtkProperty pro) { vtkTransform transform = vtkTransform.New(); // 用户自定义平移旋转 (先移动后旋转) transform.Translate(data.coor.pos.x, data.coor.pos.y, data.coor.pos.z); transform.RotateWXYZ(data.coor.rotate_theta, data.coor.rotate_axis.x, data.coor.rotate_axis.y, data.coor.rotate_axis.z); vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New(); transFilter.SetInputConnection(vtkAlgorithmOutput); transFilter.SetTransform(transform); //use vtkTransform (or maybe vtkLinearTransform) transFilter.Update(); //vtkShrinkPolyData shrink = vtkShrinkPolyData.New(); //shrink.SetInputConnection(transFilter.GetOutputPort()); //shrink.SetShrinkFactor(1); // 改 //vtkSTLWriter writer = vtkSTLWriter.New(); //calPolyData(polyData, 0.01); //writer.SetInputConnection(transFilter.GetOutputPort()); //writer.SetFileName("test.stl"); //writer.Update(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(transFilter.GetOutputPort()); mapper.ScalarVisibilityOff(); // The actor links the data pipeline to the rendering subsystem vtkActor actor = vtkActor.New(); actor.SetProperty(pro); actor.SetMapper(mapper); return(actor); }
/// <summary> /// 进行三维结构的转换 /// </summary> /// <param name="degree"></param> /// <param name="polyData"></param> /// <param name="info"></param> /// <returns></returns> private static vtkPolyData Extrude3DSection(float degree, vtkPolyData polyData, ModelingBaseInfo info) { //进行拉伸以构造的三维实体 vtkRotationalExtrusionFilter extrude = vtkRotationalExtrusionFilter.New(); extrude.SetInput(polyData); extrude.SetResolution(80); extrude.SetAngle(degree);//旋转 extrude.CappingOn(); vtkPolyDataNormals normals = vtkPolyDataNormals.New(); normals.SetInput(extrude.GetOutput()); normals.SetFeatureAngle(100); //进行转换 vtkTransform transform = vtkTransform.New(); transform.RotateX(info.Angle); //逆时针为正,顺时针为负 transform.Translate(info.BaseCoordinate.X, info.BaseCoordinate.Y, info.BaseCoordinate.Z); //先旋转后平移 vtkTransformFilter transFilter = vtkTransformFilter.New(); transFilter.SetTransform(transform); transFilter.SetInput(normals.GetOutput()); //vtkTriangleFilter filter = vtkTriangleFilter.New(); //filter.SetInput(transFilter.GetOutput()); //return filter.GetPolyDataInput(0); vtkCleanPolyData clearPolydata = vtkCleanPolyData.New();//清除重合的点和片 clearPolydata.SetInput(transFilter.GetOutput()); return(clearPolydata.GetOutput()); //return transFilter.GetPolyDataOutput(); }
private void TransformAxes(vtkAxesActor axes, Position position) { vtkTransform transform = new vtkTransform(); transform.Translate(position.X, position.Y, position.Z); transform.RotateWXYZ(position.A, 0, 0, 1); transform.RotateWXYZ(position.B, 0, 1, 0); transform.RotateWXYZ(position.C, 1, 0, 0); axes.SetUserTransform(transform); }
/// <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(); }
public void SetTranslation() { vtkTransform.Translate(translateX, translateY, translateZ); }
/// <summary> /// Rotates 3D vtk volume around x and y axes. /// </summary> /// <param name="input"></param> /// <param name="angle"></param> /// <param name="axis"></param> /// <param name="out_extent"></param> /// <returns></returns> public static vtkImageData rotate_sample(vtkImageData input, double angle, int axis, int out_extent = 0) { //get input data dimensions int[] dims = input.GetExtent(); //Compute centers int[] centers = new int[] { (dims[1] + dims[0]) / 2, (dims[3] + dims[2]) / 2, (dims[5] + dims[4]) / 2 }; //Set rotation axis int[] axes = new int[3]; axes[axis] = 1; int[] new_dims = new int[] { dims[0], dims[1], dims[2], dims[3], dims[4], dims[5] }; int[] new_centers = new int[] { centers[0], centers[1], centers[2] }; //Compute new sample dimensions if (axis == 0) { new_dims[3] = (int)(Math.Cos(Math.Abs(angle / 180) * Math.PI) * new_dims[3] + Math.Sin(Math.Abs(angle / 180) * Math.PI) * new_dims[5]); new_dims[5] = (int)(Math.Sin(Math.Abs(angle / 180) * Math.PI) * new_dims[3] + Math.Cos(Math.Abs(angle / 180) * Math.PI) * new_dims[5]); new_centers[1] = (Math.Abs(new_dims[3]) + Math.Abs(new_dims[2])) / 2; new_centers[2] = (Math.Abs(new_dims[5]) + Math.Abs(new_dims[4])) / 2; } if (axis == 1) { new_dims[1] = (int)(Math.Cos(Math.Abs(angle / 180) * Math.PI) * new_dims[1] + Math.Sin(Math.Abs(angle / 180) * Math.PI) * new_dims[5]); new_dims[5] = (int)(Math.Sin(Math.Abs(angle / 180) * Math.PI) * new_dims[1] + Math.Cos(Math.Abs(angle / 180) * Math.PI) * new_dims[5]); new_centers[0] = (Math.Abs(new_dims[0]) + Math.Abs(new_dims[1])) / 2; new_centers[2] = (Math.Abs(new_dims[5]) + Math.Abs(new_dims[4])) / 2; } //Image transformation vtkTransform transform = vtkTransform.New(); transform.Translate(centers[0], centers[1], centers[2]); transform.RotateWXYZ(angle, axes[0], axes[1], axes[2]); if (out_extent == 0) { transform.Translate(-centers[0], -centers[1], -centers[2]); } else { transform.Translate(-new_centers[0], -new_centers[1], -new_centers[2]); } //Console.ReadKey(); transform.Update(); //Compute new data extent int[] diff = new int[] { new_dims[1] - dims[1], new_dims[3] - dims[3], new_dims[5] - dims[5] }; new_dims[0] += diff[0] / 2; new_dims[1] -= diff[0] / 2; new_dims[2] += diff[1] / 2; new_dims[3] -= diff[1] / 2; new_dims[4] += diff[2] / 2; new_dims[5] -= diff[2] / 2; //Image reslicing vtkImageReslice rotater = vtkImageReslice.New(); rotater.SetInput(input); rotater.SetInformationInput(input); rotater.SetResliceTransform(transform); rotater.SetInterpolationModeToCubic(); //rotater.SetInterpolationModeToLinear(); if (out_extent == 1) { rotater.SetOutputSpacing(input.GetSpacing()[0], input.GetSpacing()[1], input.GetSpacing()[2]); rotater.SetOutputOrigin(input.GetOrigin()[0], input.GetOrigin()[1], input.GetOrigin()[2]); rotater.SetOutputExtent(new_dims[0], new_dims[1], new_dims[2], new_dims[3], new_dims[4], new_dims[5]); } rotater.Update(); vtkImageData output = vtkImageData.New(); output.DeepCopy(rotater.GetOutput()); rotater.Dispose(); transform.Dispose(); return(output); }
/// <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 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(); }
static public vtkProp3D genFieldActor(FieldBase data) { int N_width = data.Ex.Count; int M_depth = data.Ex.Count; double ds = data.ds_x; double width = N_width * ds; double depth = M_depth * ds; vtkImageData img = vtkImageData.New(); img.SetDimensions(N_width, M_depth, 1); img.SetSpacing(0.01 * ds / 0.01, 0.01 * ds / 0.01, 1); img.SetScalarTypeToDouble(); img.SetNumberOfScalarComponents(1); double max = -100000000, min = 0; List <List <Complex> > tempEH = null; int content = 1; bool isPhs = false; bool isLinear = true; const double dB_RABNGE = 60; switch (content) { case 0: tempEH = data.Ex; break; case 1: tempEH = data.Ey; break; case 2: tempEH = data.Ez; break; case 3: tempEH = data.Hx; break; case 4: tempEH = data.Hy; break; case 5: tempEH = data.Hz; break; default: break; } double[] data_tmp = new double[M_depth * N_width]; int count = 0; for (int j = 0; j < M_depth; j++) { for (int i = 0; i < N_width; i++) { double tempD; Complex temp; temp = tempEH[i][j]; if (isPhs) { if (temp.real != 0) { tempD = Math.Atan2(temp.imag, temp.real); } else { tempD = 0; } } else { tempD = Math.Pow((temp.real * temp.real + temp.imag * temp.imag), 0.5); } if (!isLinear && !isPhs) { tempD = 20 * Math.Log(tempD + 0.000000001); if (min > tempD) { min = tempD; } if (max < tempD) { max = tempD; } } else { if (max < tempD) { max = tempD; } if (min > tempD) { min = tempD; } } data_tmp[count++] = tempD; } } //ptr = img.GetScalarPointer(); vtkLookupTable colorTable = vtkLookupTable.New(); if (!isLinear && !isPhs) { min = max - dB_RABNGE; } if (!isPhs) { for (int i = 0; i < N_width * M_depth * 1; i++) { data_tmp[i] = max - data_tmp[i]; } colorTable.SetRange(0, max - min); } else { colorTable.SetRange(min, max); } IntPtr ptr = img.GetScalarPointer(); System.Runtime.InteropServices.Marshal.Copy(data_tmp, 0, ptr, M_depth * N_width); colorTable.Build(); vtkImageMapToColors colorMap = vtkImageMapToColors.New(); colorMap.SetInput(img); colorMap.SetLookupTable(colorTable); colorMap.Update(); vtkTransform transform = vtkTransform.New(); transform.Translate(data.coordinate.pos.x, data.coordinate.pos.y, data.coordinate.pos.z); transform.RotateWXYZ(data.coordinate.rotate_theta, data.coordinate.rotate_axis.x, data.coordinate.rotate_axis.y, data.coordinate.rotate_axis.z); transform.Translate(-width / 2, -depth / 2, 0); vtkImageActor actor = vtkImageActor.New(); actor.SetInput(colorMap.GetOutput()); actor.SetUserTransform(transform); return(actor); }
private void TransformRobotPart(vtkActor part, Position shift, Position position) { vtkTransform transform = new vtkTransform(); transform.Translate(position.X, position.Y, position.Z); transform.RotateWXYZ(position.A, 0, 0, 1); transform.RotateWXYZ(position.B, 0, 1, 0); transform.RotateWXYZ(position.C, 1, 0, 0); if (part == robot1part7) transform.RotateWXYZ(11.5, 0, 0, 1); transform.RotateWXYZ(shift.C, 1, 0, 0); transform.RotateWXYZ(shift.B, 0, 1, 0); transform.RotateWXYZ(shift.A, 0, 0, 1); transform.Translate(shift.X, shift.Y, shift.Z); part.SetUserTransform(transform); }