#include "gLocalize.h" #include #include gLocalize::gLocalize(){ abortSignal=false; } void gLocalize::localize(vtkImageData* vol, int march_tresh, double thrDown_D, double thrUp_D, double thr_HAUSD, double thr_S, QList selectedFilters){ abortSignal=false; int i=0; int progress=0; //variabili vtkSmartPointer fixOutput = vtkSmartPointer::New(); vtkSmartPointer filter = vtkSmartPointer::New(); vtkSmartPointer marchingcubes = vtkSmartPointer::New() ; vtkSmartPointer smoother = vtkSmartPointer::New(); vtkSmartPointer fixed = vtkSmartPointer :: New(); marchingcubes->SetInput(vol); //The algorithm starts with a marching cube at a given intensity level threshold marchingcubes->SetValue(0,march_tresh); // Surface #0, iso-value=1 marchingcubes->SetComputeNormals(0); if (marchingcubes.GetPointer()->GetNumberOfInputConnections(0)==0) {return; //EMIT FAIL QUALCOSA //return -1; } marchingcubes->Update(); std::cout<< "inizio run" <GetNumberOfContours()); if(item.toInt()<=0){ throw("CRITICAL: No surfaces found with given treshold"); QList dummylist; // emit sendrenderMarkerList (dummylist); } // Smoothing filter and normals calculation on marching cubes output data smoother->SetInput(marchingcubes->GetOutput()); smoother->SetNumberOfIterations(20); smoother->NormalizeCoordinatesOn(); smoother->SetPassBand(0.01); smoother->BoundarySmoothingOn(); smoother->Update(); vtkSmartPointer normals=vtkSmartPointer::New(); normals->SetInput(smoother->GetOutput()); vtkSmartPointer normalact=vtkSmartPointer::New(); vtkSmartPointer normalmap=vtkSmartPointer::New(); normalmap->SetInput( normals->GetOutput()); normalact->SetMapper(normalmap); // Start of marker recognitioning procedure filter->AddInput(normals->GetOutput()); filter->SetExtractionModeToAllRegions(); filter->SetColorRegions(0); filter->Update(); QString regionnumber = regionnumber.number(filter->GetNumberOfExtractedRegions()); filter->SetExtractionModeToSpecifiedRegions(); filter->Update(); //Some data allocation: //surflist: list of surfaces where the recognized marker are added //tempsurf: one surface used as temporary variable during geometrical filtering QList surflist; surflist.clear(); surf tempsurf; //Double check on number of surface in ConnectivityFilter output if(regionnumber.toInt()==0){ std::cout<<"ok"< dummylist; // emit sendrenderMarkerList (dummylist); }; if(regionnumber.toInt()>3000){ cout<<"ho trovato troppe superfici: "<AddSpecifiedRegion(idouble); filter->Update(); // Filter on bounding box diagonal lenght if(selectedFilters.at(0)) if(ok==1) { tempsurf.lenght=filter->GetOutput()->GetLength(); if(tempsurf.lenghtthrUp_D ) ok=0; } //Hausdorf reads from tempsurf the bounding box center and use it as reference center if(selectedFilters.at(1)) if(ok==1) { OKd++; filter->GetOutput()->GetCenter(tempsurf.center); tempsurf.hausdorff=hausdorff(filter,tempsurf); if(tempsurf.hausdorff> (thr_HAUSD) ) ok=0; } // Filter based on sides difference if(selectedFilters.at(2)) if(ok==1) { OKh++; filter->GetOutput()->GetBounds(tempsurf.bounds); tempsurf.confronto_lati=lati(tempsurf.bounds); if(tempsurf.confronto_lati>thr_S) ok=0; } //if all filters are verified, add a surface index and append it to the surflist if(ok==1) { OKs++; tempsurf.sorting=idouble; //indexing surflist.append(tempsurf); } // MANDATORY filter cleaning filter->DeleteSpecifiedRegion(idouble); } cout<<"Nsurfaces"< final_list; surf tmp_p; if(surflist.count()!=0){ for(i=0;iAddSpecifiedRegion(surflist.at(i).sorting); filter->Update(); //Centroid calculation needs mesh vertex vtkSmartPointer edge_extractor =vtkSmartPointer::New(); edge_extractor->RemoveAllInputs(); edge_extractor->SetInput(filter->GetOutput()); edge_extractor->Update(); vtkSmartPointer tmp = vtkSmartPointer::New(); tmp=edge_extractor->GetOutput(); tmp->Update(); tmp->BuildCells(); tmp->BuildLinks(); QList punti; point ptemp; for (int id=0;id< (int) tmp->GetNumberOfPoints();id++){ ptemp.x=tmp->GetPoint(id)[0]; ptemp.y=tmp->GetPoint(id)[1]; ptemp.z=tmp->GetPoint(id)[2]; /*cout<GetOutput()->GetPoint(id)[0]<<" "<GetOutput()->GetPoint(id)[1]<<" "<GetOutput()->GetPoint(id)[2]<DeleteSpecifiedRegion(surflist.at(i).sorting); final_list.append(tmp_p); }; }; for(int ii=0;ii punti) { int i; point centroide; centroide.x=0,centroide.y=0,centroide.z=0; for ( i=0;id2 && d1>d3) return d1; if(d2>d1 && d2>d3) return d2; if(d3>d2 && d3>d1) return d3; return 9999; } int gLocalize::get_byteorder() { union { long l; char c[4]; } test; test.l = 1; if( test.c[3] && !test.c[2] && !test.c[1] && !test.c[0] ) return ORDER_BIGENDIAN; if( !test.c[3] && !test.c[2] && !test.c[1] && test.c[0] ) return ORDER_LITTLEENDIAN; return ORDER_UNKNOWN; } /** * Implementation of the Hausdorff distance from a reference 1 cm diameter sphere */ double gLocalize::hausdorff(vtkPolyDataConnectivityFilter* filter, surf tempsurf) { vtkSmartPointer source_sphere = vtkSmartPointer::New(); source_sphere->SetCenter(tempsurf.center[0],tempsurf.center[1],tempsurf.center[2]); source_sphere->SetRadius(5.0); source_sphere->Update(); vtkSmartPointer sphere = source_sphere->GetOutput(); sphere->Update(); sphere->BuildCells(); vtkSmartPointer edge_extractor =vtkSmartPointer::New(); edge_extractor->RemoveAllInputs(); edge_extractor->SetInput(filter->GetOutput()); edge_extractor->Update(); vtkSmartPointer tmp = vtkSmartPointer::New(); tmp=edge_extractor->GetOutput(); tmp->Update(); tmp->BuildCells(); tmp->BuildLinks(); QList punti_sup; point ptemp; for (int id=0;id< (int) tmp->GetNumberOfPoints();id++){ ptemp.x=tmp->GetPoint(id)[0]; ptemp.y=tmp->GetPoint(id)[1]; ptemp.z=tmp->GetPoint(id)[2]; /*cout<GetOutput()->GetPoint(id)[0]<<" "<GetOutput()->GetPoint(id)[1]<<" "<GetOutput()->GetPoint(id)[2]< punti_sphere; for (int id=0;id< (int) sphere->GetNumberOfPoints();id++){ ptemp.x=sphere->GetPoint(id)[0]; ptemp.y=sphere->GetPoint(id)[1]; ptemp.z=sphere->GetPoint(id)[2]; /*cout<GetOutput()->GetPoint(id)[0]<<" "<GetOutput()->GetPoint(id)[1]<<" "<GetOutput()->GetPoint(id)[2]< largest) largest = dist; } summin += smallest; summax += largest; if (smallest > maxmin) maxmin = smallest; // so this is max min if (largest > maxmax) maxmax = largest; // and this is max max } punti_sphere.clear(); punti_sup.clear(); return maxmin; // Hausdorff distance }