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
184 model->notifyObservers();
186 //Register the controller of the new object
187 registerController((InteractorStyleMaracas*) controller);
189 //Add the object to the objects list
190 int newId = _controllers.size();
191 controller->setId(newId);
192 _controllers[newId] = controller;
196 //=========================================================================
198 void wxVtkSceneManager::createGInputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxInputDescriptor *desc)
200 createGPort(portType,posinBox,blackBox);
203 //=========================================================================
205 void wxVtkSceneManager::createGOutputPort(int portType, int posinBox,GBlackBoxModel *blackBox, BlackBoxOutputDescriptor *desc)
207 createGPort(portType,posinBox,blackBox);
210 //=========================================================================
212 void wxVtkSceneManager::createGPort(int portType, int posInBox,GBlackBoxModel *blackBox)
216 //Create the MVC Objects
217 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
218 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
219 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
221 model->registerInBox(blackBox,portType, posInBox);
222 blackBox->addOutputPort(model);
224 model->addObserver(view);
225 model->addObserver(this);
227 //Associates the view with the correspondent renderer and the model.
228 //(NOTE: Refresh is only made by the view)
229 view->setModel(model);
230 view->setBaseView(_baseView);
231 view->initVtkObjects();
233 //Associates the controller with the correspondent model and view
234 controller->setModelAndView(model,view);
236 model->notifyObservers();
238 //Register the controller of the new object
239 registerController((InteractorStyleMaracas*) controller);
241 int newId = _controllers.size();
242 controller->setId(newId);
243 _controllers[newId] = controller;
246 //=========================================================================
248 void wxVtkSceneManager::createGConnector(GPortModel* startPort)
250 int type = GCONNECTOR;
252 manualConnectorContourController* manContourControl = new manualConnectorContourController();
253 manualConnectorContourView* manViewerContour = new manualConnectorContourView();
254 manualContourModel* manContourModel = new manualContourModel();
256 GConnectorController* connectorcontroller = new GConnectorController();
257 GConnectorModel* connectorModel = new GConnectorModel();
258 GConnectorView* connectorView = new GConnectorView();
259 connectorModel->setGObjectType(type);
261 manContourModel->SetCloseContour(false);
262 connectorModel->setStartPort(startPort);
264 manViewerContour->SetModel( manContourModel );
265 manViewerContour->SetWxVtkBaseView( _baseView );
266 manViewerContour->SetRange( 0.5 );
267 manViewerContour->SetZ( 900 );
269 manViewerContour->SetColorNormalContour(0, 0, 1);
270 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
271 manViewerContour->SetColorSelectContour(1, 0.8, 0);
272 manViewerContour->SetWidthLine(1);
274 manContourControl->SetModelView( manContourModel , manViewerContour );
276 manContourControl->CreateNewManualContour();
278 manViewerContour->RefreshContour();
282 connectorModel->getInicPoint(x,y,z);
284 manContourControl->SetState(1);
285 manContourModel->SetCloseContour(false);
287 manContourModel->AddPoint(x,y,z);
288 manViewerContour->AddPoint();
290 manContourModel->AddPoint(x,y,z);
291 manViewerContour->AddPoint();
293 int bak= manContourControl->GetNumberOfPointsManualContour() - 1;
294 manContourControl->_bakIdPoint=bak;
295 manViewerContour->Refresh();
297 manContourControl->SetMoving( false );
299 registerController((InteractorStyleMaracas*) connectorcontroller);
301 connectorcontroller->setManualContourController(manContourControl);
302 connectorModel->setManualContourModel(manContourModel);
303 connectorcontroller->setModelAndView(connectorModel,NULL);
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 if(cont->getGObjectType() == GPORT)
349 GPortModel* startOutputPort = (GPortModel*)cont->getModel();
350 createGConnector(startOutputPort);
352 // The last one is the controller of the connector
353 for(int i=0;i<_controllers.size()-1;i++)
355 GObjectController* cont = _controllers[i];
356 if(cont->getGObjectType() == GPORT )
358 GPortModel* port = (GPortModel*)cont->getModel();
359 if(port->getPortType()==GINPUTPORT)
361 cont->SetActive(true);
365 cont->getView()->setState(NOTHING_HAPPENS);
366 cont->SetActive(false);
371 cont->getView()->setState(NOTHING_HAPPENS);
372 cont->SetActive(false);
375 _worldState = CREATING_CONTOUR;
377 else if(command == FIN_CREATION_CONTOUR && _worldState == CREATING_CONTOUR)
379 _worldState = NOTHING_HAPPENS;
380 int id = _controllers.size()-1;
381 GObjectController* cont = _controllers[id];
382 GConnectorModel* modelContour = (GConnectorModel*)cont->getModel();
384 GObjectController* finPort = _controllers[idController];
385 if(cont->getGObjectType() == GPORT)
387 GPortModel* modelPort = (GPortModel*)finPort->getModel();
388 modelContour->setEndPort(modelPort);
391 manualContourControler* manCont = ((GConnectorController*)cont)->getManualContourController();
393 //manCont->SetCompleteCreation( true );
394 //manCont->SetKeyBoardMoving( false );
395 //manCont->GetManualContourModel()->SetCloseContour(false);
396 //manCont->SetEditable( false );
397 //manCont->SetPosibleToMove( false );
398 //manCont->SetState(0);
400 for(int i=0;i<_controllers.size();i++)
402 GObjectController* cont = _controllers[i];
403 if(cont->getView()!=NULL)
405 cont->getView()->setState(NOTHING_HAPPENS);
407 cont->SetActive(true);
412 //=========================================================================
414 } // EO namespace bbtk