1 /*=========================================================================
4 Module: $RCSfile: CutModel2Manager.cxx,v $
6 Date: $Date: 2009/12/08 13:42:39 $
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 "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());
42 void CutModel2Manager::setImageData(vtkImageData* img){
47 _img2 = vtkImageData::New();
48 _img2->SetExtent(_img->GetExtent());
49 _img2->SetSpacing(_img->GetSpacing());
50 _img2->AllocateScalars();
52 _img2->DeepCopy(_img);
56 void CutModel2Manager::setInteractor(vtkRenderWindowInteractor* interactor){
57 _interactor = interactor;
60 void CutModel2Manager::setRenderer(vtkRenderer* renderer){
64 void CutModel2Manager::onAddCutModel2(int id, vtkCommand* observer) throw( CutModelException){
67 CutModelData* data = new CutModelData(id,_interactor, observer, _img2);
68 _vectordata.push_back(data);
70 _render->AddActor(data->getActor());
72 //_render->UpdateCamera();
76 void CutModel2Manager::checkInvariant() throw( CutModelException){
78 throw CutModelException("The image is not set");
81 throw CutModelException("The copyimage is not set");
83 if(_interactor==NULL){
84 throw CutModelException("Interactor not set");
87 throw CutModelException("Render not set");
91 double* CutModel2Manager::getImageRange()throw( CutModelException){
93 return _img2->GetScalarRange();
96 void CutModel2Manager::changeOpacity(int id,int opacity)throw( CutModelException){
98 CutModelData* current = getCutModelData(id);
99 current->changeOpacity(opacity);
102 void CutModel2Manager::ShowViewBox(int id,bool check)throw( CutModelException){
104 CutModelData* current = getCutModelData(id);
105 current->ShowViewBox(check);
108 void CutModel2Manager::ChangeShape(int id,int selection)throw( CutModelException){
110 CutModelData* current = getCutModelData(id);
111 current->ChangeShape(selection);
115 CutModelData* CutModel2Manager::getCutModelData(int id)throw( CutModelException){
117 CutModelData* current = NULL;
118 for(int i= 0; i < _vectordata.size();i++){
119 std::cout<<"id in CutModel2Manager:: "<<id<<std::endl;
120 std::cout<<"vectordataid in CutModel2Manager:: "<<_vectordata[i]->getId()<<std::endl;
122 if(_vectordata[i]->getId()==id){
123 current = _vectordata[i];
128 throw CutModelException("Data not found");
133 void CutModel2Manager::updateActorDirection(int id)throw( CutModelException){
135 CutModelData* current = getCutModelData(id);
136 current->udapteActorDirection();
140 void CutModel2Manager::changeColor(int id,double r,double g,double b)throw( CutModelException){
143 CutModelData* current = getCutModelData(id);
144 current->changeColor(r,g,b);
147 void CutModel2Manager::RemoveActor(int id)throw( CutModelException){
151 CutModelData* current = getCutModelData(id);
152 for(int i = 0; i < _vectordata.size()-1;i++){
153 if(_vectordata[i]->getId()==id){
154 for(int j = i; j < _vectordata.size()-1;j++){
155 _vectordata[j]=_vectordata[j+1];
157 i = _vectordata.size();
160 _render->RemoveActor(current->getActor());
162 _vectordata.pop_back();
167 void CutModel2Manager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
170 CutModelData* current = getCutModelData(id);
171 current->ExecuteCut(range, isinside, _img);
175 Setting extra information for the undo
177 CutModelSaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL_CUT);
178 undoaction->setRange(range);
179 undoaction->setIsInside(isinside);
183 vtkImageData* CutModel2Manager::GetResultImage(){
188 void CutModel2Manager::RefreshActor(int id){
190 CutModelData* current = getCutModelData(id);
191 _render->RemoveActor(current->getActor());
192 _render->AddActor(current->getActor());
193 current->RefreshViewBox();
197 void CutModel2Manager::SaveCutModelData(std::string filename)throw( CutModelException){
200 throw CutModelException("not implemented");
209 void CutModel2Manager::LoadCutModelData(std::string filename)throw( CutModelException){
211 throw CutModelException("not implemented");
215 CutModelSaveBinInfo* CutModel2Manager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModelException){
217 for(int i = _undoredo.size()-1; i > _currentaction;i--){
219 _undoredo.pop_back();
222 CutModelSaveBinInfo* cutmodel = new CutModelSaveBinInfo(idc, _currentaction, type, _path);
223 if(type == CUTMODEL_CUT){
224 cutmodel->saveMatrix4x4(this->getCutModelData(idc)->getCurrentMatrix()->GetMatrix());
225 cutmodel->setCurrentShape(this->getCutModelData(idc)->getCurrentShape());
228 _undoredo.push_back(cutmodel);
230 _currentaction++;// = _undoredo.size();
231 //std::cout<<"current index "<<_currentaction;
236 int CutModel2Manager::Undo() throw( CutModelException){
237 //&& _currentaction < _undoredo.size()
238 if(_currentaction > 0){
239 int tempaction = _currentaction-1;
240 CutModelSaveBinInfo* currentundo = _undoredo[tempaction];
241 CutModelData* currentmodel;
243 if(currentundo->getActionType()==CUTMODEL_CUT){
245 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
247 currentmodel = getCutModelData(currentundo->getId());
249 currentmodel->setTransform(transform, _img);
251 currentmodel->setCurrentShape(currentundo->getCurrentShape());
253 currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img2, _img);
263 int CutModel2Manager::Redo() throw( CutModelException){
265 if(_currentaction >= 0 && _currentaction < _undoredo.size()){
268 CutModelSaveBinInfo* currentundo = _undoredo[_currentaction];
269 CutModelData* currentmodel;
271 if(currentundo->getActionType()==CUTMODEL_CUT){
273 vtkTransform* transform = currentundo->getTransformFromMatrixFile();
274 currentmodel = getCutModelData(currentundo->getId());
275 currentmodel->setTransform(transform, _img2);
276 currentmodel->setCurrentShape(currentundo->getCurrentShape());
277 currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _img2);