public void Read_MultiblockData_File(string filename) { vtkXMLMultiBlockDataReader reader = new vtkXMLMultiBlockDataReader(); reader.SetFileName(filename); reader.Update(); vtkMultiBlockDataSet data = (vtkMultiBlockDataSet)reader.GetOutput(); vtkInformation vtkInformation = data.GetMetaData(0); uint numBlocks = data.GetNumberOfBlocks(); if (numBlocks == 1) { vtkStructuredGrid structuredGrid = (vtkStructuredGrid)data.GetBlock(0); dimensions = structuredGrid.GetDimensions(); vtkPoints points = structuredGrid.GetPoints(); int numPoints = (int)structuredGrid.GetNumberOfPoints(); List <Vector3d> point_dat = new List <Vector3d>(); if (numPoints != 0) { // Read Point Data double[] pt; for (int i = 0; i < numPoints; i++) { pt = points.GetPoint(i); point_dat.Add(new Vector3d((float)pt[0], (float)pt[1], (float)pt[2])); } if (this.vertex_data.ContainsKey("vertices")) { this.vertex_data["vertices"] = point_dat; } else { this.vertex_data.Add("vertices", point_dat); } Console.WriteLine("All points read in correctly!"); } vtkPointData scalarValues = (vtkPointData)data.GetBlock(0).GetAttributes(0); // Load point attributes this.Load_Point_Attributes(scalarValues); } }
private static void MultiBlockMergeFilter() { vtkSphereSource sphereSource1 = vtkSphereSource.New(); sphereSource1.Update(); vtkSphereSource sphereSource2 = vtkSphereSource.New(); sphereSource2.SetCenter(10, 10, 10); sphereSource2.Update(); vtkMultiBlockDataSet multiBlockDataSet1 = vtkMultiBlockDataSet.New(); multiBlockDataSet1.SetNumberOfBlocks(1); multiBlockDataSet1.SetBlock(0, sphereSource1.GetOutput()); #if VTK_MAJOR_VERSION_5 multiBlockDataSet1.Update(); #endif vtkMultiBlockDataSet multiBlockDataSet2 = vtkMultiBlockDataSet.New(); multiBlockDataSet2.SetNumberOfBlocks(1); multiBlockDataSet2.SetBlock(0, sphereSource2.GetOutput()); #if VTK_MAJOR_VERSION_5 multiBlockDataSet2.Update(); #endif vtkMultiBlockMergeFilter multiBlockMergeFilter = vtkMultiBlockMergeFilter.New(); #if VTK_MAJOR_VERSION_5 multiBlockMergeFilter.AddInput(multiBlockDataSet1); multiBlockMergeFilter.AddInput(multiBlockDataSet2); #else multiBlockMergeFilter.AddInputData(multiBlockDataSet1); multiBlockMergeFilter.AddInputData(multiBlockDataSet2); #endif multiBlockMergeFilter.Update(); }
///<summary> A Set Method for Static Variables </summary> public static void Setmbds(vtkMultiBlockDataSet toSet) { mbds = toSet; }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestMultiBlockStreamer(String [] argv) { //Prefix Content is: "" // we need to use composite data pipeline with multiblock datasets[] alg = new vtkAlgorithm(); pip = new vtkCompositeDataPipeline(); vtkAlgorithm.SetDefaultExecutivePrototype((vtkExecutive)pip); //skipping Delete pip Ren1 = vtkRenderer.New(); Ren1.SetBackground((double)0.33, (double)0.35, (double)0.43); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)Ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); Plot3D0 = new vtkMultiBlockPLOT3DReader(); Plot3D0.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin"); Plot3D0.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin"); Plot3D0.SetBinaryFile((int)1); Plot3D0.SetMultiGrid((int)0); Plot3D0.SetHasByteCount((int)0); Plot3D0.SetIBlanking((int)0); Plot3D0.SetTwoDimensionalGeometry((int)0); Plot3D0.SetForceRead((int)0); Plot3D0.SetByteOrder((int)0); Plot3D0.Update(); Geometry5 = new vtkStructuredGridOutlineFilter(); Geometry5.SetInputData((vtkDataSet)Plot3D0.GetOutput().GetBlock(0)); Mapper5 = vtkPolyDataMapper.New(); Mapper5.SetInputConnection((vtkAlgorithmOutput)Geometry5.GetOutputPort()); Mapper5.SetImmediateModeRendering((int)1); Mapper5.UseLookupTableScalarRangeOn(); Mapper5.SetScalarVisibility((int)0); Mapper5.SetScalarModeToDefault(); Actor5 = new vtkActor(); Actor5.SetMapper((vtkMapper)Mapper5); Actor5.GetProperty().SetRepresentationToSurface(); Actor5.GetProperty().SetInterpolationToGouraud(); Actor5.GetProperty().SetAmbient((double)0.15); Actor5.GetProperty().SetDiffuse((double)0.85); Actor5.GetProperty().SetSpecular((double)0.1); Actor5.GetProperty().SetSpecularPower((double)100); Actor5.GetProperty().SetSpecularColor((double)1, (double)1, (double)1); Actor5.GetProperty().SetColor((double)1, (double)1, (double)1); Ren1.AddActor((vtkProp)Actor5); ExtractGrid[0] = new vtkExtractGrid(); ExtractGrid[0].SetInputData((vtkDataSet)Plot3D0.GetOutput().GetBlock(0)); ExtractGrid[0].SetVOI((int)0, (int)14, (int)0, (int)32, (int)0, (int)24); ExtractGrid[0].SetSampleRate((int)1, (int)1, (int)1); ExtractGrid[0].SetIncludeBoundary((int)0); ExtractGrid[1] = new vtkExtractGrid(); ExtractGrid[1].SetInputData((vtkDataSet)Plot3D0.GetOutput().GetBlock(0)); ExtractGrid[1].SetVOI((int)14, (int)29, (int)0, (int)32, (int)0, (int)24); ExtractGrid[1].SetSampleRate((int)1, (int)1, (int)1); ExtractGrid[1].SetIncludeBoundary((int)0); ExtractGrid[2] = new vtkExtractGrid(); ExtractGrid[2].SetInputData((vtkDataSet)Plot3D0.GetOutput().GetBlock(0)); ExtractGrid[2].SetVOI((int)29, (int)56, (int)0, (int)32, (int)0, (int)24); ExtractGrid[2].SetSampleRate((int)1, (int)1, (int)1); ExtractGrid[2].SetIncludeBoundary((int)0); LineSourceWidget0 = new vtkLineSource(); LineSourceWidget0.SetPoint1((double)3.05638, (double)-3.00497, (double)28.2211); LineSourceWidget0.SetPoint2((double)3.05638, (double)3.95916, (double)28.2211); LineSourceWidget0.SetResolution((int)20); mbds = new vtkMultiBlockDataSet(); mbds.SetNumberOfBlocks((uint)3); i = 0; while ((i) < 3) { ExtractGrid[i].Update(); sg[i] = vtkStructuredGrid.New(); sg[i].ShallowCopy(ExtractGrid[i].GetOutput()); mbds.SetBlock((uint)i, sg[i]); //skipping Delete sg[i] i = i + 1; } Stream0 = new vtkStreamTracer(); Stream0.SetInputData((vtkDataObject)mbds); Stream0.SetSourceConnection(LineSourceWidget0.GetOutputPort()); Stream0.SetIntegrationStepUnit(2); Stream0.SetMaximumPropagation((double)20); Stream0.SetInitialIntegrationStep((double)0.5); Stream0.SetIntegrationDirection((int)0); Stream0.SetIntegratorType((int)0); Stream0.SetMaximumNumberOfSteps((int)2000); Stream0.SetTerminalSpeed((double)1e-12); //skipping Delete mbds aa = new vtkAssignAttribute(); aa.SetInputConnection((vtkAlgorithmOutput)Stream0.GetOutputPort()); aa.Assign((string)"Normals", (string)"NORMALS", (string)"POINT_DATA"); Ribbon0 = new vtkRibbonFilter(); Ribbon0.SetInputConnection((vtkAlgorithmOutput)aa.GetOutputPort()); Ribbon0.SetWidth((double)0.1); Ribbon0.SetAngle((double)0); Ribbon0.SetDefaultNormal((double)0, (double)0, (double)1); Ribbon0.SetVaryWidth((int)0); LookupTable1 = new vtkLookupTable(); LookupTable1.SetNumberOfTableValues((int)256); LookupTable1.SetHueRange((double)0, (double)0.66667); LookupTable1.SetSaturationRange((double)1, (double)1); LookupTable1.SetValueRange((double)1, (double)1); LookupTable1.SetTableRange((double)0.197813, (double)0.710419); LookupTable1.SetVectorComponent((int)0); LookupTable1.Build(); Mapper10 = vtkPolyDataMapper.New(); Mapper10.SetInputConnection((vtkAlgorithmOutput)Ribbon0.GetOutputPort()); Mapper10.SetImmediateModeRendering((int)1); Mapper10.UseLookupTableScalarRangeOn(); Mapper10.SetScalarVisibility((int)1); Mapper10.SetScalarModeToUsePointFieldData(); Mapper10.SelectColorArray((string)"Density"); Mapper10.SetLookupTable((vtkScalarsToColors)LookupTable1); Actor10 = new vtkActor(); Actor10.SetMapper((vtkMapper)Mapper10); Actor10.GetProperty().SetRepresentationToSurface(); Actor10.GetProperty().SetInterpolationToGouraud(); Actor10.GetProperty().SetAmbient((double)0.15); Actor10.GetProperty().SetDiffuse((double)0.85); Actor10.GetProperty().SetSpecular((double)0); Actor10.GetProperty().SetSpecularPower((double)1); Actor10.GetProperty().SetSpecularColor((double)1, (double)1, (double)1); Ren1.AddActor((vtkProp)Actor10); // enable user interface interactor[] iren.Initialize(); // prevent the tk window from showing up then start the event loop[] vtkAlgorithm.SetDefaultExecutivePrototype(null); //skipping Delete alg //deleteAllVTKObjects(); }
public void WritSimpleVTM() { string filePath = "..\\..\\..\\..\\..\\03Daten\\testData\\simpleTest8Points.vtm"; vtkMultiBlockDataSet multiBlockDataSet = vtkMultiBlockDataSet.New(); multiBlockDataSet.SetNumberOfBlocks(2); vtkUnstructuredGrid unstructuredGrid1 = vtkUnstructuredGrid.New(); vtkPoints points1 = vtkPoints.New(); points1.InsertNextPoint(0, 0, 0); points1.InsertNextPoint(1, 0, 0); points1.InsertNextPoint(1, 1, 0); points1.InsertNextPoint(0, 1, 1); vtkPoints points2 = vtkPoints.New(); points1.InsertNextPoint(2, 0, 0); points1.InsertNextPoint(2, 2, 0); points1.InsertNextPoint(2, 2, 3); points1.InsertNextPoint(0, 2, 3); vtkTetra tetra = vtkTetra.New(); tetra.GetPointIds().SetId(0, 0); tetra.GetPointIds().SetId(1, 1); tetra.GetPointIds().SetId(2, 2); tetra.GetPointIds().SetId(3, 3); vtkCellArray cellArray1 = vtkCellArray.New(); cellArray1.InsertNextCell(tetra); unstructuredGrid1.SetPoints(points1); const int VTK_TETRA = 10; unstructuredGrid1.SetCells(VTK_TETRA, cellArray1); vtkCellArray cellArray2 = vtkCellArray.New(); tetra = vtkTetra.New(); tetra.GetPointIds().SetId(0, 4); tetra.GetPointIds().SetId(1, 5); tetra.GetPointIds().SetId(2, 6); tetra.GetPointIds().SetId(3, 7); cellArray2.InsertNextCell(tetra); tetra = vtkTetra.New(); tetra.GetPointIds().SetId(0, 7); tetra.GetPointIds().SetId(1, 5); tetra.GetPointIds().SetId(2, 2); tetra.GetPointIds().SetId(3, 4); cellArray2.InsertNextCell(tetra); vtkUnstructuredGrid unstructuredGrid = vtkUnstructuredGrid.New(); unstructuredGrid.SetPoints(points1); unstructuredGrid.SetCells(VTK_TETRA, cellArray2); multiBlockDataSet.SetBlock(0, unstructuredGrid1); multiBlockDataSet.SetBlock(1, unstructuredGrid); // Write file vtkXMLMultiBlockDataWriter writer = vtkXMLMultiBlockDataWriter.New(); writer.SetFileName(filePath); writer.SetInput(multiBlockDataSet); writer.Write(); }
public void WriteVTM(string filePath, List <Vector3d> point_data, List <Vector4> tetrapoints, Dictionary <String, vtkDataArray> scalar_dataArray, List <String> arrayNames, int numberOfPoints, int numberOfTetraPoints) { vtkPoints points = vtkPoints.New(); for (int i = 0; i < numberOfPoints; i++) { points.InsertNextPoint(point_data[i].X, point_data[i].Y, point_data[i].Z); } vtkMultiBlockDataSet multiBlockDataSet = vtkMultiBlockDataSet.New(); double countBlocks = Math.Ceiling((double)((1.0 * numberOfTetraPoints) / 1000000)); multiBlockDataSet.SetNumberOfBlocks((uint)1); for (int j = 0; j < 1; j++) { vtkUnstructuredGrid unstructuredGrid = vtkUnstructuredGrid.New(); vtkCellArray cellArrayOne = vtkCellArray.New(); int countTetras = 0; int startTetras = j * 1000000; if (numberOfTetraPoints < (j * 1000000) + 1000000) { countTetras = numberOfTetraPoints; } else { countTetras = (j * 1000000) + 1000000; } for (int i = startTetras; i < tetrapoints.Count(); i++) { vtkTetra tetra = vtkTetra.New(); tetra.GetPointIds().SetId(0, (long)tetrapoints[i][0]); tetra.GetPointIds().SetId(1, (long)tetrapoints[i][1]); tetra.GetPointIds().SetId(2, (long)tetrapoints[i][2]); tetra.GetPointIds().SetId(3, (long)tetrapoints[i][3]); cellArrayOne.InsertNextCell(tetra); } //for (int i = 0; i < tetrapoints2.Count(); i++) //{ // vtkTetra tetra = vtkTetra.New(); // tetra.GetPointIds().SetId(0, (long)tetrapoints2[i][0]); // tetra.GetPointIds().SetId(1, (long)tetrapoints2[i][1]); // tetra.GetPointIds().SetId(2, (long)tetrapoints2[i][2]); // tetra.GetPointIds().SetId(3, (long)tetrapoints2[i][3]); // cellArrayOne.InsertNextCell(tetra); //} unstructuredGrid.SetPoints(points); const int VTK_TETRA = 10; unstructuredGrid.SetCells(VTK_TETRA, cellArrayOne); int numberOfScalarData = scalar_dataArray.Count(); for (int i = 0; i < numberOfScalarData; i++) { scalar_dataArray.TryGetValue(arrayNames[i], out vtkDataArray scalars); unstructuredGrid.GetPointData().AddArray(scalars); } multiBlockDataSet.SetBlock((uint)j, unstructuredGrid); } // add file ending if it is not existent string suffix = (".vtm"); if (!(filePath.EndsWith(suffix))) { filePath += suffix; } // Write file vtkXMLMultiBlockDataWriter writer = vtkXMLMultiBlockDataWriter.New(); writer.SetFileName(filePath); writer.SetInput(multiBlockDataSet); writer.Write(); // Read and display file for verification that it was written correctly vtkXMLMultiBlockDataReader reader = vtkXMLMultiBlockDataReader.New(); if (reader.CanReadFile(filePath) == 0) { //MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK); return; } Console.WriteLine("VTU file was writen and is saved at {0}", filePath); }
/// <summary> /// The main entry method called by the CSharp driver /// </summary> /// <param name="argv"></param> public static void AVTestMultiBlockStreamer(String [] argv) { //Prefix Content is: "" // we need to use composite data pipeline with multiblock datasets[] alg = new vtkAlgorithm(); pip = new vtkCompositeDataPipeline(); vtkAlgorithm.SetDefaultExecutivePrototype((vtkExecutive)pip); //skipping Delete pip Ren1 = vtkRenderer.New(); Ren1.SetBackground((double)0.33,(double)0.35,(double)0.43); renWin = vtkRenderWindow.New(); renWin.AddRenderer((vtkRenderer)Ren1); iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow((vtkRenderWindow)renWin); Plot3D0 = new vtkPLOT3DReader(); Plot3D0.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin"); Plot3D0.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin"); Plot3D0.SetBinaryFile((int)1); Plot3D0.SetMultiGrid((int)0); Plot3D0.SetHasByteCount((int)0); Plot3D0.SetIBlanking((int)0); Plot3D0.SetTwoDimensionalGeometry((int)0); Plot3D0.SetForceRead((int)0); Plot3D0.SetByteOrder((int)0); Geometry5 = new vtkStructuredGridOutlineFilter(); Geometry5.SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort()); Mapper5 = vtkPolyDataMapper.New(); Mapper5.SetInputConnection((vtkAlgorithmOutput)Geometry5.GetOutputPort()); Mapper5.SetImmediateModeRendering((int)1); Mapper5.UseLookupTableScalarRangeOn(); Mapper5.SetScalarVisibility((int)0); Mapper5.SetScalarModeToDefault(); Actor5 = new vtkActor(); Actor5.SetMapper((vtkMapper)Mapper5); Actor5.GetProperty().SetRepresentationToSurface(); Actor5.GetProperty().SetInterpolationToGouraud(); Actor5.GetProperty().SetAmbient((double)0.15); Actor5.GetProperty().SetDiffuse((double)0.85); Actor5.GetProperty().SetSpecular((double)0.1); Actor5.GetProperty().SetSpecularPower((double)100); Actor5.GetProperty().SetSpecularColor((double)1,(double)1,(double)1); Actor5.GetProperty().SetColor((double)1,(double)1,(double)1); Ren1.AddActor((vtkProp)Actor5); ExtractGrid[0] = new vtkExtractGrid(); ExtractGrid[0].SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort()); ExtractGrid[0].SetVOI((int)0,(int)14,(int)0,(int)32,(int)0,(int)24); ExtractGrid[0].SetSampleRate((int)1,(int)1,(int)1); ExtractGrid[0].SetIncludeBoundary((int)0); ExtractGrid[1] = new vtkExtractGrid(); ExtractGrid[1].SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort()); ExtractGrid[1].SetVOI((int)14,(int)29,(int)0,(int)32,(int)0,(int)24); ExtractGrid[1].SetSampleRate((int)1,(int)1,(int)1); ExtractGrid[1].SetIncludeBoundary((int)0); ExtractGrid[2] = new vtkExtractGrid(); ExtractGrid[2].SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort()); ExtractGrid[2].SetVOI((int)29,(int)56,(int)0,(int)32,(int)0,(int)24); ExtractGrid[2].SetSampleRate((int)1,(int)1,(int)1); ExtractGrid[2].SetIncludeBoundary((int)0); LineSourceWidget0 = new vtkLineSource(); LineSourceWidget0.SetPoint1((double)3.05638,(double)-3.00497,(double)28.2211); LineSourceWidget0.SetPoint2((double)3.05638,(double)3.95916,(double)28.2211); LineSourceWidget0.SetResolution((int)20); mbds = new vtkMultiBlockDataSet(); mbds.SetNumberOfBlocks((uint)3); i = 0; while((i) < 3) { ExtractGrid[i].Update(); sg[i] = vtkStructuredGrid.New(); sg[i].ShallowCopy(ExtractGrid[i].GetOutput()); mbds.SetBlock((uint)i, sg[i]); //skipping Delete sg[i] i = i + 1; } Stream0 = new vtkStreamTracer(); Stream0.SetInput((vtkDataObject)mbds); Stream0.SetSource((vtkDataSet)LineSourceWidget0.GetOutput()); Stream0.SetIntegrationStepUnit(2); Stream0.SetMaximumPropagation((double)20); Stream0.SetInitialIntegrationStep((double)0.5); Stream0.SetIntegrationDirection((int)0); Stream0.SetIntegratorType((int)0); Stream0.SetMaximumNumberOfSteps((int)2000); Stream0.SetTerminalSpeed((double)1e-12); //skipping Delete mbds aa = new vtkAssignAttribute(); aa.SetInputConnection((vtkAlgorithmOutput)Stream0.GetOutputPort()); aa.Assign((string)"Normals",(string)"NORMALS",(string)"POINT_DATA"); Ribbon0 = new vtkRibbonFilter(); Ribbon0.SetInputConnection((vtkAlgorithmOutput)aa.GetOutputPort()); Ribbon0.SetWidth((double)0.1); Ribbon0.SetAngle((double)0); Ribbon0.SetDefaultNormal((double)0,(double)0,(double)1); Ribbon0.SetVaryWidth((int)0); LookupTable1 = new vtkLookupTable(); LookupTable1.SetNumberOfTableValues((int)256); LookupTable1.SetHueRange((double)0,(double)0.66667); LookupTable1.SetSaturationRange((double)1,(double)1); LookupTable1.SetValueRange((double)1,(double)1); LookupTable1.SetTableRange((double)0.197813,(double)0.710419); LookupTable1.SetVectorComponent((int)0); LookupTable1.Build(); Mapper10 = vtkPolyDataMapper.New(); Mapper10.SetInputConnection((vtkAlgorithmOutput)Ribbon0.GetOutputPort()); Mapper10.SetImmediateModeRendering((int)1); Mapper10.UseLookupTableScalarRangeOn(); Mapper10.SetScalarVisibility((int)1); Mapper10.SetScalarModeToUsePointFieldData(); Mapper10.SelectColorArray((string)"Density"); Mapper10.SetLookupTable((vtkScalarsToColors)LookupTable1); Actor10 = new vtkActor(); Actor10.SetMapper((vtkMapper)Mapper10); Actor10.GetProperty().SetRepresentationToSurface(); Actor10.GetProperty().SetInterpolationToGouraud(); Actor10.GetProperty().SetAmbient((double)0.15); Actor10.GetProperty().SetDiffuse((double)0.85); Actor10.GetProperty().SetSpecular((double)0); Actor10.GetProperty().SetSpecularPower((double)1); Actor10.GetProperty().SetSpecularColor((double)1,(double)1,(double)1); Ren1.AddActor((vtkProp)Actor10); // enable user interface interactor[] iren.Initialize(); // prevent the tk window from showing up then start the event loop[] vtkAlgorithm.SetDefaultExecutivePrototype(null); //skipping Delete alg //deleteAllVTKObjects(); }
///<summary> A Set Method for Static Variables </summary> public static void Setmbds(vtkMultiBlockDataSet toSet) { mbds = toSet; }