]> Creatis software - creaMaracasVisu.git/blobdiff - bbtk/src/bbmaracasvisuContourToControlPoints.cxx
The bbtk folder with the maracasvisu bbtk package was added to the creaMaracasVisu...
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuContourToControlPoints.cxx
diff --git a/bbtk/src/bbmaracasvisuContourToControlPoints.cxx b/bbtk/src/bbmaracasvisuContourToControlPoints.cxx
new file mode 100644 (file)
index 0000000..4691558
--- /dev/null
@@ -0,0 +1,150 @@
+#ifdef _USE_VTK_
+#ifdef _USE_ITK_
+
+#include "bbmaracasvisuContourToControlPoints.h"
+#include "bbmaracasvisuPackage.h"
+namespace bbmaracasvisu
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(maracasvisu,ContourToControlPoints)
+//BBTK_USER_BLACK_BOX_IMPLEMENTATION(ContourToControlPoints,bbtk::AtomicBlackBox);
+BBTK_BLACK_BOX_IMPLEMENTATION(ContourToControlPoints,bbtk::AtomicBlackBox);
+
+//------------------------------------------------------------
+void ContourToControlPoints::Process()
+{
+               if ( bbGetInputSampling() >= 3.0 )
+               {
+                       OutContourX.clear();
+                       OutContourY.clear();
+                       OutContourZ.clear();
+                       _ext2D->SetContour( bbGetInputInContourX(),bbGetInputInContourY(),bbGetInputInContourZ() );
+                       _ext2D->SetSamplingControlPoints( bbGetInputSampling() );
+                       _ext2D->GetSamplingControlPoints( &OutContourX,&OutContourY,&OutContourZ );
+               }
+               if(bbGetInputSampling() == 2.0)
+               {
+                       OutContourX.clear();
+                       OutContourY.clear();
+                       OutContourZ.clear();
+                       _ext2D->SetContour( bbGetInputInContourX(),bbGetInputInContourY(),bbGetInputInContourZ() );
+                       _ext2D->GetControlPoints( &OutContourX,&OutContourY,&OutContourZ );
+               }
+               
+               //Liberates the memory from the VTK's objects. Always must do that!!    
+               if ( bbGetInputLoadContour()== 1 )
+               {
+                       if (_imagedata!=NULL)
+                       {
+                               _imagedata->Delete();
+                       }
+                       KeyContourX.clear();
+                       KeyContourY.clear();
+                       KeyContourZ.clear();
+                       KeySizes.clear();
+                       FILE* fd;
+                       fd = fopen("C:/bbtk_JS/data/SavedContours.txt","r"); 
+                       _propgdata->ReadKeyContour( fd );
+                       fclose(fd);
+                       _propgdata->GetKeyContours(&KeyContourX,&KeyContourY,&KeyContourZ,&KeySizes);
+                       if(KeySizes.size() == 1)
+                       {
+                               //Method for 2D
+                       //      _imagedata = _propgdata->method_RBF(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
+                       }
+                       if(KeySizes.size() >= 2)
+                       {
+                               //Method for 3D
+                               //_imagedata = _propgdata->method_RBF_3D(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
+                       //      _imagedata = _propgdata->method_RBF_3D_ThinPlate(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
+                       }
+               }
+               if ( bbGetInputLoadContour()== 2 )
+               {
+                       if (_imagedata!=NULL)
+                       {
+                               _imagedata->Delete();
+                       }
+                       FILE* fd;
+                       fd = fopen("C:/bbtk_JS/data/SavedManualPoints.txt","r"); 
+                       _propgdata->ReadKeyContour( fd );
+                       fclose(fd);
+                       _propgdata->GetKeyContours(&KeyContourX,&KeyContourY,&KeyContourZ,&KeySizes);
+                       if(KeySizes.size() == 1)
+                       {
+                               //Method for 2D
+                       //      _imagedata = _propgdata->method_RBF(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
+                       }
+                       if(KeySizes.size() >= 2)
+                       {
+                               //Method for 3D
+                               //_imagedata = _propgdata->method_RBF_3D(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
+                       //      _imagedata = _propgdata->method_RBF_3D_ThinPlate(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
+                       }
+               }
+
+               if ( bbGetInputLoadContour()== 3 )
+               {
+                       if (_imagedata!=NULL)
+                       {
+                               _imagedata->Delete();
+                       }
+                       vtkImageData *itemp = vtkImageData::New();
+                       _contprop->appendContour();
+                       _contprop->setInterpolationNumber(300);
+                       itemp = _contprop->GetKeyContours(&KeyContourX,&KeyContourY,&KeyContourZ,&KeySizes);
+                       if(KeySizes.size() == 1)
+                       {
+                       }
+                       if(KeySizes.size() >= 2)
+                       {
+                               //Method for 3D
+                               _imagedata = itemp;
+                               _contprop->resetAppend();
+                               _contprop->appendContour(&KeyContourX,&KeyContourY,&KeyContourZ);
+                               //_contprop->GetContour(bbGetInputSlice(),&OutContourX,&OutContourY,&OutContourZ);
+                               _contprop->GetControlPoints(bbGetInputSlice(),&OutContourX,&OutContourY,&OutContourZ);
+                               printf("\n Size OutContourX = %d",OutContourX.size());
+                       }
+               }
+
+               bbSetOutputControlPointX( &OutContourX );
+               bbSetOutputControlPointY( &OutContourY );
+               bbSetOutputControlPointZ( &OutContourZ );
+               bbSetOutputImagePropg( _imagedata );
+}
+//------------------------------------------------------------
+void ContourToControlPoints::bbUserConstructor()
+{
+               bbSetInputSampling(5.0);
+               bbSetInputSlice(0);
+               bbSetInputInContourX(NULL);
+               bbSetInputInContourY(NULL);
+               bbSetInputInContourZ(NULL);
+               bbSetInputRadRBF(1000.0);
+               bbSetInputOption(1);
+               bbSetInputLoadContour(0);
+
+               _contprop       = new ContourPropagation();
+               _propgdata      = new PropContour();
+               _imagedata      = vtkImageData::New();
+               _ext2D          = new ExtractControlPoints2D();
+               _fd = NULL;
+               pos = 0;
+               it = NULL;
+               bool inic = false;
+}
+//------------------------------------------------------------
+void ContourToControlPoints::bbUserCopyConstructor()
+{
+}
+//------------------------------------------------------------
+void ContourToControlPoints::bbUserDestructor()
+{
+}
+
+}
+// EO namespace bbmaracasvisu
+
+#endif //_USE_ITK_
+#endif //_USE_VTK_