]> Creatis software - creaMaracasVisu.git/blobdiff - lib/GUI/Base/SurfaceRenderer/wxMaracasSurfaceRenderingManager.cxx
addition of image stencil to surface rendering
[creaMaracasVisu.git] / lib / GUI / Base / SurfaceRenderer / wxMaracasSurfaceRenderingManager.cxx
index ac816f6241cfcf4f38b6a1d7198f8422a9b01877..d60ea625517b2252843e78d2e709c3a4c22ae205 100644 (file)
@@ -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:
      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<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::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<vtkPolyDataReader> polyreader =vtkSmartPointer<vtkPolyDataReader>::New();
+                polyreader->SetFileName(filename.c_str());
+                polyreader->Update();
+                polydata->DeepCopy(polyreader->GetOutput());
             }
 
             vtkSmartPointer<vtkPolyDataMapper> dataMapper = vtkSmartPointer<vtkPolyDataMapper>::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);
+    }
 }