level 1
Issac✆
楼主
在同一个渲染窗口,第一次显示可以正常显示,但是切换到其他路径的文件或者打开同一个文件去渲染的时候,vtk会报unable to allocate的错误,请问我这个功能应该怎样实现?目前报错代码如下:
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
try
{
vP.Reset();
PointCloudHead Pchead;
Pchead._height = 0;
Pchead._width = 0;
Pchead._xInterval = 0;
Pchead._yInterval = 0;
string path = openFileDialog1.FileName;
char[] ch = path.ToCharArray();
readECD_pSize(ch, ref Pchead);
int[] data = new int[Pchead._height * Pchead._width];
readECD_ExternSize(ch, data, ref Pchead);
//Create a vtkPoints. A pipeline is created.
//vtkPoints vP = vtkPoints.New();
int n = 0;
double x = 0;
double y = 0;
double z = 0;
for (int i = 0; i < Pchead._height; ++i)
{
for (int j = 0; j < Pchead._width; ++j)
{
x = (double)j * Pchead._xInterval;
y = (double)i * Pchead._yInterval;
if (data[i * Pchead._width + j] < -99000000)
z = 0.0 / 0.0;
else
z = data[i * Pchead._width + j] / 100000.0;
vP.InsertPoint(n, x, y, z);
n++;
}
}
vtkPolyVertex polyvertex = vtkPolyVertex.New();
polyvertex.GetPointIds().SetNumberOfIds(n);
int num = 0; //建立拓扑关系
for (num = 0; num < n; num++)
{
polyvertex.GetPointIds().SetId(num, num);
}
vtkUnstructuredGrid grid = vtkUnstructuredGrid.New();
grid.SetPoints(vP);
grid.InsertNextCell(polyvertex.GetCellType(), polyvertex.GetPointIds());
vtkDataSetMapper mapper = vtkDataSetMapper.New();
mapper.SetInput(grid);
//The actor links the data pipeline to the rendering subsystem
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
actor.GetProperty().SetColor(1, 0, 0);
//Create components of the rendering subsystem
//renderWindowControl1作为输入来显示
//Add the actors to the renderer, set the window size
renderer.AddViewProp(actor);
}
catch (Exception)
{
}
}
2020年01月02日 08点01分
1
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
try
{
vP.Reset();
PointCloudHead Pchead;
Pchead._height = 0;
Pchead._width = 0;
Pchead._xInterval = 0;
Pchead._yInterval = 0;
string path = openFileDialog1.FileName;
char[] ch = path.ToCharArray();
readECD_pSize(ch, ref Pchead);
int[] data = new int[Pchead._height * Pchead._width];
readECD_ExternSize(ch, data, ref Pchead);
//Create a vtkPoints. A pipeline is created.
//vtkPoints vP = vtkPoints.New();
int n = 0;
double x = 0;
double y = 0;
double z = 0;
for (int i = 0; i < Pchead._height; ++i)
{
for (int j = 0; j < Pchead._width; ++j)
{
x = (double)j * Pchead._xInterval;
y = (double)i * Pchead._yInterval;
if (data[i * Pchead._width + j] < -99000000)
z = 0.0 / 0.0;
else
z = data[i * Pchead._width + j] / 100000.0;
vP.InsertPoint(n, x, y, z);
n++;
}
}
vtkPolyVertex polyvertex = vtkPolyVertex.New();
polyvertex.GetPointIds().SetNumberOfIds(n);
int num = 0; //建立拓扑关系
for (num = 0; num < n; num++)
{
polyvertex.GetPointIds().SetId(num, num);
}
vtkUnstructuredGrid grid = vtkUnstructuredGrid.New();
grid.SetPoints(vP);
grid.InsertNextCell(polyvertex.GetCellType(), polyvertex.GetPointIds());
vtkDataSetMapper mapper = vtkDataSetMapper.New();
mapper.SetInput(grid);
//The actor links the data pipeline to the rendering subsystem
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
actor.GetProperty().SetColor(1, 0, 0);
//Create components of the rendering subsystem
//renderWindowControl1作为输入来显示
//Add the actors to the renderer, set the window size
renderer.AddViewProp(actor);
}
catch (Exception)
{
}
}