vtk中将数组赋值给imagedata

    vtkDataArray* temparr = input->GetPointData()->GetScalars();
    int datasize = 512*512*50;
    double* testshortarr = new double[datasize];
    for(int i=0; i<datasize; i++){
        testshortarr[i] = temparr->GetComponent(i,0);
    }

    vtkDoubleArray* tempimarr2 = vtkDoubleArray::New();
    tempimarr2->SetVoidArray(testshortarr,datasize,1);
//    temparr->GetData(0,datasize-1,0,0,tempimarr2);
    vtkImageData* testimdata = vtkImageData::New();
    testimdata->SetDimensions(512,512,50);
    testimdata->SetSpacing(spacing);
    testimdata->GetPointData()->SetScalars(tempimarr2);
    testimdata->Modified();

你可能感兴趣的:(VTK)