[vtkusers] Visualize 3D image (.mhd)

Martijn Steenwijk martijnsteenwijk at gmail.com
Mon Jul 12 08:55:15 EDT 2010


It is. Sorry, the s from set should be capitalized:
->SetFileDimensionality(int)

http://www.vtk.org/doc/release/5.0/html/a00777.html

Best,
Martijn

---
Martijn Steenwijk
T 06 20693913
E martijnsteenwijk at gmail.com


-----Original Message-----
From: Urvoas, Paul [mailto:paul.urvoas at philips.com] 
Sent: maandag 12 juli 2010 14:37
To: martijnsteenwijk at gmail.com
Cc: vtkusers at vtk.org
Subject: RE: [vtkusers] Visualize 3D image (.mhd)

Ok but reader is an object from the class vtkMetaImageReader, and
setFileDimensionality is not a function from this class.
Regards,
Paul

('setFileDimensionality' : is not a member of 'vtkMetaImageReader')

-----Original Message-----
From: Martijn Steenwijk [mailto:martijnsteenwijk at gmail.com]
Sent: 2010 Jul 12 2:29 PM
To: Urvoas, Paul
Cc: vtkusers at vtk.org
Subject: RE: [vtkusers] Visualize 3D image (.mhd)

Try

reader->setFileDimensionality(3)

Best,
Martijn

---
Martijn Steenwijk
T 06 20693913
E martijnsteenwijk at gmail.com


-----Original Message-----
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf
Of Urvoas, Paul
Sent: maandag 12 juli 2010 14:21
To: Bill Lorensen
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] Visualize 3D image (.mhd)

It change anything.
I have just found a program to read Meta Image. But I get the following
error (during the execution):

NDims required and not defined.
MetaObject: Read: MET_Read Failed
MetaImage: M_Read: Error parsing file
MetaImage: Read: Cannot parse file
NDims required and not defined.
MetaObject: Read: MET_Read Failed
MetaImage: M_Read: Error parsing file
MetaImage: Read: Cannot parse file

My input is of course a 3d mhd file...

Thanks in advance,
Paul





This is the program I am trying to use:

int main( int argc, char * argv[] )
{

        char * in_file_name  = argv[1];
        char * out_file_name = argv[2];

  // View up
  double vux = atof(     argv[3] );
        double vuy = atof(     argv[4] );
        double vuz = atof(     argv[5] );

  // Camera position direction from fp
  double px  = atof(     argv[6] );
        double py  = atof(     argv[7] );
        double pz  = atof(     argv[8] );

  // MIP or not
  int    mip = atoi(     argv[9] );

  // Focal point set to center.
  double fpx;
        double fpy;
        double fpz;


        // Graphics Factory
        vtkGraphicsFactory * graphics_factory
                = vtkGraphicsFactory::New();
        graphics_factory->SetOffScreenOnlyMode( 1);
        graphics_factory->SetUseMesaClasses( 1 );

        // Imaging Factory
        vtkImagingFactory * imaging_factory
                = vtkImagingFactory::New();
        imaging_factory->SetUseMesaClasses( 1 );

        // Image Reader
        //vtkXMLImageDataReader * reader
        //      = vtkXMLImageDataReader::New();
  vtkMetaImageReader * reader  = vtkMetaImageReader::New();
        reader->SetFileName( in_file_name );
  reader->ReleaseDataFlagOn();

        // Get center
        reader->Update();
        vtkImageData * image = reader->GetOutput();
        double * image_spacing = image->GetSpacing();
        double * image_origin = image->GetOrigin();
        int * whole_extent = image->GetWholeExtent();
        int image_dim[3];
        image_dim[0] = whole_extent[1] + 1;
        image_dim[1] = whole_extent[3] + 1;
        image_dim[2] = whole_extent[5] + 1;
        fpx = image_origin[0]
                + image_dim[0] / 2 * image_spacing[0];
        fpy = image_origin[1]
                + image_dim[1] / 2 * image_spacing[1];
        fpz = image_origin[2]
                + image_dim[2] / 2 * image_spacing[2];

        // Opacity
        vtkPiecewiseFunction * opacity
                = vtkPiecewiseFunction::New();
  opacity->AddPoint(   0, 0.0 );
        opacity->AddPoint( 255, 0.8 );
  opacity->AddPoint( 256, 0.0 );
  opacity->AddPoint( 511, 0.8 );
  opacity->AddPoint( 512, 0.0 );
  opacity->AddPoint( 767, 1.0 );

        // Color
        vtkColorTransferFunction * color
                = vtkColorTransferFunction::New();
  color->AddRGBPoint( 0,   1.0, 0.0, 0.0 );
        color->AddRGBPoint( 255, 1.0, 0.0, 0.0 );
  color->AddRGBPoint( 256, 0.0, 1.0, 0.0 );
        color->AddRGBPoint( 511, 0.0, 1.0, 0.0 );
  color->AddRGBPoint( 512, 1.0, 1.0, 0.0 );
        color->AddRGBPoint( 767, 1.0, 1.0, 0.0 );

        // Volume Property
        vtkVolumeProperty * vol_prop = vtkVolumeProperty::New();
        vol_prop->SetColor( color );
  if ( mip == 0 )
    {
    vol_prop->SetScalarOpacity( opacity );
    }
  //vol_prop->SetInterpolationTypeToLinear();
  vol_prop->SetInterpolationTypeToNearest();

        // Mapper
        vtkFixedPointVolumeRayCastMapper * mapper
                = vtkFixedPointVolumeRayCastMapper::New();
  if ( mip == 0 )
    {
    mapper->SetBlendModeToComposite();
    }
  else
    {
    mapper->SetBlendModeToMaximumIntensity();
    }
        mapper->SetInputConnection( reader->GetOutputPort() );

        // Volume
        vtkVolume * volume = vtkVolume::New();
        volume->SetMapper( mapper );
        volume->SetProperty( vol_prop );

        // Camera
        vtkCamera * camera = vtkCamera::New();
  camera->ParallelProjectionOn();
        camera->SetViewUp (vux, vuy, vuz);
        camera->SetPosition (
                        fpx + px,
                        fpy + py,
                        fpz + pz );
        camera->SetFocalPoint (fpx, fpy, fpz);
        camera->ComputeViewPlaneNormal();

  // Scale PolyData
  vtkPoints * scale_points = vtkPoints::New();
  scale_points->InsertNextPoint(-10.0, 0.0,  0.0);
  scale_points->InsertNextPoint(-10.0, 100.0, 0.0);
  vtkCellArray * scale_cells = vtkCellArray::New();
  scale_cells->InsertNextCell( 2 );
  scale_cells->InsertCellPoint( 0 );
  scale_cells->InsertCellPoint( 1 );
  vtkPolyData * scale_poly = vtkPolyData::New();
  scale_poly->SetPoints( scale_points );
  scale_poly->SetLines( scale_cells );
  vtkPolyDataMapper * scale_mapper = vtkPolyDataMapper::New();
  scale_mapper->SetInput( scale_poly );
  vtkActor * scale_actor = vtkActor::New();
  scale_actor->GetProperty()->SetColor(1.0, 1.0, 1.0);
  scale_actor->SetMapper( scale_mapper );

        // Renderer
        vtkRenderer * renderer = vtkRenderer::New();
        renderer->SetBackground( 0, 0, 0 );
  renderer->AddVolume( volume );
  //renderer->AddActor( scale_actor );
        renderer->SetActiveCamera(camera);
        renderer->ResetCamera();

        camera->Zoom(1.3);

        // Render Window
        vtkRenderWindow * render_window = vtkRenderWindow::New();
        render_window->SetSize( WSIZE, WSIZE );
        render_window->SetOffScreenRendering( 1 );
        render_window->AddRenderer( renderer );
        // ***** STEREO *****
        //render_window->StereoRenderOn();

        // Window to Image
        vtkWindowToImageFilter * win_2_image
                = vtkWindowToImageFilter::New();
        win_2_image->SetInput( render_window );

        // PNG Writer
        vtkPNGWriter * writer = vtkPNGWriter::New();
        writer->SetFileName( out_file_name );
        writer->SetInputConnection( win_2_image->GetOutputPort() );

        render_window->Render();

        writer->Write();

        return 0;
}



-----Original Message-----
From: Bill Lorensen [mailto:bill.lorensen at gmail.com]
Sent: 2010 Jul 12 1:59 PM
To: Urvoas, Paul
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] Visualize 3D image (.mhd)

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
>
>

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


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.




More information about the vtkusers mailing list