[vtkusers] Fw: Could you give me your source code using user defined data?

Jung-Su Oh koorye at bmsil.snu.ac.kr
Tue Jan 7 22:05:38 EST 2003


----- Original Message ----- 
From: Jung-Su Oh 
To: vtkusers at public.kitware.com ; alexeyr at netcracker.com 
Sent: Wednesday, January 08, 2003 12:03 PM
Subject: Could you give me your source code using user defined data?


Hi, I'm mailing again. I'm beginner of  VTK.
(I've mailed sometimes ago but all of them has font problems....
I can't understand why it ocurred. anyway....)
So I don't know how to do the volume rendering of the data in file or array in C language.
I think that your source contains them. (I saw it in user's digest.)
Could you give me the full volume rendering source code in Cpp with 
my data like those follows?
(The source code of me is not working properly)
Please complete the souce code as that can run.

 vtkRenderer *ren1 = vtkRenderer::New();
 vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);

 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

 unsigned char* data=new unsigned char[1000000];
 int i;

//Just making user defined data - sphere shape
 for(int x=0;x<100;x++){
  for(int y=0;y<100;y++){
   for(int z=0;z<100;z++){
    i = x*10000+y*100+z;
    if(x^2+y^2+z^2<10000)
     data[i]=200;
   }
  }
 }

 vtkImageImport *img=vtkImageImport::New();
 img->SetImportVoidPointer (data);
 img->SetDataScalarTypeToUnsignedChar ();
 img->SetWholeExtent (0, 100, 0, 100, 0, 100);
 img->SetDataExtentToWholeExtent();

//
//
//Is there any other setting is needed?
//
//
 
 vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
  oTFun->AddSegment(80,0.0,255,1.0);
 vtkPiecewiseFunction *gTFun = vtkPiecewiseFunction::New();
  gTFun->AddSegment(0,1.0,255,1.0);

 vtkVolumeProperty *volProperty = vtkVolumeProperty::New();
  volProperty->SetColor(gTFun);
  volProperty->SetGradientOpacity(oTFun);
  volProperty->SetInterpolationTypeToLinear();
  volProperty->ShadeOn();

 vtkVolumeRayCastCompositeFunction *compositeFunction = 
  vtkVolumeRayCastCompositeFunction::New();

 vtkVolumeRayCastMapper *volMapper = 
  vtkVolumeRayCastMapper::New(); 

 volMapper->SetVolumeRayCastFunction(compositeFunction);
 volMapper->SetInput (img->GetOutput());
 vtkVolume *vol = vtkVolume::New();

 vol->SetMapper(volMapper);
 vol->SetProperty(volProperty);

 ren1->AddVolume(vol);
 renWin->Render();
 ren1->GetActiveCamera()->Azimuth(20);
 renWin->Render();
 ren1->GetActiveCamera()->Dolly(1.65);
 renWin->Render();
 iren->SetDesiredUpdateRate(3.0);
 renWin->Render();
 iren->Start(); 


More information about the vtkusers mailing list