1 /*=========================================================================
4 Module: $RCSfile: CutModel2Manager.cxx,v $
6 Date: $Date: 2009/11/19 15:24:57 $
7 Version: $Revision: 1.1 $
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( CutModel2Exception){
62 CutModel2Data* data = new CutModel2Data(id,_interactor, observer, _copyimg);
63 _vectordata.push_back(data);
65 _render->AddActor(data->getActor());
67 //_render->UpdateCamera();
71 void CutModel2Manager::checkInvariant() throw( CutModel2Exception){
73 throw CutModel2Exception("The image is not set");
76 throw CutModel2Exception("The image is not set");
78 if(_interactor==NULL){
79 throw CutModel2Exception("Interactor not set");
82 throw CutModel2Exception("Render not set");
86 double* CutModel2Manager::getImageRange()throw( CutModel2Exception){
88 return _copyimg->GetScalarRange();
91 void CutModel2Manager::changeOpacity(int id,int opacity)throw( CutModel2Exception){
93 CutModel2Data* current = getCutModel2Data(id);
94 current->changeOpacity(opacity);
97 void CutModel2Manager::ShowViewBox(int id,bool check)throw( CutModel2Exception){
99 CutModel2Data* current = getCutModel2Data(id);
100 current->ShowViewBox(check);
103 void CutModel2Manager::ChangeShape(int id,int selection)throw( CutModel2Exception){
105 CutModel2Data* current = getCutModel2Data(id);
106 current->ChangeShape(selection);
110 CutModel2Data* CutModel2Manager::getCutModel2Data(int id)throw( CutModel2Exception){
112 CutModel2Data* current = NULL;
113 for(int i= 0; i < _vectordata.size();i++){
114 std::cout<<"id in CutModel2Manager:: "<<id<<std::endl;
115 std::cout<<"vectordataid in CutModel2Manager:: "<<_vectordata[i]->getId()<<std::endl;
117 if(_vectordata[i]->getId()==id){
118 current = _vectordata[i];
123 throw CutModel2Exception("Data not found");
128 void CutModel2Manager::updateActorDirection(int id)throw( CutModel2Exception){
130 CutModel2Data* current = getCutModel2Data(id);
131 current->udapteActorDirection();
135 void CutModel2Manager::changeColor(int id,double r,double g,double b)throw( CutModel2Exception){
138 CutModel2Data* current = getCutModel2Data(id);
139 current->changeColor(r,g,b);
142 void CutModel2Manager::RemoveActor(int id)throw( CutModel2Exception){
146 CutModel2Data* current = getCutModel2Data(id);
147 for(int i = 0; i < _vectordata.size()-1;i++){
148 if(_vectordata[i]->getId()==id){
149 for(int j = i; j < _vectordata.size()-1;j++){
150 _vectordata[j]=_vectordata[j+1];
152 i = _vectordata.size();
155 _render->RemoveActor(current->getActor());
157 _vectordata.pop_back();
162 void CutModel2Manager::ExecuteCut(int id, double* range, bool isinside)throw( CutModel2Exception){
165 CutModel2Data* current = getCutModel2Data(id);
166 current->ExecuteCut(range, isinside, _img);
170 Setting extra information for the undo
172 CutModel2SaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL2_CUT);
173 undoaction->setRange(range);
174 undoaction->setIsInside(isinside);
178 vtkImageData* CutModel2Manager::GetResultImage(){
183 void CutModel2Manager::RefreshActor(int id){
185 CutModel2Data* current = getCutModel2Data(id);
186 _render->RemoveActor(current->getActor());
187 _render->AddActor(current->getActor());
188 current->RefreshViewBox();
192 void CutModel2Manager::SaveCutModel2Data(std::string filename)throw( CutModel2Exception){
195 throw CutModel2Exception("not implemented");
204 void CutModel2Manager::LoadCutModel2Data(std::string filename)throw( CutModel2Exception){
206 throw CutModel2Exception("not implemented");
210 CutModel2SaveBinInfo* CutModel2Manager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModel2Exception){
212 for(int i = _undoredo.size()-1; i > _currentaction;i--){
214 _undoredo.pop_back();
217 CutModel2SaveBinInfo* cutmodel = new CutModel2SaveBinInfo(idc, _currentaction, type, _path);
218 if(type == CUTMODEL2_CUT){
219 cutmodel->saveMatrix4x4(this->getCutModel2Data(idc)->getCurrentMatrix()->GetMatrix());
220 cutmodel->setCurrentShape(this->getCutModel2Data(idc)->getCurrentShape());
223 _undoredo.push_back(cutmodel);
225 _currentaction++;// = _undoredo.size();
226 //std::cout<<"current index "<<_currentaction;
231 int CutModel2Manager::Undo() throw( CutModel2Exception){
232 //&& _currentaction < _undoredo.size()
233 if(_currentaction > 0){
234 int tempaction = _currentaction-1;
235 CutModel2SaveBinInfo* currentundo = _undoredo[tempaction];
236 CutModel2Data* currentmodel;
238 if(currentundo->getActionType()==CUTMODEL2_CUT){
240 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
242 currentmodel = getCutModel2Data(currentundo->getId());
244 currentmodel->setTransform(transform, _img);
246 currentmodel->setCurrentShape(currentundo->getCurrentShape());
248 currentmodel->ExecuteUnCut(currentundo->getIsInside(), _copyimg, _img);
258 int CutModel2Manager::Redo() throw( CutModel2Exception){
260 if(_currentaction >= 0 && _currentaction < _undoredo.size()){
263 CutModel2SaveBinInfo* currentundo = _undoredo[_currentaction];
264 CutModel2Data* currentmodel;
266 if(currentundo->getActionType()==CUTMODEL2_CUT){
268 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
269 currentmodel = getCutModel2Data(currentundo->getId());
270 currentmodel->setTransform(transform, _copyimg);
271 currentmodel->setCurrentShape(currentundo->getCurrentShape());
272 currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _copyimg);