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);
100 // Create a vector text
101 vtkVectorText* vecText = vtkVectorText::New();
102 vecText->SetText("vtkVectorText");
104 vtkPolyDataMapper* txtMapper = vtkPolyDataMapper::New();
105 txtMapper->SetInputConnection( vecText->GetOutputPort());
106 vtkActor* txtActor = vtkActor::New();
107 txtActor->SetMapper(txtMapper);
108 //getRenderer()->AddActor(txtActor);
110 // ******* TO ERASE *******
111 /////////////////////
116 //=========================================================================
117 void wxVtkSceneManager::disconnectDrop()
119 _baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(NULL);
121 //=========================================================================
122 wxVtkSceneManager::~wxVtkSceneManager()
125 //=========================================================================
127 void wxVtkSceneManager::configureBaseView()
129 vtkInteractorStyleBaseView2D *interactorstylebaseview = vtkInteractorStyleBaseView2D::New();
131 _baseView->SetInteractorStyleBaseView(interactorstylebaseview);
133 // Important to activate the 2D interaction system
134 wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
135 interactorstylebaseview->SetInteractor ( iren );
136 iren->SetInteractorStyle(interactorstylebaseview);
137 interactorstylebaseview->SetwxVtkBaseView(_baseView);
139 _baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
140 _baseView->GetRenderer()->GradientBackgroundOff();
141 _baseView->Refresh();
145 //=========================================================================
147 void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
150 int windowWidth=_baseView->GetRenWin()->GetSize()[0];
151 int windowHeight=_baseView->GetRenWin()->GetSize()[1];
153 int type = GBLACKBOX;
155 //Create the MVC Objects
157 GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
158 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
159 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
161 BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
163 //Prepares the initial model
164 //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
167 double yy = windowHeight-y;
169 //z value is not important yet, because it is only used a parallel projection
172 _baseView->TransCoordScreenToWorld(xx,yy,zz);
173 model->setInicPoint(xx,yy,zz);
175 int cantObjects = _objects.size();
177 std::stringstream stream;
178 stream << "Object " << cantObjects;
179 std::string arraystring = stream.str();
181 model->setBBTKName(arraystring);
182 model->setBBTKType(boxName);
184 model->addObserver(view);
185 model->addObserver(this);
187 //Iterate and create the input ports
188 std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
189 std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
192 for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
194 BlackBoxInputDescriptor *desc = itInput->second;
195 createGInputPort(desc,model,i);
199 //Iterate and create the output ports
200 std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
201 std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
204 for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
206 BlackBoxOutputDescriptor *desc = itOutput->second;
207 createGOutputPort(desc,model,i);
212 //Associates the view with the correspondent renderer and the model.
213 //(NOTE: Refresh is only made by the view)
214 view->setModel(model);
215 view->setBaseView(_baseView);
216 view->initVtkObjects();
218 //Associates the controller with the correspondent model and view
219 controller->setModelAndView(model,view);
221 //Resgiter change to the observers of the actual model
223 model->notifyObservers();
225 //Register the controller of the new object
226 registerController((InteractorStyleMaracas*) controller);
228 //Add the object to the objects list (only boxes and connectors)
229 _objects.push_back(model);
233 //=========================================================================
235 void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
239 //Create the MVC Objects
240 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
241 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
242 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
244 model->registerInBox(blackBox,GOUTPUTPORT, pos);
245 blackBox->addOutputPort(model);
247 model->addObserver(view);
248 model->addObserver(this);
250 //Associates the view with the correspondent renderer and the model.
251 //(NOTE: Refresh is only made by the view)
252 view->setModel(model);
253 view->setBaseView(_baseView);
254 view->initVtkObjects();
256 //Associates the controller with the correspondent model and view
257 controller->setModelAndView(model,view);
259 //Register the controller of the new object
260 registerController((InteractorStyleMaracas*) controller);
263 //=========================================================================
265 void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
269 //Create the MVC Objects
270 GPortModel *model = (GPortModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
271 vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
272 GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
274 model->registerInBox(blackBox,GINPUTPORT,pos);
275 blackBox->addInputPort(model);
277 model->addObserver(view);
278 model->addObserver(this);
280 //Associates the view with the correspondent renderer and the model.
281 //(NOTE: Refresh is only made by the view)
282 view->setModel(model);
283 view->setBaseView(_baseView);
284 view->initVtkObjects();
286 //Associates the controller with the correspondent model and view
287 controller->setModelAndView(model,view);
289 //Register the controller of the new object
290 registerController((InteractorStyleMaracas*) controller);
293 //=========================================================================
295 void wxVtkSceneManager::createGConnector(GPortModel* startPort)
297 manualContourControler* manContourControl = new manualContourControler();
298 manualViewContour* manViewerContour = new manualViewContour();
299 manualContourModel* manContourModel = new manualContourModel();
302 manViewerContour->SetModel( manContourModel );
303 manViewerContour->SetWxVtkBaseView( _baseView );
304 manViewerContour->SetRange( 0.5 );
305 manViewerContour->SetZ( 900 );
307 manViewerContour->SetColorNormalContour(0, 0, 1);
308 manViewerContour->SetColorEditContour(0.5, 0.5, 0.5);
309 manViewerContour->SetColorSelectContour(1, 0.8, 0);
310 manViewerContour->SetWidthLine(1);
312 manContourControl->SetModelView( manContourModel , manViewerContour );
313 manContourControl->Configure();
314 int i,sizeLstPoints = manContourModel->GetSizeLstPoints();
315 for ( i=0; i<sizeLstPoints; i++ )
317 manViewerContour->AddPoint();
320 manContourControl->CreateNewManualContour();
321 manViewerContour->RefreshContour();
322 registerController((InteractorStyleMaracas*) manContourControl);
326 //=========================================================================
328 void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
330 vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
331 baseViewControlManager->AddInteractorStyleMaracas( param );
334 //=========================================================================
336 vtkRenderer* wxVtkSceneManager::getRenderer()
338 return _baseView->GetRenderer();
341 //=========================================================================
343 vtkRenderWindow* wxVtkSceneManager::getRenderWindow()
345 return _baseView->GetRenWin();
347 //=========================================================================
349 bool wxVtkSceneManager::OnMouseMove()
354 //=========================================================================
356 void wxVtkSceneManager::update(int command)
359 if(command==INIT_CREATION_CONTOUR)
361 for(int i = 0; i<_objects.size();i++)
363 if(_objects[i]->getGObjectType() == GBLACKBOX)
366 GPortModel* startInputPort=((GBlackBoxModel*)_objects[i])->getStartInputPort();
367 createGConnector(startInputPort);
372 // The others must not react to events
378 //=========================================================================
380 } // EO namespace bbtk