1 /*=========================================================================
4 Module: $RCSfile: wxMaracasIRMViewManager.cxx,v $
6 Date: $Date: 2009/04/09 13:58:38 $
7 Version: $Revision: 1.2 $
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(...){
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){
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(...){
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(...){
92 this->getViewData(propid)->changeOpacity(value);
99 ** changes the isovalue in a prop3D
101 void wxMaracasIRMViewManager::changeIsoValue(int propid, int value )throw (...){
104 wxMaracasIRMViewManagerData* data = this->getViewData(propid);
106 _renderer->RemoveViewProp(data->getProp3D());
107 data->changeIsoValue(value);
108 _renderer->AddViewProp(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(...){
145 if(this->_renderer==NULL){
146 throw "Renderer not set";
150 wxMaracasIRMViewManagerData* wxMaracasIRMViewManager::getViewData(int id) throw(...){
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){
164 return this->getViewData(propid)->getMaxGreyLevel();
168 void wxMaracasIRMViewManager::changeColor(int propid, double red, double green, double blue) throw (...){
170 this->getViewData(propid)->changeColor(red, green, blue);
174 /********************************************************************************************
175 ** Start of data viewmanagerData
176 *********************************************************************************************/
178 wxMaracasIRMViewManagerData::wxMaracasIRMViewManagerData(vtkProp3D* prop3Dvect, std::string dataname){
180 _prop3D = prop3Dvect;
181 _dataname = dataname;
184 wxMaracasIRMViewManagerData::wxMaracasIRMViewManagerData(vtkImageData* imagedata, std::string dataname){
186 this->setVtkImageData(imagedata);
187 _dataname = dataname;
189 _maxgreylevel = getMaxLevel(imagedata);
192 this->changeIsoValue(this->_maxgreylevel);
195 ** changes the isovalue in a prop3D
197 void wxMaracasIRMViewManagerData::changeIsoValue(int value){
203 _dataMapper->Delete();
206 vtkMarchingCubes *cubesFilter = vtkMarchingCubes::New();
207 cubesFilter->SetInput(this->_imagedata);
208 cubesFilter->SetValue(0,value);
209 cubesFilter->ComputeGradientsOn ();
210 cubesFilter->ComputeScalarsOn ();
211 cubesFilter->SetNumberOfContours( 1 );
213 // Unir puntos duplicados y remover primitivas degeneradas
214 vtkCleanPolyData *cleanFilter = vtkCleanPolyData::New();
215 cleanFilter->SetInput ( cubesFilter->GetOutput() );
216 cleanFilter->Update();
218 _polydata = vtkPolyData::New();
219 _polydata->DeepCopy(cleanFilter->GetOutput());
221 cubesFilter->Delete();
222 cleanFilter->Delete();
225 _dataMapper = vtkPolyDataMapper::New();
226 _dataMapper->SetInput(_polydata);
228 vtkActor* dataActor = vtkActor::New();
229 dataActor->SetMapper(_dataMapper);
234 int wxMaracasIRMViewManagerData::getMaxGreyLevel(){
235 return _maxgreylevel;
237 wxMaracasIRMViewManagerData::~wxMaracasIRMViewManagerData(){
240 ** Adds a prop3D to the world of the application
243 ** Get's the max grey level of the image
245 int wxMaracasIRMViewManagerData::getMaxLevel(vtkImageData* img){
247 int ext[6], i, j, k,max=0;
250 for(i = ext[0]; i < ext[1];i++){
251 for(j = ext[2]; j < ext[3];j++){
252 for(k = ext[4]; k < ext[5];k++){
253 unsigned short* ptr = (unsigned short*)img->GetScalarPointer(i,j,k);
254 int temp = (int)*ptr;
265 void wxMaracasIRMViewManagerData::setVtkImageData(vtkImageData* imagedata){
266 _imagedata = imagedata;
269 ** Adds a prop3D to the world of the application
271 void wxMaracasIRMViewManagerData::setProp3D(vtkProp3D* prop3D){
275 ** Changes the opacity in a prop3D
277 void wxMaracasIRMViewManagerData::changeOpacity(int value){
278 vtkActor* actor = (vtkActor*)_prop3D;
279 actor->GetProperty()->SetOpacity((double)value/100.0);
283 ** Check if the variables are setted correctly
285 void wxMaracasIRMViewManagerData::checkInvariant(){
291 vtkProp3D* wxMaracasIRMViewManagerData::getProp3D(){
295 ** return the id from the daat
297 int wxMaracasIRMViewManagerData::getId(){
303 void wxMaracasIRMViewManagerData::setId(int propid){
310 std::string wxMaracasIRMViewManagerData::getDataname(){
316 void wxMaracasIRMViewManagerData::setDataname(std::string dataname){
317 _dataname = dataname;
320 void wxMaracasIRMViewManagerData::changeColor(double red, double green, double blue){
321 vtkActor* actor = (vtkActor*)_prop3D;
322 actor->GetProperty()->SetColor(red,green,blue);