1 /*=========================================================================
4 Module: $RCSfile: CutModelManager.cxx,v $
6 Date: $Date: 2009/12/08 13:42:39 $
7 Version: $Revision: 1.5 $
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 "CutModelManager.h"
18 #include "CutModelMainPanel.h"
21 ** Start of the manager class
23 CutModelManager::CutModelManager(std::string path){
32 CutModelManager::~CutModelManager(){
33 std::string files = _path;
34 files+="/infounrd_0_fig_0.info";
35 remove(files.c_str());
44 void CutModelManager::setImageData(vtkImageData* img){
45 int type = CutModelMainPanel::getInstance()->GetType();
53 _img2 = vtkImageData::New();
54 _img2->SetExtent(_img->GetExtent());
55 _img2->SetSpacing(_img->GetSpacing());
56 _img2->AllocateScalars();
58 _img2->DeepCopy(_img);
67 _img = vtkImageData::New();
68 _img->SetExtent(_img2->GetExtent());
69 _img->SetSpacing(_img2->GetSpacing());
70 _img->AllocateScalars();
72 _img->DeepCopy(_img2);
76 void CutModelManager::setInteractor(vtkRenderWindowInteractor* interactor){
77 _interactor = interactor;
80 void CutModelManager::setRenderer(vtkRenderer* renderer){
84 void CutModelManager::onAddCutModel(int id, vtkCommand* observer) throw( CutModelException){
88 CutModelData* data = new CutModelData(id,_interactor, observer, _img);
89 _vectordata.push_back(data);
91 _render->AddActor(data->getActor());
93 //_render->UpdateCamera();
97 void CutModelManager::checkInvariant() throw( CutModelException){
99 throw CutModelException("The image is not set");
102 throw CutModelException("The image is not set");
104 if(_interactor==NULL){
105 throw CutModelException("Interactor not set");
108 throw CutModelException("Render not set");
112 double* CutModelManager::getImageRange()throw( CutModelException){
114 return _img->GetScalarRange();
117 void CutModelManager::changeOpacity(int id,int opacity)throw( CutModelException){
119 CutModelData* current = getCutModelData(id);
120 current->changeOpacity(opacity);
123 void CutModelManager::ShowViewBox(int id,bool check)throw( CutModelException){
125 CutModelData* current = getCutModelData(id);
126 current->ShowViewBox(check);
129 void CutModelManager::ChangeShape(int id,int selection)throw( CutModelException){
131 CutModelData* current = getCutModelData(id);
132 current->ChangeShape(selection);
136 CutModelData* CutModelManager::getCutModelData(int id)throw( CutModelException){
138 CutModelData* current = NULL;
139 for(int i= 0; i < _vectordata.size();i++){
140 CutModelData* temp = _vectordata[i];
141 std::cout<<"id in CutModelManager:: "<<id<<std::endl;
142 std::cout<<"vectordataid in CutModelManager:: "<<temp->getId()<<std::endl;
144 if(temp->getId() == id){
150 throw CutModelException("Data not found");
155 void CutModelManager::updateActorDirection(int id)throw( CutModelException){
157 CutModelData* current = getCutModelData(id);
158 current->udapteActorDirection();
162 void CutModelManager::changeColor(int id,double r,double g,double b)throw( CutModelException){
165 CutModelData* current = getCutModelData(id);
166 current->changeColor(r,g,b);
169 void CutModelManager::RemoveActor(int id)throw( CutModelException){
173 CutModelData* current = getCutModelData(id);
174 for(int i = 0; i < _vectordata.size()-1;i++){
175 if(_vectordata[i]->getId()==id){
176 for(int j = i; j < _vectordata.size()-1;j++){
177 _vectordata[j]=_vectordata[j+1];
179 i = _vectordata.size();
182 _render->RemoveViewProp(current->getActor());
183 //_render->RemoveViewProp(current->get
185 _vectordata.pop_back();
190 void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
193 CutModelData* current = getCutModelData(id);
194 current->ExecuteCut(range, isinside,_img2);
198 Setting extra information for the undo
200 CutModelSaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL_CUT);
201 undoaction->setRange(range);
202 undoaction->setIsInside(isinside);
206 vtkImageData* CutModelManager::GetResultImage(){
211 void CutModelManager::RefreshActor(int id){
213 CutModelData* current = getCutModelData(id);
214 _render->RemoveActor(current->getActor());
215 _render->AddActor(current->getActor());
216 current->RefreshViewBox();
220 void CutModelManager::SaveCutModelData(std::string filename)throw( CutModelException){
223 throw CutModelException("not implemented");
232 void CutModelManager::LoadCutModelData(std::string filename)throw( CutModelException){
234 throw CutModelException("not implemented");
238 CutModelSaveBinInfo* CutModelManager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModelException){
240 for(int i = _undoredo.size()-1; i > _currentaction;i--){
242 _undoredo.pop_back();
245 CutModelSaveBinInfo* cutmodel = new CutModelSaveBinInfo(idc, _currentaction, type, _path);
246 if(type == CUTMODEL_CUT){
247 cutmodel->saveMatrix4x4(this->getCutModelData(idc)->getCurrentMatrix()->GetMatrix());
248 cutmodel->setCurrentShape(this->getCutModelData(idc)->getCurrentShape());
251 _undoredo.push_back(cutmodel);
253 _currentaction++;// = _undoredo.size();
254 //std::cout<<"current index "<<_currentaction;
259 int CutModelManager::Undo() throw( CutModelException){
260 //&& _currentaction < _undoredo.size()
261 if(_currentaction > 0){
262 int tempaction = _currentaction-1;
263 CutModelSaveBinInfo* currentundo = _undoredo[tempaction];
264 CutModelData* currentmodel;
266 if(currentundo->getActionType()==CUTMODEL_CUT){
268 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
270 currentmodel = getCutModelData(currentundo->getId());
272 currentmodel->setTransform(transform, _img2);
274 currentmodel->setCurrentShape(currentundo->getCurrentShape());
276 currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img, _img2);
286 int CutModelManager::Redo() throw( CutModelException){
288 if(_currentaction >= 0 && _currentaction < _undoredo.size()){
291 CutModelSaveBinInfo* currentundo = _undoredo[_currentaction];
292 CutModelData* currentmodel;
294 if(currentundo->getActionType()==CUTMODEL_CUT){
296 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
297 currentmodel = getCutModelData(currentundo->getId());
298 currentmodel->setTransform(transform, _img2);
299 currentmodel->setCurrentShape(currentundo->getCurrentShape());
300 currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _img2);