<div dir="ltr">Hey all,<div><br></div><div>I'm running into a segmentation violation when I attempt to use osgVolume::MultipassTechnique more or less as a drop in replacement for RayTracedTechnique using OSG 3.4. My use of RayTracedTechnique works and renders fine.</div><div><br></div><div>Here is an partial code listing demonstrating my use of MultipassTechnique:</div><div><b><br></b></div><div><div><b>    void setVolumeProperties(osg::ref_ptr<osgVolume::Volume> volume,osg::ref_ptr<osgVolume::VolumeTile> tile,</b></div><div><b>            osg::ref_ptr<osgVolume::ImageLayer> layer, VolumePropertyManager &volumeProperties, osg::ref_ptr<osgVolume::VolumeScene> volumeScene)</b></div><div><b>    {</b></div><div><b>        </b></div><div><b>        // FixedFunctionTechnique turns on GL_LIGHTING, which breaks the color rendering.</b></div><div><b>        osg::StateSet* stateset = volume->getOrCreateStateSet();</b></div><div><b>                </b></div><div><b>        if (volumeProperties.volumeTechnique == VolumeTechnique::RayTraced){</b></div><div><b>            osg::ref_ptr<osgVolume::RayTracedTechnique> rayTraced = new osgVolume::RayTracedTechnique();</b></div><div><b>            tile->setVolumeTechnique(rayTraced.get());</b></div><div><b>            osg::ref_ptr<osg::FrontFace> frontFace(new osg::FrontFace(osg::FrontFace::CLOCKWISE));</b></div><div><b>            stateset->setAttribute(frontFace.get(), osg::StateAttribute::PROTECTED);</b></div><div><b>            layer->addProperty(new osgVolume::SampleDensityWhenMovingProperty(volumeProperties.sampleDensityWhenMoving));</b></div><div><b>            layer->addProperty(new osgVolume::SampleDensityProperty(volumeProperties.sampleDensity));</b></div><div><b>        } else if (volumeProperties.volumeTechnique == VolumeTechnique::Multipass) {</b></div><div><b>            osg::ref_ptr<osgVolume::MultipassTechnique> multipass = new osgVolume::MultipassTechnique();</b></div><div><b>            tile->setVolumeTechnique(multipass.get());</b></div><div><b>            volumeScene->addChild(volume.get());</b></div><div><b>            volume->getOrCreateStateSet();</b></div><div><b>            layer->addProperty(new osgVolume::SampleRatioProperty(1.0f));</b></div><div><b>            layer->addProperty(new osgVolume::SampleRatioWhenMovingProperty(0.5f));</b></div><div><b>            </b></div><div><b>        } else if (volumeProperties.volumeTechnique == VolumeTechnique::FixedFunction) {</b></div><div><b>            tile->setVolumeTechnique(new osgVolume::FixedFunctionTechnique());</b></div><div><b>            stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);</b></div><div><b>        } else {</b></div><div><b>            throw hg::PropertyException("VolumeTechnique");</b></div><div><b>        }</b></div><div><b><br></b></div><div><b>        layer->addProperty(new osgVolume::TransferFunctionProperty(volumeProperties.transferFunction.get()));</b></div><div><b>        layer->addProperty(new osgVolume::AlphaFuncProperty(volumeProperties.alphaFunc));</b></div><div><b>        if (volumeProperties.useLighting) layer->addProperty(new osgVolume::LightingProperty);</b></div><div><b>        if (volumeProperties.useIsosurface) layer->addProperty(new osgVolume::IsoSurfaceProperty(volumeProperties.alphaFunc));</b></div><div><b>        if (volumeProperties.useMaximumIntensityProjection) layer->addProperty(new osgVolume::MaximumIntensityProjectionProperty());</b></div><div><b>    }</b></div></div><div><br></div><div>The following function returns the Node * that will be passed to the viewer. I either return a osgVolume::Volume * or osgVolume::VolumeScene * object depending on whether I'm using multipass rendering as my Node *. </div><div><b><br></b></div><div><div><b>    osg::Node* BP_createPeerHelper(Volume& v,</b></div><div><b>            hg::SceneClient& client,</b></div><div><b>            const gui_objects::Cookie& owner,</b></div><div><b>            hg::UpdateState& us) {</b></div><div><b>        </b></div><div><b>        osg::ref_ptr<osgVolume::Volume> volume = new osgVolume::Volume;</b></div><div><b>        osg::ref_ptr<osgVolume::VolumeScene> volumeScene = new osgVolume::VolumeScene;</b></div><div><b><br></b></div><div><b>        const mxArray* data = v.getData();</b></div><div><b>        VolumePropertyManager volumeProperties(v,us);</b></div><div><b><br></b></div><div><b>        if (data != NULL && mxGetNumberOfDimensions(data) == 3 && mxGetClassID(data) == mxUINT8_CLASS) {</b></div><div><b>                       </b></div><div><b>            </b></div><div><b>            osg::ref_ptr<osgVolume::VolumeTile> tile = new osgVolume::VolumeTile;</b></div><div><b>            volume->addChild(tile.get());</b></div><div><b>            </b></div><div><b>            // If we are using FixedFunctionTechnique, we need to apply the transfer function to get a new allocated RGBA memory on the CPU to pass to OSG.</b></div><div><b>            // Otherwise, we can pass the intensity data directly to the card. GPU shaders does the RGBA directly.</b></div><div><b>            osg::ref_ptr<osg::Image> intensityImage = createTexture3D(data);</b></div><div><b>            osg::ref_ptr<osg::Image> image_3d = (volumeProperties.volumeTechnique == VolumeTechnique::FixedFunction) ?</b></div><div><b>                                                    osgVolume::applyTransferFunction(intensityImage.get(),volumeProperties.transferFunction.get()) :</b></div><div><b>                                                    intensityImage.release();</b></div><div><b>            </b></div><div><b>            osg::ref_ptr<osgVolume::ImageLayer> layer = new osgVolume::ImageLayer(image_3d);</b></div><div><b>            tile->setLayer(layer.get());</b></div><div><b>            </b></div><div><b>            setVolumeProperties(volume,tile,layer,volumeProperties,volumeScene);</b></div><div><b>                        </b></div><div><b>            // Our original implementation positioned the bbox [-0.5,0.5] in each dimension.</b></div><div><b>            // FixedFunctionTechnique applies the locator matrix to the a unit cube [0 1] in each dimension.</b></div><div><b>            // To get the equivalent spatial referencing, apply a translation of -0.5 to each dimension.</b></div><div><b>            osg::ref_ptr<osg::RefMatrix> matrix = new osg::RefMatrix();</b></div><div><b>            matrix->makeTranslate(-0.5,-0.5,-0.5);</b></div><div><b>            </b></div><div><b>            tile->setLocator(new osgVolume::Locator(*matrix));</b></div><div><b>            </b></div><div><b>        }</b></div><div><b>        else {</b></div><div><b>            throw hg::PropertyException("Data");</b></div><div><b>        }</b></div><div><b>        </b></div><div><b>        std::cout << "volumeScene pointer: " << volumeScene.get() << std::endl;</b></div><div><b>        </b></div><div><b>        if (volumeProperties.volumeTechnique == VolumeTechnique::Multipass)</b></div><div><b>            return volumeScene.release();</b></div><div><b>        else</b></div><div><b>            return volume.release();</b></div><div><b>        </b></div><div><b>    }</b></div></div><div><b><br></b></div><div>When I execute my code that previously worked with RayTracedTechnique, I receive the following stack trace</div><div><br></div><div>







<p class="p1"><span class="s1">Stack Trace (from fault):</span></p>
<p class="p1"><span class="s1"><b>[  0] 0x0000000104879d04 fl::diag::stacktrace_base::capture(fl::diag::thread_context const&, unsigned long) at stacktrace.cpp:175 (in /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libmwfl.dylib)</b></span></p>
<p class="p1"><span class="s1"><b>[  1] 0x000000010487cf9a void (anonymous namespace)::terminate_impl::log<char const*>(char const* const&, fl::diag::thread_context const&, char const*, int, char const*, bool) at terminate.cpp:238 (in /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libmwfl.dylib)</b></span></p>
<p class="p1"><span class="s1"><b>[  2] 0x000000010487ca09 fl::diag::terminate_log(char const*, __darwin_ucontext const*) at lock_types.hpp:362 (in /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libmwfl.dylib)</b></span></p>
<p class="p1"><span class="s1"><b>[  3] 0x00000001081cf0a8 (anonymous namespace)::crash_context::generate_crash_report_(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const at sighndl.cpp:1149 (in /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libmwmcr.dylib)</b></span></p>
<p class="p1"><span class="s1"><b>[  4] 0x00000001081cea00 (anonymous namespace)::crash_context::ctor_() at sighndl.cpp:1025 (in /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libmwmcr.dylib)</b></span></p>
<p class="p1"><span class="s1"><b>[  5] 0x00000001081cd62a mnFatalSignalHandler at sighndl.cpp:729 (in /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libmwmcr.dylib)</b></span></p>
<p class="p1"><span class="s1"><b>[  6] 0x00007fff90c31f1a _sigtramp+00000026 at /usr/lib/system/libsystem_platform.dylib+20250 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[  7] 0x0000000000000005 [unknown function] at [unknown module] (no module specified)</b></span></p>
<p class="p1"><span class="s1"><b>[  8] 0x00000001204c4e56 osgVolume::MultipassTechnique::traverse(osg::NodeVisitor&)+00000086 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosgVolume.130.dylib+106070 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[  9] 0x00000001204dcbf6 osgVolume::VolumeTile::traverse(osg::NodeVisitor&)+00000438 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosgVolume.130.dylib+203766 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 10] 0x00000001204d7c0b osgVolume::VolumeScene::traverse(osg::NodeVisitor&)+00008827 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosgVolume.130.dylib+183307 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 11] 0x0000000143a8daf2 osgUtil::CullVisitor::apply(osg::Group&)+00000642 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosgUtil.130.dylib+39666 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 12] 0x00000001204d8a79 osgVolume::VolumeScene::accept(osg::NodeVisitor&)+00000121 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosgVolume.130.dylib+187001 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 13] 0x00000001438749ef osg::Group::traverse(osg::NodeVisitor&)+00000047 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosg.130.dylib+522735 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 14] 0x0000000143a8dbf0 osgUtil::CullVisitor::apply(osg::Transform&)+00000240 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosgUtil.130.dylib+39920 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 15] 0x00000001438b9499 osg::MatrixTransform::accept(osg::NodeVisitor&)+00000121 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosg.130.dylib+803993 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 16] 0x00000001438749ef osg::Group::traverse(osg::NodeVisitor&)+00000047 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosg.130.dylib+522735 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 17] 0x0000000143a8daf2 osgUtil::CullVisitor::apply(osg::Group&)+00000642 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosgUtil.130.dylib+39666 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 18] 0x0000000143876049 osg::Group::accept(osg::NodeVisitor&)+00000121 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosg.130.dylib+528457 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 19] 0x00000001438749ef osg::Group::traverse(osg::NodeVisitor&)+00000047 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosg.130.dylib+522735 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 20] 0x0000000143a8f29d osgUtil::CullVisitor::apply(osg::Camera&)+00003021 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosgUtil.130.dylib+45725 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 21] 0x000000014381c209 osg::Camera::accept(osg::NodeVisitor&)+00000121 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosg.130.dylib+160265 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 22] 0x00000001438749ef osg::Group::traverse(osg::NodeVisitor&)+00000047 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosg.130.dylib+522735 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 23] 0x0000000143a8daf2 osgUtil::CullVisitor::apply(osg::Group&)+00000642 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosgUtil.130.dylib+39666 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 24] 0x0000000143876049 osg::Group::accept(osg::NodeVisitor&)+00000121 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosg.130.dylib+528457 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 25] 0x00000001438749ef osg::Group::traverse(osg::NodeVisitor&)+00000047 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosg.130.dylib+522735 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 26] 0x0000000143b486bb osgUtil::SceneView::cullStage(osg::Matrixd const&, osg::Matrixd const&, osgUtil::CullVisitor*, osgUtil::StateGraph*, osgUtil::RenderStage*, osg::Viewport*)+00002875 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosgUtil.130.dylib+804539 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 27] 0x0000000143b47117 osgUtil::SceneView::cull()+00001399 at /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libosgUtil.130.dylib+798999 (no debugging symbols found)</b></span></p>
<p class="p1"><span class="s1"><b>[ 28] 0x00000001372607da SceneRendererImpl::renderScene(hg::openscenegraph::RenderTimes&, hg::openscenegraph::RenderCounts&, osgUtil::SceneView*, unsigned int) at osgSceneServer.cpp:1448 (in /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libmwosgserver.dylib)</b></span></p>
<p class="p1"><span class="s1"><b>[ 29] 0x000000013725922e hg::openscenegraph::OsgSceneServer::cullAndDraw(int, bool, double, double) at osgSceneServer.cpp:1809 (in /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libmwosgserver.dylib)</b></span></p>
<p class="p1"><span class="s1"><b>[ 30] 0x000000011f298082 UIJ_call_OpenGLPaintFcn(gui_objects::scene_server::SceneServerProxy*, int, bool, double, double) at SceneServerPeerEvents.cpp:56 (in /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libuij.dylib)</b></span></p>
<p class="p1"><span class="s1"><b>[ 31] 0x000000011e589414 Java_com_mathworks_hg_peer_JavaSceneServerPeer_doDisplay at Scene.cpp:129 (in /mathworks/devel/sbs/28/ataylor.Bmlhg_task1.j377265/matlab/bin/maci64/libnativehg.dylib)</b></span></p></div><div>I was wondering if either from the stack trace or my code segments if there is an obvious culprit in terms of my use of MultipassTechnique. I feel like my use is consistent with the pattern established in the shipping example, but I'm a bit stuck at the moment as far as next directions to debug my problem...</div><div><br></div><div>Thanks as always for any help,</div><div><br></div><div>Alex</div><div><br></div><div><br></div><div><br></div><div><br></div></div>