[vtkusers] Color a point in a 3D volume

VJay Vijay.Sundaram at asu.edu
Mon Jul 13 13:45:01 EDT 2009


Hey Valerie,

Thanks a lot for the response. As I am a newbie to vtk, could you please
help me integrate your solution to mine ? I have appended the code below. As
I have not written my volume rendering code as classes, I'm finding it a
little tough to integrate. Thanks in advance. 

Cheers
VJ


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

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


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);
  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->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/Color-a-point-in-a-3D-volume-tp24451362p24466214.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list