#include "bbUtilitiesDrawAxis.h" #include "bbUtilitiesPackage.h" namespace bbUtilities { BBTK_ADD_BLACK_BOX_TO_PACKAGE(Utilities,DrawAxis) BBTK_BLACK_BOX_IMPLEMENTATION(DrawAxis,bbtk::AtomicBlackBox); void DrawAxis::Process() { vtkRenderer *render = bbGetInputInRenderer(); vtkImageData* img= bbGetInputImage(); std::string fileAxisPoints= bbGetInputFileNameAxisPoints(); std::string filePoints = bbGetInputFileNamePoints(); std::vector color = bbGetInputColor(); std::vector< double > pointx; std::vector< double > pointy; std::vector< double > pointz; std::string line; std::ifstream file; int radio=1; file.open( filePoints.c_str() ); if(file.is_open()) { int i=0; while(!file.eof() && i<5) { std::getline(file,line); //OJO LOS TEORICOS ESTAN SEPARADOS POR ; int pos=line.find(" "); int pos2=line.find_last_of(" "); int size=line.size(); std::string xs=line.substr(0,pos); std::string ys=line.substr(pos+1,pos2); std::string zs=line.substr(pos2+1,size); double x0=atof(xs.c_str()); double y0=atof(ys.c_str()); double z0=atof(zs.c_str()); vtkSphereSource* sphere = vtkSphereSource::New(); sphere->SetCenter(x0,y0,z0); sphere->SetRadius(radio); vtkPolyDataMapper* spheremapper = vtkPolyDataMapper::New(); spheremapper->SetInput(sphere->GetOutput()); spheremapper->Update(); vtkActor* sphereactor = vtkActor::New(); sphereactor->SetMapper(spheremapper); if(i==0) sphereactor->GetProperty()->SetColor(1.0,1.0,1.0); if( i==1 ) sphereactor->GetProperty()->SetColor(i,0.0,0.0); if(i==2) sphereactor->GetProperty()->SetColor(0.0,i,0.0); if(i==3 ) sphereactor->GetProperty()->SetColor(0.0,0.0,i); //borrame else sphereactor->GetProperty()->SetColor(1.0,1.0,0.0); render->AddActor(sphereactor); i++; } } file.close(); std::vector< double > vectx ; std::vector< double > vecty ; std::vector< double > vectz ; std::ifstream file1; double* spc = img->GetSpacing(); file1.open( fileAxisPoints.c_str() ); if(file1.is_open()) { while(!file1.eof()) { std::getline(file1,line); int pos=line.find(" "); int pos2=line.find_last_of(" "); int size=line.size(); std::string xs=line.substr(0,pos); std::string ys=line.substr(pos+1,pos2); std::string zs=line.substr(pos2+1,size); double x0=atof(xs.c_str()); double y0=atof(ys.c_str()); double z0=atof(zs.c_str()); vectx.push_back(x0); vecty.push_back(y0); vectz.push_back(z0); } } file1.close(); //----------------------------------------------------------------------------- unsigned int i; if(!vectx.empty()&&!vecty.empty()&&!vectz.empty()&& img != NULL){ vtkPoints* allPoints = vtkPoints::New( ); vtkCellArray* allTopology = vtkCellArray::New( ); allTopology->InsertNextCell( vectx.size( ) ); for( i = 0; i < vectx.size( ); i++) { allPoints->InsertNextPoint( vectx[i], vecty[i], vectz[i] ); allTopology->InsertCellPoint( i ); } // rof vtkPolyData *_allData = vtkPolyData::New( ); _allData->SetPoints( allPoints ); _allData->SetLines( allTopology ); allPoints->Delete(); allTopology->Delete(); vtkPolyDataMapper* polydatamapper = vtkPolyDataMapper::New(); vtkActor* vtkactor = vtkActor::New(); polydatamapper->SetInput(_allData); vtkactor->SetMapper(polydatamapper); vtkactor->GetProperty()->SetColor(color[0],color[1],color[2]); vtkactor->GetProperty()->SetLineWidth(2.2); render->AddActor(vtkactor); } } void DrawAxis::bbUserSetDefaultValues() { } void DrawAxis::bbUserInitializeProcessing() { } void DrawAxis::bbUserFinalizeProcessing() { } } // EO namespace bbUtilities