/*========================================================================= Program: bbtk Module: $RCSfile$ Language: C++ Date: $Date$ Version: $Revision$ =========================================================================*/ /* --------------------------------------------------------------------- * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale) * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux * * This software is governed by the CeCILL-B license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/ or redistribute the software under the terms of the CeCILL-B * license as circulated by CEA, CNRS and INRIA at the following URL * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html * or in the file LICENSE.txt. * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited * liability. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-B license and that you accept its terms. * ------------------------------------------------------------------------ */ /** * \file * \brief Class bbtk::wxVtkSceneManager . */ #include "wxVtkSceneManager.h" namespace bbtk { //========================================================================= wxVtkSceneManager::wxVtkSceneManager(wxDropTarget *parent, wxVtk3DBaseView *baseView,int id) { _id=id; _baseView=baseView; if( _baseView!=NULL ) { _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(parent); registerController(this); configureBaseView(); ///// ******* TO ERASE ******* //JUST TO TEST // vtkConeSource *cone = vtkConeSource::New(); cone->SetResolution(10); vtkPolyDataMapper *map = vtkPolyDataMapper::New(); map->SetInput(cone->GetOutput()); vtkActor *act = vtkActor::New(); act->SetMapper(map); vtkPoints *_pts = vtkPoints::New(); _pts->SetNumberOfPoints(4); _pts->SetPoint(0, -1 , -1 , 0 ); _pts->SetPoint(1, 1 , -1 , 0 ); _pts->SetPoint(2, 1 , 1 , 0 ); _pts->SetPoint(3, -1 , 1 , 0 ); vtkCellArray *lines = vtkCellArray::New(); lines->InsertNextCell(5); lines->InsertCellPoint(0); lines->InsertCellPoint(1); lines->InsertCellPoint(2); lines->InsertCellPoint(3); lines->InsertCellPoint(0); vtkPolyData *_pd = vtkPolyData::New(); _pd->SetPoints( _pts ); _pd->SetLines( lines ); vtkActor *_pointVtkActor = vtkActor::New(); vtkPolyDataMapper* _bboxMapper = vtkPolyDataMapper::New(); _bboxMapper->SetInput(_pd); _pointVtkActor->SetMapper(_bboxMapper); getRenderer()->AddActor(_pointVtkActor); // Create a vector text vtkVectorText* vecText = vtkVectorText::New(); vecText->SetText("vtkVectorText"); vtkPolyDataMapper* txtMapper = vtkPolyDataMapper::New(); txtMapper->SetInputConnection( vecText->GetOutputPort()); vtkActor* txtActor = vtkActor::New(); txtActor->SetMapper(txtMapper); //getRenderer()->AddActor(txtActor); // ******* TO ERASE ******* ///////////////////// } } //========================================================================= void wxVtkSceneManager::disconnectDrop() { _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL); } //========================================================================= wxVtkSceneManager::~wxVtkSceneManager() { } //========================================================================= void wxVtkSceneManager::configureBaseView() { vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New(); _baseView->SetInteractorStyleBaseView(interactorstylebaseview); // Important to activate the 2D interaction system wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor(); interactorstylebaseview->SetInteractor ( iren ); iren->SetInteractorStyle(interactorstylebaseview); interactorstylebaseview->SetwxVtkBaseView(_baseView); _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9); _baseView->GetRenderer()->GradientBackgroundOff(); _baseView->Refresh(); } //========================================================================= void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName) { int windowWidth=_baseView->GetRenWin()->GetSize()[0]; int windowHeight=_baseView->GetRenWin()->GetSize()[1]; int type = GBLACKBOX; //Create the MVC Objects GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type); vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type); GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type); BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName); //Prepares the initial model //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height double xx = x; double yy = windowHeight-y; //z value is not important yet, because it is only used a parallel projection double zz = 0; _baseView->TransCoordScreenToWorld(xx,yy,zz); model->setInicPoint(xx,yy,zz); int cantObjects = _objects.size(); cantObjects++; std::stringstream stream; stream << "Object " << cantObjects; std::string arraystring = stream.str(); model->setBBTKName(arraystring); model->setBBTKType(boxName); model->addObserver(view); model->addObserver(this); //Iterate and create the input ports std::map descriptorInMap = descriptor->GetInputDescriptorMap(); std::map::iterator itInput; int i=0; for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) { BlackBoxInputDescriptor *desc = itInput->second; createGInputPort(desc,model,i); i++; } //Iterate and create the output ports std::map descriptorOutMap = descriptor->GetOutputDescriptorMap(); std::map::iterator itOutput; i=0; for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput) { BlackBoxOutputDescriptor *desc = itOutput->second; createGOutputPort(desc,model,i); i++; } //Associates the view with the correspondent renderer and the model. //(NOTE: Refresh is only made by the view) view->setModel(model); view->setBaseView(_baseView); view->initVtkObjects(); //Associates the controller with the correspondent model and view controller->setModelAndView(model,view); //Resgiter change to the observers of the actual model model->setChanged(); model->notifyObservers(); //Register the controller of the new object registerController((InteractorStyleMaracas*) controller); //Add the object to the objects list (only boxes and connectors) _objects.push_back(model); } //========================================================================= void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox, int pos) { int type = GPORT; //Create the MVC Objects GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type); vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type); GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type); model->registerInBox(blackBox,GOUTPUTPORT, pos); blackBox->addOutputPort(model); model->addObserver(view); model->addObserver(this); //Associates the view with the correspondent renderer and the model. //(NOTE: Refresh is only made by the view) view->setModel(model); view->setBaseView(_baseView); view->initVtkObjects(); //Associates the controller with the correspondent model and view controller->setModelAndView(model,view); //Register the controller of the new object registerController((InteractorStyleMaracas*) controller); } //========================================================================= void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos) { int type = GPORT; //Create the MVC Objects GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type); vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type); GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type); model->registerInBox(blackBox,GINPUTPORT,pos); blackBox->addInputPort(model); model->addObserver(view); model->addObserver(this); //Associates the view with the correspondent renderer and the model. //(NOTE: Refresh is only made by the view) view->setModel(model); view->setBaseView(_baseView); view->initVtkObjects(); //Associates the controller with the correspondent model and view controller->setModelAndView(model,view); //Register the controller of the new object registerController((InteractorStyleMaracas*) controller); } //========================================================================= void wxVtkSceneManager::createGConnector(GPortModel* startPort) { manualContourControler* manContourControl = new manualContourControler(); manualViewContour* manViewerContour = new manualViewContour(); manualContourModel* manContourModel = new manualContourModel(); manViewerContour->SetModel( manContourModel ); manViewerContour->SetWxVtkBaseView( _baseView ); manViewerContour->SetRange( 0.5 ); manViewerContour->SetZ( 900 ); manViewerContour->SetColorNormalContour(0, 0, 1); manViewerContour->SetColorEditContour(0.5, 0.5, 0.5); manViewerContour->SetColorSelectContour(1, 0.8, 0); manViewerContour->SetWidthLine(1); manContourControl->SetModelView( manContourModel , manViewerContour ); manContourControl->Configure(); int i,sizeLstPoints = manContourModel->GetSizeLstPoints(); for ( i=0; iAddPoint(); } manContourControl->CreateNewManualContour(); manViewerContour->RefreshContour(); registerController((InteractorStyleMaracas*) manContourControl); } //========================================================================= void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) { vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView(); baseViewControlManager->AddInteractorStyleMaracas( param ); } //========================================================================= vtkRenderer* wxVtkSceneManager::getRenderer() { return _baseView->GetRenderer(); } //========================================================================= vtkRenderWindow* wxVtkSceneManager::getRenderWindow() { return _baseView->GetRenWin(); } //========================================================================= bool wxVtkSceneManager::OnMouseMove() { return true; } //========================================================================= void wxVtkSceneManager::update(int command) { if(command==INIT_CREATION_CONTOUR) { for(int i = 0; i<_objects.size();i++) { if(_objects[i]->getGObjectType() == GBLACKBOX) { GPortModel* startInputPort=((GBlackBoxModel*)_objects[i])->getStartInputPort(); createGConnector(startInputPort); } else { // The others must not react to events } } } } //========================================================================= } // EO namespace bbtk // EOF