From: Juan Prieto Date: Fri, 11 May 2012 11:46:36 +0000 (+0000) Subject: addition of image stencil to surface rendering X-Git-Tag: v1.0.4~24 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=30b7a0a5d40cb89fc765a4e7af305962dcebf75c;p=creaMaracasVisu.git addition of image stencil to surface rendering --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f2f6cf..e1df889 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,8 @@ INCLUDE_DIRECTORIES( #JCP Ubuntu this file not found glibconfig.h, config of wxgtk goes wrong somewhere -INCLUDE_DIRECTORIES(/usr/lib/x86_64-linux-gnu/glib-2.0/include/) +INCLUDE_DIRECTORIES(/usr/lib/x86_64-linux-gnu/gtk-2.0/include/) +LINK_DIRECTORIES(/usr/lib/x86_64-linux-gnu/) #JCP Ubuntu this file not found glibconfig.h, config of wxgtk goes wrong somewhere ADD_SUBDIRECTORY(install) diff --git a/appli/QtVTKViewer/qtvtkviewer.cxx b/appli/QtVTKViewer/qtvtkviewer.cxx index fb6abc8..63becde 100644 --- a/appli/QtVTKViewer/qtvtkviewer.cxx +++ b/appli/QtVTKViewer/qtvtkviewer.cxx @@ -61,9 +61,9 @@ int main(int argc, char **argv) QtVTKViewerWidget *viewer = new QtVTKViewerWidget(mainwindow); mainwindow-> setCentralWidget(viewer); + mainwindow->setMinimumSize(1024, 768); - - mainwindow->show(); + mainwindow->showMaximized(); if(img) viewer->setImage(img); diff --git a/lib/GUI/Base/SurfaceRenderer/wxMaracasSurfaceRenderingManager.cxx b/lib/GUI/Base/SurfaceRenderer/wxMaracasSurfaceRenderingManager.cxx index ac816f6..d60ea62 100644 --- a/lib/GUI/Base/SurfaceRenderer/wxMaracasSurfaceRenderingManager.cxx +++ b/lib/GUI/Base/SurfaceRenderer/wxMaracasSurfaceRenderingManager.cxx @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: wxMaracasSurfaceRenderingManager.cxx,v $ Language: C++ - Date: $Date: 2011/10/05 16:26:55 $ - Version: $Revision: 1.2 $ + Date: $Date: 2012/05/11 11:46:37 $ + Version: $Revision: 1.3 $ Copyright: (c) 2002, 2003 License: @@ -14,13 +14,10 @@ PURPOSE. See the above copyright notice for more information. =========================================================================*/ + #include "wxMaracasSurfaceRenderingManager.h" #include "wxMaracasSurfaceRenderingManagerDataMhd.h" - -#include "vtkPLYReader.h" -#include "vtkSmartPointer.h" - /** ** Start of the manager class **/ @@ -28,6 +25,7 @@ wxMaracasSurfaceRenderingManager::wxMaracasSurfaceRenderingManager(){ _renderer = NULL; _interactor = NULL; _idCount=0; + image = 0; } wxMaracasSurfaceRenderingManager::~wxMaracasSurfaceRenderingManager(){ } @@ -87,6 +85,35 @@ int wxMaracasSurfaceRenderingManager::addProp3D(int idTP, vtkProp3D* prop3D, std } return -1; } + +/** +** Adds a polydata and creates the prop3D (actor) to the manager and returns the identifier +**/ +/** +** Adds a polydata and creates the prop3D (actor) to the manager and returns the identifier +**/ +int wxMaracasSurfaceRenderingManager::addProp3D(int idTP, std::string filename, std::string dataname){ + + + wxMaracasSurfaceRenderingManagerData* data = new wxMaracasSurfaceRenderingManagerData(filename, _interactor); + if(dataname.compare("") != 0) + data->setDataname(dataname); + + prop3Dvect.push_back(data); + _renderer->AddActor(data->getProp3D()); + if(idTP == -1) + { + data->setId(_idCount); + _idCount++; + } + else + { + data->setId(idTP); + } + return data->getId(); + +} + int wxMaracasSurfaceRenderingManager::addPropMHD(int idTP, vtkImageData* imagedata, std::string dataname) throw(char*){ checkInvariant(); if(imagedata != NULL){ @@ -113,7 +140,7 @@ int wxMaracasSurfaceRenderingManager::addPropMHD(int idTP, vtkImageData* imageda /** ** adds or removes an actor depending of the bool value **/ -void wxMaracasSurfaceRenderingManager::addRemoveActor(int propid, bool addremove) throw(char*){ +bool wxMaracasSurfaceRenderingManager::addRemoveActor(int propid, bool addremove) throw(char*){ checkInvariant(); wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid); @@ -124,12 +151,14 @@ void wxMaracasSurfaceRenderingManager::addRemoveActor(int propid, bool addremove _renderer->RemoveViewProp(data->getProp3D()); } _renderer->Render(); + return true; }else { if(addremove && propid == 0 && image){ addPropMHD(0, image, "id0"); + return true; } - return; } + return false; } /** ** adds or removes the surface box depending of the bool value @@ -194,7 +223,7 @@ void wxMaracasSurfaceRenderingManager::changeIsoValue(int propid, double min, do _renderer->Render(); } -vtkProp3D* wxMaracasSurfaceRenderingManager:: getProp3D(std::string filename){ +/*vtkProp3D* wxMaracasSurfaceRenderingManager:: getProp3D(std::string filename){ if(filename.compare("")!= 0){ vtkSmartPointer polydata = vtkSmartPointer::New(); @@ -210,6 +239,11 @@ vtkProp3D* wxMaracasSurfaceRenderingManager:: getProp3D(std::string filename){ plyreader->SetFileName(filename.c_str()); plyreader->Update(); polydata->DeepCopy(plyreader->GetOutput()); + }else if(ext.compare(VTK)==0){ + vtkSmartPointer polyreader =vtkSmartPointer::New(); + polyreader->SetFileName(filename.c_str()); + polyreader->Update(); + polydata->DeepCopy(polyreader->GetOutput()); } vtkSmartPointer dataMapper = vtkSmartPointer::New(); @@ -221,7 +255,7 @@ vtkProp3D* wxMaracasSurfaceRenderingManager:: getProp3D(std::string filename){ return dataActor; } return NULL; -} +}*/ vtkImageData* wxMaracasSurfaceRenderingManager::getImageData(std::string filename){ if(filename.compare("")!= 0){ @@ -251,17 +285,16 @@ void wxMaracasSurfaceRenderingManager::checkInvariant() throw(char*){ } wxMaracasSurfaceRenderingManagerData* wxMaracasSurfaceRenderingManager::getViewData(int id) throw(char*){ - int i; + int i = 0; for(i = 0; i < (int)(prop3Dvect.size());i++){ if(prop3Dvect[i]->getId() == id){ return prop3Dvect[i]; } - } - return 0; + } #ifndef USE_QT throw "id not found in the data"; #else - return NULL; + return 0; #endif @@ -335,5 +368,14 @@ void wxMaracasSurfaceRenderingManager::saveProp3DSTL(int propid,const char* file } void wxMaracasSurfaceRenderingManager::loadProp3DSTL(const char* filename){ - this->addProp3D(-1, this->getProp3D(filename), filename); + this->addProp3D(-1, filename); +} + +void wxMaracasSurfaceRenderingManager::exportImageStencil(int propid,const char* filename){ + checkInvariant(); + + wxMaracasSurfaceRenderingManagerData* data = this->getViewData(propid); + if(data && data->getProp3D()!=NULL){ + data->exportImageStencil(filename); + } } diff --git a/lib/GUI/Base/SurfaceRenderer/wxMaracasSurfaceRenderingManager.h b/lib/GUI/Base/SurfaceRenderer/wxMaracasSurfaceRenderingManager.h index 6342797..abaaf46 100644 --- a/lib/GUI/Base/SurfaceRenderer/wxMaracasSurfaceRenderingManager.h +++ b/lib/GUI/Base/SurfaceRenderer/wxMaracasSurfaceRenderingManager.h @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: wxMaracasSurfaceRenderingManager.h,v $ Language: C++ - Date: $Date: 2011/10/05 16:26:55 $ - Version: $Revision: 1.2 $ + Date: $Date: 2012/05/11 11:46:37 $ + Version: $Revision: 1.3 $ Copyright: (c) 2002, 2003 License: @@ -55,6 +55,12 @@ public: ** Adds a prop3D to the manager and returns the identifier **/ int addProp3D(int idTP, vtkProp3D* prop3D, std::string dataname) throw (char*); + + /** + ** Adds a polydata and creates the prop3D (actor) to the manager and returns the identifier + **/ + int addProp3D(int idTP, std::string filename, std::string dataname = ""); + /** ** Adds a prop3D to the manager and returns the identifier **/ @@ -74,7 +80,7 @@ public: /** ** loads a prop3D from a nSTL file **/ - vtkProp3D* getProp3D(std::string filename); + //vtkProp3D* getProp3D(std::string filename); /** ** loads a MHD file to convert it into an actor @@ -91,7 +97,7 @@ public: /** ** adds or removes an actor depending of the bool value **/ - void addRemoveActor(int propid, bool addremove)throw(char*); + bool addRemoveActor(int propid, bool addremove)throw(char*); /** ** **/ @@ -137,6 +143,7 @@ public: void loadProp3DSTL(const char* filename); + void exportImageStencil(int propid,const char* filename); private: std::vector prop3Dvect; diff --git a/lib/GUI/Qt/SurfaceRenderer/qtsurfacerenderer.cxx b/lib/GUI/Qt/SurfaceRenderer/qtsurfacerenderer.cxx index 2907ce7..94de761 100644 --- a/lib/GUI/Qt/SurfaceRenderer/qtsurfacerenderer.cxx +++ b/lib/GUI/Qt/SurfaceRenderer/qtsurfacerenderer.cxx @@ -13,13 +13,25 @@ QtSurfaceRenderer::QtSurfaceRenderer(QWidget *parent) : this->ui->tabWidgetSurface->removeTab(1); this->ui->tabWidgetSurface->removeTab(0); - QtSurfaceRendererPanel* surfacepanel = new QtSurfaceRendererPanel(this); this->ui->tabWidgetSurface->addTab(surfacepanel, QString("Surface Rendering")); Renderer = 0; Interactor = 0; } +void QtSurfaceRenderer::SetRenderer(vtkRenderer* render){ + Renderer = render; + this->ui->tabWidgetSurface->setCurrentIndex(0); + QtSurfaceRendererPanel* surfacepanel = (QtSurfaceRendererPanel*)this->ui->tabWidgetSurface->currentWidget(); + surfacepanel->setRenderer(Renderer); +} + +void QtSurfaceRenderer::SetInteractor(vtkRenderWindowInteractor* interactor){ + Interactor = interactor; + this->ui->tabWidgetSurface->setCurrentIndex(0); + QtSurfaceRendererPanel* surfacepanel = (QtSurfaceRendererPanel*)this->ui->tabWidgetSurface->currentWidget(); + surfacepanel->setInteractor(Interactor); +} QtSurfaceRenderer::~QtSurfaceRenderer() { @@ -28,9 +40,7 @@ QtSurfaceRenderer::~QtSurfaceRenderer() void QtSurfaceRenderer::SetImageData(vtkImageData* img){ this->ui->tabWidgetSurface->setCurrentIndex(0); - QtSurfaceRendererPanel* surfacepanel = (QtSurfaceRendererPanel*)this->ui->tabWidgetSurface->currentWidget(); - surfacepanel->setInteractor(Interactor); - surfacepanel->setRenderer(Renderer); + QtSurfaceRendererPanel* surfacepanel = (QtSurfaceRendererPanel*)this->ui->tabWidgetSurface->currentWidget(); surfacepanel->setImageData(img); } diff --git a/lib/GUI/Qt/SurfaceRenderer/qtsurfacerenderer.h b/lib/GUI/Qt/SurfaceRenderer/qtsurfacerenderer.h index 6ffe36e..d4ad18c 100644 --- a/lib/GUI/Qt/SurfaceRenderer/qtsurfacerenderer.h +++ b/lib/GUI/Qt/SurfaceRenderer/qtsurfacerenderer.h @@ -17,8 +17,8 @@ public: ~QtSurfaceRenderer(); - vtkSetMacro(Renderer, vtkRenderer*); - vtkSetMacro(Interactor, vtkRenderWindowInteractor*); + void SetRenderer(vtkRenderer* render); + void SetInteractor(vtkRenderWindowInteractor* interactor); void SetImageData(vtkImageData* img); private slots: diff --git a/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.cxx b/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.cxx index b675aa6..0c431b4 100644 --- a/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.cxx +++ b/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.cxx @@ -18,8 +18,13 @@ QtSurfaceRendererPanel::QtSurfaceRendererPanel(QWidget *parent) : this->ui->pushButtonColorChooser->setIcon(QIcon(Color_xpm)); - this->ui->pushButtonSave->setIcon(QIcon(Save_xpm)); + //this->ui->pushButtonSave->setIcon(QIcon(Save_xpm)); this->ui->pushButtonOpen->setIcon(QIcon(OpenImage_xpm)); + + this->ui->comboBoxSave->addItem(QIcon(Save_xpm), QString("")); + this->ui->comboBoxSave->addItem(QString("Save surface")); + this->ui->comboBoxSave->addItem(QString("Export image stencil")); + _ImageSet = false; } QtSurfaceRendererPanel::~QtSurfaceRendererPanel() @@ -34,6 +39,7 @@ void QtSurfaceRendererPanel::setImageData(vtkImageData* img){ this->ui->horizontalSliderMaxIso->setRange(range[0], range[1]); wxMaracasSurfaceRenderingManager::setImageData(img); + _ImageSet = true; } void QtSurfaceRendererPanel::on_OpacitySlider_valueChanged(int value) @@ -77,8 +83,9 @@ void QtSurfaceRendererPanel::on_pushButtonColorChooser_clicked() void QtSurfaceRendererPanel::on_checkBox_clicked(bool checked) { - this->addRemoveActor(0, checked); - if(!checked){ + if(!this->addRemoveActor(0, checked)){ + this->ui->checkBox->setChecked(false); + }else if(!checked){ this->ui->checkBoxBoundingBox->setCheckState(Qt::Unchecked); this->on_checkBoxBoundingBox_clicked(false); } @@ -106,22 +113,23 @@ void QtSurfaceRendererPanel::on_horizontalSliderMinIso_sliderReleased() } void QtSurfaceRendererPanel::onIsoValueChanged(){ - this->changeIsoValue(0, this->ui->horizontalSliderMinIso->value(), this->ui->horizontalSliderMaxIso->value()); + if(_ImageSet) + this->changeIsoValue(0, this->ui->horizontalSliderMinIso->value(), this->ui->horizontalSliderMaxIso->value()); } -void QtSurfaceRendererPanel::on_pushButtonSave_clicked() +/*void QtSurfaceRendererPanel::on_pushButtonSave_clicked() { QString filename = QFileDialog::getSaveFileName(this, tr("Save Mesh File"), QDir::currentPath(), - tr("Mesh files (*.stl *.ply)") ); + tr("Mesh files (*.stl *.ply *.vtk)") ); if( !filename.isNull() ){ //filename.append(".stl"); this->saveProp3DSTL(0, filename.toStdString().c_str()); } -} +}*/ void QtSurfaceRendererPanel::on_checkBoxBoundingBox_clicked(bool checked) { @@ -136,9 +144,37 @@ void QtSurfaceRendererPanel::on_pushButtonOpen_clicked(bool checked) void QtSurfaceRendererPanel::on_pushButtonOpen_clicked() { - QString filename = QFileDialog::getOpenFileName(this, tr("Load Mesh File"), QDir::currentPath(), tr("Mesh files (*.stl *.ply)")); + QString filename = QFileDialog::getOpenFileName(this, tr("Load Mesh File"), QDir::currentPath(), tr("Mesh files (*.stl *.ply *.vtk)")); if(!filename.isNull()){ this->loadProp3DSTL(filename.toStdString().c_str()); + this->ui->checkBox->setCheckState(Qt::Checked); + } +} + +void QtSurfaceRendererPanel::on_comboBoxSave_activated(int index) +{ + if(index == 1){ + QString filename = QFileDialog::getSaveFileName(this, + tr("Save Mesh File"), + QDir::currentPath(), + tr("Mesh files (*.stl *.ply *.vtk)") ); + + if( !filename.isNull() ){ + //filename.append(".stl"); + this->saveProp3DSTL(0, filename.toStdString().c_str()); + } + }else if(index == 2){ + + QString filename = QFileDialog::getSaveFileName(this, + tr("Save Image File"), + QDir::currentPath(), + tr("Meta Image file (*.mhd)") ); + + if( !filename.isNull() ){ + + this->exportImageStencil(0, filename.toStdString().c_str()); + } } + this->ui->comboBoxSave->setCurrentIndex(0); } diff --git a/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.h b/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.h index d583d11..019c79d 100644 --- a/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.h +++ b/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.h @@ -35,7 +35,7 @@ private slots: void on_horizontalSliderMinIso_sliderReleased(); - void on_pushButtonSave_clicked(); + //void on_pushButtonSave_clicked(); void on_checkBoxBoundingBox_clicked(bool checked); @@ -44,11 +44,15 @@ private slots: void on_pushButtonOpen_clicked(); + void on_comboBoxSave_activated(int index); + private: Ui::QtSurfaceRendererPanel *ui; void onIsoValueChanged(); + + bool _ImageSet; }; #endif // QTSURFACERENDERERPANEL_H diff --git a/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.ui b/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.ui index 2af643b..2d64a86 100644 --- a/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.ui +++ b/lib/GUI/Qt/SurfaceRenderer/qtsurfacerendererpanel.ui @@ -6,15 +6,15 @@ 0 0 - 197 - 299 + 252 + 362 Form - + Show @@ -55,16 +55,21 @@ - + false - - + + Save current surface or export an image using stencil - - - ../../../../data/Icons/Save.xpm../../../../data/Icons/Save.xpm + + false + + + -1 + + + 2 @@ -225,8 +230,8 @@ 18 - 136 - 21 + 242 + 30 @@ -249,64 +254,64 @@ checkBox toggled(bool) - pushButtonSave + OpacitySlider setEnabled(bool) - 56 - 20 + 43 + 19 - 216 - 50 + 83 + 170 checkBox toggled(bool) - OpacitySlider + horizontalSliderMinIso setEnabled(bool) - 43 - 19 + 36 + 15 - 73 - 125 + 38 + 283 checkBox toggled(bool) - horizontalSliderMinIso + horizontalSliderMaxIso setEnabled(bool) - 36 - 15 + 42 + 22 - 28 - 367 + 102 + 351 checkBox toggled(bool) - horizontalSliderMaxIso + comboBoxSave setEnabled(bool) - 42 - 22 + 88 + 19 - 92 - 434 + 126 + 53 diff --git a/lib/GUI/Qt/Viewers/CMakeLists.txt b/lib/GUI/Qt/Viewers/CMakeLists.txt index 37ab67d..a03c68f 100644 --- a/lib/GUI/Qt/Viewers/CMakeLists.txt +++ b/lib/GUI/Qt/Viewers/CMakeLists.txt @@ -89,9 +89,9 @@ IF ( BUILD_${LIBRARY_NAME} ) ${QT_LIBRARIES} QVTK -#EED GUIQtVolumeRenderer -#EED GUIQtSurfaceRenderer -#EED KernelViewerWidgets + GUIQtVolumeRenderer + GUIQtSurfaceRenderer + KernelViewerWidgets # If this library must link against other libraries # USER! : Add here any extra Library you need diff --git a/lib/GUI/Qt/Viewers/qtvtkviewer.cpp b/lib/GUI/Qt/Viewers/qtvtkviewer.cpp index d4c0685..9320d60 100644 --- a/lib/GUI/Qt/Viewers/qtvtkviewer.cpp +++ b/lib/GUI/Qt/Viewers/qtvtkviewer.cpp @@ -7,7 +7,8 @@ QtVTKViewer::QtVTKViewer(QWidget* parent) { - this->GetRenderWindow()->AddRenderer(vtkRenderer::New()); + vtkRenderer* renderer = vtkRenderer::New(); + this->GetRenderWindow()->AddRenderer(renderer); this->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->SetBackground(1,1,1); SuperImagePlaneWidget::initialize(this->GetRenderWindow()->GetInteractor()); diff --git a/lib/GUI/Qt/Viewers/qtvtkviewerwidget.cxx b/lib/GUI/Qt/Viewers/qtvtkviewerwidget.cxx index 7229daa..1f10cdf 100644 --- a/lib/GUI/Qt/Viewers/qtvtkviewerwidget.cxx +++ b/lib/GUI/Qt/Viewers/qtvtkviewerwidget.cxx @@ -29,6 +29,7 @@ vtkRenderer* QtVTKViewerWidget::getRenderer(){ void QtVTKViewerWidget::setImage(vtkImageData* img){ + ui->checkBoxShowPlanes->setChecked(true); ui->_qtvtkviewer->setImage(img); ui->m_VolumeRender->SetImageData(img); ui->m_SurfaceRender->SetImageData(img); diff --git a/lib/GUI/Qt/Viewers/qtvtkviewerwidget.ui b/lib/GUI/Qt/Viewers/qtvtkviewerwidget.ui index d7d8ae4..6c5eeb9 100644 --- a/lib/GUI/Qt/Viewers/qtvtkviewerwidget.ui +++ b/lib/GUI/Qt/Viewers/qtvtkviewerwidget.ui @@ -37,13 +37,13 @@ Image Widget - + 0 20 201 - 246 + 260 @@ -56,7 +56,7 @@ Show Planes - true + false false @@ -246,9 +246,6 @@ 0 - toolBox - toolBox - toolBox diff --git a/lib/GUI/Qt/VolumeRenderer/qtvolumerendererpanel.cxx b/lib/GUI/Qt/VolumeRenderer/qtvolumerendererpanel.cxx index 779621c..ea51154 100644 --- a/lib/GUI/Qt/VolumeRenderer/qtvolumerendererpanel.cxx +++ b/lib/GUI/Qt/VolumeRenderer/qtvolumerendererpanel.cxx @@ -39,11 +39,15 @@ void QtVolumeRendererPanel::on_opacitySlider_valueChanged(int value) double* range = ImageData->GetScalarRange(); vector greylevel; - greylevel.push_back(0); - greylevel.push_back(1); + greylevel.push_back(0); //first grey level + //greylevel.push_back(1); + greylevel.push_back(10); + greylevel.push_back(20); greylevel.push_back(range[1]); vector vectvalue; + vectvalue.push_back(0); //first opacity value + //vectvalue.push_back(value/100.0); vectvalue.push_back(0); vectvalue.push_back(value/100.0); vectvalue.push_back(value/100.0); diff --git a/lib/GUI/Wx/SurfaceRenderer/wxMaracasSurfaceRendering.cxx b/lib/GUI/Wx/SurfaceRenderer/wxMaracasSurfaceRendering.cxx index 429734e..2c1c56c 100644 --- a/lib/GUI/Wx/SurfaceRenderer/wxMaracasSurfaceRendering.cxx +++ b/lib/GUI/Wx/SurfaceRenderer/wxMaracasSurfaceRendering.cxx @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: wxMaracasSurfaceRendering.cxx,v $ Language: C++ - Date: $Date: 2011/06/28 16:56:16 $ - Version: $Revision: 1.1 $ + Date: $Date: 2012/05/11 11:46:39 $ + Version: $Revision: 1.2 $ Copyright: (c) 2002, 2003 License: @@ -196,14 +196,22 @@ void wxMaracasSurfaceRendering::addPropMHD(vtkImageData* imgdata, std::string da } void wxMaracasSurfaceRendering::loadProp3D(wxString filename, wxString dataname){ - std::string s = std::string(filename.mb_str()); - vtkProp3D* prop3D = surrendmanager->getProp3D(s); + std::string fn = std::string(filename.mb_str()); + std::string dn = std::string(dataname.mb_str()); + + int id = surrendmanager->addProp3D(-1, fn, dn); + + if(id!=-1){ + wxMaracasSurfaceRenderingPanel* controlpan = new wxMaracasSurfaceRenderingProp3D(this, id, false, -1); + addSurfaceRenderingPanel(controlpan, dn); + } + /*vtkProp3D* prop3D = surrendmanager->getProp3D(s); if(prop3D != NULL){ s = std::string(dataname.mb_str() ); this->addProp3D(prop3D,s); }else{ //TODO msj to the user indicating error in file - } + }*/ } void wxMaracasSurfaceRendering::addProp3D(vtkProp3D* prop3D, std::string dataname){ diff --git a/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.cxx b/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.cxx new file mode 100644 index 0000000..ec92d05 --- /dev/null +++ b/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.cxx @@ -0,0 +1,70 @@ +#include "surfacerenderingimagestencilexport.h" + +#include "vtkObjectFactory.h" +#include "vtkMetaImageWriter.h" + +#include "math.h" + +vtkStandardNewMacro(SurfaceRenderingImageStencilExport) + +SurfaceRenderingImageStencilExport::SurfaceRenderingImageStencilExport() +{ + ImageOutput = 0; +} + +SurfaceRenderingImageStencilExport::~SurfaceRenderingImageStencilExport(){ + + if(ImageOutput){ + ImageOutput->Delete(); + } +} + +void SurfaceRenderingImageStencilExport::Update(){ + this->Execute(0); +} + +void SurfaceRenderingImageStencilExport::Execute(vtkImageData *data){ + + vtkPolyData* polydata = (vtkPolyData*)this->GetInput(); + + vtkSmartPointer polytostencil = vtkSmartPointer::New(); + polytostencil->SetInput(polydata); + polytostencil->Update(); + + double *bounds = polydata->GetBounds(); + vtkSmartPointer imagein = vtkSmartPointer::New(); + + imagein->SetExtent(bounds[0] - 1, bounds[1] + 1, bounds[2] - 1, bounds[3] + 1, bounds[4] - 1, bounds[5] + 1); + imagein->SetScalarTypeToUnsignedShort(); + imagein->AllocateScalars(); + + + int* extent = imagein->GetExtent(); + + for (int x = extent[0]; x <= extent[1]; x++){ + for (int y = extent[2]; y <= extent[3]; y++){ + for (int z =extent[4]; z <= extent[5]; z++){ + unsigned short* pixel = static_cast(imagein->GetScalarPointer(x,y,z)); + *pixel = 0; + } + } + } + + vtkSmartPointer stencil = vtkSmartPointer::New(); + stencil->SetInput(imagein); + stencil->SetStencil(polytostencil->GetOutput()); + stencil->ReverseStencilOn(); + stencil->SetBackgroundValue(128); + stencil->Update(); + + if(ImageOutput){ + ImageOutput->Delete(); + } + ImageOutput = vtkImageData::New(); + ImageOutput->DeepCopy(stencil->GetOutput()); + +} + +vtkImageData* SurfaceRenderingImageStencilExport::GetOutput(){ + return ImageOutput; +} diff --git a/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.h b/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.h new file mode 100644 index 0000000..fc63b39 --- /dev/null +++ b/lib/Kernel/VTKObjects/SurfaceRenderer/surfacerenderingimagestencilexport.h @@ -0,0 +1,32 @@ +#ifndef SURFACERENDERINGIMAGESTENCILEXPORT_H +#define SURFACERENDERINGIMAGESTENCILEXPORT_H + +#include +#include +#include +#include +#include +#include + +class SurfaceRenderingImageStencilExport : public vtkDataSetToImageFilter +{ +public: + static SurfaceRenderingImageStencilExport *New(); + + vtkTypeMacro(SurfaceRenderingImageStencilExport,vtkDataSetToImageFilter) + + virtual void Update(); + vtkImageData* GetOutput(); +protected: + + virtual void Execute(vtkImageData *data); + +private: + + SurfaceRenderingImageStencilExport(); + ~SurfaceRenderingImageStencilExport(); + + vtkImageData* ImageOutput; +}; + +#endif // SURFACERENDERINGIMAGESTENCILEXPORT_H diff --git a/lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerData.cxx b/lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerData.cxx index 510ec5c..1faca33 100644 --- a/lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerData.cxx +++ b/lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerData.cxx @@ -4,6 +4,12 @@ #include #include "vtkSTLWriter.h" #include "vtkPLYWriter.h" +#include "vtkPolyDataWriter.h" +#include "surfacerenderingimagestencilexport.h" +#include "vtkMetaImageWriter.h" +#include "vtkPolyDataReader.h" +#include "vtkPLYReader.h" +#include "vtkSmartPointer.h" /******************************************************************************************** ** Start of data viewmanagerData @@ -27,6 +33,49 @@ wxMaracasSurfaceRenderingManagerData::wxMaracasSurfaceRenderingManagerData(vtkPr _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(3) );*/ } +wxMaracasSurfaceRenderingManagerData::wxMaracasSurfaceRenderingManagerData(string filename, vtkRenderWindowInteractor* interactor){ + + _prop3D = getProp3D(filename); + _dataname = filename; + _boxWidgetS1=NULL; + + initializeBoxWidget(interactor); +} + +vtkProp3D* wxMaracasSurfaceRenderingManagerData::getProp3D(std::string filename){ + + if(filename.compare("")!= 0){ + + vtkSmartPointer polydata = vtkSmartPointer::New(); + std::string ext = filename.substr(filename.find_last_of("."), 4); + if(ext.compare(STL)==0){ + vtkSmartPointer STLReader=vtkSmartPointer::New(); + STLReader->SetFileName(filename.c_str()); + STLReader->Update(); + polydata->DeepCopy(STLReader->GetOutput()); + + }else if(ext.compare(PLY)==0){ + vtkSmartPointer plyreader =vtkSmartPointer::New(); + plyreader->SetFileName(filename.c_str()); + plyreader->Update(); + polydata->DeepCopy(plyreader->GetOutput()); + }else if(ext.compare(VTK)==0){ + vtkSmartPointer polyreader =vtkSmartPointer::New(); + polyreader->SetFileName(filename.c_str()); + polyreader->Update(); + polydata->DeepCopy(polyreader->GetOutput()); + } + + _dataMapper = vtkPolyDataMapper::New(); + _dataMapper->SetInput(polydata); + + vtkActor* dataActor = vtkActor::New(); + dataActor->SetMapper(_dataMapper); + dataActor->GetProperty()->SetOpacity(1); + return dataActor; + } + return NULL; +} wxMaracasSurfaceRenderingManagerData::~wxMaracasSurfaceRenderingManagerData(){ @@ -124,13 +173,20 @@ void wxMaracasSurfaceRenderingManagerData::saveProp3DSTL(const char* filename){ plywriter->SetFileName(filename); plywriter->SetInput(_dataMapper->GetInput()); plywriter->Write(); - }else if(ext.compare(PLY) == 0){ + }else if(ext.compare(STL) == 0){ vtkSmartPointer stlWriter = vtkSmartPointer::New(); stlWriter->SetFileName(filename); stlWriter->SetInput(_dataMapper->GetInput()); stlWriter->SetFileTypeToBinary(); stlWriter->Write(); + }else if(ext.compare(VTK) == 0){ + vtkSmartPointer polydataWriter = + vtkSmartPointer::New(); + polydataWriter->SetFileName(filename); + polydataWriter->SetInput(_dataMapper->GetInput()); + polydataWriter->SetFileTypeToBinary(); + polydataWriter->Write(); }else{ cout<<"unsupported format"< stencilexport = vtkSmartPointer< SurfaceRenderingImageStencilExport >::New(); + stencilexport->SetInput( _dataMapper->GetInput()); + stencilexport->Update(); + vtkImageData* imgstencil = stencilexport->GetOutput(); + + vtkSmartPointer metawriter = vtkSmartPointer::New(); + metawriter->SetFileName(filename); + metawriter->SetInput(imgstencil); + metawriter->Write(); + }else{ + cout<<"No poly data set to data mapper."<SetInput(this->_imagedata); + _tresholdFilter->SetInValue(255); + _tresholdFilter->SetOutValue(0); + + _cubesFilter = vtkMarchingCubes::New(); - _cubesFilter->SetInput(this->_imagedata); - _cubesFilter->ComputeGradientsOn (); - _cubesFilter->ComputeScalarsOn (); - _cubesFilter->SetNumberOfContours( 1 ); + _cubesFilter->SetInput(_tresholdFilter->GetOutput()); + //_cubesFilter->ComputeGradientsOn(); + _cubesFilter->ComputeScalarsOn(); + _cubesFilter->ComputeNormalsOn(); + _cubesFilter->SetNumberOfContours( 1 ); _cleanFilter = vtkCleanPolyData::New(); _cleanFilter->SetInput ( _cubesFilter->GetOutput() ); + _smooth = vtkSmoothPolyDataFilter::New(); + _smooth->SetInput(_cleanFilter->GetOutput()); + _smooth->SetNumberOfIterations(6); + _smooth->SetRelaxationFactor(0.3); + //_smooth->FeatureEdgeSmoothingOff(); + _dataMapper = vtkPolyDataMapper::New( ); _dataMapper->ScalarVisibilityOff( ); _dataMapper->ImmediateModeRenderingOn(); @@ -38,8 +51,8 @@ wxMaracasSurfaceRenderingManagerDataMhd::wxMaracasSurfaceRenderingManagerDataMhd boxSurfaceObserver* observer = boxSurfaceObserver::New(); vtkStripper* striper = vtkStripper::New(); - striper->SetInput( _cleanFilter->GetOutput() ); - //striper->SetInput( _cubesFilter->GetOutput() ); + striper->SetInput( _smooth->GetOutput() ); + //striper->SetInput( _cleanFilter->GetOutput() ); striper->Update(); _boxWidgetS1->SetInput(striper->GetOutput()); @@ -69,13 +82,17 @@ wxMaracasSurfaceRenderingManagerDataMhd::wxMaracasSurfaceRenderingManagerDataMhd _boxWidgetS1->HandlesOn (); _boxWidgetS1->EnabledOff(); }else{ - _dataMapper->SetInput(_cleanFilter->GetOutput()); + //_dataMapper->SetInput(_cleanFilter->GetOutput()); + _dataMapper->SetInput(_smooth->GetOutput()); } dataActor->SetMapper(_dataMapper); - this->_prop3D = dataActor; + float cr=1,cg=0.5,cb=0.5; + dataActor->GetProperty()->SetDiffuseColor(1,0.5,0.5 ); + dataActor->GetProperty()->SetSpecular(.3); + dataActor->GetProperty()->SetSpecularPower(20); - + this->_prop3D = dataActor; this->changeIsoValue(this->_maxgreylevel); @@ -116,7 +133,10 @@ void wxMaracasSurfaceRenderingManagerDataMhd::UpdateSurface() void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double value){ - _cubesFilter->SetValue(0,value); + _tresholdFilter->ThresholdByLower(value); + _tresholdFilter->Update(); + + _cubesFilter->SetValue(0,255); _cubesFilter->Update(); _cleanFilter->Update(); _dataMapper->Update(); @@ -129,8 +149,9 @@ void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double value){ **/ void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double min, double max){ - - _cubesFilter->SetValue(min,max); + _tresholdFilter->ThresholdBetween(min, max); + _tresholdFilter->Update(); + _cubesFilter->SetValue(0,255); _cubesFilter->Update(); _cleanFilter->Update(); _dataMapper->Update(); diff --git a/lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerDataMhd.h b/lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerDataMhd.h index 44320db..de2165d 100644 --- a/lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerDataMhd.h +++ b/lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerDataMhd.h @@ -11,6 +11,8 @@ #include "vtkImageData.h" #include "vtkClipPolyData.h" #include "vtkPlanes.h" +#include "vtkImageThreshold.h" +#include "vtkSmoothPolyDataFilter.h" class wxMaracasSurfaceRenderingManagerDataMhd : public wxMaracasSurfaceRenderingManagerData { @@ -67,6 +69,8 @@ private: vtkCleanPolyData* _cleanFilter; vtkClipPolyData* _tissueClipper; vtkPlanes* _tissuePlanes; + vtkImageThreshold * _tresholdFilter; + vtkSmoothPolyDataFilter* _smooth; /** ** Get's the max grey level of the image diff --git a/lib/Kernel/VTKObjects/VolumeRenderer/volumerenderermanagerdata.cxx b/lib/Kernel/VTKObjects/VolumeRenderer/volumerenderermanagerdata.cxx index 21047fa..ba51a3c 100644 --- a/lib/Kernel/VTKObjects/VolumeRenderer/volumerenderermanagerdata.cxx +++ b/lib/Kernel/VTKObjects/VolumeRenderer/volumerenderermanagerdata.cxx @@ -47,9 +47,12 @@ void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string datana _volumeProperty = vtkVolumeProperty::New(); _volumeProperty->SetInterpolationTypeToLinear(); - //_volumeProperty->ShadeOn(); - _volumeProperty->DisableGradientOpacityOn(); - _tfun = vtkPiecewiseFunction::New(); + _volumeProperty->ShadeOn(); + _volumeProperty->SetAmbient(3); + _volumeProperty->SetDiffuse(0.2); + _volumeProperty->SetSpecular(0.5); + //_volumeProperty->DisableGradientOpacityOn(); + _tfun = vtkPiecewiseFunction::New(); _volumeProperty->SetScalarOpacity(_tfun ); _ctfun = vtkColorTransferFunction::New(); @@ -147,10 +150,10 @@ VolumeRendererManagerData::~VolumeRendererManagerData() } void VolumeRendererManagerData::SetIndependentComponents(bool independent){ - if(!independent){ - _volumeProperty->IndependentComponentsOff(); - }else{ + if(independent){ _volumeProperty->IndependentComponentsOn(); + }else{ + _volumeProperty->IndependentComponentsOff(); } } diff --git a/lib/maracasVisuLib/CMakeLists.txt b/lib/maracasVisuLib/CMakeLists.txt index 9ffe586..8943f40 100644 --- a/lib/maracasVisuLib/CMakeLists.txt +++ b/lib/maracasVisuLib/CMakeLists.txt @@ -182,12 +182,13 @@ FILE(GLOB ${LIBRARY_NAME}_HEADERS_CUTMODULE src/CutModule/interface/*.h src/CutM SET(${LIBRARY_NAME}_INSTALL_FOLDER ${LIBRARY_NAME}) SET(${LIBRARY_NAME}_LIBRARIES - ${LIBRARY_NAME} + BaseVolumeRenderer BaseSurfaceRenderer KernelVolumeRenderer KernelViewerWidgets KernelSurfaceRenderer + ${LIBRARY_NAME} ) # SET(${LIBRARY_NAME}_LIBRARIES ${LIBRARY_NAME} diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.h index 55694ac..4f10303 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.h @@ -3,9 +3,14 @@ #include "BrushFilter.h" #include "FillFilter.h" + +//#include "regionStructUR.h" +//#include "imageUndoRedo.h" + #include "imageModificationManager.h" #include "imageUndoRedo.h" + class ManualPaintModel { public: ManualPaintModel(); diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/baseFilterManualPaint.h b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/baseFilterManualPaint.h index f2406be..3725be5 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/baseFilterManualPaint.h +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/baseFilterManualPaint.h @@ -2,8 +2,12 @@ #define _BASE_FILTER_MANUAL_PAINT_H_ #include + +//#include "regionStructUR.h" + #include "imageModificationManager.h" + class baseFilterManualPaint { public: