typedef std::vector< AirwaysTree > AirwaysVector;
+#include <itkCastImageFilter.h>
+
// Auxiliar struct to save info for execution.
typedef void* TImagePointer;
struct TreeInfo{
- TImagePointer image;
+
+ TreeInfo( )
+ {
+ this->myWorkspace = new cpPlugins::Workspace( );
+ }
+ ~TreeInfo( )
+ {
+ /*
+ if( this->IsMyWorkspace )
+ delete this->myWorkspace;
+ */
+ }
+
+ void CastImage( )
+ {
+ auto image = this->myWorkspace->GetFilter( "reader" )->GetOutputData( "Output" )->GetITK< itk::Image< unsigned char, 3 > >( );
+ typedef itk::CastImageFilter< itk::Image< unsigned char, 3 >, TInputImage > _TCast;
+ _TCast::Pointer cast = _TCast::New( );
+ cast->SetInput( image );
+ cast->Update( );
+ this->Image = cast->GetOutput( );
+ this->Image->DisconnectPipeline( );
+ }
+
+ TInputImage::Pointer Image;
+ cpPlugins::Workspace* myWorkspace;
+ bool IsMyWorkspace;
Vec3 seed;
std::string folderpath_pigResults;
std::string pig_name;
unsigned char cyan[3]= { 0, 255, 255 };
cpPlugins::Interface myPlugins;
-cpPlugins::Workspace myWorkspace;
// -------------------------------------------------------------------------
-void Load_cpPlugins( const std::string& plugins, const std::string& ws );
+void Load_cpPlugins( const std::string& plugins );
void CreateResultDirectory(AirwaysTree tree);
void DrawVTKLinesFromTree(AirwaysTree& tree, const std::string filename, bool common);
-AirwaysTree& CreateAirwaysTreeFromSegmentation(Vec3 seed, TImagePointer input_image);
+AirwaysTree& CreateAirwaysTreeFromSegmentation(Vec3 seed, TInputImage* input_image, cpPlugins::Workspace& ws );
vector<TreeInfo> ReadInputFile(const char* filename);
void printCommonTreeBetweenTwoTrees(AirwaysTree tree_A, AirwaysTree tree_B, std::vector< std::pair< std::pair<Node*, Node*>, std::pair<Node*, Node*> > > vector_pair_edges_A_to_B, unsigned int Q, unsigned int F);
void printMatchingResultToFile(AirwaysTree tree_A, AirwaysTree tree_B, std::map< unsigned int, std::vector<Node*> > map_A_to_B, std::map< unsigned int, std::vector<Node*> > map_B_to_A, unsigned int Q, unsigned int F);
// -------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
+ Load_cpPlugins( "./plugins.cfg" );
+
try
{
// Define and parse the program options
{
for(unsigned int i = 0; i < treeInfoVector.size(); ++ i){
TreeInfo info = treeInfoVector[i];
- AirwaysTree tree = CreateAirwaysTreeFromSegmentation(info.seed, info.image);
+ std::string err = info.myWorkspace->Execute( "eb" );
+ if( err != "" )
+ {
+ std::cerr << "Error: " << err << std::endl;
+ std::exit( 1 );
+
+ } // fi
+ info.CastImage( );
+ AirwaysTree tree = CreateAirwaysTreeFromSegmentation( info.seed, info.Image, *(info.myWorkspace ));
tree.SetResultPath(info.folderpath_pigResults);
tree.SetImageName(info.image_name);
aVector.push_back(tree);
}
// -------------------------------------------------------------------------
-void Load_cpPlugins( const std::string& plugins, const std::string& ws )
+void Load_cpPlugins( const std::string& plugins )
{
myPlugins.LoadConfiguration( plugins );
- myWorkspace.SetInterface( &myPlugins );
- std::string err = myWorkspace.LoadWorkspace( ws );
- if( err != "" )
- {
- std::cerr << "Error: " << err << std::endl;
- std::exit( 1 );
-
- } // fi
}
// -------------------------------------------------------------------------
return new Node(alfPoint);
}
-AirwaysTree& ConvertFilterToAirwaysTree( )
+AirwaysTree& ConvertFilterToAirwaysTree( TInputImage* input_image, cpPlugins::Workspace& ws )
{
/*
typedef FilterType TFilter;
std::time(&start);
std::cout << "Starting conversion " << std::endl;
- auto w_filter = myWorkspace.GetFilter( "eb" );
+ auto w_filter = ws.GetFilter( "eb" );
auto branches = w_filter->GetOutputData( "Skeleton" )->GetITK< TFASkeleton >( );
auto& endpoints = w_filter->GetOutputData( "EndPoints" )->GetITK< TVerticesFA >( )->Get( );
auto& bifurcations = w_filter->GetOutputData( "Bifurcations" )->GetITK< TVerticesFA >( )->Get( );
- auto image = myWorkspace.GetFilter( "reader" )->GetOutputData( "Output" )->GetITK< itk::ImageBase< 3 > >( );
- auto distance_map = myWorkspace.GetFilter( "dmap" )->GetOutputData( "Output" )->GetITK< itk::Image< float, 3 > >( );
+ auto image = ws.GetFilter( "reader" )->GetOutputData( "Output" )->GetITK< itk::ImageBase< 3 > >( );
+ auto distance_map = ws.GetFilter( "dmap" )->GetOutputData( "Output" )->GetITK< itk::Image< float, 3 > >( );
/*
TBranchesFA* branches = filter->GetBranches( );
int leoTreeWeigth = endpoints.size()+bifurcations.size()+1;
std::cout<< "Creates FA Tree with : "<<leoTreeWeigth << " nodes "<<std::endl;
- auto seed0 = myWorkspace.GetFilter( "seed" )->GetOutputData( "Output" )->GetITK< TVerticesFA >( )->Get( )[ 0 ];
+ auto seed0 = ws.GetFilter( "seed" )->GetOutputData( "Output" )->GetITK< TVerticesFA >( )->Get( )[ 0 ];
//Fill vertex map. Gotta do it with bifurcations, endpoints and the root.
//Do the root
vertexMap[ seed0 ] = FAVertexToNode( seed0, image );
auto eIt = endpoints.begin();
for( ; eIt != endpoints.end(); ++eIt )
{
- vertexMap[*eIt]=FAVertexToNode( *eIt,image );
+ vertexMap[*eIt]=FAVertexToNode( *eIt, image );
}
auto biIt = bifurcations.begin();
destination->SetFather(source);
source->AddChild(destination);
TEdgeAirways* edge = new Edge();
- edge->SetSource(source);
- edge->SetTarget(destination);
//Update path info for the edge. This is why we don't need to call UpdateEdges on the constructor of the tree.
auto edgePath = brIt->second->GetVertexList( );
for( unsigned int pIt = 0; pIt < edgePath->Size( ); ++pIt )
{
- auto cidx = edgePath->GetElement(pIt);
itk::ImageBase< 3 >::PointType pnt;
+ auto cidx = edgePath->GetElement( pIt );
image->TransformContinuousIndexToPhysicalPoint(cidx,pnt);
TVertexFA idx;
image->TransformPhysicalPointToIndex(pnt,idx);
pair_posVox_rad skPair(coords,distance_map->GetPixel(idx));
edge->AddSkeletonPairInfo(skPair);
}
- destination->SetEdge(edge);
}
}
- AirwaysTree* tree = new AirwaysTree(dynamic_cast< TInputImage* >( image ), NULL, vertexMap[seed0], false);
+ AirwaysTree* tree = new AirwaysTree( input_image, NULL, vertexMap[seed0], false);
std::time(&end);
+ std::cout << input_image << std::endl;
std::cout << "Finished conversion. New AlfTree has weight: "<<tree->GetWeight()<<". Takes "<<(end-start)<<" s." << std::endl;
return *tree;
}
// -------------------------------------------------------------------------
-AirwaysTree& CreateAirwaysTreeFromSegmentation(Vec3 seed, TImagePointer input_image)
+AirwaysTree& CreateAirwaysTreeFromSegmentation(Vec3 seed, TInputImage* input_image, cpPlugins::Workspace& ws )
{
- std::string err = myWorkspace.Execute( "eb" );
- if( err != "" )
- {
- std::cerr << "Error: " << err << std::endl;
- std::exit( 1 );
-
- } // fi
- return( ConvertFilterToAirwaysTree( ) );
+ return( ConvertFilterToAirwaysTree( input_image, ws ) );
}
// -------------------------------------------------------------------------
/*
treeInfo.image = ReadImage<TInputImage>(filepath_airwayImage);
*/
- Load_cpPlugins( "./plugins.cfg", "./workspace_airwaysappli.wxml" );
-
// Execute first pipeline's part
std::stringstream seed_stream;
seed_stream
<< point_trachea[0] << " "
<< point_trachea[1] << " "
<< point_trachea[2];
- myWorkspace.SetParameter( "FileNames@reader", filepath_airwayImage );
- myWorkspace.SetParameter( "Text@seed", seed_stream.str( ) );
+
+ treeInfo.myWorkspace->SetInterface( &myPlugins );
+ std::string err = treeInfo.myWorkspace->LoadWorkspace( "./workspace_airwaysappli.wxml" );
+ if( err != "" )
+ {
+ std::cerr << "Error: " << err << std::endl;
+ std::exit( 1 );
+
+ } // fi
+ treeInfo.myWorkspace->SetParameter( "FileNames@reader", filepath_airwayImage );
+ treeInfo.myWorkspace->SetParameter( "Text@seed", seed_stream.str( ) );
vectorInfo.push_back(treeInfo);
} //else