有时候使用表面重建不能显示细节。因此使用VolumeRender才好。
见代码:
#include "base.h"
void show(vtkSmartPointer<vtkRenderer> renderer){
// show the renderer window using passed renderer object.
vtkSmartPointer<vtkRenderWindow> renWin=vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(renderer);
renWin->SetSize(640,480);
//renWin->Render(); //Not use it in ray-casting
vtkSmartPointer<vtkRenderWindowInteractor> iren=vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style=vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
iren->SetInteractorStyle(style);
iren->Initialize();
iren->Start();
}
// Get all the color scheme names.
// Return a map os the names keyed on their index.
map<int,string> GetAllColorSchemes(){
//
map<int,string> colorSchemes;
vtkSmartPointer<vtkColorSeries> colorSeries=vtkSmartPointer<vtkColorSeries>::New();
for(int i=0;i<colorSeries->GetNumberOfColorSchemes();++i){
colorSeries->SetColorScheme(i);
colorSchemes[i]=colorSeries->GetColorSchemeName();
}
return colorSchemes;
}
// The available color scheme indexes and names.
// return a string is the indexes and names.
string AvailableColorSchemes(map<int,string> & colorSchemes){
ostringstream os;
for(map<int,string>::const_iterator p=colorSchemes.begin();p!=colorSchemes.end();++p)
os<<std::setw(3)<<p->first<<"\t"<<p->second<<endl;
return os.str();
}
// Display the available color schemes.
void DisplayAvailableColorSchemes(){
string line("---------------------------------------------------\n");
map<int,string> colorSchemes;
//colorSchemes=GetAllColorSchemes();
colorSchemes=GetAllNamedColorSchemes();
cout<<line<<AvailableColorSchemes(colorSchemes)<<line<<endl;
}
map<int,string> GetAllNamedColorSchemes(){
//
map<int,string> colorSchemes;
vtkSmartPointer<vtkNamedColors> colors=vtkSmartPointer<vtkNamedColors>::New();
for(int i=0;i<colors->GetNumberOfColors();++i){
//colors->SetReferenceCount(i);
colorSchemes[i]=colors->GetColorNames();
}
return colorSchemes;
}