public void ExtractEdgesVTKBuilderWithoutRunning(ref vtkActor actor, ref vtkPoints points, ref vtkCellArray polys, ref vtkFloatArray scalars, ref vtkLookupTable Luk) { int pointsNum = 0; TowerModelInstance.VTKDrawModel(ref points, ref polys, ref scalars, ref pointsNum, paras); vtkPolyData profile = vtkPolyData.New(); profile.SetPoints(points); profile.SetPolys(polys); vtkExtractEdges ExtProfile = new vtkExtractEdges(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); if (paras.RotateAngle == 0) { profile.GetCellData().SetScalars(scalars); ExtProfile.SetInput(profile); mapper.SetInputConnection(ExtProfile.GetOutputPort()); } else { vtkRotationalExtrusionFilter refilter = vtkRotationalExtrusionFilter.New(); profile.Update(); profile.GetCellData().SetScalars(scalars); //profile.GetPointData().SetScalars(scalars); ExtProfile.SetInput(profile); refilter.SetInputConnection(ExtProfile.GetOutputPort()); refilter.SetResolution(50); refilter.SetAngle(paras.RotateAngle); refilter.SetTranslation(0); refilter.SetDeltaRadius(0); mapper.SetInputConnection(refilter.GetOutputPort()); } mapper.SetScalarRange(0, 5); mapper.SetLookupTable(Luk); actor.SetMapper(mapper); Luk.SetNumberOfTableValues(7); Luk.SetTableValue(0, 0, 1, 0, 1); // Luk.SetTableValue(1, 0, 0, 0.8, 1); //inner surface Luk.SetTableValue(2, 0, 1, 0, 1); // Luk.SetTableValue(3, 0, 0, 1, 1); Luk.SetTableValue(4, 0, 0, 0.8, 1); //insider Luk.SetTableValue(5, 0, 0.8, 0, 1); //outer surface Luk.Build(); }
private static void FindAllData(ref vtkPolyData polydata) { Console.WriteLine("Normals: " + polydata.GetPointData().GetNormals()); int numberOfPointArrays = polydata.GetPointData().GetNumberOfArrays(); Console.WriteLine("Number of PointData arrays: " + numberOfPointArrays); int numberOfCellArrays = polydata.GetCellData().GetNumberOfArrays(); Console.WriteLine("Number of CellData arrays: " + numberOfCellArrays); Console.WriteLine( Environment.NewLine + "Type table/key: " + Environment.NewLine + "-------------------------"); //more values can be found in <VTK_DIR>/Common/vtkSetGet.h Console.WriteLine(3 + " unsigned char"); Console.WriteLine(7 + " unsigned int"); Console.WriteLine(10 + " float"); Console.WriteLine(11 + " double" + Environment.NewLine); for (int i = 0; i < numberOfPointArrays; i++) { // The following two lines are equivalent //arrayNames.push_back(polydata.GetPointData().GetArray(i).GetName()); //arrayNames.push_back(polydata.GetPointData().GetArrayName(i)); int dataTypeID = polydata.GetPointData().GetArray(i).GetDataType(); string dataTypeAsString = polydata.GetPointData().GetArray(i).GetDataTypeAsString(); Console.WriteLine("Array " + i + ": " + polydata.GetPointData().GetArrayName(i) + " (type: " + dataTypeID + ")" + " (type as string: " + dataTypeAsString + ")" + Environment.NewLine); } for (int i = 0; i < numberOfCellArrays; i++) { // The following two lines are equivalent //polydata.GetPointData().GetArray(i).GetName(); //polydata.GetPointData().GetArrayName(i); int dataTypeID = polydata.GetCellData().GetArray(i).GetDataType(); string dataTypeAsString = polydata.GetPointData().GetArray(i).GetDataTypeAsString(); Console.WriteLine("Array " + i + ": " + polydata.GetCellData().GetArrayName(i) + " (type: " + dataTypeID + ")" + " (type as string: " + dataTypeAsString + ")"); } }
private static void FindAllData(ref vtkPolyData polydata) { Console.WriteLine("Normals: " + polydata.GetPointData().GetNormals()); int numberOfPointArrays = polydata.GetPointData().GetNumberOfArrays(); Console.WriteLine("Number of PointData arrays: " + numberOfPointArrays); int numberOfCellArrays = polydata.GetCellData().GetNumberOfArrays(); Console.WriteLine("Number of CellData arrays: " + numberOfCellArrays); Console.WriteLine( Environment.NewLine + "Type table/key: " + Environment.NewLine + "-------------------------"); //more values can be found in <VTK_DIR>/Common/vtkSetGet.h Console.WriteLine(3 + " unsigned char"); Console.WriteLine(7 + " unsigned int"); Console.WriteLine(10 + " float"); Console.WriteLine(11 + " double" + Environment.NewLine); for(int i = 0; i < numberOfPointArrays; i++) { // The following two lines are equivalent //arrayNames.push_back(polydata.GetPointData().GetArray(i).GetName()); //arrayNames.push_back(polydata.GetPointData().GetArrayName(i)); int dataTypeID = polydata.GetPointData().GetArray(i).GetDataType(); string dataTypeAsString = polydata.GetPointData().GetArray(i).GetDataTypeAsString(); Console.WriteLine("Array " + i + ": " + polydata.GetPointData().GetArrayName(i) + " (type: " + dataTypeID + ")" + " (type as string: " + dataTypeAsString + ")" + Environment.NewLine); } for(int i = 0; i < numberOfCellArrays; i++) { // The following two lines are equivalent //polydata.GetPointData().GetArray(i).GetName(); //polydata.GetPointData().GetArrayName(i); int dataTypeID = polydata.GetCellData().GetArray(i).GetDataType(); string dataTypeAsString = polydata.GetPointData().GetArray(i).GetDataTypeAsString(); Console.WriteLine("Array " + i + ": " + polydata.GetCellData().GetArrayName(i) + " (type: " + dataTypeID + ")" + " (type as string: " + dataTypeAsString + ")"); } }
private void ColoredLines() { // Create three points. Join (Origin and P0) with a red line and // (Origin and P1) with a green line double[] origin = new double[] { 0.0, 0.0, 0.0 }; double[] p0 = new double[] { 1.0, 0.0, 0.0 }; double[] p1 = new double[] { 0.0, 1.0, 0.0 }; // Create a vtkPoints object and store the points in it vtkPoints pts = vtkPoints.New(); pts.InsertNextPoint(origin[0], origin[1], origin[2]); pts.InsertNextPoint(p0[0], p0[1], p0[2]); pts.InsertNextPoint(p1[0], p1[1], p1[2]); // Setup two colors - one for each line byte[] red = new byte[] { 255, 0, 0 }; byte[] green = new byte[] { 0, 255, 0 }; // Setup the colors array vtkUnsignedCharArray colors = vtkUnsignedCharArray.New(); colors.SetNumberOfComponents(3); colors.SetName("Colors"); // Add the colors we created to the colors array colors.InsertNextValue(red[0]); colors.InsertNextValue(red[1]); colors.InsertNextValue(red[2]); colors.InsertNextValue(green[0]); colors.InsertNextValue(green[1]); colors.InsertNextValue(green[2]); // Create the first line (between Origin and P0) vtkLine line0 = vtkLine.New(); line0.GetPointIds().SetId(0, 0); //the second 0 is the index of the Origin in the vtkPoints line0.GetPointIds().SetId(1, 1); //the second 1 is the index of P0 in the vtkPoints // Create the second line (between Origin and P1) vtkLine line1 = vtkLine.New(); line1.GetPointIds().SetId(0, 0); //the second 0 is the index of the Origin in the vtkPoints line1.GetPointIds().SetId(1, 2); //2 is the index of P1 in the vtkPoints // Create a cell array to store the lines in and add the lines to it vtkCellArray lines = vtkCellArray.New(); lines.InsertNextCell(line0); lines.InsertNextCell(line1); // Create a polydata to store everything in vtkPolyData linesPolyData = vtkPolyData.New(); // Add the points to the dataset linesPolyData.SetPoints(pts); // Add the lines to the dataset linesPolyData.SetLines(lines); // Color the lines - associate the first component (red) of the // colors array with the first component of the cell array (line 0) // and the second component (green) of the colors array with the // second component of the cell array (line 1) linesPolyData.GetCellData().SetScalars(colors); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInput(linesPolyData); // create an actor vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); RenderAddActor(actor); }
//Parameters for building a model private void BasicVTKBuilder(ref vtkActor actor, ref vtkPoints points, ref vtkCellArray polys, ref vtkFloatArray scalars, ref vtkLookupTable Luk, ref vtkActor2D actor2D) { int pointsNum = 0; TowerModelInstance.VTKDrawModel(ref points, ref polys, ref scalars, ref pointsNum, paras); vtkPolyData profile = vtkPolyData.New(); profile.SetPoints(points); profile.SetPolys(polys); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); if (paras.RotateAngle == 0) { profile.GetCellData().SetScalars(scalars); mapper.SetInput(profile); } else { vtkRotationalExtrusionFilter refilter = vtkRotationalExtrusionFilter.New(); profile.Update(); profile.GetCellData().SetScalars(scalars); //profile.GetPointData().SetScalars(scalars); refilter.SetInput(profile); refilter.SetResolution(50); refilter.SetAngle(paras.RotateAngle); refilter.SetTranslation(0); refilter.SetDeltaRadius(0); mapper.SetInputConnection(refilter.GetOutputPort()); } mapper.SetScalarRange(TowerModelInstance.GetColorGenColorTableMinvalue(), TowerModelInstance.GetColorGenColorTableMaxValue()); actor.SetMapper(mapper); // This text property is for scalarBar vtkTextProperty textProperty = vtkTextProperty.New(); //textProperty.SetFontFamilyToCourier(); //textProperty.SetColor(1.0, 1.0, 0.5); textProperty.SetFontSize(10); vtkScalarBarActor scalarBar = vtkScalarBarActor.New(); scalarBar.SetLookupTable(mapper.GetLookupTable()); scalarBar.SetTitle("Color Table"); scalarBar.SetNumberOfLabels(TowerModelInstance.GetColorGenColorTableSize()); scalarBar.SetTitleTextProperty(textProperty); scalarBar.SetLabelTextProperty(textProperty); scalarBar.SetWidth(0.07); scalarBar.SetHeight(0.6); //scalarBar.SetDrawFrame(1); vtkLookupTable hueLut = vtkLookupTable.New(); hueLut.SetTableRange(TowerModelInstance.GetColorGenColorTableMinvalue(), TowerModelInstance.GetColorGenColorTableMaxValue()); hueLut.SetHueRange(0.667, 0); hueLut.SetSaturationRange(1, 1); hueLut.SetValueRange(1, 1); hueLut.SetNumberOfTableValues(TowerModelInstance.GetColorGenColorTableSize()); hueLut.Build(); mapper.SetLookupTable(hueLut); scalarBar.SetLookupTable(hueLut); // The actor links the data pipeline to the rendering subsystem actor2D = scalarBar; //actor.GetProperty().SetColor(0.388, 0.388, 0.388); }