[vtkusers] re nder a sphere at a point in a volume

VJay Vijay.Sundaram at asu.edu
Mon Jul 13 17:36:52 EDT 2009


Hey,

I have a question on rendering multiple data in the same render window. I
have a volume rendered in a window (rendered using DICOM datasets - slices
of images). Now, i create a sphere source and set its properties and I wish
to render the sphere in the same render window at a particular point
(x,y,z). I can set the center of the sphere at the sphere source and have a
common rendering window where i add both the actors. But the problem is that
the code compiles perfectly, but I am not able to see the sphere at all..!
Only the volume is rendered and I can see it without any problems. Where is
the sphere ? Am I making a mistake ? 

I have attached the code below. Please have a look at it and reply at the
earliest. 

Thanks in advance,
VJay


--------------------------------------------------------------------------------------------------


#include "vtkRenderWindow.h"
#include "vtkCamera.h"
#include "vtkPiecewiseFunction.h "
#include "vtkVolumeProperty.h"
#include "vtkRenderer.h"
#include "vtkDICOMImageReader.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolumeRayCastCompositeFunction.h "
#include "vtkVolumeRayCastMapper.h"
#include "vtkFixedPointVolumeRayCastMapper.h"
#include "vtkColorTransferFunction.h"
#include "vtkProp.h"
#include "vtkImageData.h"
#include "vtkSmartPointer.h"
#include "vtkPoints.h"
#include "vtkWin32RenderWindowInteractor.h"
#include "vtkGlyph3D.h"
#include "vtkSphereSource.h"
#include "vtkProperty.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataReader.h"

void main()
{
  vtkRenderer         *render = vtkRenderer::New();
  vtkRenderWindow     *renwin = vtkRenderWindow::New();
  vtkDICOMImageReader *reader = vtkDICOMImageReader::New();

  reader->SetDirectoryName("D:\\DICOMimages\\");
  reader->SetFileNameSliceOffset(1);
  reader->SetFileNameSliceSpacing(1);
  reader->SetDataExtent(0,511,0,511,0,224); 
  reader->SetDataSpacing(360.0/512,360.0/512,1.0); 
  reader->SetDataOrigin(0.0,0.0,0.0);
  
  reader->Update();

  vtkPiecewiseFunction *opacity = vtkPiecewiseFunction::New();
  
  opacity->AddPoint(0.0,0.0);
  opacity->AddPoint(50.0,0.0);
  opacity->AddPoint(200.0,0.0);
  opacity->AddPoint(255.0,1.0);
  opacity->Modified();
  opacity->Update();

  vtkColorTransferFunction *color = vtkColorTransferFunction::New();
  
  color->AddRGBPoint(10.0,1.0,0.0,0.0);
  color->AddRGBPoint(50.0,0.0,1.0,1.0);
  color->AddRGBPoint(200.0,0.0,0.0,1.0);
  color->AddRGBPoint(255.0,1.0,1.0,1.0);

  vtkVolumeProperty *prop = vtkVolumeProperty::New();
  
  //prop->SetColor(color);
  prop->SetScalarOpacity(opacity);

  vtkVolume *volume = vtkVolume::New();
  
  //vtkVolumeRayCastMapper *volumemapper = vtkVolumeRayCastMapper::New();
  vtkFixedPointVolumeRayCastMapper *volumemapper =
vtkFixedPointVolumeRayCastMapper::New();
       
    //vtkVolumeRayCastCompositeFunction *raycast =
vtkVolumeRayCastCompositeFunction::New();
  //volumemapper->SetVolumeRayCastFunction(raycast);

  vtkSphereSource *sphere = vtkSphereSource::New();
  sphere->SetCenter(0,0,0);
  sphere->SetPhiResolution(18);
  sphere->SetThetaResolution(18);
  sphere->SetRadius(0.1);

     // map to graphics library
  vtkPolyDataMapper *map = vtkPolyDataMapper::New();
  map->SetInput(sphere->GetOutput());

  // actor coordinates geometry, properties, transformation
  vtkActor *aSphere = vtkActor::New();
  aSphere->SetMapper(map);
  aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue 

  volumemapper->SetInputConnection(reader->GetOutputPort());
  volumemapper->SetSampleDistance(1.0);
  volumemapper->SetBlendModeToMaximumIntensity();
  volume->SetMapper(volumemapper);

  volume->SetProperty(prop);
  
  vtkCamera *camera = vtkCamera::New();
  camera->SetViewUp(1,0,0);
  camera->SetPosition(0,1,0);
  camera->SetFocalPoint(0,0,0);
  camera->ComputeViewPlaneNormal();

  render->AddActor(volume);
  render->AddActor(aSphere);
  
  render->SetActiveCamera(camera);
  render->ResetCamera();
  render->SetBackground(0,0,0);

  renwin->AddRenderer(render);
  
  vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renwin);
  renwin->Render();
  iren->Initialize();
  iren->Start();

  reader->Delete();
  iren->Delete();
}

-- 
View this message in context: http://www.nabble.com/render-a-sphere-at-a-point-in-a-volume-tp24469849p24469849.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list