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 id)
51 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(parent);
52 registerController(this);
55 ///// ******* TO ERASE *******
59 vtkConeSource *cone = vtkConeSource::New();
61 cone->SetResolution(10);
63 vtkPolyDataMapper *map = vtkPolyDataMapper::New();
64 map->SetInput(cone->GetOutput());
66 vtkActor *act = vtkActor::New();
70 vtkPoints *_pts = vtkPoints::New();
71 _pts->SetNumberOfPoints(4);
73 _pts->SetPoint(0, -100 , -100 , 900 );
74 _pts->SetPoint(1, 100 , -100 , 900 );
75 _pts->SetPoint(2, 100 , 100 , 900 );
76 _pts->SetPoint(3, -100 , 100 , 900 );
78 vtkCellArray *lines = vtkCellArray::New();
79 lines->InsertNextCell(5);
80 lines->InsertCellPoint(0);
81 lines->InsertCellPoint(1);
82 lines->InsertCellPoint(2);
83 lines->InsertCellPoint(3);
84 lines->InsertCellPoint(0);
86 vtkPolyData *_pd = vtkPolyData::New();
87 _pd->SetPoints( _pts );
88 _pd->SetLines( lines );
90 vtkActor *_pointVtkActor = vtkActor::New();
91 vtkPolyDataMapper* _bboxMapper = vtkPolyDataMapper::New();
93 _bboxMapper->SetInput(_pd);
94 _pointVtkActor->SetMapper(_bboxMapper);
96 getRenderer()->AddActor(_pointVtkActor);
101 vtkPoints *_pts2 = vtkPoints::New();
102 _pts2->SetNumberOfPoints(4);
104 _pts2->SetPoint(0, -105 , -100 , -50 );
105 _pts2->SetPoint(1, 100 , -100 , -50 );
106 _pts2->SetPoint(2, 100 , 100 , -50 );
107 _pts2->SetPoint(3, -105 , 100 , -50 );
109 vtkCellArray *lines2 = vtkCellArray::New();
110 lines2->InsertNextCell(5);
111 lines2->InsertCellPoint(0);
112 lines2->InsertCellPoint(1);
113 lines2->InsertCellPoint(2);
114 lines2->InsertCellPoint(3);
115 lines2->InsertCellPoint(0);
117 vtkPolyData *_pd2 = vtkPolyData::New();
118 _pd2->SetPoints( _pts2 );
119 _pd2->SetLines( lines2 );
121 vtkActor *_pointVtkActor2 = vtkActor::New();
122 vtkPolyDataMapper* _bboxMapper2 = vtkPolyDataMapper::New();
124 _bboxMapper2->SetInput(_pd2);
125 _pointVtkActor2->SetMapper(_bboxMapper2);
127 getRenderer()->AddActor(_pointVtkActor2);
130 // ******* TO ERASE *******
131 /////////////////////
137 //=========================================================================
138 void wxVtkSceneManager::disconnectDrop()
140 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
142 //=========================================================================
143 wxVtkSceneManager::~wxVtkSceneManager()
146 //=========================================================================
148 void wxVtkSceneManager::configureBaseView()
150 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
152 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
154 // Important to activate the 2D interaction system
155 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
156 interactorstylebaseview->SetInteractor ( iren );
157 iren->SetInteractorStyle(interactorstylebaseview);
158 interactorstylebaseview->SetwxVtkBaseView(_baseView);
161 _baseView->GetRenderer()->GetActiveCamera()->ParallelProjectionOn();
162 _baseView->GetRenderer()->GetActiveCamera()->SetPosition(0,0,1000);
163 _baseView->GetRenderer()->GetActiveCamera()->GetPosition(posCamera);
164 _baseView->GetRenderer()->ResetCamera();
165 _baseView->GetRenderer()->ResetCameraClippingRange();
168 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
169 _baseView->GetRenderer()->GradientBackgroundOff();
170 _baseView->Refresh();
173 //=========================================================================
175 void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
178 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
179 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
181 int type = GBLACKBOX;
183 //Create the MVC Objects
185 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
186 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
187 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
189 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
191 //Prepares the initial model
192 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
195 double yy = windowHeight-y;
197 //z value is not important yet, because it is only used a parallel projection
200 _baseView->TransCoordScreenToWorld(xx,yy,zz);
201 model->setInicPoint(xx,yy,zz);
203 int cantObjects = _objects.size();
205 std::stringstream stream;
206 stream << "Box " << cantObjects;
207 std::string arraystring = stream.str();
209 model->setBBTKName(arraystring);
210 model->setBBTKType(boxName);
212 model->addObserver(view);
213 model->addObserver(this);
215 //Iterate and create the input ports
216 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
217 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
220 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
222 BlackBoxInputDescriptor *desc = itInput->second;
223 createGInputPort(desc,model,i);
227 //Iterate and create the output ports
228 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
229 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
232 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
234 BlackBoxOutputDescriptor *desc = itOutput->second;
235 createGOutputPort(desc,model,i);
240 //Associates the view with the correspondent renderer and the model.
241 //(NOTE: Refresh is only made by the view)
242 view->setModel(model);
243 view->setBaseView(_baseView);
244 view->initVtkObjects();
246 //Associates the controller with the correspondent model and view
247 controller->setModelAndView(model,view);
249 //Resgiter change to the observers of the actual model
251 model->notifyObservers();
253 //Register the controller of the new object
254 registerController((InteractorStyleMaracas*) controller);
256 //Add the object to the objects list (only boxes and connectors)
257 _objects.push_back(model);
261 //=========================================================================
263 void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
267 //Create the MVC Objects
268 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
269 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
270 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
272 model->registerInBox(blackBox,GOUTPUTPORT, pos);
273 blackBox->addOutputPort(model);
275 model->addObserver(view);
276 model->addObserver(this);
278 //Associates the view with the correspondent renderer and the model.
279 //(NOTE: Refresh is only made by the view)
280 view->setModel(model);
281 view->setBaseView(_baseView);
282 view->initVtkObjects();
284 //Associates the controller with the correspondent model and view
285 controller->setModelAndView(model,view);
287 //Register the controller of the new object
288 registerController((InteractorStyleMaracas*) controller);
291 //=========================================================================
293 void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
297 //Create the MVC Objects
298 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
299 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
300 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
302 model->registerInBox(blackBox,GINPUTPORT,pos);
303 blackBox->addInputPort(model);
305 model->addObserver(view);
306 model->addObserver(this);
308 //Associates the view with the correspondent renderer and the model.
309 //(NOTE: Refresh is only made by the view)
310 view->setModel(model);
311 view->setBaseView(_baseView);
312 view->initVtkObjects();
314 //Associates the controller with the correspondent model and view
315 controller->setModelAndView(model,view);
317 //Register the controller of the new object
318 registerController((InteractorStyleMaracas*) controller);
321 //=========================================================================
323 void wxVtkSceneManager::createGConnector(GPortModel* startPort)
325 manualContourControler* manContourControl = new manualContourControler();
326 GConnectorView* manViewerContour = new GConnectorView();
327 manualContourModel* manContourModel = new manualContourModel();
330 manViewerContour->SetModel( manContourModel );
331 manViewerContour->SetWxVtkBaseView( _baseView );
332 manViewerContour->SetRange( 0.5 );
333 manViewerContour->SetZ( 900 );
335 manViewerContour->SetColorNormalContour(0, 0, 1);
336 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
337 manViewerContour->SetColorSelectContour(1, 0.8, 0);
338 manViewerContour->SetWidthLine(1);
340 manContourControl->SetModelView( manContourModel , manViewerContour );
341 manContourControl->Configure();
342 int i,sizeLstPoints = manContourModel->GetSizeLstPoints();
343 //std::cout<<"RaC wxVtkSceneManager::createGConnector "<<this<<" size:"<<sizeLstPoints<<std::endl;
344 for ( i=0; i<sizeLstPoints; i++ )
346 manViewerContour->AddPoint();
349 manContourControl->CreateNewManualContour();
350 manViewerContour->RefreshContour();
351 registerController((InteractorStyleMaracas*) manContourControl);
355 //=========================================================================
357 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
359 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
360 baseViewControlManager->AddInteractorStyleMaracas( param );
363 //=========================================================================
365 vtkRenderer* wxVtkSceneManager::getRenderer()
367 return _baseView->GetRenderer();
370 //=========================================================================
372 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
374 return _baseView->GetRenWin();
376 //=========================================================================
378 bool wxVtkSceneManager::OnMouseMove()
383 //=========================================================================
385 void wxVtkSceneManager::update(int command)
388 if(command==INIT_CREATION_CONTOUR)
390 for(int i = 0; i<_objects.size();i++)
392 if(_objects[i]->getGObjectType() == GBLACKBOX)
395 GPortModel* startOutputPort=((GBlackBoxModel*)_objects[i])->getStartOutputPort();
396 createGConnector(startOutputPort);
401 // The others must not react to events
407 //=========================================================================
409 } // EO namespace bbtk