SUBDIRS(CutModule)
-SUBDIRS(CutModule2)
+
+++ /dev/null
-#----------------------------------------------------------------------------
-# SET THE NAME OF YOUR LIBRARY
-
-
-SET ( LIBRARY_NAME creaMaracasVisu_CutModule2 )
-#----------------------------------------------------------------------------
-
-#----------------------------------------------------------------------------
-# CREATES A USER OPTION IN CMAKE
-OPTION ( BUILD_${LIBRARY_NAME} "Build ${LIBRARY_NAME} library ?" ON)
-
-#----------------------------------------------------------------------------
-IF ( BUILD_${LIBRARY_NAME} )#----------------------------------------------------------------------------
-
- #----------------------------------------------------------------------------
- # BUILD LIBRARY
- #----------------------------------------------------------------------------
-#jhcl-Start===========================================================================
- INCLUDE_DIRECTORIES(
- interface
- kernel
-)
- SUBDIRS(interface)
- SUBDIRS(kernel)
-ENDIF ( BUILD_${LIBRARY_NAME} )
-
+++ /dev/null
-#----------------------------------------------------------------------------
-# SET THE NAME OF YOUR LIBRARY
-SET ( LIBRARY_NAME creaMaracasVisu_CutModule2_interface )
-#----------------------------------------------------------------------------
-#----------------------------------------------------------------------------
-
- #----------------------------------------------------------------------------
- # BUILD LIBRARY
- #----------------------------------------------------------------------------
-
- #----------------------------------------------------------------------------
- # LIBRARY HEADERS (TO BE INSTALLED)
- # EITHER LIST ALL .h IN CURRENT DIR USING NEXT LINE:
- FILE(GLOB ${LIBRARY_NAME}_HEADERS "*.h")
- # OR MANUALLY LIST YOUR HEADERS WITH NEXT COMMAND
- # SET ( ${LIBRARY_NAME}_HEADERS
- #
- # )
- #----------------------------------------------------------------------------
-
- #----------------------------------------------------------------------------
- # LIBRARY SOURCES (TO BE COMPILED)
- # EITHER LIST ALL .cxx, *.cpp, *.cc IN CURRENT DIR USING NEXT LINE:
- FILE(GLOB ${LIBRARY_NAME}_SOURCES *.cxx *.cpp *.cc)
- # OR MANUALLY LIST YOUR FILES WITH NEXT COMMAND (WITHOUT EXTENSION)
- # SET ( ${LIBRARY_NAME}_SOURCES
- #
- # )
- #----------------------------------------------------------------------------
-
- #----------------------------------------------------------------------------
- # LIBRARY DEPENDENCIES (LIBRARIES TO LINK WITH)
- SET ( ${LIBRARY_NAME}_LINK_LIBRARIES
- ${crea_LIBRARIES}
- ${WXWIDGETS_LIBRARIES}
- # ${VTK_LIBRARIES}
- # ${ITK_LIBRARIES}
- # ${GDCM_LIBRARIES}
- # ${BOOST_LIBRARIES}
- )
- #----------------------------------------------------------------------------
-
-
- #----------------------------------------------------------------------------
- # MACRO WHICH DOES ALL THE JOB : BUILD AND INSTALL
- #CREA_ADD_LIBRARY( ${LIBRARY_NAME} )
- #----------------------------------------------------------------------------
-
- ADD_LIBRARY(${LIBRARY_NAME} STATIC ${${LIBRARY_NAME}_SOURCES} ${${LIBRARY_NAME}_HEADERS} )
- # LINK
- TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${${LIBRARY_NAME}_LINK_LIBRARIES})
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2MainPanel.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:56 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-// EOF - wxMaracasMPR.cxx
-
-#include "CutModel2MainPanel.h"
-#include "HistogramDialog.h"
-#include "creaSystem.h"
-
-#include <wx/colordlg.h>
-#include <wx/bmpbuttn.h>
-
-#include <Add.xpm>
-#include <Undo.xpm>
-#include <Redo.xpm>
-#include <OkAll.xpm>
-
-
-
-CutModel2MainPanel* CutModel2MainPanel::instance=NULL;
-
-CutModel2MainPanel::CutModel2MainPanel( wxWindow* parent, std::string path)
-: wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
-
- cutmanager=NULL;
-
- initialize(path);
-
-}
-CutModel2MainPanel::~CutModel2MainPanel( ){
-
- delete cutmanager;
-}
-
-void CutModel2MainPanel::initialize(std::string path){
-
- cutmanager = new CutModel2Manager(path);
-
- _panelid = 0;
- _wxauimanager = new wxAuiManager(this);
-
- wxAuiPaneInfo paneinfo;
- _wxauimanager->AddPane(new ToolBarCutModel2(this),paneinfo.ToolbarPane().Top());
-
- _wxauimanager->Update();
-}
-
-CutModel2MainPanel* CutModel2MainPanel::getInstance(wxWindow* parent, std::string path){
- if(instance==NULL){
- if(parent == NULL){
- parent = new wxFrame();
- }
- instance = new CutModel2MainPanel(parent, path);
- }
- return instance;
-}
-
-/*CutModel2MainPanel* CutModel2MainPanel::getInstance(){
- return instance;
-}*/
-
-void CutModel2MainPanel::setImageData(vtkImageData* img){
- try{
- checkInvariant();
- cutmanager->setImageData(img);
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModel2MainPanel::setInteractor(vtkRenderWindowInteractor* interactor){
- try{
- checkInvariant();
- cutmanager->setInteractor(interactor);
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModel2MainPanel::setRenderer(vtkRenderer* renderer){
- try{
- checkInvariant();
- cutmanager->setRenderer(renderer);
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModel2MainPanel::checkInvariant()throw (CutModel2Exception){
- if(cutmanager==NULL){
- throw CutModel2Exception("The manager is not initialize");
- }
-}
-
-void CutModel2MainPanel::showErrorDialog(std::string str){
- wxMessageDialog* diag = new wxMessageDialog(this, wxString(str.c_str(),wxConvUTF8 ), wxString(str.c_str(),wxConvUTF8 ), wxICON_ERROR);
- diag->ShowModal();
-}
-
-void CutModel2MainPanel::RemoveActor(int id){
- try{
- checkInvariant();
-
- for(int i = 0; i < viewpanels.size()-1;i++){
- if(viewpanels[i]->getId()==id){
- for(int j = i; j < viewpanels.size()-1;j++){
- viewpanels[j]=viewpanels[j+1];
- }
- i = viewpanels.size();
- }
- }
- viewpanels.pop_back();
-
-
- cutmanager->RemoveActor(id);
-
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModel2MainPanel::onAddCutModel2(){
- try{
- checkInvariant();
-
- int id = addNewViewPanel();
- cutmanager->onAddCutModel2(id, getModelView(id));
-
- _panelid++;
-
- ShowCurrentPanel(id);
-
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-}
-void CutModel2MainPanel::ShowCurrentPanel(int id){
- for(int i = 0; i < viewpanels.size();i++){
- if(viewpanels[i]->getId()==id){
- _wxauimanager->GetPane(viewpanels[i]).Show(true);
- cutmanager->RefreshActor(id);
- }else{
- _wxauimanager->GetPane(viewpanels[i]).Show(false);
- }
- }
- _wxauimanager->Update();
-}
-int CutModel2MainPanel::addNewViewPanel()throw( CutModel2Exception){
-
- CutModel2View* viewpanel = new CutModel2View(this,cutmanager->getImageRange());
-
- wxAuiPaneInfo paneinfo0;
- _wxauimanager->AddPane(viewpanel, paneinfo0.DefaultPane().DestroyOnClose().Centre());
- _wxauimanager->Update();
-
- viewpanel->setId(_panelid);
- viewpanels.push_back(viewpanel);
-
- return viewpanel->getId();
-
-
-}
-CutModel2View* CutModel2MainPanel::getModelView(int id)throw( CutModel2Exception){
-
- CutModel2View* current = NULL;
- for(int i = 0; i < viewpanels.size();i++){
- if(viewpanels[i]->getId()==id){
- current = viewpanels[i];
- }
- }
- if(current == NULL){
- std::string s = "Id not found";
- throw CutModel2Exception(s);
- }
- return current;
-}
-void CutModel2MainPanel::onUndo(){
- try{
- checkInvariant();
- int result = cutmanager->Undo();
-
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-
-}
-
-void CutModel2MainPanel::onRedo(){
-
- try{
- checkInvariant();
- int result = cutmanager->Redo();
-
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-
-}
-
-void CutModel2MainPanel::changeOpacity(int id,int opacity){
- try{
- checkInvariant();
- cutmanager->changeOpacity(id, opacity);
-
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModel2MainPanel::ShowViewBox(int id,bool check){
- try{
- checkInvariant();
- cutmanager->ShowViewBox(id, check);
-
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-}
-void CutModel2MainPanel::ShowPopUpMenu(int id){
- showErrorDialog("test");
-}
-void CutModel2MainPanel::changeColor(int id,double r,double g,double b){
-
- try{
- checkInvariant();
- cutmanager->changeColor(id, r, g, b);
-
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-
-}
-void CutModel2MainPanel::ChangeShape(int id,int selection){
- try{
- checkInvariant();
-
- cutmanager->ChangeShape(id, selection);
-
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-}
-void CutModel2MainPanel::updateActorDirection(int id){
- try{
- checkInvariant();
-
- cutmanager->updateActorDirection(id);
-
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModel2MainPanel::ExecuteCut(int id, double* range, bool isinside){
- try{
- checkInvariant();
-
- cutmanager->ExecuteCut(id, range, isinside);
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModel2MainPanel::ExecuteAll(){
- for(int i = 0; i < viewpanels.size();i++){
- viewpanels[i]->ExecuteCut();
- }
-
-}
-vtkImageData* CutModel2MainPanel::GetResultImage(){
- try{
- checkInvariant();
- return cutmanager->GetResultImage();
- }catch(CutModel2Exception e){
- showErrorDialog(e.getCause());
- }
- return NULL;
-}
-
-void CutModel2MainPanel::ShowStatistics(int id){
-
- checkInvariant();
- HistogramDialog *histo = new HistogramDialog(this, _T("Statistics"));
-
- histo->initializeHistogram(cutmanager->GetResultImage());
-
- histo->ShowModal();
-
- delete histo;
-}
-
-void CutModel2MainPanel::SaveCutModel2Data(std::string filename){
- cutmanager->SaveCutModel2Data(filename);
-}
-
-void CutModel2MainPanel::LoadCutModel2Data(std::string filename){
- cutmanager->LoadCutModel2Data(filename);
-}
-/**
-**
-**/
-
-ToolBarCutModel2::ToolBarCutModel2(wxWindow * parent)
-: wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
-{
-
- wxBitmap bitmap10(Add_xpm);
- this->AddTool(10, wxString(_T("Add")),bitmap10);
-
- this->AddSeparator();
-
- wxBitmap bitmap20(Undo_xpm);
- this->AddTool(20, wxString(_T("Undo")),bitmap20);
-
- wxBitmap bitmap30(Redo_xpm);
- this->AddTool(30, wxString(_T("Redo")),bitmap30);
-
- this->AddSeparator();
-
- wxBitmap bitmap40(OkAll_xpm);
- this->AddTool(40, wxString(_T("Ok All")),bitmap40);
-
- this->Realize();
-
- _evthand = new ToolBarEventHandlerCutModel2();
- this->SetEventHandler(_evthand);
-
-}
-
-ToolBarCutModel2::~ToolBarCutModel2(void){
-}
-
-ToolBarEventHandlerCutModel2::ToolBarEventHandlerCutModel2()
-: wxEvtHandler(){
-}
-ToolBarEventHandlerCutModel2::~ToolBarEventHandlerCutModel2(){
-}
-
-void ToolBarEventHandlerCutModel2::onAdd(wxCommandEvent& event){
- CutModel2MainPanel::getInstance()->onAddCutModel2();
-}
-
-void ToolBarEventHandlerCutModel2::onUndo(wxCommandEvent& event){
- CutModel2MainPanel::getInstance()->onUndo();
-}
-
-void ToolBarEventHandlerCutModel2::onRedo(wxCommandEvent& event){
- CutModel2MainPanel::getInstance()->onRedo();
-}
-
-void ToolBarEventHandlerCutModel2::onExecuteAll(wxCommandEvent& event){
- CutModel2MainPanel::getInstance()->ExecuteAll();
-}
-
-
-BEGIN_EVENT_TABLE(ToolBarEventHandlerCutModel2, wxEvtHandler)
- EVT_MENU(10, ToolBarEventHandlerCutModel2::onAdd)
- EVT_MENU(20, ToolBarEventHandlerCutModel2::onUndo)
- EVT_MENU(30, ToolBarEventHandlerCutModel2::onRedo)
- EVT_MENU(40, ToolBarEventHandlerCutModel2::onExecuteAll)
-END_EVENT_TABLE()
-
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2MainPanel.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:56 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-#ifndef __CutModel2MainPanelPanelH__
-#define __CutModel2MainPanelPanelH__
-
-#include <vector>
-#include <wx/wx.h>
-#include <wx/treebook.h>
-#include "wx/aui/aui.h"
-#include <wx/toolbar.h>
-#include <iostream>
-#include "marTypes.h"
-
-
-#include "CutModel2Manager.h"
-#include "CutModel2Exception.h"
-#include "CutModel2View.h"
-
-#include "vtkImageData.h"
-#include "vtkRenderWindowInteractor.h"
-
-
-class creaMaracasVisu_EXPORT CutModel2MainPanel : public wxPanel
-{
-
-public:
-
- ~CutModel2MainPanel( );
-
- static CutModel2MainPanel* getInstance(wxWindow* parent=NULL, std::string path ="");
-
- //static CutModel2MainPanel* getInstance();
-
- void setImageData(vtkImageData* img);
-
- void setInteractor(vtkRenderWindowInteractor* interactor);
-
- void setRenderer(vtkRenderer* renderer);
-
- void initialize(std::string path);
-
- void onAddCutModel2();
-
- void onUndo();
-
- void onRedo();
-
- void changeOpacity(int id,int opacity);
-
- void ShowViewBox(int id,bool check);
-
- void ChangeShape(int id,int selection);
-
- void changeColor(int id,double r,double g,double b);
-
- void updateActorDirection(int id);
-
- void RemoveActor(int id);
-
- void ExecuteCut(int id, double* range, bool isinside);
-
- void ExecuteAll();
-
- vtkImageData* GetResultImage();
-
- void ShowCurrentPanel(int id);
-
- void ShowPopUpMenu(int id);
-
- void ShowStatistics(int id);
-
-
-private:
-
- CutModel2MainPanel( wxWindow* parent, std::string path);
-
- static CutModel2MainPanel* instance;
-
- CutModel2Manager* cutmanager;
-
- void checkInvariant() throw( CutModel2Exception);
-
- void showErrorDialog(std::string str);
-
- void SaveCutModel2Data(std::string filename);
-
- void LoadCutModel2Data(std::string filename);
-
- std::vector<CutModel2View*> viewpanels;
-
- wxAuiManager* _wxauimanager;
-
-
- int addNewViewPanel()throw( CutModel2Exception);
-
- CutModel2View* getModelView(int id)throw( CutModel2Exception);
-
- int _panelid;
-};
-
-
-class ToolBarEventHandlerCutModel2 : public wxEvtHandler{
-
- public:
- ToolBarEventHandlerCutModel2();
- ~ToolBarEventHandlerCutModel2();
-
- void onAdd(wxCommandEvent& event);
-
- void onUndo(wxCommandEvent& event);
-
- void onRedo(wxCommandEvent& event);
-
- void onExecuteAll(wxCommandEvent& event);
-
- private:
-
- DECLARE_EVENT_TABLE()
- };
-
-class ToolBarCutModel2 : public wxToolBar{
-
-
-public:
- ToolBarCutModel2(wxWindow * parent);
- ~ToolBarCutModel2(void);
-
-
-private:
-
- ToolBarEventHandlerCutModel2* _evthand;
-
-};
-
-#endif
-
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2View.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:56 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-// EOF - wxMaracasMPR.cxx
-
-#include "CutModel2View.h"
-
-
-#include <wx/colordlg.h>
-#include <wx/bmpbuttn.h>
-
-#include <OpenImage.xpm>
-#include <Color.xpm>
-#include <Ok1.xpm>
-#include <Statistics.xpm>
-
-#include "vtkBoxWidget.h"
-
-#include "CutModel2MainPanel.h"
-
-CutModel2View::CutModel2View( wxWindow* parent, double* range)
-: wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
-
- wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
-
- this->SetSizer(sizer);
-
- sizer->Add(getBoxControls(this, range),wxSizerFlags().FixedMinSize());
-
- sizer->AddSpacer(5);
-
- sizer->Add(getActorProperties(this),wxSizerFlags().FixedMinSize());
-
-
- wxBitmap bitmapok(Ok1_xpm);
- wxBitmapButton* okbutton = new wxBitmapButton(this, -1, bitmapok,wxDefaultPosition,wxSize(30,30));
- Connect(okbutton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModel2ViewEventHandler::onExecute));
-
- sizer->AddSpacer(5);
- sizer->Add(okbutton,wxSizerFlags().FixedMinSize());
-
-
-
-
-
-}
-CutModel2View::~CutModel2View( ){
- CutModel2MainPanel::getInstance()->RemoveActor(this->getId());
-}
-
-wxSizer* CutModel2View::getBoxControls(wxWindow* parent,double* range){
-
- wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
- wxCheckBox* checkbox = new wxCheckBox(parent,-1,_T("View Box"));
- sizer->Add(checkbox,wxSizerFlags().FixedMinSize());
- checkbox->SetValue(true);
- Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)(&CutModel2ViewEventHandler::onViewBoxChecked));
-
- wxString choices1[3];
- //choices1[0] = _T("Select a shape...");
- choices1[0] = _T("Sphere");
- choices1[1] = _T("Cylinder");
- choices1[2] = _T("Cube");
- wxComboBox* combo = new wxComboBox(parent, -1,_T(""),wxDefaultPosition,wxDefaultSize,3,choices1);
- combo->SetValue(_T("Sphere"));
- sizer->Add(combo,wxSizerFlags().FixedMinSize());
- Connect(combo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED,(wxObjectEventFunction)(&CutModel2ViewEventHandler::onShapeChange));
-
- wxStaticText* labelgreyv = new wxStaticText(parent, -1, wxString(_T("Grey value range")));
- _sliderrange = new wxSlider(parent, -1, range[0],range[0],range[1],wxDefaultPosition,wxDefaultSize,wxSL_LABELS|wxSL_SELRANGE);
- wxBoxSizer* sizergreyv = new wxBoxSizer(wxVERTICAL);
- sizergreyv->Add(labelgreyv,wxSizerFlags().FixedMinSize());
- sizergreyv->Add(_sliderrange,wxSizerFlags().FixedMinSize());
- sizer->Add(sizergreyv,wxSizerFlags().FixedMinSize().Border());
-
- wxString choices0[2];
- choices0[0] = _T("inside");
- choices0[1] = _T("outside");
- _radioinsideout = new wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices0);
- sizer->Add(_radioinsideout,wxSizerFlags().FixedMinSize());
-
- /*wxString choices[2];
- choices[0] = _T("Cut");
- choices[1] = _T("Statistics");
- _radiocutstat = new wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices);
- sizer->Add(_radiocutstat,wxSizerFlags().FixedMinSize());*/
-
- wxBitmap bitmap(Statistics_xpm);
- wxBitmapButton* statbut = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));
- Connect(statbut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModel2ViewEventHandler::onStatistics));
- sizer->Add(statbut,wxSizerFlags().FixedMinSize());
-
-
-
- return sizer;
-}
-wxSizer* CutModel2View::getActorProperties(wxWindow* parent){
-
- wxBoxSizer* sizeractorproperties = new wxBoxSizer(wxVERTICAL);
-
- wxStaticText* labelshapeactor = new wxStaticText(parent, -1, wxString(_T("Actor's properties")));
-
- sizeractorproperties->Add(labelshapeactor,wxSizerFlags().FixedMinSize());
-
- sizeractorproperties->Add(getColorChooseActor(parent),wxSizerFlags().FixedMinSize());
-
- sizeractorproperties->Add(getOpacityActor(parent),wxSizerFlags().FixedMinSize());
-
- return sizeractorproperties;
-
-}
-
-wxSizer* CutModel2View::getOpacityActor(wxWindow* parent){
- wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);
-
- wxStaticText* labelopacity = new wxStaticText(parent, -1, wxString(_T("Opacity")));
- wxSlider* slider0 = new wxSlider(parent, -1, 60,0,100,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
- Connect(slider0->GetId(), wxEVT_SCROLL_THUMBRELEASE,(wxObjectEventFunction)(&CutModel2ViewEventHandler::onOpacityChange));
-
- sizeropacity->Add(labelopacity,wxSizerFlags().FixedMinSize());
- sizeropacity->Add(slider0,wxSizerFlags().FixedMinSize());
-
- return sizeropacity;
-}
-
-wxSizer* CutModel2View::getColorChooseActor(wxWindow* parent){
- wxBoxSizer* sizercolor = new wxBoxSizer(wxHORIZONTAL);
- wxBitmap bitmap(Color_xpm);
- wxBitmapButton* colorchoose = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));
- wxObjectEventFunction f = (wxObjectEventFunction)(&CutModel2ViewEventHandler::onColorChange);
- Connect(colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, f);
-
- _currentcolor = new wxStaticText(parent,-1,_T(""),wxDefaultPosition,wxSize(20,20));
- this->SetCurrentColor(wxColour(255.0,0.0,0.0));
-
- sizercolor->Add(colorchoose,wxSizerFlags().FixedMinSize());
- sizercolor->AddSpacer(5);
- sizercolor->Add(_currentcolor,wxSizerFlags().FixedMinSize().Centre());
- return sizercolor;
-}
-
-void CutModel2View::checkInvariant()throw (CutModel2Exception){
-
-}
-
-void CutModel2View::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
- //vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
-
- if(eventId==vtkCommand::StartInteractionEvent){
- CutModel2MainPanel::getInstance()->ShowCurrentPanel(this->getId());
- }else if(eventId==vtkCommand::InteractionEvent){
- CutModel2MainPanel::getInstance()->updateActorDirection(this->getId());
- }else if(eventId==vtkCommand::RightButtonReleaseEvent){
- // =(
- CutModel2MainPanel::getInstance()->ShowPopUpMenu(this->getId());
- }
-}
-
-void CutModel2View::ExecuteCut(){
- if(this->isCut()){
- CutModel2MainPanel::getInstance()->ExecuteCut(this->getId(),this->getRange(),this->isInside());
- }else{
- }
-
-}
-
-double* CutModel2View::getRange(){
- double* x = new double[3];
- x[0] = 0;
- x[1] = _sliderrange->GetValue();
- x[2] = 100000;
-
- return x;
-}
-bool CutModel2View::isCut(){
- return true;
- //return _radiocutstat->GetSelection()==0;
-}
-bool CutModel2View::isInside(){
- return _radioinsideout->GetSelection()==0;
-}
-void CutModel2View::SetCurrentColor(wxColour colour){
- _currentcolor->SetBackgroundColour(colour);
-
- this->Refresh();
- this->Layout();
-}
-
-void CutModel2ViewEventHandler::onColorChange(wxCommandEvent& event){
- CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
- wxColourDialog* colourdiag = new wxColourDialog(parent);
- if(colourdiag->ShowModal()==wxID_OK){
- wxColour colour = colourdiag->GetColourData().GetColour();
-
- parent->SetCurrentColor(colour);
-
- double r = (double)(colour.Red())/255.0;
- double g = (double)(colour.Green())/255.0;
- double b = (double)(colour.Blue())/255.0;
- CutModel2MainPanel::getInstance()->changeColor(parent->getId(),r,g,b);
-
-
- }
- delete colourdiag;
-}
-
-void CutModel2ViewEventHandler::onOpacityChange(wxScrollEvent& event){
- CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
-
- CutModel2MainPanel::getInstance()->changeOpacity(parent->getId(),event.GetInt());
-}
-void CutModel2ViewEventHandler::onViewBoxChecked(wxCommandEvent& event){
- CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
-
- CutModel2MainPanel::getInstance()->ShowViewBox(parent->getId(),event.IsChecked());
-}
-void CutModel2ViewEventHandler::onShapeChange(wxCommandEvent& event){
- CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
-
- //if(event.GetSelection()>0){
- //std::cout<<"id in CutModel2ViewEventHandler:: "<<parent->getId()<<std::endl;
- CutModel2MainPanel::getInstance()->ChangeShape(parent->getId(),event.GetSelection());
- //}
-}
-void CutModel2ViewEventHandler::onStatistics(wxCommandEvent& event){
- CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
- CutModel2MainPanel::getInstance()->ShowStatistics(parent->getId());
-}
-void CutModel2ViewEventHandler::onExecute(wxCommandEvent& event){
- CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
-
- parent->ExecuteCut();
-
-}
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2View.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:56 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-#ifndef __CutModel2ViewPanelH__
-#define __CutModel2ViewPanelH__
-
-#include <vector>
-#include <wx/wx.h>
-#include <wx/radiobut.h>
-#include "wx/aui/aui.h"
-#include <iostream>
-#include "marTypes.h"
-
-
-#include "CutModel2Manager.h"
-#include "CutModel2Exception.h"
-
-#include "vtkObject.h"
-#include "vtkCommand.h"
-
-
-class creaMaracasVisu_EXPORT CutModel2View : public wxPanel, public vtkCommand
-{
-
-public:
- CutModel2View( wxWindow* parent,double* range);
- ~CutModel2View( );
-
- virtual void Execute(vtkObject *wdg, unsigned long eventId, void* calldata) ;
-
- int getId(){
- return _id;
- }
- void setId(int id){
- _id = id;
- }
-
- void ExecuteCut();
-
- void SetCurrentColor(wxColour colour);
-
-private:
-
- int _id;
-
- wxSlider* _sliderrange;
- wxRadioBox* _radioinsideout;
- //wxRadioBox* _radiocutstat;
- wxStaticText* _currentcolor;
-
- double* getRange();
- bool isCut();
- bool isInside();
-
-
-
- wxSizer* getBoxControls(wxWindow* parent, double* range);
-
-
- wxSizer* getActorProperties(wxWindow* parent);
- wxSizer* getColorChooseActor(wxWindow* parent);
- wxSizer* getOpacityActor(wxWindow* parent);
-
- void checkInvariant() throw( CutModel2Exception);
-
-};
-
-class CutModel2ViewEventHandler : public wxEvtHandler{
-
- public:
- CutModel2ViewEventHandler(): wxEvtHandler(){};
- ~CutModel2ViewEventHandler(){};
-
- void onColorChange(wxCommandEvent& event);
- void onOpacityChange(wxScrollEvent& event);
- void onViewBoxChecked(wxCommandEvent& event);
- void onShapeChange(wxCommandEvent& event);
- void onStatistics(wxCommandEvent& event);
- void onExecute(wxCommandEvent& event);
-
-
-
- private:
-
-};
-
-
-#endif
-
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelMainPanel.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:56 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-// EOF - wxMaracasMPR.cxx
-
-#include "CutModelMainPanel.h"
-#include "HistogramDialog.h"
-#include "creaSystem.h"
-
-#include <wx/colordlg.h>
-#include <wx/bmpbuttn.h>
-
-#include <Add.xpm>
-#include <Undo.xpm>
-#include <Redo.xpm>
-#include <OkAll.xpm>
-
-
-
-CutModelMainPanel* CutModelMainPanel::instance=NULL;
-
-CutModelMainPanel::CutModelMainPanel( wxWindow* parent, std::string path)
-: wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
-
- cutmanager=NULL;
-
- initialize(path);
-
-}
-CutModelMainPanel::~CutModelMainPanel( ){
-
- delete cutmanager;
-}
-
-void CutModelMainPanel::initialize(std::string path){
-
- cutmanager = new CutModelManager(path);
-
- _panelid = 0;
- _wxauimanager = new wxAuiManager(this);
-
- wxAuiPaneInfo paneinfo;
- _wxauimanager->AddPane(new ToolBarCutModel(this),paneinfo.ToolbarPane().Top());
-
- _wxauimanager->Update();
-}
-
-CutModelMainPanel* CutModelMainPanel::getInstance(wxWindow* parent, std::string path){
- if(instance==NULL){
- if(parent == NULL){
- parent = new wxFrame();
- }
- instance = new CutModelMainPanel(parent, path);
- }
- return instance;
-}
-
-/*CutModelMainPanel* CutModelMainPanel::getInstance(){
- return instance;
-}*/
-
-void CutModelMainPanel::setImageData(vtkImageData* img){
- try{
- checkInvariant();
- cutmanager->setImageData(img);
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModelMainPanel::setInteractor(vtkRenderWindowInteractor* interactor){
- try{
- checkInvariant();
- cutmanager->setInteractor(interactor);
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModelMainPanel::setRenderer(vtkRenderer* renderer){
- try{
- checkInvariant();
- cutmanager->setRenderer(renderer);
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModelMainPanel::checkInvariant()throw (CutModelException){
- if(cutmanager==NULL){
- throw CutModelException("The manager is not initialize");
- }
-}
-
-void CutModelMainPanel::showErrorDialog(std::string str){
- wxMessageDialog* diag = new wxMessageDialog(this, wxString(str.c_str(),wxConvUTF8 ), wxString(str.c_str(),wxConvUTF8 ), wxICON_ERROR);
- diag->ShowModal();
-}
-
-void CutModelMainPanel::RemoveActor(int id){
- try{
- checkInvariant();
-
- for(int i = 0; i < viewpanels.size()-1;i++){
- if(viewpanels[i]->getId()==id){
- for(int j = i; j < viewpanels.size()-1;j++){
- viewpanels[j]=viewpanels[j+1];
- }
- i = viewpanels.size();
- }
- }
- viewpanels.pop_back();
-
-
- cutmanager->RemoveActor(id);
-
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModelMainPanel::onAddCutModel(){
- try{
- checkInvariant();
-
- int id = addNewViewPanel();
- cutmanager->onAddCutModel(id, getModelView(id));
-
- _panelid++;
-
- ShowCurrentPanel(id);
-
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-}
-void CutModelMainPanel::ShowCurrentPanel(int id){
- for(int i = 0; i < viewpanels.size();i++){
- if(viewpanels[i]->getId()==id){
- _wxauimanager->GetPane(viewpanels[i]).Show(true);
- cutmanager->RefreshActor(id);
- }else{
- _wxauimanager->GetPane(viewpanels[i]).Show(false);
- }
- }
- _wxauimanager->Update();
-}
-int CutModelMainPanel::addNewViewPanel()throw( CutModelException){
-
- CutModelView* viewpanel = new CutModelView(this,cutmanager->getImageRange());
-
- wxAuiPaneInfo paneinfo0;
- _wxauimanager->AddPane(viewpanel, paneinfo0.DefaultPane().DestroyOnClose().Centre());
-
- viewpanel->setId(_panelid);
- viewpanels.push_back(viewpanel);
-
- return viewpanel->getId();
-
-
-}
-CutModelView* CutModelMainPanel::getModelView(int id)throw( CutModelException){
-
- CutModelView* current = NULL;
- for(int i = 0; i < viewpanels.size();i++){
- if(viewpanels[i]->getId()==id){
- current = viewpanels[i];
- }
- }
- if(current == NULL){
- std::string s = "Id not found";
- throw CutModelException(s);
- }
- return current;
-}
-void CutModelMainPanel::onUndo(){
- try{
- checkInvariant();
- int result = cutmanager->Undo();
-
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-
-}
-
-void CutModelMainPanel::onRedo(){
-
- try{
- checkInvariant();
- int result = cutmanager->Redo();
-
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-
-}
-
-void CutModelMainPanel::changeOpacity(int id,int opacity){
- try{
- checkInvariant();
- cutmanager->changeOpacity(id, opacity);
-
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModelMainPanel::ShowViewBox(int id,bool check){
- try{
- checkInvariant();
- cutmanager->ShowViewBox(id, check);
-
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-}
-void CutModelMainPanel::ShowPopUpMenu(int id){
- showErrorDialog("test");
-}
-void CutModelMainPanel::changeColor(int id,double r,double g,double b){
-
- try{
- checkInvariant();
- cutmanager->changeColor(id, r, g, b);
-
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-
-}
-void CutModelMainPanel::ChangeShape(int id,int selection){
- try{
- checkInvariant();
-
- cutmanager->ChangeShape(id, selection);
-
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-}
-void CutModelMainPanel::updateActorDirection(int id){
- try{
- checkInvariant();
-
- cutmanager->updateActorDirection(id);
-
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModelMainPanel::ExecuteCut(int id, double* range, bool isinside){
- try{
- checkInvariant();
-
- cutmanager->ExecuteCut(id, range, isinside);
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
-}
-
-void CutModelMainPanel::ExecuteAll(){
- for(int i = 0; i < viewpanels.size();i++){
- viewpanels[i]->ExecuteCut();
- }
-
-}
-vtkImageData* CutModelMainPanel::GetResultImage(){
- try{
- checkInvariant();
- return cutmanager->GetResultImage();
- }catch(CutModelException e){
- showErrorDialog(e.getCause());
- }
- return NULL;
-}
-
-void CutModelMainPanel::ShowStatistics(int id){
-
- checkInvariant();
- HistogramDialog *histo = new HistogramDialog(this, _T("Statistics"));
-
- histo->initializeHistogram(cutmanager->GetResultImage());
-
- histo->ShowModal();
-
- delete histo;
-}
-
-void CutModelMainPanel::SaveCutModelData(std::string filename){
- cutmanager->SaveCutModelData(filename);
-}
-
-void CutModelMainPanel::LoadCutModelData(std::string filename){
- cutmanager->LoadCutModelData(filename);
-}
-/**
-**
-**/
-
-ToolBarCutModel::ToolBarCutModel(wxWindow * parent)
-: wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
-{
-
- wxBitmap bitmap10(Add_xpm);
- this->AddTool(10, wxString(_T("Add")),bitmap10);
-
- this->AddSeparator();
-
- wxBitmap bitmap20(Undo_xpm);
- this->AddTool(20, wxString(_T("Undo")),bitmap20);
-
- wxBitmap bitmap30(Redo_xpm);
- this->AddTool(30, wxString(_T("Redo")),bitmap30);
-
- this->AddSeparator();
-
- wxBitmap bitmap40(OkAll_xpm);
- this->AddTool(40, wxString(_T("Ok All")),bitmap40);
-
- this->Realize();
-
- _evthand = new ToolBarEventHandlerCutModel();
- this->SetEventHandler(_evthand);
-
-}
-
-ToolBarCutModel::~ToolBarCutModel(void){
-}
-
-ToolBarEventHandlerCutModel::ToolBarEventHandlerCutModel()
-: wxEvtHandler(){
-}
-ToolBarEventHandlerCutModel::~ToolBarEventHandlerCutModel(){
-}
-
-void ToolBarEventHandlerCutModel::onAdd(wxCommandEvent& event){
- CutModelMainPanel::getInstance()->onAddCutModel();
-}
-
-void ToolBarEventHandlerCutModel::onUndo(wxCommandEvent& event){
- CutModelMainPanel::getInstance()->onUndo();
-}
-
-void ToolBarEventHandlerCutModel::onRedo(wxCommandEvent& event){
- CutModelMainPanel::getInstance()->onRedo();
-}
-
-void ToolBarEventHandlerCutModel::onExecuteAll(wxCommandEvent& event){
- CutModelMainPanel::getInstance()->ExecuteAll();
-}
-
-
-BEGIN_EVENT_TABLE(ToolBarEventHandlerCutModel, wxEvtHandler)
- EVT_MENU(10, ToolBarEventHandlerCutModel::onAdd)
- EVT_MENU(20, ToolBarEventHandlerCutModel::onUndo)
- EVT_MENU(30, ToolBarEventHandlerCutModel::onRedo)
- EVT_MENU(40, ToolBarEventHandlerCutModel::onExecuteAll)
-END_EVENT_TABLE()
-
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelMainPanel.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:56 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-#ifndef __CutModelMainPanelPanelH__
-#define __CutModelMainPanelPanelH__
-
-#include <vector>
-#include <wx/wx.h>
-#include <wx/treebook.h>
-#include "wx/aui/aui.h"
-#include <wx/toolbar.h>
-#include <iostream>
-#include "marTypes.h"
-
-
-#include "CutModelManager.h"
-#include "CutModelException.h"
-#include "CutModelView.h"
-
-#include "vtkImageData.h"
-#include "vtkRenderWindowInteractor.h"
-
-
-class creaMaracasVisu_EXPORT CutModelMainPanel : public wxPanel
-{
-
-public:
-
- ~CutModelMainPanel( );
-
- static CutModelMainPanel* getInstance(wxWindow* parent=NULL, std::string path ="");
-
- //static CutModelMainPanel* getInstance();
-
- void setImageData(vtkImageData* img);
-
- void setInteractor(vtkRenderWindowInteractor* interactor);
-
- void setRenderer(vtkRenderer* renderer);
-
- void initialize(std::string path);
-
- void onAddCutModel();
-
- void onUndo();
-
- void onRedo();
-
- void changeOpacity(int id,int opacity);
-
- void ShowViewBox(int id,bool check);
-
- void ChangeShape(int id,int selection);
-
- void changeColor(int id,double r,double g,double b);
-
- void updateActorDirection(int id);
-
- void RemoveActor(int id);
-
- void ExecuteCut(int id, double* range, bool isinside);
-
- void ExecuteAll();
-
- vtkImageData* GetResultImage();
-
- void ShowCurrentPanel(int id);
-
- void ShowPopUpMenu(int id);
-
- void ShowStatistics(int id);
-
-
-private:
-
- CutModelMainPanel( wxWindow* parent, std::string path);
-
- static CutModelMainPanel* instance;
-
- CutModelManager* cutmanager;
-
- void checkInvariant() throw( CutModelException);
-
- void showErrorDialog(std::string str);
-
- void SaveCutModelData(std::string filename);
-
- void LoadCutModelData(std::string filename);
-
- std::vector<CutModelView*> viewpanels;
-
- wxAuiManager* _wxauimanager;
-
-
- int addNewViewPanel()throw( CutModelException);
-
- CutModelView* getModelView(int id)throw( CutModelException);
-
- int _panelid;
-};
-
-
-class ToolBarEventHandlerCutModel : public wxEvtHandler{
-
- public:
- ToolBarEventHandlerCutModel();
- ~ToolBarEventHandlerCutModel();
-
- void onAdd(wxCommandEvent& event);
-
- void onUndo(wxCommandEvent& event);
-
- void onRedo(wxCommandEvent& event);
-
- void onExecuteAll(wxCommandEvent& event);
-
- private:
-
- DECLARE_EVENT_TABLE()
- };
-
-class ToolBarCutModel : public wxToolBar{
-
-
-public:
- ToolBarCutModel(wxWindow * parent);
- ~ToolBarCutModel(void);
-
-
-private:
-
- ToolBarEventHandlerCutModel* _evthand;
-
-};
-
-#endif
-
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelView.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:56 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-// EOF - wxMaracasMPR.cxx
-
-#include "CutModelView.h"
-
-
-#include <wx/colordlg.h>
-#include <wx/bmpbuttn.h>
-
-#include <OpenImage.xpm>
-#include <Color.xpm>
-#include <Ok1.xpm>
-#include <Statistics.xpm>
-
-#include "vtkBoxWidget.h"
-
-#include "CutModelMainPanel.h"
-
-CutModelView::CutModelView( wxWindow* parent, double* range)
-: wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
-
- wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
-
- this->SetSizer(sizer);
-
- sizer->Add(getBoxControls(this, range),wxSizerFlags().FixedMinSize());
-
- sizer->AddSpacer(5);
-
- sizer->Add(getActorProperties(this),wxSizerFlags().FixedMinSize());
-
-
- wxBitmap bitmapok(Ok1_xpm);
- wxBitmapButton* okbutton = new wxBitmapButton(this, -1, bitmapok,wxDefaultPosition,wxSize(30,30));
- Connect(okbutton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModelViewEventHandler::onExecute));
-
- sizer->AddSpacer(5);
- sizer->Add(okbutton,wxSizerFlags().FixedMinSize());
-
-
-
-
-
-}
-CutModelView::~CutModelView( ){
- CutModelMainPanel::getInstance()->RemoveActor(this->getId());
-}
-
-wxSizer* CutModelView::getBoxControls(wxWindow* parent,double* range){
-
- wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
- wxCheckBox* checkbox = new wxCheckBox(parent,-1,_T("View Box"));
- sizer->Add(checkbox,wxSizerFlags().FixedMinSize());
- checkbox->SetValue(true);
- Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)(&CutModelViewEventHandler::onViewBoxChecked));
-
- wxString choices1[3];
- //choices1[0] = _T("Select a shape...");
- choices1[0] = _T("Sphere");
- choices1[1] = _T("Cylinder");
- choices1[2] = _T("Cube");
- wxComboBox* combo = new wxComboBox(parent, -1,_T(""),wxDefaultPosition,wxDefaultSize,3,choices1);
- combo->SetValue(_T("Sphere"));
- sizer->Add(combo,wxSizerFlags().FixedMinSize());
- Connect(combo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED,(wxObjectEventFunction)(&CutModelViewEventHandler::onShapeChange));
-
- wxStaticText* labelgreyv = new wxStaticText(parent, -1, wxString(_T("Grey value range")));
- _sliderrange = new wxSlider(parent, -1, range[0],range[0],range[1],wxDefaultPosition,wxDefaultSize,wxSL_LABELS|wxSL_SELRANGE);
- wxBoxSizer* sizergreyv = new wxBoxSizer(wxVERTICAL);
- sizergreyv->Add(labelgreyv,wxSizerFlags().FixedMinSize());
- sizergreyv->Add(_sliderrange,wxSizerFlags().FixedMinSize());
- sizer->Add(sizergreyv,wxSizerFlags().FixedMinSize().Border());
-
- wxString choices0[2];
- choices0[0] = _T("inside");
- choices0[1] = _T("outside");
- _radioinsideout = new wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices0);
- sizer->Add(_radioinsideout,wxSizerFlags().FixedMinSize());
-
- /*wxString choices[2];
- choices[0] = _T("Cut");
- choices[1] = _T("Statistics");
- _radiocutstat = new wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices);
- sizer->Add(_radiocutstat,wxSizerFlags().FixedMinSize());*/
-
- wxBitmap bitmap(Statistics_xpm);
- wxBitmapButton* statbut = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));
- Connect(statbut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModelViewEventHandler::onStatistics));
- sizer->Add(statbut,wxSizerFlags().FixedMinSize());
-
-
-
- return sizer;
-}
-wxSizer* CutModelView::getActorProperties(wxWindow* parent){
-
- wxBoxSizer* sizeractorproperties = new wxBoxSizer(wxVERTICAL);
-
- wxStaticText* labelshapeactor = new wxStaticText(parent, -1, wxString(_T("Actor's properties")));
-
- sizeractorproperties->Add(labelshapeactor,wxSizerFlags().FixedMinSize());
-
- sizeractorproperties->Add(getColorChooseActor(parent),wxSizerFlags().FixedMinSize());
-
- sizeractorproperties->Add(getOpacityActor(parent),wxSizerFlags().FixedMinSize());
-
- return sizeractorproperties;
-
-}
-
-wxSizer* CutModelView::getOpacityActor(wxWindow* parent){
- wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);
-
- wxStaticText* labelopacity = new wxStaticText(parent, -1, wxString(_T("Opacity")));
- wxSlider* slider0 = new wxSlider(parent, -1, 60,0,100,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
- Connect(slider0->GetId(), wxEVT_SCROLL_THUMBRELEASE,(wxObjectEventFunction)(&CutModelViewEventHandler::onOpacityChange));
-
- sizeropacity->Add(labelopacity,wxSizerFlags().FixedMinSize());
- sizeropacity->Add(slider0,wxSizerFlags().FixedMinSize());
-
- return sizeropacity;
-}
-
-wxSizer* CutModelView::getColorChooseActor(wxWindow* parent){
- wxBoxSizer* sizercolor = new wxBoxSizer(wxHORIZONTAL);
- wxBitmap bitmap(Color_xpm);
- wxBitmapButton* colorchoose = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));
- wxObjectEventFunction f = (wxObjectEventFunction)(&CutModelViewEventHandler::onColorChange);
- Connect(colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, f);
-
- _currentcolor = new wxStaticText(parent,-1,_T(""),wxDefaultPosition,wxSize(20,20));
- this->SetCurrentColor(wxColour(255.0,0.0,0.0));
-
- sizercolor->Add(colorchoose,wxSizerFlags().FixedMinSize());
- sizercolor->AddSpacer(5);
- sizercolor->Add(_currentcolor,wxSizerFlags().FixedMinSize().Centre());
- return sizercolor;
-}
-
-void CutModelView::checkInvariant()throw (CutModelException){
-
-}
-
-void CutModelView::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
- //vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
-
- if(eventId==vtkCommand::StartInteractionEvent){
- CutModelMainPanel::getInstance()->ShowCurrentPanel(this->getId());
- }else if(eventId==vtkCommand::InteractionEvent){
- CutModelMainPanel::getInstance()->updateActorDirection(this->getId());
- }else if(eventId==vtkCommand::RightButtonReleaseEvent){
- // =(
- CutModelMainPanel::getInstance()->ShowPopUpMenu(this->getId());
- }
-}
-
-void CutModelView::ExecuteCut(){
- if(this->isCut()){
- CutModelMainPanel::getInstance()->ExecuteCut(this->getId(),this->getRange(),this->isInside());
- }else{
- }
-
-}
-
-double* CutModelView::getRange(){
- double* x = new double[3];
- x[0] = 0;
- x[1] = _sliderrange->GetValue();
- x[2] = 100000;
-
- return x;
-}
-bool CutModelView::isCut(){
- return true;
- //return _radiocutstat->GetSelection()==0;
-}
-bool CutModelView::isInside(){
- return _radioinsideout->GetSelection()==0;
-}
-void CutModelView::SetCurrentColor(wxColour colour){
- _currentcolor->SetBackgroundColour(colour);
-
- this->Refresh();
- this->Layout();
-}
-
-void CutModelViewEventHandler::onColorChange(wxCommandEvent& event){
- CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
- wxColourDialog* colourdiag = new wxColourDialog(parent);
- if(colourdiag->ShowModal()==wxID_OK){
- wxColour colour = colourdiag->GetColourData().GetColour();
-
- parent->SetCurrentColor(colour);
-
- double r = (double)(colour.Red())/255.0;
- double g = (double)(colour.Green())/255.0;
- double b = (double)(colour.Blue())/255.0;
- CutModelMainPanel::getInstance()->changeColor(parent->getId(),r,g,b);
-
-
- }
- delete colourdiag;
-}
-
-void CutModelViewEventHandler::onOpacityChange(wxScrollEvent& event){
- CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
-
- CutModelMainPanel::getInstance()->changeOpacity(parent->getId(),event.GetInt());
-}
-void CutModelViewEventHandler::onViewBoxChecked(wxCommandEvent& event){
- CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
-
- CutModelMainPanel::getInstance()->ShowViewBox(parent->getId(),event.IsChecked());
-}
-void CutModelViewEventHandler::onShapeChange(wxCommandEvent& event){
- CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
-
- //if(event.GetSelection()>0){
- //std::cout<<"id in CutModelViewEventHandler:: "<<parent->getId()<<std::endl;
- CutModelMainPanel::getInstance()->ChangeShape(parent->getId(),event.GetSelection());
- //}
-}
-void CutModelViewEventHandler::onStatistics(wxCommandEvent& event){
- CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
- CutModelMainPanel::getInstance()->ShowStatistics(parent->getId());
-}
-void CutModelViewEventHandler::onExecute(wxCommandEvent& event){
- CutModelView* parent = (CutModelView*)((wxWindow*)event.GetEventObject())->GetParent();
-
- parent->ExecuteCut();
-
-}
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelView.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:56 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-#ifndef __CutModelViewPanelH__
-#define __CutModelViewPanelH__
-
-#include <vector>
-#include <wx/wx.h>
-#include <wx/radiobut.h>
-#include "wx/aui/aui.h"
-#include <iostream>
-#include "marTypes.h"
-
-
-#include "CutModelManager.h"
-#include "CutModelException.h"
-
-#include "vtkObject.h"
-#include "vtkCommand.h"
-
-
-class creaMaracasVisu_EXPORT CutModelView : public wxPanel, public vtkCommand
-{
-
-public:
- CutModelView( wxWindow* parent,double* range);
- ~CutModelView( );
-
- virtual void Execute(vtkObject *wdg, unsigned long eventId, void* calldata) ;
-
- int getId(){
- return _id;
- }
- void setId(int id){
- _id = id;
- }
-
- void ExecuteCut();
-
- void SetCurrentColor(wxColour colour);
-
-private:
-
- int _id;
-
- wxSlider* _sliderrange;
- wxRadioBox* _radioinsideout;
- //wxRadioBox* _radiocutstat;
- wxStaticText* _currentcolor;
-
- double* getRange();
- bool isCut();
- bool isInside();
-
-
-
- wxSizer* getBoxControls(wxWindow* parent, double* range);
-
-
- wxSizer* getActorProperties(wxWindow* parent);
- wxSizer* getColorChooseActor(wxWindow* parent);
- wxSizer* getOpacityActor(wxWindow* parent);
-
- void checkInvariant() throw( CutModelException);
-
-};
-
-class CutModelViewEventHandler : public wxEvtHandler{
-
- public:
- CutModelViewEventHandler(): wxEvtHandler(){};
- ~CutModelViewEventHandler(){};
-
- void onColorChange(wxCommandEvent& event);
- void onOpacityChange(wxScrollEvent& event);
- void onViewBoxChecked(wxCommandEvent& event);
- void onShapeChange(wxCommandEvent& event);
- void onStatistics(wxCommandEvent& event);
- void onExecute(wxCommandEvent& event);
-
-
-
- private:
-
-};
-
-
-#endif
-
+++ /dev/null
-#----------------------------------------------------------------------------
-# SET THE NAME OF YOUR LIBRARY
-SET ( LIBRARY_NAME creaMaracasVisu_CutModule2_kernel )
-#----------------------------------------------------------------------------
-#----------------------------------------------------------------------------
-
- #----------------------------------------------------------------------------
- # BUILD LIBRARY
- #----------------------------------------------------------------------------
-
- #----------------------------------------------------------------------------
- # LIBRARY HEADERS (TO BE INSTALLED)
- # EITHER LIST ALL .h IN CURRENT DIR USING NEXT LINE:
- FILE(GLOB ${LIBRARY_NAME}_HEADERS "*.h")
- # OR MANUALLY LIST YOUR HEADERS WITH NEXT COMMAND
- # SET ( ${LIBRARY_NAME}_HEADERS
- #
- # )
- #----------------------------------------------------------------------------
-
- #----------------------------------------------------------------------------
- # LIBRARY SOURCES (TO BE COMPILED)
- # EITHER LIST ALL .cxx, *.cpp, *.cc IN CURRENT DIR USING NEXT LINE:
- FILE(GLOB ${LIBRARY_NAME}_SOURCES *.cxx *.cpp *.cc)
- # OR MANUALLY LIST YOUR FILES WITH NEXT COMMAND (WITHOUT EXTENSION)
- # SET ( ${LIBRARY_NAME}_SOURCES
- #
- # )
- #----------------------------------------------------------------------------
-
- #----------------------------------------------------------------------------
- # LIBRARY DEPENDENCIES (LIBRARIES TO LINK WITH)
- SET ( ${LIBRARY_NAME}_LINK_LIBRARIES
- ${crea_LIBRARIES}
- # ${VTK_LIBRARIES}
- # ${ITK_LIBRARIES}
- # ${GDCM_LIBRARIES}
- # ${BOOST_LIBRARIES}
- )
- #----------------------------------------------------------------------------
-
-
- #----------------------------------------------------------------------------
- # MACRO WHICH DOES ALL THE JOB : BUILD AND INSTALL
- #CREA_ADD_LIBRARY( ${LIBRARY_NAME} )
- #----------------------------------------------------------------------------
-
- ADD_LIBRARY(${LIBRARY_NAME} STATIC ${${LIBRARY_NAME}_SOURCES} ${${LIBRARY_NAME}_HEADERS} )
- # LINK
- TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${${LIBRARY_NAME}_LINK_LIBRARIES})
\ No newline at end of file
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2Data.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-#include "CutModel2Data.h"
-
-/**
-** Start of the manager class
-**/
-CutModel2Data::CutModel2Data(int id, vtkRenderWindowInteractor* interactor, vtkCommand* observer, vtkImageData* img){
-
- initializeData(id, interactor, observer, img);
-
-}
-CutModel2Data::CutModel2Data(){
-
-}
-void CutModel2Data::initializeData(int id, vtkRenderWindowInteractor* interactor, vtkCommand* observer, vtkImageData* img){
- _id = id;
- _currentshape=0;
- createBoxWidget(interactor, observer);
- setTransform(img);
- createActor();
- createShapes();
- ChangeShape(0);
- checkInvariant();
-}
-CutModel2Data::~CutModel2Data(){
- checkInvariant();
- _boxWidgetVolume->Off();
- _boxWidgetVolume->Delete();
- _Mapper->Delete();
- _Actor->Delete();
- delete _cubefigure;
- delete _cylinderfigure;
- delete _spherefigure;
- currentmatrix->Delete();
- inversModel->Delete();
-}
-void CutModel2Data::RefreshViewBox(){
-
-}
-void CutModel2Data::createBoxWidget(vtkRenderWindowInteractor* interactor, vtkCommand* observer){
-
- _boxWidgetVolume = vtkBoxWidget::New();
- _boxWidgetVolume->SetInteractor( interactor );
- //_boxWidgetVolume->SetPlaceFactor(1);
- //_boxWidgetVolume->SetInput( img );
- //_boxWidgetVolume->PlaceWidget();
-
- _boxWidgetVolume->AddObserver( vtkCommand::InteractionEvent , observer );
- _boxWidgetVolume->AddObserver( vtkCommand::StartInteractionEvent , observer );
- _boxWidgetVolume->AddObserver( vtkCommand::RightButtonReleaseEvent , observer );
-
- _boxWidgetVolume->HandlesOn ();
- _boxWidgetVolume->On();
- //_boxWidgetVolume->GetHandleProperty()->SetOpacity(0.5);
- //_boxWidgetVolume->GetOutlineProperty()->SetOpacity(0.5);
-}
-void CutModel2Data::setTransform(vtkImageData* img)throw( CutModel2Exception){
-
- currentmatrix = vtkTransform::New();
- modeltransform = vtkTransform::New();
- inversModel = vtkTransform::New();
-
- vtkMatrix4x4* matrix = vtkMatrix4x4::New();
- matrix->Identity();
- int *ext = img->GetExtent();
- double *spc = img->GetSpacing();
-
-
- matrix->SetElement(0,0,(ext[1]-ext[0])/4*spc[0]);
- matrix->SetElement(1,1,(ext[3]-ext[2])/4*spc[1]);
- matrix->SetElement(2,2,(ext[5]-ext[4])/4*spc[2]);
-
- double orgx = (ext[1]-ext[0])/2*spc[0];
- double orgy = (ext[3]-ext[2])/2*spc[1];
- double orgz = (ext[5]-ext[4])/2*spc[2];
-
- matrix->SetElement(0,3,orgx);
- matrix->SetElement(1,3,orgy);
- matrix->SetElement(2,3,orgz);
-
-
- currentmatrix->SetMatrix(matrix);
- _boxWidgetVolume->SetTransform(currentmatrix);
-
-}
-void CutModel2Data::createActor(){
-
- _Mapper = vtkPolyDataMapper::New();
- _Actor = vtkActor::New();
- _Actor->SetMapper(_Mapper);
- _Actor->GetProperty()->SetColor(1, 0, 0);
- _Actor->GetProperty()->SetOpacity(0.5);
-
-}
-void CutModel2Data::udapteActorDirection()throw( CutModel2Exception){
- checkInvariant();
-
- _boxWidgetVolume->GetTransform(currentmatrix);
- _Actor->SetUserMatrix(currentmatrix->GetMatrix());//SetUserTransform(currentmatrix );
-}
-void CutModel2Data::createShapes(){
- _cubefigure = new CutModel2FigureCube();
- _cylinderfigure = new CutModel2FigureCylinder();
- _spherefigure = new CutModel2FigureSphere();
-}
-void CutModel2Data::changeOpacity(int opacity)throw( CutModel2Exception){
- checkInvariant();
- _Actor->GetProperty()->SetOpacity((double)opacity/100.0);
-}
-
-void CutModel2Data::ShowViewBox(bool check)throw( CutModel2Exception){
- checkInvariant();
- if(check){
- _boxWidgetVolume->On();
- }else{
- _boxWidgetVolume->Off();
- }
-}
-
-void CutModel2Data::ChangeShape(int selection)throw( CutModel2Exception){
- checkInvariant();
-
- if(selection == 0){
- _Mapper->SetInput(_spherefigure->getPolyData());
- }else if(selection == 1){
- _Mapper->SetInput(_cylinderfigure->getPolyData());
- }else if(selection == 2){
- _Mapper->SetInput(_cubefigure->getPolyData());
- }else{
- throw CutModel2Exception("Shape type not found");
- }
-
- _currentshape=selection;
-}
-
-void CutModel2Data::checkInvariant()throw( CutModel2Exception){
- if(_boxWidgetVolume==NULL){
- throw CutModel2Exception("Box Widget not created");
- }
- if(_Mapper==NULL){
- throw CutModel2Exception("Mapper not created");
- }
- if(_Actor==NULL){
- throw CutModel2Exception("Actor not created");
- }
- if(_cubefigure==NULL){
- throw CutModel2Exception("Cube not created");
- }
- if(_cylinderfigure==NULL){
- throw CutModel2Exception("Cylinder not created");
- }
- if(_spherefigure==NULL){
- throw CutModel2Exception("Sphere not created");
- }
-
-}
-
-vtkActor* CutModel2Data::getActor()throw( CutModel2Exception){
- checkInvariant();
- return _Actor;
-}
-
-void CutModel2Data::changeColor(double r,double g,double b)throw( CutModel2Exception){
- checkInvariant();
- _Actor->GetProperty()->SetColor( r, g, b );
-}
-CutModel2Figure* CutModel2Data::getCurentCuttingModel(){
- checkInvariant();
-
- if(_currentshape == 0){
- return _spherefigure;
- }else if(_currentshape == 1){
- return _cylinderfigure;
- }else if(_currentshape == 2){
- return _cubefigure;
- }else{
- throw CutModel2Exception("Shape type not found");
- }
-}
-void CutModel2Data::ExecuteCut( double* range, bool isinside, vtkImageData* copyimage)throw( CutModel2Exception)
-{
-
- wxBusyCursor wait;
-
- CutModel2Figure* actualCuttingModel = getCurentCuttingModel();
-
- //_boxWidgetVolume->GetTransform(currentmatrix);
- actualCuttingModel->SetVtkTransform(getModelTransform(copyimage));
- //actualCuttingModel->SetVtkTransform(currentmatrix);
- actualCuttingModel->SetInversVtkTransform(getModelTransformInvers());
-
- bool inside;
- bool volInt, volExt;
- int xx,yy,zz;
- unsigned short* pOrg;
- int ext[6];
- double spc[3];
- long int contAfter = 0;
- long int contBefor = 0;
-
- double minvalue = range[0];
- double value = range[1];
- double maxvalue = range[2];
-
-
- copyimage->GetExtent(ext);
-
- for (xx=ext[0];xx<ext[1]; xx++)
- {
- for (yy=ext[2];yy<ext[3]; yy++)
- {
- for (zz=ext[4];zz<ext[5];zz++)
- {
- inside=actualCuttingModel->IfPointInside(xx,yy,zz);
- if ( ((inside==true)&&(isinside==true)) || ((!inside==true)&&(!isinside)) )
- {
- pOrg=(unsigned short*)copyimage->GetScalarPointer (xx,yy,zz);
-
- //std::cout<<"xx,yy,zz "<<xx<<","<<yy<<","<<zz<<" "<<*pOrg<<std::endl;
- if ((unsigned short)minvalue <=(*pOrg)&&(*pOrg)<=(unsigned short)maxvalue)
- {
-
- *pOrg=(unsigned short)value;
-
- }
- } // if inside
- } // for zz
- } // for yy
- } // for xx
-
-}
-
-void CutModel2Data::ExecuteUnCut(bool isinside, vtkImageData* image, vtkImageData* copyimage)throw( CutModel2Exception)
-{
-
- wxBusyCursor wait;
-
- CutModel2Figure* actualCuttingModel = getCurentCuttingModel();
-
- actualCuttingModel->SetVtkTransform(getModelTransform(copyimage));
-
- actualCuttingModel->SetInversVtkTransform(getModelTransformInvers());
-
- bool inside;
- bool volInt, volExt;
- int xx,yy,zz;
- unsigned short* pOrg;
- int ext[6];
- double spc[3];
- long int contAfter = 0;
- long int contBefor = 0;
-
- double value;
-
-
-
- copyimage->GetExtent(ext);
-
- for (xx=ext[0];xx<ext[1]; xx++)
- {
- for (yy=ext[2];yy<ext[3]; yy++)
- {
- for (zz=ext[4];zz<ext[5];zz++)
- {
- inside=actualCuttingModel->IfPointInside(xx,yy,zz);
- if ( ((inside==true)&&(isinside==true)) || ((!inside==true)&&(!isinside)) )
- {
- value = *((unsigned short*)image->GetScalarPointer (xx,yy,zz));
- pOrg=(unsigned short*)copyimage->GetScalarPointer (xx,yy,zz);
- //std::cout<<"CutModel2Data::ExecuteUnCut() "<<value<<" "<<*pOrg<<std::endl;
- *pOrg=(unsigned short)value;
- } // if inside
- } // for zz
- } // for yy
- } // for xx
-
-}
-
-vtkTransform* CutModel2Data::getModelTransform(vtkImageData* copyimage){
-
- double *spc = copyimage->GetSpacing();
- modeltransform->Identity();
-
- vtkMatrix4x4* matrix = currentmatrix->GetMatrix();
- vtkMatrix4x4* matrixmodel = modeltransform->GetMatrix();
- matrixmodel->SetElement(0,0,matrix->GetElement(0,0)/spc[0]);
- matrixmodel->SetElement(1,0,matrix->GetElement(1,0)/spc[0]);
- matrixmodel->SetElement(2,0,matrix->GetElement(2,0)/spc[0]);
- matrixmodel->SetElement(0,1,matrix->GetElement(0,1)/spc[1]);
- matrixmodel->SetElement(1,1,matrix->GetElement(1,1)/spc[1]);
- matrixmodel->SetElement(2,1,matrix->GetElement(2,1)/spc[1]);
- matrixmodel->SetElement(0,2,matrix->GetElement(0,2)/spc[2]);
- matrixmodel->SetElement(1,2,matrix->GetElement(1,2)/spc[2]);
- matrixmodel->SetElement(2,2,matrix->GetElement(2,2)/spc[2]);
- matrixmodel->SetElement(0,3,matrix->GetElement(0,3)/spc[0]);
- matrixmodel->SetElement(1,3,matrix->GetElement(1,3)/spc[1]);
- matrixmodel->SetElement(2,3,matrix->GetElement(2,3)/spc[2]);
-
- /*
-
- double* pos = currentmatrix->GetPosition();
- modeltransform->Translate(pos[0]/spc[0],pos[1]/spc[1],pos[2]/spc[2]);
-
- double* scal = currentmatrix->GetScale();
- modeltransform->Scale(scal[0]/spc[0],scal[1]/spc[1],scal[2]/spc[2]);
-
- //double* orient = currentmatrix->GetOrientation();
- //modeltransform->RotateZ(orient[2]);
- //modeltransform->RotateY(orient[1]);
- //modeltransform->RotateX(orient[0]);
- double* orient = currentmatrix->GetOrientationWXYZ();
- modeltransform->RotateWXYZ(orient[0],orient[1],orient[2],orient[3]);
-
- */
-
-
- modeltransform->Update();
-
- return modeltransform;
-
-
-}
-void CutModel2Data::setTransform(vtkTransform* transform, vtkImageData* img)throw( CutModel2Exception){
-
-
- double *spc = img->GetSpacing();
-
- currentmatrix->Identity();
-
- /*double* orient = transform->GetOrientationWXYZ();
- currentmatrix->RotateWXYZ(orient[0],orient[1],orient[2],orient[3]);
-
- double* pos = transform->GetPosition();
- currentmatrix->Translate(pos[0]/spc[0],pos[1]/spc[1],pos[2]/spc[2]);
-
- double* scal = transform->GetScale();
- currentmatrix->Scale(scal[0]/spc[0],scal[1]/spc[1],scal[2]/spc[2]);
-
- currentmatrix->Update(); */
-
- _boxWidgetVolume->SetTransform(transform);
-
- /*vtkMatrix4x4* matrix = transform->GetMatrix();
- vtkMatrix4x4* matrixcurrent = currentmatrix->GetMatrix();
- matrixcurrent->SetElement(0,0,matrix->GetElement(0,0)/spc[0]);
- matrixcurrent->SetElement(1,0,matrix->GetElement(1,0)/spc[0]);
- matrixcurrent->SetElement(2,0,matrix->GetElement(2,0)/spc[0]);
- matrixcurrent->SetElement(0,1,matrix->GetElement(0,1)/spc[1]);
- matrixcurrent->SetElement(1,1,matrix->GetElement(1,1)/spc[1]);
- matrixcurrent->SetElement(2,1,matrix->GetElement(2,1)/spc[1]);
- matrixcurrent->SetElement(0,2,matrix->GetElement(0,2)/spc[2]);
- matrixcurrent->SetElement(1,2,matrix->GetElement(1,2)/spc[2]);
- matrixcurrent->SetElement(2,2,matrix->GetElement(2,2)/spc[2]);
- matrixcurrent->SetElement(0,3,matrix->GetElement(0,3)/spc[0]);
- matrixcurrent->SetElement(1,3,matrix->GetElement(1,3)/spc[1]);
- matrixcurrent->SetElement(2,3,matrix->GetElement(2,3)/spc[2]); */
-
-
- udapteActorDirection();
- getModelTransform(img);
-
-}
-vtkTransform* CutModel2Data::getModelTransformInvers(){
- inversModel->Identity ();
- inversModel->Concatenate ( modeltransform );
- inversModel->Inverse();
- return inversModel;
-}
-
-vtkPolyData* CutModel2Data::getPolyData()throw( CutModel2Exception){
- return _Mapper->GetInput();
-}
-
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2Data.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-
-#ifndef __CutModel2DataH__
-#define __CutModel2DataH__
-
-#include <iostream>
-#include <vector>
-
-#include "vtkImageData.h"
-#include "vtkRenderWindowInteractor.h"
-#include "vtkCommand.h"
-#include "vtkBoxWidget.h"
-#include "vtkPolyDataMapper.h"
-#include "vtkActor.h"
-#include "vtkProperty.h"
-#include "CutModel2Exception.h"
-#include "CutModel2Figure.h"
-#include "CutModel2FigureCube.h"
-#include "CutModel2FigureSphere.h"
-#include "CutModel2FigureCylinder.h"
-
-#include <wx/utils.h>
-
-class CutModel2Data {
-
-public:
- CutModel2Data();
- CutModel2Data(int id, vtkRenderWindowInteractor* interactor, vtkCommand* observer, vtkImageData* img);
- ~CutModel2Data();
- void initializeData(int id, vtkRenderWindowInteractor* interactor, vtkCommand* observer, vtkImageData* img);
-
-
- int getId(){
- return _id;
- }
-
- void changeOpacity(int opacity)throw( CutModel2Exception);
-
- void ShowViewBox(bool check)throw( CutModel2Exception);
-
- void ChangeShape(int selection)throw( CutModel2Exception);
-
- vtkActor* getActor()throw( CutModel2Exception);
-
- vtkPolyData* getPolyData()throw( CutModel2Exception);
-
- void changeColor(double r,double g,double b)throw( CutModel2Exception);
-
- void udapteActorDirection()throw( CutModel2Exception);
-
- void ExecuteCut( double* range, bool isinside, vtkImageData* copyimage)throw( CutModel2Exception);
-
- void ExecuteUnCut( bool isinside, vtkImageData* image, vtkImageData* copyimage)throw( CutModel2Exception);
-
- void RefreshViewBox();
-
- vtkTransform* getCurrentMatrix(){
- return currentmatrix;
- }
-
- int getCurrentShape(){
- return _currentshape;
- }
-
- void setCurrentShape(int currentshape){
- _currentshape = currentshape;
- }
-
- void setTransform(vtkTransform* transform,vtkImageData* img)throw( CutModel2Exception);
-private:
-
- void checkInvariant()throw( CutModel2Exception);
-
- void createBoxWidget(vtkRenderWindowInteractor* interactor, vtkCommand* observer);
- void createActor();
- void setTransform(vtkImageData* img)throw( CutModel2Exception);
- void createShapes();
-
- vtkBoxWidget* _boxWidgetVolume;
- vtkPolyDataMapper* _Mapper;
- vtkActor* _Actor;
- int _id;
-
- int _currentshape;
-
- CutModel2FigureCube* _cubefigure;
- CutModel2FigureCylinder* _cylinderfigure;
- CutModel2FigureSphere* _spherefigure;
- vtkTransform* currentmatrix;
- vtkTransform* modeltransform;
- vtkTransform* inversModel;
-
-
- CutModel2Figure* getCurentCuttingModel();
-
- vtkTransform* getModelTransform(vtkImageData* copyimage);
- vtkTransform* getModelTransformInvers();
-};
-
-#endif
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2Exception.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-#include "CutModel2Exception.h"
-
-/**
-** Start of the manager class
-**/
-CutModel2Exception::CutModel2Exception(std::string cause)
-:std::exception(){
- _cause = cause;
-}
-CutModel2Exception::~CutModel2Exception()throw(){
-}
-
-
-
-
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2Exception.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-
-#ifndef __CutModel2ExceptionH__
-#define __CutModel2ExceptionH__
-
-#include <iostream>
-#include <vector>
-
-
-class CutModel2Exception : public std::exception{
-
-public:
- CutModel2Exception(std::string cause);
- ~CutModel2Exception() throw();
-
- std::string getCause(){
- return _cause;
- }
-
-private:
-
- std::string _cause;
-
-};
-
-#endif
+++ /dev/null
-
-#include "CutModelFigure.h"
-
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-CutModelFigure::CutModelFigure()
-{
- _inversModel = vtkTransform::New();
- _matrixModel = vtkTransform::New();
- _matrixVisual = vtkTransform::New();
-
- _spcX=1;
- _spcY=1;
- _spcZ=1;
-}
-//----------------------------------------------------------------------------
-CutModelFigure::~CutModelFigure() // virtual
-{
- _inversModel->Delete();
-}
-//----------------------------------------------------------------------------
-void CutModelFigure::SetPosition(double x,double y, double z)
-{
- _px=x;
- _py=y;
- _pz=z;
-}
-//----------------------------------------------------------------------------
-void CutModelFigure::SetScale(double sx,double sy, double sz)
-{
- _sx=sx;
- _sy=sy;
- _sz=sz;
-}
-//----------------------------------------------------------------------------
-void CutModelFigure::SetRotation(double alfa,double beta, double teta)
-{
- _alfa=alfa;
- _beta=beta;
- _teta=teta;
-}
-
-//----------------------------------------------------------------------------
-void CutModelFigure::CalculeMatrix()
-{
- _matrixModel->Identity();
- _matrixModel->Translate(_px,_py,_pz);
- _matrixModel->RotateY(_beta);
- _matrixModel->RotateX(_alfa);
- _matrixModel->RotateY(_teta);
- _matrixModel->Scale(_sx,_sy,_sz);
-
- _matrixVisual->Identity();
- _matrixVisual->Translate( _px*_spcX , _py*_spcY , _pz*_spcZ );
- _matrixVisual->RotateY(_beta);
- _matrixVisual->RotateX(_alfa);
- _matrixVisual->RotateY(_teta);
- _matrixVisual->Scale( _sx*_spcX , _sy*_spcY , _sz*_spcZ );
-
-}
-
-
-//----------------------------------------------------------------------------
-void CutModelFigure::CalculeInversMatrix()
-{
- _inversModel->Identity ();
- _inversModel->Concatenate ( _matrixModel );
- _inversModel->Inverse();
-}
-//----------------------------------------------------------------------------
-bool CutModelFigure::IfPointInside(double x, double y, double z) // virtual
-{
- return true;
-}
-
-//----------------------------------------------------------------------------
-vtkTransform *CutModelFigure::GetVtkTransform()
-{
- return _matrixVisual;
-}
-
-//----------------------------------------------------------------------------
-//void CutModelFigure::SetVtkTransform(vtkTransform *matrix)
-//{
-// _matrixModel = matrix;
-//}
-
-//----------------------------------------------------------------------------
-double CutModelFigure::GetTheoricVolume() // virtual
-{
- return 0;
-}
-
-//----------------------------------------------------------------------------
-double CutModelFigure::GetPositionX()
-{
- return _px;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetPositionY()
-{
- return _py;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetPositionZ()
-{
- return _pz;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetScaleX()
-{
- return _sx;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetScaleY()
-{
- return _sy;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetScaleZ()
-{
- return _sz;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetAngleAlfa()
-{
- return _alfa;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetAngleBeta()
-{
- return _beta;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetAngleTeta()
-{
- return _teta;
-}
-//----------------------------------------------------------------------------
-char *CutModelFigure::GetName() // virtual
-{
- return "--";
-}
-
-//----------------------------------------------------------------------------
-void CutModelFigure::SetSpacing(double spcX,double spcY, double spcZ)
-{
- _spcX = spcX;
- _spcY = spcY;
- _spcZ = spcZ;
-}
\ No newline at end of file
+++ /dev/null
-#ifndef FIGURECUTTINGMODEL_H_
-#define FIGURECUTTINGMODEL_H_
-
-#include "vtkTransform.h"
-#include "vtkPolyData.h"
-
-class CutModel2Figure
-{
-public:
- CutModel2Figure(){}
-
- //~CutModel2Figure();
-
- virtual void SetPosition(double x,double y, double z){
- _px = x;
- _py = y;
- _pz = z;
- }
-
- virtual void SetScale(double sx,double sy, double sz){
- _sx = sx;
- _sy = sy;
- _sz = sz;
- }
-
- virtual void SetRotation(double alfa,double beta, double teta){
- _alfa = alfa;
- _beta = beta;
- _teta = teta;
- }
-
- virtual void SetSpacing(double spcX,double spcY, double spcZ){
- _spcX = spcX;
- _spcY = spcY;
- _spcZ = spcZ;
- }
-
- virtual void SetVtkTransform(vtkTransform *transform){
- double *orient = transform->GetOrientation();
- _alfa = orient[0];
- _beta = orient[1];
- _teta = orient[2];
-
- double *scale = transform->GetScale();
- _sx = scale[0];
- _sy = scale[1];
- _sz = scale[2];
-
- double *position = transform->GetPosition();
- _px = position[0];
- _py = position[1];
- _pz = position[2];
-
-
- }
- virtual void SetInversVtkTransform(vtkTransform *inverstransform){
- _inversModel = inverstransform;
- }
-
- virtual bool IfPointInside(double x, double y, double z) = 0;
- virtual double GetTheoricVolume()=0;
- virtual vtkPolyData* getPolyData()=0;
-
-private:
- double _px;
- double _py;
- double _pz;
- double _alfa;
- double _beta;
- double _teta;
- double _spcX;
- double _spcY;
- double _spcZ;
- char *GetName;
-protected:
- double _sx;
- double _sy;
- double _sz;
- vtkTransform *_inversModel;
- vtkTransform *_matrixModel;
-};
-
-#endif /*FIGURECUTTINGMODEL_H_*/
+++ /dev/null
-
-#include "CutModel2FigureCube.h"
-
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-CutModel2FigureCube::CutModel2FigureCube()
-: CutModel2Figure()
-{
- _vtkcube = vtkCubeSource::New();
- _vtkcube->SetXLength (1);
- _vtkcube->SetYLength (1);
- _vtkcube->SetZLength (1);
-}
-//----------------------------------------------------------------------------
-CutModel2FigureCube::~CutModel2FigureCube() // virtual
-{
- _vtkcube->Delete();
-}
-//----------------------------------------------------------------------------
-bool CutModel2FigureCube::IfPointInside(double x, double y, double z) // virtual
-{
- double in[4],out[4];
- in[0]=x;
- in[1]=y;
- in[2]=z;
- in[3]=1;
- _inversModel->MultiplyPoint (in, out);
-
- bool result=false;
- if ((out[0]>-0.5) && (out[0]<0.5) && (out[1]>-0.5) && (out[1]<0.5) && (out[2]>-0.5) && (out[2]<0.5) )
- {
- result=true;
- }
- return result;
-}
-//----------------------------------------------------------------------------
-double CutModel2FigureCube::GetTheoricVolume() // virtual
-{
- return _sx * _sy * _sz;
-}
-
-//----------------------------------------------------------------------------
-char *CutModel2FigureCube::GetName() // virtual
-{
- return "Cube";
-}
-
-vtkPolyData* CutModel2FigureCube::getPolyData(){
- return _vtkcube->GetOutput();
-}
-
+++ /dev/null
-#ifndef CutModel2FigureCube_H_
-#define CutModel2FigureCube_H_
-
-#include "CutModel2Figure.h"
-#include "vtkCubeSource.h"
-
-class CutModel2FigureCube : public CutModel2Figure
-{
-public:
- CutModel2FigureCube();
- virtual ~CutModel2FigureCube();
- virtual bool IfPointInside(double x, double y, double z);
- virtual double GetTheoricVolume();
- virtual vtkPolyData* getPolyData();
- virtual char *GetName();
-private:
- vtkCubeSource* _vtkcube;
-protected:
-};
-
-#endif /*FIGURECUTTINGCUBEMODEL_H_*/
+++ /dev/null
-
-#include "CutModel2FigureCylinder.h"
-
-CutModel2FigureCylinder::CutModel2FigureCylinder()
-{
- _vtkcylinder = vtkCylinderSource::New();
- _vtkcylinder->SetResolution(20);
-}
-//----------------------------------------------------------------------------
-CutModel2FigureCylinder::~CutModel2FigureCylinder() // virtual
-{
- _vtkcylinder->Delete();
-}
-//----------------------------------------------------------------------------
-bool CutModel2FigureCylinder::IfPointInside(double x, double y, double z) // virtual
-{
- double in[4],out[4];
- in[0]=x;
- in[1]=y;
- in[2]=z;
- in[3]=1;
- _inversModel->MultiplyPoint (in, out);
-
- bool result=false;
- if ((sqrt( out[0]*out[0] + out[2]*out[2] )<0.5 ) && (out[1]>-0.5) && (out[1]<0.5) )
- {
- result=true;
- }
- return result;
-}
-//----------------------------------------------------------------------------
-double CutModel2FigureCylinder::GetTheoricVolume() // virtual
-{
- double piTMP=3.14159265;
- return piTMP*(_sx/2)*(_sz/2)*_sy;
-}
-//----------------------------------------------------------------------------
-char *CutModel2FigureCylinder::GetName() // virtual
-{
- return "Cylinder";
-}
-vtkPolyData* CutModel2FigureCylinder::getPolyData(){
- return _vtkcylinder->GetOutput();
-}
-//----------------------------------------------------------------------------
+++ /dev/null
-#ifndef CutModel2FigureCylinder_H_
-#define CutModel2FigureCylinder_H_
-
-#include "CutModel2Figure.h"
-#include "vtkCylinderSource.h"
-
-class CutModel2FigureCylinder : public CutModel2Figure
-{
-public:
- CutModel2FigureCylinder();
- virtual ~CutModel2FigureCylinder();
- virtual bool IfPointInside(double x, double y, double z);
- virtual double GetTheoricVolume();
- virtual vtkPolyData* getPolyData();
- virtual char *GetName();
-
-private:
- vtkCylinderSource* _vtkcylinder;
-protected:
-};
-
-#endif /*FIGURECUTTINGCYLINDERMODEL_H_*/
+++ /dev/null
-#include "CutModel2FigureSphere.h"
-
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-CutModel2FigureSphere::CutModel2FigureSphere()
-{
- _vtksphere = vtkSphereSource::New();
- _vtksphere->SetThetaResolution (20);
- _vtksphere->SetPhiResolution (20);
-}
-//----------------------------------------------------------------------------
-CutModel2FigureSphere::~CutModel2FigureSphere() // virtual
-{
- _vtksphere->Delete();
-}
-//----------------------------------------------------------------------------
-bool CutModel2FigureSphere::IfPointInside(double x, double y, double z) // virtual
-{
- double in[4],out[4];
- in[0]=x;
- in[1]=y;
- in[2]=z;
- in[3]=1;
- _inversModel->MultiplyPoint (in, out);
-
- bool result=false;
- if (sqrt( out[0]*out[0] + out[1]*out[1] + out[2]*out[2] )<0.5 )
- {
- result=true;
- }
- return result;
-}
-//----------------------------------------------------------------------------
-double CutModel2FigureSphere::GetTheoricVolume() // virtual
-{
- double piTMP=3.14159265;
- return (4.0/3.0) * piTMP * (_sx/2)*(_sy/2)*(_sz/2);
-}
-//----------------------------------------------------------------------------
-char *CutModel2FigureSphere::GetName() // virtual
-{
- return "Sphere";
-}
-
-vtkPolyData* CutModel2FigureSphere::getPolyData(){
- return _vtksphere->GetOutput();
-}
-
+++ /dev/null
-#ifndef CutModel2FigureSphere_H_
-#define CutModel2FigureSphere_H_
-
-#include "CutModel2Figure.h"
-#include "vtkSphereSource.h"
-
-class CutModel2FigureSphere : public CutModel2Figure
-{
-public:
- CutModel2FigureSphere();
- virtual ~CutModel2FigureSphere();
- virtual bool IfPointInside(double x, double y, double z);
- virtual double GetTheoricVolume();
- virtual char *GetName();
- virtual vtkPolyData* getPolyData();
-private:
- vtkSphereSource* _vtksphere;
-protected:
-};
-
-#endif /*FIGURECUTTINGSPHEREMODEL_H_*/
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2Manager.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-#include "CutModel2Manager.h"
-
-/**
-** Start of the manager class
-**/
-CutModel2Manager::CutModel2Manager(std::string path){
- _path = path;
- _img = NULL;
- _copyimg = NULL;
- _interactor = NULL;
- _render = NULL;
- _currentaction=0;
-}
-CutModel2Manager::~CutModel2Manager(){
- std::string files = _path;
- files+="/infounrd_0_fig_0.info";
- remove(files.c_str());
-}
-
-
-void CutModel2Manager::setImageData(vtkImageData* img){
- _img = img;
- if(_copyimg!=NULL){
- _copyimg->Delete();
- }
- _copyimg = vtkImageData::New();
- _copyimg->SetExtent(_img->GetExtent());
- _copyimg->SetSpacing(_img->GetSpacing());
- _copyimg->AllocateScalars();
-
- _copyimg->DeepCopy(_img);
-
-}
-
-void CutModel2Manager::setInteractor(vtkRenderWindowInteractor* interactor){
- _interactor = interactor;
-}
-
-void CutModel2Manager::setRenderer(vtkRenderer* renderer){
- _render = renderer;
-}
-
-void CutModel2Manager::onAddCutModel2(int id, vtkCommand* observer) throw( CutModel2Exception){
- checkInvariant();
-
- CutModel2Data* data = new CutModel2Data(id,_interactor, observer, _copyimg);
- _vectordata.push_back(data);
-
- _render->AddActor(data->getActor());
-
- //_render->UpdateCamera();
- _render->Render();
-}
-
-void CutModel2Manager::checkInvariant() throw( CutModel2Exception){
- if(_img==NULL){
- throw CutModel2Exception("The image is not set");
- }
- if(_copyimg==NULL){
- throw CutModel2Exception("The image is not set");
- }
- if(_interactor==NULL){
- throw CutModel2Exception("Interactor not set");
- }
- if(_render==NULL){
- throw CutModel2Exception("Render not set");
- }
-}
-
-double* CutModel2Manager::getImageRange()throw( CutModel2Exception){
- checkInvariant();
- return _copyimg->GetScalarRange();
-}
-
-void CutModel2Manager::changeOpacity(int id,int opacity)throw( CutModel2Exception){
- checkInvariant();
- CutModel2Data* current = getCutModel2Data(id);
- current->changeOpacity(opacity);
-}
-
-void CutModel2Manager::ShowViewBox(int id,bool check)throw( CutModel2Exception){
- checkInvariant();
- CutModel2Data* current = getCutModel2Data(id);
- current->ShowViewBox(check);
-}
-
-void CutModel2Manager::ChangeShape(int id,int selection)throw( CutModel2Exception){
- checkInvariant();
- CutModel2Data* current = getCutModel2Data(id);
- current->ChangeShape(selection);
- _render->Render();
-}
-
-CutModel2Data* CutModel2Manager::getCutModel2Data(int id)throw( CutModel2Exception){
-
- CutModel2Data* current = NULL;
- for(int i= 0; i < _vectordata.size();i++){
- std::cout<<"id in CutModel2Manager:: "<<id<<std::endl;
- std::cout<<"vectordataid in CutModel2Manager:: "<<_vectordata[i]->getId()<<std::endl;
-
- if(_vectordata[i]->getId()==id){
- current = _vectordata[i];
- }
- }
- if(current ==NULL){
-
- throw CutModel2Exception("Data not found");
- }
- return current;
-}
-
-void CutModel2Manager::updateActorDirection(int id)throw( CutModel2Exception){
- checkInvariant();
- CutModel2Data* current = getCutModel2Data(id);
- current->udapteActorDirection();
-
-}
-
-void CutModel2Manager::changeColor(int id,double r,double g,double b)throw( CutModel2Exception){
-
- checkInvariant();
- CutModel2Data* current = getCutModel2Data(id);
- current->changeColor(r,g,b);
- _render->Render();
-}
-void CutModel2Manager::RemoveActor(int id)throw( CutModel2Exception){
-
- checkInvariant();
-
- CutModel2Data* current = getCutModel2Data(id);
- for(int i = 0; i < _vectordata.size()-1;i++){
- if(_vectordata[i]->getId()==id){
- for(int j = i; j < _vectordata.size()-1;j++){
- _vectordata[j]=_vectordata[j+1];
- }
- i = _vectordata.size();
- }
- }
- _render->RemoveActor(current->getActor());
- delete current;
- _vectordata.pop_back();
- _render->Render();
-
-}
-
-void CutModel2Manager::ExecuteCut(int id, double* range, bool isinside)throw( CutModel2Exception){
- checkInvariant();
-
- CutModel2Data* current = getCutModel2Data(id);
- current->ExecuteCut(range, isinside, _img);
-
-
- /*
- Setting extra information for the undo
- */
- CutModel2SaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL2_CUT);
- undoaction->setRange(range);
- undoaction->setIsInside(isinside);
-
-}
-
-vtkImageData* CutModel2Manager::GetResultImage(){
- checkInvariant();
- return _copyimg;
-}
-
-void CutModel2Manager::RefreshActor(int id){
- checkInvariant();
- CutModel2Data* current = getCutModel2Data(id);
- _render->RemoveActor(current->getActor());
- _render->AddActor(current->getActor());
- current->RefreshViewBox();
- _render->Render();
-}
-
-void CutModel2Manager::SaveCutModel2Data(std::string filename)throw( CutModel2Exception){
-
-
- throw CutModel2Exception("not implemented");
-
-
-
-
-}
-
-
-
-void CutModel2Manager::LoadCutModel2Data(std::string filename)throw( CutModel2Exception){
-
- throw CutModel2Exception("not implemented");
-
-}
-
-CutModel2SaveBinInfo* CutModel2Manager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModel2Exception){
-
- for(int i = _undoredo.size()-1; i > _currentaction;i--){
- delete _undoredo[i];
- _undoredo.pop_back();
- }
-
- CutModel2SaveBinInfo* cutmodel = new CutModel2SaveBinInfo(idc, _currentaction, type, _path);
- if(type == CUTMODEL2_CUT){
- cutmodel->saveMatrix4x4(this->getCutModel2Data(idc)->getCurrentMatrix()->GetMatrix());
- cutmodel->setCurrentShape(this->getCutModel2Data(idc)->getCurrentShape());
- }
-
- _undoredo.push_back(cutmodel);
-
- _currentaction++;// = _undoredo.size();
- //std::cout<<"current index "<<_currentaction;
-
- return cutmodel;
-}
-
-int CutModel2Manager::Undo() throw( CutModel2Exception){
- //&& _currentaction < _undoredo.size()
- if(_currentaction > 0){
- int tempaction = _currentaction-1;
- CutModel2SaveBinInfo* currentundo = _undoredo[tempaction];
- CutModel2Data* currentmodel;
-
- if(currentundo->getActionType()==CUTMODEL2_CUT){
- //Undo the cut
- vtkTransform* transform = currentundo->getTransformFromMatrixFile();
-
- currentmodel = getCutModel2Data(currentundo->getId());
-
- currentmodel->setTransform(transform, _img);
-
- currentmodel->setCurrentShape(currentundo->getCurrentShape());
-
- currentmodel->ExecuteUnCut(currentundo->getIsInside(), _copyimg, _img);
-
- }
- //Every thing ok
- _currentaction--;
- return 0;
- }
- return -1;
-}
-
-int CutModel2Manager::Redo() throw( CutModel2Exception){
-
- if(_currentaction >= 0 && _currentaction < _undoredo.size()){
-
-
- CutModel2SaveBinInfo* currentundo = _undoredo[_currentaction];
- CutModel2Data* currentmodel;
-
- if(currentundo->getActionType()==CUTMODEL2_CUT){
- //Redo the cut
- vtkTransform* transform = currentundo->getTransformFromMatrixFile();
- currentmodel = getCutModel2Data(currentundo->getId());
- currentmodel->setTransform(transform, _copyimg);
- currentmodel->setCurrentShape(currentundo->getCurrentShape());
- currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _copyimg);
- }
-
- _currentaction++;
-
- return 0;
- }
- return -1;
-}
\ No newline at end of file
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2Manager.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-
-#ifndef __CutModel2ManagerH__
-#define __CutModel2ManagerH__
-
-#include <iostream>
-#include <stdio.h>
-#include <vector>
-
-#include "vtkImageData.h"
-#include "vtkRenderWindowInteractor.h"
-#include "vtkRenderer.h"
-#include <vtkPolyDataWriter.h>
-
-#include "CutModel2Exception.h"
-#include "CutModel2Data.h"
-#include "CutModel2SaveBinInfo.h"
-
-
-
-class CutModel2Manager {
-
-public:
- CutModel2Manager(std::string path);
- ~CutModel2Manager();
-
- void setImageData(vtkImageData* img);
-
- void setInteractor(vtkRenderWindowInteractor* interactor);
-
- void setRenderer(vtkRenderer* renderer);
-
- void onAddCutModel2(int id, vtkCommand* observer) throw( CutModel2Exception);
-
- double* getImageRange()throw( CutModel2Exception);
-
- void changeOpacity(int id,int opacity)throw( CutModel2Exception);
-
- void ShowViewBox(int id,bool check)throw( CutModel2Exception);
-
- void ChangeShape(int id,int selection)throw( CutModel2Exception);
-
- void changeColor(int id,double r,double g,double b)throw( CutModel2Exception);
-
- void updateActorDirection(int id)throw( CutModel2Exception);
-
- void RemoveActor(int id)throw( CutModel2Exception);
-
- void ExecuteCut(int id, double* range, bool isinside)throw( CutModel2Exception);
-
- vtkImageData* GetResultImage();
-
- void RefreshActor(int id);
-
- void SaveCutModel2Data(std::string filename)throw( CutModel2Exception);
-
- void LoadCutModel2Data(std::string filename)throw( CutModel2Exception);
-
- CutModel2SaveBinInfo* AddActionUndo(int id, UNDOTYPE type)throw( CutModel2Exception);
-
- int Undo()throw( CutModel2Exception);
-
- int Redo()throw( CutModel2Exception);
-private:
-
- int _currentaction;
-
- void checkInvariant() throw( CutModel2Exception);
- std::string _path;
- vtkImageData* _img;
- vtkImageData* _copyimg;
- vtkRenderer* _render;
- vtkRenderWindowInteractor* _interactor;
-
- std::vector<CutModel2Data*> _vectordata;
- std::vector<CutModel2SaveBinInfo*> _undoredo;
- CutModel2Data* getCutModel2Data(int id)throw( CutModel2Exception);
-
-};
-
-#endif
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2SaveBinInfo.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-#include "CutModel2SaveBinInfo.h"
-
-/**
-** Start of the manager class
-**/
-CutModel2SaveBinInfo::CutModel2SaveBinInfo(int id, int currentaction, UNDOTYPE actiontype, std::string path){
-
- _id = id;
-
- char c[100];
- sprintf(c,"/infounrd_%d_fig_%d.info",currentaction,id);
-
- _stdFilename = path;
- _stdFilename+=c;
- _stdFilename+=".poly";
-
- _matrixFilename = path;
- _matrixFilename+=c;
- _actiontype = actiontype;
-
-
-}
-CutModel2SaveBinInfo::~CutModel2SaveBinInfo(){
-
-}
-void CutModel2SaveBinInfo::savePolyData(vtkPolyData* polydata){
- vtkPolyDataWriter * writer = vtkPolyDataWriter ::New();
- writer->SetFileName(_stdFilename.c_str());
- writer->SetInput(polydata);
- writer->SetFileTypeToBinary();
- writer->Write();
- writer->Delete();
-}
-
-vtkTransform* CutModel2SaveBinInfo::getPolyDataTransform()throw( CutModel2Exception){
- vtkPolyDataReader* reader = vtkPolyDataReader::New();
- //std::cout<<"filename vtkTransform* CutModel2SaveBinInfo::getPolyDataTransform()"<<this->getSTDFileName()<<std::endl;
- reader->SetFileName(this->getSTDFileName().c_str());
- vtkPolyData* poly = reader->GetOutput();
-
- vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
- mapper->SetInput(poly);
- vtkActor* actor = vtkActor::New();
- actor->SetMapper(mapper);
- vtkMatrix4x4* actmatrix = actor->GetMatrix();
-
- std::cout<<"tkTransform* CutModel2SaveBinInfo::getPolyDataTransform() Actor "<<actor<<std::endl;
- std::cout<<"tkTransform* CutModel2SaveBinInfo::getPolyDataTransform() Actor Matrix "<<actmatrix<<std::endl;
-
- mapper->Update();
-
- vtkTransform* transform = vtkTransform::New();
-
- transform->Identity();
-
- transform->GetMatrix()->SetElement(0,0,actmatrix->GetElement(0,0));
- transform->GetMatrix()->SetElement(1,0,actmatrix->GetElement(1,0));
- transform->GetMatrix()->SetElement(2,0,actmatrix->GetElement(2,0));
- transform->GetMatrix()->SetElement(0,1,actmatrix->GetElement(0,1));
- transform->GetMatrix()->SetElement(1,1,actmatrix->GetElement(1,1));
- transform->GetMatrix()->SetElement(2,1,actmatrix->GetElement(2,1));
- transform->GetMatrix()->SetElement(0,2,actmatrix->GetElement(0,2));
- transform->GetMatrix()->SetElement(1,2,actmatrix->GetElement(1,2));
- transform->GetMatrix()->SetElement(2,2,actmatrix->GetElement(2,2));
- transform->GetMatrix()->SetElement(0,3,actmatrix->GetElement(0,3));
- transform->GetMatrix()->SetElement(1,3,actmatrix->GetElement(1,3));
- transform->GetMatrix()->SetElement(2,3,actmatrix->GetElement(2,3));
-
- actor->Delete();
- mapper->Delete();
- reader->Delete();
- //poly->Delete();
-
-
- return transform;
-
-}
-
-
-void CutModel2SaveBinInfo::saveMatrix4x4(vtkMatrix4x4* matrix){
- fstream binary_file(_matrixFilename.c_str(),ios::out|ios::binary);
- binary_file.write(reinterpret_cast<char *>(matrix),sizeof(vtkMatrix4x4));
- binary_file.close();
-}
-vtkTransform* CutModel2SaveBinInfo::getTransformFromMatrixFile()throw( CutModel2Exception){
- vtkMatrix4x4* matrix = vtkMatrix4x4::New();
- fstream binary_file(_matrixFilename.c_str(),ios::binary|ios::in);
- binary_file.read(reinterpret_cast<char *>(matrix),sizeof(vtkMatrix4x4));
- binary_file.close();
-
- vtkTransform* transform = vtkTransform::New();
- transform->SetMatrix(matrix);
-
- return transform;
-}
-
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModel2SaveBinInfo.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-
-#ifndef __CutModel2SaveBinInfoH__
-#define __CutModel2SaveBinInfoH__
-
-#include <iostream>
-#include <vector>
-#include "CutModel2Exception.h"
-
-#include <vtkPolyData.h>
-#include <vtkPolyDataWriter.h>
-#include <vtkPolyDataReader.h>
-#include <vtkPolyDataMapper.h>
-#include <vtkTransform.h>
-#include <vtkMatrix4x4.h>
-#include <vtkActor.h>
-
-enum UNDOTYPE
-{
- CUTMODEL2_ADD = 0,
- CUTMODEL2_REMOVE = 10,
- CUTMODEL2_CUT= 20,
-
-};
-
-class CutModel2SaveBinInfo {
-
-public:
-
- CutModel2SaveBinInfo(int id, int currentaction,UNDOTYPE actiontype, std::string path);
- ~CutModel2SaveBinInfo();
-
- int getId(){
- return _id;
- }
-
- UNDOTYPE getActionType(){
- return _actiontype;
- }
- std::string getSTDFileName()throw( CutModel2Exception){
- if(_stdFilename==""){
- throw new CutModel2Exception("Filename undoredo does not exists");
- }
- return _stdFilename;
- }
-
- /*void setSTDFileName(std::string filename){
- _stdFilename = filename;
- }*/
-
- int getCurrentShape(){
- return _currentshape;
- }
-
- void setCurrentShape(int currentshape){
- _currentshape=currentshape;
- }
-
- void savePolyData(vtkPolyData* polydata);
-
- vtkTransform* getPolyDataTransform()throw( CutModel2Exception);
-
- void saveMatrix4x4(vtkMatrix4x4* matrix);
- vtkTransform* getTransformFromMatrixFile()throw( CutModel2Exception);
-
- void setRange(double* range){
- _range = range;
- }
- void setIsInside(bool isinside){
- _isinside = isinside;
- }
-
- double* getRange(){
- return _range;
- }
- bool getIsInside(){
- return _isinside;
- }
-
-private:
-
- int _id;
- UNDOTYPE _actiontype;
- int _currentshape;
- double* _range;
- bool _isinside;
- std::string _stdFilename;
- std::string _matrixFilename;
-};
-
-
-
-#endif
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelData.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-#include "CutModelData.h"
-
-/**
-** Start of the manager class
-**/
-CutModelData::CutModelData(int id, vtkRenderWindowInteractor* interactor, vtkCommand* observer, vtkImageData* img){
-
- initializeData(id, interactor, observer, img);
-
-}
-CutModelData::CutModelData(){
-
-}
-void CutModelData::initializeData(int id, vtkRenderWindowInteractor* interactor, vtkCommand* observer, vtkImageData* img){
- _id = id;
- _currentshape=0;
- createBoxWidget(interactor, observer);
- setTransform(img);
- createActor();
- createShapes();
- ChangeShape(0);
- checkInvariant();
-}
-CutModelData::~CutModelData(){
- checkInvariant();
- _boxWidgetVolume->Off();
- _boxWidgetVolume->Delete();
- _Mapper->Delete();
- _Actor->Delete();
- delete _cubefigure;
- delete _cylinderfigure;
- delete _spherefigure;
- currentmatrix->Delete();
- inversModel->Delete();
-}
-void CutModelData::RefreshViewBox(){
-
-}
-void CutModelData::createBoxWidget(vtkRenderWindowInteractor* interactor, vtkCommand* observer){
-
- _boxWidgetVolume = vtkBoxWidget::New();
- _boxWidgetVolume->SetInteractor( interactor );
- //_boxWidgetVolume->SetPlaceFactor(1);
- //_boxWidgetVolume->SetInput( img );
- //_boxWidgetVolume->PlaceWidget();
-
- _boxWidgetVolume->AddObserver( vtkCommand::InteractionEvent , observer );
- _boxWidgetVolume->AddObserver( vtkCommand::StartInteractionEvent , observer );
- _boxWidgetVolume->AddObserver( vtkCommand::RightButtonReleaseEvent , observer );
-
- _boxWidgetVolume->HandlesOn ();
- _boxWidgetVolume->On();
- //_boxWidgetVolume->GetHandleProperty()->SetOpacity(0.5);
- //_boxWidgetVolume->GetOutlineProperty()->SetOpacity(0.5);
-}
-void CutModelData::setTransform(vtkImageData* img)throw( CutModelException){
-
- currentmatrix = vtkTransform::New();
- modeltransform = vtkTransform::New();
- inversModel = vtkTransform::New();
-
- vtkMatrix4x4* matrix = vtkMatrix4x4::New();
- matrix->Identity();
- int *ext = img->GetExtent();
- double *spc = img->GetSpacing();
-
-
- matrix->SetElement(0,0,(ext[1]-ext[0])/4*spc[0]);
- matrix->SetElement(1,1,(ext[3]-ext[2])/4*spc[1]);
- matrix->SetElement(2,2,(ext[5]-ext[4])/4*spc[2]);
-
- double orgx = (ext[1]-ext[0])/2*spc[0];
- double orgy = (ext[3]-ext[2])/2*spc[1];
- double orgz = (ext[5]-ext[4])/2*spc[2];
-
- matrix->SetElement(0,3,orgx);
- matrix->SetElement(1,3,orgy);
- matrix->SetElement(2,3,orgz);
-
-
- currentmatrix->SetMatrix(matrix);
- _boxWidgetVolume->SetTransform(currentmatrix);
-
-}
-void CutModelData::createActor(){
-
- _Mapper = vtkPolyDataMapper::New();
- _Actor = vtkActor::New();
- _Actor->SetMapper(_Mapper);
- _Actor->GetProperty()->SetColor(1, 0, 0);
- _Actor->GetProperty()->SetOpacity(0.5);
-
-}
-void CutModelData::udapteActorDirection()throw( CutModelException){
- checkInvariant();
-
- _boxWidgetVolume->GetTransform(currentmatrix);
- _Actor->SetUserMatrix(currentmatrix->GetMatrix());//SetUserTransform(currentmatrix );
-}
-void CutModelData::createShapes(){
- _cubefigure = new CutModelFigureCube();
- _cylinderfigure = new CutModelFigureCylinder();
- _spherefigure = new CutModelFigureSphere();
-}
-void CutModelData::changeOpacity(int opacity)throw( CutModelException){
- checkInvariant();
- _Actor->GetProperty()->SetOpacity((double)opacity/100.0);
-}
-
-void CutModelData::ShowViewBox(bool check)throw( CutModelException){
- checkInvariant();
- if(check){
- _boxWidgetVolume->On();
- }else{
- _boxWidgetVolume->Off();
- }
-}
-
-void CutModelData::ChangeShape(int selection)throw( CutModelException){
- checkInvariant();
-
- if(selection == 0){
- _Mapper->SetInput(_spherefigure->getPolyData());
- }else if(selection == 1){
- _Mapper->SetInput(_cylinderfigure->getPolyData());
- }else if(selection == 2){
- _Mapper->SetInput(_cubefigure->getPolyData());
- }else{
- throw CutModelException("Shape type not found");
- }
-
- _currentshape=selection;
-}
-
-void CutModelData::checkInvariant()throw( CutModelException){
- if(_boxWidgetVolume==NULL){
- throw CutModelException("Box Widget not created");
- }
- if(_Mapper==NULL){
- throw CutModelException("Mapper not created");
- }
- if(_Actor==NULL){
- throw CutModelException("Actor not created");
- }
- if(_cubefigure==NULL){
- throw CutModelException("Cube not created");
- }
- if(_cylinderfigure==NULL){
- throw CutModelException("Cylinder not created");
- }
- if(_spherefigure==NULL){
- throw CutModelException("Sphere not created");
- }
-
-}
-
-vtkActor* CutModelData::getActor()throw( CutModelException){
- checkInvariant();
- return _Actor;
-}
-
-void CutModelData::changeColor(double r,double g,double b)throw( CutModelException){
- checkInvariant();
- _Actor->GetProperty()->SetColor( r,g,b );
-}
-CutModelFigure* CutModelData::getCurentCuttingModel(){
- checkInvariant();
-
- if(_currentshape == 0){
- return _spherefigure;
- }else if(_currentshape == 1){
- return _cylinderfigure;
- }else if(_currentshape == 2){
- return _cubefigure;
- }else{
- throw CutModelException("Shape type not found");
- }
-}
-void CutModelData::ExecuteCut( double* range, bool isinside, vtkImageData* copyimage)throw( CutModelException)
-{
-
- wxBusyCursor wait;
-
- CutModelFigure* actualCuttingModel = getCurentCuttingModel();
-
- //_boxWidgetVolume->GetTransform(currentmatrix);
- actualCuttingModel->SetVtkTransform(getModelTransform(copyimage));
- //actualCuttingModel->SetVtkTransform(currentmatrix);
- actualCuttingModel->SetInversVtkTransform(getModelTransformInvers());
-
- bool inside;
- bool volInt, volExt;
- int xx,yy,zz;
- unsigned short* pOrg;
- int ext[6];
- double spc[3];
- long int contAfter = 0;
- long int contBefor = 0;
-
- double minvalue = range[0];
- double value = range[1];
- double maxvalue = range[2];
-
-
- copyimage->GetExtent(ext);
-
- for (xx=ext[0];xx<ext[1]; xx++)
- {
- for (yy=ext[2];yy<ext[3]; yy++)
- {
- for (zz=ext[4];zz<ext[5];zz++)
- {
- inside=actualCuttingModel->IfPointInside(xx,yy,zz);
- if ( ((inside==true)&&(isinside==true)) || ((!inside==true)&&(!isinside)) )
- {
- pOrg=(unsigned short*)copyimage->GetScalarPointer (xx,yy,zz);
-
- //std::cout<<"xx,yy,zz "<<xx<<","<<yy<<","<<zz<<" "<<*pOrg<<std::endl;
- if ((unsigned short)minvalue <=(*pOrg)&&(*pOrg)<=(unsigned short)maxvalue)
- {
-
- *pOrg=(unsigned short)value;
-
- }
- } // if inside
- } // for zz
- } // for yy
- } // for xx
-
-}
-
-void CutModelData::ExecuteUnCut(bool isinside, vtkImageData* image, vtkImageData* copyimage)throw( CutModelException)
-{
-
- wxBusyCursor wait;
-
- CutModelFigure* actualCuttingModel = getCurentCuttingModel();
-
- actualCuttingModel->SetVtkTransform(getModelTransform(copyimage));
-
- actualCuttingModel->SetInversVtkTransform(getModelTransformInvers());
-
- bool inside;
- bool volInt, volExt;
- int xx,yy,zz;
- unsigned short* pOrg;
- int ext[6];
- double spc[3];
- long int contAfter = 0;
- long int contBefor = 0;
-
- double value;
-
-
-
- copyimage->GetExtent(ext);
-
- for (xx=ext[0];xx<ext[1]; xx++)
- {
- for (yy=ext[2];yy<ext[3]; yy++)
- {
- for (zz=ext[4];zz<ext[5];zz++)
- {
- inside=actualCuttingModel->IfPointInside(xx,yy,zz);
- if ( ((inside==true)&&(isinside==true)) || ((!inside==true)&&(!isinside)) )
- {
- value = *((unsigned short*)image->GetScalarPointer (xx,yy,zz));
- pOrg=(unsigned short*)copyimage->GetScalarPointer (xx,yy,zz);
- //std::cout<<"CutModelData::ExecuteUnCut() "<<value<<" "<<*pOrg<<std::endl;
- *pOrg=(unsigned short)value;
- } // if inside
- } // for zz
- } // for yy
- } // for xx
-
-}
-
-vtkTransform* CutModelData::getModelTransform(vtkImageData* copyimage){
-
- double *spc = copyimage->GetSpacing();
- modeltransform->Identity();
-
- vtkMatrix4x4* matrix = currentmatrix->GetMatrix();
- vtkMatrix4x4* matrixmodel = modeltransform->GetMatrix();
- matrixmodel->SetElement(0,0,matrix->GetElement(0,0)/spc[0]);
- matrixmodel->SetElement(1,0,matrix->GetElement(1,0)/spc[0]);
- matrixmodel->SetElement(2,0,matrix->GetElement(2,0)/spc[0]);
- matrixmodel->SetElement(0,1,matrix->GetElement(0,1)/spc[1]);
- matrixmodel->SetElement(1,1,matrix->GetElement(1,1)/spc[1]);
- matrixmodel->SetElement(2,1,matrix->GetElement(2,1)/spc[1]);
- matrixmodel->SetElement(0,2,matrix->GetElement(0,2)/spc[2]);
- matrixmodel->SetElement(1,2,matrix->GetElement(1,2)/spc[2]);
- matrixmodel->SetElement(2,2,matrix->GetElement(2,2)/spc[2]);
- matrixmodel->SetElement(0,3,matrix->GetElement(0,3)/spc[0]);
- matrixmodel->SetElement(1,3,matrix->GetElement(1,3)/spc[1]);
- matrixmodel->SetElement(2,3,matrix->GetElement(2,3)/spc[2]);
-
- /*
-
- double* pos = currentmatrix->GetPosition();
- modeltransform->Translate(pos[0]/spc[0],pos[1]/spc[1],pos[2]/spc[2]);
-
- double* scal = currentmatrix->GetScale();
- modeltransform->Scale(scal[0]/spc[0],scal[1]/spc[1],scal[2]/spc[2]);
-
- //double* orient = currentmatrix->GetOrientation();
- //modeltransform->RotateZ(orient[2]);
- //modeltransform->RotateY(orient[1]);
- //modeltransform->RotateX(orient[0]);
- double* orient = currentmatrix->GetOrientationWXYZ();
- modeltransform->RotateWXYZ(orient[0],orient[1],orient[2],orient[3]);
-
- */
-
-
- modeltransform->Update();
-
- return modeltransform;
-
-
-}
-void CutModelData::setTransform(vtkTransform* transform, vtkImageData* img)throw( CutModelException){
-
-
- double *spc = img->GetSpacing();
-
- currentmatrix->Identity();
-
- /*double* orient = transform->GetOrientationWXYZ();
- currentmatrix->RotateWXYZ(orient[0],orient[1],orient[2],orient[3]);
-
- double* pos = transform->GetPosition();
- currentmatrix->Translate(pos[0]/spc[0],pos[1]/spc[1],pos[2]/spc[2]);
-
- double* scal = transform->GetScale();
- currentmatrix->Scale(scal[0]/spc[0],scal[1]/spc[1],scal[2]/spc[2]);
-
- currentmatrix->Update(); */
-
- _boxWidgetVolume->SetTransform(transform);
-
- /*vtkMatrix4x4* matrix = transform->GetMatrix();
- vtkMatrix4x4* matrixcurrent = currentmatrix->GetMatrix();
- matrixcurrent->SetElement(0,0,matrix->GetElement(0,0)/spc[0]);
- matrixcurrent->SetElement(1,0,matrix->GetElement(1,0)/spc[0]);
- matrixcurrent->SetElement(2,0,matrix->GetElement(2,0)/spc[0]);
- matrixcurrent->SetElement(0,1,matrix->GetElement(0,1)/spc[1]);
- matrixcurrent->SetElement(1,1,matrix->GetElement(1,1)/spc[1]);
- matrixcurrent->SetElement(2,1,matrix->GetElement(2,1)/spc[1]);
- matrixcurrent->SetElement(0,2,matrix->GetElement(0,2)/spc[2]);
- matrixcurrent->SetElement(1,2,matrix->GetElement(1,2)/spc[2]);
- matrixcurrent->SetElement(2,2,matrix->GetElement(2,2)/spc[2]);
- matrixcurrent->SetElement(0,3,matrix->GetElement(0,3)/spc[0]);
- matrixcurrent->SetElement(1,3,matrix->GetElement(1,3)/spc[1]);
- matrixcurrent->SetElement(2,3,matrix->GetElement(2,3)/spc[2]); */
-
-
- udapteActorDirection();
- getModelTransform(img);
-
-}
-vtkTransform* CutModelData::getModelTransformInvers(){
- inversModel->Identity ();
- inversModel->Concatenate ( modeltransform );
- inversModel->Inverse();
- return inversModel;
-}
-
-vtkPolyData* CutModelData::getPolyData()throw( CutModelException){
- return _Mapper->GetInput();
-}
-
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelData.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-
-#ifndef __CutModelDataH__
-#define __CutModelDataH__
-
-#include <iostream>
-#include <vector>
-
-#include "vtkImageData.h"
-#include "vtkRenderWindowInteractor.h"
-#include "vtkCommand.h"
-#include "vtkBoxWidget.h"
-#include "vtkPolyDataMapper.h"
-#include "vtkActor.h"
-#include "vtkProperty.h"
-#include "CutModelException.h"
-#include "CutModelFigure.h"
-#include "CutModelFigureCube.h"
-#include "CutModelFigureSphere.h"
-#include "CutModelFigureCylinder.h"
-
-#include <wx/utils.h>
-
-class CutModelData {
-
-public:
- CutModelData();
- CutModelData(int id, vtkRenderWindowInteractor* interactor, vtkCommand* observer, vtkImageData* img);
- ~CutModelData();
- void initializeData(int id, vtkRenderWindowInteractor* interactor, vtkCommand* observer, vtkImageData* img);
-
-
- int getId(){
- return _id;
- }
-
- void changeOpacity(int opacity)throw( CutModelException);
-
- void ShowViewBox(bool check)throw( CutModelException);
-
- void ChangeShape(int selection)throw( CutModelException);
-
- vtkActor* getActor()throw( CutModelException);
-
- vtkPolyData* getPolyData()throw( CutModelException);
-
- void changeColor(double r,double g,double b)throw( CutModelException);
-
- void udapteActorDirection()throw( CutModelException);
-
- void ExecuteCut( double* range, bool isinside, vtkImageData* copyimage)throw( CutModelException);
-
- void ExecuteUnCut( bool isinside, vtkImageData* image, vtkImageData* copyimage)throw( CutModelException);
-
- void RefreshViewBox();
-
- vtkTransform* getCurrentMatrix(){
- return currentmatrix;
- }
-
- int getCurrentShape(){
- return _currentshape;
- }
-
- void setCurrentShape(int currentshape){
- _currentshape = currentshape;
- }
-
- void setTransform(vtkTransform* transform,vtkImageData* img)throw( CutModelException);
-private:
-
- void checkInvariant()throw( CutModelException);
-
- void createBoxWidget(vtkRenderWindowInteractor* interactor, vtkCommand* observer);
- void createActor();
- void setTransform(vtkImageData* img)throw( CutModelException);
- void createShapes();
-
- vtkBoxWidget* _boxWidgetVolume;
- vtkPolyDataMapper* _Mapper;
- vtkActor* _Actor;
- int _id;
-
- int _currentshape;
-
- CutModelFigureCube* _cubefigure;
- CutModelFigureCylinder* _cylinderfigure;
- CutModelFigureSphere* _spherefigure;
- vtkTransform* currentmatrix;
- vtkTransform* modeltransform;
- vtkTransform* inversModel;
-
-
- CutModelFigure* getCurentCuttingModel();
-
- vtkTransform* getModelTransform(vtkImageData* copyimage);
- vtkTransform* getModelTransformInvers();
-};
-
-#endif
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelException.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-#include "CutModelException.h"
-
-/**
-** Start of the manager class
-**/
-CutModelException::CutModelException(std::string cause)
-:std::exception(){
- _cause = cause;
-}
-CutModelException::~CutModelException()throw(){
-}
-
-
-
-
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelException.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-
-#ifndef __CutModelExceptionH__
-#define __CutModelExceptionH__
-
-#include <iostream>
-#include <vector>
-
-
-class CutModelException : public std::exception{
-
-public:
- CutModelException(std::string cause);
- ~CutModelException() throw();
-
- std::string getCause(){
- return _cause;
- }
-
-private:
-
- std::string _cause;
-
-};
-
-#endif
+++ /dev/null
-
-#include "CutModelFigure.h"
-
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-CutModelFigure::CutModelFigure()
-{
- _inversModel = vtkTransform::New();
- _matrixModel = vtkTransform::New();
- _matrixVisual = vtkTransform::New();
-
- _spcX=1;
- _spcY=1;
- _spcZ=1;
-}
-//----------------------------------------------------------------------------
-CutModelFigure::~CutModelFigure() // virtual
-{
- _inversModel->Delete();
-}
-//----------------------------------------------------------------------------
-void CutModelFigure::SetPosition(double x,double y, double z)
-{
- _px=x;
- _py=y;
- _pz=z;
-}
-//----------------------------------------------------------------------------
-void CutModelFigure::SetScale(double sx,double sy, double sz)
-{
- _sx=sx;
- _sy=sy;
- _sz=sz;
-}
-//----------------------------------------------------------------------------
-void CutModelFigure::SetRotation(double alfa,double beta, double teta)
-{
- _alfa=alfa;
- _beta=beta;
- _teta=teta;
-}
-
-//----------------------------------------------------------------------------
-void CutModelFigure::CalculeMatrix()
-{
- _matrixModel->Identity();
- _matrixModel->Translate(_px,_py,_pz);
- _matrixModel->RotateY(_beta);
- _matrixModel->RotateX(_alfa);
- _matrixModel->RotateY(_teta);
- _matrixModel->Scale(_sx,_sy,_sz);
-
- _matrixVisual->Identity();
- _matrixVisual->Translate( _px*_spcX , _py*_spcY , _pz*_spcZ );
- _matrixVisual->RotateY(_beta);
- _matrixVisual->RotateX(_alfa);
- _matrixVisual->RotateY(_teta);
- _matrixVisual->Scale( _sx*_spcX , _sy*_spcY , _sz*_spcZ );
-
-}
-
-
-//----------------------------------------------------------------------------
-void CutModelFigure::CalculeInversMatrix()
-{
- _inversModel->Identity ();
- _inversModel->Concatenate ( _matrixModel );
- _inversModel->Inverse();
-}
-//----------------------------------------------------------------------------
-bool CutModelFigure::IfPointInside(double x, double y, double z) // virtual
-{
- return true;
-}
-
-//----------------------------------------------------------------------------
-vtkTransform *CutModelFigure::GetVtkTransform()
-{
- return _matrixVisual;
-}
-
-//----------------------------------------------------------------------------
-//void CutModelFigure::SetVtkTransform(vtkTransform *matrix)
-//{
-// _matrixModel = matrix;
-//}
-
-//----------------------------------------------------------------------------
-double CutModelFigure::GetTheoricVolume() // virtual
-{
- return 0;
-}
-
-//----------------------------------------------------------------------------
-double CutModelFigure::GetPositionX()
-{
- return _px;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetPositionY()
-{
- return _py;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetPositionZ()
-{
- return _pz;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetScaleX()
-{
- return _sx;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetScaleY()
-{
- return _sy;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetScaleZ()
-{
- return _sz;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetAngleAlfa()
-{
- return _alfa;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetAngleBeta()
-{
- return _beta;
-}
-//----------------------------------------------------------------------------
-double CutModelFigure::GetAngleTeta()
-{
- return _teta;
-}
-//----------------------------------------------------------------------------
-char *CutModelFigure::GetName() // virtual
-{
- return "--";
-}
-
-//----------------------------------------------------------------------------
-void CutModelFigure::SetSpacing(double spcX,double spcY, double spcZ)
-{
- _spcX = spcX;
- _spcY = spcY;
- _spcZ = spcZ;
-}
\ No newline at end of file
+++ /dev/null
-#ifndef FIGURECUTTINGMODEL_H_
-#define FIGURECUTTINGMODEL_H_
-
-#include "vtkTransform.h"
-#include "vtkPolyData.h"
-
-class CutModelFigure
-{
-public:
- CutModelFigure(){}
-
- //~CutModelFigure();
-
- virtual void SetPosition(double x,double y, double z){
- _px = x;
- _py = y;
- _pz = z;
- }
-
- virtual void SetScale(double sx,double sy, double sz){
- _sx = sx;
- _sy = sy;
- _sz = sz;
- }
-
- virtual void SetRotation(double alfa,double beta, double teta){
- _alfa = alfa;
- _beta = beta;
- _teta = teta;
- }
-
- virtual void SetSpacing(double spcX,double spcY, double spcZ){
- _spcX = spcX;
- _spcY = spcY;
- _spcZ = spcZ;
- }
-
- virtual void SetVtkTransform(vtkTransform *transform){
- double *orient = transform->GetOrientation();
- _alfa = orient[0];
- _beta = orient[1];
- _teta = orient[2];
-
- double *scale = transform->GetScale();
- _sx = scale[0];
- _sy = scale[1];
- _sz = scale[2];
-
- double *position = transform->GetPosition();
- _px = position[0];
- _py = position[1];
- _pz = position[2];
-
-
- }
- virtual void SetInversVtkTransform(vtkTransform *inverstransform){
- _inversModel = inverstransform;
- }
-
- virtual bool IfPointInside(double x, double y, double z) = 0;
- virtual double GetTheoricVolume()=0;
- virtual vtkPolyData* getPolyData()=0;
-
-private:
- double _px;
- double _py;
- double _pz;
- double _alfa;
- double _beta;
- double _teta;
- double _spcX;
- double _spcY;
- double _spcZ;
- char *GetName;
-protected:
- double _sx;
- double _sy;
- double _sz;
- vtkTransform *_inversModel;
- vtkTransform *_matrixModel;
-};
-
-#endif /*FIGURECUTTINGMODEL_H_*/
+++ /dev/null
-
-#include "CutModelFigureCube.h"
-
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-CutModelFigureCube::CutModelFigureCube()
-: CutModelFigure()
-{
- _vtkcube = vtkCubeSource::New();
- _vtkcube->SetXLength (1);
- _vtkcube->SetYLength (1);
- _vtkcube->SetZLength (1);
-}
-//----------------------------------------------------------------------------
-CutModelFigureCube::~CutModelFigureCube() // virtual
-{
- _vtkcube->Delete();
-}
-//----------------------------------------------------------------------------
-bool CutModelFigureCube::IfPointInside(double x, double y, double z) // virtual
-{
- double in[4],out[4];
- in[0]=x;
- in[1]=y;
- in[2]=z;
- in[3]=1;
- _inversModel->MultiplyPoint (in, out);
-
- bool result=false;
- if ((out[0]>-0.5) && (out[0]<0.5) && (out[1]>-0.5) && (out[1]<0.5) && (out[2]>-0.5) && (out[2]<0.5) )
- {
- result=true;
- }
- return result;
-}
-//----------------------------------------------------------------------------
-double CutModelFigureCube::GetTheoricVolume() // virtual
-{
- return _sx * _sy * _sz;
-}
-
-//----------------------------------------------------------------------------
-char *CutModelFigureCube::GetName() // virtual
-{
- return "Cube";
-}
-
-vtkPolyData* CutModelFigureCube::getPolyData(){
- return _vtkcube->GetOutput();
-}
-
+++ /dev/null
-#ifndef CutModelFigureCube_H_
-#define CutModelFigureCube_H_
-
-#include "CutModelFigure.h"
-#include "vtkCubeSource.h"
-
-class CutModelFigureCube : public CutModelFigure
-{
-public:
- CutModelFigureCube();
- virtual ~CutModelFigureCube();
- virtual bool IfPointInside(double x, double y, double z);
- virtual double GetTheoricVolume();
- virtual vtkPolyData* getPolyData();
- virtual char *GetName();
-private:
- vtkCubeSource* _vtkcube;
-protected:
-};
-
-#endif /*FIGURECUTTINGCUBEMODEL_H_*/
+++ /dev/null
-
-#include "CutModelFigureCylinder.h"
-
-CutModelFigureCylinder::CutModelFigureCylinder()
-{
- _vtkcylinder = vtkCylinderSource::New();
- _vtkcylinder->SetResolution(20);
-}
-//----------------------------------------------------------------------------
-CutModelFigureCylinder::~CutModelFigureCylinder() // virtual
-{
- _vtkcylinder->Delete();
-}
-//----------------------------------------------------------------------------
-bool CutModelFigureCylinder::IfPointInside(double x, double y, double z) // virtual
-{
- double in[4],out[4];
- in[0]=x;
- in[1]=y;
- in[2]=z;
- in[3]=1;
- _inversModel->MultiplyPoint (in, out);
-
- bool result=false;
- if ((sqrt( out[0]*out[0] + out[2]*out[2] )<0.5 ) && (out[1]>-0.5) && (out[1]<0.5) )
- {
- result=true;
- }
- return result;
-}
-//----------------------------------------------------------------------------
-double CutModelFigureCylinder::GetTheoricVolume() // virtual
-{
- double piTMP=3.14159265;
- return piTMP*(_sx/2)*(_sz/2)*_sy;
-}
-//----------------------------------------------------------------------------
-char *CutModelFigureCylinder::GetName() // virtual
-{
- return "Cylinder";
-}
-vtkPolyData* CutModelFigureCylinder::getPolyData(){
- return _vtkcylinder->GetOutput();
-}
-//----------------------------------------------------------------------------
+++ /dev/null
-#ifndef CutModelFigureCylinder_H_
-#define CutModelFigureCylinder_H_
-
-#include "CutModelFigure.h"
-#include "vtkCylinderSource.h"
-
-class CutModelFigureCylinder : public CutModelFigure
-{
-public:
- CutModelFigureCylinder();
- virtual ~CutModelFigureCylinder();
- virtual bool IfPointInside(double x, double y, double z);
- virtual double GetTheoricVolume();
- virtual vtkPolyData* getPolyData();
- virtual char *GetName();
-
-private:
- vtkCylinderSource* _vtkcylinder;
-protected:
-};
-
-#endif /*FIGURECUTTINGCYLINDERMODEL_H_*/
+++ /dev/null
-#include "CutModelFigureSphere.h"
-
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-CutModelFigureSphere::CutModelFigureSphere()
-{
- _vtksphere = vtkSphereSource::New();
- _vtksphere->SetThetaResolution (20);
- _vtksphere->SetPhiResolution (20);
-}
-//----------------------------------------------------------------------------
-CutModelFigureSphere::~CutModelFigureSphere() // virtual
-{
- _vtksphere->Delete();
-}
-//----------------------------------------------------------------------------
-bool CutModelFigureSphere::IfPointInside(double x, double y, double z) // virtual
-{
- double in[4],out[4];
- in[0]=x;
- in[1]=y;
- in[2]=z;
- in[3]=1;
- _inversModel->MultiplyPoint (in, out);
-
- bool result=false;
- if (sqrt( out[0]*out[0] + out[1]*out[1] + out[2]*out[2] )<0.5 )
- {
- result=true;
- }
- return result;
-}
-//----------------------------------------------------------------------------
-double CutModelFigureSphere::GetTheoricVolume() // virtual
-{
- double piTMP=3.14159265;
- return (4.0/3.0) * piTMP * (_sx/2)*(_sy/2)*(_sz/2);
-}
-//----------------------------------------------------------------------------
-char *CutModelFigureSphere::GetName() // virtual
-{
- return "Sphere";
-}
-
-vtkPolyData* CutModelFigureSphere::getPolyData(){
- return _vtksphere->GetOutput();
-}
-
+++ /dev/null
-#ifndef CutModelFigureSphere_H_
-#define CutModelFigureSphere_H_
-
-#include "CutModelFigure.h"
-#include "vtkSphereSource.h"
-
-class CutModelFigureSphere : public CutModelFigure
-{
-public:
- CutModelFigureSphere();
- virtual ~CutModelFigureSphere();
- virtual bool IfPointInside(double x, double y, double z);
- virtual double GetTheoricVolume();
- virtual char *GetName();
- virtual vtkPolyData* getPolyData();
-private:
- vtkSphereSource* _vtksphere;
-protected:
-};
-
-#endif /*FIGURECUTTINGSPHEREMODEL_H_*/
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelManager.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-#include "CutModelManager.h"
-
-/**
-** Start of the manager class
-**/
-CutModelManager::CutModelManager(std::string path){
- _path = path;
- _img = NULL;
- _copyimg = NULL;
- _interactor = NULL;
- _render = NULL;
- _currentaction=0;
-}
-CutModelManager::~CutModelManager(){
- std::string files = _path;
- files+="/infounrd_0_fig_0.info";
- remove(files.c_str());
-}
-
-
-void CutModelManager::setImageData(vtkImageData* img){
- _img = img;
- if(_copyimg!=NULL){
- _copyimg->Delete();
- }
- _copyimg = vtkImageData::New();
- _copyimg->SetExtent(_img->GetExtent());
- _copyimg->SetSpacing(_img->GetSpacing());
- _copyimg->AllocateScalars();
-
- _copyimg->DeepCopy(_img);
-
-}
-
-void CutModelManager::setInteractor(vtkRenderWindowInteractor* interactor){
- _interactor = interactor;
-}
-
-void CutModelManager::setRenderer(vtkRenderer* renderer){
- _render = renderer;
-}
-
-void CutModelManager::onAddCutModel(int id, vtkCommand* observer) throw( CutModelException){
- checkInvariant();
-
- CutModelData* data = new CutModelData(id,_interactor, observer, _img);
- _vectordata.push_back(data);
-
- _render->AddActor(data->getActor());
-
- //_render->UpdateCamera();
- _render->Render();
-}
-
-void CutModelManager::checkInvariant() throw( CutModelException){
- if(_img==NULL){
- throw CutModelException("The image is not set");
- }
- if(_copyimg==NULL){
- throw CutModelException("The image is not set");
- }
- if(_interactor==NULL){
- throw CutModelException("Interactor not set");
- }
- if(_render==NULL){
- throw CutModelException("Render not set");
- }
-}
-
-double* CutModelManager::getImageRange()throw( CutModelException){
- checkInvariant();
- return _img->GetScalarRange();
-}
-
-void CutModelManager::changeOpacity(int id,int opacity)throw( CutModelException){
- checkInvariant();
- CutModelData* current = getCutModelData(id);
- current->changeOpacity(opacity);
-}
-
-void CutModelManager::ShowViewBox(int id,bool check)throw( CutModelException){
- checkInvariant();
- CutModelData* current = getCutModelData(id);
- current->ShowViewBox(check);
-}
-
-void CutModelManager::ChangeShape(int id,int selection)throw( CutModelException){
- checkInvariant();
- CutModelData* current = getCutModelData(id);
- current->ChangeShape(selection);
- _render->Render();
-}
-
-CutModelData* CutModelManager::getCutModelData(int id)throw( CutModelException){
-
- CutModelData* current = NULL;
- for(int i= 0; i < _vectordata.size();i++){
- std::cout<<"id in CutModelManager:: "<<id<<std::endl;
- std::cout<<"vectordataid in CutModelManager:: "<<_vectordata[i]->getId()<<std::endl;
-
- if(_vectordata[i]->getId()==id){
- current = _vectordata[i];
- }
- }
- if(current ==NULL){
-
- throw CutModelException("Data not found");
- }
- return current;
-}
-
-void CutModelManager::updateActorDirection(int id)throw( CutModelException){
- checkInvariant();
- CutModelData* current = getCutModelData(id);
- current->udapteActorDirection();
-
-}
-
-void CutModelManager::changeColor(int id,double r,double g,double b)throw( CutModelException){
-
- checkInvariant();
- CutModelData* current = getCutModelData(id);
- current->changeColor(r,g,b);
- _render->Render();
-}
-void CutModelManager::RemoveActor(int id)throw( CutModelException){
-
- checkInvariant();
-
- CutModelData* current = getCutModelData(id);
- for(int i = 0; i < _vectordata.size()-1;i++){
- if(_vectordata[i]->getId()==id){
- for(int j = i; j < _vectordata.size()-1;j++){
- _vectordata[j]=_vectordata[j+1];
- }
- i = _vectordata.size();
- }
- }
- _render->RemoveActor(current->getActor());
- delete current;
- _vectordata.pop_back();
- _render->Render();
-
-}
-
-void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
- checkInvariant();
-
- CutModelData* current = getCutModelData(id);
- current->ExecuteCut(range, isinside,_copyimg);
-
-
- /*
- Setting extra information for the undo
- */
- CutModelSaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL_CUT);
- undoaction->setRange(range);
- undoaction->setIsInside(isinside);
-
-}
-
-vtkImageData* CutModelManager::GetResultImage(){
- checkInvariant();
- return _copyimg;
-}
-
-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, _copyimg);
-
- currentmodel->setCurrentShape(currentundo->getCurrentShape());
-
- currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img, _copyimg);
-
- }
- //Every thing ok
- _currentaction--;
- return 0;
- }
- return -1;
-}
-
-int CutModelManager::Redo() throw( CutModelException){
-
- if(_currentaction >= 0 && _currentaction < _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, _copyimg);
- currentmodel->setCurrentShape(currentundo->getCurrentShape());
- currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _copyimg);
- }
-
- _currentaction++;
-
- return 0;
- }
- return -1;
-}
\ No newline at end of file
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelManager.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-
-#ifndef __CutModelManagerH__
-#define __CutModelManagerH__
-
-#include <iostream>
-#include <stdio.h>
-#include <vector>
-
-#include "vtkImageData.h"
-#include "vtkRenderWindowInteractor.h"
-#include "vtkRenderer.h"
-#include <vtkPolyDataWriter.h>
-
-#include "CutModelException.h"
-#include "CutModelData.h"
-#include "CutModelSaveBinInfo.h"
-
-
-
-class CutModelManager {
-
-public:
- CutModelManager(std::string path);
- ~CutModelManager();
-
- void setImageData(vtkImageData* img);
-
- void setInteractor(vtkRenderWindowInteractor* interactor);
-
- void setRenderer(vtkRenderer* renderer);
-
- void onAddCutModel(int id, vtkCommand* observer) throw( CutModelException);
-
- double* getImageRange()throw( CutModelException);
-
- void changeOpacity(int id,int opacity)throw( CutModelException);
-
- void ShowViewBox(int id,bool check)throw( CutModelException);
-
- void ChangeShape(int id,int selection)throw( CutModelException);
-
- void changeColor(int id,double r,double g,double b)throw( CutModelException);
-
- void updateActorDirection(int id)throw( CutModelException);
-
- void RemoveActor(int id)throw( CutModelException);
-
- void ExecuteCut(int id, double* range, bool isinside)throw( CutModelException);
-
- vtkImageData* GetResultImage();
-
- void RefreshActor(int id);
-
- void SaveCutModelData(std::string filename)throw( CutModelException);
-
- void LoadCutModelData(std::string filename)throw( CutModelException);
-
- CutModelSaveBinInfo* AddActionUndo(int id, UNDOTYPE type)throw( CutModelException);
-
- int Undo()throw( CutModelException);
-
- int Redo()throw( CutModelException);
-private:
-
- int _currentaction;
-
- void checkInvariant() throw( CutModelException);
- std::string _path;
- vtkImageData* _img;
- vtkImageData* _copyimg;
- vtkRenderer* _render;
- vtkRenderWindowInteractor* _interactor;
-
- std::vector<CutModelData*> _vectordata;
- std::vector<CutModelSaveBinInfo*> _undoredo;
- CutModelData* getCutModelData(int id)throw( CutModelException);
-
-};
-
-#endif
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelSaveBinInfo.cxx,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-#include "CutModelSaveBinInfo.h"
-
-/**
-** Start of the manager class
-**/
-CutModelSaveBinInfo::CutModelSaveBinInfo(int id, int currentaction, UNDOTYPE actiontype, std::string path){
-
- _id = id;
-
- char c[100];
- sprintf(c,"/infounrd_%d_fig_%d.info",currentaction,id);
-
- _stdFilename = path;
- _stdFilename+=c;
- _stdFilename+=".poly";
-
- _matrixFilename = path;
- _matrixFilename+=c;
- _actiontype = actiontype;
-
-
-}
-CutModelSaveBinInfo::~CutModelSaveBinInfo(){
-
-}
-void CutModelSaveBinInfo::savePolyData(vtkPolyData* polydata){
- vtkPolyDataWriter * writer = vtkPolyDataWriter ::New();
- writer->SetFileName(_stdFilename.c_str());
- writer->SetInput(polydata);
- writer->SetFileTypeToBinary();
- writer->Write();
- writer->Delete();
-}
-
-vtkTransform* CutModelSaveBinInfo::getPolyDataTransform()throw( CutModelException){
- vtkPolyDataReader* reader = vtkPolyDataReader::New();
- //std::cout<<"filename vtkTransform* CutModelSaveBinInfo::getPolyDataTransform()"<<this->getSTDFileName()<<std::endl;
- reader->SetFileName(this->getSTDFileName().c_str());
- vtkPolyData* poly = reader->GetOutput();
-
- vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
- mapper->SetInput(poly);
- vtkActor* actor = vtkActor::New();
- actor->SetMapper(mapper);
- vtkMatrix4x4* actmatrix = actor->GetMatrix();
-
- std::cout<<"tkTransform* CutModelSaveBinInfo::getPolyDataTransform() Actor "<<actor<<std::endl;
- std::cout<<"tkTransform* CutModelSaveBinInfo::getPolyDataTransform() Actor Matrix "<<actmatrix<<std::endl;
-
- mapper->Update();
-
- vtkTransform* transform = vtkTransform::New();
-
- transform->Identity();
-
- transform->GetMatrix()->SetElement(0,0,actmatrix->GetElement(0,0));
- transform->GetMatrix()->SetElement(1,0,actmatrix->GetElement(1,0));
- transform->GetMatrix()->SetElement(2,0,actmatrix->GetElement(2,0));
- transform->GetMatrix()->SetElement(0,1,actmatrix->GetElement(0,1));
- transform->GetMatrix()->SetElement(1,1,actmatrix->GetElement(1,1));
- transform->GetMatrix()->SetElement(2,1,actmatrix->GetElement(2,1));
- transform->GetMatrix()->SetElement(0,2,actmatrix->GetElement(0,2));
- transform->GetMatrix()->SetElement(1,2,actmatrix->GetElement(1,2));
- transform->GetMatrix()->SetElement(2,2,actmatrix->GetElement(2,2));
- transform->GetMatrix()->SetElement(0,3,actmatrix->GetElement(0,3));
- transform->GetMatrix()->SetElement(1,3,actmatrix->GetElement(1,3));
- transform->GetMatrix()->SetElement(2,3,actmatrix->GetElement(2,3));
-
- actor->Delete();
- mapper->Delete();
- reader->Delete();
- //poly->Delete();
-
-
- return transform;
-
-}
-
-
-void CutModelSaveBinInfo::saveMatrix4x4(vtkMatrix4x4* matrix){
- fstream binary_file(_matrixFilename.c_str(),ios::out|ios::binary);
- binary_file.write(reinterpret_cast<char *>(matrix),sizeof(vtkMatrix4x4));
- binary_file.close();
-}
-vtkTransform* CutModelSaveBinInfo::getTransformFromMatrixFile()throw( CutModelException){
- vtkMatrix4x4* matrix = vtkMatrix4x4::New();
- fstream binary_file(_matrixFilename.c_str(),ios::binary|ios::in);
- binary_file.read(reinterpret_cast<char *>(matrix),sizeof(vtkMatrix4x4));
- binary_file.close();
-
- vtkTransform* transform = vtkTransform::New();
- transform->SetMatrix(matrix);
-
- return transform;
-}
-
+++ /dev/null
-/*=========================================================================
-
- Program: wxMaracas
- Module: $RCSfile: CutModelSaveBinInfo.h,v $
- Language: C++
- Date: $Date: 2009/11/19 15:24:57 $
- Version: $Revision: 1.1 $
-
- Copyright: (c) 2002, 2003
- License:
-
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notice for more information.
-
-=========================================================================*/
-
-
-
-
-#ifndef __CutModelSaveBinInfoH__
-#define __CutModelSaveBinInfoH__
-
-#include <iostream>
-#include <vector>
-#include "CutModelException.h"
-
-#include <vtkPolyData.h>
-#include <vtkPolyDataWriter.h>
-#include <vtkPolyDataReader.h>
-#include <vtkPolyDataMapper.h>
-#include <vtkTransform.h>
-#include <vtkMatrix4x4.h>
-#include <vtkActor.h>
-
-enum UNDOTYPE
-{
- CUTMODEL_ADD = 0,
- CUTMODEL_REMOVE = 10,
- CUTMODEL_CUT= 20,
-
-};
-
-class CutModelSaveBinInfo {
-
-public:
-
- CutModelSaveBinInfo(int id, int currentaction,UNDOTYPE actiontype, std::string path);
- ~CutModelSaveBinInfo();
-
- int getId(){
- return _id;
- }
-
- UNDOTYPE getActionType(){
- return _actiontype;
- }
- std::string getSTDFileName()throw( CutModelException){
- if(_stdFilename==""){
- throw new CutModelException("Filename undoredo does not exists");
- }
- return _stdFilename;
- }
-
- /*void setSTDFileName(std::string filename){
- _stdFilename = filename;
- }*/
-
- int getCurrentShape(){
- return _currentshape;
- }
-
- void setCurrentShape(int currentshape){
- _currentshape=currentshape;
- }
-
- void savePolyData(vtkPolyData* polydata);
-
- vtkTransform* getPolyDataTransform()throw( CutModelException);
-
- void saveMatrix4x4(vtkMatrix4x4* matrix);
- vtkTransform* getTransformFromMatrixFile()throw( CutModelException);
-
- void setRange(double* range){
- _range = range;
- }
- void setIsInside(bool isinside){
- _isinside = isinside;
- }
-
- double* getRange(){
- return _range;
- }
- bool getIsInside(){
- return _isinside;
- }
-
-private:
-
- int _id;
- UNDOTYPE _actiontype;
- int _currentshape;
- double* _range;
- bool _isinside;
- std::string _stdFilename;
- std::string _matrixFilename;
-};
-
-
-
-#endif