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 *******
61 vtkConeSource *cone = vtkConeSource::New();
63 cone->SetResolution(10);
65 vtkPolyDataMapper *map = vtkPolyDataMapper::New();
66 map->SetInput(cone->GetOutput());
68 vtkActor *act = vtkActor::New();
72 vtkPoints *_pts = vtkPoints::New();
73 _pts->SetNumberOfPoints(4);
75 _pts->SetPoint(0, -1 , -1 , 0 );
76 _pts->SetPoint(1, 1 , -1 , 0 );
77 _pts->SetPoint(2, 1 , 1 , 0 );
78 _pts->SetPoint(3, -1 , 1 , 0 );
80 vtkCellArray *lines = vtkCellArray::New();
81 lines->InsertNextCell(5);
82 lines->InsertCellPoint(0);
83 lines->InsertCellPoint(1);
84 lines->InsertCellPoint(2);
85 lines->InsertCellPoint(3);
86 lines->InsertCellPoint(0);
88 vtkPolyData *_pd = vtkPolyData::New();
89 _pd->SetPoints( _pts );
90 _pd->SetLines( lines );
92 vtkActor *_pointVtkActor = vtkActor::New();
93 vtkPolyDataMapper* _bboxMapper = vtkPolyDataMapper::New();
95 _bboxMapper->SetInput(_pd);
96 _pointVtkActor->SetMapper(_bboxMapper);
98 getRenderer()->AddActor(_pointVtkActor);
102 // ******* TO ERASE *******
103 /////////////////////
108 //=========================================================================
109 void wxVtkSceneManager::disconnectDrop()
111 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
113 //=========================================================================
114 wxVtkSceneManager::~wxVtkSceneManager()
117 //=========================================================================
119 void wxVtkSceneManager::configureBaseView()
121 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
123 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
125 // Important to activate the 2D interaction system
126 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
127 interactorstylebaseview->SetInteractor ( iren );
128 iren->SetInteractorStyle(interactorstylebaseview);
129 interactorstylebaseview->SetwxVtkBaseView(_baseView);
131 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
132 _baseView->GetRenderer()->GradientBackgroundOff();
133 _baseView->Refresh();
137 //=========================================================================
139 void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
142 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
143 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
145 int type = GBLACKBOX;
147 //Create the MVC Objects
149 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
150 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
151 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
153 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
155 //Prepares the initial model
156 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
159 double yy = windowHeight-y;
161 //z value is not important yet, because it is only used a parallel projection
164 _baseView->TransCoordScreenToWorld(xx,yy,zz);
165 model->setInicPoint(xx,yy,zz);
167 model->addObserver(view);
168 model->addObserver(this);
170 //Iterate and create the input ports
171 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
172 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
175 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
177 BlackBoxInputDescriptor *desc = itInput->second;
178 createGInputPort(desc,model,i);
182 //Iterate and create the output ports
183 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
184 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
187 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
189 BlackBoxOutputDescriptor *desc = itOutput->second;
190 createGOutputPort(desc,model,i);
195 //Associates the view with the correspondent renderer and the model.
196 //(NOTE: Refresh is only made by the view)
197 view->setModel(model);
198 view->setBaseView(_baseView);
199 view->initVtkObjects();
201 //Associates the controller with the correspondent model and view
202 controller->setModelAndView(model,view);
204 //Resgiter change to the observers of the actual model
206 model->notifyObservers();
208 //Register the controller of the new object
209 registerController((InteractorStyleMaracas*) controller);
211 //Add the object to the objects list (only boxes and connectors)
212 _objects.push_back(model);
216 //=========================================================================
218 void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
222 //Create the MVC Objects
223 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
224 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
225 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
227 model->registerInBox(blackBox,GOUTPUTPORT, pos);
228 blackBox->addOutputPort(model);
230 model->addObserver(view);
231 model->addObserver(this);
233 //Associates the view with the correspondent renderer and the model.
234 //(NOTE: Refresh is only made by the view)
235 view->setModel(model);
236 view->setBaseView(_baseView);
237 view->initVtkObjects();
239 //Associates the controller with the correspondent model and view
240 controller->setModelAndView(model,view);
242 //Register the controller of the new object
243 registerController((InteractorStyleMaracas*) controller);
246 //=========================================================================
248 void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
252 //Create the MVC Objects
253 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
254 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
255 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
257 model->registerInBox(blackBox,GINPUTPORT,pos);
258 blackBox->addInputPort(model);
260 model->addObserver(view);
261 model->addObserver(this);
263 //Associates the view with the correspondent renderer and the model.
264 //(NOTE: Refresh is only made by the view)
265 view->setModel(model);
266 view->setBaseView(_baseView);
267 view->initVtkObjects();
269 //Associates the controller with the correspondent model and view
270 controller->setModelAndView(model,view);
272 //Register the controller of the new object
273 registerController((InteractorStyleMaracas*) controller);
276 //=========================================================================
278 void wxVtkSceneManager::createGConnector(GPortModel* startPort)
280 manualContourControler* manContourControl = new manualContourControler();
281 manualViewContour* manViewerContour = new manualViewContour();
282 manualContourModel* manContourModel = new manualContourModel();
285 manViewerContour->SetModel( manContourModel );
286 manViewerContour->SetWxVtkBaseView( _baseView );
287 manViewerContour->SetRange( 0.5 );
288 manViewerContour->SetZ( 900 );
290 manViewerContour->SetColorNormalContour(0, 0, 1);
291 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
292 manViewerContour->SetColorSelectContour(1, 0.8, 0);
293 manViewerContour->SetWidthLine(1);
295 manContourControl->SetModelView( manContourModel , manViewerContour );
296 manContourControl->Configure();
297 int i,sizeLstPoints = manContourModel->GetSizeLstPoints();
298 for ( i=0; i<sizeLstPoints; i++ )
300 manViewerContour->AddPoint();
303 manContourControl->CreateNewManualContour();
304 manViewerContour->RefreshContour();
305 registerController((InteractorStyleMaracas*) manContourControl);
309 //=========================================================================
311 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
313 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
314 baseViewControlManager->AddInteractorStyleMaracas( param );
317 //=========================================================================
319 vtkRenderer* wxVtkSceneManager::getRenderer()
321 return _baseView->GetRenderer();
324 //=========================================================================
326 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
328 return _baseView->GetRenWin();
330 //=========================================================================
332 bool wxVtkSceneManager::OnMouseMove()
337 //=========================================================================
339 void wxVtkSceneManager::update(int command)
342 if(command==INIT_CREATION_CONTOUR)
344 std::cout<<"wxVtkSceneManager::update size:"<<_objects.size()<<std::endl;
345 for(int i = 0; i<_objects.size();i++)
347 std::cout<<"wxVtkSceneManager::update type:"<<_objects[i]->getGObjectType()<<std::endl;
348 if(_objects[i]->getGObjectType() == GBLACKBOX)
351 GPortModel* startInputPort=((GBlackBoxModel*)_objects[i])->getStartInputPort();
352 std::cout<<"wxVtkSceneManager::update "<<startInputPort<<std::endl;
353 createGConnector(startInputPort);
358 // The others must not react to events
364 //=========================================================================
366 } // EO namespace bbtk