+ checkInvariant();
+ return _img2;
+}
+
+void CutModelManager::RefreshActor(int id){
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ _render->RemoveActor(current->getActor());
+ _render->AddActor(current->getActor());
+ current->RefreshViewBox();
+ _render->Render();
+}
+
+void CutModelManager::SaveCutModelData(std::string filename)throw( CutModelException){
+
+
+ throw CutModelException("not implemented");
+
+
+
+
+}
+
+
+
+void CutModelManager::LoadCutModelData(std::string filename)throw( CutModelException){
+
+ throw CutModelException("not implemented");
+
+}
+
+CutModelSaveBinInfo* CutModelManager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModelException){
+
+ for(int i = _undoredo.size()-1; i > _currentaction;i--){
+ delete _undoredo[i];
+ _undoredo.pop_back();
+ }
+
+ CutModelSaveBinInfo* cutmodel = new CutModelSaveBinInfo(idc, _currentaction, type, _path);
+ if(type == CUTMODEL_CUT){
+ cutmodel->saveMatrix4x4(this->getCutModelData(idc)->getCurrentMatrix()->GetMatrix());
+ cutmodel->setCurrentShape(this->getCutModelData(idc)->getCurrentShape());
+ }
+
+ _undoredo.push_back(cutmodel);
+
+ _currentaction++;// = _undoredo.size();
+ //std::cout<<"current index "<<_currentaction;
+
+ return cutmodel;
+}
+
+int CutModelManager::Undo() throw( CutModelException){
+ //&& _currentaction < _undoredo.size()
+ if(_currentaction > 0){
+ int tempaction = _currentaction-1;
+ CutModelSaveBinInfo* currentundo = _undoredo[tempaction];
+ CutModelData* currentmodel;
+
+ if(currentundo->getActionType()==CUTMODEL_CUT){
+ //Undo the cut
+ vtkTransform* transform = currentundo->getTransformFromMatrixFile();
+
+ currentmodel = getCutModelData(currentundo->getId());
+
+ currentmodel->setTransform(transform, _img2);
+
+ currentmodel->setCurrentShape(currentundo->getCurrentShape());
+
+ currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img, _img2);
+
+ }
+ //Every thing ok
+ _currentaction--;
+ return 0;
+ }
+ return -1;
+}
+
+int CutModelManager::Redo() throw( CutModelException){
+
+ if(_currentaction >= 0 && _currentaction < (int)_undoredo.size()){
+
+ CutModelSaveBinInfo* currentundo = _undoredo[_currentaction];
+ CutModelData* currentmodel;
+
+ if(currentundo->getActionType()==CUTMODEL_CUT){
+ //Redo the cut
+ vtkTransform* transform = currentundo->getTransformFromMatrixFile();
+ currentmodel = getCutModelData(currentundo->getId());
+ currentmodel->setTransform(transform, _img2);
+ currentmodel->setCurrentShape(currentundo->getCurrentShape());
+ currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _img2);
+ }
+
+ _currentaction++;
+
+ return 0;
+ }
+ return -1;
+}
+
+void CutModelManager::ParallelProjectionOn(){
+ _render->GetActiveCamera()->ParallelProjectionOn();
+}
+
+void CutModelManager::ParallelProjectionOff(){
+ _render->GetActiveCamera()->ParallelProjectionOff();
+}
+
+
+//RaC
+void CutModelManager::UpdatePolygon(bool mode)
+{
+ if(mode)
+ {
+ cutterstyle->Delete();
+ cutterstyle = vtkInteractorStyleCutter::New();
+
+ cutterstyle->SetInteractor ( _interactor );
+ _interactor ->SetInteractorStyle( cutterstyle );
+ }
+ else
+ {
+ cutterstyle->VisibilityOff();
+
+ loop = vtkImplicitSelectionLoop::New();
+ mapper = vtkPolyDataMapper::New();
+ if(cutterstyle->Finished())
+ {
+ if(actor3D != NULL)
+ {
+ _render->RemoveActor(actor3D);
+ }
+
+ loop->SetLoop( cutterstyle->GetLoopPoints() );
+ loop->SetNormal( cutterstyle->GetDirection());
+
+
+ /// Printing Points
+ int numPoints = cutterstyle->GetLoopPoints()->GetNumberOfPoints();
+ contourDirection = cutterstyle->GetDirection();
+
+ contourPoints = cutterstyle->GetLoopPoints();
+
+ _polygonCutter = new CutModelPolygon();
+
+ cout<<"RaC Printing points......"<<endl;
+ for(int t=0;t<numPoints;t++)
+ {
+ double point[3];
+ cutterstyle->GetLoopPoints()->GetPoint(t,point);
+ cout<<"Initial Point:"<<t<<" XX:"<<point[0]<<" YY:"<<point[1]<<" ZZ:"<<point[2]<<endl;
+ }
+ cout<<endl;
+
+ sample = vtkSampleFunction::New();
+
+ sample->SetImplicitFunction(loop);
+ sample->CappingOn();
+
+ contour = vtkContourFilter::New();
+ contour->SetInput((vtkDataObject *)sample->GetOutput());
+ contour->SetValue(0,1);
+
+ actor = contour->GetOutput();
+
+ actor3D = vtkActor::New();
+ mapper->SetInput(actor);
+ mapper->SetScalarModeToUseCellData();
+ actor3D->SetMapper( mapper);
+ _render->AddActor(actor3D);
+ }
+
+ interactorstyle->SetInteractor ( _interactor );
+ _interactor->SetInteractorStyle( interactorstyle );
+ }
+
+ _interactor->Render();
+ _render->ResetCameraClippingRange();
+}
+void CutModelManager::ExecuteCutPolygon(bool inOutCut){
+
+ _polygonCutter->setInImage(_img2);
+ _polygonCutter->setPoints(contourPoints);
+ _polygonCutter->setDirection(contourDirection);
+ _polygonCutter->processOutImage(inOutCut);
+}
+
+void CutModelManager::InitializePolygonInteractorStyle(){
+
+ cutterstyle = vtkInteractorStyleCutter::New();
+ interactorstyle = vtkInteractorStyleTrackballCamera ::New();
+ interactorstyle->SetInteractor ( _interactor );
+ _interactor->SetInteractorStyle( interactorstyle );
+}