Beispiel #1
0
void GSTemple::DrawScene()
{
  if (!m_loadedOk)
    return;

  GetSceneGraph()->GetCamera()->SetFromCamera(m_camera);
  GetSceneGraph()->Draw();
}
//----------------------------------------------------------------------------
void mafViewImageCompound::OnEvent(mafEventBase *maf_event)
//----------------------------------------------------------------------------
{
  switch(maf_event->GetId()) 
  {
		case ID_RANGE_MODIFIED:
			{
				//Windowing
				if(mafVMEImage::SafeDownCast(GetSceneGraph()->GetSelectedVme()))
				{
					double low, hi;
					m_LutSlider->GetSubRange(&low,&hi);
					m_ColorLUT->SetTableRange(low,hi);
					mafEventMacro(mafEvent(this,CAMERA_UPDATE));
				}
			}
			break;
		case ID_LUT_CHOOSER:
			{
				double *sr;
				sr = m_ColorLUT->GetRange();
				m_LutSlider->SetSubRange((long)sr[0],(long)sr[1]);
			}
			break;
    default:
      mafEventMacro(*maf_event);
  }
}
// Initialize scene
bool CEffectViewerScene::Init ()
{
    if (m_bInited)
        return true;

	glewInit();

	m_pRenderer = GetRenderer();
	m_pRenderer->SetViewport(m_ResX, m_ResY, 4.0f, 4500.0f, 0.67f);

	m_pResourceMgr = GetResourceMgr();
	m_pSg = GetSceneGraph();
	m_pCamera = m_pRenderer->GetCamera();
	m_pActorMgr = GetActorManager();

	UpdateCamera();

	OGVec3 vLightDir = OGVec3(0,1,0);
	OGVec4 vLightColor = OGVec4(1,1,1,1);
	IOGLight* pMainLight = m_pRenderer->GetLightMgr()->CreateLight();
	pMainLight->type = OG_LIGHT_DIRECTIONAL;
	pMainLight->vPosition = vLightDir;
	pMainLight->fIntensity = 100.0f;
	pMainLight->vAmbientColor = OGVec4(vLightColor.x, vLightColor.y, vLightColor.z, 1.0f);
	pMainLight->vDiffuseColor = OGVec4(vLightColor.x, vLightColor.y, vLightColor.z, 1.0f);
	pMainLight->vSpecularColor = OGVec4(vLightColor.x, vLightColor.y, vLightColor.z, 1.0f);

	glDisable(GL_CULL_FACE);
	glEnable(GL_NORMALIZE);

	if (m_pResourceMgr->Load(OG_RESPOOL_GAME) == false)
	{
        return false;
	}

	if (GetActorParamsMgr()->Init() == false)
	{
        return false;
	}

	const std::map<std::string, EffectItem>& effects = GetEffectsManager()->GetEffectsList();
	std::map<std::string, EffectItem>::const_iterator iter = effects.begin();
	for (; iter != effects.end(); ++iter)
	{
		CommonToolEvent<ResLoadEventData> cmd(EVENTID_RESLOAD);
		cmd.SetEventCustomData(ResLoadEventData(wxT(iter->first.c_str()), 
			wxT("Effects"),
			wxT("")));
		GetEventHandlersTable()->FireEvent(EVENTID_RESLOAD, &cmd);
	}

	SetupEffect(NULL);
    m_bInited = true;

	return true;
}
//----------------------------------------------------------------------------
void mafViewImageCompound::VmeShow(mafNode *node, bool show)
//----------------------------------------------------------------------------
{
	for(int i=0; i<this->GetNumberOfSubView(); i++)
    m_ChildViewList[i]->VmeShow(node, show);

	if(GetSceneGraph()->GetSelectedVme()==node)
	{
    mafPipeImage3D *pipe = (mafPipeImage3D *)m_ChildViewList[ID_VIEW_IMAGE]->GetNodePipe(node);
		UpdateWindowing(show && pipe && pipe->IsGrayImage(),node);
	}

	mafEventMacro(mafEvent(this,CAMERA_UPDATE));
}
Beispiel #5
0
void V4SceneManager::CreateIDandAddToPool(GF_Node *node)
{
	// gets a node ID
	u32 id = gf_sg_get_next_available_node_id(GetSceneGraph());

	char d[10]; // supposes no more than 1 000 000 000 objects

	// queries the pool to know which number to use for the name
	itoa(pools.GetCount(gf_node_get_tag(node)), d, 10); 

	char c[50];
	strcpy(c, gf_node_get_class_name(node));
	strncat(c, "_", 1);
	strncat(c, d, 10);

	gf_node_set_id(node, id, c); // assigns NodeID and name
	pools.Add(node); // adds to the node pool

}
//----------------------------------------------------------------------------
void mafViewOrthoSlice::OnEvent(mafEventBase *maf_event)
//----------------------------------------------------------------------------
{
  if (mafEvent *e = mafEvent::SafeDownCast(maf_event))
  {
    switch(e->GetId()) 
    {
  /*    case ID_SIDE_ORTHO:
      {          
        if (m_Side == 1)
        {
          ((mafViewSlice *)m_ChildViewList[CHILD_XN_VIEW])->CameraSet(CAMERA_RX_RIGHT);
          ((mafViewSlice*)m_ChildViewList[CHILD_XN_VIEW])->CameraUpdate();
        }
        else
        {
          ((mafViewSlice *)m_ChildViewList[CHILD_XN_VIEW])->CameraSet(CAMERA_RX_LEFT);
          ((mafViewSlice*)m_ChildViewList[CHILD_XN_VIEW])->CameraUpdate();
        }
      }
      break;*/
			case ID_BORDER_CHANGE:
			{
				OnEventSetThickness();
			}
			break;
			case ID_ALL_SURFACE:
			{
				if(m_AllSurface)
				{
					mafNode* node=GetSceneGraph()->GetSelectedVme();
					mafVME* vme=(mafVME*)node;
					mafNode* root=vme->GetRoot();
					SetThicknessForAllSurfaceSlices(root);
				}
			}
			break;
      case ID_LUT_CHOOSER:
      {
        mmaVolumeMaterial *currentVolumeMaterial = ((mafVMEOutputVolume *)m_CurrentVolume->GetOutput())->GetMaterial();
        currentVolumeMaterial->UpdateFromTables();
        for(int i=0; i<m_NumOfChildView; i++)
        {
          mafPipeVolumeSlice_BES *p = (mafPipeVolumeSlice_BES *)((mafViewSlice *)m_ChildViewList[i])->GetNodePipe(m_CurrentVolume);
          p->SetColorLookupTable(m_ColorLUT);
        }
        double *sr;
        sr = m_ColorLUT->GetRange();
        m_LutSlider->SetSubRange((long)sr[0],(long)sr[1]);
        CameraUpdate();
      }
      break;
      case ID_RANGE_MODIFIED:
      {
        if(((mafViewSlice *)m_ChildViewList[0])->VolumeIsVisible())
        {
          double low, hi;
          m_LutSlider->GetSubRange(&low,&hi);
          m_ColorLUT->SetTableRange(low,hi);
          mmaVolumeMaterial *currentVolumeMaterial = ((mafVMEOutputVolume *)m_CurrentVolume->GetOutput())->GetMaterial();
          currentVolumeMaterial->UpdateFromTables();
          CameraUpdate();
        }
      }
      break;
      case MOUSE_UP:
      case MOUSE_MOVE:
      {
        // get the gizmo that is being moved
        long gizmoId = e->GetArg();
        double pos[3];
        vtkPoints *p = (vtkPoints *)e->GetVtkObj();
        if(p == NULL) return;
        p->GetPoint(0,pos);
        this->SetSlicePosition(gizmoId, p);
      }
      break;
			case ID_SNAP:
			{
				if(this->m_CurrentVolume==NULL && m_Snap)
				{
					wxMessageBox("You can't switch to snap modality!");
					m_Snap=0;
					m_Gui->Update();
				}
				else
				{
					for(int i=GIZMO_XN; i<GIZMOS_NUMBER; i++)
					{
						if(m_Snap==1)
							m_Gizmo[i]->SetGizmoMovingModalityToSnap();
						else
							m_Gizmo[i]->SetGizmoMovingModalityToBound();
					}
				}
			}
			break;
      case ID_RESET_SLICES:
      {
        assert(m_CurrentVolume);
        this->ResetSlicesPosition(m_CurrentVolume);
      }
      break;
      // Added by Losi 11.25.2009
      case ID_ENABLE_GPU:
        {
          if (m_CurrentVolume)
          {
            for(int i=0; i<m_NumOfChildView; i++)
            {
              mafPipeVolumeSlice_BES *p = NULL;
              p = mafPipeVolumeSlice_BES::SafeDownCast(((mafViewSlice *)m_ChildViewList[i])->GetNodePipe(m_CurrentVolume));
              if (p)
              {
                p->SetEnableGPU(m_EnableGPU);
              }
            }
            this->CameraUpdate();
          }
        }
        break;
      case ID_TRILINEAR_INTERPOLATION:
        {
          if (m_CurrentVolume)
          {
            for(int i=0; i<m_NumOfChildView; i++)
            {
              mafPipeVolumeSlice_BES *p = NULL;
              p = mafPipeVolumeSlice_BES::SafeDownCast(((mafViewSlice *)m_ChildViewList[i])->GetNodePipe(m_CurrentVolume));
              if (p)
              {
                p->SetTrilinearInterpolation(m_TrilinearInterpolationOn);
              }
            }
            this->CameraUpdate();
          }
        }
        break;
      default:
        mafViewCompound::OnEvent(maf_event);
    }
  }
}
Beispiel #7
0
//----------------------------------------------------------------------------
void mafViewRXCT::OnEvent(mafEventBase *maf_event)
//----------------------------------------------------------------------------
{
  if (mafEvent *e = mafEvent::SafeDownCast(maf_event))
  {
    switch(maf_event->GetId()) 
    { 
      // events from the slider
      case ID_RANGE_MODIFIED:
      {
        OnEventRangeModified(maf_event);
      }
      break;

	  case ID_HELP:
	  {
		mafEvent helpEvent;
		helpEvent.SetSender(this);
		mafString viewLabel = this->m_Label;
		helpEvent.SetString(&viewLabel);
		helpEvent.SetId(OPEN_HELP_PAGE);
		mafEventMacro(helpEvent);
	  }
	  break;

      case ID_SNAP:
      {
        OnEventSnapModality();
      }
      case ID_RIGHT_OR_LEFT:
        {
          if (m_RightOrLeft==0)
          {
            ((mafViewRX *)m_ChildViewList[RX_SIDE_VIEW])->CameraSet(CAMERA_RX_RIGHT);
          }
          else
            ((mafViewRX *)m_ChildViewList[RX_SIDE_VIEW])->CameraSet(CAMERA_RX_LEFT);
        }
      break;

      case MOUSE_UP:
      case MOUSE_MOVE:
      {
        OnEventMouseMove(e);
      }
      break;

      case ID_ADJUST_SLICES:
        {
          OnEventSortSlices();
        }
        break;
        
      case ID_BORDER_CHANGE:
      {
        OnEventSetThickness();
      }
      break;

      case ID_RESET_SLICES:
        {
          assert(m_CurrentVolume);
          this->ResetSlicesPosition(m_CurrentVolume);
        }
        break;
      // Added by Losi 11.25.2009
      case ID_ENABLE_GPU:
        {
          if (m_CurrentVolume)
          {
            for(int i=0; i<CT_CHILD_VIEWS_NUMBER; i++)
            {
              mafPipeVolumeSlice_BES *p = NULL;
              p = mafPipeVolumeSlice_BES::SafeDownCast(((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(i))->GetNodePipe(m_CurrentVolume));
              if (p)
              {
                p->SetEnableGPU(m_EnableGPU);
              }
            }
            this->CameraUpdate();
          }

          for (int i=0;i<CT_CHILD_VIEWS_NUMBER;i++)
          {
          	((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(i))->SetEnableGPU(m_EnableGPU);
          }
        }
        break;
      case ID_TRILINEAR_INTERPOLATION:
        {
          if (m_CurrentVolume)
          {
            for(int i=0; i<CT_CHILD_VIEWS_NUMBER; i++)
            {
              mafPipeVolumeSlice_BES *p = NULL;
              p = mafPipeVolumeSlice_BES::SafeDownCast(((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(i))->GetNodePipe(m_CurrentVolume));
              if (p)
              {
                p->SetTrilinearInterpolation(m_TrilinearInterpolationOn);
              }
            }
            mafPipeVolumeSlice_BES *p = NULL;
            p = mafPipeVolumeSlice_BES::SafeDownCast(((mafViewSlice *)((mafViewCompound *)m_ChildViewList[RX_SIDE_VIEW]))->GetNodePipe(m_CurrentVolume));
            if (p)
            {
              p->SetTrilinearInterpolation(m_TrilinearInterpolationOn);
            }
            p = mafPipeVolumeSlice_BES::SafeDownCast(((mafViewSlice *)((mafViewCompound *)m_ChildViewList[RX_FRONT_VIEW]))->GetNodePipe(m_CurrentVolume));
            if (p)
            {
              p->SetTrilinearInterpolation(m_TrilinearInterpolationOn);
            }
            this->CameraUpdate();
          }

          for (int i=0;i<CT_CHILD_VIEWS_NUMBER;i++)
          {
            ((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW]))->SetTrilinearInterpolation(m_TrilinearInterpolationOn);
          }
        }
        break;
      case ID_ALL_SURFACE:
      {
        if(m_AllSurface)
        {
          mafNode* node=GetSceneGraph()->GetSelectedVme();
          mafVME* vme=(mafVME*)node;
          mafNode* root=vme->GetRoot();
          SetThicknessForAllSurfaceSlices(root);
        }
      }

      default:
      mafViewCompound::OnEvent(maf_event);
    }
  }
  else
  {
    mafViewCompound::OnEvent(maf_event);
  }
}
Beispiel #8
0
//----------------------------------------------------------------------------
void mafViewRXCT::OnEventSortSlices()
//----------------------------------------------------------------------------
{
  mafNode* node=GetSceneGraph()->GetSelectedVme();
  mafPipe *p=((mafViewRX *)m_ChildViewList[0])->GetNodePipe(node);
  if(((mafVME *)node)->GetOutput()->IsA("mafVMEOutputVolume"))
    mafLogMessage("SURFACE NOT SELECTED");
  else  if (node->IsMAFType(mafVMESurface))
  {
    double center[3],b[6],step;
    mafVMESurface *surface=(mafVMESurface*)node;
    surface->GetOutput()->GetBounds(b);
    step = (b[5]-b[4])/7.0;
    center[0]=0;
    center[1]=0;
    for (int currChildCTView=0; currChildCTView < CT_CHILD_VIEWS_NUMBER; currChildCTView++)
    {
      if(m_GizmoSlice[currChildCTView])
      {
        center[2] = b[5]-step*(currChildCTView+1);
        center[2] = center[2] > b[5] ? b[5] : center[2];
        center[2] = center[2] < b[4] ? b[4] : center[2];
        m_GizmoSlice[currChildCTView]->CreateGizmoSliceInLocalPositionOnAxis(currChildCTView,mafGizmoSlice::GIZMO_SLICE_Z,center[2]);
        m_Pos[currChildCTView]=center[2];
        m_Sort[currChildCTView]=currChildCTView;
        ((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(currChildCTView))->SetSliceLocalOrigin(center);
        ((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(currChildCTView))->SetTextColor(m_BorderColor[currChildCTView]);
        ((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(currChildCTView))->UpdateText();
        ((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(currChildCTView))->BorderCreate(m_BorderColor[currChildCTView]);
        ((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(currChildCTView))->CameraUpdate();
      }
    }
    m_ChildViewList[RX_FRONT_VIEW]->CameraUpdate();
    m_ChildViewList[RX_SIDE_VIEW]->CameraUpdate();
  }
	else if (node->IsMAFType(mafVMESurfaceParametric))
	{
		double center[3],b[6],step;
		mafVMESurfaceParametric *surface=(mafVMESurfaceParametric*)node;
		surface->GetOutput()->GetBounds(b);
		step = (b[5]-b[4])/7.0;
		center[0]=0;
		center[1]=0;
		for (int currChildCTView=0; currChildCTView < CT_CHILD_VIEWS_NUMBER; currChildCTView++)
		{
			if(m_GizmoSlice[currChildCTView])
			{
				center[2] = b[5]-step*(currChildCTView+1);
				center[2] = center[2] > b[5] ? b[5] : center[2];
				center[2] = center[2] < b[4] ? b[4] : center[2];
				m_GizmoSlice[currChildCTView]->CreateGizmoSliceInLocalPositionOnAxis(currChildCTView,mafGizmoSlice::GIZMO_SLICE_Z,center[2]);
				m_Pos[currChildCTView]=center[2];
				m_Sort[currChildCTView]=currChildCTView;
				((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(currChildCTView))->SetSliceLocalOrigin(center);
				((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(currChildCTView))->SetTextColor(m_BorderColor[currChildCTView]);
				((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(currChildCTView))->UpdateText();
				((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(currChildCTView))->BorderCreate(m_BorderColor[currChildCTView]);
				((mafViewSlice *)((mafViewCompound *)m_ChildViewList[CT_COMPOUND_VIEW])->GetSubView(currChildCTView))->CameraUpdate();
			}
		}
		m_ChildViewList[RX_FRONT_VIEW]->CameraUpdate();
		m_ChildViewList[RX_SIDE_VIEW]->CameraUpdate();
	}
}
// Initialize scene
bool CViewerScene::Init ()
{
    if (m_bInited)
        return true;

    glewInit();

    m_pRenderer = GetRenderer();
    m_pRenderer->SetViewport(m_ResX, m_ResY, 4.0f, 4500.0f, 0.67f);

    m_pResourceMgr = GetResourceMgr();
    m_pSg = GetSceneGraph();
    m_pCamera = m_pRenderer->GetCamera();
    m_pActorMgr = GetActorManager();

    OGVec3 vTarget (0, 0, 0);
    OGVec3 vDir (0, -1.0f, 0.4f);
    vDir = vDir.normalize();
    OGVec3 vUp = vDir.cross (OGVec3(1, 0, 0));
    m_pCamera->Setup (vTarget - (vDir*m_fCameraDistance), vTarget, vUp);

    OGVec3 vLightDir = OGVec3(0,1,0);
    OGVec4 vLightColor = OGVec4(1,1,1,1);
    IOGLight* pMainLight = m_pRenderer->GetLightMgr()->CreateLight();
    pMainLight->type = OG_LIGHT_DIRECTIONAL;
    pMainLight->vPosition = vLightDir;
    pMainLight->fIntensity = 100.0f;
    pMainLight->vAmbientColor = OGVec4(vLightColor.x, vLightColor.y, vLightColor.z, 1.0f);
    pMainLight->vDiffuseColor = OGVec4(vLightColor.x, vLightColor.y, vLightColor.z, 1.0f);
    pMainLight->vSpecularColor = OGVec4(vLightColor.x, vLightColor.y, vLightColor.z, 1.0f);

    glDisable(GL_CULL_FACE);
    glEnable(GL_NORMALIZE);

    if (m_pResourceMgr->Load(OG_RESPOOL_GAME) == false)
    {
        return false;
    }

    if (GetActorParamsMgr()->Init())
    {
        std::list<IOGActorParams*> ActorsParamsList;
        GetActorParamsMgr()->GetParamsList(ActorsParamsList);
        std::list<IOGActorParams*>::const_iterator iter = ActorsParamsList.begin();
        for (; iter != ActorsParamsList.end(); ++iter)
        {
            if ((*iter)->type == OG_ACTOR_MISSILE ||
                (*iter)->type == OG_ACTOR_PLASMAMISSILE ||
                (*iter)->type == OG_ACTOR_GAUSSRAY )
            {
                continue;
            }

            CommonToolEvent<ResLoadEventData> cmd(EVENTID_RESLOAD);
            cmd.SetEventCustomData(ResLoadEventData(wxT((*iter)->alias.c_str()), 
                wxT(ActorTypeToGroupName((*iter)->type).c_str()),
                wxT((*iter)->icon.c_str())));
            GetEventHandlersTable()->FireEvent(EVENTID_RESLOAD, &cmd);
        }
    }
    else
    {
        return false;
    }

    SetupModel(NULL);
    m_bInited = true;

    return true;
}