1 /*=========================================================================
4 Module: $RCSfile: wxMaracasIRMViewManager.cxx,v $
6 Date: $Date: 2009/05/04 07:35:42 $
7 Version: $Revision: 1.4 $
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 =========================================================================*/
17 #include "wxMaracasIRMViewManager.h"
20 ** Start of the manager class
22 wxMaracasIRMViewManager::wxMaracasIRMViewManager(){
26 wxMaracasIRMViewManager::~wxMaracasIRMViewManager(){
30 ** Sets the renderer to manage the prop3D from the view
32 void wxMaracasIRMViewManager::setRenderer(vtkRenderer* renderer){
36 ** Adds a prop3D to the manager and returns the identifier
38 int wxMaracasIRMViewManager::addProp3D(vtkProp3D* prop3D, std::string dataname) throw(char*){
41 wxMaracasIRMViewManagerData* data = new wxMaracasIRMViewManagerData(prop3D, dataname);
42 prop3Dvect.push_back(data);
43 _renderer->AddActor(data->getProp3D());
44 data->setId(_idCount);
48 throw "Check vtkProp3D file or input";
52 int wxMaracasIRMViewManager::addPropMHD(vtkImageData* imagedata, std::string dataname) throw(char*){
55 if(imagedata != NULL){
56 wxMaracasIRMViewManagerData* data = new wxMaracasIRMViewManagerData(imagedata, dataname);
57 prop3Dvect.push_back(data);
58 _renderer->AddActor(data->getProp3D());
59 data->setId(_idCount);
63 throw "Check ImageData file or input";
69 ** adds or removes an actor depending of the bool value
71 void wxMaracasIRMViewManager::addRemoveActor(int propid, bool addremove) throw(char*){
74 wxMaracasIRMViewManagerData* data = this->getViewData(propid);
75 if(data->getProp3D()!=NULL){
77 _renderer->AddViewProp(data->getProp3D());
79 _renderer->RemoveViewProp(data->getProp3D());
86 ** Changes the opacity in a prop3D
88 void wxMaracasIRMViewManager::changeOpacity(int propid, int value) throw(char*){
92 this->getViewData(propid)->changeOpacity(value);
99 ** changes the isovalue in a prop3D
101 void wxMaracasIRMViewManager::changeIsoValue(int propid, double value )throw(char*){
104 wxMaracasIRMViewManagerData* data = this->getViewData(propid);
106 //_renderer->RemoveActor(data->getProp3D());
107 data->changeIsoValue(value);
108 //_renderer->AddActor(data->getProp3D());
113 vtkProp3D* wxMaracasIRMViewManager:: getProp3D(std::string filename){
114 if(filename.compare("")!= 0){
115 vtkSTLReader *STLReader=vtkSTLReader::New();
116 STLReader->SetFileName(filename.c_str());
118 vtkPolyDataMapper* dataMapper = vtkPolyDataMapper::New();
119 dataMapper->SetInput(STLReader->GetOutput());
121 vtkActor* dataActor = vtkActor::New();
122 dataActor->SetMapper(dataMapper);
123 dataActor->GetProperty()->SetOpacity(1);
130 vtkImageData* wxMaracasIRMViewManager::getImageData(std::string filename){
131 if(filename.compare("")!= 0){
134 vtkMetaImageReader* reader = vtkMetaImageReader::New();
135 reader->SetFileName(filename.c_str());
137 vtkImageData* img = reader->GetOutput();
144 void wxMaracasIRMViewManager::checkInvariant() throw(char*){
145 if(this->_renderer==NULL){
146 throw "Renderer not set";
150 wxMaracasIRMViewManagerData* wxMaracasIRMViewManager::getViewData(int id) throw(char*){
152 for(i = 0; i < prop3Dvect.size();i++){
153 if(prop3Dvect[i]->getId() == id){
154 return prop3Dvect[i];
157 throw "id not found in the data";
162 int wxMaracasIRMViewManager::getMaxIsoValue(int propid) throw(char*){
164 return this->getViewData(propid)->getMaxGreyLevel();
168 void wxMaracasIRMViewManager::changeColor(int propid, double red, double green, double blue) throw(char*){
170 this->getViewData(propid)->changeColor(red, green, blue);
175 void wxMaracasIRMViewManager::deleteActor(int propid) throw (char *){
178 this->addRemoveActor(propid, false);
182 for(i = 0; i < prop3Dvect.size()&&!exit;i++){
183 if(prop3Dvect[i]->getId() == propid){
189 wxMaracasIRMViewManagerData* data = prop3Dvect[n];
191 for(j = i; j < prop3Dvect.size()-1;j++){
192 prop3Dvect[j] = prop3Dvect[j+1];
195 prop3Dvect.pop_back();
197 throw "id not found in the data";
205 /********************************************************************************************
206 ** Start of data viewmanagerData
207 *********************************************************************************************/
209 wxMaracasIRMViewManagerData::wxMaracasIRMViewManagerData(vtkProp3D* prop3Dvect, std::string dataname){
211 _prop3D = prop3Dvect;
212 _dataname = dataname;
219 wxMaracasIRMViewManagerData::wxMaracasIRMViewManagerData(vtkImageData* imagedata, std::string dataname){
221 this->setVtkImageData(imagedata);
222 _dataname = dataname;
224 _maxgreylevel = getMaxLevel(imagedata);
227 _cubesFilter = vtkMarchingCubes::New();
228 _cleanFilter = vtkCleanPolyData::New();
229 _dataMapper = vtkPolyDataMapper::New();
230 vtkActor* dataActor = vtkActor::New();
232 _cubesFilter->SetInput(this->_imagedata);
233 _cubesFilter->ComputeGradientsOn ();
234 _cubesFilter->ComputeScalarsOn ();
235 _cubesFilter->SetNumberOfContours( 1 );
236 _cleanFilter->SetInput ( _cubesFilter->GetOutput() );
237 _dataMapper->SetInput(_cleanFilter->GetOutput());
238 _dataMapper->ScalarVisibilityOff();
239 _dataMapper->ImmediateModeRenderingOn();
240 dataActor->SetMapper(_dataMapper);
242 this->_prop3D = dataActor;
244 this->changeIsoValue(this->_maxgreylevel);
249 ** changes the isovalue in a prop3D
251 void wxMaracasIRMViewManagerData::changeIsoValue(double value){
254 _cubesFilter->SetValue(0,value);
255 _cubesFilter->Update();
256 _cleanFilter->Update();
257 _dataMapper->Update();
262 int wxMaracasIRMViewManagerData::getMaxGreyLevel(){
263 return _maxgreylevel;
265 wxMaracasIRMViewManagerData::~wxMaracasIRMViewManagerData(){
266 if(_cubesFilter!=NULL){
267 _cubesFilter->Delete();
268 _cleanFilter->Delete();
269 _dataMapper->Delete();
274 ** Adds a prop3D to the world of the application
277 ** Get's the max grey level of the image
279 int wxMaracasIRMViewManagerData::getMaxLevel(vtkImageData* img){
281 int ext[6], i, j, k,max=0;
284 for(i = ext[0]; i < ext[1];i++){
285 for(j = ext[2]; j < ext[3];j++){
286 for(k = ext[4]; k < ext[5];k++){
287 unsigned short* ptr = (unsigned short*)img->GetScalarPointer(i,j,k);
288 int temp = (int)*ptr;
299 void wxMaracasIRMViewManagerData::setVtkImageData(vtkImageData* imagedata){
300 _imagedata = imagedata;
303 ** Adds a prop3D to the world of the application
305 void wxMaracasIRMViewManagerData::setProp3D(vtkProp3D* prop3D){
309 ** Changes the opacity in a prop3D
311 void wxMaracasIRMViewManagerData::changeOpacity(int value){
312 std::cout<<"chage op"<<value<<std::endl;
313 vtkActor* actor = (vtkActor*)this->_prop3D;
314 actor->GetProperty()->SetOpacity((double)value/100.0);
319 void wxMaracasIRMViewManagerData::changeColor(double red, double green, double blue){
320 std::cout<<"chage col"<<red<<green<<blue<<std::endl;
321 vtkActor* actor = (vtkActor*)this->_prop3D;
322 actor->GetProperty()->SetColor(red,green,blue);
325 ** Check if the variables are setted correctly
327 void wxMaracasIRMViewManagerData::checkInvariant(){
333 vtkProp3D* wxMaracasIRMViewManagerData::getProp3D(){
334 return this->_prop3D;
337 ** return the id from the daat
339 int wxMaracasIRMViewManagerData::getId(){
345 void wxMaracasIRMViewManagerData::setId(int propid){
352 std::string wxMaracasIRMViewManagerData::getDataname(){
358 void wxMaracasIRMViewManagerData::setDataname(std::string dataname){
359 _dataname = dataname;