1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 /*=========================================================================
29 Module: $RCSfile: wxMaracasSurfaceRenderingManager.cxx,v $
31 Date: $Date: 2012/11/15 14:17:03 $
32 Version: $Revision: 1.4 $
34 Copyright: (c) 2002, 2003
37 This software is distributed WITHOUT ANY WARRANTY; without even
38 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39 PURPOSE. See the above copyright notice for more information.
41 =========================================================================*/
43 #include "wxMaracasSurfaceRenderingManager.h"
44 #include "wxMaracasSurfaceRenderingManagerDataMhd.h"
47 ** Start of the manager class
49 wxMaracasSurfaceRenderingManager::wxMaracasSurfaceRenderingManager(){
55 wxMaracasSurfaceRenderingManager::~wxMaracasSurfaceRenderingManager(){
59 ** Sets the renderer to manage the prop3D from the surface render
61 void wxMaracasSurfaceRenderingManager::setRenderer(vtkRenderer* renderer){
66 ** Sets the renderer to manage the prop3D from the surface render
68 void wxMaracasSurfaceRenderingManager::setInteractor(vtkRenderWindowInteractor* interactor){
69 _interactor = interactor;
74 ** Gets the renderer to manage the prop3D from the surface render
76 vtkRenderer* wxMaracasSurfaceRenderingManager::getRenderer(){
83 void wxMaracasSurfaceRenderingManager::Update(int pid)throw(char*){
84 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(pid);
85 ((wxMaracasSurfaceRenderingManagerDataMhd*)data)->UpdateSurface();
90 ** Adds a prop3D to the manager and returns the identifier
92 int wxMaracasSurfaceRenderingManager::addProp3D(int idTP, vtkProp3D* prop3D, std::string dataname) throw(char*){
95 wxMaracasSurfaceRenderingManagerData* data = new wxMaracasSurfaceRenderingManagerData(prop3D, dataname, _interactor);
96 prop3Dvect.push_back(data);
97 _renderer->AddActor(data->getProp3D());
100 data->setId(_idCount);
107 return data->getId();
109 throw "Check vtkProp3D file or input";
115 ** Adds a polydata and creates the prop3D (actor) to the manager and returns the identifier
118 ** Adds a polydata and creates the prop3D (actor) to the manager and returns the identifier
120 int wxMaracasSurfaceRenderingManager::addProp3D(int idTP, std::string filename, std::string dataname){
123 wxMaracasSurfaceRenderingManagerData* data = new wxMaracasSurfaceRenderingManagerData(filename, _interactor);
124 if(dataname.compare("") != 0)
125 data->setDataname(dataname);
127 prop3Dvect.push_back(data);
128 _renderer->AddActor(data->getProp3D());
131 data->setId(_idCount);
138 return data->getId();
142 int wxMaracasSurfaceRenderingManager::addPropMHD(int idTP, vtkImageData* imagedata, std::string dataname) throw(char*){
144 if(imagedata != NULL){
146 wxMaracasSurfaceRenderingManagerData* data = new wxMaracasSurfaceRenderingManagerDataMhd(imagedata, dataname, _interactor);
147 prop3Dvect.push_back(data);
148 _renderer->AddActor(data->getProp3D());
151 data->setId(_idCount);
158 printf("wxMaracasSurfaceRenderingManager::addPropMHD->idSurfaceRender: %i\n", data->getId());
159 return data->getId();
161 throw "Check ImageData file or input";
166 ** adds or removes an actor depending of the bool value
168 bool wxMaracasSurfaceRenderingManager::addRemoveActor(int propid, bool addremove) throw(char*){
171 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
172 if(data && data->getProp3D()!=NULL){
174 _renderer->AddViewProp(data->getProp3D());
176 _renderer->RemoveViewProp(data->getProp3D());
181 if(addremove && propid == 0 && image){
182 addPropMHD(0, image, "id0");
189 ** adds or removes the surface box depending of the bool value
191 void wxMaracasSurfaceRenderingManager::addRemoveSurfaceBox(int propid, bool addremove) throw(char*){
194 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
195 if(data->getProp3D()!=NULL){
196 data->addRemoveSurfaceBox(addremove);
199 _renderer->AddViewProp(data->getProp3D());
201 _renderer->RemoveViewProp(data->getProp3D());
203 _renderer->Render();*/
209 ** Changes the opacity in a prop3D
211 void wxMaracasSurfaceRenderingManager::changeOpacity(int propid, int value) throw(char*){
215 this->getViewData(propid)->changeOpacity(value);
222 ** changes the isovalue in a prop3D
224 void wxMaracasSurfaceRenderingManager::changeIsoValue(int propid, double value ){
227 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
229 //_renderer->RemoveActor(data->getProp3D());
230 ((wxMaracasSurfaceRenderingManagerDataMhd*)data)->changeIsoValue(value);
231 //_renderer->AddActor(data->getProp3D());
237 ** changes the isovalue in a prop3D
239 void wxMaracasSurfaceRenderingManager::changeIsoValue(int propid, double min, double max ){
242 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
244 //_renderer->RemoveActor(data->getProp3D());
245 ((wxMaracasSurfaceRenderingManagerDataMhd*)data)->changeIsoValue(min, max);
246 //_renderer->AddActor(data->getProp3D());
251 /*vtkProp3D* wxMaracasSurfaceRenderingManager:: getProp3D(std::string filename){
252 if(filename.compare("")!= 0){
254 vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
255 std::string ext = filename.substr(filename.find_last_of("."), 4);
256 if(ext.compare(STL)==0){
257 vtkSmartPointer<vtkSTLReader> STLReader=vtkSmartPointer<vtkSTLReader>::New();
258 STLReader->SetFileName(filename.c_str());
260 polydata->DeepCopy(STLReader->GetOutput());
262 }else if(ext.compare(PLY)==0){
263 vtkSmartPointer<vtkPLYReader> plyreader =vtkSmartPointer<vtkPLYReader>::New();
264 plyreader->SetFileName(filename.c_str());
266 polydata->DeepCopy(plyreader->GetOutput());
267 }else if(ext.compare(VTK)==0){
268 vtkSmartPointer<vtkPolyDataReader> polyreader =vtkSmartPointer<vtkPolyDataReader>::New();
269 polyreader->SetFileName(filename.c_str());
270 polyreader->Update();
271 polydata->DeepCopy(polyreader->GetOutput());
274 vtkSmartPointer<vtkPolyDataMapper> dataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
275 dataMapper->SetInput(polydata);
277 vtkActor* dataActor = vtkActor::New();
278 dataActor->SetMapper(dataMapper);
279 dataActor->GetProperty()->SetOpacity(1);
285 vtkImageData* wxMaracasSurfaceRenderingManager::getImageData(std::string filename){
286 if(filename.compare("")!= 0){
288 vtkMetaImageReader* reader = vtkMetaImageReader::New();
289 reader->SetFileName(filename.c_str());
291 vtkImageData* img = reader->GetOutput();
298 vtkImageData* wxMaracasSurfaceRenderingManager::getImageData(){
302 void wxMaracasSurfaceRenderingManager::setImageData(vtkImageData* img){
306 void wxMaracasSurfaceRenderingManager::checkInvariant() throw(char*){
307 if(this->_renderer==NULL){
308 throw "Renderer not set";
312 wxMaracasSurfaceRenderingManagerData* wxMaracasSurfaceRenderingManager::getViewData(int id) throw(char*){
314 for(i = 0; i < (int)(prop3Dvect.size());i++){
315 if(prop3Dvect[i]->getId() == id){
316 return prop3Dvect[i];
320 throw "id not found in the data";
328 int wxMaracasSurfaceRenderingManager::getMaxIsoValue(int propid) throw(char*){
330 return ((wxMaracasSurfaceRenderingManagerDataMhd*)this->getViewData(propid))->getMaxGreyLevel();
334 void wxMaracasSurfaceRenderingManager::changeColor(int propid, double red, double green, double blue) throw(char*){
336 this->getViewData(propid)->changeColor(red, green, blue);
341 void wxMaracasSurfaceRenderingManager::deleteActor(int propid) throw (char *){
344 this->addRemoveActor(propid, false);
348 for(i = 0; i < (int)(prop3Dvect.size())&&!exit;i++){
349 if(prop3Dvect[i]->getId() == propid){
355 wxMaracasSurfaceRenderingManagerData* data = prop3Dvect[n];
357 for(j = i; j < (int)(prop3Dvect.size())-1;j++){
358 prop3Dvect[j] = prop3Dvect[j+1];
361 prop3Dvect.pop_back();
364 throw "id not found in the data";
370 void wxMaracasSurfaceRenderingManager::enableBoundingBox(int propid, bool enable){
373 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
376 data->enableBoxWidget(enable);
378 void wxMaracasSurfaceRenderingManager::Transform(vtkMatrix4x4* tmatrix){
382 bool wxMaracasSurfaceRenderingManager::interactorSet(){
383 return _interactor? true:false;
386 void wxMaracasSurfaceRenderingManager::saveProp3DSTL(int propid,const char* filename){
389 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
390 if(data->getProp3D()!=NULL){
391 data->saveProp3DSTL(filename);
395 void wxMaracasSurfaceRenderingManager::loadProp3DSTL(const char* filename){
396 this->addProp3D(-1, filename);
399 void wxMaracasSurfaceRenderingManager::exportImageStencil(int propid,const char* filename){
402 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
403 if(data && data->getProp3D()!=NULL){
404 data->exportImageStencil(filename);