1 /*=========================================================================
4 Module: $RCSfile: wxMaracasSurfaceRenderingManager.cxx,v $
6 Date: $Date: 2012/05/11 11:46:37 $
7 Version: $Revision: 1.3 $
9 Copyright: (c) 2002, 2003
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notice for more information.
16 =========================================================================*/
18 #include "wxMaracasSurfaceRenderingManager.h"
19 #include "wxMaracasSurfaceRenderingManagerDataMhd.h"
22 ** Start of the manager class
24 wxMaracasSurfaceRenderingManager::wxMaracasSurfaceRenderingManager(){
30 wxMaracasSurfaceRenderingManager::~wxMaracasSurfaceRenderingManager(){
34 ** Sets the renderer to manage the prop3D from the surface render
36 void wxMaracasSurfaceRenderingManager::setRenderer(vtkRenderer* renderer){
41 ** Sets the renderer to manage the prop3D from the surface render
43 void wxMaracasSurfaceRenderingManager::setInteractor(vtkRenderWindowInteractor* interactor){
44 _interactor = interactor;
49 ** Gets the renderer to manage the prop3D from the surface render
51 vtkRenderer* wxMaracasSurfaceRenderingManager::getRenderer(){
58 void wxMaracasSurfaceRenderingManager::Update(int pid)throw(char*){
59 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(pid);
60 ((wxMaracasSurfaceRenderingManagerDataMhd*)data)->UpdateSurface();
65 ** Adds a prop3D to the manager and returns the identifier
67 int wxMaracasSurfaceRenderingManager::addProp3D(int idTP, vtkProp3D* prop3D, std::string dataname) throw(char*){
70 wxMaracasSurfaceRenderingManagerData* data = new wxMaracasSurfaceRenderingManagerData(prop3D, dataname, _interactor);
71 prop3Dvect.push_back(data);
72 _renderer->AddActor(data->getProp3D());
75 data->setId(_idCount);
84 throw "Check vtkProp3D file or input";
90 ** Adds a polydata and creates the prop3D (actor) to the manager and returns the identifier
93 ** Adds a polydata and creates the prop3D (actor) to the manager and returns the identifier
95 int wxMaracasSurfaceRenderingManager::addProp3D(int idTP, std::string filename, std::string dataname){
98 wxMaracasSurfaceRenderingManagerData* data = new wxMaracasSurfaceRenderingManagerData(filename, _interactor);
99 if(dataname.compare("") != 0)
100 data->setDataname(dataname);
102 prop3Dvect.push_back(data);
103 _renderer->AddActor(data->getProp3D());
106 data->setId(_idCount);
113 return data->getId();
117 int wxMaracasSurfaceRenderingManager::addPropMHD(int idTP, vtkImageData* imagedata, std::string dataname) throw(char*){
119 if(imagedata != NULL){
121 wxMaracasSurfaceRenderingManagerData* data = new wxMaracasSurfaceRenderingManagerDataMhd(imagedata, dataname, _interactor);
122 prop3Dvect.push_back(data);
123 _renderer->AddActor(data->getProp3D());
126 data->setId(_idCount);
133 printf("wxMaracasSurfaceRenderingManager::addPropMHD->idSurfaceRender: %i\n", data->getId());
134 return data->getId();
136 throw "Check ImageData file or input";
141 ** adds or removes an actor depending of the bool value
143 bool wxMaracasSurfaceRenderingManager::addRemoveActor(int propid, bool addremove) throw(char*){
146 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
147 if(data && data->getProp3D()!=NULL){
149 _renderer->AddViewProp(data->getProp3D());
151 _renderer->RemoveViewProp(data->getProp3D());
156 if(addremove && propid == 0 && image){
157 addPropMHD(0, image, "id0");
164 ** adds or removes the surface box depending of the bool value
166 void wxMaracasSurfaceRenderingManager::addRemoveSurfaceBox(int propid, bool addremove) throw(char*){
169 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
170 if(data->getProp3D()!=NULL){
171 data->addRemoveSurfaceBox(addremove);
174 _renderer->AddViewProp(data->getProp3D());
176 _renderer->RemoveViewProp(data->getProp3D());
178 _renderer->Render();*/
184 ** Changes the opacity in a prop3D
186 void wxMaracasSurfaceRenderingManager::changeOpacity(int propid, int value) throw(char*){
190 this->getViewData(propid)->changeOpacity(value);
197 ** changes the isovalue in a prop3D
199 void wxMaracasSurfaceRenderingManager::changeIsoValue(int propid, double value ){
202 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
204 //_renderer->RemoveActor(data->getProp3D());
205 ((wxMaracasSurfaceRenderingManagerDataMhd*)data)->changeIsoValue(value);
206 //_renderer->AddActor(data->getProp3D());
212 ** changes the isovalue in a prop3D
214 void wxMaracasSurfaceRenderingManager::changeIsoValue(int propid, double min, double max ){
217 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
219 //_renderer->RemoveActor(data->getProp3D());
220 ((wxMaracasSurfaceRenderingManagerDataMhd*)data)->changeIsoValue(min, max);
221 //_renderer->AddActor(data->getProp3D());
226 /*vtkProp3D* wxMaracasSurfaceRenderingManager:: getProp3D(std::string filename){
227 if(filename.compare("")!= 0){
229 vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
230 std::string ext = filename.substr(filename.find_last_of("."), 4);
231 if(ext.compare(STL)==0){
232 vtkSmartPointer<vtkSTLReader> STLReader=vtkSmartPointer<vtkSTLReader>::New();
233 STLReader->SetFileName(filename.c_str());
235 polydata->DeepCopy(STLReader->GetOutput());
237 }else if(ext.compare(PLY)==0){
238 vtkSmartPointer<vtkPLYReader> plyreader =vtkSmartPointer<vtkPLYReader>::New();
239 plyreader->SetFileName(filename.c_str());
241 polydata->DeepCopy(plyreader->GetOutput());
242 }else if(ext.compare(VTK)==0){
243 vtkSmartPointer<vtkPolyDataReader> polyreader =vtkSmartPointer<vtkPolyDataReader>::New();
244 polyreader->SetFileName(filename.c_str());
245 polyreader->Update();
246 polydata->DeepCopy(polyreader->GetOutput());
249 vtkSmartPointer<vtkPolyDataMapper> dataMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
250 dataMapper->SetInput(polydata);
252 vtkActor* dataActor = vtkActor::New();
253 dataActor->SetMapper(dataMapper);
254 dataActor->GetProperty()->SetOpacity(1);
260 vtkImageData* wxMaracasSurfaceRenderingManager::getImageData(std::string filename){
261 if(filename.compare("")!= 0){
263 vtkMetaImageReader* reader = vtkMetaImageReader::New();
264 reader->SetFileName(filename.c_str());
266 vtkImageData* img = reader->GetOutput();
273 vtkImageData* wxMaracasSurfaceRenderingManager::getImageData(){
277 void wxMaracasSurfaceRenderingManager::setImageData(vtkImageData* img){
281 void wxMaracasSurfaceRenderingManager::checkInvariant() throw(char*){
282 if(this->_renderer==NULL){
283 throw "Renderer not set";
287 wxMaracasSurfaceRenderingManagerData* wxMaracasSurfaceRenderingManager::getViewData(int id) throw(char*){
289 for(i = 0; i < (int)(prop3Dvect.size());i++){
290 if(prop3Dvect[i]->getId() == id){
291 return prop3Dvect[i];
295 throw "id not found in the data";
303 int wxMaracasSurfaceRenderingManager::getMaxIsoValue(int propid) throw(char*){
305 return ((wxMaracasSurfaceRenderingManagerDataMhd*)this->getViewData(propid))->getMaxGreyLevel();
309 void wxMaracasSurfaceRenderingManager::changeColor(int propid, double red, double green, double blue) throw(char*){
311 this->getViewData(propid)->changeColor(red, green, blue);
316 void wxMaracasSurfaceRenderingManager::deleteActor(int propid) throw (char *){
319 this->addRemoveActor(propid, false);
323 for(i = 0; i < (int)(prop3Dvect.size())&&!exit;i++){
324 if(prop3Dvect[i]->getId() == propid){
330 wxMaracasSurfaceRenderingManagerData* data = prop3Dvect[n];
332 for(j = i; j < (int)(prop3Dvect.size())-1;j++){
333 prop3Dvect[j] = prop3Dvect[j+1];
336 prop3Dvect.pop_back();
339 throw "id not found in the data";
345 void wxMaracasSurfaceRenderingManager::enableBoundingBox(int propid, bool enable){
348 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
351 data->enableBoxWidget(enable);
353 void wxMaracasSurfaceRenderingManager::Transform(vtkMatrix4x4* tmatrix){
357 bool wxMaracasSurfaceRenderingManager::interactorSet(){
358 return _interactor? true:false;
361 void wxMaracasSurfaceRenderingManager::saveProp3DSTL(int propid,const char* filename){
364 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
365 if(data->getProp3D()!=NULL){
366 data->saveProp3DSTL(filename);
370 void wxMaracasSurfaceRenderingManager::loadProp3DSTL(const char* filename){
371 this->addProp3D(-1, filename);
374 void wxMaracasSurfaceRenderingManager::exportImageStencil(int propid,const char* filename){
377 wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid);
378 if(data && data->getProp3D()!=NULL){
379 data->exportImageStencil(filename);