[vtkusers] Visualize 3D image (.mhd)
Bill Lorensen
bill.lorensen at gmail.com
Mon Jul 12 07:58:58 EDT 2010
Updates are usually done on the filters, not the outpus of the filter.Try:
reader->Update();
and
caster->Update();
On Mon, Jul 12, 2010 at 7:08 AM, Urvoas, Paul <paul.urvoas at philips.com> wrote:
> Hi,
>
> I would like to visualize 3d mhd image with VTK, thanks to another program,
> I wrote the following code.
>
> It crashes just after cout<<”caster ok” and I don’t find my mistakes.
>
>
>
> Thanks in advance,
>
> Paul
>
>
>
>
>
> int main(int argc, char* argv)
>
> {
>
>
>
> vtkImageData** ImageOriginale = new vtkImageData*[10];
>
>
>
> vtkViewImage3D* view;
>
>
>
> cout << "start" <<endl;
>
>
>
> vtkMetaImageReader* reader = vtkMetaImageReader::New();
>
> reader->SetFileName ("Synthetic-04.mhd");
>
> reader->GetOutput()->Update();
>
> cout << "reader ok" <<endl;
>
>
>
> vtkImageCast* caster = vtkImageCast::New();
>
> caster->SetInput (reader->GetOutput());
>
> caster->SetOutputScalarTypeToUnsignedShort ();
>
> caster->GetOutput()->Update();
>
>
>
> cout << "caster ok" <<endl;
>
>
>
> ImageOriginale[0]->DeepCopy(caster->GetOutput()) ;
>
>
>
> cout << "Copy volume to ImageOriaginale" <<endl;
>
>
>
> caster->Delete();
>
> reader->Delete();
>
>
>
> cout << "reader caster deleted" <<endl;
>
>
>
> int dims[3];
>
> ImageOriginale[0]->GetDimensions(dims);
>
> double spacing[3];
>
> ImageOriginale[0]->GetSpacing(spacing);
>
> cout << "spacing & dimension" <<endl;
>
>
>
>
>
> view->SetImage(ImageOriginale[0]);
>
>
>
> view->SetRenderingModeToVR();
>
> view->SetVolumeRayCastFunctionToMIP();
>
>
>
> vtkRenderer *ren = vtkRenderer::New();
>
> vtkRenderWindow *renWin = vtkRenderWindow::New();
>
> renWin->AddRenderer(ren);
>
> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>
> iren->SetRenderWindow(renWin);
>
>
>
>
>
> view->SetImage (ImageOriginale[0]);
>
> view->SetRenderingModeToVR();
>
> view->SetVolumeRayCastFunctionToMIP();
>
>
>
> cout << "befor render" <<endl;
>
> renWin->Render();
>
>
>
> }
>
> ________________________________
> The information contained in this message may be confidential and legally
> protected under applicable law. The message is intended solely for the
> addressee(s). If you are not the intended recipient, you are hereby notified
> that any use, forwarding, dissemination, or reproduction of this message is
> strictly prohibited and may be unlawful. If you are not the intended
> recipient, please contact the sender by return e-mail and destroy all copies
> of the original message.
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
More information about the vtkusers
mailing list