[prev in list] [next in list] [prev in thread] [next in thread]
List: vtkusers
Subject: [vtkusers] Rendering multiple objects in one render window
From: WangQ <wangq1979 () outlook ! com>
Date: 2015-12-28 14:06:23
Message-ID: SNT153-W55A118E6AA750B3D6753ECB4FB0 () phx ! gbl
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
[Attachment #4 (text/plain)]
Hello there,
I am quite new to VTK, and I am trying to render a volume and an isosurface in one \
render window using viewpoint. I follow the example of \
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/StructuredDataTypes but no \
luck so far. Here is the code I wrote. Could anyone help to figure out where is \
wrong? Would appreciate any help.
// Create an image data vtkSmartPointer<vtkImageData> imageData \
= vtkSmartPointer<vtkImageData>::New(); // load data \
here
// Define viewport ranges double upperViewport[4] = {0.0, 0.0, 1.0, \
0.5}; double centerViewport[4] = {0.0, 0.5, 1.0, 1.0}; // create render \
window vtkSmartPointer<vtkRenderWindow> renWin = \
vtkSmartPointer<vtkRenderWindow>::New(); \
vtkSmartPointer<vtkRenderWindowInteractor> iren = \
vtkSmartPointer<vtkRenderWindowInteractor>::New(); renWin->SetSize(1200, 600); \
renWin->Render(); renWin->SetWindowName("Volume Clipping"); \
iren->SetRenderWindow(renWin); \
/**************************************************************** \
create volume renderer to render stacked tomograms \
****************************************************************/ \
vtkSmartPointer<vtkSmartVolumeMapper> volumeMapper = \
vtkSmartPointer<vtkSmartVolumeMapper>::New(); \
volumeMapper->SetBlendModeToComposite(); // composite first \
volumeMapper->SetInputData(imageData); \
volumeMapper->SetInterpolationModeToLinear(); \
volumeMapper->SetRequestedRenderModeToGPU(); vtkSmartPointer<vtkVolumeProperty> \
volumeProperty = vtkSmartPointer<vtkVolumeProperty>::New(); \
volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION); \
volumeProperty->ShadeOff(); vtkSmartPointer<vtkColorTransferFunction> color = \
vtkSmartPointer<vtkColorTransferFunction>::New(); \
//color->SetColorSpaceToRGB(); color->AddRGBPoint(0.0, 0.0, 0.0, 1.0); \
color->AddRGBPoint(0.25, 0.0, 1.0, 1.0); color->AddRGBPoint(0.5, 0.0, 1.0, \
0.0); color->AddRGBPoint(0.75, 1.0, 1.0, 0.0); color->AddRGBPoint(1.0, \
1.0, 0.0, 0.0); color->SetScaleToLinear(); \
volumeProperty->SetColor(color); vtkSmartPointer<vtkPiecewiseFunction> \
compositeOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New(); \
compositeOpacity->AddPoint(-1.0, 0.0); compositeOpacity->AddPoint(0.0, 0.0); \
compositeOpacity->AddPoint(0.39, 0.4); compositeOpacity->AddPoint(0.4, 0.8); \
compositeOpacity->AddPoint(1.0, 1.0); \
volumeProperty->SetScalarOpacity(compositeOpacity); \
vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New(); \
volume->SetMapper(volumeMapper); volume->SetProperty(volumeProperty); \
vtkSmartPointer<vtkRenderer> volumeRenderer = vtkSmartPointer<vtkRenderer>::New(); \
renWin->AddRenderer(volumeRenderer); \
volumeRenderer->SetViewPoint(upperViewport); // position volume rendering at upper \
part volumeRenderer->SetBackground(0.4, 0.5, 0.6); \
vtkSmartPointer<vtkScalarBarWidget> scalarWidget = \
vtkSmartPointer<vtkScalarBarWidget>::New(); scalarWidget->SetInteractor(iren); \
scalarWidget->GetScalarBarActor()->SetTitle("Concentration"); \
scalarWidget->GetScalarBarActor()->SetLookupTable(color); \
scalarWidget->GetScalarBarActor()->SetOrientationToHorizontal(); \
scalarWidget->RepositionableOn(); scalarWidget->ResizableOn(); \
scalarWidget->EnabledOn(); vtkSmartPointer<vtkAxesActor> axes = \
vtkSmartPointer<vtkAxesActor>::New(); axes->SetTotalLength(50.0, 50.0, 50.0); \
/**********************************End of volume \
renderer*********************************/ \
/**************************************************************** create \
contour renderer to contouring stacked tomograms \
****************************************************************/ // Create an \
isosurface vtkSmartPointer<vtkContourFilter> contourFilter = \
vtkSmartPointer<vtkContourFilter>::New(); \
contourFilter->SetInputData(imageData); const double isovalue = 0.6; \
contourFilter->GenerateValues(1, isovalue, isovalue); // (numContours, rangeStart, \
rangeEnd) // Map the contours to graphical primitives \
vtkSmartPointer<vtkPolyDataMapper> contourMapper = \
vtkSmartPointer<vtkPolyDataMapper>::New(); \
contourMapper->SetInputData(contourFilter->GetOutput()); // Create an actor for the \
contours vtkSmartPointer<vtkActor> contourActor = \
vtkSmartPointer<vtkActor>::New(); contourActor->SetMapper(contourMapper); // \
Create the outline vtkSmartPointer<vtkOutlineFilter> outlineFilter = \
vtkSmartPointer<vtkOutlineFilter>::New(); \
outlineFilter->SetInputData(imageData); vtkSmartPointer<vtkPolyDataMapper> \
outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); \
outlineMapper->SetInputData(outlineFilter->GetOutput()); \
vtkSmartPointer<vtkActor> outlineActor = vtkSmartPointer<vtkActor>::New(); \
outlineActor->SetMapper(outlineMapper); // Visualize \
vtkSmartPointer<vtkRenderer> contourRenderer = \
vtkSmartPointer<vtkRenderer>::New(); renWin->AddRenderer(contourRenderer); \
contourRenderer->SetViewPoint(centerViewport); \
contourRenderer->SetBackground(0.5, .4, .6); \
/**********************************End of contour \
renderer*********************************/
volumeRenderer->AddActor(volume); volumeRenderer->AddActor(axes);
contourRenderer->AddActor(contourActor); \
contourRenderer->AddActor(outlineActor);
contourRenderer->SetActiveCamera(volumeRenderer->GetActiveCamera()); \
volumeRenderer->ResetCamera(); contourRenderer->ResetCamera();
// Render composite. In default mode. For coverage. renWin->Render(); \
iren->Start();
[Attachment #5 (text/html)]
<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:΢ÈíÑźÚ
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><span style="color: rgb(34, 34, 34); \
font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, \
255);">Hello there, </span><div style="color: rgb(34, 34, 34); font-family: \
arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, \
255);"><br></div><div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; \
font-size: 12.8px; background-color: rgb(255, 255, 255);">I am quite new to VTK, and \
I am trying to render a volume and an isosurface in one render window using \
viewpoint. I follow the example of <a \
href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/StructuredDataTypes" \
target="_blank" style="color: rgb(17, 85, \
204);">http://www.vtk.org/Wiki/<wbr>VTK/Examples/Cxx/<wbr>Visualization/<wbr>StructuredDataTypes</a> but \
no luck so far. Here is the code I wrote. Could anyone help to figure out where is \
wrong? </div><div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; \
font-size: 12.8px; background-color: rgb(255, 255, 255);"><br></div><div \
style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; \
background-color: rgb(255, 255, 255);">Would appreciate any help.</div><div \
style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px; \
background-color: rgb(255, 255, 255);"><br></div><div style="color: rgb(34, 34, 34); \
font-family: arial, sans-serif; font-size: 12.8px; background-color: rgb(255, 255, \
255);"><div><br></div><div> </div><div> \
// Create an image data</div><div> \
vtkSmartPointer<vtkImageData> imageData =</div><div> \
vtkSmartPointer<vtkImageData>:<wbr>:New();</div><div><span \
style="white-space: pre-wrap;"> </span></div><div><span style="white-space: \
pre-wrap;"> </span>// load data here</div><div><br></div><div> \
// Define viewport ranges</div><div> double \
upperViewport[4] = {0.0, 0.0, 1.0, 0.5};</div><div> double \
centerViewport[4] = {0.0, 0.5, 1.0, 1.0};</div><div><br></div><div> \
// create render window</div><div> \
vtkSmartPointer<<wbr>vtkRenderWindow> renWin = \
vtkSmartPointer<<wbr>vtkRenderWindow>::New();</div><div> \
vtkSmartPointer<<wbr>vtkRenderWindowInteractor> iren =</div><div> \
\
vtkSmartPointer<<wbr>vtkRenderWindowInteractor>::<wbr>New();</div><div> \
renWin->SetSize(1200, 600);</div><div> \
renWin->Render();</div><div> \
renWin->SetWindowName("Volume Clipping");</div><div> \
iren->SetRenderWindow(renWin);</div><div><br></div><div> \
/*****************************<wbr>******************************<wbr>*****</div><div> \
create volume renderer to \
render stacked tomograms</div><div> \
******************************<wbr>******************************<wbr>****/ </div><div> \
vtkSmartPointer<<wbr>vtkSmartVolumeMapper> volumeMapper \
=</div><div> \
vtkSmartPointer<<wbr>vtkSmartVolumeMapper>::New();</div><div> \
volumeMapper-><wbr>SetBlendModeToComposite(); // composite \
first</div><div> \
volumeMapper->SetInputData(<wbr>imageData);</div><div> \
volumeMapper-><wbr>SetInterpolationModeToLinear()<wbr>;</div><div> \
volumeMapper-><wbr>SetRequestedRenderModeToGPU();</div><div><br></div><div> \
vtkSmartPointer<<wbr>vtkVolumeProperty> volumeProperty \
=</div><div> \
vtkSmartPointer<<wbr>vtkVolumeProperty>::New();</div><div> \
volumeProperty-><wbr>SetInterpolationType(VTK_<wbr>LINEAR_INTERPOLATION);</div><div> \
volumeProperty->ShadeOff();</div><div><br></div><div> \
vtkSmartPointer<<wbr>vtkColorTransferFunction> color \
=</div><div> \
vtkSmartPointer<<wbr>vtkColorTransferFunction>::<wbr>New();</div><div> \
//color->SetColorSpaceToRGB();</div><div> \
color->AddRGBPoint(0.0, 0.0, 0.0, 1.0);</div><div> \
color->AddRGBPoint(0.25, 0.0, 1.0, 1.0);</div><div> \
color->AddRGBPoint(0.5, 0.0, 1.0, 0.0);</div><div> \
color->AddRGBPoint(0.75, 1.0, 1.0, 0.0);</div><div> \
color->AddRGBPoint(1.0, 1.0, 0.0, 0.0);</div><div> \
color->SetScaleToLinear();</div><div> \
volumeProperty->SetColor(<wbr>color);</div><div><br></div><div> \
vtkSmartPointer<<wbr>vtkPiecewiseFunction> compositeOpacity \
=</div><div> \
vtkSmartPointer<<wbr>vtkPiecewiseFunction>::New();</div><div> \
compositeOpacity->AddPoint(-1.<wbr>0, 0.0);</div><div> \
compositeOpacity->AddPoint(0.<wbr>0, 0.0);</div><div> \
compositeOpacity->AddPoint(0.<wbr>39, 0.4);</div><div> \
compositeOpacity->AddPoint(0.<wbr>4, 0.8);</div><div> \
compositeOpacity->AddPoint(1.<wbr>0, 1.0);</div><div> \
volumeProperty-><wbr>SetScalarOpacity(<wbr>compositeOpacity);</div><div><span \
style="white-space: pre-wrap;"> </span></div><div> \
vtkSmartPointer<vtkVolume> volume =</div><div> \
vtkSmartPointer<vtkVolume>::<wbr>New();</div><div> \
volume->SetMapper(<wbr>volumeMapper);</div><div> \
volume->SetProperty(<wbr>volumeProperty);</div><div><br></div><div> \
vtkSmartPointer<vtkRenderer> volumeRenderer = \
vtkSmartPointer<vtkRenderer>::<wbr>New();</div><div> \
renWin->AddRenderer(<wbr>volumeRenderer);</div><div> \
volumeRenderer->SetViewPoint(<wbr>upperViewport); // position volume rendering at \
upper part</div><div> \
volumeRenderer->SetBackground(<wbr>0.4, 0.5, 0.6);</div><div><br></div><div> \
vtkSmartPointer<<wbr>vtkScalarBarWidget> scalarWidget \
=</div><div> \
vtkSmartPointer<<wbr>vtkScalarBarWidget>::New();</div><div> \
scalarWidget->SetInteractor(<wbr>iren);</div><div> \
scalarWidget-><wbr>GetScalarBarActor()->SetTitle(<wbr>"Concentration");</div><div> \
\
scalarWidget-><wbr>GetScalarBarActor()-><wbr>SetLookupTable(color);</div><div> \
\
scalarWidget-><wbr>GetScalarBarActor()-><wbr>SetOrientationToHorizontal();</div><div> \
scalarWidget-><wbr>RepositionableOn();</div><div> \
scalarWidget->ResizableOn();</div><div> \
scalarWidget->EnabledOn();</div><div><br></div><div> \
vtkSmartPointer<vtkAxesActor> axes =</div><div> \
\
vtkSmartPointer<vtkAxesActor>:<wbr>:New();</div><div> \
axes->SetTotalLength(50.0, 50.0, 50.0);</div><div> \
/*****************************<wbr>*****End of volume \
renderer**********************<wbr>***********/</div><div><br></div><div> \
\
/*****************************<wbr>******************************<wbr>*****</div><div> \
create contour renderer to contouring stacked \
tomograms</div><div> \
******************************<wbr>******************************<wbr>****/</div><div> \
// Create an isosurface</div><div> \
vtkSmartPointer<<wbr>vtkContourFilter> contourFilter =</div><div> \
\
vtkSmartPointer<<wbr>vtkContourFilter>::New();</div><div> \
contourFilter->SetInputData(<wbr>imageData);</div><div><span \
style="white-space: pre-wrap;"> </span></div><div> const \
double isovalue = 0.6;</div><div> \
contourFilter->GenerateValues(<wbr>1, isovalue, isovalue); // (numContours, \
rangeStart, rangeEnd)</div><div> // Map the contours to \
graphical primitives</div><div> \
vtkSmartPointer<<wbr>vtkPolyDataMapper> contourMapper =</div><div> \
\
vtkSmartPointer<<wbr>vtkPolyDataMapper>::New();</div><div> \
contourMapper->SetInputData(<wbr>contourFilter->GetOutput());</div><div><br></div><div> \
// Create an actor for the contours</div><div> \
vtkSmartPointer<vtkActor> contourActor =</div><div> \
\
vtkSmartPointer<vtkActor>::<wbr>New();</div><div> \
contourActor->SetMapper(<wbr>contourMapper);</div><div><br></div><div> \
// Create the outline</div><div> \
vtkSmartPointer<<wbr>vtkOutlineFilter> outlineFilter =</div><div> \
\
vtkSmartPointer<<wbr>vtkOutlineFilter>::New();</div><div> \
outlineFilter->SetInputData(<wbr>imageData);</div><div><span \
style="white-space: pre-wrap;"> </span></div><div> \
vtkSmartPointer<<wbr>vtkPolyDataMapper> outlineMapper =</div><div> \
\
vtkSmartPointer<<wbr>vtkPolyDataMapper>::New();</div><div> \
outlineMapper->SetInputData(<wbr>outlineFilter->GetOutput());</div><div> \
vtkSmartPointer<vtkActor> outlineActor =</div><div> \
\
vtkSmartPointer<vtkActor>::<wbr>New();</div><div> \
outlineActor->SetMapper(<wbr>outlineMapper);</div><div><br></div><div> \
// Visualize</div><div> \
vtkSmartPointer<vtkRenderer> contourRenderer =</div><div> \
vtkSmartPointer<vtkRenderer>::<wbr>New();</div><div> \
renWin->AddRenderer(<wbr>contourRenderer);</div><div> \
\
contourRenderer->SetViewPoint(<wbr>centerViewport);</div><div> \
contourRenderer-><wbr>SetBackground(0.5, .4, .6);</div><div> \
/*****************************<wbr>*****End of contour \
renderer**********************<wbr>***********/</div><div><br></div><div> \
volumeRenderer->AddActor(<wbr>volume);</div><div> \
\
volumeRenderer->AddActor(axes)<wbr>;</div><div><br></div><div> \
contourRenderer->AddActor(<wbr>contourActor);</div><div> \
contourRenderer->AddActor(<wbr>outlineActor);</div><div><br></div><div> \
\
contourRenderer-><wbr>SetActiveCamera(<wbr>volumeRenderer-><wbr>GetActiveCamera());</div><div> \
volumeRenderer->ResetCamera();</div><div> \
contourRenderer->ResetCamera()<wbr>;</div><div><br></div><div> \
// Render composite. In default mode. For coverage.</div><div> \
renWin->Render();</div><div> \
iren->Start();</div></div> </div></body> </html>
_______________________________________________
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
Search the list archives at: http://markmail.org/search/?q=vtkusers
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic