public void AddCylinderEdgeToActors(byte[] bgColor, ref vtkActorCollection actors) { vtkProperty pp = vtkProperty.New(); pp.SetOpacity(0.7); pp.SetColor(bgColor[0], bgColor[1], bgColor[2]); pp.SetLineWidth(5); pp.SetLighting(false); vtkRegularPolygonSource circle = vtkRegularPolygonSource.New(); circle.GeneratePolygonOn(); circle.SetNumberOfSides(50); circle.SetRadius(radius); circle.SetCenter(0, 0, 0); vtkPolyDataMapper mappper = vtkPolyDataMapper.New(); mappper.SetInputConnection(circle.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetProperty(pp); actor.SetMapper(mappper); actors.AddItem(actor); actor.SetProperty(pp); actors.AddItem(actor); vtkLineSource ls = vtkLineSource.New(); ls.SetPoint1(0, 0, 0); ls.SetPoint2(0, 0, height); vtkTubeFilter tf = vtkTubeFilter.New(); tf.SetInputConnection(ls.GetOutputPort()); tf.SetRadius(radius); tf.SetNumberOfSides(100); tf.CappingOff(); vtkPolyDataMapper dm = vtkPolyDataMapper.New(); dm.SetInputConnection(tf.GetOutputPort()); vtkActor a2 = vtkActor.New(); a2.SetMapper(dm); a2.SetProperty(pp); pp.SetOpacity(0.5); actor.SetProperty(pp); actors.AddItem(a2); }
/// <summary> /// 绘制立长方体的边缘 /// </summary> /// <param name="bgColor">边缘的颜色</param> /// <param name="actors">添加至该对象</param> public void AddContainerEdgeToActorCollection(byte[] bgColor, ref vtkActorCollection actors) { vtkProperty pp = vtkProperty.New(); pp.SetOpacity(0.5); pp.SetColor(bgColor[0], bgColor[1], bgColor[2]); pp.SetLineWidth(5); pp.SetLighting(false); vtkCubeSource cs = vtkCubeSource.New(); cs.SetCenter(sideLen / 2, sideLen / 2, height / 2); cs.SetXLength(sideLen); cs.SetYLength(sideLen); cs.SetZLength(height); #region 采用描点的方式绘制长方体 只需要添加到mapper.SetInput(pd);即可 //vtkPoints points = vtkPoints.New(); //points.InsertNextPoint(0 + offset[0], 0 + offset[1], 0 + offset[2]); //points.InsertNextPoint(sideLen + offset[0], 0 + offset[1], 0 + offset[2]); //points.InsertNextPoint(sideLen + offset[0], sideLen + offset[1], 0 + offset[2]); //points.InsertNextPoint(0 + offset[0], sideLen + offset[1], 0 + offset[2]); //points.InsertNextPoint(0 + offset[0], sideLen + offset[1], height + offset[2]); //points.InsertNextPoint(sideLen + offset[0], sideLen + offset[1], height + offset[2]); //points.InsertNextPoint(sideLen + offset[0], 0 + offset[1], height + offset[2]); //points.InsertNextPoint(0 + offset[0], 0 + offset[1], height + offset[2]); //vtkPolyData pd = vtkPolyData.New(); //vtkLine line = vtkLine.New(); //vtkCellArray cellArr = vtkCellArray.New(); ////描出边框 //for (int i = 0; i < 4; i++) //{ // line.GetPointIds().SetId(0, i); // line.GetPointIds().SetId(1, (i + 1) % 4); // cellArr.InsertNextCell(line); // line.GetPointIds().SetId(0, i + 4); // line.GetPointIds().SetId(1, (i + 1) % 4 + 4); // cellArr.InsertNextCell(line); // line.GetPointIds().SetId(0, i); // line.GetPointIds().SetId(1, 7 - i); // cellArr.InsertNextCell(line); //} //IntPtr iColor = Marshal.AllocHGlobal(bgColor.Length); //Marshal.Copy(bgColor, 0, iColor, bgColor.Length); //vtkUnsignedCharArray colors = vtkUnsignedCharArray.New(); //colors.SetNumberOfComponents(3); //for (int i = 0; i < cellArr.GetNumberOfCells(); i++) //{ // colors.InsertNextTupleValue(iColor); //} //pd.SetPoints(points); //pd.SetLines(cellArr); //pd.GetCellData().SetScalars(colors); //Marshal.FreeHGlobal(iColor); #endregion vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); //mapper.SetInput(pd); mapper.SetInputConnection(cs.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); actor.SetProperty(pp); actors.AddItem(actor); }