1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::wxVtkSceneManager .
37 #include "wxVtkSceneManager.h"
43 //=========================================================================
44 wxVtkSceneManager::wxVtkSceneManager(wxDropTarget *parent, wxVtk3DBaseView *baseView,int idManager)
53 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(parent);
54 registerController(this);
56 _worldState=NOTHING_HAPPENS;
64 //=========================================================================
66 void wxVtkSceneManager::disconnectDrop()
68 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
71 //=========================================================================
73 wxVtkSceneManager::~wxVtkSceneManager()
77 //=========================================================================
79 void wxVtkSceneManager::configureBaseView()
81 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
83 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
85 // Important to activate the 2D interaction system
86 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
87 interactorstylebaseview->SetInteractor ( iren );
88 iren->SetInteractorStyle(interactorstylebaseview);
89 interactorstylebaseview->SetwxVtkBaseView(_baseView);
91 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
92 _baseView->GetRenderer()->ResetCamera(-100,100,-100,100,900,1000);
94 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
95 _baseView->GetRenderer()->GradientBackgroundOff();
99 //=========================================================================
101 void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
104 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
105 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
107 int type = GBLACKBOX;
109 //Create the MVC Objects
111 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
112 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
113 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
115 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
117 //Prepares the initial model
118 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
121 double yy = windowHeight-y;
123 //z value is not important yet, because it is only used a parallel projection
126 _baseView->TransCoordScreenToWorld(xx,yy,zz);
127 model->setInicPoint(xx,yy,zz);
130 std::stringstream stream;
134 stream << "Box0" << _numBoxes;
138 stream << "Box" << _numBoxes;
140 std::string arraystring = stream.str();
142 model->setBBTKName(arraystring);
143 model->setBBTKType(boxName);
145 model->addObserver(view);
146 model->addObserver(this);
148 //Iterate and create the input ports
149 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
150 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
153 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
155 BlackBoxInputDescriptor *desc = itInput->second;
156 createGInputPort(GINPUTPORT,i,model,desc);
160 //Iterate and create the output ports
161 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
162 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
165 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
167 BlackBoxOutputDescriptor *desc = itOutput->second;
168 createGOutputPort(GOUTPUTPORT,i,model,desc);
173 //Associates the view with the correspondent renderer and the model.
174 //(NOTE: Refresh is only made by the view)
175 view->setModel(model);
176 view->setBaseView(_baseView);
177 view->initVtkObjects();
179 //Associates the controller with the correspondent model and view
180 controller->setModelAndView(model,view);
182 //Resgiter change to the observers of the actual model
183 model->notifyObservers(_idManager);
185 //Register the controller of the new object
186 registerController((InteractorStyleMaracas*) controller);
188 //Add the object to the objects list
189 int newId = _controllers.size();
190 controller->setId(newId);
191 _controllers[newId] = controller;
195 //=========================================================================
197 void wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc)
199 createGPort(portType,posinBox,blackBox);
202 //=========================================================================
204 void wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
206 createGPort(portType,posinBox,blackBox);
209 //=========================================================================
211 void wxVtkSceneManager::createGPort(int portType, int posInBox,GBlackBoxModel *blackBox)
215 //Create the MVC Objects
216 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
217 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
218 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
220 model->registerInBox(blackBox,portType, posInBox);
221 blackBox->addOutputPort(model);
223 model->addObserver(view);
224 model->addObserver(this);
226 //Associates the view with the correspondent renderer and the model.
227 //(NOTE: Refresh is only made by the view)
228 view->setModel(model);
229 view->setBaseView(_baseView);
230 view->initVtkObjects();
232 //Associates the controller with the correspondent model and view
233 controller->setModelAndView(model,view);
235 model->notifyObservers(_idManager);
237 //Register the controller of the new object
238 registerController((InteractorStyleMaracas*) controller);
240 int newId = _controllers.size();
241 controller->setId(newId);
242 _controllers[newId] = controller;
245 //=========================================================================
247 void wxVtkSceneManager::createGConnector(GPortModel* startPort)
249 int type = GCONNECTOR;
251 manualConnectorContourController* manContourControl = new manualConnectorContourController();
252 manualConnectorContourView* manContourView = new manualConnectorContourView();
253 manualContourModel* manContourModel = new manualContourModel();
255 GConnectorController* connectorcontroller = new GConnectorController();
256 GConnectorModel* connectorModel = new GConnectorModel();
257 GConnectorView* connectorView = new GConnectorView();
258 connectorModel->setGObjectType(type);
260 manContourModel->SetCloseContour(false);
261 connectorModel->setStartPort(startPort);
263 manContourView->SetModel( manContourModel );
264 manContourView->SetWxVtkBaseView( _baseView );
265 manContourView->SetRange( 0.5 );
266 manContourView->SetZ( 900 );
268 manContourView->SetColorNormalContour(0, 0, 1);
269 manContourView->SetColorEditContour(0.5, 0.5, 0.5);
270 manContourView->SetColorSelectContour(1, 0.8, 0);
271 manContourView->SetWidthLine(1);
273 manContourControl->SetModelView( manContourModel , manContourView );
275 manContourControl->CreateNewManualContour();
277 manContourView->RefreshContour();
281 connectorModel->getInicPoint(x,y,z);
283 manContourControl->SetState(1);
284 manContourModel->SetCloseContour(false);
286 manContourModel->AddPoint(x,y,z);
287 manContourView->AddPoint();
289 manContourModel->AddPoint(x,y,z);
290 manContourView->AddPoint();
292 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
293 manContourControl->_bakIdPoint=bak;
294 manContourView->Refresh();
296 manContourControl->SetMoving( false );
298 registerController((InteractorStyleMaracas*) connectorcontroller);
300 connectorcontroller->setManualContourController(manContourControl);
301 connectorModel->setManualContourModel(manContourModel);
302 connectorView->setManualContourView(manContourView);
303 connectorcontroller->setModelAndView(connectorModel,connectorView);
305 int newId = _controllers.size();
306 connectorcontroller->setId(newId);
307 _controllers[newId] = connectorcontroller;
311 //=========================================================================
313 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
315 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
316 baseViewControlManager->AddInteractorStyleMaracas( param );
319 //=========================================================================
321 vtkRenderer* wxVtkSceneManager::getRenderer()
323 return _baseView->GetRenderer();
326 //=========================================================================
328 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
330 return _baseView->GetRenWin();
332 //=========================================================================
334 bool wxVtkSceneManager::OnMouseMove()
339 //=========================================================================
341 void wxVtkSceneManager::update(int idController,int command)
344 if(command == INIT_CREATION_CONTOUR)
346 GObjectController* cont = _controllers[idController];
347 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
348 createGConnector(startOutputPort);
350 // The last one is the controller of the connector
351 for(int i=0;i<_controllers.size()-1;i++)
353 GObjectController* cont = _controllers[i];
354 if(cont->getGObjectType() == GPORT )
356 GPortModel* port = (GPortModel*)cont->getModel();
357 if(port->getPortType()==GINPUTPORT)
359 cont->SetActive(true);
363 cont->getView()->setState(NOTHING_HAPPENS);
364 cont->SetActive(false);
369 cont->getView()->setState(NOTHING_HAPPENS);
370 cont->SetActive(false);
373 _worldState = CREATING_CONTOUR;
375 else if(command == FIN_CREATION_CONTOUR && _worldState == CREATING_CONTOUR)
378 _worldState = NOTHING_HAPPENS;
379 int id = _controllers.size()-1;
380 GObjectController* cont = _controllers[id];
381 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
383 GObjectController* finPort = _controllers[idController];
384 if(finPort->getGObjectType() == GPORT)
386 GPortModel* modelPort = (GPortModel*)finPort->getModel();
387 modelContour->setEndPort(modelPort);
390 manualConnectorContourController* manCont = ((GConnectorController*)cont)->getManualContourController();
391 manualConnectorContourView* connView = (manualConnectorContourView*)manCont->GetManualViewBaseContour();
394 for(int i=0;i<_controllers.size();i++)
396 GObjectController* cont = _controllers[i];
397 if(cont->getView()!=NULL)
399 cont->getView()->setState(NOTHING_HAPPENS);
401 cont->SetActive(true);
406 //=========================================================================
408 } // EO namespace bbtk