+/*
+# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+# pour la Sante)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+# This software is governed by the CeCILL-B license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/ or redistribute the software under the terms of the CeCILL-B
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+# or in the file LICENSE.txt.
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------
+*/
+
+#include "cutImageSegmentation.h"
+
+cutImageSegmentation::cutImageSegmentation()
+{
+}
+
+cutImageSegmentation::~cutImageSegmentation()
+{
+}
+
+void cutImageSegmentation::SetAnglesImage( vtkImageData* image )
+{
+ this->m_Image = image;
+}
+
+void cutImageSegmentation::SetMesh1(vtkPolyData* mesh)
+{
+ this->m_Mesh1 = mesh;
+}
+
+vtkImageData*
+cutImageSegmentation::GetResultImage()
+{
+ return m_ResultImage;
+}
+
+void cutImageSegmentation::InitValues()
+{
+
+
+}
+
+void cutImageSegmentation::Process()
+{
+ std::cout << "MLER cutImageSegmentation :: Process Start()" << std::endl;
+
+ if(m_Mesh1 != NULL)
+ {
+
+ vtkLinearExtrusionFilter *extrude = vtkLinearExtrusionFilter::New();
+ vtkPolyDataToImageStencil *dataToStencil = vtkPolyDataToImageStencil::New();
+ vtkImageStencil *imageStencil = vtkImageStencil::New();
+ //vtkExtractVOI *extract = vtkExtractVOI::New();
+ vtkAppendPolyData *append = vtkAppendPolyData::New();
+ //vtkTriangleFilter *triangleFilter = vtkTriangleFilter::New();
+ vtkStripper *stripper = vtkStripper::New();
+ vtkTransformPolyDataFilter *transformFilter= vtkTransformPolyDataFilter::New();
+
+ double bounds[6];
+
+ //vtkPolyDataToImageStencil* stencil = vtkPolyDataToImageStencil::New();
+ /* Test # 1 Cod Python
+ extract->SetVOI( 0, 128, 0, 104, 0, 9);
+ extract->SetSampleRate(1, 1, 1);
+ extract->SetInput(m_Image);
+ extract->ReleaseDataFlagOff();
+
+
+ extrude->SetInput(m_Mesh1);
+ extrude->SetScaleFactor(1);
+ extrude->SetExtrusionTypeToNormalExtrusion();
+ extrude->SetVector(0,0,1);
+ //extrude->Update();
+
+ extrude->Print(std::cout);
+
+ std::cout << "MLER cutImageSegmentation ---> polygonal data --> image stencil:" << std::endl;
+
+ //dataToStencil->SetTolerance(0);
+ dataToStencil->SetInput(extrude->GetOutput());
+ //dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
+ //dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
+ //dataToStencil->Update();
+
+ dataToStencil->Print(std::cout);
+
+ imageStencil->SetInput(extract->GetOutput());
+ imageStencil->SetStencil(dataToStencil->GetOutput());
+
+ imageStencil->ReverseStencilOff();
+ imageStencil->SetBackgroundValue(128);
+ imageStencil->Update();
+
+ imageStencil->Print(std::cout);
+
+ m_ResultImage = imageStencil->GetOutput();
+ */
+
+ /*Test #2
+ stripper->SetInput(m_Mesh1);
+ transformFilter->SetInput(stripper->GetOutput());
+
+ dataToStencil->SetOutputOrigin(m_Image->GetOrigin());
+ dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
+ dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
+
+ dataToStencil->SetInput(transformFilter->GetOutput());
+
+ imageStencil->SetInput(m_Image);
+ imageStencil->SetStencil(dataToStencil->GetOutput());
+ imageStencil->Update();
+
+ m_ResultImage = imageStencil->GetOutput();
+ */
+
+ //Test 3
+ /*
+ m_Mesh1->GetBounds(bounds);
+
+ dataToStencil->SetInput(m_Mesh1);
+ dataToStencil->SetOutputOrigin(m_Image->GetOrigin());
+ dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
+ dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
+ dataToStencil->Update();
+
+ imageStencil->SetInput(m_Image);
+ imageStencil->SetStencil(dataToStencil->GetOutput());
+ imageStencil->ReverseStencilOff();
+ //imageStencil->SetBackgroundValue(100);
+ imageStencil->Update();
+ */
+
+ //Test 4
+ m_Mesh1->GetBounds(bounds);
+
+ std::cout << "bounds 0:" << bounds[0]<< std::endl;
+ std::cout << "bounds 1:" << bounds[1]<< std::endl;
+ std::cout << "bounds 2:" << bounds[2]<< std::endl;
+ std::cout << "bounds 3:" << bounds[3]<< std::endl;
+ std::cout << "bounds 4:" << bounds[4]<< std::endl;
+ std::cout << "bounds 5:" << bounds[5]<< std::endl;
+
+
+
+ double origin[3];
+ double *spacing = NULL;
+ spacing = m_Image->GetSpacing();
+
+ std::cout << "spacing 0:" << spacing[0]<< std::endl;
+ std::cout << "spacing 1:" << spacing[1]<< std::endl;
+ std::cout << "spacing 2:" << spacing[2]<< std::endl;
+
+ origin[0] = 63;//bounds[0];
+ origin[1] = 44;//bounds[2];
+ origin[2] = 4;//bounds[4];
+
+ std::cout << "origin;0:" << origin[0]<< std::endl;
+ std::cout << "origin 1:" << origin[1]<< std::endl;
+ std::cout << "origin 2:" << origin[2]<< std::endl;
+
+
+ m_Image->SetOrigin(origin);
+
+
+ extrude->SetInput(m_Mesh1);
+ extrude->SetScaleFactor(1);
+ extrude->SetExtrusionTypeToNormalExtrusion();
+ extrude->SetVector(0,0,1);
+ extrude->Update();
+
+ dataToStencil->SetTolerance(0);
+ dataToStencil->SetInput(extrude->GetOutput());
+ dataToStencil->SetOutputOrigin(origin);
+ dataToStencil->SetOutputSpacing(spacing);
+ dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
+ dataToStencil->Update();
+
+ imageStencil->SetInput(m_Image);
+ imageStencil->SetStencil(dataToStencil->GetOutput());
+ imageStencil->ReverseStencilOff();
+ imageStencil->SetBackgroundValue(0);
+ imageStencil->Update();
+
+ m_ResultImage = imageStencil->GetOutput();
+
+
+ }//i m_Mesh1 != Null
+ else{
+
+ std::cout << "MLER cutImageSegmentation :: NO HAY MESH" << std::endl;
+
+ }//else if m_Mesh1
+
+ std::cout << "MLER cutImageSegmentation :: Process End" << std::endl;
+
+}
+
+//---------------------------------------------
+//Method template
+//---------------------------------------------
+/*
+void cutImageSegmentation::FunctionName(int& parameterA)
+{
+ parameterA = 2 * parameterA;
+ return;
+}
+*/
+