1 /*=========================================================================
4 Module: $RCSfile: CutModel2Manager.cxx,v $
6 Date: $Date: 2009/11/23 13:00:30 $
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 =========================================================================*/
17 #include "CutModel2Manager.h"
20 ** Start of the manager class
22 CutModel2Manager::CutModel2Manager(std::string path){
30 CutModel2Manager::~CutModel2Manager(){
31 std::string files = _path;
32 files+="/infounrd_0_fig_0.info";
33 remove(files.c_str());
37 void CutModel2Manager::setImageData(vtkImageData* img){
42 _copyimg = vtkImageData::New();
43 _copyimg->SetExtent(_img->GetExtent());
44 _copyimg->SetSpacing(_img->GetSpacing());
45 _copyimg->AllocateScalars();
47 _copyimg->DeepCopy(_img);
51 void CutModel2Manager::setInteractor(vtkRenderWindowInteractor* interactor){
52 _interactor = interactor;
55 void CutModel2Manager::setRenderer(vtkRenderer* renderer){
59 void CutModel2Manager::onAddCutModel2(int id, vtkCommand* observer) throw( CutModelException){
63 CutModelData* data = new CutModelData(id,_interactor, observer, _copyimg);
64 _vectordata.push_back(data);
66 _render->AddActor(data->getActor());
68 //_render->UpdateCamera();
72 void CutModel2Manager::checkInvariant() throw( CutModelException){
74 throw CutModelException("The image is not set");
77 throw CutModelException("The copyimage is not set");
79 if(_interactor==NULL){
80 throw CutModelException("Interactor not set");
83 throw CutModelException("Render not set");
87 double* CutModel2Manager::getImageRange()throw( CutModelException){
89 return _copyimg->GetScalarRange();
92 void CutModel2Manager::changeOpacity(int id,int opacity)throw( CutModelException){
94 CutModelData* current = getCutModelData(id);
95 current->changeOpacity(opacity);
98 void CutModel2Manager::ShowViewBox(int id,bool check)throw( CutModelException){
100 CutModelData* current = getCutModelData(id);
101 current->ShowViewBox(check);
104 void CutModel2Manager::ChangeShape(int id,int selection)throw( CutModelException){
106 CutModelData* current = getCutModelData(id);
107 current->ChangeShape(selection);
111 CutModelData* CutModel2Manager::getCutModelData(int id)throw( CutModelException){
113 CutModelData* current = NULL;
114 for(int i= 0; i < _vectordata.size();i++){
115 std::cout<<"id in CutModel2Manager:: "<<id<<std::endl;
116 std::cout<<"vectordataid in CutModel2Manager:: "<<_vectordata[i]->getId()<<std::endl;
118 if(_vectordata[i]->getId()==id){
119 current = _vectordata[i];
124 throw CutModelException("Data not found");
129 void CutModel2Manager::updateActorDirection(int id)throw( CutModelException){
131 CutModelData* current = getCutModelData(id);
132 current->udapteActorDirection();
136 void CutModel2Manager::changeColor(int id,double r,double g,double b)throw( CutModelException){
139 CutModelData* current = getCutModelData(id);
140 current->changeColor(r,g,b);
143 void CutModel2Manager::RemoveActor(int id)throw( CutModelException){
147 CutModelData* current = getCutModelData(id);
148 for(int i = 0; i < _vectordata.size()-1;i++){
149 if(_vectordata[i]->getId()==id){
150 for(int j = i; j < _vectordata.size()-1;j++){
151 _vectordata[j]=_vectordata[j+1];
153 i = _vectordata.size();
156 _render->RemoveActor(current->getActor());
158 _vectordata.pop_back();
163 void CutModel2Manager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
166 CutModelData* current = getCutModelData(id);
167 current->ExecuteCut(range, isinside, _img);
171 Setting extra information for the undo
173 CutModelSaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL_CUT);
174 undoaction->setRange(range);
175 undoaction->setIsInside(isinside);
179 vtkImageData* CutModel2Manager::GetResultImage(){
184 void CutModel2Manager::RefreshActor(int id){
186 CutModelData* current = getCutModelData(id);
187 _render->RemoveActor(current->getActor());
188 _render->AddActor(current->getActor());
189 current->RefreshViewBox();
193 void CutModel2Manager::SaveCutModelData(std::string filename)throw( CutModelException){
196 throw CutModelException("not implemented");
205 void CutModel2Manager::LoadCutModelData(std::string filename)throw( CutModelException){
207 throw CutModelException("not implemented");
211 CutModelSaveBinInfo* CutModel2Manager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModelException){
213 for(int i = _undoredo.size()-1; i > _currentaction;i--){
215 _undoredo.pop_back();
218 CutModelSaveBinInfo* cutmodel = new CutModelSaveBinInfo(idc, _currentaction, type, _path);
219 if(type == CUTMODEL_CUT){
220 cutmodel->saveMatrix4x4(this->getCutModelData(idc)->getCurrentMatrix()->GetMatrix());
221 cutmodel->setCurrentShape(this->getCutModelData(idc)->getCurrentShape());
224 _undoredo.push_back(cutmodel);
226 _currentaction++;// = _undoredo.size();
227 //std::cout<<"current index "<<_currentaction;
232 int CutModel2Manager::Undo() throw( CutModelException){
233 //&& _currentaction < _undoredo.size()
234 if(_currentaction > 0){
235 int tempaction = _currentaction-1;
236 CutModelSaveBinInfo* currentundo = _undoredo[tempaction];
237 CutModelData* currentmodel;
239 if(currentundo->getActionType()==CUTMODEL_CUT){
241 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
243 currentmodel = getCutModelData(currentundo->getId());
245 currentmodel->setTransform(transform, _img);
247 currentmodel->setCurrentShape(currentundo->getCurrentShape());
249 currentmodel->ExecuteUnCut(currentundo->getIsInside(), _copyimg, _img);
259 int CutModel2Manager::Redo() throw( CutModelException){
261 if(_currentaction >= 0 && _currentaction < _undoredo.size()){
264 CutModelSaveBinInfo* currentundo = _undoredo[_currentaction];
265 CutModelData* currentmodel;
267 if(currentundo->getActionType()==CUTMODEL_CUT){
269 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
270 currentmodel = getCutModelData(currentundo->getId());
271 currentmodel->setTransform(transform, _copyimg);
272 currentmodel->setCurrentShape(currentundo->getCurrentShape());
273 currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _copyimg);