SbBool
SoXipOverlayTransformBoxManip::computeSelectionXBoundingBox( SoGLRenderAction* action )
{
	mXBoundingBox.makeEmpty();

	const SoFullPath* path = (SoFullPath *) action->getCurPath();
	SoNode* searchRoot = path->getNodeFromTail( numNodesUpToContainer.getValue() );
	SoNodeList shapes = XipOverlayUtils::getManipulableShapes( searchRoot, TRUE );

	int numShapes = shapes.getLength();

	// Don't display if the shape the transformBox is applied to is filtered
	if ( (numShapes == 1) && 
		!SoXipOverlayFilterElement::isOn( action->getState(), ((SoXipManipulableShape *)shapes[0])->label ) )
	{
		return mXBoundingBox.isEmpty();
	}
	

	for( int i = 0; i < numShapes; ++ i )
	{
		SoXipManipulableShape* shape = (SoXipManipulableShape *) shapes[i];

		SbXfBox3f newbox;
		shape->computeXBoundingBox( newbox );

		mXBoundingBox.extendBy( newbox );
	}

	return !mXBoundingBox.isEmpty();
}
void
SoXipImageOverlayManager::loadOverlays()
{
	// When the patient changes
	clearClipboard();

	// Remove all the geometries from the switch
	mShapeSwitch->removeAllChildren();
	mShapeSwitch->whichChild.setValue(-1);

	mCurrentSlice = -1;

	if( mImageData )
	{
		SbString overlayStr = mImageData->getProperty( "overlays" );
		SoNodeList nodes = XipOverlayUtils::loadOverlaysFromString( overlayStr.getString(), overlayStr.getLength(), TRUE );

		for( int i = 0; i < nodes.getLength(); ++ i )
		{
			if( !nodes[i]->isOfType( SoXipShapeList::getClassTypeId() ) )
			{
				SoDebugError::post( __FILE__, "Invalid overlay node found in Dicom. Ignored." );				
				continue ;
			}
			mShapeSwitch->addChild( nodes[i] );
		}
	}

	updateSliceMap();
}
SoNodeList Renderer::getChildByName(SoSeparator * ivRoot, SbName & childName,
                                            SoType targetType, int maxResultsExpected)
{
    assert(ivRoot);
    SoNodeList resultList;

    SoSearchAction sa;
    sa.setSearchingAll(true);

    sa.setType(targetType, true);
    sa.setInterest( SoSearchAction::ALL);
    sa.setName(childName);
    sa.setFind(SoSearchAction::NAME);
    sa.apply(ivRoot);

    SoPathList &pathList = sa.getPaths();
    int numPaths = pathList.getLength();
    if (numPaths > maxResultsExpected)
    {
        //DBGA(this->className() << "::getChildByName::Found too many children of node: "
        //     << ivRoot->getName().getString()  << " with name: "
        //     <<childName.getString() << " " );
        //DBGA(this->className() << "::getChildByName:: Expected:" << maxResultsExpected
        //     << " Found:" << numPaths);
        //resultList.append(static_cast<SoNode *>(NULL));
        return resultList;
    }

    for(int i = 0; i < numPaths; ++i)
    {
        resultList.append(pathList[i]->getTail());
    }
    return resultList;
}
 SoSeparator * Renderer::getOrAddSeparator(SoSeparator * ivRoot, SbName & childName)
{
    SoNodeList children = getChildByName(ivRoot, childName);
    if(children.getLength())
        return static_cast<SoSeparator *>(children[0]);
    else
    {
        SoSeparator * newChild = new SoSeparator();
        newChild->setName(childName);
        ivRoot->addChild(newChild);
        return newChild;
    }
}
示例#5
0
文件: SoNode.cpp 项目: Alexpux/Coin3D
/*!
  Finds all nodes with \a name and appends them to the \a l nodelist.
  Returns the number of nodes with the specified name.

  \sa SoBase::setName()
*/
int
SoNode::getByName(const SbName & name, SoNodeList & l)
{
  SoBaseList bl;
  int nr = SoBase::getNamedBases(name, bl, SoNode::getClassTypeId());
  for (int i=0; i < nr; i++) l.append((SoNode *)bl[i]);
  return nr;
}
示例#6
0
SoNode *
SoToVRMLActionP::search_for_node(SoNode * root, const SbName & name, const SoType & type)
{
  SoNodeList mylist;
  if (name == SbName::empty()) return NULL;

  mylist.truncate(0);
  int num = SoNode::getByName(name, mylist);
  int cnt = 0;
  SoNode * retnode = NULL;
  for (int i = 0; i < num; i++) {
    SoNode * node = mylist[i];
    if (node->getTypeId() == type) {
      retnode = node;
      cnt++;
    }
  }

  // if there is only one node with that name, return it
  if (retnode && cnt == 1) return retnode;
  if (!retnode) return NULL;

  this->searchaction.setSearchingAll(TRUE);
  this->searchaction.setName(name);
  this->searchaction.setType(type);
  this->searchaction.setInterest(SoSearchAction::LAST);
  this->searchaction.setFind(SoSearchAction::TYPE|SoSearchAction::NAME);

#ifdef HAVE_NODEKITS
  SbBool old = SoBaseKit::isSearchingChildren();
  SoBaseKit::setSearchingChildren(TRUE);
#endif // HAVE_NODEKITS

  this->searchaction.apply(root);
  SoNode * tail = NULL;
  SoFullPath * path = reclassify_cast<SoFullPath*>(this->searchaction.getPath());
  if (path) {
    tail = path->getTail();
  }
  this->searchaction.reset();
#ifdef HAVE_NODEKITS
  SoBaseKit::setSearchingChildren(old);
#endif // HAVE_NODEKITS
  return tail;
}
示例#7
0
文件: modlist.cpp 项目: DundalkIT/pcp
void 
ModList::refresh(bool fetchFlag)
{
    for (int i = 0; i < _list.size(); i++)
	_list[i]->refresh(fetchFlag);
    for (int n=elementalNodeList.getLength()-1; n >= 0; n--) {
	elementalNodeList[n]->doAction(_viewer->getGLRenderAction());
    }
}
void 
SoXipImageOverlayManager::saveOverlays()
{
	if( mImageData )
	{
		SoNodeList overlays;
		for( int i = 0; i < mShapeSwitch->getNumChildren(); ++ i )
		{
			SoXipShapeList* shapeList = (SoXipShapeList *) mShapeSwitch->getChild(i);
			if( !shapeList )
			{
				SoDebugError::post( __FILE__, "Warning. Should not have NULL pointer in list of overlays" );
				continue ;
			}

			if( shapeList->getNumChildren() )
				overlays.append( shapeList );
		}

		SbString overlayStr = XipOverlayUtils::saveOverlaysToString( overlays );
		mImageData->setProperty( "overlays", overlayStr );
	}
}
void
SoXipImageOverlayManager::updateOverlays( SoAction* action )
{
	if( imageChanged( action ) )
	{
		this->saveOverlays();

		if( mImageData )
		{
			mImageData->unref();		
			mImageData = 0;
		}

		SoXipDataImage* eltData = SoXipDataImageElement::get( action->getState() );

		// Reset the current slice to force the update
		mCurrentSlice = -1;

		if( eltData )
		{
			// Get reference image
			SoXipDataImage* refData = 0;
			SoXipDataImage* eltData = SoXipDataImageElement::get( action->getState() );
	
			while( (refData = (SoXipDataImage *) eltData->getRefByType( SoXipDataImage::getClassTypeId() )) )
				eltData = refData;

			mImageData = eltData;
			mImageData->ref();

			// retrieve ROI overlay from Dicom
			this->loadOverlays();
		}
	}

	int sliceIndex = SoXipDataImageElement::getSliceIndex( action->getState() );
	if( sliceIndex != mCurrentSlice )
	{
		// When switching to a different slice, unselect all the shapes that were
		// previously selected.
		SoNodeList selection = XipOverlayUtils::getTopLevelShapes( mShapeSwitch, TRUE );	

		for( int i = 0; i < selection.getLength(); ++ i )
			((SoXipShape *) selection[i])->select( FALSE );

		mSelection.truncate(0);

		SoXipShapeList* sliceShapeList = mSliceMap[ sliceIndex ];
		if( sliceShapeList )
		{
			mShapeSwitch->whichChild.setValue( mShapeSwitch->findChild( sliceShapeList ) );
		}
		else
		{
			sliceShapeList = new SoXipShapeList;
			sliceShapeList->label.setValue( SbString( sliceIndex ) );
			
			mShapeSwitch->addChild( sliceShapeList );
			mShapeSwitch->whichChild.setValue( mShapeSwitch->getNumChildren() - 1 );

			mSliceMap[ sliceIndex ] = sliceShapeList;
		}

		mCurrentSlice = sliceIndex;
	}
}
示例#10
0
static float
timeRendering(Options &options,
	      const SbViewportRegion &vpr,
	      SoSeparator *&root)
//
//////////////////////////////////////////////////////////////
{
    SbTime 		timeDiff, startTime;
    int 		frameIndex;
    SoTransform		*sceneTransform;
    SoGLRenderAction 	ra(vpr);
    SoNodeList		noCacheList;
    SoSeparator 	*newRoot;

    // clear the window
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //
    // reset autocaching threshold before each experiment
    //   done by replacing every separator in the scene graph
    //   with a new one
    //
    newRoot = (SoSeparator *) replaceSeparators(root);
    newRoot->ref();
    newRoot->renderCaching = SoSeparator::OFF;

    // get a list of separators marked as being touched by the application
    newRoot->getByName(NO_CACHE_NAME, noCacheList);

    // find the transform node that spins the scene
    SoNodeList	xformList;
    newRoot->getByName(SCENE_XFORM_NAME, xformList);
    sceneTransform = (SoTransform *) xformList[0];

    if (options.noMaterials) {  // nuke material node
	removeNodes(newRoot, SoMaterial::getClassTypeId());
	removeNodes(newRoot, SoPackedColor::getClassTypeId());
	removeNodes(newRoot, SoBaseColor::getClassTypeId());
    }

    if (options.noXforms) {  // nuke transforms
	removeNodes(newRoot, SoTransformation::getClassTypeId());
    }

    if (options.noTextures || options.oneTexture) {  // override texture node

	removeNodes(newRoot, SoTexture2::getClassTypeId());

	if (options.oneTexture) {
	    // texture node with simple texture
	    static unsigned char img[] = {
		255, 255, 0, 0,
		255, 255, 0, 0,
		0, 0, 255, 255,
		0, 0, 255, 255
		};
	    SoTexture2 *overrideTex = new SoTexture2;	
	    overrideTex->image.setValue(SbVec2s(4, 4), 1, img);
	    newRoot->insertChild(overrideTex, 1);
	}
    }

    if (options.noFill) {  // draw as points
	SoDrawStyle *overrideFill = new SoDrawStyle;
	overrideFill->style.setValue(SoDrawStyle::POINTS);
	overrideFill->lineWidth.setIgnored(TRUE);
	overrideFill->linePattern.setIgnored(TRUE);
	overrideFill->setOverride(TRUE);
	newRoot->insertChild(overrideFill, 0);

	// cull backfaces so that extra points don't get drawn
	SoShapeHints *cullBackfaces = new SoShapeHints;
	cullBackfaces->shapeType = SoShapeHints::SOLID;
	cullBackfaces->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
	cullBackfaces->setOverride(TRUE);
	newRoot->insertChild(cullBackfaces, 0);
    }

    if (options.noVtxXforms) {  // draw invisible
	SoDrawStyle *overrideVtxXforms = new SoDrawStyle;
	overrideVtxXforms->style.setValue(SoDrawStyle::INVISIBLE);
	overrideVtxXforms->setOverride(TRUE);
	newRoot->insertChild(overrideVtxXforms, 0);
    }

    if (options.noLights) {  // set lighting model to base color
	SoLightModel *baseColor = new SoLightModel;
	baseColor->model = SoLightModel::BASE_COLOR;
	newRoot->insertChild(baseColor, 0);
    }
 
    for (frameIndex = 0; ; frameIndex++) {

	// wait till autocaching has kicked in then start timing
	if (frameIndex == NUM_FRAMES_AUTO_CACHING)
	    startTime = SbTime::getTimeOfDay();

	// stop timing and exit loop when requisite number of
	//    frames have been drawn
	if (frameIndex == options.numFrames + NUM_FRAMES_AUTO_CACHING) {
	    glFinish();
	    timeDiff = SbTime::getTimeOfDay() - startTime;
	    break;
	}
	    
	// if not frozen, update realTime and destroy labelled caches
	if (! options.freeze) { 

	    // update realTime 
	    SoSFTime *realTime = (SoSFTime *) SoDB::getGlobalField("realTime");
	    realTime->setValue(SbTime::getTimeOfDay());

	    // touch the separators marked NoCache 
	    for (int i=0; i<noCacheList.getLength(); i++)
		((SoSeparator *) noCacheList[i])->getChild(0)->touch();
	}

	// Rotate the scene
	sceneTransform->rotation.setValue(SbVec3f(1, 1, 1), 
                           frameIndex * 2 * M_PI / options.numFrames);

	if (! options.noClear)
	    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	ra.apply(newRoot);
    }

    // Get rid of newRoot
    newRoot->unref();

    return (timeDiff.getValue() / options.numFrames);
}